-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[GStreamer] Increase use of CStringView and other string management improvements #51259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
EWS run on previous version of this PR (hash fb419f6) Details |
fb419f6 to
274546e
Compare
|
EWS run on previous version of this PR (hash 274546e) Details |
aperezdc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reviewed about half of the patch, and while I like the direction in this is going, I have a few general comments:
- Could this be split in smaller chunks to ease reviewing?
- One pattern I noticed is that many of the changes switch from
StringViewto usingString, which results in copies. Many of this look like cases in which the newCStringViewcould be used, but not done because the latter is not supported for certain operations. It would seem better to me to e.g. add support to passCStringViewinstances tomakeString(), have anequalStringsIgnoringASCIICase()overload, and so on.
| auto tokens = StringView::fromLatin1(g_getenv(optionsEnvVarName)); | ||
| for (auto it : tokens.split(',')) { | ||
| auto option = it.toString(); | ||
| auto tokens = String::fromUTF8(g_getenv(optionsEnvVarName)); | ||
| for (auto option : tokens.split(',')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there some reason for this change? The original avoids making a copy of the environment variable contents into a String. This is not a big deal because it does not seem to be performance-critical code; but I am curious.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also curious about this, also the env var value is going to be ascii anyway.
| auto dotFilename = makeString(unsafeSpan(GST_ELEMENT_NAME(endPoint->pipeline())), '-', unsafeSpan(desc.get())); | ||
| auto dotFilename = makeString(String::fromUTF8(GST_ELEMENT_NAME(endPoint->pipeline())), '-', String::fromUTF8(desc.get())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Connot these two be CStringView::unsafeFromUTF8() instead of String::fromUTF8() to avoid copies?
|
|
||
| #ifndef GST_DISABLE_GST_DEBUG | ||
| auto dotFileName = makeString(unsafeSpan(GST_OBJECT_NAME(m_pipeline.get())), ".setLocalDescription"_s); | ||
| auto dotFileName = makeString(String::fromUTF8(GST_OBJECT_NAME(m_pipeline.get())), ".setLocalDescription"_s); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, maybe this could be CStringView::unsafeFromUTF8()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...and I see below that there are many other cases where this would apply, and all use makeString(). Could it be that makeString() does not have support for CStringView? It would seem like a good thing to me to make sure it can accept CStringView instances.
| static bool isWidevineUUID(CStringView uuid) | ||
| { | ||
| return equalIgnoringASCIICase(uuid, s_WidevineUUID); | ||
| return equalIgnoringASCIICase(uuid.toString(), s_WidevineUUID); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it make more sense to have overloads of equalIgnoringASCICase() that can take CStringView parameters instead of creating temporary String copies of the contents?
274546e to
75513d3
Compare
|
EWS run on previous version of this PR (hash 75513d3) Details |
I guess it could, but it would be a bit PITA for me and I think considering the mechanical nature of most of the changes, it does not pay off even when the review can take longer. I can wait, I have other things to do.
Encondings! We can't. CStringView is utf8 only and the rest of WK string management classes are Latin1 or UTF16. Hence, when you have to mix both worlds you have to turn the CStringView into a String and just make a copy in the best case scenario. Could we create a toStringView returning a std::optional and check before if all characters are just ASCII? We could, but then I don't know if the overhead of iterating the chars one by one pays off the extra error management we'd have to make.
We could do this, but to compare only among other CStringViews and ASCIILiterals and for this case, I checked and it does not pay off at least in the short term. I think more or less this addresses your inline comments as well. Let's discuss them in general before. |
philn
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the ASCIILiteral changes. But in general I don't really see the point of the changes introducing string copies and un-necessary conversions to utf8.
| auto tokens = StringView::fromLatin1(g_getenv(optionsEnvVarName)); | ||
| for (auto it : tokens.split(',')) { | ||
| auto option = it.toString(); | ||
| auto tokens = String::fromUTF8(g_getenv(optionsEnvVarName)); | ||
| for (auto option : tokens.split(',')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also curious about this, also the env var value is going to be ascii anyway.
| if (auto factory = adoptGRef(gst_element_factory_find("netsim"))) { | ||
| g_signal_connect_swapped(m_webrtcBin.get(), "deep-element-added", G_CALLBACK(+[](GStreamerMediaEndpoint* self, GstBin* bin, GstElement* element) { | ||
| GUniquePtr<char> elementName(gst_element_get_name(element)); | ||
| auto view = StringView::fromLatin1(elementName.get()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
element names are ascii, can you revert this kind of change in the whole PR?
| #endif | ||
| for (unsigned i = 0; i < totalMedias; i++) { | ||
| const auto media = gst_sdp_message_get_media(sdpMessage, i); | ||
| auto mediaType = StringView::fromLatin1(gst_sdp_media_get_media(media)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is un-necessary.
| if (!connection->nettype || !connection->addrtype || !connection->address) | ||
| return; | ||
|
|
||
| m_stringBuilder.append("c="_s, unsafeSpan(connection->nettype), ' ', unsafeSpan(connection->addrtype), ' ', unsafeSpan(connection->address)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert unsafeSpan -> String changes in this class
|
|
||
| auto width = destinationSize.width(); | ||
| auto height = destinationSize.height(); | ||
| auto formatName = unsafeSpan(gst_video_format_to_string(format)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really necessary?
| GUniquePtr<char> mimeCodec(gst_codec_utils_caps_get_mime_codec(caps.get())); | ||
| if (mimeCodec) { | ||
| String codec = unsafeSpan(mimeCodec.get()); | ||
| String codec = String::fromUTF8(mimeCodec.get()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are ascii...
| static URL convertPlaybinURI(String&& uriString) | ||
| { | ||
| return URL { String::fromLatin1(uriString) }; | ||
| return URL { uriString }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no WTFMove needed?
| #endif | ||
|
|
||
| String elementClass = unsafeSpan(gst_element_get_metadata(m_demux.get(), GST_ELEMENT_METADATA_KLASS)); | ||
| String elementClass = String::fromUTF8(gst_element_get_metadata(m_demux.get(), GST_ELEMENT_METADATA_KLASS)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is ascii too
| ASSERT(isMainThread()); | ||
| ASSERT(m_hasReceivedFirstInitializationSegment); | ||
| auto trackId = AtomString(unsafeSpan8(GST_PAD_NAME(demuxerSrcPad))); | ||
| auto trackId = AtomString(String::fromUTF8(GST_PAD_NAME(demuxerSrcPad))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How often do we see pad names encoded in utf8?
| gst_element_get_state(m_element.get(), nullptr, nullptr, GST_CLOCK_TIME_NONE); | ||
|
|
||
| static Atomic<uint64_t> uniqueStreamId; | ||
| auto streamId = makeString(unsafeSpan(GST_OBJECT_NAME(m_element.get())), '-', uniqueStreamId.exchangeAdd(1)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert the changes in this file
|
EWS run on previous version of this PR (hash 4ae06b8) Details |
|
EWS run on previous version of this PR (hash eb55135) Details |
|
EWS run on current version of this PR (hash 5c7bf12) Details |
…mprovements 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
5c7bf12 to
9d73b18
Compare
|
Committed 304152@main (9d73b18): https://commits.webkit.org/304152@main Reviewed commits have been landed. Closing PR #51259 and removing active labels. |
9d73b18
5c7bf12
🛠 win🧪 wpe-wk2🧪 win-tests🧪 ios-wk2-wpt🧪 api-mac-debug🧪 api-ios🧪 mac-wk2🧪 gtk-wk2🧪 vision-wk2🧪 mac-intel-wk2🛠 tv-sim🛠 mac-safer-cpp