static PyObject* ALSAAudio_resume(output_ALSAAudio *self, PyObject *args)
{
    snd_pcm_pause(self->output, 0);

    Py_INCREF(Py_None);
    return Py_None;
}
Beispiel #2
0
void alsa_pause(struct codec *c, int p)
{
	struct alsa_state *state = (struct alsa_state *) c->data;
	if (snd_pcm_state(state->dev) != SND_PCM_STATE_PAUSED)
		snd_pcm_delay(state->dev, &state->delay);
	snd_pcm_pause(state->dev, p);
}
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;
}
Beispiel #4
0
static void
alsa_audio_play(audio_decoder_t *ad)
{
  decoder_t *d = (decoder_t *)ad;
  if(d->h == NULL)
    return;
  snd_pcm_pause(d->h, 0);
  d->samples = 0;
}
int
sa_stream_pause(sa_stream_t *s) {

  if (s == NULL || s->output_unit == NULL) {
    return SA_ERROR_NO_INIT;
  }

  if (snd_pcm_pause(s->output_unit, 1) != 0)
    return SA_ERROR_NOT_SUPPORTED;

  return SA_SUCCESS;
}
Beispiel #6
0
qint64 ALSAWriter::write(const QByteArray &arr)
{
	if (!readyWrite())
		return 0;

	const int samples = arr.size() / sizeof(float);
	const int to_write = samples / channels;

	const int bytes = samples * sample_size;
	if (int_samples.size() < bytes)
		int_samples.resize(bytes);
	switch (sample_size)
	{
		case 4:
			convert_samples((const float *)arr.constData(), samples, (qint32 *)int_samples.constData(), mustSwapChn ? channels : 0);
			break;
		case 2:
			convert_samples((const float *)arr.constData(), samples, (qint16 *)int_samples.constData(), mustSwapChn ? channels : 0);
			break;
		case 1:
			convert_samples((const float *)arr.constData(), samples, (qint8 *)int_samples.constData(), mustSwapChn ? channels : 0);
			break;
	}
	switch (snd_pcm_state(snd))
	{
		case SND_PCM_STATE_XRUN:
			if (!snd_pcm_prepare(snd))
			{
				const int silence = snd_pcm_avail(snd) - to_write;
				if (silence > 0)
				{
					QByteArray silenceArr(silence * channels * sample_size, 0);
					snd_pcm_writei(snd, silenceArr.constData(), silence);
				}
			}
			break;
		case SND_PCM_STATE_PAUSED:
			snd_pcm_pause(snd, false);
			break;
		default:
			break;
	}
	int ret = snd_pcm_writei(snd, int_samples.constData(), to_write);
	if (ret < 0 && ret != -EPIPE && snd_pcm_recover(snd, ret, false))
	{
		QMPlay2Core.logError("ALSA :: " + tr("Playback error"));
		err = true;
		return 0;
	}

	return arr.size();
}
int
sa_stream_resume(sa_stream_t *s) {

  if (s == NULL || s->output_unit == NULL) {
    return SA_ERROR_NO_INIT;
  }

  if (s->pulseaudio) {
    s->resumed = 1;
  }

  if (snd_pcm_pause(s->output_unit, 0) != 0)
    return SA_ERROR_NOT_SUPPORTED;
  return SA_SUCCESS;
}
Beispiel #8
0
static int alsa_resume(void)
{
    int err;

    if (!alsa_can_pause) {
        return 1;
    }

    if ((err = snd_pcm_pause(handle, 0)) < 0) {
        log_message(LOG_DEFAULT, "Unable to resume playback: %s", snd_strerror(err));
        return 1;
    }

    return 0;
}
Beispiel #9
0
static int ao_alsa_resume(dtaudio_output_t *aout)
{
    alsa_ctx_t *ctx = (alsa_ctx_t *)wrapper->ao_priv;
    snd_pcm_t *handle = (snd_pcm_t *) ctx->handle;

    int ret = 0;
    if (ctx->pause_support == 1) {
        ret = snd_pcm_pause(handle, 0);
        dt_info(TAG, "ALSA PAUSED SUPPORT RESUME DIRECTLY  ret:%d status:%d \n", ret,
                snd_pcm_state(handle));
    } else {
        snd_pcm_prepare(handle);
    }
    dt_info(TAG, "ALSA RESUME \n");
    return 0;
}
Beispiel #10
0
static bool alsa_stop(void *data)
{
   alsa_t *alsa = (alsa_t*)data;
   if (alsa->can_pause && !alsa->is_paused)
   {
      if (snd_pcm_pause(alsa->pcm, 1) == 0)
      {
         alsa->is_paused = true;
         return true;
      }
      else
         return false;
   }
   else
      return true;
}
Beispiel #11
0
static bool alsa_stop(void *data)
{
   alsa_t *alsa = (alsa_t*)data;

   if (alsa->can_pause
         && !alsa->is_paused)
   {
      int ret = snd_pcm_pause(alsa->pcm, 1);

      if (ret < 0)
         return false;

      alsa->is_paused = true;
   }

   return true;
}
int DAUDIO_Stop(void* id, int isSource) {
    AlsaPcmInfo* info = (AlsaPcmInfo*) id;
    int ret;

    TRACE0("> DAUDIO_Stop\n");
    // set to blocking mode
    snd_pcm_nonblock(info->handle, 0);
    setStartThreshold(info, FALSE /* don't use threshold */); // device will not start after buffer xrun
    ret = snd_pcm_pause(info->handle, 1);
    // set to non-blocking mode
    snd_pcm_nonblock(info->handle, 1);
    if (ret != 0) {
        ERROR1("ERROR in snd_pcm_pause: %s\n", snd_strerror(ret));
        return FALSE;
    }
    TRACE0("< DAUDIO_Stop success\n");
    return TRUE;
}
Beispiel #13
0
/**
 * \brief stop output
 * \param audec pointer to audec
 * \return 0 on success otherwise negative error code
 */
int alsa_stop_raw(struct aml_audio_dec* audec)
{
    alsa_param_t *alsa_params;
    int res = 0;
    int dgraw = amsysfs_get_sysfs_int("/sys/class/audiodsp/digital_raw");

    if(audec->aout_ops.private_data_raw) {
        alsa_params = (alsa_param_t *)audec->aout_ops.private_data_raw;
    } else {
        adec_print("OUT SETTING::PCM\n");
        return -1;
    }

    //resume the spdif card, otherwise the output will block
    if(alsa_params->pause_flag == 1){
        while ((res = snd_pcm_pause(alsa_params->handle, 0)) == -EAGAIN) {
            usleep(1000);
        }
    }

    alsa_params->pause_flag = 0; //we should clear pause flag ,as we can stop from paused state
    alsa_params->stop_flag = 1;
    alsa_params->wait_flag = 0;

    pthread_cond_signal(&alsa_params->playback_cond);
    pthread_join(alsa_params->playback_tid, NULL);
    pthread_mutex_destroy(&alsa_params->playback_mutex);
    pthread_cond_destroy(&alsa_params->playback_cond);


    snd_pcm_drop(alsa_params->handle);
    snd_pcm_close(alsa_params->handle);

    free(alsa_params);
    audec->aout_ops.private_data_raw = NULL;
    adec_print("exit alsa out raw stop\n");
    if((AUDIO_SPDIF_PASSTHROUGH == dgraw)||(AUDIO_HDMI_PASSTHROUGH == dgraw)){
        if((audec->format == ACODEC_FMT_AC3) ||(audec->format == ACODEC_FMT_EAC3) ){
            amsysfs_set_sysfs_int("/sys/class/audiodsp/digital_codec",0);
        }
    }

    return 0;
}
Beispiel #14
0
static void audio_resume(void)
{
    int err;

    if (alsa_can_pause) {
        if ((err = snd_pcm_pause(alsa_handler, 0)) < 0)
        {
            mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_PcmResumeError, snd_strerror(err));
            return;
        }
          mp_msg(MSGT_AO,MSGL_V,"alsa-resume: resume supported by hardware\n");
    } else {
        if ((err = snd_pcm_prepare(alsa_handler)) < 0)
        {
           mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_PcmPrepareError, snd_strerror(err));
            return;
        }
    }
}
Beispiel #15
0
static void audio_pause(void)
{
    int err;

    if (alsa_can_pause) {
        if ((err = snd_pcm_pause(alsa_handler, 1)) < 0)
        {
            mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_PcmPauseError, snd_strerror(err));
            return;
        }
          mp_msg(MSGT_AO,MSGL_V,"alsa-pause: pause supported by hardware\n");
    } else {
        if ((err = snd_pcm_drop(alsa_handler)) < 0)
        {
            mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_PcmDropError, snd_strerror(err));
            return;
        }
    }
}
Beispiel #16
0
static bool alsa_start(void *data)
{
   alsa_t *alsa = (alsa_t*)data;
   if (alsa->can_pause && alsa->is_paused)
   {
      int ret = snd_pcm_pause(alsa->pcm, 0);
      if (ret < 0)
      {
         RARCH_ERR("[ALSA]: Failed to unpause: %s.\n", snd_strerror(ret));
         return false;
      }
      else
      {
         alsa->is_paused = false;
         return true;
      }
   }
   else
      return true;
}
/*----------------------------------------------------------------------
|       AlsaOutput_Resume
+---------------------------------------------------------------------*/
BLT_METHOD
AlsaOutput_Resume(BLT_MediaNode* _self)
{
    AlsaOutput* self = ATX_SELF_EX(AlsaOutput, BLT_BaseMediaNode, BLT_MediaNode);
        
    ATX_LOG_FINER("resuming output");

    /* pause the device */
    switch (self->state) {
      case BLT_ALSA_OUTPUT_STATE_PREPARED:
        snd_pcm_pause(self->device_handle, 0);
        break;

      default:
        /* ignore */
        break;
    }

    return BLT_SUCCESS;
}
Beispiel #18
0
/**
 * \brief resume output
 * \param audec pointer to audec
 * \return 0 on success otherwise negative error code
 */
int alsa_resume_raw(struct aml_audio_dec* audec)
{

    int res = 0;
    alsa_param_t *alsa_params;

    if(audec->aout_ops.private_data_raw) {
        alsa_params = (alsa_param_t *)audec->aout_ops.private_data_raw;
    } else {
        adec_print("OUT SETTING::PCM\n");
        return -1;
    }

    alsa_params->pause_flag = 0;
    while ((res = snd_pcm_pause(alsa_params->handle, 0)) == -EAGAIN) {
        sleep(1);
    }

    return res;
}
void SoundOutput_alsa::write_fragment(float *data)
{
	snd_pcm_sframes_t rc;

	if (handle == nullptr) return;

	switch(snd_pcm_state(handle)) {
		case SND_PCM_STATE_XRUN:
		case SND_PCM_STATE_SUSPENDED:
			snd_pcm_prepare(handle);
			break;
		case SND_PCM_STATE_PAUSED:
			snd_pcm_pause(handle, 0);
			break;
		default:
			break;
	}

	rc = snd_pcm_writei(handle, data, frames_in_period);
	if (rc < 0)
		log_event("debug", "ClanSound: snd_pcm_writei() failed!");
}
Beispiel #20
0
static void audio_resume(void)
{
    int err;

    if (snd_pcm_state(alsa_handler) == SND_PCM_STATE_SUSPENDED) {
        mp_msg(MSGT_AO,MSGL_INFO,MSGTR_AO_ALSA_PcmInSuspendModeTryingResume);
        while ((err = snd_pcm_resume(alsa_handler)) == -EAGAIN) sleep(1);
    }
    if (alsa_can_pause) {
        if ((err = snd_pcm_pause(alsa_handler, 0)) < 0)
        {
            mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_PcmResumeError, snd_strerror(err));
            return;
        }
          mp_msg(MSGT_AO,MSGL_V,"alsa-resume: resume supported by hardware\n");
    } else {
        if ((err = snd_pcm_prepare(alsa_handler)) < 0)
        {
           mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_PcmPrepareError, snd_strerror(err));
            return;
        }
    }
}
Beispiel #21
0
static int
alsa_stream_start(cubeb_stream * stm)
{
  cubeb * ctx;

  assert(stm);
  ctx = stm->context;

  pthread_mutex_lock(&stm->mutex);
  snd_pcm_pause(stm->pcm, 0);
  gettimeofday(&stm->last_activity, NULL);
  pthread_mutex_unlock(&stm->mutex);

  pthread_mutex_lock(&ctx->mutex);
  if (stm->state != INACTIVE) {
    pthread_mutex_unlock(&ctx->mutex);
    return CUBEB_ERROR;
  }
  alsa_set_stream_state(stm, RUNNING);
  pthread_mutex_unlock(&ctx->mutex);

  return CUBEB_OK;
}
Beispiel #22
0
int
cubeb_stream_start(cubeb_stream * stm)
{
  int r;
  struct cubeb_msg msg;

  assert(stm);

  pthread_mutex_lock(&stm->lock);

  /* XXX check how this is used in refill loop */
  if (stm->state == CUBEB_STREAM_STATE_ACTIVE || stm->state == CUBEB_STREAM_STATE_ACTIVATING) {
    pthread_mutex_unlock(&stm->lock);
    return CUBEB_OK; /* XXX perhaps this should signal an error */
  }

  r = snd_pcm_pause(stm->pcm, 0);
#if 0
  assert(r == 0);
#endif

  if (stm->state != CUBEB_STREAM_STATE_ACTIVATING) {
    stm->state = CUBEB_STREAM_STATE_ACTIVATING;

    msg.type = CUBEB_MSG_ADD_STREAM;
    msg.data = stm;
    cubeb_send_msg(stm->context, &msg);
  }

  while (stm->state == CUBEB_STREAM_STATE_ACTIVATING) {
    pthread_cond_wait(&stm->cond, &stm->lock);
  }

  pthread_mutex_unlock(&stm->lock);

  return CUBEB_OK;
}
Beispiel #23
0
static int
alsa_stream_stop(cubeb_stream * stm)
{
  cubeb * ctx;
  int r;

  assert(stm);
  ctx = stm->context;

  pthread_mutex_lock(&ctx->mutex);
  while (stm->state == PROCESSING) {
    r = pthread_cond_wait(&stm->cond, &ctx->mutex);
    assert(r == 0);
  }

  alsa_set_stream_state(stm, INACTIVE);
  pthread_mutex_unlock(&ctx->mutex);

  pthread_mutex_lock(&stm->mutex);
  snd_pcm_pause(stm->pcm, 1);
  pthread_mutex_unlock(&stm->mutex);

  return CUBEB_OK;
}
Beispiel #24
0
int
cubeb_stream_stop(cubeb_stream * stm)
{
  int r;
  struct cubeb_msg msg;

  assert(stm);

  pthread_mutex_lock(&stm->lock);

  if (stm->state == CUBEB_STREAM_STATE_INACTIVE) {
    pthread_mutex_unlock(&stm->lock);
    return CUBEB_OK; /* XXX perhaps this should signal an error */
  }

  r = snd_pcm_pause(stm->pcm, 1);
#if 0
  assert(r == 0);
#endif

  if (stm->state != CUBEB_STREAM_STATE_DEACTIVATING) {
    stm->state = CUBEB_STREAM_STATE_DEACTIVATING;

    msg.type = CUBEB_MSG_DEL_STREAM;
    msg.data = stm;
    cubeb_send_msg(stm->context, &msg);
  }

  while (stm->state == CUBEB_STREAM_STATE_DEACTIVATING) {
    pthread_cond_wait(&stm->cond, &stm->lock);
  }

  pthread_mutex_unlock(&stm->lock);

  return CUBEB_OK;
}
Beispiel #25
0
/**
 * \brief pause output
 * \param audec pointer to audec
 * \return 0 on success otherwise negative error code
 */
int alsa_pause_raw(struct aml_audio_dec* audec)
{

    int res = 0;
    alsa_param_t *alsa_params;

    if(audec->aout_ops.private_data_raw) {
        alsa_params = (alsa_param_t *)audec->aout_ops.private_data_raw;
    } else {
        adec_print("OUT SETTING::PCM\n");
        return -1;
    }
    if(1 == alsa_params->pause_flag) {
        adec_print("[%s::%d]--[already in pause(%d) status]\n",__FUNCTION__, __LINE__,alsa_params->pause_flag);
        return 0;
    }

    alsa_params->pause_flag = 1;
    while ((res = snd_pcm_pause(alsa_params->handle, 1)) == -EAGAIN) {
        sleep(1);
    }

    return res;
}
void SoundOutput_alsa::silence()
{
	/* Note: not supported by all hardware! */
	if (handle)
		snd_pcm_pause(handle, 1);
}
Beispiel #27
0
void ALSAWriter::pause()
{
	if (canPause)
		snd_pcm_pause(snd, true);
}
Beispiel #28
0
void OutputALSA::suspend()
{
    if (m_can_pause)
        snd_pcm_pause(pcm_handle, 1);
    snd_pcm_prepare(pcm_handle);
}
Beispiel #29
0
void OutputALSA::resume()
{
    if (m_can_pause)
        snd_pcm_pause(pcm_handle, 0);
    snd_pcm_prepare(pcm_handle);
}
Beispiel #30
0
int snd_pcm_generic_pause(snd_pcm_t *pcm, int enable)
{
    snd_pcm_generic_t *generic = pcm->private_data;
    return snd_pcm_pause(generic->slave, enable);
}