1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
/*
* Copyright (C) 2019-2022 Igalia S.L. All rights reserved.
* Copyright (C) 2022 Metrological Group B.V.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "config.h"
#include "GStreamerRtpSenderBackend.h"
#if ENABLE(WEB_RTC) && USE(GSTREAMER_WEBRTC)
#include "GStreamerDTMFSenderBackend.h"
#include "GStreamerDtlsTransportBackend.h"
#include "GStreamerPeerConnectionBackend.h"
#include "GStreamerRtpSenderTransformBackend.h"
#include "GStreamerWebRTCUtils.h"
#include "JSDOMPromiseDeferred.h"
#include "NotImplemented.h"
#include "RTCPeerConnection.h"
#include "RTCRtpSender.h"
#include "RealtimeOutgoingAudioSourceGStreamer.h"
#include "RealtimeOutgoingVideoSourceGStreamer.h"
#include "ScriptExecutionContext.h"
namespace WebCore {
template<typename Source>
static inline bool updateTrackSource(Source& source, MediaStreamTrack* track)
{
if (!track) {
source.stop();
return true;
}
return source.setTrack(track->privateTrack());
}
void GStreamerRtpSenderBackend::startSource()
{
switchOn(m_source, [](Ref<RealtimeOutgoingAudioSourceGStreamer>& source) {
source->start();
}, [](Ref<RealtimeOutgoingVideoSourceGStreamer>& source) {
source->start();
}, [](std::nullptr_t&) {
});
}
WARN_UNUSED_RETURN GRefPtr<GstElement> GStreamerRtpSenderBackend::stopSource()
{
switchOn(m_source, [](Ref<RealtimeOutgoingAudioSourceGStreamer>& source) {
source->stop();
return GRefPtr<GstElement>(source->bin());
}, [](Ref<RealtimeOutgoingVideoSourceGStreamer>& source) {
source->stop();
return GRefPtr<GstElement>(source->bin());
}, [](std::nullptr_t&) {
return GRefPtr<GstElement>(nullptr);
});
return nullptr;
}
bool GStreamerRtpSenderBackend::replaceTrack(RTCRtpSender& sender, MediaStreamTrack* track)
{
if (!track) {
auto stoppedSource = stopSource();
return true;
}
if (sender.track()) {
switchOn(m_source, [&](Ref<RealtimeOutgoingAudioSourceGStreamer>& source) {
ASSERT(track->source().type() == RealtimeMediaSource::Type::Audio);
source->stop();
source->setSource(track->privateTrack());
source->start();
}, [&](Ref<RealtimeOutgoingVideoSourceGStreamer>& source) {
ASSERT(track->source().type() == RealtimeMediaSource::Type::Video);
source->stop();
source->setSource(track->privateTrack());
source->start();
}, [](std::nullptr_t&) {
});
}
m_peerConnectionBackend->setSenderSourceFromTrack(*this, *track);
return true;
}
RTCRtpSendParameters GStreamerRtpSenderBackend::getParameters() const
{
return toRTCRtpSendParameters(m_initData.get());
}
void GStreamerRtpSenderBackend::setParameters(const RTCRtpSendParameters&, DOMPromiseDeferred<void>&& promise)
{
if (!m_rtcSender) {
promise.reject(NotSupportedError);
return;
}
notImplemented();
promise.resolve();
}
std::unique_ptr<RTCDTMFSenderBackend> GStreamerRtpSenderBackend::createDTMFBackend()
{
return makeUnique<GStreamerDTMFSenderBackend>();
}
Ref<RTCRtpTransformBackend> GStreamerRtpSenderBackend::rtcRtpTransformBackend()
{
return GStreamerRtpSenderTransformBackend::create(m_rtcSender);
}
void GStreamerRtpSenderBackend::setMediaStreamIds(const FixedVector<String>&)
{
notImplemented();
}
std::unique_ptr<RTCDtlsTransportBackend> GStreamerRtpSenderBackend::dtlsTransportBackend()
{
GRefPtr<GstWebRTCDTLSTransport> transport;
g_object_get(m_rtcSender.get(), "transport", &transport.outPtr(), nullptr);
return transport ? makeUnique<GStreamerDtlsTransportBackend>(transport) : nullptr;
}
} // namespace WebCore
#endif // ENABLE(WEB_RTC) && USE(GSTREAMER_WEBRTC)
|