之前发了个v3s使用gstreamer的插件openmax调用cedar硬解码的主题
https://whycan.com/t_5398.html
不少小伙伴用F1C200s尝试使用遇到了问题
报了个初始化解码库失败的错误
经排查发现是配置libcedarc时要选择一个编译硬解码库的gcc
之前用v3s时这个配置项默认是arm-linux-gnueabihf 恰好是适合v3s使用的gcc
但是在F1C200s就不能用了 要进行修改
在修改完以后 继续尝试播放 发现屏幕显示一片墨绿 过一会内核崩溃了 绿的我发慌
重启还起不来 发现是有和启动相关的库被破坏掉了 要重新烧录才行能正常启动
后来排查发现是硬解码输出帧格式的问题 (但不至于内核奔溃甚至破坏启动库吧)
我们在用v3s进行硬解码时 openmax是被默认配置为输出YV12 所以v3s用起来没问题 但是到F1C200s就不行了 F1C200s只能输出MB32 (详细资料看隔壁硬解码主题8楼 https://whycan.com/t_5429.html)
所以我们只要将openmax配置修改一下 再对输出格式做个转换 就可以了
下面开始修改内容
1.配置编译硬解码库的gcc
在buildroot配置libcedarc
Target packages ->
Hardware handling ->
libcedarc ->
Arch library select
改成arm-none-linux-gnueabi
2.修改openmax
在buildroot进入目录output/build/libcedarc-master
cd output/build/libcedarc-master
修改源文件omx_vdec_aw_decoder_linux.c
vim openmax/vdec/src/omx_vdec_aw_decoder_linux.c
在结构体类型typedef struct OmxAwDecoderContext增加以下成员
char* pYV12;
VideoPicture CvtPicture;
在函数__liPrepare中
把
pCtx->mVideoConfig.eOutputPixelFormat = PIXEL_FORMAT_YV12;
改为
pCtx->mVideoConfig.eOutputPixelFormat = PIXEL_FORMAT_YUV_MB32_420;
在语句ret = InitializeVideoDecoder(pCtx->m_decoder, 上面一行添加以下内容
pCtx->pYV12 = (char*)malloc(sizeof(char) * pCtx->mStreamInfo.nWidth * pCtx->mStreamInfo.nHeight * 3 / 2);
if(pCtx->pYV12 == NULL)
{
loge("pCtx->pYV12 malloc fail\n");
return -1;
}
pCtx->CvtPicture.pData0 = pCtx->pYV12;
pCtx->CvtPicture.ePixelFormat = PIXEL_FORMAT_YV12;
在函数__liDrain中
在logv("*** picture info: w(%d),h(%d),offset,t(%d),b(%d),l(%d),r(%d)",上面一行添加以下内容
RotatePicture(pCtx->decMemOps, pCtx->pPicture, &pCtx->CvtPicture, 0, 32, 32);
将
AlignCopyYV12((unsigned char*)pOutBufHdr->pBuffer,
(unsigned char*)pCtx->pPicture->pData0,
outDef->format.video.nFrameWidth,
outDef->format.video.nFrameHeight);
改成
AlignCopyYV12((unsigned char*)pOutBufHdr->pBuffer,
(unsigned char*)pCtx->CvtPicture.pData0,
outDef->format.video.nFrameWidth,
outDef->format.video.nFrameHeight);
在函数__liGetFormat
把
pCtx->mVideoConfig.eOutputPixelFormat = PIXEL_FORMAT_YV12;
改为
pCtx->mVideoConfig.eOutputPixelFormat = PIXEL_FORMAT_YUV_MB32_420;
在函数__liClose
在if(pCtx->m_decoder != NULL)上面一行添加以下内容
if(pCtx->pYV12 != NULL)
{
free(pCtx->pYV12);
pCtx->pYV12 = NULL;
}
3.修改libcedarc 添加格式转换
修改源文件pixel_format.c
vim vdecoder/pixel_format.c
在函数ConvertPixelFormat上面添加一个函数
void MB32_CVT_YV12_(char* pSrc, char* pSrc_v, char* pDst, int nWidth, int nHeight)
{
int i = 0;
int j = 0;
int m = 0;
int n = 0;
int k = 0;
int nMbWidth = 0;
int nMbHeight = 0;
int nMbWidth_uv = 0;
int nMbHeight_uv = 0;
int nLineStride = 0;
int nLineStride_uv = 0;
int lineNum = 0;
int lineNum_uv = 0;
int offset = 0;
int offset_uv = 0;
int maxNum = 0;
char* ptr = NULL;
char* ptr_uv = NULL;
char* pDstU = NULL;
char* pDstV = NULL;
int nWidth_uv = 0;
int nHeight_uv = 0;
char bufferY[32];
char bufferV[16], bufferU[16];
int nWidthMatchFlag = 0;
int nWidthMatchFlag_uv = 0;
int nCopyMbWidth = 0;
int nCopyMbWidth_uv = 0;
char *dstAsm = NULL;
char *dst0Asm = NULL;
char *dst1Asm = NULL;
char *srcAsm = NULL;
char *srcAsm_uv = NULL;
int bCnt2 = 1;
nLineStride = (nWidth + 15) &~15;
nMbWidth = (nWidth + 31)&~31;
nMbWidth >>= 5;//n 32 width / 32
nMbHeight = (nHeight + 31)&~31;
nMbHeight >>= 5;// / 32
ptr = pSrc;
nWidthMatchFlag = 0;
nCopyMbWidth = nMbWidth - 1;
nWidth_uv = (nWidth + 1) / 2;
nHeight_uv = (nHeight + 1) / 2;
nLineStride_uv = (nWidth_uv + 7)&~7;
nMbWidth_uv = (nWidth_uv * 2 + 31)&~31;
nMbWidth_uv >>= 5;// / 32
nMbHeight_uv = (nHeight_uv + 31)&~31;
nMbHeight_uv >>= 5;// / 32
ptr_uv = pSrc_v;
pDstU = pDst + (nWidth * nHeight) + (nWidth / 2 * nHeight / 2);
pDstV = pDst + (nWidth * nHeight);
nWidthMatchFlag_uv = 0;
nCopyMbWidth_uv = nMbWidth_uv - 1;
if ((nMbWidth << 5) == nLineStride)// * 32
{
nWidthMatchFlag = 1;
nCopyMbWidth = nMbWidth;
}
if ((nMbWidth_uv << 4) == nLineStride_uv)//*16
{
nWidthMatchFlag_uv = 1;
nCopyMbWidth_uv = nMbWidth_uv;
}
for (i = 0; i < nMbHeight; i++)
{
for (j = 0; j < nCopyMbWidth; j++)
{
for (m = 0; m < 32; m++)
{
if (((i << 5) + m) >= nHeight)// * 32
{
ptr += 32;
continue;
}
srcAsm = ptr;
lineNum = (i << 5) + m; //line num * 32
offset = lineNum * nLineStride + (j << 5);// * 32
dstAsm = pDst + offset;
memcpy(dstAsm, srcAsm, 32);
if (bCnt2)
{
srcAsm_uv = ptr_uv;
lineNum_uv = (i << 4) + m; //line num i / 2 * 32
offset_uv = lineNum_uv * nLineStride_uv + (j << 4);// * 16
dst0Asm = pDstU + offset_uv;
dst1Asm = pDstV + offset_uv;
memcpy(dst0Asm, srcAsm_uv, 16);
memcpy(dst1Asm, (void *)(srcAsm_uv + 16), 16);
ptr_uv += 32;
}
ptr += 32;
}
}
if (nWidthMatchFlag != 1)
{
for (m = 0; m < 32; m++)
{
if (((i << 5) + m) >= nHeight)// * 32
{
ptr += 32;
continue;
}
dstAsm = bufferY;
srcAsm = ptr;
lineNum = (i << 5) + m; //line num * 32
offset = lineNum * nLineStride + (j << 5);// * 32
memcpy(dstAsm, srcAsm, 32);
ptr += 32;
for (k = 0; k < 32; k++)
{
if ((j * 32 + k) >= nLineStride)
{
break;
}
pDst[offset + k] = bufferY[k];
}
}
}
if (bCnt2) {
if (nWidthMatchFlag_uv != 1)
{
for (m = 0; m < 32; m++)
{
if (((i << 4) + m) >= nHeight_uv)//i / 2 * 32
{
ptr_uv += 32;
continue;
}
srcAsm = ptr_uv;
lineNum_uv = (i << 4) + m; //line num i / 2 * 32
offset = lineNum_uv * nLineStride_uv + (j << 4);// * 16
dst0Asm = bufferU;
dst1Asm = bufferV;
memcpy(dst0Asm, srcAsm, 16);
memcpy(dst1Asm, (char *)(srcAsm + 16), 16);
ptr_uv += 32;
for (k = 0; k < 16; k++)
{
if (((j << 4) + k) >= nLineStride_uv)// j * 16
{
break;
}
pDstV[offset + k] = bufferV[k];
pDstU[offset + k] = bufferU[k];
}
}
}
}
bCnt2 = !bCnt2;
}
}
在函数ConvertPixelFormat的
if(pPictureOut->ePixelFormat==PIXEL_FORMAT_YV12){
和#ifdef CEDARX_DECODER_ARM32之间添加以下内容
if(pPictureIn->ePixelFormat == PIXEL_FORMAT_YUV_MB32_420)
{
MB32_CVT_YV12(pPictureIn->pData0, pPictureIn->pData1, pPictureOut->pData0, \
pPictureIn->nWidth, pPictureIn->nHeight);
}
清除libcedarc之前的编译文件
make clean
清除buildroot对于libcedarc的编译标记
rm .stamp_built
3.和v3s一样 给gstreamer的openmax插件添加全志的颜色空间定义
cd ../gst-omx-1.16.0/
vim omx/gstomxvideo.c
在函数gst_omx_video_get_format_from_omx的switch下添加case
case OMX_COLOR_FormatYVU420Planar:
format = GST_VIDEO_FORMAT_YV12;
break;
保存退出
清除gst-omx之前的编译文件
(之前那篇帖子有人说OMX_COLOR_FormatYVU420Planar找不到定义 我估计就是这个没有清)
make clean
清除buildroot对于gst-omx的编译标记
rm .stamp_built
回到buildroot目录
cd ../../../
编译
make
这样源文件的修改就完成了 gstreamer的配置就看回上面v3s的主题
打包烧录后进入系统 进行gst-omx注册后就可以进行硬解码播放了
离线
F1C200s硬解码播放现场:
镜像和使用方法
https://whycan.com/files/members/1105/F1C200s_gst-omx硬解码镜像.zip
验证平台:
硬件 Widora R3 晕哥特供
linux 主线内核5.2荔枝派官方的
启动方式 TF卡 屏幕800 * 480
h264文件 bad_apple.mp4
最后感谢晕哥在歪朵拉R3断货时 雪中送炭 支援了我一块 真够豪爽的
最近编辑记录 逸俊晨晖 (2021-01-07 23:32:04)
离线
厉害厉害,学习了,这回可玩性就大多了,有声音吗?
我说我杀人不眨眼 你问我眼睛酸不酸?
上面搞了这么多 都是硬解视频流 声音要先把声卡配出来 然后用以下命令解码才有
gst-launch-1.0 filesrc location=bad_apple.mp4 ! qtdemux name=demux demux.audio_0 \
! queue ! decodebin ! audioconvert ! audioresample ! alsasink \
demux.video_0 ! queue ! h264parse ! omxh264dec ! videoconvert ! videoscale ! fbdevsink
离线
这个帧率有多少呢?
没测试过 肯定比bsp差一些 追求极致要配合DE 省去软件yuv转rgb环节
离线
为啥无法启动呢?没有任何输出
我估计你用F1C100s玩火了 内存不足警告
注意串口接口 歪朵拉R3的是PA2 PA3
最近编辑记录 逸俊晨晖 (2021-01-08 20:36:13)
离线
大神,帮我看看,是哪一步出错了。。
在设备树中 cedar_dev和ion 的status 项从 disabled改成okay
离线
为什么这么卡,看上去fps好低啊?
超频走起 DE走起
离线
18楼的问题已修复 修复了两个问题
1.字节对齐问题
就是https://whycan.com/t_6139.html里说的 “并且分辨率: 32的整数倍* 32的整数倍 偏离一个像素都可能导致错误。”
现在分辨率不是32整数倍的视频也可以正常播放了
2.颜色错误问题
测试其他视频发现颜色不对 现已修复
测试镜像:
F1C200s主线gstreamer使用openmax调用cedar硬解码附件20210813.zip
下楼改源文件修复问题
离线
在buildroot进入目录output/build/libcedarc-master
cd output/build/libcedarc-master
修改源文件omx_vdec_aw_decoder_linux.c
vim openmax/vdec/src/omx_vdec_aw_decoder_linux.c
在结构体类型typedef struct OmxAwDecoderContext增加以下成员
int tWidth;
int tHeight;
在
#if (ENABLE_SCALEDOWN_WHEN_RESOLUTION_MOER_THAN_1080P)
if (pCtx->mStreamInfo.nWidth > 1920
&& pCtx->mStreamInfo.nHeight > 1088)
{
pCtx->mVideoConfig.bScaleDownEn = 1;
pCtx->mVideoConfig.nHorizonScaleDownRatio = 1;
pCtx->mVideoConfig.nVerticalScaleDownRatio = 1;
}
#endif
下面添加
pCtx->tWidth = pCtx->mStreamInfo.nWidth;
pCtx->tHeight = pCtx->mStreamInfo.nHeight;
pCtx->mStreamInfo.nWidth = (pCtx->mStreamInfo.nWidth + 31) & ~31;
pCtx->mStreamInfo.nHeight = (pCtx->mStreamInfo.nHeight + 31) & ~31;
在函数
static int __liCallback(OmxDecoder* pDec, DecoderCallback callback,
void* pUserData)
上面添加一个函数
static int yv12_align_fill(char* p_dst, int w, int h, int aw, int ah)
{
int i, j;
int map = aw * ah;
int v_size = (map) >> 2;
char *pv = p_dst + map;
char *pu = pv + v_size;// / 4
int dw = aw - w;
int dh = ah -h;
int dw_h = dw / 2;
int dh_h = dh / 2;
int w_h = w / 2;
int h_h = h / 2;
int aw_h = aw / 2;
int ah_h = ah / 2;
int map_oft = aw_h * h_h;
if((w == aw) && (h == ah))
return 0;
for(i=0;i<h_h;i++)
{
for(j=0;j<dw_h;j++)
{
pv[w_h + j + aw_h * i] = 128;
pu[w_h + j + aw_h * i] = 128;
}
}
for(i=0;i<dh_h;i++)
{
for(j=0;j<aw_h;j++)
{
pv[map_oft + j + aw_h * i] = 128;
pu[map_oft + j + aw_h * i] = 128;
}
}
return 0;
}
在函数__liDrain中
RotatePicture(pCtx->decMemOps, pCtx->pPicture, &pCtx->CvtPicture, 0, 32, 32);
的下面添加
yv12_align_fill(pCtx->CvtPicture.pData0, pCtx-> tWidth, pCtx-> tWidth, pCtx->mStreamInfo.nWidth, pCtx->mStreamInfo.nHeight);
保存退出
修改源文件pixel_format.c
vim vdecoder/pixel_format.c
把函数
MB32_CVT_YV12
替换成
static void MB32_CVT_YV12(char* pSrc, char* pSrc_v, char* pDst, int nWidth, int nHeight)
{
int i = 0;
int j = 0;
int m = 0;
int n = 0;
int k = 0;
int nMbWidth = 0;
int nMbHeight = 0;
int nMbWidth_uv = 0;
int nMbHeight_uv = 0;
int nLineStride = 0;
int nLineStride_uv = 0;
int lineNum = 0;
int lineNum_uv = 0;
int offset = 0;
int offset_uv = 0;
int maxNum = 0;
char* ptr = NULL;
char* ptr_uv = NULL;
char* pDstU = NULL;
char* pDstV = NULL;
int nWidth_uv = 0;
int nHeight_uv = 0;
char bufferY[32];
char bufferV[16], bufferU[16];
int nWidthMatchFlag = 0;
int nWidthMatchFlag_uv = 0;
int nCopyMbWidth = 0;
int nCopyMbWidth_uv = 0;
char *dstAsm = NULL;
char *dst0Asm = NULL;
char *dst1Asm = NULL;
char *srcAsm = NULL;
char *srcAsm_uv = NULL;
int bCnt2 = 1;
nLineStride = (nWidth + 15) &~15;
nMbWidth = (nWidth + 31)&~31;
nMbWidth >>= 5;//n 32 width / 32
nMbHeight = (nHeight + 31)&~31;
nMbHeight >>= 5;// / 32
ptr = pSrc;
nWidthMatchFlag = 0;
nCopyMbWidth = nMbWidth - 1;
nWidth_uv = (nWidth + 1) / 2;
nHeight_uv = (nHeight + 1) / 2;
nLineStride_uv = (nWidth_uv + 7)&~7;
nMbWidth_uv = (nWidth_uv * 2 + 31)&~31;
nMbWidth_uv >>= 5;// / 32
nMbHeight_uv = (nHeight_uv + 31)&~31;
nMbHeight_uv >>= 5;// / 32
ptr_uv = pSrc_v;
pDstU = pDst + (nWidth * nHeight) + (nWidth / 2 * nHeight / 2);
pDstV = pDst + (nWidth * nHeight);
nWidthMatchFlag_uv = 0;
nCopyMbWidth_uv = nMbWidth_uv - 1;
if ((nMbWidth << 5) == nLineStride)// * 32
{
nWidthMatchFlag = 1;
nCopyMbWidth = nMbWidth;
}
if ((nMbWidth_uv << 4) == nLineStride_uv)//*16
{
nWidthMatchFlag_uv = 1;
nCopyMbWidth_uv = nMbWidth_uv;
}
for (i = 0; i < nMbHeight; i++)
{
for (j = 0; j < nCopyMbWidth; j++)
{
for (m = 0; m < 32; m++)
{
if (((i << 5) + m) >= nHeight)// * 32
{
ptr += 32;
continue;
}
srcAsm = ptr;
lineNum = (i << 5) + m; //line num * 32
offset = lineNum * nLineStride + (j << 5);// * 32
dstAsm = pDst + offset;
memcpy(dstAsm, srcAsm, 32);
if (bCnt2)
{
srcAsm_uv = ptr_uv;
lineNum_uv = (i << 4) + m; //line num i / 2 * 32
offset_uv = lineNum_uv * nLineStride_uv + (j << 4);// * 16
dst0Asm = pDstU + offset_uv;
dst1Asm = pDstV + offset_uv;
//memcpy(dst0Asm, srcAsm_uv, 16);
//memcpy(dst1Asm, (void *)(srcAsm_uv + 16), 16);
dst0Asm[0] = srcAsm_uv[0];
dst0Asm[1] = srcAsm_uv[2];
dst0Asm[2] = srcAsm_uv[4];
dst0Asm[3] = srcAsm_uv[6];
dst0Asm[4] = srcAsm_uv[8];
dst0Asm[5] = srcAsm_uv[10];
dst0Asm[6] = srcAsm_uv[12];
dst0Asm[7] = srcAsm_uv[14];
dst0Asm[8] = srcAsm_uv[16];
dst0Asm[9] = srcAsm_uv[18];
dst0Asm[10] = srcAsm_uv[20];
dst0Asm[11] = srcAsm_uv[22];
dst0Asm[12] = srcAsm_uv[24];
dst0Asm[13] = srcAsm_uv[26];
dst0Asm[14] = srcAsm_uv[28];
dst0Asm[15] = srcAsm_uv[30];
dst1Asm[0] = srcAsm_uv[1];
dst1Asm[1] = srcAsm_uv[3];
dst1Asm[2] = srcAsm_uv[5];
dst1Asm[3] = srcAsm_uv[7];
dst1Asm[4] = srcAsm_uv[9];
dst1Asm[5] = srcAsm_uv[11];
dst1Asm[6] = srcAsm_uv[13];
dst1Asm[7] = srcAsm_uv[15];
dst1Asm[8] = srcAsm_uv[17];
dst1Asm[9] = srcAsm_uv[19];
dst1Asm[10] = srcAsm_uv[21];
dst1Asm[11] = srcAsm_uv[23];
dst1Asm[12] = srcAsm_uv[25];
dst1Asm[13] = srcAsm_uv[27];
dst1Asm[14] = srcAsm_uv[29];
dst1Asm[15] = srcAsm_uv[31];
ptr_uv += 32;
}
ptr += 32;
}
}
if (nWidthMatchFlag != 1)
{
for (m = 0; m < 32; m++)
{
if (((i << 5) + m) >= nHeight)// * 32
{
ptr += 32;
continue;
}
dstAsm = bufferY;
srcAsm = ptr;
lineNum = (i << 5) + m; //line num * 32
offset = lineNum * nLineStride + (j << 5);// * 32
memcpy(dstAsm, srcAsm, 32);
ptr += 32;
for (k = 0; k < 32; k++)
{
if ((j * 32 + k) >= nLineStride)
{
break;
}
pDst[offset + k] = bufferY[k];
}
}
}
if (bCnt2) {
if (nWidthMatchFlag_uv != 1)
{
for (m = 0; m < 32; m++)
{
if (((i << 4) + m) >= nHeight_uv)//i / 2 * 32
{
ptr_uv += 32;
continue;
}
srcAsm_uv = ptr_uv;
lineNum_uv = (i << 4) + m; //line num i / 2 * 32
offset = lineNum_uv * nLineStride_uv + (j << 4);// * 16
dst0Asm = bufferU;
dst1Asm = bufferV;
//memcpy(dst0Asm, srcAsm, 16);
//memcpy(dst1Asm, (char *)(srcAsm + 16), 16);
dst0Asm[0] = srcAsm_uv[0];
dst0Asm[1] = srcAsm_uv[2];
dst0Asm[2] = srcAsm_uv[4];
dst0Asm[3] = srcAsm_uv[6];
dst0Asm[4] = srcAsm_uv[8];
dst0Asm[5] = srcAsm_uv[10];
dst0Asm[6] = srcAsm_uv[12];
dst0Asm[7] = srcAsm_uv[14];
dst0Asm[8] = srcAsm_uv[16];
dst0Asm[9] = srcAsm_uv[18];
dst0Asm[10] = srcAsm_uv[20];
dst0Asm[11] = srcAsm_uv[22];
dst0Asm[12] = srcAsm_uv[24];
dst0Asm[13] = srcAsm_uv[26];
dst0Asm[14] = srcAsm_uv[28];
dst0Asm[15] = srcAsm_uv[30];
dst1Asm[0] = srcAsm_uv[1];
dst1Asm[1] = srcAsm_uv[3];
dst1Asm[2] = srcAsm_uv[5];
dst1Asm[3] = srcAsm_uv[7];
dst1Asm[4] = srcAsm_uv[9];
dst1Asm[5] = srcAsm_uv[11];
dst1Asm[6] = srcAsm_uv[13];
dst1Asm[7] = srcAsm_uv[15];
dst1Asm[8] = srcAsm_uv[17];
dst1Asm[9] = srcAsm_uv[19];
dst1Asm[10] = srcAsm_uv[21];
dst1Asm[11] = srcAsm_uv[23];
dst1Asm[12] = srcAsm_uv[25];
dst1Asm[13] = srcAsm_uv[27];
dst1Asm[14] = srcAsm_uv[29];
dst1Asm[15] = srcAsm_uv[31];
ptr_uv += 32;
for (k = 0; k < 16; k++)
{
if (((j << 4) + k) >= nLineStride_uv)// j * 16
{
break;
}
pDstV[offset + k] = bufferV[k];
pDstU[offset + k] = bufferU[k];
}
}
}
}
bCnt2 = !bCnt2;
}
}
保存退出
清除libcedarc之前的编译文件
make clean
清除buildroot对于libcedarc的编译标记
rm .stamp_built
回到buildroot目录
cd ../../../
编译
make
这样源文件的修改就完成了
离线