From 4d002f588b6f98245ae050373bb9291832292eb9 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Fri, 17 Apr 2015 01:34:10 -0700 Subject: [PATCH] (API Change) Remove encoder callback boilerplate API Changed (in struct obs_encoder_info): ---------------------------------------- bool (*get_audio_info)(void *data, struct audio_convert_info *info); bool (*get_video_info)(void *data, struct video_scale_info *info); To: ---------------------------------------- void (*get_audio_info)(void *data, struct audio_convert_info *info); void (*get_video_info)(void *data, struct video_scale_info *info); The encoder video/audio information callbacks no longer need to manually query the libobs video/audio information, that information is now passed via the parameter, which the callbacks can modify. The refactor that reduces boilerplate in the encoder video/audio information callbacks also removes the need for their return values, so change the return types to void. --- libobs/obs-encoder.h | 16 ++++++--------- plugins/obs-ffmpeg/obs-ffmpeg-aac.c | 5 +---- plugins/obs-libfdk/obs-libfdk.c | 6 +----- plugins/obs-x264/obs-x264.c | 26 +++++++++++++------------ plugins/win-dshow/win-dshow-encoder.cpp | 17 ++++++---------- 5 files changed, 28 insertions(+), 42 deletions(-) diff --git a/libobs/obs-encoder.h b/libobs/obs-encoder.h index 3cbc11267..4d894170f 100644 --- a/libobs/obs-encoder.h +++ b/libobs/obs-encoder.h @@ -211,22 +211,18 @@ struct obs_encoder_info { /** * Returns desired audio format and sample information * - * @param data Data associated with this encoder context - * @param[out] info Audio format information - * @return true if specific format is desired, false - * otherwise + * @param data Data associated with this encoder context + * @param[in/out] info Audio format information */ - bool (*get_audio_info)(void *data, struct audio_convert_info *info); + void (*get_audio_info)(void *data, struct audio_convert_info *info); /** * Returns desired video format information * - * @param data Data associated with this encoder context - * @param[out] info Video format information - * @return true if specific format is desired, false - * otherwise + * @param data Data associated with this encoder context + * @param[in/out] info Video format information */ - bool (*get_video_info)(void *data, struct video_scale_info *info); + void (*get_video_info)(void *data, struct video_scale_info *info); }; EXPORT void obs_register_encoder_s(const struct obs_encoder_info *info, diff --git a/plugins/obs-ffmpeg/obs-ffmpeg-aac.c b/plugins/obs-ffmpeg/obs-ffmpeg-aac.c index 154181700..d53d1276d 100644 --- a/plugins/obs-ffmpeg/obs-ffmpeg-aac.c +++ b/plugins/obs-ffmpeg/obs-ffmpeg-aac.c @@ -277,13 +277,10 @@ static bool aac_extra_data(void *data, uint8_t **extra_data, size_t *size) return true; } -static bool aac_audio_info(void *data, struct audio_convert_info *info) +static void aac_audio_info(void *data, struct audio_convert_info *info) { struct aac_encoder *enc = data; - - memset(info, 0, sizeof(struct audio_convert_info)); info->format = convert_ffmpeg_sample_format(enc->context->sample_fmt); - return true; } static size_t aac_frame_size(void *data) diff --git a/plugins/obs-libfdk/obs-libfdk.c b/plugins/obs-libfdk/obs-libfdk.c index 4982155e5..752f43457 100644 --- a/plugins/obs-libfdk/obs-libfdk.c +++ b/plugins/obs-libfdk/obs-libfdk.c @@ -273,14 +273,10 @@ static bool libfdk_extra_data(void *data, uint8_t **extra_data, size_t *size) return true; } -static bool libfdk_audio_info(void *data, struct audio_convert_info *info) +static void libfdk_audio_info(void *data, struct audio_convert_info *info) { UNUSED_PARAMETER(data); - - memset(info, 0, sizeof(struct audio_convert_info)); info->format = AUDIO_FORMAT_16BIT; - - return true; } static size_t libfdk_frame_size(void *data) diff --git a/plugins/obs-x264/obs-x264.c b/plugins/obs-x264/obs-x264.c index 01564e964..d709d03a2 100644 --- a/plugins/obs-x264/obs-x264.c +++ b/plugins/obs-x264/obs-x264.c @@ -638,23 +638,25 @@ static bool obs_x264_sei(void *data, uint8_t **sei, size_t *size) return true; } -static bool obs_x264_video_info(void *data, struct video_scale_info *info) +static inline bool valid_format(enum video_format format) +{ + return format == VIDEO_FORMAT_I420 || + format == VIDEO_FORMAT_NV12; +} + +static void obs_x264_video_info(void *data, struct video_scale_info *info) { struct obs_x264 *obsx264 = data; - video_t *video = obs_encoder_video(obsx264->encoder); - const struct video_output_info *vid_info = video_output_get_info(video); + enum video_format pref_format; - if (vid_info->format == VIDEO_FORMAT_I420 || - vid_info->format == VIDEO_FORMAT_NV12) - return false; + pref_format = obs_encoder_get_preferred_video_format(obsx264->encoder); - info->format = VIDEO_FORMAT_NV12; - info->width = vid_info->width; - info->height = vid_info->height; - info->range = vid_info->range; - info->colorspace = vid_info->colorspace; + if (!valid_format(pref_format)) { + pref_format = valid_format(info->format) ? + info->format : VIDEO_FORMAT_NV12; + } - return true; + info->format = pref_format; } struct obs_encoder_info obs_x264_encoder = { diff --git a/plugins/win-dshow/win-dshow-encoder.cpp b/plugins/win-dshow/win-dshow-encoder.cpp index 13ba9c870..7a8cc0789 100644 --- a/plugins/win-dshow/win-dshow-encoder.cpp +++ b/plugins/win-dshow/win-dshow-encoder.cpp @@ -289,21 +289,18 @@ static inline bool ValidResolution(uint32_t width, uint32_t height) (width == 1024 && height == 768); } -static bool GetDShowVideoInfo(void *data, struct video_scale_info *info) +static void GetDShowVideoInfo(void *data, struct video_scale_info *info) { DShowEncoder *encoder = reinterpret_cast(data); - video_t *video = obs_encoder_video(encoder->context); - const struct video_output_info *vid_info = video_output_get_info(video); - encoder->format = VIDEO_FORMAT_I420; - if (vid_info->format == VIDEO_FORMAT_I420 && - ValidResolution(vid_info->width, vid_info->height)) - return false; + if (info->format == VIDEO_FORMAT_I420 && + ValidResolution(info->width, info->height)) + return; info->format = VIDEO_FORMAT_I420; - info->width = vid_info->width; - info->height = vid_info->height; + info->width = info->width; + info->height = info->height; info->range = VIDEO_RANGE_DEFAULT; info->colorspace = VIDEO_CS_DEFAULT; @@ -316,8 +313,6 @@ static bool GetDShowVideoInfo(void *data, struct video_scale_info *info) info->width = 1280; info->height = 720; } - - return true; } static void GetDShowEncoderDefauts(obs_data_t *settings)