| 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 <memory> | 
|  | 9 | 
| 8 #include "base/android/scoped_java_ref.h" | 10 #include "base/android/scoped_java_ref.h" | 
| 9 #include "base/macros.h" | 11 #include "base/macros.h" | 
| 10 #include "base/memory/scoped_ptr.h" |  | 
| 11 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" | 
| 12 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" | 
| 13 #include "base/time/default_tick_clock.h" | 14 #include "base/time/default_tick_clock.h" | 
| 14 #include "media/base/android/demuxer_android.h" | 15 #include "media/base/android/demuxer_android.h" | 
| 15 #include "media/base/android/media_drm_bridge.h" | 16 #include "media/base/android/media_drm_bridge.h" | 
| 16 #include "media/base/android/media_player_android.h" | 17 #include "media/base/android/media_player_android.h" | 
| 17 #include "media/base/android/media_statistics.h" | 18 #include "media/base/android/media_statistics.h" | 
| 18 #include "media/base/demuxer_stream.h" | 19 #include "media/base/demuxer_stream.h" | 
| 19 #include "media/base/media_export.h" | 20 #include "media/base/media_export.h" | 
| 20 #include "media/base/time_delta_interpolator.h" | 21 #include "media/base/time_delta_interpolator.h" | 
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 183 | 184 | 
| 184   // For testing only. | 185   // For testing only. | 
| 185   typedef base::Callback<void(DemuxerStream::Type)> CodecCreatedCallback; | 186   typedef base::Callback<void(DemuxerStream::Type)> CodecCreatedCallback; | 
| 186 | 187 | 
| 187   // Constructs a player with the given ID and demuxer. |manager| must outlive | 188   // Constructs a player with the given ID and demuxer. |manager| must outlive | 
| 188   // the lifetime of this object. | 189   // the lifetime of this object. | 
| 189   MediaCodecPlayer( | 190   MediaCodecPlayer( | 
| 190       int player_id, | 191       int player_id, | 
| 191       base::WeakPtr<MediaPlayerManager> manager, | 192       base::WeakPtr<MediaPlayerManager> manager, | 
| 192       const OnDecoderResourcesReleasedCB& on_decoder_resources_released_cb, | 193       const OnDecoderResourcesReleasedCB& on_decoder_resources_released_cb, | 
| 193       scoped_ptr<DemuxerAndroid> demuxer, | 194       std::unique_ptr<DemuxerAndroid> demuxer, | 
| 194       const GURL& frame_url, | 195       const GURL& frame_url, | 
| 195       int media_session_id); | 196       int media_session_id); | 
| 196   ~MediaCodecPlayer() override; | 197   ~MediaCodecPlayer() override; | 
| 197 | 198 | 
| 198   // A helper method that performs the media thread part of initialization. | 199   // A helper method that performs the media thread part of initialization. | 
| 199   void Initialize(); | 200   void Initialize(); | 
| 200 | 201 | 
| 201   // MediaPlayerAndroid implementation. | 202   // MediaPlayerAndroid implementation. | 
| 202   void DeleteOnCorrectThread() override; | 203   void DeleteOnCorrectThread() override; | 
| 203   void SetVideoSurface(gfx::ScopedJavaSurface surface) override; | 204   void SetVideoSurface(gfx::ScopedJavaSurface surface) override; | 
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 337   base::TimeDelta GetInterpolatedTime(); | 338   base::TimeDelta GetInterpolatedTime(); | 
| 338 | 339 | 
| 339   static const char* AsString(PlayerState state); | 340   static const char* AsString(PlayerState state); | 
| 340 | 341 | 
| 341   // Data. | 342   // Data. | 
| 342 | 343 | 
| 343   // Object for posting tasks on UI thread. | 344   // Object for posting tasks on UI thread. | 
| 344   scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; | 345   scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; | 
| 345 | 346 | 
| 346   // Major components: demuxer, audio and video decoders. | 347   // Major components: demuxer, audio and video decoders. | 
| 347   scoped_ptr<DemuxerAndroid> demuxer_; | 348   std::unique_ptr<DemuxerAndroid> demuxer_; | 
| 348   scoped_ptr<AudioMediaCodecDecoder> audio_decoder_; | 349   std::unique_ptr<AudioMediaCodecDecoder> audio_decoder_; | 
| 349   scoped_ptr<VideoMediaCodecDecoder> video_decoder_; | 350   std::unique_ptr<VideoMediaCodecDecoder> video_decoder_; | 
| 350 | 351 | 
| 351   // The state of the state machine. | 352   // The state of the state machine. | 
| 352   PlayerState state_; | 353   PlayerState state_; | 
| 353 | 354 | 
| 354   // Notification callbacks, they call MediaPlayerManager. | 355   // Notification callbacks, they call MediaPlayerManager. | 
| 355   TimeUpdateCallback time_update_cb_; | 356   TimeUpdateCallback time_update_cb_; | 
| 356   base::Closure completion_cb_; | 357   base::Closure completion_cb_; | 
| 357   base::Closure waiting_for_decryption_key_cb_; | 358   base::Closure waiting_for_decryption_key_cb_; | 
| 358   SeekDoneCallback seek_done_cb_; | 359   SeekDoneCallback seek_done_cb_; | 
| 359   ErrorCallback error_cb_; | 360   ErrorCallback error_cb_; | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
| 379   // Tracks the most recent media time update and provides interpolated values | 380   // Tracks the most recent media time update and provides interpolated values | 
| 380   // as playback progresses. | 381   // as playback progresses. | 
| 381   TimeDeltaInterpolator interpolator_; | 382   TimeDeltaInterpolator interpolator_; | 
| 382 | 383 | 
| 383   // Pending data to be picked up by the upcoming state. | 384   // Pending data to be picked up by the upcoming state. | 
| 384   gfx::ScopedJavaSurface pending_surface_; | 385   gfx::ScopedJavaSurface pending_surface_; | 
| 385   bool pending_start_; | 386   bool pending_start_; | 
| 386   base::TimeDelta pending_seek_; | 387   base::TimeDelta pending_seek_; | 
| 387 | 388 | 
| 388   // Data associated with a seek in progress. | 389   // Data associated with a seek in progress. | 
| 389   scoped_ptr<SeekInfo> seek_info_; | 390   std::unique_ptr<SeekInfo> seek_info_; | 
| 390 | 391 | 
| 391   // Configuration data for the manager, accessed on the UI thread. | 392   // Configuration data for the manager, accessed on the UI thread. | 
| 392   MediaMetadata metadata_cache_; | 393   MediaMetadata metadata_cache_; | 
| 393 | 394 | 
| 394   // Cached current time, accessed on UI thread. | 395   // Cached current time, accessed on UI thread. | 
| 395   base::TimeDelta current_time_cache_; | 396   base::TimeDelta current_time_cache_; | 
| 396 | 397 | 
| 397   // For testing only. | 398   // For testing only. | 
| 398   DecodersTimeCallback decoders_time_cb_; | 399   DecodersTimeCallback decoders_time_cb_; | 
| 399 | 400 | 
| 400   // Holds a ref-count to the CDM to keep |media_crypto_| valid. | 401   // Holds a ref-count to the CDM to keep |media_crypto_| valid. | 
| 401   scoped_refptr<MediaKeys> cdm_; | 402   scoped_refptr<MediaKeys> cdm_; | 
| 402 | 403 | 
| 403   MediaDrmBridge::JavaObjectPtr media_crypto_; | 404   MediaDrmBridge::JavaObjectPtr media_crypto_; | 
| 404 | 405 | 
| 405   int cdm_registration_id_; | 406   int cdm_registration_id_; | 
| 406 | 407 | 
| 407   // The flag is set when the player receives the error from decoder that the | 408   // The flag is set when the player receives the error from decoder that the | 
| 408   // decoder needs a new decryption key. Cleared on starting the playback. | 409   // decoder needs a new decryption key. Cleared on starting the playback. | 
| 409   bool key_is_required_; | 410   bool key_is_required_; | 
| 410 | 411 | 
| 411   // The flag is set after the new encryption key is added to MediaDrm. Cleared | 412   // The flag is set after the new encryption key is added to MediaDrm. Cleared | 
| 412   // on starting the playback. | 413   // on starting the playback. | 
| 413   bool key_is_added_; | 414   bool key_is_added_; | 
| 414 | 415 | 
| 415   // Gathers and reports playback quality statistics to UMA. | 416   // Gathers and reports playback quality statistics to UMA. | 
| 416   // Use pointer to enable replacement of this object for tests. | 417   // Use pointer to enable replacement of this object for tests. | 
| 417   scoped_ptr<MediaStatistics> media_stat_; | 418   std::unique_ptr<MediaStatistics> media_stat_; | 
| 418 | 419 | 
| 419   base::WeakPtr<MediaCodecPlayer> media_weak_this_; | 420   base::WeakPtr<MediaCodecPlayer> media_weak_this_; | 
| 420   // NOTE: Weak pointers must be invalidated before all other member variables. | 421   // NOTE: Weak pointers must be invalidated before all other member variables. | 
| 421   base::WeakPtrFactory<MediaCodecPlayer> media_weak_factory_; | 422   base::WeakPtrFactory<MediaCodecPlayer> media_weak_factory_; | 
| 422 | 423 | 
| 423   DISALLOW_COPY_AND_ASSIGN(MediaCodecPlayer); | 424   DISALLOW_COPY_AND_ASSIGN(MediaCodecPlayer); | 
| 424 }; | 425 }; | 
| 425 | 426 | 
| 426 }  // namespace media | 427 }  // namespace media | 
| 427 | 428 | 
| 428 #endif  // MEDIA_BASE_ANDROID_MEDIA_CODEC_PLAYER_H_ | 429 #endif  // MEDIA_BASE_ANDROID_MEDIA_CODEC_PLAYER_H_ | 
| OLD | NEW | 
|---|