Bug 275609 - [GStreamer] Add gstStructureGet helper function
Summary: [GStreamer] Add gstStructureGet helper function
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Platform (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2024-06-18 07:37 PDT by Carlos Bentzen
Modified: 2024-06-18 12:36 PDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Carlos Bentzen 2024-06-18 07:37:51 PDT
In GStreamerStatsCollector.cpp, we need to assign to a bunch of std::optional<T> fields and the pattern below gets repeated many times:

struct InboundRtpStreamStats : RtpStreamStats {
    std::optional<uint64_t> bytesReceived;
    std::optional<uint32_t> firCount;
};

void fillInboundRTPStreamStats(InboundRtpStreamStats& stats, const GstStructure* structure)
{
    uint64_t bytesReceived;
    if (gst_structure_get_uint64(structure, "bytes-received", &value))
        stats.bytesReceived = value;

    unsigned firCount;
    if (gst_structure_get_uint(structure, "fir-count", &firCount))
        stats.firCount = firCount;
}

It would be nice to not have to always declare new variables and if conditions:

template<typename T>
std::optional<T> gstStructureGet(const GstStructure* structure, ASCIILiteral key);

void fillInboundRTPStreamStats(InboundRtpStreamStats& stats, const GstStructure* structure)
{
    stats.bytesReceived = gstStructureGet<unint64_t>(structure, "bytes-received"_s);
    stats.firCount = gstStructureGet<unsigned>(structure, "fir-count"_s);
}
Comment 1 Carlos Bentzen 2024-06-18 08:04:19 PDT
Pull request: https://github.com/WebKit/WebKit/pull/29931
Comment 2 EWS 2024-06-18 12:35:24 PDT
Committed 280130@main (c09dbedb8429): <https://commits.webkit.org/280130@main>

Reviewed commits have been landed. Closing PR #29931 and removing active labels.
Comment 3 Radar WebKit Bug Importer 2024-06-18 12:36:15 PDT
<rdar://problem/130099156>