| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 | 93 |
| 94 // Gets MediaCrypto object from |drm_bridge_|. | 94 // Gets MediaCrypto object from |drm_bridge_|. |
| 95 base::android::ScopedJavaLocalRef<jobject> GetMediaCrypto(); | 95 base::android::ScopedJavaLocalRef<jobject> GetMediaCrypto(); |
| 96 | 96 |
| 97 // Callback to notify that MediaCrypto is ready in |drm_bridge_|. | 97 // Callback to notify that MediaCrypto is ready in |drm_bridge_|. |
| 98 void OnMediaCryptoReady(); | 98 void OnMediaCryptoReady(); |
| 99 | 99 |
| 100 // 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. |
| 101 void ProcessPendingEvents(); | 101 void ProcessPendingEvents(); |
| 102 | 102 |
| 103 // Helper method to clear any pending |SURFACE_CHANGE_EVENT_PENDING| | |
| 104 // and reset |video_decoder_job_| to null. | |
| 105 void ResetVideoDecoderJob(); | |
| 106 void ResetAudioDecoderJob(); | |
| 107 | |
| 108 // Helper methods to configure the decoder jobs. | |
| 109 void ConfigureVideoDecoderJob(); | |
| 110 void ConfigureAudioDecoderJob(); | |
| 111 | |
| 112 // Flush the decoders and clean up all the data needs to be decoded. | 103 // Flush the decoders and clean up all the data needs to be decoded. |
| 113 void ClearDecodingData(); | 104 void ClearDecodingData(); |
| 114 | 105 |
| 115 // Called to decode more data. | 106 // Called to decode more data. |
| 116 void DecodeMoreAudio(); | 107 void DecodeMoreAudio(); |
| 117 void DecodeMoreVideo(); | 108 void DecodeMoreVideo(); |
| 118 | 109 |
| 119 // Functions check whether audio/video is present. | 110 // Functions check whether audio/video is present. |
| 120 bool HasVideo(); | 111 bool HasVideo(); |
| 121 bool HasAudio(); | 112 bool HasAudio(); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 148 void ScheduleSeekEventAndStopDecoding(base::TimeDelta seek_time); | 139 void ScheduleSeekEventAndStopDecoding(base::TimeDelta seek_time); |
| 149 | 140 |
| 150 // Schedules a browser seek event. We must not currently be processing any | 141 // 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 | 142 // 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 | 143 // may unexpectedly stall due to lack of buffered data at or after the browser |
| 153 // seek time. | 144 // seek time. |
| 154 // TODO(wolenetz): Instead of doing hack browser seek, replay cached data | 145 // TODO(wolenetz): Instead of doing hack browser seek, replay cached data |
| 155 // since last keyframe. See http://crbug.com/304234. | 146 // since last keyframe. See http://crbug.com/304234. |
| 156 void BrowserSeekToCurrentTime(); | 147 void BrowserSeekToCurrentTime(); |
| 157 | 148 |
| 158 // Helper function to set the volume. | |
| 159 void SetVolumeInternal(); | |
| 160 | |
| 161 // Helper function to determine whether a protected surface is needed for | 149 // Helper function to determine whether a protected surface is needed for |
| 162 // video playback. | 150 // video playback. |
| 163 bool IsProtectedSurfaceRequired(); | 151 bool IsProtectedSurfaceRequired(); |
| 164 | 152 |
| 165 // Called when a MediaDecoderJob finishes prefetching data. Once all | 153 // Called when a MediaDecoderJob finishes prefetching data. Once all |
| 166 // MediaDecoderJobs have prefetched data, then this method updates | 154 // MediaDecoderJobs have prefetched data, then this method updates |
| 167 // |start_time_ticks_| and |start_presentation_timestamp_| so that video can | 155 // |start_time_ticks_| and |start_presentation_timestamp_| so that video can |
| 168 // resync with audio and starts decoding. | 156 // resync with audio and starts decoding. |
| 169 void OnPrefetchDone(); | 157 void OnPrefetchDone(); |
| 170 | 158 |
| 159 // Called when the demuxer config changes. |
| 160 void OnDemuxerConfigsChanged(); |
| 161 |
| 171 // Test-only method to setup hook for the completion of the next decode cycle. | 162 // Test-only method to setup hook for the completion of the next decode cycle. |
| 172 // This callback state is cleared when it is next run. | 163 // This callback state is cleared when it is next run. |
| 173 // Prevent usage creep by only calling this from the | 164 // Prevent usage creep by only calling this from the |
| 174 // ReleaseWithOnPrefetchDoneAlreadyPosted MediaSourcePlayerTest. | 165 // ReleaseWithOnPrefetchDoneAlreadyPosted MediaSourcePlayerTest. |
| 175 void set_decode_callback_for_testing(const base::Closure& test_decode_cb) { | 166 void set_decode_callback_for_testing(const base::Closure& test_decode_cb) { |
| 176 decode_callback_for_testing_ = test_decode_cb; | 167 decode_callback_for_testing_ = test_decode_cb; |
| 177 } | 168 } |
| 178 | 169 |
| 179 // TODO(qinmin/wolenetz): Reorder these based on their priority from | 170 // TODO(qinmin/wolenetz): Reorder these based on their priority from |
| 180 // ProcessPendingEvents(). Release() and other routines are dependent upon | 171 // ProcessPendingEvents(). Release() and other routines are dependent upon |
| 181 // priority consistency. | 172 // priority consistency. |
| 182 enum PendingEventFlags { | 173 enum PendingEventFlags { |
| 183 NO_EVENT_PENDING = 0, | 174 NO_EVENT_PENDING = 0, |
| 184 SEEK_EVENT_PENDING = 1 << 0, | 175 SEEK_EVENT_PENDING = 1 << 0, |
| 185 SURFACE_CHANGE_EVENT_PENDING = 1 << 1, | 176 PREFETCH_REQUEST_EVENT_PENDING = 1 << 1, |
| 186 CONFIG_CHANGE_EVENT_PENDING = 1 << 2, | 177 PREFETCH_DONE_EVENT_PENDING = 1 << 2, |
| 187 PREFETCH_REQUEST_EVENT_PENDING = 1 << 3, | 178 DECODER_CREATION_EVENT_PENDING = 1 << 3, |
| 188 PREFETCH_DONE_EVENT_PENDING = 1 << 4, | |
| 189 }; | 179 }; |
| 190 | 180 |
| 191 static const char* GetEventName(PendingEventFlags event); | 181 static const char* GetEventName(PendingEventFlags event); |
| 192 bool IsEventPending(PendingEventFlags event) const; | 182 bool IsEventPending(PendingEventFlags event) const; |
| 193 void SetPendingEvent(PendingEventFlags event); | 183 void SetPendingEvent(PendingEventFlags event); |
| 194 void ClearPendingEvent(PendingEventFlags event); | 184 void ClearPendingEvent(PendingEventFlags event); |
| 195 | 185 |
| 196 scoped_ptr<DemuxerAndroid> demuxer_; | 186 scoped_ptr<DemuxerAndroid> demuxer_; |
| 197 | 187 |
| 198 // Pending event that the player needs to do. | 188 // Pending event that the player needs to do. |
| 199 unsigned pending_event_; | 189 unsigned pending_event_; |
| 200 | 190 |
| 201 // Stats about the media. | 191 // Stats about the media. |
| 202 base::TimeDelta duration_; | 192 base::TimeDelta duration_; |
| 203 int width_; | |
| 204 int height_; | |
| 205 AudioCodec audio_codec_; | |
| 206 VideoCodec video_codec_; | |
| 207 int num_channels_; | |
| 208 int sampling_rate_; | |
| 209 // TODO(xhwang/qinmin): Add |video_extra_data_|. | |
| 210 std::vector<uint8> audio_extra_data_; | |
| 211 bool reached_audio_eos_; | |
| 212 bool reached_video_eos_; | |
| 213 bool playing_; | 193 bool playing_; |
| 214 bool is_audio_encrypted_; | |
| 215 bool is_video_encrypted_; | |
| 216 double volume_; | |
| 217 | 194 |
| 218 // base::TickClock used by |clock_|. | 195 // base::TickClock used by |clock_|. |
| 219 base::DefaultTickClock default_tick_clock_; | 196 base::DefaultTickClock default_tick_clock_; |
| 220 | 197 |
| 221 // Reference clock. Keeps track of current playback time. | 198 // Reference clock. Keeps track of current playback time. |
| 222 Clock clock_; | 199 Clock clock_; |
| 223 | 200 |
| 224 // Timestamps for providing simple A/V sync. When start decoding an audio | 201 // Timestamps for providing simple A/V sync. When start decoding an audio |
| 225 // chunk, we record its presentation timestamp and the current system time. | 202 // chunk, we record its presentation timestamp and the current system time. |
| 226 // Then we use this information to estimate when the next audio/video frame | 203 // Then we use this information to estimate when the next audio/video frame |
| 227 // should be rendered. | 204 // should be rendered. |
| 228 // TODO(qinmin): Need to fix the problem if audio/video lagged too far behind | 205 // TODO(qinmin): Need to fix the problem if audio/video lagged too far behind |
| 229 // due to network or decoding problem. | 206 // due to network or decoding problem. |
| 230 base::TimeTicks start_time_ticks_; | 207 base::TimeTicks start_time_ticks_; |
| 231 base::TimeDelta start_presentation_timestamp_; | 208 base::TimeDelta start_presentation_timestamp_; |
| 232 | 209 |
| 233 // The surface object currently owned by the player. | |
| 234 gfx::ScopedJavaSurface surface_; | |
| 235 | |
| 236 // Track whether or not the player has received any video data since the most | |
| 237 // recent of player construction, end of last seek, or receiving and | |
| 238 // detecting a |kConfigChanged| access unit from the demuxer. | |
| 239 // If no such video data has been received, the next video data begins with | |
| 240 // an I-frame. Otherwise, we have no such guarantee. | |
| 241 bool next_video_data_is_iframe_; | |
| 242 | |
| 243 // Flag that is true if doing a hack browser seek or false if doing a | 210 // Flag that is true if doing a hack browser seek or false if doing a |
| 244 // regular seek. Only valid when |SEEK_EVENT_PENDING| is pending. | 211 // regular seek. Only valid when |SEEK_EVENT_PENDING| is pending. |
| 245 // TODO(wolenetz): Instead of doing hack browser seek, replay cached data | 212 // TODO(wolenetz): Instead of doing hack browser seek, replay cached data |
| 246 // since last keyframe. See http://crbug.com/304234. | 213 // since last keyframe. See http://crbug.com/304234. |
| 247 bool doing_browser_seek_; | 214 bool doing_browser_seek_; |
| 248 | 215 |
| 249 // If already doing a browser seek when a regular seek request arrives, | 216 // If already doing a browser seek when a regular seek request arrives, |
| 250 // these fields remember the regular seek so OnDemuxerSeekDone() can trigger | 217 // these fields remember the regular seek so OnDemuxerSeekDone() can trigger |
| 251 // it when the browser seek is done. These are only valid when | 218 // it when the browser seek is done. These are only valid when |
| 252 // |SEEK_EVENT_PENDING| is pending. | 219 // |SEEK_EVENT_PENDING| is pending. |
| 253 bool pending_seek_; | 220 bool pending_seek_; |
| 254 base::TimeDelta pending_seek_time_; | 221 base::TimeDelta pending_seek_time_; |
| 255 | 222 |
| 256 // Decoder jobs. | 223 // Decoder jobs. |
| 257 scoped_ptr<AudioDecoderJob, MediaDecoderJob::Deleter> audio_decoder_job_; | 224 scoped_ptr<AudioDecoderJob, MediaDecoderJob::Deleter> audio_decoder_job_; |
| 258 scoped_ptr<VideoDecoderJob, MediaDecoderJob::Deleter> video_decoder_job_; | 225 scoped_ptr<VideoDecoderJob, MediaDecoderJob::Deleter> video_decoder_job_; |
| 259 | 226 |
| 260 bool reconfig_audio_decoder_; | |
| 261 bool reconfig_video_decoder_; | |
| 262 | |
| 263 // Track the most recent preroll target. Decoder re-creation needs this to | 227 // Track the most recent preroll target. Decoder re-creation needs this to |
| 264 // resume any in-progress preroll. | 228 // resume any in-progress preroll. |
| 265 base::TimeDelta preroll_timestamp_; | 229 base::TimeDelta preroll_timestamp_; |
| 266 | 230 |
| 267 // A cancelable task that is posted when the audio decoder starts requesting | 231 // 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 | 232 // new data. This callback runs if no data arrives before the timeout period |
| 269 // elapses. | 233 // elapses. |
| 270 base::CancelableClosure decoder_starvation_callback_; | 234 base::CancelableClosure decoder_starvation_callback_; |
| 271 | 235 |
| 272 MediaDrmBridge* drm_bridge_; | 236 MediaDrmBridge* drm_bridge_; |
| 273 | 237 |
| 274 // No decryption key available to decrypt the encrypted buffer. In this case, | 238 // 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 | 239 // the player should pause. When a new key is added (OnKeyAdded()), we should |
| 276 // try to start playback again. | 240 // try to start playback again. |
| 277 bool is_waiting_for_key_; | 241 bool is_waiting_for_key_; |
| 278 | 242 |
| 243 // Indicates whether the player is waiting for audio or video decoder to be |
| 244 // created. |
| 245 // TODO(qinmin): currently only |is_waiting_for_audio_decoder_| is used due to |
| 246 // empty surface. Will remove is_|waiting_for_audio_decoder_| if needed. |
| 247 bool is_waiting_for_audio_decoder_; |
| 248 bool is_waiting_for_video_decoder_; |
| 249 |
| 279 // Test-only callback for hooking the completion of the next decode cycle. | 250 // Test-only callback for hooking the completion of the next decode cycle. |
| 280 base::Closure decode_callback_for_testing_; | 251 base::Closure decode_callback_for_testing_; |
| 281 | 252 |
| 282 // Whether |surface_| is currently used by the player. | 253 // Whether |surface_| is currently used by the player. |
| 283 bool is_surface_in_use_; | 254 bool is_surface_in_use_; |
| 284 | 255 |
| 285 // Whether there are pending data requests by the decoder. | |
| 286 bool has_pending_audio_data_request_; | |
| 287 bool has_pending_video_data_request_; | |
| 288 | |
| 289 // Weak pointer passed to media decoder jobs for callbacks. | 256 // Weak pointer passed to media decoder jobs for callbacks. |
| 290 // NOTE: Weak pointers must be invalidated before all other member variables. | 257 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 291 base::WeakPtrFactory<MediaSourcePlayer> weak_factory_; | 258 base::WeakPtrFactory<MediaSourcePlayer> weak_factory_; |
| 292 | 259 |
| 293 DISALLOW_COPY_AND_ASSIGN(MediaSourcePlayer); | 260 DISALLOW_COPY_AND_ASSIGN(MediaSourcePlayer); |
| 294 }; | 261 }; |
| 295 | 262 |
| 296 } // namespace media | 263 } // namespace media |
| 297 | 264 |
| 298 #endif // MEDIA_BASE_ANDROID_MEDIA_SOURCE_PLAYER_H_ | 265 #endif // MEDIA_BASE_ANDROID_MEDIA_SOURCE_PLAYER_H_ |
| OLD | NEW |