#include "FFNvDecoderManager.h" #include #include "cuda_kernels.h" #include "NvJpegEncoder.h" unsigned char *pHwRgb = nullptr; /** * 注意: gpuFrame 在解码器设置的显卡上,后续操作要十分注意这一点,尤其是多线程情况 * */ void postDecoded(const void * userPtr, AVFrame * gpuFrame){ FFNvDecoder* decoder = (FFNvDecoder*)userPtr; if (decoder!= nullptr) { cout << decoder->getName() << endl; const char* gpu_pixfmt = av_get_pix_fmt_name((AVPixelFormat)gpuFrame->format); cout << "pixfmt: " << gpu_pixfmt << endl; cout << "keyframe: " << gpuFrame->key_frame << " width: " << gpuFrame->width << " height: "<< gpuFrame->height << endl; cout << "decode successed ✿✿ヽ(°▽°)ノ✿ " << endl; if (gpuFrame->format == AV_PIX_FMT_CUDA) { cout << "gpuid = " << atoi(decoder->m_cfg.gpuid.c_str()) << endl; // cudaSetDevice(atoi(decoder->m_cfg.gpuid.c_str())); // cudaError_t cudaStatus; // if(pHwRgb == nullptr){ // cuda_common::setColorSpace2( ITU709, 0 ); // cudaStatus = cudaMalloc((void **)&pHwRgb, 3 * gpuFrame->width * gpuFrame->height * sizeof(unsigned char)); // } // cudaStatus = cuda_common::CUDAToBGR((CUdeviceptr)gpuFrame->data[0],(CUdeviceptr)gpuFrame->data[1], gpuFrame->linesize[0], gpuFrame->linesize[1], pHwRgb, gpuFrame->width, gpuFrame->height); // cudaDeviceSynchronize(); // if (cudaStatus != cudaSuccess) { // cout << "CUDAToBGR failed !!!" << endl; // return; // } // string path = "/home/cmhu/FFNvDecoder/" + decoder->m_cfg.gpuid + ".jpg"; // saveJpeg(path.c_str(), pHwRgb, gpuFrame->width, gpuFrame->height); // 验证 CUDAToRGB } } } int main(){ FFNvDecoderManager* pDecManager = FFNvDecoderManager::getInstance(); MgrDecConfig config; config.name = "dec1"; config.cfg.uri = "rtmp://192.168.10.56:1935/objecteye/1"; config.cfg.post_decoded_cbk = postDecoded; config.cfg.force_tcp = true; config.cfg.gpuid = "1"; FFNvDecoder* decoder = pDecManager->createDecoder(config); if (!decoder) { return 1; } pDecManager->setUserPtr(config.name, decoder); pDecManager->startDecodeByName(config.name); config.name = "dec2"; config.cfg.uri = "rtmp://192.168.10.56:1935/objecteye/1"; config.cfg.gpuid = "2"; FFNvDecoder* dec2 = pDecManager->createDecoder(config); if (!dec2) { return 1; } pDecManager->setUserPtr(config.name, dec2); pDecManager->startDecodeByName(config.name); config.name = "dec0"; config.cfg.uri = "rtmp://192.168.10.56:1935/objecteye/1"; config.cfg.gpuid = "0"; FFNvDecoder* dec0 = pDecManager->createDecoder(config); if (!dec0) { return 1; } pDecManager->setUserPtr(config.name, dec0); pDecManager->startDecodeByName(config.name); config.name = "dec01"; config.cfg.uri = "rtmp://192.168.10.56:1935/objecteye/1"; config.cfg.gpuid = "0"; FFNvDecoder* dec01 = pDecManager->createDecoder(config); if (!dec01) { return 1; } pDecManager->setUserPtr(config.name, dec01); pDecManager->startDecodeByName(config.name); // while (getchar() != 'q'); // // pDecManager->closeDecoderByName("dec1"); // // pDecManager->pauseDecoder("dec1"); // pDecManager->pauseDecoder("dec2"); // while (getchar() != 'q'); // // pDecManager->resumeDecoder("dec1"); // pDecManager->resumeDecoder("dec2"); while (getchar() != 'q'); pDecManager->closeAllDecoder(); }