зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1616875: Remove code that we will not need to move to RTCRtpReceiver. r=ng,smaug
Primarily, this removes code that was compensating for inconsistencies between webrtc.org's timestamps, and JS timestamps. Also, this removes a few bits of indirection on GetRtpSources; that's all going to go directly to RTCRtpReceiver now. None of this code is being moved elsewhere. Depends on D50395 Differential Revision: https://phabricator.services.mozilla.com/D64234 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
7fd72ae8fd
Коммит
82081f2ffa
|
@ -368,23 +368,6 @@ class PeerConnectionTelemetry {
|
|||
}
|
||||
}
|
||||
|
||||
// Cache for RTPSourceEntries
|
||||
// Note: each cache is only valid for one JS event loop execution
|
||||
class RTCRtpSourceCache {
|
||||
constructor() {
|
||||
// The time in RTP source time (ms)
|
||||
this.tsNowInRtpSourceTime = null;
|
||||
// The time in JS
|
||||
this.jsTimestamp = null;
|
||||
// Time difference between JS time and RTP source time
|
||||
this.timestampOffset = null;
|
||||
// RTPSourceEntries cached by track id
|
||||
this.rtpSourcesByTrackId = new Map();
|
||||
// Has a cache wipe already been scheduled
|
||||
this.scheduledClear = null;
|
||||
}
|
||||
}
|
||||
|
||||
class RTCPeerConnection {
|
||||
constructor() {
|
||||
this._receiveStreams = new Map();
|
||||
|
@ -406,10 +389,6 @@ class RTCPeerConnection {
|
|||
|
||||
this._hasStunServer = this._hasTurnServer = false;
|
||||
this._iceGatheredRelayCandidates = false;
|
||||
// Stored webrtc timing information
|
||||
this._storedRtpSourceReferenceTime = null;
|
||||
// Stores cached RTP sources state
|
||||
this._rtpSourceCache = new RTCRtpSourceCache();
|
||||
// Records telemetry
|
||||
this._pcTelemetry = new PeerConnectionTelemetry();
|
||||
}
|
||||
|
@ -1476,48 +1455,6 @@ class RTCPeerConnection {
|
|||
this._transceivers.push(transceiver);
|
||||
}
|
||||
|
||||
/* Returns a dictionary with three keys:
|
||||
* sources: a list of contributing and synchronization sources
|
||||
* sourceClockOffset: an offset to apply to the source timestamp to get a
|
||||
* very close approximation of the sample time with respect to the local
|
||||
* clock.
|
||||
* jsTimestamp: the current JS time
|
||||
* Note: because the two clocks can drift with respect to each other, once
|
||||
* a timestamp offset has been calculated it should not be recalculated
|
||||
* until the timestamp changes, this way it will not appear as if a new
|
||||
* audio level sample has arrived.
|
||||
*/
|
||||
_getRtpSources(receiver) {
|
||||
let cache = this._rtpSourceCache;
|
||||
// Schedule cache invalidation
|
||||
if (!cache.scheduledClear) {
|
||||
cache.scheduledClear = true;
|
||||
Promise.resolve().then(() => {
|
||||
this._rtpSourceCache = new RTCRtpSourceCache();
|
||||
});
|
||||
}
|
||||
// Fetch the RTP source local time, store it for reuse, calculate
|
||||
// the local offset, likewise store it for reuse.
|
||||
if (cache.tsNowInRtpSourceTime !== undefined) {
|
||||
cache.tsNowInRtpSourceTime = this._impl.getNowInRtpSourceReferenceTime();
|
||||
cache.jsTimestamp =
|
||||
this._win.performance.now() + this._win.performance.timeOrigin;
|
||||
cache.timestampOffset = cache.jsTimestamp - cache.tsNowInRtpSourceTime;
|
||||
}
|
||||
let id = receiver.track.id;
|
||||
if (cache.rtpSourcesByTrackId[id] === undefined) {
|
||||
cache.rtpSourcesByTrackId[id] = this._impl.getRtpSources(
|
||||
receiver.track,
|
||||
cache.tsNowInRtpSourceTime
|
||||
);
|
||||
}
|
||||
return {
|
||||
sources: cache.rtpSourcesByTrackId[id],
|
||||
sourceClockOffset: cache.timestampOffset,
|
||||
jsTimestamp: cache.jsTimestamp,
|
||||
};
|
||||
}
|
||||
|
||||
addTransceiver(sendTrackOrKind, init) {
|
||||
this._checkClosed();
|
||||
let transceiver = this._addTransceiverNoEvents(sendTrackOrKind, init);
|
||||
|
@ -1692,11 +1629,6 @@ class RTCPeerConnection {
|
|||
.map(transceiver => transceiver.receiver);
|
||||
}
|
||||
|
||||
// test-only: get the current time using the webrtc clock
|
||||
mozGetNowInRtpSourceReferenceTime() {
|
||||
return this._impl.getNowInRtpSourceReferenceTime();
|
||||
}
|
||||
|
||||
// test-only: insert a contributing source entry for a track
|
||||
mozInsertAudioLevelForContributingSource(
|
||||
receiver,
|
||||
|
@ -2364,11 +2296,6 @@ class RTCRtpReceiver {
|
|||
_oldRecvBit: false,
|
||||
_streams: [],
|
||||
_oldstreams: [],
|
||||
// Sync and contributing sources must be kept cached so that timestamps
|
||||
// remain stable, as the timestamp offset can vary
|
||||
// note key = entry.source + entry.sourceType
|
||||
_rtpSources: new Map(),
|
||||
_rtpSourcesJsTimestamp: null,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -2378,87 +2305,6 @@ class RTCRtpReceiver {
|
|||
return this._pc._async(async () => this._pc.getStats(this.track));
|
||||
}
|
||||
|
||||
_getRtpSource(source, type) {
|
||||
this._fetchRtpSources();
|
||||
return this._rtpSources.get(type + source).entry;
|
||||
}
|
||||
|
||||
/* Fetch all of the RTP Contributing and Sync sources for the receiver
|
||||
* and store them so they are available when asked for.
|
||||
*/
|
||||
_fetchRtpSources() {
|
||||
if (this._rtpSourcesJsTimestamp !== null) {
|
||||
return;
|
||||
}
|
||||
// Queue microtask to mark the cache as stale after this task completes
|
||||
Promise.resolve().then(() => (this._rtpSourcesJsTimestamp = null));
|
||||
let { sources, sourceClockOffset, jsTimestamp } = this._pc._getRtpSources(
|
||||
this
|
||||
);
|
||||
this._rtpSourcesJsTimestamp = jsTimestamp;
|
||||
for (let entry of sources) {
|
||||
// Set the clock offset for calculating the 10-second window
|
||||
entry.sourceClockOffset = sourceClockOffset;
|
||||
// Store the new entries or update existing entries
|
||||
let key = entry.source + entry.sourceType;
|
||||
let cached = this._rtpSources.get(key);
|
||||
if (cached === undefined) {
|
||||
this._rtpSources.set(key, entry);
|
||||
} else if (cached.timestamp != entry.timestamp) {
|
||||
// Only update if the timestamp has changed
|
||||
// This also prevents the sourceClockOffset from changing unecessarily
|
||||
// which could cause a value to flutter at the edge of the 10 second
|
||||
// window.
|
||||
this._rtpSources.set(key, entry);
|
||||
}
|
||||
}
|
||||
// Clear old entries
|
||||
let cutoffTime = this._rtpSourcesJsTimestamp - 10 * 1000;
|
||||
let removeKeys = [];
|
||||
for (let entry of this._rtpSources.values()) {
|
||||
if (entry.timestamp + entry.sourceClockOffset < cutoffTime) {
|
||||
removeKeys.push(entry.source + entry.sourceType);
|
||||
}
|
||||
}
|
||||
for (let delKey of removeKeys) {
|
||||
this._rtpSources.delete(delKey);
|
||||
}
|
||||
}
|
||||
|
||||
_getRtpSourcesByType(type) {
|
||||
this._fetchRtpSources();
|
||||
// Only return the values from within the last 10 seconds as per the spec
|
||||
const cutoffTime = this._rtpSourcesJsTimestamp - 10 * 1000;
|
||||
return [...this._rtpSources.values()]
|
||||
.filter(entry => {
|
||||
return (
|
||||
entry.sourceType == type &&
|
||||
entry.timestamp + entry.sourceClockOffset >= cutoffTime
|
||||
);
|
||||
})
|
||||
.map(e => {
|
||||
const newEntry = {
|
||||
source: e.source,
|
||||
timestamp: e.timestamp + e.sourceClockOffset,
|
||||
rtpTimestamp: e.rtpTimestamp,
|
||||
audioLevel: e.audioLevel,
|
||||
};
|
||||
if (e.voiceActivityFlag !== undefined) {
|
||||
Object.assign(newEntry, { voiceActivityFlag: e.voiceActivityFlag });
|
||||
}
|
||||
return newEntry;
|
||||
})
|
||||
.sort((a, b) => b.timestamp - a.timestamp);
|
||||
}
|
||||
|
||||
getContributingSources() {
|
||||
return this._getRtpSourcesByType("contributing");
|
||||
}
|
||||
|
||||
getSynchronizationSources() {
|
||||
return this._getRtpSourcesByType("synchronization");
|
||||
}
|
||||
|
||||
setStreamIds(streamIds) {
|
||||
this._streams = streamIds.map(id => this._pc._getOrCreateStream(id));
|
||||
}
|
||||
|
|
|
@ -51,10 +51,6 @@ interface PeerConnectionImpl {
|
|||
optional unsigned long interToneGap = 70);
|
||||
[Throws]
|
||||
DOMString getDTMFToneBuffer(RTCRtpSender sender);
|
||||
[Throws]
|
||||
sequence<RTCRtpSourceEntry> getRtpSources(MediaStreamTrack track,
|
||||
DOMHighResTimeStamp rtpSourceNow);
|
||||
DOMHighResTimeStamp getNowInRtpSourceReferenceTime();
|
||||
|
||||
[Throws]
|
||||
void replaceTrackNoRenegotiation(TransceiverImpl transceiverImpl,
|
||||
|
|
|
@ -138,9 +138,6 @@ interface RTCPeerConnection : EventTarget {
|
|||
sequence<RTCRtpReceiver> getReceivers();
|
||||
sequence<RTCRtpTransceiver> getTransceivers();
|
||||
|
||||
// test-only: for testing getContributingSources
|
||||
[ChromeOnly]
|
||||
DOMHighResTimeStamp mozGetNowInRtpSourceReferenceTime();
|
||||
// test-only: for testing getContributingSources
|
||||
[ChromeOnly]
|
||||
void mozInsertAudioLevelForContributingSource(RTCRtpReceiver receiver,
|
||||
|
|
|
@ -1710,27 +1710,6 @@ void PeerConnectionImpl::DumpPacket_m(size_t level, dom::mozPacketDumpType type,
|
|||
mPCObserver->OnPacket(level, type, sending, arrayBuffer, jrv);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
PeerConnectionImpl::GetRtpSources(
|
||||
MediaStreamTrack& aRecvTrack, DOMHighResTimeStamp aRtpSourceTimeNow,
|
||||
nsTArray<dom::RTCRtpSourceEntry>& outRtpSources) {
|
||||
PC_AUTO_ENTER_API_CALL(true);
|
||||
outRtpSources.Clear();
|
||||
std::vector<RefPtr<TransceiverImpl>>& transceivers =
|
||||
mMedia->GetTransceivers();
|
||||
for (RefPtr<TransceiverImpl>& transceiver : transceivers) {
|
||||
if (transceiver->HasReceiveTrack(&aRecvTrack)) {
|
||||
transceiver->GetRtpSources(aRtpSourceTimeNow, outRtpSources);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
DOMHighResTimeStamp PeerConnectionImpl::GetNowInRtpSourceReferenceTime() {
|
||||
return RtpSourceObserver::NowInReportClockTime();
|
||||
}
|
||||
|
||||
// test-only: adds fake CSRCs and audio data
|
||||
nsresult PeerConnectionImpl::InsertAudioLevelForContributingSource(
|
||||
const dom::MediaStreamTrack& aRecvTrack, const unsigned long aSource,
|
||||
|
|
|
@ -304,15 +304,6 @@ class PeerConnectionImpl final
|
|||
rv = GetDTMFToneBuffer(sender, outToneBuffer);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_TO_ERRORRESULT(
|
||||
GetRtpSources, ErrorResult& rv, dom::MediaStreamTrack& aRecvTrack,
|
||||
DOMHighResTimeStamp aRtpSourceNow,
|
||||
nsTArray<dom::RTCRtpSourceEntry>& outRtpSources) {
|
||||
rv = GetRtpSources(aRecvTrack, aRtpSourceNow, outRtpSources);
|
||||
}
|
||||
|
||||
DOMHighResTimeStamp GetNowInRtpSourceReferenceTime();
|
||||
|
||||
NS_IMETHODIMP_TO_ERRORRESULT(ReplaceTrackNoRenegotiation, ErrorResult& rv,
|
||||
TransceiverImpl& aTransceiver,
|
||||
mozilla::dom::MediaStreamTrack* aWithTrack) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче