-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[Glib][GStreamer] Implement GMallocString class and apply it to GStreamer code #55162
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 004c1b3) Details |
| { } | ||
|
|
||
| bool isNull() const { return m_spanWithNullTerminator.span().empty(); } | ||
| const char* utf8() const LIFETIME_BOUND { return byteCast<char>(m_spanWithNullTerminator.span().data()); } |
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 would name this data(). Unless it is guaranteed that the span actually contains UTF8 characters.
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 should follow the same convention as CStringView, where it is named like that because it is returning UTF8 characters as char* . And it is "guaranteed" (the same way was CStringView) it contains only UTF8 because the storage type is char8_t.
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.
The hardest problem in computer science!
I'm tempted to agree with Phil: it's confusing because String::utf8 returns an owned copy of the data, whereas CString::data is unowned (lifetime-bound). But GMallocString::utf8 and CStringView::utf8 are both unowned.
Since CStringView is new, it's probably still easy to change....
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.
Answering @mcatanzaro and @philn . I think it is a mistake to change the name of this function, unless we do it for something that keeps clear that the returning string is a char* with UTF8 encoding. I can't make up anything better than this. We already discussed this at #51619 and I encourage you to read that before making me have either something different from CStringView or breaking the consensus we got there.
|
|
||
| bool isNull() const { return m_spanWithNullTerminator.span().empty(); } | ||
| const char* utf8() const LIFETIME_BOUND { return byteCast<char>(m_spanWithNullTerminator.span().data()); } | ||
| char* leakUTF8() WARN_UNUSED_RETURN { return byteCast<char>(m_spanWithNullTerminator.leakSpan().data()); } |
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.
Why not just leak()?
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.
Because of the same reason as in utf8(). Internal storage is char8_t, we are casting, for convenience, to char and we should then reflect that in the function name.
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 wrote a few notes about the implementation of the new class and helper functions. Could you take a look? Thanks!
The changes to change existing code to use the new GMallocString class look fine. Very nice that you added unit tests, too 👍🏼.
| // GMallocString is null terminated | ||
| inline const char* safePrintfType(const GMallocString& string) { return string.utf8(); } | ||
|
|
||
| inline CStringView toCStringView(const GMallocString& string LIFETIME_BOUND) { return CStringView::fromUTF8(string.spanIncludingNullTerminator()); } |
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 why this cannot be a member function, instead of a free one?
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 tried to apply the same design principles to this class as for CStringView and, according to Darin, the less in the class the better. That's why it's outside. It does not need to be inside.
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.
Okay, but what is the reason for this... Being able to provide overloads of toCStringView() for other types down the line? I am not against having it as a free function, but would like to understand the why.
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.
The reason why having this function is, for example, being able to pass this as a CStringView to a function taking that.
|
I addressed most of the comments and made the class non-copyable. |
|
EWS run on previous version of this PR (hash d7240dd) Details |
| #ifndef GST_DISABLE_GST_DEBUG | ||
| GUniquePtr<char> stateString(g_enum_to_string(GST_TYPE_WEBRTC_DATA_CHANNEL_STATE, channelState)); | ||
| DC_DEBUG("Dispatching state change to %s on channel %p", stateString.get(), m_channel.get()); | ||
| auto stateString = GMallocString::adoptUnsafeFromUTF8(g_enum_to_string(GST_TYPE_WEBRTC_DATA_CHANNEL_STATE, channelState)); |
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.
| auto stateString = GMallocString::adoptUnsafeFromUTF8(g_enum_to_string(GST_TYPE_WEBRTC_DATA_CHANNEL_STATE, channelState)); | |
| auto stateString = GMallocString::adoptUnsafeFromUTF8(g_enum_to_string(GST_TYPE_WEBRTC_DATA_CHANNEL_STATE, channelState)); |
| { } | ||
|
|
||
| bool isNull() const { return m_spanWithNullTerminator.span().empty(); } | ||
| const char* utf8() const LIFETIME_BOUND { return byteCast<char>(m_spanWithNullTerminator.span().data()); } |
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.
The hardest problem in computer science!
I'm tempted to agree with Phil: it's confusing because String::utf8 returns an owned copy of the data, whereas CString::data is unowned (lifetime-bound). But GMallocString::utf8 and CStringView::utf8 are both unowned.
Since CStringView is new, it's probably still easy to change....
|
EWS run on previous version of this PR (hash 4bcdabf) Details |
|
EWS run on current version of this PR (hash d219842) 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.
@calvaris Thanks for the updates to the patch, which LGTM 👏🏼
…amer code https://bugs.webkit.org/show_bug.cgi?id=303909 Reviewed by Adrian Perez de Castro. When interfacing with Glib APIs there was no way to wrap an owned malloced char* so GMallocString was created. It can adopt C strings in several ways, providing then easy ways to interface with the WebKit strings the same way CStringView does and also preserving the original null terminated C string without performing any copy. I applied this to the GStreamer code. Tests: Tools/TestWebKitAPI/Tests/WTF/CStringView.cpp Tools/TestWebKitAPI/Tests/WTF/glib/GMallocString.cpp Tools/TestWebKitAPI/Tests/WebCore/gstreamer/GStreamerTest.cpp Tools/TestWebKitAPI/Tests/WebCore/gstreamer/GstElementHarness.cpp * Source/WTF/wtf/PlatformGTK.cmake: * Source/WTF/wtf/PlatformWPE.cmake: * Source/WTF/wtf/glib/GMallocString.cpp: Added. * Source/WTF/wtf/glib/GMallocString.h: Added. (WTF::operator==): (WTF::safePrintfType): (WTF::toCStringView): * Source/WTF/wtf/glib/GSpanExtras.h: (WTF::dupGMallocSpan): (WTF::adoptGMallocString): Deleted. * Source/WTF/wtf/text/CStringView.h: * Source/WebCore/Modules/mediastream/gstreamer/GStreamerDataChannelHandler.cpp: (WebCore::GStreamerDataChannelHandler::checkState): * Source/WebCore/Modules/mediastream/gstreamer/GStreamerDtlsTransportBackend.cpp: (WebCore::GStreamerDtlsTransportBackendObserver::stateChanged): * Source/WebCore/Modules/mediastream/gstreamer/GStreamerIceAgent.cpp: (webkitGstWebRTCIceAgentLocalCandidateGatheredForStream): * Source/WebCore/Modules/mediastream/gstreamer/GStreamerIceTransportBackend.cpp: (WebCore::GStreamerIceTransportBackend::registerClient): (WebCore::GStreamerIceTransportBackend::stateChanged const): * Source/WebCore/Modules/mediastream/gstreamer/GStreamerMediaEndpoint.cpp: (WebCore::GStreamerMediaEndpoint::initializePipeline): (WebCore::fetchDescription): (WebCore::fetchSignalingState): (WebCore::toGStreamerMediaEndpointTransceiverState): (WebCore::transceiverStatesFromWebRTCBin): (WebCore::GStreamerMediaEndpoint::linkOutgoingSources): (WebCore::GStreamerMediaEndpoint::setDescription): (WebCore::GStreamerMediaEndpoint::processSDPMessage): (WebCore::GStreamerMediaEndpoint::createTransceiverBackends): (WebCore::GStreamerMediaEndpoint::onIceGatheringChange): (WebCore::GStreamerMediaEndpoint::collectTransceivers): * Source/WebCore/Modules/mediastream/gstreamer/GStreamerRtpTransceiverBackend.cpp: (WebCore::GStreamerRtpTransceiverBackend::setDirection): * Source/WebCore/Modules/mediastream/gstreamer/GStreamerWebRTCUtils.cpp: (WebCore::setSsrcAudioLevelVadOn): * Source/WebCore/platform/audio/gstreamer/AudioEncoderGStreamer.cpp: (WebCore::GStreamerInternalAudioEncoder::initialize): * Source/WebCore/platform/graphics/gstreamer/AudioTrackPrivateGStreamer.cpp: (WebCore::AudioTrackPrivateGStreamer::updateConfigurationFromCaps): * Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp: (WebCore::getStreamIdFromPad): (WebCore::registerActivePipeline): (WebCore::unregisterPipeline): (WebCore::videoColorSpaceFromInfo): * Source/WebCore/platform/graphics/gstreamer/GStreamerSinksWorkarounds.cpp: (WebCore::BaseSinkPositionFlushWorkaroundProbe::checkIsNeeded): (WebCore::AppSinkFlushCapsWorkaroundProbe::checkIsNeeded): * Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp: (WebCore::MediaPlayerPrivateGStreamer::elementIdChanged const): (WebCore::MediaPlayerPrivateGStreamer::handleMessage): (WebCore::MediaPlayerPrivateGStreamer::updateBufferingStatus): (WebCore::MediaPlayerPrivateGStreamer::configureParsebin): (WebCore::MediaPlayerPrivateGStreamer::configureElement): (WebCore::MediaPlayerPrivateGStreamer::configureDownloadBuffer): (WebCore::MediaPlayerPrivateGStreamer::downloadBufferFileCreatedCallback): (WebCore::MediaPlayerPrivateGStreamer::setupCodecProbe): (WebCore::MediaPlayerPrivateGStreamer::configureVideoDecoder): (WebCore::MediaPlayerPrivateGStreamer::getVideoOrientation): (WebCore::MediaPlayerPrivateGStreamer::audioOutputDeviceChanged): * Source/WebCore/platform/graphics/gstreamer/VideoTrackPrivateGStreamer.cpp: (WebCore::VideoTrackPrivateGStreamer::updateConfigurationFromCaps): * Source/WebCore/platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp: (webKitWebSrcSetProperty): (webKitWebSrcGetProperty): (webKitWebSrcSetExtraHeader): (webKitWebSrcMakeRequest): * Source/WebCore/platform/graphics/gstreamer/mse/AppendPipeline.cpp: (WebCore::AppendPipeline::didReceiveInitializationSegment): * Source/WebCore/platform/graphics/gstreamer/mse/GStreamerMediaDescription.cpp: (WebCore::GStreamerMediaDescription::extractCodecName const): * Source/WebCore/platform/graphics/gstreamer/mse/WebKitMediaSourceGStreamer.cpp: (webKitMediaSrcLoop): (webKitMediaSrcGetUri): (webKitMediaSrcSetUri): * Source/WebCore/platform/gstreamer/GStreamerElementHarness.cpp: (WebCore::MermaidBuilder::describeCaps): (WebCore::GStreamerElementHarness::dumpGraph): * Source/WebCore/platform/mediastream/gstreamer/DesktopPortal.cpp: (WebCore::DesktopPortal::waitResponseSignal): (WebCore::DesktopPortalScreenCast::createScreencastSession): (WebCore::DesktopPortalScreenCast::ScreencastSession::openPipewireRemote): * Source/WebCore/platform/mediastream/gstreamer/DesktopPortal.h: (WebCore::DesktopPortal::waitResponseSignal): * Source/WebCore/platform/mediastream/gstreamer/GStreamerCaptureDeviceManager.cpp: (WebCore::sortDevices): (WebCore::GStreamerCaptureDeviceManager::captureDeviceFromGstDevice): (WebCore::GStreamerCaptureDeviceManager::refreshCaptureDevices): * Source/WebCore/platform/mediastream/gstreamer/GStreamerDisplayCaptureDeviceManager.cpp: (WebCore::GStreamerDisplayCaptureDeviceManager::createDisplayCaptureSource): * Source/WebCore/platform/mediastream/gstreamer/GStreamerIncomingTrackProcessor.cpp: (WebCore::GStreamerIncomingTrackProcessor::mediaStreamIdFromPad): * Source/WebCore/platform/mediastream/gstreamer/GStreamerMediaStreamSource.cpp: (webkitMediaStreamSrcAddTrack): * Source/WebCore/platform/mediastream/gstreamer/RealtimeOutgoingMediaSourceGStreamer.cpp: (WebCore::RealtimeOutgoingMediaSourceGStreamer::checkMid): * Tools/TestWebKitAPI/PlatformGTK.cmake: * Tools/TestWebKitAPI/PlatformWPE.cmake: * Tools/TestWebKitAPI/Tests/WTF/CStringView.cpp: (TestWebKitAPI::TEST(WTF, CStringViewFrom)): * Tools/TestWebKitAPI/Tests/WTF/glib/GMallocString.cpp: Added. (TestWebKitAPI::TEST(WTF_GMallocString, NullAndEmpty)): (TestWebKitAPI::TEST(WTF_GMallocString, Move)): (TestWebKitAPI::TEST(WTF_GMallocString, Length)): (TestWebKitAPI::TEST(WTF_GMallocString, Equality)): (TestWebKitAPI::TEST(WTF_GMallocString, CStringView)): (TestWebKitAPI::TEST(WTF_GMallocString, LeakUTF8)): (TestWebKitAPI::TEST(WTF_GMallocString, ToCStringView)): * Tools/TestWebKitAPI/Tests/WebCore/gstreamer/GStreamerTest.cpp: (TestWebKitAPI::TEST_F(GStreamerTest, capsFromCodecString)): * Tools/TestWebKitAPI/Tests/WebCore/gstreamer/GstElementHarness.cpp: (TestWebKitAPI::TEST_F(GStreamerTest, harnessParseMP4)): (TestWebKitAPI::TEST_F(GStreamerTest, harnessDecodeMP4Video)): Canonical link: https://commits.webkit.org/304343@main
d219842 to
f27346b
Compare
|
Committed 304343@main (f27346b): https://commits.webkit.org/304343@main Reviewed commits have been landed. Closing PR #55162 and removing active labels. |
🧪 webkitpy
f27346b
d219842
🧪 jsc-armv7-tests