Example #1
0
int pa_simple_flush(pa_simple *p, int *rerror) {
    pa_operation *o = NULL;

    pa_assert(p);

    CHECK_VALIDITY_RETURN_ANY(rerror, p->direction == PA_STREAM_PLAYBACK, PA_ERR_BADSTATE, -1);

    pa_threaded_mainloop_lock(p->mainloop);
    CHECK_DEAD_GOTO(p, rerror, unlock_and_fail);

    o = pa_stream_flush(p->stream, success_cb, p);
    CHECK_SUCCESS_GOTO(p, rerror, o, unlock_and_fail);

    p->operation_success = 0;
    while (pa_operation_get_state(o) == PA_OPERATION_RUNNING) {
        pa_threaded_mainloop_wait(p->mainloop);
        CHECK_DEAD_GOTO(p, rerror, unlock_and_fail);
    }
    CHECK_SUCCESS_GOTO(p, rerror, p->operation_success, unlock_and_fail);

    pa_operation_unref(o);
    pa_threaded_mainloop_unlock(p->mainloop);

    return 0;

unlock_and_fail:

    if (o) {
        pa_operation_cancel(o);
        pa_operation_unref(o);
    }

    pa_threaded_mainloop_unlock(p->mainloop);
    return -1;
}
Example #2
0
static void context_unlink(pa_context *c) {
    pa_stream *s;

    pa_assert(c);

    s = c->streams ? pa_stream_ref(c->streams) : NULL;
    while (s) {
        pa_stream *n = s->next ? pa_stream_ref(s->next) : NULL;
        pa_stream_set_state(s, c->state == PA_CONTEXT_FAILED ? PA_STREAM_FAILED : PA_STREAM_TERMINATED);
        pa_stream_unref(s);
        s = n;
    }

    while (c->operations)
        pa_operation_cancel(c->operations);

    if (c->pdispatch) {
        pa_pdispatch_unref(c->pdispatch);
        c->pdispatch = NULL;
    }

    if (c->pstream) {
        pa_pstream_unlink(c->pstream);
        pa_pstream_unref(c->pstream);
        c->pstream = NULL;
    }

    if (c->client) {
        pa_socket_client_unref(c->client);
        c->client = NULL;
    }

    reset_callbacks(c);
}
Example #3
0
static gboolean
play_timeout (MokoNotify *notify)
{
  MokoNotifyPrivate *priv;

  g_return_val_if_fail (MOKO_IS_NOTIFY (notify), FALSE);
  priv = notify->priv;

  if (!priv->pac)
    return FALSE;

  if (!priv->operation)
  {
    g_debug ("No operation");
    return FALSE;
  }
  if (!priv->started)
  {
    pa_operation_cancel (priv->operation);
    g_debug ("Cancelling early");
    return FALSE;
  }
  if (pa_operation_get_state (priv->operation) == PA_OPERATION_DONE)
  {
    g_timeout_add (1500, (GSourceFunc)play, (gpointer)notify);
    g_debug ("Playing done");
    return FALSE;
  }
  g_debug ("Not finshed yet");
  return TRUE;
}
Example #4
0
/*
  this method may be called inside the pulse main loop,
  so be VERY careful with locking
*/
void CPulseAEStream::Destroy()
{
  if (!m_Initialized)
    return;

  if (m_Destroyed)
    return;

  m_fader.StopThread(true);

  pa_threaded_mainloop_lock(m_MainLoop);

  if (m_DrainOperation)
  {
    pa_operation_cancel(m_DrainOperation);
    pa_operation_unref(m_DrainOperation);
    m_DrainOperation = NULL;
  }

  if (m_Stream)
  {
    pa_stream_disconnect(m_Stream);
    pa_stream_unref(m_Stream);
    m_Stream = NULL;
  }

  /* signal CPulseAE to free us */
  m_Destroyed = true;
  m_Initialized = false;

  pa_threaded_mainloop_unlock(m_MainLoop);
}
int pa_simple_cork(pa_simple *p, int cork, int *rerror) {
    pa_operation *o = NULL;

    pa_assert(p);

    pa_threaded_mainloop_lock(p->mainloop);
    CHECK_DEAD_GOTO(p, rerror, unlock_and_fail);

    o = pa_stream_cork(p->stream, cork, success_context_cb, p);
    CHECK_SUCCESS_GOTO(p, rerror, o, unlock_and_fail);

    p->operation_success = 0;
    while (pa_operation_get_state(o) == PA_OPERATION_RUNNING) {
        pa_threaded_mainloop_wait(p->mainloop);
        CHECK_DEAD_GOTO(p, rerror, unlock_and_fail);
    }
    CHECK_SUCCESS_GOTO(p, rerror, p->operation_success, unlock_and_fail);

    pa_operation_unref(o);
    pa_threaded_mainloop_unlock(p->mainloop);

    return 0;

unlock_and_fail:

    if (o) {
        pa_operation_cancel(o);
        pa_operation_unref(o);
    }

    pa_threaded_mainloop_unlock(p->mainloop);
    return -1;
}
Example #6
0
void CPulseAESound::Stop()
{
  if (m_op)
  {
    pa_operation_cancel(m_op);
    pa_operation_unref(m_op);
    m_op = NULL;
  }
}
Example #7
0
static void
gst_pulsesrc_reset (GstAudioSrc * asrc)
{
  GstPulseSrc *pulsesrc = GST_PULSESRC_CAST (asrc);
  pa_operation *o = NULL;

  pa_threaded_mainloop_lock (pulsesrc->mainloop);
  GST_DEBUG_OBJECT (pulsesrc, "reset");

  if (gst_pulsesrc_is_dead (pulsesrc, TRUE))
    goto unlock_and_fail;

  if (!(o =
          pa_stream_flush (pulsesrc->stream, gst_pulsesrc_success_cb,
              pulsesrc))) {
    GST_ELEMENT_ERROR (pulsesrc, RESOURCE, FAILED,
        ("pa_stream_flush() failed: %s",
            pa_strerror (pa_context_errno (pulsesrc->context))), (NULL));
    goto unlock_and_fail;
  }

  pulsesrc->paused = TRUE;
  /* Inform anyone waiting in _write() call that it shall wakeup */
  if (pulsesrc->in_read) {
    pa_threaded_mainloop_signal (pulsesrc->mainloop, 0);
  }

  pulsesrc->operation_success = FALSE;
  while (pa_operation_get_state (o) == PA_OPERATION_RUNNING) {

    if (gst_pulsesrc_is_dead (pulsesrc, TRUE))
      goto unlock_and_fail;

    pa_threaded_mainloop_wait (pulsesrc->mainloop);
  }

  if (!pulsesrc->operation_success) {
    GST_ELEMENT_ERROR (pulsesrc, RESOURCE, FAILED, ("Flush failed: %s",
            pa_strerror (pa_context_errno (pulsesrc->context))), (NULL));
    goto unlock_and_fail;
  }

unlock_and_fail:

  if (o) {
    pa_operation_cancel (o);
    pa_operation_unref (o);
  }

  pa_threaded_mainloop_unlock (pulsesrc->mainloop);
}
Example #8
0
void m1sdr_PlayStop(void)
{
	#if 0
	pa_operation *op;
	#endif

	#ifdef USE_SDL
	if (lnxdrv_apimode == 0) 
	{
		SDL_PauseAudio(1);
	}
	#endif

	if (lnxdrv_apimode == 1)
	{
//		snd_pcm_pause(pHandle, 1);
		snd_pcm_drop(pHandle);
	}

	#if PULSE_USE_SIMPLE
	if ((lnxdrv_apimode == 3) && (my_simple))
	{
		pa_simple_flush(my_simple, NULL);
		pa_simple_free(my_simple);
		my_simple = NULL;
	}
	#else
#if 0
	if (lnxdrv_apimode == 3)
	{
		op = pa_stream_drain(my_pa_stream, &pa_stream_drain_complete, NULL);
		if (op)
		{
			while (pa_operation_get_state(op) != PA_OPERATION_DONE)
			{
				if (pa_context_get_state(my_pa_context) != PA_CONTEXT_READY ||
				    pa_stream_get_state(my_pa_stream) != PA_STREAM_READY ||
				    pa_mainloop_iterate(my_pa_mainloop, 0, NULL) < 0)
				    {
				    	pa_operation_cancel(op);
					break;
				    }
			}
		}
	}
#endif
	#endif

	waveLogStop();
	oss_playing = 0;
}
pa_operation *pa_ext_device_manager_delete(
        pa_context *c,
        const char *const s[],
        pa_context_success_cb_t cb,
        void *userdata) {

    uint32_t tag;
    pa_operation *o = NULL;
    pa_tagstruct *t = NULL;
    const char *const *k;

    pa_assert(c);
    pa_assert(PA_REFCNT_VALUE(c) >= 1);
    pa_assert(s);

    PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED);
    PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
    PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >= 14, PA_ERR_NOTSUPPORTED);

    o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);

    t = pa_tagstruct_command(c, PA_COMMAND_EXTENSION, &tag);
    pa_tagstruct_putu32(t, PA_INVALID_INDEX);
    pa_tagstruct_puts(t, "module-device-manager");
    pa_tagstruct_putu32(t, SUBCOMMAND_DELETE);

    for (k = s; *k; k++) {
        if (!*k || !**k)
            goto fail;

        pa_tagstruct_puts(t, *k);
    }

    pa_pstream_send_tagstruct(c->pstream, t);
    pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, pa_context_simple_ack_callback, pa_operation_ref(o), (pa_free_cb_t) pa_operation_unref);

    return o;

fail:
    if (o) {
        pa_operation_cancel(o);
        pa_operation_unref(o);
    }

    if (t)
        pa_tagstruct_free(t);

    pa_context_set_error(c, PA_ERR_INVALID);
    return NULL;
}
int pa_simple_set_volume(pa_simple *p, int volume, int *rerror) {
    pa_operation *o = NULL;
    pa_stream *s = NULL;
    uint32_t idx;
    pa_cvolume cv;
    pa_volume_t v;

    pa_assert(p);

    CHECK_VALIDITY_RETURN_ANY(rerror, p->direction == PA_STREAM_PLAYBACK, PA_ERR_BADSTATE, -1);
    CHECK_VALIDITY_RETURN_ANY(rerror, volume >= 0, PA_ERR_INVALID, -1);
    CHECK_VALIDITY_RETURN_ANY(rerror, volume <= 65535, PA_ERR_INVALID, -1);

    pa_threaded_mainloop_lock(p->mainloop);
    CHECK_DEAD_GOTO(p, rerror, unlock_and_fail);

    CHECK_SUCCESS_GOTO(p, rerror, ((idx = pa_stream_get_index (p->stream)) != PA_INVALID_INDEX), unlock_and_fail);

    s = p->stream;
    pa_assert(s);
    pa_cvolume_set(&cv, s->sample_spec.channels, volume);

    o = pa_context_set_sink_input_volume (p->context, idx, &cv, success_context_cb, p);

    CHECK_SUCCESS_GOTO(p, rerror, o, unlock_and_fail);

    p->operation_success = 0;
    while (pa_operation_get_state(o) == PA_OPERATION_RUNNING) {
        pa_threaded_mainloop_wait(p->mainloop);
        CHECK_DEAD_GOTO(p, rerror, unlock_and_fail);
    }
    CHECK_SUCCESS_GOTO(p, rerror, p->operation_success, unlock_and_fail);

    pa_operation_unref(o);
    pa_threaded_mainloop_unlock(p->mainloop);

    return 0;

unlock_and_fail:

    if (o) {
        pa_operation_cancel(o);
        pa_operation_unref(o);
    }

    pa_threaded_mainloop_unlock(p->mainloop);
    return -1;
}
Example #11
0
static void
moko_notify_stop_ringtone (MokoNotify *notify)
{
  MokoNotifyPrivate *priv;

  g_return_if_fail (MOKO_IS_NOTIFY (notify));
  priv = notify->priv;

  if (priv->operation)
  {
    pa_operation_cancel (priv->operation);
    g_debug ("Cancelling");
  }

  priv->operation = NULL;
}
Example #12
0
void
cubeb_stream_destroy(cubeb_stream * stm)
{
  if (stm->stream) {
    stream_cork(stm, CORK);

    pa_threaded_mainloop_lock(stm->context->mainloop);

    if (stm->draining) {
      pa_operation_cancel(stm->draining);
      pa_operation_unref(stm->draining);
    }

    pa_stream_disconnect(stm->stream);
    pa_stream_unref(stm->stream);
    pa_threaded_mainloop_unlock(stm->context->mainloop);
  }

  free(stm);
}
Example #13
0
gboolean xmms_pulse_backend_flush (xmms_pulse *p, int *rerror)
{
	pa_operation *o = NULL;

	pa_threaded_mainloop_lock (p->mainloop);
	if (!check_pulse_health (p, rerror))
		goto unlock_and_fail;

	o = pa_stream_flush (p->stream, drain_result_cb, p);
	if (!o) {
		if (rerror)
			*rerror = pa_context_errno ((p)->context);
		goto unlock_and_fail;
	}

	p->operation_success = 0;
	while (pa_operation_get_state (o) != PA_OPERATION_DONE) {
		pa_threaded_mainloop_wait (p->mainloop);
		if (!check_pulse_health (p, rerror))
			goto unlock_and_fail;
	}
	pa_operation_unref (o);
	o = NULL;
	if (!p->operation_success) {
		if (rerror)
			*rerror = pa_context_errno ((p)->context);
		goto unlock_and_fail;
	}

	pa_threaded_mainloop_unlock (p->mainloop);
	return 0;

 unlock_and_fail:
	if (o) {
		pa_operation_cancel (o);
		pa_operation_unref (o);
	}

	pa_threaded_mainloop_unlock (p->mainloop);
	return -1;
}
Example #14
0
pa_operation *pa_ext_stream_restore_write(
        pa_context *c,
        pa_update_mode_t mode,
        const pa_ext_stream_restore_info data[],
        unsigned n,
        int apply_immediately,
        pa_context_success_cb_t cb,
        void *userdata) {

    uint32_t tag;
    pa_operation *o = NULL;
    pa_tagstruct *t = NULL;

    pa_assert(c);
    pa_assert(PA_REFCNT_VALUE(c) >= 1);
    pa_assert(mode == PA_UPDATE_MERGE || mode == PA_UPDATE_REPLACE || mode == PA_UPDATE_SET);
    pa_assert(data);

    PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED);
    PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
    PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >= 14, PA_ERR_NOTSUPPORTED);

    o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);

    t = pa_tagstruct_command(c, PA_COMMAND_EXTENSION, &tag);
    pa_tagstruct_putu32(t, PA_INVALID_INDEX);
    pa_tagstruct_puts(t, "module-stream-restore");
    pa_tagstruct_putu32(t, SUBCOMMAND_WRITE);

    pa_tagstruct_putu32(t, mode);
    pa_tagstruct_put_boolean(t, apply_immediately);

    for (; n > 0; n--, data++) {
        if (!data->name || !*data->name)
            goto fail;

        pa_tagstruct_puts(t, data->name);

        if (data->volume.channels > 0 &&
            !pa_cvolume_compatible_with_channel_map(&data->volume, &data->channel_map))
            goto fail;

        pa_tagstruct_put_channel_map(t, &data->channel_map);
        pa_tagstruct_put_cvolume(t, &data->volume);
        pa_tagstruct_puts(t, data->device);
        pa_tagstruct_put_boolean(t, data->mute);
    }

    pa_pstream_send_tagstruct(c->pstream, t);
    pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, pa_context_simple_ack_callback, pa_operation_ref(o), (pa_free_cb_t) pa_operation_unref);

    return o;

fail:
    pa_operation_cancel(o);
    pa_operation_unref(o);

    pa_tagstruct_free(t);

    pa_context_set_error(c, PA_ERR_INVALID);
    return NULL;
}