[FFmpeg-devel] [PATCH v3 1/2] libavutil: create av_media_type_get_string()
Scott Theisen
scott.the.elm at gmail.com
Sun Feb 13 23:52:29 EET 2022
This deprecates av_get_media_type_string() which does return NULL.
printf %s with a null pointer is undefined behavior
This also matches behavior with avcodec_get_name() which never returns NULL,
instead it returns "unknown_codec".
---
doc/APIchanges | 3 +++
libavutil/avutil.h | 7 +++++++
libavutil/utils.c | 13 +++++++++++++
3 files changed, 23 insertions(+)
diff --git a/doc/APIchanges b/doc/APIchanges
index ea402f6118..7733de8dea 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -14,6 +14,9 @@ libavutil: 2021-04-27
API changes, most recent first:
+2022-02-XX - xxxxxxxxxxx - lavu 57.19.100 - avutil.h
+ Add av_media_type_get_string() which deprecates av_get_media_type_string().
+
2022-02-07 - xxxxxxxxxx - lavu 57.21.100 - fifo.h
Deprecate AVFifoBuffer and the API around it, namely av_fifo_alloc(),
av_fifo_alloc_array(), av_fifo_free(), av_fifo_freep(), av_fifo_reset(),
diff --git a/libavutil/avutil.h b/libavutil/avutil.h
index 4d633156d1..6cabeb405a 100644
--- a/libavutil/avutil.h
+++ b/libavutil/avutil.h
@@ -209,9 +209,16 @@ enum AVMediaType {
/**
* Return a string describing the media_type enum, NULL if media_type
* is unknown.
+ *
+ * @deprecated Use av_media_type_get_string() instead.
*/
const char *av_get_media_type_string(enum AVMediaType media_type);
+/**
+ * Return a string describing the media_type enum, never NULL.
+ */
+const char *av_media_type_get_string(enum AVMediaType media_type);
+
/**
* @defgroup lavu_const Constants
* @{
diff --git a/libavutil/utils.c b/libavutil/utils.c
index ea9b5097b8..92d242f678 100644
--- a/libavutil/utils.c
+++ b/libavutil/utils.c
@@ -80,6 +80,19 @@ const char *av_get_media_type_string(enum AVMediaType media_type)
}
}
+const char *av_media_type_get_string(enum AVMediaType media_type)
+{
+ switch (media_type) {
+ case AVMEDIA_TYPE_UNKNOWN: return "unknown";
+ 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 "invalid_media_type";
+ }
+}
+
char av_get_picture_type_char(enum AVPictureType pict_type)
{
switch (pict_type) {
--
2.32.0
More information about the ffmpeg-devel
mailing list