登录
注册
开源
企业版
高校版
搜索
帮助中心
使用条款
关于我们
开源
企业版
高校版
私有云
模力方舟
AI 队友
登录
注册
6 月10 日(下周三晚 19:00)直播预告:龙虾还活着吗?来看 PocketClaw 上市两个月后对 AI 硬件的真实复盘,点击预约,开播有提醒~
代码拉取完成,页面将自动刷新
开源项目
>
人工智能
>
AI-人工智能
&&
捐赠
捐赠前请先登录
取消
前往登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
Watch
不关注
关注所有动态
仅关注版本发行动态
关注但不提醒动态
224
Star
1.3K
Fork
1.1K
Ascend
/
samples
代码
Issues
41
Pull Requests
98
Wiki
统计
流水线
服务
JavaDoc
PHPDoc
质量分析
Jenkins for Gitee
腾讯云托管
腾讯云 Serverless
悬镜安全
阿里云 SAE
Codeblitz
SBOM
开发画像分析
我知道了,不再自动展开
更新失败,请稍后重试!
移除标识
内容风险标识
本任务被
标识为内容中包含有代码安全 Bug 、隐私泄露等敏感信息,仓库外成员不可访问
venc编码仍然存在问题,新到的帧,只能编码第一帧
DONE
#IAPAYM
Bug-Report
sxj731533730
创建于
2024-09-06 10:21
https://gitee.com/ascend/samples/issues/IAIL76#note_30525319 参考这个,从共享连续取出帧进行编码 ``` // // Created by sxj on 2024/8/25. // #include "Atlas_venc.h" #define INFO_LOG(fmt, args...) fprintf(stdout, "[INFO] " fmt "\n", ##args) #define WARN_LOG(fmt, args...) fprintf(stdout, "[WARN] " fmt "\n", ##args) #define ERROR_LOG(fmt, args...) fprintf(stderr, "[ERROR] " fmt "\n", ##args) #define YUV420SP_SIZE(width, height) ((width) * (height) * 3 / 2) #define ALIGN_UP(num, align) (((num) + (align) - 1) & ~((align) - 1)) #define ALIGN_UP2(num) ALIGN_UP(num, 2) #define ALIGN_UP16(num) ALIGN_UP(num, 16) #define ALIGN_UP128(num) ALIGN_UP(num, 128) bool g_venc_runFlag= true; extern int32_t deviceId_; extern aclrtContext context_; extern aclrtStream stream_; atlas_venc::atlas_venc() { item_reader = new ReaderMem(); aclError ret = item_reader->init_paramter(MEMORY_ID); if (ret != 0) { printf("fail\n"); } item_writer = new WriteMem(); ret = item_writer->init_paramter(MEMORY_ID+10); if (ret != 0) { printf("fail\n"); } } atlas_venc::~atlas_venc() { } Result atlas_venc::init_vnec() { Init(WIDTH, HEIGHT); return SUCCESS; } void *ThreadFuncEnc(aclrtContext sharedContext) { if (sharedContext == nullptr) { ERROR_LOG("sharedContext can not be nullptr"); return ((void *) (-1)); } INFO_LOG("use shared context for this thread"); aclError ret = aclrtSetCurrentContext(sharedContext); if (ret != ACL_SUCCESS) { ERROR_LOG("aclrtSetCurrentContext failed, errorCode = %d", static_cast<int32_t>(ret)); return ((void *) (-1)); } INFO_LOG("process callback thread start "); while (g_venc_runFlag) { // Notice: timeout 1000ms (void) aclrtProcessReport(1000); } return nullptr; } void atlas_venc::send_frame(acldvppPicDesc *input, acldvppStreamDesc *outputStreamDesc){ void *outputDev = acldvppGetStreamDescData(outputStreamDesc); uint32_t streamDescSize = acldvppGetStreamDescSize(outputStreamDesc); bool ret = true; if (this->runMode == ACL_HOST) { void *hostPtr = nullptr; aclrtMallocHost(&hostPtr, streamDescSize); aclrtMemcpy(hostPtr, streamDescSize, outputDev, streamDescSize, ACL_MEMCPY_DEVICE_TO_HOST); item_writer->write_data((uint8_t *)outputDev,streamDescSize,"venc"); //ret = WriteToFile(outFileFp, hostPtr, streamDescSize); (void) aclrtFreeHost(hostPtr); } else { // ret = WriteToFile(outFileFp, outputDev, streamDescSize); item_writer->write_data((uint8_t *)outputDev,streamDescSize,"venc"); } void *data = acldvppGetPicDescData(input); if (data != nullptr) { acldvppFree(data); } acldvppDestroyPicDesc(input); if (!ret) { ERROR_LOG("write file failed."); } INFO_LOG("success to callback, stream size:%u", streamDescSize); } //string outFileFp = fopen("../out_video.h264", "wb+"); void callback(acldvppPicDesc *input, acldvppStreamDesc *outputStreamDesc, void *userdata) { pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); printf("execute venc callback function run \n"); ((atlas_venc *)userdata)->send_frame(input,outputStreamDesc); } Result atlas_venc::InitResource() { // aclError ret = aclInit(nullptr); // if (ret != ACL_SUCCESS) { // ERROR_LOG("Acl init failed"); // return FAILED; // } // INFO_LOG("Acl init success"); // // ret = aclrtSetDevice(deviceId_); // if (ret != ACL_SUCCESS) { // ERROR_LOG("Acl open device %d failed", deviceId); // return FAILED; // } // INFO_LOG("Open device %d success", deviceId); // // ret = aclrtCreateContext(&context, deviceId); // if (ret != ACL_SUCCESS) { // ERROR_LOG("acl create context failed"); // return FAILED; // } // INFO_LOG("create context success"); //Gets whether the current application is running on host or Device aclError ret = aclrtGetRunMode(&runMode); if (ret != ACL_SUCCESS) { ERROR_LOG("acl get run mode failed"); return FAILED; } return SUCCESS; } Result atlas_venc::Init(int imgWidth, int imgHeight) { InitResource(); pthread_create(&threadId, nullptr, ThreadFuncEnc, context_); width = imgWidth; height = imgHeight; alignWidth = ALIGN_UP16(width); alignHeight = ALIGN_UP16(height); if (alignWidth == 0 || alignHeight == 0) { ERROR_LOG("InitCodeInputDesc AlignmentHelper failed. image w %d, h %d, align w%u, h%u", width, height, alignWidth, alignHeight); return FAILED; } // Allocate a large enough memory uint32_t inputBufferSize = YUV420SP_SIZE(alignWidth, alignHeight); aclError ret = acldvppMalloc(&g_codeInputBufferDev, inputBufferSize); if (ret != ACL_SUCCESS) { ERROR_LOG("Dvpp malloc InputBufferDev failed"); return FAILED; } format = static_cast<acldvppPixelFormat>(PIXEL_FORMAT_YUV_SEMIPLANAR_420); printf(" format %d\n", format); vencFrameConfig = aclvencCreateFrameConfig(); aclvencSetFrameConfigForceIFrame(vencFrameConfig, 0); vencChannelDesc = aclvencCreateChannelDesc(); if (vencChannelDesc == nullptr) { ERROR_LOG("aclvencCreateChannelDesc failed"); return FAILED; } aclvencSetChannelDescThreadId(vencChannelDesc, threadId); aclvencSetChannelDescCallback(vencChannelDesc, callback); aclvencSetChannelDescEnType(vencChannelDesc, static_cast<acldvppStreamFormat>(enType)); aclvencSetChannelDescPicFormat(vencChannelDesc, format); aclvencSetChannelDescKeyFrameInterval(vencChannelDesc, 1); aclvencSetChannelDescPicWidth(vencChannelDesc, width); aclvencSetChannelDescPicHeight(vencChannelDesc, height); aclvencSetChannelDescRcMode(vencChannelDesc, g_rcMode); aclvencSetChannelDescMaxBitRate(vencChannelDesc, g_maxBitRate); aclvencCreateChannel(vencChannelDesc); INFO_LOG("dvpp init resource ok"); return SUCCESS; } Result atlas_venc::SendFrame() { aclError ret; ret = acldvppMalloc(&g_codeInputBufferDev, inBufferSize); if (runMode == ACL_HOST) { ret = aclrtMemcpy(g_codeInputBufferDev, inBufferSize, g_inBufferDev, inBufferSize, ACL_MEMCPY_HOST_TO_DEVICE); } else { ret = aclrtMemcpy(g_codeInputBufferDev, inBufferSize, g_inBufferDev, inBufferSize, ACL_MEMCPY_DEVICE_TO_DEVICE); } vpcInputDesc = acldvppCreatePicDesc(); if (vpcInputDesc == nullptr) { ERROR_LOG("acldvppCreatePicDesc vpcInputDesc failed"); return FAILED; } acldvppSetPicDescFormat(vpcInputDesc, format); acldvppSetPicDescWidth(vpcInputDesc, width); acldvppSetPicDescHeight(vpcInputDesc, height); acldvppSetPicDescWidthStride(vpcInputDesc, alignWidth); acldvppSetPicDescHeightStride(vpcInputDesc, alignHeight); acldvppSetPicDescData(vpcInputDesc, g_codeInputBufferDev); acldvppSetPicDescSize(vpcInputDesc, inBufferSize); printf("execute venc callback function start \n"); aclvencSendFrame(vencChannelDesc, vpcInputDesc, static_cast<void *>(outputStreamDesc), vencFrameConfig, this); printf("execute venc callback function end \n"); return SUCCESS; } void atlas_venc::DestroyAclResource() { aclError ret; if (context_ != nullptr) { ret = aclrtDestroyContext(context_); if (ret != ACL_SUCCESS) { ERROR_LOG("destroy context failed"); } context_ = nullptr; } INFO_LOG("end to destroy context"); ret = aclrtResetDevice(deviceId_); if (ret != ACL_SUCCESS) { ERROR_LOG("reset device failed"); } INFO_LOG("end to reset device is %d", deviceId_); ret = aclFinalize(); if (ret != ACL_SUCCESS) { ERROR_LOG("finalize acl failed"); } INFO_LOG("end to finalize acl"); } void atlas_venc::DestroyResource() { aclvencSetFrameConfigEos(vencFrameConfig, 1); aclvencSetFrameConfigForceIFrame(vencFrameConfig, 0); aclvencSendFrame(vencChannelDesc, nullptr, nullptr, vencFrameConfig, nullptr); if (vencFrameConfig != nullptr) { (void) aclvencDestroyFrameConfig(vencFrameConfig); vencFrameConfig = nullptr; } if (vpcInputDesc != nullptr) { (void) acldvppDestroyPicDesc(vpcInputDesc); vpcInputDesc = nullptr; } if (g_codeInputBufferDev != nullptr) { (void) acldvppFree(g_codeInputBufferDev); g_codeInputBufferDev = nullptr; } if (outputStreamDesc != nullptr) { (void) acldvppDestroyStreamDesc(outputStreamDesc); outputStreamDesc = nullptr; } aclError aclRet; if (vencChannelDesc != nullptr) { aclRet = aclvencDestroyChannel(vencChannelDesc); if (aclRet != ACL_SUCCESS) { ERROR_LOG("aclvencDestroyChannel failed, aclRet = %d", aclRet); } (void) aclvencDestroyChannelDesc(vencChannelDesc); vencChannelDesc = nullptr; } g_venc_runFlag = false; void *res = nullptr; pthread_cancel(threadId); pthread_join(threadId, &res); //fclose(outFileFp); DestroyAclResource(); INFO_LOG("end to destroy Resource"); } void atlas_venc::swapYUV_I420toNV12(unsigned char *i420bytes, unsigned char *nv12bytes, int width, int height) { int nLenY = width * height; int nLenU = nLenY / 4; memcpy(nv12bytes, i420bytes, width * height); for (int i = 0; i < nLenU; i++) { nv12bytes[nLenY + 2 * i] = i420bytes[nLenY + i]; // U nv12bytes[nLenY + 2 * i + 1] = i420bytes[nLenY + nLenU + i]; // V } } void atlas_venc::BGR2YUV_nv12(const cv::Mat &src, cv::Mat &dst) { int w_img = src.cols; int h_img = src.rows; dst = cv::Mat(h_img * 1.5, w_img, CV_8UC1, cv::Scalar(0)); cv::Mat src_YUV_I420(h_img * 1.5, w_img, CV_8UC1, cv::Scalar(0)); //YUV_I420 cvtColor(src, src_YUV_I420, cv::COLOR_BGR2YUV_I420); swapYUV_I420toNV12(src_YUV_I420.data, dst.data, w_img, h_img); } void *CopyDataDeviceToDvpp(void *data, int size) { void *buffer = nullptr; auto aclRet = acldvppMalloc(&buffer, size); if (aclRet != ACL_ERROR_NONE) { ERROR_LOG("acl malloc dvpp data failed, dataSize=%u, ret=%d", size, aclRet); return nullptr; } // INFO_LOG("malloc dvpp memory size %d ok", size); // copy input to device memory aclRet = aclrtMemcpy(buffer, size, data, size, ACL_MEMCPY_DEVICE_TO_DEVICE); if (aclRet != ACL_ERROR_NONE) { ERROR_LOG("acl memcpy data to dvpp failed, size %u, error %d", size, aclRet); acldvppFree(buffer); return nullptr; } // INFO_LOG("copy data to dvpp ok"); return buffer; } void *CopyDataHostToDvpp(void *data, int size) { void *buffer = nullptr; auto aclRet = acldvppMalloc(&buffer, size); if (aclRet != ACL_ERROR_NONE) { ERROR_LOG("acl malloc dvpp data failed, dataSize=%u, ret=%d", size, aclRet); return nullptr; } // INFO_LOG("malloc dvpp memory size %d ok", size); // copy input to device memory aclRet = aclrtMemcpy(buffer, size, data, size, ACL_MEMCPY_HOST_TO_DEVICE); if (aclRet != ACL_ERROR_NONE) { ERROR_LOG("acl memcpy data to dvpp failed, size %u, error %d", size, aclRet); acldvppFree(buffer); return nullptr; } INFO_LOG("copy data to dvpp ok"); return buffer; } Result atlas_venc::CopyImageDataToDvpp(cv::Mat &srcImage) { aclrtRunMode runMode_; aclError ret = aclrtGetRunMode(&runMode_); if (ret != ACL_ERROR_NONE) { ERROR_LOG("acl get run mode failed"); return FAILED; } void *buffer = nullptr; if (runMode_ == ACL_HOST) { buffer = CopyDataHostToDvpp(srcImage.data, srcImage.rows * srcImage.cols * srcImage.elemSize()); if (buffer == nullptr) { ERROR_LOG("Copy image to device failed"); return FAILED; } } else { buffer = CopyDataDeviceToDvpp(srcImage.data, srcImage.rows * srcImage.cols * srcImage.elemSize()); if (buffer == nullptr) { ERROR_LOG("Copy image to device failed"); return FAILED; } } inBufferSize = srcImage.rows * srcImage.cols * srcImage.elemSize(); g_inBufferDev = (uint8_t *) buffer; return SUCCESS; } Result atlas_venc::process() { cv::Mat frame; auto ret = item_reader->read_data(frame, "VDEC"); if (ret != 0 || frame.empty()) { //printf("reader empty data\n"); //return -1; return FAILED; } cv::Mat yuv; BGR2YUV_nv12(frame, yuv); CopyImageDataToDvpp(yuv); SendFrame(); return SUCCESS; } void atlas_venc::destory() { DestroyResource(); } ``` 日志 ``` execute venc callback function run [INFO] success to callback, stream size:40513 execute vdec callback function run [INFO] success to callback, send stream data execute venc callback function start execute venc callback function end execute vdec callback function start execute vdec callback function end execute venc callback function run [INFO] success to callback, stream size:40970 execute vdec callback function run [INFO] success to callback, send stream data execute venc callback function start execute venc callback function end execute vdec callback function start execute vdec callback function end execute vdec callback function run execute venc callback function run [INFO] success to callback, stream size:40944 [INFO] success to callback, send stream data execute venc callback function start execute venc callback function end execute vdec callback function start execute vdec callback function end execute vdec callback function run execute venc callback function run [INFO] success to callback, stream size:40640 [INFO] success to callback, send stream data execute venc callback function start execute venc callback function end execute venc callback function run execute vdec callback function start [INFO] success to callback, stream size:40579 execute vdec callback function end execute vdec callback function run [INFO] success to callback, send stream data execute vdec callback function run execute venc callback function start execute venc callback function end execute venc callback function run execute vdec callback function start [INFO] success to callback, stream size:40663 execute vdec callback function end [INFO] success to callback, send stream data execute vdec callback function run [INFO] success to callback, send stream data execute venc callback function start execute venc callback function end execute vdec callback function start execute vdec callback function end execute venc callback function run [INFO] success to callback, stream size:40873 execute venc callback function start execute venc callback function end execute vdec callback function start execute vdec callback function end reader empty data execute vdec callback function run execute vdec callback function start execute vdec callback function end [INFO] success to callback, send stream data execute vdec callback function run [INFO] success to callback, send stream data execute venc callback function start execute venc callback function end execute vdec callback function start execute vdec callback function end reader empty data execute vdec callback function run ```
https://gitee.com/ascend/samples/issues/IAIL76#note_30525319 参考这个,从共享连续取出帧进行编码 ``` // // Created by sxj on 2024/8/25. // #include "Atlas_venc.h" #define INFO_LOG(fmt, args...) fprintf(stdout, "[INFO] " fmt "\n", ##args) #define WARN_LOG(fmt, args...) fprintf(stdout, "[WARN] " fmt "\n", ##args) #define ERROR_LOG(fmt, args...) fprintf(stderr, "[ERROR] " fmt "\n", ##args) #define YUV420SP_SIZE(width, height) ((width) * (height) * 3 / 2) #define ALIGN_UP(num, align) (((num) + (align) - 1) & ~((align) - 1)) #define ALIGN_UP2(num) ALIGN_UP(num, 2) #define ALIGN_UP16(num) ALIGN_UP(num, 16) #define ALIGN_UP128(num) ALIGN_UP(num, 128) bool g_venc_runFlag= true; extern int32_t deviceId_; extern aclrtContext context_; extern aclrtStream stream_; atlas_venc::atlas_venc() { item_reader = new ReaderMem(); aclError ret = item_reader->init_paramter(MEMORY_ID); if (ret != 0) { printf("fail\n"); } item_writer = new WriteMem(); ret = item_writer->init_paramter(MEMORY_ID+10); if (ret != 0) { printf("fail\n"); } } atlas_venc::~atlas_venc() { } Result atlas_venc::init_vnec() { Init(WIDTH, HEIGHT); return SUCCESS; } void *ThreadFuncEnc(aclrtContext sharedContext) { if (sharedContext == nullptr) { ERROR_LOG("sharedContext can not be nullptr"); return ((void *) (-1)); } INFO_LOG("use shared context for this thread"); aclError ret = aclrtSetCurrentContext(sharedContext); if (ret != ACL_SUCCESS) { ERROR_LOG("aclrtSetCurrentContext failed, errorCode = %d", static_cast<int32_t>(ret)); return ((void *) (-1)); } INFO_LOG("process callback thread start "); while (g_venc_runFlag) { // Notice: timeout 1000ms (void) aclrtProcessReport(1000); } return nullptr; } void atlas_venc::send_frame(acldvppPicDesc *input, acldvppStreamDesc *outputStreamDesc){ void *outputDev = acldvppGetStreamDescData(outputStreamDesc); uint32_t streamDescSize = acldvppGetStreamDescSize(outputStreamDesc); bool ret = true; if (this->runMode == ACL_HOST) { void *hostPtr = nullptr; aclrtMallocHost(&hostPtr, streamDescSize); aclrtMemcpy(hostPtr, streamDescSize, outputDev, streamDescSize, ACL_MEMCPY_DEVICE_TO_HOST); item_writer->write_data((uint8_t *)outputDev,streamDescSize,"venc"); //ret = WriteToFile(outFileFp, hostPtr, streamDescSize); (void) aclrtFreeHost(hostPtr); } else { // ret = WriteToFile(outFileFp, outputDev, streamDescSize); item_writer->write_data((uint8_t *)outputDev,streamDescSize,"venc"); } void *data = acldvppGetPicDescData(input); if (data != nullptr) { acldvppFree(data); } acldvppDestroyPicDesc(input); if (!ret) { ERROR_LOG("write file failed."); } INFO_LOG("success to callback, stream size:%u", streamDescSize); } //string outFileFp = fopen("../out_video.h264", "wb+"); void callback(acldvppPicDesc *input, acldvppStreamDesc *outputStreamDesc, void *userdata) { pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); printf("execute venc callback function run \n"); ((atlas_venc *)userdata)->send_frame(input,outputStreamDesc); } Result atlas_venc::InitResource() { // aclError ret = aclInit(nullptr); // if (ret != ACL_SUCCESS) { // ERROR_LOG("Acl init failed"); // return FAILED; // } // INFO_LOG("Acl init success"); // // ret = aclrtSetDevice(deviceId_); // if (ret != ACL_SUCCESS) { // ERROR_LOG("Acl open device %d failed", deviceId); // return FAILED; // } // INFO_LOG("Open device %d success", deviceId); // // ret = aclrtCreateContext(&context, deviceId); // if (ret != ACL_SUCCESS) { // ERROR_LOG("acl create context failed"); // return FAILED; // } // INFO_LOG("create context success"); //Gets whether the current application is running on host or Device aclError ret = aclrtGetRunMode(&runMode); if (ret != ACL_SUCCESS) { ERROR_LOG("acl get run mode failed"); return FAILED; } return SUCCESS; } Result atlas_venc::Init(int imgWidth, int imgHeight) { InitResource(); pthread_create(&threadId, nullptr, ThreadFuncEnc, context_); width = imgWidth; height = imgHeight; alignWidth = ALIGN_UP16(width); alignHeight = ALIGN_UP16(height); if (alignWidth == 0 || alignHeight == 0) { ERROR_LOG("InitCodeInputDesc AlignmentHelper failed. image w %d, h %d, align w%u, h%u", width, height, alignWidth, alignHeight); return FAILED; } // Allocate a large enough memory uint32_t inputBufferSize = YUV420SP_SIZE(alignWidth, alignHeight); aclError ret = acldvppMalloc(&g_codeInputBufferDev, inputBufferSize); if (ret != ACL_SUCCESS) { ERROR_LOG("Dvpp malloc InputBufferDev failed"); return FAILED; } format = static_cast<acldvppPixelFormat>(PIXEL_FORMAT_YUV_SEMIPLANAR_420); printf(" format %d\n", format); vencFrameConfig = aclvencCreateFrameConfig(); aclvencSetFrameConfigForceIFrame(vencFrameConfig, 0); vencChannelDesc = aclvencCreateChannelDesc(); if (vencChannelDesc == nullptr) { ERROR_LOG("aclvencCreateChannelDesc failed"); return FAILED; } aclvencSetChannelDescThreadId(vencChannelDesc, threadId); aclvencSetChannelDescCallback(vencChannelDesc, callback); aclvencSetChannelDescEnType(vencChannelDesc, static_cast<acldvppStreamFormat>(enType)); aclvencSetChannelDescPicFormat(vencChannelDesc, format); aclvencSetChannelDescKeyFrameInterval(vencChannelDesc, 1); aclvencSetChannelDescPicWidth(vencChannelDesc, width); aclvencSetChannelDescPicHeight(vencChannelDesc, height); aclvencSetChannelDescRcMode(vencChannelDesc, g_rcMode); aclvencSetChannelDescMaxBitRate(vencChannelDesc, g_maxBitRate); aclvencCreateChannel(vencChannelDesc); INFO_LOG("dvpp init resource ok"); return SUCCESS; } Result atlas_venc::SendFrame() { aclError ret; ret = acldvppMalloc(&g_codeInputBufferDev, inBufferSize); if (runMode == ACL_HOST) { ret = aclrtMemcpy(g_codeInputBufferDev, inBufferSize, g_inBufferDev, inBufferSize, ACL_MEMCPY_HOST_TO_DEVICE); } else { ret = aclrtMemcpy(g_codeInputBufferDev, inBufferSize, g_inBufferDev, inBufferSize, ACL_MEMCPY_DEVICE_TO_DEVICE); } vpcInputDesc = acldvppCreatePicDesc(); if (vpcInputDesc == nullptr) { ERROR_LOG("acldvppCreatePicDesc vpcInputDesc failed"); return FAILED; } acldvppSetPicDescFormat(vpcInputDesc, format); acldvppSetPicDescWidth(vpcInputDesc, width); acldvppSetPicDescHeight(vpcInputDesc, height); acldvppSetPicDescWidthStride(vpcInputDesc, alignWidth); acldvppSetPicDescHeightStride(vpcInputDesc, alignHeight); acldvppSetPicDescData(vpcInputDesc, g_codeInputBufferDev); acldvppSetPicDescSize(vpcInputDesc, inBufferSize); printf("execute venc callback function start \n"); aclvencSendFrame(vencChannelDesc, vpcInputDesc, static_cast<void *>(outputStreamDesc), vencFrameConfig, this); printf("execute venc callback function end \n"); return SUCCESS; } void atlas_venc::DestroyAclResource() { aclError ret; if (context_ != nullptr) { ret = aclrtDestroyContext(context_); if (ret != ACL_SUCCESS) { ERROR_LOG("destroy context failed"); } context_ = nullptr; } INFO_LOG("end to destroy context"); ret = aclrtResetDevice(deviceId_); if (ret != ACL_SUCCESS) { ERROR_LOG("reset device failed"); } INFO_LOG("end to reset device is %d", deviceId_); ret = aclFinalize(); if (ret != ACL_SUCCESS) { ERROR_LOG("finalize acl failed"); } INFO_LOG("end to finalize acl"); } void atlas_venc::DestroyResource() { aclvencSetFrameConfigEos(vencFrameConfig, 1); aclvencSetFrameConfigForceIFrame(vencFrameConfig, 0); aclvencSendFrame(vencChannelDesc, nullptr, nullptr, vencFrameConfig, nullptr); if (vencFrameConfig != nullptr) { (void) aclvencDestroyFrameConfig(vencFrameConfig); vencFrameConfig = nullptr; } if (vpcInputDesc != nullptr) { (void) acldvppDestroyPicDesc(vpcInputDesc); vpcInputDesc = nullptr; } if (g_codeInputBufferDev != nullptr) { (void) acldvppFree(g_codeInputBufferDev); g_codeInputBufferDev = nullptr; } if (outputStreamDesc != nullptr) { (void) acldvppDestroyStreamDesc(outputStreamDesc); outputStreamDesc = nullptr; } aclError aclRet; if (vencChannelDesc != nullptr) { aclRet = aclvencDestroyChannel(vencChannelDesc); if (aclRet != ACL_SUCCESS) { ERROR_LOG("aclvencDestroyChannel failed, aclRet = %d", aclRet); } (void) aclvencDestroyChannelDesc(vencChannelDesc); vencChannelDesc = nullptr; } g_venc_runFlag = false; void *res = nullptr; pthread_cancel(threadId); pthread_join(threadId, &res); //fclose(outFileFp); DestroyAclResource(); INFO_LOG("end to destroy Resource"); } void atlas_venc::swapYUV_I420toNV12(unsigned char *i420bytes, unsigned char *nv12bytes, int width, int height) { int nLenY = width * height; int nLenU = nLenY / 4; memcpy(nv12bytes, i420bytes, width * height); for (int i = 0; i < nLenU; i++) { nv12bytes[nLenY + 2 * i] = i420bytes[nLenY + i]; // U nv12bytes[nLenY + 2 * i + 1] = i420bytes[nLenY + nLenU + i]; // V } } void atlas_venc::BGR2YUV_nv12(const cv::Mat &src, cv::Mat &dst) { int w_img = src.cols; int h_img = src.rows; dst = cv::Mat(h_img * 1.5, w_img, CV_8UC1, cv::Scalar(0)); cv::Mat src_YUV_I420(h_img * 1.5, w_img, CV_8UC1, cv::Scalar(0)); //YUV_I420 cvtColor(src, src_YUV_I420, cv::COLOR_BGR2YUV_I420); swapYUV_I420toNV12(src_YUV_I420.data, dst.data, w_img, h_img); } void *CopyDataDeviceToDvpp(void *data, int size) { void *buffer = nullptr; auto aclRet = acldvppMalloc(&buffer, size); if (aclRet != ACL_ERROR_NONE) { ERROR_LOG("acl malloc dvpp data failed, dataSize=%u, ret=%d", size, aclRet); return nullptr; } // INFO_LOG("malloc dvpp memory size %d ok", size); // copy input to device memory aclRet = aclrtMemcpy(buffer, size, data, size, ACL_MEMCPY_DEVICE_TO_DEVICE); if (aclRet != ACL_ERROR_NONE) { ERROR_LOG("acl memcpy data to dvpp failed, size %u, error %d", size, aclRet); acldvppFree(buffer); return nullptr; } // INFO_LOG("copy data to dvpp ok"); return buffer; } void *CopyDataHostToDvpp(void *data, int size) { void *buffer = nullptr; auto aclRet = acldvppMalloc(&buffer, size); if (aclRet != ACL_ERROR_NONE) { ERROR_LOG("acl malloc dvpp data failed, dataSize=%u, ret=%d", size, aclRet); return nullptr; } // INFO_LOG("malloc dvpp memory size %d ok", size); // copy input to device memory aclRet = aclrtMemcpy(buffer, size, data, size, ACL_MEMCPY_HOST_TO_DEVICE); if (aclRet != ACL_ERROR_NONE) { ERROR_LOG("acl memcpy data to dvpp failed, size %u, error %d", size, aclRet); acldvppFree(buffer); return nullptr; } INFO_LOG("copy data to dvpp ok"); return buffer; } Result atlas_venc::CopyImageDataToDvpp(cv::Mat &srcImage) { aclrtRunMode runMode_; aclError ret = aclrtGetRunMode(&runMode_); if (ret != ACL_ERROR_NONE) { ERROR_LOG("acl get run mode failed"); return FAILED; } void *buffer = nullptr; if (runMode_ == ACL_HOST) { buffer = CopyDataHostToDvpp(srcImage.data, srcImage.rows * srcImage.cols * srcImage.elemSize()); if (buffer == nullptr) { ERROR_LOG("Copy image to device failed"); return FAILED; } } else { buffer = CopyDataDeviceToDvpp(srcImage.data, srcImage.rows * srcImage.cols * srcImage.elemSize()); if (buffer == nullptr) { ERROR_LOG("Copy image to device failed"); return FAILED; } } inBufferSize = srcImage.rows * srcImage.cols * srcImage.elemSize(); g_inBufferDev = (uint8_t *) buffer; return SUCCESS; } Result atlas_venc::process() { cv::Mat frame; auto ret = item_reader->read_data(frame, "VDEC"); if (ret != 0 || frame.empty()) { //printf("reader empty data\n"); //return -1; return FAILED; } cv::Mat yuv; BGR2YUV_nv12(frame, yuv); CopyImageDataToDvpp(yuv); SendFrame(); return SUCCESS; } void atlas_venc::destory() { DestroyResource(); } ``` 日志 ``` execute venc callback function run [INFO] success to callback, stream size:40513 execute vdec callback function run [INFO] success to callback, send stream data execute venc callback function start execute venc callback function end execute vdec callback function start execute vdec callback function end execute venc callback function run [INFO] success to callback, stream size:40970 execute vdec callback function run [INFO] success to callback, send stream data execute venc callback function start execute venc callback function end execute vdec callback function start execute vdec callback function end execute vdec callback function run execute venc callback function run [INFO] success to callback, stream size:40944 [INFO] success to callback, send stream data execute venc callback function start execute venc callback function end execute vdec callback function start execute vdec callback function end execute vdec callback function run execute venc callback function run [INFO] success to callback, stream size:40640 [INFO] success to callback, send stream data execute venc callback function start execute venc callback function end execute venc callback function run execute vdec callback function start [INFO] success to callback, stream size:40579 execute vdec callback function end execute vdec callback function run [INFO] success to callback, send stream data execute vdec callback function run execute venc callback function start execute venc callback function end execute venc callback function run execute vdec callback function start [INFO] success to callback, stream size:40663 execute vdec callback function end [INFO] success to callback, send stream data execute vdec callback function run [INFO] success to callback, send stream data execute venc callback function start execute venc callback function end execute vdec callback function start execute vdec callback function end execute venc callback function run [INFO] success to callback, stream size:40873 execute venc callback function start execute venc callback function end execute vdec callback function start execute vdec callback function end reader empty data execute vdec callback function run execute vdec callback function start execute vdec callback function end [INFO] success to callback, send stream data execute vdec callback function run [INFO] success to callback, send stream data execute venc callback function start execute venc callback function end execute vdec callback function start execute vdec callback function end reader empty data execute vdec callback function run ```
评论 (
1
)
登录
后才可以发表评论
状态
DONE
TODO
Analysing
ACCEPTED
WIP
Feedback
TEST
DONE
REJECTED
负责人
未设置
标签
未设置
项目
未立项任务
未立项任务
里程碑
未关联里程碑
未关联里程碑
Pull Requests
未关联
未关联
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
未关联
分支 (
-
)
标签 (
-
)
开始日期   -   截止日期
-
置顶选项
不置顶
置顶等级:高
置顶等级:中
置顶等级:低
优先级
不指定
严重
主要
次要
不重要
预计工期
(小时)
参与者(2)
1
https://gitee.com/ascend/samples.git
git@gitee.com:ascend/samples.git
ascend
samples
samples
点此查找更多帮助
搜索帮助
Git 命令在线学习
如何在 Gitee 导入 GitHub 仓库
Git 仓库基础操作
企业版和社区版功能对比
SSH 公钥设置
如何处理代码冲突
仓库体积过大,如何减小?
如何找回被删除的仓库数据
Gitee 产品配额说明
GitHub仓库快速导入Gitee及同步更新
什么是 Release(发行版)
将 PHP 项目自动发布到 packagist.org
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册