Problem using Appsrc as a source to stream a computer generated video buffer

Chinnapong Angsuchotmetee achinapong at gmail.com
Thu Nov 24 23:57:25 PST 2011


Dear all,

I try to create a basic video application whose generate a raw frame
buffer, encoded it via x264enc and stream it via AutovideoSink. I
stucked on the error as followed:


(a.out:11729): GStreamer-CRITICAL **: gst_buffer_create_sub: assertion
`buffer->mini_object.refcount > 0' failed

(a.out:11729): GStreamer-CRITICAL **: gst_mini_object_unref: assertion
`mini_object->refcount > 0' failed
Segmentation fault


I have no idea what to do to solve this error, Some suggestion on
google recommend me to set the caps property of the appsrc source.
However, I already did that and the assertion is still remained.
Sourcecode is attached below. Any suggestion or explanation would be
highly appreciated.

Best regards,

Chinnapong


Here are the sourcecode:


#include <gst/gst.h>
#include <gst/app/gstappsrc.h>
#include <gdk-pixbuf/gdk-pixbuf.h>


GstElement *pipeline, *source, *decoder, *video_sink;
GstCaps * caps;

static gboolean bus_call(GstBus * bus,
			 GstMessage * msg,
			 gpointer data)
{
	GMainLoop *loop = (GMainLoop *) data;
	switch (GST_MESSAGE_TYPE (msg))
	{
		case GST_MESSAGE_EOS:
			g_print("End-of-stream\n");
			g_main_loop_quit(loop);
			break;
		case GST_MESSAGE_ERROR:
		{
			gchar * debug;
			GError *err;

			gst_message_parse_error (msg, &err, &debug);
			g_free (debug);

			g_print("Error: %s\n", err->message);
			g_main_loop_quit(loop);
			break;
		}
		default:
			break;
		return TRUE;
	}
}


 static void feed(	GstElement* object,
                        guint arg0,
                        gpointer src )
{
	
	GstBuffer *buffer;
        GdkPixbuf *pb;
	GstFlowReturn ret;
        gboolean ok = TRUE;
        buffer = gst_buffer_new();
        pb = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, 640, 480);
        gdk_pixbuf_fill(pb, 0xffffffff);

        GST_BUFFER_DATA (buffer) = gdk_pixbuf_get_pixels(pb);
        GST_BUFFER_SIZE (buffer) = 640*480*3*sizeof(guchar);

        GST_DEBUG ("feed buffer");
        g_signal_emit_by_name (src, "push-buffer", buffer, &ret);


	if (ret != GST_FLOW_OK) {
          GST_DEBUG ("some error");
        }

        gst_buffer_unref (buffer);

	
}

static void new_pad(	GstElement * element,
			GstPad	* pad,
			gpointer data )
{
	GstPad *sinkpad = NULL;
	GstElement *decoder = (GstElement *) data;
	sinkpad = gst_element_get_static_pad(decoder,"vsink");
	gst_pad_link(pad,sinkpad);
	gst_object_unref (sinkpad);
}

int main(int argc, char * argv[])
{
	GMainLoop * loop;
	GstBus * bus;

	gst_init(&argc, &argv);
	loop = g_main_loop_new(NULL, FALSE);

	
	pipeline = gst_pipeline_new("test-push-buffer");
	source = gst_element_factory_make("appsrc","source");
	decoder = gst_element_factory_make("x264enc","decoder");
	caps = gst_caps_new_simple ("video/x-raw-rgb",
		    "bpp",G_TYPE_INT,24,
		    "depth",G_TYPE_INT,24,
		    "width", G_TYPE_INT, 640,
   		    "height", G_TYPE_INT, 480,
		 NULL);

	video_sink = gst_element_factory_make("autovideosink","vsink");
	if(!pipeline || !source || ! video_sink || ! decoder)
	{
		g_print("Element creation Error\n");
		return -1;
	}

	gst_app_src_set_caps((GstAppSrc*)source, caps);
	g_signal_connect (source, "need-data", G_CALLBACK (feed), source);

	g_object_set(G_OBJECT(source), "caps", caps, NULL);		
	bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
	gst_bus_add_watch (bus, bus_call, loop);
	gst_object_unref (bus);


	gst_bin_add_many(GST_BIN (pipeline), source, decoder, video_sink, NULL);
	gst_element_link_many (source, decoder, video_sink);


	g_signal_connect (decoder, "pad-added", G_CALLBACK(new_pad), NULL);

	g_print("Setting to Playing\n");
	gst_element_set_state(pipeline, GST_STATE_PLAYING);
	g_print("Running\n");
	g_main_loop_run(loop);


	g_print("Stop playback\n");
	gst_element_set_state(pipeline, GST_STATE_NULL);
	g_print("Delete Pipeline\n");
	gst_object_unref (GST_OBJECT (pipeline));

	return 0;


}


More information about the gstreamer-devel mailing list