OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROMECAST_MEDIA_CMA_PIPELINE_MEDIA_PIPELINE_IMPL_H_ | 5 #ifndef CHROMECAST_MEDIA_CMA_PIPELINE_MEDIA_PIPELINE_IMPL_H_ |
6 #define CHROMECAST_MEDIA_CMA_PIPELINE_MEDIA_PIPELINE_IMPL_H_ | 6 #define CHROMECAST_MEDIA_CMA_PIPELINE_MEDIA_PIPELINE_IMPL_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/threading/thread_checker.h" | 13 #include "base/threading/thread_checker.h" |
14 #include "chromecast/media/cma/pipeline/load_type.h" | 14 #include "chromecast/media/cma/pipeline/load_type.h" |
15 #include "chromecast/media/cma/pipeline/media_pipeline.h" | |
16 #include "chromecast/media/cma/pipeline/media_pipeline_client.h" | 15 #include "chromecast/media/cma/pipeline/media_pipeline_client.h" |
| 16 #include "chromecast/public/media/media_pipeline_backend.h" |
17 #include "media/base/serial_runner.h" | 17 #include "media/base/serial_runner.h" |
18 | 18 |
| 19 namespace media { |
| 20 class AudioDecoderConfig; |
| 21 class VideoDecoderConfig; |
| 22 } // namespace media |
| 23 |
19 namespace chromecast { | 24 namespace chromecast { |
20 namespace media { | 25 namespace media { |
21 class AudioPipelineImpl; | 26 class AudioPipelineImpl; |
| 27 struct AvPipelineClient; |
| 28 struct VideoPipelineClient; |
22 class BrowserCdmCast; | 29 class BrowserCdmCast; |
23 class BufferingController; | 30 class BufferingController; |
24 class MediaClockDevice; | 31 class CodedFrameProvider; |
25 class MediaPipelineBackend; | |
26 class VideoPipelineImpl; | 32 class VideoPipelineImpl; |
27 | 33 |
28 class MediaPipelineImpl : public MediaPipeline { | 34 class MediaPipelineImpl : public MediaPipelineBackend::Delegate { |
29 public: | 35 public: |
30 MediaPipelineImpl(); | 36 MediaPipelineImpl(); |
31 ~MediaPipelineImpl() override; | 37 ~MediaPipelineImpl() override; |
32 | 38 |
33 // Initialize the media pipeline: the pipeline is configured based on | 39 // Initialize the media pipeline: the pipeline is configured based on |
34 // |load_type|. | 40 // |load_type|. |
35 void Initialize(LoadType load_type, | 41 void Initialize(LoadType load_type, |
36 scoped_ptr<MediaPipelineBackend> media_pipeline_backend); | 42 scoped_ptr<MediaPipelineBackend> media_pipeline_backend); |
37 | 43 |
38 // MediaPipeline implementation. | 44 void SetClient(const MediaPipelineClient& client); |
39 void SetClient(const MediaPipelineClient& client) override; | 45 void SetCdm(int cdm_id); |
40 void SetCdm(int cdm_id) override; | |
41 AudioPipeline* GetAudioPipeline() const override; | |
42 VideoPipeline* GetVideoPipeline() const override; | |
43 void InitializeAudio( | |
44 const ::media::AudioDecoderConfig& config, | |
45 scoped_ptr<CodedFrameProvider> frame_provider, | |
46 const ::media::PipelineStatusCB& status_cb) override; | |
47 void InitializeVideo( | |
48 const std::vector<::media::VideoDecoderConfig>& configs, | |
49 scoped_ptr<CodedFrameProvider> frame_provider, | |
50 const ::media::PipelineStatusCB& status_cb) override; | |
51 void StartPlayingFrom(base::TimeDelta time) override; | |
52 void Flush(const ::media::PipelineStatusCB& status_cb) override; | |
53 void Stop() override; | |
54 void SetPlaybackRate(double playback_rate) override; | |
55 | 46 |
56 AudioPipelineImpl* GetAudioPipelineImpl() const; | 47 // MediaPipelineBackendDelegate implementation: |
57 VideoPipelineImpl* GetVideoPipelineImpl() const; | 48 void OnVideoResolutionChanged(MediaPipelineBackend::VideoDecoder* decoder, |
| 49 const Size& size) override; |
| 50 void OnPushBufferComplete(MediaPipelineBackend::Decoder* decoder, |
| 51 MediaPipelineBackend::BufferStatus status) override; |
| 52 void OnEndOfStream(MediaPipelineBackend::Decoder* decoder) override; |
| 53 void OnDecoderError(MediaPipelineBackend::Decoder* decoder) override; |
| 54 |
| 55 void InitializeAudio(const ::media::AudioDecoderConfig& config, |
| 56 const AvPipelineClient& client, |
| 57 scoped_ptr<CodedFrameProvider> frame_provider, |
| 58 const ::media::PipelineStatusCB& status_cb); |
| 59 void InitializeVideo(const std::vector< ::media::VideoDecoderConfig>& configs, |
| 60 const VideoPipelineClient& client, |
| 61 scoped_ptr<CodedFrameProvider> frame_provider, |
| 62 const ::media::PipelineStatusCB& status_cb); |
| 63 void StartPlayingFrom(base::TimeDelta time); |
| 64 void Flush(const ::media::PipelineStatusCB& status_cb); |
| 65 void Stop(); |
| 66 void SetPlaybackRate(double playback_rate); |
| 67 void SetVolume(float volume); |
58 | 68 |
59 void SetCdm(BrowserCdmCast* cdm); | 69 void SetCdm(BrowserCdmCast* cdm); |
60 | 70 |
61 private: | 71 private: |
62 void StateTransition(const ::media::PipelineStatusCB& status_cb, | 72 void StateTransition(const ::media::PipelineStatusCB& status_cb, |
63 ::media::PipelineStatus status); | 73 ::media::PipelineStatus status); |
64 | 74 |
65 // Invoked to notify about a change of buffering state. | 75 // Invoked to notify about a change of buffering state. |
66 void OnBufferingNotification(bool is_buffering); | 76 void OnBufferingNotification(bool is_buffering); |
67 | 77 |
68 void UpdateMediaTime(); | 78 void UpdateMediaTime(); |
69 | 79 |
70 void OnError(::media::PipelineStatus error); | 80 void OnError(::media::PipelineStatus error); |
71 | 81 |
72 base::ThreadChecker thread_checker_; | 82 base::ThreadChecker thread_checker_; |
73 | 83 |
74 MediaPipelineClient client_; | 84 MediaPipelineClient client_; |
75 | 85 |
76 scoped_ptr<BufferingController> buffering_controller_; | 86 scoped_ptr<BufferingController> buffering_controller_; |
77 | 87 |
78 // Interface with the underlying hardware media pipeline. | 88 // Interface with the underlying hardware media pipeline. |
79 scoped_ptr<MediaPipelineBackend> media_pipeline_backend_; | 89 scoped_ptr<MediaPipelineBackend> media_pipeline_backend_; |
80 MediaClockDevice* clock_device_; | 90 MediaPipelineBackend::AudioDecoder* audio_decoder_; |
| 91 MediaPipelineBackend::VideoDecoder* video_decoder_; |
81 | 92 |
| 93 bool backend_initialized_; |
82 bool has_audio_; | 94 bool has_audio_; |
83 bool has_video_; | 95 bool has_video_; |
84 scoped_ptr<AudioPipelineImpl> audio_pipeline_; | 96 scoped_ptr<AudioPipelineImpl> audio_pipeline_; |
85 scoped_ptr<VideoPipelineImpl> video_pipeline_; | 97 scoped_ptr<VideoPipelineImpl> video_pipeline_; |
86 scoped_ptr< ::media::SerialRunner> pending_flush_callbacks_; | 98 scoped_ptr< ::media::SerialRunner> pending_flush_callbacks_; |
87 | 99 |
| 100 // Whether or not the backend is currently paused. |
| 101 bool paused_; |
88 // Playback rate set by the upper layer. | 102 // Playback rate set by the upper layer. |
89 float target_playback_rate_; | 103 float target_playback_rate_; |
90 | 104 |
91 // Indicate a possible re-buffering phase. | |
92 bool is_buffering_; | |
93 | |
94 // The media time is retrieved at regular intervals. | 105 // The media time is retrieved at regular intervals. |
95 // Indicate whether time update is enabled. | 106 // Indicate whether time update is enabled. |
96 bool enable_time_update_; | 107 bool enable_time_update_; |
97 bool pending_time_update_task_; | 108 bool pending_time_update_task_; |
98 base::TimeDelta last_media_time_; | 109 base::TimeDelta last_media_time_; |
99 | 110 |
100 // Used to make the statistics update period a multiplier of the time update | 111 // Used to make the statistics update period a multiplier of the time update |
101 // period. | 112 // period. |
102 int statistics_rolling_counter_; | 113 int statistics_rolling_counter_; |
103 | 114 |
104 base::WeakPtr<MediaPipelineImpl> weak_this_; | 115 base::WeakPtr<MediaPipelineImpl> weak_this_; |
105 base::WeakPtrFactory<MediaPipelineImpl> weak_factory_; | 116 base::WeakPtrFactory<MediaPipelineImpl> weak_factory_; |
106 | 117 |
107 DISALLOW_COPY_AND_ASSIGN(MediaPipelineImpl); | 118 DISALLOW_COPY_AND_ASSIGN(MediaPipelineImpl); |
108 }; | 119 }; |
109 | 120 |
110 } // namespace media | 121 } // namespace media |
111 } // namespace chromecast | 122 } // namespace chromecast |
112 | 123 |
113 #endif // CHROMECAST_MEDIA_CMA_PIPELINE_MEDIA_PIPELINE_IMPL_H_ | 124 #endif // CHROMECAST_MEDIA_CMA_PIPELINE_MEDIA_PIPELINE_IMPL_H_ |
OLD | NEW |