Page 1 of 1

Lifetime of libvlc_new args

Posted: 23 Oct 2018 16:07
by User101
Hello,
I'm currently implementing the argument option for libvlc_new in rust.
Because of rust internal Strings to c_string conversion I have to ask: does the argument have to be alive longer than the call of libvlc_new ?

Example in pseudo code

Code: Select all

var a = ["--no-video"]; var instance = libvlc_new(1,a); free(a); .. use instance
I've tried digging through the source but the amount of places where arg is used and the missing doc about the lifetime of the argument makes it pretty hard to understand whether or not I need to keep this variable allocated.

Re: Lifetime of libvlc_new args

Posted: 23 Oct 2018 16:08
by User101
(Also I'm welcoming hints for how to disable video playback programmatically, instead of arguments.)

Re: Lifetime of libvlc_new args

Posted: 24 Oct 2018 04:51
by mfkl
https://github.com/videolan/vlc-3.0/blo ... .c#L51-L52
I'd say you should be fine freeing them after the call has returned. Try it anyway.
(Also I'm welcoming hints for how to disable video playback programmatically, instead of arguments.)
You need to use

Code: Select all

libvlc_media_tracks_get libvlc_video_set_track

Re: Lifetime of libvlc_new args

Posted: 24 Oct 2018 12:30
by User101
Thanks for the answer.
Yeah, in retrospect it makes sense that this is a full copy of argv..
Edit: I've tried it and it also doesn't crash, did some verification with valgrind.

About get_track & set I'll have to see. My understanding was that you can't do this until media has started when it's a stream. But I'll try again today, this at least steers me on the right track ;) .

Re: Lifetime of libvlc_new args

Posted: 24 Oct 2018 21:32
by RĂ©mi Denis-Courmont
Please refer to Doxygen. The only supported way to use libvlc_new() is to pass zero arguments, and then your question is moot.