RR SDK with GStreamer

RR SDK with GStreamer

  • I really want to access the camera data from the fakesink buffer in the cb_handoff. For some reason this function does not even get called. Can anyone be of help here?

    I have also attached the output when i run this application, maybe i am not using the g_signal_connect appropriately.

     

    #include <string.h>
    #include <gst/gst.h>

    #define VIDEO_SRC "v4l2src"
    #define VIDEO_SINK "TIDmaiVideoSink"

    typedef struct
    {
        void *buffer;
        unsigned int buffer_size;
        int width;
        int height;
    }MainData;
    static void
    cb_handoff (GstElement *fakesink,
         GstBuffer *buffer,
         GstPad     *pad,
         MainData *user_data)
    {
         unsigned int tbuffersize;
        user_data->width=666;
        /*tbuffersize=GST_BUFFER_SIZE (buffer);
        if(!user_data->buffer || user_data->buffer_size != tbuffersize)
        {
            GstCaps * caps;
            GstStructure *structure;
            if(user_data->buffer)
                free(user_data->buffer);
            user_data->buffer=(void*) malloc(tbuffersize * sizeof(void));
            user_data->buffer_size=tbuffersize;

            caps=gst_buffer_get_caps(buffer);
            structure = gst_caps_get_structure(caps, 0);
            gst_structure_get_int(structure, "width", &user_data->width);
            gst_structure_get_int(structure, "height", &user_data->height);
            gst_caps_unref(caps);
        }
       
        memcpy(user_data->buffer, GST_BUFFER_DATA(buffer), tbuffersize);*/
       
    }
    gint
    main (gint    argc,
           gchar *argv[])
    {
        MainData *main_data;
        main_data=g_new0(MainData, 1);
        main_data->buffer=NULL;
        main_data->width=40;
        main_data->height=80;
        main_data->buffer_size=0;
        int itv, pixelD;

        GstElement *pipeline, *camera_src, *fakesink;
        GstElement *csp_filter;
        GstCaps *caps;
        GMainLoop *loop;
          /* init GStreamer */
          gst_init (&argc, &argv);
          loop = g_main_loop_new (NULL, FALSE);
          /* setup pipeline */
          pipeline = gst_pipeline_new ("test-camera");
        camera_src=gst_element_factory_make(VIDEO_SRC, "camera_src");
        csp_filter = gst_element_factory_make ("ffmpegcolorspace", "csp_filter");
        fakesink = gst_element_factory_make ("fakesink","sink");
       
        if(!(pipeline && camera_src && csp_filter && fakesink))
        {
            g_critical("Could not create pipeline elements");
            return FALSE;
        }
        else
        {     g_print("Pipeline elements ready");}

       

        gst_bin_add_many (GST_BIN (pipeline), camera_src, csp_filter, fakesink, NULL);


        caps = gst_caps_new_simple("video/x-raw-rgb",
                "width", G_TYPE_INT, 640,
                "height", G_TYPE_INT, 480,
                NULL);
        if(!gst_element_link_filtered(camera_src, csp_filter, caps))
        {
            g_print("Camera CANNOT linked to fiter at VGA size!!\n");
            return FALSE;
        }
        else
        {
            g_print("Camera linked to fiter at VGA size!!\n");
        }

        gst_caps_unref(caps);
       
        if(!gst_element_link(csp_filter, fakesink))
        {
            g_print("csp filter could not link to fakesink\n");
        }
        else
        {
            g_print("Csp filter successfully linked to fakesink!!\n");
        }
       
        g_object_set(G_OBJECT(fakesink), "signal-handoffs", TRUE, NULL);
        g_signal_connect (fakesink, "handoff", G_CALLBACK (cb_handoff), main_data);

          gst_element_set_state (pipeline, GST_STATE_PLAYING);

       

        g_print("print pixels out\n");

        g_print("The image is of width %i and height %i\n",main_data->width, main_data->height);

        /*for(itv=0;itv<(640*480);itv+=100)
        {
            pixelD=main_data->buffer[itv];
            g_print("pixel[%i]=%i",itv,pixelD);   
        }*/

          g_main_loop_run (loop);

          /* clean up */
          gst_element_set_state (pipeline, GST_STATE_NULL);
          gst_object_unref (GST_OBJECT (pipeline));

        if(main_data->buffer)
            free(main_data->buffer);
          return 0;
    }
    ======output=============

    /examples # ./gst-test
    Pipeline elements readyCamera linked to fiter at VGA size!!
    [42949435.560000] mt9v113 1-003c: invalid control id 9963781
    Csp filter succe[42949435.570000] mt9v113 1-003c: invalid control id 9963782
    ssfully linked t[42949435.570000] mt9v113 1-003c: invalid control id 9963783
    o fakesink!!
    [42949435.580000] mt9v113 1-003c: invalid control id 9963784
    [42949435.590000] mt9v113 1-003c: invalid control id 9963785
    [42949435.590000] mt9v113 1-003c: invalid control id 9963786
    [42949435.600000] mt9v113 1-003c: invalid control id 9963787
    [42949435.600000] mt9v113 1-003c: invalid control id 9963788
    [42949435.610000] mt9v113 1-003c: invalid control id 9963789
    [42949435.610000] mt9v113 1-003c: invalid control id 9963790
    [42949435.620000] mt9v113 1-003c: invalid control id 9963791
    [42949435.630000] mt9v113 1-003c: invalid control id 9963792
    [42949435.630000] mt9v113 1-003c: invalid control id 9963793
    [42949435.640000] mt9v113 1-003c: invalid control id 9963796
    [42949435.640000] mt9v113 1-003c: invalid control id 9963797
    [42949435.650000] mt9v113 1-003c: invalid control id 9963798
    [42949435.650000] mt9v113 1-003c: invalid control id 9963799
    [42949435.660000] mt9v113 1-003c: invalid control id 9963800
    [42949435.670000] mt9v113 1-003c: invalid control id 9963801
    [42949435.670000] mt9v113 1-003c: invalid control id 9963802
    [42949435.680000] mt9v113 1-003c: invalid control id 9963803
    [42949435.680000] mt9v113 1-003c: invalid control id 9963804
    [42949435.690000] mt9v113 1-003c: invalid control id 9963805
    [42949435.690000] mt9v113 1-003c: invalid control id 9963806
    print pixels out
    The image is of width 40 and height 80
    -------------------

    i was expecting the width to change from 40 to 666 when the cb_handoff get called. Am i doing something wrong here?

     

     

     

  • Thanks guys. Figured out the pipeline was in GST_STATE_CHANGE_FAILURE state, because of the way i was connecting to the camera.