| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROMECAST_RENDERER_MEDIA_CMA_RENDERER_H_ | |
| 6 #define CHROMECAST_RENDERER_MEDIA_CMA_RENDERER_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 #include "base/memory/weak_ptr.h" | |
| 12 #include "base/synchronization/lock.h" | |
| 13 #include "base/threading/thread_checker.h" | |
| 14 #include "base/time/default_tick_clock.h" | |
| 15 #include "media/base/buffering_state.h" | |
| 16 #include "media/base/renderer.h" | |
| 17 #include "ui/gfx/geometry/size.h" | |
| 18 | |
| 19 namespace base { | |
| 20 class SingleThreadTaskRunner; | |
| 21 } | |
| 22 | |
| 23 namespace media { | |
| 24 class DemuxerStreamProvider; | |
| 25 class GpuVideoAcceleratorFactories; | |
| 26 class TimeDeltaInterpolator; | |
| 27 class VideoFrame; | |
| 28 class VideoOverlayFactory; | |
| 29 class VideoRendererSink; | |
| 30 } | |
| 31 | |
| 32 namespace chromecast { | |
| 33 namespace media { | |
| 34 class AudioPipelineProxy; | |
| 35 class BalancedMediaTaskRunnerFactory; | |
| 36 class MediaPipelineProxy; | |
| 37 class VideoPipelineProxy; | |
| 38 | |
| 39 class CmaRenderer : public ::media::Renderer { | |
| 40 public: | |
| 41 CmaRenderer(std::unique_ptr<MediaPipelineProxy> media_pipeline, | |
| 42 ::media::VideoRendererSink* video_renderer_sink, | |
| 43 ::media::GpuVideoAcceleratorFactories* gpu_factories); | |
| 44 ~CmaRenderer() override; | |
| 45 | |
| 46 // ::media::Renderer implementation: | |
| 47 void Initialize(::media::DemuxerStreamProvider* demuxer_stream_provider, | |
| 48 ::media::RendererClient* client, | |
| 49 const ::media::PipelineStatusCB& init_cb) override; | |
| 50 void Flush(const base::Closure& flush_cb) override; | |
| 51 void StartPlayingFrom(base::TimeDelta time) override; | |
| 52 void SetPlaybackRate(double playback_rate) override; | |
| 53 void SetVolume(float volume) override; | |
| 54 base::TimeDelta GetMediaTime() override; | |
| 55 bool HasAudio() override; | |
| 56 bool HasVideo() override; | |
| 57 void SetCdm(::media::CdmContext* cdm_context, | |
| 58 const ::media::CdmAttachedCB& cdm_attached_cb) override; | |
| 59 | |
| 60 private: | |
| 61 enum State { | |
| 62 kUninitialized, | |
| 63 kPlaying, | |
| 64 kFlushed, | |
| 65 kError, | |
| 66 }; | |
| 67 | |
| 68 // Asynchronous initialization sequence. These four methods are invoked in | |
| 69 // the order below, with a successful initialization making it to | |
| 70 // OnVideoPipelineInitializeDone, regardless of which streams are present. | |
| 71 void InitializeAudioPipeline(); | |
| 72 void OnAudioPipelineInitializeDone(bool audio_stream_present, | |
| 73 ::media::PipelineStatus status); | |
| 74 void InitializeVideoPipeline(); | |
| 75 void OnVideoPipelineInitializeDone(bool video_stream_present, | |
| 76 ::media::PipelineStatus status); | |
| 77 | |
| 78 // Callbacks for AvPipelineClient. | |
| 79 void OnWaitForKey(bool is_audio); | |
| 80 void OnEosReached(bool is_audio); | |
| 81 void OnStatisticsUpdated(const ::media::PipelineStatistics& stats); | |
| 82 void OnNaturalSizeChanged(const gfx::Size& size); | |
| 83 | |
| 84 // Callbacks for MediaPipelineClient. | |
| 85 void OnPlaybackTimeUpdated(base::TimeDelta time, | |
| 86 base::TimeDelta max_time, | |
| 87 base::TimeTicks capture_time); | |
| 88 void OnBufferingNotification(::media::BufferingState state); | |
| 89 | |
| 90 void OnFlushDone(); | |
| 91 void OnError(::media::PipelineStatus status); | |
| 92 | |
| 93 // Begin a state transition. | |
| 94 // Return true if delayed because of a pending state transition. | |
| 95 void BeginStateTransition(); | |
| 96 void CompleteStateTransition(State new_state); | |
| 97 | |
| 98 base::ThreadChecker thread_checker_; | |
| 99 | |
| 100 scoped_refptr<BalancedMediaTaskRunnerFactory> media_task_runner_factory_; | |
| 101 std::unique_ptr<MediaPipelineProxy> media_pipeline_; | |
| 102 AudioPipelineProxy* audio_pipeline_; | |
| 103 VideoPipelineProxy* video_pipeline_; | |
| 104 ::media::VideoRendererSink* video_renderer_sink_; | |
| 105 | |
| 106 ::media::DemuxerStreamProvider* demuxer_stream_provider_; | |
| 107 | |
| 108 // Set of callbacks. | |
| 109 ::media::RendererClient* client_; | |
| 110 ::media::PipelineStatusCB init_cb_; | |
| 111 base::Closure flush_cb_; | |
| 112 | |
| 113 // Renderer state. | |
| 114 // Used mostly for checking that transitions are correct. | |
| 115 State state_; | |
| 116 bool is_pending_transition_; | |
| 117 | |
| 118 bool has_audio_; | |
| 119 bool has_video_; | |
| 120 | |
| 121 bool received_audio_eos_; | |
| 122 bool received_video_eos_; | |
| 123 | |
| 124 // Data members for helping the creation of the video hole frame. | |
| 125 ::media::GpuVideoAcceleratorFactories* gpu_factories_; | |
| 126 std::unique_ptr<::media::VideoOverlayFactory> video_overlay_factory_; | |
| 127 | |
| 128 // Lock protecting access to |time_interpolator_|. | |
| 129 base::Lock time_interpolator_lock_; | |
| 130 | |
| 131 // base::TickClock used by |time_interpolator_|. | |
| 132 base::DefaultTickClock default_tick_clock_; | |
| 133 | |
| 134 // Tracks the most recent media time update and provides interpolated values | |
| 135 // as playback progresses. | |
| 136 std::unique_ptr<::media::TimeDeltaInterpolator> time_interpolator_; | |
| 137 | |
| 138 double playback_rate_; | |
| 139 | |
| 140 base::WeakPtr<CmaRenderer> weak_this_; | |
| 141 base::WeakPtrFactory<CmaRenderer> weak_factory_; | |
| 142 | |
| 143 DISALLOW_COPY_AND_ASSIGN(CmaRenderer); | |
| 144 }; | |
| 145 | |
| 146 } // namespace media | |
| 147 } // namespace chromecast | |
| 148 | |
| 149 #endif // CHROMECAST_RENDERER_MEDIA_CMA_RENDERER_H_ | |
| OLD | NEW |