Skip to content

Commit 9d73b18

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
1 parent 4d39224 commit 9d73b18

File tree

60 files changed

+539
-514
lines changed

Some content is hidden

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

60 files changed

+539
-514
lines changed

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); }
@@ -78,8 +81,8 @@ GMallocSpan<char, Malloc> adoptGMallocString(char* str)
7881
WTF_ALLOW_UNSAFE_BUFFER_USAGE_END
7982
}
8083

81-
WTF_EXPORT_PRIVATE GMallocSpan<char> gFileGetContents(const char* path, GUniqueOutPtr<GError>&);
82-
WTF_EXPORT_PRIVATE GMallocSpan<char*, GMallocStrv> gKeyFileGetKeys(GKeyFile*, const char* groupName, GUniqueOutPtr<GError>&);
84+
WTF_EXPORT_PRIVATE Expected<GMallocSpan<char>, GUniquePtr<GError>> gFileGetContents(CStringView);
85+
WTF_EXPORT_PRIVATE Expected<GMallocSpan<char*, GMallocStrv>, GUniquePtr<GError>> gKeyFileGetKeys(GKeyFile*, CStringView groupName);
8386
WTF_EXPORT_PRIVATE GMallocSpan<GParamSpec*> gObjectClassGetProperties(GObjectClass*);
8487
WTF_EXPORT_PRIVATE GMallocSpan<const char*> gVariantGetStrv(const GRefPtr<GVariant>&);
8588

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ GStreamerDataChannelHandler::GStreamerDataChannelHandler(GRefPtr<GstWebRTCDataCh
115115
handler->onMessageData(bytes);
116116
}), this);
117117
g_signal_connect_swapped(m_channel.get(), "on-message-string", G_CALLBACK(+[](GStreamerDataChannelHandler* handler, const char* message) {
118-
handler->onMessageString(message);
118+
handler->onMessageString(CStringView::unsafeFromUTF8(message));
119119
}), this);
120120
g_signal_connect_swapped(m_channel.get(), "on-error", G_CALLBACK(+[](GStreamerDataChannelHandler* handler, GError* error) {
121121
handler->onError(error);
@@ -377,27 +377,26 @@ void GStreamerDataChannelHandler::onMessageData(GBytes* bytes)
377377
});
378378
}
379379

380-
void GStreamerDataChannelHandler::onMessageString(const char* message)
380+
void GStreamerDataChannelHandler::onMessageString(CStringView message)
381381
{
382382
Locker locker { m_clientLock };
383383

384-
DC_TRACE("Incoming string: %s", message);
384+
DC_TRACE("Incoming string: %s", message.utf8());
385385
if (!m_client) {
386386
DC_DEBUG("No client yet, keeping as buffered message");
387-
m_pendingMessages.append(String::fromUTF8(message));
387+
m_pendingMessages.append(String(message.span()));
388388
return;
389389
}
390390

391391
if (!*m_client)
392392
return;
393393

394-
auto string = String::fromUTF8(message);
395-
DC_DEBUG("Dispatching string of size %u", string.length());
396-
postTask([client = m_client, string = WTFMove(string)] {
394+
DC_DEBUG("Dispatching string of size %zu", message.lengthInBytes());
395+
postTask([client = m_client, string = String(message.span())] mutable {
397396
if (!*client)
398397
return;
399398

400-
client.value()->didReceiveStringData(string);
399+
client.value()->didReceiveStringData(WTFMove(string));
401400
});
402401
}
403402

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

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

6363
void onMessageData(GBytes*);
64-
void onMessageString(const char*);
64+
void onMessageString(CStringView);
6565
void onError(GError*);
6666
void onClose();
6767

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

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ void GStreamerMediaEndpoint::maybeInsertNetSimForElement(GstBin* bin, GstElement
125125
return;
126126

127127
// Unlink the element, add a netsim element in bin and link it to the element to simulate varying network conditions.
128-
const char* padName = isSource ? "src" : "sink";
129-
auto pad = adoptGRef(gst_element_get_static_pad(element, padName));
128+
ASCIILiteral padName = isSource ? "src"_s : "sink"_s;
129+
auto pad = adoptGRef(gst_element_get_static_pad(element, padName.characters()));
130130
auto peer = adoptGRef(gst_pad_get_peer(pad.get()));
131131
if (!peer) [[unlikely]]
132132
return;
@@ -140,7 +140,7 @@ void GStreamerMediaEndpoint::maybeInsertNetSimForElement(GstBin* bin, GstElement
140140
for (const auto& [key, value] : options)
141141
gst_util_set_object_arg(G_OBJECT(netsim), key.ascii().data(), value.ascii().data());
142142

143-
pad = adoptGRef(gst_element_get_static_pad(netsim, padName));
143+
pad = adoptGRef(gst_element_get_static_pad(netsim, padName.characters()));
144144
if (isSource) {
145145
gst_element_link(element, netsim);
146146
gst_pad_link(pad.get(), peer.get());
@@ -474,7 +474,7 @@ static std::optional<std::pair<RTCSdpType, String>> fetchDescription(GstElement*
474474
unsigned totalAttributesNumber = gst_sdp_message_attributes_len(description->sdp);
475475
for (unsigned i = 0; i < totalAttributesNumber; i++) {
476476
const auto attribute = gst_sdp_message_get_attribute(description->sdp, i);
477-
if (!g_strcmp0(attribute->key, "end-of-candidates")) {
477+
if (equal(unsafeSpan(attribute->key), "end-of-candidates"_s)) {
478478
gst_sdp_message_remove_attribute(description->sdp, i);
479479
i--;
480480
}
@@ -556,15 +556,16 @@ Vector<String> getMediaStreamIdsFromSDPMedia(const GstSDPMedia& media)
556556
HashSet<String> mediaStreamIdsSet;
557557
for (guint i = 0; i < gst_sdp_media_attributes_len(&media); ++i) {
558558
const auto attribute = gst_sdp_media_get_attribute(&media, i);
559-
if (!g_strcmp0(attribute->key, "msid")) {
560-
auto components = String::fromUTF8(attribute->value).split(' ');
559+
auto key = CStringView::unsafeFromUTF8(attribute->key);
560+
if (key == "msid"_s) {
561+
auto components = String(byteCast<char8_t>(unsafeSpan(attribute->value))).split(' ');
561562
if (components.size() < 2)
562563
continue;
563564
mediaStreamIdsSet.add(components[0]);
564565
}
565566
// MSID may also come in ssrc attributes, specially if they're in an SDP answer. They look like:
566567
// a=ssrc:3612593434 msid:e1019f4a-0983-4863-b923-b75903cced2c webrtctransceiver1
567-
if (!g_strcmp0(attribute->key, "ssrc")) {
568+
if (key == "ssrc"_s) {
568569
auto outerComponents = String::fromUTF8(attribute->value).split(' ');
569570
for (auto& outer : outerComponents) {
570571
auto innerComponents = outer.split(':');
@@ -686,10 +687,10 @@ void GStreamerMediaEndpoint::linkOutgoingSources(GstSDPMessage* sdpMessage)
686687
continue;
687688
}
688689

689-
auto msid = String::fromUTF8(gst_sdp_media_get_attribute_val(media, "msid"));
690+
auto msid = CStringView::unsafeFromUTF8(gst_sdp_media_get_attribute_val(media, "msid"));
690691

691-
GST_DEBUG_OBJECT(m_pipeline.get(), "Looking-up outgoing source with msid %s in %zu unlinked sources", msid.utf8().data(), m_unlinkedOutgoingSources.size());
692-
m_unlinkedOutgoingSources.removeFirstMatching([&](auto& source) -> bool {
692+
GST_DEBUG_OBJECT(m_pipeline.get(), "Looking-up outgoing source with msid %s in %zu unlinked sources", msid.utf8(), m_unlinkedOutgoingSources.size());
693+
m_unlinkedOutgoingSources.removeFirstMatching([&, msid = String(msid.span())](auto& source) -> bool {
693694
if (source->type() != sourceType)
694695
return false;
695696

@@ -929,12 +930,12 @@ void GStreamerMediaEndpoint::doSetRemoteDescription(const RTCSessionDescription&
929930
auto peerConnectionBackend = this->peerConnectionBackend();
930931
if (!peerConnectionBackend)
931932
return;
932-
processSDPMessage(&message, [this](unsigned, StringView mid, const auto* media) {
933+
processSDPMessage(&message, [this](unsigned, CStringView mid, const auto* media) {
933934
auto mediaType = CStringView::unsafeFromUTF8(gst_sdp_media_get_media(media));
934-
m_mediaForMid.set(mid.toString(), mediaType == "audio"_s ? RealtimeMediaSource::Type::Audio : RealtimeMediaSource::Type::Video);
935+
m_mediaForMid.set(mid.span(), mediaType == "audio"_s ? RealtimeMediaSource::Type::Audio : RealtimeMediaSource::Type::Video);
935936

936937
// https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1907
937-
if (sdpMediaHasAttributeKey(media, "ice-lite")) {
938+
if (sdpMediaHasAttributeKey(media, "ice-lite"_s)) {
938939
GRefPtr<GstWebRTCICE> ice;
939940
g_object_get(m_webrtcBin.get(), "ice-agent", &ice.outPtr(), nullptr);
940941
g_object_set(ice.get(), "ice-lite", TRUE, nullptr);
@@ -961,7 +962,7 @@ void GStreamerMediaEndpoint::doSetRemoteDescription(const RTCSessionDescription&
961962

962963
#ifndef GST_DISABLE_GST_DEBUG
963964
auto dotFileName = makeString(unsafeSpan(GST_OBJECT_NAME(m_pipeline.get())), ".setRemoteDescription"_s);
964-
GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS(GST_BIN(m_pipeline.get()), GST_DEBUG_GRAPH_SHOW_ALL, dotFileName.utf8().data());
965+
GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS(GST_BIN(m_pipeline.get()), GST_DEBUG_GRAPH_SHOW_ALL, dotFileName.ascii().data());
965966
#endif
966967

967968
auto rtcTransceiverStates = transceiverStatesFromWebRTCBin(m_webrtcBin);
@@ -1096,7 +1097,7 @@ void GStreamerMediaEndpoint::setDescription(const RTCSessionDescription* descrip
10961097
}, data, reinterpret_cast<GDestroyNotify>(destroySetDescriptionCallData)));
10971098
}
10981099

1099-
void GStreamerMediaEndpoint::processSDPMessage(const GstSDPMessage* message, Function<void(unsigned, StringView, const GstSDPMedia*)> mediaCallback)
1100+
void GStreamerMediaEndpoint::processSDPMessage(const GstSDPMessage* message, Function<void(unsigned, CStringView, const GstSDPMedia*)> mediaCallback)
11001101
{
11011102
unsigned totalMedias = gst_sdp_message_medias_len(message);
11021103
for (unsigned mediaIndex = 0; mediaIndex < totalMedias; mediaIndex++) {
@@ -1109,15 +1110,15 @@ void GStreamerMediaEndpoint::processSDPMessage(const GstSDPMessage* message, Fun
11091110
GUniquePtr<char> mediaRepresentation(gst_sdp_media_as_text(media));
11101111
GST_LOG_OBJECT(m_pipeline.get(), "Processing media:\n%s", mediaRepresentation.get());
11111112
#endif
1112-
const char* mid = gst_sdp_media_get_attribute_val(media, "mid");
1113+
auto mid = CStringView::unsafeFromUTF8(gst_sdp_media_get_attribute_val(media, "mid"));
11131114
if (!mid)
11141115
continue;
11151116

11161117
bool isInactive = false;
11171118
unsigned totalAttributes = gst_sdp_media_attributes_len(media);
11181119
for (unsigned attributeIndex = 0; attributeIndex < totalAttributes; attributeIndex++) {
11191120
const auto* attribute = gst_sdp_media_get_attribute(media, attributeIndex);
1120-
if (!g_strcmp0(attribute->key, "inactive")) {
1121+
if (CStringView::unsafeFromUTF8(attribute->key) == "inactive"_s) {
11211122
isInactive = true;
11221123
break;
11231124
}
@@ -1127,7 +1128,7 @@ void GStreamerMediaEndpoint::processSDPMessage(const GstSDPMessage* message, Fun
11271128
continue;
11281129
}
11291130

1130-
mediaCallback(mediaIndex, StringView::fromLatin1(mid), media);
1131+
mediaCallback(mediaIndex, mid, media);
11311132
}
11321133
}
11331134

@@ -1226,8 +1227,7 @@ std::optional<bool> GStreamerMediaEndpoint::isIceGatheringComplete(const String&
12261227
unsigned numberOfMedias = gst_sdp_message_medias_len(message.get());
12271228
for (unsigned i = 0; i < numberOfMedias; i++) {
12281229
const auto* media = gst_sdp_message_get_media(message.get(), i);
1229-
const char* value = gst_sdp_media_get_attribute_val_n(media, "end-of-candidates", 0);
1230-
if (!value)
1230+
if (!gst_sdp_media_get_attribute_val_n(media, "end-of-candidates", 0))
12311231
return false;
12321232
}
12331233

@@ -1372,8 +1372,7 @@ void GStreamerMediaEndpoint::initiate(bool isInitiator, GstStructure* rawOptions
13721372
}
13731373

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

13781377
GUniquePtr<GstWebRTCSessionDescription> description;
13791378
if (holder->sdpType == RTCSdpType::Answer) {
@@ -1453,12 +1452,12 @@ MediaStream& GStreamerMediaEndpoint::mediaStreamFromRTCStream(String mediaStream
14531452

14541453
String GStreamerMediaEndpoint::trackIdFromSDPMedia(const GstSDPMedia& media)
14551454
{
1456-
const char* msidAttribute = gst_sdp_media_get_attribute_val(&media, "msid");
1455+
auto msidAttribute = CStringView::unsafeFromUTF8(gst_sdp_media_get_attribute_val(&media, "msid"));
14571456
if (!msidAttribute)
14581457
return emptyString();
14591458

1460-
GST_LOG_OBJECT(m_pipeline.get(), "SDP media msid attribute value: %s", msidAttribute);
1461-
auto components = String::fromUTF8(msidAttribute).split(' ');
1459+
GST_LOG_OBJECT(m_pipeline.get(), "SDP media msid attribute value: %s", msidAttribute.utf8());
1460+
auto components = String(msidAttribute.span()).split(' ');
14621461
if (components.size() < 2)
14631462
return emptyString();
14641463

@@ -1589,7 +1588,7 @@ void GStreamerMediaEndpoint::connectPad(GstPad* pad)
15891588

15901589
#ifndef GST_DISABLE_GST_DEBUG
15911590
auto dotFileName = makeString(unsafeSpan(GST_OBJECT_NAME(m_pipeline.get())), ".pending-"_s, unsafeSpan(GST_OBJECT_NAME(pad)));
1592-
GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS(GST_BIN(m_pipeline.get()), GST_DEBUG_GRAPH_SHOW_ALL, dotFileName.utf8().data());
1591+
GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS(GST_BIN(m_pipeline.get()), GST_DEBUG_GRAPH_SHOW_ALL, dotFileName.ascii().data());
15931592
#endif
15941593
}
15951594

@@ -2712,7 +2711,7 @@ std::optional<bool> GStreamerMediaEndpoint::canTrickleIceCandidates() const
27122711

27132712
for (unsigned i = 0; i < gst_sdp_message_attributes_len(description->sdp); i++) {
27142713
const auto attribute = gst_sdp_message_get_attribute(description->sdp, i);
2715-
if (g_strcmp0(attribute->key, "ice-options"))
2714+
if (!equal(unsafeSpan(attribute->key), "ice-options"_s))
27162715
continue;
27172716

27182717
auto values = makeString(unsafeSpan(attribute->value)).split(' ');
@@ -2722,7 +2721,6 @@ std::optional<bool> GStreamerMediaEndpoint::canTrickleIceCandidates() const
27222721
return false;
27232722
}
27242723

2725-
27262724
void GStreamerMediaEndpoint::updatePtDemuxSrcPadCaps(GstElement* ptDemux, GstPad* pad)
27272725
{
27282726
GUniqueOutPtr<GstWebRTCSessionDescription> description;
@@ -2825,8 +2823,8 @@ GUniquePtr<GstSDPMessage> GStreamerMediaEndpoint::completeSDPAnswer(const String
28252823
if (key != "extmap"_s)
28262824
continue;
28272825

2828-
auto value = StringView::fromLatin1(attribute->value);
2829-
Vector<String> tokens = value.toStringWithoutCopying().split(' ');
2826+
String value(byteCast<char8_t>(unsafeSpan(attribute->value)));
2827+
Vector<String> tokens = value.split(' ');
28302828
if (tokens.size() < 2) [[unlikely]]
28312829
continue;
28322830

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

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

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

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

170170
WARN_UNUSED_RETURN GRefPtr<GstPad> requestPad(const GRefPtr<GstCaps>&, const String& mediaStreamID);
171171

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

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

170-
extensions.add(key.toString(), String::fromLatin1(g_value_get_string(value)));
170+
extensions.add(key, byteCast<char8_t>(unsafeSpan(g_value_get_string(value))));
171171
return true;
172172
});
173173
}

0 commit comments

Comments
 (0)