コード例 #1
0
ファイル: context.c プロジェクト: Wezl/pulseaudio
static void pstream_memblock_callback(pa_pstream *p, uint32_t channel, int64_t offset, pa_seek_mode_t seek, const pa_memchunk *chunk, void *userdata) {
    pa_context *c = userdata;
    pa_stream *s;

    pa_assert(p);
    pa_assert(chunk);
    pa_assert(chunk->length > 0);
    pa_assert(c);
    pa_assert(PA_REFCNT_VALUE(c) >= 1);

    pa_context_ref(c);

    if (c->srb_template.readfd != -1 && c->srb_template.memblock == NULL) {
        handle_srbchannel_memblock(c, chunk->memblock);
        pa_context_unref(c);
        return;
    }

    if ((s = pa_hashmap_get(c->record_streams, PA_UINT32_TO_PTR(channel)))) {

        if (chunk->memblock) {
            pa_memblockq_seek(s->record_memblockq, offset, seek, true);
            pa_memblockq_push_align(s->record_memblockq, chunk);
        } else
            pa_memblockq_seek(s->record_memblockq, offset+chunk->length, seek, true);

        if (s->read_callback) {
            size_t l;

            if ((l = pa_memblockq_get_length(s->record_memblockq)) > 0)
                s->read_callback(s, l, s->read_userdata);
        }
    }

    pa_context_unref(c);
}
コード例 #2
0
ファイル: ausrv.c プロジェクト: jusa/tone-generator
void ausrv_destroy(struct ausrv *ausrv)
{
    if (ausrv != NULL) {
        stream_kill_all(ausrv);

        if (ausrv->context != NULL)
            pa_context_unref(ausrv->context);
        
        if (ausrv->mainloop != NULL)
            pa_glib_mainloop_free(ausrv->mainloop);
        
        free(ausrv->server);
        free(ausrv);
    }
}
コード例 #3
0
ファイル: backend.c プロジェクト: kfihihc/xmms2-devel
void xmms_pulse_backend_free (xmms_pulse *p)
{
	assert (p);

	if (p->stream)
		xmms_pulse_backend_close_stream (p);
	if (p->mainloop)
		pa_threaded_mainloop_stop (p->mainloop);
	if (p->context)
		pa_context_unref (p->context);
	if (p->mainloop)
		pa_threaded_mainloop_free (p->mainloop);

	g_free (p);
}
コード例 #4
0
ファイル: cgtk.c プロジェクト: martyr-deepin/pypulseaudio
static void m_destroy(GtkWindow *window, gpointer user_data) 
{
    if (m_pa_ctx) {
        pa_context_unref(m_pa_ctx);
        m_pa_ctx = NULL;
    }

    if (m_pa_ml) {
        pa_threaded_mainloop_stop(m_pa_ml);
        pa_threaded_mainloop_free(m_pa_ml);
        m_pa_ml = NULL;
    }

    gtk_main_quit();
}
コード例 #5
0
ファイル: pulseaudio.cpp プロジェクト: CammyVee/MuseScore
bool PulseAudio::init(bool)
      {
      pa_ml                     = pa_mainloop_new();
      pa_mainloop_api* pa_mlapi = pa_mainloop_get_api(pa_ml);
      pa_context* pa_ctx        = pa_context_new(pa_mlapi, "MuseScore");
      if (pa_context_connect(pa_ctx, NULL, pa_context_flags_t(0), NULL) != 0) {
            qDebug("PulseAudio Context Connect Failed with Error: %s", pa_strerror(pa_context_errno(pa_ctx)));
            return false;
            }

      int pa_ready = 0;
      pa_context_set_state_callback(pa_ctx, pa_state_cb, &pa_ready);

      while (pa_ready == 0)
            pa_mainloop_iterate(pa_ml, 1, NULL);
      if (pa_ready == 2)
            return false;

      ss.rate     = _sampleRate;
      ss.channels = 2;
      ss.format   = PA_SAMPLE_FLOAT32LE;

      pa_stream* playstream = pa_stream_new(pa_ctx, "Playback", &ss, NULL);
      if (!playstream) {
            qDebug("pa_stream_new failed: %s", pa_strerror(pa_context_errno(pa_ctx)));
            return false;
            }
      pa_stream_set_write_callback(playstream, paCallback, this);

      bufattr.fragsize  = (uint32_t)-1;
      bufattr.maxlength = FRAMES * 2 * sizeof(float);
      bufattr.minreq    = FRAMES * 1 * sizeof(float); // pa_usec_to_bytes(0, &ss);
      bufattr.prebuf    = (uint32_t)-1;
      bufattr.tlength   = bufattr.maxlength;

      int r = pa_stream_connect_playback(playstream, nullptr, &bufattr,
         PA_STREAM_NOFLAGS, nullptr, nullptr);

      if (r < 0) {
            qDebug("pa_stream_connect_playback failed");
            pa_context_disconnect(pa_ctx);
            pa_context_unref(pa_ctx);
            pa_mainloop_free(pa_ml);
            pa_ml = 0;
            return false;
            }
      return true;
      }
コード例 #6
0
void QPulseAudioThread::cleanup()
{

    pa_threaded_mainloop_stop ( mainloop );

    if ( stream )
        pa_stream_unref ( stream );

    if ( context )
        pa_context_unref ( context );


    if ( stdio_event ) {
        assert ( mainloop_api );
        mainloop_api->io_free ( stdio_event );
    }


    if ( time_event ) {
        assert ( mainloop_api );
        mainloop_api->time_free ( time_event );
    }

    if ( mainloop_api )
        mainloop_api->quit ( mainloop_api, 0 );

    if ( mainloop ) {
        pa_signal_done();
        pa_threaded_mainloop_free ( mainloop );
    }

    if ( buffer )
        pa_xfree ( buffer );

    if ( server )
        pa_xfree ( server );

    if ( device )
        pa_xfree ( device );

    if ( client_name )
        pa_xfree ( client_name );

    if ( stream_name )
        pa_xfree ( stream_name );

    return ;
}
コード例 #7
0
ファイル: PulseAE.cpp プロジェクト: 2BReality/xbmc
CPulseAE::~CPulseAE()
{
  if (m_Context)
  {
    pa_context_disconnect(m_Context);
    pa_context_unref(m_Context);
    m_Context = NULL;
  }

  if (m_MainLoop)
  {
    pa_threaded_mainloop_stop(m_MainLoop);
    pa_threaded_mainloop_free(m_MainLoop);
  }

}
コード例 #8
0
AudioDevPulseAudio::~AudioDevPulseAudio()
{
    this->uninit();

    if (this->d->m_context) {
        pa_context_disconnect(this->d->m_context);
        pa_context_unref(this->d->m_context);
    }

    if (this->d->m_mainLoop) {
        pa_threaded_mainloop_stop(this->d->m_mainLoop);
        pa_threaded_mainloop_free(this->d->m_mainLoop);
    }

    delete this->d;
}
コード例 #9
0
ファイル: sounds.cpp プロジェクト: alinelena/cameraplus
void Sounds::destroy() {
  if (m_loop) {
    pa_threaded_mainloop_stop(m_loop);
  }

  if (m_ctx) {
    pa_context_disconnect(m_ctx);
    pa_context_unref(m_ctx);
    m_ctx = 0;
  }

  if (m_loop) {
    pa_threaded_mainloop_free(m_loop);
    m_loop = 0;
  }
}
コード例 #10
0
ファイル: pulseaudio.c プロジェクト: siana/2p-openal
static pa_context *connect_context(pa_threaded_mainloop *loop, ALboolean silent)
{
    const char *name = "OpenAL Soft";
    char path_name[PATH_MAX];
    pa_context_state_t state;
    pa_context *context;
    int err;

    if(pa_get_binary_name(path_name, sizeof(path_name)))
        name = pa_path_get_filename(path_name);

    context = pa_context_new(pa_threaded_mainloop_get_api(loop), name);
    if(!context)
    {
        ERR("pa_context_new() failed\n");
        return NULL;
    }

    pa_context_set_state_callback(context, context_state_callback, loop);

    if((err=pa_context_connect(context, NULL, pulse_ctx_flags, NULL)) >= 0)
    {
        while((state=pa_context_get_state(context)) != PA_CONTEXT_READY)
        {
            if(!PA_CONTEXT_IS_GOOD(state))
            {
                err = pa_context_errno(context);
                if(err > 0)  err = -err;
                break;
            }

            pa_threaded_mainloop_wait(loop);
        }
    }
    pa_context_set_state_callback(context, NULL, NULL);

    if(err < 0)
    {
        if(!silent)
            ERR("Context did not connect: %s\n", pa_strerror(err));
        pa_context_unref(context);
        return NULL;
    }

    return context;
}
コード例 #11
0
ファイル: PulseAudio.cpp プロジェクト: AceXare/mumble
PulseAudioSystem::~PulseAudioSystem() {
	bRunning = false;
	if (bAttenuating) {
		qmWait.lock();
		bAttenuating = false;
		setVolumes();
		bool success = qwcWait.wait(&qmWait, 1000);
		if (! success) {
			qWarning("PulseAudio: Shutdown timeout when attempting to restore volumes.");
		}
		qmWait.unlock();
	}
	pa_threaded_mainloop_stop(pam);
	pa_context_disconnect(pacContext);
	pa_context_unref(pacContext);
	pa_threaded_mainloop_free(pam);
}
コード例 #12
0
ファイル: context.c プロジェクト: Wezl/pulseaudio
static void pa_command_enable_srbchannel(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
    pa_context *c = userdata;

#ifdef HAVE_CREDS
    pa_cmsg_ancil_data *ancil = NULL;

    pa_assert(pd);
    pa_assert(command == PA_COMMAND_ENABLE_SRBCHANNEL);
    pa_assert(t);
    pa_assert(c);
    pa_assert(PA_REFCNT_VALUE(c) >= 1);

    ancil = pa_pdispatch_take_ancil_data(pd);
    if (!ancil)
        goto fail;

    /* Currently only one srb channel is supported, might change in future versions */
    if (c->srb_template.readfd != -1)
        goto fail;

    if (ancil->nfd != 2 || ancil->fds[0] == -1 || ancil->fds[1] == -1)
        goto fail;

    pa_context_ref(c);

    c->srb_template.readfd = ancil->fds[0];
    c->srb_template.writefd = ancil->fds[1];
    c->srb_setup_tag = tag;

    pa_context_unref(c);

    ancil->close_fds_on_cleanup = false;
    return;

fail:
    if (ancil)
        pa_cmsg_ancil_data_close_fds(ancil);

    pa_context_fail(c, PA_ERR_PROTOCOL);
    return;
#else
    pa_assert(c);
    pa_context_fail(c, PA_ERR_PROTOCOL);
#endif
}
コード例 #13
0
void PulseAudioPlayer::CloseStream()
{
	if (!open) return;
	//printf("Closing PuseAudio\n");

	if (is_playing) Stop();

	// Hope for the best and just do things as quickly as possible
	pa_stream_disconnect(stream);
	pa_stream_unref(stream);
	pa_context_disconnect(context);
	pa_context_unref(context);
	pa_threaded_mainloop_stop(mainloop);
	pa_threaded_mainloop_free(mainloop);

	//printf("Closed PulseAudio\n");
	open = false;
}
コード例 #14
0
ファイル: pulsesrc.c プロジェクト: PeterXu/gst-mobile
static void
gst_pulsesrc_destroy_context (GstPulseSrc * pulsesrc)
{

  gst_pulsesrc_destroy_stream (pulsesrc);

  if (pulsesrc->context) {
    pa_context_disconnect (pulsesrc->context);

    /* Make sure we don't get any further callbacks */
    pa_context_set_state_callback (pulsesrc->context, NULL, NULL);
    pa_context_set_subscribe_callback (pulsesrc->context, NULL, NULL);

    pa_context_unref (pulsesrc->context);

    pulsesrc->context = NULL;
  }
}
コード例 #15
0
ファイル: apulse-context.c プロジェクト: i-rinat/apulse
static void
pai_context_set_state(pa_context *c, pa_context_state_t new_state)
{
    if (c->state == new_state)
        return;

    pa_context_ref(c);
    c->state = new_state;

    if (c->state_cb)
        c->state_cb(c, c->state_cb_userdata);

    if (new_state == PA_CONTEXT_FAILED || new_state == PA_CONTEXT_TERMINATED) {
        c->state_cb = NULL;
    }

    pa_context_unref(c);
}
コード例 #16
0
ファイル: pulseaudio.c プロジェクト: 24BitGames/LoomSDK
ALCboolean alc_pulse_init(BackendFuncs *func_list)
{
    ALCboolean ret = ALC_FALSE;

    if(pulse_load())
    {
        pa_threaded_mainloop *loop;

        pulse_ctx_flags = 0;
        if(!GetConfigValueBool("pulse", "spawn-server", 0))
            pulse_ctx_flags |= PA_CONTEXT_NOAUTOSPAWN;

        if((loop=pa_threaded_mainloop_new()) &&
           pa_threaded_mainloop_start(loop) >= 0)
        {
            pa_context *context;

            pa_threaded_mainloop_lock(loop);
            context = connect_context(loop, AL_TRUE);
            if(context)
            {
                *func_list = pulse_funcs;
                ret = ALC_TRUE;

                /* Some libraries (Phonon, Qt) set some pulseaudio properties
                 * through environment variables, which causes all streams in
                 * the process to inherit them. This attempts to filter those
                 * properties out by setting them to 0-length data. */
                prop_filter = pa_proplist_new();
                pa_proplist_set(prop_filter, PA_PROP_MEDIA_ROLE, NULL, 0);
                pa_proplist_set(prop_filter, "phonon.streamid", NULL, 0);

                pa_context_disconnect(context);
                pa_context_unref(context);
            }
            pa_threaded_mainloop_unlock(loop);
            pa_threaded_mainloop_stop(loop);
        }
        if(loop)
            pa_threaded_mainloop_free(loop);
    }

    return ret;
}
コード例 #17
0
/** Destroy libao driver */
static void uninit(int immed) {
    if (stream) {
        if (!immed && pa_stream_get_state(stream) == PA_STREAM_READY)
                wait_for_operation(pa_stream_drain(stream, NULL, NULL));
        
        pa_stream_unref(stream);
        stream = NULL;
    }

    if (context) {
        pa_context_unref(context);
        context = NULL;
    }

    if (mainloop) {
        pa_mainloop_free(mainloop);
        mainloop = NULL;
    }
}
コード例 #18
0
PulseHandler::~PulseHandler(void)
{
    // TODO - do we need to drain the context??

    LOG(VB_AUDIO, LOG_INFO, LOC + "Destroying PulseAudio handler");

    // is this correct?
    if (m_ctx)
    {
        pa_context_disconnect(m_ctx);
        pa_context_unref(m_ctx);
    }

    if (m_loop)
    {
        pa_signal_done();
        pa_mainloop_free(m_loop);
    }
}
コード例 #19
0
ファイル: context.c プロジェクト: felfert/pulseaudio
void pa_context_set_state(pa_context *c, pa_context_state_t st) {
    pa_assert(c);
    pa_assert(PA_REFCNT_VALUE(c) >= 1);

    if (c->state == st)
        return;

    pa_context_ref(c);

    c->state = st;

    if (c->state_callback)
        c->state_callback(c, c->state_userdata);

    if (st == PA_CONTEXT_FAILED || st == PA_CONTEXT_TERMINATED)
        context_unlink(c);

    pa_context_unref(c);
}
コード例 #20
0
void QPulseAudioEngine::release()
{
    if (!m_prepared)
        return;

    if (m_context) {
        pa_context_disconnect(m_context);
        pa_context_unref(m_context);
        m_context = 0;
    }

    if (m_mainLoop) {
        pa_threaded_mainloop_stop(m_mainLoop);
        pa_threaded_mainloop_free(m_mainLoop);
        m_mainLoop = 0;
    }

    m_prepared = false;
}
コード例 #21
0
	void Uninit()
	{
		int ret;
		if (mStream) {
			ret = pa_stream_disconnect(mStream);
			pa_stream_unref(mStream); //needed?
			mStream = nullptr;
		}
		if (mPContext) {
			pa_context_disconnect(mPContext);
			pa_context_unref(mPContext);
			mPContext = nullptr;
		}
		if (mPMainLoop) {
			pa_threaded_mainloop_stop(mPMainLoop);
			pa_threaded_mainloop_free(mPMainLoop);
			mPMainLoop = nullptr;
		}
	}
コード例 #22
0
ファイル: paaudio.c プロジェクト: juanquintela/qemu
static void qpa_audio_fini (void *opaque)
{
    paaudio *g = opaque;

    if (g->mainloop) {
        pa_threaded_mainloop_stop (g->mainloop);
    }

    if (g->context) {
        pa_context_disconnect (g->context);
        pa_context_unref (g->context);
    }

    if (g->mainloop) {
        pa_threaded_mainloop_free (g->mainloop);
    }

    g_free(g);
}
コード例 #23
0
ファイル: simple.c プロジェクト: KOLIA112/pulseaudio
void pa_simple_free(pa_simple *s) {
    pa_assert(s);

    if (s->mainloop)
        pa_threaded_mainloop_stop(s->mainloop);

    if (s->stream)
        pa_stream_unref(s->stream);

    if (s->context) {
        pa_context_disconnect(s->context);
        pa_context_unref(s->context);
    }

    if (s->mainloop)
        pa_threaded_mainloop_free(s->mainloop);

    pa_xfree(s);
}
コード例 #24
0
ファイル: sync-playback.c プロジェクト: Klayv/pulseaudio
int main(int argc, char *argv[]) {
    pa_mainloop* m = NULL;
    int i, ret = 0;

    for (i = 0; i < SAMPLE_HZ; i++)
        data[i] = (float) sin(((double) i/SAMPLE_HZ)*2*M_PI*SINE_HZ)/2;

    for (i = 0; i < NSTREAMS; i++)
        streams[i] = NULL;

    /* Set up a new main loop */
    m = pa_mainloop_new();
    assert(m);

    mainloop_api = pa_mainloop_get_api(m);

    context = pa_context_new(mainloop_api, argv[0]);
    assert(context);

    pa_context_set_state_callback(context, context_state_callback, NULL);

    /* Connect the context */
    if (pa_context_connect(context, NULL, 0, NULL) < 0) {
        fprintf(stderr, "pa_context_connect() failed.\n");
        goto quit;
    }

    if (pa_mainloop_run(m, &ret) < 0)
        fprintf(stderr, "pa_mainloop_run() failed.\n");

quit:
    pa_context_unref(context);

    for (i = 0; i < NSTREAMS; i++)
        if (streams[i])
            pa_stream_unref(streams[i]);

    pa_mainloop_free(m);

    return ret;
}
コード例 #25
0
ファイル: pulseaudio.c プロジェクト: IceDragon200/libsoundio
static void destroy_pa(struct SoundIoPrivate *si) {
    struct SoundIoPulseAudio *sipa = &si->backend_data.pulseaudio;

    if (sipa->main_loop)
        pa_threaded_mainloop_stop(sipa->main_loop);

    pa_context_disconnect(sipa->pulse_context);
    pa_context_unref(sipa->pulse_context);

    soundio_destroy_devices_info(sipa->current_devices_info);
    soundio_destroy_devices_info(sipa->ready_devices_info);

    if (sipa->main_loop)
        pa_threaded_mainloop_free(sipa->main_loop);

    if (sipa->props)
        pa_proplist_free(sipa->props);

    free(sipa->default_sink_name);
    free(sipa->default_source_name);
}
コード例 #26
0
void executeRequest( StateData* stateData )
{
	// Create mainloop
	pa_mainloop* mainLoop = pa_mainloop_new();
	// Create mainloop API
	pa_mainloop_api* mainLoopApi = pa_mainloop_get_api( mainLoop );
	// Create context
	pa_context* context = pa_context_new( mainLoopApi, "cinder-requests" );
	// Set context state callback
	stateData->mainLoopApi = mainLoopApi;
	pa_context_set_state_callback( context, processContextState, static_cast<void*>( stateData ) );
	// Connect context
	if( pa_context_connect( context, nullptr, PA_CONTEXT_NOFLAGS, nullptr ) >= 0 ) {
		// Run mainloop
		int result = 0;
		if( pa_mainloop_run( mainLoop, &result ) < 0 ) {
			// Handle error
		}
	}
	pa_context_unref( context );
	pa_mainloop_free( mainLoop );
}
コード例 #27
0
ファイル: tsmf_pulse.c プロジェクト: 10084462/FreeRDP
static void tsmf_pulse_free(ITSMFAudioDevice *audio)
{
	TSMFPulseAudioDevice *pulse = (TSMFPulseAudioDevice *) audio;
	DEBUG_TSMF("");
	tsmf_pulse_close_stream(pulse);
	if(pulse->mainloop)
	{
		pa_threaded_mainloop_stop(pulse->mainloop);
	}
	if(pulse->context)
	{
		pa_context_disconnect(pulse->context);
		pa_context_unref(pulse->context);
		pulse->context = NULL;
	}
	if(pulse->mainloop)
	{
		pa_threaded_mainloop_free(pulse->mainloop);
		pulse->mainloop = NULL;
	}
	free(pulse);
}
コード例 #28
0
void pulse_unref()
{
	pthread_mutex_lock(&pulse_mutex);

	if (--pulse_refs == 0) {
		pulse_lock();
		if (pulse_context != NULL) {
			pa_context_disconnect(pulse_context);
			pa_context_unref(pulse_context);
			pulse_context = NULL;
		}
		pulse_unlock();

		if (pulse_mainloop != NULL) {
			pa_threaded_mainloop_stop(pulse_mainloop);
			pa_threaded_mainloop_free(pulse_mainloop);
			pulse_mainloop = NULL;
		}
	}

	pthread_mutex_unlock(&pulse_mutex);
}
コード例 #29
0
static void pa_command_enable_srbchannel(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
    pa_context *c = userdata;

#ifdef HAVE_CREDS
    const int *fds;
    int nfd;

    pa_assert(pd);
    pa_assert(command == PA_COMMAND_ENABLE_SRBCHANNEL);
    pa_assert(t);
    pa_assert(c);
    pa_assert(PA_REFCNT_VALUE(c) >= 1);

    /* Currently only one srb channel is supported, might change in future versions */
    if (c->srb_template.readfd != -1) {
        pa_context_fail(c, PA_ERR_PROTOCOL);
        return;
    }

    fds = pa_pdispatch_fds(pd, &nfd);
    if (nfd != 2 || !fds || fds[0] == -1 || fds[1] == -1) {
        pa_context_fail(c, PA_ERR_PROTOCOL);
        return;
    }

    pa_context_ref(c);

    c->srb_template.readfd = fds[0];
    c->srb_template.writefd = fds[1];
    c->srb_setup_tag = tag;

    pa_context_unref(c);

#else
    pa_assert(c);
    pa_context_fail(c, PA_ERR_PROTOCOL);
#endif
}
コード例 #30
0
int context_create(){
    if(context != NULL){
        return 0;
    }
    connected = false;
    failed = false;

    threaded_main_loop = pa_threaded_mainloop_new();
    pa_mainloop_api *main_loop_api = pa_threaded_mainloop_get_api(threaded_main_loop);
    context =  pa_context_new(main_loop_api, "vumeter");

    pa_context_set_state_callback(context, context_state_callback, NULL);

    if(pa_context_connect(context, NULL, (pa_context_flags_t) PA_CONTEXT_NOAUTOSPAWN, NULL)){
        qDebug("Error connecting to server...");
        pa_threaded_mainloop_stop(threaded_main_loop);
        pa_threaded_mainloop_free(threaded_main_loop);
        return -1;
    }

    pa_threaded_mainloop_start(threaded_main_loop);

    pa_threaded_mainloop_lock(threaded_main_loop);
    while ((! connected) && (! failed)) {
        qDebug("Waiting until connection is established...");
        pa_threaded_mainloop_wait(threaded_main_loop);
        qDebug("Received signal...");
    }
    pa_threaded_mainloop_unlock(threaded_main_loop);

    if(failed){
        pa_context_unref(context);
        context = NULL;
        return -2;
    }

    return 0;
}