OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_CODEC_PLAYER_H_ | 5 #ifndef MEDIA_BASE_ANDROID_MEDIA_CODEC_PLAYER_H_ |
6 #define MEDIA_BASE_ANDROID_MEDIA_CODEC_PLAYER_H_ | 6 #define MEDIA_BASE_ANDROID_MEDIA_CODEC_PLAYER_H_ |
7 | 7 |
8 #include "base/android/scoped_java_ref.h" | 8 #include "base/android/scoped_java_ref.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "base/threading/thread.h" | 11 #include "base/threading/thread.h" |
12 #include "base/time/default_tick_clock.h" | 12 #include "base/time/default_tick_clock.h" |
13 #include "media/base/android/demuxer_android.h" | 13 #include "media/base/android/demuxer_android.h" |
| 14 #include "media/base/android/media_drm_bridge.h" |
14 #include "media/base/android/media_player_android.h" | 15 #include "media/base/android/media_player_android.h" |
15 #include "media/base/demuxer_stream.h" | 16 #include "media/base/demuxer_stream.h" |
16 #include "media/base/media_export.h" | 17 #include "media/base/media_export.h" |
17 #include "media/base/time_delta_interpolator.h" | 18 #include "media/base/time_delta_interpolator.h" |
18 #include "ui/gfx/geometry/size.h" | 19 #include "ui/gfx/geometry/size.h" |
19 #include "ui/gl/android/scoped_java_surface.h" | 20 #include "ui/gl/android/scoped_java_surface.h" |
20 | 21 |
21 // The MediaCodecPlayer class implements the media player by using Android's | 22 // The MediaCodecPlayer class implements the media player by using Android's |
22 // MediaCodec. It differs from MediaSourcePlayer in that it removes most | 23 // MediaCodec. It differs from MediaSourcePlayer in that it removes most |
23 // processing away from the UI thread: it uses a dedicated Media thread to | 24 // processing away from the UI thread: it uses a dedicated Media thread to |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 | 211 |
211 private: | 212 private: |
212 // The state machine states. | 213 // The state machine states. |
213 enum PlayerState { | 214 enum PlayerState { |
214 kStatePaused, | 215 kStatePaused, |
215 kStateWaitingForConfig, | 216 kStateWaitingForConfig, |
216 kStatePrefetching, | 217 kStatePrefetching, |
217 kStatePlaying, | 218 kStatePlaying, |
218 kStateStopping, | 219 kStateStopping, |
219 kStateWaitingForSurface, | 220 kStateWaitingForSurface, |
| 221 kStateWaitingForKey, |
| 222 kStateWaitingForCrypto, |
220 kStateWaitingForSeek, | 223 kStateWaitingForSeek, |
221 kStateError, | 224 kStateError, |
222 }; | 225 }; |
223 | 226 |
224 enum StartStatus { | 227 enum StartStatus { |
225 kStartOk = 0, | 228 kStartOk = 0, |
226 kStartBrowserSeekRequired, | 229 kStartBrowserSeekRequired, |
| 230 kStartCryptoRequired, |
227 kStartFailed, | 231 kStartFailed, |
228 }; | 232 }; |
229 | 233 |
230 // Cached values for the manager. | 234 // Cached values for the manager. |
231 struct MediaMetadata { | 235 struct MediaMetadata { |
232 base::TimeDelta duration; | 236 base::TimeDelta duration; |
233 gfx::Size video_size; | 237 gfx::Size video_size; |
234 }; | 238 }; |
235 | 239 |
236 // Information about current seek in progress. | 240 // Information about current seek in progress. |
(...skipping 12 matching lines...) Expand all Loading... |
249 // This method caches the current time and calls manager's OnTimeUpdate(). | 253 // This method caches the current time and calls manager's OnTimeUpdate(). |
250 void OnTimeUpdate(base::TimeDelta current_timestamp, | 254 void OnTimeUpdate(base::TimeDelta current_timestamp, |
251 base::TimeTicks current_time_ticks) override; | 255 base::TimeTicks current_time_ticks) override; |
252 | 256 |
253 // Callbacks from decoders | 257 // Callbacks from decoders |
254 void RequestDemuxerData(DemuxerStream::Type stream_type); | 258 void RequestDemuxerData(DemuxerStream::Type stream_type); |
255 void OnPrefetchDone(); | 259 void OnPrefetchDone(); |
256 void OnPrerollDone(); | 260 void OnPrerollDone(); |
257 void OnDecoderDrained(DemuxerStream::Type type); | 261 void OnDecoderDrained(DemuxerStream::Type type); |
258 void OnStopDone(DemuxerStream::Type type); | 262 void OnStopDone(DemuxerStream::Type type); |
| 263 void OnKeyRequired(DemuxerStream::Type type); |
259 void OnError(); | 264 void OnError(); |
260 void OnStarvation(DemuxerStream::Type stream_type); | 265 void OnStarvation(DemuxerStream::Type stream_type); |
261 void OnTimeIntervalUpdate(DemuxerStream::Type stream_type, | 266 void OnTimeIntervalUpdate(DemuxerStream::Type stream_type, |
262 base::TimeDelta now_playing, | 267 base::TimeDelta now_playing, |
263 base::TimeDelta last_buffered, | 268 base::TimeDelta last_buffered, |
264 bool postpone); | 269 bool postpone); |
265 | 270 |
266 // Callbacks from video decoder | 271 // Callbacks from video decoder |
267 void OnVideoCodecCreated(); | 272 void OnVideoCodecCreated(); |
268 void OnVideoResolutionChanged(const gfx::Size& size); | 273 void OnVideoResolutionChanged(const gfx::Size& size); |
269 | 274 |
| 275 // Callbacks from DRM |
| 276 void OnMediaCryptoReady(MediaDrmBridge::JavaObjectPtr media_crypto); |
| 277 void OnKeyAdded(); |
| 278 void OnCdmUnset(); |
| 279 |
270 // Operations called from the state machine. | 280 // Operations called from the state machine. |
271 void SetState(PlayerState new_state); | 281 void SetState(PlayerState new_state); |
272 void SetPendingStart(bool need_to_start); | 282 void SetPendingStart(bool need_to_start); |
273 bool HasPendingStart() const; | 283 bool HasPendingStart() const; |
274 void SetPendingSeek(base::TimeDelta timestamp); | 284 void SetPendingSeek(base::TimeDelta timestamp); |
275 base::TimeDelta GetPendingSeek() const; | 285 base::TimeDelta GetPendingSeek() const; |
276 bool HasVideo() const; | 286 bool HasVideo() const; |
277 bool HasAudio() const; | 287 bool HasAudio() const; |
278 void SetDemuxerConfigs(const DemuxerConfigs& configs); | 288 void SetDemuxerConfigs(const DemuxerConfigs& configs); |
279 void StartPrefetchDecoders(); | 289 void StartPrefetchDecoders(); |
(...skipping 26 matching lines...) Expand all Loading... |
306 scoped_ptr<MediaCodecAudioDecoder> audio_decoder_; | 316 scoped_ptr<MediaCodecAudioDecoder> audio_decoder_; |
307 scoped_ptr<MediaCodecVideoDecoder> video_decoder_; | 317 scoped_ptr<MediaCodecVideoDecoder> video_decoder_; |
308 | 318 |
309 // The state of the state machine. | 319 // The state of the state machine. |
310 PlayerState state_; | 320 PlayerState state_; |
311 | 321 |
312 // Notification callbacks, they call MediaPlayerManager. | 322 // Notification callbacks, they call MediaPlayerManager. |
313 base::Closure request_resources_cb_; | 323 base::Closure request_resources_cb_; |
314 TimeUpdateCallback time_update_cb_; | 324 TimeUpdateCallback time_update_cb_; |
315 base::Closure completion_cb_; | 325 base::Closure completion_cb_; |
| 326 base::Closure key_required_cb_; |
316 SeekDoneCallback seek_done_cb_; | 327 SeekDoneCallback seek_done_cb_; |
317 ErrorCallback error_cb_; | 328 ErrorCallback error_cb_; |
318 | 329 |
319 // A callback that updates metadata cache and calls the manager. | 330 // A callback that updates metadata cache and calls the manager. |
320 MetadataChangedCallback metadata_changed_cb_; | 331 MetadataChangedCallback metadata_changed_cb_; |
321 | 332 |
322 // We call the base class' AttachListener() and DetachListener() methods on UI | 333 // We call the base class' AttachListener() and DetachListener() methods on UI |
323 // thread with these callbacks. | 334 // thread with these callbacks. |
324 base::Closure attach_listener_cb_; | 335 base::Closure attach_listener_cb_; |
325 base::Closure detach_listener_cb_; | 336 base::Closure detach_listener_cb_; |
(...skipping 22 matching lines...) Expand all Loading... |
348 | 359 |
349 // Configuration data for the manager, accessed on the UI thread. | 360 // Configuration data for the manager, accessed on the UI thread. |
350 MediaMetadata metadata_cache_; | 361 MediaMetadata metadata_cache_; |
351 | 362 |
352 // Cached current time, accessed on UI thread. | 363 // Cached current time, accessed on UI thread. |
353 base::TimeDelta current_time_cache_; | 364 base::TimeDelta current_time_cache_; |
354 | 365 |
355 // For testing only. | 366 // For testing only. |
356 DecodersTimeCallback decoders_time_cb_; | 367 DecodersTimeCallback decoders_time_cb_; |
357 | 368 |
| 369 // DRM |
| 370 MediaDrmBridge* drm_bridge_; |
| 371 int cdm_registration_id_; |
| 372 MediaDrmBridge::JavaObjectPtr media_crypto_; |
| 373 |
| 374 // The flag is set when the player receives the error from decoder that the |
| 375 // decoderneeds a new encryption key. Cleared on starting the playback. |
| 376 bool key_is_required_; |
| 377 |
| 378 // The flag is set after the new encryption key is added to MediaDrm. Cleared |
| 379 // on starting the playback. |
| 380 bool key_is_added_; |
| 381 |
358 base::WeakPtr<MediaCodecPlayer> media_weak_this_; | 382 base::WeakPtr<MediaCodecPlayer> media_weak_this_; |
359 // NOTE: Weak pointers must be invalidated before all other member variables. | 383 // NOTE: Weak pointers must be invalidated before all other member variables. |
360 base::WeakPtrFactory<MediaCodecPlayer> media_weak_factory_; | 384 base::WeakPtrFactory<MediaCodecPlayer> media_weak_factory_; |
361 | 385 |
362 DISALLOW_COPY_AND_ASSIGN(MediaCodecPlayer); | 386 DISALLOW_COPY_AND_ASSIGN(MediaCodecPlayer); |
363 }; | 387 }; |
364 | 388 |
365 } // namespace media | 389 } // namespace media |
366 | 390 |
367 #endif // MEDIA_BASE_ANDROID_MEDIA_CODEC_PLAYER_H_ | 391 #endif // MEDIA_BASE_ANDROID_MEDIA_CODEC_PLAYER_H_ |
OLD | NEW |