Skip to content

Commit

Permalink
UI: Remove multitrack deactivate handlers
Browse files Browse the repository at this point in the history
With the encoder reference counting fixups this is no longer required.
  • Loading branch information
dsaedtler committed Oct 30, 2024
1 parent 7c523c4 commit 4f07df8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 50 deletions.
52 changes: 9 additions & 43 deletions UI/multitrack-video-output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ static OBSOutputs SetupOBSOutput(QWidget *parent, const QString &multitrack_vide
const char *audio_encoder_id, size_t main_audio_mixer,
std::optional<size_t> vod_track_mixer);
static void SetupSignalHandlers(bool recording, MultitrackVideoOutput *self, obs_output_t *output, OBSSignal &start,
OBSSignal &stop, OBSSignal &deactivate);
OBSSignal &stop);

void MultitrackVideoOutput::PrepareStreaming(
QWidget *parent, const char *service_name, obs_service_t *service, const std::optional<std::string> &rtmp_url,
Expand Down Expand Up @@ -408,15 +408,12 @@ void MultitrackVideoOutput::PrepareStreaming(

OBSSignal start_streaming;
OBSSignal stop_streaming;
OBSSignal deactivate_stream;
SetupSignalHandlers(false, this, output, start_streaming, stop_streaming, deactivate_stream);
SetupSignalHandlers(false, this, output, start_streaming, stop_streaming);

if (dump_stream_to_file_config && recording_output) {
OBSSignal start_recording;
OBSSignal stop_recording;
OBSSignal deactivate_recording;
SetupSignalHandlers(true, this, recording_output, start_recording, stop_recording,
deactivate_recording);
SetupSignalHandlers(true, this, recording_output, start_recording, stop_recording);

decltype(audio_encoders) recording_audio_encoders;
recording_audio_encoders.reserve(audio_encoders.size());
Expand All @@ -433,7 +430,6 @@ void MultitrackVideoOutput::PrepareStreaming(
nullptr,
std::move(start_recording),
std::move(stop_recording),
std::move(deactivate_recording),
});
}
}
Expand All @@ -446,7 +442,6 @@ void MultitrackVideoOutput::PrepareStreaming(
std::move(multitrack_video_service),
std::move(start_streaming),
std::move(stop_streaming),
std::move(deactivate_stream),
});
}

Expand Down Expand Up @@ -780,17 +775,14 @@ static OBSOutputs SetupOBSOutput(QWidget *parent, const QString &multitrack_vide
}

void SetupSignalHandlers(bool recording, MultitrackVideoOutput *self, obs_output_t *output, OBSSignal &start,
OBSSignal &stop, OBSSignal &deactivate)
OBSSignal &stop)
{
auto handler = obs_output_get_signal_handler(output);

if (recording)
start.Connect(handler, "start", RecordingStartHandler, self);

stop.Connect(handler, "stop", !recording ? StreamStopHandler : RecordingStopHandler, self);

deactivate.Connect(handler, "deactivate", !recording ? StreamDeactivateHandler : RecordingDeactivateHandler,
self);
}

std::optional<MultitrackVideoOutput::OBSOutputObjects> MultitrackVideoOutput::take_current()
Expand Down Expand Up @@ -819,7 +811,7 @@ void MultitrackVideoOutput::ReleaseOnMainThread(std::optional<OBSOutputObjects>
QApplication::instance()->thread(), [objects = std::move(objects)] {}, Qt::QueuedConnection);
}

void StreamStopHandler(void *arg, calldata_t *params)
void StreamStopHandler(void *arg, calldata_t *data)
{
auto self = static_cast<MultitrackVideoOutput *>(arg);

Expand All @@ -832,25 +824,9 @@ void StreamStopHandler(void *arg, calldata_t *params)
if (stream_dump_output)
obs_output_stop(stream_dump_output);

if (obs_output_active(static_cast<obs_output_t *>(calldata_ptr(params, "output"))))
return;

MultitrackVideoOutput::ReleaseOnMainThread(self->take_current());
}

void StreamDeactivateHandler(void *arg, calldata_t *params)
{
auto self = static_cast<MultitrackVideoOutput *>(arg);

if (obs_output_reconnecting(static_cast<obs_output_t *>(calldata_ptr(params, "output"))))
return;

/* Unregister the BPM (Broadcast Performance Metrics) callback
* and destroy the allocated metrics data.
*/
obs_output_remove_packet_callback(static_cast<obs_output_t *>(calldata_ptr(params, "output")), bpm_inject,
NULL);
bpm_destroy(static_cast<obs_output_t *>(calldata_ptr(params, "output")));
/* Unregister the BPM (Broadcast Performance Metrics) callback and destroy the allocated metrics data. */
obs_output_remove_packet_callback(static_cast<obs_output_t *>(calldata_ptr(data, "output")), bpm_inject, NULL);
bpm_destroy(static_cast<obs_output_t *>(calldata_ptr(data, "output")));

MultitrackVideoOutput::ReleaseOnMainThread(self->take_current());
}
Expand All @@ -860,19 +836,9 @@ void RecordingStartHandler(void * /* arg */, calldata_t * /* data */)
blog(LOG_INFO, "MultitrackVideoOutput: recording started");
}

void RecordingStopHandler(void *arg, calldata_t *params)
void RecordingStopHandler(void *arg, calldata_t *)
{
auto self = static_cast<MultitrackVideoOutput *>(arg);
blog(LOG_INFO, "MultitrackVideoOutput: recording stopped");

if (obs_output_active(static_cast<obs_output_t *>(calldata_ptr(params, "output"))))
return;

MultitrackVideoOutput::ReleaseOnMainThread(self->take_current_stream_dump());
}

void RecordingDeactivateHandler(void *arg, calldata_t * /*data*/)
{
auto self = static_cast<MultitrackVideoOutput *>(arg);
MultitrackVideoOutput::ReleaseOnMainThread(self->take_current_stream_dump());
}
10 changes: 3 additions & 7 deletions UI/multitrack-video-output.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@
class QString;

void StreamStopHandler(void *arg, calldata_t *data);
void StreamDeactivateHandler(void *arg, calldata_t *data);

void RecordingStartHandler(void *arg, calldata_t *data);
void RecordingStopHandler(void *arg, calldata_t *data);
void RecordingDeactivateHandler(void *arg, calldata_t *data);
void RecordingStopHandler(void *arg, calldata_t *);

bool MultitrackVideoDeveloperModeEnabled();

Expand Down Expand Up @@ -49,7 +47,7 @@ struct MultitrackVideoOutput {
std::shared_ptr<obs_encoder_group_t> video_encoder_group_;
std::vector<OBSEncoderAutoRelease> audio_encoders_;
OBSServiceAutoRelease multitrack_video_service_;
OBSSignal start_signal, stop_signal, deactivate_signal;
OBSSignal start_signal, stop_signal;
};

std::optional<OBSOutputObjects> take_current();
Expand All @@ -64,8 +62,6 @@ struct MultitrackVideoOutput {
std::optional<OBSOutputObjects> current_stream_dump;

friend void StreamStopHandler(void *arg, calldata_t *data);
friend void StreamDeactivateHandler(void *arg, calldata_t *data);
friend void RecordingStartHandler(void *arg, calldata_t *data);
friend void RecordingStopHandler(void *arg, calldata_t *data);
friend void RecordingDeactivateHandler(void *arg, calldata_t *data);
friend void RecordingStopHandler(void *arg, calldata_t *);
};

0 comments on commit 4f07df8

Please sign in to comment.