Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: chromecast/media/cma/pipeline/av_pipeline_impl.h

Issue 1372393007: [Chromecast] Upgrade to new CMA backend API (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Remove unnecessary abstract base classes. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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. 82 // Callback invoked when playback has reached the end of stream.
slan 2015/10/07 20:56:16 nit: rm
kmackay 2015/10/09 20:35:40 Done.
88 void OnEos();
89 83
90 // Feed the pipeline, getting the frames from |frame_provider_|. 84 // Feed the pipeline, getting the frames from |frame_provider_|.
91 void FetchBufferIfNeeded(); 85 void FetchBufferIfNeeded();
92 86
93 // Callback invoked when receiving a new frame from |frame_provider_|. 87 // Callback invoked when receiving a new frame from |frame_provider_|.
94 void OnNewFrame(const scoped_refptr<DecoderBufferBase>& buffer, 88 void OnNewFrame(const scoped_refptr<DecoderBufferBase>& buffer,
95 const ::media::AudioDecoderConfig& audio_config, 89 const ::media::AudioDecoderConfig& audio_config,
96 const ::media::VideoDecoderConfig& video_config); 90 const ::media::VideoDecoderConfig& video_config);
97 91
98 // Process a pending buffer. 92 // Process a pending buffer.
99 void ProcessPendingBuffer(); 93 void ProcessPendingBuffer();
100 94
101 void OnFramePushed(MediaComponentDevice::FrameStatus status);
102
103 // Callbacks: 95 // Callbacks:
104 // - when BrowserCdm updated its state. 96 // - when BrowserCdm updated its state.
105 // - when BrowserCdm has been destroyed. 97 // - when BrowserCdm has been destroyed.
106 void OnCdmStateChanged(); 98 void OnCdmStateChanged();
107 void OnCdmDestroyed(); 99 void OnCdmDestroyed();
108 100
109 // Callback invoked when a frame has been buffered by |frame_provider_| 101 // Callback invoked when a frame has been buffered by |frame_provider_|
110 // which is a BufferingFrameProvider. 102 // which is a BufferingFrameProvider.
111 void OnFrameBuffered(const scoped_refptr<DecoderBufferBase>& buffer, 103 void OnFrameBuffered(const scoped_refptr<DecoderBufferBase>& buffer,
112 bool is_at_max_capacity); 104 bool is_at_max_capacity);
113 void UpdatePlayableFrames(); 105 void UpdatePlayableFrames();
114 106
115 base::ThreadChecker thread_checker_; 107 base::ThreadChecker thread_checker_;
116 108
117 UpdateConfigCB update_config_cb_; 109 UpdateConfigCB update_config_cb_;
118 110
119 AvPipelineClient client_;
120
121 // Backends. 111 // Backends.
122 MediaComponentDevice* media_component_device_; 112 MediaPipelineBackend::Decoder* decoder_;
123 113
124 // AV pipeline state. 114 // AV pipeline state.
125 State state_; 115 State state_;
126 116
127 // Buffering state. 117 // Buffering state.
128 // Can be NULL if there is no buffering strategy. 118 // Can be NULL if there is no buffering strategy.
129 scoped_refptr<BufferingState> buffering_state_; 119 scoped_refptr<BufferingState> buffering_state_;
130 120
131 // |buffered_time_| is the maximum timestamp of buffered frames. 121 // |buffered_time_| is the maximum timestamp of buffered frames.
132 // |playable_buffered_time_| is the maximum timestamp of buffered and 122 // |playable_buffered_time_| is the maximum timestamp of buffered and
133 // playable frames (i.e. the key id is available for those frames). 123 // playable frames (i.e. the key id is available for those frames).
134 base::TimeDelta buffered_time_; 124 base::TimeDelta buffered_time_;
135 base::TimeDelta playable_buffered_time_; 125 base::TimeDelta playable_buffered_time_;
136 126
137 // List of frames buffered but not playable right away due to a missing 127 // List of frames buffered but not playable right away due to a missing
138 // key id. 128 // key id.
139 std::list<scoped_refptr<DecoderBufferBase> > non_playable_frames_; 129 std::list<scoped_refptr<DecoderBufferBase> > non_playable_frames_;
140 130
141 // Buffer provider. 131 // Buffer provider.
142 scoped_ptr<BufferingFrameProvider> frame_provider_; 132 scoped_ptr<BufferingFrameProvider> frame_provider_;
143 133
144 // Indicate whether the frame fetching process is active. 134 // Indicate whether the frame fetching process is active.
145 bool enable_feeding_; 135 bool enable_feeding_;
146 136
147 // Indicate whether there is a pending buffer read. 137 // Indicate whether there is a pending buffer read.
148 bool pending_read_; 138 bool pending_read_;
149 139
150 // Pending buffer. 140 // Pending buffer (not pushed to device yet)
151 scoped_refptr<DecoderBufferBase> pending_buffer_; 141 scoped_refptr<DecoderBufferBase> pending_buffer_;
152 142
153 // Indicate if there is a frame being pushed to the audio device. 143 // Buffer that has been pushed to the device but not processed yet.
154 bool pending_push_; 144 scoped_ptr<CastDecoderBuffer> pushed_buffer_;
155 145
156 // The media time is retrieved at regular intervals. 146 // The media time is retrieved at regular intervals.
157 // Indicate whether time update is enabled. 147 // Indicate whether time update is enabled.
158 bool enable_time_update_; 148 bool enable_time_update_;
159 bool pending_time_update_task_; 149 bool pending_time_update_task_;
160 150
161 // Decryption keys, if available. 151 // Decryption keys, if available.
162 BrowserCdmCast* media_keys_; 152 BrowserCdmCast* media_keys_;
163 int media_keys_callback_id_; 153 int media_keys_callback_id_;
164 154
165 base::WeakPtr<AvPipelineImpl> weak_this_; 155 base::WeakPtr<AvPipelineImpl> weak_this_;
166 base::WeakPtrFactory<AvPipelineImpl> weak_factory_; 156 base::WeakPtrFactory<AvPipelineImpl> weak_factory_;
167 157
168 DISALLOW_COPY_AND_ASSIGN(AvPipelineImpl); 158 DISALLOW_COPY_AND_ASSIGN(AvPipelineImpl);
169 }; 159 };
170 160
171 } // namespace media 161 } // namespace media
172 } // namespace chromecast 162 } // namespace chromecast
173 163
174 #endif // CHROMECAST_MEDIA_CMA_BASE_AV_PIPELINE_IMPL_H_ 164 #endif // CHROMECAST_MEDIA_CMA_BASE_AV_PIPELINE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698