int ai_alsa_xrun(audio_in_t *ai) { snd_pcm_status_t *status; int res; snd_pcm_status_alloca(&status); if ((res = snd_pcm_status(ai->alsa.handle, status))<0) { mp_tmsg(MSGT_TV, MSGL_ERR, "ALSA status error: %s", snd_strerror(res)); return -1; } if (snd_pcm_status_get_state(status) == SND_PCM_STATE_XRUN) { struct timeval now, diff, tstamp; gettimeofday(&now, 0); snd_pcm_status_get_trigger_tstamp(status, &tstamp); timersub(&now, &tstamp, &diff); mp_tmsg(MSGT_TV, MSGL_ERR, "ALSA xrun!!! (at least %.3f ms long)\n", diff.tv_sec * 1000 + diff.tv_usec / 1000.0); if (mp_msg_test(MSGT_TV, MSGL_V)) { mp_tmsg(MSGT_TV, MSGL_ERR, "ALSA Status:\n"); snd_pcm_status_dump(status, ai->alsa.log); } if ((res = snd_pcm_prepare(ai->alsa.handle))<0) { mp_tmsg(MSGT_TV, MSGL_ERR, "ALSA xrun: prepare error: %s", snd_strerror(res)); return -1; } return 0; /* ok, data should be accepted again */ } mp_tmsg(MSGT_TV, MSGL_ERR, "ALSA read/write error"); return -1; }
// I/O error handler static void xrun(void) { snd_pcm_status_t *status; int res; snd_pcm_status_alloca(&status); if ((res = snd_pcm_status(handle, status))<0) { error(_("status error: %s"), snd_strerror(res)); exit(EXIT_FAILURE); } if (snd_pcm_status_get_state(status) == SND_PCM_STATE_XRUN) { struct timeval now, diff, tstamp; gettimeofday(&now, 0); snd_pcm_status_get_trigger_tstamp(status, &tstamp); timersub(&now, &tstamp, &diff); fprintf(stderr, _("%s!!! (at least %.3f ms long)\n"), stream == SND_PCM_STREAM_PLAYBACK ? _("underrun") : _("overrun"), diff.tv_sec * 1000 + diff.tv_usec / 1000.0); if ((res = snd_pcm_prepare(handle))<0) { error(_("xrun: prepare error: %s"), snd_strerror(res)); exit(EXIT_FAILURE); } return; // ok, data should be accepted again } if (snd_pcm_status_get_state(status) == SND_PCM_STATE_DRAINING) { } error(_("read/write error, state = %s"), snd_pcm_state_name(snd_pcm_status_get_state(status))); exit(EXIT_FAILURE); }
qint64 QAudioOutputPrivate::elapsedUSecs() const { if(!handle) return 0; if (deviceState == QAudio::StoppedState) return 0; #if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14) snd_pcm_status_t* status; snd_pcm_status_alloca(&status); snd_timestamp_t t1,t2; if( snd_pcm_status(handle, status) >= 0) { snd_pcm_status_get_tstamp(status,&t1); snd_pcm_status_get_trigger_tstamp(status,&t2); t1.tv_sec-=t2.tv_sec; signed long l = (signed long)t1.tv_usec - (signed long)t2.tv_usec; if(l < 0) { t1.tv_sec--; l = -l; l %= 1000000; } return ((t1.tv_sec * 1000000)+l); } else return 0; #else return clockStamp.elapsed()*1000; #endif return 0; }
int ai_alsa_xrun(audio_in_t *ai) { snd_pcm_status_t *status; int res; snd_pcm_status_alloca(&status); if ((res = snd_pcm_status(ai->alsa.handle, status))<0) { mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIALSA_AlsaStatusError, snd_strerror(res)); return -1; } if (snd_pcm_status_get_state(status) == SND_PCM_STATE_XRUN) { struct timeval now, diff, tstamp; gettimeofday(&now, 0); snd_pcm_status_get_trigger_tstamp(status, &tstamp); timersub(&now, &tstamp, &diff); mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIALSA_AlsaXRUN, diff.tv_sec * 1000 + diff.tv_usec / 1000.0); if (mp_msg_test(MSGT_TV, MSGL_V)) { mp_msg(MSGT_TV, MSGL_ERR, "ALSA Status:\n"); snd_pcm_status_dump(status, ai->alsa.log); } if ((res = snd_pcm_prepare(ai->alsa.handle))<0) { mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIALSA_AlsaXRUNPrepareError, snd_strerror(res)); return -1; } return 0; /* ok, data should be accepted again */ } mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIALSA_AlsaReadWriteError); return -1; }
static void xrun(void) { snd_pcm_status_t *status; int res; snd_pcm_status_alloca(&status); if ((res = snd_pcm_status(AHandle, status)) < 0) { fprintf(stderr, "status error: %s", snd_strerror(res)); exit(EXIT_FAILURE); } if (snd_pcm_status_get_state(status) == SND_PCM_STATE_XRUN) { struct timeval now, diff, tstamp; gettimeofday(&now, 0); snd_pcm_status_get_trigger_tstamp(status, &tstamp); timersub(&now, &tstamp, &diff); fprintf(stderr, "Underrun!!! (at least %.3f ms long)\n", diff.tv_sec * 1000 + diff.tv_usec / 1000.0); if ((res = snd_pcm_prepare(AHandle)) < 0) { fprintf(stderr, "xrun: prepare error: %s", snd_strerror(res)); exit(EXIT_FAILURE); } return; // ok, data should be accepted // again } fprintf(stderr, "read/write error, state = %s", snd_pcm_state_name(snd_pcm_status_get_state(status))); exit(EXIT_FAILURE); }
void gettimestamp(snd_pcm_t *handle, snd_timestamp_t *timestamp) { int err; snd_pcm_status_t *status; snd_pcm_status_alloca(&status); if ((err = snd_pcm_status(handle, status)) < 0) { printf("Stream status error: %s\n", snd_strerror(err)); exit(0); } snd_pcm_status_get_trigger_tstamp(status, timestamp); }
/* I/O error handler */ static void xrun(void) { snd_pcm_status_t *status; int res; snd_pcm_status_alloca(&status); if ((res = snd_pcm_status(handle, status))<0) { error("status error: %s", snd_strerror(res)); exit(EXIT_FAILURE); } if (snd_pcm_status_get_state(status) == SND_PCM_STATE_XRUN) { struct timeval now, diff, tstamp; gettimeofday(&now, 0); snd_pcm_status_get_trigger_tstamp(status, &tstamp); timersub(&now, &tstamp, &diff); fprintf(stderr, "%s!!! (at least %.3f ms long)\n", stream == SND_PCM_STREAM_PLAYBACK ? "underrun" : "overrun", diff.tv_sec * 1000 + diff.tv_usec / 1000.0); if (verbose) { fprintf(stderr, "Status:\n"); snd_pcm_status_dump(status, log); } if ((res = snd_pcm_prepare(handle))<0) { error("xrun: prepare error: %s", snd_strerror(res)); exit(EXIT_FAILURE); } return; /* ok, data should be accepted again */ } if (snd_pcm_status_get_state(status) == SND_PCM_STATE_DRAINING) { if (verbose) { fprintf(stderr, "Status(DRAINING):\n"); snd_pcm_status_dump(status, log); } if (stream == SND_PCM_STREAM_CAPTURE) { fprintf(stderr, "capture stream format change? attempting recover...\n"); if ((res = snd_pcm_prepare(handle))<0) { error("xrun(DRAINING): prepare error: %s", snd_strerror(res)); exit(EXIT_FAILURE); } return; } } if (verbose) { fprintf(stderr, "Status(R/W):\n"); snd_pcm_status_dump(status, log); } error("read/write error, state = %s", snd_pcm_state_name(snd_pcm_status_get_state(status))); exit(EXIT_FAILURE); }
static void xrun(void) { snd_pcm_status_t *status; int res; snd_pcm_status_alloca(&status); if ((res = snd_pcm_status(AHandle, status))<0) { fprintf(stderr, "status error: %s", snd_strerror(res)); return; } if (snd_pcm_status_get_state(status) == SND_PCM_STATE_XRUN) { if (monotonic) { #ifdef HAVE_CLOCK_GETTIME struct timespec now, diff, tstamp; clock_gettime(CLOCK_MONOTONIC, &now); snd_pcm_status_get_trigger_htstamp(status, &tstamp); timermsub(&now, &tstamp, &diff); fprintf(stderr, _("%s!!! (at least %.3f ms long)\n"), stream == SND_PCM_STREAM_PLAYBACK ? _("underrun") : _("overrun"), diff.tv_sec * 1000 + diff.tv_nsec / 10000000.0); #else fprintf(stderr, "%s !!!\n", "underrun"); #endif } else { struct timeval now, diff, tstamp; gettimeofday(&now, 0); snd_pcm_status_get_trigger_tstamp(status, &tstamp); timersub(&now, &tstamp, &diff); fprintf(stderr, "%s!!! (at least %.3f ms long)\n", "Underrun", diff.tv_sec * 1000 + diff.tv_usec / 1000.0); } if ((res = snd_pcm_prepare(AHandle))<0) { fprintf(stderr, "xrun: prepare error: %s", snd_strerror(res)); /* we should probably die here */ return; } return; /* ok, data should be accepted again */ } fprintf(stderr, "read/write error, state = %s", snd_pcm_state_name(snd_pcm_status_get_state(status))); }
/*a@nufront start*/ void AudioStreamInALSA::xrun(snd_pcm_t * handle) { snd_pcm_status_t *status; int res; ZJFLOGD("function in."); snd_pcm_status_alloca(&status); if ((res = snd_pcm_status(handle, status))<0) { ZJFLOGE("status error: %s", snd_strerror(res)); return; } if (snd_pcm_status_get_state(status) == SND_PCM_STATE_XRUN) { struct timeval now, diff, tstamp; gettimeofday(&now, 0); snd_pcm_status_get_trigger_tstamp(status, &tstamp); timersub(&now, &tstamp, &diff); ZJFLOGE("overrun!!! (at least %.3f ms long)", diff.tv_sec * 1000 + diff.tv_usec / 1000.0); } ZJFLOGD("function out."); return; }
static int alsa_write_float (snd_pcm_t *alsa_dev, float *data, int frames, int channels) { static int epipe_count = 0 ; int total = 0 ; int retval ; if (epipe_count > 0) epipe_count -- ; while (total < frames) { retval = snd_pcm_writei (alsa_dev, data + total * channels, frames - total) ; if (retval >= 0) { total += retval ; if (total == frames) return total ; continue ; } ; switch (retval) { case -EAGAIN : puts ("alsa_write_float: EAGAIN") ; continue ; break ; case -EPIPE : if (epipe_count > 0) { printf ("alsa_write_float: EPIPE %d\n", epipe_count) ; if (epipe_count > 140) return retval ; } ; epipe_count += 100 ; #if 0 if (0) { snd_pcm_status_t *status ; snd_pcm_status_alloca (&status) ; if ((retval = snd_pcm_status (alsa_dev, status)) < 0) fprintf (stderr, "alsa_out: xrun. can't determine length\n") ; else if (snd_pcm_status_get_state (status) == SND_PCM_STATE_XRUN) { struct timeval now, diff, tstamp ; gettimeofday (&now, 0) ; snd_pcm_status_get_trigger_tstamp (status, &tstamp) ; timersub (&now, &tstamp, &diff) ; fprintf (stderr, "alsa_write_float xrun: of at least %.3f msecs. resetting stream\n", diff.tv_sec * 1000 + diff.tv_usec / 1000.0) ; } else fprintf (stderr, "alsa_write_float: xrun. can't determine length\n") ; } ; #endif snd_pcm_prepare (alsa_dev) ; break ; case -EBADFD : fprintf (stderr, "alsa_write_float: Bad PCM state.n") ; return 0 ; break ; case -ESTRPIPE : fprintf (stderr, "alsa_write_float: Suspend event.n") ; return 0 ; break ; case -EIO : puts ("alsa_write_float: EIO") ; return 0 ; default : fprintf (stderr, "alsa_write_float: retval = %d\n", retval) ; return 0 ; break ; } ; /* switch */ } ; /* while */ return total ; } /* alsa_write_float */