<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:굴림;
        panose-1:2 11 6 0 0 1 1 1 1 1;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"맑은 고딕";
        panose-1:2 11 5 3 2 0 0 2 0 4;}
@font-face
        {font-family:"\@굴림";
        panose-1:2 11 6 0 0 1 1 1 1 1;}
@font-face
        {font-family:"\@맑은 고딕";}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        font-size:12.0pt;
        font-family:굴림;}
span.EmailStyle20
        {mso-style-type:personal-reply;
        font-family:"맑은 고딕";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"맑은 고딕";
        mso-ligatures:none;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:3.0cm 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=KO link="#0563C1" vlink="#954F72" style='word-wrap:break-word'><div class=WordSection1><p class=MsoNormal style='word-break:break-hangul'><span lang=EN-US style='font-size:10.0pt;font-family:"맑은 고딕"'>Hi,<o:p></o:p></span></p><p class=MsoNormal style='word-break:break-hangul'><span lang=EN-US style='font-size:10.0pt;font-family:"맑은 고딕"'><o:p> </o:p></span></p><p class=MsoNormal style='word-break:break-hangul'><span lang=EN-US style='font-size:10.0pt;font-family:"맑은 고딕"'>GstCudaMemory’s stride is likely different from default one. <o:p></o:p></span></p><p class=MsoNormal style='word-break:break-hangul'><span lang=EN-US style='font-size:10.0pt;font-family:"맑은 고딕"'>You will need to use gst_video_frame_map() and GST_VIDEO_FRAME_PLANE_STRIDE(frame, 0), or GstCudaMemory.info.stride[0]<o:p></o:p></span></p><p class=MsoNormal style='word-break:break-hangul'><span lang=EN-US style='font-size:10.0pt;font-family:"맑은 고딕"'><o:p> </o:p></span></p><p class=MsoNormal style='word-break:break-hangul'><span lang=EN-US style='font-size:10.0pt;font-family:"맑은 고딕"'>Regards,<o:p></o:p></span></p><p class=MsoNormal style='word-break:break-hangul'><span lang=EN-US style='font-size:10.0pt;font-family:"맑은 고딕"'>Seungha<o:p></o:p></span></p><p class=MsoNormal style='word-break:break-hangul'><span lang=EN-US style='font-size:10.0pt;font-family:"맑은 고딕"'><o:p> </o:p></span></p><div style='border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p class=MsoNormal><b><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri",sans-serif'>From:</span></b><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri",sans-serif'> gstreamer-devel <gstreamer-devel-bounces@lists.freedesktop.org> <b>On Behalf Of </b>Richard Pickler via gstreamer-devel<br><b>Sent:</b> Thursday, June 8, 2023 10:05 PM<br><b>To:</b> gstreamer-devel@lists.freedesktop.org<br><b>Cc:</b> Richard Pickler <rpickler@gmail.com><br><b>Subject:</b> CUDA GstBuffer output buffer with OpenCV GpuMat<o:p></o:p></span></p></div><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><div><div><p class=MsoNormal><span lang=EN-US>I'm struggling to use the recent cuda improvements in gstreamer, using an OpenCV GpuMat to write to a CUDAMemory outbuf.  I'm was successful in getting an appropriate buffer through decide/propose_allocation, but simply cannot seem to write to a buffer properly.  In my transform function below, I'm able to map the buffer and have the demosaic function run properly, but the output stream comes out garbage.  I placed a simple cv::imwrite in the code, and sure enough, the data comes through the function properly, it's just not in a structure that gstreamer is happy with.<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US>Any ideas?  I've been pounding my head against this wall for a couple days now.<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p></div><div><p class=MsoNormal style='margin-bottom:12.0pt'><span lang=EN-US>static GstFlowReturn<br>debayer_transform(GstBaseTransform *base, <br>                  GstBuffer *inbuf, GstBuffer *outbuf)<br>{<br>    Debayer *debayer = DEBAYER(base);<br>    GstCudaBaseTransform *btrans = GST_CUDA_BASE_TRANSFORM (base);<br><br>    if (gst_buffer_n_memory (outbuf) != 1) {<br>        GST_ERROR_OBJECT (debayer, "Invalid output buffer");<br>        return GST_FLOW_ERROR;<br>    }<br><br>    GstMemory *mem;<br>    mem = gst_buffer_peek_memory (outbuf, 0);<br>    if (!gst_is_cuda_memory (mem)) {<br>        GST_ERROR_OBJECT (debayer, "Input buffer is not CUDA");<br>        std::cout << "Input buffer is not cuda" << std::endl;<br>        return GST_FLOW_ERROR;<br>    }<br><br>    GstMapInfo map;<br>    if(!gst_buffer_map(inbuf, &map, GST_MAP_READ))<br>    {<br>        std::cout << "Can't map" << std::endl;<br>        return GST_FLOW_ERROR;<br>    }<br>    <br>    GstMapInfo outmap;<br>    if(!gst_buffer_map(outbuf, &outmap, (GstMapFlags)(GST_MAP_WRITE | GST_MAP_CUDA)))<br>    {<br>        std::cout << "Can't map" << std::endl;<br>        return GST_FLOW_ERROR;<br>    }<br><br>    cv::Mat in(<br>        cv::Size(debayer->info.width, debayer->info.height), CV_8UC1,<br>        (char*) map.data);<br><br>    cv::cuda::GpuMat gpu_in;<br><br>    cv::cuda::GpuMat gpu_out(<br>        cv::Size(debayer->info.width, debayer->info.height),<br>        CV_8UC3,<br>        (char*) outmap.data, debayer->info.stride[0]);<br><br>    gpu_in.upload(in);<br>    cv::cuda::demosaicing(gpu_in, gpu_out, cv::COLOR_BayerRG2BGR);<br>    cv::Mat out(gpu_out);<br>    cv::imwrite("foo.jpg", out);<br><br>    gst_buffer_unmap(inbuf, &map);<br>    gst_buffer_unmap(outbuf, &outmap);<br>    return GST_FLOW_OK;<br>}<br><br><o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p></div><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p></div></div></body></html>