From 16237d589a9bddbe12018f3f5c1be55ce3d847e6 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 6 Aug 2022 09:56:39 +0200 Subject: Fix audio recording with pipewire and with different pulseaudio system settings (frag) --- src/sound.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/sound.cpp b/src/sound.cpp index 779aa87..d177c8e 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -19,6 +19,7 @@ #include #include +#include #ifdef PULSEAUDIO #include @@ -31,13 +32,18 @@ int sound_device_get_by_name(SoundDevice *device, const char *name, unsigned int ss.channels = num_channels; int error; - pa_simple *pa_handle = pa_simple_new(nullptr, "gpu-screen-recorder", PA_STREAM_RECORD, name, "record", &ss, nullptr, nullptr, &error); + pa_buffer_attr buffer_attr; + memset(&buffer_attr, -1, sizeof(buffer_attr)); + buffer_attr.maxlength = period_frame_size * 2 * num_channels; // 2 bytes/sample, @num_channels channels + buffer_attr.fragsize = buffer_attr.maxlength; + + pa_simple *pa_handle = pa_simple_new(nullptr, "gpu-screen-recorder", PA_STREAM_RECORD, name, "record", &ss, nullptr, &buffer_attr, &error); if(!pa_handle) { fprintf(stderr, "pa_simple_new() failed: %s. Audio input device %s might not be valid\n", pa_strerror(error), name); return -1; } - int buffer_size = period_frame_size * 2 * num_channels; // 2 bytes/sample, @num_channels channels + int buffer_size = buffer_attr.maxlength; void *buffer = malloc(buffer_size); if(!buffer) { fprintf(stderr, "failed to allocate buffer for audio\n"); -- cgit v1.2.3