diff mbox series

[FFmpeg-devel,06/15] lavc/codec_desc: add avcodec_descriptor_get_by_mime_type

Message ID 20200909060217.25794-6-rcombs@rcombs.me
State New
Headers show
Series [FFmpeg-devel,01/15] lavc/codec_desc: add MIME type to AV_CODEC_ID_TEXT
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Ridley Combs Sept. 9, 2020, 6:02 a.m. UTC
---
 libavcodec/codec_desc.c | 41 +++++++++++++++++++++++++++++++++++++++++
 libavcodec/codec_desc.h | 12 ++++++++++++
 libavcodec/version.h    |  2 +-
 3 files changed, 54 insertions(+), 1 deletion(-)
diff mbox series

Patch

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, \