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; |
32 class VideoDecoderJob; | 33 class VideoDecoderJob; |
33 | 34 |
34 // This class handles media source extensions on Android. It uses Android | 35 // This class handles media source extensions on Android. It uses Android |
35 // MediaCodec to decode audio and video streams in two separate threads. | 36 // MediaCodec to decode audio and video streams in two separate threads. |
36 class MEDIA_EXPORT MediaSourcePlayer : public MediaPlayerAndroid, | 37 class MEDIA_EXPORT MediaSourcePlayer : public MediaPlayerAndroid, |
37 public DemuxerAndroidClient { | 38 public DemuxerAndroidClient { |
38 public: | 39 public: |
39 // Constructs a player with the given ID and demuxer. |manager| must outlive | 40 // Constructs a player with the given ID and demuxer. |manager| must outlive |
40 // the lifetime of this object. | 41 // the lifetime of this object. |
41 MediaSourcePlayer(int player_id, | 42 MediaSourcePlayer(int player_id, |
(...skipping 27 matching lines...) Expand all Loading... |
69 virtual void OnDemuxerConfigsAvailable(const DemuxerConfigs& params) OVERRIDE; | 70 virtual void OnDemuxerConfigsAvailable(const DemuxerConfigs& params) OVERRIDE; |
70 virtual void OnDemuxerDataAvailable(const DemuxerData& params) OVERRIDE; | 71 virtual void OnDemuxerDataAvailable(const DemuxerData& params) OVERRIDE; |
71 virtual void OnDemuxerSeekDone( | 72 virtual void OnDemuxerSeekDone( |
72 base::TimeDelta actual_browser_seek_time) OVERRIDE; | 73 base::TimeDelta actual_browser_seek_time) OVERRIDE; |
73 virtual void OnDemuxerDurationChanged(base::TimeDelta duration) OVERRIDE; | 74 virtual void OnDemuxerDurationChanged(base::TimeDelta duration) OVERRIDE; |
74 | 75 |
75 private: | 76 private: |
76 friend class MediaSourcePlayerTest; | 77 friend class MediaSourcePlayerTest; |
77 | 78 |
78 // Update the current timestamp. | 79 // Update the current timestamp. |
79 void UpdateTimestamps(base::TimeDelta current_presentation_timestamp, | 80 void UpdateTimestamps(base::TimeDelta presentation_timestamp, |
80 base::TimeDelta max_presentation_timestamp); | 81 size_t audio_output_bytes); |
81 | 82 |
82 // Helper function for starting media playback. | 83 // Helper function for starting media playback. |
83 void StartInternal(); | 84 void StartInternal(); |
84 | 85 |
85 // Playback is completed for one channel. | 86 // Playback is completed for one channel. |
86 void PlaybackCompleted(bool is_audio); | 87 void PlaybackCompleted(bool is_audio); |
87 | 88 |
88 // Called when the decoder finishes its task. | 89 // Called when the decoder finishes its task. |
89 void MediaDecoderCallback( | 90 void MediaDecoderCallback( |
90 bool is_audio, MediaCodecStatus status, | 91 bool is_audio, MediaCodecStatus status, |
91 base::TimeDelta current_presentation_timestamp, | 92 base::TimeDelta presentation_timestamp, |
92 base::TimeDelta max_presentation_timestamp); | 93 size_t audio_output_bytes); |
93 | 94 |
94 // Gets MediaCrypto object from |drm_bridge_|. | 95 // Gets MediaCrypto object from |drm_bridge_|. |
95 base::android::ScopedJavaLocalRef<jobject> GetMediaCrypto(); | 96 base::android::ScopedJavaLocalRef<jobject> GetMediaCrypto(); |
96 | 97 |
97 // Callback to notify that MediaCrypto is ready in |drm_bridge_|. | 98 // Callback to notify that MediaCrypto is ready in |drm_bridge_|. |
98 void OnMediaCryptoReady(); | 99 void OnMediaCryptoReady(); |
99 | 100 |
100 // Handle pending events if all the decoder jobs are not currently decoding. | 101 // Handle pending events if all the decoder jobs are not currently decoding. |
101 void ProcessPendingEvents(); | 102 void ProcessPendingEvents(); |
102 | 103 |
(...skipping 22 matching lines...) Expand all Loading... |
125 bool AudioFinished(); | 126 bool AudioFinished(); |
126 bool VideoFinished(); | 127 bool VideoFinished(); |
127 | 128 |
128 // Determine seekability based on duration. | 129 // Determine seekability based on duration. |
129 bool Seekable(); | 130 bool Seekable(); |
130 | 131 |
131 // Called when the |decoder_starvation_callback_| times out. | 132 // Called when the |decoder_starvation_callback_| times out. |
132 void OnDecoderStarved(); | 133 void OnDecoderStarved(); |
133 | 134 |
134 // Starts the |decoder_starvation_callback_| task with the timeout value. | 135 // Starts the |decoder_starvation_callback_| task with the timeout value. |
135 // |current_presentation_timestamp| - The presentation timestamp used for | 136 // |presentation_timestamp| - The presentation timestamp used for starvation |
136 // starvation timeout computations. It represents the current timestamp of | 137 // timeout computations. It represents the timestamp of the last piece of |
137 // rendered data. | 138 // decoded data. |
138 // |max_presentation_timestamp| - The presentation timestamp if all the | 139 void StartStarvationCallback(base::TimeDelta presentation_timestamp); |
139 // decoded data are rendered. | |
140 void StartStarvationCallback( | |
141 base::TimeDelta current_presentation_timestamp, | |
142 base::TimeDelta max_presentation_timestamp); | |
143 | 140 |
144 // Schedules a seek event in |pending_events_| and calls StopDecode() on all | 141 // Schedules a seek event in |pending_events_| and calls StopDecode() on all |
145 // the MediaDecoderJobs. Sets clock to |seek_time|, and resets | 142 // the MediaDecoderJobs. Sets clock to |seek_time|, and resets |
146 // |pending_seek_|. There must not already be a seek event in | 143 // |pending_seek_|. There must not already be a seek event in |
147 // |pending_events_|. | 144 // |pending_events_|. |
148 void ScheduleSeekEventAndStopDecoding(base::TimeDelta seek_time); | 145 void ScheduleSeekEventAndStopDecoding(base::TimeDelta seek_time); |
149 | 146 |
150 // Schedules a browser seek event. We must not currently be processing any | 147 // 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 | 148 // 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 | 149 // 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... |
262 | 259 |
263 // Track the most recent preroll target. Decoder re-creation needs this to | 260 // Track the most recent preroll target. Decoder re-creation needs this to |
264 // resume any in-progress preroll. | 261 // resume any in-progress preroll. |
265 base::TimeDelta preroll_timestamp_; | 262 base::TimeDelta preroll_timestamp_; |
266 | 263 |
267 // A cancelable task that is posted when the audio decoder starts requesting | 264 // A cancelable task that is posted when the audio decoder starts requesting |
268 // new data. This callback runs if no data arrives before the timeout period | 265 // new data. This callback runs if no data arrives before the timeout period |
269 // elapses. | 266 // elapses. |
270 base::CancelableClosure decoder_starvation_callback_; | 267 base::CancelableClosure decoder_starvation_callback_; |
271 | 268 |
| 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 |