| OLD | NEW |
| 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 11 matching lines...) Expand all Loading... |
| 22 #include "media/base/android/media_codec_bridge.h" | 22 #include "media/base/android/media_codec_bridge.h" |
| 23 #include "media/base/android/media_decoder_job.h" | 23 #include "media/base/android/media_decoder_job.h" |
| 24 #include "media/base/android/media_drm_bridge.h" | 24 #include "media/base/android/media_drm_bridge.h" |
| 25 #include "media/base/android/media_player_android.h" | 25 #include "media/base/android/media_player_android.h" |
| 26 #include "media/base/clock.h" | 26 #include "media/base/clock.h" |
| 27 #include "media/base/media_export.h" | 27 #include "media/base/media_export.h" |
| 28 | 28 |
| 29 namespace media { | 29 namespace media { |
| 30 | 30 |
| 31 class AudioDecoderJob; | 31 class AudioDecoderJob; |
| 32 class AudioTimestampHelper; | |
| 33 class VideoDecoderJob; | 32 class VideoDecoderJob; |
| 34 | 33 |
| 35 // This class handles media source extensions on Android. It uses Android | 34 // This class handles media source extensions on Android. It uses Android |
| 36 // MediaCodec to decode audio and video streams in two separate threads. | 35 // MediaCodec to decode audio and video streams in two separate threads. |
| 37 class MEDIA_EXPORT MediaSourcePlayer : public MediaPlayerAndroid, | 36 class MEDIA_EXPORT MediaSourcePlayer : public MediaPlayerAndroid, |
| 38 public DemuxerAndroidClient { | 37 public DemuxerAndroidClient { |
| 39 public: | 38 public: |
| 40 // Constructs a player with the given ID and demuxer. |manager| must outlive | 39 // Constructs a player with the given ID and demuxer. |manager| must outlive |
| 41 // the lifetime of this object. | 40 // the lifetime of this object. |
| 42 MediaSourcePlayer(int player_id, | 41 MediaSourcePlayer(int player_id, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 70 virtual void OnDemuxerConfigsAvailable(const DemuxerConfigs& params) OVERRIDE; | 69 virtual void OnDemuxerConfigsAvailable(const DemuxerConfigs& params) OVERRIDE; |
| 71 virtual void OnDemuxerDataAvailable(const DemuxerData& params) OVERRIDE; | 70 virtual void OnDemuxerDataAvailable(const DemuxerData& params) OVERRIDE; |
| 72 virtual void OnDemuxerSeekDone( | 71 virtual void OnDemuxerSeekDone( |
| 73 base::TimeDelta actual_browser_seek_time) OVERRIDE; | 72 base::TimeDelta actual_browser_seek_time) OVERRIDE; |
| 74 virtual void OnDemuxerDurationChanged(base::TimeDelta duration) OVERRIDE; | 73 virtual void OnDemuxerDurationChanged(base::TimeDelta duration) OVERRIDE; |
| 75 | 74 |
| 76 private: | 75 private: |
| 77 friend class MediaSourcePlayerTest; | 76 friend class MediaSourcePlayerTest; |
| 78 | 77 |
| 79 // Update the current timestamp. | 78 // Update the current timestamp. |
| 80 void UpdateTimestamps(base::TimeDelta presentation_timestamp, | 79 void UpdateTimestamps(base::TimeDelta current_presentation_timestamp, |
| 81 size_t audio_output_bytes); | 80 base::TimeDelta max_presentation_timestamp); |
| 82 | 81 |
| 83 // Helper function for starting media playback. | 82 // Helper function for starting media playback. |
| 84 void StartInternal(); | 83 void StartInternal(); |
| 85 | 84 |
| 86 // Playback is completed for one channel. | 85 // Playback is completed for one channel. |
| 87 void PlaybackCompleted(bool is_audio); | 86 void PlaybackCompleted(bool is_audio); |
| 88 | 87 |
| 89 // Called when the decoder finishes its task. | 88 // Called when the decoder finishes its task. |
| 90 void MediaDecoderCallback( | 89 void MediaDecoderCallback( |
| 91 bool is_audio, MediaCodecStatus status, | 90 bool is_audio, MediaCodecStatus status, |
| 92 base::TimeDelta presentation_timestamp, | 91 base::TimeDelta current_presentation_timestamp, |
| 93 size_t audio_output_bytes); | 92 base::TimeDelta max_presentation_timestamp); |
| 94 | 93 |
| 95 // Gets MediaCrypto object from |drm_bridge_|. | 94 // Gets MediaCrypto object from |drm_bridge_|. |
| 96 base::android::ScopedJavaLocalRef<jobject> GetMediaCrypto(); | 95 base::android::ScopedJavaLocalRef<jobject> GetMediaCrypto(); |
| 97 | 96 |
| 98 // Callback to notify that MediaCrypto is ready in |drm_bridge_|. | 97 // Callback to notify that MediaCrypto is ready in |drm_bridge_|. |
| 99 void OnMediaCryptoReady(); | 98 void OnMediaCryptoReady(); |
| 100 | 99 |
| 101 // 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. |
| 102 void ProcessPendingEvents(); | 101 void ProcessPendingEvents(); |
| 103 | 102 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 126 bool AudioFinished(); | 125 bool AudioFinished(); |
| 127 bool VideoFinished(); | 126 bool VideoFinished(); |
| 128 | 127 |
| 129 // Determine seekability based on duration. | 128 // Determine seekability based on duration. |
| 130 bool Seekable(); | 129 bool Seekable(); |
| 131 | 130 |
| 132 // Called when the |decoder_starvation_callback_| times out. | 131 // Called when the |decoder_starvation_callback_| times out. |
| 133 void OnDecoderStarved(); | 132 void OnDecoderStarved(); |
| 134 | 133 |
| 135 // Starts the |decoder_starvation_callback_| task with the timeout value. | 134 // Starts the |decoder_starvation_callback_| task with the timeout value. |
| 136 // |presentation_timestamp| - The presentation timestamp used for starvation | 135 // |current_presentation_timestamp| - The presentation timestamp used for |
| 137 // timeout computations. It represents the timestamp of the last piece of | 136 // starvation timeout computations. It represents the current timestamp of |
| 138 // decoded data. | 137 // rendered data. |
| 139 void StartStarvationCallback(base::TimeDelta presentation_timestamp); | 138 // |max_presentation_timestamp| - The presentation timestamp if all the |
| 139 // decoded data are rendered. |
| 140 void StartStarvationCallback( |
| 141 base::TimeDelta current_presentation_timestamp, |
| 142 base::TimeDelta max_presentation_timestamp); |
| 140 | 143 |
| 141 // Schedules a seek event in |pending_events_| and calls StopDecode() on all | 144 // Schedules a seek event in |pending_events_| and calls StopDecode() on all |
| 142 // the MediaDecoderJobs. Sets clock to |seek_time|, and resets | 145 // the MediaDecoderJobs. Sets clock to |seek_time|, and resets |
| 143 // |pending_seek_|. There must not already be a seek event in | 146 // |pending_seek_|. There must not already be a seek event in |
| 144 // |pending_events_|. | 147 // |pending_events_|. |
| 145 void ScheduleSeekEventAndStopDecoding(base::TimeDelta seek_time); | 148 void ScheduleSeekEventAndStopDecoding(base::TimeDelta seek_time); |
| 146 | 149 |
| 147 // Schedules a browser seek event. We must not currently be processing any | 150 // Schedules a browser seek event. We must not currently be processing any |
| 148 // seek. Note that there is possibility that browser seek of renderer demuxer | 151 // seek. Note that there is possibility that browser seek of renderer demuxer |
| 149 // may unexpectedly stall due to lack of buffered data at or after the browser | 152 // may unexpectedly stall due to lack of buffered data at or after the browser |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 | 262 |
| 260 // Track the most recent preroll target. Decoder re-creation needs this to | 263 // Track the most recent preroll target. Decoder re-creation needs this to |
| 261 // resume any in-progress preroll. | 264 // resume any in-progress preroll. |
| 262 base::TimeDelta preroll_timestamp_; | 265 base::TimeDelta preroll_timestamp_; |
| 263 | 266 |
| 264 // A cancelable task that is posted when the audio decoder starts requesting | 267 // A cancelable task that is posted when the audio decoder starts requesting |
| 265 // new data. This callback runs if no data arrives before the timeout period | 268 // new data. This callback runs if no data arrives before the timeout period |
| 266 // elapses. | 269 // elapses. |
| 267 base::CancelableClosure decoder_starvation_callback_; | 270 base::CancelableClosure decoder_starvation_callback_; |
| 268 | 271 |
| 269 // Object to calculate the current audio timestamp for A/V sync. | |
| 270 scoped_ptr<AudioTimestampHelper> audio_timestamp_helper_; | |
| 271 | |
| 272 MediaDrmBridge* drm_bridge_; | 272 MediaDrmBridge* drm_bridge_; |
| 273 | 273 |
| 274 // No decryption key available to decrypt the encrypted buffer. In this case, | 274 // No decryption key available to decrypt the encrypted buffer. In this case, |
| 275 // the player should pause. When a new key is added (OnKeyAdded()), we should | 275 // the player should pause. When a new key is added (OnKeyAdded()), we should |
| 276 // try to start playback again. | 276 // try to start playback again. |
| 277 bool is_waiting_for_key_; | 277 bool is_waiting_for_key_; |
| 278 | 278 |
| 279 // Test-only callback for hooking the completion of the next decode cycle. | 279 // Test-only callback for hooking the completion of the next decode cycle. |
| 280 base::Closure decode_callback_for_testing_; | 280 base::Closure decode_callback_for_testing_; |
| 281 | 281 |
| 282 // Whether |surface_| is currently used by the player. | 282 // Whether |surface_| is currently used by the player. |
| 283 bool is_surface_in_use_; | 283 bool is_surface_in_use_; |
| 284 | 284 |
| 285 // Whether there are pending data requests by the decoder. | 285 // Whether there are pending data requests by the decoder. |
| 286 bool has_pending_audio_data_request_; | 286 bool has_pending_audio_data_request_; |
| 287 bool has_pending_video_data_request_; | 287 bool has_pending_video_data_request_; |
| 288 | 288 |
| 289 // Weak pointer passed to media decoder jobs for callbacks. | 289 // Weak pointer passed to media decoder jobs for callbacks. |
| 290 // NOTE: Weak pointers must be invalidated before all other member variables. | 290 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 291 base::WeakPtrFactory<MediaSourcePlayer> weak_factory_; | 291 base::WeakPtrFactory<MediaSourcePlayer> weak_factory_; |
| 292 | 292 |
| 293 DISALLOW_COPY_AND_ASSIGN(MediaSourcePlayer); | 293 DISALLOW_COPY_AND_ASSIGN(MediaSourcePlayer); |
| 294 }; | 294 }; |
| 295 | 295 |
| 296 } // namespace media | 296 } // namespace media |
| 297 | 297 |
| 298 #endif // MEDIA_BASE_ANDROID_MEDIA_SOURCE_PLAYER_H_ | 298 #endif // MEDIA_BASE_ANDROID_MEDIA_SOURCE_PLAYER_H_ |
| OLD | NEW |