import changes from `dev' branch of rmottola/Arctic-Fox:

- Bug 1144107 - Part 4: Prevent assert when hitting EOS. r=kentuckyfriedtakahe (4e66e9d148)
- Bug 1226842: Error rather than asserting when encountering error in sample table. r=gerald (4bbe6cd7f2)
- Bug 1189992: Don't assume the last chunk always contains the sample we're looking for. r=gerald (4cf3a3f63a)
- Bug 1225703 - Update in-tree libcubeb. r=padenot (49ce53e3c8)
- Bug 1203449 - Remove OutputStreamListener from DecodedStream.cpp. r=roc. (24421a02e1)
- Bug 1207915 - Apply the fix of bug 1052206 to DecodedStream. r=roc. (c73a3aecc6)
- Bug 1218311 - Port the fix of bug 1193614 to VideoSink. r=cpearce. (cbbe3dc1ab)
- Bug 1230338 - Record video frames dropped by the compositor, or while flushing during skip-to-keyframe. r=jya (edf53548d3)
- Bug 1230882. Part 1 - destroy DecodedStreamData properly when dispatch fails. r=roc. (adb3c05671)
- Bug 1230004. Part 1 - cache data in MDSM so it won't need to ask MediaDecoder. r=cpearce. (728c6b3e82)
- Bug 1219163. Part 1 - Remove unused functions from AbstractMediaDecoder. r=jya. (f1dba3d50c)
- Bug 1219163. Part 2 - Move some functions that are never called from the interface of AbstractMediaDecoder down the class hierarchy. r=jya. (c0fc72790f)
- Bug 1226569. Part 1 - Use MediaEventSource to publish MetadataLoaded and FirstFrameLoaded events. r=jya. (76195567a5)
- Bug 1226569. Part 2 - assert functions that should never be called after shutdown. r=jya. (672df604e5)
- Bug 1227797 - Use MediaEventSource to publish playback events for MDSM. r=jya. (4a3fda2f34)
- Bug 1228923 - Merge some MediaEventSource for MDSM. r=jya. (31929f5777)
- Bug 1228939 - 1. add mSeekable to MediaInfo. 2. use MediaEventSource to notify the decoder when the media is not seekable. 3. remove unused code. r=jya. (38fb6d1099)
- Bug 1230004. Part 2 - have MDSM::BeginShutdown return a promise and remove MDSM::mDecoder. r=cpearce. (0f45558e15)
- add some disabled EME stuff (c4fa7e65be)
- Bug 873438 - Implement IAccessible2_2::accessibleWithCaret, r=yzen (9fb71ce7f3)
- Bug 1159872 - Make IAccessible2::Get_States once again return S_OK when it detects a defunct accessible. r=surkov (91ad6d1798)
- bug 606080 - on windows give accessibles a unique 32 bit id r=surkov (848c16f16c)
- Bug 1220897 - fix IAccessible2::get_accessibleWithCaret, r=tbsaunde (492790b4e1)
- Bug 1225298 - Use GCHashMap for UniqueIdMap, r=terrence (ee896fb807)
- Bug 1227567 - Optimise module namespace imports in Ion where we have type information r=shu (19fdf97bc3)
- Bug 1230337 - Fix TypedArrayObject::isNeutered to stop calling typed arrays using inline storage neutered. (r=Waldo) (2838830319)
- Bug 1055472 - Part 1: Factor out GetPrototypeFromConstructor and use it in existing object creation paths. (r=Waldo) (a26c188064)
- Bug 1055472 - Part 2: Make the Function constructor properly subclassable. (r=Waldo) (e2ff4b48d4)
- Bug 1055472 - Part 2b: Make Function.prototype.bind play nicely with subclassed functions. (r=Waldo, shoutouts for good flyby by evilpie) (59b347ced4)
- Bug 1055472 - Part 3: Make the Object constructor properly subclassable. (r=Waldo) (aa23b6c005)
- Bug 1055472 - Part 4: Make the Boolean constructor properly subclassable. (r=Waldo) (6ff68c5198)
- Bug 1055472 - Part 5: Make the various Error constructors properly subclassable. (r=Waldo) (7e36f26bcd)
- Bug 1055472 - Part 6: Make the Number constructor properly subclassable. (r=Waldo) (5b081bb54c)
- Bug 1055472 - Part 7: Make the Date constructor properly subclassable. (r=Waldo) (a841523521)
- Bug 1055472 - Part 8 prelim: Rename InitializeRegExp to RegExpObject::initFromAtom for readability. (r=Waldo) (053ce20768)
- Bug 1055472 - Part 8: Make the RegExp constructor properly subclassable. (r=Waldo) (a522ecca25)
- Bug 1055472 - Part 9: Make the Map constructor properly subclassable. (r=Waldo) (a29bb1408a)
- Bug 1055472 - Part 10: Make the Set constructor properly subclassable. (r=Waldo) (82befdc508)
- Bug 1055472 - Part 11: Make the WeakMap constructor properly subclassable. (r=Waldo) (0ea50757d4)
- Bug 1055472 - Part 12: Mae the WeakSet constructor properly subclassable. (r=Waldo) (6ba67d4fe6)
- Bug 1055472 - Part 13: Make the ArrayBuffer constructor properly subclassable. (r=Waldo) (7811dadf92)
- Bug 1055472 - Part 14: Make the various TypedArray constructors properly subclassable. (r=Waldo, r=bhackett) (6bc10f8ec1)
- Bug 1055472 - Part 15: Make the DataView constructor properly subclassable. (r=jorendorff, r=bhackett) (b2b6aef1f6)
- Bug 1055472 - Part 16: Make the String constructor properly subclassable. (r=Waldo) (6bed2e45bc)
- Bug 1055472 - Part 17: Make the Array constructor properly subclassable. (r=jorendorff, r=bhackett, r=terrence) (d301fe9814)
- Bug 1055472 - Part 18: Incorportate arai's test into the subclassing suite. (r=me) (cfbc97738a)
- Bug 1226416 - Expose a method to get a node's set of immediately dominated nodes in the dominator tree; r=bz,sfink (8226985fb6)
- Bug 1199422 - Stop pattern matching class-constructors in String#replace and Array#sort. r=efaust (58b56ad143)
- Bug 1206308 - include nsprpub and zlib for Windows, plus minor enhancements to make-source-package.sh, r=sstangl (e933f3a27a)
- Bug 1229729 - Make make-source-package.sh work on OS X. r=sfink (d55f9bc552)
- Bug 1221747 - Make JS_vsnprintf() return a value that indicates failure if we reach the buffer limit r=nbp (1bc82ccafd)
- Bug 1227385 - Properly propagate $DIST from top-level after bug 1224490. r=mshal (ee4fc81981)
- Bug 1200304 - Move stumbling code from gonkgps to MozStumbler.cpp. r=jdm (89aea7211c)
- Bug 1207266 - turn off b2g stumbler if no RIL. r=jdm (ae42aeb5a2)
- Bug 1228947 - Replace mfbt/Constants.h with math.h. r=roc (d56e2bbe2f)
- Bug 1176261 - Discard gps with impossibly tiny accuracy. r=jaliu (93a4114ac7)
- Bug 772750 - Get mobile connection technology from MobileConnectionService. r=garvank,echen (742d68becb)
- Bug 1168068 - GonkGPSGeolocationProvider should use mRilDataServiceId in SetReferenceLocation. r=garvank (b07ee26cc4)
- Bug 1227385 - Avoid make variable references in VISIBILITY_FLAGS and STL_FLAGS. r=mshal (e3e7fc9d99)
- Bug 1225298 - Use GCHashSet for atoms table, r=terrence (4bce42238c)
- Bug 1225298 - Use GCHashSet for InnerViewTable, r=terrence (e8da10443c)
- Bug 1203297 - Fix one last bit of unified bustage; r=bbouvier (7395aca8da)
- Bug 1228340: Rename JitOptions into DefaultJitOptions and get rid of the js_ prefix for the instance; r=h4writer (19777f9a49)
- Bug 1227190 part 1. change PrepareScriptEnvironmentAndInvoke to return void, not bool, to make it clearer that it reports exceptions for you. r=jorendorff (7525efb3ad)
- Bug 1227190 part 2. Change PrepareScriptEnvironmentAndInvoke to take a JSContext*, not a JSRuntime*. r=jorendorff (01b69ccab1)
- Bug 1227190 part 3. Make debugger error reporting play nice with the embedding taking ownership of error reporting. r=jorendorff (008195b9a3)
- Bug 1221600 - Tweak comments about standard internal methods in jsobj.h, jsfriendapi.h. r=efaust. (c1a4b0e2bf)
- Bug 1223372 - Handle ToWindowProxyIfWindow returning a dead wrapper in PrepareForWrapping. r=bholley (0b3dd8084b)
- Bug 1197095 - ensure that ForOfIterator does not pass arguments to next calls; r=evilpie (29acf9b12d)
- Bug 1197094 - ForOfIterator calls ToObject on iterable; r=evilpie (533dd11111)
- Bug 1216379 - Throw less cryptic error message when using a non-iterable in a for...of loop. r=jorendorff (ae7d4c3734)
- Bug 1230010 - OdinMonkey: MIPS: Make immediate patching shared. r=luke (97b5650d3a)
- Bug 1131759 - Atomicize SharedScriptData::marked. (r=terrence) (bafe64c080)
- Bug 1229579 - Make class members properly XDR-able. (r=billm) (d95743694f)
- Bug 1227642: Make data a ScopedJSFreePtr in js::detail::CopyScript to ensure it doesn't leak; r=jonco (db8bcafc09)
- Bug 1227287 - Fix minor bug with f.arguments and lazy arguments. r=luke (9c1cc5aaad)
- Bug 1228947 - mingw fixup. (3216b8df21)
- Bug 1231163 - Don't assume the RNG's been initialized by a prior call to Math.random, when a call to Math.random is being inlined. (A method can be inlined once its identity has been guarded against, but mere identity can be established without the method having been called.) r=jwalden (d7e2235e63)
- crash stuff (12dfaea226)
- Bug 1218027 - "--with-system-icu fails: js/src/jsapi.cpp:69: error: visibility does not match previous declaration". r=mh+mozilla (5929f4280c)
- Bug 1229740 - add <array> to the list of wrapped system headers; r=glandium (990a0a22ab)
- Bug 1192312 - Use MediaCodecSource for camera recording since gonkL r=aosmond (f68121e622)
- Bug 1210293 - Remove legacy check from the XPIDL HTMLInputElement::SetUserInput. r=bz (f70fbfd8ea)
- Bug 1220323 - Enable FasterMake backend by default for all apps. r=gps (7421f68979)
- Fixup for b2g bustage from bug 1164921. r=me (6207a28039)
- Bug 1209391 - Remove build/unix/uniq.py. r=mshal (d757f44938)
- Bug 1192233 - delete check for sys/cdefs.h from configure; r=mshal (ca2709a478)
- Bug 1191816 - don't check for sys/int_types.h in configure; r=mshal (3f77884338)
- Bug 1182565 - Disable sandboxing on Linux Thread Sanitizer builds. r=kang (5dcd521ca1)
- missing bits of Bug 1157768 - Build files and config headers for libav fft (5ab19c5158)
- Bug 1149279 - Remove unused build config variable NSS_NO_LIBPKIX. r=gps (0abbcd89c3)
- Bug 1161238 - Remove --disable-logging. r=gps (b896b8f77d)
- Bug 1167201 - Make absence of gconf developer packages a fatal error rather than disabling gconf automatically in the build system. This is necessary because if gconf is disabled, many tests don't work because they use gconf to detect linux. r=glandium (4def45dc4f)
- bug 1220037 pack and unpack Nyquist for MOZ_LIBAV_FFT r=padenot (23e4e277ff)
- bug 1220041 remove unnecessary temp buffer and copy with libav FFT r=padenot (20df464d7b)
- bug 1220041 scale when copying for inverse FFT to avoid iterating twice r=padenot (d9c11db7e2)
- bug 1223520 avoid leaking NaNs to and from the otherwise unused imaginary frequency components r=padenot (0ff120a534)
- bug 1188704 remove now unused PerformInverseFFT() variation r=rillian (b82b4d459a)
- bug 1188704 add accessor functions for setting frequency components for inverse FFT r=rillian (c8357b6268)
- style (3b9fc23a34)
- Bug 1173016 - Properly refcount the inner PeriodicWave object. r=karlt (634e09bb79)
- bug 1187785 reverse tableInterpolationFactor to make it consistent with documentation r=rillian (928fa29f6c)
- bug 1188704 redefine halfSize as fftSize / 2 r=rillian (1cf36a13e3)
- bug 1188704 trim unnecessary extra basic waveform coeffient r=rillian (c33983684a)
- bug 1188704 simplify culling of partials r=rillian (484932e54e)
- bug 1188704 combine scaling with copying r=rillian (7e5d3f9c7d)
- bug 1188704 limit number of Fourier coefficients used to halfSize earlier r=rillian (abba4f31bb)
- bug 1188704 use existing FFTBlock arrays instead of allocating and copying and scaling r=rillian (74b58f3bc3)
- warnings (cf6c0840e8)
- Bug 1171436 - support at least 8192 elements for PeriodicWave r=padenot (7ddeb3ec3f)
- bug 1221831 remove unused Reverb::reset() r=padenot (913849471f)
- bug 1221831 remove unused Reverb::latencyFrames() r=padenot (767744e87c)
- bug 1221830 use WEBAUDIO_BLOCK_SIZE constant in Reverb methods r=padenot (38dc6b0a92)
- bug 1221831 use initial input buffer offset to control when convolver stages perform their FFT r=padenot (4f594ded7a)
- bug 1221831 remove now-unnecessary m_preDelayBuffer r=padenot (af5b36efdc)
- bug 1221830 use WEBAUDIO_BLOCK_SIZE slice size for background convolver thread r=padenot (0d6dbe1daa)
- bug 1221830 double maximum realtime convolver stage size to 2048 r=padenot (1cf7698f2d)
- bug 1221830 use WEBAUDIO_BLOCK_SIZE constant in FFTConvolver r=padenot (955e902db8)
- bug 1221833 reduce FFTConvolver latency by one block r=padenot (024b13396a)
- bug 1221833 replace initial direct convolution stage with fft r=padenot (70319e951b)
- bug 1221833 remove first two half-block-size convolver stages r=padenot (2709910848)
- bug 1221833 remove now-unused direct convolver r=padenot (d0cfb712af)
- bug 1221836 return output pointer from FFTConvolver::process() to save a buffer copy r=padenot (4bf6c5e6c8)
- Bug 1196608 - Link liblgpllibs against mozglue. r=mshal (3212491e68)
- missing bit of 1157768 (3d6844b56e)
- bug 1224102 reduce the size of the final FFT convolution stage if possible r=padenot (f1fbd7f04d)
- Bug 1192587 - Build media/libav in unified mode. r=qDot (77dd2810e3)
- Bug 1228230 - Rely more on top-level configure auto-detection. r=qdot (8add5f4014)
- Bug 1261414 - Don't build libav with sysctl on Unix (it's not used anyway). r=glandium (195c3ddba4)
- Bug 1222405 - (part 1) Store PeriodicWave components for later use r=padenot (a993b3303d)
- Bug 1222405 - (part 2) Build band limited tables after fundamental frequency is known r=padenot (d350f2e201)
- Bug 1222405 - (part 3) Build band limited tables lazily r=padenot (0dc6f013fc)
This commit is contained in:
2023-05-09 11:34:56 +08:00
parent 967126c55b
commit 9855d648fe
255 changed files with 5079 additions and 2547 deletions
+93 -121
View File
@@ -62,7 +62,7 @@ using namespace mozilla::media;
#undef VERBOSE_LOG
#define LOG(m, l, x, ...) \
MOZ_LOG(m, l, ("Decoder=%p " x, mDecoder.get(), ##__VA_ARGS__))
MOZ_LOG(m, l, ("Decoder=%p " x, mDecoderID, ##__VA_ARGS__))
#define DECODER_LOG(x, ...) \
LOG(gMediaDecoderLog, LogLevel::Debug, x, ##__VA_ARGS__)
#define VERBOSE_LOG(x, ...) \
@@ -74,7 +74,7 @@ using namespace mozilla::media;
// when __VA_ARGS__ expands to nothing. This is a workaround for it.
#define DECODER_WARN_HELPER(a, b) NS_WARNING b
#define DECODER_WARN(x, ...) \
DECODER_WARN_HELPER(0, (nsPrintfCString("Decoder=%p " x, mDecoder.get(), ##__VA_ARGS__).get()))
DECODER_WARN_HELPER(0, (nsPrintfCString("Decoder=%p " x, mDecoderID, ##__VA_ARGS__).get()))
// Certain constants get stored as member variables and then adjusted by various
// scale factors on a per-decoder basis. We want to make sure to avoid using these
@@ -199,7 +199,10 @@ static void InitVideoQueuePrefs() {
MediaDecoderStateMachine::MediaDecoderStateMachine(MediaDecoder* aDecoder,
MediaDecoderReader* aReader,
bool aRealTime) :
mDecoder(aDecoder),
mDecoderID(aDecoder),
mFrameStats(&aDecoder->GetFrameStatistics()),
mVideoFrameContainer(aDecoder->GetVideoFrameContainer()),
mAudioChannel(aDecoder->GetAudioChannel()),
mTaskQueue(new TaskQueue(GetMediaThreadPool(MediaThreadType::PLAYBACK),
/* aSupportsTailDispatch = */ true)),
mWatchManager(this, mTaskQueue),
@@ -280,7 +283,8 @@ MediaDecoderStateMachine::MediaDecoderStateMachine(MediaDecoder* aDecoder,
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
// Dispatch initialization that needs to happen on that task queue.
nsCOMPtr<nsIRunnable> r = NS_NewRunnableMethod(this, &MediaDecoderStateMachine::InitializationTask);
nsCOMPtr<nsIRunnable> r = NS_NewRunnableMethodWithArg<RefPtr<MediaDecoder>>(
this, &MediaDecoderStateMachine::InitializationTask, aDecoder);
mTaskQueue->Dispatch(r.forget());
InitVideoQueuePrefs();
@@ -305,6 +309,13 @@ MediaDecoderStateMachine::MediaDecoderStateMachine(MediaDecoder* aDecoder,
mMetadataManager.Connect(mReader->TimedMetadataEvent(), OwnerThread());
mMediaSink = CreateMediaSink(mAudioCaptured);
#ifdef MOZ_EME
mCDMProxyPromise.Begin(aDecoder->RequestCDMProxy()->Then(
OwnerThread(), __func__, this,
&MediaDecoderStateMachine::OnCDMProxyReady,
&MediaDecoderStateMachine::OnCDMProxyNotReady));
#endif
}
MediaDecoderStateMachine::~MediaDecoderStateMachine()
@@ -320,25 +331,25 @@ MediaDecoderStateMachine::~MediaDecoderStateMachine()
}
void
MediaDecoderStateMachine::InitializationTask()
MediaDecoderStateMachine::InitializationTask(MediaDecoder* aDecoder)
{
MOZ_ASSERT(OnTaskQueue());
// Connect mirrors.
mBuffered.Connect(mReader->CanonicalBuffered());
mEstimatedDuration.Connect(mDecoder->CanonicalEstimatedDuration());
mExplicitDuration.Connect(mDecoder->CanonicalExplicitDuration());
mPlayState.Connect(mDecoder->CanonicalPlayState());
mNextPlayState.Connect(mDecoder->CanonicalNextPlayState());
mLogicallySeeking.Connect(mDecoder->CanonicalLogicallySeeking());
mVolume.Connect(mDecoder->CanonicalVolume());
mLogicalPlaybackRate.Connect(mDecoder->CanonicalPlaybackRate());
mPreservesPitch.Connect(mDecoder->CanonicalPreservesPitch());
mSameOriginMedia.Connect(mDecoder->CanonicalSameOriginMedia());
mPlaybackBytesPerSecond.Connect(mDecoder->CanonicalPlaybackBytesPerSecond());
mPlaybackRateReliable.Connect(mDecoder->CanonicalPlaybackRateReliable());
mDecoderPosition.Connect(mDecoder->CanonicalDecoderPosition());
mMediaSeekable.Connect(mDecoder->CanonicalMediaSeekable());
mEstimatedDuration.Connect(aDecoder->CanonicalEstimatedDuration());
mExplicitDuration.Connect(aDecoder->CanonicalExplicitDuration());
mPlayState.Connect(aDecoder->CanonicalPlayState());
mNextPlayState.Connect(aDecoder->CanonicalNextPlayState());
mLogicallySeeking.Connect(aDecoder->CanonicalLogicallySeeking());
mVolume.Connect(aDecoder->CanonicalVolume());
mLogicalPlaybackRate.Connect(aDecoder->CanonicalPlaybackRate());
mPreservesPitch.Connect(aDecoder->CanonicalPreservesPitch());
mSameOriginMedia.Connect(aDecoder->CanonicalSameOriginMedia());
mPlaybackBytesPerSecond.Connect(aDecoder->CanonicalPlaybackBytesPerSecond());
mPlaybackRateReliable.Connect(aDecoder->CanonicalPlaybackRateReliable());
mDecoderPosition.Connect(aDecoder->CanonicalDecoderPosition());
mMediaSeekable.Connect(aDecoder->CanonicalMediaSeekable());
// Initialize watchers.
mWatchManager.Watch(mBuffered, &MediaDecoderStateMachine::BufferedRangeUpdated);
@@ -368,7 +379,7 @@ MediaDecoderStateMachine::CreateAudioSink()
MOZ_ASSERT(self->OnTaskQueue());
return new DecodedAudioDataSink(
self->mAudioQueue, self->GetMediaTime(),
self->mInfo.mAudio, self->mDecoder->GetAudioChannel());
self->mInfo.mAudio, self->mAudioChannel);
};
return new AudioSinkWrapper(mTaskQueue, audioSinkCreator);
}
@@ -384,8 +395,8 @@ MediaDecoderStateMachine::CreateMediaSink(bool aAudioCaptured)
RefPtr<media::MediaSink> mediaSink =
new VideoSink(mTaskQueue, audioSink, mVideoQueue,
mDecoder->GetVideoFrameContainer(), mRealTime,
mDecoder->GetFrameStatistics(), AUDIO_DURATION_USECS,
mVideoFrameContainer, mRealTime,
*mFrameStats,
sVideoQueueSendToCompositorSize);
return mediaSink.forget();
}
@@ -887,19 +898,6 @@ MediaDecoderStateMachine::OnVideoDecoded(MediaData* aVideoSample)
StopPrerollingVideo();
}
// Schedule the state machine to send stream data as soon as possible if
// the VideoQueue() is empty or contains one frame before the Push().
//
// The state machine threads requires a frame in VideoQueue() that is `in
// the future` to gather precise timing information. The head of
// VideoQueue() is always `in the past`.
//
// Schedule the state machine as soon as possible to render the video
// frame or delay the state machine thread accurately.
if (VideoQueue().GetSize() <= 2) {
ScheduleStateMachine();
}
// For non async readers, if the requested video sample was slow to
// arrive, increase the amount of audio we buffer to ensure that we
// don't run out of audio. This is unnecessary for async readers,
@@ -1058,7 +1056,7 @@ void MediaDecoderStateMachine::StopPlayback()
MOZ_ASSERT(OnTaskQueue());
DECODER_LOG("StopPlayback()");
mDecoder->DispatchPlaybackStopped();
mOnPlaybackEvent.Notify(MediaEventType::PlaybackStopped);
if (IsPlaying()) {
mMediaSink->SetPlaying(false);
@@ -1091,7 +1089,7 @@ void MediaDecoderStateMachine::MaybeStartPlayback()
}
DECODER_LOG("MaybeStartPlayback() starting playback");
mDecoder->DispatchPlaybackStarted();
mOnPlaybackEvent.Notify(MediaEventType::PlaybackStarted);
StartMediaSink();
if (!IsPlaying()) {
@@ -1303,7 +1301,8 @@ MediaDecoderStateMachine::SetDormant(bool aDormant)
}
}
void MediaDecoderStateMachine::Shutdown()
RefPtr<ShutdownPromise>
MediaDecoderStateMachine::Shutdown()
{
MOZ_ASSERT(OnTaskQueue());
@@ -1317,6 +1316,10 @@ void MediaDecoderStateMachine::Shutdown()
mPendingSeek.RejectIfExists(__func__);
mCurrentSeek.RejectIfExists(__func__);
#ifdef MOZ_EME
mCDMProxyPromise.DisconnectIfExists();
#endif
if (IsPlaying()) {
StopPlayback();
}
@@ -1330,13 +1333,16 @@ void MediaDecoderStateMachine::Shutdown()
mStartTimeRendezvous->Destroy();
}
DECODER_LOG("Shutdown started");
// Put a task in the decode queue to shutdown the reader.
// the queue to spin down.
InvokeAsync(DecodeTaskQueue(), mReader.get(), __func__, &MediaDecoderReader::Shutdown)
return InvokeAsync(DecodeTaskQueue(), mReader.get(), __func__,
&MediaDecoderReader::Shutdown)
->Then(OwnerThread(), __func__, this,
&MediaDecoderStateMachine::FinishShutdown,
&MediaDecoderStateMachine::FinishShutdown);
DECODER_LOG("Shutdown started");
&MediaDecoderStateMachine::FinishShutdown)
->CompletionPromise();
}
void MediaDecoderStateMachine::StartDecoding()
@@ -1599,12 +1605,7 @@ MediaDecoderStateMachine::InitiateSeek()
StopPlayback();
UpdatePlaybackPositionInternal(mCurrentSeek.mTarget.mTime);
nsCOMPtr<nsIRunnable> startEvent =
NS_NewRunnableMethodWithArg<MediaDecoderEventVisibility>(
mDecoder,
&MediaDecoder::SeekingStarted,
mCurrentSeek.mTarget.mEventVisibility);
AbstractThread::MainThread()->Dispatch(startEvent.forget());
mOnSeekingStart.Notify(mCurrentSeek.mTarget.mEventVisibility);
// Reset our state machine and decoding pipeline before seeking.
Reset();
@@ -1897,9 +1898,7 @@ MediaDecoderStateMachine::DecodeError()
// MediaDecoder::DecodeError notifies the owner, and then shuts down the state
// machine.
nsCOMPtr<nsIRunnable> event =
NS_NewRunnableMethod(mDecoder, &MediaDecoder::DecodeError);
AbstractThread::MainThread()->Dispatch(event.forget());
mOnPlaybackEvent.Notify(MediaEventType::DecodeError);
}
void
@@ -1916,7 +1915,6 @@ MediaDecoderStateMachine::OnMetadataRead(MetadataHolder* aMetadata)
// Set mode to PLAYBACK after reading metadata.
mResource->SetReadMode(MediaCacheStream::MODE_PLAYBACK);
mDecoder->DispatchSetMediaSeekable(mReader->IsMediaSeekable());
mInfo = aMetadata->mInfo;
mMetadataTags = aMetadata->mTags.forget();
RefPtr<MediaDecoderStateMachine> self = this;
@@ -1964,7 +1962,11 @@ MediaDecoderStateMachine::OnMetadataRead(MetadataHolder* aMetadata)
// thus get the metadata). We could fix this if we could compute the start
// time by demuxing without necessaring decoding.
bool waitingForCDM =
#ifdef MOZ_EME
mInfo.IsEncrypted() && !mCDMProxy;
#else
false;
#endif
mNotifyMetadataBeforeFirstFrame = mDuration.Ref().isSome() || waitingForCDM;
if (mNotifyMetadataBeforeFirstFrame) {
EnqueueLoadedMetadataEvent();
@@ -1996,14 +1998,12 @@ void
MediaDecoderStateMachine::EnqueueLoadedMetadataEvent()
{
MOZ_ASSERT(OnTaskQueue());
nsAutoPtr<MediaInfo> info(new MediaInfo());
*info = mInfo;
MediaDecoderEventVisibility visibility = mSentLoadedMetadataEvent?
MediaDecoderEventVisibility::Suppressed :
MediaDecoderEventVisibility::Observable;
nsCOMPtr<nsIRunnable> metadataLoadedEvent =
new MetadataEventRunner(mDecoder, info, mMetadataTags, visibility);
AbstractThread::MainThread()->Dispatch(metadataLoadedEvent.forget());
MediaDecoderEventVisibility visibility =
mSentLoadedMetadataEvent ? MediaDecoderEventVisibility::Suppressed
: MediaDecoderEventVisibility::Observable;
mMetadataLoadedEvent.Notify(nsAutoPtr<MediaInfo>(new MediaInfo(mInfo)),
Move(mMetadataTags),
Move(visibility));
mSentLoadedMetadataEvent = true;
}
@@ -2011,14 +2011,11 @@ void
MediaDecoderStateMachine::EnqueueFirstFrameLoadedEvent()
{
MOZ_ASSERT(OnTaskQueue());
nsAutoPtr<MediaInfo> info(new MediaInfo());
*info = mInfo;
MediaDecoderEventVisibility visibility = mSentFirstFrameLoadedEvent?
MediaDecoderEventVisibility::Suppressed :
MediaDecoderEventVisibility::Observable;
nsCOMPtr<nsIRunnable> event =
new FirstFrameLoadedEventRunner(mDecoder, info, visibility);
AbstractThread::MainThread()->Dispatch(event.forget());
MediaDecoderEventVisibility visibility =
mSentFirstFrameLoadedEvent ? MediaDecoderEventVisibility::Suppressed
: MediaDecoderEventVisibility::Observable;
mFirstFrameLoadedEvent.Notify(nsAutoPtr<MediaInfo>(new MediaInfo(mInfo)),
Move(visibility));
mSentFirstFrameLoadedEvent = true;
}
@@ -2159,46 +2156,19 @@ MediaDecoderStateMachine::SeekCompleted()
if (video) {
mMediaSink->Redraw();
nsCOMPtr<nsIRunnable> event =
NS_NewRunnableMethod(mDecoder, &MediaDecoder::Invalidate);
AbstractThread::MainThread()->Dispatch(event.forget());
mOnPlaybackEvent.Notify(MediaEventType::Invalidate);
}
}
class DecoderDisposer
{
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(DecoderDisposer)
DecoderDisposer(MediaDecoder* aDecoder, MediaDecoderStateMachine* aStateMachine)
: mDecoder(aDecoder), mStateMachine(aStateMachine) {}
void OnTaskQueueShutdown()
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(mStateMachine);
MOZ_ASSERT(mDecoder);
mStateMachine->BreakCycles();
mDecoder->BreakCycles();
mStateMachine = nullptr;
mDecoder = nullptr;
}
private:
virtual ~DecoderDisposer() {}
RefPtr<MediaDecoder> mDecoder;
RefPtr<MediaDecoderStateMachine> mStateMachine;
};
void
MediaDecoderStateMachine::DispatchShutdown()
RefPtr<ShutdownPromise>
MediaDecoderStateMachine::BeginShutdown()
{
mStreamSink->BeginShutdown();
nsCOMPtr<nsIRunnable> runnable =
NS_NewRunnableMethod(this, &MediaDecoderStateMachine::Shutdown);
OwnerThread()->Dispatch(runnable.forget());
return InvokeAsync(OwnerThread(), this, __func__,
&MediaDecoderStateMachine::Shutdown);
}
void
RefPtr<ShutdownPromise>
MediaDecoderStateMachine::FinishShutdown()
{
MOZ_ASSERT(OnTaskQueue());
@@ -2239,25 +2209,8 @@ MediaDecoderStateMachine::FinishShutdown()
MOZ_ASSERT(mState == DECODER_STATE_SHUTDOWN,
"How did we escape from the shutdown state?");
// We must daisy-chain these events to destroy the decoder. We must
// destroy the decoder on the main thread, but we can't destroy the
// decoder while this thread holds the decoder monitor. We can't
// dispatch an event to the main thread to destroy the decoder from
// here, as the event may run before the dispatch returns, and we
// hold the decoder monitor here. We also want to guarantee that the
// state machine is destroyed on the main thread, and so the
// event runner running this function (which holds a reference to the
// state machine) needs to finish and be released in order to allow
// that. So we dispatch an event to run after this event runner has
// finished and released its monitor/references. That event then will
// dispatch an event to the main thread to release the decoder and
// state machine.
DECODER_LOG("Shutting down state machine task queue");
RefPtr<DecoderDisposer> disposer = new DecoderDisposer(mDecoder, this);
OwnerThread()->BeginShutdown()->Then(AbstractThread::MainThread(), __func__,
disposer.get(),
&DecoderDisposer::OnTaskQueueShutdown,
&DecoderDisposer::OnTaskQueueShutdown);
return OwnerThread()->BeginShutdown();
}
nsresult MediaDecoderStateMachine::RunStateMachine()
@@ -2414,9 +2367,7 @@ nsresult MediaDecoderStateMachine::RunStateMachine()
// Ensure readyState is updated before firing the 'ended' event.
UpdateNextFrameStatus();
nsCOMPtr<nsIRunnable> event =
NS_NewRunnableMethod(mDecoder, &MediaDecoder::PlaybackEnded);
AbstractThread::MainThread()->Dispatch(event.forget());
mOnPlaybackEvent.Notify(MediaEventType::PlaybackEnded);
mSentPlaybackEndedEvent = true;
@@ -2482,7 +2433,7 @@ MediaDecoderStateMachine::CheckFrameValidity(VideoData* aData)
// Update corrupt-frames statistics
if (aData->mImage && !aData->mImage->IsValid()) {
FrameStatistics& frameStats = mDecoder->GetFrameStatistics();
FrameStatistics& frameStats = *mFrameStats;
frameStats.NotifyCorruptFrame();
// If more than 10% of the last 30 frames have been corrupted, then try disabling
// hardware acceleration. We use 10 as the corrupt value because RollingMean<>
@@ -2915,6 +2866,27 @@ void MediaDecoderStateMachine::OnMediaSinkAudioError()
DecodeError();
}
#ifdef MOZ_EME
void
MediaDecoderStateMachine::OnCDMProxyReady(RefPtr<CDMProxy> aProxy)
{
MOZ_ASSERT(OnTaskQueue());
mCDMProxyPromise.Complete();
mCDMProxy = aProxy;
mReader->SetCDMProxy(aProxy);
if (mState == DECODER_STATE_WAIT_FOR_CDM) {
StartDecoding();
}
}
void
MediaDecoderStateMachine::OnCDMProxyNotReady()
{
MOZ_ASSERT(OnTaskQueue());
mCDMProxyPromise.Complete();
}
#endif
void
MediaDecoderStateMachine::SetAudioCaptured(bool aCaptured)
{