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..0ac0838c5c82d6edafa9011de804d37b18388ac1 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,57 @@ MediaStreamTrack* RTCRtpReceiver::track() const { |
return m_track; |
} |
+HeapVector<Member<RTCRtpContributingSource>> |
+RTCRtpReceiver::getContributingSources() { |
+ updateSources(); |
+ return m_contributingSources; |
+} |
+ |
+void RTCRtpReceiver::updateSources() { |
Taylor_Brandstetter
2017/04/05 19:28:28
nit: "maybeUpdateSources", or "updateSourcesIfNeed
hbos_chromium
2017/04/06 08:59:43
Done.
|
+ if (m_contributingSourcesNeedsUpdating) { |
+ m_contributingSources.clear(); |
+ for (const auto& 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 = *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 iteration of the event loop. 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 |