RV1126 屏幕demo

RV1126 屏幕demo 杰杰 2024-01-02 11:26:03 228

RV1126 屏幕demo

1.RK_MPI_SYS_Bind绑定VI-VO

#include <assert.h>
#include <fcntl.h>
#include <getopt.h>
#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
#include <getopt.h>

#include "common/sample_common.h"
#include "librtsp/rtsp_demo.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 const struct option long_options[] = {
  {"s32CamId",required_argument,NULL,'I'},
  {"iqfiles",required_argument,NULL,'a'},
  {NULL,0,NULL,0}
};

int main(int argc,char *argv[]) {
  int ret=0;
  RK_S32 s32CamId = 0;
  char *iq_dir = NULL;
  int c=0;
  // 使用getopt_long解析命令行获取配置文件和初始化ispp1还是ispp0
  while((c=getopt_long(argc,argv,"I:a:",long_options,NULL))!=-1){
      switch(c){
        case 'a':
            iq_dir=(char *)optarg;
            break;
        case 'I':
            s32CamId=atoi(optarg);
            break;
        default:
            printf("no argument\n");
            return 0;
      }
  }
 // 初始化ispp
 ret = SAMPLE_COMM_ISP_Init(s32CamId, RK_AIQ_WORKING_MODE_NORMAL, RK_FALSE,
                                 iq_dir);
  if (ret != 0) {
    printf("isp init failed");
    return -1;
  }

 ret = SAMPLE_COMM_ISP_Run(s32CamId);
  if (ret != 0) {
    printf("isp_run failed");
    return -1;
  }

 SAMPLE_COMM_ISP_SetFrameRate(s32CamId, 30);

 RK_MPI_SYS_Init();

  // vi_init
  VI_CHN_ATTR_S vi_chn_attr;
  memset(&vi_chn_attr, 0, sizeof(vi_chn_attr));
  vi_chn_attr.pcVideoNode = "rkispp_scale0";// 摄像头节点
  vi_chn_attr.u32BufCnt = 3;
  vi_chn_attr.u32Width = 1024;
  vi_chn_attr.u32Height = 600;
  vi_chn_attr.enPixFmt = IMAGE_TYPE_NV12;
  vi_chn_attr.enBufType = VI_CHN_BUF_TYPE_MMAP;
  vi_chn_attr.enWorkMode = VI_WORK_MODE_NORMAL;
  ret = RK_MPI_VI_SetChnAttr(s32CamId, 0, &vi_chn_attr);
  ret |= RK_MPI_VI_EnableChn(s32CamId, 0);
  if (ret) {
    printf("Create vi[0] failed! ret=%d\n", ret);
    return -1;
  }

  printf("-----------enable vi channel success\n");

  // vo_init
  VO_CHN_ATTR_S stVoAttr = {0};
  memset(&stVoAttr, 0, sizeof(stVoAttr));
  stVoAttr.pcDevNode = "/dev/dri/card0"; // 屏幕节点
  stVoAttr.emPlaneType = VO_PLANE_OVERLAY;
  stVoAttr.enImgType = IMAGE_TYPE_NV12;
  stVoAttr.u16Zpos = 1;
  stVoAttr.u32Width = 1024;
  stVoAttr.u32Height = 600;
  stVoAttr.stImgRect.s32X = 0;
  stVoAttr.stImgRect.s32Y = 0;
  stVoAttr.stImgRect.u32Width = 1024;
  stVoAttr.stImgRect.u32Height = 600;
  stVoAttr.stDispRect.s32X = 0;
  stVoAttr.stDispRect.s32Y = 0;
  stVoAttr.stDispRect.u32Width = 1024;
  stVoAttr.stDispRect.u32Height = 600;
  ret = RK_MPI_VO_CreateChn(0, &stVoAttr);
  if (ret) {
    printf("Create vo[0] failed! ret=%d\n", ret);
    return -1;
  }

  printf("-----------enable vo channel success\n");


  MPP_CHN_S stSrcChn = {0};
  MPP_CHN_S stDestChn = {0};
  // 绑定VI-VO
  printf("#Bind VI[0] to VO[0]....\n");
  stSrcChn.enModId = RK_ID_VI;
  stSrcChn.s32DevId = s32CamId;
  stSrcChn.s32ChnId = 0;
  stDestChn.enModId = RK_ID_VO;
  stDestChn.s32DevId = 0;
  stDestChn.s32ChnId = 0;
  ret = RK_MPI_SYS_Bind(&stSrcChn, &stDestChn);
  if (ret) {
    printf("Bind vi[0] to vo[0] failed! ret=%d\n", ret);
    return -1;
  }
  // 捕捉信号(ctrl+c)  
  signal(SIGINT, sigterm_handler);
  while (!quit) {
      usleep(500000);
  }
  // 解绑VI-VO
  printf("%s exit!\n", __func__);
  stSrcChn.enModId = RK_ID_VI;
  stSrcChn.s32DevId = s32CamId;
  stSrcChn.s32ChnId = 0;
  stDestChn.enModId = RK_ID_VO;
  stDestChn.s32DevId = 0;
  stDestChn.s32ChnId = 0;
  ret = RK_MPI_SYS_UnBind(&stSrcChn, &stDestChn);
  if (ret) {
    printf("UnBind vi[0] to vo[0] failed! ret=%d\n", ret);
    return -1;
  }

  RK_MPI_VO_DestroyChn(0);
  RK_MPI_VI_DisableChn(s32CamId, 0);
  SAMPLE_COMM_ISP_Stop(s32CamId);
  return 0;
}

2.RK_MPI_SYS_GetMediaBuffer获取VI数据帧

#include <assert.h>
#include <fcntl.h>
#include <getopt.h>
#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
#include <getopt.h>

#include "common/sample_common.h"
#include "librtsp/rtsp_demo.h"
#include "rkmedia_api.h"
#include "rkmedia_venc.h"

static const struct option long_options[] = {
  {"s32CamId",required_argument,NULL,'I'},
  {"iqfiles",required_argument,NULL,'a'},
  {NULL,0,NULL,0}
};

int main(int argc,char *argv[]) {
  MEDIA_BUFFER buffer;
  int ret=0;
  RK_S32 s32CamId = 0;
  char *iq_dir = NULL;
  int c=0;
  // 使用getopt_long解析命令行获取配置文件和初始化ispp1还是ispp0
  while((c=getopt_long(argc,argv,"I:a:",long_options,NULL))!=-1){
      switch(c){
        case 'a':
            iq_dir=(char *)optarg;
            break;
        case 'I':
            s32CamId=atoi(optarg);
            break;
        default:
            printf("no argument\n");
            return 0;
      }
  }
 // 初始化ispp
 ret = SAMPLE_COMM_ISP_Init(s32CamId, RK_AIQ_WORKING_MODE_NORMAL, RK_FALSE,
                                 iq_dir);
  if (ret != 0) {
    printf("isp init failed");
    return -1;
  }

  ret = SAMPLE_COMM_ISP_Run(s32CamId);
  if (ret != 0) {
    printf("isp_run failed");
    return -1;
  }

 SAMPLE_COMM_ISP_SetFrameRate(s32CamId, 30);

 RK_MPI_SYS_Init();

  // vi_init
  VI_CHN_ATTR_S vi_chn_attr;
  memset(&vi_chn_attr, 0, sizeof(vi_chn_attr));
  vi_chn_attr.pcVideoNode = "rkispp_scale0"; // 摄像头节点
  vi_chn_attr.u32BufCnt = 3;
  vi_chn_attr.u32Width = 1024;
  vi_chn_attr.u32Height = 600;
  vi_chn_attr.enPixFmt = IMAGE_TYPE_NV12;
  vi_chn_attr.enBufType = VI_CHN_BUF_TYPE_MMAP;
  vi_chn_attr.enWorkMode = VI_WORK_MODE_NORMAL;
  ret = RK_MPI_VI_SetChnAttr(s32CamId, 0, &vi_chn_attr);
  ret |= RK_MPI_VI_EnableChn(s32CamId, 0);
  if (ret) {
    printf("Create vi[0] failed! ret=%d\n", ret);
    return -1;
  }

  printf("-----------enable vi channel success\n");

  // vo_init
  VO_CHN_ATTR_S stVoAttr = {0};
  memset(&stVoAttr, 0, sizeof(stVoAttr));
  stVoAttr.pcDevNode = "/dev/dri/card0"; // 屏幕节点
  stVoAttr.emPlaneType = VO_PLANE_OVERLAY;
  stVoAttr.enImgType = IMAGE_TYPE_NV12;
  stVoAttr.u16Zpos = 1;
  stVoAttr.u32Width = 1024;
  stVoAttr.u32Height = 600;
  stVoAttr.stImgRect.s32X = 0;
  stVoAttr.stImgRect.s32Y = 0;
  stVoAttr.stImgRect.u32Width = 1024;
  stVoAttr.stImgRect.u32Height = 600;
  stVoAttr.stDispRect.s32X = 0;
  stVoAttr.stDispRect.s32Y = 0;
  stVoAttr.stDispRect.u32Width = 1024;
  stVoAttr.stDispRect.u32Height = 600;
  ret = RK_MPI_VO_CreateChn(0, &stVoAttr);
  if (ret) {
    printf("Create vo[0] failed! ret=%d\n", ret);
    return -1;
  }

  printf("-----------enable vo channel success\n");

  // 启动视频流
  ret = RK_MPI_VI_StartStream(s32CamId, 0);
  if (ret) {
    printf("Start VI[0] failed! ret=%d\n", ret);
    return -1;
  }

  // 镜像
  SAMPLE_COMM_ISP_SET_mirror(0, 0);
  // 阻塞等待获取数据帧,然后发送
  while (1) {
    buffer = RK_MPI_SYS_GetMediaBuffer(RK_ID_VI, 0, -1);
    if (!buffer) {
      continue;
    }

    RK_MPI_SYS_SendMediaBuffer(RK_ID_VO, 0, buffer);
    RK_MPI_MB_ReleaseBuffer(buffer);
  }

  RK_MPI_VO_DestroyChn(0);
  RK_MPI_VI_DisableChn(s32CamId, 0);
  SAMPLE_COMM_ISP_Stop(s32CamId);

  return 0;
}
声明:本文内容由易百纳平台入驻作者撰写,文章观点仅代表作者本人,不代表易百纳立场。如有内容侵权或者其他问题,请联系本站进行删除。
杰杰
红包 点赞 收藏 评论 打赏
评论
0个
内容存在敏感词
手气红包
    易百纳技术社区暂无数据
相关专栏
置顶时间设置
结束时间
删除原因
  • 广告/SPAM
  • 恶意灌水
  • 违规内容
  • 文不对题
  • 重复发帖
打赏作者
易百纳技术社区
杰杰
您的支持将鼓励我继续创作!
打赏金额:
¥1易百纳技术社区
¥5易百纳技术社区
¥10易百纳技术社区
¥50易百纳技术社区
¥100易百纳技术社区
支付方式:
微信支付
支付宝支付
易百纳技术社区微信支付
易百纳技术社区
打赏成功!

感谢您的打赏,如若您也想被打赏,可前往 发表专栏 哦~

举报反馈

举报类型

  • 内容涉黄/赌/毒
  • 内容侵权/抄袭
  • 政治相关
  • 涉嫌广告
  • 侮辱谩骂
  • 其他

详细说明

审核成功

发布时间设置
发布时间:
是否关联周任务-专栏模块

审核失败

失败原因
备注
拼手气红包 红包规则
祝福语
恭喜发财,大吉大利!
红包金额
红包最小金额不能低于5元
红包数量
红包数量范围10~50个
余额支付
当前余额:
可前往问答、专栏板块获取收益 去获取
取 消 确 定

小包子的红包

恭喜发财,大吉大利

已领取20/40,共1.6元 红包规则

    易百纳技术社区