Skip to content

Commit d1f397a

Browse files
philnwebkit-commit-queue
authored andcommitted
[GStreamer][WebRTC] An audio track should be muted when capture is interrupted by the OS.
https://bugs.webkit.org/show_bug.cgi?id=196606 Patch by Philippe Normand <pnormand@igalia.com> on 2021-04-12 Reviewed by Xabier Rodriguez-Calvar. Source/WebCore: Add basic interruption support in the audio capture source and mock audio capture source. * platform/mediastream/gstreamer/GStreamerAudioCaptureSource.cpp: (WebCore::GStreamerAudioCaptureSource::interrupted const): (WebCore::GStreamerAudioCaptureSource::setInterruptedForTesting): * platform/mediastream/gstreamer/GStreamerAudioCaptureSource.h: * platform/mediastream/gstreamer/GStreamerCapturer.cpp: (WebCore::GStreamerCapturer::setupPipeline): (WebCore::GStreamerCapturer::interrupted const): (WebCore::GStreamerCapturer::setInterrupted): * platform/mediastream/gstreamer/GStreamerCapturer.h: * platform/mediastream/gstreamer/MockRealtimeAudioSourceGStreamer.cpp: (WebCore::MockRealtimeAudioSourceGStreamer::setInterruptedForTesting): * platform/mediastream/gstreamer/MockRealtimeAudioSourceGStreamer.h: LayoutTests: * platform/glib/TestExpectations: fast/mediastream/media-stream-track-interrupted.html is now passing. Canonical link: https://commits.webkit.org/236397@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@275827 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 71d0f15 commit d1f397a

9 files changed

Lines changed: 76 additions & 5 deletions

File tree

LayoutTests/ChangeLog

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
2021-04-12 Philippe Normand <pnormand@igalia.com>
2+
3+
[GStreamer][WebRTC] An audio track should be muted when capture is interrupted by the OS.
4+
https://bugs.webkit.org/show_bug.cgi?id=196606
5+
6+
Reviewed by Xabier Rodriguez-Calvar.
7+
8+
* platform/glib/TestExpectations: fast/mediastream/media-stream-track-interrupted.html is now passing.
9+
110
2021-04-12 Sam Weinig <weinig@apple.com>
211

312
Update color-contrast() to support a target contrast ratio

LayoutTests/platform/glib/TestExpectations

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,6 @@ webkit.org/b/210337 fast/mediastream/mediastreamtrack-audio-clone.html [ Failure
532532
webkit.org/b/210385 fast/mediastream/stream-switch.html [ Crash Timeout ]
533533
webkit.org/b/210528 fast/mediastream/MediaStream-MediaElement-setObject-null.html [ Crash Pass ]
534534
webkit.org/b/210528 fast/mediastream/mediastreamtrack-video-frameRate-clone-decreasing.html [ Crash Pass ]
535-
webkit.org/b/213011 fast/mediastream/media-stream-track-interrupted.html [ Failure ]
536535

537536
webkit.org/b/203078 media/media-source/media-source-remove-unload-crash.html [ Crash Timeout Pass ]
538537
webkit.org/b/210528 media/media-source/media-source-seek-back.html [ Crash Pass ]

Source/WebCore/ChangeLog

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
2021-04-12 Philippe Normand <pnormand@igalia.com>
2+
3+
[GStreamer][WebRTC] An audio track should be muted when capture is interrupted by the OS.
4+
https://bugs.webkit.org/show_bug.cgi?id=196606
5+
6+
Reviewed by Xabier Rodriguez-Calvar.
7+
8+
Add basic interruption support in the audio capture source and mock audio capture source.
9+
10+
* platform/mediastream/gstreamer/GStreamerAudioCaptureSource.cpp:
11+
(WebCore::GStreamerAudioCaptureSource::interrupted const):
12+
(WebCore::GStreamerAudioCaptureSource::setInterruptedForTesting):
13+
* platform/mediastream/gstreamer/GStreamerAudioCaptureSource.h:
14+
* platform/mediastream/gstreamer/GStreamerCapturer.cpp:
15+
(WebCore::GStreamerCapturer::setupPipeline):
16+
(WebCore::GStreamerCapturer::interrupted const):
17+
(WebCore::GStreamerCapturer::setInterrupted):
18+
* platform/mediastream/gstreamer/GStreamerCapturer.h:
19+
* platform/mediastream/gstreamer/MockRealtimeAudioSourceGStreamer.cpp:
20+
(WebCore::MockRealtimeAudioSourceGStreamer::setInterruptedForTesting):
21+
* platform/mediastream/gstreamer/MockRealtimeAudioSourceGStreamer.h:
22+
123
2021-04-12 Sam Weinig <weinig@apple.com>
224

325
Update color-contrast() to support a target contrast ratio

Source/WebCore/platform/mediastream/gstreamer/GStreamerAudioCaptureSource.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,17 @@ const RealtimeMediaSourceSettings& GStreamerAudioCaptureSource::settings()
208208
return m_currentSettings.value();
209209
}
210210

211+
bool GStreamerAudioCaptureSource::interrupted() const
212+
{
213+
return m_capturer->isInterrupted() || RealtimeMediaSource::interrupted();
214+
}
215+
216+
void GStreamerAudioCaptureSource::setInterruptedForTesting(bool isInterrupted)
217+
{
218+
m_capturer->setInterrupted(isInterrupted);
219+
RealtimeMediaSource::setInterruptedForTesting(isInterrupted);
220+
}
221+
211222
} // namespace WebCore
212223

213224
#endif // ENABLE(MEDIA_STREAM) && USE(GSTREAMER)

Source/WebCore/platform/mediastream/gstreamer/GStreamerAudioCaptureSource.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ class GStreamerAudioCaptureSource : public RealtimeMediaSource {
5353
mutable Optional<RealtimeMediaSourceSettings> m_currentSettings;
5454

5555
private:
56+
bool interrupted() const final;
57+
void setInterruptedForTesting(bool) final;
58+
5659
bool isCaptureSource() const final { return true; }
5760
void settingsDidChange(OptionSet<RealtimeMediaSourceSettings::Flag>) final;
5861

Source/WebCore/platform/mediastream/gstreamer/GStreamerCapturer.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,16 @@ void GStreamerCapturer::setupPipeline()
108108
GRefPtr<GstElement> source = createSource();
109109
GRefPtr<GstElement> converter = createConverter();
110110

111+
m_valve = makeElement("valve");
111112
m_capsfilter = makeElement("capsfilter");
112113
m_tee = makeElement("tee");
113114
m_sink = makeElement("appsink");
114115

115116
gst_app_sink_set_emit_signals(GST_APP_SINK(m_sink.get()), TRUE);
116117
g_object_set(m_capsfilter.get(), "caps", m_caps.get(), nullptr);
117118

118-
gst_bin_add_many(GST_BIN(m_pipeline.get()), source.get(), converter.get(), m_capsfilter.get(), m_tee.get(), nullptr);
119-
gst_element_link_many(source.get(), converter.get(), m_capsfilter.get(), m_tee.get(), nullptr);
119+
gst_bin_add_many(GST_BIN(m_pipeline.get()), source.get(), converter.get(), m_capsfilter.get(), m_valve.get(), m_tee.get(), nullptr);
120+
gst_element_link_many(source.get(), converter.get(), m_capsfilter.get(), m_valve.get(), m_tee.get(), nullptr);
120121

121122
addSink(m_sink.get());
122123

@@ -182,6 +183,18 @@ void GStreamerCapturer::stop()
182183
gst_element_set_state(pipeline(), GST_STATE_NULL);
183184
}
184185

186+
bool GStreamerCapturer::isInterrupted() const
187+
{
188+
gboolean isInterrupted;
189+
g_object_get(m_valve.get(), "drop", &isInterrupted, nullptr);
190+
return isInterrupted;
191+
}
192+
193+
void GStreamerCapturer::setInterrupted(bool isInterrupted)
194+
{
195+
g_object_set(m_valve.get(), "drop", isInterrupted, nullptr);
196+
}
197+
185198
} // namespace WebCore
186199

187200
#endif // ENABLE(VIDEO) && ENABLE(MEDIA_STREAM) && USE(GSTREAMER)

Source/WebCore/platform/mediastream/gstreamer/GStreamerCapturer.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ class GStreamerCapturer {
3939
~GStreamerCapturer();
4040

4141
void setupPipeline();
42-
virtual void play();
43-
virtual void stop();
42+
void play();
43+
void stop();
4444
GstCaps* caps();
4545
void addSink(GstElement *newSink);
4646
GstElement* makeElement(const char* factoryName);
@@ -54,9 +54,13 @@ class GStreamerCapturer {
5454
GstElement* pipeline() const { return m_pipeline.get(); }
5555
virtual GstElement* createConverter() = 0;
5656

57+
bool isInterrupted() const;
58+
void setInterrupted(bool);
59+
5760
protected:
5861
GRefPtr<GstElement> m_sink;
5962
GRefPtr<GstElement> m_src;
63+
GRefPtr<GstElement> m_valve;
6064
GRefPtr<GstElement> m_tee;
6165
GRefPtr<GstElement> m_capsfilter;
6266
GRefPtr<GstDevice> m_device;

Source/WebCore/platform/mediastream/gstreamer/MockRealtimeAudioSourceGStreamer.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,12 @@ void MockRealtimeAudioSourceGStreamer::reconfigure()
140140
addHum(s_NoiseVolume, s_NoiseFrequency, rate, 0, m_bipBopBuffer.data(), sampleCount);
141141
}
142142

143+
void MockRealtimeAudioSourceGStreamer::setInterruptedForTesting(bool isInterrupted)
144+
{
145+
m_isInterrupted = isInterrupted;
146+
MockRealtimeAudioSource::setInterruptedForTesting(isInterrupted);
147+
}
148+
143149
} // namespace WebCore
144150

145151
#endif // ENABLE(MEDIA_STREAM) && USE(GSTREAMER)

Source/WebCore/platform/mediastream/gstreamer/MockRealtimeAudioSourceGStreamer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,15 @@ class MockRealtimeAudioSourceGStreamer final : public MockRealtimeAudioSource {
4545
void reconfigure();
4646
void addHum(float amplitude, float frequency, float sampleRate, uint64_t start, float *p, uint64_t count);
4747

48+
bool interrupted() const final { return m_isInterrupted; };
49+
void setInterruptedForTesting(bool) final;
50+
4851
Optional<GStreamerAudioStreamDescription> m_streamFormat;
4952
Vector<float> m_bipBopBuffer;
5053
uint32_t m_maximiumFrameCount;
5154
uint64_t m_samplesEmitted { 0 };
5255
uint64_t m_samplesRendered { 0 };
56+
bool m_isInterrupted { false };
5357
};
5458

5559
} // namespace WebCore

0 commit comments

Comments
 (0)