Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Unified Diff: third_party/WebKit/Source/modules/peerconnection/RTCRtpReceiver.cpp

Issue 2803693002: RTCRtpReceiver.getContributingSources() added. (Closed)
Patch Set: Addressed guidou's comments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/peerconnection/RTCRtpReceiver.cpp
diff --git a/third_party/WebKit/Source/modules/peerconnection/RTCRtpReceiver.cpp b/third_party/WebKit/Source/modules/peerconnection/RTCRtpReceiver.cpp
index e929cb6b097b02b5cd35cc05d06d702514c9511e..9dcc5acd87838055167973a79e50f81d1d5d568e 100644
--- a/third_party/WebKit/Source/modules/peerconnection/RTCRtpReceiver.cpp
+++ b/third_party/WebKit/Source/modules/peerconnection/RTCRtpReceiver.cpp
@@ -4,6 +4,8 @@
#include "modules/peerconnection/RTCRtpReceiver.h"
+#include "bindings/core/v8/Microtask.h"
+#include "public/platform/WebRTCRtpContributingSource.h"
#include "wtf/text/WTFString.h"
namespace blink {
@@ -20,8 +22,58 @@ MediaStreamTrack* RTCRtpReceiver::track() const {
return m_track;
}
+const HeapVector<Member<RTCRtpContributingSource>>&
+RTCRtpReceiver::getContributingSources() {
+ updateSourcesIfNeeded();
+ return m_contributingSources;
+}
+
+void RTCRtpReceiver::updateSourcesIfNeeded() {
+ if (!m_contributingSourcesNeedsUpdating)
+ return;
+ m_contributingSources.clear();
+ for (const std::unique_ptr<WebRTCRtpContributingSource>&
+ webContributingSource : m_receiver->getSources()) {
+ if (webContributingSource->sourceType() ==
+ WebRTCRtpContributingSourceType::SSRC) {
+ // TODO(hbos): When |getSynchronizationSources| is added to get SSRC
+ // sources don't ignore SSRCs here.
+ continue;
+ }
+ DCHECK_EQ(webContributingSource->sourceType(),
+ WebRTCRtpContributingSourceType::CSRC);
+ auto it =
+ m_contributingSourcesBySourceId.find(webContributingSource->source());
+ if (it == m_contributingSourcesBySourceId.end()) {
+ RTCRtpContributingSource* contributingSource =
+ new RTCRtpContributingSource(this, *webContributingSource);
+ m_contributingSourcesBySourceId.insert(contributingSource->source(),
+ contributingSource);
+ m_contributingSources.push_back(contributingSource);
+ } else {
+ it->value->updateMembers(*webContributingSource);
+ m_contributingSources.push_back(it->value);
+ }
+ }
+ // Clear the flag and schedule a microtask to reset it to true. This makes
+ // the cache valid until the next microtask checkpoint. As such, sources
+ // represent a snapshot and can be compared reliably in .js code, no risk of
+ // being updated due to an RTP packet arriving. E.g.
+ // "source.timestamp == source.timestamp" will always be true.
+ m_contributingSourcesNeedsUpdating = false;
+ Microtask::enqueueMicrotask(
+ WTF::bind(&RTCRtpReceiver::setContributingSourcesNeedsUpdating,
+ wrapWeakPersistent(this)));
+}
+
+void RTCRtpReceiver::setContributingSourcesNeedsUpdating() {
+ m_contributingSourcesNeedsUpdating = true;
+}
+
DEFINE_TRACE(RTCRtpReceiver) {
visitor->trace(m_track);
+ visitor->trace(m_contributingSourcesBySourceId);
+ visitor->trace(m_contributingSources);
}
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698