| 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_DECODER_H_ | 5 #ifndef MEDIA_BASE_ANDROID_MEDIA_CODEC_DECODER_H_ |
| 6 #define MEDIA_BASE_ANDROID_MEDIA_CODEC_DECODER_H_ | 6 #define MEDIA_BASE_ANDROID_MEDIA_CODEC_DECODER_H_ |
| 7 | 7 |
| 8 #include "base/android/scoped_java_ref.h" | 8 #include "base/android/scoped_java_ref.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 | 186 |
| 187 // Releases MediaCodecBridge and any related buffers or references. | 187 // Releases MediaCodecBridge and any related buffers or references. |
| 188 virtual void ReleaseMediaCodec(); | 188 virtual void ReleaseMediaCodec(); |
| 189 | 189 |
| 190 // Returns corresponding conditions. | 190 // Returns corresponding conditions. |
| 191 bool IsPrefetchingOrPlaying() const; | 191 bool IsPrefetchingOrPlaying() const; |
| 192 bool IsStopped() const; | 192 bool IsStopped() const; |
| 193 bool IsCompleted() const; | 193 bool IsCompleted() const; |
| 194 bool NotCompletedAndNeedsPreroll() const; | 194 bool NotCompletedAndNeedsPreroll() const; |
| 195 | 195 |
| 196 // Requests an A/V sync mechanism that is similar to preroll, but stops at the | 196 // Sets preroll timestamp and requests preroll. |
| 197 // first available output frame rather than passing certain PTS. | 197 void SetPrerollTimestamp(base::TimeDelta preroll_ts); |
| 198 void SetDecodingUntilOutputIsPresent(); | |
| 199 | 198 |
| 200 base::android::ScopedJavaLocalRef<jobject> GetMediaCrypto(); | 199 base::android::ScopedJavaLocalRef<jobject> GetMediaCrypto(); |
| 201 | 200 |
| 202 // Starts prefetching: accumulates enough data in AccessUnitQueue. | 201 // Starts prefetching: accumulates enough data in AccessUnitQueue. |
| 203 // Decoder thread is not running. | 202 // Decoder thread is not running. |
| 204 void Prefetch(const base::Closure& prefetch_done_cb); | 203 void Prefetch(const base::Closure& prefetch_done_cb); |
| 205 | 204 |
| 206 // Configures MediaCodec. | 205 // Configures MediaCodec. |
| 207 ConfigStatus Configure(); | 206 ConfigStatus Configure(); |
| 208 | 207 |
| 209 // Starts the decoder for prerolling. This method starts the decoder thread. | 208 // Starts the decoder for prerolling. This method starts the decoder thread. |
| 210 bool Preroll(base::TimeDelta preroll_timestamp, | 209 bool Preroll(const base::Closure& preroll_done_cb); |
| 211 const base::Closure& preroll_done_cb); | |
| 212 | 210 |
| 213 // Starts the decoder after preroll is not needed, starting decoder thread | 211 // Starts the decoder after preroll is not needed, starting decoder thread |
| 214 // if it has not started yet. | 212 // if it has not started yet. |
| 215 bool Start(base::TimeDelta start_timestamp); | 213 bool Start(base::TimeDelta start_timestamp); |
| 216 | 214 |
| 217 // Stops the playback process synchronously. This method stops the decoder | 215 // Stops the playback process synchronously. This method stops the decoder |
| 218 // thread synchronously, and then releases all MediaCodec buffers. | 216 // thread synchronously, and then releases all MediaCodec buffers. |
| 219 void SyncStop(); | 217 void SyncStop(); |
| 220 | 218 |
| 221 // Requests to stop the playback and returns. | 219 // Requests to stop the playback and returns. |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 kPrefetching, | 339 kPrefetching, |
| 342 kPrefetched, | 340 kPrefetched, |
| 343 kPrerolling, | 341 kPrerolling, |
| 344 kPrerolled, | 342 kPrerolled, |
| 345 kRunning, | 343 kRunning, |
| 346 kStopping, | 344 kStopping, |
| 347 kInEmergencyStop, | 345 kInEmergencyStop, |
| 348 kError, | 346 kError, |
| 349 }; | 347 }; |
| 350 | 348 |
| 351 enum PrerollMode { | |
| 352 kNoPreroll = 0, | |
| 353 kPrerollTillOutputIsPresent, | |
| 354 kPrerollTillPTS, | |
| 355 }; | |
| 356 | |
| 357 // Helper method that processes an error from MediaCodec. | 349 // Helper method that processes an error from MediaCodec. |
| 358 void OnCodecError(); | 350 void OnCodecError(); |
| 359 | 351 |
| 360 // Requests data. Ensures there is no more than one request at a time. | 352 // Requests data. Ensures there is no more than one request at a time. |
| 361 void RequestData(); | 353 void RequestData(); |
| 362 | 354 |
| 363 // Prefetching callback that is posted to Media thread | 355 // Prefetching callback that is posted to Media thread |
| 364 // in the kPrefetching state. | 356 // in the kPrefetching state. |
| 365 void PrefetchNextChunk(); | 357 void PrefetchNextChunk(); |
| 366 | 358 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 // Callback for posting OnPrerollDone method. | 405 // Callback for posting OnPrerollDone method. |
| 414 base::Closure internal_preroll_done_cb_; | 406 base::Closure internal_preroll_done_cb_; |
| 415 | 407 |
| 416 // Internal state. | 408 // Internal state. |
| 417 DecoderState state_; | 409 DecoderState state_; |
| 418 mutable base::Lock state_lock_; | 410 mutable base::Lock state_lock_; |
| 419 | 411 |
| 420 // Preroll timestamp is set if we need preroll and cleared after we done it. | 412 // Preroll timestamp is set if we need preroll and cleared after we done it. |
| 421 base::TimeDelta preroll_timestamp_; | 413 base::TimeDelta preroll_timestamp_; |
| 422 | 414 |
| 423 // The preroll mode. If not |kNoPreroll|, the playback should start with | 415 // Set to true when MediaCodec internal buffers are filled up. |
| 424 // preroll. | 416 bool is_prepared_; |
| 425 PrerollMode preroll_mode_; | |
| 426 | 417 |
| 427 // Flag is set when the EOS is enqueued into MediaCodec. Reset by Flush. | 418 // Flag is set when the EOS is enqueued into MediaCodec. Reset by Flush. |
| 428 bool eos_enqueued_; | 419 bool eos_enqueued_; |
| 429 | 420 |
| 430 // Flag is set when the EOS is received in MediaCodec output. Reset by Flush. | 421 // Flag is set when the EOS is received in MediaCodec output. Reset by Flush. |
| 431 bool completed_; | 422 bool completed_; |
| 432 | 423 |
| 433 // Flag to ensure we post last frame notification once. | 424 // Flag to ensure we post last frame notification once. |
| 434 bool last_frame_posted_; | 425 bool last_frame_posted_; |
| 435 | 426 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 446 | 437 |
| 447 // NOTE: Weak pointers must be invalidated before all other member variables. | 438 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 448 base::WeakPtrFactory<MediaCodecDecoder> weak_factory_; | 439 base::WeakPtrFactory<MediaCodecDecoder> weak_factory_; |
| 449 | 440 |
| 450 DISALLOW_COPY_AND_ASSIGN(MediaCodecDecoder); | 441 DISALLOW_COPY_AND_ASSIGN(MediaCodecDecoder); |
| 451 }; | 442 }; |
| 452 | 443 |
| 453 } // namespace media | 444 } // namespace media |
| 454 | 445 |
| 455 #endif // MEDIA_BASE_ANDROID_MEDIA_CODEC_DECODER_H_ | 446 #endif // MEDIA_BASE_ANDROID_MEDIA_CODEC_DECODER_H_ |
| OLD | NEW |