From 55b9aa9ddd2e5104de97302ed5097eb154487280 Mon Sep 17 00:00:00 2001 From: Jean-Yves Avenard Date: Mon, 18 May 2015 16:13:20 +1000 Subject: [PATCH] Bug 1165585: Part1. Use AsyncReadmetadata with web audio. r=cpearce --- dom/media/webaudio/MediaBufferDecoder.cpp | 29 ++++++++++++++++------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/dom/media/webaudio/MediaBufferDecoder.cpp b/dom/media/webaudio/MediaBufferDecoder.cpp index cddeeb914c6a..be0ca8273f8d 100644 --- a/dom/media/webaudio/MediaBufferDecoder.cpp +++ b/dom/media/webaudio/MediaBufferDecoder.cpp @@ -126,6 +126,8 @@ private: } void Decode(); + void OnMetadataRead(MetadataHolder* aMetadata); + void OnMetadataNotRead(ReadMetadataFailureReason aReason); void RequestSample(); void SampleDecoded(AudioData* aData); void SampleNotDecoded(MediaDecoderReader::NotDecodedReason aReason); @@ -254,23 +256,32 @@ MediaDecodeTask::Decode() // backend support. mDecoderReader->SetIgnoreAudioOutputFormat(); - nsAutoPtr tags; - nsresult rv = mDecoderReader->ReadMetadata(&mMediaInfo, getter_Transfers(tags)); - if (NS_FAILED(rv)) { - mDecoderReader->Shutdown(); - ReportFailureOnMainThread(WebAudioDecodeJob::InvalidContent); - return; - } + mDecoderReader->AsyncReadMetadata()->Then(mDecoderReader->GetTaskQueue(), __func__, this, + &MediaDecodeTask::OnMetadataRead, + &MediaDecodeTask::OnMetadataNotRead); +} - if (!mDecoderReader->HasAudio()) { +void +MediaDecodeTask::OnMetadataRead(MetadataHolder* aMetadata) +{ + mMediaInfo = aMetadata->mInfo; + if (!mMediaInfo.HasAudio()) { mDecoderReader->Shutdown(); ReportFailureOnMainThread(WebAudioDecodeJob::NoAudio); return; } - RequestSample(); } +void +MediaDecodeTask::OnMetadataNotRead(ReadMetadataFailureReason aReason) +{ + MOZ_RELEASE_ASSERT(aReason != ReadMetadataFailureReason::WAITING_FOR_RESOURCES); + mDecoderReader->Shutdown(); + ReportFailureOnMainThread(WebAudioDecodeJob::InvalidContent); + return; +} + void MediaDecodeTask::RequestSample() {