From e09461933635b643754a9f158041c12fe6b36f8c Mon Sep 17 00:00:00 2001 From: Marten Richter Date: Sat, 3 Nov 2012 19:32:57 +0100 Subject: [PATCH] Some fixes on cancellation points --- audioomx.cc | 32 +++++++++++++++++++++++----- videoomx.cc | 60 ++++++++++++++++++++++++++++------------------------- 2 files changed, 59 insertions(+), 33 deletions(-) diff --git a/audioomx.cc b/audioomx.cc index 978f9b3..de9264e 100644 --- a/audioomx.cc +++ b/audioomx.cc @@ -1670,6 +1670,7 @@ UINT AudioOMX::DeliverMediaPacket(MediaPacket packet, const UCHAR* buffer, if (!omx_running) return 0; // if we are not runnig do not do this if (paused) return 0; //Block if we pause + //Log::getInstance()->log("Audio", Log::DEBUG, "DMP mark 1"); //Log::getInstance()->log("Audio", Log::DEBUG, "DeliverMediaPacketOMX time %lld",packet.presentation_time); @@ -1682,7 +1683,7 @@ UINT AudioOMX::DeliverMediaPacket(MediaPacket packet, const UCHAR* buffer, return packet.length; }*/ - + //Log::getInstance()->log("Audio", Log::DEBUG, "DMP mark 2"); UINT headerstrip = 0; if (packet.disconti) { @@ -1699,7 +1700,7 @@ UINT AudioOMX::DeliverMediaPacket(MediaPacket packet, const UCHAR* buffer, } lsync=true; } - + //Log::getInstance()->log("Audio", Log::DEBUG, "DMP mark 3"); if (packet.type != lastAType) {//Format Change //Push data out ! firstsynched = false; achange=true; @@ -1715,15 +1716,22 @@ UINT AudioOMX::DeliverMediaPacket(MediaPacket packet, const UCHAR* buffer, } cur_input_buf_omx = NULL; } + int oldcancelstate; + int oldcanceltype; + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldcancelstate); + pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldcanceltype); vw->LockClock(); if (!ChangeAudioPortConfig(true)) { Log::getInstance()->log("Audio", Log::DEBUG, "Changing audio port config failed", error); } vw->UnlockClock(); + pthread_setcancelstate(oldcancelstate, NULL); + pthread_setcanceltype(oldcanceltype, NULL); lsync=true; } + //Log::getInstance()->log("Audio", Log::DEBUG, "DMP mark 4"); /*Inspect PES-Header */ if (*samplepos == 0 && packet.type != MPTYPE_MPEG_AUDIO_LAYER3) {//stripheader @@ -1750,6 +1758,7 @@ UINT AudioOMX::DeliverMediaPacket(MediaPacket packet, const UCHAR* buffer, if (!firstsynched) {// *samplepos = packet.length;//if we have not processed at least one decompress_buffer_filled=0; + //Log::getInstance()->log("Audio", Log::DEBUG, "DMP mark 5"); return packet.length;//synched packet ignore it! } } @@ -1758,6 +1767,7 @@ UINT AudioOMX::DeliverMediaPacket(MediaPacket packet, const UCHAR* buffer, input_bufs_omx_mutex.Lock(); if (input_bufs_omx_free.size()==0) { input_bufs_omx_mutex.Unlock(); + //Log::getInstance()->log("Audio", Log::DEBUG, "DMP mark 6"); //Log::getInstance()->log("Audio", Log::DEBUG, "Deliver MediaPacket no free sample"); return 0; // we do not have a free media sample @@ -1769,6 +1779,7 @@ UINT AudioOMX::DeliverMediaPacket(MediaPacket packet, const UCHAR* buffer, input_bufs_omx_free.pop_front(); input_bufs_omx_mutex.Unlock(); } + //Log::getInstance()->log("Audio", Log::DEBUG, "DMP mark 7"); if (cur_input_buf_omx->nFilledLen == 0) {//will only be changed on first packet if (packet.synched) { @@ -1803,12 +1814,14 @@ UINT AudioOMX::DeliverMediaPacket(MediaPacket packet, const UCHAR* buffer, } } + //Log::getInstance()->log("Audio", Log::DEBUG, "DMP mark 8"); if (*samplepos>packet.length) *samplepos=0; //propably the thread got interrupted and sample is not valid any more! unsigned int haveToCopy=packet.length-*samplepos; if (passthrough) { while (haveToCopy>0) { + //Log::getInstance()->log("Audio", Log::DEBUG, "DMP mark 9"); if (lsync) { unsigned int gotframesize=0; int adv=0; @@ -1838,6 +1851,7 @@ UINT AudioOMX::DeliverMediaPacket(MediaPacket packet, const UCHAR* buffer, *samplepos+=adv; } else { *samplepos=packet.length; //no ac3 sync byte + //Log::getInstance()->log("Audio", Log::DEBUG, "DMP mark 10"); return packet.length; } } @@ -1847,6 +1861,7 @@ UINT AudioOMX::DeliverMediaPacket(MediaPacket packet, const UCHAR* buffer, haveToCopy-=cancopy; cur_input_buf_omx->nFilledLen+=cancopy; *samplepos+=cancopy; + //Log::getInstance()->log("Audio", Log::DEBUG, "DMP mark 11"); error = vw->ProtOMXEmptyThisBuffer(omx_aud_rend/*dec*/, cur_input_buf_omx); if (error != OMX_ErrorNone) { @@ -1870,9 +1885,10 @@ UINT AudioOMX::DeliverMediaPacket(MediaPacket packet, const UCHAR* buffer, input_bufs_omx_free.pop_front(); input_bufs_omx_mutex.Unlock(); } - + //Log::getInstance()->log("Audio", Log::DEBUG, "DMP mark 12"); } + //Log::getInstance()->log("Audio", Log::DEBUG, "DMP mark 13"); } else { int len; @@ -1909,6 +1925,7 @@ UINT AudioOMX::DeliverMediaPacket(MediaPacket packet, const UCHAR* buffer, incoming_paket_libav.data =(uint8_t*) buffer+packet.pos_buffer+*samplepos; incoming_paket_libav.size = haveToCopy; } + //Log::getInstance()->log("Audio", Log::DEBUG, "DMP mark 18"); while (haveToCopy> 0 && errcount<3) { @@ -1962,7 +1979,7 @@ UINT AudioOMX::DeliverMediaPacket(MediaPacket packet, const UCHAR* buffer, } // else Log::getInstance()->log("Audio", Log::DEBUG,"Loop run" ); } - + //Log::getInstance()->log("Audio", Log::DEBUG, "DMP mark 19"); if (!donotdecompress) { int oldcancelstate; int oldcanceltype; @@ -1989,6 +2006,7 @@ UINT AudioOMX::DeliverMediaPacket(MediaPacket packet, const UCHAR* buffer, len=0; } //Log::getInstance()->log("Audio", Log::DEBUG, "libav out2"); + //Log::getInstance()->log("Audio", Log::DEBUG, "DMP mark 20"); if (!omx_running) { libav_mutex.Unlock(); return *samplepos; @@ -2021,6 +2039,7 @@ UINT AudioOMX::DeliverMediaPacket(MediaPacket packet, const UCHAR* buffer, framesize=haveToCopy; } } + //Log::getInstance()->log("Audio", Log::DEBUG, "DMP mark 21"); incoming_paket_libav.size =framesize; if (gotta) { @@ -2052,7 +2071,9 @@ UINT AudioOMX::DeliverMediaPacket(MediaPacket packet, const UCHAR* buffer, // Log::getInstance()->log("Audio", Log::DEBUG, // "Deliver MediaPacket no free sample"); MILLISLEEP(5); + //Log::getInstance()->log("Audio", Log::DEBUG, "DMP mark22"); if (!omx_running) return *samplepos; + //Log::getInstance()->log("Audio", Log::DEBUG, "DMP mark 23"); continue; } cur_input_buf_omx = input_bufs_omx_free.front(); @@ -2085,6 +2106,7 @@ UINT AudioOMX::DeliverMediaPacket(MediaPacket packet, const UCHAR* buffer, } } + //Log::getInstance()->log("Audio", Log::DEBUG, "DMP mark 24"); decompress_buffer_filled=0; if (haveToCopy ) { Log::getInstance()->log("Audio", Log::DEBUG,"We can not decompress %d save for later %d %x %x",haveToCopy,packet.type,incoming_paket_libav.data,packet.pos_buffer); @@ -2108,7 +2130,7 @@ UINT AudioOMX::DeliverMediaPacket(MediaPacket packet, const UCHAR* buffer, } - + //Log::getInstance()->log("Audio", Log::DEBUG, "DMP mark 25"); *samplepos=packet.length; return packet.length; diff --git a/videoomx.cc b/videoomx.cc index 548c58d..faae9a1 100644 --- a/videoomx.cc +++ b/videoomx.cc @@ -880,7 +880,6 @@ int VideoOMX::AllocateCodecsOMX() } /* TODO end */ - clock_mutex.Lock(); if (h264) { error=OMX_GetHandle(&omx_vid_dec,VPE_OMX_H264_DECODER,NULL,&callbacks); @@ -2099,6 +2098,10 @@ ULLONG VideoOMX::getCurrentTimestamp() { return 0; long long ncur_clock_time = cur_clock_time; if (omx_running) { + int oldcancelstate; + int oldcanceltype; + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldcancelstate); + pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldcanceltype); clock_mutex.Lock(); OMX_ERRORTYPE error; OMX_TIME_CONFIG_CLOCKSTATETYPE clock_conf; @@ -2129,6 +2132,8 @@ ULLONG VideoOMX::getCurrentTimestamp() { } } clock_mutex.Unlock(); + pthread_setcancelstate(oldcancelstate, NULL); + pthread_setcanceltype(oldcanceltype, NULL); } //ncur_clock_time -= startoffset; @@ -2245,8 +2250,11 @@ void VideoOMX::ResetTimeOffsets() { void VideoOMX::DeinterlaceFix() { - + int oldcancelstate; + int oldcanceltype; Demuxer* demux=Demuxer::getInstance(); + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldcancelstate); + pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldcanceltype); clock_mutex.Lock(); OMX_ERRORTYPE error; OMX_PARAM_PORTDEFINITIONTYPE port_def_type; @@ -2282,6 +2290,8 @@ void VideoOMX::DeinterlaceFix() Log::getInstance()->log("Video", Log::DEBUG, "Set OMX_IndexParamPortDefinition1 failed %x", error); clock_mutex.Unlock(); + pthread_setcancelstate(oldcancelstate, NULL); + pthread_setcanceltype(oldcanceltype, NULL); return; } @@ -2292,6 +2302,8 @@ void VideoOMX::DeinterlaceFix() Log::getInstance()->log("Video", Log::DEBUG, "Set OMX_IndexParamPortDefinition2 failed %x", error); clock_mutex.Unlock(); + pthread_setcancelstate(oldcancelstate, NULL); + pthread_setcanceltype(oldcanceltype, NULL); return; } @@ -2302,6 +2314,9 @@ void VideoOMX::DeinterlaceFix() EnablePort(omx_vid_sched,omx_shed_input_port,false); } clock_mutex.Unlock(); + pthread_setcancelstate(oldcancelstate, NULL); + pthread_setcanceltype(oldcanceltype, NULL); + } @@ -2327,7 +2342,7 @@ OMX_ERRORTYPE VideoOMX::ProtOMXEmptyThisBuffer(OMX_HANDLETYPE handle, OMX_BUFFER /* long long temp =buffer->nTimeStamp.nLowPart | ((long long) buffer->nTimeStamp.nHighPart << 32);*/ - pthread_testcancel(); + //pthread_testcancel(); pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldcancelstate); pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldcanceltype); clock_mutex.Lock(); @@ -2357,7 +2372,7 @@ OMX_ERRORTYPE VideoOMX::ProtOMXEmptyThisBuffer(OMX_HANDLETYPE handle, OMX_BUFFER clock_mutex.Unlock(); pthread_setcancelstate(oldcancelstate, NULL); pthread_setcanceltype(oldcanceltype, NULL); - pthread_testcancel(); + //pthread_testcancel(); return ret_val; } @@ -2447,29 +2462,9 @@ UINT VideoOMX::DeliverMediaPacket(MediaPacket packet, if (!omx_running) return 0; // if we are not runnig do not do this if (paused) return 0; //Block if we pause +// Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 1"); //Log::getInstance()->log("Video", Log::DEBUG, "DeliverMediaPacketOMX time %lld",packet.presentation_time); -/* if (packet.synched && packet.presentation_time <= 0) { - *samplepos = packet.length; - firstsynched = false; - Log::getInstance()->log("Video", Log::DEBUG, - "DeliverMediaPacketOMX Frameskip"); - return packet.length; - }*/ - /*if (packet.synched && FrameSkip(packet.presentation_time)) { - *samplepos=packet.length; - Log::getInstance()->log("Video", Log::DEBUG, "DeliverMediaPacketOMX Frameskip"); - *samplepos=packet.length; - return packet.length; - }*/ - //long long current_media_time=GetCurrentSystemTime()+playbacktimeoffset; -/* if (packet.synched && - (packet.presentation_time<0 /*|| // preroll skip frames - (packet.presentation_time+5000000LL)<(current_media_time)*)) { // we are late skip - Log::getInstance()->log("Video", Log::DEBUG, "DeliverMediaPacketOMX Preroll or too late %lld %lld; %lld", packet.presentation_time,current_media_time,playbacktimeoffset); - *samplepos=packet.length; - return packet.length; - }*/ OMX_ERRORTYPE error; @@ -2488,7 +2483,7 @@ UINT VideoOMX::DeliverMediaPacket(MediaPacket packet, cur_input_buf_omx=NULL; } } - + //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 2"); /*Inspect PES-Header */ // OMX_STATETYPE temp_state; @@ -2501,33 +2496,39 @@ UINT VideoOMX::DeliverMediaPacket(MediaPacket packet, *samplepos+=headerstrip; if ( packet.synched ) { if (!firstsynched) { + //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 2a"); // check if this is an I frame, the decoder does not like non I frames at startup! if (!detectIFrame(buffer,packet.length)) { *samplepos=packet.length;//if we have not processed at least one + //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 3"); return packet.length;//synched packet ignore it! } } if (cur_input_buf_omx) { + //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 4a"); cur_input_buf_omx->nFlags|=OMX_BUFFERFLAG_ENDOFFRAME; PutBufferToPres(cur_input_buf_omx); cur_input_buf_omx=NULL;//write out old data + //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 4b"); } firstsynched=true; } else { if (!firstsynched) {// *samplepos=packet.length;//if we have not processed at least one + //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 5"); return packet.length;//synched packet ignore it! } } } - + //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 6"); if (!cur_input_buf_omx) { 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, "DMP mark 7"); return 0; // we do not have a free media sample } @@ -2572,6 +2573,7 @@ UINT VideoOMX::DeliverMediaPacket(MediaPacket packet, } unsigned int haveToCopy=packet.length-*samplepos; + //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 8"); while (haveToCopy> (cur_input_buf_omx->nAllocLen-cur_input_buf_omx->nFilledLen)) { //Log::getInstance()->log("Video", Log::DEBUG, "Big buffer %d %d %d",packet.length,cur_input_buf_omx->nAllocLen,cur_input_buf_omx->nFilledLen); @@ -2581,6 +2583,7 @@ UINT VideoOMX::DeliverMediaPacket(MediaPacket packet, cur_input_buf_omx->nFilledLen+=cancopy; *samplepos+=cancopy; // push old buffer out + //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 9"); PutBufferToPres(cur_input_buf_omx); cur_input_buf_omx=NULL; @@ -2598,13 +2601,14 @@ UINT VideoOMX::DeliverMediaPacket(MediaPacket packet, cur_input_buf_omx->nTimeStamp=intToOMXTicks(0); input_bufs_omx_free.pop_front(); input_bufs_omx_mutex.Unlock(); + //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 10"); } memcpy(cur_input_buf_omx->pBuffer+cur_input_buf_omx->nFilledLen, buffer+packet.pos_buffer+*samplepos,haveToCopy); cur_input_buf_omx->nFilledLen+=haveToCopy; - +// Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 11"); *samplepos+=haveToCopy; -- 2.39.5