Posts: 73
Joined: Aug 2016
Reputation:
0
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?
Posts: 1,506
Joined: Nov 2013
json. it should do just fine with polling. also there is a notification/push api for a lot of stuff.
Posts: 73
Joined: Aug 2016
Reputation:
0
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.
Posts: 1,506
Joined: Nov 2013
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).
Posts: 73
Joined: Aug 2016
Reputation:
0
2016-08-22, 12:30
(This post was last modified: 2016-08-22, 12:30 by M-Reimer.)
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?
Posts: 1,506
Joined: Nov 2013
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
Posts: 73
Joined: Aug 2016
Reputation:
0
2016-08-22, 13:47
(This post was last modified: 2016-08-22, 14:07 by M-Reimer.)
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.
Posts: 73
Joined: Aug 2016
Reputation:
0
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?
Posts: 1,663
Joined: Jun 2011
Reputation:
119
2016-08-22, 15:01
(This post was last modified: 2016-08-22, 15:03 by Roman_V_M.)
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.
Posts: 19,982
Joined: May 2009
Reputation:
451
nickr
Retired Team-Kodi Member
Posts: 19,982
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.)