<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body>
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Arial,Helvetica,sans-serif;" dir="ltr">
<p>Hello, Jack</p>
<p><br>
</p>
<p>I don`t really get your question.</p>
<p><span style="font-size: 12pt;">Can you be more specific, please?</span><br>
</p>
<p>Also more details will be useful.</p>
<p><br>
</p>
<p>Mikl</p>
</div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> gstreamer-devel <gstreamer-devel-bounces@lists.freedesktop.org> on behalf of Jack D <jackstuff3@gmail.com><br>
<b>Sent:</b> Wednesday, November 16, 2016 12:04:36 AM<br>
<b>To:</b> Discussion of the development of and with GStreamer<br>
<b>Subject:</b> Deconstructing a pipeline</font>
<div> </div>
</div>
<div>
<div dir="ltr">I am trying to duplicate the following pipeline through a C program
<div><br>
</div>
<div>gst-launch-1.0 v4l2src device=/dev/video0 ! 'video/x-raw,width=800,height=480' ! gtksink </div>
<div><br>
</div>
<div><font color="#000000" face="monospace, courier"><span style="font-size:12.7px;white-space:pre-wrap;background-color:rgb(249,249,249)">The C program nearly duplicates the output of this command line pipeline. The problem is the video is fuzzy or unfocused.
 I can run them side by side and the action is precise, just the command line output is clear and pristine and the c code output is bad.
</span></font></div>
<div><font color="#000000" face="monospace, courier"><span style="font-size:12.7px;white-space:pre-wrap;background-color:rgb(249,249,249)"><br>
</span></font></div>
<div><font color="#000000" face="monospace, courier"><span style="font-size:12.7px;white-space:pre-wrap;background-color:rgb(249,249,249)">Since the C code is relatively short, I'll include it here.
</span></font></div>
<div><font color="#000000" face="monospace, courier"><span style="font-size:12.7px;white-space:pre-wrap;background-color:rgb(249,249,249)"><br>
</span></font></div>
<div><font color="#000000" face="monospace, courier"><span style="font-size:12.7px;white-space:pre-wrap;background-color:rgb(249,249,249)">Thanks,</span></font></div>
<div><font color="#000000" face="monospace, courier"><span style="font-size:12.7px;white-space:pre-wrap;background-color:rgb(249,249,249)">Jack</span></font></div>
<div><font color="#000000" face="monospace, courier"><span style="font-size:12.7px;white-space:pre-wrap;background-color:rgb(249,249,249)"><br>
</span></font></div>
<div><font color="#000000" face="monospace, courier"><span style="background-color:rgb(249,249,249)">
<div><span style="font-size:12.7px;white-space:pre-wrap">#include <string.h></span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">   </span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">#include <gtk/gtk.h></span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">#include <gst/gst.h></span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">     </span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">#include <gst/video/videooverlay.h>     </span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">#include <gdk/gdk.h></span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap"><br>
</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">#define vid_caps "video/x-raw,width=800,height=480"</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap"><br>
</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">/* Structure to contain all our information, so we can pass it around */</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">typedef struct _CustomData {</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  GstElement *pipeline;           /* Pipeline */</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  GstElement *playbin;            /* Source */</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  GstElement *playsink;           /* Sink */</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  GstElement *sink;               /* sink to hold video */<span class="gmail-Apple-tab-span" style="white-space:pre">
</span>     </span></div>
<div><span style="font-size:12.7px"><span class="gmail-Apple-tab-span" style="white-space:pre"></span>      </span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  GstState state;                 /* Current state of the pipeline */</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">} CustomData;</span></div>
<div><span style="font-size:12.7px"><span class="gmail-Apple-tab-span" style="white-space:pre"></span>     </span></div>
<div><span style="font-size:12.7px"><span class="gmail-Apple-tab-span" style="white-space:pre"></span>    </span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">/* This function is called when the PLAY button is clicked */</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">static void play_cb (GtkButton *button, CustomData *data) {</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  gst_element_set_state (data->pipeline, GST_STATE_PLAYING);</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">}</span></div>
<div><span style="font-size:12.7px"><span class="gmail-Apple-tab-span" style="white-space:pre"></span>         </span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">/* This function is called when the PAUSE button is clicked */</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">static void pause_cb (GtkButton *button, CustomData *data) {</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  gst_element_set_state (data->pipeline, GST_STATE_PAUSED);</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">}</span></div>
<div><span style="font-size:12.7px"><span class="gmail-Apple-tab-span" style="white-space:pre"></span>      </span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">/* This function is called when the STOP button is clicked */</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">static void stop_cb (GtkButton *button, CustomData *data) {</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  gst_element_set_state (data->pipeline, GST_STATE_READY);</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">}</span></div>
<div><span style="font-size:12.7px"><span class="gmail-Apple-tab-span" style="white-space:pre"></span>   </span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">/* This function is called when the main window is closed */</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">static void delete_event_cb (GtkWidget *widget, GdkEvent *event, CustomData *data) {</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  stop_cb (NULL, data);</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  gtk_main_quit ();</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">}</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap"><br>
</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap"><br>
</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">/* This creates all the GTK+ widgets that compose our application, and registers the callbacks */</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">static void create_ui (CustomData *data) {</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  GtkWidget *main_window;  /* The uppermost window, containing all other windows */</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  GtkWidget *video_window; /* The drawing area where the video will be shown */</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  GtkWidget *main_box;     /* VBox to hold main_hbox and the controls */</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  GtkWidget *main_hbox;    /* HBox to hold the video_window and the stream info text widget */</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  GtkWidget *controls;     /* HBox to hold the buttons and the slider */</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  GtkWidget *play_button, *pause_button, *stop_button; /* Buttons */</span></div>
<div><span style="font-size:12.7px"><span class="gmail-Apple-tab-span" style="white-space:pre"></span>       </span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  main_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  g_signal_connect (G_OBJECT (main_window), "delete-event", G_CALLBACK (delete_event_cb), data);</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap"><br>
</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  g_object_get (data->playsink, "widget", &video_window, NULL);</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap"><br>
</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  gtk_widget_set_double_buffered (video_window, FALSE);</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  play_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_PLAY);</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  g_signal_connect (G_OBJECT (play_button), "clicked", G_CALLBACK (play_cb), data);</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  pause_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_PAUSE);</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  g_signal_connect (G_OBJECT (pause_button), "clicked", G_CALLBACK (pause_cb), data);</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  controls = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  gtk_box_pack_start (GTK_BOX (controls), play_button, FALSE, FALSE, 2);</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  gtk_box_pack_start (GTK_BOX (controls), pause_button, FALSE, FALSE, 2);</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  main_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  gtk_box_pack_start (GTK_BOX (main_hbox), video_window, TRUE, TRUE, 0);</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  main_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  gtk_box_pack_start (GTK_BOX (main_box), main_hbox, TRUE, TRUE, 0);</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  gtk_box_pack_start (GTK_BOX (main_box), controls, FALSE, FALSE, 0);</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  gtk_container_add (GTK_CONTAINER (main_window), main_box);</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  gtk_window_set_default_size (GTK_WINDOW (main_window), 640, 480);</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  gtk_widget_show_all (main_window);</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">}</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap"><br>
</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">/* This function is called when an End-Of-Stream message is posted on the bus.</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap"> * We just set the pipeline to READY (which stops playback) */</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">static void eos_cb (GstBus *bus, GstMessage *msg, CustomData *data) {</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  g_print ("End-Of-Stream reached.\n");</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  gst_element_set_state (data->pipeline, GST_STATE_READY);</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">}</span></div>
<div><span style="font-size:12.7px"><span class="gmail-Apple-tab-span" style="white-space:pre"></span>     </span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap"><br>
</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">int main(int argc, char *argv[]) {</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  CustomData data;</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  GstStateChangeReturn ret;</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  GstBus *bus;</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  GError **parse_error;</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  GstCaps *video_caps;</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  gboolean link_ok;</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap"><br>
</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  /* Initialize GTK */</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  gtk_init (&argc, &argv);</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap"><br>
</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  /* Initialize GStreamer */</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  gst_init (&argc, &argv);</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap"><br>
</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  /* Initialize our data structure */</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  memset (&data, 0, sizeof (data));</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  </span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  /* Create the elements */</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  data.pipeline = gst_pipeline_new ("pipeline");</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  data.playbin = gst_element_factory_make ("v4l2src", "source");</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  data.playsink = gst_element_factory_make ("gtksink", "playsink");</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  video_caps = gst_caps_from_string(vid_caps);</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">//  printf("Vid caps %s.\n", vid_caps);</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  if (!data.playbin || !data.pipeline || !data.playsink || !video_caps) {</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">    g_printerr ("Not all elements could be created.\n");</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">    return -1;</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  }</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap"><br>
</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  /* Set the URI to play */</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  g_object_set (G_OBJECT(data.playbin), "device", "/dev/video0", NULL);</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap"><br>
</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  gst_bin_add (GST_BIN(data.pipeline), data.playbin);</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  </span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  gst_bin_add (GST_BIN(data.pipeline), data.playsink);</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap"><br>
</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  if (!(gst_element_link(data.playbin, data.playsink))) {</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">    g_printerr ("Unable to link the source and the sink.\n");</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">    gst_object_unref (data.pipeline);</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">    return -1;</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  }</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap"><br>
</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  gst_element_link_many (data.playbin, data.playsink, NULL);</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  link_ok = gst_element_link_filtered (data.playbin, data.playsink, video_caps);</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  gst_caps_unref(video_caps);</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  </span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  if (!link_ok) {</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">    g_warning("Failed to link playbin and playsink with caps");</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">    }</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap"><br>
</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  /* Create the GUI */</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  create_ui (&data);</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  </span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  </span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  /* Start playing */</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  ret = gst_element_set_state (data.pipeline, GST_STATE_PLAYING);</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  if (ret == GST_STATE_CHANGE_FAILURE) {</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">    g_printerr ("Unable to set the pipeline to the playing state.\n");</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">    gst_object_unref (data.pipeline);</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">    return -1;</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  }</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap"><br>
</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  /* Start the GTK main loop. We will not regain control until gtk_main_quit is called. */</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  gtk_main ();</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  </span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  /* Free resources */</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  gst_element_set_state (data.pipeline, GST_STATE_NULL);</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  gst_object_unref (data.pipeline);</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">  return 0;</span></div>
<div><span style="font-size:12.7px;white-space:pre-wrap">}</span></div>
<div style="font-size:12.7px;white-space:pre-wrap"><br>
</div>
</span></font></div>
</div>
</div>
</body>
</html>