4#include <gst/video/video-event.h>
6#include <QtCore/QByteArray>
8#include <QtCore/QLatin1String>
9#include <QtCore/QString>
20void removeAndStop(
GstElement* element,
bool flush)
32 GST_STATE_LOCK(parent.get());
33 (void) gst_bin_remove(GST_BIN(parent.get()), element);
35 (void) gst_element_foreach_sink_pad(
37 [](
GstElement* , GstPad* pad, gpointer ) -> gboolean {
38 (void) gst_pad_send_event(pad, gst_event_new_flush_start());
45 (void) gst_element_set_state(element, GST_STATE_NULL);
46 GST_STATE_UNLOCK(parent.get());
53 removeAndStop(element,
false);
58 removeAndStop(element,
true);
66#if GST_CHECK_VERSION(1, 28, 0)
68 gst_object_call_async(
69 GST_OBJECT_CAST(element), [](GstObject*
object, gpointer ) {
disposeChild(GST_ELEMENT_CAST(
object)); },
72 gst_element_call_async(
79 if (!element || g_object_is_floating(element.get())) {
80 qCCritical(GStreamerHelpersLog) <<
"Missing or floating element for" << what;
84 const bool ok = gst_bin_add(GST_BIN(bin), added);
86 gst_object_unref(added);
88 qCWarning(GStreamerHelpersLog) <<
"gst_bin_add() failed for" << what;
99 return QFile::encodeName(file);
108 (void) gst_pad_push_event(sinkPad, gst_video_event_new_upstream_force_key_unit(GST_CLOCK_TIME_NONE, TRUE, 0));
121 gst_event_unref(event);
124 auto*
const pending =
new PendingEvent{.pad =
adoptPad(GST_PAD(gst_object_ref(pad))), .event =
adoptEvent(event)};
125#if GST_CHECK_VERSION(1, 28, 0)
127 gst_object_call_async(
128 GST_OBJECT_CAST(parent.get()),
129 [](GstObject* , gpointer data) {
130 const std::unique_ptr<PendingEvent> owned(static_cast<PendingEvent*>(data));
131 (void) gst_pad_send_event(owned->pad.get(), owned->event.release());
135 gst_element_call_async(
138 auto* const queued = static_cast<PendingEvent*>(data);
139 (void) gst_pad_send_event(queued->pad.get(), queued->event.release());
141 pending, [](gpointer data) { delete static_cast<PendingEvent*>(data); });
147 GstPad* first =
nullptr;
149 (void) gst_element_foreach_src_pad(
151 [](
GstElement* , GstPad* pad, gpointer userData) -> gboolean {
152 *
static_cast<GstPad**
>(userData) = GST_PAD(gst_object_ref(pad));
161 GstElementFactory*
const factory =
162 (
object && GST_IS_ELEMENT(
object)) ? gst_element_get_factory(GST_ELEMENT_CAST(
object)) :
nullptr;
163 return factory ? GST_OBJECT_NAME(factory) :
nullptr;
169 const gulong blockId = gst_pad_add_probe(
170 pad, GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM,
171 [](GstPad* , GstPadProbeInfo* , gpointer ) {
return GST_PAD_PROBE_OK; },
nullptr,
173 return [blockId, heldPad =
shareObject(pad), link = std::move(link)]() {
175 gst_pad_remove_probe(heldPad.get(), blockId);
179void forEachPlugin(GstRegistry* registry,
const std::function<
void(GstPlugin*)>& visitor)
181 if (!registry || !visitor)
183 GList* plugins = gst_registry_get_plugin_list(registry);
184 for (GList* node = plugins; node !=
nullptr; node = node->next) {
185 GstPlugin* plugin =
static_cast<GstPlugin*
>(node->data);
189 gst_plugin_list_free(plugins);
struct _GstElement GstElement
#define QGC_LOGGING_CATEGORY(name, categoryStr)
void disposeChild(GstElement *element)
void disposeChildAsync(GstElement *element)
GstPadPtr firstSrcPad(GstElement *element)
element's first src pad, or null when it has none (yet).
std::unique_ptr< GstObject, GstObjectDeleter > GstObjectPtr
std::unique_ptr< GstEvent, GstEventDeleter > GstEventPtr
std::function< void()> holdPadUntilLinked(GstPad *pad, std::function< void(GstPad *pad)> link)
GstEventPtr adoptEvent(GstEvent *event) noexcept
void forEachPlugin(GstRegistry *registry, const std::function< void(GstPlugin *)> &visitor)
const char * factoryNameOf(GstObject *object)
The name of the factory that made object ("rtph264depay"); null when it is no element or has no facto...
GstElement * addToBin(GstElement *bin, GstElementPtr element, const char *what)
void sendEventAsync(GstPad *pad, GstEvent *event)
std::shared_ptr< T > shareObject(T *object)
A copyable owner of a new ref on object, for tasks that must be copyable (std::function).
std::unique_ptr< GstElement, GstObjectDeleter > GstElementPtr
std::unique_ptr< GstPad, GstObjectDeleter > GstPadPtr
GstObjectPtr adoptObject(GstObject *object) noexcept
GstElementPtr adoptElement(GstElement *element) noexcept
QByteArray glibFileName(const QString &file)
void flushAndDisposeChild(GstElement *element)
GstPadPtr adoptPad(GstPad *pad) noexcept
void requestKeyframe(GstPad *sinkPad)