1// Copyright (C) 2016 Jolla Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include <common/qgstreamerbufferprobe_p.h>
5
6#include <common/qgst_p.h>
7
8QT_BEGIN_NAMESPACE
9
10QGstreamerBufferProbe::QGstreamerBufferProbe(Flags flags)
11 : m_flags(flags)
12{
13}
14
15QGstreamerBufferProbe::~QGstreamerBufferProbe() = default;
16
17void QGstreamerBufferProbe::addProbeToPad(GstPad *pad, bool downstream)
18{
19 QGstCaps caps{
20 gst_pad_get_current_caps(pad),
21 QGstCaps::HasRef,
22 };
23
24 if (caps)
25 probeCaps(caps: caps.caps());
26
27 if (m_flags & ProbeCaps) {
28 m_capsProbeId = gst_pad_add_probe(
29 pad,
30 mask: downstream
31 ? GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM
32 : GST_PAD_PROBE_TYPE_EVENT_UPSTREAM,
33 callback: capsProbe,
34 user_data: this,
35 destroy_data: nullptr);
36 }
37 if (m_flags & ProbeBuffers) {
38 m_bufferProbeId = gst_pad_add_probe(
39 pad, mask: GST_PAD_PROBE_TYPE_BUFFER, callback: bufferProbe, user_data: this, destroy_data: nullptr);
40 }
41}
42
43void QGstreamerBufferProbe::removeProbeFromPad(GstPad *pad)
44{
45 if (m_capsProbeId != -1) {
46 gst_pad_remove_probe(pad, id: m_capsProbeId);
47 m_capsProbeId = -1;
48 }
49 if (m_bufferProbeId != -1) {
50 gst_pad_remove_probe(pad, id: m_bufferProbeId);
51 m_bufferProbeId = -1;
52 }
53}
54
55void QGstreamerBufferProbe::probeCaps(GstCaps *)
56{
57}
58
59bool QGstreamerBufferProbe::probeBuffer(GstBuffer *)
60{
61 return true;
62}
63
64GstPadProbeReturn QGstreamerBufferProbe::capsProbe(GstPad *, GstPadProbeInfo *info, gpointer user_data)
65{
66 QGstreamerBufferProbe * const control = static_cast<QGstreamerBufferProbe *>(user_data);
67
68 if (GstEvent * const event = gst_pad_probe_info_get_event(info)) {
69 if (GST_EVENT_TYPE(event) == GST_EVENT_CAPS) {
70 GstCaps *caps;
71 gst_event_parse_caps(event, caps: &caps);
72
73 control->probeCaps(caps);
74 }
75 }
76 return GST_PAD_PROBE_OK;
77}
78
79GstPadProbeReturn QGstreamerBufferProbe::bufferProbe(
80 GstPad *, GstPadProbeInfo *info, gpointer user_data)
81{
82 QGstreamerBufferProbe * const control = static_cast<QGstreamerBufferProbe *>(user_data);
83 if (GstBuffer * const buffer = gst_pad_probe_info_get_buffer(info))
84 return control->probeBuffer(buffer) ? GST_PAD_PROBE_OK : GST_PAD_PROBE_DROP;
85 return GST_PAD_PROBE_OK;
86}
87
88QT_END_NAMESPACE
89

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of qtmultimedia/src/plugins/multimedia/gstreamer/common/qgstreamerbufferprobe.cpp