Skip to content

adding a server/headless mode to xbmc #890

Closed
wants to merge 1 commit into from

10 participants

@vajonam
vajonam commented Apr 20, 2012
  • re-based with pull instead of merge
  • cleaned up indenting

this allows a headless xbmc, that can be used to keep the DB upto date, when content is added automatically using an internet pvr like sickbeard or couchpotato

@jmarshallnz
Team Kodi member

Please squash down the commits and take care of any cosmetics (there's a double bracket (indent?) in 379884e.

Am I right that this is essentially a rebase of #542 ?

@vajonam
vajonam commented Apr 20, 2012

cleaned up rebased and squashed commits.

jmarshall yes that is right this a rebase of #542

@Montellese
Team Kodi member

First of all there's a lot of bad indentation in these changes. We use 2 spaces (not tabs) per indentation level. Furthermore you should squash the last two commits into the first. And you don't really need to put the URL to a github repo into the commit message as the commit would show up under your name anyway.

On topic I have to say I don't really like this because it's very hacky. After installing XBMC you first need to start it as usual (without the new --server command line option) to be able to configure it. So you'll need to install XBMC onto a machine which actually has a graphics card, an attached monitor etc. Once configured you can either remove the attached monitor etc or you can copy the XBMC installation onto a headless server and then run XBMC with --server there. The only other way I can see is to manually adjust guisettings.xml, which is even more hacky (and you can easily mess up the settings).

IMO that's so far from user-friendly that I can't even see it anymore.

@Montellese Montellese referenced this pull request Apr 21, 2012
Closed

xbmc server code #542

@amejia1
Team Kodi member
amejia1 commented Apr 21, 2012

I presume a dedicated XBMC server wouldn't need various configuration settings anyway. Ideally, a server instance of XBMC should be able to run with default settings and without the need of any config file. A local admin can then adjust settings via a config file, say /etc/xbmc/*.

@vajonam
vajonam commented Apr 22, 2012

I did already squash the code down. into a commit, am not sure why that isn't showing up as one commit. I have also fixed all the indents. again not sure why git hub isn't showing the squashed

regarding the actual code, I agree with most of the comments, except that you don't need a graphics card to install this package, I have tested this on a system without a card. But that being said the current dependencies on an ubuntu include a number of sdl packages.

The main point of this server is to be always available on the network so internet pvrs can notify it of changes and keep the db upto date. or to run periodic updates to keep db upto date for a multi seat install.

there is a lot of hackery in here I agree. What is the suggested approach to keep this moving forward?

@Montellese
Team Kodi member

@vajonam When I look at the rebased version of e.g. Application.cpp on github I still see a lot of bad indentation. Maybe your editor/IDE hides them from you?
And my comment with the graphics card wasn't meant as "you need a graphics card to install XBMC". I meant that you need to install it on a computer which has a monitor attached (and therefore needs an (internal or external) graphics card), because you need a monitor to view xbmc's GUI to change the settings/set up sources.

@amejia1 Well first of all you need to setup video sources etc because otherwise xbmc won't be of much use to you. This is something everyone must do. Then (at least) I always need to change the settings of the default scraper because they don't match my preferences. You'll also need to setup the corresponding services (upnp, webserver, json-rpc, airplay etc) if you want to be able to access your library from somewhere else. All the other settings that I normally change are GUI related so they won't be needed but at least setting up the sources is absolutely necessary (and probably adjusting the scrapers as well).
Sure this could be done in an extra configuration file but xbmc already has a ton of configuration files so not sure if adding another one is a good call. And it still means that the user needs to manually change a text file. While this is certainly no problem for the more advanced user (and linux user) I am pretty sure that if this hits an official build, everyone will want to try out the new "server mode" and then they end up frustrated because they don't know how to set it up or it's too difficult for them.

@vajonam
vajonam commented Apr 22, 2012

@Montellese, I use vi and set the tabstop and shiftinden and expandtab and then did a retab and ensured the indents a re okay. If you are mean the if-defs those indents aren't consistent in Application.cpp to being with, I have made them have no indents as per spec in the sections I touched.

@Montellese,@amejia1 assuming that mysql / shared database is used. there is no need for a sources or gui to adjust the scrapers. they can all be done from another headed machine. since all the scraper information is stored in the database anyway. Any additional sources and so on can also be configued from the headed machine again which gets added to the db. the scrapers and scanners all use this rather than the sources.xml anyway!

the only config this server needs its to point to the same mysql database, if it will make this less easy to stumble upon I can change it that the server mode can be set only by editing the advancedsettings.xml this will remove the -s or --server switch. Which would mean for now this would be just for advanced users who are familiar with using the advanced settings file.

as i see it this is what I see as the minimum requirements

  1. atleast 1 XMBC running in full GUI/Headed mode this will be used to configure.
  2. use of MySQL for a shared database
  3. ability to edit / create advancedsettings.xml for the server/headless under the userdata folder

I think this makes sense because. to use MySQL the user modified and edited an advancedsettings.xml anyway even in the headed GUI XBMC instance.

@Montellese Montellese commented on an outdated diff Apr 22, 2012
xbmc/Application.cpp
@@ -625,62 +628,67 @@ bool CApplication::Create()
}
#ifdef HAS_XRANDR
- g_xrandr.LoadCustomModeLinesToAllOutputs();
+ if (!g_application.IsServerMode())
+ {
@Montellese
Team Kodi member
Montellese added a note Apr 22, 2012

bad indentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@Montellese Montellese commented on an outdated diff Apr 22, 2012
xbmc/Application.cpp
#endif
// Init our DllLoaders emu env
init_emu_environ();
+ if (!g_application.IsServerMode())
+ {
@Montellese
Team Kodi member
Montellese added a note Apr 22, 2012

bad indentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@Montellese Montellese commented on an outdated diff Apr 22, 2012
xbmc/Application.cpp
{
- CLog::Log(LOGFATAL, "CApplication::Create: Unable to init windowing system");
- return false;
+ if (!g_Windowing.InitWindowSystem())
+ {
@Montellese
Team Kodi member
Montellese added a note Apr 22, 2012

bad indentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@Montellese Montellese commented on an outdated diff Apr 22, 2012
xbmc/Application.cpp
#if defined(__APPLE__) && !defined(__arm__)
// Configure and possible manually start the helper.
XBMCHelper::GetInstance().Configure();
#endif
+ if (!g_application.IsServerMode())
+ {
@Montellese
Team Kodi member
Montellese added a note Apr 22, 2012

bad indentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@Montellese
Team Kodi member

Just to show you what I mean I picked out a few places with bad indentation. I didn't bother to mark them all because they are pretty obvious when looking at the diff off this PR here on github.

@vajonam
vajonam commented Apr 22, 2012

@Montellese thats for pointing those out, stopped seeing them after seeing the patch for so long.. but doesn't look like this PR is going too far based on the discussion thus far?

@Montellese
Team Kodi member

@vajonam I know that feeling when you have seen some code for too long ;-)

What I stated above is just my personal opinion. Considering that I neither have multiple XBMC installations nor use MySQL I'm not really your target audience anyway.

@theuni
Team Kodi member
theuni commented Apr 23, 2012

I'm really not sure that this is the way to go here. Compare to #214

With a headless xbmc, you don't get much. But by using xbmc as a lib and being able to create a server around it, you could add lots of functionality that we would never want in mainline.

@vajonam
vajonam commented Apr 23, 2012

interesting, if this is path that we want to take, I can offer to code something but will need some help / direction I am just bit of hacker when it comes to XBMC i am afraid, enough to be dangerous!

what will be needed to achieve the following?

  • a server that listens exposing the http-api or jsonrpc api
  • updates a mysql db by running the scan and updating content.

wont this almost duplicate a lot of code that is already written in xbmc?

@theuni
Team Kodi member
theuni commented Apr 23, 2012

well, the idea would be to start breaking breaking stuff out of Application.cpp and into a "services" class.

So then you would have an application that includes xbmc's "services" header, starts those services, then does whatever else it needs to do. So there would be no duplication, it would be running the same code as the desktop binary.

I'm not opposed to the headless idea, but it does seem to conflict with the notion of having a libxbmc for similar functionality. So I just want to be sure we think it through before going either route.

@theuni
Team Kodi member
theuni commented Apr 23, 2012

I've pushed a branch that's updated for master. I'll get it cleaned up and working this week.

https://github.com/theuni/xbmc/tree/shared-lib

@blades
blades commented Apr 23, 2012

@theuni going down the lib route is definitely the preferred long-term solution to this. however, that's a long-term solution as opposed to something available right now, and on top of that there wasn't much interest in making that happen right at this moment in time. the original pull request i created was a quick hack to get something available with the bare minimum of changes such that we could have a working server mode available here and now that wasn't going to need a massive re-architecting of the mainline codebase. i fully agree that it's not the ideal solution, but it works, and it's available now with only a few minor changes to the mainline codebase that don't impact anything else.

ultimately, so long as there's a server mode, that's the important thing. people have been begging for this for a very, very long time, and i saw a simple and quick way of getting it working. personally, i don't particularly care how it's done, just that it is done. this was within my abilities; shared libraries and building an entirely new server application to use them isn't.

@theuni
Team Kodi member
theuni commented Apr 23, 2012

Well it's not an issue of getting it done, clearly the headless approach works. The issue is that once it goes in we have to support it. And indeed a server-mode is a big deal. Think of all the new-functionality requests we'll get and have to add to xbmc, for a short-term solution.

But rather than stalling for the future's sake, I'm working on getting something done up that resembles the current functionality here, but done in a lib-way.

@theuni
Team Kodi member
theuni commented Apr 23, 2012

Additionally, looking closer at the changes here...

Most of the things that are special-cased for server mode should instead just not be compiled in. For ex, X, SDL, peripherals, etc.. Otherwise we still end up with tons of deps.. unsuitable for installing in places where this would be the most helpful.

@theuni
Team Kodi member
theuni commented Apr 23, 2012

Ok, I've pushed some changes that do this using xbmc as a lib, while keeping the spirit of this PR. See my branch here: https://github.com/theuni/xbmc/tree/shared-lib

At the moment, it basically functions as @vajonam's headless binary would. The difference is that it is actually only a tiny stub application, that calls into libxbmc and blocks there. See here: https://github.com/theuni/xbmc/blob/shared-lib/xbmc/xbmc_headless.cpp for the example.

So it's very uninteresting in its current form. But. If we go this route, we can begin splitting things out into more reasonable chunks. For example, you may want a binary that does nothing more than serves XBMC's webinterface. In that case, a huge chunk of system libs could be removed, leaving you with a clean unit-testable application, or functional server.

The work isn't too bad, it mainly entails pulling Application::Create() and Application::Initialize apart and exposing the bits that start services to xbmc.h. Then, it would be dead-simple to create an application that just starts a few of our services and waits.

I think this also lends itself towards @jimfcarroll's world-domination plans, as iirc he was looking to nuke CApplication altogether.

@theuni
Team Kodi member
theuni commented Apr 23, 2012

Most credit for the above belongs to @dbrobins btw. I'll be sure to mention that in the commits if we go this way.

@dbrobins

Thanks. It would be great if the shared lib/headless changes finally made make it in in some form. :)

@pietheinstrengholt
Team Kodi member

Maybe just an idea.. Can't we ask Alasdair Campbell to have a look at this as well? He's Google Summer project is all about XBMC serving content by UPnP / DLNA. Would be nice to see a headless xbmc server serving content to other (xbmc) clients.

@blades
blades commented Apr 25, 2012

@theuni the only downside is that you've now got a separate application: it's not a server-mode within xbmc, but instead an entirely new application using a shared library. to be honest, that's not even remotely a problem, but it's not something that i had the temerity to suggest with my changes :p

my only intention with this was to provide a quick-win that could be in use, and indeed it's been in use for the last few months with a hardcore bunch who were happy to compile it for themselves on the original thread here: http://forum.xbmc.org/showthread.php?tid=114612

now that there's a better solution that does this properly, i'd much rather see this brought up to a usable state instead. yeah, i'm a little gutted that i don't end up actually contributing to the project, but i can console myself with the thought that i've poked and prodded it enough to get an xbmc server onto the radar!

to be honest, it'll be nice not to have to be constantly defending the approach i took with this, too. all i wanted was a quick win to give the dev team space to do it properly while giving those who wanted a server mode something usable to play with.

anyway. what needs to be done from here to get your new branch into a state whereby i can give the thread something to use? how would i go about running your headless version?

@theuni
Team Kodi member
theuni commented Apr 26, 2012

Wow, what a helpful response. You know we're supposed to be nerds with monstrous egos, right? :p

Here's how this really went. I have been meaning to get the lib concept into shape for quite a while. You guys came along with something that conflicted with it, so I had no choice but to do my part or shut up and let it go a different direction. So in that way, you definitely got things rolling.

All I've done so far is to get things building in a way that facilitates running headless. I created a stub app (xbmc_headless.bin) and verified that it runs the webserver.

The todo's mainly look like this:

  • Verify that the reorg in Application.cpp didn't break anything in the desktop usage of XBMC. @jmarshallnz had some valid concerns. This needs to happen first as we can't pull it in if it's breaking stuff.

  • Verify that server stuff actually works. There are bound to be some things that rely on the GUI being present. I don't know how to find these problems other than just hitting them during use.

  • Begin breaking things out into xbmc.h. Again, the hope is that run_xbmc() could go away, and the headless app could just launch individual services instead.

I could use some help with all of the above. I'd guess that the third probably won't be done until it hits mainline.

To help, just merge my branch, commit with --enable-shared-lib on or off, and start hacking.

I suppose I'll do some github cleanup. Will close this PR as well as the other, and do mine as an RFC. That will make it easier to discuss.

Thanks for the help!

@vajonam
vajonam commented Apr 26, 2012

@theuni where do you want feedback about bugs? forum or here?

@blades
blades commented Apr 26, 2012

well, i've got an ego somewhere around here if there's one missing :p

i have to admit, i know very, very little about C++. however, there's never a bad time to learn some new skills! i may need a little help to get things moving, though - is there a better way to communicate with you than via here? i'm happy to pass over my email address to you to take this off here, for example...

as to gui reliance, we did find a few bits for database updates (http://forum.xbmc.org/showthread.php?tid=114612&pid=985613#pid985613):

"You have to allow creation of two windows in Application.cpp:

  • g_windowManager.Add(new CGUIDialogMusicScan);
  • g_windowManager.Add(new CGUIDialogVideoScan);"

i also disabled some functionality in the builtins class when running as a server, just to be on the safe side, too.

@basrieter

Wow! I really appreciate that this is being picked up and supported by the XBMC team! Nice.

Would it be a good idea to start a central topic on this headless version on the XBMC forums so we can discuss builds, bugs and features there?

I myself an not a very skilled c++ coder. I did however created a tiny service addon that allows a user to schedule Video and Music backups on a daily basis. As soon as this headless server is official it might be a nice addition?

@xbmcfanboy

@theuni I would like to help. Can you give more information about "commit with --enable-shared-lib on or off" please.

@theuni
Team Kodi member
theuni commented May 1, 2012

@xbmcfanboy what OS are you running? I meant ./configure with --enable-shared-lib

I will need to discuss with the others, but I'd be ok with merging this in as soon as we could verify that the current functionality works as intended without breaking mainline. It's obviously a popular feature.

@blades: Thanks, I'll have a look at those. I'd much rather remove those dependencies on the gui than work around them, but I'm not sure what work is involved there yet.

@vajonam forum probably makes the most sense.

@theuni
Team Kodi member
theuni commented May 1, 2012

I've taken a stab at fixing the scan+gui dependency here: #916. That will mean we won't need those hacks for allowing certain windows to be created. As I mentioned above, I'd prefer to fix any of those dependencies rather than just working around them.

Once we get that into mainline (assuming it works!), I'll rebase my lib work and do a new PR. We can begin testing/discussing then.

@theuni
Team Kodi member
theuni commented Jun 6, 2012

Closing this in favor of #1049

@theuni theuni closed this Jun 6, 2012
@theuni theuni referenced this pull request Jun 12, 2012
Merged

Build Shared Lib #1049

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.