18#include "applicationsource.h"
19#include "../elementfactory.h"
20#include <gst/app/gstappsrc.h>
27struct QTGSTREAMERUTILS_NO_EXPORT ApplicationSource::Priv
32 void lazyConstruct(ApplicationSource *self);
33 void setCallbacks(ApplicationSource *self);
35 inline GstAppSrc *appSrc()
37 return reinterpret_cast<GstAppSrc*
>(
static_cast<GstElement*
>(m_appsrc));
41 static void need_data(GstAppSrc *src, guint length, gpointer user_data);
42 static void enough_data(GstAppSrc *src, gpointer user_data);
43 static gboolean seek_data(GstAppSrc *src, guint64 offset, gpointer user_data);
45 static void need_data_noop(GstAppSrc*, guint, gpointer) {}
46 static void enough_data_noop(GstAppSrc*, gpointer) {}
47 static gboolean seek_data_noop(GstAppSrc*, guint64, gpointer) {
return FALSE; }
50void ApplicationSource::Priv::lazyConstruct(ApplicationSource *self)
53 m_appsrc = QGst::ElementFactory::make(
"appsrc");
55 qWarning() <<
"Failed to construct appsrc";
61void ApplicationSource::Priv::setCallbacks(ApplicationSource *self)
65 static GstAppSrcCallbacks callbacks = { &need_data, &enough_data, &seek_data, NULL };
66 gst_app_src_set_callbacks(appSrc(), &callbacks, self, NULL);
68 static GstAppSrcCallbacks callbacks = { &need_data_noop, &enough_data_noop, &seek_data_noop, NULL };
69 gst_app_src_set_callbacks(appSrc(), &callbacks, NULL, NULL);
74void ApplicationSource::Priv::need_data(GstAppSrc *src, guint length, gpointer user_data)
77 static_cast<ApplicationSource*
>(user_data)->needData(length);
80void ApplicationSource::Priv::enough_data(GstAppSrc *src, gpointer user_data)
83 static_cast<ApplicationSource*
>(user_data)->enoughData();
86gboolean ApplicationSource::Priv::seek_data(GstAppSrc *src, guint64 offset, gpointer user_data)
89 return static_cast<ApplicationSource*
>(user_data)->seekData(offset) ? TRUE : FALSE;
94ApplicationSource::ApplicationSource()
99ApplicationSource::~ApplicationSource()
101 d->setCallbacks(NULL);
113 Q_ASSERT(QGlib::Type::fromInstance(appsrc).isA(GST_TYPE_APP_SRC));
114 d->setCallbacks(NULL);
115 d->m_appsrc = appsrc;
116 d->setCallbacks(
this);
123 c = CapsPtr::wrap(gst_app_src_get_caps(d->appSrc()),
false);
128void ApplicationSource::setCaps(
const CapsPtr & caps)
130 d->lazyConstruct(
this);
132 gst_app_src_set_caps(d->appSrc(), caps);
136quint64 ApplicationSource::minLatency()
const
140 gst_app_src_get_latency(d->appSrc(), &ret, NULL);
145quint64 ApplicationSource::maxLatency()
const
149 gst_app_src_get_latency(d->appSrc(), NULL, &ret);
154void ApplicationSource::setLatency(quint64 min, quint64 max)
156 d->lazyConstruct(
this);
158 gst_app_src_set_latency(d->appSrc(), min, max);
162qint64 ApplicationSource::size()
const
164 return d->appSrc() ? gst_app_src_get_size(d->appSrc()) : -1;
167void ApplicationSource::setSize(qint64 size)
169 d->lazyConstruct(
this);
171 gst_app_src_set_size(d->appSrc(), size);
177 return d->appSrc() ?
static_cast<AppStreamType>(gst_app_src_get_stream_type(d->appSrc()))
183 d->lazyConstruct(
this);
185 gst_app_src_set_stream_type(d->appSrc(),
static_cast<GstAppStreamType
>(type));
189quint64 ApplicationSource::maxBytes()
const
191 return d->appSrc() ? gst_app_src_get_max_bytes(d->appSrc()) : 0;
194void ApplicationSource::setMaxBytes(quint64 max)
196 d->lazyConstruct(
this);
198 gst_app_src_set_max_bytes(d->appSrc(), max);
202bool ApplicationSource::blockEnabled()
const
204 return d->m_appsrc ? d->m_appsrc->property(
"block").toBool() :
false;
207void ApplicationSource::enableBlock(
bool enable)
209 d->lazyConstruct(
this);
211 d->m_appsrc->setProperty(
"block", enable);
215bool ApplicationSource::isLive()
const
217 return d->m_appsrc ? d->m_appsrc->property(
"is-live").toBool() :
false;
220void ApplicationSource::setLive(
bool islive)
222 d->lazyConstruct(
this);
224 d->m_appsrc->setProperty(
"is-live", islive);
228uint ApplicationSource::minPercent()
const
230 return d->m_appsrc ? d->m_appsrc->property(
"min-percent").toUInt() : 0;
233void ApplicationSource::setMinPercent(uint min)
235 d->lazyConstruct(
this);
237 d->m_appsrc->setProperty(
"min-percent", min);
241Format ApplicationSource::format()
const
243 return d->m_appsrc ? d->m_appsrc->property(
"format").get<Format>() : FormatBytes;
246void ApplicationSource::setFormat(Format f)
248 d->lazyConstruct(
this);
250 d->m_appsrc->setProperty(
"format", f);
254FlowReturn ApplicationSource::pushBuffer(
const BufferPtr & buffer)
257 return static_cast<FlowReturn
>(gst_app_src_push_buffer(d->appSrc(), gst_buffer_ref(buffer)));
263FlowReturn ApplicationSource::endOfStream()
266 return static_cast<FlowReturn
>(gst_app_src_end_of_stream(d->appSrc()));
272void ApplicationSource::needData(uint length)
277void ApplicationSource::enoughData()
281bool ApplicationSource::seekData(quint64 offset)
Helper class for using a GstAppSrc.
Wrappers for GStreamer classes.