| Index: media/base/android/media_codec_decoder.cc
|
| diff --git a/media/base/android/media_codec_decoder.cc b/media/base/android/media_codec_decoder.cc
|
| index c6e0004caa37ae8ef9d78d7aef00e8297c7b87cd..72116e557fa83a2b5e8708cfbd98faccead3be1b 100644
|
| --- a/media/base/android/media_codec_decoder.cc
|
| +++ b/media/base/android/media_codec_decoder.cc
|
| @@ -35,14 +35,18 @@ MediaCodecDecoder::MediaCodecDecoder(
|
| const scoped_refptr<base::SingleThreadTaskRunner>& media_task_runner,
|
| const base::Closure& external_request_data_cb,
|
| const base::Closure& starvation_cb,
|
| + const base::Closure& decoder_drained_cb,
|
| const base::Closure& stop_done_cb,
|
| const base::Closure& error_cb,
|
| const char* decoder_thread_name)
|
| : media_task_runner_(media_task_runner),
|
| decoder_thread_(decoder_thread_name),
|
| needs_reconfigure_(false),
|
| + drain_decoder_(false),
|
| + always_reconfigure_for_tests_(false),
|
| external_request_data_cb_(external_request_data_cb),
|
| starvation_cb_(starvation_cb),
|
| + decoder_drained_cb_(decoder_drained_cb),
|
| stop_done_cb_(stop_done_cb),
|
| error_cb_(error_cb),
|
| state_(kStopped),
|
| @@ -93,8 +97,6 @@ void MediaCodecDecoder::ReleaseDecoderResources() {
|
|
|
| SetState(kStopped);
|
| ReleaseMediaCodec();
|
| -
|
| - needs_preroll_ = true;
|
| }
|
|
|
| void MediaCodecDecoder::Flush() {
|
| @@ -111,6 +113,7 @@ void MediaCodecDecoder::Flush() {
|
|
|
| eos_enqueued_ = false;
|
| completed_ = false;
|
| + drain_decoder_ = false;
|
| au_queue_.Flush();
|
|
|
| #ifndef NDEBUG
|
| @@ -141,6 +144,8 @@ void MediaCodecDecoder::ReleaseMediaCodec() {
|
| DVLOG(1) << class_name() << "::" << __FUNCTION__;
|
|
|
| media_codec_bridge_.reset();
|
| +
|
| + needs_preroll_ = true;
|
| }
|
|
|
| bool MediaCodecDecoder::IsPrefetchingOrPlaying() const {
|
| @@ -183,6 +188,13 @@ bool MediaCodecDecoder::NeedsPreroll() const {
|
| return HasStream() && needs_preroll_ && !completed_;
|
| }
|
|
|
| +void MediaCodecDecoder::SetNeedsPreroll() {
|
| + DCHECK(media_task_runner_->BelongsToCurrentThread());
|
| + DVLOG(1) << class_name() << "::" << __FUNCTION__;
|
| +
|
| + needs_preroll_ = true;
|
| +}
|
| +
|
| base::android::ScopedJavaLocalRef<jobject> MediaCodecDecoder::GetMediaCrypto() {
|
| base::android::ScopedJavaLocalRef<jobject> media_crypto;
|
|
|
| @@ -223,24 +235,31 @@ MediaCodecDecoder::ConfigStatus MediaCodecDecoder::Configure() {
|
| ReleaseMediaCodec();
|
| }
|
|
|
| - MediaCodecDecoder::ConfigStatus result;
|
| if (media_codec_bridge_) {
|
| DVLOG(1) << class_name() << "::" << __FUNCTION__
|
| << ": reconfiguration is not required, ignoring";
|
| - result = kConfigOk;
|
| - } else {
|
| - result = ConfigureInternal();
|
| + return kConfigOk;
|
| + }
|
| +
|
| + // Read all |kConfigChanged| units preceding the data one.
|
| + AccessUnitQueue::Info au_info = au_queue_.GetInfo();
|
| + while (au_info.configs) {
|
| + SetDemuxerConfigs(*au_info.configs);
|
| + au_queue_.Advance();
|
| + au_info = au_queue_.GetInfo();
|
| + }
|
| +
|
| + MediaCodecDecoder::ConfigStatus result = ConfigureInternal();
|
|
|
| #ifndef NDEBUG
|
| - // We check and reset |verify_next_frame_is_key_| on Decoder thread.
|
| - // This DCHECK ensures we won't need to lock this variable.
|
| - DCHECK(!decoder_thread_.IsRunning());
|
| + // We check and reset |verify_next_frame_is_key_| on Decoder thread.
|
| + // This DCHECK ensures we won't need to lock this variable.
|
| + DCHECK(!decoder_thread_.IsRunning());
|
|
|
| - // For video the first frame after reconfiguration must be key frame.
|
| - if (result == kConfigOk)
|
| - verify_next_frame_is_key_ = true;
|
| + // For video the first frame after reconfiguration must be key frame.
|
| + if (result == kConfigOk)
|
| + verify_next_frame_is_key_ = true;
|
| #endif
|
| - }
|
|
|
| return result;
|
| }
|
| @@ -385,7 +404,7 @@ void MediaCodecDecoder::RequestToStop() {
|
| case kStopped:
|
| case kPrefetching:
|
| case kPrefetched:
|
| - // There is nothing to wait for, we can sent nofigication right away.
|
| + // There is nothing to wait for, we can sent notification right away.
|
| DCHECK(!decoder_thread_.IsRunning());
|
| SetState(kStopped);
|
| media_task_runner_->PostTask(FROM_HERE, stop_done_cb_);
|
| @@ -396,20 +415,28 @@ void MediaCodecDecoder::RequestToStop() {
|
| }
|
| }
|
|
|
| -void MediaCodecDecoder::OnLastFrameRendered(bool completed) {
|
| +void MediaCodecDecoder::OnLastFrameRendered(bool eos_encountered) {
|
| DCHECK(media_task_runner_->BelongsToCurrentThread());
|
|
|
| - DVLOG(0) << class_name() << "::" << __FUNCTION__
|
| - << " completed:" << completed;
|
| + DVLOG(1) << class_name() << "::" << __FUNCTION__
|
| + << " eos_encountered:" << eos_encountered;
|
|
|
| decoder_thread_.Stop(); // synchronous
|
|
|
| SetState(kStopped);
|
| - completed_ = completed;
|
| + completed_ = (eos_encountered && !drain_decoder_);
|
|
|
| - if (completed_ && !preroll_done_cb_.is_null())
|
| + if (completed_ && !preroll_done_cb_.is_null()) {
|
| media_task_runner_->PostTask(FROM_HERE,
|
| base::ResetAndReturn(&preroll_done_cb_));
|
| + }
|
| +
|
| + if (eos_encountered && drain_decoder_) {
|
| + ReleaseMediaCodec();
|
| + drain_decoder_ = false;
|
| + eos_enqueued_ = false;
|
| + media_task_runner_->PostTask(FROM_HERE, decoder_drained_cb_);
|
| + }
|
|
|
| media_task_runner_->PostTask(FROM_HERE, stop_done_cb_);
|
| }
|
| @@ -464,6 +491,11 @@ bool MediaCodecDecoder::IsPrerollingForTests() const {
|
| return GetState() == kPrerolling;
|
| }
|
|
|
| +void MediaCodecDecoder::SetAlwaysReconfigureForTests() {
|
| + // UI task runner.
|
| + always_reconfigure_for_tests_ = true;
|
| +}
|
| +
|
| int MediaCodecDecoder::NumDelayedRenderTasks() const {
|
| return 0;
|
| }
|
| @@ -595,33 +627,58 @@ bool MediaCodecDecoder::EnqueueInputBuffer() {
|
|
|
| // Get the next frame from the queue and the queue info
|
|
|
| - AccessUnitQueue::Info au_info = au_queue_.GetInfo();
|
| + // Retrieve access units from the |au_queue_| in a loop until we either get
|
| + // a non-config front unit or until the new config is incompatible and we need
|
| + // to drain decoder.
|
|
|
| - // Request the data from Demuxer
|
| - if (au_info.length <= kPlaybackLowLimit && !au_info.has_eos)
|
| - media_task_runner_->PostTask(FROM_HERE, request_data_cb_);
|
| + AccessUnitQueue::Info au_info;
|
| + do {
|
| + // |drain_decoder_| can be set here upon the first time we enter the loop if
|
| + // we could not dequeue the input buffer for it right away.
|
| + if (drain_decoder_)
|
| + break;
|
|
|
| - // Get the next frame from the queue
|
| + au_info = au_queue_.GetInfo();
|
|
|
| - if (!au_info.length) {
|
| - // Report starvation and return, Start() will be called again later.
|
| - DVLOG(1) << class_name() << "::" << __FUNCTION__ << ": starvation detected";
|
| - media_task_runner_->PostTask(FROM_HERE, starvation_cb_);
|
| - return true;
|
| - }
|
| + // Request the data from Demuxer
|
| + if (au_info.length <= kPlaybackLowLimit && !au_info.has_eos)
|
| + media_task_runner_->PostTask(FROM_HERE, request_data_cb_);
|
|
|
| - if (au_info.configs) {
|
| - DVLOG(1) << class_name() << "::" << __FUNCTION__
|
| - << ": received new configs, not implemented";
|
| - // post an error for now?
|
| - media_task_runner_->PostTask(FROM_HERE, internal_error_cb_);
|
| - return false;
|
| - }
|
| + // Get the next frame from the queue
|
| +
|
| + if (!au_info.length) {
|
| + // Report starvation and return, Start() will be called again later.
|
| + DVLOG(1) << class_name() << "::" << __FUNCTION__
|
| + << ": starvation detected";
|
| + media_task_runner_->PostTask(FROM_HERE, starvation_cb_);
|
| + return true;
|
| + }
|
| +
|
| + if (au_info.configs) {
|
| + DVLOG(1) << class_name() << "::" << __FUNCTION__ << ": received configs "
|
| + << (*au_info.configs);
|
| +
|
| + // Compare the new and current configs.
|
| + if (IsCodecReconfigureNeeded(*au_info.configs)) {
|
| + DVLOG(1) << class_name() << "::" << __FUNCTION__
|
| + << ": reconfiguration required";
|
| + drain_decoder_ = true;
|
| + }
|
| +
|
| + // Replace the current configs.
|
| + SetDemuxerConfigs(*au_info.configs);
|
| +
|
| + // Remove the configs from the queue.
|
| + au_queue_.Advance();
|
| + }
|
| + } while (au_info.configs);
|
|
|
| // We are ready to enqueue the front unit.
|
|
|
| + DCHECK(au_info.front_unit);
|
| +
|
| #ifndef NDEBUG
|
| - if (verify_next_frame_is_key_) {
|
| + if (verify_next_frame_is_key_ && !drain_decoder_) {
|
| verify_next_frame_is_key_ = false;
|
| VerifyUnitIsKeyFrame(au_info.front_unit);
|
| }
|
| @@ -659,9 +716,10 @@ bool MediaCodecDecoder::EnqueueInputBuffer() {
|
| DCHECK_GE(index, 0);
|
|
|
| const AccessUnit* unit = au_info.front_unit;
|
| +
|
| DCHECK(unit);
|
|
|
| - if (unit->is_end_of_stream) {
|
| + if (drain_decoder_ || unit->is_end_of_stream) {
|
| DVLOG(1) << class_name() << "::" << __FUNCTION__ << ": QueueEOS";
|
| media_codec_bridge_->QueueEOS(index);
|
| eos_enqueued_ = true;
|
|
|