Seems like set callbacks unsuccessful
Erickson.LU
ericksonlushan at gmail.com
Wed Apr 18 14:17:45 UTC 2018
I put the main module in there, i have two pipeline, one is appsink, another
one is for appsrc.
The problem is when i use gst_parse_launch construct the pipeline the
program runs OK.
But when i use ----
pipeline_sink = gst_pipeline_new(NULL);
gst_bin_add_many(GST_BIN(pipeline_sink), v4l2src,
filter1,nvvidconv_1,filter2, nvvidconv_2,filter3,appsink, NULL);
gst_element_link_many (v4l2src, filter1,nvvidconv_1,filter2,
nvvidconv_2,filter3,appsink, NULL);gst_caps_unref (number1);
......something like that ....
When i build and run the program the camera is on, there is a led beside
it.So, i think the pipeline is working.But, the appsink's callbacks seems
never be called. I don't know why. The pipeline_sink changed to
GST_STATE_ASYNC when i called
gst_element_set_state(pipeline_sink,GST_STATE_PLAYING);
I followed
https://gstreamer.freedesktop.org/documentation/application-development/advanced/pipeline-manipulation.html
<https://gstreamer.freedesktop.org/documentation/application-development/advanced/pipeline-manipulation.html>
and checked so many times but never found the problems.
#define SINK "v4l2src ! video/x-raw,format=(string)YV12, width=(int)640,
height=(int)480 ! videoconvert ! video/x-raw, format=I420, width=(int)640,
height=(int)480 ! videoconvert ! video/x-raw,format=(string)BGR,
width=(int)640, height=(int)480 ! appsink name=APP_SINK
caps=video/x-raw,format=BGR,width=640,height=480,pixel-aspect-ratio=1/1"
#define SRC "appsrc name=APP_SRC ! x264enc tune=zerolatency byte-stream=true
threads=4 ! rtph264pay mtu=60000 ! udpsink host=127.0.0.1 port=3221
sync=false"
static GstElement *appsrc;
static GstElement *appsink;
int
main (int argc, char *argv[])
{
boost::thread g_main_loop_thread;
GstAppSinkCallbacks appsinkCallbacks;
GstAppSrcCallbacks appsrcCallbacks;
GstElement *conv, *encoder, *rtppay, *udpsink;
GstElement *pipeline_sink, *sink,*pipeline_src,*src ;
gint width, height;
GstSample *sample;
gchar *descr,*src_pip_str;
GError *error = NULL;
GstStateChangeReturn ret;
gboolean res;
GstMapInfo map;
gst_init (&argc, &argv);
descr = g_strdup_printf(SINK);
g_print(descr);
pipeline_sink = gst_pipeline_new(NULL);
// pipeline_sink = gst_parse_launch (descr, &error);
GstElement *filter1 = gst_element_factory_make ("capsfilter", NULL);
g_assert (filter1 != NULL); /* should always exist */
GstElement *filter2 = gst_element_factory_make ("capsfilter", NULL);
g_assert (filter2 != NULL); /* should always exist */
GstElement *filter3 = gst_element_factory_make ("capsfilter", NULL);
g_assert (filter3 != NULL); /* should always exist */
GstElement *v4l2src,*nvvidconv_1,*nvvidconv_2;
v4l2src = gst_element_factory_make("v4l2src", NULL);
g_object_set (G_OBJECT (v4l2src), "device", "/dev/video0", NULL);
nvvidconv_1 = gst_element_factory_make("videoconvert", NULL);
nvvidconv_2 = gst_element_factory_make("videoconvert", NULL);
appsink = gst_element_factory_make("appsink", "APP_SINK");
g_object_set (G_OBJECT (appsink), "name","APP_SINK","caps",
gst_caps_new_simple("video/x-raw","format",G_TYPE_STRING,"BGR","width",G_TYPE_INT,"640","height",G_TYPE_INT,"480","pixel-aspect-ratio",GST_TYPE_FRACTION,1,1,NULL),
NULL);
GstCaps *number1 =
gst_caps_new_simple("video/x-raw","format",G_TYPE_STRING,"YV12","width",G_TYPE_INT,"640","height",G_TYPE_INT,"480",NULL);
GstCaps *number2 =
gst_caps_new_simple("video/x-raw","format",G_TYPE_STRING,"I420","width",G_TYPE_INT,"640","height",G_TYPE_INT,"480",NULL);
GstCaps *number3 =
gst_caps_new_simple("video/x-raw","format",G_TYPE_STRING,"BGR","width",G_TYPE_INT,"640","height",G_TYPE_INT,"480",NULL);
g_object_set (G_OBJECT (filter1), "caps", number1, NULL);
g_object_set (G_OBJECT (filter2), "caps", number2, NULL);
g_object_set (G_OBJECT (filter3), "caps", number3, NULL);
// gst_element_link_filtered(v4l2src, nvvidconv_1, number1);
// gst_element_link_filtered(nvvidconv_1, nvvidconv_2, number2);
// gst_element_link_filtered(nvvidconv_2, appsink, number3);
gst_bin_add_many(GST_BIN(pipeline_sink), v4l2src,
filter1,nvvidconv_1,filter2, nvvidconv_2,filter3,appsink, NULL);
gst_element_link_many (v4l2src, filter1,nvvidconv_1,filter2,
nvvidconv_2,filter3,appsink, NULL);gst_caps_unref (number1);
GstStateChangeReturn ret_sink_set =
gst_element_set_state(pipeline_sink,GST_STATE_PLAYING);
if (ret_sink_set == GST_STATE_CHANGE_FAILURE) {
g_printerr("Unable to set the pipeline_sink to the playing state");
gst_object_unref(pipeline_sink);
return false;
}
gst_caps_unref (number1);
gst_caps_unref (number2);
gst_caps_unref (number3);
if (error != NULL) {
g_print ("could not construct pipeline_sink: %s\n", error->message);
g_clear_error (&error);
exit (-1);
}
// pipeline_src = gst_parse_launch (src_pip_str, &error);
pipeline_src = gst_pipeline_new("pipeline_src");
appsrc = gst_element_factory_make ("appsrc", "APP_SRC");
conv = gst_element_factory_make ("videoconvert", "conv");
encoder = gst_element_factory_make ("x264enc", "encoder");
rtppay = gst_element_factory_make ("rtph264pay", "rtppay");
udpsink = gst_element_factory_make ("udpsink", "sink");
g_object_set( encoder, "tune", 4,
"threads", 4,
"key-int-max", 15,
"intra-refresh", true,
"speed-preset", 5,
NULL);
g_object_set( udpsink, "host", "127.0.0.1", NULL );
g_object_set( udpsink, "port", 3221, NULL );
g_object_set( udpsink, "sync", false, NULL );
g_object_set( udpsink, "async", false, NULL );
if (error != NULL) {
g_print ("could not construct pipeline_sink: %s\n", error->message);
g_clear_error (&error);
exit (-1);
}
g_object_set (G_OBJECT (appsrc), "caps",
gst_caps_new_simple ("video/x-raw",
"format", G_TYPE_STRING, "BGR",
"width", G_TYPE_INT, 640,
"height", G_TYPE_INT, 480,
"framerate", GST_TYPE_FRACTION, 30,
1,
NULL), NULL);
appsrcCallbacks.need_data = NeedDataCallback;
appsrcCallbacks.enough_data = EnoughDataCallback;
appsrcCallbacks.seek_data = SeekDataCallback;
gst_app_src_set_callbacks(GST_APP_SRC(appsrc), &appsrcCallbacks, NULL,
(GDestroyNotify)DestroyCallback_src);
gst_app_src_set_max_bytes(GST_APP_SRC(appsrc), 0);
gst_bin_add_many (GST_BIN (pipeline_src), appsrc, conv, encoder, rtppay,
udpsink, NULL);
gst_element_link_many (appsrc, conv, encoder, rtppay, udpsink , NULL);
/* setup appsrc */
g_object_set (G_OBJECT (appsrc),
"stream-type", 0,
"format", GST_FORMAT_TIME, NULL);
GstStateChangeReturn ret_src_set =
gst_element_set_state(pipeline_src,GST_STATE_PLAYING);
if (ret_src_set == GST_STATE_CHANGE_FAILURE) {
g_printerr("Unable to set the pipeline_sink to the playing state");
gst_object_unref(pipeline_src);
return false;
}
appsink = gst_bin_get_by_name(GST_BIN(pipeline_sink), "APP_SINK");
appsinkCallbacks.new_preroll = &NewPrerollCallback;
appsinkCallbacks.new_sample = &NewSampleCallback;
appsinkCallbacks.eos = &EndOfStreamCallback;
gst_app_sink_set_drop(GST_APP_SINK(appsink), true);
gst_app_sink_set_max_buffers(GST_APP_SINK(appsink), 1);
gst_app_sink_set_callbacks(GST_APP_SINK(appsink), &appsinkCallbacks,
NULL, (GDestroyNotify)DestroyCallback);
g_main_loop_thread = boost::thread(&Process_frame);
g_main_loop_thread.join();
gst_element_set_state (pipeline_sink, GST_STATE_NULL);
gst_object_unref (sink);
gst_object_unref (pipeline_sink);
exit (0);
}
--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/
More information about the gstreamer-devel
mailing list