本文整理汇总了C++中snd_pcm_resume函数的典型用法代码示例。如果您正苦于以下问题:C++ snd_pcm_resume函数的具体用法?C++ snd_pcm_resume怎么用?C++ snd_pcm_resume使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了snd_pcm_resume函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CheckXRUN
static void CheckXRUN(IDsCaptureDriverBufferImpl* This)
{
snd_pcm_state_t state = snd_pcm_state(This->pcm);
snd_pcm_sframes_t delay;
int err;
snd_pcm_hwsync(This->pcm);
snd_pcm_delay(This->pcm, &delay);
if ( state == SND_PCM_STATE_XRUN )
{
err = snd_pcm_prepare(This->pcm);
CommitAll(This, FALSE);
snd_pcm_start(This->pcm);
WARN("xrun occurred\n");
if ( err < 0 )
ERR("recovery from xrun failed, prepare failed: %s\n", snd_strerror(err));
}
else if ( state == SND_PCM_STATE_SUSPENDED )
{
int err = snd_pcm_resume(This->pcm);
TRACE("recovery from suspension occurred\n");
if (err < 0 && err != -EAGAIN){
err = snd_pcm_prepare(This->pcm);
if (err < 0)
ERR("recovery from suspend failed, prepare failed: %s\n", snd_strerror(err));
}
}
else if ( state != SND_PCM_STATE_RUNNING)
{
WARN("Unhandled state: %d\n", state);
}
}
示例2: snd_pcm_prepare
int QAudioInputPrivate::xrun_recovery(int err)
{
int count = 0;
bool reset = false;
if(err == -EPIPE) {
errorState = QAudio::UnderrunError;
err = snd_pcm_prepare(handle);
if(err < 0)
reset = true;
} else if((err == -ESTRPIPE)||(err == -EIO)) {
errorState = QAudio::IOError;
while((err = snd_pcm_resume(handle)) == -EAGAIN){
usleep(100);
count++;
if(count > 5) {
reset = true;
break;
}
}
if(err < 0) {
err = snd_pcm_prepare(handle);
if(err < 0)
reset = true;
}
}
if(reset) {
close();
open();
snd_pcm_prepare(handle);
return 0;
}
return err;
}
示例3: switch
void CAESinkALSA::HandleError(const char* name, int err)
{
switch(err)
{
case -EPIPE:
CLog::Log(LOGERROR, "CAESinkALSA::HandleError(%s) - underrun", name);
if ((err = snd_pcm_prepare(m_pcm)) < 0)
CLog::Log(LOGERROR, "CAESinkALSA::HandleError(%s) - snd_pcm_prepare returned %d (%s)", name, err, snd_strerror(err));
break;
case -ESTRPIPE:
CLog::Log(LOGINFO, "CAESinkALSA::HandleError(%s) - Resuming after suspend", name);
/* try to resume the stream */
while((err = snd_pcm_resume(m_pcm)) == -EAGAIN)
Sleep(1);
/* if the hardware doesnt support resume, prepare the stream */
if (err == -ENOSYS)
if ((err = snd_pcm_prepare(m_pcm)) < 0)
CLog::Log(LOGERROR, "CAESinkALSA::HandleError(%s) - snd_pcm_prepare returned %d (%s)", name, err, snd_strerror(err));
break;
default:
CLog::Log(LOGERROR, "CAESinkALSA::HandleError(%s) - snd_pcm_writei returned %d (%s)", name, err, snd_strerror(err));
break;
}
}
示例4: snd_pcm_recover
int snd_pcm_recover(snd_pcm_t *pcm, int err, int silent)
{
if (err > 0)
err = -err;
if (err == -EINTR) /* nothing to do, continue */
return 0;
if (err == -EPIPE) {
err = snd_pcm_prepare(pcm);
if (err < 0)
return err;
return 0;
}
if (err == -ESTRPIPE) {
while ((err = snd_pcm_resume(pcm)) == -EAGAIN)
/* wait until suspend flag is released */
poll(NULL, 0, 1000);
if (err < 0) {
err = snd_pcm_prepare(pcm);
if (err < 0)
return err;
}
return 0;
}
return err;
}
示例5: xrun_recovery
/*
* Underrun and suspend recovery
*/
static gint
xrun_recovery (GstAlsaSink * alsa, snd_pcm_t * handle, gint err)
{
GST_WARNING_OBJECT (alsa, "xrun recovery %d: %s", err, g_strerror (-err));
if (err == -EPIPE) { /* under-run */
err = snd_pcm_prepare (handle);
if (err < 0)
GST_WARNING_OBJECT (alsa,
"Can't recover from underrun, prepare failed: %s",
snd_strerror (err));
gst_audio_base_sink_report_device_failure (GST_AUDIO_BASE_SINK (alsa));
return 0;
} else if (err == -ESTRPIPE) {
while ((err = snd_pcm_resume (handle)) == -EAGAIN)
g_usleep (100); /* wait until the suspend flag is released */
if (err < 0) {
err = snd_pcm_prepare (handle);
if (err < 0)
GST_WARNING_OBJECT (alsa,
"Can't recover from suspend, prepare failed: %s",
snd_strerror (err));
}
if (err == 0)
gst_audio_base_sink_report_device_failure (GST_AUDIO_BASE_SINK (alsa));
return 0;
}
return err;
}
示例6: xrun_recovery
/*
* Underrun and suspend recovery
*/
static gint
xrun_recovery (GstAlsaSink * alsa, snd_pcm_t * handle, gint err)
{
GST_DEBUG_OBJECT (alsa, "xrun recovery %d", err);
if (err == -EPIPE) { /* under-run */
err = snd_pcm_prepare (handle);
if (err < 0)
GST_WARNING_OBJECT (alsa,
"Can't recovery from underrun, prepare failed: %s",
snd_strerror (err));
return 0;
} else if (err == -ESTRPIPE) {
while ((err = snd_pcm_resume (handle)) == -EAGAIN)
g_usleep (100); /* wait until the suspend flag is released */
if (err < 0) {
err = snd_pcm_prepare (handle);
if (err < 0)
GST_WARNING_OBJECT (alsa,
"Can't recovery from suspend, prepare failed: %s",
snd_strerror (err));
}
return 0;
}
return err;
}
示例7: DAUDIO_Start
int DAUDIO_Start(void* id, int isSource) {
AlsaPcmInfo* info = (AlsaPcmInfo*) id;
int ret;
snd_pcm_state_t state;
TRACE0("> DAUDIO_Start\n");
// set to blocking mode
snd_pcm_nonblock(info->handle, 0);
// set start mode so that it always starts as soon as data is there
setStartThreshold(info, TRUE /* use threshold */);
state = snd_pcm_state(info->handle);
if (state == SND_PCM_STATE_PAUSED) {
// in case it was stopped previously
TRACE0(" Un-pausing...\n");
ret = snd_pcm_pause(info->handle, FALSE);
if (ret != 0) {
ERROR2(" NOTE: error in snd_pcm_pause:%d: %s\n", ret, snd_strerror(ret));
}
}
if (state == SND_PCM_STATE_SUSPENDED) {
TRACE0(" Resuming...\n");
ret = snd_pcm_resume(info->handle);
if (ret < 0) {
if ((ret != -EAGAIN) && (ret != -ENOSYS)) {
ERROR2(" ERROR: error in snd_pcm_resume:%d: %s\n", ret, snd_strerror(ret));
}
}
}
if (state == SND_PCM_STATE_SETUP) {
TRACE0("need to call prepare again...\n");
// prepare device
ret = snd_pcm_prepare(info->handle);
if (ret < 0) {
ERROR1("ERROR: snd_pcm_prepare: %s\n", snd_strerror(ret));
}
}
// in case there is still data in the buffers
ret = snd_pcm_start(info->handle);
if (ret != 0) {
if (ret != -EPIPE) {
ERROR2(" NOTE: error in snd_pcm_start: %d: %s\n", ret, snd_strerror(ret));
}
}
// set to non-blocking mode
ret = snd_pcm_nonblock(info->handle, 1);
if (ret != 0) {
ERROR1(" ERROR in snd_pcm_nonblock: %s\n", snd_strerror(ret));
}
state = snd_pcm_state(info->handle);
#ifdef USE_TRACE
printState(state);
#endif
ret = (state == SND_PCM_STATE_PREPARED)
|| (state == SND_PCM_STATE_RUNNING)
|| (state == SND_PCM_STATE_XRUN)
|| (state == SND_PCM_STATE_SUSPENDED);
TRACE1("< DAUDIO_Start %s\n", ret?"success":"error");
return ret?TRUE:FALSE;
}
示例8: play_buf_chunks
/* Play from alsa_buf as many chunks as possible. Move the remaining data
* to the beginning of the buffer. Return the number of bytes written
* or -1 on error. */
static int play_buf_chunks ()
{
int written = 0;
while (alsa_buf_fill >= chunk_size) {
int err;
err = snd_pcm_writei (handle, alsa_buf + written,
chunk_size / bytes_per_frame);
if (err == -EAGAIN) {
if (snd_pcm_wait(handle, 500) < 0)
logit ("snd_pcm_wait() failed");
}
else if (err == -EPIPE) {
logit ("underrun!");
if ((err = snd_pcm_prepare(handle)) < 0) {
error ("Can't recover after underrun: %s",
snd_strerror(err));
/* TODO: reopen the device */
return -1;
}
}
else if (err == -ESTRPIPE) {
logit ("Suspend, trying to resume");
while ((err = snd_pcm_resume(handle))
== -EAGAIN)
sleep (1);
if (err < 0) {
logit ("Failed, restarting");
if ((err = snd_pcm_prepare(handle))
< 0) {
error ("Failed to restart "
"device: %s.",
snd_strerror(err));
return -1;
}
}
}
else if (err < 0) {
error ("Can't play: %s", snd_strerror(err));
return -1;
}
else {
int written_bytes = err * bytes_per_frame;
written += written_bytes;
alsa_buf_fill -= written_bytes;
debug ("Played %d bytes", written_bytes);
}
}
debug ("%d bytes remain in alsa_buf", alsa_buf_fill);
memmove (alsa_buf, alsa_buf + written, alsa_buf_fill);
return written * bytes_per_frame;
}
示例9: alsaspdifsink_write_frame
static void
alsaspdifsink_write_frame (AlsaSPDIFSink * sink, guchar * buf)
{
snd_pcm_sframes_t res;
int num_frames = IEC958_FRAME_SIZE / ALSASPDIFSINK_BYTES_PER_FRAME;
/* If we couldn't output big endian when we opened the devic, then
* we need to swap here */
if (sink->need_swap) {
int i;
guchar tmp;
for (i = 0; i < IEC958_FRAME_SIZE; i += 2) {
tmp = buf[i];
buf[i] = buf[i + 1];
buf[i + 1] = tmp;
}
}
res = 0;
do {
if (res == -EPIPE) {
/* Underrun. */
GST_INFO_OBJECT (sink, "buffer underrun");
res = snd_pcm_prepare (sink->pcm);
} else if (res == -ESTRPIPE) {
/* Suspend. */
while ((res = snd_pcm_resume (sink->pcm)) == -EAGAIN) {
GST_DEBUG_OBJECT (sink, "sleeping for suspend");
g_usleep (100000);
}
if (res < 0) {
res = snd_pcm_prepare (sink->pcm);
}
}
if (res >= 0) {
res = snd_pcm_writei (sink->pcm, (void *) buf, num_frames);
}
if (res > 0) {
num_frames -= res;
}
} while (res == -EPIPE || num_frames > 0);
sink->frames++;
if (res < 0) {
GST_ELEMENT_ERROR (sink, RESOURCE, OPEN_WRITE,
("writei returned error: %s", snd_strerror (res)), GST_ERROR_SYSTEM);
return;
}
}
示例10: drvHostALSAAudioResume
static int drvHostALSAAudioResume(snd_pcm_t *phPCM)
{
AssertPtrReturn(phPCM, VERR_INVALID_POINTER);
int err = snd_pcm_resume(phPCM);
if (err < 0)
{
LogFunc(("Failed to resume stream %p: %s\n",
phPCM, snd_strerror(err)));
return VERR_ACCESS_DENIED; /** @todo Find a better rc. */
}
return VINF_SUCCESS;
}
示例11: laudio_alsa_xrun_recover
static int
laudio_alsa_xrun_recover(int err)
{
int ret;
if (err != 0)
pcm_last_error = err;
/* Buffer underrun */
if (err == -EPIPE)
{
pcm_last_error = 0;
ret = snd_pcm_prepare(hdl);
if (ret < 0)
{
DPRINTF(E_WARN, L_LAUDIO, "Couldn't recover from underrun: %s\n", snd_strerror(ret));
return 1;
}
return 0;
}
/* Device suspended */
else if (pcm_last_error == -ESTRPIPE)
{
ret = snd_pcm_resume(hdl);
if (ret == -EAGAIN)
{
pcm_recovery++;
return 2;
}
else if (ret < 0)
{
pcm_recovery = 0;
ret = snd_pcm_prepare(hdl);
if (ret < 0)
{
DPRINTF(E_WARN, L_LAUDIO, "Couldn't recover from suspend: %s\n", snd_strerror(ret));
return 1;
}
}
pcm_recovery = 0;
return 0;
}
return err;
}
示例12: ao_alsa_play
static int ao_alsa_play(dtaudio_output_t *aout, uint8_t * buf, int size)
{
alsa_ctx_t *ctx = (alsa_ctx_t *)wrapper->ao_priv;
snd_pcm_t *alsa_handle = (snd_pcm_t *) ctx->handle;
int bytes_per_sample = wrapper->para.bps * wrapper->para.dst_channels / 8;
int num_frames = size / bytes_per_sample;
snd_pcm_sframes_t res = 0;
uint8_t *data = buf;
if (!alsa_handle) {
return -1;
}
if (num_frames == 0) {
return 0;
}
if (ao_alsa_level(aout) >= ctx->buf_threshold) {
dt_debug(TAG, "ALSA EXCEED THRESHOLD,size:%d thres:%d \n", ao_alsa_level(aout),
ctx->buf_threshold);
return 0;
}
res = snd_pcm_writei(alsa_handle, data, num_frames);
if (res == -EINTR) {
dt_info(TAG, "ALSA HAS NO SPACE, WRITE AGAIN\n");
return res;
}
if (res == -ESTRPIPE) {
snd_pcm_resume(alsa_handle);
return res;
}
if (res == -EBADFD) {
snd_pcm_reset(alsa_handle);
return res;
}
if (res < 0) {
snd_pcm_prepare(alsa_handle);
dt_info(TAG, "snd pcm write failed prepare!\n");
return -1;
//goto rewrite;
}
if (res < num_frames) {
data += res * bytes_per_sample;
num_frames -= res;
//goto rewrite;
}
return res * bytes_per_sample;
}
示例13: recover
static int recover(sox_format_t * ft, snd_pcm_t * pcm, int err)
{
if (err == -EPIPE)
lsx_warn("%s-run", ft->mode == 'r'? "over" : "under");
else if (err != -ESTRPIPE)
lsx_warn("%s", snd_strerror(err));
else while ((err = snd_pcm_resume(pcm)) == -EAGAIN) {
lsx_report("suspended");
sleep(1); /* Wait until the suspend flag is released */
}
if (err < 0 && (err = snd_pcm_prepare(pcm)) < 0)
lsx_fail_errno(ft, SOX_EPERM, "%s", snd_strerror(err));
return err;
}
示例14: suspend_recover
static int
suspend_recover(void) {
int err;
while((err = snd_pcm_resume(alsa_pcm)) == -EAGAIN)
/* wait until suspend flag is released */
sleep(1);
if(err < 0) {
printf("alsa_handle_error(): " "snd_pcm_resume() failed.\n");
return snd_pcm_prepare(alsa_pcm);
}
return err;
}
示例15: suspend
static void suspend(void)
{
int res;
fprintf(stderr, "Suspended. Trying resume. "); fflush(stderr);
while ((res = snd_pcm_resume(AHandle)) == -EAGAIN)
sleep(1); /* wait until suspend flag is released */
if (res < 0) {
fprintf(stderr, "Failed. Restarting stream. "); fflush(stderr);
if ((res = snd_pcm_prepare(AHandle)) < 0) {
fprintf(stderr, "suspend: prepare error: %s", snd_strerror(res));
}
}
fprintf(stderr, "Done.\n");
}