History

lavf: add public functions converting dispositions to/from strings

Anton Khirnov committed 5 years ago

Commit b731fb51 parent ed75a083 files · +62 −0Browse files

Unified · Split

3 files
  1. doc/APIchanges +1 −0
  2. libavformat/avformat.h +14 −0
  3. libavformat/utils.c +47 −0
doc/APIchanges+1−0
@@ -17,6 +17,7 @@ API changes, most recent first: · 16 unmodified lines
1717 2021-11-xx - xxxxxxxxxx - lavf 59.9.100 - avformat.h
1818 Add av_stream_get_class(). Schedule adding AVStream.av_class at libavformat
1919 major version 60.
20+ Add av_disposition_to_string() and av_disposition_from_string().
2021
2122 2021-11-12 - xxxxxxxxxx - lavu 57.8.100 - hwcontext_vulkan.h
2223 Added AVFrame.sem_value, AVVulkanDeviceContext.queue_family_encode_index,
libavformat/avformat.h+14−0
@@ -894,6 +894,20 @@ typedef struct AVIndexEntry { · 893 unmodified lines
894894 */
895895 #define AV_DISPOSITION_STILL_IMAGE (1 << 20)
896896
897+/**
898+ * @return The AV_DISPOSITION_* flag corresponding to disp or a negative error
899+ * code if disp does not correspond to a known stream disposition.
900+ */
901+int av_disposition_from_string(const char *disp);
902+
903+/**
904+ * @param disposition a combination of AV_DISPOSITION_* values
905+ * @return The string description corresponding to the lowest set bit in
906+ * disposition. NULL when the lowest set bit does not correspond
907+ * to a known disposition or when disposition is 0.
908+ */
909+const char *av_disposition_to_string(int disposition);
910+
897911 /**
898912 * Options for behavior on timestamp wrap detection.
899913 */
libavformat/utils.c+47−0
@@ -28,6 +28,7 @@ · 27 unmodified lines
2828 #include "libavutil/bprint.h"
2929 #include "libavutil/dict.h"
3030 #include "libavutil/internal.h"
31+#include "libavutil/intmath.h"
3132 #include "libavutil/opt.h"
3233 #include "libavutil/parseutils.h"
3334 #include "libavutil/pixfmt.h"
@@ -1965,3 +1966,49 @@ void ff_format_set_url(AVFormatContext *s, char *url) · 1931 unmodified lines
19651966 av_freep(&s->url);
19661967 s->url = url;
19671968 }
1969+
1970+static const struct {
1971+ const char *str;
1972+ int disposition;
1973+} dispositions[] = {
1974+ { "default", AV_DISPOSITION_DEFAULT },
1975+ { "dub", AV_DISPOSITION_DUB },
1976+ { "original", AV_DISPOSITION_ORIGINAL },
1977+ { "comment", AV_DISPOSITION_COMMENT },
1978+ { "lyrics", AV_DISPOSITION_LYRICS },
1979+ { "karaoke", AV_DISPOSITION_KARAOKE },
1980+ { "forced", AV_DISPOSITION_FORCED },
1981+ { "hearing_impaired", AV_DISPOSITION_HEARING_IMPAIRED },
1982+ { "visual_impaired", AV_DISPOSITION_VISUAL_IMPAIRED },
1983+ { "clean_effects", AV_DISPOSITION_CLEAN_EFFECTS },
1984+ { "attached_pic", AV_DISPOSITION_ATTACHED_PIC },
1985+ { "timed_thumbnails", AV_DISPOSITION_TIMED_THUMBNAILS },
1986+ { "captions", AV_DISPOSITION_CAPTIONS },
1987+ { "descriptions", AV_DISPOSITION_DESCRIPTIONS },
1988+ { "metadata", AV_DISPOSITION_METADATA },
1989+ { "dependent", AV_DISPOSITION_DEPENDENT },
1990+ { "still_image", AV_DISPOSITION_STILL_IMAGE },
1991+};
1992+
1993+int av_disposition_from_string(const char *disp)
1994+{
1995+ for (int i = 0; i < FF_ARRAY_ELEMS(dispositions); i++)
1996+ if (!strcmp(disp, dispositions[i].str))
1997+ return dispositions[i].disposition;
1998+ return AVERROR(EINVAL);
1999+}
2000+
2001+const char *av_disposition_to_string(int disposition)
2002+{
2003+ int val;
2004+
2005+ if (disposition <= 0)
2006+ return NULL;
2007+
2008+ val = 1 << ff_ctz(disposition);
2009+ for (int i = 0; i < FF_ARRAY_ELEMS(dispositions); i++)
2010+ if (dispositions[i].disposition == val)
2011+ return dispositions[i].str;
2012+
2013+ return NULL;
2014+}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t