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" |
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 : m_receiver(std::move(receiver)), m_track(track) { | 15 : m_receiver(std::move(receiver)), m_track(track) { |
14 DCHECK(m_receiver); | 16 DCHECK(m_receiver); |
15 DCHECK(m_track); | 17 DCHECK(m_track); |
16 DCHECK_EQ(static_cast<String>(m_receiver->track().id()), m_track->id()); | 18 DCHECK_EQ(static_cast<String>(m_receiver->track().id()), m_track->id()); |
17 } | 19 } |
18 | 20 |
19 MediaStreamTrack* RTCRtpReceiver::track() const { | 21 MediaStreamTrack* RTCRtpReceiver::track() const { |
20 return m_track; | 22 return m_track; |
21 } | 23 } |
22 | 24 |
| 25 const HeapVector<Member<RTCRtpContributingSource>>& |
| 26 RTCRtpReceiver::getContributingSources() { |
| 27 updateSourcesIfNeeded(); |
| 28 return m_contributingSources; |
| 29 } |
| 30 |
| 31 void RTCRtpReceiver::updateSourcesIfNeeded() { |
| 32 if (!m_contributingSourcesNeedsUpdating) |
| 33 return; |
| 34 m_contributingSources.clear(); |
| 35 for (const std::unique_ptr<WebRTCRtpContributingSource>& |
| 36 webContributingSource : m_receiver->getSources()) { |
| 37 if (webContributingSource->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(webContributingSource->sourceType(), |
| 44 WebRTCRtpContributingSourceType::CSRC); |
| 45 auto it = |
| 46 m_contributingSourcesBySourceId.find(webContributingSource->source()); |
| 47 if (it == m_contributingSourcesBySourceId.end()) { |
| 48 RTCRtpContributingSource* contributingSource = |
| 49 new RTCRtpContributingSource(this, *webContributingSource); |
| 50 m_contributingSourcesBySourceId.insert(contributingSource->source(), |
| 51 contributingSource); |
| 52 m_contributingSources.push_back(contributingSource); |
| 53 } else { |
| 54 *it->value = *webContributingSource; |
| 55 m_contributingSources.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 m_contributingSourcesNeedsUpdating = false; |
| 64 Microtask::enqueueMicrotask( |
| 65 WTF::bind(&RTCRtpReceiver::setContributingSourcesNeedsUpdating, |
| 66 wrapWeakPersistent(this))); |
| 67 } |
| 68 |
| 69 void RTCRtpReceiver::setContributingSourcesNeedsUpdating() { |
| 70 m_contributingSourcesNeedsUpdating = true; |
| 71 } |
| 72 |
23 DEFINE_TRACE(RTCRtpReceiver) { | 73 DEFINE_TRACE(RTCRtpReceiver) { |
24 visitor->trace(m_track); | 74 visitor->trace(m_track); |
| 75 visitor->trace(m_contributingSourcesBySourceId); |
| 76 visitor->trace(m_contributingSources); |
25 } | 77 } |
26 | 78 |
27 } // namespace blink | 79 } // namespace blink |
OLD | NEW |