Merge remote-tracking branch 'origin/tracking' into custom

This commit is contained in:
roytam1 2023-10-11 11:56:50 +08:00
commit d6590573ed
22 changed files with 198 additions and 235 deletions

View file

@ -2876,8 +2876,8 @@ SourceMediaStream::AddDirectTrackListenerImpl(already_AddRefed<DirectMediaStream
TrackID aTrackID)
{
MOZ_ASSERT(IsTrackIDExplicit(aTrackID));
TrackData* data;
bool found = false;
TrackData* updateData = nullptr;
StreamTracks::Track* track = nullptr;
bool isAudio = false;
bool isVideo = false;
RefPtr<DirectMediaStreamTrackListener> listener = aListener;
@ -2886,44 +2886,29 @@ SourceMediaStream::AddDirectTrackListenerImpl(already_AddRefed<DirectMediaStream
{
MutexAutoLock lock(mMutex);
data = FindDataForTrack(aTrackID);
found = !!data;
if (found) {
isAudio = data->mData->GetType() == MediaSegment::AUDIO;
isVideo = data->mData->GetType() == MediaSegment::VIDEO;
updateData = FindDataForTrack(aTrackID);
track = FindTrack(aTrackID);
if (track) {
isAudio = track->GetType() == MediaSegment::AUDIO;
isVideo = track->GetType() == MediaSegment::VIDEO;
}
// The track might be removed from mUpdateTrack but still exist in
// mTracks.
auto streamTrack = FindTrack(aTrackID);
bool foundTrack = !!streamTrack;
if (foundTrack) {
MediaStreamVideoSink* videoSink = listener->AsMediaStreamVideoSink();
if (track && isVideo && listener->AsMediaStreamVideoSink()) {
// Re-send missed VideoSegment to new added MediaStreamVideoSink.
if (streamTrack->GetType() == MediaSegment::VIDEO && videoSink) {
VideoSegment videoSegment;
if (mTracks.GetForgottenDuration() < streamTrack->GetSegment()->GetDuration()) {
videoSegment.AppendSlice(*streamTrack->GetSegment(),
mTracks.GetForgottenDuration(),
streamTrack->GetSegment()->GetDuration());
} else {
VideoSegment* streamTrackSegment = static_cast<VideoSegment*>(streamTrack->GetSegment());
VideoChunk* lastChunk = streamTrackSegment->GetLastChunk();
if (lastChunk) {
StreamTime startTime = streamTrackSegment->GetDuration() - lastChunk->GetDuration();
videoSegment.AppendSlice(*streamTrackSegment,
startTime,
streamTrackSegment->GetDuration());
}
}
if (found) {
videoSegment.AppendSlice(*data->mData, 0, data->mData->GetDuration());
}
videoSink->SetCurrentFrames(videoSegment);
VideoSegment* trackSegment = static_cast<VideoSegment*>(track->GetSegment());
VideoSegment videoSegment;
if (mTracks.GetForgottenDuration() < trackSegment->GetDuration()) {
videoSegment.AppendSlice(*trackSegment,
mTracks.GetForgottenDuration(),
trackSegment->GetDuration());
}
if (updateData) {
videoSegment.AppendSlice(*updateData->mData, 0, updateData->mData->GetDuration());
}
listener->NotifyRealtimeTrackData(Graph(), 0, videoSegment);
}
if (found && (isAudio || isVideo)) {
if (track && (isAudio || isVideo)) {
for (auto entry : mDirectTrackListeners) {
if (entry.mListener == listener &&
(entry.mTrackID == TRACK_ANY || entry.mTrackID == aTrackID)) {
@ -2939,7 +2924,7 @@ SourceMediaStream::AddDirectTrackListenerImpl(already_AddRefed<DirectMediaStream
sourceListener->mTrackID = aTrackID;
}
}
if (!found) {
if (!track) {
STREAM_LOG(LogLevel::Warning, ("Couldn't find source track for direct track listener %p",
listener.get()));
listener->NotifyDirectListenerInstalled(
@ -2953,9 +2938,15 @@ SourceMediaStream::AddDirectTrackListenerImpl(already_AddRefed<DirectMediaStream
MOZ_ASSERT(true);
return;
}
STREAM_LOG(LogLevel::Debug, ("Added direct track listener %p", listener.get()));
STREAM_LOG(LogLevel::Debug, ("Added direct track listener %p. ended=%d",
listener.get(), !updateData));
listener->NotifyDirectListenerInstalled(
DirectMediaStreamTrackListener::InstallationResult::SUCCESS);
if (!updateData) {
// The track exists but the mUpdateTracks entry was removed.
// This means that the track has ended.
listener->NotifyEnded();
}
}
void

View file

@ -38,6 +38,16 @@ const PC_RECEIVER_CID = Components.ID("{d974b814-8fde-411c-8c45-b86791b81030}");
const PC_COREQUEST_CID = Components.ID("{74b2122d-65a8-4824-aa9e-3d664cb75dc2}");
const PC_DTMF_SENDER_CID = Components.ID("{3610C242-654E-11E6-8EC0-6D1BE389A607}");
function logMsg(msg, file, line, flag, winID) {
let scriptErrorClass = Cc["@mozilla.org/scripterror;1"];
let scriptError = scriptErrorClass.createInstance(Ci.nsIScriptError);
scriptError.initWithWindowID(msg, file, null, line, 0, flag,
"content javascript", winID);
let console = Cc["@mozilla.org/consoleservice;1"].
getService(Ci.nsIConsoleService);
console.logMessage(scriptError);
};
// Global list of PeerConnection objects, so they can be cleaned up when
// a page is torn down. (Maps inner window ID to an array of PC objects).
function GlobalPCList() {
@ -217,9 +227,7 @@ GlobalPCList.prototype = {
};
var _globalPCList = new GlobalPCList();
function RTCIceCandidate() {
this.candidate = this.sdpMid = this.sdpMLineIndex = null;
}
function RTCIceCandidate() {}
RTCIceCandidate.prototype = {
classDescription: "RTCIceCandidate",
classID: PC_ICE_CID,
@ -230,15 +238,11 @@ RTCIceCandidate.prototype = {
init: function(win) { this._win = win; },
__init: function(dict) {
this.candidate = dict.candidate;
this.sdpMid = dict.sdpMid;
this.sdpMLineIndex = ("sdpMLineIndex" in dict)? dict.sdpMLineIndex : null;
Object.assign(this, dict);
}
};
function RTCSessionDescription() {
this.type = this.sdp = null;
}
function RTCSessionDescription() {}
RTCSessionDescription.prototype = {
classDescription: "RTCSessionDescription",
classID: PC_SESSION_CID,
@ -246,11 +250,41 @@ RTCSessionDescription.prototype = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports,
Ci.nsIDOMGlobalPropertyInitializer]),
init: function(win) { this._win = win; },
init: function(win) {
this._win = win;
this._winID = this._win.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils).currentInnerWindowID;
},
__init: function(dict) {
this.type = dict.type;
this.sdp = dict.sdp;
__init: function({ type, sdp }) {
Object.assign(this, { _type: type, _sdp: sdp });
},
get type() { return this._type; },
set type(type) {
this.warn();
this._type = type;
},
get sdp() { return this._sdp; },
set sdp(sdp) {
this.warn();
this._sdp = sdp;
},
warn: function() {
if (!this._warned) {
// Warn once per RTCSessionDescription about deprecated writable usage.
this.logWarning("RTCSessionDescription's members are readonly! " +
"Writing to them is deprecated and will break soon!");
this._warned = true;
}
},
logWarning: function(msg) {
let err = this._win.Error();
logMsg(msg, err.fileName, err.lineNumber, Ci.nsIScriptError.warningFlag,
this._winID);
}
};
@ -645,13 +679,7 @@ RTCPeerConnection.prototype = {
},
logMsg: function(msg, file, line, flag) {
let scriptErrorClass = Cc["@mozilla.org/scripterror;1"];
let scriptError = scriptErrorClass.createInstance(Ci.nsIScriptError);
scriptError.initWithWindowID(msg, file, null, line, 0, flag,
"content javascript", this._winID);
let console = Cc["@mozilla.org/consoleservice;1"].
getService(Ci.nsIConsoleService);
console.logMessage(scriptError);
return logMsg(msg, file, line, flag, this._winID);
},
getEH: function(type) {
@ -711,8 +739,7 @@ RTCPeerConnection.prototype = {
this._impl.createOffer(options);
}));
p = this._addIdentityAssertion(p, origin);
return p.then(
sdp => new this._win.RTCSessionDescription({ type: "offer", sdp: sdp }));
return p.then(sdp => Cu.cloneInto({ type: "offer", sdp: sdp }, this._win));
});
});
},
@ -746,9 +773,7 @@ RTCPeerConnection.prototype = {
this._impl.createAnswer();
}));
p = this._addIdentityAssertion(p, origin);
return p.then(sdp => {
return new this._win.RTCSessionDescription({ type: "answer", sdp: sdp });
});
return p.then(sdp => Cu.cloneInto({ type: "answer", sdp: sdp }, this._win));
});
});
},
@ -957,12 +982,15 @@ RTCPeerConnection.prototype = {
containsTrickle(topSection) || sections.every(containsTrickle);
},
addIceCandidate: function(c, onSuccess, onError) {
return this._legacyCatchAndCloseGuard(onSuccess, onError, () => {
if (!c.candidate && !c.sdpMLineIndex) {
throw new this._win.DOMException("Invalid candidate passed to addIceCandidate!",
"InvalidParameterError");
if (!c) {
// TODO: Implement processing for end-of-candidates (bug 1318167)
return Promise.resolve();
}
if (c.sdpMid === null && c.sdpMLineIndex === null) {
throw new this._win.DOMException("Invalid candidate (both sdpMid and sdpMLineIndex are null).",
"TypeError");
}
return this._chain(() => new this._win.Promise((resolve, reject) => {
this._onAddIceCandidateSuccess = resolve;
@ -1106,8 +1134,7 @@ RTCPeerConnection.prototype = {
return null;
}
return new this._win.RTCSessionDescription({ type: this._localType,
sdp: sdp });
return new this._win.RTCSessionDescription({ type: this._localType, sdp });
},
get remoteDescription() {
@ -1116,8 +1143,7 @@ RTCPeerConnection.prototype = {
if (sdp.length == 0) {
return null;
}
return new this._win.RTCSessionDescription({ type: this._remoteType,
sdp: sdp });
return new this._win.RTCSessionDescription({ type: this._remoteType, sdp });
},
get peerIdentity() { return this._peerIdentity; },

View file

@ -222,7 +222,7 @@ public:
Dispatch();
}
const T& ReturnValue() const {
T ReturnValue() const {
if (mSuccess) {
return mSuccessValue;
} else {

View file

@ -86,8 +86,7 @@ function testMultipleFingerprints() {
fingerprintSdp(fingerprints.slice(1)) +
offer.sdp.slice(match.index);
var desc = new RTCSessionDescription({ type: 'offer', sdp: sdp });
return pcStrict.setRemoteDescription(desc);
return pcStrict.setRemoteDescription({ type: 'offer', sdp });
})
.then(() => {
ok(true, 'Modified fingerprints were accepted');

View file

@ -334,7 +334,7 @@ PeerConnectionTest.prototype.createOffer = function(peer) {
*
* @param {PeerConnectionWrapper} peer
The peer connection wrapper to run the command on
* @param {RTCSessionDescription} desc
* @param {RTCSessionDescriptionInit} desc
* Session description for the local description request
*/
PeerConnectionTest.prototype.setLocalDescription =
@ -403,7 +403,7 @@ PeerConnectionTest.prototype.setOfferOptions = function(options) {
*
* @param {PeerConnectionWrapper} peer
The peer connection wrapper to run the command on
* @param {RTCSessionDescription} desc
* @param {RTCSessionDescriptionInit} desc
* Session description for the remote description request
*/
PeerConnectionTest.prototype.setRemoteDescription =
@ -1064,7 +1064,7 @@ PeerConnectionWrapper.prototype = {
* Sets the local description and automatically handles the failure case.
*
* @param {object} desc
* RTCSessionDescription for the local description request
* RTCSessionDescriptionInit for the local description request
*/
setLocalDescription : function(desc) {
this.observedNegotiationNeeded = undefined;
@ -1078,7 +1078,7 @@ PeerConnectionWrapper.prototype = {
* causes the test case to fail if the call succeeds.
*
* @param {object} desc
* RTCSessionDescription for the local description request
* RTCSessionDescriptionInit for the local description request
* @returns {Promise}
* A promise that resolves to the expected error
*/
@ -1095,7 +1095,7 @@ PeerConnectionWrapper.prototype = {
* Sets the remote description and automatically handles the failure case.
*
* @param {object} desc
* RTCSessionDescription for the remote description request
* RTCSessionDescriptionInit for the remote description request
*/
setRemoteDescription : function(desc) {
this.observedNegotiationNeeded = undefined;
@ -1115,7 +1115,7 @@ PeerConnectionWrapper.prototype = {
* causes the test case to fail if the call succeeds.
*
* @param {object} desc
* RTCSessionDescription for the remote description request
* RTCSessionDescriptionInit for the remote description request
* @returns {Promise}
* a promise that resolve to the returned error
*/

View file

@ -118,7 +118,7 @@ var commandsPeerConnectionInitial = [
test.setupSignalingClient();
test.registerSignalingCallback("ice_candidate", function (message) {
var pc = test.pcRemote ? test.pcRemote : test.pcLocal;
pc.storeOrAddIceCandidate(new RTCIceCandidate(message.ice_candidate));
pc.storeOrAddIceCandidate(message.ice_candidate);
});
test.registerSignalingCallback("end_of_trickle_ice", function (message) {
test.signalingMessagesFinished();

View file

@ -19,9 +19,9 @@
test.chain.insertAfter("PC_LOCAL_SET_LOCAL_DESCRIPTION", [
function PC_LOCAL_ADD_CANDIDATE_EARLY(test) {
var candidate = new RTCIceCandidate(
{candidate:"candidate:1 1 UDP 2130706431 192.168.2.1 50005 typ host",
sdpMLineIndex: 0});
var candidate = {
candidate:"candidate:1 1 UDP 2130706431 192.168.2.1 50005 typ host",
sdpMLineIndex: 0};
return test.pcLocal._pc.addIceCandidate(candidate).then(
generateErrorCallback("addIceCandidate should have failed."),
err => {
@ -54,23 +54,23 @@
}
);
},
function PC_REMOTE_ADD_CANDIDATE_MISSING_INDEX(test) {
// Note: it is probably not a good idea to automatically fill a missing
// MLineIndex with a default value of zero, see bug 1157034
function PC_REMOTE_ADD_MISSING_MID_AND_MISSING_INDEX(test) {
var broken = new RTCIceCandidate(
{candidate:"candidate:1 1 UDP 2130706431 192.168.2.1 50005 typ host"});
return test.pcRemote._pc.addIceCandidate(broken)
.then(
// FIXME this needs to be updated once bug 1157034 is fixed
todo(false, "Missing index in got automatically set to a valid value bz://1157034")
generateErrorCallback("addIceCandidate should have failed."),
err => {
is(err.name, "TypeError", "Error is TypeError");
}
);
},
function PC_REMOTE_ADD_VALID_CANDIDATE(test) {
var candidate = new RTCIceCandidate(
{candidate:"candidate:1 1 UDP 2130706431 192.168.2.1 50005 typ host",
sdpMLineIndex: 0});
var candidate = {
candidate:"candidate:1 1 UDP 2130706431 192.168.2.1 50005 typ host",
sdpMLineIndex: 0};
return test.pcRemote._pc.addIceCandidate(candidate)
.then(ok(true, "Successfully added valid ICE candidate"));
.then(() => ok(true, "Successfully added valid ICE candidate"));
},
// bug 1095793
function PC_REMOTE_ADD_MISMATCHED_MID_AND_LEVEL_CANDIDATE(test) {
@ -79,20 +79,23 @@
sdpMLineIndex: 0,
sdpMid: "sdparta_1"});
return test.pcRemote._pc.addIceCandidate(bogus)
.then(
generateErrorCallback("addIceCandidate should have failed."),
err => {
is(err.name, "InvalidCandidateError", "Error is InvalidCandidateError");
}
);
.then(generateErrorCallback("addIceCandidate should have failed."),
err => is(err.name, "InvalidCandidateError", "Error is InvalidCandidateError"));
},
function PC_REMOTE_ADD_MID_AND_MISSING_INDEX(test) {
var candidate = new RTCIceCandidate(
{candidate:"candidate:1 1 UDP 2130706431 192.168.2.1 50005 typ host",
sdpMid: "sdparta_0"});
return test.pcRemote._pc.addIceCandidate(candidate)
.then(() => ok(true, "Successfully added valid ICE candidate"));
},
function PC_REMOTE_ADD_MATCHING_MID_AND_LEVEL_CANDIDATE(test) {
var candidate = new mozRTCIceCandidate(
var candidate = new RTCIceCandidate(
{candidate:"candidate:1 1 UDP 2130706431 192.168.2.1 50005 typ host",
sdpMLineIndex: 0,
sdpMid: "sdparta_0"});
return test.pcRemote._pc.addIceCandidate(candidate)
.then(ok(true, "Successfully added valid ICE candidate with matching mid and level"));
.then(() => ok(true, "Successfully added valid ICE candidate with matching mid and level"));
}
]);
test.run();

View file

@ -21,12 +21,12 @@ function PC_REMOTE_SETUP_NULL_ICE_HANDLER(test) {
test.pcRemote.setupIceCandidateHandler(test, function() {}, function () {});
}
function PC_REMOTE_ADD_FAKE_ICE_CANDIDATE(test) {
var cand = new RTCIceCandidate({"candidate":"candidate:0 1 UDP 2130379007 192.0.2.1 12345 typ host","sdpMid":"","sdpMLineIndex":0});
var cand = {"candidate":"candidate:0 1 UDP 2130379007 192.0.2.1 12345 typ host","sdpMid":"","sdpMLineIndex":0};
test.pcRemote.storeOrAddIceCandidate(cand);
info(test.pcRemote + " Stored fake candidate: " + JSON.stringify(cand));
}
function PC_LOCAL_ADD_FAKE_ICE_CANDIDATE(test) {
var cand = new RTCIceCandidate({"candidate":"candidate:0 1 UDP 2130379007 192.0.2.2 56789 typ host","sdpMid":"","sdpMLineIndex":0});
var cand = {"candidate":"candidate:0 1 UDP 2130379007 192.0.2.2 56789 typ host","sdpMid":"","sdpMLineIndex":0};
test.pcLocal.storeOrAddIceCandidate(cand);
info(test.pcLocal + " Stored fake candidate: " + JSON.stringify(cand));
}

View file

@ -27,8 +27,7 @@
function testSetLocalDescriptionError() {
var pc = new RTCPeerConnection();
info ("Testing setLocalDescription error");
return pc.setLocalDescription(new RTCSessionDescription({ sdp: "Picklechips!",
type: "offer" }))
return pc.setLocalDescription({ sdp: "Picklechips!", type: "offer" })
.then(generateErrorCallback("setLocalDescription with nonsense SDP should fail"),
validateReason);
};
@ -36,8 +35,7 @@
function testSetRemoteDescriptionError() {
var pc = new RTCPeerConnection();
info ("Testing setRemoteDescription error");
return pc.setRemoteDescription(new RTCSessionDescription({ sdp: "Who?",
type: "offer" }))
return pc.setRemoteDescription({ sdp: "Who?", type: "offer" })
.then(generateErrorCallback("setRemoteDescription with nonsense SDP should fail"),
validateReason);
};

View file

@ -20,12 +20,12 @@ function PC_REMOTE_SETUP_NULL_ICE_HANDLER(test) {
test.pcRemote.setupIceCandidateHandler(test, function() {}, function () {});
}
function PC_REMOTE_ADD_FAKE_ICE_CANDIDATE(test) {
var cand = new RTCIceCandidate({"candidate":"candidate:0 1 UDP 2130379007 192.0.2.1 12345 typ host","sdpMid":"","sdpMLineIndex":0});
var cand = {"candidate":"candidate:0 1 UDP 2130379007 192.0.2.1 12345 typ host","sdpMid":"","sdpMLineIndex":0};
test.pcRemote.storeOrAddIceCandidate(cand);
info(test.pcRemote + " Stored fake candidate: " + JSON.stringify(cand));
}
function PC_LOCAL_ADD_FAKE_ICE_CANDIDATE(test) {
var cand = new RTCIceCandidate({"candidate":"candidate:0 1 UDP 2130379007 192.0.2.2 56789 typ host","sdpMid":"","sdpMLineIndex":0});
var cand = {"candidate":"candidate:0 1 UDP 2130379007 192.0.2.2 56789 typ host","sdpMid":"","sdpMLineIndex":0};
test.pcLocal.storeOrAddIceCandidate(cand);
info(test.pcLocal + " Stored fake candidate: " + JSON.stringify(cand));
}

View file

@ -37,10 +37,9 @@
},
function PC_REMOTE_ROLLBACK(test) {
return test.setLocalDescription(
test.pcRemote,
new RTCSessionDescription({ type: "rollback", sdp: ""}),
STABLE);
return test.setLocalDescription(test.pcRemote,
{ type: "rollback", sdp: "" },
STABLE);
},
// Rolling back should shut down gathering

View file

@ -23,10 +23,9 @@
},
function PC_REMOTE_ROLLBACK(test) {
return test.setLocalDescription(
test.pcRemote,
new RTCSessionDescription({ type: "rollback", sdp: ""}),
STABLE);
return test.setLocalDescription(test.pcRemote,
{ type: "rollback", sdp: "" },
STABLE);
},
// Rolling back should shut down gathering

View file

@ -35,10 +35,8 @@
},
function PC_REMOTE_ROLLBACK(test) {
return test.setRemoteDescription(
test.pcRemote,
new RTCSessionDescription({ type: "rollback" }),
STABLE)
return test.setRemoteDescription(test.pcRemote, { type: "rollback" },
STABLE)
.then(() => test.pcRemote.rollbackRemoteTracksIfNotNegotiated());
},

View file

@ -20,10 +20,8 @@
function PC_REMOTE_ROLLBACK(test) {
// We still haven't negotiated the tracks
test.pcRemote.expectNegotiationNeeded();
return test.setRemoteDescription(
test.pcRemote,
new RTCSessionDescription({ type: "rollback" }),
STABLE)
return test.setRemoteDescription(test.pcRemote, { type: "rollback" },
STABLE)
.then(() => test.pcRemote.rollbackRemoteTracksIfNotNegotiated());
},

View file

@ -51,10 +51,8 @@
},
function PC_REMOTE_ROLLBACK(test) {
return test.setRemoteDescription(
test.pcRemote,
new RTCSessionDescription({ type: "rollback" }),
STABLE);
return test.setRemoteDescription(test.pcRemote, { type: "rollback" },
STABLE);
},
function PC_LOCAL_ROLLBACK(test) {

View file

@ -42,11 +42,9 @@
test.pcLocal.iceCheckingIceRollbackExpected = true;
},
function PC_LOCAL_ROLLBACK(test) {
return test.setLocalDescription(
test.pcLocal,
new RTCSessionDescription({ type: "rollback",
sdp: ""}),
STABLE);
return test.setLocalDescription(test.pcLocal,
{ type: "rollback", sdp: ""},
STABLE);
},
// Rolling back should shut down gathering
function PC_LOCAL_WAIT_FOR_END_OF_TRICKLE(test) {