Files
obs-studio/frontend/utility/MultitrackVideoOutput.hpp
PatTheMav f61619ce30 frontend: Fix multitrack custom config handling
Custom configuration for multitrack-enabled services is only supposed
to be available for the "rtmp_custom" service type, as that's also
the condition for the corresponding text input to become visible in the
settings dialog.

When a user switches their desired service from the custom service back
to another service that also supports multitrack, the custom service
configuration is still present and will be applied even though it
should only be effective for the custom service.

This change makes the simple decision to ignore any available custom
multitrack configuration if the service is not "rtmp_custom" and
requires an "auto_config_url" to be available in that case. Otherwise
the "rtmp_custom" service requires an "custom_config" to be available.

That way the implementation reflects the behavior of the settings dialog
and will not lead to the present unexpected behavior, including:

* The custom configuration is "merged" with the config ID provided
  via the "auto_config_url".
* A non-custom service might fail to configure because the custom config
  is applied and might be missing required fields.
* A non-custom service might succeed to configure because the custom
  config is applied and has all required fields, but the service was
  meant for an entirely different service.

Additionally the unused "MultitrackVideoDeveloperModeEnabled" function
was removed. For simplicity's sake, all legacy code paths that allowed
interference or custom overrides with the service configuration for
established services are removed.

If such functionality is still desired, it needs to be reimplemented in
a service-agnostic way, taking the possibility of other multitrack-
capable services into account.
2026-06-05 16:43:12 -04:00

71 lines
2.3 KiB
C++

#pragma once
#include <obs.hpp>
#include <util/config-file.h>
#include <memory>
#include <mutex>
#include <optional>
#include <string>
#include <vector>
class QString;
class QWidget;
void StreamStartHandler(void *arg, calldata_t *);
void StreamStopHandler(void *arg, calldata_t *data);
void RecordingStartHandler(void *arg, calldata_t *data);
void RecordingStopHandler(void *arg, calldata_t *);
struct MultitrackVideoOutput {
public:
void PrepareStreaming(QWidget *parent, const char *service_name, obs_service_t *service,
const std::optional<std::string> &rtmp_url, const QString &stream_key,
const char *audio_encoder_id, std::optional<uint32_t> maximum_aggregate_bitrate,
std::optional<uint32_t> maximum_video_tracks, std::optional<std::string> custom_config,
obs_data_t *dump_stream_to_file_config, size_t main_audio_mixer,
std::optional<size_t> vod_track_mixer, std::optional<bool> use_rtmps,
std::optional<QString> extra_canvas);
signal_handler_t *StreamingSignalHandler();
void StartedStreaming();
void StopStreaming();
OBSOutputAutoRelease StreamingOutput()
{
const std::lock_guard current_lock{current_mutex};
return current ? obs_output_get_ref(current->output_) : nullptr;
}
bool RestartOnError() { return restart_on_error; }
private:
struct OBSOutputObjects {
OBSOutputAutoRelease output_;
std::shared_ptr<obs_encoder_group_t> video_encoder_group_;
std::vector<OBSEncoderAutoRelease> audio_encoders_;
OBSServiceAutoRelease multitrack_video_service_;
OBSSignal start_signal, stop_signal;
std::vector<OBSCanvasAutoRelease> canvases;
};
std::optional<OBSOutputObjects> take_current();
std::optional<OBSOutputObjects> take_current_stream_dump();
static void ReleaseOnMainThread(std::optional<OBSOutputObjects> objects);
std::mutex current_mutex;
std::optional<OBSOutputObjects> current;
std::mutex current_stream_dump_mutex;
std::optional<OBSOutputObjects> current_stream_dump;
bool restart_on_error = false;
uint8_t reconnect_attempts = 0;
friend void StreamStartHandler(void *arg, calldata_t *data);
friend void StreamStopHandler(void *arg, calldata_t *data);
friend void RecordingStartHandler(void *arg, calldata_t *data);
friend void RecordingStopHandler(void *arg, calldata_t *);
};