Skip to content

Commit bbb348f

Browse files
committed
[GStreamer] Increase use of CStringView and other string management improvements
https://bugs.webkit.org/show_bug.cgi?id=299443 Reviewed by Philippe Normand. We are increasing the use of CStringView, also assuming that all input is UTF8 and that it might need to be converted in order to interact with other WebKit classes. Test: Covered by existing tests. * Source/WTF/wtf/glib/GSpanExtras.cpp: (WTF::gFileGetContents): (WTF::gKeyFileGetKeys): * Source/WTF/wtf/glib/GSpanExtras.h: * Source/WebCore/Modules/mediastream/gstreamer/GStreamerDataChannelHandler.cpp: (WebCore::GStreamerDataChannelHandler::GStreamerDataChannelHandler): (WebCore::GStreamerDataChannelHandler::onMessageString): * Source/WebCore/Modules/mediastream/gstreamer/GStreamerDataChannelHandler.h: * Source/WebCore/Modules/mediastream/gstreamer/GStreamerMediaEndpoint.cpp: (WebCore::GStreamerMediaEndpoint::maybeInsertNetSimForElement): (WebCore::fetchDescription): (WebCore::getMediaStreamIdsFromSDPMedia): (WebCore::GStreamerMediaEndpoint::linkOutgoingSources): (WebCore::GStreamerMediaEndpoint::doSetRemoteDescription): (WebCore::GStreamerMediaEndpoint::processSDPMessage): (WebCore::GStreamerMediaEndpoint::isIceGatheringComplete): (WebCore::GStreamerMediaEndpoint::initiate): (WebCore::GStreamerMediaEndpoint::trackIdFromSDPMedia): (WebCore::GStreamerMediaEndpoint::connectPad): (WebCore::GStreamerMediaEndpoint::canTrickleIceCandidates const): (WebCore::GStreamerMediaEndpoint::completeSDPAnswer): * Source/WebCore/Modules/mediastream/gstreamer/GStreamerMediaEndpoint.h: * Source/WebCore/Modules/mediastream/gstreamer/GStreamerRtpTransceiverBackend.cpp: (WebCore::GStreamerRtpTransceiverBackend::setCodecPreferences): * Source/WebCore/Modules/mediastream/gstreamer/GStreamerWebRTCUtils.cpp: (WebCore::x509Serialize): (WebCore::privateKeySerialize): (WebCore::sdpMediaHasAttributeKey): (WebCore::getDirectionFromSDPMedia): (WebCore::capsFromSDPMedia): (WebCore::setSsrcAudioLevelVadOn): (WebCore::SDPStringBuilder::appendConnection): (WebCore::SDPStringBuilder::appendMedia): (WebCore::SDPStringBuilder::SDPStringBuilder): * Source/WebCore/Modules/mediastream/gstreamer/GStreamerWebRTCUtils.h: * Source/WebCore/platform/audio/gstreamer/AudioEncoderGStreamer.cpp: (WebCore::GStreamerInternalAudioEncoder::initialize): * Source/WebCore/platform/audio/gstreamer/AudioFileReaderGStreamer.cpp: (WebCore::AudioFileReader::handleMessage): * Source/WebCore/platform/audio/gstreamer/PlatformRawAudioDataGStreamer.cpp: (WebCore::layoutToString): (WebCore::PlatformRawAudioData::copyTo): * Source/WebCore/platform/graphics/gstreamer/GLVideoSinkGStreamer.cpp: (initializeDMABufAvailability): * Source/WebCore/platform/graphics/gstreamer/GStreamerAudioMixer.cpp: (WebCore::GStreamerAudioMixer::registerProducer): (WebCore::GStreamerAudioMixer::configureSourcePeriodTime): * Source/WebCore/platform/graphics/gstreamer/GStreamerAudioMixer.h: * Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp: (WebCore::getStreamIdFromPad): (WebCore::getStreamIdFromStream): (WebCore::parseStreamId): (WebCore::extractGStreamerOptionsFromCommandLine): (WebCore::ensureGStreamerInitialized): (WebCore::registerWebKitGStreamerElements): (WebCore::deinitializeGStreamer): (WebCore::getGstPlayFlag): (WebCore::makeGStreamerElement): (WebCore::gstStructureValueToJSON): (WebCore::gstStructureToJSON): (WebCore::gstElementMatchesFactoryAndHasProperty): (WebCore::gstIdToString): (WebCore::buildDMABufCaps): (WebCore::requestGLContext): (WebCore::setGstElementGLContext): * Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h: * Source/WebCore/platform/graphics/gstreamer/GStreamerRegistryScanner.cpp: (WebCore::GStreamerRegistryScanner::ElementFactories::elementFactoryTypeToString): (WebCore::GStreamerRegistryScanner::ElementFactories::hasElementForCaps const): (WebCore::GStreamerRegistryScanner::initializeDecoders): (WebCore::GStreamerRegistryScanner::isAVC1CodecSupported const): (WebCore::probeRtpExtensions): (WebCore::GStreamerRegistryScanner::isRtpHeaderExtensionSupported): * Source/WebCore/platform/graphics/gstreamer/GStreamerRegistryScanner.h: * Source/WebCore/platform/graphics/gstreamer/GStreamerSinksWorkarounds.cpp: (WebCore::getWorkAroundModeFromEnvironment): (WebCore::BaseSinkPositionFlushWorkaroundProbe::checkIsNeeded): (WebCore::AppSinkFlushCapsWorkaroundProbe::checkIsNeeded): * Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp: (WebCore::MediaPlayerPrivateGStreamer::elementIdChanged const): (WebCore::MediaPlayerPrivateGStreamer::handleNeedContextMessage): (WebCore::MediaPlayerPrivateGStreamer::handleMessage): (WebCore::MediaPlayerPrivateGStreamer::configureParsebin): (WebCore::MediaPlayerPrivateGStreamer::configureElement): (WebCore::MediaPlayerPrivateGStreamer::configureDownloadBuffer): (WebCore::MediaPlayerPrivateGStreamer::loadNextLocation): (WebCore::MediaPlayerPrivateGStreamer::createVideoSinkGL): (WebCore::MediaPlayerPrivateGStreamer::parseInitDataFromProtectionMessage): (WebCore::MediaPlayerPrivateGStreamer::handleProtectionEvent): * Source/WebCore/platform/graphics/gstreamer/MediaSampleGStreamer.cpp: (WebCore::MediaSampleGStreamer::dump const): * Source/WebCore/platform/graphics/gstreamer/TrackPrivateBaseGStreamer.cpp: (WebCore::TrackPrivateBaseGStreamer::tagsChanged): (WebCore::TrackPrivateBaseGStreamer::getLanguageCode): (WebCore::TrackPrivateBaseGStreamer::getTag): (WebCore::TrackPrivateBaseGStreamer::notifyTrackOfTagsChanged): * Source/WebCore/platform/graphics/gstreamer/TrackPrivateBaseGStreamer.h: * Source/WebCore/platform/graphics/gstreamer/VideoFrameGStreamer.cpp: (WebCore::VideoFrameGStreamer::createFromPixelBuffer): (WebCore::VideoFrameGStreamer::convert): * Source/WebCore/platform/graphics/gstreamer/WebKitAudioSinkGStreamer.cpp: (webKitAudioSinkConfigure): * Source/WebCore/platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp: (webKitWebSrcSetExtraHeader): (webKitWebSrcMakeRequest): (convertPlaybinURI): (webKitWebSrcSetUri): * Source/WebCore/platform/graphics/gstreamer/WebKitWebSourceGStreamer.h: * Source/WebCore/platform/graphics/gstreamer/eme/CDMThunder.cpp: (WebCore::sessionLoadFailureFromThunder): (WebCore::toString): (WebCore::CDMInstanceSessionThunder::keyUpdatedCallback): (WebCore::CDMInstanceSessionThunder::loadSession): * Source/WebCore/platform/graphics/gstreamer/eme/GStreamerEMEUtilities.h: (WebCore::GStreamerEMEUtilities::isClearKeyUUID): (WebCore::GStreamerEMEUtilities::isWidevineUUID): (WebCore::GStreamerEMEUtilities::isPlayReadyUUID): (WebCore::GStreamerEMEUtilities::isUnspecifiedUUID): (WebCore::GStreamerEMEUtilities::keySystemToUuid): (WebCore::GStreamerEMEUtilities::uuidToKeySystem): * Source/WebCore/platform/graphics/gstreamer/eme/WebKitCommonEncryptionDecryptorGStreamer.cpp: (transformCaps): * Source/WebCore/platform/graphics/gstreamer/eme/WebKitCommonEncryptionDecryptorGStreamer.h: * Source/WebCore/platform/graphics/gstreamer/eme/WebKitThunderDecryptorGStreamer.cpp: (createSinkPadTemplateCaps): (protectionSystemId): * Source/WebCore/platform/graphics/gstreamer/eme/WebKitThunderParser.cpp: (createThunderParseSinkPadTemplateCaps): * Source/WebCore/platform/graphics/gstreamer/mse/AppendPipeline.cpp: (WebCore::serialize): (WebCore::AppendPipeline::didReceiveInitializationSegment): (WebCore::AppendPipeline::Track::initializeElements): (WebCore::appendPipelinePadProbeDebugInformation): (WebCore::AppendPipeline::streamTypeToString): Deleted. * Source/WebCore/platform/graphics/gstreamer/mse/AppendPipeline.h: * Source/WebCore/platform/graphics/gstreamer/mse/MediaPlayerPrivateGStreamerMSE.cpp: (dumpReadyState): (WebCore::MediaPlayerPrivateGStreamerMSE::readyStateFromMediaSourceChanged): (WebCore::MediaPlayerPrivateGStreamerMSE::propagateReadyStateToPlayer): * Source/WebCore/platform/graphics/gstreamer/mse/MediaSourcePrivateGStreamer.cpp: (WebCore::MediaSourcePrivateGStreamer::markEndOfStream): * Source/WebCore/platform/graphics/gstreamer/mse/WebKitMediaSourceGStreamer.cpp: (streamTypeToString): (webKitMediaSrcEmitStreams): * Source/WebCore/platform/gstreamer/GStreamerCodecUtilities.cpp: (WebCore::GStreamerCodecUtilities::parseH264ProfileAndLevel): (WebCore::h264CapsFromCodecString): (WebCore::GStreamerCodecUtilities::parseHEVCProfile): (WebCore::h265CapsFromCodecString): (WebCore::av1CapsFromCodecString): (): Deleted. * Source/WebCore/platform/gstreamer/GStreamerCodecUtilities.h: * Source/WebCore/platform/gstreamer/GStreamerElementHarness.cpp: (WebCore::MermaidBuilder::dumpElement): (WebCore::MermaidBuilder::describeCaps): (WebCore::GStreamerElementHarness::dumpGraph): * Source/WebCore/platform/gstreamer/GStreamerQuirkBroadcom.cpp: (WebCore::GStreamerQuirkBroadcom::configureElement): * Source/WebCore/platform/gstreamer/GStreamerQuirkBroadcomBase.cpp: (WebCore::GStreamerQuirkBroadcomBase::correctBufferingPercentage const): (WebCore::GStreamerQuirkBroadcomBase::setupBufferingPercentageCorrection const): * Source/WebCore/platform/gstreamer/GStreamerQuirkRialto.cpp: (WebCore::GStreamerQuirkRialto::GStreamerQuirkRialto): (WebCore::GStreamerQuirkRialto::configureElement): * Source/WebCore/platform/gstreamer/GStreamerQuirkWesteros.cpp: (WebCore::GStreamerQuirkWesteros::configureElement): * Source/WebCore/platform/gstreamer/GStreamerQuirks.cpp: (WebCore::GStreamerQuirksManager::GStreamerQuirksManager): * Source/WebCore/platform/gstreamer/WebKitFliteSourceGStreamer.cpp: (fliteVoice): (webKitFliteSrcSetUtterance): * Source/WebCore/platform/mediastream/gstreamer/GStreamerAudioCapturer.h: * Source/WebCore/platform/mediastream/gstreamer/GStreamerCaptureDeviceManager.cpp: (WebCore::GStreamerCaptureDeviceManager::captureDeviceFromGstDevice): * Source/WebCore/platform/mediastream/gstreamer/GStreamerCapturer.h: * Source/WebCore/platform/mediastream/gstreamer/GStreamerIncomingTrackProcessor.cpp: (WebCore::GStreamerIncomingTrackProcessor::mediaStreamIdFromPad): (WebCore::GStreamerIncomingTrackProcessor::retrieveMediaStreamAndTrackIdFromSDP): * Source/WebCore/platform/mediastream/gstreamer/GStreamerMockDevice.cpp: (webkitMockDeviceCreate): * Source/WebCore/platform/mediastream/gstreamer/GStreamerRTPPacketizer.cpp: (WebCore::GStreamerRTPPacketizer::ensureMidExtension): * Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoCapturer.cpp: (WebCore::getMaxIntValueFromStructure): (WebCore::getMaxFractionValueFromStructure): (WebCore::GStreamerVideoCapturer::reconfigure): * Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoCapturer.h: * Source/WebCore/platform/mediastream/gstreamer/GStreamerWebRTCLogSink.cpp: (WebCore::GStreamerWebRTCLogSink::start): * Source/WebCore/platform/mediastream/libwebrtc/gstreamer/GStreamerVideoDecoderFactory.cpp: (WebCore::GStreamerWebRTCVideoDecoder::GstDecoderFactory): (WebCore::VP8Decoder::Create): * Source/WebKit/UIProcess/API/glib/WebKitSettings.cpp: (webkit_settings_apply_from_key_file): * Tools/TestWebKitAPI/Tests/WebCore/gstreamer/GStreamerTest.cpp: (TestWebKitAPI::TEST_F(GStreamerTest, hevcProfileParsing)): Canonical link: https://commits.webkit.org/304152@main Signed-off-by: Xabier Rodriguez Calvar <calvaris@igalia.com>
1 parent f418dce commit bbb348f

62 files changed

Lines changed: 534 additions & 496 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Source/WTF/wtf/glib/GSpanExtras.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,31 @@
2121
#include <wtf/glib/GSpanExtras.h>
2222

2323
#include <wtf/StdLibExtras.h>
24+
#include <wtf/text/CStringView.h>
2425

2526
namespace WTF {
2627

27-
GMallocSpan<char> gFileGetContents(const char* path, GUniqueOutPtr<GError>& error)
28+
Expected<GMallocSpan<char>, GUniquePtr<GError>> gFileGetContents(CStringView path)
2829
{
2930
char* contents;
3031
gsize length;
31-
if (!g_file_get_contents(path, &contents, &length, &error.outPtr()))
32-
return { };
32+
GUniqueOutPtr<GError> error;
33+
if (!g_file_get_contents(path.utf8(), &contents, &length, &error.outPtr()))
34+
return makeUnexpected(GUniquePtr<GError>(error.release()));
3335

3436
return adoptGMallocSpan(unsafeMakeSpan(contents, length));
3537
}
3638

37-
GMallocSpan<char*, GMallocStrv> gKeyFileGetKeys(GKeyFile* keyFile, const char* groupName, GUniqueOutPtr<GError>& error)
39+
Expected<GMallocSpan<char*, GMallocStrv>, GUniquePtr<GError>> gKeyFileGetKeys(GKeyFile* keyFile, CStringView groupName)
3840
{
3941
ASSERT(keyFile);
4042
ASSERT(groupName);
4143

4244
size_t keyCount = 0;
43-
char** keys = g_key_file_get_keys(keyFile, groupName, &keyCount, &error.outPtr());
45+
GUniqueOutPtr<GError> error;
46+
char** keys = g_key_file_get_keys(keyFile, groupName.utf8(), &keyCount, &error.outPtr());
47+
if (error)
48+
return makeUnexpected(GUniquePtr<GError>(error.release()));
4449
return adoptGMallocSpan<char*, GMallocStrv>(unsafeMakeSpan(keys, keyCount));
4550
}
4651

Source/WTF/wtf/glib/GSpanExtras.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#pragma once
2121

22+
#include <wtf/Expected.h>
2223
#include <wtf/MallocSpan.h>
2324
#include <wtf/StdLibExtras.h>
2425
#include <wtf/glib/GRefPtr.h>
@@ -36,6 +37,8 @@ void g_strfreev(char**);
3637

3738
namespace WTF {
3839

40+
class CStringView;
41+
3942
struct GMalloc {
4043
static void* malloc(size_t size) { return g_malloc(size); }
4144
static void* tryMalloc(size_t size) { return g_try_malloc(size); }
@@ -64,8 +67,8 @@ GMallocSpan<T, Malloc> adoptGMallocSpan(std::span<T> span)
6467
return adoptMallocSpan<T, Malloc>(span);
6568
}
6669

67-
WTF_EXPORT_PRIVATE GMallocSpan<char> gFileGetContents(const char* path, GUniqueOutPtr<GError>&);
68-
WTF_EXPORT_PRIVATE GMallocSpan<char*, GMallocStrv> gKeyFileGetKeys(GKeyFile*, const char* groupName, GUniqueOutPtr<GError>&);
70+
WTF_EXPORT_PRIVATE Expected<GMallocSpan<char>, GUniquePtr<GError>> gFileGetContents(CStringView);
71+
WTF_EXPORT_PRIVATE Expected<GMallocSpan<char*, GMallocStrv>, GUniquePtr<GError>> gKeyFileGetKeys(GKeyFile*, CStringView groupName);
6972
WTF_EXPORT_PRIVATE GMallocSpan<GParamSpec*> gObjectClassGetProperties(GObjectClass*);
7073
WTF_EXPORT_PRIVATE GMallocSpan<const char*> gVariantGetStrv(const GRefPtr<GVariant>&);
7174

Source/WebCore/Modules/mediastream/gstreamer/GStreamerDataChannelHandler.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ GStreamerDataChannelHandler::GStreamerDataChannelHandler(GRefPtr<GstWebRTCDataCh
111111
handler->onMessageData(bytes);
112112
}), this);
113113
g_signal_connect_swapped(m_channel.get(), "on-message-string", G_CALLBACK(+[](GStreamerDataChannelHandler* handler, const char* message) {
114-
handler->onMessageString(message);
114+
handler->onMessageString(CStringView::unsafeFromUTF8(message));
115115
}), this);
116116
g_signal_connect_swapped(m_channel.get(), "on-error", G_CALLBACK(+[](GStreamerDataChannelHandler* handler, GError* error) {
117117
handler->onError(error);
@@ -366,26 +366,26 @@ void GStreamerDataChannelHandler::onMessageData(GBytes* bytes)
366366
});
367367
}
368368

369-
void GStreamerDataChannelHandler::onMessageString(const char* message)
369+
void GStreamerDataChannelHandler::onMessageString(CStringView message)
370370
{
371371
Locker locker { m_clientLock };
372372

373-
DC_TRACE("Incoming string: %s", message);
373+
DC_TRACE("Incoming string: %s", message.utf8());
374374
if (!m_client) {
375375
DC_DEBUG("No client yet, keeping as buffered message");
376-
m_pendingMessages.append(String::fromUTF8(message));
376+
m_pendingMessages.append(String(message.span()));
377377
return;
378378
}
379379

380380
if (!*m_client)
381381
return;
382382

383-
DC_DEBUG("Dispatching string of size %zu", strlen(message));
384-
postTask([client = m_client, string = String::fromUTF8(message)] {
383+
DC_DEBUG("Dispatching string of size %zu", message.lengthInBytes());
384+
postTask([client = m_client, string = String(message.span())] mutable {
385385
if (!*client)
386386
return;
387387

388-
client.value()->didReceiveStringData(string);
388+
client.value()->didReceiveStringData(WTFMove(string));
389389
});
390390
}
391391

Source/WebCore/Modules/mediastream/gstreamer/GStreamerDataChannelHandler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class GStreamerDataChannelHandler final : public RTCDataChannelHandler {
6060
void close() final;
6161

6262
void onMessageData(GBytes*);
63-
void onMessageString(const char*);
63+
void onMessageString(CStringView);
6464
void onError(GError*);
6565
void onClose();
6666

Source/WebCore/Modules/mediastream/gstreamer/GStreamerMediaEndpoint.cpp

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ void GStreamerMediaEndpoint::maybeInsertNetSimForElement(GstBin* bin, GstElement
116116
return;
117117

118118
// Unlink the element, add a netsim element in bin and link it to the element to simulate varying network conditions.
119-
const char* padName = isSource ? "src" : "sink";
120-
auto pad = adoptGRef(gst_element_get_static_pad(element, padName));
119+
ASCIILiteral padName = isSource ? "src"_s : "sink"_s;
120+
auto pad = adoptGRef(gst_element_get_static_pad(element, padName.characters()));
121121
auto peer = adoptGRef(gst_pad_get_peer(pad.get()));
122122
if (UNLIKELY(!peer))
123123
return;
@@ -131,7 +131,7 @@ void GStreamerMediaEndpoint::maybeInsertNetSimForElement(GstBin* bin, GstElement
131131
for (const auto& [key, value] : options)
132132
gst_util_set_object_arg(G_OBJECT(netsim), key.ascii().data(), value.ascii().data());
133133

134-
pad = adoptGRef(gst_element_get_static_pad(netsim, padName));
134+
pad = adoptGRef(gst_element_get_static_pad(netsim, padName.characters()));
135135
if (isSource) {
136136
gst_element_link(element, netsim);
137137
gst_pad_link(pad.get(), peer.get());
@@ -403,7 +403,7 @@ static std::optional<std::pair<RTCSdpType, String>> fetchDescription(GstElement*
403403
unsigned totalAttributesNumber = gst_sdp_message_attributes_len(description->sdp);
404404
for (unsigned i = 0; i < totalAttributesNumber; i++) {
405405
const auto attribute = gst_sdp_message_get_attribute(description->sdp, i);
406-
if (!g_strcmp0(attribute->key, "end-of-candidates")) {
406+
if (equal(unsafeSpan(attribute->key), "end-of-candidates"_s)) {
407407
gst_sdp_message_remove_attribute(description->sdp, i);
408408
i--;
409409
}
@@ -485,15 +485,16 @@ Vector<String> getMediaStreamIdsFromSDPMedia(const GstSDPMedia& media)
485485
HashSet<String> mediaStreamIdsSet;
486486
for (guint i = 0; i < gst_sdp_media_attributes_len(&media); ++i) {
487487
const auto attribute = gst_sdp_media_get_attribute(&media, i);
488-
if (!g_strcmp0(attribute->key, "msid")) {
489-
auto components = String::fromUTF8(attribute->value).split(' ');
488+
auto key = CStringView::unsafeFromUTF8(attribute->key);
489+
if (key == "msid"_s) {
490+
auto components = String(byteCast<char8_t>(unsafeSpan(attribute->value))).split(' ');
490491
if (components.size() < 2)
491492
continue;
492493
mediaStreamIdsSet.add(components[0]);
493494
}
494495
// MSID may also come in ssrc attributes, specially if they're in an SDP answer. They look like:
495496
// a=ssrc:3612593434 msid:e1019f4a-0983-4863-b923-b75903cced2c webrtctransceiver1
496-
if (!g_strcmp0(attribute->key, "ssrc")) {
497+
if (key == "ssrc"_s) {
497498
auto outerComponents = String::fromUTF8(attribute->value).split(' ');
498499
for (auto& outer : outerComponents) {
499500
auto innerComponents = outer.split(':');
@@ -620,10 +621,10 @@ void GStreamerMediaEndpoint::linkOutgoingSources(GstSDPMessage* sdpMessage)
620621
continue;
621622
}
622623

623-
auto msid = String::fromUTF8(gst_sdp_media_get_attribute_val(media, "msid"));
624+
auto msid = CStringView::unsafeFromUTF8(gst_sdp_media_get_attribute_val(media, "msid"));
624625

625-
GST_DEBUG_OBJECT(m_pipeline.get(), "Looking-up outgoing source with msid %s in %zu unlinked sources", msid.utf8().data(), m_unlinkedOutgoingSources.size());
626-
m_unlinkedOutgoingSources.removeFirstMatching([&](auto& source) -> bool {
626+
GST_DEBUG_OBJECT(m_pipeline.get(), "Looking-up outgoing source with msid %s in %zu unlinked sources", msid.utf8(), m_unlinkedOutgoingSources.size());
627+
m_unlinkedOutgoingSources.removeFirstMatching([&, msid = String(msid.span())](auto& source) -> bool {
627628
if (source->type() != sourceType)
628629
return false;
629630

@@ -837,12 +838,12 @@ void GStreamerMediaEndpoint::doSetRemoteDescription(const RTCSessionDescription&
837838
if (protectedThis->isStopped())
838839
return;
839840

840-
processSDPMessage(&message, [this](unsigned, StringView mid, const auto* media) {
841-
const char* mediaType = gst_sdp_media_get_media(media);
842-
m_mediaForMid.set(mid.toString(), g_str_equal(mediaType, "audio") ? RealtimeMediaSource::Type::Audio : RealtimeMediaSource::Type::Video);
841+
processSDPMessage(&message, [this](unsigned, CStringView mid, const auto* media) {
842+
auto mediaType = CStringView::unsafeFromUTF8(gst_sdp_media_get_media(media));
843+
m_mediaForMid.set(mid.span(), mediaType == "audio"_s ? RealtimeMediaSource::Type::Audio : RealtimeMediaSource::Type::Video);
843844

844845
// https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1907
845-
if (sdpMediaHasAttributeKey(media, "ice-lite")) {
846+
if (sdpMediaHasAttributeKey(media, "ice-lite"_s)) {
846847
GRefPtr<GstWebRTCICE> ice;
847848
g_object_get(m_webrtcBin.get(), "ice-agent", &ice.outPtr(), nullptr);
848849
g_object_set(ice.get(), "ice-lite", TRUE, nullptr);
@@ -868,8 +869,8 @@ void GStreamerMediaEndpoint::doSetRemoteDescription(const RTCSessionDescription&
868869
}
869870

870871
#ifndef GST_DISABLE_GST_DEBUG
871-
auto dotFileName = makeString(span(GST_OBJECT_NAME(m_pipeline.get())), ".setRemoteDescription"_s);
872-
GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS(GST_BIN(m_pipeline.get()), GST_DEBUG_GRAPH_SHOW_ALL, dotFileName.utf8().data());
872+
auto dotFileName = makeString(unsafeSpan(GST_OBJECT_NAME(m_pipeline.get())), ".setRemoteDescription"_s);
873+
GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS(GST_BIN(m_pipeline.get()), GST_DEBUG_GRAPH_SHOW_ALL, dotFileName.ascii().data());
873874
#endif
874875

875876
auto rtcTransceiverStates = transceiverStatesFromWebRTCBin(m_webrtcBin.get());
@@ -990,7 +991,7 @@ void GStreamerMediaEndpoint::setDescription(const RTCSessionDescription* descrip
990991
}, data, reinterpret_cast<GDestroyNotify>(destroySetDescriptionCallData)));
991992
}
992993

993-
void GStreamerMediaEndpoint::processSDPMessage(const GstSDPMessage* message, Function<void(unsigned, StringView, const GstSDPMedia*)> mediaCallback)
994+
void GStreamerMediaEndpoint::processSDPMessage(const GstSDPMessage* message, Function<void(unsigned, CStringView, const GstSDPMedia*)> mediaCallback)
994995
{
995996
unsigned totalMedias = gst_sdp_message_medias_len(message);
996997
for (unsigned mediaIndex = 0; mediaIndex < totalMedias; mediaIndex++) {
@@ -1003,15 +1004,15 @@ void GStreamerMediaEndpoint::processSDPMessage(const GstSDPMessage* message, Fun
10031004
GUniquePtr<char> mediaRepresentation(gst_sdp_media_as_text(media));
10041005
GST_LOG_OBJECT(m_pipeline.get(), "Processing media:\n%s", mediaRepresentation.get());
10051006
#endif
1006-
const char* mid = gst_sdp_media_get_attribute_val(media, "mid");
1007+
auto mid = CStringView::unsafeFromUTF8(gst_sdp_media_get_attribute_val(media, "mid"));
10071008
if (!mid)
10081009
continue;
10091010

10101011
bool isInactive = false;
10111012
unsigned totalAttributes = gst_sdp_media_attributes_len(media);
10121013
for (unsigned attributeIndex = 0; attributeIndex < totalAttributes; attributeIndex++) {
10131014
const auto* attribute = gst_sdp_media_get_attribute(media, attributeIndex);
1014-
if (!g_strcmp0(attribute->key, "inactive")) {
1015+
if (CStringView::unsafeFromUTF8(attribute->key) == "inactive"_s) {
10151016
isInactive = true;
10161017
break;
10171018
}
@@ -1021,7 +1022,7 @@ void GStreamerMediaEndpoint::processSDPMessage(const GstSDPMessage* message, Fun
10211022
continue;
10221023
}
10231024

1024-
mediaCallback(mediaIndex, StringView::fromLatin1(mid), media);
1025+
mediaCallback(mediaIndex, mid, media);
10251026
}
10261027
}
10271028

@@ -1125,8 +1126,7 @@ std::optional<bool> GStreamerMediaEndpoint::isIceGatheringComplete(const String&
11251126
unsigned numberOfMedias = gst_sdp_message_medias_len(message.get());
11261127
for (unsigned i = 0; i < numberOfMedias; i++) {
11271128
const auto* media = gst_sdp_message_get_media(message.get(), i);
1128-
const char* value = gst_sdp_media_get_attribute_val_n(media, "end-of-candidates", 0);
1129-
if (!value)
1129+
if (!gst_sdp_media_get_attribute_val_n(media, "end-of-candidates", 0))
11301130
return false;
11311131
}
11321132

@@ -1262,8 +1262,7 @@ void GStreamerMediaEndpoint::initiate(bool isInitiator, GstStructure* rawOptions
12621262
}
12631263

12641264
GUniqueOutPtr<GstWebRTCSessionDescription> sessionDescription;
1265-
const char* sdpTypeString = holder->sdpType == RTCSdpType::Offer ? "offer" : "answer";
1266-
gst_structure_get(reply, sdpTypeString, GST_TYPE_WEBRTC_SESSION_DESCRIPTION, &sessionDescription.outPtr(), nullptr);
1265+
gst_structure_get(reply, holder->sdpType == RTCSdpType::Offer ? "offer" : "answer", GST_TYPE_WEBRTC_SESSION_DESCRIPTION, &sessionDescription.outPtr(), nullptr);
12671266

12681267
#ifndef GST_DISABLE_GST_DEBUG
12691268
GUniquePtr<char> sdp(gst_sdp_message_as_text(sessionDescription->sdp));
@@ -1336,12 +1335,12 @@ MediaStream& GStreamerMediaEndpoint::mediaStreamFromRTCStream(String mediaStream
13361335

13371336
String GStreamerMediaEndpoint::trackIdFromSDPMedia(const GstSDPMedia& media)
13381337
{
1339-
const char* msidAttribute = gst_sdp_media_get_attribute_val(&media, "msid");
1338+
auto msidAttribute = CStringView::unsafeFromUTF8(gst_sdp_media_get_attribute_val(&media, "msid"));
13401339
if (!msidAttribute)
13411340
return emptyString();
13421341

1343-
GST_LOG_OBJECT(m_pipeline.get(), "SDP media msid attribute value: %s", msidAttribute);
1344-
auto components = String::fromUTF8(msidAttribute).split(' ');
1342+
GST_LOG_OBJECT(m_pipeline.get(), "SDP media msid attribute value: %s", msidAttribute.utf8());
1343+
auto components = String(msidAttribute.span()).split(' ');
13451344
if (components.size() < 2)
13461345
return emptyString();
13471346

@@ -1448,8 +1447,8 @@ void GStreamerMediaEndpoint::connectPad(GstPad* pad)
14481447
gst_element_set_state(bin, GST_STATE_PAUSED);
14491448

14501449
#ifndef GST_DISABLE_GST_DEBUG
1451-
auto dotFileName = makeString(span(GST_OBJECT_NAME(m_pipeline.get())), ".pending-"_s, span(GST_OBJECT_NAME(pad)));
1452-
GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS(GST_BIN(m_pipeline.get()), GST_DEBUG_GRAPH_SHOW_ALL, dotFileName.utf8().data());
1450+
auto dotFileName = makeString(unsafeSpan(GST_OBJECT_NAME(m_pipeline.get())), ".pending-"_s, unsafeSpan(GST_OBJECT_NAME(pad)));
1451+
GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS(GST_BIN(m_pipeline.get()), GST_DEBUG_GRAPH_SHOW_ALL, dotFileName.ascii().data());
14531452
#endif
14541453
}
14551454

@@ -2400,7 +2399,7 @@ std::optional<bool> GStreamerMediaEndpoint::canTrickleIceCandidates() const
24002399

24012400
for (unsigned i = 0; i < gst_sdp_message_attributes_len(description->sdp); i++) {
24022401
const auto attribute = gst_sdp_message_get_attribute(description->sdp, i);
2403-
if (g_strcmp0(attribute->key, "ice-options"))
2402+
if (!equal(unsafeSpan(attribute->key), "ice-options"_s))
24042403
continue;
24052404

24062405
auto values = makeString(span(attribute->value)).split(' ');

Source/WebCore/Modules/mediastream/gstreamer/GStreamerMediaEndpoint.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ class GStreamerMediaEndpoint : public ThreadSafeRefCountedAndCanMakeThreadSafeWe
162162

163163
ExceptionOr<Backends> createTransceiverBackends(const String& kind, const RTCRtpTransceiverInit&, GStreamerRtpSenderBackend::Source&&, PeerConnectionBackend::IgnoreNegotiationNeededFlag);
164164

165-
void processSDPMessage(const GstSDPMessage*, Function<void(unsigned index, StringView mid, const GstSDPMedia*)>);
165+
void processSDPMessage(const GstSDPMessage*, Function<void(unsigned index, CStringView mid, const GstSDPMedia*)>);
166166

167167
WARN_UNUSED_RETURN GRefPtr<GstPad> requestPad(const GRefPtr<GstCaps>&, const String& mediaStreamID);
168168

Source/WebCore/Modules/mediastream/gstreamer/GStreamerRtpTransceiverBackend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ ExceptionOr<void> GStreamerRtpTransceiverBackend::setCodecPreferences(const Vect
163163
if (!key.startsWith("extmap-"_s))
164164
return true;
165165

166-
extensions.add(key.toString(), String::fromLatin1(g_value_get_string(value)));
166+
extensions.add(key, byteCast<char8_t>(unsafeSpan(g_value_get_string(value))));
167167
return true;
168168
});
169169
}

0 commit comments

Comments
 (0)