Support arbitrary video resolution in getUserMedia API
[WebKit-https.git] / Source / WebCore / platform / mediastream / gstreamer / MockGStreamerAudioCaptureSource.cpp
1 /*
2  * Copyright (C) 2018 Metrological Group B.V.
3  * Author: Thibault Saunier <tsaunier@igalia.com>
4  * Author: Alejandro G. Castro  <alex@igalia.com>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public License
17  * aint with this library; see the file COPYING.LIB.  If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21
22 #include "config.h"
23
24 #if ENABLE(MEDIA_STREAM) && USE(LIBWEBRTC) && USE(GSTREAMER)
25 #include "MockGStreamerAudioCaptureSource.h"
26
27 #include "MockRealtimeAudioSource.h"
28
29 namespace WebCore {
30
31 class WrappedMockRealtimeAudioSource : public MockRealtimeAudioSource {
32 public:
33     WrappedMockRealtimeAudioSource(const String& deviceID, const String& name)
34         : MockRealtimeAudioSource(deviceID, name)
35     {
36     }
37 };
38
39 CaptureSourceOrError MockRealtimeAudioSource::create(const String& deviceID,
40     const String& name, const MediaConstraints* constraints)
41 {
42     auto source = adoptRef(*new MockGStreamerAudioCaptureSource(deviceID, name));
43
44     if (constraints && source->applyConstraints(*constraints))
45         return { };
46
47     return CaptureSourceOrError(WTFMove(source));
48 }
49
50 std::optional<std::pair<String, String>> MockGStreamerAudioCaptureSource::applyConstraints(const MediaConstraints& constraints)
51 {
52     m_wrappedSource->applyConstraints(constraints);
53     return GStreamerAudioCaptureSource::applyConstraints(constraints);
54 }
55
56 void MockGStreamerAudioCaptureSource::applyConstraints(const MediaConstraints& constraints, SuccessHandler&& successHandler, FailureHandler&& failureHandler)
57 {
58     m_wrappedSource->applyConstraints(constraints, WTFMove(successHandler), WTFMove(failureHandler));
59 }
60
61 MockGStreamerAudioCaptureSource::MockGStreamerAudioCaptureSource(const String& deviceID, const String& name)
62     : GStreamerAudioCaptureSource(deviceID, name)
63     , m_wrappedSource(std::make_unique<WrappedMockRealtimeAudioSource>(deviceID, name))
64 {
65     m_wrappedSource->addObserver(*this);
66 }
67
68 MockGStreamerAudioCaptureSource::~MockGStreamerAudioCaptureSource()
69 {
70     m_wrappedSource->removeObserver(*this);
71 }
72
73 void MockGStreamerAudioCaptureSource::stopProducingData()
74 {
75     m_wrappedSource->stop();
76
77     GStreamerAudioCaptureSource::stopProducingData();
78 }
79
80 void MockGStreamerAudioCaptureSource::startProducingData()
81 {
82     GStreamerAudioCaptureSource::startProducingData();
83     m_wrappedSource->start();
84 }
85
86 const RealtimeMediaSourceSettings& MockGStreamerAudioCaptureSource::settings()
87 {
88     return m_wrappedSource->settings();
89 }
90
91 const RealtimeMediaSourceCapabilities& MockGStreamerAudioCaptureSource::capabilities()
92 {
93     m_capabilities = m_wrappedSource->capabilities();
94     m_currentSettings = m_wrappedSource->settings();
95     return m_wrappedSource->capabilities();
96 }
97
98 void MockGStreamerAudioCaptureSource::captureFailed()
99 {
100     stop();
101     RealtimeMediaSource::captureFailed();
102 }
103
104 } // namespace WebCore
105
106 #endif // ENABLE(MEDIA_STREAM) && USE(LIBWEBRTC) && USE(GSTREAMER)