[FFmpeg-devel] [PATCH] lavu: add av_get_media_type_string() convenience function

Stefano Sabatini stefano.sabatini-lala at poste.it
Thu Aug 18 16:43:40 CEST 2011


Avoid dumb code duplication.
---
 libavutil/avutil.h |    6 ++++++
 libavutil/utils.c  |   12 ++++++++++++
 2 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/libavutil/avutil.h b/libavutil/avutil.h
index fc437dd..ac5f1d8 100644
--- a/libavutil/avutil.h
+++ b/libavutil/avutil.h
@@ -95,6 +95,12 @@ enum AVMediaType {
     AVMEDIA_TYPE_NB
 };
 
+/**
+ * Return a string describing the media_type enum, NULL if media_type
+ * is unknown.
+ */
+const char *av_get_media_type_string(enum AVMediaType media_type);
+
 #define FF_LAMBDA_SHIFT 7
 #define FF_LAMBDA_SCALE (1<<FF_LAMBDA_SHIFT)
 #define FF_QP2LAMBDA 118 ///< factor to convert from H.263 QP to lambda
diff --git a/libavutil/utils.c b/libavutil/utils.c
index c77a060..e6c8424 100644
--- a/libavutil/utils.c
+++ b/libavutil/utils.c
@@ -40,6 +40,18 @@ const char *avutil_license(void)
     return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1;
 }
 
+const char *av_get_media_type_string(enum AVMediaType media_type)
+{
+    switch (media_type) {
+    case AVMEDIA_TYPE_VIDEO:      return "video";
+    case AVMEDIA_TYPE_AUDIO:      return "audio";
+    case AVMEDIA_TYPE_DATA:       return "data";
+    case AVMEDIA_TYPE_SUBTITLE:   return "subtitle";
+    case AVMEDIA_TYPE_ATTACHMENT: return "attachment";
+    default:                      return NULL;
+    }
+}
+
 char av_get_picture_type_char(enum AVPictureType pict_type)
 {
     switch (pict_type) {
-- 
1.7.2.5



More information about the ffmpeg-devel mailing list