User Tools

Site Tools


doc:appunti:software:kodi_addon

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
doc:appunti:software:kodi_addon [2023/05/26 16:07] – [Cannot execute a graphical external program] niccolodoc:appunti:software:kodi_addon [2023/05/26 17:05] (current) – [How to start an external program from Kodi] niccolo
Line 278: Line 278:
 After many hours of trying and failing, it turned out that **it is not possibile to start an external program** from Kodi and use the **graphic display**; at least it is not possible if Kodi is **running without a full windowing system** (e.g. X11). After many hours of trying and failing, it turned out that **it is not possibile to start an external program** from Kodi and use the **graphic display**; at least it is not possible if Kodi is **running without a full windowing system** (e.g. X11).
  
-FIXME+When Kodi is installed on the **Raspberry Pi** using the **RaspiOS** operating system (based on Debian GNU/Linux 11 Bullseye), the program is started by the binary program **%%kodi.bin%%** using the argument **%%--standalone%%**.
  
-  * **[[https://kodi.wiki/view/External_players|Kodi External players]]**+**kodi-standalone** on the Raspberry Pi uses the GBM (Generic Buffer Management) windowing system to draw its graphics via the Mesa (an open source implementation of the OpenGL API). Other platforms supported by kodi-standalone are X11 and WaylandYou can see the following line into the **kodi.log**:
  
 +<code>
 +INFO <general>: CApplication::CreateGUI - using the gbm windowing system
 +</code>
 +
 +GBM/KMS only supports one "DRM master". Other applications can only use the screen when going through this master. Kodi is launched through a wrapper that uses chvt to switch X away from being the DRM master and allow kodi to become it. Without kodi supporting relinquishing being the master when launching the app and reacquiring it afterwards then launching another gui app isn't possible.
 +
 +You can verify if it is possibile to lanuch a simple graphical program like **kmscube** (from the homonymous Debian package). Just execute the command:
 +
 +<code bash>
 +# /dev/dri/card0 is /dev/dri/by-path/platform-soc:gpu-card
 +kmscube -D /dev/dri/card0
 +</code>
 +
 +If Kodi is not running the kmscube runs nicely, but if Kodi is running (you can launch the program using ''xbmc.executescript()'' as explained below), you will get the following error:
 +
 +<code>
 +failed to set mode: Permission denied
 +</code>
 +
 +If you use ''strace'' to debug the error, you can see that the problem is with the ''/dev/dri/by-path/platform-soc:gpu-card'' device:
 +
 +<code>
 +ioctl(3, DRM_IOCTL_MODE_SETCRTC, 0x7e9e17f8) = -1 EACCES (Permission denied)
 +</code>
 +
 +==== How to start an external program from Kodi ====
 +
 +I tried (but failed) to start a Python graphical program from Kodi. Because there is not an X11 windowing system, I tried **Pygame** with the drivers **directfb**, **fbcon** or **svgalib**. No problem if Kodi is stopped, Permission denied on the display if Kodi is running. Using the Python3 OpenGL module I was able to create a graphical program only under the X11 environment (using the ''DISPLAY'' environment variable).
 +
 +To execute an external program from my add-on video plugin, I used the following two methods. The first one just starts an external Python script when the code is executed:
 +     
 +<code python>
 +# This works only for a Python script.
 +# Notice "special://home" is "/home/kodi/.kodi" on the Raspberry Pi.
 +xbmc.executescript('special://home/bin/run-script.py')
 +</code>
 +
 +This second method will add a context menu item to the add-on ''ListItem'', which will launch the external program when selected:
 +
 +<code python>
 +# Add a context menu item to the add-on xbmcgui.ListItem object.
 +# This works only for a Python script.
 +li.addContextMenuItems([('Photo Reframe', 'RunScript(special://home/bin/run-script.py,arg1)')])
 +</code>
 +
 +A third method should be the following, but I did not tried it:
 +
 +<code python>
 +xbmc.executebuiltin('XBMC.RunScript(special://home/bin/run-script.py)')
 +</code>
 +
 +Other non-tested code to execute plugins or scripts:
 +
 +<code python>
 +xbmc.executebuiltin('RunPlugin(plugin://plugin.video.youtube/?addon_id=plugin.video.example)')
 +xbmc.executebuiltin('RunPlugin("plugin.video.something")')
 +xbmc.executebuiltin('RunAddon("script.something")')
 +</code>
 +
 +  * **[[https://github.com/graysky2/kodi-standalone-service/blob/master/README.md|kodi-standalone-service]]**
 +  * **[[https://en.wikipedia.org/wiki/Mesa_(computer_graphics)|Mesa]]**
 +  * **[[https://en.wikipedia.org/wiki/OpenGL|OpenGL]]**
 +  * **[[https://forum.kodi.tv/showthread.php?tid=354687|Can RasPi Kodi use VLC for its player]]**
 +  * **[[https://kodi.wiki/view/External_players|Kodi External players]]**
 +  * **[[https://kodi.wiki/view/Settings/System/Display|Kodi: Settings, System, Display]]**
 +  * **[[https://stackoverflow.com/questions/54452592/how-to-start-another-addon-from-a-kodi-addon|How to start another addon from a kodi addon]]**
 +  * **[[https://stackoverflow.com/questions/46083182/kodi-python-how-to-call-another-addon-and-if-not-installed-but-present-in-rep|Kodi python - how to call another addon and, if not installed but present in repo, ask to install it]]**
  
 ===== Web References ===== ===== Web References =====
doc/appunti/software/kodi_addon.1685110064.txt.gz · Last modified: 2023/05/26 16:07 by niccolo