questions about appsink
hugh
zzdzwd at 163.com
Fri Oct 23 01:53:26 PDT 2015
There's a question about appsink,I use this pipe to
test:videotestsrc-->caps-->appsink, why the first buffer refcount is 1 more
time than others? Can it leak to memory leak? the result I got just as :
in:appsink probe buf_ref=2
out:appsink buf_ref=3
in:appsink probe buf_ref=2
out:appsink buf_ref=2
in:appsink probe buf_ref=2
out:appsink buf_ref=2
in:appsink probe buf_ref=2
out:appsink buf_ref=2
...
and the test code is :
#include<string.h>
#include<glib.h>
#include<gst/gst.h>
#include<gst/gstelement.h>
#include<gst/gstbus.h>
#include<gst/app/gstappsink.h>
GstElement *pl = NULL;
GstElement *source = NULL;
GstCaps *caps = NULL;
GstElement *sink = NULL;
GMainLoop *loop = NULL;
static gboolean app_sink_probe(GstPad *pad, GstBuffer *buf, gpointer udata)
{
GstMiniObject *tmp = GST_MINI_OBJECT(buf);
g_print("in:appsink probe buf_ref=%d\n", tmp->refcount);
return TRUE;
}
static GstFlowReturn appsink_new_buffer(GstAppSink *sink, gpointer
user_data)
{
GstBuffer *buffer = gst_app_sink_pull_buffer(sink);
GstMiniObject *tmp = GST_MINI_OBJECT(buffer);
g_print("out:appsink buf_ref=%d\n", tmp->refcount);
gst_buffer_unref(buffer);
return GST_FLOW_OK;
}
int main()
{
gst_init(NULL, NULL);
loop = g_main_loop_new(NULL, FALSE);
pl = gst_pipeline_new("test_pipe");
source = gst_element_factory_make("videotestsrc", "my_src");
caps = gst_caps_new_simple("video/x-raw-yuv",
"width", G_TYPE_INT, 640,
"height", G_TYPE_INT, 480,
"framerate", GST_TYPE_FRACTION, 25, 1,
NULL);
sink = gst_element_factory_make("appsink", "my_sink");
if(NULL == source && NULL == sink) {
g_print("create the element failed\n");
goto quit;
}
g_object_set(sink,
"emit-signals", FALSE,
"sync", FALSE,
"enable-last-buffer", FALSE,
"sync", FALSE,
NULL);
GstAppSinkCallbacks appsink_cbs;
memset(&appsink_cbs, 0, sizeof(GstAppSinkCallbacks));
appsink_cbs.new_buffer = appsink_new_buffer;
gst_app_sink_set_callbacks((GstAppSink*)sink, &appsink_cbs, NULL, NULL);
GstPad * app_src_pad = gst_element_get_static_pad(sink, "sink");
gst_pad_add_buffer_probe(app_src_pad, G_CALLBACK(app_sink_probe), NULL);
gst_object_unref(app_src_pad);
app_src_pad = NULL;
gst_bin_add_many(GST_BIN(pl), source, sink, NULL);
gst_element_link_filtered(source, sink, caps);
if(GST_STATE_CHANGE_FAILURE == gst_element_set_state(pl,
GST_STATE_PLAYING)) {
g_print("change pipe to playing failed\n");
goto quit;
}
g_main_loop_run(loop);
gst_element_set_state(pl, GST_STATE_NULL);
g_main_loop_quit(loop);
quit:
if(NULL != source) {
gst_object_unref(source);
source = NULL;
}
if(NULL != sink) {
gst_object_unref(sink);
sink = NULL;
}
if(NULL != caps) {
gst_caps_unref(caps);
caps = NULL;
}
if(NULL != loop) {
g_main_loop_unref(loop);
loop = NULL;
}
if(pl != NULL) {
gst_object_unref(pl);
pl = NULL;
}
return 0;
}
--
View this message in context: http://gstreamer-devel.966125.n4.nabble.com/questions-about-appsink-tp4674228.html
Sent from the GStreamer-devel mailing list archive at Nabble.com.
More information about the gstreamer-devel
mailing list