• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ pa_context_connect函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中pa_context_connect函数的典型用法代码示例。如果您正苦于以下问题:C++ pa_context_connect函数的具体用法?C++ pa_context_connect怎么用?C++ pa_context_connect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了pa_context_connect函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: main

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;
}
开发者ID:Klayv,项目名称:pulseaudio,代码行数:41,代码来源:sync-playback.c


示例2: pulse_connect

/*
 * 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;
}
开发者ID:Jhonthe7th,项目名称:obs-studio,代码行数:44,代码来源:pulse-input.c


示例3: audio_driver_init

audio_class_t *
audio_driver_init(void)
{
  TRACE(TRACE_DEBUG, "PA", "Headerversion: %s, library: %s",
	pa_get_headers_version(), pa_get_library_version());

  mainloop = pa_threaded_mainloop_new();
  api = pa_threaded_mainloop_get_api(mainloop);

  pa_threaded_mainloop_lock(mainloop);
  pa_threaded_mainloop_start(mainloop);

#if PA_API_VERSION >= 12
  pa_proplist *pl = pa_proplist_new();

  pa_proplist_sets(pl, PA_PROP_APPLICATION_ID, "com.lonelycoder.hts.showtime");
  pa_proplist_sets(pl, PA_PROP_APPLICATION_NAME, "Showtime");
  
  /* Create a new connection context */
  ctx = pa_context_new_with_proplist(api, "Showtime", pl);
  pa_proplist_free(pl);
#else
  ctx = pa_context_new(api, "Showtime");
#endif

  pa_context_set_state_callback(ctx, context_state_callback, NULL);

  /* Connect the context */
  if(pa_context_connect(ctx, NULL, 0, NULL) < 0) {
    TRACE(TRACE_ERROR, "PA", "pa_context_connect() failed: %s",
	  pa_strerror(pa_context_errno(ctx)));
    pa_threaded_mainloop_unlock(mainloop);
    return NULL;
  }

  pa_threaded_mainloop_unlock(mainloop);

  return &pulseaudio_audio_class;
}
开发者ID:kshostak,项目名称:showtime,代码行数:39,代码来源:pulseaudio.c


示例4: executeRequest

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 );
}
开发者ID:cinder,项目名称:Cinder,代码行数:22,代码来源:DeviceManagerPulseAudio.cpp


示例5: get_db

double get_db()
{
    pa_glib_mainloop *pa_ml = NULL;
    pa_mainloop_api *pa_mlapi = NULL;
    //pa_operation *pa_op = NULL;
    pa_context *pa_ctx = NULL;

    GMainContext *mctx = NULL;

    pa_ml = pa_glib_mainloop_new(g_main_context_default());
    pa_mlapi = pa_glib_mainloop_get_api(pa_ml);
    pa_ctx = pa_context_new(pa_mlapi, "deepin");

    pa_context_connect(pa_ctx, NULL, 0, NULL);
    pa_context_set_state_callback(pa_ctx, pa_state_cb, NULL);

    mctx = g_main_context_default();
    mainloop = g_main_loop_new(mctx, FALSE);
    g_main_loop_run(mainloop);
    
    return ret;
}
开发者ID:tsuibin,项目名称:record_recog,代码行数:22,代码来源:get_db.c


示例6: pulse_init

int pulse_init(struct pulseaudio_t *pulse) {
    enum pa_context_state state = PA_CONTEXT_CONNECTING;

    pulse->mainloop = pa_mainloop_new();
    pulse->cxt = pa_context_new(pa_mainloop_get_api(pulse->mainloop), "pavol");
    pulse->default_sink = NULL;
    pulse->muted = 0;
    pulse->volume = 0;

    pa_context_set_state_callback(pulse->cxt, pulse_connect_state_cb, &state);
    pa_context_connect(pulse->cxt, NULL, PA_CONTEXT_NOFLAGS, NULL);
    while (state != PA_CONTEXT_READY && state != PA_CONTEXT_FAILED)
        pa_mainloop_iterate(pulse->mainloop, 1, NULL);

    if (state != PA_CONTEXT_READY) {
        fprintf(stderr, "failed to connect to pulse daemon: %s\n",
                pa_strerror(pa_context_errno(pulse->cxt)));
        return 1;
    }

    return 0;
}
开发者ID:lotrfan,项目名称:pavolume,代码行数:22,代码来源:pavol.c


示例7: swfdec_playback_open

SwfdecPlayback *
swfdec_playback_open (SwfdecPlayer *player, GMainContext *context)
{
  SwfdecPlayback *sound;
  const GList *walk;
  pa_mainloop_api *pa_api;

  g_return_val_if_fail (SWFDEC_IS_PLAYER (player), NULL);
  g_return_val_if_fail (context != NULL, NULL);

  sound = g_new0 (SwfdecPlayback, 1);
  sound->player = player;
  g_signal_connect (player, "advance", G_CALLBACK (advance_before), sound);
  g_signal_connect (player, "audio-added", G_CALLBACK (audio_added), sound);
  g_signal_connect (player, "audio-removed", G_CALLBACK (audio_removed), sound);

  /* Create our mainloop attachment to glib.  XXX: I hope this means we don't
   * have to run the main loop using pa functions.
   */
  sound->pa_mainloop = pa_glib_mainloop_new (context);
  pa_api = pa_glib_mainloop_get_api (sound->pa_mainloop);

  sound->pa = pa_context_new (pa_api, "swfdec");

  pa_context_set_state_callback (sound->pa, context_state_callback, sound);
  pa_context_connect (sound->pa,
		      NULL, /* default server */
		      0, /* default flags */
		      NULL /* spawning api */
		      );

  for (walk = swfdec_player_get_audio (player); walk; walk = walk->next) {
    swfdec_playback_stream_open (sound, walk->data);
  }
  g_main_context_ref (context);
  sound->context = context;
  return sound;
}
开发者ID:fengye,项目名称:swfdec,代码行数:38,代码来源:swfdec_playback_pulse.c


示例8: context_create

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;
}
开发者ID:ruedigergad,项目名称:vumeter,代码行数:38,代码来源:pa_context_helper.cpp


示例9: main

int main(int argc, char *argv[]) {

    // Define our pulse audio loop and connection variables
    pa_mainloop *pa_ml;
    pa_mainloop_api *pa_mlapi;

    // Create a mainloop API and connection to the default server
    pa_ml = pa_mainloop_new();
    pa_mlapi = pa_mainloop_get_api(pa_ml);
    context = pa_context_new(pa_mlapi, "Device list");

    // This function connects to the pulse server
    pa_context_connect(context, NULL, 0, NULL);

    // This function defines a callback so the server will tell us its state.
    pa_context_set_state_callback(context, context_state_cb, NULL);

    if (pa_mainloop_run(pa_ml, &ret) < 0) {
	printf("pa_mainloop_run() failed.");
	exit(1);
    }
    printf("func = %s , LINE = %d \n",__func__,__LINE__);
}
开发者ID:Pradeeplge,项目名称:pulseaudio,代码行数:23,代码来源:palist_devices.c


示例10: cubeb_init

int
cubeb_init(cubeb ** context, char const * context_name)
{
  cubeb * ctx;

  ctx = calloc(1, sizeof(*ctx));

  ctx->mainloop = pa_threaded_mainloop_new();
  ctx->context = pa_context_new(pa_threaded_mainloop_get_api(ctx->mainloop), context_name);

  pa_context_set_state_callback(ctx->context, context_state_callback, ctx->mainloop);
  pa_threaded_mainloop_start(ctx->mainloop);

  pa_threaded_mainloop_lock(ctx->mainloop);
  pa_context_connect(ctx->context, NULL, 0, NULL);
  pa_threaded_mainloop_unlock(ctx->mainloop);

  state_wait(ctx, PA_CONTEXT_READY);

  *context = ctx;

  return CUBEB_OK;
}
开发者ID:rillian,项目名称:cubeb,代码行数:23,代码来源:cubeb_pulse.c


示例11: enumerate_audio_source_devices

static gboolean enumerate_audio_source_devices(GClosure *callback)
{
    AudioListContext *context;

    context = g_slice_new0(AudioListContext);

    context->callback = callback;

    context->mainloop = pa_glib_mainloop_new(_owr_get_main_context());

    if (!context->mainloop) {
        g_warning("PulseAudio: failed to create glib mainloop");
        goto cleanup;
    }

    context->pa_context = pa_context_new(pa_glib_mainloop_get_api(context->mainloop), "Owr");

    if (!context->pa_context) {
        g_warning("PulseAudio: failed to create context");
        goto cleanup_mainloop;
    }

    pa_context_set_state_callback(context->pa_context,
        (pa_context_notify_cb_t) on_pulse_context_state_change, context);
    pa_context_connect(context->pa_context, NULL, 0, NULL);

done:
    return FALSE;

cleanup_mainloop:
    pa_glib_mainloop_free(context->mainloop);

cleanup:
    finish_pa_list(context);

    goto done;
}
开发者ID:ikonst,项目名称:openwebrtc,代码行数:37,代码来源:owr_device_list.c


示例12: audio_init

void audio_init() {
	pa_threaded_mainloop *pa_ml=pa_threaded_mainloop_new();
	pa_mainloop_api *pa_mlapi=pa_threaded_mainloop_get_api(pa_ml);
	pa_context *pa_ctx=pa_context_new(pa_mlapi, "te");
	pa_context_connect(pa_ctx, NULL, 0, NULL);
	int pa_ready = 0;
	pa_context_set_state_callback(pa_ctx, pa_state_cb, &pa_ready);

	pa_threaded_mainloop_start(pa_ml);
	while(pa_ready==0) { ; }

	printf("audio ready\n");

	if (pa_ready == 2) {
		pa_context_disconnect(pa_ctx);
		pa_context_unref(pa_ctx);
		pa_threaded_mainloop_free(pa_ml);
	}

	pa_sample_spec ss;
	ss.rate=96000;
	ss.channels=1;
	ss.format=PA_SAMPLE_S24_32LE;
	ps=pa_stream_new(pa_ctx,"Playback",&ss,NULL);
	pa_stream_set_write_callback(ps,audio_request_cb,NULL);
	pa_stream_set_underflow_callback(ps,audio_underflow_cb,NULL);

	pa_buffer_attr bufattr;
	bufattr.fragsize = (uint32_t)-1;
	bufattr.maxlength = pa_usec_to_bytes(20000,&ss);
	bufattr.minreq = pa_usec_to_bytes(0,&ss);
	bufattr.prebuf = 0;
	bufattr.tlength = pa_usec_to_bytes(20000,&ss);

	pa_stream_connect_playback(ps,NULL,&bufattr,
		PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_ADJUST_LATENCY|PA_STREAM_AUTO_TIMING_UPDATE|PA_STREAM_START_CORKED,NULL,NULL);
}
开发者ID:ITikhonov,项目名称:tem,代码行数:37,代码来源:te.c


示例13: connect_server

static void connect_server(struct ausrv *ausrv)
{
    pa_mainloop_api *api    = pa_glib_mainloop_get_api(ausrv->mainloop);
    char            *server = ausrv->server;

    cancel_timer(ausrv);


    if (server != NULL && !strcmp(ausrv->server, DEFAULT_SERVER))
        server = NULL;
    
    
    /*
     * Note: It is not possible to reconnect a context if it ever gets
     *     disconnected. If we have a context here, get rid of it and
     *     allocate a new one.
     */
    if (ausrv->context != NULL) {
        pa_context_set_state_callback(ausrv->context, NULL, NULL);
        pa_context_set_subscribe_callback(ausrv->context, NULL, NULL);
        pa_context_unref(ausrv->context);
        ausrv->context = NULL;
    }
    
    if ((ausrv->context = pa_context_new(api, pa_client_name)) == NULL) {
        LOG_ERROR("%s(): pa_context_new() failed, exiting", __FUNCTION__);
        exit(1);
    }
    
    pa_context_set_state_callback(ausrv->context, context_callback, ausrv);
    pa_context_set_subscribe_callback(ausrv->context, event_callback, ausrv);


    LOG_INFO("Trying to connect to %s...", server ? server : DEFAULT_SERVER);
    pa_context_connect(ausrv->context, server, PA_CONTEXT_NOAUTOSPAWN, NULL);
}
开发者ID:jusa,项目名称:tone-generator,代码行数:36,代码来源:ausrv.c


示例14: pa_threaded_mainloop_new

PulseAudioSystem::PulseAudioSystem() {
	pasInput = pasOutput = pasSpeaker = NULL;
	bSourceDone=bSinkDone=bServerDone = false;
	iDelayCache = 0;
	bPositionalCache = false;
	bAttenuating = false;
	iRemainingOperations = 0;
	bPulseIsGood = false;
	iSinkId = -1;

	pam = pa_threaded_mainloop_new();
	pa_mainloop_api *api = pa_threaded_mainloop_get_api(pam);

	pa_proplist *proplist;

	proplist = pa_proplist_new();
	pa_proplist_sets(proplist, PA_PROP_APPLICATION_NAME, "Mumble");
	pa_proplist_sets(proplist, PA_PROP_APPLICATION_ID, "net.sourceforge.mumble.mumble");
	pa_proplist_sets(proplist, PA_PROP_APPLICATION_ICON_NAME, "mumble");
	pa_proplist_sets(proplist, PA_PROP_MEDIA_ROLE, "game");

	pacContext = pa_context_new_with_proplist(api, NULL, proplist);
	pa_proplist_free(proplist);

	pa_context_set_subscribe_callback(pacContext, subscribe_callback, this);

	pa_context_set_state_callback(pacContext, context_state_callback, this);
	pa_context_connect(pacContext, NULL, PA_CONTEXT_NOAUTOSPAWN, NULL);

	pade = api->defer_new(api, defer_event_callback, this);
	api->defer_enable(pade, false);

	pa_threaded_mainloop_start(pam);

	bRunning = true;
}
开发者ID:AceXare,项目名称:mumble,代码行数:36,代码来源:PulseAudio.cpp


示例15: sa_stream_create_pcm

int
sa_stream_create_pcm(
  sa_stream_t      ** _s,
  const char        * client_name,
  sa_mode_t           mode,
  sa_pcm_format_t     format,
  unsigned  int       rate,
  unsigned  int       n_channels
) {
  sa_stream_t   * s = 0;
  char *server = NULL;

  /*
   * Make sure we return a NULL stream pointer on failure.
   */
  if (_s == NULL) {
    return SA_ERROR_INVALID;
  }
  *_s = NULL;

  if (mode != SA_MODE_WRONLY) {
    return SA_ERROR_NOT_SUPPORTED;
  }
  if (format != SA_PCM_FORMAT_S16_LE) {
    return SA_ERROR_NOT_SUPPORTED;
  }

  /*
   * Allocate the instance and required resources.
   */
  if ((s = malloc(sizeof(sa_stream_t))) == NULL) {
    return SA_ERROR_OOM;
  }
  if ((s->bl_head = new_buffer()) == NULL) {
    free(s);
    return SA_ERROR_OOM;
  }

  if (pthread_mutex_init(&s->mutex, NULL) != 0) {
    free(s->bl_head);
    free(s);
    return SA_ERROR_SYSTEM;
  }

  s->stream        = NULL;
  s->m             = NULL;
  s->thread_id     = 0;
  s->playing       = 0;
  s->bytes_written = 0;

  s->bl_tail       = s->bl_head;
  s->n_bufs        = 1;

  s->sample_spec.format = PA_SAMPLE_S16LE;
  s->sample_spec.channels = n_channels;
  s->sample_spec.rate = rate;

  strcpy(s->client_name, client_name);

  /* Set up a new main loop */
  s->m = pa_threaded_mainloop_new();
  pa_threaded_mainloop_start(s->m);

  pa_threaded_mainloop_lock(s->m);

  /* Create a new connection context */
  if (!(s->context = pa_context_new(pa_threaded_mainloop_get_api(s->m), "OggPlay"))) {
    fprintf(stderr, "pa_context_new() failed.\n");
    goto unlock_and_fail;
  }
  pa_context_set_state_callback(s->context, context_state_callback, s);

  pa_context_connect(s->context, server, 0, NULL);

  /* Wait until the context is ready */
  pa_threaded_mainloop_wait(s->m);
  if (pa_context_get_state(s->context) != PA_CONTEXT_READY) {
    fprintf(stderr, "creating Pulseaudio Context failed\n");
    goto unlock_and_fail;
  }
  pa_threaded_mainloop_unlock(s->m);

  *_s = s;
  return SA_SUCCESS;

unlock_and_fail:
  pa_threaded_mainloop_unlock(s->m);
  free(s);
  return SA_ERROR_OOM;
}
开发者ID:MozillaOnline,项目名称:gecko-dev,代码行数:90,代码来源:sydney_audio_pulseaudio.c


示例16: main


//.........这里部分代码省略.........
        }
    }

    /* Fill in media name if none was set */
    if (!pa_proplist_contains(proplist, PA_PROP_MEDIA_NAME)) {
        const char *t;

        if ((t = filename) ||
            (t = pa_proplist_gets(proplist, PA_PROP_APPLICATION_NAME)))
            pa_proplist_sets(proplist, PA_PROP_MEDIA_NAME, t);
    }

    /* Set up a new main loop */
    if (!(m = pa_mainloop_new())) {
        pa_log(_("pa_mainloop_new() failed."));
        goto quit;
    }

    mainloop_api = pa_mainloop_get_api(m);

    pa_assert_se(pa_signal_init(mainloop_api) == 0);
    pa_signal_new(SIGINT, exit_signal_callback, NULL);
    pa_signal_new(SIGTERM, exit_signal_callback, NULL);
#ifdef SIGUSR1
    pa_signal_new(SIGUSR1, sigusr1_signal_callback, NULL);
#endif
    pa_disable_sigpipe();

    if (raw) {
        if (!(stdio_event = mainloop_api->io_new(mainloop_api,
                                                 mode == PLAYBACK ? STDIN_FILENO : STDOUT_FILENO,
                                                 mode == PLAYBACK ? PA_IO_EVENT_INPUT : PA_IO_EVENT_OUTPUT,
                                                 mode == PLAYBACK ? stdin_callback : stdout_callback, NULL))) {
            pa_log(_("io_new() failed."));
            goto quit;
        }
    }

    /* Create a new connection context */
    if (!(context = pa_context_new_with_proplist(mainloop_api, NULL, proplist))) {
        pa_log(_("pa_context_new() failed."));
        goto quit;
    }

    pa_context_set_state_callback(context, context_state_callback, NULL);

    /* Connect the context */
    if (pa_context_connect(context, server, 0, NULL) < 0) {
        pa_log(_("pa_context_connect() failed: %s"), pa_strerror(pa_context_errno(context)));
        goto quit;
    }

    if (verbose) {
        if (!(time_event = pa_context_rttime_new(context, pa_rtclock_now() + TIME_EVENT_USEC, time_event_callback, NULL))) {
            pa_log(_("pa_context_rttime_new() failed."));
            goto quit;
        }
    }

    /* Run the main loop */
    if (pa_mainloop_run(m, &ret) < 0) {
        pa_log(_("pa_mainloop_run() failed."));
        goto quit;
    }

quit:
    if (stream)
        pa_stream_unref(stream);

    if (context)
        pa_context_unref(context);

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

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

    if (m) {
        pa_signal_done();
        pa_mainloop_free(m);
    }

    pa_xfree(buffer);

    pa_xfree(server);
    pa_xfree(device);

    if (sndfile)
        sf_close(sndfile);

    if (proplist)
        pa_proplist_free(proplist);

    return ret;
}
开发者ID:almosthappy4u,项目名称:PulseAudio-UCM,代码行数:101,代码来源:pacat.c


示例17: init

static int init(struct ao *ao, char *params)
{
    struct pa_sample_spec ss;
    struct pa_channel_map map;
    char *devarg = NULL;
    char *host = NULL;
    char *sink = NULL;
    const char *version = pa_get_library_version();

    struct priv *priv = talloc_zero(ao, struct priv);
    ao->priv = priv;

    if (params) {
        devarg = strdup(params);
        sink = strchr(devarg, ':');
        if (sink)
            *sink++ = 0;
        if (devarg[0])
            host = devarg;
    }

    priv->broken_pause = false;
    /* not sure which versions are affected, assume 0.9.11* to 0.9.14*
     * known bad: 0.9.14, 0.9.13
     * known good: 0.9.9, 0.9.10, 0.9.15
     * To test: pause, wait ca. 5 seconds, framestep and see if MPlayer
     * hangs somewhen. */
    if (strncmp(version, "0.9.1", 5) == 0 && version[5] >= '1'
        && version[5] <= '4') {
        mp_msg(MSGT_AO, MSGL_WARN,
               "[pulse] working around probably broken pause functionality,\n"
               "        see http://www.pulseaudio.org/ticket/440\n");
        priv->broken_pause = true;
    }

    ss.channels = ao->channels;
    ss.rate = ao->samplerate;

    const struct format_map *fmt_map = format_maps;
    while (fmt_map->mp_format != ao->format) {
        if (fmt_map->mp_format == AF_FORMAT_UNKNOWN) {
            mp_msg(MSGT_AO, MSGL_V,
                   "AO: [pulse] Unsupported format, using default\n");
            fmt_map = format_maps;
            break;
        }
        fmt_map++;
    }
    ao->format = fmt_map->mp_format;
    ss.format = fmt_map->pa_format;

    if (!pa_sample_spec_valid(&ss)) {
        mp_msg(MSGT_AO, MSGL_ERR, "AO: [pulse] Invalid sample spec\n");
        goto fail;
    }

    pa_channel_map_init_auto(&map, ss.channels, PA_CHANNEL_MAP_ALSA);
    ao->bps = pa_bytes_per_second(&ss);

    if (!(priv->mainloop = pa_threaded_mainloop_new())) {
        mp_msg(MSGT_AO, MSGL_ERR, "AO: [pulse] Failed to allocate main loop\n");
        goto fail;
    }

    if (!(priv->context = pa_context_new(pa_threaded_mainloop_get_api(
                                 priv->mainloop), PULSE_CLIENT_NAME))) {
        mp_msg(MSGT_AO, MSGL_ERR, "AO: [pulse] Failed to allocate context\n");
        goto fail;
    }

    pa_context_set_state_callback(priv->context, context_state_cb, ao);

    if (pa_context_connect(priv->context, host, 0, NULL) < 0)
        goto fail;

    pa_threaded_mainloop_lock(priv->mainloop);

    if (pa_threaded_mainloop_start(priv->mainloop) < 0)
        goto unlock_and_fail;

    /* Wait until the context is ready */
    pa_threaded_mainloop_wait(priv->mainloop);

    if (pa_context_get_state(priv->context) != PA_CONTEXT_READY)
        goto unlock_and_fail;

    if (!(priv->stream = pa_stream_new(priv->context, "audio stream", &ss,
                                       &map)))
        goto unlock_and_fail;

    pa_stream_set_state_callback(priv->stream, stream_state_cb, ao);
    pa_stream_set_write_callback(priv->stream, stream_request_cb, ao);
    pa_stream_set_latency_update_callback(priv->stream,
                                          stream_latency_update_cb, ao);
    pa_buffer_attr bufattr = {
        .maxlength = -1,
        .tlength = pa_usec_to_bytes(1000000, &ss),
        .prebuf = -1,
        .minreq = -1,
        .fragsize = -1,
//.........这里部分代码省略.........
开发者ID:Newbleeto,项目名称:mplayer2,代码行数:101,代码来源:ao_pulse.c


示例18: pa_threaded_mainloop_new

/*! Starts up audio streaming to the host. */
void HostAudio::open()
{
	m_mainloop = pa_threaded_mainloop_new();
	if (!m_mainloop) {
		qDebug("Could not acquire PulseAudio main loop");
		return;
	}
	m_api = pa_threaded_mainloop_get_api(m_mainloop);
	m_context = pa_context_new(m_api, "emumaster");
	pa_context_set_state_callback(m_context, contextStreamCallback, this);

	if (!m_context) {
		qDebug("Could not acquire PulseAudio device context");
		return;
	}
#if defined(MEEGO_EDITION_HARMATTAN)
	if (pa_context_connect(m_context, 0, PA_CONTEXT_NOFLAGS, 0) < 0) {
#elif defined(Q_WS_MAEMO_5)
	if (pa_context_connect(m_context, 0, (pa_context_flags_t)0, 0) < 0) {
#endif
		int error = pa_context_errno(m_context);
		qDebug("Could not connect to PulseAudio server: %s", pa_strerror(error));
		return;
	}
	pa_threaded_mainloop_lock(m_mainloop);
	if (pa_threaded_mainloop_start(m_mainloop) < 0) {
		qDebug("Could not start mainloop");
		return;
	}

	waitForStreamReady();

	pa_sample_spec fmt;
	fmt.channels = 2;
	fmt.format = PA_SAMPLE_S16LE;
	fmt.rate = 44100;

	pa_buffer_attr buffer_attributes;
	buffer_attributes.tlength = pa_bytes_per_second(&fmt) / 5;
	buffer_attributes.maxlength = buffer_attributes.tlength * 3;
	buffer_attributes.minreq = buffer_attributes.tlength / 3;
	buffer_attributes.prebuf = buffer_attributes.tlength;

	m_stream = pa_stream_new(m_context, "emumaster", &fmt, 0);
	if (!m_stream) {
		int error = pa_context_errno(m_context);
		qDebug("Could not acquire new PulseAudio stream: %s", pa_strerror(error));
		return;
	}
	pa_stream_flags_t flags = (pa_stream_flags_t)(PA_STREAM_ADJUST_LATENCY | PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_AUTO_TIMING_UPDATE);
//	pa_stream_flags_t flags = (pa_stream_flags_t) (PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_AUTO_TIMING_UPDATE | PA_STREAM_EARLY_REQUESTS);
	if (pa_stream_connect_playback(m_stream, 0, &buffer_attributes, flags, 0, 0) < 0) {
		m_stream = 0;
		int error = pa_context_errno(m_context);
		qDebug("Could not connect for playback: %s", pa_strerror(error));
		return;
	}

	waitForStreamReady();

	pa_threaded_mainloop_unlock(m_mainloop);
}

/*! Stops audio streaming. */
void HostAudio::close()
{
	if (m_mainloop)
		pa_threaded_mainloop_stop(m_mainloop);
	if (m_stream) {
		pa_stream_unref(m_stream);
		m_stream = 0;
	}
	if (m_context) {
		pa_context_disconnect(m_context);
		pa_context_unref(m_context);
		m_context = 0;
	}
	if (m_mainloop) {
		pa_threaded_mainloop_free(m_mainloop);
		m_mainloop = 0;
	}
}

/*! Streams a frame of audio from emulated system to the host. */
void HostAudio::sendFrame()
{
	if (!m_stream)
		return;
	pa_threaded_mainloop_lock(m_mainloop);
	void *data;
#if defined(MEEGO_EDITION_HARMATTAN)
	size_t size = -1;
	pa_stream_begin_write(m_stream, &data, &size);
#elif defined(Q_WS_MAEMO_5)
	size_t size = 4096;
	static char buf[4096];
	data = buf;
#endif
	size = qMin(size, pa_stream_writable_size(m_stream));
//.........这里部分代码省略.........
开发者ID:plasma-apps,项目名称:emumaster,代码行数:101,代码来源:hostaudio.cpp


示例19: assert

int PulseAudioDriver::setup(bool capture, bool playback, const QString& )
{
	PENTER;
	
	sample_spec.rate = frame_rate;
	sample_spec.channels = 2;
	sample_spec.format = PA_SAMPLE_FLOAT32NE;
	
	assert(pa_sample_spec_valid(&sample_spec));
	
	if (channel_map_set && channel_map.channels != sample_spec.channels) {
		fprintf(stderr, "Channel map doesn't match file.\n");
		return -1;
	}
	
	/* Set up a new main loop */
	if (!(mainloop = pa_mainloop_new())) {
		fprintf(stderr, "pa_mainloop_new() failed.\n");
		return -1;
	}

	mainloop_api = pa_mainloop_get_api(mainloop);

	int r = pa_signal_init(mainloop_api);
	assert(r == 0);

	/* Create a new connection context */
	if (!(context = pa_context_new(mainloop_api, "Traverso"))) {
		fprintf(stderr, "pa_context_new() failed.\n");
		return -1;
	}

	pa_context_set_state_callback(context, context_state_callback, this);

	/* Connect the context */
	pa_context_connect(context, "", (pa_context_flags_t)0, NULL);

	int ret;
	/* Run the main loop */
// 	if (pa_mainloop_run(mainloop, &ret) < 0) {
// 		fprintf(stderr, "pa_mainloop_run() failed.\n");
// 		return -1;
// 	}


	AudioChannel* audiochannel;
	int port_flags;
	char buf[32];
	
	// TODO use the found maxchannel count for the playback stream, instead of assuming 2 !!
	for (int chn = 0; chn < 2; chn++) {

		snprintf (buf, sizeof(buf) - 1, "playback_%d", chn+1);

		audiochannel = device->register_playback_channel(buf, "32 bit float audio", port_flags, frames_per_cycle, chn);
		audiochannel->set_latency( frames_per_cycle + capture_frame_latency );
		playbackChannels.append(audiochannel);
	}

	// TODO use the found maxchannel count for the capture stream, instead of assuming 0 !!
	for (int chn = 0; chn < 2; chn++) {

		snprintf (buf, sizeof(buf) - 1, "capture_%d", chn+1);

		audiochannel = device->register_capture_channel(buf, "32 bit float audio", port_flags, frames_per_cycle, chn);
		audiochannel->set_latency( frames_per_cycle + capture_frame_latency );
		captureChannels.append(audiochannel);
	}

	return 1;
}
开发者ID:ErwanLegrand,项目名称:Traverso-DAW,代码行数:71,代码来源:PulseAudioDriver.cpp


示例20: malloc

struct pulse_conn_t *pulse_conn_open(const char *name, amp_audio_f func, void *arg, const struct pulse_conf_t *conf)
{
	int err;
	unsigned int i;
	pthread_attr_t attr;
	struct sched_param param;
	struct pulse_conn_t *conn;

	conn = malloc(sizeof(struct pulse_conn_t));
	conn->quit = 0;
	conn->width = (conf->in > conf->out) ? conf->in : conf->out;
	conn->lat = conf->rate * (conf->lat / 1000.0f);
	conn->conf = *conf;
	conn->func = func;
	conn->arg = arg;
	conn->rd = 0;
	conn->wr = conn->lat;
	conn->startup = 2;
	conn->reset[0] = conn->reset[1] = 1;
	conn->nrd = conn->nwr = conf->rate;

	//printf("width: %u\n", conn->width);

	conn->buf = malloc(conn->width * sizeof(void *));
	for(i = 0; i < conn->width; i++)
		memset(conn->buf[i] = malloc(2 * conn->lat * sizeof(float)), 0x00, 2 * conn->lat * sizeof(float));

	if(pipe(conn->pipe) < 0)
		fprintf(stderr, "Cannot create pipe."), exit(1);

	conn->loop = pa_mainloop_new();
	conn->api = pa_mainloop_get_api(conn->loop);
	pa_mainloop_set_poll_func(conn->loop, conn_poll, conn);

	conn->context = pa_context_new(conn->api, name);
	pa_context_set_state_callback(conn->context, conn_state, conn);
	pa_context_connect(conn->context, NULL, 0, NULL);

	err = pthread_attr_init(&attr);
	if(err != 0)
		fprintf(stderr, "Failed to initialize thread attributes. %s.", strerror(err)), exit(1);

	err = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
	if(err != 0)
		fprintf(stderr, "Failed to set schedular inheritance. %s.", strerror(err)), exit(1);

	err = pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
	if(err != 0)
		fprintf(stderr, "Failed to set schedular policy. %s.", strerror(err)), exit(1);

	param.sched_priority = 99;
	err = pthread_attr_setschedparam(&attr, &param);
	if(err != 0)
		fprintf(stderr, "Failed to set schedular parameter. %s.", strerror(err)), exit(1);

	err = pthread_create(&conn->thread, &attr, conn_thread, conn);
	if(err != 0) {
		err = pthread_create(&conn->thread, NULL, conn_thread, conn);
		if(err != 0)
			fprintf(stderr, "Failed to start thread. %s.", strerror(err)), exit(1);
	}

	pthread_attr_destroy(&attr);
	if(err != 0)
		fprintf(stderr, "Failed to destroy thread attributes. %s.", strerror(err)), exit(1);

	return conn;
}
开发者ID:marcandrysco,项目名称:AudioManipProg,代码行数:68,代码来源:conn.c



注:本文中的pa_context_connect函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ pa_context_disconnect函数代码示例发布时间:2022-05-30
下一篇:
C++ pa_close函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap