Bug 1391142. P1 - dispatch IsLiveStream changes from MediaDecoder to MDSM.
This allows us to remove the dependency on MediaResource from MDSM in P2.
MozReview-Commit-ID: I46fWXfnGQK
--- a/dom/media/MediaDecoder.cpp
+++ b/dom/media/MediaDecoder.cpp
@@ -677,16 +677,21 @@ MediaDecoder::DiscardOngoingSeekIfExists
void
MediaDecoder::CallSeek(const SeekTarget& aTarget)
{
MOZ_ASSERT(NS_IsMainThread());
AbstractThread::AutoEnter context(AbstractMainThread());
DiscardOngoingSeekIfExists();
+ // Since we don't have a listener for changes in IsLiveStream, our best bet
+ // is to ensure IsLiveStream is uptodate when seek begins. This value will be
+ // checked when seek is completed.
+ mDecoderStateMachine->DispatchIsLiveStream(GetResource()->IsLiveStream());
+
mDecoderStateMachine->InvokeSeek(aTarget)
->Then(mAbstractMainThread, __func__, this,
&MediaDecoder::OnSeekResolved, &MediaDecoder::OnSeekRejected)
->Track(mSeekRequest);
}
double
MediaDecoder::GetCurrentTime()
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -2465,18 +2465,17 @@ DecodingState::MaybeStartBuffering()
}
void
MediaDecoderStateMachine::
SeekingState::SeekCompleted()
{
const auto newCurrentTime = CalculateNewCurrentTime();
- bool isLiveStream = Resource()->IsLiveStream();
- if (newCurrentTime == mMaster->Duration() && !isLiveStream) {
+ if (newCurrentTime == mMaster->Duration() && !mMaster->mIsLiveStream) {
// Seeked to end of media. Explicitly finish the queues so DECODING
// will transition to COMPLETED immediately. Note we don't do
// this when playing a live stream, since the end of media will advance
// once we download more data!
AudioQueue().Finish();
VideoQueue().Finish();
// We won't start MediaSink when paused. m{Audio,Video}Completed will
--- a/dom/media/MediaDecoderStateMachine.h
+++ b/dom/media/MediaDecoderStateMachine.h
@@ -214,16 +214,27 @@ public:
nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction(
"MediaDecoderStateMachine::DispatchCanPlayThrough",
[self, aCanPlayThrough]() {
self->mCanPlayThrough = aCanPlayThrough;
});
OwnerThread()->DispatchStateChange(r.forget());
}
+ void DispatchIsLiveStream(bool aIsLiveStream)
+ {
+ RefPtr<MediaDecoderStateMachine> self = this;
+ nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction(
+ "MediaDecoderStateMachine::DispatchIsLiveStream",
+ [self, aIsLiveStream]() {
+ self->mIsLiveStream = aIsLiveStream;
+ });
+ OwnerThread()->DispatchStateChange(r.forget());
+ }
+
// Drop reference to mResource. Only called during shutdown dance.
void BreakCycles() {
MOZ_ASSERT(NS_IsMainThread());
mResource = nullptr;
}
TimedMetadataEventSource& TimedMetadataEvent() {
return mMetadataManager.TimedMetadataEvent();
@@ -579,16 +590,18 @@ private:
const char* AudioRequestStatus() const;
const char* VideoRequestStatus() const;
void OnSuspendTimerResolved();
void CancelSuspendTimer();
bool mCanPlayThrough = false;
+ bool mIsLiveStream = false;
+
// True if we shouldn't play our audio (but still write it to any capturing
// streams). When this is true, the audio thread will never start again after
// it has stopped.
bool mAudioCaptured;
// True if all audio frames are already rendered.
bool mAudioCompleted = false;