Page 1 of 1

libVLC VLM example

Posted: 01 Aug 2012 10:51
by desp
Hi there,
i am using 2.x libvlc version and want to use vlm functionality to stream "sheduled" streams (udp, rtp protocols). But i end up with strange problems such a blocking in libvlc_vlm_stop_media or in some more certain libvlc_vlm_* functions in my own libvlc_VlmMediaInstanceStatusEnd event callback. What i want is actually just to stop current streaming in any time, or continue streaming another file when current one is finished. I need some decent libvlc_vlm_* usage examples or just advices to find out what i am doing wrong. To clear out my actual problem i provide some code examples:

Registering event handler:

Code: Select all

eventManager = libvlc_vlm_get_event_manager(vlc); libvlc_event_attach(eventManager, libvlc_VlmMediaInstanceStatusEnd, vlcEventHandler, NULL);
My event callback

Code: Select all

void vlcEventHandler(const struct libvlc_event_t * evt, void * data) { printf("stream end?\n"); int ret = libvlc_vlm_stop_media(vlc, "media_name"); PINFO("Returned: %d", ret); // it does not print, prints -1 when media_name is faked one //int ret = libvlc_vlm_set_input(vlc, "media_name", "/home/algirdas/dev/live555/adstreamer/big_buck_bunny_1080p_surround.ts"); blocks here again //PINFO("Return value: %d", ret); //ret = libvlc_vlm_play_media(vlc, "media_name"); blocks here too //PINFO("Return value: %d", ret); }
Streaming (playing)

Code: Select all

libvlc_vlm_play_media(vlc, "media_name");
After *_play_media() call i use

Code: Select all

while (1) { sleep(1); }
Thanks!

Re: libVLC VLM example

Posted: 01 Aug 2012 22:48
by Jean-Baptiste Kempf
To be honest, I wouldn't be surprised if the libvlc_vlm code to have some internal issues.

Re: libVLC VLM example

Posted: 01 Aug 2012 23:05
by Rémi Denis-Courmont
Seriously, for scheduling, you may be better off implementing the timer in your application. You can use a normal LibVLC media player object then.

The VLM API is a bitch, if I may say.

Re: libVLC VLM example

Posted: 02 Aug 2012 08:52
by desp
Seriously, for scheduling, you may be better off implementing the timer in your application. You can use a normal LibVLC media player object then.
Huh? It is not about playback, it is about streaming to network or maybe libvlc_media_player_* module has streaming ability too which i did not notice. Can anyone give just simple streaming without VLM example to start with?

Re: libVLC VLM example

Posted: 02 Aug 2012 09:02
by Rémi Denis-Courmont
It's the same. You need to set the input path, the sout options, etc.

The only component that, alas, can currently really only be reached through VLM is RTSP VoD.

Re: libVLC VLM example

Posted: 02 Aug 2012 09:21
by desp
Thanks for your answers. So it depends only on sout i guess, i will try to read docs about it, thanks again. Will write here when i fail again :)

Re: libVLC VLM example

Posted: 02 Aug 2012 15:06
by desp
Ok, i got same problem about blocking as i said about from the start. Now all VLM functions are removed. I extracted my other code and tested vlc-only. Wrote my problems in code as comments. There it is:

Code: Select all

#include <vlc/libvlc.h> #include <vlc/libvlc_media.h> #include <vlc/libvlc_media_player.h> #include <vlc/libvlc_events.h> #include <stdio.h> #include <time.h> #include <unistd.h> #define PERROR(x,...) printf("ERROR: (%s) "x"\n", __func__, ##__VA_ARGS__) #define PWARNING(x,...) printf("WARNING: (%s) "x"\n", __func__, ##__VA_ARGS__) #define PINFO(x,...) printf("INFO: (%s) "x"\n", __func__, ##__VA_ARGS__) static int streaming = 1; static libvlc_instance_t *vlc; static libvlc_media_player_t *mediaPlayer; void vlcEventHandler(const struct libvlc_event_t * evt, void * data) { PINFO("stream end? %x", mediaPlayer); libvlc_media_t *m = libvlc_media_new_path(vlc, "movie_next.ts"); // PROBLEM: blocks from here libvlc_media_player_stop(mediaPlayer); libvlc_media_player_set_media(mediaPlayer, m); libvlc_media_player_play(mediaPlayer); PINFO("Does not reach here"); } int main(int argc, char * argv[]) { const char * sout = "--sout #std{access=udp,mux=ts,dst=239.1.1.2}"; const char * const vlcArgs[] = { "-I", "dummy", "--ignore-config", "--extraintf=logger", "--verbose=0", "--sout-all", "--sout", "#std{access=udp,mux=ts,dst=239.1.1.2}", "--sout-keep", "--no-skip-frames", "--no-drop-late-frames", "vlclog.log" }; const char * url = "movie1.ts"; libvlc_event_manager_t *eventManager; // VLC main job vlc = libvlc_new(sizeof(vlcArgs)/sizeof(vlcArgs[0]), (const char * const*)vlcArgs); libvlc_media_t *m = libvlc_media_new_path(vlc, url); libvlc_media_add_option(m, sout); // ANOTHER PROBLEM: this one is not working either, how to add whole sout line by this method? I need it for more dynamic use mediaPlayer = libvlc_media_player_new_from_media(m); libvlc_media_release(m); // events eventManager = libvlc_media_player_event_manager(mediaPlayer); libvlc_event_attach(eventManager, libvlc_MediaPlayerEndReached, vlcEventHandler, NULL); libvlc_media_player_play(mediaPlayer); PINFO("Entering loop"); while (streaming) { sleep(1); } PINFO("Exiting loop.."); }

Re: libVLC VLM example

Posted: 02 Aug 2012 15:31
by Rémi Denis-Courmont
Controlling LibVLC from its own event callback is going to deadlock. No big surprises there.

Re: libVLC VLM example

Posted: 02 Aug 2012 15:37
by desp
Oh, i understand now, but... how to avoid it? It seems i need to add more logics here, like set some extra vars and change player's state in some other places but not in event callbacks. Thanks. Btw, can i add sout line with libvlc_media_add_option() or it can be used only when creating vlc instance?

Re: libVLC VLM example

Posted: 02 Aug 2012 19:33
by sherington
Oh, i understand now, but... how to avoid it?
I simply send all the events I receive via the callback to a background thread. That other thread can serialise all the events and safely call back into libvlc.