<div dir="ltr"><div>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.</div><div><br></div><div>Any ideas?  I've been pounding my head against this wall for a couple days now.</div><div><br></div><div>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><br></div><div><br></div><br></div>