initializing Xlib for Python bindings

This forum is about all development around libVLC.
sampsa
Blank Cone
Blank Cone
Posts: 42
Joined: 16 Dec 2014 13:54

initializing Xlib for Python bindings

Postby sampsa » 17 Nov 2016 16:06

Hi,

First of all thanks to Olivier for writing the python binding. It's great!

However, I have never managed to run vdpau with it, because of ..

Code: Select all

[00007f008404b8d8] vdpau_avcodec generic error: Xlib not initialized for threads [00007f008404b8d8] vdpau_avcodec generic error: Xlib is required for VDPAU
This is an "eternal problem": how to initialize Xlib from python. I've tried the vlc 2.2 python bindings, both examples "gtkvlc.py" and "qtvlc.py", i.e. the "gtkvlc.py" does have the following lines:

import gtk
gtk.gdk.threads_init()

But still no success when trying "gtkvlc.py".

Kind Regards,

Sampsa

Rémi Denis-Courmont
Developer
Developer
Posts: 15153
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: initializing Xlib for Python bindings

Postby Rémi Denis-Courmont » 17 Nov 2016 17:42

The process must call XInitThreads() before libvlc_new(). How to call XInitThreads() in any specific language is probably not very topical here.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

sampsa
Blank Cone
Blank Cone
Posts: 42
Joined: 16 Dec 2014 13:54

Re: initializing Xlib for Python bindings

Postby sampsa » 18 Nov 2016 13:27

Dear Remi,

Thanks for the .. reply.

If the python bindings dont work with vdpau/x11 as expected / suggested in the python bindings documentation, I think it's worth asking.
Luckily, I was able to solve this: all we need is a swig wrapped enclosing the XInitThreads() [filename: "pyx11.i"]:

Code: Select all

%module pyx11 %{ // each wrapper requires these initial lines #define SWIG_FILE_WITH_INIT #include <X11/Xlib.h> %} %inline %{ extern int XInitThreads(void); %}
Building the extension with setuptools is as easy. The following subroutine can be used to build the extension module in "setup.py":

Code: Select all

def make_pyx11(): d=[] c=[] l=[] lib=["X11"] s=[] return Extension("_pyx11",sources=["pyx11.i"],include_dirs=d,extra_compile_args=c,extra_link_args=l,libraries=lib,swig_opts=s)
.. after creating the python extension, we can call it in python (before importing the vlc module):

Code: Select all

i=pyx11.XInitThreads()
After this, I can get the Olivier's "qtvlc.py" example code to work correctly with vdpau. It does not complain about the uninitialized xlib anymore and, most importantly, I can see in the "Nvidia server settings" program (provided with the nvidia drivers) in "GPU 0" => "video engine utilization" the number becoming bigger than 0 %

I hope someone finds this post usefull..

Regards,

Sampsa

OlivierAubert
Developer
Developer
Posts: 92
Joined: 08 Mar 2007 15:43

Re: initializing Xlib for Python bindings

Postby OlivierAubert » 18 Nov 2016 15:30

Hello Sampsa

Your description of the problem is accurate. A simpler and more portable solution (than using swig) is to simply use ctypes to call the appropriate function. So something like

Code: Select all

x11 = ctypes.DLL("libX11.so") x11.XInitThreads()
before initializing the display code should be enough. Could you test it and (ideally) provide a patch to vlc.py so that I can integrate the change?

Olivier

sampsa
Blank Cone
Blank Cone
Posts: 42
Joined: 16 Dec 2014 13:54

Re: initializing Xlib for Python bindings

Postby sampsa » 18 Nov 2016 15:41

Hi Olivier,

Thank you for your reply. Silly me, being a swig-person I didn't think with ctypes. Your solution is indeed much simpler.

What do you think about this one..?

https://forum.videolan.org/viewtopic.php?f=32&t=136452

(did you get my test program..? ;)

Regards,

Sampsa

OlivierAubert
Developer
Developer
Posts: 92
Joined: 08 Mar 2007 15:43

Re: initializing Xlib for Python bindings

Postby OlivierAubert » 18 Nov 2016 19:10

For your test program, I do not have the required hardware, so I cannot test it.

sampsa
Blank Cone
Blank Cone
Posts: 42
Joined: 16 Dec 2014 13:54

Re: initializing Xlib for Python bindings

Postby sampsa » 28 Nov 2016 12:24

Just for the record, concerning that link:

https://forum.videolan.org/viewtopic.php?f=32&t=136452

We are unable to start several vlc instances using vdpau within the same application.. we have also tried with nvidia quadro series, that is supposed to handle unlimited number of h264 streams with vdpau. The vdpau accelerated video decoding works ok for a single vlc instance, but for several vlc instances, the video becomes choppy / corrupted.

On the other hand, launching *individual* vlc client programs, they all seem to use vdpau simultaneously and correctly (no choppiness, etc.)

I wonder if anyone has achieved running several vlc instances all using vpdau correctly with C(++) ?

If so, the problem might be python itself, and the "global interpreter lock" (GIL) - i.e. the reason why multithreading in python sucks.. on the other hand, video decoding without vdpau works ok with several vlc instances. I don't know how this is handled with ctypes.. I remember that in swig, one can release/acquire the gil within the C code..


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 5 guests