Firefly开源社区
标题:
我使用USB摄像头采集信号,通过RK3288硬解码,显示出来的图像是黑白的
[打印本页]
作者:
ranfish
时间:
2016-1-26 15:32
标题:
我使用USB摄像头采集信号,通过RK3288硬解码,显示出来的图像是黑白的
有人碰到过这各现象吗?
作者:
Johnny.Chan
时间:
2016-1-26 16:15
使用的参数提供一下,应该是输出的颜色格式错了。
作者:
ranfish
时间:
2016-1-26 16:35
static struct VpuCodecContext* ctx = NULL;
static RK_S32 fileSize =0, pkt_size =0;
static RK_S32 ret = 0, frame_count = 0;
static DecoderOut_t decOut;
static VideoPacket_t demoPkt;
static VideoPacket_t* pkt =NULL;
static DecoderOut_t pOut = NULL;
static VPU_FRAME *frame = NULL;
static RK_S64 fakeTimeUs =0;
static RK_U8 pExtra = NULL;
static RK_U32 extraSize = 0;
static void ExitVpu();
static void InitVpu();
int main() {
//初始化
InitVpu();
//喂数据
processimage() //发出来现解码是黑白
.......
//退出
ExitVpu();
}
static void processimage (const void *p,int size) {
VPU_FRAME *frame;
RK_U32 wAlign16;
RK_U32 hAlign16;
RK_U32 frameSize;
//char name256;
char s128;
if( ( pkt NULL ) || ( pOut NULL ) || ( ctx == NULL ) || (REAL_RATE_DENOMINATOR<=0) )
{
LogInfo("vpu error");
return;
}
pkt->data = (RK_U8*)p;
pkt->capability = size;
pkt->size = size;
pkt->pts = fakeTimeUs;
fakeTimeUs += 1000000/REAL_RATE_DENOMINATOR;
pOut->size = 0;
{
//LogInfo("000000000000000000");
}
if ( ctx->decode(ctx, pkt, pOut) !=0 )
{
LogInfo("DECODE_ERR_RET(ERROR_VPU_DECODE");
return;
}
if ((pOut->size) && (pOut->data))
{
frame = (VPU_FRAME *)(pOut->data);
VPUMemLink((VPUMemLinear_t *)&(frame->vpumem));
wAlign16 = ((frame->DisplayWidth+ 15) & (~15));
hAlign16 = ((frame->DisplayHeight + 15) & (~15));
frameSize = wAlign16*hAlign16*3/2;
sprintf(s,"%d,%d,%d,%d %d",wAlign16,hAlign16,INIT_IMG_WIDTH,INIT_IMG_HEIGHT,frame->vpumem.size);
LogInfo(s);
pthread_mutex_lock(&(Lock));
REAL_WIDTH = wAlign16;
REAL_HEIGHT = hAlign16;
memcpy(ybuf,frame->vpumem.vir_addr,frameSize);
sem_post(&(updatesignal));
pthread_mutex_unlock(&(Lock));
/*
FILE *fout=NULL;
sprintf(name,"/sdcard/%dx%d.jpg",REAL_WIDTH,REAL_HEIGHT);
if(fout==NULL) fout = fopen(name, "w");
if(fout)fwrite(p,size, 1, fout);
if(fout)fclose(fout);
*/
VPUFreeLinear(&(frame->vpumem));
pOut->size = 0;
}
else
}
static void InitVpu(int iextraSize) {
memset(&demoPkt, 0, sizeof(VideoPacket_t));
pkt = &demoPkt;
pkt->data = NULL;
pkt->pts = VPU_API_NOPTS_VALUE;
pkt->dts = VPU_API_NOPTS_VALUE;
memset(&decOut, 0, sizeof(DecoderOut_t));
pOut = &decOut;
pOut->data = (RK_U8*)(malloc)(sizeof(VPU_FRAME));
if (pOut->data ==NULL) {
LogInfo("DECODE_ERR_RET(ERROR_MEMORY)");
return;
}
memset(pOut->data, 0, sizeof(VPU_FRAME));
ret = vpu_open_context(&ctx);
if (ret || (ctx ==NULL)) {
LogInfo("DECODE_ERR_RET(ERROR_MEMORY)");
return;
}
extraSize = sizeof(int) * (REAL_WIDTH*REAL_HEIGHT);
pExtra = (RK_U8*)rgb;
if (pExtra ==NULL) {
LogInfo("DECODE_ERR_RET(ERROR_MEMORY)");
return;
}
memset(pExtra, 0, extraSize);
ctx->codecType = CODEC_DECODER;
ctx->videoCoding = OMX_ON2_VIDEO_CodingMJPEG;
ctx->width = REAL_WIDTH;
ctx->height = REAL_HEIGHT;
ctx->no_thread = 1;
//ctx->enableparsing = 1;
if ((ret = ctx->init(ctx, pExtra, extraSize)) !=0) {
LogInfo("DECODE_ERR_RET(ERROR_INIT_VPU)");
ExitVpu();
return;
}
/*
vpu_api_init(&mVpu_api, OMX_ON2_VIDEO_CodingMJPEG);
decHandle = mVpu_api.get_class_On2Decoder();
mVpu_api.init_class_On2Decoder(decHandle);
*/
}
static void ExitVpu() {
if (ctx) {
vpu_close_context(&ctx);
ctx = NULL;
}
if (pkt && pkt->data) {
pkt->data = NULL;
pkt = NULL;
}
if (pOut && (pOut->data)) {
free(pOut->data);
pOut->data = NULL;
pOut = NULL;
}
pExtra = NULL;
/*
mVpu_api.deinit_class_On2Decoder(decHandle);//释放
mVpu_api.destroy_class_On2Decoder(decHandle);
*/
}
欢迎光临 Firefly开源社区 (https://dev.t-firefly.com/)
Powered by Discuz! X3.1