<div>Good morning all,</div><div>I&#39;m building a simple C application that use appsink to get buffer of data from a pipeline (this last pipeline creates data reading images from a webcam 30fps):</div><div>GstBuffer* buf = gst_app_sink_pull_buffer(GST_APP_SINK(sink));</div>
<div>this function require at least 130ms (7.6fps) of processing time, so I can&#39;t grab images in real time mode (30fps).</div><div><br></div><div>I compiled my application with -O2 optimizer option and I use a PC not bad with a dual core 2.1GHz (x86).</div>
<div>How to get a faster function to work in real time mode?</div><div><br></div><div>This is the code of my application:</div><div><div>#include &lt;gst/gst.h&gt;</div><div>#include &lt;gst/app/gstappsink.h&gt;</div><div>
#include &lt;gst/app/gstappbuffer.h&gt;</div><div>#include &lt;gst/base/gstbasesink.h&gt;</div><div><br></div><div>#include &lt;string&gt;</div><div>#include &lt;iostream&gt;</div><div>#include &lt;sstream&gt;</div><div>#include &lt;map&gt;</div>
<div>#include &lt;vector&gt;</div><div><br></div><div>/***** section to measure performances***********/</div><div>#define DEBUG_FRAMERATE</div><div>#ifdef DEBUG_FRAMERATE</div><div>#include &lt;time.h&gt;</div><div>#include &lt;sys/time.h&gt;</div>
<div>#define NUM_OF_FRAMES_TO_CATCH_TO_CALCULATE_FPS 30</div><div>int frame_counter =0;</div><div>struct timespec timestamp1;</div><div>#endif</div><div>/**************************************************/</div><div>using namespace std;</div>
<div>typedef struct</div><div>{</div><div>  GMainLoop *loop;</div><div>  GstElement *source;</div><div>  GstElement *sink;</div><div>}ProgramData;</div><div><br></div><div>int main(char **argc, int argv[]){</div><div>string cameraDevice;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>bool alwaysCopy;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>string encoding;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>string formatSpecificEncoding;</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>int width;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>int height;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>int bpp; // bit per pixel</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>int depth;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>int redMask;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>int greenMask;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>int blueMask;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>int endianness;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>bool interlaced;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>int framerate;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>int brightness;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>int contrast;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>int saturation;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>int hue;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>bool gstreamerPad;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>bool rosPad;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>int num;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>double meanTime;</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>GstElement *pipeline;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>GstElement *sink;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>cameraDevice = &quot;/dev/video0&quot;;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>alwaysCopy = false;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>encoding = &quot;video/x-raw-rgb&quot;;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>formatSpecificEncoding = &quot;YUY2&quot;;</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>width = 640;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>height = 480;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>bpp = 24;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>depth = 24;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>redMask = 16711680;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>greenMask = 65280;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>blueMask = 255;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>endianness = 4321;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>interlaced = false;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>framerate = 15;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>brightness = 0;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>contrast = 0;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>saturation = 0;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>hue = 0;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>meanTime = 0;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>num = 0;</div><div><br></div><div>stringstream camConfigStream;#include &lt;gst/gst.h&gt;</div><div>#include &lt;gst/app/gstappsink.h&gt;</div><div>#include &lt;gst/app/gstappbuffer.h&gt;</div>
<div>#include &lt;gst/base/gstbasesink.h&gt;</div><div><br></div><div>#include &lt;string&gt;</div><div>#include &lt;iostream&gt;</div><div>#include &lt;sstream&gt;</div><div>#include &lt;map&gt;</div><div>#include &lt;vector&gt;</div>
<div><br></div><div>/***** section to measure performances***********/</div><div>#define DEBUG_FRAMERATE</div><div>#ifdef DEBUG_FRAMERATE</div><div>#include &lt;time.h&gt;</div><div>#include &lt;sys/time.h&gt;</div><div>#define NUM_OF_FRAMES_TO_CATCH_TO_CALCULATE_FPS 30</div>
<div>int frame_counter =0;</div><div>struct timespec timestamp1;</div><div>#endif</div><div>/**************************************************/</div><div>using namespace std;</div><div>typedef struct</div><div>{</div><div>
  GMainLoop *loop;</div><div>  GstElement *source;</div><div>  GstElement *sink;</div><div>}ProgramData;</div><div><br></div><div>int main(char **argc, int argv[]){</div><div>string cameraDevice;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>bool alwaysCopy;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>string encoding;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>string formatSpecificEncoding;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>int width;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>int height;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>int bpp; // bit per pixel</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>int depth;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>int redMask;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>int greenMask;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>int blueMask;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>int endianness;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>bool interlaced;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>int framerate;</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>int brightness;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>int contrast;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>int saturation;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>int hue;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>bool gstreamerPad;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>bool rosPad;</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>int num;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>double meanTime;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>GstElement *pipeline;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>GstElement *sink;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>cameraDevice = &quot;/dev/video0&quot;;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>alwaysCopy = false;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>encoding = &quot;video/x-raw-rgb&quot;;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>formatSpecificEncoding = &quot;YUY2&quot;;</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>width = 640;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>height = 480;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>bpp = 24;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>depth = 24;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>redMask = 16711680;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>greenMask = 65280;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>blueMask = 255;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>endianness = 4321;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>interlaced = false;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>framerate = 15;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>brightness = 0;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>contrast = 0;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>saturation = 0;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>hue = 0;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>meanTime = 0;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>num = 0;</div><div><br></div><div>stringstream camConfigStream;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>camConfigStream &lt;&lt; &quot;v4l2src device=&quot; &lt;&lt; cameraDevice; // /dev/video0</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>camConfigStream &lt;&lt; &quot; always-copy=&quot;;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if(alwaysCopy){</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>camConfigStream &lt;&lt; &quot;true&quot;;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>}else{</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>camConfigStream &lt;&lt; &quot;false&quot;;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>camConfigStream &lt;&lt; &quot; ! capsfilter caps=\&quot; &quot;;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>camConfigStream &lt;&lt; encoding; //&quot;video/x-raw-rgb</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>if(encoding.find(&quot;rgb&quot;) != string::npos){</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>camConfigStream &lt;&lt; &quot;, bpp=(int)&quot; &lt;&lt; bpp; //24</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>camConfigStream &lt;&lt; &quot;, depth=(int)&quot; &lt;&lt; depth; //24</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>camConfigStream &lt;&lt; &quot;, red_mask=(int)&quot; &lt;&lt; redMask; //16711680</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>camConfigStream &lt;&lt; &quot;, green_mask=(int)&quot; &lt;&lt; greenMask; //65280</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>camConfigStream &lt;&lt; &quot;, blue_mask=(int)&quot; &lt;&lt; blueMask; //255</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>camConfigStream &lt;&lt; &quot;, endianness=(int)&quot; &lt;&lt; endianness; //4321</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}else if(encoding.find(&quot;yuv&quot;) != string::npos){</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>camConfigStream &lt;&lt; &quot;, format=&quot; &lt;&lt; formatSpecificEncoding; //YUY2</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>camConfigStream &lt;&lt; &quot;, width=(int)&quot; &lt;&lt; width; //640</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>camConfigStream &lt;&lt; &quot;, height=(int)&quot; &lt;&lt; height; //480</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>camConfigStream &lt;&lt; &quot;, interlaced=(boolean)&quot;;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if(interlaced){</div><div>
<span class="Apple-tab-span" style="white-space:pre">                </span>camConfigStream &lt;&lt; &quot;true&quot;;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}else{</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>camConfigStream &lt;&lt; &quot;false&quot;;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>camConfigStream &lt;&lt; &quot;, framerate=(fraction)&quot; &lt;&lt; framerate &lt;&lt; &quot;/1&quot;; //15</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>camConfigStream &lt;&lt; &quot;, brightness=(int)&quot; &lt;&lt; brightness; //0</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>camConfigStream &lt;&lt; &quot;, contrast=(int)&quot; &lt;&lt; contrast; //0</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>camConfigStream &lt;&lt; &quot;, saturation=(int)&quot; &lt;&lt; saturation; //0</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>camConfigStream &lt;&lt; &quot;, hue=(int)&quot; &lt;&lt; hue; //0</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>camConfigStream &lt;&lt; &quot;\&quot; &quot;;</div><div><br></div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>gst_init(0,0);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>cout&lt;&lt; &quot;Gstreamer Version: &quot; &lt;&lt; gst_version_string() &lt;&lt; endl;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>GError *error = 0; //assignment to zero is a gst requirement</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>pipeline = gst_parse_launch(camConfigStream.str().c_str(),&amp;error);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if (pipeline == NULL) {</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>cout &lt;&lt; error-&gt;message &lt;&lt; endl;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>exit(-1);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>sink = gst_element_factory_make(&quot;appsink&quot;,NULL);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if(!sink){</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>cout &lt;&lt; &quot;Sink creation failed&quot; &lt;&lt; endl;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>string capFormat = encoding;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>GstCaps * caps_alone = gst_caps_new_simple(capFormat.c_str(), NULL);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>gst_app_sink_set_caps(GST_APP_SINK(sink), caps_alone);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>gst_caps_unref(caps_alone);</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>gst_base_sink_set_sync(GST_BASE_SINK(sink), true);</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if(GST_IS_PIPELINE(pipeline)) {</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>GstPad *outpad = gst_bin_find_unlinked_pad(GST_BIN(pipeline), GST_PAD_SRC);</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>g_assert(outpad);</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>GstElement *outelement = gst_pad_get_parent_element(outpad);</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>g_assert(outelement);</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>gst_object_unref(outpad);</div><div><br></div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>if(!gst_bin_add(GST_BIN(pipeline), sink)) {</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>cout &lt;&lt; &quot;gst_bin_add() failed\n&quot; &lt;&lt; endl; // TODO: do some unref</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>gst_object_unref(outelement);</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>gst_object_unref(pipeline);</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>return -1;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>if(!gst_element_link(outelement, sink)) {</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>cout &lt;&lt; &quot;GStreamer: cannot link outelement(\&quot;&quot; &lt;&lt;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                        </span>gst_element_get_name(outelement) &lt;&lt; &quot;\&quot;) -&gt; sink\n&quot; &lt;&lt; endl;</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>gst_object_unref(outelement);</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>gst_object_unref(pipeline);</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>return -1;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>gst_object_unref(outelement);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>} else {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>GstElement* launchpipe = pipeline;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>pipeline = gst_pipeline_new(NULL);</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>g_assert(pipeline);</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>gst_object_unparent(GST_OBJECT(launchpipe));</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>gst_bin_add_many(GST_BIN(pipeline), launchpipe, sink, NULL);</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>if(!gst_element_link(launchpipe, sink)) {</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>cout &lt;&lt; &quot;GStreamer: cannot link launchpipe -&gt; sink\n&quot; &lt;&lt; endl;</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>gst_object_unref(pipeline);</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>return -1;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>gst_element_set_state(pipeline, GST_STATE_PAUSED);</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if (gst_element_get_state(pipeline, NULL, NULL, -1) == GST_STATE_CHANGE_FAILURE) {</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>cout &lt;&lt; &quot;Failed to PAUSE.&quot; &lt;&lt; endl;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>exit(-1);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>} else {</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>cout&lt;&lt; &quot;stream is PAUSED.&quot; &lt;&lt; endl;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><br></div><div>
<span class="Apple-tab-span" style="white-space:pre">        </span>// We could probably do something with the camera name, check</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>// errors or something, but at the moment, we don&#39;t care.</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>std::string camera_name;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>//TODO</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>//<span class="Apple-tab-span" style="white-space:pre">        </span>if (camera_calibration_parsers::readCalibrationIni(&quot;../camera_parameters.txt&quot;, camera_name, camera_info)) {</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>//<span class="Apple-tab-span" style="white-space:pre">                </span>ROS_INFO(&quot;Successfully read camera calibration.  Rerun camera calibrator if it is incorrect.&quot;);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>//<span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>//<span class="Apple-tab-span" style="white-space:pre">        </span>else {</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>//<span class="Apple-tab-span" style="white-space:pre">                </span>ROS_ERROR(&quot;No camera_parameters.txt file found.  Use default file if no other is available.&quot;);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>//<span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>//TODO</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>bool preroll = false;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if (preroll) {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>//The PAUSE, PLAY, PAUSE, PLAY cycle is to ensure proper pre-roll</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>//I am told this is needed and am erring on the side of caution.</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>gst_element_set_state(pipeline, GST_STATE_PLAYING);</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>if (gst_element_get_state(pipeline, NULL, NULL, -1) == GST_STATE_CHANGE_FAILURE) {</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>cout &lt;&lt; &quot;Failed to PLAY.&quot; &lt;&lt; endl;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>exit(-1);</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>} else {</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>cout &lt;&lt; &quot;stream is PLAYING.&quot; &lt;&lt; endl;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>gst_element_set_state(pipeline, GST_STATE_PAUSED);</div><div><br>
</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>if (gst_element_get_state(pipeline, NULL, NULL, -1) == GST_STATE_CHANGE_FAILURE) {</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>cout &lt;&lt; &quot;Failed to PAUSE.&quot; &lt;&lt; endl;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>exit(-1);</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>} else {</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>cout&lt;&lt; &quot;stream is PAUSED.&quot; &lt;&lt; endl;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>// TODO</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>//<span class="Apple-tab-span" style="white-space:pre">        </span>image_transport::ImageTransport it(nh);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>//<span class="Apple-tab-span" style="white-space:pre">        </span>image_transport::CameraPublisher pub = it.advertiseCamera(&quot;gscam/image_raw&quot;, 1);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>//</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>//<span class="Apple-tab-span" style="white-space:pre">        </span>ros::ServiceServer set_camera_info = nh.advertiseService(&quot;gscam/set_camera_info&quot;, setCameraInfo);</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>std::cout &lt;&lt; &quot;Processing...&quot; &lt;&lt; std::endl;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>//processVideo</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>rosPad = false;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>gstreamerPad = true;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>gst_element_set_state(pipeline, GST_STATE_PLAYING);</div>
<div>#ifdef DEBUG_FRAMERATE</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>clock_gettime(CLOCK_REALTIME, &amp;timestamp1);</div><div>#endif</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>while(1){</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>GstBuffer* buf = gst_app_sink_pull_buffer(GST_APP_SINK(sink));</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>if (!buf){</div><div>
<br></div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>return -1;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div><br></div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>GstPad* pad = gst_element_get_static_pad(sink, &quot;sink&quot;); //TODO spostare sink</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>GstCaps *caps = gst_pad_get_negotiated_caps(pad);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>GstStructure *structure = gst_caps_get_structure(caps,0);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>gst_structure_get_int(structure,&quot;width&quot;,&amp;width);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>gst_structure_get_int(structure,&quot;height&quot;,&amp;height);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>gst_buffer_unref(buf);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>//printf(&quot;fatto\n&quot;);</div><div>#ifdef DEBUG_FRAMERATE</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>frame_counter++;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if(frame_counter%NUM_OF_FRAMES_TO_CATCH_TO_CALCULATE_FPS==0){</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>struct timespec timestamp2;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>clock_gettime(CLOCK_REALTIME, &amp;timestamp2);</div><div>
<span class="Apple-tab-span" style="white-space:pre">        </span>long int sec=timestamp2.tv_sec - timestamp1.tv_sec;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>long int nsec=timestamp2.tv_nsec - timestamp1.tv_nsec;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>long milliseconds=(sec*1000000)+nsec/1000.0;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>printf(&quot;time to send one frame: %.02f ms\n&quot;,(float)milliseconds/(float)NUM_OF_FRAMES_TO_CATCH_TO_CALCULATE_FPS);</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>frame_counter=0;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>clock_gettime(CLOCK_REALTIME, &amp;timestamp1);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div>
<div>#endif</div><div><br></div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>return 0;</div><div>
}</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>camConfigStream &lt;&lt; &quot;v4l2src device=&quot; &lt;&lt; cameraDevice; // /dev/video0</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>camConfigStream &lt;&lt; &quot; always-copy=&quot;;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>if(alwaysCopy){</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>camConfigStream &lt;&lt; &quot;true&quot;;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}else{</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>camConfigStream &lt;&lt; &quot;false&quot;;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>camConfigStream &lt;&lt; &quot; ! capsfilter caps=\&quot; &quot;;</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>camConfigStream &lt;&lt; encoding; //&quot;video/x-raw-rgb</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if(encoding.find(&quot;rgb&quot;) != string::npos){</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>camConfigStream &lt;&lt; &quot;, bpp=(int)&quot; &lt;&lt; bpp; //24</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>camConfigStream &lt;&lt; &quot;, depth=(int)&quot; &lt;&lt; depth; //24</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>camConfigStream &lt;&lt; &quot;, red_mask=(int)&quot; &lt;&lt; redMask; //16711680</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>camConfigStream &lt;&lt; &quot;, green_mask=(int)&quot; &lt;&lt; greenMask; //65280</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>camConfigStream &lt;&lt; &quot;, blue_mask=(int)&quot; &lt;&lt; blueMask; //255</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>camConfigStream &lt;&lt; &quot;, endianness=(int)&quot; &lt;&lt; endianness; //4321</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>}else if(encoding.find(&quot;yuv&quot;) != string::npos){</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>camConfigStream &lt;&lt; &quot;, format=&quot; &lt;&lt; formatSpecificEncoding; //YUY2</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>camConfigStream &lt;&lt; &quot;, width=(int)&quot; &lt;&lt; width; //640</div><div>
<span class="Apple-tab-span" style="white-space:pre">        </span>camConfigStream &lt;&lt; &quot;, height=(int)&quot; &lt;&lt; height; //480</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>camConfigStream &lt;&lt; &quot;, interlaced=(boolean)&quot;;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>if(interlaced){</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>camConfigStream &lt;&lt; &quot;true&quot;;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}else{</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>camConfigStream &lt;&lt; &quot;false&quot;;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>camConfigStream &lt;&lt; &quot;, framerate=(fraction)&quot; &lt;&lt; framerate &lt;&lt; &quot;/1&quot;; //15</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>camConfigStream &lt;&lt; &quot;, brightness=(int)&quot; &lt;&lt; brightness; //0</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>camConfigStream &lt;&lt; &quot;, contrast=(int)&quot; &lt;&lt; contrast; //0</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>camConfigStream &lt;&lt; &quot;, saturation=(int)&quot; &lt;&lt; saturation; //0</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>camConfigStream &lt;&lt; &quot;, hue=(int)&quot; &lt;&lt; hue; //0</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>camConfigStream &lt;&lt; &quot;\&quot; &quot;;</div><div><br></div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>gst_init(0,0);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>cout&lt;&lt; &quot;Gstreamer Version: &quot; &lt;&lt; gst_version_string() &lt;&lt; endl;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>GError *error = 0; //assignment to zero is a gst requirement</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>pipeline = gst_parse_launch(camConfigStream.str().c_str(),&amp;error);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if (pipeline == NULL) {</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>cout &lt;&lt; error-&gt;message &lt;&lt; endl;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>exit(-1);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>sink = gst_element_factory_make(&quot;appsink&quot;,NULL);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if(!sink){</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>cout &lt;&lt; &quot;Sink creation failed&quot; &lt;&lt; endl;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>string capFormat = encoding;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>GstCaps * caps_alone = gst_caps_new_simple(capFormat.c_str(), NULL);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>gst_app_sink_set_caps(GST_APP_SINK(sink), caps_alone);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>gst_caps_unref(caps_alone);</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>gst_base_sink_set_sync(GST_BASE_SINK(sink), true);</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if(GST_IS_PIPELINE(pipeline)) {</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>GstPad *outpad = gst_bin_find_unlinked_pad(GST_BIN(pipeline), GST_PAD_SRC);</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>g_assert(outpad);</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>GstElement *outelement = gst_pad_get_parent_element(outpad);</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>g_assert(outelement);</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>gst_object_unref(outpad);</div><div><br></div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>if(!gst_bin_add(GST_BIN(pipeline), sink)) {</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>cout &lt;&lt; &quot;gst_bin_add() failed\n&quot; &lt;&lt; endl; // TODO: do some unref</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>gst_object_unref(outelement);</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>gst_object_unref(pipeline);</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>return -1;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>if(!gst_element_link(outelement, sink)) {</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>cout &lt;&lt; &quot;GStreamer: cannot link outelement(\&quot;&quot; &lt;&lt;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                        </span>gst_element_get_name(outelement) &lt;&lt; &quot;\&quot;) -&gt; sink\n&quot; &lt;&lt; endl;</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>gst_object_unref(outelement);</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>gst_object_unref(pipeline);</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>return -1;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>gst_object_unref(outelement);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>} else {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>GstElement* launchpipe = pipeline;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>pipeline = gst_pipeline_new(NULL);</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>g_assert(pipeline);</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>gst_object_unparent(GST_OBJECT(launchpipe));</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>gst_bin_add_many(GST_BIN(pipeline), launchpipe, sink, NULL);</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>if(!gst_element_link(launchpipe, sink)) {</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>cout &lt;&lt; &quot;GStreamer: cannot link launchpipe -&gt; sink\n&quot; &lt;&lt; endl;</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>gst_object_unref(pipeline);</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>return -1;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>gst_element_set_state(pipeline, GST_STATE_PAUSED);</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if (gst_element_get_state(pipeline, NULL, NULL, -1) == GST_STATE_CHANGE_FAILURE) {</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>cout &lt;&lt; &quot;Failed to PAUSE.&quot; &lt;&lt; endl;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>exit(-1);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>} else {</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>cout&lt;&lt; &quot;stream is PAUSED.&quot; &lt;&lt; endl;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><br></div><div>
<span class="Apple-tab-span" style="white-space:pre">        </span>// We could probably do something with the camera name, check</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>// errors or something, but at the moment, we don&#39;t care.</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>std::string camera_name;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>//TODO</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>//<span class="Apple-tab-span" style="white-space:pre">        </span>if (camera_calibration_parsers::readCalibrationIni(&quot;../camera_parameters.txt&quot;, camera_name, camera_info)) {</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>//<span class="Apple-tab-span" style="white-space:pre">                </span>ROS_INFO(&quot;Successfully read camera calibration.  Rerun camera calibrator if it is incorrect.&quot;);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>//<span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>//<span class="Apple-tab-span" style="white-space:pre">        </span>else {</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>//<span class="Apple-tab-span" style="white-space:pre">                </span>ROS_ERROR(&quot;No camera_parameters.txt file found.  Use default file if no other is available.&quot;);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>//<span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>//TODO</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>bool preroll = false;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if (preroll) {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>//The PAUSE, PLAY, PAUSE, PLAY cycle is to ensure proper pre-roll</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>//I am told this is needed and am erring on the side of caution.</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>gst_element_set_state(pipeline, GST_STATE_PLAYING);</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>if (gst_element_get_state(pipeline, NULL, NULL, -1) == GST_STATE_CHANGE_FAILURE) {</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>cout &lt;&lt; &quot;Failed to PLAY.&quot; &lt;&lt; endl;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>exit(-1);</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>} else {</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>cout &lt;&lt; &quot;stream is PLAYING.&quot; &lt;&lt; endl;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>gst_element_set_state(pipeline, GST_STATE_PAUSED);</div><div><br>
</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>if (gst_element_get_state(pipeline, NULL, NULL, -1) == GST_STATE_CHANGE_FAILURE) {</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>cout &lt;&lt; &quot;Failed to PAUSE.&quot; &lt;&lt; endl;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>exit(-1);</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>} else {</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>cout&lt;&lt; &quot;stream is PAUSED.&quot; &lt;&lt; endl;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>// TODO</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>//<span class="Apple-tab-span" style="white-space:pre">        </span>image_transport::ImageTransport it(nh);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>//<span class="Apple-tab-span" style="white-space:pre">        </span>image_transport::CameraPublisher pub = it.advertiseCamera(&quot;gscam/image_raw&quot;, 1);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>//</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>//<span class="Apple-tab-span" style="white-space:pre">        </span>ros::ServiceServer set_camera_info = nh.advertiseService(&quot;gscam/set_camera_info&quot;, setCameraInfo);</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>std::cout &lt;&lt; &quot;Processing...&quot; &lt;&lt; std::endl;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>//processVideo</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>rosPad = false;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>gstreamerPad = true;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>gst_element_set_state(pipeline, GST_STATE_PLAYING);</div>
<div>#ifdef DEBUG_FRAMERATE</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>clock_gettime(CLOCK_REALTIME, &amp;timestamp1);</div><div>#endif</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>while(1){</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>GstBuffer* buf = gst_app_sink_pull_buffer(GST_APP_SINK(sink));</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>if (!buf){</div><div>
<br></div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>return -1;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div><br></div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>GstPad* pad = gst_element_get_static_pad(sink, &quot;sink&quot;); //TODO spostare sink</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>GstCaps *caps = gst_pad_get_negotiated_caps(pad);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>GstStructure *structure = gst_caps_get_structure(caps,0);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>gst_structure_get_int(structure,&quot;width&quot;,&amp;width);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>gst_structure_get_int(structure,&quot;height&quot;,&amp;height);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>gst_buffer_unref(buf);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>//printf(&quot;fatto\n&quot;);</div><div>#ifdef DEBUG_FRAMERATE</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>frame_counter++;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if(frame_counter%NUM_OF_FRAMES_TO_CATCH_TO_CALCULATE_FPS==0){</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>struct timespec timestamp2;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>clock_gettime(CLOCK_REALTIME, &amp;timestamp2);</div><div>
<span class="Apple-tab-span" style="white-space:pre">        </span>long int sec=timestamp2.tv_sec - timestamp1.tv_sec;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>long int nsec=timestamp2.tv_nsec - timestamp1.tv_nsec;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>long milliseconds=(sec*1000000)+nsec/1000.0;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>printf(&quot;time to send one frame: %.02f ms\n&quot;,(float)milliseconds/(float)NUM_OF_FRAMES_TO_CATCH_TO_CALCULATE_FPS);</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>frame_counter=0;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>clock_gettime(CLOCK_REALTIME, &amp;timestamp1);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div>
<div>#endif</div><div><br></div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>return 0;</div><div>
}</div></div><div><br></div>