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