Advertisement
Guest User

xbmcVideoLibraryScan.cpp

a guest
Nov 1st, 2012
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.14 KB | None | 0 0
  1. /*
  2.  *      Copyright (C) 2005-2012 Team XBMC
  3.  *      http://www.xbmc.org
  4.  *
  5.  *  This Program is free software; you can redistribute it and/or modify
  6.  *  it under the terms of the GNU General Public License as published by
  7.  *  the Free Software Foundation; either version 2, or (at your option)
  8.  *  any later version.
  9.  *
  10.  *  This Program is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13.  *  GNU General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU General Public License
  16.  *  along with XBMC; see the file COPYING.  If not, see
  17.  *  <http://www.gnu.org/licenses/>.
  18.  *
  19.  */
  20.  
  21. #include "system.h"
  22. #include "settings/AppParamParser.h"
  23. #include "settings/AdvancedSettings.h"
  24. #include "GUIInfoManager.h"
  25. #include "FileItem.h"
  26. #include "Application.h"
  27. #include "ApplicationMessenger.h"
  28. #include "PlayListPlayer.h"
  29. #include "utils/log.h"
  30. #include "xbmc.h"
  31. #ifdef _LINUX
  32. #include <sys/resource.h>
  33. #include <signal.h>
  34. #endif
  35. #if defined(TARGET_DARWIN_OSX)
  36.   #include "Util.h"
  37.   // SDL redefines main as SDL_main
  38.   #ifdef HAS_SDL
  39.     #include <SDL/SDL.h>
  40.   #endif
  41. #endif
  42. #ifdef HAS_LIRC
  43. #include "input/linux/LIRC.h"
  44. #endif
  45. #include "XbmcContext.h"
  46.  
  47. int main(int argc, char* argv[])
  48. {
  49.   int m_ExitCode;
  50.  
  51.   // set up some xbmc specific relationships
  52.   XBMC::Context context;
  53.  
  54.   //this can't be set from CAdvancedSettings::Initialize() because it will overwrite
  55.   //the loglevel set with the --debug flag
  56.   g_advancedSettings.m_logLevel     = LOG_LEVEL_DEBUG;
  57.   g_advancedSettings.m_logLevelHint = LOG_LEVEL_DEBUG;
  58.   CLog::SetLogLevel(g_advancedSettings.m_logLevel);
  59.  
  60. #ifdef _LINUX
  61.   // Prevent child processes from becoming zombies on exit if not waited upon. See also Util::Command
  62.   struct sigaction sa;
  63.   memset(&sa, 0, sizeof(sa));
  64.  
  65.   sa.sa_flags = SA_NOCLDWAIT;
  66.   sa.sa_handler = SIG_IGN;
  67.   sigaction(SIGCHLD, &sa, NULL);
  68. #endif
  69.   setlocale(LC_NUMERIC, "C");
  70.   g_advancedSettings.Initialize();
  71.  
  72. #ifndef _WIN32
  73.   CAppParamParser appParamParser;
  74.   appParamParser.Parse((const char **)argv, argc);
  75. #endif
  76.  
  77.   if (!g_advancedSettings.Initialized())
  78.   {
  79.     g_advancedSettings.m_logLevel     = LOG_LEVEL_DEBUG;
  80.     g_advancedSettings.m_logLevelHint = LOG_LEVEL_DEBUG;
  81.     g_advancedSettings.Initialize();
  82.   }
  83.  
  84.   if (!g_application.Create())
  85.   {
  86.     fprintf(stderr, "ERROR: Unable to create application. Exiting\n");
  87.     return -1;
  88.   }
  89.  
  90.   if (!g_application.Initialize())
  91.   {
  92.     fprintf(stderr, "ERROR: Unable to Initialize. Exiting\n");
  93.     return -1;
  94.   }
  95.  
  96.   CLog::Log(LOGNOTICE, "Running the application..." );
  97.  
  98.   unsigned int lastFrameTime = 0;
  99.   unsigned int frameTime = 0;
  100.   const unsigned int noRenderFrameTime = 15;  // Simulates ~66fps
  101.  
  102.   CLog::Log(LOGNOTICE, "Starting Video Library Scan..." );
  103.  
  104.   printf("XBMC Media Center %s\n", g_infoManager.GetVersion().c_str());
  105.   printf("Copyright (C) 2005-2011 Team XBMC - http://www.xbmc.org\n\n");
  106.   printf("Starting Video Library Scan\n\n");
  107.  
  108.   // Start scanning the Video Library for changes...
  109.   g_application.StartVideoScan("");
  110.  
  111.   // Run xbmc
  112.   while (!g_application.m_bStop)
  113.   {
  114.     //-----------------------------------------
  115.     // Animate and render a frame
  116.     //-----------------------------------------
  117.     lastFrameTime = XbmcThreads::SystemClockMillis();
  118.     g_application.Process();
  119.  
  120.     // Frame move the scene
  121.     if (!g_application.m_bStop) g_application.FrameMove(true, false);
  122.  
  123.     // If scanning the Video Library has finished then ask XBMC to quit...
  124.     if (!g_application.IsVideoScanning())
  125.     {
  126.        CApplicationMessenger::Get().Quit();
  127.     } else {
  128.       printf(".");
  129.  
  130.       frameTime = XbmcThreads::SystemClockMillis() - lastFrameTime;
  131.       if(frameTime < noRenderFrameTime)
  132.          Sleep(noRenderFrameTime - frameTime);
  133.     }
  134.  
  135.   } // while (!m_bStop)
  136.  
  137.   CLog::Log(LOGNOTICE, "Finished Video Library Scan..." );
  138.  
  139.   m_ExitCode = g_application.m_ExitCode;
  140.  
  141.   g_application.Destroy();
  142.  
  143.   printf("\n\nFinished Video Library Scan...\n");
  144.  
  145.   return m_ExitCode;
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement