Bug 1208316 - A media element should autoplay a MediaStream that becomes active. r?jib
MozReview-Commit-ID: 98H7REtqShI
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -3991,16 +3991,23 @@ public:
mElement->NotifyMediaStreamTrackAdded(aTrack);
}
void NotifyTrackRemoved(const RefPtr<MediaStreamTrack>& aTrack) override
{
mElement->NotifyMediaStreamTrackRemoved(aTrack);
}
+ void NotifyActive() override
+ {
+ LOG(LogLevel::Debug, ("%p, mSrcStream %p became active",
+ mElement, mElement->mSrcStream.get()));
+ mElement->CheckAutoplayDataReady();
+ }
+
void NotifyInactive() override
{
LOG(LogLevel::Debug, ("%p, mSrcStream %p became inactive",
mElement, mElement->mSrcStream.get()));
MOZ_ASSERT(!mElement->mSrcStream->Active());
if (mElement->mMediaStreamListener) {
mElement->mMediaStreamListener->Forget();
}
@@ -4463,16 +4470,22 @@ void HTMLMediaElement::PlaybackEnded()
if (HasAttr(kNameSpaceID_None, nsGkAtoms::loop)) {
SetCurrentTime(0);
return;
}
Pause();
+ if (mSrcStream) {
+ // A MediaStream that goes from inactive to active shall be eligible for
+ // autoplay again according to the mediacapture-main spec.
+ mAutoplaying = true;
+ }
+
FireTimeUpdate(false);
DispatchAsyncEvent(NS_LITERAL_STRING("ended"));
}
void HTMLMediaElement::SeekStarted()
{
DispatchAsyncEvent(NS_LITERAL_STRING("seeking"));
}
@@ -4904,19 +4917,20 @@ void HTMLMediaElement::ChangeNetworkStat
// Changing mNetworkState affects AddRemoveSelfReference().
AddRemoveSelfReference();
}
bool HTMLMediaElement::CanActivateAutoplay()
{
// For stream inputs, we activate autoplay on HAVE_NOTHING because
// this element itself might be blocking the stream from making progress by
- // being paused. We also activate autopaly when playing a media source since
- // the data download is controlled by the script and there is no way to
- // evaluate MediaDecoder::CanPlayThrough().
+ // being paused. We only check that it has data by checking its active state.
+ // We also activate autoplay when playing a media source since the data
+ // download is controlled by the script and there is no way to evaluate
+ // MediaDecoder::CanPlayThrough().
if (!HasAttr(kNameSpaceID_None, nsGkAtoms::autoplay) || !mAutoplayEnabled) {
return false;
}
if (!mAutoplaying) {
return false;
}
@@ -4930,17 +4944,18 @@ bool HTMLMediaElement::CanActivateAutopl
}
if (mPausedForInactiveDocumentOrChannel) {
return false;
}
bool hasData =
(mDecoder && mReadyState >= nsIDOMHTMLMediaElement::HAVE_ENOUGH_DATA) ||
- mSrcStream || mMediaSource;
+ (mSrcStream && mSrcStream->Active()) ||
+ mMediaSource;
return hasData;
}
void HTMLMediaElement::CheckAutoplayDataReady()
{
if (!CanActivateAutoplay()) {
return;