Issue in seeking while streaming video files
hussain.nel
hussain6001 at gmail.com
Fri Sep 18 04:50:44 PDT 2015
Hi,
I am trying to stream video file using tcpserversink, when i try to do
seeking using gst_element_seek_simple, function is returning with TRUE
return value, but seeking is not happening.
Below is my sample code,
#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;
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);
flag = 0;
}
sample = gst_app_sink_pull_sample(GST_APP_SINK(object));
buffer = gst_sample_get_buffer(sample);
status = gst_app_src_push_buffer(GST_APP_SRC(appsrc), buffer);
return status;
}
void *seek_thread_func(void *ptr)
{
GstElement *pipeline = (GstElement *)ptr;
g_print("inside seek thread\n");
sleep(10);
gst_element_set_state(pipeline, GST_STATE_PAUSED);
if(gst_element_seek_simple(pipeline, GST_FORMAT_TIME,
GST_SEEK_FLAG_FLUSH, 240 * GST_SECOND) == TRUE)
printf("seek 2:00 done\n");
else
printf("seek failure\n");
gst_element_set_state(pipeline, GST_STATE_PLAYING);
}
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 *error;
gst_message_parse_error (msg, &error, &debug);
g_free (debug);
g_printerr ("Error: %s\n", error->message);
g_error_free (error);
g_main_loop_quit (loop);
break;
}
default:
break;
}
return TRUE;
}
int main(int argc, char **argv)
{
GMainLoop *loop;
GstElement *pipeline, *pipeline2;
GstElement *filesrc, *decodebin, *queue, *scale, *videorate, *appsink;
GstElement *videosink;
GstCaps *caps, *caps2, *caps3;
pthread_t seek_thread;
GstBus *bus;
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");
videosink = gst_element_factory_make("autovideosink", "video sink");
//
bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
gst_bus_add_watch (bus, bus_call, loop);
gst_object_unref (bus);
//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, 20, 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, 20, 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, videosink, 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(appsrc), "stream-type", 1, NULL);
g_object_set(G_OBJECT(videosink), "sync", FALSE, NULL);
gst_element_link(appsrc, videosink);
//
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;
}
Can somebody 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-tp4673710.html
Sent from the GStreamer-devel mailing list archive at Nabble.com.
More information about the gstreamer-devel
mailing list