Line data Source code
1 : /*
2 : * If not stated otherwise in this file or this component's LICENSE file the
3 : * following copyright and licenses apply:
4 : *
5 : * Copyright 2025 Sky UK
6 : *
7 : * Licensed under the Apache License, Version 2.0 (the "License");
8 : * you may not use this file except in compliance with the License.
9 : * You may obtain a copy of the License at
10 : *
11 : * http://www.apache.org/licenses/LICENSE-2.0
12 : *
13 : * Unless required by applicable law or agreed to in writing, software
14 : * distributed under the License is distributed on an "AS IS" BASIS,
15 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 : * See the License for the specific language governing permissions and
17 : * limitations under the License.
18 : */
19 :
20 : #include "RialtoMetrics.h"
21 : #include "IGlibWrapper.h"
22 : #include "IGstWrapper.h"
23 : #include "RialtoLogging.h"
24 : #include <algorithm>
25 : #include <chrono>
26 : #include <cstring>
27 : #include <gst/gst.h>
28 : #include <limits>
29 : #include <mutex>
30 : #include <unordered_map>
31 :
32 : namespace firebolt::rialto::server
33 : {
34 : class ElementToSourceMapperImpl : public ElementToSourceMapper
35 : {
36 : private:
37 : std::unordered_map<uintptr_t, std::pair<uint32_t, uint32_t>> m_elementMap;
38 : mutable std::mutex m_mapMutex;
39 :
40 : public:
41 276 : ElementToSourceMapperImpl() : m_elementMap(), m_mapMutex() {}
42 :
43 552 : virtual ~ElementToSourceMapperImpl() = default;
44 :
45 20 : void RegisterElement(GstElement *element, uint32_t session_id, uint32_t source_id) override
46 : {
47 20 : if (!element)
48 : {
49 1 : RIALTO_LOG_WARN(RIALTO_COMPONENT_SERVER,
50 : "ElementToSourceMapperImpl::RegisterElement: null element provided");
51 1 : return;
52 : }
53 :
54 19 : std::lock_guard<std::mutex> lock(m_mapMutex);
55 19 : uintptr_t elementKey = reinterpret_cast<uintptr_t>(element);
56 19 : m_elementMap[elementKey] = std::make_pair(session_id, source_id);
57 : }
58 :
59 139 : bool MapElement(GstElement *element, uint32_t &out_session_id, uint32_t &out_source_id) override
60 : {
61 139 : if (!element)
62 : {
63 1 : RIALTO_LOG_WARN(RIALTO_COMPONENT_SERVER, "ElementToSourceMapperImpl::MapElement: null element provided");
64 1 : return false;
65 : }
66 :
67 138 : std::lock_guard<std::mutex> lock(m_mapMutex);
68 138 : uintptr_t elementKey = reinterpret_cast<uintptr_t>(element);
69 138 : auto it = m_elementMap.find(elementKey);
70 :
71 138 : if (it == m_elementMap.end())
72 : {
73 13 : return false;
74 : }
75 :
76 125 : out_session_id = it->second.first;
77 125 : out_source_id = it->second.second;
78 125 : return true;
79 138 : }
80 :
81 6 : void UnregisterElement(GstElement *element) override
82 : {
83 6 : if (!element)
84 : {
85 1 : return;
86 : }
87 :
88 5 : std::lock_guard<std::mutex> lock(m_mapMutex);
89 5 : m_elementMap.erase(reinterpret_cast<uintptr_t>(element));
90 : }
91 :
92 252 : void UnregisterAllElements() override
93 : {
94 252 : std::lock_guard<std::mutex> lock(m_mapMutex);
95 252 : m_elementMap.clear();
96 : }
97 : };
98 :
99 : namespace
100 : {
101 130 : std::uint64_t getMonotonicTimestampNs()
102 : {
103 : return static_cast<std::uint64_t>(
104 130 : std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::steady_clock::now().time_since_epoch()).count());
105 : }
106 :
107 121 : std::int64_t getUnixTimestampNs()
108 : {
109 121 : return std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
110 : }
111 : } // namespace
112 :
113 157 : MetricPhase convertObservationKind(std::uint32_t observationKind)
114 : {
115 157 : switch (observationKind)
116 : {
117 137 : case 1U:
118 137 : return MetricPhase::OCCURRENCE;
119 8 : case 2U:
120 8 : return MetricPhase::EPISODE_STARTED;
121 12 : case 3U:
122 12 : return MetricPhase::EPISODE_RESOLVED;
123 0 : default:
124 0 : RIALTO_LOG_WARN(RIALTO_COMPONENT_SERVER, "convertObservationKind: unhandled southbound observation-kind value %u, defaulting to OCCURRENCE",
125 : observationKind);
126 0 : return MetricPhase::OCCURRENCE;
127 : }
128 : }
129 :
130 276 : RialtoMetrics::RialtoMetrics(SinkStatsGetter getSinkStats, std::shared_ptr<wrappers::IGstWrapper> gstWrapper,
131 276 : std::shared_ptr<wrappers::IGlibWrapper> glibWrapper)
132 276 : : m_elementToSourceMapper(std::make_unique<ElementToSourceMapperImpl>()), m_getSinkStats(std::move(getSinkStats)),
133 276 : m_gstWrapper(gstWrapper ? std::move(gstWrapper) : wrappers::IGstWrapperFactory::getFactory()->getGstWrapper()),
134 552 : m_glibWrapper(glibWrapper ? std::move(glibWrapper) : wrappers::IGlibWrapperFactory::getFactory()->getGlibWrapper())
135 : {
136 276 : RIALTO_LOG_DEBUG(RIALTO_COMPONENT_SERVER, "RialtoMetrics created");
137 : }
138 :
139 276 : RialtoMetrics::~RialtoMetrics()
140 : {
141 276 : RIALTO_LOG_DEBUG(RIALTO_COMPONENT_SERVER, "RialtoMetrics destroyed");
142 : }
143 :
144 8 : void RialtoMetrics::setSessionId(int32_t sessionId)
145 : {
146 8 : RIALTO_LOG_DEBUG(RIALTO_COMPONENT_SERVER, "RialtoMetrics::setSessionId sessionId: %d", sessionId);
147 8 : std::lock_guard<std::mutex> lock{m_counterMutex};
148 8 : m_sessionId = sessionId;
149 : }
150 :
151 226 : std::optional<MetricEvent> RialtoMetrics::onMetricMessage(GstMessage *message)
152 : {
153 226 : if (!message)
154 : {
155 1 : return std::nullopt;
156 : }
157 :
158 225 : const GstStructure *structure = m_gstWrapper->gstMessageGetStructure(message);
159 225 : if (!structure)
160 : {
161 1 : return std::nullopt;
162 : }
163 :
164 224 : if (!m_gstWrapper->gstStructureHasName(structure, "media-pipeline-metric"))
165 : {
166 1 : return std::nullopt;
167 : }
168 :
169 : // Validate the metric message; the session/source pair is resolved once here and reused for the counter cache key.
170 223 : MetricEvent parsedMessage;
171 223 : int32_t sessionId = 0;
172 223 : GstFlowReturn validationResult = validateMediaPipelineMetric(*m_gstWrapper, *m_glibWrapper, structure, parsedMessage,
173 : message, m_elementToSourceMapper.get(), &sessionId);
174 :
175 223 : if (validationResult != GST_FLOW_OK)
176 : {
177 102 : RIALTO_LOG_WARN(RIALTO_COMPONENT_SERVER, "RialtoMetrics::onMetricMessage validation failed for metric message");
178 102 : return std::nullopt;
179 : }
180 :
181 : // The GstMessage timestamp is taken from a monotonic clock when the message was posted on the bus. Unix time is
182 : // derived with the same offset so both observed-at values describe one instant. If the timestamp is invalid or in
183 : // the future, the current time is used instead.
184 121 : const std::uint64_t nowMonotonicNs = getMonotonicTimestampNs();
185 121 : const std::int64_t nowUnixNs = getUnixTimestampNs();
186 121 : const GstClockTime messageTimestamp = GST_MESSAGE_TIMESTAMP(message);
187 121 : if (GST_CLOCK_TIME_IS_VALID(messageTimestamp) && messageTimestamp <= nowMonotonicNs)
188 : {
189 1 : parsedMessage.observedAtMonotonicNs = messageTimestamp;
190 1 : parsedMessage.observedAtUnixNs = nowUnixNs - static_cast<std::int64_t>(nowMonotonicNs - messageTimestamp);
191 : }
192 : else
193 : {
194 120 : parsedMessage.observedAtMonotonicNs = nowMonotonicNs;
195 120 : parsedMessage.observedAtUnixNs = nowUnixNs;
196 : }
197 :
198 : // Counted after validation, so rejected messages never reach the counters.
199 121 : if (parsedMessage.type == MetricType::VIDEO_DECODE_ERROR && parsedMessage.phase == MetricPhase::OCCURRENCE)
200 : {
201 105 : std::lock_guard<std::mutex> lock{m_counterMutex};
202 105 : ++m_counterCache[{sessionId, parsedMessage.sourceId}].counters.corruptedFrames;
203 : }
204 121 : RIALTO_LOG_DEBUG(RIALTO_COMPONENT_SERVER, "RialtoMetrics::onMetricMessage validated metric: %u, observation_kind: %u, session_id: %d, source_id: %d",
205 : static_cast<uint32_t>(parsedMessage.type), static_cast<uint32_t>(parsedMessage.phase), sessionId,
206 : parsedMessage.sourceId);
207 :
208 121 : return parsedMessage;
209 : }
210 :
211 10011 : void RialtoMetrics::updateFrameCounters(int32_t sessionId, int32_t sourceId, const CounterSnapshot &snapshot)
212 : {
213 10011 : RIALTO_LOG_DEBUG(RIALTO_COMPONENT_SERVER,
214 : "RialtoMetrics::updateFrameCounters sessionId: %d, sourceId: %d, rendered: %llu, dropped: %llu, "
215 : "corrupted: %llu, timestamp: %llu",
216 : sessionId, sourceId,
217 : static_cast<unsigned long long>(snapshot.counters.renderedFrames), // NOLINT(runtime/int)
218 : static_cast<unsigned long long>(snapshot.counters.droppedFrames), // NOLINT(runtime/int)
219 : static_cast<unsigned long long>(snapshot.counters.corruptedFrames), // NOLINT(runtime/int)
220 : static_cast<unsigned long long>(snapshot.timestamp)); // NOLINT(runtime/int)
221 10011 : std::lock_guard<std::mutex> lock{m_counterMutex};
222 10011 : auto ¤t = m_counterCache[{sessionId, sourceId}];
223 10011 : current.counters.renderedFrames = std::max(current.counters.renderedFrames, snapshot.counters.renderedFrames);
224 10011 : current.counters.droppedFrames = std::max(current.counters.droppedFrames, snapshot.counters.droppedFrames);
225 10011 : current.counters.corruptedFrames = std::max(current.counters.corruptedFrames, snapshot.counters.corruptedFrames);
226 10011 : current.timestamp = snapshot.timestamp;
227 : }
228 :
229 9 : void RialtoMetrics::updateSinkStats(int32_t sessionId, int32_t sourceId, std::uint64_t renderedFrames,
230 : std::uint64_t droppedFrames)
231 : {
232 9 : std::lock_guard<std::mutex> lock{m_counterMutex};
233 9 : auto &counters = m_counterCache[{sessionId, sourceId}];
234 9 : counters.counters.renderedFrames = std::max(counters.counters.renderedFrames, renderedFrames);
235 9 : counters.counters.droppedFrames = std::max(counters.counters.droppedFrames, droppedFrames);
236 9 : counters.timestamp = getMonotonicTimestampNs();
237 : }
238 :
239 40018 : bool RialtoMetrics::getFrameCounters(int32_t sessionId, int32_t sourceId, const MediaSourceType &mediaSourceType,
240 : CounterSnapshot &snapshot)
241 : {
242 40018 : refreshFrameCounters(sessionId, sourceId, mediaSourceType);
243 :
244 40018 : bool found = false;
245 : {
246 40018 : std::lock_guard<std::mutex> lock{m_counterMutex};
247 40018 : const auto it = m_counterCache.find({sessionId, sourceId});
248 40018 : if (it != m_counterCache.end())
249 : {
250 40015 : snapshot = it->second;
251 40015 : found = true;
252 : }
253 40013 : }
254 40018 : return found;
255 : }
256 :
257 40018 : bool RialtoMetrics::refreshFrameCounters(int32_t sessionId, int32_t sourceId, const MediaSourceType &mediaSourceType)
258 : {
259 40018 : uint64_t renderedFrames{0};
260 40018 : uint64_t droppedFrames{0};
261 40018 : if (m_getSinkStats && m_getSinkStats(mediaSourceType, renderedFrames, droppedFrames))
262 : {
263 6 : updateSinkStats(sessionId, sourceId, renderedFrames, droppedFrames);
264 6 : return true;
265 : }
266 :
267 40012 : RIALTO_LOG_WARN(RIALTO_COMPONENT_SERVER,
268 : "Playback metric sink stats unavailable - retaining cached rendered and dropped counts");
269 40012 : return false;
270 : }
271 :
272 548 : ElementToSourceMapper *RialtoMetrics::getElementToSourceMapper()
273 : {
274 548 : return m_elementToSourceMapper.get();
275 : }
276 :
277 : // Validates a "media-pipeline-metric" structure and fills out, which is reset on every call. Checks run in order:
278 : // structure name, metric, observation-kind, optional pts-ns, duration-ns and count, then field combinations. Any
279 : // failure logs a warning and returns GST_FLOW_ERROR, so the caller drops only that message. Session and source IDs are
280 : // filled in last from GST_MESSAGE_SRC(); an unregistered element keeps source 0 rather than rejecting the message.
281 55 : GstFlowReturn validateMediaPipelineMetric(const GstStructure *msg, MetricEvent &out, GstMessage *gstMessage,
282 : ElementToSourceMapper *mapper, int32_t *outSessionId)
283 : {
284 : static const std::shared_ptr<wrappers::IGstWrapper> defaultGstWrapper =
285 55 : wrappers::IGstWrapperFactory::getFactory()->getGstWrapper();
286 : static const std::shared_ptr<wrappers::IGlibWrapper> defaultGlibWrapper =
287 55 : wrappers::IGlibWrapperFactory::getFactory()->getGlibWrapper();
288 55 : return validateMediaPipelineMetric(*defaultGstWrapper, *defaultGlibWrapper, msg, out, gstMessage, mapper,
289 55 : outSessionId);
290 : }
291 :
292 278 : GstFlowReturn validateMediaPipelineMetric(const wrappers::IGstWrapper &gstWrapper,
293 : const wrappers::IGlibWrapper &glibWrapper, const GstStructure *msg,
294 : MetricEvent &out, GstMessage *gstMessage, ElementToSourceMapper *mapper,
295 : int32_t *outSessionId)
296 : {
297 278 : out = MetricEvent{};
298 :
299 278 : if (!msg)
300 : {
301 1 : RIALTO_LOG_WARN(RIALTO_COMPONENT_SERVER, "ValidateMediaPipelineMetric: null structure provided");
302 1 : return GST_FLOW_ERROR;
303 : }
304 :
305 277 : const char *structureName = gstWrapper.gstStructureGetName(msg);
306 277 : if (!structureName || strcmp(structureName, "media-pipeline-metric") != 0)
307 : {
308 3 : RIALTO_LOG_WARN(RIALTO_COMPONENT_SERVER,
309 : "ValidateMediaPipelineMetric: invalid structure name '%s', expected 'media-pipeline-metric'",
310 : structureName ? structureName : "null");
311 3 : return GST_FLOW_ERROR;
312 : }
313 :
314 : // Validate 'metric' field - required, must be G_TYPE_UINT, value in range 1-7
315 274 : if (!gstWrapper.gstStructureHasField(msg, "metric"))
316 : {
317 3 : RIALTO_LOG_WARN(RIALTO_COMPONENT_SERVER, "ValidateMediaPipelineMetric: required field 'metric' is missing");
318 3 : return GST_FLOW_ERROR;
319 : }
320 :
321 271 : const GValue *metricValue = gstWrapper.gstStructureGetValue(msg, "metric");
322 271 : if (!metricValue || !glibWrapper.gValueHolds(metricValue, G_TYPE_UINT))
323 : {
324 3 : RIALTO_LOG_WARN(RIALTO_COMPONENT_SERVER,
325 : "ValidateMediaPipelineMetric: field 'metric' has wrong type, expected G_TYPE_UINT, actual %s",
326 : metricValue ? glibWrapper.gTypeName(G_VALUE_TYPE(metricValue)) : "null");
327 3 : return GST_FLOW_ERROR;
328 : }
329 :
330 268 : guint metricVal = glibWrapper.gValueGetUint(metricValue);
331 268 : if (metricVal < static_cast<guint>(MetricType::VIDEO_FRAME_DROP) ||
332 : metricVal > static_cast<guint>(MetricType::BUFFER_UNDERFLOW))
333 : {
334 106 : RIALTO_LOG_WARN(RIALTO_COMPONENT_SERVER,
335 : "ValidateMediaPipelineMetric: field 'metric' value %u is outside valid range %u-%u", metricVal,
336 : static_cast<guint>(MetricType::VIDEO_FRAME_DROP),
337 : static_cast<guint>(MetricType::BUFFER_UNDERFLOW));
338 106 : return GST_FLOW_ERROR;
339 : }
340 :
341 162 : out.type = static_cast<MetricType>(metricVal);
342 :
343 : // Validate 'observation-kind' field - required, must be G_TYPE_UINT, value in {1, 2, 3}
344 162 : if (!gstWrapper.gstStructureHasField(msg, "observation-kind"))
345 : {
346 2 : RIALTO_LOG_WARN(RIALTO_COMPONENT_SERVER,
347 : "ValidateMediaPipelineMetric: required field 'observation-kind' is missing");
348 2 : return GST_FLOW_ERROR;
349 : }
350 :
351 160 : const GValue *observationKindValue = gstWrapper.gstStructureGetValue(msg, "observation-kind");
352 160 : if (!observationKindValue || !glibWrapper.gValueHolds(observationKindValue, G_TYPE_UINT))
353 : {
354 2 : RIALTO_LOG_WARN(RIALTO_COMPONENT_SERVER, "ValidateMediaPipelineMetric: field 'observation-kind' has wrong type, expected G_TYPE_UINT, actual %s",
355 : observationKindValue ? glibWrapper.gTypeName(G_VALUE_TYPE(observationKindValue)) : "null");
356 2 : return GST_FLOW_ERROR;
357 : }
358 :
359 158 : guint observationKindVal = glibWrapper.gValueGetUint(observationKindValue);
360 158 : if (observationKindVal < static_cast<guint>(MetricPhase::OCCURRENCE) ||
361 : observationKindVal > static_cast<guint>(MetricPhase::EPISODE_RESOLVED))
362 : {
363 4 : RIALTO_LOG_WARN(RIALTO_COMPONENT_SERVER,
364 : "ValidateMediaPipelineMetric: field 'observation-kind' value %u is outside valid range %u-%u",
365 : observationKindVal, static_cast<guint>(MetricPhase::OCCURRENCE),
366 : static_cast<guint>(MetricPhase::EPISODE_RESOLVED));
367 4 : return GST_FLOW_ERROR;
368 : }
369 :
370 154 : out.phase = convertObservationKind(observationKindVal);
371 :
372 : // Validate 'pts-ns' field - optional, when present must be G_TYPE_INT64
373 154 : if (gstWrapper.gstStructureHasField(msg, "pts-ns"))
374 : {
375 19 : const GValue *ptsNsValue = gstWrapper.gstStructureGetValue(msg, "pts-ns");
376 19 : if (!ptsNsValue || !glibWrapper.gValueHolds(ptsNsValue, G_TYPE_INT64))
377 : {
378 3 : RIALTO_LOG_WARN(RIALTO_COMPONENT_SERVER, "ValidateMediaPipelineMetric: field 'pts-ns' has wrong type, expected G_TYPE_INT64, actual %s",
379 : ptsNsValue ? glibWrapper.gTypeName(G_VALUE_TYPE(ptsNsValue)) : "null");
380 3 : return GST_FLOW_ERROR;
381 : }
382 :
383 16 : gint64 ptsNsVal = glibWrapper.gValueGetInt64(ptsNsValue);
384 16 : out.presentationTimeStampNs = ptsNsVal;
385 : }
386 :
387 : // Validate 'duration-ns' field - optional, when present must be G_TYPE_UINT64 and non-negative
388 151 : if (gstWrapper.gstStructureHasField(msg, "duration-ns"))
389 : {
390 6 : const GValue *durationNsValue = gstWrapper.gstStructureGetValue(msg, "duration-ns");
391 6 : if (!durationNsValue || !glibWrapper.gValueHolds(durationNsValue, G_TYPE_UINT64))
392 : {
393 2 : RIALTO_LOG_WARN(RIALTO_COMPONENT_SERVER, "ValidateMediaPipelineMetric: field 'duration-ns' has wrong type, expected G_TYPE_UINT64, actual %s",
394 : durationNsValue ? glibWrapper.gTypeName(G_VALUE_TYPE(durationNsValue)) : "null");
395 2 : return GST_FLOW_ERROR;
396 : }
397 :
398 4 : guint64 durationNsVal = glibWrapper.gValueGetUint64(durationNsValue);
399 4 : out.durationNs = durationNsVal;
400 : }
401 :
402 : // Validate 'count' field - optional, when present must be G_TYPE_UINT64
403 149 : if (gstWrapper.gstStructureHasField(msg, "count"))
404 : {
405 9 : const GValue *countValue = gstWrapper.gstStructureGetValue(msg, "count");
406 9 : if (!countValue || !glibWrapper.gValueHolds(countValue, G_TYPE_UINT64))
407 : {
408 2 : RIALTO_LOG_WARN(RIALTO_COMPONENT_SERVER, "ValidateMediaPipelineMetric: field 'count' has wrong type, expected G_TYPE_UINT64, actual %s",
409 : countValue ? glibWrapper.gTypeName(G_VALUE_TYPE(countValue)) : "null");
410 3 : return GST_FLOW_ERROR;
411 : }
412 :
413 7 : guint64 countVal = glibWrapper.gValueGetUint64(countValue);
414 7 : if (countVal < 1)
415 : {
416 1 : RIALTO_LOG_WARN(RIALTO_COMPONENT_SERVER, "ValidateMediaPipelineMetric: field 'count' must be >= 1, got %llu",
417 : static_cast<unsigned long long>(countVal)); // NOLINT(runtime/int)
418 1 : return GST_FLOW_ERROR;
419 : }
420 6 : out.count = countVal;
421 : }
422 :
423 : // Semantic field-combination validation
424 : // Reject OCCURRENCE (observation-kind=1) with duration-ns or count present
425 146 : if (observationKindVal == static_cast<guint>(MetricPhase::OCCURRENCE))
426 : {
427 133 : if (gstWrapper.gstStructureHasField(msg, "duration-ns"))
428 : {
429 1 : RIALTO_LOG_WARN(RIALTO_COMPONENT_SERVER,
430 : "ValidateMediaPipelineMetric: OCCURRENCE observation-kind cannot have 'duration-ns' field");
431 1 : return GST_FLOW_ERROR;
432 : }
433 132 : if (gstWrapper.gstStructureHasField(msg, "count"))
434 : {
435 1 : RIALTO_LOG_WARN(RIALTO_COMPONENT_SERVER,
436 : "ValidateMediaPipelineMetric: OCCURRENCE observation-kind cannot have 'count' field");
437 1 : return GST_FLOW_ERROR;
438 : }
439 : }
440 :
441 : // Reject BUFFER_UNDERFLOW (metric=7) in EPISODE_RESOLVED (observation-kind=3) with count present
442 144 : if (metricVal == static_cast<guint>(MetricType::BUFFER_UNDERFLOW) &&
443 : observationKindVal == static_cast<guint>(MetricPhase::EPISODE_RESOLVED))
444 : {
445 2 : if (gstWrapper.gstStructureHasField(msg, "count"))
446 : {
447 2 : RIALTO_LOG_WARN(RIALTO_COMPONENT_SERVER, "ValidateMediaPipelineMetric: BUFFER_UNDERFLOW metric with "
448 : "EPISODE_RESOLVED observation-kind cannot have 'count' field");
449 2 : return GST_FLOW_ERROR;
450 : }
451 : }
452 :
453 142 : out.sourceId = 0;
454 142 : if (outSessionId)
455 : {
456 121 : *outSessionId = 0;
457 : }
458 : // Enrichment: Extract source element from GstMessage and map to session_id and source_id in a single lookup
459 142 : if (gstMessage && mapper)
460 : {
461 121 : GstObject *sourceObject = GST_MESSAGE_SRC(gstMessage);
462 121 : GstElement *sourceElement = gstWrapper.gstIsElement(sourceObject) ? GST_ELEMENT(sourceObject) : nullptr;
463 121 : if (sourceElement)
464 : {
465 120 : uint32_t enrichedSessionId = 0;
466 120 : uint32_t enrichedSourceId = 0;
467 :
468 120 : if (mapper->MapElement(sourceElement, enrichedSessionId, enrichedSourceId))
469 : {
470 117 : out.sourceId = static_cast<int32_t>(enrichedSourceId);
471 117 : if (outSessionId)
472 : {
473 117 : *outSessionId = static_cast<int32_t>(enrichedSessionId);
474 : }
475 : }
476 : else
477 : {
478 3 : RIALTO_LOG_DEBUG(RIALTO_COMPONENT_SERVER, "ValidateMediaPipelineMetric: failed to map element %p to session/source IDs, continuing with defaults",
479 : sourceElement);
480 : }
481 : }
482 : }
483 :
484 142 : return GST_FLOW_OK;
485 : }
486 :
487 : } // namespace firebolt::rialto::server
|