我在 unity 下 呼叫 android studio 生成的 so, so 里面呼叫了 MediaCodec 解碼 H264 獲得的畫面
但是 unity 的貼圖 要求的格式 是 rgba
我寫轉換的話 好像速度 非常慢
MediaCodec 能直接輸出 RGBA 嗎
轉換代碼如下:
void FillDispData(int *pdstRgba, int len)
{
int x,y;
unsigned int *pdst[2];
unsigned char *psrcY[2];
unsigned char *psrcUV;
if(nOutCnt==nInCnt)
{
//LOGD("NO DATA");
return;
}
nOutCnt=nInCnt;
//pthread_mutex_lock(&mutex);
//yuv2rgb
#if 1
psrcY[1]=yuv;
psrcUV=yuv+1920*1080;
for(y=0;y<1080;y+=2)
{
pdst[0]=(unsigned int*)&pdstRgba[(1078-y)*1920];
pdst[1]=pdst[0]+1920;
psrcY[0]=psrcY[1];psrcY[1]+=1920;
for(x=0;x<1920;x+=2)
{
int u,v,y[4],i;
int rx,gx,bx,r,g,b;
u=*psrcUV++;v=*psrcUV++;
gx=((u - 128) * 88 >> 8) - ((v - 128) * 183 >> 8);
rx=(v - 128) + ((v - 128) * 103 >> 8);
bx=(u - 128) + ((u - 128) * 198 >> 8);
y[0]=*psrcY[0]++;y[1]=*psrcY[0]++;
y[2]=*psrcY[1]++;y[3]=*psrcY[1]++;
for(i=0;i<4;i++)
{
r=y[i]+rx;
if(r>255) r=255;
else if(r<0) r=0;
g=y[i]+gx;
if(g>255) g=255;
else if(g<0) g=0;
b=y[i]+bx;
if(b>255) b=255;
else if(b<0) b=0;
*pdst[i/2]++=0xFF000000|(b<<16)|(g<<8)|r;
}
}
}
#endif
//pthread_mutex_unlock(&mutex);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/20376.html
標籤:Android
