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