From 119eaf1c0840aaea5ff6779234f01ca9cee6bae2 Mon Sep 17 00:00:00 2001 From: Marten Richter Date: Mon, 3 Sep 2012 08:40:15 +0200 Subject: [PATCH] Fix some thread lookups,Fix deinitilitions of video omx stuff, add messages for debugging --- afeed.cc | 2 ++ audioomx.cc | 50 ++++++++++++++++++++++++---------- videoomx.cc | 77 ++++++++++++++++++++++++++++++++++++++--------------- 3 files changed, 93 insertions(+), 36 deletions(-) diff --git a/afeed.cc b/afeed.cc index ba24e52..ee0b55b 100644 --- a/afeed.cc +++ b/afeed.cc @@ -60,7 +60,9 @@ int AFeed::start() void AFeed::stop() { + Log::getInstance()->log("AFeed", Log::DEBUG, "Stop1"); threadCancel(); + Log::getInstance()->log("AFeed", Log::DEBUG, "Stop2"); } void AFeed::threadMethod() diff --git a/audioomx.cc b/audioomx.cc index 87a82d2..2d8ec88 100644 --- a/audioomx.cc +++ b/audioomx.cc @@ -952,24 +952,29 @@ int AudioOMX::DeAllocateCodecsOMX() video->LockClock(); + Log::getInstance()->log("Audio", Log::DEBUG, "deallocatecodecsomx mark 1"); if (cur_input_buf_omx) { cur_input_buf_omx->nFlags|=OMX_BUFFERFLAG_EOS; OMX_ERRORTYPE error=OMX_EmptyThisBuffer(omx_aud_rend/*dec*/,cur_input_buf_omx); if (error!=OMX_ErrorNone) { - Log::getInstance()->log("Audio", Log::DEBUG, "OMX_EmptyThisBuffer failed %x", error); + Log::getInstance()->log("Audio", Log::DEBUG, "OMX_EmptyThisBuffer 6 failed %x", error); } cur_input_buf_omx=NULL;//write out old data } + Log::getInstance()->log("Audio", Log::DEBUG, "deallocatecodecsomx mark 2"); if (omx_aud_rend/*dec*/) { // first stop the omx elements /* if (!video->ChangeComponentState(omx_aud_dec,OMX_StateIdle)) { Log::getInstance()->log("Audio", Log::DEBUG, "aud_dec ChangeComponentState"); }*/ + Log::getInstance()->log("Audio", Log::DEBUG, "deallocatecodecsomx mark 3"); video->UnlockClock(); + Log::getInstance()->log("Audio", Log::DEBUG, "deallocatecodecsomx mark 4"); video->idleClock(); + Log::getInstance()->log("Audio", Log::DEBUG, "deallocatecodecsomx mark 5"); video->LockClock(); if (!video->ChangeComponentState(omx_aud_rend,OMX_StateIdle)) { @@ -1009,6 +1014,7 @@ int AudioOMX::DeAllocateCodecsOMX() Log::getInstance()->log("Audio", Log::DEBUG, "OMX_Flush rend clock failed %x", error); } + Log::getInstance()->log("Audio", Log::DEBUG, "deallocatecodecsomx mark 6"); if (!video->CommandFinished(omx_clock,OMX_CommandFlush,omx_clock_output_port) || !video->CommandFinished(omx_aud_rend,OMX_CommandFlush,omx_rend_clock_port)) { @@ -1016,7 +1022,9 @@ int AudioOMX::DeAllocateCodecsOMX() } DestroyInputBufsOMX(); //We have to make sure that no buffers are in use + Log::getInstance()->log("Audio", Log::DEBUG, "deallocatecodecsomx mark 6a"); DeinitDecoderLibAV(); + Log::getInstance()->log("Audio", Log::DEBUG, "deallocatecodecsomx mark 7"); //todo flushing if (!video->DisablePort(omx_aud_rend,omx_rend_input_port,true)) { @@ -1067,6 +1075,7 @@ int AudioOMX::DeAllocateCodecsOMX() Log::getInstance()->log("Audio", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error); } + Log::getInstance()->log("Audio", Log::DEBUG, "deallocatecodecsomx mark 8"); //error=OMX_FreeHandle(omx_aud_dec); @@ -1294,7 +1303,7 @@ UINT AudioOMX::DeliverMediaPacket(MediaPacket packet, const UCHAR* buffer, cur_input_buf_omx); if (error != OMX_ErrorNone) { Log::getInstance()->log("Audio", Log::DEBUG, - "OMX_EmptyThisBuffer failed %x", error); + "OMX_EmptyThisBuffer 1 failed %x", error); } cur_input_buf_omx = NULL; } @@ -1310,7 +1319,7 @@ UINT AudioOMX::DeliverMediaPacket(MediaPacket packet, const UCHAR* buffer, cur_input_buf_omx); if (error != OMX_ErrorNone) { Log::getInstance()->log("Audio", Log::DEBUG, - "OMX_EmptyThisBuffer failed %x", error); + "OMX_EmptyThisBuffer 2 failed %x", error); } cur_input_buf_omx = NULL; } @@ -1334,7 +1343,7 @@ UINT AudioOMX::DeliverMediaPacket(MediaPacket packet, const UCHAR* buffer, cur_input_buf_omx); if (error != OMX_ErrorNone) { Log::getInstance()->log("Audio", Log::DEBUG, - "OMX_EmptyThisBuffer failed %x", error); + "OMX_EmptyThisBuffer 3 failed %x", error); } //FrameWaitforDisplay(lastreftimeOMX); vw->AdjustAudioPTS(correctAudioLatency(lastreftimeOMX,cur_input_buf_omx->nFilledLen/(2*2),48000)); @@ -1429,21 +1438,34 @@ UINT AudioOMX::DeliverMediaPacket(MediaPacket packet, const UCHAR* buffer, while (haveToCopy> 0 && errcount<2) { //Log::getInstance()->log("Audio", Log::DEBUG,"libav in %d %d",framesize,current_context->frame_size); + //Log::getInstance()->log("Audio", Log::DEBUG, "libav in %d %d", + // framesize, current_context->frame_size); + int oldcancelstate; + int oldcanceltype; + pthread_testcancel(); + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldcancelstate); + pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldcanceltype); libav_mutex.Lock(); - if (!omx_running || !mp23codec_context_libav || !ac3codec_context_libav) { + if (!omx_running || !mp23codec_context_libav + || !ac3codec_context_libav) { libav_mutex.Unlock(); - return 0; + return *samplepos; } - Log::getInstance()->log("Audio", Log::DEBUG,"libav in %d %d",framesize,current_context->frame_size); + libav_mutex.Unlock(); + // Log::getInstance()->log("Audio", Log::DEBUG,"libav out"); len = avcodec_decode_audio4(current_context, decode_frame_libav, &gotta, &incoming_paket_libav); - Log::getInstance()->log("Audio", Log::DEBUG,"libav out"); + //Log::getInstance()->log("Audio", Log::DEBUG, "libav out1"); + pthread_setcancelstate(oldcancelstate, NULL); + pthread_setcanceltype(oldcanceltype, NULL); + pthread_testcancel(); + + //Log::getInstance()->log("Audio", Log::DEBUG, "libav out2"); if (!omx_running) { libav_mutex.Unlock(); - return 0; + return *samplepos; } - libav_mutex.Unlock(); - // Log::getInstance()->log("Audio", Log::DEBUG,"libav out"); + if (len>0) { incoming_paket_libav.data += len; haveToCopy -= len; @@ -1472,7 +1494,7 @@ UINT AudioOMX::DeliverMediaPacket(MediaPacket packet, const UCHAR* buffer, cur_input_buf_omx); if (error != OMX_ErrorNone) { Log::getInstance()->log("Audio", Log::DEBUG, - "OMX_EmptyThisBuffer failed %x", error); + "OMX_EmptyThisBuffer 4 failed %x", error); } cur_input_buf_omx = NULL; @@ -1486,7 +1508,7 @@ UINT AudioOMX::DeliverMediaPacket(MediaPacket packet, const UCHAR* buffer, Log::getInstance()->log("Audio", Log::DEBUG, "Deliver MediaPacket no free sample"); MILLISLEEP(5); - if (!omx_running) return 0; + if (!omx_running) return *samplepos; continue; } cur_input_buf_omx = input_bufs_omx_free.front(); @@ -1521,7 +1543,7 @@ UINT AudioOMX::DeliverMediaPacket(MediaPacket packet, const UCHAR* buffer, error = OMX_EmptyThisBuffer(omx_aud_rend/*dec*/, cur_input_buf_omx); if (error != OMX_ErrorNone) { Log::getInstance()->log("Audio", Log::DEBUG, - "OMX_EmptyThisBuffer failed %x", error); + "OMX_EmptyThisBuffer 5 failed %x", error); } if (packet.synched) vw->AdjustAudioPTS(correctAudioLatency(lastreftimeOMX,cur_input_buf_omx->nFilledLen/(2*2),48000)); cur_input_buf_omx = NULL; diff --git a/videoomx.cc b/videoomx.cc index 3a04916..f15779b 100644 --- a/videoomx.cc +++ b/videoomx.cc @@ -1232,36 +1232,72 @@ int VideoOMX::DeAllocateCodecsOMX() // TODO proper deinit sequence // first flush all buffers - error=OMX_SendCommand(omx_vid_rend,OMX_CommandFlush, omx_rend_input_port, NULL); - if (error!=OMX_ErrorNone) { - Log::getInstance()->log("Video", Log::DEBUG, "OMX_Flush rend in failed %x", error); + + error = OMX_SendCommand(omx_vid_dec, OMX_CommandFlush, + omx_codec_output_port, NULL); + if (error != OMX_ErrorNone) { + Log::getInstance()->log("Video", Log::DEBUG, + "OMX_Flush codec out failed %x", error); } - if (!CommandFinished(omx_vid_rend,OMX_CommandFlush,omx_rend_input_port)) { - Log::getInstance()->log("Video", Log::DEBUG, "flush cmd shed rend failed"); + error = OMX_SendCommand(omx_vid_sched, OMX_CommandFlush, + omx_shed_input_port, NULL); + if (error != OMX_ErrorNone) { + Log::getInstance()->log("Video", Log::DEBUG, + "OMX_Flush shed in failed %x", error); + } - error=OMX_SendCommand(omx_vid_dec,OMX_CommandFlush, omx_codec_input_port, NULL); - if (error!=OMX_ErrorNone){ - Log::getInstance()->log("Video", Log::DEBUG, "OMX_Flush codec out failed %x", error); + if (!CommandFinished(omx_vid_dec, OMX_CommandFlush, + omx_codec_output_port)) { + Log::getInstance()->log("Video", Log::DEBUG, + "flush cmd codec failed"); + } + if (!CommandFinished(omx_vid_sched, OMX_CommandFlush, + omx_shed_input_port)) { + Log::getInstance()->log("Video", Log::DEBUG, + "flush cmd shed failed"); } - error=OMX_SendCommand(omx_vid_sched,OMX_CommandFlush, omx_shed_input_port, NULL); - if (error!=OMX_ErrorNone){ - Log::getInstance()->log("Video", Log::DEBUG, "OMX_Flush shed in failed %x", error); + + error = OMX_SendCommand(omx_vid_rend, OMX_CommandFlush, + omx_rend_input_port, NULL); + if (error != OMX_ErrorNone) { + Log::getInstance()->log("Video", Log::DEBUG, + "OMX_Flush rend in failed %x", error); } - if (!CommandFinished(omx_vid_dec,OMX_CommandFlush,omx_codec_output_port) || - !CommandFinished(omx_vid_sched,OMX_CommandFlush,omx_shed_input_port)) { - Log::getInstance()->log("Video", Log::DEBUG, "flush cmd codec shed failed"); + error = OMX_SendCommand(omx_vid_sched, OMX_CommandFlush, + omx_shed_output_port, NULL); + if (error != OMX_ErrorNone) { + Log::getInstance()->log("Video", Log::DEBUG, + "OMX_Flush shed out failed %x", error); + } + + if (!CommandFinished(omx_vid_rend, OMX_CommandFlush, + omx_rend_input_port)) { + Log::getInstance()->log("Video", Log::DEBUG, + "flush cmd shed rend failed"); + } + + if (!CommandFinished(omx_vid_sched, OMX_CommandFlush, + omx_shed_output_port)) { + Log::getInstance()->log("Video", Log::DEBUG, + "flush cmd shed rend failed"); + } + + + + + error=OMX_SendCommand(omx_clock,OMX_CommandFlush, omx_clock_output_port, NULL); if (error!=OMX_ErrorNone){ Log::getInstance()->log("Video", Log::DEBUG, "OMX_Flush clock out failed %x", error); @@ -1279,23 +1315,20 @@ int VideoOMX::DeAllocateCodecsOMX() Log::getInstance()->log("Video", Log::DEBUG, "flush cmd clock shed failed"); } - error=OMX_SendCommand(omx_vid_sched,OMX_CommandFlush, omx_shed_output_port, NULL); - if (error!=OMX_ErrorNone) { - Log::getInstance()->log("Video", Log::DEBUG, "OMX_Flush shed out failed %x", error); - } + error = OMX_SendCommand(omx_vid_dec, OMX_CommandFlush, + omx_codec_input_port, NULL); + if (error != OMX_ErrorNone) { + Log::getInstance()->log("Video", Log::DEBUG, + "OMX_Flush codec out failed %x", error); - if (!CommandFinished(omx_vid_sched,OMX_CommandFlush,omx_shed_output_port) ) { - Log::getInstance()->log("Video", Log::DEBUG, "flush cmd shed rend failed"); } - - DestroyInputBufsOMX(); //todo flushing -- 2.39.2