How to detect and handle output errors
Posted: 01 Jun 2014 22:04
I'm adding VLC output audio streaming (to a Shoutcast server for example) to my software. I'm already using VLC to receive input streams and that works fine. Output streaming works fine as well, except when something goes wrong.
I've subscribed to libvlc_MediaPlayerEncounteredError events using libvlc_event_attach. But if something goes wrong (for example a shoutcast server is not available), the callback in my software never gets called. What's worse: I'm using IMEM to send audio to VLC, and if I call libvlc_media_player_stop the program blocks until I return some data in the callback that was set with --imem-get=<address>. But when there is an output error, this callback is never called (I could use that to detect an error situation) and the stop function locks as well.
To be clear: If there's no error situation, the stop function does not lock, also I'm not calling it from the same thread that contains the message pump (which also still works during a lockup). If I only call release, it works - but I'm afraid of memory or other leaks...
So, I'd like to know how to properly detect and handle this type of errors.
I've subscribed to libvlc_MediaPlayerEncounteredError events using libvlc_event_attach. But if something goes wrong (for example a shoutcast server is not available), the callback in my software never gets called. What's worse: I'm using IMEM to send audio to VLC, and if I call libvlc_media_player_stop the program blocks until I return some data in the callback that was set with --imem-get=<address>. But when there is an output error, this callback is never called (I could use that to detect an error situation) and the stop function locks as well.
To be clear: If there's no error situation, the stop function does not lock, also I'm not calling it from the same thread that contains the message pump (which also still works during a lockup). If I only call release, it works - but I'm afraid of memory or other leaks...
So, I'd like to know how to properly detect and handle this type of errors.
Code: Select all
vlcInstance = libvlc_new(sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args);
assert(vlcInstance != NULL);
libvlc_media_t *m = libvlc_media_new_location (vlcInstance, "imem://");
assert(m != NULL);
mp = libvlc_media_player_new_from_media (m);
libvlc_media_release (m); m = NULL;
assert(mp != NULL)
libvlc_event_manager_t* em = libvlc_media_player_event_manager(mp);
int r = libvlc_event_attach(em, libvlc_MediaPlayerEncounteredError, &VLCErrorCallback, this);
assert(r==0);
int r2 = libvlc_media_player_play (mp);
assert(r2==0);
Code: Select all
libvlc_media_player_stop (mp); // HANGS in case of error
libvlc_media_player_release (mp); mp = NULL; // HANGS in case of error (if I skip stop)
libvlc_release (vlcInstance); vlcInstance = NULL;