/***************************************************************** * \brief read next part of data into buffer * \return -1 if error occured or no data available yet, otherwise - bytes read * NOTE: audio device works in non-blocking mode */ static int read_chunk(audio_in_t *ai, unsigned char *buffer) { int ret; switch (ai->type) { #ifdef CONFIG_ALSA case AUDIO_IN_ALSA: //device opened in non-blocking mode ret = snd_pcm_readi(ai->alsa.handle, buffer, ai->alsa.chunk_size); if (ret != ai->alsa.chunk_size) { if (ret < 0) { if (ret==-EAGAIN) return -1; mp_tmsg(MSGT_RADIO, MSGL_ERR, "\nError reading audio: %s\n", snd_strerror(ret)); if (ret == -EPIPE) { if (ai_alsa_xrun(ai) == 0) { mp_tmsg(MSGT_RADIO, MSGL_ERR, "Recovered from cross-run, some frames may be left out!\n"); } else { mp_tmsg(MSGT_RADIO, MSGL_ERR, "Fatal error, cannot recover!\n"); } } } else { mp_tmsg(MSGT_RADIO, MSGL_ERR, "\nNot enough audio samples!\n"); } return -1; } return ret; #endif #ifdef CONFIG_OSS_AUDIO case AUDIO_IN_OSS: { int bt=0; /* we must return exactly blocksize bytes, so if we have got any bytes at first call to read, we will loop untils get all blocksize bytes otherwise we will return -1 */ while(bt<ai->blocksize) { //device opened in non-blocking mode ret = read(ai->oss.audio_fd, buffer+bt, ai->blocksize-bt); if (ret==ai->blocksize) return ret; if (ret<0) { if (errno==EAGAIN && bt==0) return -1; //no data avail yet if (errno==EAGAIN) { usleep(1000); //nilling buffer to blocksize size continue; } mp_tmsg(MSGT_RADIO, MSGL_ERR, "\nError reading audio: %s\n", strerror(errno)); return -1; } bt+=ret; } return bt; } #endif default: return -1; } }
/***************************************************************** * \brief read next part of data into buffer * \return -1 if error occured or no data available yet, otherwise - bytes read * NOTE: audio device works in non-blocking mode */ static int read_chunk(audio_in_t *ai, unsigned char *buffer) { int ret; switch (ai->type) { #if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X) case AUDIO_IN_ALSA: //device opened in non-blocking mode ret = snd_pcm_readi(ai->alsa.handle, buffer, ai->alsa.chunk_size); if (ret != ai->alsa.chunk_size) { if (ret < 0) { if (ret==-EAGAIN) return -1; mp_msg(MSGT_RADIO, MSGL_ERR, MSGTR_MPDEMUX_AUDIOIN_ErrReadingAudio, snd_strerror(ret)); if (ret == -EPIPE) { if (ai_alsa_xrun(ai) == 0) { mp_msg(MSGT_RADIO, MSGL_ERR, MSGTR_MPDEMUX_AUDIOIN_XRUNSomeFramesMayBeLeftOut); } else { mp_msg(MSGT_RADIO, MSGL_ERR, MSGTR_MPDEMUX_AUDIOIN_ErrFatalCannotRecover); } } } else { mp_msg(MSGT_RADIO, MSGL_ERR, MSGTR_MPDEMUX_AUDIOIN_NotEnoughSamples); } return -1; } return ret; #endif #ifdef USE_OSS_AUDIO case AUDIO_IN_OSS: { int bt=0; /* we must return exactly blocksize bytes, so if we have got any bytes at first call to read, we will loop untils get all blocksize bytes otherwise we will return -1 */ while(bt<ai->blocksize){ //device opened in non-blocking mode ret = read(ai->oss.audio_fd, buffer+bt, ai->blocksize-bt); if (ret==ai->blocksize) return ret; if (ret<0){ if (errno==EAGAIN && bt==0) return -1; //no data avail yet if (errno==EAGAIN) { usleep(1000); continue;} //nilling buffer to blocksize size mp_msg(MSGT_RADIO, MSGL_ERR, MSGTR_MPDEMUX_AUDIOIN_ErrReadingAudio, strerror(errno)); return -1; } bt+=ret; } return bt; } #endif default: return -1; } }
int audio_in_read_chunk(audio_in_t *ai, unsigned char *buffer) { int ret; switch (ai->type) { #ifdef CONFIG_ALSA case AUDIO_IN_ALSA: ret = snd_pcm_readi(ai->alsa.handle, buffer, ai->alsa.chunk_size); if (ret != ai->alsa.chunk_size) { if (ret < 0) { mp_tmsg(MSGT_TV, MSGL_ERR, "\nError reading audio: %s\n", snd_strerror(ret)); if (ret == -EPIPE) { if (ai_alsa_xrun(ai) == 0) { mp_tmsg(MSGT_TV, MSGL_ERR, "Recovered from cross-run, some frames may be left out!\n"); } else { mp_tmsg(MSGT_TV, MSGL_ERR, "Fatal error, cannot recover!\n"); } } } else { mp_tmsg(MSGT_TV, MSGL_ERR, "\nNot enough audio samples!\n"); } return -1; } return ret; #endif #ifdef CONFIG_OSS_AUDIO case AUDIO_IN_OSS: ret = read(ai->oss.audio_fd, buffer, ai->blocksize); if (ret != ai->blocksize) { if (ret < 0) { mp_tmsg(MSGT_TV, MSGL_ERR, "\nError reading audio: %s\n", strerror(errno)); } else { mp_tmsg(MSGT_TV, MSGL_ERR, "\nNot enough audio samples!\n"); } return -1; } return ret; #endif default: return -1; } }
int audio_in_read_chunk(audio_in_t *ai, unsigned char *buffer) { int ret; switch (ai->type) { #ifdef CONFIG_ALSA case AUDIO_IN_ALSA: ret = snd_pcm_readi(ai->alsa.handle, buffer, ai->alsa.chunk_size); if (ret != ai->alsa.chunk_size) { if (ret < 0) { mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AUDIOIN_ErrReadingAudio, snd_strerror(ret)); if (ret == -EPIPE) { if (ai_alsa_xrun(ai) == 0) { mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AUDIOIN_XRUNSomeFramesMayBeLeftOut); } else { mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AUDIOIN_ErrFatalCannotRecover); } } } else { mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AUDIOIN_NotEnoughSamples); } return -1; } return ret; #endif #ifdef CONFIG_OSS_AUDIO case AUDIO_IN_OSS: ret = read(ai->oss.audio_fd, buffer, ai->blocksize); if (ret != ai->blocksize) { if (ret < 0) { mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AUDIOIN_ErrReadingAudio, strerror(errno)); } else { mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AUDIOIN_NotEnoughSamples); } return -1; } return ret; #endif default: return -1; } }