Changeset 252987 in webkit
- Timestamp:
- Dec 2, 2019 9:26:29 AM (4 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r252986 r252987 1 2019-12-02 youenn fablet <youenn@apple.com> 2 3 Simplify RealtimeOutgoingAudioSource and RealtimeOutgoingVideooSource observeSource/unobserveSource pattern 4 https://bugs.webkit.org/show_bug.cgi?id=204570 5 6 Reviewed by Eric Carlson. 7 8 Previously, the outgoing source was observing/unobserving its track if sinks were added/removed. 9 We made LibWebRTCRTCRtpSenderBackend stopping the observing in its destructor. 10 This makes things complex and we are not always unobserving fast enough for all outgoing sources. 11 12 To make it simpler, the outgoing source is no longer handling the observing/unobserving of its track. 13 Instead, its LibWebRTCRtpSenderBackend is handling it directly. 14 Observing starts when LibWebRTCRtpSenderBackend gets the track and unobserving happens either on LibWebRTCRtpSenderBackend destruction 15 or when the LibWebRTCRtpSenderBackend is no longer interested in the track. 16 This is slight less optimal as we might observe the track even if the source has no sink but this should not happen often in practice. 17 18 Removed some unneeded methods. 19 20 Covered by existing tests no longer failing a debug ASSERTION. 21 22 * Modules/mediastream/libwebrtc/LibWebRTCRtpSenderBackend.cpp: 23 (WebCore::LibWebRTCRtpSenderBackend::LibWebRTCRtpSenderBackend): 24 (WebCore::LibWebRTCRtpSenderBackend::~LibWebRTCRtpSenderBackend): 25 (WebCore::LibWebRTCRtpSenderBackend::startSource): 26 (WebCore::LibWebRTCRtpSenderBackend::stopSource): 27 (WebCore::LibWebRTCRtpSenderBackend::replaceTrack): 28 (WebCore::LibWebRTCRtpSenderBackend::audioSource): 29 (WebCore::LibWebRTCRtpSenderBackend::videoSource): 30 (WebCore::LibWebRTCRtpSenderBackend::hasSource const): 31 (WebCore::LibWebRTCRtpSenderBackend::setSource): 32 (WebCore::LibWebRTCRtpSenderBackend::takeSource): 33 * Modules/mediastream/libwebrtc/LibWebRTCRtpSenderBackend.h: 34 * platform/mediastream/RealtimeOutgoingAudioSource.cpp: 35 (WebCore::RealtimeOutgoingAudioSource::~RealtimeOutgoingAudioSource): 36 (WebCore::RealtimeOutgoingAudioSource::observeSource): 37 (WebCore::RealtimeOutgoingAudioSource::setSource): 38 (WebCore::RealtimeOutgoingAudioSource::AddSink): 39 (WebCore::RealtimeOutgoingAudioSource::RemoveSink): 40 * platform/mediastream/RealtimeOutgoingAudioSource.h: 41 (WebCore::RealtimeOutgoingAudioSource::start): 42 * platform/mediastream/RealtimeOutgoingVideoSource.cpp: 43 (WebCore::RealtimeOutgoingVideoSource::~RealtimeOutgoingVideoSource): 44 (WebCore::RealtimeOutgoingVideoSource::observeSource): 45 (WebCore::RealtimeOutgoingVideoSource::setSource): 46 (WebCore::RealtimeOutgoingVideoSource::AddOrUpdateSink): 47 (WebCore::RealtimeOutgoingVideoSource::RemoveSink): 48 * platform/mediastream/RealtimeOutgoingVideoSource.h: 49 (WebCore::RealtimeOutgoingVideoSource::start): 50 * platform/mediastream/mac/RealtimeOutgoingAudioSourceCocoa.cpp: 51 (WebCore::RealtimeOutgoingAudioSourceCocoa::~RealtimeOutgoingAudioSourceCocoa): Deleted. 52 1 53 2019-12-02 youenn fablet <youenn@apple.com> 2 54 -
trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCRtpSenderBackend.cpp
r251989 r252987 38 38 namespace WebCore { 39 39 40 LibWebRTCRtpSenderBackend::LibWebRTCRtpSenderBackend(LibWebRTCPeerConnectionBackend& backend, rtc::scoped_refptr<webrtc::RtpSenderInterface>&& rtcSender, Source&& source) 41 : m_peerConnectionBackend(makeWeakPtr(&backend)) 42 , m_rtcSender(WTFMove(rtcSender)) 43 , m_source(WTFMove(source)) 44 { 45 startSource(); 46 } 47 40 48 LibWebRTCRtpSenderBackend::~LibWebRTCRtpSenderBackend() 41 49 { 42 WTF::switchOn(m_source, [] (Ref<RealtimeOutgoingAudioSource>& source) { 43 source->stop(); 44 }, [] (Ref<RealtimeOutgoingVideoSource>& source) { 45 source->stop(); 46 }, [] (std::nullptr_t&) { 50 stopSource(); 51 } 52 53 void LibWebRTCRtpSenderBackend::startSource() 54 { 55 switchOn(m_source, [](Ref<RealtimeOutgoingAudioSource>& source) { 56 source->start(); 57 }, [](Ref<RealtimeOutgoingVideoSource>& source) { 58 source->start(); 59 }, [](std::nullptr_t&) { 47 60 }); 48 61 } 49 62 50 template<typename Source> 51 static inline bool updateTrackSource(Source& source, MediaStreamTrack* track) 63 void LibWebRTCRtpSenderBackend::stopSource() 52 64 { 53 if (!track) { 54 source.stop(); 55 return true; 56 } 57 return source.setSource(track->privateTrack()); 65 switchOn(m_source, [](Ref<RealtimeOutgoingAudioSource>& source) { 66 source->stop(); 67 }, [](Ref<RealtimeOutgoingVideoSource>& source) { 68 source->stop(); 69 }, [](std::nullptr_t&) { 70 }); 71 m_source = nullptr; 58 72 } 59 73 … … 65 79 } 66 80 67 auto* currentTrack = sender.track(); 68 69 ASSERT(!track || !currentTrack || currentTrack->source().type() == track->source().type()); 70 if (currentTrack) { 71 switch (currentTrack->source().type()) { 72 case RealtimeMediaSource::Type::None: 73 ASSERT_NOT_REACHED(); 74 promise.reject(InvalidModificationError); 75 break; 76 case RealtimeMediaSource::Type::Audio: 77 if (!updateTrackSource(*audioSource(), track.get())) { 78 promise.reject(InvalidModificationError); 79 return; 80 } 81 break; 82 case RealtimeMediaSource::Type::Video: 83 if (!updateTrackSource(*videoSource(), track.get())) { 84 promise.reject(InvalidModificationError); 85 return; 86 } 87 break; 88 } 81 if (!track) 82 stopSource(); 83 else if (auto* currentTrack = sender.track()) { 84 switchOn(m_source, [&](Ref<RealtimeOutgoingAudioSource>& source) { 85 ASSERT(track->source().type() == RealtimeMediaSource::Type::Audio); 86 source->stop(); 87 source->setSource(track->privateTrack()); 88 source->start(); 89 }, [&](Ref<RealtimeOutgoingVideoSource>& source) { 90 ASSERT(track->source().type() == RealtimeMediaSource::Type::Video); 91 source->stop(); 92 source->setSource(track->privateTrack()); 93 source->start(); 94 }, [](std::nullptr_t&) { 95 ASSERT_NOT_REACHED(); 96 }); 89 97 } 90 98 … … 108 116 } 109 117 110 m_source = nullptr;111 118 m_peerConnectionBackend->setSenderSourceFromTrack(*this, *protectedSender->track()); 112 119 promise.resolve(); … … 152 159 } 153 160 161 RealtimeOutgoingVideoSource* LibWebRTCRtpSenderBackend::videoSource() 162 { 163 return switchOn(m_source, 164 [](Ref<RealtimeOutgoingVideoSource>& source) { return source.ptr(); }, 165 [](const auto&) -> RealtimeOutgoingVideoSource* { return nullptr; } 166 ); 167 } 168 169 bool LibWebRTCRtpSenderBackend::hasSource() const 170 { 171 return switchOn(m_source, 172 [](const std::nullptr_t&) { return false; }, 173 [](const auto&) { return true; } 174 ); 175 } 176 177 void LibWebRTCRtpSenderBackend::setSource(Source&& source) 178 { 179 stopSource(); 180 m_source = WTFMove(source); 181 startSource(); 182 } 183 184 void LibWebRTCRtpSenderBackend::takeSource(LibWebRTCRtpSenderBackend& backend) 185 { 186 ASSERT(backend.hasSource()); 187 stopSource(); 188 m_source = WTFMove(backend.m_source); 189 backend.m_source = nullptr; 190 } 191 154 192 } // namespace WebCore 155 193 -
trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCRtpSenderBackend.h
r252472 r252987 55 55 56 56 using Source = Variant<std::nullptr_t, Ref<RealtimeOutgoingAudioSource>, Ref<RealtimeOutgoingVideoSource>>; 57 LibWebRTCRtpSenderBackend(LibWebRTCPeerConnectionBackend& backend, rtc::scoped_refptr<webrtc::RtpSenderInterface>&& rtcSender, Source&& source) 58 : m_peerConnectionBackend(makeWeakPtr(&backend)) 59 , m_rtcSender(WTFMove(rtcSender)) 60 , m_source(WTFMove(source)) 61 { 62 } 57 LibWebRTCRtpSenderBackend(LibWebRTCPeerConnectionBackend&, rtc::scoped_refptr<webrtc::RtpSenderInterface>&&, Source&&); 63 58 ~LibWebRTCRtpSenderBackend(); 64 59 … … 66 61 webrtc::RtpSenderInterface* rtcSender() { return m_rtcSender.get(); } 67 62 68 RealtimeOutgoingAudioSource* audioSource() 69 { 70 return WTF::switchOn(m_source, 71 [] (Ref<RealtimeOutgoingAudioSource>& source) { return source.ptr(); }, 72 [] (const auto&) -> RealtimeOutgoingAudioSource* { return nullptr; } 73 ); 74 } 75 76 RealtimeOutgoingVideoSource* videoSource() 77 { 78 return WTF::switchOn(m_source, 79 [] (Ref<RealtimeOutgoingVideoSource>& source) { return source.ptr(); }, 80 [] (const auto&) -> RealtimeOutgoingVideoSource* { return nullptr; } 81 ); 82 } 83 84 bool hasSource() const 85 { 86 return WTF::switchOn(m_source, 87 [] (const std::nullptr_t&) { return false; }, 88 [] (const auto&) { return true; } 89 ); 90 } 91 92 void clearSource() 93 { 94 ASSERT(hasSource()); 95 m_source = nullptr; 96 } 97 98 void setSource(Source&& source) 99 { 100 ASSERT(!hasSource()); 101 m_source = WTFMove(source); 102 ASSERT(hasSource()); 103 } 104 105 void takeSource(LibWebRTCRtpSenderBackend& backend) 106 { 107 ASSERT(backend.hasSource()); 108 setSource(WTFMove(backend.m_source)); 109 backend.m_source = nullptr; 110 } 63 RealtimeOutgoingVideoSource* videoSource(); 64 void clearSource() { setSource(nullptr); } 65 void setSource(Source&&); 66 void takeSource(LibWebRTCRtpSenderBackend&); 111 67 112 68 private: … … 115 71 void setParameters(const RTCRtpSendParameters&, DOMPromiseDeferred<void>&&) final; 116 72 std::unique_ptr<RTCDTMFSenderBackend> createDTMFBackend() final; 73 74 void startSource(); 75 void stopSource(); 76 bool hasSource() const; 117 77 118 78 WeakPtr<LibWebRTCPeerConnectionBackend> m_peerConnectionBackend; -
trunk/Source/WebCore/platform/mediastream/RealtimeOutgoingAudioSource.cpp
r251989 r252987 46 46 RealtimeOutgoingAudioSource::~RealtimeOutgoingAudioSource() 47 47 { 48 ASSERT(!m_audioSource->hasObserver(*this)); 48 ASSERT(!m_audioSource->hasObserver(*this)); 49 #if !ASSERT_DISABLED 50 auto locker = holdLock(m_sinksLock); 51 #endif 49 52 ASSERT(m_sinks.isEmpty()); 53 50 54 stop(); 51 55 } … … 53 57 void RealtimeOutgoingAudioSource::observeSource() 54 58 { 59 ASSERT(!m_audioSource->hasObserver(*this)); 55 60 m_audioSource->addObserver(*this); 56 61 initializeConverter(); … … 62 67 } 63 68 64 boolRealtimeOutgoingAudioSource::setSource(Ref<MediaStreamTrackPrivate>&& newSource)69 void RealtimeOutgoingAudioSource::setSource(Ref<MediaStreamTrackPrivate>&& newSource) 65 70 { 66 71 ALWAYS_LOG("Changing source to ", newSource->logIdentifier()); 67 auto locker = holdLock(m_sinksLock);68 bool hasSinks = !m_sinks.isEmpty();69 72 70 if (hasSinks) 71 unobserveSource(); 73 ASSERT(!m_audioSource->hasObserver(*this)); 72 74 m_audioSource = WTFMove(newSource); 73 if (hasSinks)74 observeSource();75 76 75 sourceUpdated(); 77 78 return true;79 76 } 80 77 … … 97 94 void RealtimeOutgoingAudioSource::AddSink(webrtc::AudioTrackSinkInterface* sink) 98 95 { 99 {100 96 auto locker = holdLock(m_sinksLock); 101 if (!m_sinks.add(sink) || m_sinks.size() != 1) 102 return; 103 } 104 105 callOnMainThread([protectedThis = makeRef(*this)]() { 106 protectedThis->observeSource(); 107 }); 97 m_sinks.add(sink); 108 98 } 109 99 110 100 void RealtimeOutgoingAudioSource::RemoveSink(webrtc::AudioTrackSinkInterface* sink) 111 101 { 112 {113 102 auto locker = holdLock(m_sinksLock); 114 if (!m_sinks.remove(sink) || !m_sinks.isEmpty()) 115 return; 116 } 117 118 unobserveSource(); 103 m_sinks.remove(sink); 119 104 } 120 105 -
trunk/Source/WebCore/platform/mediastream/RealtimeOutgoingAudioSource.h
r252472 r252987 65 65 ~RealtimeOutgoingAudioSource(); 66 66 67 void start() { observeSource(); } 67 68 void stop() { unobserveSource(); } 68 69 69 boolsetSource(Ref<MediaStreamTrackPrivate>&&);70 void setSource(Ref<MediaStreamTrackPrivate>&&); 70 71 MediaStreamTrackPrivate& source() const { return m_audioSource.get(); } 71 72 72 73 protected: 73 74 explicit RealtimeOutgoingAudioSource(Ref<MediaStreamTrackPrivate>&&); 74 75 void unobserveSource();76 75 77 76 bool isSilenced() const { return m_muted || !m_enabled; } … … 106 105 107 106 void observeSource(); 107 void unobserveSource(); 108 108 109 109 void sourceMutedChanged(); -
trunk/Source/WebCore/platform/mediastream/RealtimeOutgoingVideoSource.cpp
r251989 r252987 57 57 RealtimeOutgoingVideoSource::~RealtimeOutgoingVideoSource() 58 58 { 59 ASSERT(!m_videoSource->hasObserver(*this)); 59 ASSERT(!m_videoSource->hasObserver(*this)); 60 #if !ASSERT_DISABLED 61 auto locker = holdLock(m_sinksLock); 62 #endif 60 63 ASSERT(m_sinks.isEmpty()); 61 64 stop(); … … 64 67 void RealtimeOutgoingVideoSource::observeSource() 65 68 { 69 ASSERT(!m_videoSource->hasObserver(*this)); 66 70 m_videoSource->addObserver(*this); 67 71 initializeFromSource(); … … 73 77 } 74 78 75 bool RealtimeOutgoingVideoSource::setSource(Ref<MediaStreamTrackPrivate>&& newSource) 76 { 77 if (!m_initialSettings) 78 m_initialSettings = m_videoSource->source().settings(); 79 80 auto locker = holdLock(m_sinksLock); 81 bool hasSinks = !m_sinks.isEmpty(); 82 83 if (hasSinks) 84 unobserveSource(); 79 void RealtimeOutgoingVideoSource::setSource(Ref<MediaStreamTrackPrivate>&& newSource) 80 { 81 ASSERT(!m_videoSource->hasObserver(*this)); 85 82 m_videoSource = WTFMove(newSource); 86 if (hasSinks)87 observeSource();88 89 return true;90 83 } 91 84 … … 145 138 m_shouldApplyRotation = true; 146 139 147 { 148 auto locker = holdLock(m_sinksLock); 149 if (!m_sinks.add(sink) || m_sinks.size() != 1) 150 return; 151 } 152 153 callOnMainThread([protectedThis = makeRef(*this)]() { 154 protectedThis->observeSource(); 155 }); 140 auto locker = holdLock(m_sinksLock); 141 m_sinks.add(sink); 156 142 } 157 143 158 144 void RealtimeOutgoingVideoSource::RemoveSink(rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) 159 145 { 160 { 161 auto locker = holdLock(m_sinksLock); 162 163 if (!m_sinks.remove(sink) || m_sinks.size()) 164 return; 165 } 166 167 unobserveSource(); 168 169 callOnMainThread([protectedThis = makeRef(*this)]() { 170 if (protectedThis->m_blackFrameTimer.isActive()) 171 protectedThis->m_blackFrameTimer.stop(); 172 }); 146 auto locker = holdLock(m_sinksLock); 147 m_sinks.remove(sink); 173 148 } 174 149 -
trunk/Source/WebCore/platform/mediastream/RealtimeOutgoingVideoSource.h
r252472 r252987 60 60 ~RealtimeOutgoingVideoSource(); 61 61 62 void start() { observeSource(); } 62 63 void stop(); 63 boolsetSource(Ref<MediaStreamTrackPrivate>&&);64 void setSource(Ref<MediaStreamTrackPrivate>&&); 64 65 MediaStreamTrackPrivate& source() const { return m_videoSource.get(); } 65 66 … … 129 130 130 131 Ref<MediaStreamTrackPrivate> m_videoSource; 131 Optional<RealtimeMediaSourceSettings> m_initialSettings;132 132 Timer m_blackFrameTimer; 133 133 rtc::scoped_refptr<webrtc::VideoFrameBuffer> m_blackFrame; -
trunk/Source/WebCore/platform/mediastream/gstreamer/RealtimeOutgoingAudioSourceLibWebRTC.cpp
r239921 r252987 39 39 RealtimeOutgoingAudioSourceLibWebRTC::~RealtimeOutgoingAudioSourceLibWebRTC() 40 40 { 41 unobserveSource();42 41 m_sampleConverter = nullptr; 43 42 } -
trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingAudioSourceCocoa.cpp
r252960 r252987 51 51 } 52 52 53 RealtimeOutgoingAudioSourceCocoa::~RealtimeOutgoingAudioSourceCocoa() 54 { 55 unobserveSource(); 56 } 53 RealtimeOutgoingAudioSourceCocoa::~RealtimeOutgoingAudioSourceCocoa() = default; 57 54 58 55 Ref<RealtimeOutgoingAudioSource> RealtimeOutgoingAudioSource::create(Ref<MediaStreamTrackPrivate>&& audioSource)
Note: See TracChangeset
for help on using the changeset viewer.