本文主要是介绍2021-07-23 编译 rv1126 手动编译 extra,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1/
2/lpthread rk_leasymedia 库要添加到 lib gcc
库接口复制到源码目录
3/官方源码
// Copyright 2020 Fuzhou Rockchip Electronics Co., Ltd. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.#include <assert.h>
#include <fcntl.h>
#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>#include <pthread.h>//#include "common/sample_common.h"
#include "rkmedia_api.h"
#include "rkmedia_venc.h"static bool quit = false;// 信号处理程序
static void sigterm_handler(int sig)
{
fprintf(stderr, "signal %d\n", sig);
quit = true;
}// 图像数据处理线程
static void *GetMediaBuffer(void *arg)
{
RGA_CHN rga_chn = *(RGA_CHN *)arg;
char save_path[512];//
printf("#Start %s thread, rga_chn:%d\n", __func__, rga_chn);
sprintf(save_path, "/userdata/output_%d.nv12", rga_chn);
//
FILE *save_file = fopen(save_path, "w");
if (!save_file)printf("ERROR: Open %s failed!\n", save_path);MEDIA_BUFFER mb = NULL;
int save_cnt = 0;
int recv_len;
while (!quit)
{mb = RK_MPI_SYS_GetMediaBuffer(RK_ID_RGA, rga_chn, 50);if (!mb){if (!quit){continue;}printf("chn-%d:RK_MPI_SYS_GetMediaBuffer get null buffer!\n", rga_chn);break;}recv_len = RK_MPI_MB_GetSize(mb);printf("Get Frame-chn-%d:ptr:%p, fd:%d, size:%zu, mode:%d, channel:%d, ""timestamp:%lld\n",rga_chn,RK_MPI_MB_GetPtr(mb), RK_MPI_MB_GetFD(mb), recv_len,RK_MPI_MB_GetModeID(mb), RK_MPI_MB_GetChannelID(mb),RK_MPI_MB_GetTimestamp(mb));if (save_file && (save_cnt < 1)){int rtn = fwrite(RK_MPI_MB_GetPtr(mb), 1, recv_len, save_file);fsync(fileno(save_file));printf("#Save frame-chn-%d:%d to %s, rtn = %d\n", rga_chn, save_cnt, save_path, rtn);save_cnt++;}RK_MPI_MB_ReleaseBuffer(mb);
}if (save_file)fclose(save_file);
printf("%s-chn-%d - exit\r\n", __func__, rga_chn);return NULL;
}//
int main(){
int ret = -1;
//
VI_PIPE vi_pipe_0 = 0;
VI_CHN vi_chn_1 = 1;
//
RGA_CHN rga_chn_0 = 0;
RGA_CHN rga_chn_1 = 1;
RGA_CHN rga_chn_2 = 2;// 初始化mpi sys
RK_MPI_SYS_Init();//
// 数据源,ISP20的输出:
// rkispp_m_bypass, 不支持设置分辨率,不支持缩放, NV12/NV16/YUYV/FBC0/FBC2
// rkispp_scale0, max width: 3264,最大支持 8 倍缩放, NV12/NV16/YUYV
// rkispp_scale1, max width: 1280,最大支持 8 倍缩放, NV12/NV16/YUYV
// rkispp_scale2, max width: 1280,最大支持 8 倍缩放, NV12/NV16/YUYV
//
VI_CHN_ATTR_S vi_chn_attr;
vi_chn_attr.pcVideoNode = "rkispp_scale0";
vi_chn_attr.u32BufCnt = 4;
vi_chn_attr.u32Width = 1920;
vi_chn_attr.u32Height = 1080;
vi_chn_attr.enPixFmt = IMAGE_TYPE_NV12;
vi_chn_attr.enWorkMode = VI_WORK_MODE_NORMAL;
//
ret = RK_MPI_VI_SetChnAttr(vi_pipe_0, vi_chn_1, &vi_chn_attr);
ret |= RK_MPI_VI_EnableChn(vi_pipe_0, vi_chn_1);
if (ret)
{printf("Create vi[%d] failed! ret=%d\n", vi_chn_1, ret);return -1;
}//
// 源数据配置
//
MPP_CHN_S stSrcChn;
stSrcChn.enModId = RK_ID_VI;
stSrcChn.s32DevId = vi_pipe_0;
stSrcChn.s32ChnId = vi_chn_1;//
// 输出-0
// 格式转换 IMAGE_TYPE_NV12 -> IMAGE_TYPE_YUV420P
//
RGA_ATTR_S stRgaAttr_0;
stRgaAttr_0.bEnBufPool = RK_TRUE;
stRgaAttr_0.u16BufPoolCnt = 4;
stRgaAttr_0.u16Rotaion = 0;
stRgaAttr_0.stImgIn.u32X = 0;
stRgaAttr_0.stImgIn.u32Y = 0;
stRgaAttr_0.stImgIn.imgType = IMAGE_TYPE_NV12;
stRgaAttr_0.stImgIn.u32Width = 1920;
stRgaAttr_0.stImgIn.u32Height = 1080;
stRgaAttr_0.stImgIn.u32HorStride = 1920;
stRgaAttr_0.stImgIn.u32VirStride = 1080;
stRgaAttr_0.stImgOut.u32X = 0;
stRgaAttr_0.stImgOut.u32Y = 0;
stRgaAttr_0.stImgOut.imgType = IMAGE_TYPE_YUV420P;
stRgaAttr_0.stImgOut.u32Width = 1920;
stRgaAttr_0.stImgOut.u32Height = 1080;
stRgaAttr_0.stImgOut.u32HorStride = 1920;
stRgaAttr_0.stImgOut.u32VirStride = 1080;
//
ret = RK_MPI_RGA_CreateChn(rga_chn_0, &stRgaAttr_0);
if (ret)
{printf("Create rga[%d] falied! ret=%d\n", rga_chn_0, ret);goto EXIT_0;
}pthread_t read_thread_0;
pthread_create(&read_thread_0, NULL, GetMediaBuffer, &rga_chn_0);//
MPP_CHN_S stDestChn_0;
stDestChn_0.enModId = RK_ID_RGA;
stDestChn_0.s32DevId = 0;
stDestChn_0.s32ChnId = rga_chn_0;
//
ret = RK_MPI_SYS_Bind(&stSrcChn, &stDestChn_0);
if (ret)
{printf("Bind vi[1] and rga[%d] failed! ret=%d\n", rga_chn_0, ret);goto EXIT_1;
}//
// 输出-1
// 旋转 270 度
// 缩放 1920 -> 960
// 缩放 1080 -> 544
// 格式转换 IMAGE_TYPE_NV12 -> IMAGE_TYPE_YUV420P
//
RGA_ATTR_S stRgaAttr_1;
stRgaAttr_1.bEnBufPool = RK_TRUE;
stRgaAttr_1.u16BufPoolCnt = 4;
stRgaAttr_1.u16Rotaion = 270;
stRgaAttr_1.stImgIn.u32X = 0;
stRgaAttr_1.stImgIn.u32Y = 0;
stRgaAttr_1.stImgIn.imgType = IMAGE_TYPE_NV12;
stRgaAttr_1.stImgIn.u32Width = 1920;
stRgaAttr_1.stImgIn.u32Height = 1080;
stRgaAttr_1.stImgIn.u32HorStride = 1920;
stRgaAttr_1.stImgIn.u32VirStride = 1080;
stRgaAttr_1.stImgOut.u32X = 0;
stRgaAttr_1.stImgOut.u32Y = 0;
stRgaAttr_1.stImgOut.imgType = IMAGE_TYPE_YUV420P;
stRgaAttr_1.stImgOut.u32Width = 544;
stRgaAttr_1.stImgOut.u32Height = 960;
stRgaAttr_1.stImgOut.u32HorStride = 544;
stRgaAttr_1.stImgOut.u32VirStride = 960;
//
ret = RK_MPI_RGA_CreateChn(rga_chn_1, &stRgaAttr_1);
if (ret)
{printf("Create rga[%d] falied! ret=%d\n", rga_chn_1, ret);goto EXIT_2;
}pthread_t read_thread_1;
pthread_create(&read_thread_1, NULL, GetMediaBuffer, &rga_chn_1);//
MPP_CHN_S stDestChn_1;
stDestChn_1.enModId = RK_ID_RGA;
stDestChn_1.s32DevId = 0;
stDestChn_1.s32ChnId = rga_chn_1;
//
ret = RK_MPI_SYS_Bind(&stSrcChn, &stDestChn_1);
if (ret)
{printf("Bind vi[1] and rga[%d] failed! ret=%d\n", rga_chn_1, ret);goto EXIT_3;
}//
// 输出-2
// 裁剪 1920 -> 1000, 取中间部分
// 裁剪 1080 -> 800, 取中间部分
// 格式转换 IMAGE_TYPE_NV12 -> IMAGE_TYPE_YUV420P
//
RGA_ATTR_S stRgaAttr_2;
stRgaAttr_2.bEnBufPool = RK_TRUE;
stRgaAttr_2.u16BufPoolCnt = 4;
stRgaAttr_2.u16Rotaion = 0;
stRgaAttr_2.stImgIn.u32X = 460;
stRgaAttr_2.stImgIn.u32Y = 140;
stRgaAttr_2.stImgIn.imgType = IMAGE_TYPE_NV12;
stRgaAttr_2.stImgIn.u32Width = 1000;
stRgaAttr_2.stImgIn.u32Height = 800;
stRgaAttr_2.stImgIn.u32HorStride = 1920;
stRgaAttr_2.stImgIn.u32VirStride = 1080;
stRgaAttr_2.stImgOut.u32X = 0;
stRgaAttr_2.stImgOut.u32Y = 0;
stRgaAttr_2.stImgOut.imgType = IMAGE_TYPE_YUV420P;
stRgaAttr_2.stImgOut.u32Width = 1000;
stRgaAttr_2.stImgOut.u32Height = 800;
stRgaAttr_2.stImgOut.u32HorStride = 1000;
stRgaAttr_2.stImgOut.u32VirStride = 800;
//
ret = RK_MPI_RGA_CreateChn(rga_chn_2, &stRgaAttr_2);
if (ret)
{printf("Create rga[%d] falied! ret=%d\n", rga_chn_2, ret);goto EXIT_4;
}pthread_t read_thread_2;
pthread_create(&read_thread_2, NULL, GetMediaBuffer, &rga_chn_2);//
MPP_CHN_S stDestChn_2;
stDestChn_2.enModId = RK_ID_RGA;
stDestChn_2.s32DevId = 0;
stDestChn_2.s32ChnId = rga_chn_2;
//
ret = RK_MPI_SYS_Bind(&stSrcChn, &stDestChn_2);
if (ret)
{printf("Bind vi[1] and rga[%d] failed! ret=%d\n", rga_chn_2, ret);goto EXIT_5;
}//
// 监听退出信号
//
printf("%s initial finish\n", __func__);
signal(SIGINT, sigterm_handler);//
// 等待退出信号
while (!quit)
{usleep(100);
}//
// 退出
//
ret = 0;EXIT_6:
RK_MPI_SYS_UnBind(&stSrcChn, &stDestChn_2);
EXIT_5:
RK_MPI_RGA_DestroyChn(rga_chn_2);
EXIT_4:
RK_MPI_SYS_UnBind(&stSrcChn, &stDestChn_1);
EXIT_3:
RK_MPI_RGA_DestroyChn(rga_chn_1);
EXIT_2:
RK_MPI_SYS_UnBind(&stSrcChn, &stDestChn_0);
EXIT_1:
RK_MPI_RGA_DestroyChn(rga_chn_0);
EXIT_0:
RK_MPI_VI_DisableChn(vi_pipe_0, vi_chn_1);return ret;
}
5/运行正常
这篇关于2021-07-23 编译 rv1126 手动编译 extra的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!