Issue in seeking while streaming video files

hussain.nel hussain6001 at gmail.com
Fri Sep 18 05:00:34 PDT 2015


Hi,

I am trying to stream a video file using tcpserversink. When i try to seek
the pipeline it is not happening even though gst_element_seek_simple call is
returning without any error.

Please find the code below,

#include <stdio.h>
#include <gst/gst.h>
#include <gst/app/gstappsink.h>
#include <gst/app/gstappsrc.h>

void on_pad_added (GstElement* object,
		   GstPad* pad,
		   gpointer user_data)
{
	GstPad *sinkpad;
	GstElement *queue = (GstElement *) user_data;

	GstPadTemplate *template;
	GstCaps *new_pad_caps = NULL;
	GstStructure *new_pad_struct = NULL;
	const gchar *new_pad_type = NULL;

	template = gst_pad_get_pad_template(pad);

//	printf("template name: %s\n", GST_PAD_TEMPLATE_NAME_TEMPLATE(template));
	new_pad_caps = gst_pad_get_current_caps (pad);
	new_pad_struct = gst_caps_get_structure (new_pad_caps, 0);
	new_pad_type = gst_structure_get_name (new_pad_struct);

	printf("new pad type: %s\n", new_pad_type);


	if(g_str_has_prefix (new_pad_type, "video/x-raw")) {
		sinkpad = gst_element_get_static_pad (queue, "sink");
		gst_pad_link (pad, sinkpad);
		printf("video pad\n");
	}


//	gst_object_unref (sinkpad);

}

static GstElement *appsrc;

GstFlowReturn on_new_sample_from_sink (GstElement* object,
				       gpointer user_data)
{
	GstSample *sample;
	GstBuffer *buffer, *app_buffer;
	GstCaps *caps;
        GstPad *pad;
        gchar *str;
        GstFlowReturn status;
	static int flag = 1;


	if(flag == 1) {
		g_print("new sample\n");
		pad = gst_element_get_static_pad(object,"sink");
		caps = gst_pad_get_current_caps(pad);
		str = gst_caps_to_string(caps);
		g_print("caps : %s\n",str);
		gst_caps_unref(caps);
		flag = 0;
	}

	
	sample = gst_app_sink_pull_sample(GST_APP_SINK(object));

	buffer = gst_sample_get_buffer(sample);

	app_buffer = gst_buffer_copy(buffer);

	gst_sample_unref(sample);

	status = gst_app_src_push_buffer(GST_APP_SRC(appsrc), app_buffer);
		
	return status;
}


void *seek_thread_func(void *ptr)
{
        GstElement *pipeline = (GstElement *)ptr;

        sleep(20);
//	gst_element_set_state(pipeline, GST_STATE_PAUSED);
        if(gst_element_seek_simple(pipeline, GST_FORMAT_TIME,
GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_KEY_UNIT, 240 * GST_SECOND) == TRUE)
                printf("seek 4:00 done\n");
        else
                printf("seek failure\n");

//	gst_element_set_state(pipeline, GST_STATE_PLAYING);
}


int main(int argc, char **argv)
{

	GMainLoop *loop;
	GstElement *pipeline, *pipeline2;
	GstElement *filesrc, *decodebin, *queue, *scale, *videorate, *appsink;
	GstElement  *encoder, *rtppay, *gdppay, *tcpserversink;
	GstCaps *caps, *caps2, *caps3;
	pthread_t seek_thread;

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

//pipeline 1
	pipeline = gst_pipeline_new("video pipeline 1");
//
//pipeline 2
	pipeline2 = gst_pipeline_new("video pipeline 2");
//

//pipeline 1
	filesrc = gst_element_factory_make("filesrc", "file source");
	decodebin = gst_element_factory_make("decodebin", "decoder");
	queue = gst_element_factory_make("queue", "video queue");
	scale = gst_element_factory_make("videoscale", "video scale");
	videorate = gst_element_factory_make("videorate", "video rate");
	appsink = gst_element_factory_make("appsink", "application sink");
//

//pipeline 2
	appsrc = gst_element_factory_make("appsrc", "application source");
	encoder = gst_element_factory_make("x264enc", "h264 encoder");
	rtppay = gst_element_factory_make("rtph264pay", "rtp payloader");
	gdppay = gst_element_factory_make("gdppay", "gdppay");
	tcpserversink = gst_element_factory_make("tcpserversink", "tcp server
sink");
//

//pipeline 1
	caps = gst_caps_new_simple ("video/x-raw",
				    "format", G_TYPE_STRING, "I420",
				    "width", G_TYPE_INT, 600,
				    "height", G_TYPE_INT, 480,
				    NULL);

	caps2 = gst_caps_new_simple ("video/x-raw",
				     "framerate",GST_TYPE_FRACTION, 30, 1,
				    NULL);
//

//pipeline 2
	caps3 = gst_caps_new_simple ("video/x-raw",
				    "format", G_TYPE_STRING, "I420",
				    "width", G_TYPE_INT, 600,
				    "height", G_TYPE_INT, 480,
				    "framerate",GST_TYPE_FRACTION, 30, 1,
				    NULL);
//

//pipeline 1
	gst_bin_add_many(GST_BIN(pipeline), filesrc, decodebin, queue, scale,
videorate, appsink, NULL);
//

//pipeline 2
	gst_bin_add_many(GST_BIN(pipeline2), appsrc, encoder, rtppay, gdppay,
tcpserversink, NULL);
//

//pipeline 1
	g_object_set(G_OBJECT(filesrc), "location", argv[1], NULL);


	gst_element_link(filesrc, decodebin);
	g_signal_connect(decodebin, "pad-added", G_CALLBACK(on_pad_added), queue);
	gst_element_link(queue, scale);
	gst_element_link_filtered(scale, videorate, caps);
	gst_element_link_filtered(videorate, appsink, caps2);

	g_object_set(G_OBJECT(appsink), "emit-signals", TRUE, "sync", FALSE, NULL);
	g_signal_connect(appsink, "new-sample",
G_CALLBACK(on_new_sample_from_sink), NULL);
//

//pipeline 2
	gst_app_src_set_caps(GST_APP_SRC(appsrc), caps3);
	g_object_set(G_OBJECT(tcpserversink), "host", "localhost", "port", 5000,
/*"sync", FALSE,*/ NULL);
	
	gst_element_link_many(appsrc, encoder, rtppay, gdppay, tcpserversink,
NULL);
//
	gst_element_set_state(pipeline, GST_STATE_PLAYING);
	gst_element_set_state(pipeline2, GST_STATE_PLAYING);
	g_print("playing....\n");
	pthread_create(&seek_thread, NULL, seek_thread_func, (void *)pipeline);
	g_main_loop_run(loop);

	gst_element_set_state(pipeline, GST_STATE_NULL);
	gst_object_unref (GST_OBJECT (pipeline));
	g_main_loop_unref (loop);

	return 0;
}


Please help me to resolve this issue.

Regards,
Abdul




--
View this message in context: http://gstreamer-devel.966125.n4.nabble.com/Issue-in-seeking-while-streaming-video-files-tp4673712.html
Sent from the GStreamer-devel mailing list archive at Nabble.com.


More information about the gstreamer-devel mailing list