Ejemplo n.º 1
0
/**
 * @brief Callback function called when the state of the context is changed
 * @param c Context which changed status
 * @param this_gen pulse_class_t pointer for the PulseAudio output class
 */
static void __xine_pa_context_state_callback(pa_context *c, void *this_gen)
{
  pulse_driver_t * this = (pulse_driver_t*) this_gen;

  switch (pa_context_get_state(c)) {

    case PA_CONTEXT_READY:
    case PA_CONTEXT_TERMINATED:
    case PA_CONTEXT_FAILED:
      pa_threaded_mainloop_signal(this->mainloop, 0);
      break;

    case PA_CONTEXT_CONNECTING:
    case PA_CONTEXT_UNCONNECTED:
    case PA_CONTEXT_AUTHORIZING:
    case PA_CONTEXT_SETTING_NAME:
      break;
  }
}
Ejemplo n.º 2
0
static void
gst_pulsesrc_context_state_cb (pa_context * c, void *userdata)
{
  GstPulseSrc *pulsesrc = GST_PULSESRC_CAST (userdata);

  switch (pa_context_get_state (c)) {
    case PA_CONTEXT_READY:
    case PA_CONTEXT_TERMINATED:
    case PA_CONTEXT_FAILED:
      pa_threaded_mainloop_signal (pulsesrc->mainloop, 0);
      break;

    case PA_CONTEXT_UNCONNECTED:
    case PA_CONTEXT_CONNECTING:
    case PA_CONTEXT_AUTHORIZING:
    case PA_CONTEXT_SETTING_NAME:
      break;
  }
}
Ejemplo n.º 3
0
static void context_state_cb(pa_context *c, void *userdata) {
    pa_simple *p = userdata;
    pa_assert(c);
    pa_assert(p);

    switch (pa_context_get_state(c)) {
        case PA_CONTEXT_READY:
        case PA_CONTEXT_TERMINATED:
        case PA_CONTEXT_FAILED:
            pa_threaded_mainloop_signal(p->mainloop, 0);
            break;

        case PA_CONTEXT_UNCONNECTED:
        case PA_CONTEXT_CONNECTING:
        case PA_CONTEXT_AUTHORIZING:
        case PA_CONTEXT_SETTING_NAME:
            break;
    }
}
Ejemplo n.º 4
0
static void context_state_callback(pa_context *c, void *userdata)
{
	switch (pa_context_get_state(c)) {
	case PA_CONTEXT_CONNECTING:
	case PA_CONTEXT_AUTHORIZING:
	case PA_CONTEXT_SETTING_NAME:
	case PA_CONTEXT_READY:
		break;
	case PA_CONTEXT_TERMINATED:
		gtk_main_quit();
		break;
	case PA_CONTEXT_FAILED:
	default:
		fprintf(stderr, "Connection failure: %s",
			pa_strerror(pa_context_errno(c)));
		gtk_main_quit();
		break;
	}
}
Ejemplo n.º 5
0
void context_state_cb(pa_context *c, void *userdata) {

    switch (pa_context_get_state(c)) {
    case PA_CONTEXT_UNCONNECTED:
    case PA_CONTEXT_CONNECTING:
    case PA_CONTEXT_AUTHORIZING:
    case PA_CONTEXT_SETTING_NAME:
	break;

    case PA_CONTEXT_READY: {
    printf("func = %s , LINE = %d \n",__func__,__LINE__);
	pa_operation *o;

	// set up a callback to tell us about source devices
	if (!(o = pa_context_get_source_info_list(c,
					    sourcelist_cb,
					    NULL
						  ))) {
	    show_error(_("pa_context_subscribe() failed"));
	    return;
	}
	pa_operation_unref(o);

	// set up a callback to tell us about sink devices
	if (!(o = pa_context_get_sink_info_list(c,
					    sinklist_cb,
					    NULL
						  ))) {
	    show_error(_("pa_context_subscribe() failed"));
	    return;
	}
	pa_operation_unref(o);

	break;
    }

    case PA_CONTEXT_FAILED:
    case PA_CONTEXT_TERMINATED:
    default:
	return;
    }
}
Ejemplo n.º 6
0
static void pa_state_cb(pa_context* c, void* data)
      {
      int* pa_ready = (int*)data;
      switch (pa_context_get_state(c)) {
            // These are just here for reference
            case PA_CONTEXT_UNCONNECTED:
            case PA_CONTEXT_CONNECTING:
            case PA_CONTEXT_AUTHORIZING:
            case PA_CONTEXT_SETTING_NAME:
            default:
                  break;
            case PA_CONTEXT_FAILED:
            case PA_CONTEXT_TERMINATED:
                  *pa_ready = 2;
                  break;
            case PA_CONTEXT_READY:
                  *pa_ready = 1;
                  break;
            }
      }
std::shared_ptr<AudioSink> AudioSinksManager::create_new_sink(std::string name,
                                                              std::string pretty_name) {
    auto internal_sink = std::shared_ptr<InternalAudioSink>(
            new InternalAudioSink(this, std::move(name), std::move(pretty_name)));
    auto sink = std::shared_ptr<AudioSink>(new AudioSink(internal_sink));
    pa_mainloop.get_strand().dispatch([this, internal_sink]() {
        if (stopping) {
            internal_sink->free();
        } else {
            logger->trace("(AudioSinkManager) Registering audio_sink '{}'",
                          internal_sink->get_name());
            audio_sinks.insert(internal_sink);
            sink_identifier_audio_sink.emplace(internal_sink->get_identifier(), internal_sink);
            if (pa_context_get_state(context) == PA_CONTEXT_READY) {
                internal_sink->start_sink();
            }
        }
    });
    return sink;
}
Ejemplo n.º 8
0
void AudioOutputPulseAudio::ContextStateCallback(pa_context *c, void *arg)
{
    QString fn_log_tag = "_ContextStateCallback, ";
    AudioOutputPulseAudio *audoutP = static_cast<AudioOutputPulseAudio*>(arg);
    switch (pa_context_get_state(c))
    {
    case PA_CONTEXT_READY:
        pa_threaded_mainloop_signal(audoutP->mainloop, 0);
        break;
    case PA_CONTEXT_TERMINATED:
    case PA_CONTEXT_FAILED:
        pa_threaded_mainloop_signal(audoutP->mainloop, 0);
        break;
    case PA_CONTEXT_CONNECTING:
    case PA_CONTEXT_UNCONNECTED:
    case PA_CONTEXT_AUTHORIZING:
    case PA_CONTEXT_SETTING_NAME:
        break;
    }
}
Ejemplo n.º 9
0
void context_state_callback(pa_context *context, void *data){
    (void) data;

    pa_context_state_t state = pa_context_get_state(context);
    qDebug("Context state changed: %d", state);
    switch(state){
    case PA_CONTEXT_READY:
        qDebug("Ready, set, go...");
        connected = true;
        pa_threaded_mainloop_signal(threaded_main_loop, 0);
        break;
    case PA_CONTEXT_FAILED:
        qDebug("Connecting context failed.");
        failed = true;
        pa_threaded_mainloop_signal(threaded_main_loop, 0);
        break;
    default:
        break;
    }
}
void PulseAudioSinksManager::pulseAudioStateCallback(pa_context *ctx, void *userdata)
{
    PulseAudioSinksManager* sinksManager = (PulseAudioSinksManager*)userdata;
    pa_context_state_t state =  pa_context_get_state(ctx);
    switch  (state) {
    // There are just here for reference
    case PA_CONTEXT_UNCONNECTED:
    case PA_CONTEXT_CONNECTING:
    case PA_CONTEXT_AUTHORIZING:
    case PA_CONTEXT_SETTING_NAME:
    case PA_CONTEXT_TERMINATED:
    default:
        break;
    case PA_CONTEXT_FAILED:
        sinksManager->emitSignalError("Cannot connect to pulse audio");
        break;
    case PA_CONTEXT_READY:
        sinksManager->retrieveSinksInfo();
        break;
    }
}
Ejemplo n.º 11
0
/**
 * Context status changed.
 */
static void drvHostPulseAudioCbCtxState(pa_context *pContext, void *pvUser)
{
    AssertPtrReturnVoid(pContext);
    NOREF(pvUser);

    switch (pa_context_get_state(pContext))
    {
        case PA_CONTEXT_READY:
        case PA_CONTEXT_TERMINATED:
            drvHostPulseAudioAbortMainLoop();
            break;

        case PA_CONTEXT_FAILED:
            LogRel(("PulseAudio: Audio input/output stopped!\n"));
            drvHostPulseAudioAbortMainLoop();
            break;

        default:
            break;
    }
}
Ejemplo n.º 12
0
static void
gst_pulsemixer_ctrl_context_state_cb (pa_context * context, void *userdata)
{
  GstPulseMixerCtrl *c = GST_PULSEMIXER_CTRL (userdata);

  /* Called from the background thread! */

  switch (pa_context_get_state (context)) {
    case PA_CONTEXT_READY:
    case PA_CONTEXT_TERMINATED:
    case PA_CONTEXT_FAILED:
      pa_threaded_mainloop_signal (c->mainloop, 0);
      break;

    case PA_CONTEXT_UNCONNECTED:
    case PA_CONTEXT_CONNECTING:
    case PA_CONTEXT_AUTHORIZING:
    case PA_CONTEXT_SETTING_NAME:
      break;
  }
}
Ejemplo n.º 13
0
static void tsmf_pulse_context_state_callback(pa_context *context, void *userdata)
{
	TSMFPulseAudioDevice *pulse = (TSMFPulseAudioDevice *) userdata;
	pa_context_state_t state;
	state = pa_context_get_state(context);
	switch(state)
	{
		case PA_CONTEXT_READY:
			DEBUG_TSMF("PA_CONTEXT_READY");
			pa_threaded_mainloop_signal(pulse->mainloop, 0);
			break;
		case PA_CONTEXT_FAILED:
		case PA_CONTEXT_TERMINATED:
			DEBUG_TSMF("state %d", (int)state);
			pa_threaded_mainloop_signal(pulse->mainloop, 0);
			break;
		default:
			DEBUG_TSMF("state %d", (int)state);
			break;
	}
}
Ejemplo n.º 14
0
/* This is called whenever the context status changes */
static void context_state_callback(pa_context *c, void *userdata) {
    fail_unless(c != NULL);

    switch (pa_context_get_state(c)) {
        case PA_CONTEXT_CONNECTING:
        case PA_CONTEXT_AUTHORIZING:
        case PA_CONTEXT_SETTING_NAME:
            break;

        case PA_CONTEXT_READY: {

            int i;
            fprintf(stderr, "Connection established.\n");

            for (i = 0; i < NSTREAMS; i++) {
                char name[64];

                fprintf(stderr, "Creating stream %i\n", i);

                snprintf(name, sizeof(name), "stream #%i", i);

                streams[i] = pa_stream_new(c, name, &sample_spec, NULL);
                fail_unless(streams[i] != NULL);
                pa_stream_set_state_callback(streams[i], stream_state_callback, (void*) (long) i);
                pa_stream_connect_playback(streams[i], NULL, &buffer_attr, PA_STREAM_START_CORKED, NULL, i == 0 ? NULL : streams[0]);
            }

            break;
        }

        case PA_CONTEXT_TERMINATED:
            mainloop_api->quit(mainloop_api, 0);
            break;

        case PA_CONTEXT_FAILED:
        default:
            fprintf(stderr, "Context error: %s\n", pa_strerror(pa_context_errno(c)));
            fail();
    }
}
Ejemplo n.º 15
0
void PulseSrc::pa_context_state_callback(pa_context* pulse_context, void* user_data) {
  PulseSrc* context = static_cast<PulseSrc*>(user_data);
  switch (pa_context_get_state(pulse_context)) {
    case PA_CONTEXT_CONNECTING:
      // g_print ("PA_CONTEXT_CONNECTING\n");
      break;
    case PA_CONTEXT_AUTHORIZING:
      // g_print ("PA_CONTEXT_AUTHORIZING\n");
      break;
    case PA_CONTEXT_SETTING_NAME:
      // g_print ("PA_CONTEXT_SETTING_NAME\n");
      break;
    case PA_CONTEXT_READY:
      // g_print ("PA_CONTEXT_READY\n");
      context->make_device_description(pulse_context);
      // pa_operation_unref(pa_context_get_source_info_list(pulse_context,
      //  get_source_info_callback,
      //  nullptr));
      pa_context_set_subscribe_callback(pulse_context, on_pa_event_callback, nullptr);
      pa_operation_unref(pa_context_subscribe(
          pulse_context,
          static_cast<pa_subscription_mask_t>(
              PA_SUBSCRIPTION_MASK_SINK | PA_SUBSCRIPTION_MASK_SOURCE |
              PA_SUBSCRIPTION_MASK_SINK_INPUT | PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT |
              PA_SUBSCRIPTION_MASK_MODULE | PA_SUBSCRIPTION_MASK_CLIENT |
              PA_SUBSCRIPTION_MASK_SAMPLE_CACHE | PA_SUBSCRIPTION_MASK_SERVER |
              PA_SUBSCRIPTION_MASK_CARD),
          nullptr,    // pa_context_success_cb_t cb,
          nullptr));  // void *userdata);
      break;
    case PA_CONTEXT_TERMINATED: {
      g_debug("PulseSrc: PA_CONTEXT_TERMINATED");
    } break;
    case PA_CONTEXT_FAILED:
      g_debug("PA_CONTEXT_FAILED");
      break;
    default:
      g_debug("PulseSrc Context error: %s", pa_strerror(pa_context_errno(pulse_context)));
  }
}
Ejemplo n.º 16
0
void
xvd_toggle_mute (XvdInstance *i)
{
  pa_operation *op = NULL;

  if (!i || !i->pulse_context)
   {
      g_warning ("xvd_toggle_mute: pulseaudio context is null");
      return;
   }

  if (pa_context_get_state (i->pulse_context) != PA_CONTEXT_READY)
    {
      g_warning ("xvd_toggle_mute: pulseaudio context isn't ready");
      return;
    }

  if (i->sink_index == PA_INVALID_INDEX)
    {
      g_warning ("xvd_toggle_mute: undefined sink");
      return;
    }

  /* backup existing mute and update */
  i->mute = !(old_mute = i->mute);

  op =  pa_context_set_sink_mute_by_index (i->pulse_context,
                                           i->sink_index,
                                           i->mute,
                                           xvd_notify_volume_callback,
                                           i);

  if (!op)
    {
      g_warning ("xvd_toggle_mute: failed");
      return;
    }
  pa_operation_unref (op);
}
Ejemplo n.º 17
0
/**
 * Callback for context state.
 * Sets *user_data to one of conn_state_t.
 */
void state_cb(pa_context *ctx, void *user_data) {
    pa_context_state_t state;
    enum conn_state_t *pa_ready = user_data;

    state = pa_context_get_state(ctx);
    switch (state) {
        case PA_CONTEXT_UNCONNECTED:
        case PA_CONTEXT_CONNECTING:
        case PA_CONTEXT_AUTHORIZING:
        case PA_CONTEXT_SETTING_NAME:
        default:
            *pa_ready = CONN_WAIT;
            break;
        case PA_CONTEXT_FAILED:
        case PA_CONTEXT_TERMINATED:
            *pa_ready = CONN_FAILED;
            break;
        case PA_CONTEXT_READY:
            *pa_ready = CONN_READY;
            break;
    }
}
Ejemplo n.º 18
0
// This callback gets called when our context changes state.  We really only
// care about when it's ready or if it has failed.
static void pa_names_state_cb(pa_context *c, void *userdata) {
	pa_context_state_t ctx_state;
	int *main_state = userdata;

	ctx_state = pa_context_get_state(c);
	switch  (ctx_state) {
		// There are just here for reference
		case PA_CONTEXT_UNCONNECTED:
		case PA_CONTEXT_CONNECTING:
		case PA_CONTEXT_AUTHORIZING:
		case PA_CONTEXT_SETTING_NAME:
		default:
			break;
		case PA_CONTEXT_FAILED:
		case PA_CONTEXT_TERMINATED:
			*main_state = 9;
			break;
		case PA_CONTEXT_READY:
			*main_state = 1;
			break;
	}
}
Ejemplo n.º 19
0
void PulseAudioSystem::contextCallback(pa_context *c) {
	Q_ASSERT(c == pacContext);
	switch (pa_context_get_state(c)) {
		case PA_CONTEXT_READY:
			bPulseIsGood = true;
			pa_operation_unref(pa_context_subscribe(pacContext, PA_SUBSCRIPTION_MASK_SOURCE, NULL, this));
			pa_operation_unref(pa_context_subscribe(pacContext, PA_SUBSCRIPTION_MASK_SINK, NULL, this));
			query();
			break;
		case PA_CONTEXT_TERMINATED:
			qWarning("PulseAudio: Forcibly disconnected from PulseAudio");
			break;
		case PA_CONTEXT_FAILED:
			qWarning("PulseAudio: Connection failure: %s", pa_strerror(pa_context_errno(c)));
			break;
		default:
			return;
	}
	qmWait.lock();
	qwcWait.wakeAll();
	qmWait.unlock();
}
Ejemplo n.º 20
0
/*
 * Create a new pulse audio main loop and connect to the server
 *
 * Returns a negative value on error
 */
static int pulse_connect(struct pulse_data *data)
{
	data->mainloop = pa_mainloop_new();
	if (!data->mainloop) {
		blog(LOG_ERROR, "pulse-input: Unable to create main loop");
		return -1;
	}

	data->context = pa_context_new_with_proplist(
		pa_mainloop_get_api(data->mainloop), "OBS Studio", data->props);
	if (!data->context) {
		blog(LOG_ERROR, "pulse-input: Unable to create context");
		return -1;
	}

	int status = pa_context_connect(
		data->context, NULL, PA_CONTEXT_NOAUTOSPAWN, NULL);
	if (status < 0) {
		blog(LOG_ERROR, "pulse-input: Unable to connect! Status: %d",
		     status);
		return -1;
	}

	// wait until connected
	for (;;) {
		pulse_iterate(data);
		pa_context_state_t state = pa_context_get_state(data->context);
		if (state == PA_CONTEXT_READY) {
			blog(LOG_DEBUG, "pulse-input: Context ready");
			break;
		}
		if (!PA_CONTEXT_IS_GOOD(state)) {
			blog(LOG_ERROR, "pulse-input: Context connect failed");
			return -1;
		}
	}

	return 0;
}
static void __pulseaudio_context_state_cb(pa_context *pulse_context, void *user_data)
{
	int state = 0;
	SOUND_INFO *info = NULL;

	mmf_return_if_fail(user_data);

	info = (SOUND_INFO *)user_data;

	state = pa_context_get_state(pulse_context);
	switch (state) {
	case PA_CONTEXT_READY:
		_mmcam_dbg_log("pulseaudio context READY");
		if (info->pulse_context == pulse_context) {
			/* Signal */
			_mmcam_dbg_log("pulseaudio send signal");
			pa_threaded_mainloop_signal(info->pulse_mainloop, 0);
		}
		break;
	case PA_CONTEXT_TERMINATED:
		if (info->pulse_context == pulse_context) {
			/* Signal */
			_mmcam_dbg_log("Context terminated : pulseaudio send signal");
			pa_threaded_mainloop_signal(info->pulse_mainloop, 0);
		}
		break;
	case PA_CONTEXT_UNCONNECTED:
	case PA_CONTEXT_CONNECTING:
	case PA_CONTEXT_AUTHORIZING:
	case PA_CONTEXT_SETTING_NAME:
	case PA_CONTEXT_FAILED:
	default:
		_mmcam_dbg_log("pulseaudio context %p, state %d",
		               pulse_context, state);
		break;
	}

	return;
}
Ejemplo n.º 22
0
void pa_state_cb(pa_context *c, void *userdata)
{
	pa_context_state_t state;
	int *pa_ready = userdata;

	state = pa_context_get_state(c);
	switch  (state) {
		case PA_CONTEXT_UNCONNECTED:
		case PA_CONTEXT_CONNECTING:
		case PA_CONTEXT_AUTHORIZING:
		case PA_CONTEXT_SETTING_NAME:
		default:
			break;
		case PA_CONTEXT_FAILED:
		case PA_CONTEXT_TERMINATED:
			*pa_ready = 2;
			break;
		case PA_CONTEXT_READY:
			*pa_ready = 1;
			break;
	}
}
Ejemplo n.º 23
0
////////////////////////////////////////////////////////////////////////
// CALLBACKS FOR THREADED MAINLOOP
////////////////////////////////////////////////////////////////////////
static void context_state_cb (pa_context *context, void *userdata)
{
     Device *dev = userdata;

     if ((context == NULL) || (dev == NULL))
	  return;

     switch (pa_context_get_state (context))
     {
     case PA_CONTEXT_READY:
     case PA_CONTEXT_TERMINATED:
     case PA_CONTEXT_FAILED:
	  pa_threaded_mainloop_signal (dev->mainloop, 0);
	  break;

     case PA_CONTEXT_UNCONNECTED:
     case PA_CONTEXT_CONNECTING:
     case PA_CONTEXT_AUTHORIZING:
     case PA_CONTEXT_SETTING_NAME:
	  break;
     }
}
Ejemplo n.º 24
0
void WavegenClient::onContextStateChanged() {
	switch (pa_context_get_state(paContext_)) {
	case PA_CONTEXT_FAILED:
		reportContextError(paContext_, pa_context_get_server(paContext_));
		notifyResult(OperationType::Connect, OperationResult::Failed, true);
		break;
	case PA_CONTEXT_TERMINATED:
		notifyResult(OperationType::Connect, OperationResult::Failed, true);
		break;
	case PA_CONTEXT_READY:
		// connection OK
		if (firstConnection_) {
			onConnectionEstablishedFirstTime();
			firstConnection_ = false;
		}
		notifyResult(OperationType::Connect, OperationResult::Success, true);
		break;
	default:
		// connecting in progress...
		notifyResult(OperationType::Connect, OperationResult::InProgress, false);
		break;
	}
}
Ejemplo n.º 25
0
/**
 * Context status changed.
 */
static void paContextCbStateChanged(pa_context *pCtx, void *pvUser)
{
    AssertPtrReturnVoid(pCtx);

    PDRVHOSTPULSEAUDIO pThis = (PDRVHOSTPULSEAUDIO)pvUser;
    AssertPtrReturnVoid(pThis);

    switch (pa_context_get_state(pCtx))
    {
        case PA_CONTEXT_READY:
        case PA_CONTEXT_TERMINATED:
            paSignalWaiter(pThis);
            break;

        case PA_CONTEXT_FAILED:
            LogRel(("PulseAudio: Audio context has failed, stopping\n"));
            paSignalWaiter(pThis);
            break;

        default:
            break;
    }
}
Ejemplo n.º 26
0
void pa_state_cb(pa_context *c, void *userdata)
{
        pa_context_state_t state;

        state = pa_context_get_state(c);
        switch  (state) {
                // There are just here for reference
                case PA_CONTEXT_UNCONNECTED:
                case PA_CONTEXT_CONNECTING:
                case PA_CONTEXT_AUTHORIZING:
                case PA_CONTEXT_SETTING_NAME:
                        break;
                case PA_CONTEXT_FAILED:
                case PA_CONTEXT_TERMINATED:
                        exit(-1);
                        break;
                case PA_CONTEXT_READY:
                    if (m_pa_stream_connect(c) < 0) {
                        exit(-1);
                    }
                        break;
        }
}
Ejemplo n.º 27
0
/******************************************************************************
 * The context_state_cb() will be called by PulseAudio when the PulseAudio
 * context changes state.
 * So far, we are only interested in PA_CONTEXT_READY: When the context is
 * ready, we initialize a PulseAudio stream and connect it to the server.
 *****************************************************************************/
static void context_state_cb(pa_context *context, void *userdata) {
    _mbx_out out = (_mbx_out ) userdata;
    pa_context_state_t state = pa_context_get_state(context);
    assert ( out != NULL && out->pa_ctx == context );
    log_context_state(state);
    switch  (state) {
        case PA_CONTEXT_READY:
            context_ready(out);
            out->state = _MBX_OUT_READY;
            break;
        case PA_CONTEXT_UNCONNECTED:
        case PA_CONTEXT_CONNECTING:
        case PA_CONTEXT_AUTHORIZING:
        case PA_CONTEXT_SETTING_NAME:
            /* Do nothing until the state becomes PA_CONTEXT_READY. */
            break;
        case PA_CONTEXT_FAILED:
        case PA_CONTEXT_TERMINATED:
        default:
            /* Initialization error. */
            out->state = _MBX_OUT_PULSEAUDIO_ERROR;
    }
}
/**
 * Context status changed.
 */
static void drvHostPulseAudioCbCtxState(pa_context *pContext, void *pvContext)
{
    AssertPtrReturnVoid(pContext);

    PPULSEAUDIOSTREAM pStrm = (PPULSEAUDIOSTREAM)pvContext;
    NOREF(pStrm);

    switch (pa_context_get_state(pContext))
    {
        case PA_CONTEXT_READY:
        case PA_CONTEXT_TERMINATED:
            pa_threaded_mainloop_signal(g_pMainLoop, 0);
            break;

        case PA_CONTEXT_FAILED:
            LogRel(("PulseAudio: Audio input/output stopped!\n"));
            pa_threaded_mainloop_signal(g_pMainLoop, 0);
            break;

        default:
            break;
    }
}
Ejemplo n.º 29
0
static void
context_state_callback (pa_context *pa, void *data)
{
  SwfdecPlayback *sound = data;

  switch (pa_context_get_state(pa)) {
  case PA_CONTEXT_FAILED:
    g_printerr ("PA context failed\n");
    pa_context_unref (pa);
    sound->pa = NULL;
    break;

  default:
  case PA_CONTEXT_TERMINATED:
  case PA_CONTEXT_UNCONNECTED:
  case PA_CONTEXT_CONNECTING:
  case PA_CONTEXT_AUTHORIZING:
  case PA_CONTEXT_SETTING_NAME:
  case PA_CONTEXT_READY:
    break;

  }
}
Ejemplo n.º 30
0
int AudioOutputPulseAudio::GetBufferedOnSoundcard(void) const
{
    pa_usec_t latency = (pa_usec_t) -1;
    size_t buffered = 0;

    if (!pcontext || pa_context_get_state(pcontext) != PA_CONTEXT_READY)
        return 0;

    if (!pstream || pa_stream_get_state(pstream) != PA_STREAM_READY)
        return 0;

    const pa_buffer_attr *buf_attr =  pa_stream_get_buffer_attr(pstream);
    size_t bfree = pa_stream_writable_size(pstream);
    buffered = buf_attr->tlength - bfree;

    pa_threaded_mainloop_lock(mainloop);

    while (pa_stream_get_latency(pstream, &latency, NULL) < 0)
    {
        if (pa_context_errno(pcontext) != PA_ERR_NODATA)
        {
            latency = 0;
            break;
        }
        pa_threaded_mainloop_wait(mainloop);
    }

    pa_threaded_mainloop_unlock(mainloop);

    if (latency < 0)
    {
        latency = 0;
    }

    return ((uint64_t)latency * samplerate *
            output_bytes_per_frame / 1000000) + buffered;
}