Skip to content

Commit

Permalink
Improved encoder unpairing
Browse files Browse the repository at this point in the history
  • Loading branch information
avoitenko-logitech committed Dec 21, 2023
1 parent f8c275e commit e424386
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
13 changes: 0 additions & 13 deletions libobs/obs-encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -557,19 +557,6 @@ void obs_encoder_shutdown(obs_encoder_t *encoder)
obs_encoder_get_name(encoder), obs_encoder_get_id(encoder),
encoder);

// Unpairing encoders, if any
if (encoder->paired_encoder) {
pthread_mutex_lock(&encoder->paired_encoder->init_mutex);

blog(LOG_INFO, "obs_encoder_shutdown - unpair '%s' (%s) (%p)",
obs_encoder_get_name(encoder->paired_encoder),
obs_encoder_get_id(encoder->paired_encoder),
encoder->paired_encoder);

encoder->paired_encoder->paired_encoder = NULL;
pthread_mutex_unlock(&encoder->paired_encoder->init_mutex);
}

pthread_mutex_lock(&encoder->init_mutex);
if (encoder->context.data) {
encoder->info.destroy(encoder->context.data);
Expand Down
30 changes: 30 additions & 0 deletions libobs/obs-output.c
Original file line number Diff line number Diff line change
Expand Up @@ -2167,6 +2167,34 @@ static inline void pair_encoders(obs_output_t *output)
}
}

static inline void unpair_encoders(obs_output_t *output)
{
struct obs_encoder *video = output->video_encoder;
if (video) {
pthread_mutex_lock(&video->init_mutex);
blog(LOG_INFO, "unpair_encoders - video: '%s' (%s) (%p)",
obs_encoder_get_name(video), obs_encoder_get_id(video),
video);

struct obs_encoder *audio = video->paired_encoder;

if (audio) {
pthread_mutex_lock(&audio->init_mutex);
blog(LOG_INFO,
"unpair_encoders - audio: '%s' (%s) (%p)",
obs_encoder_get_name(audio),
obs_encoder_get_id(audio), audio);

audio->paired_encoder = NULL;
pthread_mutex_unlock(&audio->init_mutex);
}

video->paired_encoder = NULL;

pthread_mutex_unlock(&video->init_mutex);
}
}

bool obs_output_initialize_encoders(obs_output_t *output, uint32_t flags)
{
bool encoded, has_video, has_audio, has_service, force_encoder;
Expand Down Expand Up @@ -2339,6 +2367,8 @@ static void *end_data_capture_thread(void *data)
convert_flags(output, 0, &encoded, &has_video, &has_audio, &has_service,
&force_encoder);

unpair_encoders(output);

if (encoded) {
if (output->active_delay_ns)
encoded_callback = process_delay;
Expand Down

0 comments on commit e424386

Please sign in to comment.