--- libavcodec/codec_desc.c | 41 +++++++++++++++++++++++++++++++++++++++++ libavcodec/codec_desc.h | 12 ++++++++++++ libavcodec/version.h | 2 +- 3 files changed, 54 insertions(+), 1 deletion(-)
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c index ad044318c7..61b7f8d74f 100644 --- a/libavcodec/codec_desc.c +++ b/libavcodec/codec_desc.c @@ -21,6 +21,7 @@ #include <string.h> +#include "libavutil/avstring.h" #include "libavutil/common.h" #include "libavutil/internal.h" @@ -3480,6 +3481,46 @@ const AVCodecDescriptor *avcodec_descriptor_get_by_name(const char *name) return NULL; } +const AVCodecDescriptor *avcodec_descriptor_get_by_mime_type(const char *search, const char *prefix) +{ + const AVCodecDescriptor *desc = NULL; + int len, prefix_len; + if (!search) + return NULL; + + len = strlen(search); + if (!len) + return NULL; + + if (strchr(search, '/')) + prefix = NULL; + + if (prefix) + prefix_len = strlen(prefix); + + while ((desc = avcodec_descriptor_next(desc))) { + if (desc->mime_types) { + int i; + for (i = 0; desc->mime_types[i]; i++) { + const char *check = desc->mime_types[i]; + if (prefix) { + if (!av_strncasecmp(check, prefix, prefix_len) && + check[prefix_len] == '/') + check += prefix_len + 1; + else + continue; + } + + if (!av_strncasecmp(check, search, len) && + (check[len] == 0 || check[len] == '+' || check[len] == ';')) + return desc; + } + } + } + + return NULL; +} + enum AVMediaType avcodec_get_type(enum AVCodecID codec_id) { const AVCodecDescriptor *desc = avcodec_descriptor_get(codec_id); diff --git a/libavcodec/codec_desc.h b/libavcodec/codec_desc.h index 126b52df47..da38784a49 100644 --- a/libavcodec/codec_desc.h +++ b/libavcodec/codec_desc.h @@ -121,6 +121,18 @@ const AVCodecDescriptor *avcodec_descriptor_next(const AVCodecDescriptor *prev); */ const AVCodecDescriptor *avcodec_descriptor_get_by_name(const char *name); +/** + * Locate a codec descriptor with a particular MIME type + * + * @param search the MIME type to search for. + * @param prefix a prefix to use if the search type does not contain a media type. + * NULL if no default prefix should be used. + * + * @return codec descriptor with the given MIME type or NULL if no such + * descriptor exists. + */ +const AVCodecDescriptor *avcodec_descriptor_get_by_mime_type(const char *search, const char *prefix); + /** * @} */ diff --git a/libavcodec/version.h b/libavcodec/version.h index 4b221f96ad..5ce4ba55d9 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -28,7 +28,7 @@ #include "libavutil/version.h" #define LIBAVCODEC_VERSION_MAJOR 58 -#define LIBAVCODEC_VERSION_MINOR 105 +#define LIBAVCODEC_VERSION_MINOR 106 #define LIBAVCODEC_VERSION_MICRO 100 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ -- 2.27.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".