(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.
This commit is contained in:
parent
5c91d93d87
commit
4d002f588b
@ -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,
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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 = {
|
||||
|
@ -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<DShowEncoder*>(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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user