| 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..3e36b1774c005d895df419270fd70583341dac46 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 = *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
|
|
|