Skip to content

Commit

Permalink
Merge m-c to autoland, a=merge
Browse files Browse the repository at this point in the history
  • Loading branch information
KWierso committed Oct 20, 2016
2 parents 0e54f17 + 6631230 commit 2b2380a
Show file tree
Hide file tree
Showing 27 changed files with 100 additions and 233 deletions.
4 changes: 4 additions & 0 deletions dom/html/HTMLMediaElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2210,11 +2210,15 @@ class HTMLMediaElement::StreamCaptureTrackSource :
nsString())
, mCapturedTrackSource(aCapturedTrackSource)
{
mCapturedTrackSource->RegisterSink(this);
}

void Destroy() override
{
MOZ_ASSERT(mCapturedTrackSource);
if (mCapturedTrackSource) {
mCapturedTrackSource->UnregisterSink(this);
}
}

MediaSourceEnum GetMediaSource() const override
Expand Down
23 changes: 0 additions & 23 deletions dom/media/MediaStreamTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,22 +387,6 @@ MediaStreamTrack::Clone()
return newStream->CloneDOMTrack(*this, mTrackID);
}

void
MediaStreamTrack::SetReadyState(MediaStreamTrackState aState)
{
MOZ_ASSERT(!(mReadyState == MediaStreamTrackState::Ended &&
aState == MediaStreamTrackState::Live),
"We don't support overriding the ready state from ended to live");

if (mReadyState == MediaStreamTrackState::Live &&
aState == MediaStreamTrackState::Ended &&
mSource) {
mSource->UnregisterSink(this);
}

mReadyState = aState;
}

void
MediaStreamTrack::NotifyEnded()
{
Expand All @@ -414,13 +398,6 @@ MediaStreamTrack::NotifyEnded()

LOG(LogLevel::Info, ("MediaStreamTrack %p ended", this));

if (!mSource) {
MOZ_ASSERT(false);
return;
}

mSource->UnregisterSink(this);

mReadyState = MediaStreamTrackState::Ended;

DispatchTrustedEvent(NS_LITERAL_STRING("ended"));
Expand Down
2 changes: 1 addition & 1 deletion dom/media/MediaStreamTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ class MediaStreamTrack : public DOMEventTargetHelper,
* Forces the ready state to a particular value, for instance when we're
* cloning an already ended track.
*/
void SetReadyState(MediaStreamTrackState aState);
void SetReadyState(MediaStreamTrackState aState) { mReadyState = aState; }

/**
* Notified by the MediaStreamGraph, through our owning MediaStream on the
Expand Down
33 changes: 8 additions & 25 deletions dom/media/tests/mochitest/mediaStreamPlayback.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ MediaStreamPlayback.prototype = {
* @param {Boolean} isResume specifies if this media element is being resumed
* from a previous run
*/
playMedia : function(isResume) {
playMediaWithMediaStreamTracksStop : function(isResume) {
this.startMedia(isResume);
return this.verifyPlaying()
.then(() => this.stopTracksForStreamInMediaPlayback())
.then(() => this.detachFromMediaElement());
.then(() => this.stopMediaElement());
},

/**
Expand Down Expand Up @@ -80,15 +80,15 @@ MediaStreamPlayback.prototype = {

/**
* Starts media with a media stream, runs it until a canplaythrough and
* timeupdate event fires, and detaches from the element without stopping media.
* timeupdate event fires, and stops the media.
*
* @param {Boolean} isResume specifies if this media element is being resumed
* from a previous run
*/
playMediaWithoutStoppingTracks : function(isResume) {
playMedia : function(isResume) {
this.startMedia(isResume);
return this.verifyPlaying()
.then(() => this.detachFromMediaElement());
.then(() => this.stopMediaElement());
},

/**
Expand Down Expand Up @@ -156,12 +156,12 @@ MediaStreamPlayback.prototype = {
},

/**
* Detaches from the element without stopping the media.
* Stops the media with the associated stream.
*
* Precondition: The media stream and element should both be actively
* being played.
*/
detachFromMediaElement : function() {
stopMediaElement : function() {
this.mediaElement.pause();
this.mediaElement.srcObject = null;
}
Expand Down Expand Up @@ -198,7 +198,7 @@ LocalMediaStreamPlayback.prototype = Object.create(MediaStreamPlayback.prototype
this.startMedia(isResume);
return this.verifyPlaying()
.then(() => this.deprecatedStopStreamInMediaPlayback())
.then(() => this.detachFromMediaElement());
.then(() => this.stopMediaElement());
}
},

Expand Down Expand Up @@ -254,23 +254,6 @@ function createHTML(options) {
return scriptsReady.then(() => realCreateHTML(options));
}

var pushPrefs = (...p) => new Promise(r => SpecialPowers.pushPrefEnv({set: p}, r));

// noGum - Helper to detect whether active guM tracks still exist.
//
// It relies on the fact that, by spec, device labels from enumerateDevices are
// only visible during active gum calls. They're also visible when persistent
// permissions are granted, so turn off media.navigator.permission.disabled
// (which is normally on otherwise in our tests). Lastly, we must turn on
// media.navigator.permission.fake otherwise fake devices don't count as active.

var noGum = () => pushPrefs(["media.navigator.permission.disabled", false],
["media.navigator.permission.fake", true])
.then(() => navigator.mediaDevices.enumerateDevices())
.then(([device]) => device &&
is(device.label, "", "Test must leave no active gUM streams behind."));

var runTest = testFunction => scriptsReady
.then(() => runTestWhenReady(testFunction))
.then(() => noGum())
.then(() => finish());
1 change: 0 additions & 1 deletion dom/media/tests/mochitest/mochitest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ skip-if = android_version == '18' # android(Bug 1189784, timeouts on 4.3 emulato
[test_getUserMedia_stopVideoAudioStreamWithFollowupVideoAudio.html]
[test_getUserMedia_stopVideoStream.html]
[test_getUserMedia_stopVideoStreamWithFollowupVideo.html]
[test_getUserMedia_trackCloneCleanup.html]
[test_getUserMedia_trackEnded.html]
[test_getUserMedia_peerIdentity.html]
[test_peerConnection_addIceCandidate.html]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

var testElem = createMediaElement('video', 'testAddTrackAudioVideo');
var playback = new LocalMediaStreamPlayback(testElem, stream);
return playback.playMedia(false);
return playback.playMediaWithMediaStreamTracksStop(false);
}))
.then(() => getUserMedia({video: true})).then(stream =>
getUserMedia({video: true}).then(otherStream => {
Expand All @@ -44,7 +44,7 @@

var test = createMediaElement('video', 'testAddTrackDoubleVideo');
var playback = new LocalMediaStreamPlayback(test, stream);
return playback.playMedia(false);
return playback.playMediaWithMediaStreamTracksStop(false);
}))
.then(() => getUserMedia({video: true})).then(stream =>
getUserMedia({video: true}).then(otherStream => {
Expand Down Expand Up @@ -81,7 +81,7 @@
stream.addTrack(track);
checkMediaStreamContains(stream, [track], "Re-added added-then-removed track");
var playback = new LocalMediaStreamPlayback(elem, stream);
return playback.playMedia(false);
return playback.playMediaWithMediaStreamTracksStop(false);
})
.then(() => otherTrack.stop());
}))
Expand All @@ -99,7 +99,7 @@

var elem = createMediaElement('video', 'testAddRemoveOriginalTrackVideo');
var playback = new LocalMediaStreamPlayback(elem, audioStream);
return playback.playMedia(false);
return playback.playMediaWithMediaStreamTracksStop(false);
}))
.then(() => {
var ac = new AudioContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
var stream;
var clone;
var newStream;
var tracks = [];

var addTrack = track => {
info("Adding track " + track.id);
Expand Down Expand Up @@ -50,14 +49,15 @@
})
.then(s => {
newStream = s;

info("Stopping an original track");
stopTrack(stream.getTracks()[0]);

return spinEventLoop();
})
.then(() => {
info("Removing original tracks");
stream.getTracks().forEach(t => (stream.removeTrack(t), tracks.push(t)));
stream.getTracks().forEach(t => stream.removeTrack(t));

return spinEventLoop();
})
Expand Down Expand Up @@ -89,7 +89,6 @@
.then(() => {
info("Stopping originals");
stream.getTracks().forEach(t => stopTrack(t));
tracks.forEach(t => stopTrack(t));

return spinEventLoop();
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
]))
.then(() => playback.verifyPlaying()) // still playing
.then(() => playback.deprecatedStopStreamInMediaPlayback())
.then(() => playback.detachFromMediaElement());
.then(() => playback.stopMediaElement());
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
]))
.then(() => playback.verifyPlaying()) // still playing
.then(() => playback.deprecatedStopStreamInMediaPlayback())
.then(() => playback.detachFromMediaElement());
.then(() => playback.stopMediaElement());
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
ok(video.videoHeight > 0, "Expected nonzero video width");
resolve();
});
})
.then(() => stream.getTracks().forEach(t => t.stop()));
});
});
});

Expand Down
10 changes: 3 additions & 7 deletions dom/media/tests/mochitest/test_getUserMedia_bug1223696.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@
});

runTest(() => Promise.resolve()
.then(() => getUserMedia({audio:true, video: true})).then(stream => {
.then(() => getUserMedia({audio:true, video: true})).then(stream => {
info("Test addTrack()ing a video track to an audio-only gUM stream");

var video = createMediaElement("video", "test_video_track");
video.srcObject = stream;
video.play();

var h = new CaptureStreamTestHelper2D();
var removedTrack = stream.getVideoTracks()[0];
stream.removeTrack(removedTrack);
stream.removeTrack(stream.getVideoTracks()[0]);
video.onloadeddata = () => {
info("loadeddata");
var canvas = document.createElement("canvas");
Expand All @@ -41,10 +40,7 @@

return listenUntil(video, "loadeddata", () => true)
.then(() => h.waitForPixelColor(video, h.grey, 5,
"The canvas track should be rendered by the media element"))
.then(() => {
[removedTrack, ...stream.getAudioTracks()].forEach(t => t.stop());
});
"The canvas track should be rendered by the media element"));
}));
</script>
</pre>
Expand Down
77 changes: 40 additions & 37 deletions dom/media/tests/mochitest/test_getUserMedia_constraints.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,50 +102,53 @@
* test by verifying that the right resolution and rejection is fired.
*/

runTest(() => Promise.resolve()
.then(() => {
// Check supported constraints first.
var dict = navigator.mediaDevices.getSupportedConstraints();
var supported = Object.keys(dict);
runTest(function() {

mustSupport.forEach(key => ok(supported.indexOf(key) != -1 && dict[key],
"Supports " + key));
// Check supported constraints first.
var dict = navigator.mediaDevices.getSupportedConstraints();
var supported = Object.keys(dict);

var unexpected = supported.filter(key => mustSupport.indexOf(key) == -1);
is(unexpected.length, 0,
"Unanticipated support (please update test): " + unexpected);
})
.then(() => pushPrefs(["media.getusermedia.browser.enabled", false],
["media.getusermedia.screensharing.enabled", false]))
.then(() => tests.reduce((p, test) => p.then(() => getUserMedia(test.constraints))
.then(stream => {
is(null, test.error, test.message);
stream.getTracks().forEach(t => t.stop());
}, e => {
mustSupport.forEach(key => ok(supported.indexOf(key) != -1 && dict[key],
"Supports " + key));

var unexpected = supported.filter(key => mustSupport.indexOf(key) == -1);
is(unexpected.length, 0,
"Unanticipated support (please update test): " + unexpected);

// Run constraint tests

var p = new Promise(resolve => SpecialPowers.pushPrefEnv({
set : [ ['media.getusermedia.browser.enabled', false],
['media.getusermedia.screensharing.enabled', false] ]
}, resolve));

return tests.reduce((p, test) =>
p.then(() => navigator.mediaDevices.getUserMedia(test.constraints))
.then(() => is(null, test.error, test.message), e => {
is(e.name, test.error, test.message + ": " + e.message);
if (test.constraint) {
is(e.constraint, test.constraint,
test.message + " w/correct constraint.");
}
}), Promise.resolve()))
.then(() => getUserMedia({video: true, audio: true}))
.then(stream => stream.getVideoTracks()[0].applyConstraints({ width: 320 })
.then(() => stream.getAudioTracks()[0].applyConstraints({ }))
.then(() => {
stream.getTracks().forEach(track => track.stop());
ok(true, "applyConstraints code exercised");
}))
// TODO: Test outcome once fake devices support constraints (Bug 1088621)
.then(() => mustFailWith("applyConstraints fails on non-Gum tracks",
"OverconstrainedError", "",
() => (new AudioContext())
.createMediaStreamDestination().stream
.getAudioTracks()[0].applyConstraints()))
.then(() => mustFailWith(
"getUserMedia with unsatisfied required constraint",
"OverconstrainedError", "deviceId",
() => getUserMedia({ audio: true,
video: { deviceId: { exact: "unheardof" } } }))));
}), p)
.then(() => navigator.mediaDevices.getUserMedia({video: true, audio: true}))
.then(stream => stream.getVideoTracks()[0].applyConstraints({ width: 320 })
.then(() => stream.getAudioTracks()[0].applyConstraints({ })))
.then(() => ok(true, "applyConstraints code exercised"))
// TODO: Test outcome once fake devices support constraints (Bug 1088621)
.then(() => mustFailWith("applyConstraints fails on non-Gum tracks",
"OverconstrainedError", "",
() => (new AudioContext())
.createMediaStreamDestination().stream
.getAudioTracks()[0].applyConstraints()))
.then(() => mustFailWith(
"getUserMedia with unsatisfied required constraint",
"OverconstrainedError", "deviceId",
() => navigator.mediaDevices.getUserMedia({
audio: true,
video: { deviceId: { exact: "unheardof" } },
})));
});

</script>
</pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
newStream.addTrack(videoTrack);
is(newStream.getTrackById(videoTrack.id), videoTrack,
"getTrackByid with matching id should return the track");
[audioTrack, videoTrack].forEach(t => t.stop());
});
});

Expand Down
12 changes: 5 additions & 7 deletions dom/media/tests/mochitest/test_getUserMedia_loadedmetadata.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@
var constraints = {video: true, audio: true};
return getUserMedia(constraints).then(stream => new Promise(resolve => {
v.srcObject = stream;
v.onloadedmetadata = () => {
isnot(v.videoWidth, 0, "videoWidth shall be set on 'loadedmetadata'");
isnot(v.videoHeight, 0, "videoHeight shall be set on 'loadedmetadata'");
resolve();
};
})
.then(() => stream.getTracks().forEach(t => t.stop())));
v.onloadedmetadata = resolve;
})).then(() => {
isnot(v.videoWidth, 0, "videoWidth shall be set on 'loadedmetadata'");
isnot(v.videoHeight, 0, "videoHeight shall be set on 'loadedmetadata'");
});
});

</script>
Expand Down
Loading

0 comments on commit 2b2380a

Please sign in to comment.