| 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 27706ff98c69d207d32866163b1c8a7e76277634..e164e4dbfe4431631389cc426daa94d89f2774eb 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 track_;
|
| }
|
|
|
| +const HeapVector<Member<RTCRtpContributingSource>>&
|
| +RTCRtpReceiver::getContributingSources() {
|
| + UpdateSourcesIfNeeded();
|
| + return contributing_sources_;
|
| +}
|
| +
|
| +void RTCRtpReceiver::UpdateSourcesIfNeeded() {
|
| + if (!contributing_sources_needs_updating_)
|
| + return;
|
| + contributing_sources_.Clear();
|
| + for (const std::unique_ptr<WebRTCRtpContributingSource>&
|
| + web_contributing_source : receiver_->GetSources()) {
|
| + if (web_contributing_source->SourceType() ==
|
| + WebRTCRtpContributingSourceType::SSRC) {
|
| + // TODO(hbos): When |getSynchronizationSources| is added to get SSRC
|
| + // sources don't ignore SSRCs here.
|
| + continue;
|
| + }
|
| + DCHECK_EQ(web_contributing_source->SourceType(),
|
| + WebRTCRtpContributingSourceType::CSRC);
|
| + auto it = contributing_sources_by_source_id_.Find(
|
| + web_contributing_source->Source());
|
| + if (it == contributing_sources_by_source_id_.end()) {
|
| + RTCRtpContributingSource* contributing_source =
|
| + new RTCRtpContributingSource(this, *web_contributing_source);
|
| + contributing_sources_by_source_id_.insert(contributing_source->source(),
|
| + contributing_source);
|
| + contributing_sources_.push_back(contributing_source);
|
| + } else {
|
| + it->value->UpdateMembers(*web_contributing_source);
|
| + contributing_sources_.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.
|
| + contributing_sources_needs_updating_ = false;
|
| + Microtask::EnqueueMicrotask(
|
| + WTF::Bind(&RTCRtpReceiver::SetContributingSourcesNeedsUpdating,
|
| + WrapWeakPersistent(this)));
|
| +}
|
| +
|
| +void RTCRtpReceiver::SetContributingSourcesNeedsUpdating() {
|
| + contributing_sources_needs_updating_ = true;
|
| +}
|
| +
|
| DEFINE_TRACE(RTCRtpReceiver) {
|
| visitor->Trace(track_);
|
| + visitor->Trace(contributing_sources_by_source_id_);
|
| + visitor->Trace(contributing_sources_);
|
| }
|
|
|
| } // namespace blink
|
|
|