Chromium Code Reviews| 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 HeapVector<Member<RTCRtpContributingSource>> | |
| 26 RTCRtpReceiver::getContributingSources() { | |
| 27 updateSourcesIfNeeded(); | |
| 28 return m_contributingSources; | |
| 29 } | |
| 30 | |
| 31 void RTCRtpReceiver::updateSourcesIfNeeded() { | |
| 32 if (m_contributingSourcesNeedsUpdating) { | |
|
foolip
2017/04/06 10:07:23
if (!m_contributingSourcesNeedsUpdating) return.
hbos_chromium
2017/04/06 11:10:15
Done.
| |
| 33 m_contributingSources.clear(); | |
| 34 for (const auto& webContributingSource : m_receiver->getSources()) { | |
|
foolip
2017/04/06 10:07:23
Can you spell out the type here, unless it's some
hbos_chromium
2017/04/06 11:10:15
Done.
| |
| 35 if (webContributingSource->sourceType() == | |
| 36 WebRTCRtpContributingSourceType::SSRC) { | |
| 37 // TODO(hbos): When |getSynchronizationSources| is added to get SSRC | |
| 38 // sources don't ignore SSRCs here. | |
| 39 continue; | |
| 40 } | |
| 41 DCHECK_EQ(webContributingSource->sourceType(), | |
| 42 WebRTCRtpContributingSourceType::CSRC); | |
| 43 auto it = | |
| 44 m_contributingSourcesBySourceId.find(webContributingSource->source()); | |
| 45 if (it == m_contributingSourcesBySourceId.end()) { | |
| 46 RTCRtpContributingSource* contributingSource = | |
| 47 new RTCRtpContributingSource(this, *webContributingSource); | |
| 48 m_contributingSourcesBySourceId.insert(contributingSource->source(), | |
| 49 contributingSource); | |
| 50 m_contributingSources.push_back(contributingSource); | |
| 51 } else { | |
| 52 *it->value = *webContributingSource; | |
| 53 m_contributingSources.push_back(it->value); | |
| 54 } | |
| 55 } | |
| 56 // Clear the flag and schedule a microtask to reset it to true. This makes | |
| 57 // the cache valid until the next iteration of the event loop. As such, | |
|
foolip
2017/04/06 10:07:23
s/iteration of the event loop/microtask checkpoint
hbos_chromium
2017/04/06 11:10:15
Done.
The spec says objects are to be updated whe
Taylor_Brandstetter
2017/04/06 20:34:41
The webrtc editors ended up filing this exact bug
foolip
2017/04/07 06:49:51
OK. The situation is very similar to media element
Taylor_Brandstetter
2017/04/07 17:07:46
As far as I know, this is all the related state. F
foolip
2017/04/10 07:42:33
Great, thanks!
| |
| 58 // sources represent a snapshot and can be compared reliably in .js code, | |
| 59 // no risk of being updated due to an RTP packet arriving. E.g. | |
| 60 // "source.timestamp == source.timestamp" will always be true. | |
| 61 m_contributingSourcesNeedsUpdating = false; | |
| 62 Microtask::enqueueMicrotask( | |
| 63 WTF::bind(&RTCRtpReceiver::setContributingSourcesNeedsUpdating, | |
| 64 wrapWeakPersistent(this))); | |
| 65 } | |
| 66 } | |
| 67 | |
| 68 void RTCRtpReceiver::setContributingSourcesNeedsUpdating() { | |
| 69 m_contributingSourcesNeedsUpdating = true; | |
| 70 } | |
| 71 | |
| 23 DEFINE_TRACE(RTCRtpReceiver) { | 72 DEFINE_TRACE(RTCRtpReceiver) { |
| 24 visitor->trace(m_track); | 73 visitor->trace(m_track); |
| 74 visitor->trace(m_contributingSourcesBySourceId); | |
| 75 visitor->trace(m_contributingSources); | |
| 25 } | 76 } |
| 26 | 77 |
| 27 } // namespace blink | 78 } // namespace blink |
| OLD | NEW |