/*static*/ int jack_init (cubeb ** context, char const * context_name) { int r; *context = NULL; cubeb * ctx = (cubeb *)calloc(1, sizeof(*ctx)); if (ctx == NULL) { return CUBEB_ERROR; } r = load_jack_lib(ctx); if (r != 0) { cbjack_destroy(ctx); return CUBEB_ERROR; } api_jack_set_error_function(silent_jack_error_callback); api_jack_set_info_function(silent_jack_error_callback); ctx->ops = &cbjack_ops; ctx->mutex = PTHREAD_MUTEX_INITIALIZER; for (r = 0; r < MAX_STREAMS; r++) { ctx->streams[r].mutex = PTHREAD_MUTEX_INITIALIZER; } const char * jack_client_name = "cubeb"; if (context_name) jack_client_name = context_name; ctx->jack_client = api_jack_client_open(jack_client_name, JackNoStartServer, NULL); if (ctx->jack_client == NULL) { cbjack_destroy(ctx); return CUBEB_ERROR; } ctx->jack_xruns = 0; api_jack_set_process_callback (ctx->jack_client, cbjack_process, ctx); api_jack_set_xrun_callback (ctx->jack_client, cbjack_xrun_callback, ctx); api_jack_set_graph_order_callback (ctx->jack_client, cbjack_graph_order_callback, ctx); if (api_jack_activate (ctx->jack_client)) { cbjack_destroy(ctx); return CUBEB_ERROR; } ctx->jack_sample_rate = api_jack_get_sample_rate(ctx->jack_client); ctx->jack_latency = 128 * 1000 / ctx->jack_sample_rate; ctx->active = true; *context = ctx; return CUBEB_OK; }
/*static*/ int jack_init (cubeb ** context, char const * context_name) { int r; if (context == NULL) { return CUBEB_ERROR_INVALID_PARAMETER; } *context = NULL; cubeb *ctx = (cubeb*)calloc(1, sizeof(*ctx)); if (ctx == NULL) { return CUBEB_ERROR; } r = load_jack_lib(ctx); if (r != 0) { cbjack_destroy(ctx); return CUBEB_ERROR; } r = pthread_mutex_init(&ctx->mutex, NULL); if (r != 0) { cbjack_destroy(ctx); return CUBEB_ERROR; } ctx->ops = &cbjack_ops; const char* jack_client_name = "cubeb"; if (context_name) jack_client_name = context_name; ctx->jack_client = api_jack_client_open(jack_client_name, JackNoStartServer, NULL); if (ctx->jack_client == NULL) { cbjack_destroy(ctx); return CUBEB_ERROR; } ctx->jack_sample_rate = api_jack_get_sample_rate(ctx->jack_client); api_jack_set_process_callback (ctx->jack_client, cbjack_process, ctx); if (api_jack_activate (ctx->jack_client)) { cbjack_destroy(ctx); return CUBEB_ERROR; } for (int s = 0; s < MAX_STREAMS; s++) { for (int c = 0; c < MAX_CHANNELS; c++) { ctx->streams[s].ringbuffer[c] = api_jack_ringbuffer_create(FIFO_SIZE); if (!ctx->streams[s].ringbuffer[c]) { cbjack_destroy(ctx); return CUBEB_ERROR; } } } ctx->active = true; r = pthread_create (&ctx->stream_refill_thread, NULL, stream_refill_thread, (void *)ctx); if (r != 0) { ctx->stream_refill_thread = 0; cbjack_destroy(ctx); return CUBEB_ERROR; } *context = ctx; return CUBEB_OK; }