Skip to content

Commit 4124cb5

Browse files
committed
remove callback on recsource destructor
1 parent d6c4c0d commit 4124cb5

File tree

2 files changed

+38
-32
lines changed

2 files changed

+38
-32
lines changed

src/device/gamepad.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ GamepadDevice::GamepadDevice() : m_should_poll(true)
137137
reported on the input-overlay repo: https://github.com/univrsal/input-overlay/issues/426
138138
The issue also occurs when using the obs input-overlay plugin only, without input-rec.
139139
*/
140-
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
140+
// std::this_thread::sleep_for(std::chrono::milliseconds(10000));
141141

142142
m_polling_thread = SDL_CreateThread(
143143
[](void *data) -> int {

src/obs_source.cpp

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,43 +14,49 @@ class RecSource {
1414
obs_data_t *m_settings;
1515
obs_source_t *m_source;
1616
std::unique_ptr<InputWriter> m_input_writer;
17+
obs_frontend_event_cb m_event_callback;
1718

1819
public:
1920
RecSource(obs_data_t *settings, obs_source_t *source)
2021
: m_settings{settings},
2122
m_source{source},
22-
m_input_writer{std::make_unique<ParquetWriter>(std::make_unique<GamepadDevice>())}
23+
m_input_writer{std::make_unique<CSVWriter>(std::make_unique<GamepadDevice>())}
2324
{
24-
obs_frontend_add_event_callback(
25-
[](enum obs_frontend_event event, void *private_data) {
26-
InputWriter *current_writer = static_cast<InputWriter *>(private_data);
27-
switch (event) {
28-
case OBS_FRONTEND_EVENT_RECORDING_STARTING: {
29-
obs_log(LOG_INFO, "OBS_FRONTEND_EVENT_RECORDING_STARTING received");
30-
current_writer->prepare_recording();
31-
break;
32-
}
33-
case OBS_FRONTEND_EVENT_RECORDING_STARTED: {
34-
obs_log(LOG_INFO, "OBS_FRONTEND_EVENT_RECORDING_STARTED received");
35-
current_writer->start_recording();
36-
break;
37-
}
38-
case OBS_FRONTEND_EVENT_RECORDING_STOPPING: {
39-
obs_log(LOG_INFO, "OBS_FRONTEND_EVENT_RECORDING_STOPPING received");
40-
current_writer->stop_recording();
41-
break;
42-
}
43-
case OBS_FRONTEND_EVENT_RECORDING_STOPPED: {
44-
obs_log(LOG_INFO, "OBS_FRONTEND_EVENT_RECORDING_STOPPED received");
45-
// Get last recording path
46-
std::string recording_path{obs_frontend_get_last_recording()};
47-
current_writer->close_recording(recording_path);
48-
break;
49-
}
50-
default: break;
51-
}
52-
},
53-
m_input_writer.get());
25+
26+
m_event_callback = [](enum obs_frontend_event event, void *private_data) {
27+
InputWriter *current_writer = static_cast<InputWriter *>(private_data);
28+
switch (event) {
29+
case OBS_FRONTEND_EVENT_RECORDING_STARTING: {
30+
obs_log(LOG_INFO, "OBS_FRONTEND_EVENT_RECORDING_STARTING received");
31+
current_writer->prepare_recording();
32+
break;
33+
}
34+
case OBS_FRONTEND_EVENT_RECORDING_STARTED: {
35+
obs_log(LOG_INFO, "OBS_FRONTEND_EVENT_RECORDING_STARTED received");
36+
current_writer->start_recording();
37+
break;
38+
}
39+
case OBS_FRONTEND_EVENT_RECORDING_STOPPING: {
40+
obs_log(LOG_INFO, "OBS_FRONTEND_EVENT_RECORDING_STOPPING received");
41+
current_writer->stop_recording();
42+
break;
43+
}
44+
case OBS_FRONTEND_EVENT_RECORDING_STOPPED: {
45+
obs_log(LOG_INFO, "OBS_FRONTEND_EVENT_RECORDING_STOPPED received");
46+
// Get last recording path
47+
std::string recording_path{obs_frontend_get_last_recording()};
48+
current_writer->close_recording(recording_path);
49+
break;
50+
}
51+
default: break;
52+
}
53+
};
54+
obs_frontend_add_event_callback(m_event_callback, m_input_writer.get());
55+
}
56+
57+
~RecSource()
58+
{
59+
obs_frontend_remove_event_callback(m_event_callback, m_input_writer.get());
5460
}
5561

5662
void tick(float seconds) { UNUSED_PARAMETER(seconds); }

0 commit comments

Comments
 (0)