[LINUX] xbmc server: possible quick implementation?

  Thread Rating:
  • 1 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
bladesuk1 Offline
Junior Member
Posts: 32
Joined: Jul 2011
Reputation: 0
Lightbulb  [LINUX] xbmc server: possible quick implementation?
Post: #1
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
find quote
spiff Offline
Retired Developer
Posts: 12,386
Joined: Nov 2003
Post: #2
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.
find quote
bladesuk1 Offline
Junior Member
Posts: 32
Joined: Jul 2011
Reputation: 0
Post: #3
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...
find quote
spiff Offline
Retired Developer
Posts: 12,386
Joined: Nov 2003
Post: #4
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'
find quote
bladesuk1 Offline
Junior Member
Posts: 32
Joined: Jul 2011
Reputation: 0
Post: #5
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.
find quote
spiff Offline
Retired Developer
Posts: 12,386
Joined: Nov 2003
Post: #6
context would be a what a patch offer. it shows exactly where code is inserted, where code is removed and so on.
find quote
Croaker Offline
Member
Posts: 61
Joined: Mar 2010
Reputation: 0
Post: #7
interesting...prepared similar approach a while ago and stalled for similar reason too: doughter took most of my time Smile
find quote
pko66 Offline
Senior Member
Posts: 191
Joined: Dec 2006
Reputation: 0
Post: #8
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.
find quote
branlr Offline
Fan
Posts: 356
Joined: Dec 2009
Reputation: 3
Location: I live in Chicago.
Post: #9
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
find quote
TugboatBill Offline
Posting Freak
Posts: 829
Joined: Oct 2009
Reputation: 7
Post: #10
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
find quote
Croaker Offline
Member
Posts: 61
Joined: Mar 2010
Reputation: 0
Post: #11
pko66 Wrote: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.

Just want to second that as it describes my situation 100% Big Grin

- ubuntu server with MySQL, transmission, tvheadend, smb-shares, ...
- office-pc with embermm (and XBMC Eden testing, so not compatible with the others)
- 2 other XBMC boxes (Dharma for now, more to come, perhaps 1 OpenElec when they reach Eden)

so when new media arrives i have to
- unpack and move to correct folders (not automated this, not XBMC stuff)
- run renamer tool (also not XBMC stuff)
- run embermm and scrape (generates NFO+images)
- go to living room or get laptop running (start XBMC)
- start library update

as my collection grows nearly every day i have to perform those steps often and as the amount of data grows, some steps take a significant amount of time (1000+ movies, 20+ series about 5 modified often)

another crappy thing is this:
- new episodes arrive, but only english NFO data available, so take this for now
- XBMC shows en
- a week later german info is available, so getting that
- XBMC needs refresh and that kills the 'latest episodes' listing as the already watched go to the top of the list

this applies to movies too.
find quote
bladesuk1 Offline
Junior Member
Posts: 32
Joined: Jul 2011
Reputation: 0
Post: #12
it's exactly the situation you're talking about (albeit i'm not yet sharing thumbnails, but that's on the cards when i get some time). i'm basically trying to stop all of the graphical stuff from starting up by using a command line switch. yes, it's still a full installation of xbmc, but i'd hope that the scrapers and database interaction would be able to run headless... keep your fingers crossed!

yes, it would be nicer if all i was doing was running something to populate a database (the scraper utilities and so on) without any additional code overhead, but this side of the code isn't something that can currently be run independently as it stands. also, the database structures and so on change pretty much with every revision (what are we on, db revision 57 now or something like that?), so there's no way in hell you'd want to start writing a new entirely separate codebase to interact with those database changes as then you're maintaining the same code in two places. you'd have to essentially split the database management side of things off entirely and re-architect xbmc to use that project for the media server instead for that to work. occam's razor (for me) suggests keeping the code in the same place, and basically just not running anything that isn't required to do this and only this.

my initial post isn't up-to-date any more - the git revision was different to the dharma code i was looking at, so i've tried to switch to the git codebase instead. i'm most of the way there, but last time i tried it didn't start, and now i can't get the damn thing to compile. i'm pulling from git again, and i'm going to try from there to see what i can do. i'll let you know what happens Smile
find quote
Croaker Offline
Member
Posts: 61
Joined: Mar 2010
Reputation: 0
Post: #13
so *fingers_crossed* Smile
find quote
bladesuk1 Offline
Junior Member
Posts: 32
Joined: Jul 2011
Reputation: 0
Post: #14
haven't been able to test it as i'm currently remote, but *something* is running without a gui and hasn't fallen over for a while. if anyone else is in a position to try it out and see if it does what's expected, then by all means give it a go and let me know how you get on.

apply the patch, compile, and start it with xbmc --no-test --server and see what happens, i suppose!

anyways, here's the pastebin link:

http://pastebin.com/HzgEhdQ9
find quote
bladesuk1 Offline
Junior Member
Posts: 32
Joined: Jul 2011
Reputation: 0
Post: #15
and it looks like the webserver's running along with the eventserver, and it's connecting to the database. however, the jsonrpc side of things isn't starting up at the moment according to the logs:

ERROR: JSONRPC Server: Failed to bind serversocket

of course, there's no mention of which socket it's trying to use, and i've no idea if that's configurable anyway. still, it's a start, and proves that the general idea seems to be workable. if i can get the jsorpc server to start up, that should give us the back-end server that we want to play with Smile

i'm still getting masses of mysql server connections, mind - don't know what the hell's going on with that, but it might be a known bug:

http://trac.xbmc.org/ticket/12156
find quote
Post Reply