Bug 1299072: P7. Use MediaResult with MetadataPromise. r=jwwang

MozReview-Commit-ID: KrRr8wDuPNT

--HG--
extra : rebase_source : 3df3763890a55c898ca3f00dd914e3c78fe714b1
This commit is contained in:
Jean-Yves Avenard 2016-09-10 19:56:50 +10:00
Родитель c590867926
Коммит a3d152a719
7 изменённых файлов: 20 добавлений и 27 удалений

Просмотреть файл

@ -360,8 +360,6 @@ MediaDecoderReader::GetBuffered()
RefPtr<MediaDecoderReader::MetadataPromise> RefPtr<MediaDecoderReader::MetadataPromise>
MediaDecoderReader::AsyncReadMetadata() MediaDecoderReader::AsyncReadMetadata()
{ {
typedef ReadMetadataFailureReason Reason;
MOZ_ASSERT(OnTaskQueue()); MOZ_ASSERT(OnTaskQueue());
DECODER_LOG("MediaDecoderReader::AsyncReadMetadata"); DECODER_LOG("MediaDecoderReader::AsyncReadMetadata");
@ -374,7 +372,7 @@ MediaDecoderReader::AsyncReadMetadata()
// error. // error.
if (NS_FAILED(rv) || !metadata->mInfo.HasValidMedia()) { if (NS_FAILED(rv) || !metadata->mInfo.HasValidMedia()) {
DECODER_WARN("ReadMetadata failed, rv=%x HasValidMedia=%d", rv, metadata->mInfo.HasValidMedia()); DECODER_WARN("ReadMetadata failed, rv=%x HasValidMedia=%d", rv, metadata->mInfo.HasValidMedia());
return MetadataPromise::CreateAndReject(Reason::METADATA_ERROR, __func__); return MetadataPromise::CreateAndReject(NS_ERROR_DOM_MEDIA_METADATA_ERR, __func__);
} }
// Success! // Success!

Просмотреть файл

@ -51,11 +51,6 @@ private:
virtual ~MetadataHolder() {} virtual ~MetadataHolder() {}
}; };
enum class ReadMetadataFailureReason : int8_t
{
METADATA_ERROR
};
// Encapsulates the decoding and reading of media data. Reading can either // Encapsulates the decoding and reading of media data. Reading can either
// synchronous and done on the calling "decode" thread, or asynchronous and // synchronous and done on the calling "decode" thread, or asynchronous and
// performed on a background thread, with the result being returned by // performed on a background thread, with the result being returned by
@ -72,7 +67,7 @@ public:
using TrackSet = EnumSet<TrackInfo::TrackType>; using TrackSet = EnumSet<TrackInfo::TrackType>;
using MetadataPromise = using MetadataPromise =
MozPromise<RefPtr<MetadataHolder>, ReadMetadataFailureReason, IsExclusive>; MozPromise<RefPtr<MetadataHolder>, MediaResult, IsExclusive>;
using MediaDataPromise = using MediaDataPromise =
MozPromise<RefPtr<MediaData>, MediaResult, IsExclusive>; MozPromise<RefPtr<MediaData>, MediaResult, IsExclusive>;
using SeekPromise = MozPromise<media::TimeUnit, nsresult, IsExclusive>; using SeekPromise = MozPromise<media::TimeUnit, nsresult, IsExclusive>;

Просмотреть файл

@ -263,8 +263,8 @@ public:
[this] (MetadataHolder* aMetadata) { [this] (MetadataHolder* aMetadata) {
OnMetadataRead(aMetadata); OnMetadataRead(aMetadata);
}, },
[this] (ReadMetadataFailureReason aReason) { [this] (const MediaResult& aError) {
OnMetadataNotRead(aReason); OnMetadataNotRead(aError);
})); }));
} }
@ -355,11 +355,11 @@ private:
SetState(DECODER_STATE_DECODING_FIRSTFRAME); SetState(DECODER_STATE_DECODING_FIRSTFRAME);
} }
void OnMetadataNotRead(ReadMetadataFailureReason aReason) void OnMetadataNotRead(const MediaResult& aError)
{ {
mMetadataRequest.Complete(); mMetadataRequest.Complete();
SWARN("Decode metadata failed, shutting down decoder"); SWARN("Decode metadata failed, shutting down decoder");
mMaster->DecodeError(); mMaster->DecodeError(aError);
} }
MozPromiseRequestHolder<MediaDecoderReader::MetadataPromise> mMetadataRequest; MozPromiseRequestHolder<MediaDecoderReader::MetadataPromise> mMetadataRequest;

Просмотреть файл

@ -93,7 +93,7 @@ MediaFormatReader::Shutdown()
MOZ_ASSERT(OnTaskQueue()); MOZ_ASSERT(OnTaskQueue());
mDemuxerInitRequest.DisconnectIfExists(); mDemuxerInitRequest.DisconnectIfExists();
mMetadataPromise.RejectIfExists(ReadMetadataFailureReason::METADATA_ERROR, __func__); mMetadataPromise.RejectIfExists(NS_ERROR_DOM_MEDIA_CANCELED, __func__);
mSeekPromise.RejectIfExists(NS_ERROR_DOM_MEDIA_CANCELED, __func__); mSeekPromise.RejectIfExists(NS_ERROR_DOM_MEDIA_CANCELED, __func__);
mSkipRequest.DisconnectIfExists(); mSkipRequest.DisconnectIfExists();
@ -283,7 +283,7 @@ MediaFormatReader::OnDemuxerInitDone(nsresult)
// We currently only handle the first video track. // We currently only handle the first video track.
mVideo.mTrackDemuxer = mDemuxer->GetTrackDemuxer(TrackInfo::kVideoTrack, 0); mVideo.mTrackDemuxer = mDemuxer->GetTrackDemuxer(TrackInfo::kVideoTrack, 0);
if (!mVideo.mTrackDemuxer) { if (!mVideo.mTrackDemuxer) {
mMetadataPromise.Reject(ReadMetadataFailureReason::METADATA_ERROR, __func__); mMetadataPromise.Reject(NS_ERROR_DOM_MEDIA_METADATA_ERR, __func__);
return; return;
} }
@ -292,7 +292,7 @@ MediaFormatReader::OnDemuxerInitDone(nsresult)
if (videoActive) { if (videoActive) {
if (platform && !platform->SupportsMimeType(videoInfo->mMimeType, nullptr)) { if (platform && !platform->SupportsMimeType(videoInfo->mMimeType, nullptr)) {
// We have no decoder for this track. Error. // We have no decoder for this track. Error.
mMetadataPromise.Reject(ReadMetadataFailureReason::METADATA_ERROR, __func__); mMetadataPromise.Reject(NS_ERROR_DOM_MEDIA_METADATA_ERR, __func__);
return; return;
} }
mInfo.mVideo = *videoInfo->GetAsVideoInfo(); mInfo.mVideo = *videoInfo->GetAsVideoInfo();
@ -312,7 +312,7 @@ MediaFormatReader::OnDemuxerInitDone(nsresult)
if (audioActive) { if (audioActive) {
mAudio.mTrackDemuxer = mDemuxer->GetTrackDemuxer(TrackInfo::kAudioTrack, 0); mAudio.mTrackDemuxer = mDemuxer->GetTrackDemuxer(TrackInfo::kAudioTrack, 0);
if (!mAudio.mTrackDemuxer) { if (!mAudio.mTrackDemuxer) {
mMetadataPromise.Reject(ReadMetadataFailureReason::METADATA_ERROR, __func__); mMetadataPromise.Reject(NS_ERROR_DOM_MEDIA_METADATA_ERR, __func__);
return; return;
} }
@ -364,7 +364,7 @@ MediaFormatReader::OnDemuxerInitDone(nsresult)
mDemuxer->IsSeekableOnlyInBufferedRanges(); mDemuxer->IsSeekableOnlyInBufferedRanges();
if (!videoActive && !audioActive) { if (!videoActive && !audioActive) {
mMetadataPromise.Reject(ReadMetadataFailureReason::METADATA_ERROR, __func__); mMetadataPromise.Reject(NS_ERROR_DOM_MEDIA_METADATA_ERR, __func__);
return; return;
} }
@ -379,7 +379,7 @@ void
MediaFormatReader::OnDemuxerInitFailed(DemuxerFailureReason aFailure) MediaFormatReader::OnDemuxerInitFailed(DemuxerFailureReason aFailure)
{ {
mDemuxerInitRequest.Complete(); mDemuxerInitRequest.Complete();
mMetadataPromise.Reject(ReadMetadataFailureReason::METADATA_ERROR, __func__); mMetadataPromise.Reject(NS_ERROR_DOM_MEDIA_METADATA_ERR, __func__);
} }
bool bool

Просмотреть файл

@ -88,7 +88,7 @@ public:
&MediaFormatReaderBinding::OnNotDemuxed); &MediaFormatReaderBinding::OnNotDemuxed);
} }
void OnMetadataNotRead(ReadMetadataFailureReason aReason) { void OnMetadataNotRead(const MediaResult& aError) {
EXPECT_TRUE(false); EXPECT_TRUE(false);
ReaderShutdown(); ReaderShutdown();
} }

Просмотреть файл

@ -175,7 +175,7 @@ MediaOmxReader::Shutdown()
void MediaOmxReader::ReleaseResources() void MediaOmxReader::ReleaseResources()
{ {
mMediaResourceRequest.DisconnectIfExists(); mMediaResourceRequest.DisconnectIfExists();
mMetadataPromise.RejectIfExists(ReadMetadataFailureReason::METADATA_ERROR, __func__); mMetadataPromise.RejectIfExists(NS_ERROR_DOM_MEDIA_METADATA_ERR, __func__);
ResetDecode(); ResetDecode();
// Before freeing a video codec, all video buffers needed to be released // Before freeing a video codec, all video buffers needed to be released
@ -221,7 +221,7 @@ MediaOmxReader::AsyncReadMetadata()
nsresult rv = InitOmxDecoder(); nsresult rv = InitOmxDecoder();
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
return MediaDecoderReader::MetadataPromise::CreateAndReject( return MediaDecoderReader::MetadataPromise::CreateAndReject(
ReadMetadataFailureReason::METADATA_ERROR, __func__); NS_ERROR_DOM_MEDIA_METADATA_ERR, __func__);
} }
bool isMP3 = mDecoder->GetResource()->GetContentType().EqualsASCII(AUDIO_MP3); bool isMP3 = mDecoder->GetResource()->GetContentType().EqualsASCII(AUDIO_MP3);
@ -243,7 +243,7 @@ MediaOmxReader::AsyncReadMetadata()
self->HandleResourceAllocated(); self->HandleResourceAllocated();
}, [self] (bool) -> void { }, [self] (bool) -> void {
self->mMediaResourceRequest.Complete(); self->mMediaResourceRequest.Complete();
self->mMetadataPromise.Reject(ReadMetadataFailureReason::METADATA_ERROR, __func__); self->mMetadataPromise.Reject(NS_ERROR_DOM_MEDIA_METADATA_ERR, __func__);
})); }));
return p; return p;
@ -255,7 +255,7 @@ void MediaOmxReader::HandleResourceAllocated()
// After resources are available, set the metadata. // After resources are available, set the metadata.
if (!mOmxDecoder->EnsureMetadata()) { if (!mOmxDecoder->EnsureMetadata()) {
mMetadataPromise.Reject(ReadMetadataFailureReason::METADATA_ERROR, __func__); mMetadataPromise.Reject(NS_ERROR_DOM_MEDIA_METADATA_ERR, __func__);
return; return;
} }
@ -289,7 +289,7 @@ void MediaOmxReader::HandleResourceAllocated()
nsIntSize displaySize(displayWidth, displayHeight); nsIntSize displaySize(displayWidth, displayHeight);
nsIntSize frameSize(width, height); nsIntSize frameSize(width, height);
if (!IsValidVideoRegion(frameSize, pictureRect, displaySize)) { if (!IsValidVideoRegion(frameSize, pictureRect, displaySize)) {
mMetadataPromise.Reject(ReadMetadataFailureReason::METADATA_ERROR, __func__); mMetadataPromise.RejectNS_ERROR_DOM_MEDIA_METADATA_ERR, __func__);
return; return;
} }

Просмотреть файл

@ -132,7 +132,7 @@ private:
void Decode(); void Decode();
void OnMetadataRead(MetadataHolder* aMetadata); void OnMetadataRead(MetadataHolder* aMetadata);
void OnMetadataNotRead(ReadMetadataFailureReason aReason); void OnMetadataNotRead(const MediaResult& aError);
void RequestSample(); void RequestSample();
void SampleDecoded(MediaData* aData); void SampleDecoded(MediaData* aData);
void SampleNotDecoded(const MediaResult& aError); void SampleNotDecoded(const MediaResult& aError);
@ -310,7 +310,7 @@ MediaDecodeTask::OnMetadataRead(MetadataHolder* aMetadata)
} }
void void
MediaDecodeTask::OnMetadataNotRead(ReadMetadataFailureReason aReason) MediaDecodeTask::OnMetadataNotRead(const MediaResult& aReason)
{ {
mDecoderReader->Shutdown(); mDecoderReader->Shutdown();
ReportFailureOnMainThread(WebAudioDecodeJob::InvalidContent); ReportFailureOnMainThread(WebAudioDecodeJob::InvalidContent);