From d43c2477b969e8aaddd96c0ceece78c4d6ab8136 Mon Sep 17 00:00:00 2001 From: Marten Richter Date: Sun, 14 Oct 2012 16:52:09 +0200 Subject: [PATCH] Remove thread from videoomx, Code cleanup, Fix remote keys (could crash server!). --- audioomx.cc | 9 +++ log.cc | 2 +- remote.cc | 57 ++++++++------ remote.h | 4 +- remotelinux.cc | 4 +- vdr.cc | 2 +- videoomx.cc | 207 ++++++------------------------------------------- videoomx.h | 11 +-- 8 files changed, 72 insertions(+), 224 deletions(-) diff --git a/audioomx.cc b/audioomx.cc index e3bc9b5..98796f1 100644 --- a/audioomx.cc +++ b/audioomx.cc @@ -1376,6 +1376,15 @@ 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 + if (packet.synched && packet.presentation_time < 0) { + *samplepos = packet.length; + firstsynched = false; + Log::getInstance()->log("Audio", Log::DEBUG, + "DeliverMediaPacketOMX Frameskip"); + return packet.length; + } + + //Log::getInstance()->log("Audio", Log::DEBUG, "DeliverMediaPacketOMX time %lld",packet.presentation_time); UINT headerstrip = 0; if (packet.disconti) { diff --git a/log.cc b/log.cc index 2c39da1..ac80171 100644 --- a/log.cc +++ b/log.cc @@ -203,7 +203,7 @@ void Log::logLongString(const char *fromModule, int level,const char *message) int string_size=strlen(message); char buffer[100]; const char * pointer=message; - for (int str_written=0; str_writtenlog("Remote", Log::INFO, "Config General/Remote keys num keys %d",number); + char buffer[1024]; + char keybuf[1024]; + for (int i = 0; i < number; i++) { + sprintf(keybuf, "RemoteKey%d", i); + const char *keytrans = vdr->configLoad("General", keybuf); + if (keytrans) { + ULONG ul1, ul2; + ULONG uc; + if (sscanf(keytrans, "%lXI%lXK%lX", &ul1, &ul2, &uc) == 3) { + translist[((ULLONG) ul1) | ((ULLONG) ul2) << 32] = (UCHAR) uc; + } + } + + } } -char *Remote::SaveKeysConfig() +void Remote::SaveKeysConfig() { - int length=21*translist.size() +1; - char *output=new char[length]; - char *current=output; + int number=0; + char buffer[1024]; + char keybuf[1024]; RemoteTranslationList::const_iterator it; for (it = translist.begin(); it != translist.end(); it++) { - current+=snprintf(current,21,"H%08lXI%08lXK%02X", + sprintf(buffer,"%08lXI%08lXK%02X", (ULONG)it->first ,(ULONG) (it->first >> 32), it->second); + sprintf(keybuf,"RemoteKey%d",number); + VDR::getInstance()->configSave("General",keybuf,buffer); + number++; } - return output; + sprintf(buffer,"%d",number); + VDR::getInstance()->configSave("General","RemoteKeyNum",buffer); } @@ -508,12 +517,12 @@ bool Remote::loadOptionsfromServer(VDR* vdr) { // Set remote keys char * config; - config = vdr->configLoad("General", "Remote keys"); + config = vdr->configLoad("General", "RemoteKeyNum"); if (config) { - Log::getInstance()->log("Remote", Log::INFO, "Config General/Remote keys load"); - LoadKeysConfig(config); + Log::getInstance()->log("Remote", Log::INFO, "Config General/Remote keys load"); + LoadKeysConfig(vdr,config); delete[] config; } else @@ -526,8 +535,6 @@ bool Remote::loadOptionsfromServer(VDR* vdr) bool Remote::saveOptionstoServer() { - char *keyscon=SaveKeysConfig(); - VDR::getInstance()->configSave("General","Remote keys",keyscon); - delete [] keyscon; + SaveKeysConfig(); return true; } diff --git a/remote.h b/remote.h index 2a4da44..9f7b935 100644 --- a/remote.h +++ b/remote.h @@ -45,8 +45,8 @@ class Remote: public AbstractOption void setRemoteType(UCHAR type); void setHWCtoCommand(ULLONG hcw,UCHAR command); void unsetHWC(ULLONG hcw); - void LoadKeysConfig(char *cfg); - char *SaveKeysConfig(); + void LoadKeysConfig(VDR *vdr,const char*keynum); + void SaveKeysConfig(); void EnterLearningMode(UCHAR command); virtual int init(char *devName)=0; diff --git a/remotelinux.cc b/remotelinux.cc index f604f9d..221a18a 100644 --- a/remotelinux.cc +++ b/remotelinux.cc @@ -451,7 +451,7 @@ void RemoteLinux::InitHWCListwithDefaults() translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_NUMBER2)] = TWO; translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_NUMBER1)] = ONE; translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_NUMBER0)] = ZERO; - translist[W_G_HCW(W_HCW_CEC,KEY_KPDOT)] = STAR; + //translist[W_G_HCW(W_HCW_CEC,KEY_KPDOT)] = STAR; @@ -478,8 +478,6 @@ void RemoteLinux::InitHWCListwithDefaults() translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_CHANNEL_UP )] = CHANNELUP; translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_CHANNEL_DOWN)] = CHANNELDOWN; - - } #define NAMETRICK(pre, code) linux_keymap[pre ## code]= #code diff --git a/vdr.cc b/vdr.cc index b18cac0..19128ab 100644 --- a/vdr.cc +++ b/vdr.cc @@ -1037,7 +1037,7 @@ int VDR::configSave(const char* section, const char* key, const char* value) VDR_ResponsePacket* vresp = RequestResponse(&vrp); if (vresp->noResponse()) { delete vresp; return 0; } - + int toReturn = (int)vresp->extractULONG(); delete vresp; diff --git a/videoomx.cc b/videoomx.cc index 5cee6fb..b8b66bd 100644 --- a/videoomx.cc +++ b/videoomx.cc @@ -1324,7 +1324,6 @@ int VideoOMX::AllocateCodecsOMX() omx_running=true; clock_mutex.Unlock(); updateMode(); - threadStart(); setClockExecutingandRunning(); @@ -1615,10 +1614,6 @@ int VideoOMX::DestroyInputBufsOMX() //need s to be called with locked mutex } input_bufs_omx_all.clear(); input_bufs_omx_free.clear(); - input_bufs_omx_present.clear(); - input_time_present.clear(); - //input_time_pts.clear(); - //input_is_last.clear(); input_bufs_omx_mutex.Unlock(); } @@ -1759,8 +1754,6 @@ int VideoOMX::DeAllocateCodecsOMX() OMX_ERRORTYPE error; omx_running=false; Log::getInstance()->log("Video", Log::DEBUG, "enter deallocatecodecsomx"); - threadStop(); - if (cur_input_buf_omx) { cur_input_buf_omx->nFlags|=OMX_BUFFERFLAG_EOS; @@ -2216,163 +2209,8 @@ void VideoOMX::ResetTimeOffsets() { lastrefvideotime=0; lastreftimeOMX=0; lastreftimePTS=0; - //cur_pts=0; -} -/* -long long VideoOMX::GetCurrentSystemTime() -{ - struct timespec ts; - clock_gettime(CLOCK_MONOTONIC, &ts); - return ts.tv_sec*10000000LL+ts.tv_nsec/100LL; -} - -void VideoOMX::WaitUntil(long long time) -{ - struct timespec interval; - interval.tv_sec=time/10000000LL; - interval.tv_nsec=(time %10000000LL)*100LL; - while (clock_nanosleep(CLOCK_MONOTONIC,TIMER_ABSTIME,&interval,NULL)==EINTR) { - //Log::getInstance()->log("Video", Log::DEBUG, "Wait until multi"); - - }; } -bool VideoOMX::FrameSkip(long long pts) -{ - //ok first calculate the absolute time - bool skip=false; - long long target_time=pts-playbacktimeoffset; - // we have to wait untile the next frame - long long offset=Demuxer::getInstance()->getFrameRate(); - if (offset==0) offset=25; - offset=-2*10000000LL/offset; - target_time+=offset; - long long current_time=GetCurrentSystemTime(); - if (!skipping) { - if ((target_time-current_time)<-400000LL) { - skip=true; // we are too slow - skipping=true; - /* Log::getInstance()->log("Video", Log::DEBUG, - "Skipping frames1 %lld %lld %d",target_time-current_time,pts,Demuxer::getInstance()->getFrameRate()); - Log::getInstance()->log("Video", Log::DEBUG, "skip detail pts: %lld target: %lld sys: %lld off: %lld diff %lld",pts,target_time,current_time,offset, - target_time-current_time);* - } else { - skipping=false; - } - } else { - if ((target_time - current_time) < 0000LL) { //skip a bit more - skip = true; // we are too slow - skipping = true; -/* Log::getInstance()->log("Video", Log::DEBUG,"Skipping frames2 %lld %lld %d",target_time-current_time,pts,Demuxer::getInstance()->getFrameRate()); - Log::getInstance()->log("Video", Log::DEBUG, "skip detail pts: %lld target: %lld sys: %lld off: %lld diff %lld",pts,target_time,current_time,offset, - target_time-current_time);* - } else { - skipping = false; - } - - } - - return skip; -} - -void VideoOMX::FrameWaitforDisplay(long long pts) -{ - //ok first calculate the absolute time - long long target_time=pts-playbacktimeoffset; - // we have to wait untile the next frame - long long offset=Demuxer::getInstance()->getFrameRate(); - long long current_time=GetCurrentSystemTime(); - if (offset==0) offset=25; - offset=-3*10000000LL/offset; - target_time+=offset; - //Log::getInstance()->log("Video", Log::DEBUG, "Wait for display pts: %lld tg: %lld sys: %lld off: %lld diff %lld po: %lld",pts,target_time,current_time,offset, - // target_time-current_time,playbacktimeoffset); - if ((target_time-current_time)>1000000LL) target_time=current_time+1000000LL; // something is wrong do not wait too long - //Log::getInstance()->log("Video", Log::DEBUG, "Wait for display pts: %lld tg: %lld sys: %lld off: %lld diff %lld po: %lld",pts,target_time,current_time,offset, - // target_time-current_time,playbacktimeoffset); - - WaitUntil(target_time); - //Log::getInstance()->log("Video", Log::DEBUG, "Wait for display out %lld",GetCurrentSystemTime()); -} - -void VideoOMX::AdjustAudioPTS(long long pts) -{ - long long newplaybacktimeoffset=pts-GetCurrentSystemTime(); - if ((newplaybacktimeoffset-1000000LL)>playbacktimeoffset - || (newplaybacktimeoffset+1000000LL)log("Video", Log::DEBUG, "Adjust Playbackoffsettime o: %lld n: %lld", - playbacktimeoffset,newplaybacktimeoffset); - playbacktimeoffset=newplaybacktimeoffset; - - } -} -*/ -void VideoOMX::threadPostStopCleanup() -{ - //Doing nothing - //goo; - Log::getInstance()->log("Video", Log::DEBUG, - "end thread"); -} - - -void VideoOMX::threadMethod() -{ - Log::getInstance()->log("Video", Log::DEBUG, - "start thread"); - while (true) { - - OMX_BUFFERHEADERTYPE* pict=NULL; - long long time; - //bool islast; - if (!paused) { - input_bufs_omx_mutex.Lock(); - if (input_bufs_omx_present.size()>0) { - //cur_pts=input_time_pts.front(); - pict=input_bufs_omx_present.front(); - time=input_time_present.front(); - //islast=input_is_last.front(); - input_bufs_omx_present.pop_front(); - input_time_present.pop_front(); - //input_time_pts.pop_front(); - //input_is_last.pop_front(); - } - input_bufs_omx_mutex.Unlock(); - } - - if ( pict) { - //Log::getInstance()->log("Video", Log::DEBUG, - // "Got pict"); - if (time!=0 && /*FrameSkip(time)*/false && !(pict->nFlags &OMX_BUFFERFLAG_STARTTIME)) { - - input_bufs_omx_mutex.Lock(); - input_bufs_omx_free.push_back(pict); - input_bufs_omx_mutex.Unlock(); - //Log::getInstance()->log("Video", Log::DEBUG, "threadMethod Frameskip"); - - } else { - // Log::getInstance()->log("Video", Log::DEBUG, - // "prot empty this buffer in"); - //if (islast) FrameWaitforDisplay(time); - OMX_ERRORTYPE error = ProtOMXEmptyThisBuffer(omx_vid_dec, pict); - if (error != OMX_ErrorNone) { - Log::getInstance()->log("Video", Log::DEBUG, - "OMX_EmptyThisBuffer failed %x", error); - } - //Log::getInstance()->log("Video", Log::DEBUG, - // "time %lld",time); - if (deint_first_frame && dodeint) DeinterlaceFix(); - - } - } else { - MILLISLEEP(1); - } - - threadCheckExit(); - } - Log::getInstance()->log("Video", Log::DEBUG, - "end thread"); -} void VideoOMX::DeinterlaceFix() { @@ -2438,14 +2276,15 @@ void VideoOMX::DeinterlaceFix() } -void VideoOMX::PutBufferToPres(OMX_BUFFERHEADERTYPE* buffer, long long time, /*long long pts,*/bool islast) +void VideoOMX::PutBufferToPres(OMX_BUFFERHEADERTYPE* buffer) { - input_bufs_omx_mutex.Lock(); - input_bufs_omx_present.push_back(buffer); - input_time_present.push_back(time); - //input_time_pts.push_back(pts); -// input_is_last.push_back(islast); - input_bufs_omx_mutex.Unlock(); + + OMX_ERRORTYPE error = ProtOMXEmptyThisBuffer(omx_vid_dec, buffer); + if (error != OMX_ErrorNone) { + Log::getInstance()->log("Video", Log::DEBUG, + "OMX_EmptyThisBuffer failed %x", error); + } + if (deint_first_frame && dodeint) DeinterlaceFix(); } @@ -2516,6 +2355,15 @@ 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, "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"); @@ -2544,7 +2392,7 @@ UINT VideoOMX::DeliverMediaPacket(MediaPacket packet, if (packet.disconti) { firstsynched=false; if (cur_input_buf_omx) { - PutBufferToPres(cur_input_buf_omx, lastreftimeOMX,/*lastreftimePTS,*/ true); + PutBufferToPres(cur_input_buf_omx); cur_input_buf_omx=NULL; } } @@ -2562,7 +2410,7 @@ UINT VideoOMX::DeliverMediaPacket(MediaPacket packet, if ( packet.synched ) { if (cur_input_buf_omx) { cur_input_buf_omx->nFlags|=OMX_BUFFERFLAG_ENDOFFRAME; - PutBufferToPres(cur_input_buf_omx, lastreftimeOMX,/*lastreftimePTS,*/true); + PutBufferToPres(cur_input_buf_omx); cur_input_buf_omx=NULL;//write out old data @@ -2635,7 +2483,7 @@ UINT VideoOMX::DeliverMediaPacket(MediaPacket packet, *samplepos+=cancopy; // push old buffer out - PutBufferToPres(cur_input_buf_omx, lastreftimeOMX,/*lastreftimePTS,*/false); + PutBufferToPres(cur_input_buf_omx); cur_input_buf_omx=NULL; // get5 new buffer input_bufs_omx_mutex.Lock(); @@ -2725,7 +2573,7 @@ bool VideoOMX::displayIFrame(const UCHAR* buffer, UINT length) { } cur_input_buf_omx->nTimeStamp = intToOMXTicks(0); - PutBufferToPres(cur_input_buf_omx, 0,/*0,*/false); + PutBufferToPres(cur_input_buf_omx); cur_input_buf_omx = NULL; if (!cur_input_buf_omx) { @@ -2782,7 +2630,7 @@ bool VideoOMX::displayIFrame(const UCHAR* buffer, UINT length) { } cur_input_buf_omx->nTimeStamp = intToOMXTicks(0); - PutBufferToPres(cur_input_buf_omx, 0,/*0,*/false); + PutBufferToPres(cur_input_buf_omx); cur_input_buf_omx = NULL; @@ -2795,18 +2643,9 @@ int VideoOMX::EnterIframePlayback() Log::getInstance()->log("Video", Log::DEBUG, "EnterIframePlayback"); if (cur_input_buf_omx) { - PutBufferToPres(cur_input_buf_omx, lastreftimeOMX,/* lastreftimePTS,*/true); + PutBufferToPres(cur_input_buf_omx); cur_input_buf_omx = NULL; } - input_bufs_omx_mutex.Lock(); - while (input_bufs_omx_present.size()) { - input_bufs_omx_free.push_back(input_bufs_omx_present.front()); - input_bufs_omx_present.pop_front(); - } - input_time_present.clear(); - /*input_time_pts.clear(); - input_is_last.clear();*/ - input_bufs_omx_mutex.Unlock(); Log::getInstance()->log("Video", Log::DEBUG, "EnterIframePlayback 2"); ((AudioOMX*)Audio::getInstance())->DeAllocateCodecsOMX(); diff --git a/videoomx.h b/videoomx.h index ffb4e2c..395f04a 100644 --- a/videoomx.h +++ b/videoomx.h @@ -62,7 +62,7 @@ struct VPE_OMX_EVENT { class AudioVPE; -class VideoOMX : public Video, public Thread_TYPE +class VideoOMX : public Video { friend class AudioOMX; public: @@ -244,16 +244,11 @@ class VideoOMX : public Video, public Thread_TYPE vector input_bufs_omx_all; list input_bufs_omx_free; - list input_bufs_omx_present; - list input_time_present; - //list input_time_pts; - // list input_is_last; Mutex input_bufs_omx_mutex; OMX_BUFFERHEADERTYPE* cur_input_buf_omx; - void PutBufferToPres(OMX_BUFFERHEADERTYPE* buffer, long long time,/*long long pts,*/ bool is_last); - void threadMethod(); - void threadPostStopCleanup(); + void PutBufferToPres(OMX_BUFFERHEADERTYPE* buffer); + bool omx_running; -- 2.39.5