| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/peerconnection/RTCRtpReceiver.h" | 5 #include "modules/peerconnection/RTCRtpReceiver.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/Microtask.h" | |
| 8 #include "public/platform/WebRTCRtpContributingSource.h" | |
| 9 #include "wtf/text/WTFString.h" | 7 #include "wtf/text/WTFString.h" |
| 10 | 8 |
| 11 namespace blink { | 9 namespace blink { |
| 12 | 10 |
| 13 RTCRtpReceiver::RTCRtpReceiver(std::unique_ptr<WebRTCRtpReceiver> receiver, | 11 RTCRtpReceiver::RTCRtpReceiver(std::unique_ptr<WebRTCRtpReceiver> receiver, |
| 14 MediaStreamTrack* track) | 12 MediaStreamTrack* track) |
| 15 : receiver_(std::move(receiver)), track_(track) { | 13 : receiver_(std::move(receiver)), track_(track) { |
| 16 DCHECK(receiver_); | 14 DCHECK(receiver_); |
| 17 DCHECK(track_); | 15 DCHECK(track_); |
| 18 DCHECK_EQ(static_cast<String>(receiver_->Track().Id()), track_->id()); | 16 DCHECK_EQ(static_cast<String>(receiver_->Track().Id()), track_->id()); |
| 19 } | 17 } |
| 20 | 18 |
| 21 MediaStreamTrack* RTCRtpReceiver::track() const { | 19 MediaStreamTrack* RTCRtpReceiver::track() const { |
| 22 return track_; | 20 return track_; |
| 23 } | 21 } |
| 24 | 22 |
| 25 const HeapVector<Member<RTCRtpContributingSource>>& | |
| 26 RTCRtpReceiver::getContributingSources() { | |
| 27 UpdateSourcesIfNeeded(); | |
| 28 return contributing_sources_; | |
| 29 } | |
| 30 | |
| 31 void RTCRtpReceiver::UpdateSourcesIfNeeded() { | |
| 32 if (!contributing_sources_needs_updating_) | |
| 33 return; | |
| 34 contributing_sources_.Clear(); | |
| 35 for (const std::unique_ptr<WebRTCRtpContributingSource>& | |
| 36 web_contributing_source : receiver_->GetSources()) { | |
| 37 if (web_contributing_source->SourceType() == | |
| 38 WebRTCRtpContributingSourceType::SSRC) { | |
| 39 // TODO(hbos): When |getSynchronizationSources| is added to get SSRC | |
| 40 // sources don't ignore SSRCs here. | |
| 41 continue; | |
| 42 } | |
| 43 DCHECK_EQ(web_contributing_source->SourceType(), | |
| 44 WebRTCRtpContributingSourceType::CSRC); | |
| 45 auto it = contributing_sources_by_source_id_.Find( | |
| 46 web_contributing_source->Source()); | |
| 47 if (it == contributing_sources_by_source_id_.end()) { | |
| 48 RTCRtpContributingSource* contributing_source = | |
| 49 new RTCRtpContributingSource(this, *web_contributing_source); | |
| 50 contributing_sources_by_source_id_.insert(contributing_source->source(), | |
| 51 contributing_source); | |
| 52 contributing_sources_.push_back(contributing_source); | |
| 53 } else { | |
| 54 it->value->UpdateMembers(*web_contributing_source); | |
| 55 contributing_sources_.push_back(it->value); | |
| 56 } | |
| 57 } | |
| 58 // Clear the flag and schedule a microtask to reset it to true. This makes | |
| 59 // the cache valid until the next microtask checkpoint. As such, sources | |
| 60 // represent a snapshot and can be compared reliably in .js code, no risk of | |
| 61 // being updated due to an RTP packet arriving. E.g. | |
| 62 // "source.timestamp == source.timestamp" will always be true. | |
| 63 contributing_sources_needs_updating_ = false; | |
| 64 Microtask::EnqueueMicrotask( | |
| 65 WTF::Bind(&RTCRtpReceiver::SetContributingSourcesNeedsUpdating, | |
| 66 WrapWeakPersistent(this))); | |
| 67 } | |
| 68 | |
| 69 void RTCRtpReceiver::SetContributingSourcesNeedsUpdating() { | |
| 70 contributing_sources_needs_updating_ = true; | |
| 71 } | |
| 72 | |
| 73 DEFINE_TRACE(RTCRtpReceiver) { | 23 DEFINE_TRACE(RTCRtpReceiver) { |
| 74 visitor->Trace(track_); | 24 visitor->Trace(track_); |
| 75 visitor->Trace(contributing_sources_by_source_id_); | |
| 76 visitor->Trace(contributing_sources_); | |
| 77 } | 25 } |
| 78 | 26 |
| 79 } // namespace blink | 27 } // namespace blink |
| OLD | NEW |