18 #include "applicationsource.h"
19 #include "../elementfactory.h"
20 #include <gst/app/gstappsrc.h>
27 struct 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; }
50 void ApplicationSource::Priv::lazyConstruct(ApplicationSource *
self)
53 m_appsrc = QGst::ElementFactory::make(
"appsrc");
55 qWarning() <<
"Failed to construct appsrc";
61 void 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);
74 void ApplicationSource::Priv::need_data(GstAppSrc *src, guint length, gpointer user_data)
77 static_cast<ApplicationSource*
>(user_data)->needData(length);
80 void ApplicationSource::Priv::enough_data(GstAppSrc *src, gpointer user_data)
83 static_cast<ApplicationSource*
>(user_data)->enoughData();
86 gboolean ApplicationSource::Priv::seek_data(GstAppSrc *src, guint64 offset, gpointer user_data)
89 return static_cast<ApplicationSource*
>(user_data)->seekData(offset) ? TRUE : FALSE;
94 ApplicationSource::ApplicationSource()
99 ApplicationSource::~ApplicationSource()
101 d->setCallbacks(NULL);
107 d->lazyConstruct(const_cast<ApplicationSource*>(
this));
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);
130 d->lazyConstruct(
this);
132 gst_app_src_set_caps(d->appSrc(),
caps);
140 gst_app_src_get_latency(d->appSrc(), &ret, NULL);
149 gst_app_src_get_latency(d->appSrc(), NULL, &ret);
156 d->lazyConstruct(
this);
158 gst_app_src_set_latency(d->appSrc(), min, max);
164 return d->appSrc() ? gst_app_src_get_size(d->appSrc()) : -1;
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()))
178 : AppStreamTypeStream;
183 d->lazyConstruct(
this);
185 gst_app_src_set_stream_type(d->appSrc(),
static_cast<GstAppStreamType
>(type));
191 return d->appSrc() ? gst_app_src_get_max_bytes(d->appSrc()) : 0;
196 d->lazyConstruct(
this);
198 gst_app_src_set_max_bytes(d->appSrc(), max);
204 return d->m_appsrc ? d->m_appsrc->property(
"block").toBool() :
false;
209 d->lazyConstruct(
this);
211 d->m_appsrc->setProperty(
"block", enable);
217 return d->m_appsrc ? d->m_appsrc->property(
"is-live").toBool() :
false;
222 d->lazyConstruct(
this);
224 d->m_appsrc->setProperty(
"is-live", islive);
230 return d->m_appsrc ? d->m_appsrc->property(
"min-percent").toUInt() : 0;
235 d->lazyConstruct(
this);
237 d->m_appsrc->setProperty(
"min-percent", min);
241 Format ApplicationSource::format()
const
243 return d->m_appsrc ? d->m_appsrc->property(
"format").get<Format>() : FormatBytes;
246 void ApplicationSource::setFormat(Format f)
248 d->lazyConstruct(
this);
250 d->m_appsrc->setProperty(
"format", f);
257 return static_cast<FlowReturn
>(gst_app_src_push_buffer(d->appSrc(), gst_buffer_ref(buffer)));
266 return static_cast<FlowReturn
>(gst_app_src_end_of_stream(d->appSrc()));
static RefPointer< T > wrap(typename T::CType *nativePtr, bool increaseRef=true)
void enableBlock(bool enable)
void setMaxBytes(quint64 max)
void setElement(const ElementPtr &appsrc)
AppStreamType streamType() const
Wrappers for GStreamer classes.
void setMinPercent(uint min)
ElementPtr element() const
virtual void enoughData()
void setSize(qint64 size)
bool blockEnabled() const
void setLatency(quint64 min, quint64 max)
void setStreamType(AppStreamType type)
virtual void needData(uint length)
quint64 maxLatency() const
void setCaps(const CapsPtr &caps)
void setLive(bool islive)
quint64 minLatency() const
FlowReturn pushBuffer(const BufferPtr &buffer)
virtual bool seekData(quint64 offset)