diff options
author | dec05eba <dec05eba@protonmail.com> | 2022-08-06 09:56:39 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2022-08-06 09:56:39 +0200 |
commit | 16237d589a9bddbe12018f3f5c1be55ce3d847e6 (patch) | |
tree | d3b6985c90bcdaccd39afda0c91a3011a1a09da2 /src/sound.cpp | |
parent | a10a96e0326859d5611332d7e82d8d398fcafaea (diff) |
Fix audio recording with pipewire and with different pulseaudio system settings (frag)
Diffstat (limited to 'src/sound.cpp')
-rw-r--r-- | src/sound.cpp | 10 |
1 files 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 <stdlib.h> #include <stdio.h> +#include <string.h> #ifdef PULSEAUDIO #include <pulse/simple.h> @@ -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"); |