Seems like set callbacks unsuccessful

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Seems like set callbacks unsuccessful

Erickson.LU
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/
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

AW: Seems like set callbacks unsuccessful

Thornton, Keith
What do your NeedDataCallback and NewSampleCallback look like. Are they identical to that described in
advanced/pipeline-manipulation.html ?

-----Urspr√ľngliche Nachricht-----
Von: gstreamer-devel [mailto:[hidden email]] Im Auftrag von Erickson.LU
Gesendet: Mittwoch, 18. April 2018 16:18
An: [hidden email]
Betreff: Seems like set callbacks unsuccessful

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/
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: AW: Seems like set callbacks unsuccessful

Erickson.LU
Appreciate your reply, in the official they use signal but i used callback.
Of course, they are different. But, the problem is the callback function has
never been called. I use breakpoint and g_print checked that.
And when i use *pipeline_sink = gst_parse_launch (descr, &error); * They all
went well.

And there is *NewSampleCallback* and *NewPrerollCallback*.
GstFlowReturn NewSampleCallback(GstAppSink* appsink, gpointer user_data)
{
    ReceiveNewSample();
    return GST_FLOW_OK;
}

GstFlowReturn NewPrerollCallback(GstAppSink* appsink, gpointer user_data)
{
    GstSample* sample = gst_app_sink_pull_preroll(appsink);
    gst_sample_unref(sample);
    return GST_FLOW_OK;
}
Thanks again





--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

AW: AW: Seems like set callbacks unsuccessful

Thornton, Keith
Hi, with the code you have provided I still can't see what you are doing but
I also have an appsink / appsrc construction in my rtsp streaming code which I handle by

        if (m_pAppSink == nullptr) {
            m_pAppSink = gst_element_factory_make("appsink", "MySink");
            if (m_pAppSink == nullptr)
            {
                return false;
            }
            gst_object_ref(GST_OBJECT(m_pAppSink));

            GstAppSinkCallbacks appsinkCallbacks;
            appsinkCallbacks.new_preroll = prerollSampleCallback;
            appsinkCallbacks.new_sample = sampleCallback;
            appsinkCallbacks.eos = eosCallback;

            gst_app_sink_set_drop(GST_APP_SINK(m_pAppSink), true);
            gst_app_sink_set_callbacks(GST_APP_SINK(m_pAppSink), &appsinkCallbacks, this, nullptr);
        }

I then receive my buffers in the function sampleCallback which does the following

    GstFlowReturn BaseStreamer::sampleCallback(GstAppSink* appsink, gpointer user_data)
    {
        BaseStreamer* pStreamer = (BaseStreamer*)user_data;

        GstSample* pSample = gst_app_sink_pull_sample(appsink);
        if (!pSample) {
            return GST_FLOW_ERROR;
        }

        if (gst_app_src_push_sample(appSrc, pSample != GST_FLOW_OK) {
            gst_buffer_unref(pNewBuffer);
            gst_sample_unref(pNewSample);
            return GST_FLOW_ERROR;
        }
        }

The appsrc then gets the buffers.
I don't do anything with need-data on the appsrc side.
regards
-----Urspr√ľngliche Nachricht-----
Von: gstreamer-devel [mailto:[hidden email]] Im Auftrag von Erickson.LU
Gesendet: Donnerstag, 19. April 2018 02:57
An: [hidden email]
Betreff: Re: AW: Seems like set callbacks unsuccessful

Appreciate your reply, in the official they use signal but i used callback.
Of course, they are different. But, the problem is the callback function has never been called. I use breakpoint and g_print checked that.
And when i use *pipeline_sink = gst_parse_launch (descr, &error); * They all went well.

And there is *NewSampleCallback* and *NewPrerollCallback*.
GstFlowReturn NewSampleCallback(GstAppSink* appsink, gpointer user_data) {
    ReceiveNewSample();
    return GST_FLOW_OK;
}

GstFlowReturn NewPrerollCallback(GstAppSink* appsink, gpointer user_data) {
    GstSample* sample = gst_app_sink_pull_preroll(appsink);
    gst_sample_unref(sample);
    return GST_FLOW_OK;
}
Thanks again





--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: AW: AW: Seems like set callbacks unsuccessful

Erickson.LU
Appreciate your reply and thanks a lot.
I haven't test your code...But I still think the problem is procedure of
constructing the pipeline.

Cause when i use
*  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, NULL);*
to set the callbacks.
The log will report critical error:
*** (test_now:21439): CRITICAL **: gst_app_sink_set_drop: assertion
'GST_IS_APP_SINK (appsink)' failed

** (test_now:21439): CRITICAL **: gst_app_sink_set_max_buffers: assertion
'GST_IS_APP_SINK (appsink)' failed

** (test_now:21439): CRITICAL **: gst_app_sink_set_callbacks: assertion
'GST_IS_APP_SINK (appsink)' failed
*

I think it cause i get a wrong appsink when i use "appsink =
gst_bin_get_by_name(GST_BIN(pipeline), appsink_name.c_str());" or the
pipeline is not ok, before i call set appcallbacks.




The procedure is below :
*      gst_init(&argc, &argv);
//    XInitThreads();
    boost::thread g_main_loop_thread0;

    GstAppSinkCallbacks appsinkCallbacks;
    std::string pipelineString = SINK0;
    std::string appsink_name="APP_SINK0";
    GError* err = 0;
//    pipeline = gst_parse_launch(pipelineString.c_str(), &err);


    pipeline =gst_pipeline_new(NULL);
    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_SINK0");
    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_bin_add_many(GST_BIN(pipeline), 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);


    bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
    gst_bus_add_watch(bus, (GstBusFunc)GstMessageParser, NULL);

//    g_main_loop_thread_ = boost::thread(RunMainLoop);
//    RunMainLoop();
    appsink = gst_bin_get_by_name(GST_BIN(pipeline), appsink_name.c_str());

    g_print("main thread lwpid = %u\n", syscall(SYS_gettid));
    g_print("main thread tid = %u\n", pthread_self());


    appsinkCallbacks.new_preroll = &PrerollCallback;
    appsinkCallbacks.new_sample = &SampleCallback;
//    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, NULL);


    GstStateChangeReturn ret = gst_element_set_state(pipeline,
GST_STATE_PLAYING);

    if (ret == GST_STATE_CHANGE_FAILURE) {
        g_printerr("Unable to set the pipeline to the playing state");
        gst_object_unref(pipeline);
        return false;
    }
    gst_caps_unref (number1);
    gst_caps_unref (number2);
    gst_caps_unref (number3);
 *

Regards




--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel