fan-chao / nvjmi

封装Jetson Multimedia API的编解码库,基于https://github.com/jocover/jetson-ffmpeg基础进行的修改,未集成于ffmpeg,可单独使用。
MIT License
31 stars 12 forks source link

请教一个问题,本项目的nvdec解码是否用到了cuda,如果用到的话能不能让解码得到的数据存放于cuda的显存中 #8

Closed zjhellofss closed 2 years ago

zjhellofss commented 2 years ago

如题,非常感谢

fan-chao commented 2 years ago
    // do CUDA conversion: RGBA packed@res#2 --> BGR planar@res#2
                ctx->cuda_converter->convert(egl_frame,
                    ctx->resize_width,
                    ctx->resize_height,
                    COLOR_FORMAT_BGR,
                    (void *)ctx->frame_buffer[buf_index],
                    ctx->cuda_stream);

                cudaStreamSynchronize(ctx->cuda_stream);

这个地方的缓冲区的指针(void *)ctx->frame_buffer[buf_index]就是GPU上的存储区域。

zjhellofss commented 2 years ago

我看了一下代码,是不是可以这样理解 从


    JMI_API int nvjmi_decoder_retrieve_frame_data(nvJmiCtx *ctx, nvFrameMeta *frame_meta, void *frame_data)
    {
        if (frame_data)
        {
            memcpy((unsigned char *)frame_data, ctx->frame_buffer[frame_meta->frame_index], frame_meta->payload_size);
            frame_meta->got_data = 1;
        }

        while (!ctx->frame_pools->try_push(frame_meta->frame_index) && !ctx->capture_plane_stop)
        {
            std::this_thread::yield();
        }
        return NVJMI_OK;
    }

中获取的void *frame_data是一个既指向主存又指向显存的指针

fan-chao commented 2 years ago

是的,jetson如果使用特定的cuda接口分配内存,cpu和gpu的指针是一样的,实现了零拷贝。可以参考https://github.com/fan-chao/cuda_utils/blob/main/source/cuda/cudaMappedMemory.h 里面的内存分配方式。

zjhellofss commented 2 years ago

我明白了,大佬