Remove thread from videoomx, Code cleanup, Fix remote keys (could crash server!).
authorMarten Richter <marten.richter@freenet.de>
Sun, 14 Oct 2012 14:52:09 +0000 (16:52 +0200)
committerMarten Richter <marten.richter@freenet.de>
Sun, 14 Oct 2012 14:52:09 +0000 (16:52 +0200)
audioomx.cc
log.cc
remote.cc
remote.h
remotelinux.cc
vdr.cc
videoomx.cc
videoomx.h

index e3bc9b5ea5aef1e67569372cd262f0f0760a1a39..98796f12a02bc051acece7d33e1d03f0799bc7c1 100644 (file)
@@ -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 2c39da11613c991ef8ad02c5573a3f5ef89ea873..ac80171e65af8d8d8847f084bde36817a8419f93 100644 (file)
--- 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);\r
        char buffer[100];\r
        const char * pointer=message;\r
-       for (int str_written=0; str_written<string_size;str_written+=119) {\r
+       for (int str_written=0; str_written<string_size;str_written+=99) {\r
                strncpy(buffer,pointer,99);\r
                buffer[99]=0;\r
                pointer+=99;\r
index 7c20b6f3365fa8ca2e0eb79413de5f99d17edd41..a17e6ee1a1f8885b31d4fa04e80e7a8cea348663 100644 (file)
--- a/remote.cc
+++ b/remote.cc
@@ -239,34 +239,43 @@ void Remote::unsetHWC(ULLONG hcw)
   translist.erase(hcw);
 }
 
-void Remote::LoadKeysConfig(char *cfg)
+void Remote::LoadKeysConfig(VDR *vdr,const char *cfg)
 {
-  char *start = cfg;
-  start = strchr(cfg,'H')+1;
-  while ((start-1) != NULL)
-  {
-    ULONG ul1, ul2;
-    ULONG uc;
-    if (sscanf(start,"%lXI%lXK%lX",&ul1,&ul2,&uc) == 3)
-    {
-      translist[((ULLONG) ul1) | ((ULLONG)ul2) << 32]=(UCHAR)uc;
-    }
-    start = strchr(start, 'H')+1;
-  }
+       ULONG number=0;
+       if (sscanf(cfg,"%ld",&number) != 1) return;
+       Log::getInstance()->log("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;
 }
index 2a4da446855fe19a588ddab34ba48bf7df075b01..9f7b93569181c7d24e7cfedce8ae944f7e6705b4 100644 (file)
--- 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;
index f604f9dc616fc8de76d58a50e4851cb13ede3a09..221a18aacf1f2be4688eb0992957bb281ecb3dd6 100644 (file)
@@ -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 b18cac0ca928f71f1e9d2c8240e4bf972a5c2f91..19128ab96710340fab1b79a3ca507a2e7a414344 100644 (file)
--- a/vdr.cc
+++ b/vdr.cc
@@ -1037,7 +1037,7 @@ int VDR::configSave(const char* section, const char* key, const char* value)
 \r
   VDR_ResponsePacket* vresp = RequestResponse(&vrp);\r
   if (vresp->noResponse()) { delete vresp; return 0; }\r
-  \r
+\r
   int toReturn = (int)vresp->extractULONG();\r
   delete vresp;\r
 \r
index 5cee6fb3e73caad71b87482b7e507df2e29edbb2..b8b66bd93e701465ef577d5b9cfbb74ef3eb4748 100644 (file)
@@ -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)<playbacktimeoffset) {
-               Log::getInstance()->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();
index ffb4e2c08b7130865bc819ef5d83c2e9371e2fff..395f04ab7b28115cfb2c855bc5c86decdc6aa01b 100644 (file)
@@ -62,7 +62,7 @@ struct VPE_OMX_EVENT {
 \r
 class AudioVPE;\r
 \r
-class VideoOMX : public Video, public Thread_TYPE\r
+class VideoOMX : public Video\r
 {\r
   friend class AudioOMX;\r
   public:\r
@@ -244,16 +244,11 @@ class VideoOMX : public Video, public Thread_TYPE
 \r
           vector<OMX_BUFFERHEADERTYPE*> input_bufs_omx_all;\r
           list<OMX_BUFFERHEADERTYPE*> input_bufs_omx_free;\r
-          list<OMX_BUFFERHEADERTYPE*> input_bufs_omx_present;\r
-          list<long long> input_time_present;\r
-          //list<long long> input_time_pts;\r
-         // list<bool> input_is_last;\r
           Mutex input_bufs_omx_mutex;\r
           OMX_BUFFERHEADERTYPE* cur_input_buf_omx;\r
 \r
-          void PutBufferToPres(OMX_BUFFERHEADERTYPE* buffer, long long time,/*long long pts,*/ bool is_last);\r
-          void threadMethod();\r
-          void threadPostStopCleanup();\r
+          void PutBufferToPres(OMX_BUFFERHEADERTYPE* buffer);\r
+\r
 \r
 \r
           bool omx_running;\r