/** * Start recording * * We request the default format used by pulse here because the data will be * converted and possibly re-sampled by obs anyway. * * For now we request a buffer length of 25ms although pulse seems to ignore * this setting for monitor streams. For "real" input streams this should work * fine though. */ static int_fast32_t pulse_start_recording(struct pulse_data *data) { if (pulse_get_server_info(pulse_server_info, (void *) data) < 0) { blog(LOG_ERROR, "Unable to get server info !"); return -1; } if (pulse_get_source_info(pulse_source_info, data->device, (void *) data) < 0) { blog(LOG_ERROR, "Unable to get source info !"); return -1; } pa_sample_spec spec; spec.format = data->format; spec.rate = data->samples_per_sec; spec.channels = data->channels; if (!pa_sample_spec_valid(&spec)) { blog(LOG_ERROR, "Sample spec is not valid"); return -1; } data->speakers = pulse_channels_to_obs_speakers(spec.channels); data->bytes_per_frame = pa_frame_size(&spec); data->stream = pulse_stream_new(obs_source_get_name(data->source), &spec, NULL); if (!data->stream) { blog(LOG_ERROR, "Unable to create stream"); return -1; } pulse_lock(); pa_stream_set_read_callback(data->stream, pulse_stream_read, (void *) data); pulse_unlock(); pa_buffer_attr attr; attr.fragsize = pa_usec_to_bytes(25000, &spec); attr.maxlength = (uint32_t) -1; attr.minreq = (uint32_t) -1; attr.prebuf = (uint32_t) -1; attr.tlength = (uint32_t) -1; pa_stream_flags_t flags = PA_STREAM_ADJUST_LATENCY; pulse_lock(); int_fast32_t ret = pa_stream_connect_record(data->stream, data->device, &attr, flags); pulse_unlock(); if (ret < 0) { pulse_stop_recording(data); blog(LOG_ERROR, "Unable to connect to stream"); return -1; } blog(LOG_INFO, "Started recording from '%s'", data->device); return 0; }
/** * Destroy the plugin object and free all memory */ static void pulse_destroy(void *vptr) { PULSE_DATA(vptr); if (!data) return; if (data->stream) pulse_stop_recording(data); pulse_unref(); if (data->device) bfree(data->device); bfree(data); }
/* * Destroy the plugin object and free all memory */ static void pulse_destroy(void *vptr) { PULSE_DATA(vptr); if (!data) return; pulse_stop_recording(data); pulse_unref(); if (data->device) bfree(data->device); bfree(data); blog(LOG_DEBUG, "pulse-input: Input destroyed"); }
/** * Update the input settings */ static void pulse_update(void *vptr, obs_data_t *settings) { PULSE_DATA(vptr); bool restart = false; const char *new_device; new_device = obs_data_get_string(settings, "device_id"); if (!data->device || strcmp(data->device, new_device) != 0) { if (data->device) bfree(data->device); data->device = bstrdup(new_device); restart = true; } if (!restart) return; if (data->stream) pulse_stop_recording(data); pulse_start_recording(data); }