diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 1cab5c5950..77d5e2290c 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -4675,7 +4675,13 @@ enum AVPixelFormat avcodec_default_get_format(struct AVCodecContext *s, const en * @} */ +#if FF_API_SET_DIMENSIONS +/** + * @deprecated this function is not supposed to be used from outside of lavc + */ +attribute_deprecated void avcodec_set_dimensions(AVCodecContext *s, int width, int height); +#endif /** * Put a string representing the codec tag codec_tag in buf. diff --git a/libavcodec/internal.h b/libavcodec/internal.h index 96976e1ae9..bfeb0962fd 100644 --- a/libavcodec/internal.h +++ b/libavcodec/internal.h @@ -225,4 +225,10 @@ const uint8_t *avpriv_find_start_code(const uint8_t *p, const uint8_t *end, uint32_t *state); +/** + * Check that the provided frame dimensions are valid and set them on the codec + * context. + */ +int ff_set_dimensions(AVCodecContext *s, int width, int height); + #endif /* AVCODEC_INTERNAL_H */ diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 7ea0084dc8..e45ea5b25f 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -230,12 +230,26 @@ unsigned avcodec_get_edge_width(void) return EDGE_WIDTH; } +#if FF_API_SET_DIMENSIONS void avcodec_set_dimensions(AVCodecContext *s, int width, int height) { + ff_set_dimensions(s, width, height); +} +#endif + +int ff_set_dimensions(AVCodecContext *s, int width, int height) +{ + int ret = av_image_check_size(width, height, 0, s); + + if (ret < 0) + width = height = 0; + s->coded_width = width; s->coded_height = height; s->width = FF_CEIL_RSHIFT(width, s->lowres); s->height = FF_CEIL_RSHIFT(height, s->lowres); + + return ret; } #if HAVE_NEON || ARCH_PPC || HAVE_MMX diff --git a/libavcodec/version.h b/libavcodec/version.h index 073c8dc8c6..96852e2e41 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -100,5 +100,8 @@ #ifndef FF_API_VOXWARE #define FF_API_VOXWARE (LIBAVCODEC_VERSION_MAJOR < 56) #endif +#ifndef FF_API_SET_DIMENSIONS +#define FF_API_SET_DIMENSIONS (LIBAVCODEC_VERSION_MAJOR < 56) +#endif #endif /* AVCODEC_VERSION_H */