Bug 1324629. Part 3 - remove AudioWait and videoWait callbacks. r=kaku

MozReview-Commit-ID: 9pXLLrYLN4c

--HG--
extra : rebase_source : c66cc3f37fd3cebb0d6a9c7525f863f2ade2a67e
extra : intermediate-source : fbb3fcf20109d9caa13e556c679aee5e692e78f2
extra : source : e8eff4dc4bc1fae74e6f228d51d9677d215ff66a
This commit is contained in:
JW Wang 2016-12-20 14:31:29 +08:00
Родитель 08a93dbdc4
Коммит d1e5b672ea
4 изменённых файлов: 68 добавлений и 112 удалений

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

@ -76,20 +76,6 @@ MediaDecoderReaderWrapper::RequestVideoData(bool aSkipToNextKeyframe,
[] (const MediaResult& aError) {});
}
bool
MediaDecoderReaderWrapper::IsWaitingAudioData() const
{
MOZ_ASSERT(mOwnerThread->IsCurrentThreadIn());
return mAudioWaitRequest.Exists();
}
bool
MediaDecoderReaderWrapper::IsWaitingVideoData() const
{
MOZ_ASSERT(mOwnerThread->IsCurrentThreadIn());
return mVideoWaitRequest.Exists();
}
RefPtr<MediaDecoderReader::SeekPromise>
MediaDecoderReaderWrapper::Seek(const SeekTarget& aTarget)
{
@ -102,38 +88,12 @@ MediaDecoderReaderWrapper::Seek(const SeekTarget& aTarget)
Move(adjustedTarget));
}
void
RefPtr<MediaDecoderReaderWrapper::WaitForDataPromise>
MediaDecoderReaderWrapper::WaitForData(MediaData::Type aType)
{
MOZ_ASSERT(mOwnerThread->IsCurrentThreadIn());
auto p = InvokeAsync(mReader->OwnerThread(), mReader.get(), __func__,
&MediaDecoderReader::WaitForData, aType);
RefPtr<MediaDecoderReaderWrapper> self = this;
WaitRequestRef(aType).Begin(p->Then(mOwnerThread, __func__,
[self] (MediaData::Type aType) {
self->WaitRequestRef(aType).Complete();
self->WaitCallbackRef(aType).Notify(AsVariant(aType));
},
[self, aType] (WaitForDataRejectValue aRejection) {
self->WaitRequestRef(aType).Complete();
self->WaitCallbackRef(aType).Notify(AsVariant(aRejection));
}));
}
MediaCallbackExc<WaitCallbackData>&
MediaDecoderReaderWrapper::WaitCallbackRef(MediaData::Type aType)
{
MOZ_ASSERT(mOwnerThread->IsCurrentThreadIn());
return aType == MediaData::AUDIO_DATA ? mAudioWaitCallback : mVideoWaitCallback;
}
MozPromiseRequestHolder<MediaDecoderReader::WaitForDataPromise>&
MediaDecoderReaderWrapper::WaitRequestRef(MediaData::Type aType)
{
MOZ_ASSERT(mOwnerThread->IsCurrentThreadIn());
return aType == MediaData::AUDIO_DATA ? mAudioWaitRequest : mVideoWaitRequest;
return InvokeAsync(mReader->OwnerThread(), mReader.get(), __func__,
&MediaDecoderReader::WaitForData, aType);
}
void
@ -149,15 +109,6 @@ void
MediaDecoderReaderWrapper::ResetDecode(TrackSet aTracks)
{
MOZ_ASSERT(mOwnerThread->IsCurrentThreadIn());
if (aTracks.contains(TrackInfo::kAudioTrack)) {
mAudioWaitRequest.DisconnectIfExists();
}
if (aTracks.contains(TrackInfo::kVideoTrack)) {
mVideoWaitRequest.DisconnectIfExists();
}
nsCOMPtr<nsIRunnable> r =
NewRunnableMethod<TrackSet>(mReader,
&MediaDecoderReader::ResetDecode,

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

@ -37,10 +37,6 @@ class MediaDecoderReaderWrapper {
typedef MediaDecoderReader::TrackSet TrackSet;
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaDecoderReaderWrapper);
private:
MediaCallbackExc<WaitCallbackData> mAudioWaitCallback;
MediaCallbackExc<WaitCallbackData> mVideoWaitCallback;
public:
MediaDecoderReaderWrapper(AbstractThread* aOwnerThread,
MediaDecoderReader* aReader);
@ -48,9 +44,6 @@ public:
media::TimeUnit StartTime() const;
RefPtr<MetadataPromise> ReadMetadata();
decltype(mAudioWaitCallback)& AudioWaitCallback() { return mAudioWaitCallback; }
decltype(mVideoWaitCallback)& VideoWaitCallback() { return mVideoWaitCallback; }
// NOTE: please set callbacks before requesting audio/video data!
RefPtr<MediaDataPromise> RequestAudioData();
@ -58,10 +51,7 @@ public:
RequestVideoData(bool aSkipToNextKeyframe, media::TimeUnit aTimeThreshold);
// NOTE: please set callbacks before invoking WaitForData()!
void WaitForData(MediaData::Type aType);
bool IsWaitingAudioData() const;
bool IsWaitingVideoData() const;
RefPtr<WaitForDataPromise> WaitForData(MediaData::Type aType);
RefPtr<SeekPromise> Seek(const SeekTarget& aTarget);
RefPtr<ShutdownPromise> Shutdown();
@ -108,20 +98,14 @@ public:
private:
~MediaDecoderReaderWrapper();
void OnMetadataRead(MetadataHolder* aMetadata);
void OnMetadataNotRead() {}
MediaCallbackExc<WaitCallbackData>& WaitCallbackRef(MediaData::Type aType);
MozPromiseRequestHolder<WaitForDataPromise>& WaitRequestRef(MediaData::Type aType);
const RefPtr<AbstractThread> mOwnerThread;
const RefPtr<MediaDecoderReader> mReader;
bool mShutdown = false;
Maybe<media::TimeUnit> mStartTime;
MozPromiseRequestHolder<WaitForDataPromise> mAudioWaitRequest;
MozPromiseRequestHolder<WaitForDataPromise> mVideoWaitRequest;
};
} // namespace mozilla

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

@ -237,7 +237,7 @@ protected:
// have a waiting promise pending (such as with non-MSE EME).
return Resource()->IsExpectingMoreData() ||
(Reader()->IsWaitForDataSupported() &&
(Reader()->IsWaitingAudioData() || Reader()->IsWaitingVideoData()));
(mMaster->IsWaitingAudioData() || mMaster->IsWaitingVideoData()));
}
MediaQueue<MediaData>& AudioQueue() const { return mMaster->mAudioQueue; }
MediaQueue<MediaData>& VideoQueue() const { return mMaster->mVideoQueue; }
@ -683,8 +683,8 @@ private:
void MaybeStopPrerolling()
{
if (mIsPrerolling &&
(DonePrerollingAudio() || Reader()->IsWaitingAudioData()) &&
(DonePrerollingVideo() || Reader()->IsWaitingVideoData())) {
(DonePrerollingAudio() || mMaster->IsWaitingAudioData()) &&
(DonePrerollingVideo() || mMaster->IsWaitingVideoData())) {
mIsPrerolling = false;
// Check if we can start playback.
mMaster->ScheduleStateMachine();
@ -928,7 +928,7 @@ public:
// If the decoder is waiting for data, we tell it to call us back when the
// data arrives.
if (aError == NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA) {
Reader()->WaitForData(aType);
mMaster->WaitForData(aType);
return;
}
@ -1065,7 +1065,7 @@ private:
{
MOZ_ASSERT(!mDoneAudioSeeking);
MOZ_ASSERT(!mMaster->IsRequestingAudioData());
MOZ_ASSERT(!Reader()->IsWaitingAudioData());
MOZ_ASSERT(!mMaster->IsWaitingAudioData());
mMaster->RequestAudioData();
}
@ -1073,7 +1073,7 @@ private:
{
MOZ_ASSERT(!mDoneVideoSeeking);
MOZ_ASSERT(!mMaster->IsRequestingVideoData());
MOZ_ASSERT(!Reader()->IsWaitingVideoData());
MOZ_ASSERT(!mMaster->IsWaitingVideoData());
mMaster->RequestVideoData(false, media::TimeUnit());
}
@ -1281,7 +1281,7 @@ private:
if (!NeedMoreVideo()) {
FinishSeek();
} else if (!mMaster->IsRequestingVideoData() &&
!Reader()->IsWaitingVideoData()) {
!mMaster->IsWaitingVideoData()) {
RequestVideoData();
}
}
@ -1367,7 +1367,7 @@ private:
// Video seek not finished.
switch (aError.Code()) {
case NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA:
Reader()->WaitForData(MediaData::VIDEO_DATA);
mMaster->WaitForData(MediaData::VIDEO_DATA);
break;
case NS_ERROR_DOM_MEDIA_CANCELED:
RequestVideoData();
@ -1716,7 +1716,7 @@ StateObject::HandleNotDecoded(MediaData::Type aType, const MediaResult& aError)
if (aError == NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA) {
MOZ_ASSERT(Reader()->IsWaitForDataSupported(),
"Readers that send WAITING_FOR_DATA need to implement WaitForData");
Reader()->WaitForData(aType);
mMaster->WaitForData(aType);
HandleWaitingForData();
return;
}
@ -2047,8 +2047,8 @@ DecodingState::MaybeStartBuffering()
} else {
MOZ_ASSERT(Reader()->IsWaitForDataSupported());
shouldBuffer =
(mMaster->OutOfDecodedAudio() && Reader()->IsWaitingAudioData()) ||
(mMaster->OutOfDecodedVideo() && Reader()->IsWaitingVideoData());
(mMaster->OutOfDecodedAudio() && mMaster->IsWaitingAudioData()) ||
(mMaster->OutOfDecodedVideo() && mMaster->IsWaitingVideoData());
}
if (shouldBuffer) {
SetState<BufferingState>();
@ -2138,11 +2138,11 @@ BufferingState::Step()
MOZ_ASSERT(mMaster->mMinimizePreroll ||
!mMaster->OutOfDecodedAudio() ||
mMaster->IsRequestingAudioData() ||
Reader()->IsWaitingAudioData());
mMaster->IsWaitingAudioData());
MOZ_ASSERT(mMaster->mMinimizePreroll ||
!mMaster->OutOfDecodedVideo() ||
mMaster->IsRequestingVideoData() ||
Reader()->IsWaitingVideoData());
mMaster->IsWaitingVideoData());
SLOG("In buffering mode, waiting to be notified: outOfAudio: %d, "
"mAudioStatus: %s, outOfVideo: %d, mVideoStatus: %s",
mMaster->OutOfDecodedAudio(), mMaster->AudioRequestStatus(),
@ -2189,6 +2189,8 @@ ShutdownState::Enter()
master->CancelMediaDecoderReaderWrapperCallback();
master->mAudioDataRequest.DisconnectIfExists();
master->mVideoDataRequest.DisconnectIfExists();
master->mAudioWaitRequest.DisconnectIfExists();
master->mVideoWaitRequest.DisconnectIfExists();
master->Reset();
@ -2715,32 +2717,12 @@ void
MediaDecoderStateMachine::SetMediaDecoderReaderWrapperCallback()
{
MOZ_ASSERT(OnTaskQueue());
mAudioWaitCallback = mReader->AudioWaitCallback().Connect(
mTaskQueue, [this] (WaitCallbackData aData) {
if (aData.is<MediaData::Type>()) {
OnAudioWaited(aData.as<MediaData::Type>());
} else {
OnNotWaited(aData.as<WaitForDataRejectValue>());
}
});
mVideoWaitCallback = mReader->VideoWaitCallback().Connect(
mTaskQueue, [this] (WaitCallbackData aData) {
if (aData.is<MediaData::Type>()) {
OnVideoWaited(aData.as<MediaData::Type>());
} else {
OnNotWaited(aData.as<WaitForDataRejectValue>());
}
});
}
void
MediaDecoderStateMachine::CancelMediaDecoderReaderWrapperCallback()
{
MOZ_ASSERT(OnTaskQueue());
mAudioWaitCallback.Disconnect();
mVideoWaitCallback.Disconnect();
}
void MediaDecoderStateMachine::StopPlayback()
@ -3070,7 +3052,7 @@ MediaDecoderStateMachine::EnsureAudioDecodeTaskQueued()
if (!IsAudioDecoding() ||
IsRequestingAudioData() ||
mReader->IsWaitingAudioData()) {
IsWaitingAudioData()) {
return;
}
@ -3118,7 +3100,7 @@ MediaDecoderStateMachine::EnsureVideoDecodeTaskQueued()
if (!IsVideoDecoding() ||
IsRequestingVideoData() ||
mReader->IsWaitingVideoData()) {
IsWaitingVideoData()) {
return;
}
@ -3148,6 +3130,40 @@ MediaDecoderStateMachine::RequestVideoData(bool aSkipToNextKeyframe,
);
}
void
MediaDecoderStateMachine::WaitForData(MediaData::Type aType)
{
MOZ_ASSERT(OnTaskQueue());
MOZ_ASSERT(aType == MediaData::AUDIO_DATA || aType == MediaData::VIDEO_DATA);
if (aType == MediaData::AUDIO_DATA) {
mAudioWaitRequest.Begin(
mReader->WaitForData(MediaData::AUDIO_DATA)->Then(
OwnerThread(), __func__,
[this] (MediaData::Type aType) {
mAudioWaitRequest.Complete();
OnAudioWaited(aType);
},
[this] (const WaitForDataRejectValue& aRejection) {
mAudioWaitRequest.Complete();
OnNotWaited(aRejection);
})
);
} else {
mVideoWaitRequest.Begin(
mReader->WaitForData(MediaData::VIDEO_DATA)->Then(
OwnerThread(), __func__,
[this] (MediaData::Type aType) {
mVideoWaitRequest.Complete();
OnVideoWaited(aType);
},
[this] (const WaitForDataRejectValue& aRejection) {
mVideoWaitRequest.Complete();
OnNotWaited(aRejection);
})
);
}
}
void
MediaDecoderStateMachine::StartMediaSink()
{
@ -3376,6 +3392,7 @@ MediaDecoderStateMachine::Reset(TrackSet aTracks)
mVideoCompleted = false;
VideoQueue().Reset();
mVideoDataRequest.DisconnectIfExists();
mVideoWaitRequest.DisconnectIfExists();
}
if (aTracks.contains(TrackInfo::kAudioTrack)) {
@ -3383,6 +3400,7 @@ MediaDecoderStateMachine::Reset(TrackSet aTracks)
mAudioCompleted = false;
AudioQueue().Reset();
mAudioDataRequest.DisconnectIfExists();
mAudioWaitRequest.DisconnectIfExists();
}
mPlaybackOffset = 0;
@ -3786,9 +3804,9 @@ MediaDecoderStateMachine::AudioRequestStatus() const
{
MOZ_ASSERT(OnTaskQueue());
if (IsRequestingAudioData()) {
MOZ_DIAGNOSTIC_ASSERT(!mReader->IsWaitingAudioData());
MOZ_DIAGNOSTIC_ASSERT(!IsWaitingAudioData());
return "pending";
} else if (mReader->IsWaitingAudioData()) {
} else if (IsWaitingAudioData()) {
return "waiting";
}
return "idle";
@ -3799,9 +3817,9 @@ MediaDecoderStateMachine::VideoRequestStatus() const
{
MOZ_ASSERT(OnTaskQueue());
if (IsRequestingVideoData()) {
MOZ_DIAGNOSTIC_ASSERT(!mReader->IsWaitingVideoData());
MOZ_DIAGNOSTIC_ASSERT(!IsWaitingVideoData());
return "pending";
} else if (mReader->IsWaitingVideoData()) {
} else if (IsWaitingVideoData()) {
return "waiting";
}
return "idle";

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

@ -477,8 +477,12 @@ protected:
void RequestVideoData(bool aSkipToNextKeyframe,
const media::TimeUnit& aCurrentTime);
void WaitForData(MediaData::Type aType);
bool IsRequestingAudioData() const { return mAudioDataRequest.Exists(); }
bool IsRequestingVideoData() const { return mVideoDataRequest.Exists(); }
bool IsWaitingAudioData() const { return mAudioWaitRequest.Exists(); }
bool IsWaitingVideoData() const { return mVideoWaitRequest.Exists(); }
// Re-evaluates the state and determines whether we need to dispatch
// events to run the decode, or if not whether we should set the reader
@ -659,13 +663,12 @@ private:
// Only one of a given pair of ({Audio,Video}DataPromise, WaitForDataPromise)
// should exist at any given moment.
MediaEventListener mAudioWaitCallback;
MediaEventListener mVideoWaitCallback;
using MediaDataPromise = MediaDecoderReader::MediaDataPromise;
using WaitForDataPromise = MediaDecoderReader::WaitForDataPromise;
MozPromiseRequestHolder<MediaDataPromise> mAudioDataRequest;
MozPromiseRequestHolder<MediaDataPromise> mVideoDataRequest;
MozPromiseRequestHolder<WaitForDataPromise> mAudioWaitRequest;
MozPromiseRequestHolder<WaitForDataPromise> mVideoWaitRequest;
const char* AudioRequestStatus() const;
const char* VideoRequestStatus() const;