Add module: speaker capture

This commit is contained in:
dijunkun
2024-07-24 16:16:13 +08:00
parent f446154747
commit a99a4230af
12 changed files with 789 additions and 20 deletions

View File

@@ -108,6 +108,36 @@ int Render::StopScreenCapture() {
return 0;
}
int Render::StartSpeakerCapture() {
speaker_capturer_ = (SpeakerCapturer *)speaker_capturer_factory_->Create();
int speaker_capturer_init_ret =
speaker_capturer_->Init([this](unsigned char *data, size_t size) -> void {
SendData(peer_, DATA_TYPE::AUDIO, (const char *)data, size);
});
if (0 == speaker_capturer_init_ret) {
speaker_capturer_->Start();
} else {
speaker_capturer_->Destroy();
delete speaker_capturer_;
speaker_capturer_ = nullptr;
}
return 0;
}
int Render::StopSpeakerCapture() {
if (speaker_capturer_) {
LOG_INFO("Destroy speaker capturer")
speaker_capturer_->Destroy();
delete speaker_capturer_;
speaker_capturer_ = nullptr;
}
return 0;
}
int Render::StartMouseControl() {
device_controller_factory_ = new DeviceControllerFactory();
mouse_controller_ = (MouseController *)device_controller_factory_->Create(
@@ -239,10 +269,10 @@ int Render::Run() {
want_out.channels = 1;
// want_out.silence = 0;
want_out.samples = 480;
want_out.callback = SdlCaptureAudioOut;
want_out.callback = nullptr;
want_out.userdata = this;
output_dev_ = SDL_OpenAudioDevice(NULL, 0, &want_out, &have_out, 0);
output_dev_ = SDL_OpenAudioDevice(nullptr, 0, &want_out, NULL, 0);
if (output_dev_ == 0) {
SDL_Log("Failed to open input: %s", SDL_GetError());
// return 1;
@@ -301,10 +331,15 @@ int Render::Run() {
// Screen capture
screen_capturer_factory_ = new ScreenCapturerFactory();
// Speaker capture
// speaker_capturer_factory_ = new SpeakerCapturerFactory();
// Mouse control
device_controller_factory_ = new DeviceControllerFactory();
}
// StartSpeakerCapture();
// Main loop
while (!exit_) {
if (SignalStatus::SignalConnected == signal_status_ &&

View File

@@ -20,6 +20,7 @@
#include "imgui_impl_sdl2.h"
#include "imgui_impl_sdlrenderer2.h"
#include "screen_capturer_factory.h"
#include "speaker_capturer_factory.h"
class Render {
public:
@@ -72,6 +73,9 @@ class Render {
int StartScreenCapture();
int StopScreenCapture();
int StartSpeakerCapture();
int StopSpeakerCapture();
int StartMouseControl();
int StopMouseControl();
@@ -213,6 +217,8 @@ class Render {
private:
ScreenCapturerFactory *screen_capturer_factory_ = nullptr;
ScreenCapturer *screen_capturer_ = nullptr;
SpeakerCapturerFactory *speaker_capturer_factory_ = nullptr;
SpeakerCapturer *speaker_capturer_ = nullptr;
DeviceControllerFactory *device_controller_factory_ = nullptr;
MouseController *mouse_controller_ = nullptr;

View File

@@ -78,24 +78,24 @@ int Render::ProcessMouseKeyEven(SDL_Event &ev) {
}
void Render::SdlCaptureAudioIn(void *userdata, Uint8 *stream, int len) {
// Render *render = (Render *)userdata;
// if (1) {
// if ("Connected" == render->connection_status_str_) {
// SendData(render->peer_, DATA_TYPE::AUDIO, (const char *)stream, len);
// }
// } else {
// memcpy(render->audio_buffer_, stream, len);
// render->audio_len_ = len;
// SDL_Delay(10);
// render->audio_buffer_fresh_ = true;
// }
Render *render = (Render *)userdata;
if (1) {
if ("Connected" == render->connection_status_str_) {
SendData(render->peer_, DATA_TYPE::AUDIO, (const char *)stream, len);
}
} else {
memcpy(render->audio_buffer_, stream, len);
render->audio_len_ = len;
SDL_Delay(10);
render->audio_buffer_fresh_ = true;
}
}
void Render::SdlCaptureAudioOut(void *userdata, Uint8 *stream, int len) {
Render *render = (Render *)userdata;
if ("Connected" == render->connection_status_str_) {
SendData(render->peer_, DATA_TYPE::AUDIO, (const char *)stream, len);
}
// Render *render = (Render *)userdata;
// if ("Connected" == render->connection_status_str_) {
// SendData(render->peer_, DATA_TYPE::AUDIO, (const char *)stream, len);
// }
// if (!render->audio_buffer_fresh_) {
// return;