Bug 1171311: P1. Add MediaDataDemuxer::IsThreadSafe() method. r=cpearce

This commit is contained in:
Jean-Yves Avenard 2015-06-12 09:26:57 +10:00
parent be0c4421e7
commit dec5a2fb99
2 changed files with 13 additions and 1 deletions

View File

@ -50,6 +50,14 @@ public:
// again to retry once more data has been received.
virtual nsRefPtr<InitPromise> Init() = 0;
// MediaFormatReader ensures that calls to the MediaDataDemuxer are thread-safe.
// This is done by having multiple demuxers, created with Clone(), one per
// running thread.
// However, should the MediaDataDemuxer object guaranteed to be thread-safe
// such cloning is unecessary and only one demuxer will be used across
// all threads.
virtual bool IsThreadSafe() { return false; }
// Clone the demuxer and return a new initialized demuxer.
// This can only be called once Init() has succeeded.
// The new demuxer can be immediately use to retrieve the track demuxers.

View File

@ -341,7 +341,11 @@ MediaFormatReader::OnDemuxerInitDone(nsresult)
mSeekable = mDemuxer->IsSeekable();
// Create demuxer object for main thread.
mMainThreadDemuxer = mDemuxer->Clone();
if (mDemuxer->IsThreadSafe()) {
mMainThreadDemuxer = mDemuxer;
} else {
mMainThreadDemuxer = mDemuxer->Clone();
}
if (!mMainThreadDemuxer) {
mMetadataPromise.Reject(ReadMetadataFailureReason::METADATA_ERROR, __func__);
NS_WARNING("Unable to clone current MediaDataDemuxer");