C++ calls to get infos from Kodi?
#1
Hello,

I have a LCD where I have C API to control it (graphical LCD).

I would like to be a bit creative and try to do some nice themed output on this LCD. I want to use the C++ Addon API to do this.

Which ways do I have to get information about the current Kodi status from C++? I need stuff like:
- What is currently active (Music, Video, Main menu)
- What is active in the current "application" (Artist, Title while playback or current menu item in main menu)
- If possible it would be nice to have access to raw PCM frames to display visualization on the LCD while music is played.

So far I didn't find the right API calls to do stuff like this.

There is an API to get data for visualizations, but does my addon have to be an "visualization addon" to get this data?
How can I get the information about the current status? I think JSON RPC could be a way, but how performant is this? Can I call it several times per second?
Reply
#2
json. it should do just fine with polling. also there is a notification/push api for a lot of stuff.
Reply
#3
OK. So I'll use JSON for the information fetching.

How does JSON notification/push work?

How to get the visualization data? Does this only work if I'm writing an visualization addon and my addon is set to be the default visualization? This part is nice to have/optional but would be some cool addition.
Reply
#4
json push is listening on a tcp port, 9090 iirc.

the visualization data you are interested in should be exposed as general info labels which you can fetch using a json query, i don't think those changes are announced (but it should be added imo).
Reply
#5
Thanks. I'll have a look at JSON RPC and try to find out how the visualization data is sent.

What would be the correct way to get my main loop? Does Kodi run my Addon directly in its own thread or do I have to launch my own to not block Kodi in some way?
Reply
#6
thing is, what you are trying to do has mostly been done in python / as external things thus far. there is no service-type binary add-ons yet, though it makes a lot of sense to add such beasts.

the good thing is you can draft the api exactly as you want it in regards to threads Wink
Reply
#7
So it may be the better idea to create a standalone daemon, right?
I need a solution that works for Kodi 16 as this is what my distributor ships and I don't want to compile everything on my own.
Reply
#8
(2016-08-22, 13:15)ironic_monkey Wrote: thing is, what you are trying to do has mostly been done in python / as external things thus far. there is no service-type binary add-ons yet, though it makes a lot of sense to add such beasts.


Technically, any addon can be binary except for a small "launcher" that must be in pure Python. But supporting such addons for variety of target systems will be real PITA.

(2016-08-22, 13:47)M-Reimer Wrote: I need a solution that works for Kodi 1.6 as this is what my distributor ships and I don't want to compile everything on my own.

There is no such thing as Kodi 1.6. As for "main loop" and such, Kodi launches a separate Python interpreter for each addon.
Reply
#9
I don't know much about python and I need C anyway to drive the LCD so my hope was to code this purely in C(++).

About "Kodi 1.6": I meant Kodi 16 (Jarvis).

I don't need "a variety of target systems". My display driver library is Linux-Only anyway.

I didn't find any mentioning about visualization data in any JSON-RPC documentation. Can someone give me a hint here?
Reply
#10
At this point general purpose addons can be written only in Python. Pure binary addons are restricted to a very limited set of domains, like PVR, audio encoders, visualizations and such.

But a Python program (and a Kodi addon is essentially a Python program) can have binary components written in C/C++. There are 2 main ways to do that: Ctypes which can work with generic shared libs (.dll/.so) but have limited capabilities, and Python-C API which allows you to use all Python features. Raw Python-C API is rather verbose and not very convenient, but there are helper tools/libraries, like Boost.Python, Pybind11, SWIG (the latter is used by Kodi itself to expose its features to Python). My personal preference is Pybind11 which is headers-only and supports modern C++ features.

As for visualization data, I guess the guys above misunderstood you. There is no way to tap into raw video/audio data from Python.
Reply
#11
Should the OP be looking at some code from visualisation addons? After all that's essentially what he is trying to make (although to play on a different screen) .
If I have helped you or increased your knowledge, click the 'thumbs up' button to give thanks :) (People with less than 20 posts won't see the "thumbs up" button.)
Reply
#12
(2016-08-22, 09:11)M-Reimer Wrote: There is an API to get data for visualizations, but does my addon have to be an "visualization addon" to get this data?
FYI, the same question was also asked here http://forum.kodi.tv/showthread.php?tid=223983

Oterwise I believe that you can currently use LCDproc for everything you want with the exception of the visualizations?

http://forum.kodi.tv/showthread.php?tid=143912

http://kodi.wiki/view/Add-on:XBMC_LCDproc

https://github.com/herrnst/script.xbmc.lcdproc

https://github.com/herrnst/script.xbmc.lcdproc/wiki

LCD and VFD displays used to be supported nativly by the XBMC/Kodi core before that addon, see:

http://kodi.wiki/view/LCDs

Maybe the API that the LCDproc addons uses could be extended to also do visualization?
Reply

Logout Mark Read Team Forum Stats Members Help
C++ calls to get infos from Kodi?0