Hopefully improved pa_stream_unref issues

Signed-off-by: Alexis Maiquez <almamu@almamu.com>
This commit is contained in:
Alexis Maiquez 2023-03-29 22:10:10 +02:00
parent b70264e54a
commit bf47510d0d

View File

@ -92,10 +92,18 @@ namespace WallpaperEngine::Audio::Drivers::Recorders
spec.channels = 1;
if (recorder->getCaptureStream ())
{
pa_stream_unref (recorder->getCaptureStream ());
// get rid of the reference just in case
recorder->setCaptureStream (nullptr);
}
pa_stream* captureStream = pa_stream_new(ctx, "output monitor", &spec, nullptr);
// store the stream first, if the record start fails there'll still be a reference to it
// so it can be free'd later
recorder->setCaptureStream (captureStream),
pa_stream_set_state_callback(captureStream, &pa_stream_notify_cb, userdata);
pa_stream_set_read_callback(captureStream, &pa_stream_read_cb, userdata);
@ -105,8 +113,6 @@ namespace WallpaperEngine::Audio::Drivers::Recorders
sLog.error ("Failed to connect to input for recording");
return;
}
recorder->setCaptureStream (captureStream);
}
void pa_context_subscribe_cb (pa_context *ctx, pa_subscription_event_type_t t, uint32_t idx, void *userdata)
@ -143,7 +149,8 @@ namespace WallpaperEngine::Audio::Drivers::Recorders
}
}
CPulseAudioPlaybackRecorder::CPulseAudioPlaybackRecorder ()
CPulseAudioPlaybackRecorder::CPulseAudioPlaybackRecorder () :
m_captureStream (nullptr)
{
this->m_mainloop = pa_mainloop_new ();
this->m_mainloopApi = pa_mainloop_get_api (this->m_mainloop);