<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div class="elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Hi all,</div>
<div class="elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div class="elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
I am trying to get a GStreamer application working where the upstream element (an appsink) will be able to pass a custom buffer pool into an avdec_mjpeg decoder.   The reason for doing this is to avoid a memcpy() operation between the avdec_mjpeg decode and
 the display.  This implementation is an embedded system with limited resources (it is an FPGA SoC, Xilinx Zynq) and so avoiding a memcpy is essential to maintaining performance.</div>
<div class="elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div class="elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
In the ideal world, I would implement a custom allocator that when presented with a request for a new buffer would choose one of the N buffers available in FPGA space. (N ~14 at present, could be extended later.)  Or I could set up a bufferpool with all these
 buffers available.  The buffer addresses are fixed: they are mmap'd representations of physical addresses, so unfortunately I can't do this any other way (unless I write my own JPEG decoder, which I'm trying to avoid doing.)</div>
<div class="elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div class="elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
In the ideal world, the JPEG decode would directly decompress the pixel data into the passed framebuffer, achieving zero-copy performance.  </div>
<div class="elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div class="elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
The problem I'm having is I've tried setting up an ALLOCATION query like so:</div>
<div class="elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div class="elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
    gst_element_foreach_sink_pad(GST_ELEMENT(gAppSink), cb_padForeach, NULL);</div>
<div class="elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div class="elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
then my <span style="background-color:rgb(255,255,255); display:inline!important">cb_padForeach implementation is like this:</span></div>
<div class="elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<span style="background-color:rgb(255,255,255); display:inline!important"><br>
</span></div>
<div class="elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<span style="background-color:rgb(255,255,255); display:inline!important">
<div></div>
    gboolean cb_padForeach(GstElement *element, GstPad *pad, gpointer user_data)
<div>    {</div>
<div>        printf("pad %08x %08x %08x\n", element, pad, user_data);</div>
<div><br>
</div>
<div>        GstCaps *resultCaps = gst_caps_new_empty_simple("result");</div>
<div>        GstCaps *caps = gst_caps_new_empty_simple("mycaps");</div>
<div>        gboolean need_pool = FALSE;</div>
<div>        </div>
<div>        GstQuery *query = gst_query_new_allocation(caps, TRUE);</div>
<div>        gst_pad_query(pad, query);</div>
<div><br>
</div>
<div>        gst_query_parse_allocation(query, &resultCaps, &need_pool);</div>
<div><br>
</div>
<div>        GstBufferPool *pool = gst_buffer_pool_new();</div>
<div>        gst_buffer_pool_config_set_params(GST_STRUCTURE(pool), NULL, 460800, 36, 36);</div>
<div><br>
</div>
<div>        gst_query_add_allocation_pool(query, pool, 460800, 36, 36);</div>
<div><br>
</div>
<div>        gst_caps_unref(caps);</div>
<div>        gst_caps_unref(resultCaps);</div>
<div><br>
</div>
<div>        return TRUE;</div>
    }<br>
</span></div>
<div class="elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div class="elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
It may be obvious,  but I don't *really* know what I'm doing here;  I'm trying to set the bufferpool up for now to have 36 qty of buffers each 460800 bytes long, but avdec_mjpeg is still using its two buffers (I can see if I print the buffer addresses going
 into appsink.)  I know this block is entered, but it doesn't appear to influence any behaviour in GStreamer.   <span style="background-color:rgb(255, 255, 255);display:inline !important">N.B. I use 36 in this example as I saw some code in the avdec_X plugin
 that suggested it wanted to see at least 32 buffers in its ALLOCATION query, but I'm unclear as to whether that is encountered here.  I just set it high for now so I could ensure I wasn't trapping on this.  And I'm aware that this is not using my FPGA buffer
 addresses, but one step at a time!</span></div>
<div class="elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div class="elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<span style="color: rgb(0, 0, 0); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;">I'd appreciate pointers (no pun intended) to any examples of setting up custom bufferpools or allocators in the upstream. 
</span><br>
</div>
<div class="elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div class="elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
This is my pipeline (in gstreamer syntax, the implementation is in C):</div>
<div class="elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div class="elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
    udpsrc port=5555 ! 'application/x-rtp,payload=26' ! rtpjpegdepay ! queue ! jpegparse ! avdec_mjpeg ! videoconvert ! appsink</div>
<div class="elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div class="elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
I know this pipeline works ok as I can replace appsink with a display sink and I see video from my test pattern generator, also running with GStreamer.  </div>
<div class="elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
</div>
<div class="elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div class="elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
[P.S. I had posted this on IRC, but as I was using a web-client I lost any chat history, and I've just moved house so I've been offline for a week, so apologies if I'm repeating myself.]</div>
<div class="elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div class="elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Thanks in advance for any advice,</div>
<div class="elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Tom </div>
<div class="elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div class="elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div>
<div id="Signature">
<div></div>
</div>
</div>
</body>
</html>