Skip to content

Commit 5e6b0d7

Browse files
committed
[GStreamer] Change gstStructureGetString and Name to properly handle null terminated strings
https://bugs.webkit.org/show_bug.cgi?id=290306 Reviewed by Geoffrey Garen. Created a new CStringView type to wrap a C String and be able to recover, without copies, the original string while taking advantage of some other string niceties likes comparisons and the like. This class handles UTF8 strings only, so if you need to compare or interface with any other WebKit strings, you have to convert to String. I used that on gstStructureGetString and Name and updated the rest of the code accordingly. Tests: Tools/TestWebKitAPI/Tests/WTF/CStringView.cpp * Source/WTF/WTF.xcodeproj/project.pbxproj: * Source/WTF/wtf/CMakeLists.txt: * Source/WTF/wtf/text/CStringView.cpp: Added. (WTF::CStringView::toString const): (WTF::CStringView::dump const): * Source/WTF/wtf/text/CStringView.h: Added. (WTF::operator==): (WTF::safePrintfType): * Source/WebCore/Modules/mediastream/gstreamer/GStreamerMediaEndpoint.cpp: (WebCore::GStreamerMediaEndpoint::requestPad): (WebCore::GStreamerMediaEndpoint::connectIncomingTrack): (WebCore::GStreamerMediaEndpoint::preprocessStats): * Source/WebCore/Modules/mediastream/gstreamer/GStreamerRtpReceiverBackend.cpp: (WebCore::GStreamerRtpReceiverBackend::getParameters): * Source/WebCore/Modules/mediastream/gstreamer/GStreamerStatsCollector.cpp: (WebCore::iceCandidateType): * Source/WebCore/Modules/mediastream/gstreamer/GStreamerWebRTCUtils.cpp: (WebCore::toRTCEncodingParameters): (WebCore::toRTCRtpSendParameters): (WebCore::payloadTypeForEncodingName): (WebCore::capsFromRtpCapabilities): (WebCore::capsFromSDPMedia): (WebCore::extractMidAndRidFromRTPBuffer): * Source/WebCore/Modules/mediastream/gstreamer/GStreamerWebRTCUtils.h: * Source/WebCore/inspector/agents/page/PageHeapAgent.cpp: (WebCore::PageHeapAgent::heapSnapshotBuilderOverrideClassName): * Source/WebCore/loader/FrameLoader.cpp: (WebCore::FrameLoader::userAgent const): * Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp: (WebCore::webkitGstGhostPadFromStaticTemplate): (WebCore::capsMediaType): (WebCore::doCapsHaveType): (WebCore::gstStructureGet): (WebCore::gstStructureGetString): (WebCore::gstStructureGetName): (WebCore::gstStructureGetArray): (WebCore::gstStructureGetList): * Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h: * Source/WebCore/platform/graphics/gstreamer/GStreamerRegistryScanner.cpp: (WebCore::GStreamerRegistryScanner::isContentTypeSupported const): * Source/WebCore/platform/graphics/gstreamer/GStreamerVideoFrameConverter.cpp: (WebCore::GStreamerVideoFrameConverter::convert): * Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp: (WebCore::MediaPlayerPrivateGStreamer::handleMessage): (WebCore::MediaPlayerPrivateGStreamer::loadNextLocation): * Source/WebCore/platform/graphics/gstreamer/VideoEncoderGStreamer.cpp: (WebCore::retrieveTemporalIndex): * Source/WebCore/platform/graphics/gstreamer/WebKitAudioSinkGStreamer.cpp: (webKitAudioSinkConfigure): * Source/WebCore/platform/graphics/gstreamer/eme/WebKitCommonEncryptionDecryptorGStreamer.cpp: (transformCaps): (transformInPlace): * Source/WebCore/platform/graphics/gstreamer/mse/AppendPipeline.cpp: (WebCore::AppendPipeline::AppendPipeline): (WebCore::AppendPipeline::appsinkCapsChanged): * Source/WebCore/platform/graphics/gstreamer/mse/GStreamerMediaDescription.cpp: (WebCore::GStreamerMediaDescription::extractCodecName const): * Source/WebCore/platform/gstreamer/GStreamerElementHarness.cpp: (WebCore::MermaidBuilder::describeCaps): * Source/WebCore/platform/gstreamer/VideoEncoderPrivateGStreamer.cpp: (webkit_video_encoder_class_init): * Source/WebCore/platform/mediastream/gstreamer/GStreamerAudioRTPPacketizer.cpp: (WebCore::GStreamerAudioRTPPacketizer::create): * Source/WebCore/platform/mediastream/gstreamer/GStreamerCaptureDeviceManager.cpp: (WebCore::GStreamerCaptureDeviceManager::captureDeviceFromGstDevice): * Source/WebCore/platform/mediastream/gstreamer/GStreamerIncomingTrackProcessor.cpp: (WebCore::GStreamerIncomingTrackProcessor::configure): (WebCore::GStreamerIncomingTrackProcessor::incomingTrackProcessor): * Source/WebCore/platform/mediastream/gstreamer/GStreamerMediaStreamSource.cpp: (webkitMediaStreamSrcAddTrack): * Source/WebCore/platform/mediastream/gstreamer/GStreamerMockDeviceProvider.cpp: (webkitGstMockDeviceProviderSwitchDefaultDevice): * Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoCapturer.cpp: (WebCore::GStreamerVideoCapturer::reconfigure): * Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoRTPPacketizer.cpp: (WebCore::GStreamerVideoRTPPacketizer::create): * Source/WebCore/platform/mediastream/gstreamer/RealtimeOutgoingAudioSourceGStreamer.cpp: (WebCore::RealtimeOutgoingAudioSourceGStreamer::setInitialParameters): * Source/WebCore/platform/mediastream/gstreamer/RealtimeOutgoingMediaSourceGStreamer.cpp: (WebCore::RealtimeOutgoingMediaSourceGStreamer::setParameters): (WebCore::RealtimeOutgoingMediaSourceGStreamer::getPacketizerForRid): * Source/WebCore/platform/mediastream/gstreamer/RealtimeOutgoingMediaSourceGStreamer.h: * Source/WebCore/platform/mediastream/libwebrtc/gstreamer/GStreamerVideoDecoderFactory.cpp: (WebCore::GStreamerWebRTCVideoDecoder::makeElement): * Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCAAnimationRemote.mm: (WebKit::operator<<): * Tools/TestWebKitAPI/CMakeLists.txt: * Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * Tools/TestWebKitAPI/Tests/WTF/CStringView.cpp: Added. (TestWebKitAPI::TEST(WTF, CStringViewNullAndEmpty)): (TestWebKitAPI::TEST(WTF, CStringViewLength)): (TestWebKitAPI::TEST(WTF, CStringViewFrom)): (TestWebKitAPI::TEST(WTF, CStringViewEquality)): Canonical link: https://commits.webkit.org/300318@main Signed-off-by: Xabier Rodriguez Calvar <calvaris@igalia.com>
1 parent 7aab71b commit 5e6b0d7

32 files changed

Lines changed: 386 additions & 118 deletions

Source/WTF/WTF.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@
209209
C2BCFC551F621F3F00C9222C /* LineEnding.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C2BCFC531F621F3F00C9222C /* LineEnding.cpp */; };
210210
C805EF39E5F14481A96D39FC /* ASCIILiteral.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C6F050790D9C432A99085E75 /* ASCIILiteral.cpp */; };
211211
CD5497AC15857D0300B5BC30 /* MediaTime.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD5497AA15857D0300B5BC30 /* MediaTime.cpp */; };
212+
CDD4AC792D9C309A00D11414 /* CStringView.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDD4AC772D9C309A00D11414 /* CStringView.cpp */; };
213+
CDD4AC7A2D9C309A00D11414 /* CStringView.h in Headers */ = {isa = PBXBuildFile; fileRef = CDD4AC782D9C309A00D11414 /* CStringView.h */; settings = {ATTRIBUTES = (Private, ); }; };
212214
CEA072AA236FFBF70018839C /* CrashReporter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CEA072A9236FFBF70018839C /* CrashReporter.cpp */; };
213215
DCEE22011CEA7551000C2396 /* BlockObjCExceptions.mm in Sources */ = {isa = PBXBuildFile; fileRef = DCEE21FD1CEA7551000C2396 /* BlockObjCExceptions.mm */; };
214216
DD03059327B5DA0D00344002 /* SignedPtr.h in Headers */ = {isa = PBXBuildFile; fileRef = 862A8D32278DE74A0014120C /* SignedPtr.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -1532,6 +1534,8 @@
15321534
CD5497AB15857D0300B5BC30 /* MediaTime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaTime.h; sourceTree = "<group>"; };
15331535
CD6D9FCD1EEF3AD4008B0671 /* Algorithms.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Algorithms.h; sourceTree = "<group>"; };
15341536
CDCC9BC422382FCE00FFB51C /* AggregateLogger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AggregateLogger.h; path = wtf/AggregateLogger.h; sourceTree = SOURCE_ROOT; };
1537+
CDD4AC772D9C309A00D11414 /* CStringView.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CStringView.cpp; sourceTree = "<group>"; };
1538+
CDD4AC782D9C309A00D11414 /* CStringView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CStringView.h; sourceTree = "<group>"; };
15351539
CE1132832370634900A8C83B /* AnsiColors.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AnsiColors.h; sourceTree = "<group>"; };
15361540
CEA072A8236FFBF70018839C /* CrashReporter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CrashReporter.h; sourceTree = "<group>"; };
15371541
CEA072A9236FFBF70018839C /* CrashReporter.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CrashReporter.cpp; sourceTree = "<group>"; };
@@ -2611,6 +2615,8 @@
26112615
0F8F2B9B172F2594007DBDA5 /* ConversionMode.h */,
26122616
A8A47321151A825B004123FF /* CString.cpp */,
26132617
A8A47322151A825B004123FF /* CString.h */,
2618+
CDD4AC772D9C309A00D11414 /* CStringView.cpp */,
2619+
CDD4AC782D9C309A00D11414 /* CStringView.h */,
26142620
93853DD228755A6600FF4E2B /* EscapedFormsForJSON.h */,
26152621
50DE35F3215BB01500B979C7 /* ExternalStringImpl.cpp */,
26162622
50DE35F4215BB01500B979C7 /* ExternalStringImpl.h */,
@@ -3221,6 +3227,7 @@
32213227
DD3DC8FC27A4BF8E007E5B61 /* CryptographicallyRandomNumber.h in Headers */,
32223228
DD3DC8B727A4BF8E007E5B61 /* CryptographicUtilities.h in Headers */,
32233229
DDF307E127C086DF006A526F /* CString.h in Headers */,
3230+
CDD4AC7A2D9C309A00D11414 /* CStringView.h in Headers */,
32243231
DD3DC8E327A4BF8E007E5B61 /* DataLog.h in Headers */,
32253232
DD4901E927B4748A00D7E50D /* DataMutex.h in Headers */,
32263233
DD3DC94227A4BF8E007E5B61 /* DataRef.h in Headers */,
@@ -4029,6 +4036,7 @@
40294036
A8A4739A151A825B004123FF /* CryptographicallyRandomNumber.cpp in Sources */,
40304037
E15556F518A0CC18006F48FB /* CryptographicUtilities.cpp in Sources */,
40314038
A8A47439151A825B004123FF /* CString.cpp in Sources */,
4039+
CDD4AC792D9C309A00D11414 /* CStringView.cpp in Sources */,
40324040
A8A4739C151A825B004123FF /* CurrentTime.cpp in Sources */,
40334041
A8A4739E151A825B004123FF /* DataLog.cpp in Sources */,
40344042
A8A473A0151A825B004123FF /* DateMath.cpp in Sources */,

Source/WTF/wtf/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ set(WTF_PUBLIC_HEADERS
438438
text/AtomStringTable.h
439439
text/Base64.h
440440
text/CString.h
441+
text/CStringView.h
441442
text/CharacterProperties.h
442443
text/CodePointIterator.h
443444
text/ConversionMode.h
@@ -622,6 +623,7 @@ set(WTF_SOURCES
622623
text/AtomStringTable.cpp
623624
text/Base64.cpp
624625
text/CString.cpp
626+
text/CStringView.cpp
625627
text/ExternalStringImpl.cpp
626628
text/LineEnding.cpp
627629
text/StringBuffer.cpp
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (C) 2018 Yusuke Suzuki <utatane.tea@gmail.com>
3+
* Copyright (C) 2024 Apple Inc. All Rights Reserved.
4+
* Copyright (C) 2025 Comcast Inc.
5+
* Copyright (C) 2025 Igalia S.L.
6+
*
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions
9+
* are met:
10+
* 1. Redistributions of source code must retain the above copyright
11+
* notice, this list of conditions and the following disclaimer.
12+
* 2. Redistributions in binary form must reproduce the above copyright
13+
* notice, this list of conditions and the following disclaimer in the
14+
* documentation and/or other materials provided with the distribution.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
17+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
20+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24+
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27+
*/
28+
29+
#include "config.h"
30+
#include <wtf/text/CStringView.h>
31+
32+
#include <wtf/PrintStream.h>
33+
#include <wtf/text/MakeString.h>
34+
#include <wtf/text/WTFString.h>
35+
36+
namespace WTF {
37+
38+
String CStringView::toString() const
39+
{
40+
return String::fromUTF8(span8());
41+
}
42+
43+
void CStringView::dump(PrintStream& out) const
44+
{
45+
out.print(span8());
46+
}
47+
48+
} // namespace WTF

Source/WTF/wtf/text/CStringView.h

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*
2+
* Copyright (C) 2018 Yusuke Suzuki <utatane.tea@gmail.com>
3+
* Copyright (C) 2024 Apple Inc. All Rights Reserved.
4+
* Copyright (C) 2025 Comcast Inc.
5+
* Copyright (C) 2025 Igalia S.L.
6+
*
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions
9+
* are met:
10+
* 1. Redistributions of source code must retain the above copyright
11+
* notice, this list of conditions and the following disclaimer.
12+
* 2. Redistributions in binary form must reproduce the above copyright
13+
* notice, this list of conditions and the following disclaimer in the
14+
* documentation and/or other materials provided with the distribution.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
17+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
20+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24+
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27+
*/
28+
29+
#pragma once
30+
31+
#include <span>
32+
#include <string>
33+
#include <type_traits>
34+
#include <wtf/Compiler.h>
35+
#include <wtf/ForbidHeapAllocation.h>
36+
#include <wtf/Forward.h>
37+
#include <wtf/HashFunctions.h>
38+
#include <wtf/StdLibExtras.h>
39+
#include <wtf/text/ASCIILiteral.h>
40+
#include <wtf/text/SuperFastHash.h>
41+
42+
namespace WTF {
43+
44+
class PrintStream;
45+
class String;
46+
47+
// This is a class designed to contain a UTF8 string, untouched. Interactions with other string classes in WebKit should
48+
// be handled with care or perform a string conversion through the String class, with the exception of ASCIILiteral
49+
// because ASCII characters are also UTF8.
50+
class CStringView final {
51+
WTF_FORBID_HEAP_ALLOCATION;
52+
public:
53+
static CStringView unsafeFromUTF8(const char* string)
54+
{
55+
if (!string)
56+
return CStringView();
57+
return CStringView(unsafeMakeSpan(byteCast<char8_t>(string), std::char_traits<char>::length(string) + 1));
58+
}
59+
60+
WTF_EXPORT_PRIVATE void dump(PrintStream& out) const;
61+
62+
CStringView() = default;
63+
constexpr CStringView(std::nullptr_t)
64+
: CStringView()
65+
{ }
66+
CStringView(ASCIILiteral literal LIFETIME_BOUND)
67+
{
68+
if (!literal.length())
69+
return;
70+
m_spanWithNullTerminator = byteCast<char8_t>(literal.spanIncludingNullTerminator());
71+
}
72+
73+
unsigned hash() const;
74+
bool isNull() const { return m_spanWithNullTerminator.empty(); }
75+
76+
// This method is designed to interface with external C functions handling UTF8 strings. Interactions with other
77+
// strings should be done through String with the exception of ASCIILiteral because ASCII is also UTF8.
78+
const char* utf8() const LIFETIME_BOUND { return reinterpret_cast<const char*>(m_spanWithNullTerminator.data()); }
79+
size_t length() const { return m_spanWithNullTerminator.size() > 0 ? m_spanWithNullTerminator.size() - 1 : 0; }
80+
std::span<const char8_t> span8() const LIFETIME_BOUND { return m_spanWithNullTerminator.first(length()); }
81+
std::span<const char8_t> spanIncludingNullTerminator() const LIFETIME_BOUND { return m_spanWithNullTerminator; }
82+
size_t isEmpty() const { return m_spanWithNullTerminator.size() <= 1; }
83+
WTF_EXPORT_PRIVATE String toString() const;
84+
85+
explicit operator bool() const { return !isEmpty(); }
86+
bool operator!() const { return isEmpty(); }
87+
88+
private:
89+
explicit CStringView(std::span<const char8_t> spanWithNullTerminator LIFETIME_BOUND)
90+
: m_spanWithNullTerminator(spanWithNullTerminator)
91+
{
92+
}
93+
94+
std::span<const char8_t> m_spanWithNullTerminator;
95+
};
96+
97+
inline bool operator==(CStringView a, CStringView b)
98+
{
99+
if (!a || !b)
100+
return a.utf8() == b.utf8();
101+
return equalSpans(a.span8(), b.span8());
102+
}
103+
104+
inline bool operator==(CStringView a, ASCIILiteral b)
105+
{
106+
if (a.isEmpty() || b.isEmpty())
107+
return a.utf8() == b.characters();
108+
return equalSpans(a.span8(), byteCast<char8_t>(b.span8()));
109+
}
110+
111+
inline bool operator==(ASCIILiteral a, CStringView b)
112+
{
113+
return b == a;
114+
}
115+
116+
// CStringView is null terminated
117+
inline const char* safePrintfType(const CStringView& string) { return string.utf8(); }
118+
119+
} // namespace WTF
120+
121+
using WTF::CStringView;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,7 @@ GRefPtr<GstPad> GStreamerMediaEndpoint::requestPad(const GRefPtr<GstCaps>& allow
10531053
}
10541054
std::optional<int> payloadType;
10551055
if (auto encodingName = gstStructureGetString(structure, "encoding-name"_s))
1056-
payloadType = payloadTypeForEncodingName(encodingName);
1056+
payloadType = payloadTypeForEncodingName(encodingName.toString());
10571057

10581058
if (!payloadType) {
10591059
if (availablePayloadType < 128)
@@ -2201,7 +2201,7 @@ GUniquePtr<GstStructure> GStreamerMediaEndpoint::preprocessStats(const GRefPtr<G
22012201
gst_structure_set(structure.get(), "frame-height", G_TYPE_UINT, *frameHeight, nullptr);
22022202
auto trackIdentifier = gstStructureGetString(additionalStats.get(), "track-identifier"_s);
22032203
if (!trackIdentifier.isEmpty())
2204-
gst_structure_set(structure.get(), "track-identifier", G_TYPE_STRING, trackIdentifier.toStringWithoutCopying().utf8().data(), nullptr);
2204+
gst_structure_set(structure.get(), "track-identifier", G_TYPE_STRING, trackIdentifier.utf8(), nullptr);
22052205
break;
22062206
}
22072207
case GST_WEBRTC_STATS_OUTBOUND_RTP: {
@@ -2236,9 +2236,9 @@ GUniquePtr<GstStructure> GStreamerMediaEndpoint::preprocessStats(const GRefPtr<G
22362236
gst_structure_set(structure.get(), "frames-per-second", G_TYPE_DOUBLE, *framesPerSecond, nullptr);
22372237

22382238
if (auto midValue = gstStructureGetString(ssrcStats.get(), "mid"_s))
2239-
gst_structure_set(structure.get(), "mid", G_TYPE_STRING, midValue.toString().ascii().data(), nullptr);
2239+
gst_structure_set(structure.get(), "mid", G_TYPE_STRING, midValue.utf8(), nullptr);
22402240
if (auto ridValue = gstStructureGetString(ssrcStats.get(), "rid"_s))
2241-
gst_structure_set(structure.get(), "rid", G_TYPE_STRING, ridValue.toString().ascii().data(), nullptr);
2241+
gst_structure_set(structure.get(), "rid", G_TYPE_STRING, ridValue.utf8(), nullptr);
22422242
break;
22432243
}
22442244
default:

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ RTCRtpParameters GStreamerRtpReceiverBackend::getParameters()
6767

6868
auto media = gstStructureGetString(structure, "media"_s);
6969
auto encodingName = gstStructureGetString(structure, "encoding-name"_s);
70-
if (media && encodingName)
71-
codec.mimeType = makeString(media, '/', encodingName.convertToASCIILowercase());
70+
if (!media.isEmpty() && !encodingName.isEmpty())
71+
codec.mimeType = makeString(media.toString(), '/', encodingName.toString().convertToASCIILowercase());
7272

7373
if (auto clockRate = gstStructureGet<uint64_t>(structure, "clock-rate"_s))
7474
codec.clockRate = *clockRate;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ RTCStatsReport::TransportStats::TransportStats(const GstStructure* structure)
199199
// stats.srtpCipher =
200200
}
201201

202-
static inline RTCIceCandidateType iceCandidateType(StringView type)
202+
static inline RTCIceCandidateType iceCandidateType(CStringView type)
203203
{
204204
if (type == "host"_s)
205205
return RTCIceCandidateType::Host;

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ static inline RTCRtpEncodingParameters toRTCEncodingParameters(const GstStructur
164164
parameters.maxFramerate = *maxFramerate;
165165

166166
if (auto rid = gstStructureGetString(rtcParameters, "rid"_s))
167-
parameters.rid = makeString(rid);
167+
parameters.rid = rid.toString();
168168

169169
if (auto scaleResolutionDownBy = gstStructureGet<double>(rtcParameters, "scale-resolution-down-by"_s))
170170
parameters.scaleResolutionDownBy = *scaleResolutionDownBy;
@@ -207,7 +207,7 @@ RTCRtpSendParameters toRTCRtpSendParameters(const GstStructure* rtcParameters)
207207

208208
RTCRtpSendParameters parameters;
209209
if (auto transactionId = gstStructureGetString(rtcParameters, "transaction-id"_s))
210-
parameters.transactionId = makeString(transactionId);
210+
parameters.transactionId = transactionId.toString();
211211

212212
if (auto encodings = gst_structure_get_value(rtcParameters, "encodings")) {
213213
unsigned size = gst_value_list_get_size(encodings);
@@ -555,17 +555,16 @@ uint32_t UniqueSSRCGenerator::generateSSRC()
555555
return std::numeric_limits<uint32_t>::max();
556556
}
557557

558-
std::optional<int> payloadTypeForEncodingName(StringView encodingName)
558+
std::optional<int> payloadTypeForEncodingName(const String& encodingName)
559559
{
560560
static HashMap<String, int> staticPayloadTypes = {
561561
{ "PCMU"_s, 0 },
562562
{ "PCMA"_s, 8 },
563563
{ "G722"_s, 9 },
564564
};
565565

566-
const auto key = encodingName.toStringWithoutCopying();
567-
if (staticPayloadTypes.contains(key))
568-
return staticPayloadTypes.get(key);
566+
if (staticPayloadTypes.contains(encodingName))
567+
return staticPayloadTypes.get(encodingName);
569568
return { };
570569
}
571570

@@ -588,7 +587,7 @@ GRefPtr<GstCaps> capsFromRtpCapabilities(const RTCRtpCapabilities& capabilities,
588587
gst_structure_set(codecStructure, "encoding-params", G_TYPE_STRING, makeString(*codec.channels).ascii().data(), nullptr);
589588

590589
if (auto encodingName = gstStructureGetString(codecStructure, "encoding-name"_s)) {
591-
if (auto payloadType = payloadTypeForEncodingName(encodingName))
590+
if (auto payloadType = payloadTypeForEncodingName(encodingName.toString()))
592591
gst_structure_set(codecStructure, "payload", G_TYPE_INT, *payloadType, nullptr);
593592
}
594593

@@ -661,7 +660,7 @@ GRefPtr<GstCaps> capsFromSDPMedia(const GstSDPMedia* media)
661660
"a-sendonly", "a-recvonly", "a-end-of-candidates", nullptr);
662661

663662
if (auto name = gstStructureGetString(structure, "encoding-name"_s)) {
664-
auto encodingName = name.convertToASCIIUppercase();
663+
auto encodingName = name.toString().convertToASCIIUppercase();
665664
gst_structure_set(structure, "encoding-name", G_TYPE_STRING, encodingName.ascii().data(), nullptr);
666665
}
667666

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ class UniqueSSRCGenerator : public ThreadSafeRefCounted<UniqueSSRCGenerator> {
283283
Vector<uint32_t> m_knownIds WTF_GUARDED_BY_LOCK(m_lock);
284284
};
285285

286-
std::optional<int> payloadTypeForEncodingName(StringView encodingName);
286+
std::optional<int> payloadTypeForEncodingName(const String& encodingName);
287287

288288
WARN_UNUSED_RETURN GRefPtr<GstCaps> capsFromRtpCapabilities(const RTCRtpCapabilities&, Function<void(GstStructure*)> supplementCapsCallback);
289289

0 commit comments

Comments
 (0)