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/synchronization/lock.h" |
14 #include "base/threading/thread_checker.h" | 14 #include "base/threading/thread_checker.h" |
15 #include "chromecast/media/cma/backend/media_component_device.h" | 15 #include "chromecast/media/cma/backend/media_component_device.h" |
16 #include "chromecast/media/cma/pipeline/av_pipeline_client.h" | 16 #include "chromecast/media/cma/pipeline/av_pipeline_client.h" |
17 | 17 |
18 namespace media { | 18 namespace media { |
19 class AudioDecoderConfig; | 19 class AudioDecoderConfig; |
20 class VideoDecoderConfig; | 20 class VideoDecoderConfig; |
21 } | 21 } |
22 | 22 |
23 namespace chromecast { | 23 namespace chromecast { |
24 namespace media { | 24 namespace media { |
25 class BrowserCdmCast; | 25 class BrowserCdmCast; |
26 class BufferingFrameProvider; | 26 class BufferingFrameProvider; |
27 class BufferingState; | 27 class BufferingState; |
28 class CodedFrameProvider; | 28 class CodedFrameProvider; |
29 class DecoderBufferBase; | 29 class DecoderBufferBase; |
30 class MediaComponentDevice; | 30 class MediaComponentDevice; |
31 | 31 |
32 class AvPipelineImpl { | 32 class AvPipelineImpl : public base::RefCountedThreadSafe<AvPipelineImpl> { |
33 public: | 33 public: |
34 // Pipeline states. | 34 // Pipeline states. |
35 enum State { | 35 enum State { |
36 kUninitialized, | 36 kUninitialized, |
37 kPlaying, | 37 kPlaying, |
38 kFlushing, | 38 kFlushing, |
39 kFlushed, | 39 kFlushed, |
40 kStopped, | 40 kStopped, |
41 kError, | 41 kError, |
42 }; | 42 }; |
43 | 43 |
44 typedef base::Callback< | 44 typedef base::Callback< |
45 void(const ::media::AudioDecoderConfig&, | 45 void(const ::media::AudioDecoderConfig&, |
46 const ::media::VideoDecoderConfig&)> UpdateConfigCB; | 46 const ::media::VideoDecoderConfig&)> UpdateConfigCB; |
47 | 47 |
48 AvPipelineImpl( | 48 AvPipelineImpl( |
49 MediaComponentDevice* media_component_device, | 49 MediaComponentDevice* media_component_device, |
50 const UpdateConfigCB& update_config_cb); | 50 const UpdateConfigCB& update_config_cb); |
51 ~AvPipelineImpl(); | |
52 | 51 |
53 // 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 |
54 // |kUninitialized| state. | 53 // |kUninitialized| state. |
55 void SetCodedFrameProvider(scoped_ptr<CodedFrameProvider> frame_provider, | 54 void SetCodedFrameProvider(scoped_ptr<CodedFrameProvider> frame_provider, |
56 size_t max_buffer_size, | 55 size_t max_buffer_size, |
57 size_t max_frame_size); | 56 size_t max_frame_size); |
58 void SetClient(const AvPipelineClient& client); | 57 void SetClient(const AvPipelineClient& client); |
59 | 58 |
60 // Initialize the pipeline. | 59 // Initialize the pipeline. |
61 bool Initialize(); | 60 bool Initialize(); |
62 | 61 |
63 // Setup the pipeline and ensure samples are available for the given media | 62 // Setup the pipeline and ensure samples are available for the given media |
64 // time, then start rendering samples. | 63 // time, then start rendering samples. |
65 bool StartPlayingFrom(base::TimeDelta time, | 64 bool StartPlayingFrom(base::TimeDelta time, |
66 const scoped_refptr<BufferingState>& buffering_state); | 65 const scoped_refptr<BufferingState>& buffering_state); |
67 | 66 |
68 // Flush any remaining samples in the pipeline. | 67 // Flush any remaining samples in the pipeline. |
69 // Invoke |done_cb| when flush is completed. | 68 // Invoke |done_cb| when flush is completed. |
70 void Flush(const base::Closure& done_cb); | 69 void Flush(const base::Closure& done_cb); |
71 | 70 |
72 // Tear down the pipeline and release the hardware resources. | 71 // Tear down the pipeline and release the hardware resources. |
73 void Stop(); | 72 void Stop(); |
74 | 73 |
75 State GetState() const { return state_; } | 74 State GetState() const { return state_; } |
76 void TransitionToState(State state); | 75 void TransitionToState(State state); |
77 | 76 |
78 void SetCdm(BrowserCdmCast* media_keys); | 77 void SetCdm(BrowserCdmCast* media_keys); |
79 | 78 |
80 private: | 79 private: |
| 80 friend class base::RefCountedThreadSafe<AvPipelineImpl>; |
| 81 ~AvPipelineImpl(); |
| 82 |
81 // Callback invoked when the CDM state has changed in a way that might | 83 // Callback invoked when the CDM state has changed in a way that might |
82 // impact media playback. | 84 // impact media playback. |
83 void OnCdmStateChange(); | 85 void OnCdmStateChange(); |
84 | 86 |
85 // Callback invoked when playback has reached the end of stream. | 87 // Callback invoked when playback has reached the end of stream. |
86 void OnEos(); | 88 void OnEos(); |
87 | 89 |
88 // Feed the pipeline, getting the frames from |frame_provider_|. | 90 // Feed the pipeline, getting the frames from |frame_provider_|. |
89 void FetchBufferIfNeeded(); | 91 void FetchBufferIfNeeded(); |
90 | 92 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 | 152 |
151 // Indicate if there is a frame being pushed to the audio device. | 153 // Indicate if there is a frame being pushed to the audio device. |
152 bool pending_push_; | 154 bool pending_push_; |
153 | 155 |
154 // The media time is retrieved at regular intervals. | 156 // The media time is retrieved at regular intervals. |
155 // Indicate whether time update is enabled. | 157 // Indicate whether time update is enabled. |
156 bool enable_time_update_; | 158 bool enable_time_update_; |
157 bool pending_time_update_task_; | 159 bool pending_time_update_task_; |
158 | 160 |
159 // Decryption keys, if available. | 161 // Decryption keys, if available. |
| 162 base::Lock media_keys_lock_; |
160 BrowserCdmCast* media_keys_; | 163 BrowserCdmCast* media_keys_; |
161 int media_keys_callback_id_; | 164 int media_keys_callback_id_; |
162 | 165 |
163 base::WeakPtr<AvPipelineImpl> weak_this_; | |
164 base::WeakPtrFactory<AvPipelineImpl> weak_factory_; | |
165 | |
166 DISALLOW_COPY_AND_ASSIGN(AvPipelineImpl); | 166 DISALLOW_COPY_AND_ASSIGN(AvPipelineImpl); |
167 }; | 167 }; |
168 | 168 |
169 } // namespace media | 169 } // namespace media |
170 } // namespace chromecast | 170 } // namespace chromecast |
171 | 171 |
172 #endif // CHROMECAST_MEDIA_CMA_BASE_AV_PIPELINE_IMPL_H_ | 172 #endif // CHROMECAST_MEDIA_CMA_BASE_AV_PIPELINE_IMPL_H_ |
OLD | NEW |