18 #include "applicationsink.h"
19 #include "../elementfactory.h"
20 #include <gst/app/gstappsink.h>
27 struct QTGSTREAMERUTILS_NO_EXPORT ApplicationSink::Priv
32 void lazyConstruct(ApplicationSink *
self);
33 void setCallbacks(ApplicationSink *
self);
35 inline GstAppSink *appSink()
37 return reinterpret_cast<GstAppSink*
>(
static_cast<GstElement*
>(m_appsink));
41 static void eos(GstAppSink *sink, gpointer user_data);
42 static GstFlowReturn new_preroll(GstAppSink *sink, gpointer user_data);
43 static GstFlowReturn new_buffer(GstAppSink *sink, gpointer user_data);
44 static GstFlowReturn new_buffer_list(GstAppSink *sink, gpointer user_data);
46 static void eos_noop(GstAppSink*, gpointer) {}
47 static GstFlowReturn new_preroll_noop(GstAppSink*, gpointer) {
return GST_FLOW_OK; }
48 static GstFlowReturn new_buffer_noop(GstAppSink*, gpointer) {
return GST_FLOW_OK; }
49 static GstFlowReturn new_buffer_list_noop(GstAppSink*, gpointer) {
return GST_FLOW_OK; }
52 void ApplicationSink::Priv::lazyConstruct(ApplicationSink *
self)
55 m_appsink = QGst::ElementFactory::make(
"appsink");
57 qWarning() <<
"Failed to construct appsink";
63 void ApplicationSink::Priv::setCallbacks(ApplicationSink *
self)
67 static GstAppSinkCallbacks callbacks = { &eos, &new_preroll,
68 &new_buffer, &new_buffer_list };
69 gst_app_sink_set_callbacks(appSink(), &callbacks,
self, NULL);
71 static GstAppSinkCallbacks callbacks = { &eos_noop, &new_preroll_noop,
72 &new_buffer_noop, &new_buffer_list_noop };
73 gst_app_sink_set_callbacks(appSink(), &callbacks, NULL, NULL);
78 void ApplicationSink::Priv::eos(GstAppSink* sink, gpointer user_data)
81 static_cast<ApplicationSink*
>(user_data)->eos();
84 GstFlowReturn ApplicationSink::Priv::new_preroll(GstAppSink* sink, gpointer user_data)
87 return static_cast<GstFlowReturn
>(
static_cast<ApplicationSink*
>(user_data)->newPreroll());
90 GstFlowReturn ApplicationSink::Priv::new_buffer(GstAppSink* sink, gpointer user_data)
93 return static_cast<GstFlowReturn
>(
static_cast<ApplicationSink*
>(user_data)->newBuffer());
96 GstFlowReturn ApplicationSink::Priv::new_buffer_list(GstAppSink* sink, gpointer user_data)
99 return static_cast<GstFlowReturn
>(
static_cast<ApplicationSink*
>(user_data)->newBufferList());
105 ApplicationSink::ApplicationSink()
110 ApplicationSink::~ApplicationSink()
112 d->setCallbacks(NULL);
118 d->lazyConstruct(const_cast<ApplicationSink*>(
this));
124 Q_ASSERT(QGlib::Type::fromInstance(appsink).isA(GST_TYPE_APP_SINK));
125 d->setCallbacks(NULL);
126 d->m_appsink = appsink;
127 d->setCallbacks(
this);
134 caps =
CapsPtr::wrap(gst_app_sink_get_caps(d->appSink()),
false);
139 void ApplicationSink::setCaps(
const CapsPtr & caps)
141 d->lazyConstruct(
this);
143 gst_app_sink_set_caps(d->appSink(), caps);
147 bool ApplicationSink::isEos()
const
149 return d->appSink() ? gst_app_sink_is_eos(d->appSink()) :
true;
152 uint ApplicationSink::maxBuffers()
const
154 return d->appSink() ? gst_app_sink_get_max_buffers(d->appSink()) : 0;
157 void ApplicationSink::setMaxBuffers(uint maxbuffers)
159 d->lazyConstruct(
this);
161 gst_app_sink_set_max_buffers(d->appSink(), maxbuffers);
165 bool ApplicationSink::dropEnabled()
const
167 return d->appSink() ? gst_app_sink_get_drop(d->appSink()) :
false;
170 void ApplicationSink::enableDrop(
bool enable)
172 d->lazyConstruct(
this);
174 gst_app_sink_set_drop(d->appSink(), enable);
205 void ApplicationSink::eos()
209 FlowReturn ApplicationSink::newPreroll()
214 FlowReturn ApplicationSink::newBuffer()
219 FlowReturn ApplicationSink::newBufferList()