[fix] fix crash when Stop() called in SpeakerCapturerLinux

This commit is contained in:
kunkundi
2025-07-15 15:38:58 +08:00
parent 8fe8f4fd7e
commit 78c54136e2
3 changed files with 234 additions and 159 deletions

View File

@@ -1,12 +1,18 @@
/*
* @Author: DI JUNKUN
* @Date: 2024-08-02
* Copyright (c) 2024 by DI JUNKUN, All Rights Reserved.
* @Date: 2025-07-15
* Copyright (c) 2025 by DI JUNKUN, All Rights Reserved.
*/
#ifndef _SPEAKER_CAPTURER_LINUX_H_
#define _SPEAKER_CAPTURER_LINUX_H_
#include <pulse/pulseaudio.h>
#include <atomic>
#include <functional>
#include <mutex>
#include <string>
#include <thread>
#include <vector>
@@ -17,22 +23,32 @@ class SpeakerCapturerLinux : public SpeakerCapturer {
SpeakerCapturerLinux();
~SpeakerCapturerLinux();
public:
virtual int Init(speaker_data_cb cb);
virtual int Destroy();
virtual int Start();
virtual int Stop();
int Init(speaker_data_cb cb) override;
int Destroy() override;
int Start() override;
int Stop() override;
int Pause();
int Resume();
private:
speaker_data_cb cb_ = nullptr;
std::string GetDefaultMonitorSourceName();
void Cleanup();
private:
bool inited_ = false;
// thread
std::thread capture_thread_;
speaker_data_cb cb_ = nullptr;
std::atomic<bool> inited_;
std::atomic<bool> paused_;
std::atomic<bool> stop_flag_;
std::thread mainloop_thread_;
pa_threaded_mainloop* mainloop_ = nullptr;
pa_context* context_ = nullptr;
pa_stream* stream_ = nullptr;
std::mutex state_mtx_;
std::vector<uint8_t> frame_cache_;
};
#endif