From 7b2ffc2cbbef365b67075512aa2a96b7efff3609 Mon Sep 17 00:00:00 2001 From: Marten Richter Date: Sat, 2 Jun 2012 15:54:24 +0200 Subject: [PATCH] h264 working + code cleanup --- videovpeogl.cc | 230 ++++++------------------------------------------- 1 file changed, 24 insertions(+), 206 deletions(-) diff --git a/videovpeogl.cc b/videovpeogl.cc index 508d457..866b9e9 100755 --- a/videovpeogl.cc +++ b/videovpeogl.cc @@ -463,6 +463,18 @@ int VideoVPEOGL::AllocateCodecsOMX() } + OMX_PARAM_BRCMVIDEODECODEERRORCONCEALMENTTYPE conceal; + memset(&conceal,0,sizeof(conceal)); + conceal.nSize=sizeof(conceal); + conceal.nVersion.nVersion=OMX_VERSION; + conceal.bStartWithValidFrame=OMX_FALSE; + + error=OMX_SetParameter(omx_vid_dec,OMX_IndexParamBrcmVideoDecodeErrorConcealment,&conceal); + if (error!=OMX_ErrorNone){ + Log::getInstance()->log("Video", Log::DEBUG, "OMX_IndexParamBrcmVideoDecodeErrorConcealment failed %x", error); + } + + error=OMX_GetHandle(&omx_vid_sched,VPE_OMX_VIDEO_SCHED,NULL,&callbacks); if (error!=OMX_ErrorNone){ Log::getInstance()->log("Video", Log::DEBUG, "Init OMX video scheduler failed %x", error); @@ -569,21 +581,15 @@ int VideoVPEOGL::AllocateCodecsOMX() if (!PrepareInputBufsOMX()) { - Log::getInstance()->log("Video", Log::DEBUG, "OMX mark1"); return 0; } - Log::getInstance()->log("Video", Log::DEBUG, "OMX mark2"); if (!ChangeComponentState(omx_clock,OMX_StateIdle)) { Log::getInstance()->log("Video", Log::DEBUG, "omx_clock ChangeComponentState Idle"); return 0; } - Log::getInstance()->log("Video", Log::DEBUG, "OMX mark3"); - - - error=OMX_SetupTunnel(omx_clock,omx_clock_output_port,omx_vid_sched,omx_shed_clock_port); if (error!=OMX_ErrorNone){ Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel clock to sched failed %x %d %d", error,omx_clock_output_port,omx_shed_clock_port); @@ -591,26 +597,16 @@ int VideoVPEOGL::AllocateCodecsOMX() return 0; } - Log::getInstance()->log("Video", Log::DEBUG, "OMX mark4"); - if (!EnablePort(omx_clock,omx_clock_output_port,false) || !EnablePort(omx_vid_sched,omx_shed_clock_port,false) ) { Log::getInstance()->log("Video", Log::DEBUG, "Enable Ports OMX clock shed failed"); return 0; } - Log::getInstance()->log("Video", Log::DEBUG, "OMX mark5"); - if ( !CommandFinished(omx_vid_sched,OMX_CommandPortEnable,omx_shed_clock_port)) { return 0; } - - Log::getInstance()->log("Video", Log::DEBUG, "OMX mark6"); - - - - error=OMX_SetupTunnel(omx_vid_dec,omx_codec_output_port,omx_vid_sched,omx_shed_input_port); if (error!=OMX_ErrorNone){ Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel dec to sched failed %x", error); @@ -629,42 +625,20 @@ int VideoVPEOGL::AllocateCodecsOMX() if ( !CommandFinished(omx_vid_sched,OMX_CommandPortEnable,omx_shed_input_port)) { return 0; } - - Log::getInstance()->log("Video", Log::DEBUG, "OMX mark6a"); - if (!ChangeComponentState(omx_vid_sched,OMX_StateIdle)) { Log::getInstance()->log("Video", Log::DEBUG, "vid_sched idle ChangeComponentState"); return 0; - } - Log::getInstance()->log("Video", Log::DEBUG, "OMX mark6b"); + } if (!CommandFinished(omx_clock,OMX_CommandPortEnable,omx_clock_output_port) ||!CommandFinished(omx_vid_dec,OMX_CommandPortEnable,omx_codec_output_port)){ return 0; } - Log::getInstance()->log("Video", Log::DEBUG, "OMX mark5c"); - - - - -//#error source port is enabled when destination goes idle chnage this - - - - Log::getInstance()->log("Video", Log::DEBUG, "OMX mark7"); - if (!ChangeComponentState(omx_vid_dec,OMX_StateExecuting)) { Log::getInstance()->log("Video", Log::DEBUG, "omx_vid_dec ChangeComponentState Execute"); return 0; } - Log::getInstance()->log("Video", Log::DEBUG, "OMX mark8"); - - - - - - error=OMX_SetupTunnel(omx_vid_sched,omx_shed_output_port,omx_vid_rend,omx_rend_input_port); if (error!=OMX_ErrorNone){ Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel sched to rend failed %x", error); @@ -672,34 +646,27 @@ int VideoVPEOGL::AllocateCodecsOMX() return 0; } - Log::getInstance()->log("Video", Log::DEBUG, "OMX mark9"); if (!EnablePort(omx_vid_sched,omx_shed_output_port,false) || !EnablePort(omx_vid_rend,omx_rend_input_port,false) ) { Log::getInstance()->log("Video", Log::DEBUG, "Enable Ports OMX shed rend failed"); return 0; } - Log::getInstance()->log("Video", Log::DEBUG, "OMX mark9a"); if (!CommandFinished(omx_vid_sched,OMX_CommandPortEnable,omx_shed_output_port) || !CommandFinished(omx_vid_rend,OMX_CommandPortEnable,omx_rend_input_port)) { return 0; } - Log::getInstance()->log("Video", Log::DEBUG, "OMX mark9b"); - if (!ChangeComponentState(omx_vid_rend,OMX_StateIdle)) { - Log::getInstance()->log("Video", Log::DEBUG, "vid_rend ChangeComponentState"); - return 0; - } - Log::getInstance()->log("Video", Log::DEBUG, "OMX mark9c"); - if (!ChangeComponentState(omx_vid_sched,OMX_StateExecuting)) { - Log::getInstance()->log("Video", Log::DEBUG, "omx_vid_sched ChangeComponentState Execute"); - return 0; + if (!ChangeComponentState(omx_vid_rend,OMX_StateIdle)) { + Log::getInstance()->log("Video", Log::DEBUG, "vid_rend ChangeComponentState"); + return 0; } - Log::getInstance()->log("Video", Log::DEBUG, "OMX mark9d"); - - + if (!ChangeComponentState(omx_vid_sched,OMX_StateExecuting)) { + Log::getInstance()->log("Video", Log::DEBUG, "omx_vid_sched ChangeComponentState Execute"); + return 0; + } if (!ChangeComponentState(omx_vid_rend,OMX_StateExecuting)) { Log::getInstance()->log("Video", Log::DEBUG, "omx_vid_rend ChangeComponentState Execute"); @@ -722,7 +689,7 @@ int VideoVPEOGL::AllocateCodecsOMX() return 0; } - dispconf.set=OMX_DISPLAY_SET_FULLSCREEN ; +/* dispconf.set=OMX_DISPLAY_SET_FULLSCREEN ; dispconf.fullscreen=OMX_FALSE; error=OMX_SetParameter(omx_vid_rend,OMX_IndexConfigDisplayRegion,&dispconf); if (error!=OMX_ErrorNone){ @@ -739,7 +706,7 @@ int VideoVPEOGL::AllocateCodecsOMX() if (error!=OMX_ErrorNone){ Log::getInstance()->log("Video", Log::DEBUG, "Init OMX_IndexConfigDisplayRegion failed %x", error); return 0; - } + }*/ @@ -750,112 +717,6 @@ int VideoVPEOGL::AllocateCodecsOMX() } omx_running=true; - Log::getInstance()->log("Video", Log::DEBUG, "OMX mark10"); - - - - - - -/* - error=OMX_SendCommand(omx_vid_sched,OMX_CommandStateSet,OMX_StateIdle,0); - if (error!=OMX_ErrorNone){ - Log::getInstance()->log("Video", Log::DEBUG, "vid_shed Send Command to OMX State Idle %x", error); - return 0; - } - - error=OMX_SendCommand(omx_vid_rend,OMX_CommandStateSet,OMX_StateIdle,0); - if (error!=OMX_ErrorNone){ - Log::getInstance()->log("Video", Log::DEBUG, "vid_shed Send Command to OMX State Idle %x", error); - return 0; - }*/ - - -/* - if (h264) { - OMX_NALSTREAMFORMATTYPE nalu_type; - nalu_type.nSize=sizeof(nalu_type); - nalu_type.nVersion.nVersion=OMX_VERSION; - nalu_type.nPortIndex=omx_input_port; - - error=OMX_GetParameter(omx_vid_dec,(OMX_INDEXTYPE)OMX_IndexParamNalStreamFormatSupported, &nalu_type); - - if (error!=OMX_ErrorNone) { - Log::getInstance()->log("Video", Log::DEBUG, "Getting Nalutypes failed %x", error); - } - Log::getInstance()->log("Video", Log::DEBUG, "Nalutypes %x", nalu_type.eNaluFormat); - omx_nalu_format=nalu_type.eNaluFormat; - }*/ - - - - - //TODO activate this code -/* - - - - - */ - - - - - - -/* - error=OMX_SendCommand(omx_vid_sched,OMX_CommandStateSet,OMX_StateIdle,0); - if (error!=OMX_ErrorNone){ - Log::getInstance()->log("Video", Log::DEBUG, "vid_rend Send Command to OMX State Idle %x", error); - return 0; - } - - error=OMX_SendCommand(omx_vid_rend,OMX_CommandStateSet,OMX_StateIdle,0); - if (error!=OMX_ErrorNone){ - Log::getInstance()->log("Video", Log::DEBUG, "vid_rend Send Command to OMX State Idle %x", error); - return 0; - }*/ - - - - - /* Code for querying supported formats well it says everything is supported ? - * ft_type.nIndex=0; - do { - error=OMX_GetParameter(omx_vid_dec,OMX_IndexParamVideoPortFormat,&ft_type); - if (error!=OMX_ErrorNone && error != OMX_ErrorNoMore) { - Log::getInstance()->log("Video", Log::DEBUG, "Init OMX h264 decoder OMX_SetParameter failed %x", error); - omx_can_h264=false; - } else { - Log::getInstance()->log("Video", Log::DEBUG, "OMX format found %x", ft_type.eCompressionFormat); - omx_can_h264=true; - } - ft_type.nIndex++; - }while (error==OMX_ErrorNone);*/ - - - //todo alloc buffers - - - /* - -int getHorizontalSize() { return horizontal_size; } - int getVerticalSize() { return vertical_size; } - int getAspectRatio() { return aspect_ratio; } - int getFrameRate() { return frame_rate; } - - - - - }*/ - - - - - - - - return 1; } @@ -1344,27 +1205,12 @@ UINT VideoVPEOGL::DeliverMediaSample(UCHAR* buffer, UINT *samplepos) else return 0; } -//FILE * output_hack=NULL; -//FILE * output_hack2=NULL; -//FILE * input_hack=NULL; + UINT VideoVPEOGL::DeliverMediaPacket(MediaPacket packet, const UCHAR* buffer, UINT *samplepos) { - /*if (!output_hack) { - output_hack=fopen("/home/marten/test2.h264","wb"); - - } - if (!output_hack2) { - output_hack2=fopen("/home/marten/test3.h264","wb"); - - }*/ - /*if (!input_hack) { - input_hack=fopen("/opt/vc/src/hello_pi/hello_video/test.h264","rb"); - }*/ - - if (packet.type == MPTYPE_VIDEO_H264) { @@ -1386,8 +1232,6 @@ UINT VideoVPEOGL::DeliverMediaPacket(MediaPacket packet, OMX_ERRORTYPE error; - - OMX_PARAM_PORTDEFINITIONTYPE port_image; memset(&port_image,0,sizeof(port_image)); port_image.nSize=sizeof(port_image); @@ -1399,8 +1243,6 @@ UINT VideoVPEOGL::DeliverMediaPacket(MediaPacket packet, } Log::getInstance()->log("Video", Log::DEBUG, "Image port %d %d", port_image.format.video.nFrameWidth , port_image.format.video.nFrameHeight); - - /*First Check, if we have an audio sample*/ if (iframemode) { //samplepos=0; @@ -1408,15 +1250,10 @@ UINT VideoVPEOGL::DeliverMediaPacket(MediaPacket packet, return 0; //Not in iframe mode! } - - UINT headerstrip=0; if (packet.disconti) { firstsynched=false; if (cur_input_buf_omx) { - // int read =fread(cur_input_buf_omx->pBuffer,1,cur_input_buf_omx->nFilledLen,input_hack); - Log::getInstance()->log("Video", Log::DEBUG, "Deliver MediaPacket Empty this buffer1 %d", cur_input_buf_omx->nFilledLen); - // fwrite(cur_input_buf_omx->pBuffer,1,cur_input_buf_omx->nFilledLen,output_hack); OMX_ERRORTYPE error=OMX_EmptyThisBuffer(omx_vid_dec,cur_input_buf_omx); if (error!=OMX_ErrorNone){ Log::getInstance()->log("Video", Log::DEBUG, "OMX_EmptyThisBuffer failed %x", error); @@ -1430,22 +1267,13 @@ UINT VideoVPEOGL::DeliverMediaPacket(MediaPacket packet, OMX_STATETYPE temp_state; OMX_GetState(omx_vid_dec,&temp_state); - - Log::getInstance()->log("Video", Log::DEBUG, "Deliver MediaPacket Mark1 codec state %d",temp_state); - if (*samplepos==0) {//stripheader headerstrip=buffer[packet.pos_buffer+8]+9/*is this right*/; //headerstrip+=6; //h264 *samplepos+=headerstrip; - //fwrite(buffer+packet.pos_buffer+*samplepos,1,packet.length-*samplepos,output_hack2); - Log::getInstance()->log("Video", Log::DEBUG, "Deliver MediaPacket Mark2a"); if ( packet.synched ) { - Log::getInstance()->log("Video", Log::DEBUG, "Deliver MediaPacket Mark2b"); if (cur_input_buf_omx) { - // int read =fread(cur_input_buf_omx->pBuffer,1,cur_input_buf_omx->nFilledLen,input_hack); - Log::getInstance()->log("Video", Log::DEBUG, "Deliver MediaPacket Empty this buffer2 %d", cur_input_buf_omx->nFilledLen); - //fwrite(cur_input_buf_omx->pBuffer,1,cur_input_buf_omx->nFilledLen,output_hack); OMX_ERRORTYPE error=OMX_EmptyThisBuffer(omx_vid_dec,cur_input_buf_omx); if (error!=OMX_ErrorNone){ Log::getInstance()->log("Video", Log::DEBUG, "OMX_EmptyThisBuffer failed %x", error); @@ -1458,13 +1286,11 @@ UINT VideoVPEOGL::DeliverMediaPacket(MediaPacket packet, firstsynched=true; } else { if (!firstsynched) {// - Log::getInstance()->log("Video", Log::DEBUG, "!firstsynched"); *samplepos=packet.length;//if we have not processed at least one return packet.length;//synched packet ignore it! } } } - Log::getInstance()->log("Video", Log::DEBUG, "Deliver MediaPacket Mark3"); if (!cur_input_buf_omx) { input_bufs_omx_mutex.Lock(); @@ -1483,8 +1309,6 @@ UINT VideoVPEOGL::DeliverMediaPacket(MediaPacket packet, } - Log::getInstance()->log("Video", Log::DEBUG, "Deliver MediaPacket fillinge"); - if (cur_input_buf_omx->nFilledLen==0) {//will only be changed on first packet @@ -1494,7 +1318,6 @@ UINT VideoVPEOGL::DeliverMediaPacket(MediaPacket packet, ms->SetDiscontinuity(FALSE); }*/ //if (packet.synched) { - Log::getInstance()->log("Video", Log::DEBUG, "Deliver MediaPacket fillinge test 2"); //lastreftimePTS=packet.pts; if (omx_first_frame) { // TODO time @@ -1514,7 +1337,6 @@ UINT VideoVPEOGL::DeliverMediaPacket(MediaPacket packet, } unsigned int haveToCopy=packet.length-*samplepos; - Log::getInstance()->log("Video", Log::DEBUG, "Buffersize: %d %d",cur_input_buf_omx->nAllocLen, haveToCopy); while (haveToCopy> (cur_input_buf_omx->nAllocLen-cur_input_buf_omx->nFilledLen)) { unsigned int cancopy=cur_input_buf_omx->nAllocLen-cur_input_buf_omx->nFilledLen; memcpy(cur_input_buf_omx->pBuffer+cur_input_buf_omx->nFilledLen,buffer+packet.pos_buffer+*samplepos,cancopy); @@ -1522,9 +1344,6 @@ UINT VideoVPEOGL::DeliverMediaPacket(MediaPacket packet, cur_input_buf_omx->nFilledLen+=cancopy; *samplepos+=cancopy; // push old buffer out - //int read =fread(cur_input_buf_omx->pBuffer,1,cur_input_buf_omx->nFilledLen,input_hack); - Log::getInstance()->log("Video", Log::DEBUG, "Deliver MediaPacket Empty this buffer3 %d", cur_input_buf_omx->nFilledLen); - //fwrite(cur_input_buf_omx->pBuffer,1,cur_input_buf_omx->nFilledLen,output_hack); OMX_ERRORTYPE error=OMX_EmptyThisBuffer(omx_vid_dec,cur_input_buf_omx); if (error!=OMX_ErrorNone){ @@ -1534,7 +1353,7 @@ UINT VideoVPEOGL::DeliverMediaPacket(MediaPacket packet, input_bufs_omx_mutex.Lock(); if (input_bufs_omx_free.size()==0) { input_bufs_omx_mutex.Unlock(); - Log::getInstance()->log("Video", Log::DEBUG, "Deliver MediaPacket no free sample"); + //Log::getInstance()->log("Video", Log::DEBUG, "Deliver MediaPacket no free sample"); return *samplepos; // we do not have a free media sample } cur_input_buf_omx=input_bufs_omx_free.front(); @@ -1549,7 +1368,6 @@ UINT VideoVPEOGL::DeliverMediaPacket(MediaPacket packet, } memcpy(cur_input_buf_omx->pBuffer+cur_input_buf_omx->nFilledLen, buffer+packet.pos_buffer+*samplepos,haveToCopy); -// fwrite(buffer+packet.pos_buffer+*samplepos,1,haveToCopy,output_hack); cur_input_buf_omx->nFilledLen+=haveToCopy; -- 2.39.5