7#include <QtCore/qdebug.h>
23#define ST_SINK(s) QGstSubtitleSink *sink(reinterpret_cast<QGstSubtitleSink *>(s))
30 g_object_new(QGstSubtitleSink::get_type(),
nullptr));
33 qGstCheckedCast<GstElement>(gstSink),
34 QGstElement::NeedsRef,
41 static constexpr GTypeInfo info =
43 sizeof(QGstSubtitleSinkClass),
49 sizeof(QGstSubtitleSink),
56 static const GType type = []() {
57 const auto result = g_type_register_static(
58 GST_TYPE_BASE_SINK,
"QGstSubtitleSink", &info, GTypeFlags(0));
71 GstBaseSinkClass *base_sink_class =
reinterpret_cast<GstBaseSinkClass *>(g_class);
72 base_sink_class->render = QGstSubtitleSink::render;
73 base_sink_class->get_caps = QGstSubtitleSink::get_caps;
74 base_sink_class->set_caps = QGstSubtitleSink::set_caps;
75 base_sink_class->propose_allocation = QGstSubtitleSink::propose_allocation;
76 base_sink_class->wait_event = QGstSubtitleSink::wait_event;
78 GstElementClass *element_class =
reinterpret_cast<GstElementClass *>(g_class);
79 element_class->change_state = QGstSubtitleSink::change_state;
80 gst_element_class_set_metadata(element_class,
81 "Qt built-in subtitle sink",
83 "Qt default built-in subtitle sink",
86 GObjectClass *object_class =
reinterpret_cast<GObjectClass *>(g_class);
87 object_class->finalize = QGstSubtitleSink::finalize;
92 static GstStaticPadTemplate sink_pad_template =
93 GST_STATIC_PAD_TEMPLATE(
"sink", GST_PAD_SINK, GST_PAD_ALWAYS, GST_STATIC_CAPS(
"ANY"));
95 gst_element_class_add_pad_template(
96 GST_ELEMENT_CLASS(g_class), gst_static_pad_template_get(&sink_pad_template));
111 G_OBJECT_CLASS(gst_sink_parent_class)->finalize(object);
114GstStateChangeReturn
QGstSubtitleSink::change_state(GstElement *element, GstStateChange transition)
116 return GST_ELEMENT_CLASS(gst_sink_parent_class)->change_state(element, transition);
121 return gst_sink_parent_class->get_caps(base, filter);
126 qDebug() <<
"set_caps:" << caps;
127 return gst_sink_parent_class->set_caps(base, caps);
130gboolean
QGstSubtitleSink::propose_allocation(GstBaseSink *base, GstQuery *query)
132 return gst_sink_parent_class->propose_allocation(base, query);
135GstFlowReturn
QGstSubtitleSink::wait_event(GstBaseSink *base, GstEvent *event)
137 GstFlowReturn retval = gst_sink_parent_class->wait_event(base, event);
139 if (event->type == GST_EVENT_GAP) {
141 sink->observer->updateSubtitle(QString());
149 GstMemory *mem = gst_buffer_get_memory(buffer, 0);
152 if (gst_memory_map(mem, &info, GST_MAP_READ))
153 subtitle = QString::fromUtf8(
reinterpret_cast<
const char *>(info.data));
154 gst_memory_unmap(mem, &info);
156 sink->observer->updateSubtitle(subtitle);
static QGstElement createSink(QAbstractSubtitleObserver *observer)
GstBaseSinkClass parent_class
Combined button and popup list for selecting options.
GstBaseSinkClass * gst_sink_parent_class
thread_local QAbstractSubtitleObserver * gst_current_observer