]> git.vomp.tv Git - vompclient.git/commitdiff
Control/main/winmain/util reorganisation
authorChris Tallon <chris@vomp.tv>
Mon, 20 Apr 2020 16:41:46 +0000 (17:41 +0100)
committerChris Tallon <chris@vomp.tv>
Mon, 20 Apr 2020 16:41:46 +0000 (17:41 +0100)
Move all common module startup/shutdown code from main/winmain to control
Move common global functions from main/winmain to util

17 files changed:
afeed.cc
audioomx.cc
control.cc
control.h
defines.h
imageomx.cc
main.cc
objects.mk
playervideorec.cc
tfeed.cc
threadp.cc
vconnect.cc
vfeed.cc
videoomx.cc
vscreensaver.cc
vsleeptimer.cc
winmain.cc

index 2541718370e2628ab19330f820a38d2826d9364f..546df45730645b6a4caed556a17772e361a6aab5 100644 (file)
--- a/afeed.cc
+++ b/afeed.cc
@@ -20,6 +20,7 @@
 #include "log.h"
 #include "demuxer.h"
 #include "callback.h"
+#include "util.h"
 
 #include "afeed.h"
 
index e522d2d0751f211839a673272aa0f8b3d19ec3b1..22ade6502d16bb1783bd3cec6d90efb6b19bb4de 100644 (file)
     along with VOMP.  If not, see <https://www.gnu.org/licenses/>.
 */
 
-#include "audioomx.h"
+#include <bcm_host.h>
+
 #include "videoomx.h"
 #include "log.h"
 #include "vdr.h"
 #include "woptionpane.h"
-
 #include "osdopenvg.h"
-#include <bcm_host.h>
+#include "util.h"
 
 extern "C" {
 #include "libavutil/channel_layout.h"
 #include "libavutil/opt.h"
 }
 
+#include "audioomx.h"
+
 AudioOMX::AudioOMX()
 {
   initted = 0;
index 76fc49f4d4f0ab6c878a5e581ee844c532eca36f..998a426b6eec37b37b60971f3657f1c1ecd07045 100644 (file)
 #include "wjpeg.h"
 #include "osdvector.h"
 
+
+#ifdef VOMP_PLATFORM_RASPBERRY
+  #include "ledraspberry.h"
+  #include "osdopenvg.h"
+  #include "videoomx.h"
+  #include "audioomx.h"
+#endif
+
+#ifdef WIN32
+  #include "windowsosd.h"
+  #ifdef WINDOWS_LEGACY
+    #include "osdwinpixel.h"
+  #else
+    #include "osdwinvector.h"
+  #endif
+
+  #include "ledwin.h"
+  #include "videowin.h"
+  #include "audiowin.h"
+#endif
+
 #include "control.h"
 
 Control* Control::instance = NULL;
@@ -85,70 +106,133 @@ bool Control::init(bool tcrashed)
 {
   if (initted) return false;
   crashed = tcrashed;
-
-
-  SkinFactory::InitSkin(0);
-
   logger = Log::getInstance();
 
+  SkinFactory::InitSkin(0);
 
   try
   {
-    vdr = new VDR();                           if (!boxstack) throw 1;
-    if (!vdr->init())                          throw 2;
+    led = new Led_TYPE();                     if (!led) throw 10;
+    if (!led->init(-1))                       throw 11;  // FIXME init(0) on Win32
+
+    timers = new Timers();                    if (!timers) throw 20;
+    if (!timers->init())                      throw 21;
+
+    video = new Video_TYPE();                 if (!video) throw 30;
+    if (!video->init(Video::PAL))             throw 31;
+
+    audio = new Audio_TYPE();                 if (!audio) throw 40;
+    if (!audio->init(Audio::MPEG2_PES))       throw 41;
+
+    osd = new Osd_TYPE();                     if (!osd) throw 50;
+    if (!osd->init())                         throw 51;
+
+    vdr = new VDR();                          if (!vdr) throw 60;
+    if (!vdr->init())                         throw 61;
 
-    boxstack = new BoxStack();                if (!boxstack) throw 10;
-    if (!boxstack->init())                    throw 20;
+    boxstack = new BoxStack();                if (!boxstack) throw 70;
+    if (!boxstack->init())                    throw 71;
 
-    sleeptimer = new Sleeptimer();            if (!sleeptimer) throw 30;
+    sleeptimer = new Sleeptimer();            if (!sleeptimer) throw 80;
 
-    wol = new Wol();                          if (!wol) throw 40;
+    wol = new Wol();                          if (!wol) throw 90;
+
+    inputMan = new InputMan();                if (!inputMan) throw 100;
+    if (!inputMan->init())                    throw 101;
 
   }
   catch (int e)
   {
-    if      (e == 1 ) logger->log("Control", Log::EMERG, "VDR module failed to create");
-    else if (e == 2 ) logger->log("Control", Log::EMERG, "VDR module failed to initialise");
-    else if (e == 10) logger->log("Control", Log::EMERG, "BoxStack module failed to create");
-    else if (e == 20) logger->log("Control", Log::EMERG, "BoxStack module failed to initialise");
-    else if (e == 30) logger->log("Control", Log::EMERG, "SleepTimer module failed to create");
-    else if (e == 40) logger->log("Control", Log::EMERG, "WOL module failed to create");
+    if      (e == 10) logger->log("Control", Log::EMERG, "LED module failed to create");
+    else if (e == 11) logger->log("Control", Log::EMERG, "LED module failed to initialise");
+    else if (e == 20) logger->log("Control", Log::EMERG, "Timers module failed to create");
+    else if (e == 21) logger->log("Control", Log::EMERG, "Timers module failed to initialise");
+    else if (e == 30) logger->log("Control", Log::EMERG, "Video module failed to create");
+    else if (e == 31) logger->log("Control", Log::EMERG, "Video module failed to initialise");
+    else if (e == 40) logger->log("Control", Log::EMERG, "Audio module failed to create");
+    else if (e == 41) logger->log("Control", Log::EMERG, "Audio module failed to initialise");
+    else if (e == 50) logger->log("Control", Log::EMERG, "OSD module failed to create");
+    else if (e == 51) logger->log("Control", Log::EMERG, "OSD module failed to initialise");
+    else if (e == 60) logger->log("Control", Log::EMERG, "VDR module failed to create");
+    else if (e == 61) logger->log("Control", Log::EMERG, "VDR module failed to initialise");
+    else if (e == 70) logger->log("Control", Log::EMERG, "BoxStack module failed to create");
+    else if (e == 71) logger->log("Control", Log::EMERG, "BoxStack module failed to initialise");
+    else if (e == 80) logger->log("Control", Log::EMERG, "SleepTimer module failed to create");
+    else if (e == 90) logger->log("Control", Log::EMERG, "WOL module failed to create");
+    else if (e == 100) logger->log("Control", Log::EMERG, "InputMan module failed to create");
+    else if (e == 101) logger->log("Control", Log::EMERG, "InputMan module failed to initialise");
 
     switch(e)
     {
-      case 40:
+      case 101:
+        delete inputMan;
+        inputMan = NULL;
         FALLTHROUGH
-      case 30:
+      case 100:
+        delete wol;
+        wol = NULL;
         FALLTHROUGH
-      case 20:
+      case 90:
+        delete sleeptimer;
+        sleeptimer = NULL;
+        FALLTHROUGH
+      case 80:
+        boxstack->shutdown();
+        FALLTHROUGH
+      case 71:
         delete boxstack;
         boxstack = NULL;
         FALLTHROUGH
-      case 10:
+      case 70:
+        vdr->shutdown();
         FALLTHROUGH
-      case 2:
+      case 61:
         delete vdr;
         vdr = NULL;
         FALLTHROUGH
-      case 1:
+      case 60:
+        osd->shutdown();
+        FALLTHROUGH
+      case 51:
+        delete osd;
+        osd = NULL;
+        FALLTHROUGH
+      case 50:
+        audio->shutdown();
+        FALLTHROUGH
+      case 41:
+        delete audio;
+        audio = NULL;
+        FALLTHROUGH
+      case 40:
+        video->shutdown();
+        FALLTHROUGH
+      case 31:
+        delete video;
+        video = NULL;
+        FALLTHROUGH
+      case 30:
+        timers->shutdown();
+        FALLTHROUGH
+      case 21:
+        delete timers;
+        timers = NULL;
         FALLTHROUGH
-          ;
+      case 20:
+        led->shutdown();
+        FALLTHROUGH
+      case 11:
+        delete led;
+        led = NULL;
+        FALLTHROUGH
+      case 10:
+        FALLTHROUGH
+        ;
     }
 
     return false;
   }
 
-
-  inputMan = InputMan::getInstance();
-  
-  if (!inputMan)
-  {
-    initted = false;
-    return 0;
-  }
-
-
-
   initted = true;
   return true;
 }
@@ -158,6 +242,14 @@ void Control::shutdown()
   if (!initted) return;
   initted = false;
 
+  if (inputMan)
+  {
+    inputMan->shutdown();
+    delete inputMan;
+    inputMan = NULL;
+    logger->log("Control", Log::NOTICE, "InputMan module shut down");
+  }
+
   if (wol)
   {
     delete wol;
@@ -186,6 +278,46 @@ void Control::shutdown()
     vdr = NULL;
     logger->log("Control", Log::NOTICE, "VDR module shut down");
   }
+
+  if (osd)
+  {
+    osd->shutdown();
+    delete osd;
+    osd = NULL;
+    logger->log("Control", Log::NOTICE, "OSD module shut down");
+  }
+
+  if (audio)
+  {
+    audio->shutdown();
+    delete audio;
+    audio = NULL;
+    logger->log("Control", Log::NOTICE, "Audio module shut down");
+  }
+
+  if (video)
+  {
+    video->shutdown();
+    delete video;
+    video = NULL;
+    logger->log("Control", Log::NOTICE, "Video module shut down");
+  }
+
+  if (timers)
+  {
+    timers->shutdown();
+    delete timers;
+    timers = NULL;
+    logger->log("Control", Log::NOTICE, "Timers module shut down");
+  }
+
+  if (led)
+  {
+    led->shutdown();
+    delete led;
+    led = NULL;
+    logger->log("Control", Log::NOTICE, "LED module shut down");
+  }
 }
 
 void Control::stop()
@@ -200,8 +332,6 @@ void Control::stop()
 
 void Control::doWallpaper()
 {
-  Video* video = Video::getInstance();
-
   // Blue background
   Boxx* bbg = new Boxx();
   bbg->setSize(video->getScreenWidth(), video->getScreenHeight());
@@ -727,8 +857,6 @@ void Control::doJustConnected(VConnect* vconnect)
   if (!VDR::getInstance()->isConnected()) { connectionLost(); return; }
   logger->log("Control", Log::INFO, "Entering doJustConnected");
   
-  Video* video = Video::getInstance();
-  Audio* audio = Audio::getInstance();  
   boxstack->remove(vconnect);
 
   VInfo* vi = new VInfo();
@@ -810,7 +938,6 @@ void Control::doJustConnected(VConnect* vconnect)
       boxstack->remove(wallpaper);
       delete wallpaper_pict; wallpaper_pict = NULL; wallpaper = NULL;
 
-      Osd* osd = Osd::getInstance();
 #ifndef __ANDROID__
       osd->shutdown();
 #endif
index e5e1942612e5e164b41b1275bac6f670b9dc3057..0271d0f00e8418cc8d0cc290775e25b185d7b933 100644 (file)
--- a/control.h
+++ b/control.h
@@ -37,6 +37,11 @@ class VInfo;
 class WJpeg;
 class Sleeptimer;
 class Wol;
+class Audio;
+class Video;
+class Osd;
+class Timers;
+class Led;
 
 struct ASLPref
 {
@@ -70,10 +75,16 @@ class Control : public MessageQueue
 
   private:
     // I own:
+    Led* led{};
+    Timers* timers{};
+    Osd* osd{};
+    Video* video{};
+    Audio* audio{};
     VDR* vdr{};
     BoxStack* boxstack{};
     Sleeptimer* sleeptimer{};
     Wol* wol{};
+    InputMan* inputMan{};
 
 
 
@@ -91,7 +102,6 @@ class Control : public MessageQueue
     static Control* instance;
 
     Log* logger;
-    InputMan* inputMan;
 
     bool initted{};
     bool irun{};
index d48034430e7d916904a32820bf495b437a803294..eca1dac453c31e0ea0c5dd94cae32a2a0607dc58 100644 (file)
--- a/defines.h
+++ b/defines.h
@@ -34,9 +34,6 @@ typedef unsigned long long ULLONG;
 
 // Global useful functions
 
-//ULLONG htonll(ULLONG a);
-//ULLONG ntohll(ULLONG a);
-void MILLISLEEP(ULONG a);
 long long getTimeMS();
 
 #include <string>
@@ -50,6 +47,8 @@ const std::string& getCommandLineServer();
 
 #ifdef WIN32
 
+  #define Led_TYPE LedWin
+  #define Video_TYPE VideoWin
 
   #define Thread_TYPE ThreadWin
   #define ThreadID_TYPE unsigned int
index f3a25e2deddb8c35d2112e6b37af0f6ba0520716..be7d9548e64888cc249a83efd52e1f7ba0a347e0 100644 (file)
     along with VOMP.  If not, see <https://www.gnu.org/licenses/>.
 */
 
-#include "imageomx.h"
+#include <bcm_host.h>
 #include "videoomx.h"
 #include "log.h"
 #include "vdr.h"
 #include "woptionpane.h"
-
+#include "util.h"
 #include "osdopenvg.h"
-#include <bcm_host.h>
+
+#include "imageomx.h"
 
 ImageOMX::ImageOMX(OsdVector::PictureReader * treader):OsdVector::PictureDecoder(treader)
 {
diff --git a/main.cc b/main.cc
index c405bbcd51d19512a851c446ae5142fb04754c0f..de56e17ef43975f1f6ae3190de8e3d66873b3773 100644 (file)
--- a/main.cc
+++ b/main.cc
     along with VOMP.  If not, see <https://www.gnu.org/licenses/>.
 */
 
-// FIXME
-// Work towards main and winmain only containing what they need for their own platforms
-// Move anything common to utils or control. Move any module startup / shutdown that can
-// be done in control to there.
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <signal.h>
 
+// For open
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
 #include <thread>
 #include <string>
 
@@ -44,9 +44,8 @@
 #endif
 
 #include "log.h"
-#include "timers.h"
+#include "util.h"
 #include "control.h"
-#include "inputman.h"
 
 #ifdef VOMP_PLATTFORM_NMT
   #include "lednmt.h"
   #include "videonmt.h"
 #endif
 
-#ifdef VOMP_PLATFORM_RASPBERRY
-  #include "ledraspberry.h"
-  #include "osdopenvg.h"
-  #include "audioomx.h"
-  #include "videoomx.h"
-#endif
-
-
 
 #ifndef WIN32 // FIXME do we need any if WIN32 stuff in here? windows has own winmain file
 void threadSignalReceiverFunction();
 #endif
 
-ULLONG htonll(ULLONG);
-ULLONG ntohll(ULLONG);
 void shutdown(int code);
 const std::string& getCommandLineServer();
 
-// Global variables --------------------------------------------------------------------------------------------------
 Log* logger;
-InputMan* inputMan;
-Led* led;
-Osd* osd;
-Timers* timers;
 Control* control;
-Video* video;
-Audio* audio;
 
-// Temporary, will move to Config system
+// Temporary, will move to Config system NCONFIG
 std::string argvServer;
 
 #ifdef HANDLE_VT_SWITCHING
@@ -125,35 +107,23 @@ int main(int argc, char** argv)
     }
   }
 
-  // Init global vars ------------------------------------------------------------------------------------------------
-  logger     = new Log();
-  timers     = new Timers();
-  inputMan   = new InputMan();
-
-  led        = new Led_TYPE();
-  osd        = new Osd_TYPE();
-  audio      = new Audio_TYPE();
-  video      = new Video_TYPE();
-
-  control    = new Control();
-
-  if (!logger || !timers || !inputMan || !led || !osd || !video || !audio || !control)
+  // Start Log --------------------------------------------------------------------------------------------------
+  logger = new Log();
+  if (!logger)
   {
-    printf("Could not create objects. Memory problems?\n");
+    printf("Failed to create Log object\n");
     shutdown(1);
   }
 
-  // Get logging module started --------------------------------------------------------------------------------------
-
   if (!logger->init(Log::DEBUG, "dummy", debugEnabled ? 1 : 0)) // NCONFIG x2
   {
     printf("Could not initialise log object. Aborting.\n");
     shutdown(1);
   }
 
-  logger->log("Core", Log::INFO, "Starting up...");
+  logger->log("Main", Log::INFO, "Starting up...");
 
-  // Daemonize if not -d
+  // Daemonize --------------------------------------------------------------------------------------------------
 
   if (daemonize)
   {
@@ -182,7 +152,7 @@ int main(int argc, char** argv)
   int sigBlockResult = pthread_sigmask(SIG_SETMASK, &set, NULL);
   if (sigBlockResult)
   {
-    logger->log("Core", Log::EMERG, "Could not block signals: %i", sigBlockResult);
+    logger->log("Main", Log::EMERG, "Could not block signals: %i", sigBlockResult);
     shutdown(1);
   }
 
@@ -190,7 +160,7 @@ int main(int argc, char** argv)
   std::thread threadSignalReceiver(threadSignalReceiverFunction);
   threadSignalReceiver.detach();
 
-  logger->log("Core", Log::INFO, "Signal handlers set up successfully");
+  logger->log("Main", Log::INFO, "Signal handlers set up successfully");
 
   // VT Switching -----------------------------------------------------------------------------------------------
 
@@ -203,14 +173,14 @@ int main(int argc, char** argv)
 
   )
   {
-    logger->log("Core", Log::EMERG, "Could not open /dev/tty. Please change permissions");
+    logger->log("Main", Log::EMERG, "Could not open /dev/tty. Please change permissions");
   }
   else
   {
     int free_vt;
     if (ioctl(fdtty, VT_OPENQRY, &free_vt) == -1 || free_vt == -1)
     {
-      logger->log("Core", Log::EMERG, "Could not retrieve free virtual console, please change permissions");
+      logger->log("Main", Log::EMERG, "Could not retrieve free virtual console, please change permissions");
     }
     else
     {
@@ -221,105 +191,24 @@ int main(int argc, char** argv)
   }
 #endif
 
-  // Init modules ----------------------------------------------------------------------------------------------------
-  int success;
-
-  success = inputMan->init();
-
-  if (success)
-  {
-    logger->log("Core", Log::INFO, "InputMan module initialised");
-  }
-  else
-  {
-    logger->log("Core", Log::EMERG, "InputMan module failed to initialise");
-    shutdown(1);
-  }
-
-  success = led->init(-1);
-  if (success)
-  {
-    logger->log("Core", Log::INFO, "LED module initialised");
-  }
-  else
-  {
-    logger->log("Core", Log::EMERG, "LED module failed to initialise");
-    shutdown(1);
-  }
-
-  success = timers->init();
-  if (success)
-  {
-    logger->log("Core", Log::INFO, "Timers module initialised");
-  }
-  else
-  {
-    logger->log("Core", Log::EMERG, "Timers module failed to initialise");
-    shutdown(1);
-  }
-
-  UCHAR videoFormat = Video::PAL; // PALNTSC FIXME
-
-  success = video->init(videoFormat);
-  if (success)
-  {
-    logger->log("Core", Log::INFO, "Video module initialised");
-  }
-  else
-  {
-    logger->log("Core", Log::EMERG, "Video module failed to initialise");
-    shutdown(1);
-  }
+  // Run control ----------------------------------------------------------------------------------------------------
 
-  success = osd->init();
-  if (success)
-  {
-    logger->log("Core", Log::INFO, "OSD module initialised");
-  }
-  else
+  control = new Control();
+  if (!control)
   {
-    logger->log("Core", Log::EMERG, "OSD module failed to initialise");
+    logger->log("Main", Log::EMERG, "Control module failed to create");
     shutdown(1);
   }
 
-  success = audio->init(Audio::MPEG2_PES);
-  if (success)
+  if (!control->init(crashed))
   {
-    logger->log("Core", Log::INFO, "Audio module initialised");
-  }
-  else
-  {
-    logger->log("Core", Log::EMERG, "Audio module failed to initialise");
-    shutdown(1);
-  }
-
-
-
-
-
-
-  bool bsuccess = control->init(crashed);
-  if (bsuccess)
-  {
-    logger->log("Core", Log::INFO, "Control module initialised");
-  }
-  else
-  {
-    logger->log("Core", Log::EMERG, "Control module failed to initialise");
+    logger->log("Main", Log::EMERG, "Control module failed to initialise");
+    delete control;
+    control = NULL;
     shutdown(1);
   }
 
-  // Other init ------------------------------------------------------------------------------------------------------
-
-  logger->log("Core", Log::NOTICE, "Startup successful");
-
-  // Run main loop ---------------------------------------------------------------------------------------------------
-
-  // Ok, all major device components and other bits are loaded and ready
   control->run();
-
-  // When that returns quit ------------------------------------------------------------------------------------------
-
   control->shutdown();
 
   shutdown(0);
@@ -337,11 +226,11 @@ void threadSignalReceiverFunction()
   {
     if(sigwait(&set, &sig))
     {
-      logger->log("Core", Log::CRIT, "Sigwait returned fail - signal handler exiting");
+      logger->log("Main", Log::CRIT, "Sigwait returned fail - signal handler exiting");
       return;
     }
 
-    logger->log("Core", Log::NOTICE, "Signal received: %i", sig);
+    logger->log("Main", Log::NOTICE, "Signal received: %i", sig);
 
     if ((sig == SIGINT) || (sig == SIGTERM)) control->stop();
   }
@@ -358,53 +247,9 @@ void shutdown(int code)
   {
     delete control;
     control = NULL;
-    logger->log("Core", Log::NOTICE, "Control module shut down");
-  }
-
-  if (osd)
-  {
-    osd->shutdown();
-    delete osd;
-    logger->log("Core", Log::NOTICE, "OSD module shut down");
-  }
-
-  if (audio)
-  {
-    audio->shutdown();
-    delete audio;
-    logger->log("Core", Log::NOTICE, "Audio module shut down");
+    logger->log("Main", Log::NOTICE, "Control module shut down");
   }
 
-  if (video)
-  {
-    video->shutdown();
-    delete video;
-    logger->log("Core", Log::NOTICE, "Video module shut down");
-  }
-
-  if (timers)
-  {
-    timers->shutdown();
-    delete timers;
-    logger->log("Core", Log::NOTICE, "Timers module shut down");
-  }
-
-  if (led)
-  {
-    led->shutdown();
-    delete led;
-    logger->log("Core", Log::NOTICE, "LED module shut down");
-  }
-
-  if (inputMan)
-  {
-    inputMan->shutdown();
-    delete inputMan;
-    logger->log("Core", Log::NOTICE, "InputMan module shut down");
-  }
-
-
-
 #ifdef HANDLE_VT_SWITCHING
   ioctl(fdtty, VT_UNLOCKSWITCH, 1);
   close(fdtty);
@@ -412,7 +257,7 @@ void shutdown(int code)
 
   if (logger)
   {
-    logger->log("Core", Log::NOTICE, "Log module shutting down... bye!\n\n");
+    logger->log("Main", Log::NOTICE, "Log module shutting down... bye!\n\n");
     logger->shutdown();
     delete logger;
   }
@@ -422,43 +267,6 @@ void shutdown(int code)
 
 // -------------------------------------------------------------------------------------------------------------------
 
-ULLONG htonll(ULLONG a)
-{
-  #if BYTE_ORDER == BIG_ENDIAN
-    return a;
-  #else
-    ULLONG b = 0;
-
-    b = ((a << 56) & 0xFF00000000000000ULL)
-      | ((a << 40) & 0x00FF000000000000ULL)
-      | ((a << 24) & 0x0000FF0000000000ULL)
-      | ((a <<  8) & 0x000000FF00000000ULL)
-      | ((a >>  8) & 0x00000000FF000000ULL)
-      | ((a >> 24) & 0x0000000000FF0000ULL)
-      | ((a >> 40) & 0x000000000000FF00ULL)
-      | ((a >> 56) & 0x00000000000000FFULL) ;
-
-    return b;
-  #endif
-}
-
-ULLONG ntohll(ULLONG a)
-{
-  return htonll(a);
-}
-
-void MILLISLEEP(ULONG a)
-{
-#ifndef WIN32
-  struct timespec delayTime;
-  delayTime.tv_sec = a / 1000;
-  delayTime.tv_nsec = (a % 1000) * 1000000;
-  nanosleep(&delayTime, NULL);
-#else
-  Sleep(a);
-#endif
-}
-
 long long getTimeMS()
 {
   struct timespec ts;
index 88aedcfbe3f8139366a4ed134d12eeb989c8c47f..635fb0af5d4d1c7ae143fc2e72944ab9828850ba 100644 (file)
@@ -1,4 +1,4 @@
-OBJ_COMMON = control.o thread.o timers.o i18n.o udp4.o udp6.o vdpc.o tcp.o         \
+OBJ_COMMON = util.o control.o thread.o timers.o i18n.o udp4.o udp6.o vdpc.o tcp.o  \
              message.o messagequeue.o wol.o audio.o video.o log.o                  \
              vdr.o recman.o recording.o recinfo.o channel.o rectimer.o event.o     \
              directory.o mark.o option.o vfeed.o afeed.o                           \
index 96b7d78bb589a856a9e52735b38b51f6b3d8c5d9..03a4060b7462f10a5f0904d97cbdc8cb4b3f55d6 100644 (file)
@@ -29,6 +29,7 @@
 #include "dvbsubtitles.h"
 #include "osdreceiver.h"
 #include "buffer.h"
+#include "util.h"
 
 #include "playervideorec.h"
 
index 97e5284f75893743a490ced69fd7a307b3bfadc7..063b5fa260a469bfc6506f71d21b8ddaf67d63eb 100644 (file)
--- a/tfeed.cc
+++ b/tfeed.cc
@@ -19,6 +19,7 @@
 #include "log.h"
 #include "demuxer.h"
 #include "callback.h"
+#include "util.h"
 
 #include "tfeed.h"
 
index e57cfdd7e83328f7af004e74a89ebb88262d9bff..5ae5fe96c598e523118cf936d06b36eeb6cc1860 100644 (file)
@@ -18,6 +18,8 @@
     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
 
+#include "util.h"
+
 #include "threadp.h"
 
 // Undeclared functions, only for use in this file to start the thread
index 2874e02519c4a8091a9f2d5175a4db818bc03d85..b9fe4d852732ec44ca12865aeb203ea89b16b491 100644 (file)
@@ -29,6 +29,7 @@
 #include "wol.h"
 #include "vserverselect.h"
 #include "messagequeue.h"
+#include "util.h"
 
 #include "vconnect.h"
 
index 0bc69dd64000a134750d6adb3579664e778c1d0a..00e129c99521b31f286468713323914d10b14c6a 100644 (file)
--- a/vfeed.cc
+++ b/vfeed.cc
@@ -20,6 +20,7 @@
 #include "log.h"
 #include "demuxer.h"
 #include "callback.h"
+#include "util.h"
 
 #include "vfeed.h"
 
index 2d2ce084f65eab94f29e70a60cf2504648d17297..9a90e4da8b3726550292addcd5bd157733e46a2c 100644 (file)
@@ -30,6 +30,7 @@
 #include "osdopenvg.h"
 #include "boxstack.h"
 #include "inputman.h"
+#include "util.h"
 
 #include "videoomx.h"
 
index 3d1a83afbf94a7db11932ae83451792e597eba2e..154a3680d842ff48952796381986501dce07d3e7 100644 (file)
@@ -27,6 +27,7 @@
 #include "colour.h"
 #include "video.h"
 #include "surface.h"
+#include "util.h"
 
 #include "vscreensaver.h"
 
index 965139641cf3bae4f83c56437a2c608646a47617..8db2d3c08f72f9b13169795dbb939c7500f110c1 100644 (file)
@@ -17,7 +17,6 @@
     along with VOMP.  If not, see <https://www.gnu.org/licenses/>.
 */
 
-#include "vsleeptimer.h"
 
 #include "input.h"
 #include "wsymbol.h"
@@ -26,6 +25,9 @@
 #include "boxstack.h"
 #include "message.h"
 #include "messagequeue.h"
+#include "util.h"
+
+#include "vsleeptimer.h"
 
 Sleeptimer* Sleeptimer::instance = NULL;
 
index e8f692fc96a506055f97c73b87aad29804418b66..17b9b4af6e947cfb263ef85c0172436cb1969443 100644 (file)
 #include "log.h"
 #include "inputman.h"
 #include "inputwin.h"
-#include "ledwin.h"
-#include "timers.h"
-#include "videowin.h"
-#include "audiowin.h"
+#include "util.h"
+
 #include "windowsosd.h"
-#ifdef WINDOWS_LEGACY
-#include "osdwinpixel.h"
-#else
-#include "osdwinvector.h"
-#endif
+
 #include "control.h"
 #include "message.h"
 #include "messagequeue.h"
@@ -54,14 +48,8 @@ void shutdown(int code);
 // Global variables --------------------------------------------------------------------------------------------------
 int debugEnabled = 0;
 Log* logger;
-InputMan* remote;
 InputWin* inputWin;
-Led* led;
-Osd* osd;
-Timers* timers;
 Control* control;
-Video* video;
-Audio* audio;
 std::string commandLineServer; // NCONFIG
 
 bool wnd_fullscreen=false;
@@ -84,12 +72,6 @@ DWORD lastmousemove;
 
 MessageQueue* messageQueue;
 
-
-void MILLISLEEP(ULONG a)
-{
-  Sleep(a);
-}
-
 int getClockRealTime(struct timespec *tp){
        SYSTEMTIME systime;
        __int64  filetime;
@@ -154,15 +136,9 @@ INT WINAPI WinMain( HINSTANCE hinst , HINSTANCE previnst, LPSTR cmdline, int cmd
   // Init global vars ------------------------------------------------------------------------------------------------
 
   logger     = new Log();
-  remote     = new InputMan();
-  led        = new LedWin();
-  timers     = new Timers();
-  osd        = new Osd_TYPE();
-  video      = new VideoWin();
-  audio      = new AudioWin();
   control    = new Control();
 
-  if (!logger || !remote || !led || !osd || !video || !audio || !control)
+  if (!logger || !control)
   {
     ERROR_MSG("Could not create objects. Memory problems?\n");
     shutdown(1);
@@ -185,93 +161,10 @@ INT WINAPI WinMain( HINSTANCE hinst , HINSTANCE previnst, LPSTR cmdline, int cmd
   logger->log("Core", Log::INFO, "Starting up...");
 
 
-
   // Init modules ----------------------------------------------------------------------------------------------------
   int success;
 
-  success = remote->init();
-  if (success)
-  {
-    logger->log("Core", Log::INFO, "Remote module initialised");
-  }
-  else
-  {
-    logger->log("Core", Log::EMERG, "Remote module failed to initialise");
-    shutdown(1);
-  WSACleanup();
-  return 0;
-  }
-
-  inputWin = remote->getInputWin();
-
-  success = led->init(0);
-  if (success)
-  {
-    logger->log("Core", Log::INFO, "LED module initialised");
-  }
-  else
-  {
-    logger->log("Core", Log::EMERG, "LED module failed to initialise");
-    shutdown(1);
-  WSACleanup();
-  return 0;
-  }
-
-  success = timers->init();
-  if (success)
-  {
-    logger->log("Core", Log::INFO, "Timers module initialised");
-  }
-  else
-  {
-    logger->log("Core", Log::EMERG, "Timers module failed to initialise");
-    shutdown(1);
-  WSACleanup();
-  return 0;
-  }
-
-  UCHAR videoFormat = Video::PAL; // PALNTSC FIXME.
-
-  success = video->init(videoFormat);
-  if (success)
-  {
-    logger->log("Core", Log::INFO, "Video module initialised");
-  }
-  else
-  {
-    logger->log("Core", Log::EMERG, "Video module failed to initialise");
-    shutdown(1);
-  WSACleanup();
-  return 0;
-  }
-
   dynamic_cast<WindowsOsd*>(osd)->setWindow(win);
-  success = osd->init();
-  if (success)
-  {
-    logger->log("Core", Log::INFO, "OSD module initialised");
-  }
-  else
-  {
-    logger->log("Core", Log::EMERG, "OSD module failed to initialise");
-    shutdown(1);
-    WSACleanup();
-    return 0;
-  }
-  video->setDefaultAspect();
-
-  success = audio->init(Audio::MPEG2_PES);
-  if (success)
-  {
-    logger->log("Core", Log::INFO, "Audio module initialised");
-  }
-  else
-  {
-    logger->log("Core", Log::EMERG, "Audio module failed to initialise");
-    shutdown(1);
-    WSACleanup();
-    return 0;
-  }
 
   success = control->init();
   if (success)
@@ -281,11 +174,16 @@ INT WINAPI WinMain( HINSTANCE hinst , HINSTANCE previnst, LPSTR cmdline, int cmd
   else
   {
     logger->log("Core", Log::EMERG, "Control module failed to initialise");
+    delete control;
+    control = NULL;
     shutdown(1);
     WSACleanup();
     return 0;
   }
 
+  inputWin = InputMan::getInstance()->getInputWin();
+  Video::getInstance()->setDefaultAspect();
+
   // Other init ------------------------------------------------------------------------------------------------------
 
   logger->log("Core", Log::NOTICE, "Startup successful");
@@ -313,7 +211,7 @@ INT WINAPI WinMain( HINSTANCE hinst , HINSTANCE previnst, LPSTR cmdline, int cmd
       }
     } else {
       //Render, moved to OSD !
-               Sleep(20);
+               MILLISLEEP(20);
       //((OsdWin*)osd)->Render();
     }
   }
@@ -361,6 +259,7 @@ void CalculateWindowSize(RECT * size,ULONG size_mode) {
   UCHAR mode=Video::PAL;
   UCHAR aspect=Video::ASPECT4X3;
   UCHAR tvsize=Video::ASPECT4X3;
+  Video* video = Video::getInstance();
   if (video) {
       mode=video->getMode();
       aspect=((VideoWin*)video)->getAspectRatio();
@@ -799,48 +698,6 @@ void shutdown(int code)
     logger->log("Core", Log::NOTICE, "Control module shut down");
   }
 
-  if (osd)
-  {
-    osd->shutdown();
-    delete osd;
-    logger->log("Core", Log::NOTICE, "OSD module shut down");
-  }
-
-  if (audio)
-  {
-    audio->shutdown();
-    delete audio;
-    logger->log("Core", Log::NOTICE, "Audio module shut down");
-  }
-
-  if (video)
-  {
-    video->shutdown();
-    delete video;
-    logger->log("Core", Log::NOTICE, "Video module shut down");
-  }
-
-  if (timers)
-  {
-    timers->shutdown();
-    delete timers;
-    logger->log("Core", Log::NOTICE, "Timers module shut down");
-  }
-
-  if (led)
-  {
-    led->shutdown();
-    delete led;
-    logger->log("Core", Log::NOTICE, "LED module shut down");
-  }
-
-  if (remote)
-  {
-    remote->shutdown();
-    delete remote;
-    logger->log("Core", Log::NOTICE, "Remote module shut down");
-  }
-
   if (logger)
   {
     logger->log("Core", Log::NOTICE, "Log module shutting down... bye!\n\n");
@@ -853,17 +710,6 @@ void shutdown(int code)
 
 // -------------------------------------------------------------------------------------------------------------------
 
-ULLONG htonll(ULLONG a)
-{
-  return (((ULLONG)htonl((ULONG)((a<<32)>> 32))<<32)
-    |(ULONG)htonl(((ULONG) (a >> 32))));
-}
-
-ULLONG ntohll(ULLONG a)
-{
-  return htonll(a);
-}
-
 const std::string& getCommandLineServer()
 {
   return commandLineServer;