From: <gk...@ke...> - 2011-01-18 18:12:53
|
Module: qt-gstreamer Branch: master Commit: b6a5c5cad363cb78db28c683392784a988e4dcbc URL: http://cgit.freedesktop.org/gstreamer/qt-gstreamer/commit/?id=b6a5c5cad363cb78db28c683392784a988e4dcbc Author: George Kiagiadakis <geo...@co...> Date: Mon Jan 17 18:30:52 2011 +0200 Properly detach the appsrc/appsink from our callbacks + don't allow setting a null appsrc/appsink. --- src/QGst/Utils/applicationsink.cpp | 20 +++++++++++++++++--- src/QGst/Utils/applicationsource.cpp | 17 ++++++++++++++--- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/QGst/Utils/applicationsink.cpp b/src/QGst/Utils/applicationsink.cpp index 8fc232f..ed2e975 100644 --- a/src/QGst/Utils/applicationsink.cpp +++ b/src/QGst/Utils/applicationsink.cpp @@ -42,6 +42,11 @@ private: static GstFlowReturn new_preroll(GstAppSink *sink, gpointer user_data); static GstFlowReturn new_buffer(GstAppSink *sink, gpointer user_data); static GstFlowReturn new_buffer_list(GstAppSink *sink, gpointer user_data); + + static void eos_noop(GstAppSink*, gpointer) {} + static GstFlowReturn new_preroll_noop(GstAppSink*, gpointer) { return GST_FLOW_OK; } + static GstFlowReturn new_buffer_noop(GstAppSink*, gpointer) { return GST_FLOW_OK; } + static GstFlowReturn new_buffer_list_noop(GstAppSink*, gpointer) { return GST_FLOW_OK; } }; void ApplicationSink::Priv::lazyConstruct(ApplicationSink *self) @@ -58,8 +63,15 @@ void ApplicationSink::Priv::lazyConstruct(ApplicationSink *self) void ApplicationSink::Priv::setCallbacks(ApplicationSink *self) { if (m_appsink) { - static GstAppSinkCallbacks callbacks = { &eos, &new_preroll, &new_buffer, &new_buffer_list }; - gst_app_sink_set_callbacks(appSink(), &callbacks, self, NULL); + if (self) { + static GstAppSinkCallbacks callbacks = { &eos, &new_preroll, + &new_buffer, &new_buffer_list }; + gst_app_sink_set_callbacks(appSink(), &callbacks, self, NULL); + } else { + static GstAppSinkCallbacks callbacks = { &eos_noop, &new_preroll_noop, + &new_buffer_noop, &new_buffer_list_noop }; + gst_app_sink_set_callbacks(appSink(), &callbacks, NULL, NULL); + } } } @@ -97,6 +109,7 @@ ApplicationSink::ApplicationSink() ApplicationSink::~ApplicationSink() { + d->setCallbacks(NULL); //remove the callbacks from the sink delete d; } @@ -108,7 +121,8 @@ ElementPtr ApplicationSink::element() const void ApplicationSink::setElement(const ElementPtr & appsink) { - Q_ASSERT(!appsink || QGlib::Type::fromInstance(appsink).isA(GST_TYPE_APP_SINK)); + Q_ASSERT(QGlib::Type::fromInstance(appsink).isA(GST_TYPE_APP_SINK)); + d->setCallbacks(NULL); //remove the callbacks from the previous sink d->m_appsink = appsink; d->setCallbacks(this); } diff --git a/src/QGst/Utils/applicationsource.cpp b/src/QGst/Utils/applicationsource.cpp index 6c3e9e4..fd02f0d 100644 --- a/src/QGst/Utils/applicationsource.cpp +++ b/src/QGst/Utils/applicationsource.cpp @@ -41,6 +41,10 @@ private: static void need_data(GstAppSrc *src, guint length, gpointer user_data); static void enough_data(GstAppSrc *src, gpointer user_data); static gboolean seek_data(GstAppSrc *src, guint64 offset, gpointer user_data); + + static void need_data_noop(GstAppSrc*, guint, gpointer) {} + static void enough_data_noop(GstAppSrc*, gpointer) {} + static gboolean seek_data_noop(GstAppSrc*, guint64, gpointer) { return FALSE; } }; void ApplicationSource::Priv::lazyConstruct(ApplicationSource *self) @@ -57,8 +61,13 @@ void ApplicationSource::Priv::lazyConstruct(ApplicationSource *self) void ApplicationSource::Priv::setCallbacks(ApplicationSource *self) { if (m_appsrc) { - static GstAppSrcCallbacks callbacks = { &need_data, &enough_data, &seek_data }; - gst_app_src_set_callbacks(appSrc(), &callbacks, self, NULL); + if (self) { + static GstAppSrcCallbacks callbacks = { &need_data, &enough_data, &seek_data }; + gst_app_src_set_callbacks(appSrc(), &callbacks, self, NULL); + } else { + static GstAppSrcCallbacks callbacks = { &need_data_noop, &enough_data_noop, &seek_data_noop }; + gst_app_src_set_callbacks(appSrc(), &callbacks, NULL, NULL); + } } } @@ -89,6 +98,7 @@ ApplicationSource::ApplicationSource() ApplicationSource::~ApplicationSource() { + d->setCallbacks(NULL); //remove the callbacks from the source delete d; } @@ -100,7 +110,8 @@ ElementPtr ApplicationSource::element() const void ApplicationSource::setElement(const ElementPtr & appsrc) { - Q_ASSERT(!appsrc || QGlib::Type::fromInstance(appsrc).isA(GST_TYPE_APP_SRC)); + Q_ASSERT(QGlib::Type::fromInstance(appsrc).isA(GST_TYPE_APP_SRC)); + d->setCallbacks(NULL); //remove the callbacks from the previous source d->m_appsrc = appsrc; d->setCallbacks(this); } |