Search code examples
c++visual-studioqtlibvlc

qt ip camera stream libvlc return values


I am using Qt and libvlc to create a gui for an ip camera stream. After i finished it i started testing it against wrong values NULLs... etc. My problem is that when i give a wrong string as network link i dont get NULL as return values. A portion of the code is this

const char * const vlc_args[] = {
    "--preferred-resolution=576",
    "--network-caching=250",
    "--no-audio"
};
my_vlcInstance = libvlc_new(3, vlc_args);
if (my_vlcInstance == NULL){
    emit sendDebugMessage("Couldn't create vlc instance", "Red");
    return;
}
my_LiveMedia = libvlc_media_new_location(my_vlcInstance, link.toStdString().c_str());
if (my_LiveMedia == NULL){
    emit sendDebugMessage("Error installing media", "Red");
    return;
}
my_LiveMediaPlayer = libvlc_media_player_new_from_media(my_LiveMedia);
if (my_LiveMediaPlayer == NULL){
    emit sendDebugMessage("Error creating media player", "Red");
    return;
}

now link is a QString containing the network link. I know that bad things happen as i can see the errors in the Visual studio debug window. "core input error: open of `dsfgdfgfg' failed" "Your input can't be opened" and stuff like that. So why cant i catch these errors?

Furthermore... when i push my start recording button a file is produced (corrupted obviously as there is no stream) and libvlc function calls dont return the errors as specified in the documentation. For this for example:

if (libvlc_media_player_play(my_LiveMediaPlayer) == 0){
    emit sendDebugMessage("Live mode started successfully", "Green");
    isLive = true;
}

So how do i catch the bad link?


Solution

  • I solved my problem with the libvlc_media_player_get_state function. I ignore the libvlc_media_player_play return value and i just poll the current state of the media player until i get a different state from IDLE/CLOSE and OPENING. On the bad links i get an ERROR state and on the correct links i get PLAYING state.