libVLC VLM example

This forum is about all development around libVLC.
desp
Blank Cone
Blank Cone
Posts: 11
Joined: 20 May 2009 11:59

libVLC VLM example

Postby desp » 01 Aug 2012 10:51

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!

Jean-Baptiste Kempf
Site Administrator
Site Administrator
Posts: 37523
Joined: 22 Jul 2005 15:29
VLC version: 4.0.0-git
Operating System: Linux, Windows, Mac
Location: Cone, France
Contact:

Re: libVLC VLM example

Postby Jean-Baptiste Kempf » 01 Aug 2012 22:48

To be honest, I wouldn't be surprised if the libvlc_vlm code to have some internal issues.
Jean-Baptiste Kempf
http://www.jbkempf.com/ - http://www.jbkempf.com/blog/category/Videolan
VLC media player developer, VideoLAN President and Sites administrator
If you want an answer to your question, just be specific and precise. Don't use Private Messages.

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

Re: libVLC VLM example

Postby Rémi Denis-Courmont » 01 Aug 2012 23:05

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.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

desp
Blank Cone
Blank Cone
Posts: 11
Joined: 20 May 2009 11:59

Re: libVLC VLM example

Postby desp » 02 Aug 2012 08:52

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?

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

Re: libVLC VLM example

Postby Rémi Denis-Courmont » 02 Aug 2012 09:02

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.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

desp
Blank Cone
Blank Cone
Posts: 11
Joined: 20 May 2009 11:59

Re: libVLC VLM example

Postby desp » 02 Aug 2012 09:21

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 :)

desp
Blank Cone
Blank Cone
Posts: 11
Joined: 20 May 2009 11:59

Re: libVLC VLM example

Postby desp » 02 Aug 2012 15:06

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.."); }

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

Re: libVLC VLM example

Postby Rémi Denis-Courmont » 02 Aug 2012 15:31

Controlling LibVLC from its own event callback is going to deadlock. No big surprises there.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

desp
Blank Cone
Blank Cone
Posts: 11
Joined: 20 May 2009 11:59

Re: libVLC VLM example

Postby desp » 02 Aug 2012 15:37

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?

sherington
Cone that earned his stripes
Cone that earned his stripes
Posts: 491
Joined: 10 Sep 2008 11:57
VLC version: master
Operating System: Linux

Re: libVLC VLM example

Postby sherington » 02 Aug 2012 19:33

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.


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 4 guests