bug 1161892 use separate thread pool for platform decoder task queues r=bholley

so that platform decoder tasks will run when their readers wait and block
their thread pool.

--HG--
extra : rebase_source : 6d2e3f1c1937991d746ea9754f39add4d184e413
This commit is contained in:
Karl Tomlinson 2015-05-07 16:01:43 +12:00
parent 2340828e61
commit 69631c815f
7 changed files with 43 additions and 12 deletions

View File

@ -344,7 +344,7 @@ MediaDecoderReader::EnsureTaskQueue()
{
if (!mTaskQueue) {
MOZ_ASSERT(!mTaskQueueIsBorrowed);
RefPtr<SharedThreadPool> pool(GetMediaThreadPool());
RefPtr<SharedThreadPool> pool(GetMediaThreadPool(MediaThreadType::PLAYBACK));
MOZ_DIAGNOSTIC_ASSERT(pool);
mTaskQueue = new MediaTaskQueue(pool.forget());
}

View File

@ -202,7 +202,8 @@ MediaDecoderStateMachine::MediaDecoderStateMachine(MediaDecoder* aDecoder,
MediaDecoderReader* aReader,
bool aRealTime) :
mDecoder(aDecoder),
mTaskQueue(new MediaTaskQueue(GetMediaThreadPool(), /* aAssertTailDispatch = */ true)),
mTaskQueue(new MediaTaskQueue(GetMediaThreadPool(MediaThreadType::PLAYBACK),
/* aAssertTailDispatch = */ true)),
mWatchManager(this, mTaskQueue),
mRealTime(aRealTime),
mDispatchedStateMachine(false),

View File

@ -197,10 +197,22 @@ IsValidVideoRegion(const nsIntSize& aFrame, const nsIntRect& aPicture,
aDisplay.width * aDisplay.height != 0;
}
TemporaryRef<SharedThreadPool> GetMediaThreadPool()
TemporaryRef<SharedThreadPool> GetMediaThreadPool(MediaThreadType aType)
{
return SharedThreadPool::Get(NS_LITERAL_CSTRING("Media Playback"),
Preferences::GetUint("media.num-decode-threads", 25));
const char *name;
switch (aType) {
case MediaThreadType::PLATFORM_DECODER:
name = "MediaPDecoder";
break;
default:
MOZ_ASSERT(false);
case MediaThreadType::PLAYBACK:
name = "MediaPlayback";
break;
}
return SharedThreadPool::
Get(nsDependentCString(name),
Preferences::GetUint("media.num-decode-threads", 12));
}
bool
@ -304,7 +316,8 @@ class CreateTaskQueueTask : public nsRunnable {
public:
NS_IMETHOD Run() {
MOZ_ASSERT(NS_IsMainThread());
mTaskQueue = new MediaTaskQueue(GetMediaThreadPool());
mTaskQueue =
new MediaTaskQueue(GetMediaThreadPool(MediaThreadType::PLATFORM_DECODER));
return NS_OK;
}
nsRefPtr<MediaTaskQueue> mTaskQueue;
@ -314,7 +327,8 @@ class CreateFlushableTaskQueueTask : public nsRunnable {
public:
NS_IMETHOD Run() {
MOZ_ASSERT(NS_IsMainThread());
mTaskQueue = new FlushableMediaTaskQueue(GetMediaThreadPool());
mTaskQueue =
new FlushableMediaTaskQueue(GetMediaThreadPool(MediaThreadType::PLATFORM_DECODER));
return NS_OK;
}
nsRefPtr<FlushableMediaTaskQueue> mTaskQueue;

View File

@ -216,9 +216,22 @@ private:
class SharedThreadPool;
// The MediaDataDecoder API blocks, with implementations waiting on platform
// decoder tasks. These platform decoder tasks are queued on a separate
// thread pool to ensure they can run when the MediaDataDecoder clients'
// thread pool is blocked. Tasks on the PLATFORM_DECODER thread pool must not
// wait on tasks in the PLAYBACK thread pool.
//
// No new dependencies on this mechanism should be added, as methods are being
// made async supported by MediaPromise, making this unnecessary and
// permitting unifying the pool.
enum class MediaThreadType {
PLAYBACK, // MediaDecoderStateMachine and MediaDecoderReader
PLATFORM_DECODER
};
// Returns the thread pool that is shared amongst all decoder state machines
// for decoding streams.
TemporaryRef<SharedThreadPool> GetMediaThreadPool();
TemporaryRef<SharedThreadPool> GetMediaThreadPool(MediaThreadType aType);
enum H264_PROFILE {
H264_PROFILE_UNKNOWN = 0,

View File

@ -289,10 +289,12 @@ MP4Reader::Init(MediaDecoderReader* aCloneDonor)
InitLayersBackendType();
mAudio.mTaskQueue = new FlushableMediaTaskQueue(GetMediaThreadPool());
mAudio.mTaskQueue =
new FlushableMediaTaskQueue(GetMediaThreadPool(MediaThreadType::PLATFORM_DECODER));
NS_ENSURE_TRUE(mAudio.mTaskQueue, NS_ERROR_FAILURE);
mVideo.mTaskQueue = new FlushableMediaTaskQueue(GetMediaThreadPool());
mVideo.mTaskQueue =
new FlushableMediaTaskQueue(GetMediaThreadPool(MediaThreadType::PLATFORM_DECODER));
NS_ENSURE_TRUE(mVideo.mTaskQueue, NS_ERROR_FAILURE);
static bool sSetupPrefCache = false;

View File

@ -77,7 +77,7 @@ private:
};
SharedDecoderManager::SharedDecoderManager()
: mTaskQueue(new FlushableMediaTaskQueue(GetMediaThreadPool()))
: mTaskQueue(new FlushableMediaTaskQueue(GetMediaThreadPool(MediaThreadType::PLATFORM_DECODER)))
, mActiveProxy(nullptr)
, mActiveCallback(nullptr)
, mWaitForInternalDrain(false)

View File

@ -53,7 +53,8 @@ TrackBuffer::TrackBuffer(MediaSourceDecoder* aParentDecoder, const nsACString& a
{
MOZ_COUNT_CTOR(TrackBuffer);
mParser = ContainerParser::CreateForMIMEType(aType);
mTaskQueue = new MediaTaskQueue(GetMediaThreadPool());
mTaskQueue =
new MediaTaskQueue(GetMediaThreadPool(MediaThreadType::PLAYBACK));
aParentDecoder->AddTrackBuffer(this);
mDecoderPerSegment = Preferences::GetBool("media.mediasource.decoder-per-segment", false);
MSE_DEBUG("TrackBuffer created for parent decoder %p", aParentDecoder);