-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
media_new_callbacks: c_char_p for foreign buffer #117
Comments
media_new_callbacks
: c_char_p
for foreign buffer
Just for reference, this looks like it is similar to what I encountered with callbacks for |
Your solution seems appropriate. It could be generalized into a helper function, to use in all relevant locations. The issue here is to be able to distinguish in the generator between the cases where c_char_p is appropriate, and the cases where a cast/memmove is necessary. This does not seem possible by introspecting the code alone, some heuristics have to be found. I will gladly integrate contributions if you get something. |
After a quick look at the code, I see that constness information for parameters is discarded python-vlc/generator/generate.py Lines 688 to 696 in 74bcbb0
You may have already evaluated to use this information to distinguish between immutable/mutable data, and so to use it to decide whether to use What do you think about this? |
Well spotted, it would be a first step to allow for proper ctypes mapping. This could be stored as a new property of the Par class, which would allow to do specific mapping. Do you want to try it? |
DISCLAIMER
I'm new both to
libvlc
andctypes
, so please correct me if I'm wrong on something.I'm experimenting with
media_new_callbacks
and I addressed some problems defining the read callbackread_cb
.In
libvlc
the signature for the read callback is defined aswhere the 2nd argument
unsigned char *buf
points to a buffer allocated by VLC and that the callback implementation should populate.In
python-vlc
this signature is mapped tovlc.CallbackDecorators.MediaReadCb
that iswhere the type of the 2nd argument (the 3rd of this signature, since the 1st should be the return type) is
ctypes.c_char_p
.In my knowledge,
ctypes.c_char_p
does not allow to change the value of the pointed data, and if you request the value, you get a copy of it (usually, I see it used with immutable objects). Moreover, inside the callback, the buffer parameter is automatically translated to a<class bytes>
, so I was not able to populate the VLC buffer.After a lot of tests, I decided to use my own signature of
MediaReadCb
by changingc_char_p
toPOINTER(c_char)
, which now isand now from inside the read callback, I'm able to do something like
and it works!
Is this a real problem or I can do it with
c_char_p
(can I cast it or get the pointer? from ctypes documentation I didn't find anything in the direction of "pointer to mutable").Thank you in advance for any feedback!
The text was updated successfully, but these errors were encountered: