<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none"><!-- p { margin-top: 0px; margin-bottom: 0px; }--></style>
</head>
<body dir="ltr" style="font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;">
<p>Hi Simon,<br>
</p>
<p><br>
</p>
<p>Three suggestions in the order of relevance:<br>
</p>
<p><br>
</p>
<p>1) I think there is no need to explicitly call <br>
</p>
<p>gst_buffer_ref(buffer)-- the gst_sample_get_buffer should do it internally<br>
</p>
<p><br>
</p>
<p>2) Are you sure that the performance is the issue here?<br>
</p>
<p>Try changing the condition whether you access the data<br>
</p>
<p>and see when it stops working, like:<br>
</p>
<p>if(!(buffCntr % 20)) // every 20th<br>
</p>
<p>then <br>
</p>
<p><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">if(!(buffCntr % 15)) // every 15th</span><br>
</p>
<p><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">and see if for sufficiently small denominator it stops working</span></p>
<p><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);"><br>
</span></p>
<p><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255); display: none;"></span>3) Also, try calling the "unref" methods in the opposite order as the "get/ref" methods: <br>
</p>
<p><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">You have </span></p>
<p>ref(sample)<br>
</p>
<p>ref(buffer)<br>
</p>
<p>But you release the sample first</p>
<p>unref(sample)</p>
<p>unref(buffer)<br>
</p>
<p>I think it should be:<br>
</p>
<p>unref(buffer)<br>
</p>
<p>unref(sample)<br>
</p>
<p><br>
</p>
<p>Hope that helps<br>
</p>
<p>Martin<br>
</p>
<p><br>
</p>
<div style="color: rgb(33, 33, 33);">
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> gstreamer-devel <gstreamer-devel-bounces@lists.freedesktop.org> on behalf of simo zz <simon.zz@yahoo.com><br>
<b>Sent:</b> Thursday, September 7, 2017 5:00 PM<br>
<b>To:</b> Discussion of the Development of and With GStreamer<br>
<b>Subject:</b> Speeding up a queue</font>
<div> </div>
</div>
<div>
<div style="color:#000; background-color:#fff; font-family:Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; font-size:13px">
<div id="yui_3_16_0_ym19_1_1504799459941_2385">Hello, <br>
</div>
<div id="yui_3_16_0_ym19_1_1504799459941_8753" dir="ltr">I need to record a video from the USB camera and process the raw-data at the same time, so I successfully implemented this pipeline in C:</div>
<div id="yui_3_16_0_ym19_1_1504799459941_4394"><br>
</div>
<div dir="ltr" id="yui_3_16_0_ym19_1_1504799459941_4395"><strong id="yui_3_16_0_ym19_1_1504799459941_4401">v4l2src device=/dev/webcam ! videoconvert ! video/x-raw,width=544,height=288,framerate=10/1</strong><b id="yui_3_16_0_ym19_1_1504799459941_4403"> ! tee
name=t ! <strong id="yui_3_16_0_ym19_1_1504799459941_4402">queue ! v4l2h264enc ! h264parse ! mp4mux ! filesink location=video.mp4</strong> t. ! queue ! appsink</b></div>
<div id="yui_3_16_0_ym19_1_1504799459941_4517" dir="ltr"><br>
</div>
<div id="yui_3_16_0_ym19_1_1504799459941_4518" dir="ltr">I can access to raw-data from USB camera is read using the "new-sample" signal of appsink in a function called "dataProbe", code as follows:</div>
<div id="yui_3_16_0_ym19_1_1504799459941_5317" dir="ltr"><br>
</div>
<div id="yui_3_16_0_ym19_1_1504799459941_5305" dir="ltr"><b id="yui_3_16_0_ym19_1_1504799459941_5316">GstFlowReturn dataProbe(GstElement *source)<br id="yui_3_16_0_ym19_1_1504799459941_5280">
{ <br>
</b></div>
<div id="yui_3_16_0_ym19_1_1504799459941_5441" dir="ltr"><b id="yui_3_16_0_ym19_1_1504799459941_5316"> // buffCntr is just a counter to choose when I want to process the raw-data<br>
</b></div>
<div id="yui_3_16_0_ym19_1_1504799459941_5322" dir="ltr"><b id="yui_3_16_0_ym19_1_1504799459941_8236"> if (!(</b><b id="yui_3_16_0_ym19_1_1504799459941_5316"><b id="yui_3_16_0_ym19_1_1504799459941_8237">buffCntr</b> % 10))<br id="yui_3_16_0_ym19_1_1504799459941_5282">
{ <br id="yui_3_16_0_ym19_1_1504799459941_5283">
GstMapInfo map;<br id="yui_3_16_0_ym19_1_1504799459941_5284">
GstSample *sample = gst_app_sink_pull_sample(GST_APP_SINK(source));<br id="yui_3_16_0_ym19_1_1504799459941_5285">
GstBuffer *buffer = gst_sample_get_buffer(sample);<br id="yui_3_16_0_ym19_1_1504799459941_5286">
gst_buffer_ref(buffer);<br id="yui_3_16_0_ym19_1_1504799459941_5287">
gst_buffer_map (buffer, &map, GST_MAP_READ);<br id="yui_3_16_0_ym19_1_1504799459941_5288">
g_print("Map size: %d\n", map.size);</b></div>
<div id="yui_3_16_0_ym19_1_1504799459941_5669" dir="ltr"><b id="yui_3_16_0_ym19_1_1504799459941_5316"><br>
</b></div>
<div id="yui_3_16_0_ym19_1_1504799459941_5671" dir="ltr"><b id="yui_3_16_0_ym19_1_1504799459941_5316"> /*int8_t fd = open("/path/to/someFile", O_CREAT | O_WRONLY);<br id="yui_3_16_0_ym19_1_1504799459941_5290">
if (fd != -1)<br id="yui_3_16_0_ym19_1_1504799459941_5291">
{<br id="yui_3_16_0_ym19_1_1504799459941_5292">
if(write(fd, map.data, map.size) == map.size)<br id="yui_3_16_0_ym19_1_1504799459941_5293">
g_print("Written whole data\n");<br id="yui_3_16_0_ym19_1_1504799459941_5294">
else<br id="yui_3_16_0_ym19_1_1504799459941_5295">
g_print("Cannot write whole data\n");<br id="yui_3_16_0_ym19_1_1504799459941_5296">
}<br id="yui_3_16_0_ym19_1_1504799459941_5297">
close(fd);*/<br id="yui_3_16_0_ym19_1_1504799459941_5298">
gst_buffer_unmap(buffer, &map);<br id="yui_3_16_0_ym19_1_1504799459941_5299">
gst_sample_unref(sample);<br id="yui_3_16_0_ym19_1_1504799459941_5300">
gst_buffer_unref(buffer);</b></div>
<div id="yui_3_16_0_ym19_1_1504799459941_5672" dir="ltr"><b id="yui_3_16_0_ym19_1_1504799459941_5316"><br>
</b></div>
<div id="yui_3_16_0_ym19_1_1504799459941_5842" dir="ltr"><b id="yui_3_16_0_ym19_1_1504799459941_8240"> //</b><b id="yui_3_16_0_ym19_1_1504799459941_5316"><b id="yui_3_16_0_ym19_1_1504799459941_8241">buffCntr</b> = 0;<br id="yui_3_16_0_ym19_1_1504799459941_5302">
}<br id="yui_3_16_0_ym19_1_1504799459941_5303">
}</b><br id="yui_3_16_0_ym19_1_1504799459941_5304">
</div>
<div id="yui_3_16_0_ym19_1_1504799459941_5849" dir="ltr"><br>
</div>
<div id="yui_3_16_0_ym19_1_1504799459941_6779" dir="ltr">But the execution of the function dataProbe is so critical that if I set buffCntr<b id="yui_3_16_0_ym19_1_1504799459941_5968">
</b>to zero (as shown in the last commented instruction of the function) even without writing map.data to some file, the whole program hangs, so the mp4 video is not written anymore..
<br>
</div>
<div id="yui_3_16_0_ym19_1_1504799459941_7237" dir="ltr">But I need both raw-data and mp4 video.<br>
</div>
<div id="yui_3_16_0_ym19_1_1504799459941_9446" dir="ltr"><br>
</div>
<div id="yui_3_16_0_ym19_1_1504799459941_7008" dir="ltr">What can I do to 'speed up' this queue and let my gstreamer program to record the video and write the raw data somewhere ? Pthread ? There is some helpful feature already available from gstreamer library
to handle this situation ?</div>
<div id="yui_3_16_0_ym19_1_1504799459941_7238" dir="ltr"><br>
</div>
<div id="yui_3_16_0_ym19_1_1504799459941_7357" dir="ltr">The device which run the application is an embedded board with a quad core CPU.</div>
<div id="yui_3_16_0_ym19_1_1504799459941_7360" dir="ltr"><br>
</div>
<div id="yui_3_16_0_ym19_1_1504799459941_7477" dir="ltr">Thank you in advance.</div>
<div id="yui_3_16_0_ym19_1_1504799459941_7478" dir="ltr">Regards,</div>
<div id="yui_3_16_0_ym19_1_1504799459941_9563" dir="ltr">Simon<br>
</div>
</div>
</div>
</div>
</body>
</html>