- Revision
- 235722
- Author
- [email protected]
- Date
- 2018-09-05 22:08:43 -0700 (Wed, 05 Sep 2018)
Log Message
Move ownership of outgoing source to RTCRtpSender backend
https://bugs.webkit.org/show_bug.cgi?id=189310
Reviewed by Alex Christensen.
RTCRtpSender should own the source so that it can replace/stop it.
Since this is libwebrtc specific, the source is actually owned by the backend.
Simplified replaceTrack a bit based on that.
No change of behavior.
* Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:
(WebCore::LibWebRTCMediaEndpoint::addTrack):
* Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp:
(WebCore::LibWebRTCPeerConnectionBackend::doStop):
(WebCore::updateTrackSource):
(WebCore::LibWebRTCPeerConnectionBackend::replaceTrack):
(WebCore::LibWebRTCPeerConnectionBackend::applyRotationForOutgoingVideoSources):
* Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.h:
* Modules/mediastream/libwebrtc/LibWebRTCRtpSenderBackend.h:
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (235721 => 235722)
--- trunk/Source/WebCore/ChangeLog 2018-09-06 04:07:53 UTC (rev 235721)
+++ trunk/Source/WebCore/ChangeLog 2018-09-06 05:08:43 UTC (rev 235722)
@@ -1,3 +1,26 @@
+2018-09-05 Youenn Fablet <[email protected]>
+
+ Move ownership of outgoing source to RTCRtpSender backend
+ https://bugs.webkit.org/show_bug.cgi?id=189310
+
+ Reviewed by Alex Christensen.
+
+ RTCRtpSender should own the source so that it can replace/stop it.
+ Since this is libwebrtc specific, the source is actually owned by the backend.
+ Simplified replaceTrack a bit based on that.
+
+ No change of behavior.
+
+ * Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:
+ (WebCore::LibWebRTCMediaEndpoint::addTrack):
+ * Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp:
+ (WebCore::LibWebRTCPeerConnectionBackend::doStop):
+ (WebCore::updateTrackSource):
+ (WebCore::LibWebRTCPeerConnectionBackend::replaceTrack):
+ (WebCore::LibWebRTCPeerConnectionBackend::applyRotationForOutgoingVideoSources):
+ * Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.h:
+ * Modules/mediastream/libwebrtc/LibWebRTCRtpSenderBackend.h:
+
2018-09-05 Brent Fulgham <[email protected]>
The width of an empty or nullptr TextRun should be zero
Modified: trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp (235721 => 235722)
--- trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp 2018-09-06 04:07:53 UTC (rev 235721)
+++ trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp 2018-09-06 05:08:43 UTC (rev 235722)
@@ -214,9 +214,9 @@
switch (track.privateTrack().type()) {
case RealtimeMediaSource::Type::Audio: {
- auto trackSource = RealtimeOutgoingAudioSource::create(track.privateTrack());
- auto audioTrack = m_peerConnectionFactory.CreateAudioTrack(track.id().utf8().data(), trackSource.ptr());
- m_peerConnectionBackend.addAudioSource(WTFMove(trackSource));
+ auto audioSource = RealtimeOutgoingAudioSource::create(track.privateTrack());
+ auto audioTrack = m_peerConnectionFactory.CreateAudioTrack(track.id().utf8().data(), audioSource.ptr());
+ sender.setSource(WTFMove(audioSource));
auto rtpSender = m_backend->AddTrack(audioTrack.get(), WTFMove(ids));
if (!rtpSender.ok())
return false;
@@ -226,7 +226,7 @@
case RealtimeMediaSource::Type::Video: {
auto videoSource = RealtimeOutgoingVideoSource::create(track.privateTrack());
auto videoTrack = m_peerConnectionFactory.CreateVideoTrack(track.id().utf8().data(), videoSource.ptr());
- m_peerConnectionBackend.addVideoSource(WTFMove(videoSource));
+ sender.setSource(WTFMove(videoSource));
auto rtpSender = m_backend->AddTrack(videoTrack.get(), WTFMove(ids));
if (!rtpSender.ok())
return false;
Modified: trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp (235721 => 235722)
--- trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp 2018-09-06 04:07:53 UTC (rev 235721)
+++ trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp 2018-09-06 05:08:43 UTC (rev 235722)
@@ -174,15 +174,7 @@
void LibWebRTCPeerConnectionBackend::doStop()
{
- for (auto& source : m_audioSources)
- source->stop();
- for (auto& source : m_videoSources)
- source->stop();
-
m_endpoint->stop();
-
- m_audioSources.clear();
- m_videoSources.clear();
m_pendingReceivers.clear();
}
@@ -208,16 +200,6 @@
addIceCandidateSucceeded();
}
-void LibWebRTCPeerConnectionBackend::addAudioSource(Ref<RealtimeOutgoingAudioSource>&& source)
-{
- m_audioSources.append(WTFMove(source));
-}
-
-void LibWebRTCPeerConnectionBackend::addVideoSource(Ref<RealtimeOutgoingVideoSource>&& source)
-{
- m_videoSources.append(WTFMove(source));
-}
-
static inline Ref<RTCRtpReceiver> createReceiverForSource(ScriptExecutionContext& context, Ref<RealtimeMediaSource>&& source)
{
auto remoteTrackPrivate = MediaStreamTrackPrivate::create(WTFMove(source), String { source->id() });
@@ -395,25 +377,12 @@
static inline bool updateTrackSource(Source& source, MediaStreamTrack* track)
{
if (!track) {
- source->stop();
+ source.stop();
return true;
}
- return source->setSource(track->privateTrack());
+ return source.setSource(track->privateTrack());
}
-template<typename Source>
-static inline bool tryUpdatingTrackSource(MediaStreamTrack& currentTrack, MediaStreamTrack* newTrack, const Vector<Source>& sources)
-{
- for (auto& source : sources) {
- if (&source->source() == ¤tTrack.privateTrack()) {
- if (!updateTrackSource(source, newTrack))
- return false;
- return true;
- }
- }
- return false;
-}
-
void LibWebRTCPeerConnectionBackend::replaceTrack(RTCRtpSender& sender, RefPtr<MediaStreamTrack>&& track, DOMPromiseDeferred<void>&& promise)
{
auto* currentTrack = sender.track();
@@ -426,13 +395,13 @@
promise.reject(InvalidModificationError);
break;
case RealtimeMediaSource::Type::Audio:
- if (!tryUpdatingTrackSource(*currentTrack, track.get(), m_audioSources)) {
+ if (!updateTrackSource(*backendFromRTPSender(sender).audioSource(), track.get())) {
promise.reject(InvalidModificationError);
return;
}
break;
case RealtimeMediaSource::Type::Video:
- if (!tryUpdatingTrackSource(*currentTrack, track.get(), m_videoSources)) {
+ if (!updateTrackSource(*backendFromRTPSender(sender).videoSource(), track.get())) {
promise.reject(InvalidModificationError);
return;
}
@@ -468,8 +437,10 @@
void LibWebRTCPeerConnectionBackend::applyRotationForOutgoingVideoSources()
{
- for (auto& source : m_videoSources)
- source->setApplyRotation(true);
+ for (auto& transceiver : m_peerConnection.getTransceivers()) {
+ if (auto* videoSource = backendFromRTPSender(transceiver->sender()).videoSource())
+ videoSource->setApplyRotation(true);
+ }
}
bool LibWebRTCPeerConnectionBackend::shouldOfferAllowToReceive(const char* kind) const
Modified: trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.h (235721 => 235722)
--- trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.h 2018-09-06 04:07:53 UTC (rev 235721)
+++ trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.h 2018-09-06 05:08:43 UTC (rev 235722)
@@ -52,9 +52,6 @@
LibWebRTCPeerConnectionBackend(RTCPeerConnection&, LibWebRTCProvider&);
~LibWebRTCPeerConnectionBackend();
- bool hasAudioSources() const { return m_audioSources.size(); }
- bool hasVideoSources() const { return m_videoSources.size(); }
-
void replaceTrack(RTCRtpSender&, RefPtr<MediaStreamTrack>&&, DOMPromiseDeferred<void>&&);
bool shouldOfferAllowToReceive(const char*) const;
@@ -84,8 +81,6 @@
friend class LibWebRTCMediaEndpoint;
friend class LibWebRTCRtpSenderBackend;
RTCPeerConnection& connection() { return m_peerConnection; }
- void addAudioSource(Ref<RealtimeOutgoingAudioSource>&&);
- void addVideoSource(Ref<RealtimeOutgoingVideoSource>&&);
void getStatsSucceeded(const DeferredPromise&, Ref<RTCStatsReport>&&);
@@ -119,8 +114,6 @@
bool m_isRemoteDescriptionSet { false };
Vector<std::unique_ptr<webrtc::IceCandidateInterface>> m_pendingCandidates;
- Vector<Ref<RealtimeOutgoingAudioSource>> m_audioSources;
- Vector<Ref<RealtimeOutgoingVideoSource>> m_videoSources;
Vector<Ref<RTCRtpReceiver>> m_pendingReceivers;
};
Modified: trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCRtpSenderBackend.h (235721 => 235722)
--- trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCRtpSenderBackend.h 2018-09-06 04:07:53 UTC (rev 235721)
+++ trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCRtpSenderBackend.h 2018-09-06 05:08:43 UTC (rev 235722)
@@ -28,6 +28,8 @@
#include "LibWebRTCMacros.h"
#include "RTCRtpSenderBackend.h"
+#include "RealtimeOutgoingAudioSource.h"
+#include "RealtimeOutgoingVideoSource.h"
#include <wtf/WeakPtr.h>
#pragma GCC diagnostic push
@@ -53,6 +55,42 @@
void setRTCSender(rtc::scoped_refptr<webrtc::RtpSenderInterface>&& rtcSender) { m_rtcSender = WTFMove(rtcSender); }
webrtc::RtpSenderInterface* rtcSender() { return m_rtcSender.get(); }
+ RealtimeOutgoingAudioSource* audioSource()
+ {
+ return WTF::switchOn(m_source,
+ [] (Ref<RealtimeOutgoingAudioSource>& source) { return source.ptr(); },
+ [] (const auto&) -> RealtimeOutgoingAudioSource* { return nullptr; }
+ );
+ }
+
+ RealtimeOutgoingVideoSource* videoSource()
+ {
+ return WTF::switchOn(m_source,
+ [] (Ref<RealtimeOutgoingVideoSource>& source) { return source.ptr(); },
+ [] (const auto&) -> RealtimeOutgoingVideoSource* { return nullptr; }
+ );
+ }
+
+ bool hasNoSource() const
+ {
+ return WTF::switchOn(m_source,
+ [] (const std::nullptr_t&) { return true; },
+ [] (const auto&) { return false; }
+ );
+ }
+
+ void setSource(Ref<RealtimeOutgoingAudioSource>&& source)
+ {
+ ASSERT(hasNoSource());
+ m_source = WTFMove(source);
+ }
+
+ void setSource(Ref<RealtimeOutgoingVideoSource>&& source)
+ {
+ ASSERT(hasNoSource());
+ m_source = WTFMove(source);
+ }
+
private:
void replaceTrack(RTCRtpSender&, RefPtr<MediaStreamTrack>&&, DOMPromiseDeferred<void>&&) final;
RTCRtpParameters getParameters() const final;
@@ -60,6 +98,7 @@
WeakPtr<LibWebRTCPeerConnectionBackend> m_peerConnectionBackend;
rtc::scoped_refptr<webrtc::RtpSenderInterface> m_rtcSender;
+ Variant<std::nullptr_t, Ref<RealtimeOutgoingAudioSource>, Ref<RealtimeOutgoingVideoSource>> m_source;
};
} // namespace WebCore