Home > Mobile >  Can MediaCodec output RGBA
Can MediaCodec output RGBA

Time:03-17

I call under the unity android so generated by the studio, so it calls the MediaCodec decoding H264 get picture
But the unity is rgba texture format
I like write the conversion speed is very slow
MediaCodec can directly output RGBA
The transformation code is as follows:
 
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 (& amp; Mutex);
//yuv2rgb
If # 1
PsrcY [1]=yuv;
PsrcUV=yuv + 1920 * 1080;
For (y=0; Y<1080; Y +=2)
{
PDST [0]=(unsigned int *) & amp; 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 & gt;> 8) - ((v - 128) * 183 & gt;> 8);
Rx=(v - 128) + ((v - 128) * 103 & gt;> 8);
Bx=(u - 128) + ((u - 128) * 198 & gt;> 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 (rG=y [I] + gx;
If (g> 255) g=255;
Else if (gB=y [I] + bx;
If (b> 255) b=255;
Else if (b* PDST [I/2] + +=0 xff000000 | (b<16) | (g<8) | r;
}
}
}
# endif
//pthread_mutex_unlock (& amp; Mutex);
}

  • Related