Bug 1173001 - Initialize reader task queue in the constructor. r=jww

This is a necessary step towards having mirrored/canonical values, since those
need to know the task queue in their constructor.
This commit is contained in:
Bobby Holley 2015-06-08 17:16:42 -07:00
parent 487810d0fc
commit 00f60b175b
12 changed files with 34 additions and 60 deletions

View File

@ -60,14 +60,16 @@ public:
size_t mSize;
};
MediaDecoderReader::MediaDecoderReader(AbstractMediaDecoder* aDecoder)
MediaDecoderReader::MediaDecoderReader(AbstractMediaDecoder* aDecoder,
MediaTaskQueue* aBorrowedTaskQueue)
: mAudioCompactor(mAudioQueue)
, mDecoder(aDecoder)
, mTaskQueue(aBorrowedTaskQueue ? aBorrowedTaskQueue : new MediaTaskQueue(GetMediaThreadPool(MediaThreadType::PLAYBACK)))
, mIgnoreAudioOutputFormat(false)
, mStartTime(-1)
, mHitAudioDecodeError(false)
, mShutdown(false)
, mTaskQueueIsBorrowed(false)
, mTaskQueueIsBorrowed(!!aBorrowedTaskQueue)
, mAudioDiscontinuity(false)
, mVideoDiscontinuity(false)
{
@ -331,19 +333,6 @@ MediaDecoderReader::RequestAudioData()
return p;
}
MediaTaskQueue*
MediaDecoderReader::EnsureTaskQueue()
{
if (!mTaskQueue) {
MOZ_ASSERT(!mTaskQueueIsBorrowed);
RefPtr<SharedThreadPool> pool(GetMediaThreadPool(MediaThreadType::PLAYBACK));
MOZ_DIAGNOSTIC_ASSERT(pool);
mTaskQueue = new MediaTaskQueue(pool.forget());
}
return mTaskQueue;
}
void
MediaDecoderReader::BreakCycles()
{

View File

@ -79,7 +79,7 @@ public:
// The caller must ensure that Shutdown() is called before aDecoder is
// destroyed.
explicit MediaDecoderReader(AbstractMediaDecoder* aDecoder);
explicit MediaDecoderReader(AbstractMediaDecoder* aDecoder, MediaTaskQueue* aBorrowedTaskQueue = nullptr);
// Initializes the reader, returns NS_OK on success, or NS_ERROR_FAILURE
// on failure.
@ -107,18 +107,9 @@ public:
// thread.
virtual nsRefPtr<ShutdownPromise> Shutdown();
MediaTaskQueue* EnsureTaskQueue();
virtual bool OnTaskQueue()
{
return !GetTaskQueue() || GetTaskQueue()->IsCurrentThreadIn();
}
void SetBorrowedTaskQueue(MediaTaskQueue* aTaskQueue)
{
MOZ_ASSERT(!mTaskQueue && aTaskQueue);
mTaskQueue = aTaskQueue;
mTaskQueueIsBorrowed = true;
return GetTaskQueue()->IsCurrentThreadIn();
}
// Resets all state related to decoding, emptying all buffers etc.
@ -320,6 +311,9 @@ protected:
// Reference to the owning decoder object.
AbstractMediaDecoder* mDecoder;
// Decode task queue.
nsRefPtr<MediaTaskQueue> mTaskQueue;
// Stores presentation info required for playback.
MediaInfo mInfo;
@ -347,7 +341,6 @@ private:
MediaPromiseHolder<AudioDataPromise> mBaseAudioPromise;
MediaPromiseHolder<VideoDataPromise> mBaseVideoPromise;
nsRefPtr<MediaTaskQueue> mTaskQueue;
bool mTaskQueueIsBorrowed;
// Flags whether a the next audio/video sample comes after a "gap" or

View File

@ -1258,10 +1258,6 @@ nsresult MediaDecoderStateMachine::Init(MediaDecoderStateMachine* aCloneDonor)
{
MOZ_ASSERT(NS_IsMainThread());
if (NS_WARN_IF(!mReader->EnsureTaskQueue())) {
return NS_ERROR_FAILURE;
}
MediaDecoderReader* cloneReader = nullptr;
if (aCloneDonor) {
cloneReader = aCloneDonor->mReader;

View File

@ -61,8 +61,9 @@ TrackTypeToStr(TrackInfo::TrackType aTrack)
}
MediaFormatReader::MediaFormatReader(AbstractMediaDecoder* aDecoder,
MediaDataDemuxer* aDemuxer)
: MediaDecoderReader(aDecoder)
MediaDataDemuxer* aDemuxer,
MediaTaskQueue* aBorrowedTaskQueue)
: MediaDecoderReader(aDecoder, aBorrowedTaskQueue)
, mDemuxer(aDemuxer)
, mAudio(this, MediaData::AUDIO_DATA, Preferences::GetUint("media.audio-decode-ahead", 2))
, mVideo(this, MediaData::VIDEO_DATA, Preferences::GetUint("media.video-decode-ahead", 2))

View File

@ -30,7 +30,8 @@ class MediaFormatReader final : public MediaDecoderReader
public:
explicit MediaFormatReader(AbstractMediaDecoder* aDecoder,
MediaDataDemuxer* aDemuxer);
MediaDataDemuxer* aDemuxer,
MediaTaskQueue* aBorrowedTaskQueue = nullptr);
virtual ~MediaFormatReader();

View File

@ -144,8 +144,8 @@ InvokeAndRetry(ThisType* aThisVal, ReturnType(ThisType::*aMethod)(), MP4Stream*
}
}
MP4Reader::MP4Reader(AbstractMediaDecoder* aDecoder)
: MediaDecoderReader(aDecoder)
MP4Reader::MP4Reader(AbstractMediaDecoder* aDecoder, MediaTaskQueue* aBorrowedTaskQueue)
: MediaDecoderReader(aDecoder, aBorrowedTaskQueue)
, mAudio(MediaData::AUDIO_DATA, Preferences::GetUint("media.mp4-audio-decode-ahead", 2))
, mVideo(MediaData::VIDEO_DATA, Preferences::GetUint("media.mp4-video-decode-ahead", 2))
, mLastReportedNumDecodedFrames(0)

View File

@ -34,7 +34,7 @@ class MP4Reader final : public MediaDecoderReader
typedef TrackInfo::TrackType TrackType;
public:
explicit MP4Reader(AbstractMediaDecoder* aDecoder);
explicit MP4Reader(AbstractMediaDecoder* aDecoder, MediaTaskQueue* aBorrowedTaskQueue = nullptr);
virtual ~MP4Reader();

View File

@ -36,7 +36,6 @@ public:
decoder->SetResource(resource);
reader->Init(nullptr);
reader->EnsureTaskQueue();
{
// This needs to be done before invoking GetBuffered. This is normally
// done by MediaDecoderStateMachine.

View File

@ -678,7 +678,8 @@ MediaSourceReader::ReleaseMediaResources()
}
MediaDecoderReader*
CreateReaderForType(const nsACString& aType, AbstractMediaDecoder* aDecoder)
CreateReaderForType(const nsACString& aType, AbstractMediaDecoder* aDecoder,
MediaTaskQueue* aBorrowedTaskQueue)
{
#ifdef MOZ_FMP4
// The MP4Reader that supports fragmented MP4 and uses
@ -691,15 +692,15 @@ CreateReaderForType(const nsACString& aType, AbstractMediaDecoder* aDecoder)
bool useFormatDecoder =
Preferences::GetBool("media.mediasource.format-reader.mp4", true);
MediaDecoderReader* reader = useFormatDecoder ?
static_cast<MediaDecoderReader*>(new MediaFormatReader(aDecoder, new MP4Demuxer(aDecoder->GetResource()))) :
static_cast<MediaDecoderReader*>(new MP4Reader(aDecoder));
static_cast<MediaDecoderReader*>(new MediaFormatReader(aDecoder, new MP4Demuxer(aDecoder->GetResource()), aBorrowedTaskQueue)) :
static_cast<MediaDecoderReader*>(new MP4Reader(aDecoder, aBorrowedTaskQueue));
return reader;
}
#endif
#ifdef MOZ_WEBM
if (DecoderTraits::IsWebMType(aType)) {
return new WebMReader(aDecoder);
return new WebMReader(aDecoder, aBorrowedTaskQueue);
}
#endif
@ -712,10 +713,17 @@ MediaSourceReader::CreateSubDecoder(const nsACString& aType, int64_t aTimestampO
if (IsShutdown()) {
return nullptr;
}
MOZ_ASSERT(GetTaskQueue());
// The task queue borrowing is icky. It would be nicer to just give each subreader
// its own task queue. Unfortunately though, Request{Audio,Video}Data implementations
// currently assert that they're on "the decode thread", and so having
// separate task queues makes MediaSource stuff unnecessarily cumbersome. We
// should remove the need for these assertions (which probably involves making
// all Request*Data implementations fully async), and then get rid of the
// borrowing.
nsRefPtr<SourceBufferDecoder> decoder =
new SourceBufferDecoder(new SourceBufferResource(aType), mDecoder, aTimestampOffset);
nsRefPtr<MediaDecoderReader> reader(CreateReaderForType(aType, decoder));
nsRefPtr<MediaDecoderReader> reader(CreateReaderForType(aType, decoder, GetTaskQueue()));
if (!reader) {
return nullptr;
}
@ -728,15 +736,6 @@ MediaSourceReader::CreateSubDecoder(const nsACString& aType, int64_t aTimestampO
reader->SetStartTime(0);
}
// This part is icky. It would be nicer to just give each subreader its own
// task queue. Unfortunately though, Request{Audio,Video}Data implementations
// currently assert that they're on "the decode thread", and so having
// separate task queues makes MediaSource stuff unnecessarily cumbersome. We
// should remove the need for these assertions (which probably involves making
// all Request*Data implementations fully async), and then get rid of the
// borrowing.
reader->SetBorrowedTaskQueue(GetTaskQueue());
#ifdef MOZ_FMP4
reader->SetSharedDecoderManager(mSharedDecoderManager);
#endif

View File

@ -211,10 +211,6 @@ MediaDecodeTask::CreateReader()
return false;
}
if (!mDecoderReader->EnsureTaskQueue()) {
return false;
}
return true;
}

View File

@ -161,8 +161,8 @@ ogg_packet InitOggPacket(const unsigned char* aData, size_t aLength,
static bool sIsIntelDecoderEnabled = false;
#endif
WebMReader::WebMReader(AbstractMediaDecoder* aDecoder)
: MediaDecoderReader(aDecoder)
WebMReader::WebMReader(AbstractMediaDecoder* aDecoder, MediaTaskQueue* aBorrowedTaskQueue)
: MediaDecoderReader(aDecoder, aBorrowedTaskQueue)
, mContext(nullptr)
, mPacketCount(0)
, mOpusDecoder(nullptr)

View File

@ -141,7 +141,7 @@ public:
class WebMReader : public MediaDecoderReader
{
public:
explicit WebMReader(AbstractMediaDecoder* aDecoder);
explicit WebMReader(AbstractMediaDecoder* aDecoder, MediaTaskQueue* aBorrowedTaskQueue = nullptr);
protected:
~WebMReader();