Bug 1325905. Part 2 - move IsWaitForDataSupported() assertions into MediaDecoderReaderWrapper.
MozReview-Commit-ID: 6KwjHONHKo
--- a/dom/media/MediaDecoderReaderWrapper.cpp
+++ b/dom/media/MediaDecoderReaderWrapper.cpp
@@ -8,17 +8,21 @@
#include "MediaDecoderReaderWrapper.h"
namespace mozilla {
MediaDecoderReaderWrapper::MediaDecoderReaderWrapper(AbstractThread* aOwnerThread,
MediaDecoderReader* aReader)
: mOwnerThread(aOwnerThread)
, mReader(aReader)
-{}
+{
+ // Must support either heuristic buffering or WaitForData().
+ MOZ_ASSERT(mReader->UseBufferingHeuristics() ||
+ mReader->IsWaitForDataSupported());
+}
MediaDecoderReaderWrapper::~MediaDecoderReaderWrapper()
{}
media::TimeUnit
MediaDecoderReaderWrapper::StartTime() const
{
MOZ_ASSERT(mOwnerThread->IsCurrentThreadIn());
@@ -87,16 +91,17 @@ MediaDecoderReaderWrapper::Seek(const Se
&MediaDecoderReader::Seek,
Move(adjustedTarget));
}
RefPtr<MediaDecoderReaderWrapper::WaitForDataPromise>
MediaDecoderReaderWrapper::WaitForData(MediaData::Type aType)
{
MOZ_ASSERT(mOwnerThread->IsCurrentThreadIn());
+ MOZ_ASSERT(mReader->IsWaitForDataSupported());
return InvokeAsync(mReader->OwnerThread(), mReader.get(), __func__,
&MediaDecoderReader::WaitForData, aType);
}
void
MediaDecoderReaderWrapper::ReleaseResources()
{
MOZ_ASSERT(mOwnerThread->IsCurrentThreadIn());
--- a/dom/media/MediaDecoderReaderWrapper.h
+++ b/dom/media/MediaDecoderReaderWrapper.h
@@ -47,17 +47,16 @@ public:
RefPtr<SeekPromise> Seek(const SeekTarget& aTarget);
RefPtr<ShutdownPromise> Shutdown();
void ReleaseResources();
void ResetDecode(TrackSet aTracks);
nsresult Init() { return mReader->Init(); }
- bool IsWaitForDataSupported() const { return mReader->IsWaitForDataSupported(); }
bool IsAsync() const { return mReader->IsAsync(); }
bool UseBufferingHeuristics() const { return mReader->UseBufferingHeuristics(); }
bool VideoIsHardwareAccelerated() const {
return mReader->VideoIsHardwareAccelerated();
}
TimedMetadataEventSource& TimedMetadataEvent() {
return mReader->TimedMetadataEvent();
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -231,18 +231,18 @@ protected:
MediaResource* Resource() const { return mMaster->mResource; }
MediaDecoderReaderWrapper* Reader() const { return mMaster->mReader; }
const MediaInfo& Info() const { return mMaster->Info(); }
bool IsExpectingMoreData() const
{
// We are expecting more data if either the resource states so, or if we
// have a waiting promise pending (such as with non-MSE EME).
return Resource()->IsExpectingMoreData() ||
- (Reader()->IsWaitForDataSupported() &&
- (mMaster->IsWaitingAudioData() || mMaster->IsWaitingVideoData()));
+ mMaster->IsWaitingAudioData() ||
+ mMaster->IsWaitingVideoData();
}
MediaQueue<MediaData>& AudioQueue() const { return mMaster->mAudioQueue; }
MediaQueue<MediaData>& VideoQueue() const { return mMaster->mVideoQueue; }
// Note this function will delete the current state object.
// Don't access members to avoid UAF after this call.
template <class S, typename... Ts>
auto SetState(Ts... aArgs)
@@ -1741,18 +1741,16 @@ MediaDecoderStateMachine::
StateObject::HandleNotDecoded(MediaData::Type aType, const MediaResult& aError)
{
bool isAudio = aType == MediaData::AUDIO_DATA;
MOZ_ASSERT_IF(!isAudio, aType == MediaData::VIDEO_DATA);
// 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) {
- MOZ_ASSERT(Reader()->IsWaitForDataSupported(),
- "Readers that send WAITING_FOR_DATA need to implement WaitForData");
mMaster->WaitForData(aType);
HandleWaitingForData();
return;
}
if (aError == NS_ERROR_DOM_MEDIA_CANCELED) {
if (isAudio) {
mMaster->EnsureAudioDecodeTaskQueued();
@@ -2072,17 +2070,16 @@ DecodingState::MaybeStartBuffering()
}
bool shouldBuffer;
if (Reader()->UseBufferingHeuristics()) {
shouldBuffer = IsExpectingMoreData() &&
mMaster->HasLowDecodedData() &&
mMaster->HasLowBufferedData();
} else {
- MOZ_ASSERT(Reader()->IsWaitForDataSupported());
shouldBuffer =
(mMaster->OutOfDecodedAudio() && mMaster->IsWaitingAudioData()) ||
(mMaster->OutOfDecodedVideo() && mMaster->IsWaitingVideoData());
}
if (shouldBuffer) {
SetState<BufferingState>();
}
}
@@ -2160,18 +2157,16 @@ BufferingState::Step()
IsExpectingMoreData()) {
SLOG("Buffering: wait %ds, timeout in %.3lfs",
mBufferingWait, mBufferingWait - elapsed.ToSeconds());
mMaster->ScheduleStateMachineIn(USECS_PER_S);
mMaster->DispatchDecodeTasksIfNeeded();
return;
}
} else if (mMaster->OutOfDecodedAudio() || mMaster->OutOfDecodedVideo()) {
- MOZ_ASSERT(Reader()->IsWaitForDataSupported(),
- "Don't yet have a strategy for non-heuristic + non-WaitForData");
mMaster->DispatchDecodeTasksIfNeeded();
MOZ_ASSERT(mMaster->mMinimizePreroll ||
!mMaster->OutOfDecodedAudio() ||
mMaster->IsRequestingAudioData() ||
mMaster->IsWaitingAudioData());
MOZ_ASSERT(mMaster->mMinimizePreroll ||
!mMaster->OutOfDecodedVideo() ||
mMaster->IsRequestingVideoData() ||