Backed out changeset db3c2a88f79c (bug 1502927) for mochitest failures on test_reduce_time_precision.

This commit is contained in:
Cosmin Sabou 2018-11-05 19:46:42 +02:00
parent 40a58cb720
commit dd34f6cbd5
10 changed files with 62 additions and 7 deletions

View File

@ -32,10 +32,23 @@
#include "nsRFPService.h"
#include "nsServiceManagerUtils.h"
// GetCurrentTime is defined in winbase.h as zero argument macro forwarding to
// GetTickCount() and conflicts with NS_DECL_NSIDOMMEDIASTREAM, containing
// currentTime getter.
#ifdef GetCurrentTime
#undef GetCurrentTime
#endif
#ifdef LOG
#undef LOG
#endif
// GetCurrentTime is defined in winbase.h as zero argument macro forwarding to
// GetTickCount() and conflicts with MediaStream::GetCurrentTime.
#ifdef GetCurrentTime
#undef GetCurrentTime
#endif
using namespace mozilla;
using namespace mozilla::dom;
using namespace mozilla::layers;
@ -401,9 +414,9 @@ NS_INTERFACE_MAP_END_INHERITING(DOMMediaStream)
DOMMediaStream::DOMMediaStream(nsPIDOMWindowInner* aWindow,
MediaStreamTrackSourceGetter* aTrackSourceGetter)
: mWindow(aWindow), mInputStream(nullptr), mOwnedStream(nullptr),
mPlaybackStream(nullptr), mTracksPendingRemoval(0),
mTrackSourceGetter(aTrackSourceGetter),
: mLogicalStreamStartTime(0), mWindow(aWindow),
mInputStream(nullptr), mOwnedStream(nullptr), mPlaybackStream(nullptr),
mTracksPendingRemoval(0), mTrackSourceGetter(aTrackSourceGetter),
mPlaybackTrackListener(MakeAndAddRef<PlaybackTrackListener>(this)),
mTracksCreated(false), mNotifiedOfMediaStreamGraphShutdown(false),
mActive(false), mSetInactiveOnFinish(false), mCORSMode(CORS_NONE)
@ -552,6 +565,20 @@ DOMMediaStream::Constructor(const GlobalObject& aGlobal,
return newStream.forget();
}
double
DOMMediaStream::CurrentTime()
{
if (!mPlaybackStream) {
return 0.0;
}
// The value of a MediaStream's CurrentTime will always advance forward; it will never
// reset (even if one rewinds a video.) Therefore we can use a single Random Seed
// initialized at the same time as the object.
return nsRFPService::ReduceTimePrecisionAsSecs(mPlaybackStream->
StreamTimeToSeconds(mPlaybackStream->GetCurrentTime() - mLogicalStreamStartTime),
GetRandomTimelineSeed());
}
already_AddRefed<Promise>
DOMMediaStream::CountUnderlyingStreams(const GlobalObject& aGlobal, ErrorResult& aRv)
{

View File

@ -19,6 +19,12 @@
#include "mozilla/RelativeTimeline.h"
#include "PrincipalChangeObserver.h"
// X11 has a #define for CurrentTime. Unbelievable :-(.
// See dom/media/webaudio/AudioContext.h for more fun!
#ifdef CurrentTime
#undef CurrentTime
#endif
namespace mozilla {
class AbstractThread;
@ -351,6 +357,8 @@ public:
const dom::Sequence<OwningNonNull<MediaStreamTrack>>& aTracks,
ErrorResult& aRv);
double CurrentTime();
static already_AddRefed<dom::Promise>
CountUnderlyingStreams(const dom::GlobalObject& aGlobal, ErrorResult& aRv);
@ -514,6 +522,11 @@ public:
nsIPrincipal* aPrincipal,
MediaStreamGraph* aGraph);
void SetLogicalStreamStartTime(StreamTime aTime)
{
mLogicalStreamStartTime = aTime;
}
/**
* Adds a MediaStreamTrack to mTracks and raises "addtrack".
*
@ -649,6 +662,9 @@ protected:
// the principal changes.
void RecomputePrincipal();
// StreamTime at which the currentTime attribute would return 0.
StreamTime mLogicalStreamStartTime;
// We need this to track our parent object.
nsCOMPtr<nsPIDOMWindowInner> mWindow;

View File

@ -1312,6 +1312,10 @@ public:
return;
}
// Start currentTime from the point where this stream was successfully
// returned.
aStream->SetLogicalStreamStartTime(aStream->GetPlaybackStream()->GetCurrentTime());
// This is safe since we're on main-thread, and the windowlist can only
// be invalidated from the main-thread (see OnNavigation)
LOG(("Returning success for getUserMedia()"));

View File

@ -1221,6 +1221,9 @@ class RTCPeerConnection {
}
addTrack(track, stream) {
if (stream.currentTime === undefined) {
throw new this._win.DOMException("invalid stream.", "InvalidParameterError");
}
this._checkClosed();
if (this._transceivers.some(

View File

@ -38,6 +38,7 @@ function startTest(test) {
var stream;
var checkEnded = function() {
is(stream.currentTime, vout.currentTime, test.name + " stream final currentTime");
if (test.duration) {
isGreaterThanOrEqualEps(vout.currentTime, test.duration,
test.name + " current time at end");
@ -57,6 +58,7 @@ function startTest(test) {
var onloadedmetadata = function (ev) {
stream = v.mozCaptureStreamUntilEnded();
is(stream.currentTime, 0, test.name + " stream initial currentTime");
vout.srcObject = stream;
is(vout.srcObject, stream, test.name + " set output element .srcObject correctly");
v.play();

View File

@ -92,10 +92,12 @@ MediaStreamPlayback.prototype = {
* Verifies that media is playing.
*/
verifyPlaying : function() {
var lastStreamTime = this.mediaStream.currentTime;
var lastElementTime = this.mediaElement.currentTime;
var mediaTimeProgressed = listenUntil(this.mediaElement, 'timeupdate',
() => this.mediaElement.currentTime > lastElementTime);
() => this.mediaStream.currentTime > lastStreamTime &&
this.mediaElement.currentTime > lastElementTime);
return timeout(Promise.all([this.canPlayThroughFired, mediaTimeProgressed]),
VERIFYPLAYING_TIMEOUT_LENGTH, "verifyPlaying timed out")

View File

@ -75,7 +75,7 @@ runNetworkTest(function() {
.then(() => pcall(pc1, pc1.setRemoteDescription, pc2.localDescription))
.then(() => delivered)
// .then(() => canPlayThrough) // why doesn't this fire?
.then(() => waitUntil(() => v2.currentTime > 0))
.then(() => waitUntil(() => v2.currentTime > 0 && v2.srcObject.currentTime > 0))
.then(() => ok(v2.currentTime > 0, "v2.currentTime is moving (" + v2.currentTime + ")"))
.then(() => ok(true, "Connected."))
.then(() => pcall(pc1, pc1.getStats, null))

View File

@ -51,7 +51,7 @@
.then(() => pc1.setRemoteDescription(pc2.localDescription))
.then(() => delivered)
// .then(() => canPlayThrough) // why doesn't this fire?
.then(() => waitUntil(() => v2.currentTime > 0))
.then(() => waitUntil(() => v2.currentTime > 0 && v2.srcObject.currentTime > 0))
.then(() => ok(v2.currentTime > 0, "v2.currentTime is moving (" + v2.currentTime + ")"))
.then(() => ok(true, "Connected."))
.catch(reason => ok(false, "unexpected failure: " + reason))

View File

@ -64,7 +64,7 @@
await v2loadedmetadata;
await waitUntil(() => v2.currentTime > 0);
await waitUntil(() => v2.currentTime > 0 && v2.srcObject.currentTime > 0);
ok(v2.currentTime > 0, "v2.currentTime is moving (" + v2.currentTime + ")");
ok(v1.videoWidth > 0, "source width is positive");

View File

@ -39,6 +39,7 @@ interface MediaStream : EventTarget {
readonly attribute boolean active;
attribute EventHandler onaddtrack;
attribute EventHandler onremovetrack;
readonly attribute double currentTime;
[ChromeOnly, Throws]
static Promise<long> countUnderlyingStreams();