XBMC Community Forum
[LINUX] xbmc server: possible quick implementation? - Printable Version

+- XBMC Community Forum (http://forum.xbmc.org)
+-- Forum: Development (/forumdisplay.php?fid=32)
+--- Forum: Development (/forumdisplay.php?fid=93)
+--- Thread: [LINUX] xbmc server: possible quick implementation? (/showthread.php?tid=114612)

Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13


[LINUX] xbmc server: possible quick implementation? - bladesuk1 - 2011-11-14 15:45

i'm not that hot on C/C++, so bear with me, but when i was looking over the code i think i spotted a very quick and dirty way of getting a headless server up and running.

steps i'm currently making to get myself something to play with are as follows:

in xbmc.cpp we need a new 'else if' to allow for a '-s' or '--server' flag to fed in like this:

Code:
else if (strnicmp(argv[i], "-s", 2) == 0 || strnicmp(argv[i], "--server", 8) == 0)
      {
        g_application.SetServer(true);
      }

and then before we get to g_application.Run() we wrap the playlist startup code like so:

Code:
if (!g_application.IsServerMode())
  {
      if (playlist.Size() > 0)
      {
        g_playlistPlayer.Add(0,playlist);
        g_playlistPlayer.SetCurrentPlaylist(0);
      }

      ThreadMessage tMsg = {TMSG_PLAYLISTPLAYER_PLAY, (DWORD) -1};
      g_application.getApplicationMessenger().SendMessage(tMsg, false);
  }

This obviously requires an addition to Application.h:

Code:
void SetServerMode(bool value);

  bool IsServerMode()
  {
    return m_bServerMode;
  }

As well as the corresponding code in Application.cpp:

Code:
void CApplication::SetServerMode(bool value)
{
  g_advancedSettings.m_serverMode = m_bServerMode = value;
}

Same class, we also make some tweaks in the bool CApplication::Initialize() method:

Code:
...

  // skip the following if we're in server mode
  if (!g_application.IsServerMode())
  {
      StartServices();

      // Init DPMS, before creating the corresponding setting control.
      m_dpms = new DPMSSupport();
      g_guiSettings.GetSetting("powermanagement.displaysoff")->SetVisible(
          m_dpms->IsSupported());

      g_windowManager.Add(new CGUIWindowHome);                     // window id = 0

      ...

      //  Show mute symbol
      if (g_settings.m_nVolumeLevel == VOLUME_MINIMUM)
        Mute();

  }

  g_sysinfo.Refresh();

  CLog::Log(LOGINFO, "removing tempfiles");
  CUtil::RemoveTempFiles();


  // if the user shutoff the xbox during music scan
  // restore the settings
  if (g_settings.m_bMyMusicIsScanning)
  {
    CLog::Log(LOGWARNING,"System rebooted during music scan! ... restoring UseTags and FindRemoteThumbs");
    RestoreMusicScanSettings();
  }
  

  // skip the following if we're in server mode
  if (!g_application.IsServerMode())
  {
      if (!g_settings.UsingLoginScreen())
      {
        UpdateLibraries();
    #ifdef HAS_PYTHON
      g_pythonParser.m_bLogin = true;
    #endif
      }

    #ifdef __APPLE__
      XBMCHelper::GetInstance().CaptureAllInput();
    #endif
    #if defined(HAVE_LIBCRYSTALHD)
      CCrystalHD::GetInstance();
    #endif
      // reset our screensaver (starts timers etc.)
      ResetScreenSaver();
  }

  m_slowTimer.StartZero();
  
  CLog::Log(LOGNOTICE, "initialize done");

  m_bInitializing = false;

  return true;
}

Finally, AdvancedSettings.cpp needs the following in the CAdvancedSettings::Initialize() method:

Code:
m_serverMode = g_application.IsServer();

now, if i'm on the right lines, what i think this will do is to basically knock out all of the gui code from being started up when xbmc starts while still allowing the back end library stuff (i.e. the library management interface) to come up and run in the background. When I get a chance, I'll compile and try it out, but I wanted to check to see if a) this approach is feasible and b) if i'm going to miss anything important buried elsewhere in the code. one thing i think that might be missing from this is an automatic library update, but i think i can trigger that remotely or with a plugin.

anyone got any comments (including 'this isn't going to work' if applicable!)? or should i just go ahead and attempt to compile this and see what happens?

b


- spiff - 2011-11-14 15:46

you're running out of place because inlining patches are ... an interesting approach.

use a pastebin or trac or whatever and post a proper patch file.


- bladesuk1 - 2011-11-14 15:54

spiff Wrote:you're running out of place because inlining patches are ... an interesting approach.
use a pastebin or trac or whatever and post a proper patch file.

i would if a) i knew how to create patch files and b) i was looking for anything more than a sanity check on what i'm thinking as a potential way to get a library management server Smile

as i asked - does this look like like a feasible approach, or have i missed something? it seems to easy for someone else not to have spotted this earlier given that i know the subject's been raised before, but it's not beyond the realms of possibility...


- spiff - 2011-11-14 15:56

i can't really tell without the code being in context. but to me it looks like a poor man's solution.

i assume you cloned the code using git. to obtain the patch, all you have to do then is 'git diff > patchfile'


- bladesuk1 - 2011-11-14 16:25

spiff Wrote:i can't really tell without the code being in context

what do you need for context?

Quote:but to me it looks like a poor man's solution.

the ideal solution would be a dedicated server process. however, the current codebase isn't written in such a way that any such process can be cleanly extracted from the existing code, so there'd be a massive refactoring process to perform first to do this. for what you'd actually gain (and given the scarcity of people on the development team that seem interested in the server concept) this approach is, essentially, a quick fix to provide *something* that people can use until such time that the rest of the pieces are in place to create a proper server/client architecture, should xbmc development ever go down that route.

so, yes, i agree that it's basically a hack. however, as far as hacks go it's a clean and simple hack that actually replicates other similar processes in the codebase to change the program's behaviour (e.g. the nolirc option - this would be akin to a nogui option). most importantly, it keeps the 'server' code in the main codebase along with all the rest of the library access code so that it's all in one place and it can stay there until such time as the mainline code is architected in a way to make the server/client concept viable. it's also very minimal in terms of its impact, too - an extra flag, and a check on that flag to decide whether to run some code.

of course, if you have a better idea of how to go about this, then fill me in - but please bear in mind that a) i'm a web-and-database developer with very little C/C++ and b) i've got a toddler and a baby at home who'll take priority over pretty much everything Smile

Quote:i assume you cloned the code using git. to obtain the patch, all you have to do then is 'git diff > patchfile'

nope - just a straight download of the .zip file, i'm afraid, so no git involvement at all. i'll get onto that anyway as i'll need to pull it down and compile it on my home machine to see what happens.


- spiff - 2011-11-14 16:28

context would be a what a patch offer. it shows exactly where code is inserted, where code is removed and so on.


- Croaker - 2011-11-15 14:07

interesting...prepared similar approach a while ago and stalled for similar reason too: doughter took most of my time Smile


- pko66 - 2011-11-15 15:33

spiff Wrote:context would be a what a patch offer. it shows exactly where code is inserted, where code is removed and so on.

Hey spiff, bladesuk1, first my apologies for stepping to "explain" bladesuk1 modifications to spiff, maybe is not my place, but just trying to help...

I think that what bladesuk1 is trying to implement is a "server mode": me, and from the forum I think many other ppl, have an installation of several XBMC machines running with a central storage server (usually, a linux or windows not very powerful machine but with lots of hard disk space shared on the network). In that server, a MySQL daemon is used as a central repository for the database of the XBMC machines and a shared folder is used for storing media thumbnails. Also, usually some kind of (semi)automatic download process (flexget/transmission/couch potato/utorrent/whatever) adds new media continuously. The current XBMC architecture needs a XBMC instance (and only one, because two instances simultaneusly trying to update will break the database) to scrape the media and generate thumbnails.

The problem is, the server usually has not graphical capability to run XBMC, maybe the server does not even has an attached screen, so the database needs to be update from one of the clients manually (I have xbmc installed in my main windows computer just to do that). I think what blasesuk1 is trying to implement is a "server mode" xbmc that, simply, runs without GUI and does nothing but running the scrapers from time to time. That could be running in the server (or, maybe even better, in a virtual machine inside the server that could be virtually switched on and off when needed) and will update the database and create the thumbnails automatically whenever is needed. Maybe a "start, look for and scrape new media, optionally clean database and then exit when finished" mode could be included.

I, for one, would find that extremely useful.


- branlr - 2011-11-15 16:33

Indeed--it seems foolish to bog down the weak server system with a full XBMC install, but otherwise, you will be slaving your clients to another client machine that also must more or less remain running all of the time.

Especially when you consider that playback of the files isn't even possible on some of these headless servers, it makes sense to have a way of using the server features of XBMC without all of that overhead.

Although, it would be nice to have some sort of GUI for this "mode" so that certain library-relevant addons could be run, such as logo downloaders, automatic deletion, periodic update....

But, maybe that's implemented in the mysterious code above Laugh


- TugboatBill - 2011-11-15 17:51

This would be very helpful. I have an ESX system I use for my servers. With several XBMC boxes in the house I set up a server w/MySQL as my XBMC server. My plan was to do the scrapping on the server with an install of XBMC there too. Alas, XBMC won't run on it as virtual systems just don't have the video drivers that XBMC demands. Sad