<div dir="ltr"><div><div><div>Hello,<br><br></div>I used the basic tutorial 8 in order to get a frame in memory buffer from v4l2src using appsink, without success.<br><br></div>The code compiles, but I get a segmentation fault and the pipeline doesn't even start..<br><br></div><div>Any help would be much appreciated.<br><br><br></div><div>Cheers,<br></div><div>Panos<br><br><br><br></div>PS: My code is the following:<br><div><div><br>#include <gst/gst.h><br><br>/* Set V4L2 device to grab from. */<br>char * v4l2dev = "/dev/video0";<br><br>  <br>/* Structure to contain all our information, so we can pass it to callbacks */<br>typedef struct _CustomData {<br>  GstElement *pipeline;<br>  GstElement *source;<br>  GstElement *filter;<br>  GstElement *sink;<br>} CustomData;<br><br><br>/* The appsink has received a buffer */<br>static void new_sample (GstElement *sink, CustomData *data) {<br>  g_printerr ("In the callback function.\n");<br>  <br>  GstSample *sample;  <br>  /* Retrieve the buffer */<br>  g_signal_emit_by_name (sink, "pull-sample", &sample);<br>  if (sample) {<br>    /* The only thing we do in this example is print a * to indicate a received buffer */<br>    g_print ("*");<br>    gst_sample_unref (sample);<br>  }<br>}<br><br>  <br>int main(int argc, char *argv[]) {<br>  CustomData data;<br>  GstCaps *cap;<br>  GstCaps *app_cap;<br>  GstBus *bus;<br>  GstMessage *msg;<br>  GstStateChangeReturn ret;<br>  gboolean terminate = FALSE;<br>  <br>  /* Initialize GStreamer */<br>  gst_init (&argc, &argv);<br>  g_printerr ("Init done.\n");<br>  <br>  /* Create caps */<br>  cap = gst_caps_new_simple ("video/x-raw",<br>        "format", G_TYPE_STRING, "YUY2",<br>         "width", G_TYPE_INT, 640,<br>         "height", G_TYPE_INT, 480,<br>         "framerate", GST_TYPE_FRACTION, 30, 1,<br>         NULL);<br>  app_cap = cap;<br>  g_printerr ("Caps created.\n");<br>   <br>  /* Create the elements */<br>  data.source = gst_element_factory_make ("v4l2src", "source");<br>  data.filter = gst_element_factory_make ("capsfilter","filter");<br>  data.sink = gst_element_factory_make ("appsink", "sink");<br>  g_printerr ("Elements created.\n");<br>  <br>  /* Create the empty pipeline */<br>  data.pipeline = gst_pipeline_new ("test-pipeline");<br>  if (!data.pipeline || !data.source || !data.filter || !data.sink) {<br>    g_printerr ("Not all elements could be created.\n");<br>    return -1;<br>  }<br>  g_printerr ("Pipeline created.\n");<br>  <br>  /* Configure appsink */<br>  g_object_set (data.sink, "emit-signals", TRUE, "caps", app_cap, NULL);<br>  g_signal_connect (data.sink, "new-sample", G_CALLBACK (new_sample), &data);<br>  gst_caps_unref (app_cap);<br>  g_printerr ("Appsink configured.\n");<br>  <br>  /* Build the pipeline. */<br>  gst_bin_add_many (GST_BIN (data.pipeline), data.source, data.filter, data.sink, NULL);<br>  if (!gst_element_link_many (data.source, data.filter, data.sink, NULL)) {<br>    g_printerr ("Elements could not be linked.\n");<br>    gst_object_unref (data.pipeline);<br>    return -1;<br>  }<br>  g_printerr ("Pipeline builded.\n");<br>  <br>  /* Modify the elements' properties */<br>  g_object_set (data.source, "device", v4l2dev, NULL);<br>  g_object_set (data.filter,"caps",cap,NULL);<br>  g_printerr ("Elements' properties set.\n");<br>  <br>  /* Start playing */<br>  ret = gst_element_set_state (data.pipeline, GST_STATE_PLAYING);<br>  if (ret == GST_STATE_CHANGE_FAILURE) {<br>    g_printerr ("Unable to set the pipeline to the playing state.\n");<br>    gst_object_unref (data.pipeline);<br>    return -1;<br>  }<br>  g_printerr ("Pipeline in playing mode.\n");<br>  <br>  /* Listen to the bus */<br>  bus = gst_element_get_bus (data.pipeline);<br>  do {<br>    msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE,<br>        GST_MESSAGE_STATE_CHANGED | GST_MESSAGE_ERROR | GST_MESSAGE_EOS);<br>   <br>    /* Parse message */<br>    if (msg != NULL) {<br>      GError *err;<br>      gchar *debug_info;<br>       <br>      switch (GST_MESSAGE_TYPE (msg)) {<br>        case GST_MESSAGE_ERROR:<br>          gst_message_parse_error (msg, &err, &debug_info);<br>          g_printerr ("Error received from element %s: %s\n", GST_OBJECT_NAME (msg->src), err->message);<br>          g_printerr ("Debugging information: %s\n", debug_info ? debug_info : "none");<br>          g_clear_error (&err);<br>          g_free (debug_info);<br>          terminate = TRUE;<br>          break;<br>        case GST_MESSAGE_EOS:<br>          g_print ("End-Of-Stream reached.\n");<br>          terminate = TRUE;<br>          break;<br>        case GST_MESSAGE_STATE_CHANGED:<br>          /* We are only interested in state-changed messages from the pipeline */<br>          if (GST_MESSAGE_SRC (msg) == GST_OBJECT (data.pipeline)) {<br>            GstState old_state, new_state, pending_state;<br>            gst_message_parse_state_changed (msg, &old_state, &new_state, &pending_state);<br>            g_print ("Pipeline state changed from %s to %s:\n",<br>                gst_element_state_get_name (old_state), gst_element_state_get_name (new_state));<br>          }<br>          break;<br>        default:<br>          /* We should not reach here */<br>          g_printerr ("Unexpected message received.\n");<br>          break;<br>      }<br>      gst_message_unref (msg);<br>    }<br>  } while (!terminate);<br>   <br>  /* Free resources */<br>  gst_caps_unref (cap);<br>  gst_object_unref (bus);<br>  gst_element_set_state (data.pipeline, GST_STATE_NULL);<br>  gst_object_unref (data.pipeline);<br>  return 0;<br>} <br></div></div></div>