libobs: Add support functions for encoder error handling

Similar to how outputs can pass errors, add the same functionality for
encoders so that if an output encoder has an error, it is made available
to the output and eventually the UI / user.
master
Richard Stanway 2019-10-09 18:27:09 +02:00 committed by Richard Stanway
parent c5125e0a17
commit 5dc9f989d6
4 changed files with 37 additions and 1 deletions

View File

@ -276,6 +276,8 @@ static void obs_encoder_actually_destroy(obs_encoder_t *encoder)
obs_context_data_free(&encoder->context);
if (encoder->owns_info_id)
bfree((void *)encoder->info.id);
if (encoder->last_error_message)
bfree(encoder->last_error_message);
bfree(encoder);
}
}
@ -1484,3 +1486,25 @@ bool obs_encoder_paused(const obs_encoder_t *encoder)
? os_atomic_load_bool(&encoder->paused)
: false;
}
const char *obs_encoder_get_last_error(obs_encoder_t *encoder)
{
if (!obs_encoder_valid(encoder, "obs_encoder_get_last_error"))
return NULL;
return encoder->last_error_message;
}
void obs_encoder_set_last_error(obs_encoder_t *encoder, const char *message)
{
if (!obs_encoder_valid(encoder, "obs_encoder_set_last_error"))
return;
if (encoder->last_error_message)
bfree(encoder->last_error_message);
if (message)
encoder->last_error_message = bstrdup(message);
else
encoder->last_error_message = NULL;
}

View File

@ -1076,6 +1076,7 @@ struct obs_encoder {
struct pause_data pause;
const char *profile_encoder_encode_name;
char *last_error_message;
};
extern struct obs_encoder_info *find_encoder(const char *id);

View File

@ -1979,6 +1979,9 @@ static inline bool initialize_audio_encoders(obs_output_t *output,
{
for (size_t i = 0; i < num_mixes; i++) {
if (!obs_encoder_initialize(output->audio_encoders[i])) {
obs_output_set_last_error(
output, obs_encoder_get_last_error(
output->audio_encoders[i]));
return false;
}
}
@ -2038,8 +2041,12 @@ bool obs_output_initialize_encoders(obs_output_t *output, uint32_t flags)
if (!encoded)
return false;
if (has_video && !obs_encoder_initialize(output->video_encoder))
if (has_video && !obs_encoder_initialize(output->video_encoder)) {
obs_output_set_last_error(
output,
obs_encoder_get_last_error(output->video_encoder));
return false;
}
if (has_audio && !initialize_audio_encoders(output, num_mixes))
return false;

View File

@ -2102,6 +2102,10 @@ EXPORT void *obs_encoder_create_rerouted(obs_encoder_t *encoder,
/** Returns whether encoder is paused */
EXPORT bool obs_encoder_paused(const obs_encoder_t *output);
EXPORT const char *obs_encoder_get_last_error(obs_encoder_t *encoder);
EXPORT void obs_encoder_set_last_error(obs_encoder_t *encoder,
const char *message);
/* ------------------------------------------------------------------------- */
/* Stream Services */