| 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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 private: | 229 private: |
| 229 // The state machine states. | 230 // The state machine states. |
| 230 enum PlayerState { | 231 enum PlayerState { |
| 231 kStatePaused, | 232 kStatePaused, |
| 232 kStateWaitingForConfig, | 233 kStateWaitingForConfig, |
| 233 kStateWaitingForPermission, | 234 kStateWaitingForPermission, |
| 234 kStatePrefetching, | 235 kStatePrefetching, |
| 235 kStatePlaying, | 236 kStatePlaying, |
| 236 kStateStopping, | 237 kStateStopping, |
| 237 kStateWaitingForSurface, | 238 kStateWaitingForSurface, |
| 239 kStateWaitingForKey, |
| 240 kStateWaitingForMediaCrypto, |
| 238 kStateWaitingForSeek, | 241 kStateWaitingForSeek, |
| 239 kStateError, | 242 kStateError, |
| 240 }; | 243 }; |
| 241 | 244 |
| 242 enum StartStatus { | 245 enum StartStatus { |
| 243 kStartOk = 0, | 246 kStartOk = 0, |
| 244 kStartBrowserSeekRequired, | 247 kStartBrowserSeekRequired, |
| 248 kStartCryptoRequired, |
| 245 kStartFailed, | 249 kStartFailed, |
| 246 }; | 250 }; |
| 247 | 251 |
| 248 // Cached values for the manager. | 252 // Cached values for the manager. |
| 249 struct MediaMetadata { | 253 struct MediaMetadata { |
| 250 base::TimeDelta duration; | 254 base::TimeDelta duration; |
| 251 gfx::Size video_size; | 255 gfx::Size video_size; |
| 252 }; | 256 }; |
| 253 | 257 |
| 254 // Information about current seek in progress. | 258 // Information about current seek in progress. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 276 | 280 |
| 277 // Callback from manager | 281 // Callback from manager |
| 278 void OnPermissionDecided(bool granted); | 282 void OnPermissionDecided(bool granted); |
| 279 | 283 |
| 280 // Callbacks from decoders | 284 // Callbacks from decoders |
| 281 void RequestDemuxerData(DemuxerStream::Type stream_type); | 285 void RequestDemuxerData(DemuxerStream::Type stream_type); |
| 282 void OnPrefetchDone(); | 286 void OnPrefetchDone(); |
| 283 void OnPrerollDone(); | 287 void OnPrerollDone(); |
| 284 void OnDecoderDrained(DemuxerStream::Type type); | 288 void OnDecoderDrained(DemuxerStream::Type type); |
| 285 void OnStopDone(DemuxerStream::Type type); | 289 void OnStopDone(DemuxerStream::Type type); |
| 290 void OnMissingKeyReported(DemuxerStream::Type type); |
| 286 void OnError(); | 291 void OnError(); |
| 287 void OnStarvation(DemuxerStream::Type stream_type); | 292 void OnStarvation(DemuxerStream::Type stream_type); |
| 288 void OnTimeIntervalUpdate(DemuxerStream::Type stream_type, | 293 void OnTimeIntervalUpdate(DemuxerStream::Type stream_type, |
| 289 base::TimeDelta now_playing, | 294 base::TimeDelta now_playing, |
| 290 base::TimeDelta last_buffered, | 295 base::TimeDelta last_buffered, |
| 291 bool postpone); | 296 bool postpone); |
| 292 | 297 |
| 293 // Callbacks from video decoder | 298 // Callbacks from video decoder |
| 294 void OnVideoCodecCreated(); | 299 void OnVideoCodecCreated(); |
| 295 void OnVideoResolutionChanged(const gfx::Size& size); | 300 void OnVideoResolutionChanged(const gfx::Size& size); |
| 296 | 301 |
| 302 // Callbacks from CDM |
| 303 void OnMediaCryptoReady(MediaDrmBridge::JavaObjectPtr media_crypto, |
| 304 bool needs_protected_surface); |
| 305 void OnKeyAdded(); |
| 306 void OnCdmUnset(); |
| 307 |
| 297 // Operations called from the state machine. | 308 // Operations called from the state machine. |
| 298 void SetState(PlayerState new_state); | 309 void SetState(PlayerState new_state); |
| 299 void SetPendingStart(bool need_to_start); | 310 void SetPendingStart(bool need_to_start); |
| 300 bool HasPendingStart() const; | 311 bool HasPendingStart() const; |
| 301 void SetPendingSeek(base::TimeDelta timestamp); | 312 void SetPendingSeek(base::TimeDelta timestamp); |
| 302 base::TimeDelta GetPendingSeek() const; | 313 base::TimeDelta GetPendingSeek() const; |
| 303 bool HasVideo() const; | 314 bool HasVideo() const; |
| 304 bool HasAudio() const; | 315 bool HasAudio() const; |
| 305 void SetDemuxerConfigs(const DemuxerConfigs& configs); | 316 void SetDemuxerConfigs(const DemuxerConfigs& configs); |
| 306 void RequestPlayPermission(); | 317 void RequestPlayPermission(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 334 scoped_ptr<MediaCodecAudioDecoder> audio_decoder_; | 345 scoped_ptr<MediaCodecAudioDecoder> audio_decoder_; |
| 335 scoped_ptr<MediaCodecVideoDecoder> video_decoder_; | 346 scoped_ptr<MediaCodecVideoDecoder> video_decoder_; |
| 336 | 347 |
| 337 // The state of the state machine. | 348 // The state of the state machine. |
| 338 PlayerState state_; | 349 PlayerState state_; |
| 339 | 350 |
| 340 // Notification callbacks, they call MediaPlayerManager. | 351 // Notification callbacks, they call MediaPlayerManager. |
| 341 base::Closure request_resources_cb_; | 352 base::Closure request_resources_cb_; |
| 342 TimeUpdateCallback time_update_cb_; | 353 TimeUpdateCallback time_update_cb_; |
| 343 base::Closure completion_cb_; | 354 base::Closure completion_cb_; |
| 355 base::Closure waiting_for_decryption_key_cb_; |
| 344 SeekDoneCallback seek_done_cb_; | 356 SeekDoneCallback seek_done_cb_; |
| 345 ErrorCallback error_cb_; | 357 ErrorCallback error_cb_; |
| 346 | 358 |
| 347 // A callback that updates metadata cache and calls the manager. | 359 // A callback that updates metadata cache and calls the manager. |
| 348 MetadataChangedCallback metadata_changed_cb_; | 360 MetadataChangedCallback metadata_changed_cb_; |
| 349 | 361 |
| 350 // We call the base class' AttachListener() and DetachListener() methods on UI | 362 // We call the base class' AttachListener() and DetachListener() methods on UI |
| 351 // thread with these callbacks. | 363 // thread with these callbacks. |
| 352 base::Closure attach_listener_cb_; | 364 base::Closure attach_listener_cb_; |
| 353 base::Closure detach_listener_cb_; | 365 base::Closure detach_listener_cb_; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 376 | 388 |
| 377 // Configuration data for the manager, accessed on the UI thread. | 389 // Configuration data for the manager, accessed on the UI thread. |
| 378 MediaMetadata metadata_cache_; | 390 MediaMetadata metadata_cache_; |
| 379 | 391 |
| 380 // Cached current time, accessed on UI thread. | 392 // Cached current time, accessed on UI thread. |
| 381 base::TimeDelta current_time_cache_; | 393 base::TimeDelta current_time_cache_; |
| 382 | 394 |
| 383 // For testing only. | 395 // For testing only. |
| 384 DecodersTimeCallback decoders_time_cb_; | 396 DecodersTimeCallback decoders_time_cb_; |
| 385 | 397 |
| 398 // DRM |
| 399 MediaDrmBridge::JavaObjectPtr media_crypto_; |
| 400 |
| 401 MediaDrmBridge* drm_bridge_; |
| 402 int cdm_registration_id_; |
| 403 |
| 404 // The flag is set when the player receives the error from decoder that the |
| 405 // decoder needs a new decryption key. Cleared on starting the playback. |
| 406 bool key_is_required_; |
| 407 |
| 408 // The flag is set after the new encryption key is added to MediaDrm. Cleared |
| 409 // on starting the playback. |
| 410 bool key_is_added_; |
| 411 |
| 386 base::WeakPtr<MediaCodecPlayer> media_weak_this_; | 412 base::WeakPtr<MediaCodecPlayer> media_weak_this_; |
| 387 // NOTE: Weak pointers must be invalidated before all other member variables. | 413 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 388 base::WeakPtrFactory<MediaCodecPlayer> media_weak_factory_; | 414 base::WeakPtrFactory<MediaCodecPlayer> media_weak_factory_; |
| 389 | 415 |
| 390 DISALLOW_COPY_AND_ASSIGN(MediaCodecPlayer); | 416 DISALLOW_COPY_AND_ASSIGN(MediaCodecPlayer); |
| 391 }; | 417 }; |
| 392 | 418 |
| 393 } // namespace media | 419 } // namespace media |
| 394 | 420 |
| 395 #endif // MEDIA_BASE_ANDROID_MEDIA_CODEC_PLAYER_H_ | 421 #endif // MEDIA_BASE_ANDROID_MEDIA_CODEC_PLAYER_H_ |
| OLD | NEW |