#include "media/remoting/courier_renderer.h"
#include <algorithm>
#include <limits>
#include <memory>
#include <utility>
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/ptr_util.h"
#include "base/numerics/safe_math.h"
#include "base/task/bind_post_task.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/default_tick_clock.h"
#include "base/time/time.h"
#include "media/base/buffering_state.h"
#include "media/base/media_resource.h"
#include "media/base/renderer_client.h"
#include "media/base/video_renderer_sink.h"
#include "media/base/waiting.h"
#include "media/cast/openscreen/remoting_proto_enum_utils.h"
#include "media/cast/openscreen/remoting_proto_utils.h"
#include "media/remoting/demuxer_stream_adapter.h"
#include "media/remoting/renderer_controller.h"
RpcMessenger;
namespace media {
namespace remoting {
namespace {
constexpr base::TimeDelta kTrackingWindow = …;
constexpr base::TimeDelta kMediaPlaybackDelayThreshold = …;
constexpr int kPlaybackDelayCountThreshold = …;
constexpr int kMaxNumVideoFramesDroppedPercentage = …;
constexpr base::TimeDelta kStabilizationPeriod = …;
constexpr base::TimeDelta kDataFlowPollPeriod = …;
void RegisterForRpcTask(
openscreen::WeakPtr<openscreen::cast::RpcMessenger> rpc_messenger,
int rpc_handle,
openscreen::cast::RpcMessenger::ReceiveMessageCallback message_cb) { … }
void DeregisterFromRpcTask(
openscreen::WeakPtr<openscreen::cast::RpcMessenger> rpc_messenger,
int rpc_handle) { … }
}
CourierRenderer::CourierRenderer(
scoped_refptr<base::SequencedTaskRunner> media_task_runner,
const base::WeakPtr<RendererController>& controller,
VideoRendererSink* video_renderer_sink)
: … { … }
CourierRenderer::~CourierRenderer() { … }
void CourierRenderer::Initialize(MediaResource* media_resource,
RendererClient* client,
PipelineStatusCallback init_cb) { … }
void CourierRenderer::SetLatencyHint(
std::optional<base::TimeDelta> latency_hint) { … }
void CourierRenderer::Flush(base::OnceClosure flush_cb) { … }
void CourierRenderer::StartPlayingFrom(base::TimeDelta time) { … }
void CourierRenderer::SetPlaybackRate(double playback_rate) { … }
void CourierRenderer::SetVolume(float volume) { … }
base::TimeDelta CourierRenderer::GetMediaTime() { … }
RendererType CourierRenderer::GetRendererType() { … }
void CourierRenderer::OnDataPipeCreatedOnMainThread(
scoped_refptr<base::SequencedTaskRunner> media_task_runner,
base::WeakPtr<CourierRenderer> self,
openscreen::WeakPtr<RpcMessenger> rpc_messenger,
mojo::PendingRemote<mojom::RemotingDataStreamSender> audio,
mojo::PendingRemote<mojom::RemotingDataStreamSender> video,
mojo::ScopedDataPipeProducerHandle audio_handle,
mojo::ScopedDataPipeProducerHandle video_handle) { … }
void CourierRenderer::OnDataPipeCreated(
mojo::PendingRemote<mojom::RemotingDataStreamSender> audio,
mojo::PendingRemote<mojom::RemotingDataStreamSender> video,
mojo::ScopedDataPipeProducerHandle audio_handle,
mojo::ScopedDataPipeProducerHandle video_handle,
int audio_rpc_handle,
int video_rpc_handle) { … }
void CourierRenderer::OnMessageReceivedOnMainThread(
scoped_refptr<base::SequencedTaskRunner> media_task_runner,
base::WeakPtr<CourierRenderer> self,
std::unique_ptr<openscreen::cast::RpcMessage> message) { … }
void CourierRenderer::OnReceivedRpc(
std::unique_ptr<openscreen::cast::RpcMessage> message) { … }
void CourierRenderer::SendRpcToRemote(
std::unique_ptr<openscreen::cast::RpcMessage> message) { … }
void CourierRenderer::AcquireRendererDone(
std::unique_ptr<openscreen::cast::RpcMessage> message) { … }
void CourierRenderer::InitializeCallback(
std::unique_ptr<openscreen::cast::RpcMessage> message) { … }
void CourierRenderer::FlushUntilCallback() { … }
void CourierRenderer::OnTimeUpdate(
std::unique_ptr<openscreen::cast::RpcMessage> message) { … }
void CourierRenderer::OnBufferingStateChange(
std::unique_ptr<openscreen::cast::RpcMessage> message) { … }
void CourierRenderer::OnAudioConfigChange(
std::unique_ptr<openscreen::cast::RpcMessage> message) { … }
void CourierRenderer::OnVideoConfigChange(
std::unique_ptr<openscreen::cast::RpcMessage> message) { … }
void CourierRenderer::OnVideoNaturalSizeChange(
std::unique_ptr<openscreen::cast::RpcMessage> message) { … }
void CourierRenderer::OnVideoOpacityChange(
std::unique_ptr<openscreen::cast::RpcMessage> message) { … }
void CourierRenderer::OnStatisticsUpdate(
std::unique_ptr<openscreen::cast::RpcMessage> message) { … }
void CourierRenderer::OnFatalError(StopTrigger stop_trigger) { … }
void CourierRenderer::OnMediaTimeUpdated() { … }
void CourierRenderer::UpdateVideoStatsQueue(int video_frames_decoded,
int video_frames_dropped) { … }
void CourierRenderer::ResetMeasurements() { … }
void CourierRenderer::MeasureAndRecordDataRates() { … }
bool CourierRenderer::IsWaitingForDataFromDemuxers() const { … }
void CourierRenderer::RegisterForRpcMessaging() { … }
void CourierRenderer::DeregisterFromRpcMessaging() { … }
}
}