| 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_BASE_AV_PIPELINE_IMPL_H_ | 5 #ifndef CHROMECAST_MEDIA_CMA_BASE_AV_PIPELINE_IMPL_H_ |
| 6 #define CHROMECAST_MEDIA_CMA_BASE_AV_PIPELINE_IMPL_H_ | 6 #define CHROMECAST_MEDIA_CMA_BASE_AV_PIPELINE_IMPL_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/threading/thread_checker.h" | 14 #include "base/threading/thread_checker.h" |
| 15 #include "chromecast/media/cma/pipeline/av_pipeline_client.h" | 15 #include "chromecast/media/cma/base/cast_decoder_buffer_impl.h" |
| 16 #include "chromecast/public/media/media_component_device.h" | 16 #include "chromecast/public/media/media_pipeline_backend.h" |
| 17 #include "chromecast/public/media/stream_id.h" | 17 #include "chromecast/public/media/stream_id.h" |
| 18 | 18 |
| 19 namespace media { | 19 namespace media { |
| 20 class AudioDecoderConfig; | 20 class AudioDecoderConfig; |
| 21 class VideoDecoderConfig; | 21 class VideoDecoderConfig; |
| 22 } | 22 } |
| 23 | 23 |
| 24 namespace chromecast { | 24 namespace chromecast { |
| 25 namespace media { | 25 namespace media { |
| 26 class BrowserCdmCast; | 26 class BrowserCdmCast; |
| 27 class BufferingFrameProvider; | 27 class BufferingFrameProvider; |
| 28 class BufferingState; | 28 class BufferingState; |
| 29 class CodedFrameProvider; | 29 class CodedFrameProvider; |
| 30 class DecoderBufferBase; | 30 class DecoderBufferBase; |
| 31 class MediaComponentDevice; | |
| 32 | 31 |
| 33 class AvPipelineImpl { | 32 class AvPipelineImpl { |
| 34 public: | 33 public: |
| 35 // Pipeline states. | 34 // Pipeline states. |
| 36 enum State { | 35 enum State { |
| 37 kUninitialized, | 36 kUninitialized, |
| 38 kPlaying, | 37 kPlaying, |
| 39 kFlushing, | 38 kFlushing, |
| 40 kFlushed, | 39 kFlushed, |
| 41 kStopped, | 40 kStopped, |
| 42 kError, | 41 kError, |
| 43 }; | 42 }; |
| 44 | 43 |
| 45 typedef base::Callback< | 44 typedef base::Callback< |
| 46 void(StreamId id, | 45 void(StreamId id, |
| 47 const ::media::AudioDecoderConfig&, | 46 const ::media::AudioDecoderConfig&, |
| 48 const ::media::VideoDecoderConfig&)> UpdateConfigCB; | 47 const ::media::VideoDecoderConfig&)> UpdateConfigCB; |
| 49 | 48 |
| 50 AvPipelineImpl( | 49 AvPipelineImpl(MediaPipelineBackend::Decoder* decoder, |
| 51 MediaComponentDevice* media_component_device, | 50 const UpdateConfigCB& update_config_cb); |
| 52 const UpdateConfigCB& update_config_cb); | |
| 53 ~AvPipelineImpl(); | 51 ~AvPipelineImpl(); |
| 54 | 52 |
| 55 // Setting the frame provider or the client must be done in the | 53 // Setting the frame provider or the client must be done in the |
| 56 // |kUninitialized| state. | 54 // |kUninitialized| state. |
| 57 void SetCodedFrameProvider(scoped_ptr<CodedFrameProvider> frame_provider, | 55 void SetCodedFrameProvider(scoped_ptr<CodedFrameProvider> frame_provider, |
| 58 size_t max_buffer_size, | 56 size_t max_buffer_size, |
| 59 size_t max_frame_size); | 57 size_t max_frame_size); |
| 60 void SetClient(const AvPipelineClient& client); | |
| 61 | |
| 62 // Initialize the pipeline. | |
| 63 bool Initialize(); | |
| 64 | 58 |
| 65 // Setup the pipeline and ensure samples are available for the given media | 59 // Setup the pipeline and ensure samples are available for the given media |
| 66 // time, then start rendering samples. | 60 // time, then start rendering samples. |
| 67 bool StartPlayingFrom(base::TimeDelta time, | 61 bool StartPlayingFrom(base::TimeDelta time, |
| 68 const scoped_refptr<BufferingState>& buffering_state); | 62 const scoped_refptr<BufferingState>& buffering_state); |
| 69 | 63 |
| 70 // Flush any remaining samples in the pipeline. | 64 // Flush any remaining samples in the pipeline. |
| 71 // Invoke |done_cb| when flush is completed. | 65 // Invoke |done_cb| when flush is completed. |
| 72 void Flush(const base::Closure& done_cb); | 66 void Flush(const base::Closure& done_cb); |
| 73 | 67 |
| 74 // Tear down the pipeline and release the hardware resources. | 68 // Tear down the pipeline and release the hardware resources. |
| 75 void Stop(); | 69 void Stop(); |
| 76 | 70 |
| 77 State GetState() const { return state_; } | 71 State GetState() const { return state_; } |
| 78 void TransitionToState(State state); | 72 void TransitionToState(State state); |
| 79 | 73 |
| 80 void SetCdm(BrowserCdmCast* media_keys); | 74 void SetCdm(BrowserCdmCast* media_keys); |
| 81 | 75 |
| 76 void OnBufferPushed(MediaPipelineBackend::BufferStatus status); |
| 77 |
| 82 private: | 78 private: |
| 83 // Callback invoked when the CDM state has changed in a way that might | 79 // Callback invoked when the CDM state has changed in a way that might |
| 84 // impact media playback. | 80 // impact media playback. |
| 85 void OnCdmStateChange(); | 81 void OnCdmStateChange(); |
| 86 | 82 |
| 87 // Callback invoked when playback has reached the end of stream. | |
| 88 void OnEos(); | |
| 89 | |
| 90 // Feed the pipeline, getting the frames from |frame_provider_|. | 83 // Feed the pipeline, getting the frames from |frame_provider_|. |
| 91 void FetchBufferIfNeeded(); | 84 void FetchBufferIfNeeded(); |
| 92 | 85 |
| 93 // Callback invoked when receiving a new frame from |frame_provider_|. | 86 // Callback invoked when receiving a new frame from |frame_provider_|. |
| 94 void OnNewFrame(const scoped_refptr<DecoderBufferBase>& buffer, | 87 void OnNewFrame(const scoped_refptr<DecoderBufferBase>& buffer, |
| 95 const ::media::AudioDecoderConfig& audio_config, | 88 const ::media::AudioDecoderConfig& audio_config, |
| 96 const ::media::VideoDecoderConfig& video_config); | 89 const ::media::VideoDecoderConfig& video_config); |
| 97 | 90 |
| 98 // Process a pending buffer. | 91 // Process a pending buffer. |
| 99 void ProcessPendingBuffer(); | 92 void ProcessPendingBuffer(); |
| 100 | 93 |
| 101 void OnFramePushed(MediaComponentDevice::FrameStatus status); | |
| 102 | |
| 103 // Callbacks: | 94 // Callbacks: |
| 104 // - when BrowserCdm updated its state. | 95 // - when BrowserCdm updated its state. |
| 105 // - when BrowserCdm has been destroyed. | 96 // - when BrowserCdm has been destroyed. |
| 106 void OnCdmStateChanged(); | 97 void OnCdmStateChanged(); |
| 107 void OnCdmDestroyed(); | 98 void OnCdmDestroyed(); |
| 108 | 99 |
| 109 // Callback invoked when a frame has been buffered by |frame_provider_| | 100 // Callback invoked when a media buffer has been buffered by |frame_provider_| |
| 110 // which is a BufferingFrameProvider. | 101 // which is a BufferingFrameProvider. |
| 111 void OnFrameBuffered(const scoped_refptr<DecoderBufferBase>& buffer, | 102 void OnDataBuffered(const scoped_refptr<DecoderBufferBase>& buffer, |
| 112 bool is_at_max_capacity); | 103 bool is_at_max_capacity); |
| 113 void UpdatePlayableFrames(); | 104 void UpdatePlayableFrames(); |
| 114 | 105 |
| 115 base::ThreadChecker thread_checker_; | 106 base::ThreadChecker thread_checker_; |
| 116 | 107 |
| 117 UpdateConfigCB update_config_cb_; | 108 UpdateConfigCB update_config_cb_; |
| 118 | 109 |
| 119 AvPipelineClient client_; | |
| 120 | |
| 121 // Backends. | 110 // Backends. |
| 122 MediaComponentDevice* media_component_device_; | 111 MediaPipelineBackend::Decoder* decoder_; |
| 123 | 112 |
| 124 // AV pipeline state. | 113 // AV pipeline state. |
| 125 State state_; | 114 State state_; |
| 126 | 115 |
| 127 // Buffering state. | 116 // Buffering state. |
| 128 // Can be NULL if there is no buffering strategy. | 117 // Can be NULL if there is no buffering strategy. |
| 129 scoped_refptr<BufferingState> buffering_state_; | 118 scoped_refptr<BufferingState> buffering_state_; |
| 130 | 119 |
| 131 // |buffered_time_| is the maximum timestamp of buffered frames. | 120 // |buffered_time_| is the maximum timestamp of buffered frames. |
| 132 // |playable_buffered_time_| is the maximum timestamp of buffered and | 121 // |playable_buffered_time_| is the maximum timestamp of buffered and |
| 133 // playable frames (i.e. the key id is available for those frames). | 122 // playable frames (i.e. the key id is available for those frames). |
| 134 base::TimeDelta buffered_time_; | 123 base::TimeDelta buffered_time_; |
| 135 base::TimeDelta playable_buffered_time_; | 124 base::TimeDelta playable_buffered_time_; |
| 136 | 125 |
| 137 // List of frames buffered but not playable right away due to a missing | 126 // List of frames buffered but not playable right away due to a missing |
| 138 // key id. | 127 // key id. |
| 139 std::list<scoped_refptr<DecoderBufferBase> > non_playable_frames_; | 128 std::list<scoped_refptr<DecoderBufferBase> > non_playable_frames_; |
| 140 | 129 |
| 141 // Buffer provider. | 130 // Buffer provider. |
| 142 scoped_ptr<BufferingFrameProvider> frame_provider_; | 131 scoped_ptr<BufferingFrameProvider> frame_provider_; |
| 143 | 132 |
| 144 // Indicate whether the frame fetching process is active. | 133 // Indicate whether the frame fetching process is active. |
| 145 bool enable_feeding_; | 134 bool enable_feeding_; |
| 146 | 135 |
| 147 // Indicate whether there is a pending buffer read. | 136 // Indicate whether there is a pending buffer read. |
| 148 bool pending_read_; | 137 bool pending_read_; |
| 149 | 138 |
| 150 // Pending buffer. | 139 // Pending buffer (not pushed to device yet) |
| 151 scoped_refptr<DecoderBufferBase> pending_buffer_; | 140 scoped_refptr<DecoderBufferBase> pending_buffer_; |
| 152 | 141 |
| 153 // Indicate if there is a frame being pushed to the audio device. | 142 // Buffer that has been pushed to the device but not processed yet. |
| 154 bool pending_push_; | 143 CastDecoderBufferImpl pushed_buffer_; |
| 155 | 144 |
| 156 // The media time is retrieved at regular intervals. | 145 // The media time is retrieved at regular intervals. |
| 157 // Indicate whether time update is enabled. | 146 // Indicate whether time update is enabled. |
| 158 bool enable_time_update_; | 147 bool enable_time_update_; |
| 159 bool pending_time_update_task_; | 148 bool pending_time_update_task_; |
| 160 | 149 |
| 161 // Decryption keys, if available. | 150 // Decryption keys, if available. |
| 162 BrowserCdmCast* media_keys_; | 151 BrowserCdmCast* media_keys_; |
| 163 int media_keys_callback_id_; | 152 int media_keys_callback_id_; |
| 164 | 153 |
| 165 base::WeakPtr<AvPipelineImpl> weak_this_; | 154 base::WeakPtr<AvPipelineImpl> weak_this_; |
| 166 base::WeakPtrFactory<AvPipelineImpl> weak_factory_; | 155 base::WeakPtrFactory<AvPipelineImpl> weak_factory_; |
| 167 | 156 |
| 168 DISALLOW_COPY_AND_ASSIGN(AvPipelineImpl); | 157 DISALLOW_COPY_AND_ASSIGN(AvPipelineImpl); |
| 169 }; | 158 }; |
| 170 | 159 |
| 171 } // namespace media | 160 } // namespace media |
| 172 } // namespace chromecast | 161 } // namespace chromecast |
| 173 | 162 |
| 174 #endif // CHROMECAST_MEDIA_CMA_BASE_AV_PIPELINE_IMPL_H_ | 163 #endif // CHROMECAST_MEDIA_CMA_BASE_AV_PIPELINE_IMPL_H_ |
| OLD | NEW |