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

Side by Side Diff: media/base/android/media_source_player.h

Issue 254473010: Refactor MSE implementation on Android to simplify the logic and improve the performance (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressing comments Created 6 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 MEDIA_BASE_ANDROID_MEDIA_SOURCE_PLAYER_H_ 5 #ifndef MEDIA_BASE_ANDROID_MEDIA_SOURCE_PLAYER_H_
6 #define MEDIA_BASE_ANDROID_MEDIA_SOURCE_PLAYER_H_ 6 #define MEDIA_BASE_ANDROID_MEDIA_SOURCE_PLAYER_H_
7 7
8 #include <jni.h> 8 #include <jni.h>
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 93
94 // Gets MediaCrypto object from |drm_bridge_|. 94 // Gets MediaCrypto object from |drm_bridge_|.
95 base::android::ScopedJavaLocalRef<jobject> GetMediaCrypto(); 95 base::android::ScopedJavaLocalRef<jobject> GetMediaCrypto();
96 96
97 // Callback to notify that MediaCrypto is ready in |drm_bridge_|. 97 // Callback to notify that MediaCrypto is ready in |drm_bridge_|.
98 void OnMediaCryptoReady(); 98 void OnMediaCryptoReady();
99 99
100 // Handle pending events if all the decoder jobs are not currently decoding. 100 // Handle pending events if all the decoder jobs are not currently decoding.
101 void ProcessPendingEvents(); 101 void ProcessPendingEvents();
102 102
103 // Helper method to clear any pending |SURFACE_CHANGE_EVENT_PENDING|
104 // and reset |video_decoder_job_| to null.
105 void ResetVideoDecoderJob();
106 void ResetAudioDecoderJob();
107
108 // Helper methods to configure the decoder jobs.
109 void ConfigureVideoDecoderJob();
110 void ConfigureAudioDecoderJob();
111
112 // Flush the decoders and clean up all the data needs to be decoded. 103 // Flush the decoders and clean up all the data needs to be decoded.
113 void ClearDecodingData(); 104 void ClearDecodingData();
114 105
115 // Called to decode more data. 106 // Called to decode more data.
116 void DecodeMoreAudio(); 107 void DecodeMoreAudio();
117 void DecodeMoreVideo(); 108 void DecodeMoreVideo();
118 109
119 // Functions check whether audio/video is present. 110 // Functions check whether audio/video is present.
120 bool HasVideo(); 111 bool HasVideo();
121 bool HasAudio(); 112 bool HasAudio();
(...skipping 26 matching lines...) Expand all
148 void ScheduleSeekEventAndStopDecoding(base::TimeDelta seek_time); 139 void ScheduleSeekEventAndStopDecoding(base::TimeDelta seek_time);
149 140
150 // Schedules a browser seek event. We must not currently be processing any 141 // Schedules a browser seek event. We must not currently be processing any
151 // seek. Note that there is possibility that browser seek of renderer demuxer 142 // seek. Note that there is possibility that browser seek of renderer demuxer
152 // may unexpectedly stall due to lack of buffered data at or after the browser 143 // may unexpectedly stall due to lack of buffered data at or after the browser
153 // seek time. 144 // seek time.
154 // TODO(wolenetz): Instead of doing hack browser seek, replay cached data 145 // TODO(wolenetz): Instead of doing hack browser seek, replay cached data
155 // since last keyframe. See http://crbug.com/304234. 146 // since last keyframe. See http://crbug.com/304234.
156 void BrowserSeekToCurrentTime(); 147 void BrowserSeekToCurrentTime();
157 148
158 // Helper function to set the volume.
159 void SetVolumeInternal();
160
161 // Helper function to determine whether a protected surface is needed for 149 // Helper function to determine whether a protected surface is needed for
162 // video playback. 150 // video playback.
163 bool IsProtectedSurfaceRequired(); 151 bool IsProtectedSurfaceRequired();
164 152
165 // Called when a MediaDecoderJob finishes prefetching data. Once all 153 // Called when a MediaDecoderJob finishes prefetching data. Once all
166 // MediaDecoderJobs have prefetched data, then this method updates 154 // MediaDecoderJobs have prefetched data, then this method updates
167 // |start_time_ticks_| and |start_presentation_timestamp_| so that video can 155 // |start_time_ticks_| and |start_presentation_timestamp_| so that video can
168 // resync with audio and starts decoding. 156 // resync with audio and starts decoding.
169 void OnPrefetchDone(); 157 void OnPrefetchDone();
170 158
171 // Sets the demuxer configs for audio or video stream. 159 // Called when the demuxer config changes.
172 void SetDemuxerConfigs(const DemuxerConfigs& configs, bool is_audio); 160 void OnDemuxerConfigsChanged();
173 161
174 // Test-only method to setup hook for the completion of the next decode cycle. 162 // Test-only method to setup hook for the completion of the next decode cycle.
175 // This callback state is cleared when it is next run. 163 // This callback state is cleared when it is next run.
176 // Prevent usage creep by only calling this from the 164 // Prevent usage creep by only calling this from the
177 // ReleaseWithOnPrefetchDoneAlreadyPosted MediaSourcePlayerTest. 165 // ReleaseWithOnPrefetchDoneAlreadyPosted MediaSourcePlayerTest.
178 void set_decode_callback_for_testing(const base::Closure& test_decode_cb) { 166 void set_decode_callback_for_testing(const base::Closure& test_decode_cb) {
179 decode_callback_for_testing_ = test_decode_cb; 167 decode_callback_for_testing_ = test_decode_cb;
180 } 168 }
181 169
182 // TODO(qinmin/wolenetz): Reorder these based on their priority from 170 // Please keep this in sync with |kPendingEventNames| in GetEventName().
183 // ProcessPendingEvents(). Release() and other routines are dependent upon
184 // priority consistency.
185 enum PendingEventFlags { 171 enum PendingEventFlags {
186 NO_EVENT_PENDING = 0, 172 NO_EVENT_PENDING = 0,
187 SEEK_EVENT_PENDING = 1 << 0, 173 PREFETCH_DONE_EVENT_PENDING = 1 << 0,
188 SURFACE_CHANGE_EVENT_PENDING = 1 << 1, 174 SEEK_EVENT_PENDING = 1 << 1,
189 CONFIG_CHANGE_EVENT_PENDING = 1 << 2, 175 VIDEO_DECODER_CREATION_EVENT_PENDING = 1 << 2,
190 PREFETCH_REQUEST_EVENT_PENDING = 1 << 3, 176 PREFETCH_REQUEST_EVENT_PENDING = 1 << 3,
191 PREFETCH_DONE_EVENT_PENDING = 1 << 4,
192 }; 177 };
193 178
194 static const char* GetEventName(PendingEventFlags event); 179 static const char* GetEventName(PendingEventFlags event);
195 bool IsEventPending(PendingEventFlags event) const; 180 bool IsEventPending(PendingEventFlags event) const;
196 void SetPendingEvent(PendingEventFlags event); 181 void SetPendingEvent(PendingEventFlags event);
197 void ClearPendingEvent(PendingEventFlags event); 182 void ClearPendingEvent(PendingEventFlags event);
198 183
184 // Called when error happens.
185 void OnDecodeError();
186
199 scoped_ptr<DemuxerAndroid> demuxer_; 187 scoped_ptr<DemuxerAndroid> demuxer_;
200 188
201 // Pending event that the player needs to do. 189 // Pending event that the player needs to do.
202 unsigned pending_event_; 190 unsigned pending_event_;
203 191
204 // Stats about the media. 192 // Stats about the media.
205 base::TimeDelta duration_; 193 base::TimeDelta duration_;
206 int width_;
207 int height_;
208 AudioCodec audio_codec_;
209 VideoCodec video_codec_;
210 int num_channels_;
211 int sampling_rate_;
212 // TODO(xhwang/qinmin): Add |video_extra_data_|.
213 std::vector<uint8> audio_extra_data_;
214 bool reached_audio_eos_;
215 bool reached_video_eos_;
216 bool playing_; 194 bool playing_;
217 bool is_audio_encrypted_;
218 bool is_video_encrypted_;
219 double volume_;
220 195
221 // base::TickClock used by |clock_|. 196 // base::TickClock used by |clock_|.
222 base::DefaultTickClock default_tick_clock_; 197 base::DefaultTickClock default_tick_clock_;
223 198
224 // Reference clock. Keeps track of current playback time. 199 // Reference clock. Keeps track of current playback time.
225 Clock clock_; 200 Clock clock_;
226 201
227 // Timestamps for providing simple A/V sync. When start decoding an audio 202 // Timestamps for providing simple A/V sync. When start decoding an audio
228 // chunk, we record its presentation timestamp and the current system time. 203 // chunk, we record its presentation timestamp and the current system time.
229 // Then we use this information to estimate when the next audio/video frame 204 // Then we use this information to estimate when the next audio/video frame
230 // should be rendered. 205 // should be rendered.
231 // TODO(qinmin): Need to fix the problem if audio/video lagged too far behind 206 // TODO(qinmin): Need to fix the problem if audio/video lagged too far behind
232 // due to network or decoding problem. 207 // due to network or decoding problem.
233 base::TimeTicks start_time_ticks_; 208 base::TimeTicks start_time_ticks_;
234 base::TimeDelta start_presentation_timestamp_; 209 base::TimeDelta start_presentation_timestamp_;
235 210
236 // The surface object currently owned by the player.
237 gfx::ScopedJavaSurface surface_;
238
239 // Track whether or not the player has received any video data since the most
240 // recent of player construction, end of last seek, or receiving and
241 // detecting a |kConfigChanged| access unit from the demuxer.
242 // If no such video data has been received, the next video data begins with
243 // an I-frame. Otherwise, we have no such guarantee.
244 bool next_video_data_is_iframe_;
245
246 // Flag that is true if doing a hack browser seek or false if doing a 211 // Flag that is true if doing a hack browser seek or false if doing a
247 // regular seek. Only valid when |SEEK_EVENT_PENDING| is pending. 212 // regular seek. Only valid when |SEEK_EVENT_PENDING| is pending.
248 // TODO(wolenetz): Instead of doing hack browser seek, replay cached data 213 // TODO(wolenetz): Instead of doing hack browser seek, replay cached data
249 // since last keyframe. See http://crbug.com/304234. 214 // since last keyframe. See http://crbug.com/304234.
250 bool doing_browser_seek_; 215 bool doing_browser_seek_;
251 216
252 // If already doing a browser seek when a regular seek request arrives, 217 // If already doing a browser seek when a regular seek request arrives,
253 // these fields remember the regular seek so OnDemuxerSeekDone() can trigger 218 // these fields remember the regular seek so OnDemuxerSeekDone() can trigger
254 // it when the browser seek is done. These are only valid when 219 // it when the browser seek is done. These are only valid when
255 // |SEEK_EVENT_PENDING| is pending. 220 // |SEEK_EVENT_PENDING| is pending.
256 bool pending_seek_; 221 bool pending_seek_;
257 base::TimeDelta pending_seek_time_; 222 base::TimeDelta pending_seek_time_;
258 223
259 // Decoder jobs. 224 // Decoder jobs.
260 scoped_ptr<AudioDecoderJob, MediaDecoderJob::Deleter> audio_decoder_job_; 225 scoped_ptr<AudioDecoderJob, MediaDecoderJob::Deleter> audio_decoder_job_;
261 scoped_ptr<VideoDecoderJob, MediaDecoderJob::Deleter> video_decoder_job_; 226 scoped_ptr<VideoDecoderJob, MediaDecoderJob::Deleter> video_decoder_job_;
262 227
263 bool reconfig_audio_decoder_;
264 bool reconfig_video_decoder_;
265
266 // Track the most recent preroll target. Decoder re-creation needs this to 228 // Track the most recent preroll target. Decoder re-creation needs this to
267 // resume any in-progress preroll. 229 // resume any in-progress preroll.
268 base::TimeDelta preroll_timestamp_; 230 base::TimeDelta preroll_timestamp_;
269 231
270 // A cancelable task that is posted when the audio decoder starts requesting 232 // A cancelable task that is posted when the audio decoder starts requesting
271 // new data. This callback runs if no data arrives before the timeout period 233 // new data. This callback runs if no data arrives before the timeout period
272 // elapses. 234 // elapses.
273 base::CancelableClosure decoder_starvation_callback_; 235 base::CancelableClosure decoder_starvation_callback_;
274 236
275 MediaDrmBridge* drm_bridge_; 237 MediaDrmBridge* drm_bridge_;
276 238
277 // No decryption key available to decrypt the encrypted buffer. In this case, 239 // No decryption key available to decrypt the encrypted buffer. In this case,
278 // the player should pause. When a new key is added (OnKeyAdded()), we should 240 // the player should pause. When a new key is added (OnKeyAdded()), we should
279 // try to start playback again. 241 // try to start playback again.
280 bool is_waiting_for_key_; 242 bool is_waiting_for_key_;
281 243
244 // Indicates whether the player is waiting for video decoder to be created.
245 bool is_waiting_for_video_decoder_;
246
282 // Test-only callback for hooking the completion of the next decode cycle. 247 // Test-only callback for hooking the completion of the next decode cycle.
283 base::Closure decode_callback_for_testing_; 248 base::Closure decode_callback_for_testing_;
284 249
285 // Whether |surface_| is currently used by the player. 250 // Whether |surface_| is currently used by the player.
286 bool is_surface_in_use_; 251 bool is_surface_in_use_;
287 252
288 // Whether there are pending data requests by the decoder.
289 bool has_pending_audio_data_request_;
290 bool has_pending_video_data_request_;
291
292 // Weak pointer passed to media decoder jobs for callbacks. 253 // Weak pointer passed to media decoder jobs for callbacks.
293 // NOTE: Weak pointers must be invalidated before all other member variables. 254 // NOTE: Weak pointers must be invalidated before all other member variables.
294 base::WeakPtrFactory<MediaSourcePlayer> weak_factory_; 255 base::WeakPtrFactory<MediaSourcePlayer> weak_factory_;
295 256
296 DISALLOW_COPY_AND_ASSIGN(MediaSourcePlayer); 257 DISALLOW_COPY_AND_ASSIGN(MediaSourcePlayer);
297 }; 258 };
298 259
299 } // namespace media 260 } // namespace media
300 261
301 #endif // MEDIA_BASE_ANDROID_MEDIA_SOURCE_PLAYER_H_ 262 #endif // MEDIA_BASE_ANDROID_MEDIA_SOURCE_PLAYER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698