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

Side by Side Diff: third_party/WebKit/Source/modules/peerconnection/RTCRtpReceiver.cpp

Issue 2808113002: Reland of TCRtpReceiver.getContributingSources() added. (Closed)
Patch Set: 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 unified diff | Download patch
OLDNEW
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"
7 #include "wtf/text/WTFString.h" 9 #include "wtf/text/WTFString.h"
8 10
9 namespace blink { 11 namespace blink {
10 12
11 RTCRtpReceiver::RTCRtpReceiver(std::unique_ptr<WebRTCRtpReceiver> receiver, 13 RTCRtpReceiver::RTCRtpReceiver(std::unique_ptr<WebRTCRtpReceiver> receiver,
12 MediaStreamTrack* track) 14 MediaStreamTrack* track)
13 : receiver_(std::move(receiver)), track_(track) { 15 : receiver_(std::move(receiver)), track_(track) {
14 DCHECK(receiver_); 16 DCHECK(receiver_);
15 DCHECK(track_); 17 DCHECK(track_);
16 DCHECK_EQ(static_cast<String>(receiver_->Track().Id()), track_->id()); 18 DCHECK_EQ(static_cast<String>(receiver_->Track().Id()), track_->id());
17 } 19 }
18 20
19 MediaStreamTrack* RTCRtpReceiver::track() const { 21 MediaStreamTrack* RTCRtpReceiver::track() const {
20 return track_; 22 return track_;
21 } 23 }
22 24
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
23 DEFINE_TRACE(RTCRtpReceiver) { 73 DEFINE_TRACE(RTCRtpReceiver) {
24 visitor->Trace(track_); 74 visitor->Trace(track_);
75 visitor->Trace(contributing_sources_by_source_id_);
76 visitor->Trace(contributing_sources_);
25 } 77 }
26 78
27 } // namespace blink 79 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698