diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2015-03-29 16:29:20 +0200 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2015-03-29 16:29:20 +0200 |
commit | 2cf75c9364300274bcb131d2a6adf50eab12831d (patch) | |
tree | 1ad2765fd045b13f907ced3ab5f040bf82ecc5c6 | |
parent | 8861236aa6ced1e0a5ff67e739ad8130d5093e10 (diff) | |
download | toolame-dab-2cf75c9364300274bcb131d2a6adf50eab12831d.tar.gz toolame-dab-2cf75c9364300274bcb131d2a6adf50eab12831d.tar.bz2 toolame-dab-2cf75c9364300274bcb131d2a6adf50eab12831d.zip |
Fix vlc input error handling
-rw-r--r-- | audio_read.c | 12 | ||||
-rw-r--r-- | toolame.c | 5 | ||||
-rw-r--r-- | vlc_input.c | 12 | ||||
-rw-r--r-- | vlc_input.h | 2 |
4 files changed, 19 insertions, 12 deletions
diff --git a/audio_read.c b/audio_read.c index 20ac1dc..0556f13 100644 --- a/audio_read.c +++ b/audio_read.c @@ -237,12 +237,14 @@ unsigned long read_samples (music_in_t* musicin, short sample_buffer[2304], fprintf (stderr, "Hit end of WAV audio data\n"); } else if (glopts.input_select == INPUT_SELECT_VLC) { - size_t bytes_read = vlc_in_read(sample_buffer, sizeof(short) * (int)samples_read); - if (bytes_read == 0) { - fprintf (stderr, "Hit end of VLC audio data\n"); + ssize_t bytes_read = vlc_in_read(sample_buffer, sizeof(short) * (int)samples_read); + if (bytes_read == -1) { + fprintf (stderr, "VLC input error\n"); + samples_read = 0; + } + else { + samples_read = bytes_read / sizeof(short); } - - samples_read = bytes_read / sizeof(short); } /* @@ -1060,7 +1060,10 @@ void parse_args (int argc, char **argv, frame_info * frame, int *psy, exit (1); } *num_samples = MAX_U_32_NUM; - vlc_in_prepare(glopts.verbosity, samplerate, inPath); + if (vlc_in_prepare(glopts.verbosity, samplerate, inPath) != 0) { + fprintf(stderr, "VLC initialisation failed\n"); + exit(1); + } } else { fprintf(stderr, "INVALID INPUT\n"); diff --git a/vlc_input.c b/vlc_input.c index 1abf9d1..07cb859 100644 --- a/vlc_input.c +++ b/vlc_input.c @@ -142,13 +142,10 @@ int vlc_in_prepare(unsigned verbosity, unsigned int rate, const char* uri) head_buffer = vlc_buffer_new(); // Start playing - libvlc_media_player_play(m_mp); - - fprintf(stderr, "VLC launched.\n"); - return 0; + return libvlc_media_player_play(m_mp); } -size_t vlc_in_read(void *buf, size_t len) +ssize_t vlc_in_read(void *buf, size_t len) { size_t requested = len; for (;;) { @@ -197,6 +194,11 @@ size_t vlc_in_read(void *buf, size_t len) pthread_mutex_unlock(&buffer_lock); usleep(100); + + libvlc_media_t *media = libvlc_media_player_get_media(m_mp); + if (libvlc_media_get_state(media) == libvlc_Error) { + return -1; + } } abort(); diff --git a/vlc_input.h b/vlc_input.h index 976a7e7..1614ae3 100644 --- a/vlc_input.h +++ b/vlc_input.h @@ -37,7 +37,7 @@ void handleStream( int vlc_in_prepare(unsigned verbosity, unsigned int rate, const char* uri); // Read len audio bytes into buf -size_t vlc_in_read(void *buf, size_t len); +ssize_t vlc_in_read(void *buf, size_t len); #endif |