diff options
author | Josh de Kock <josh@itanimul.li> | 2018-01-02 14:34:18 +0000 |
---|---|---|
committer | Josh de Kock <josh@itanimul.li> | 2018-02-06 18:57:42 +0000 |
commit | 0fd475704e871ef3a535947596a012894bae3cbd (patch) | |
tree | b4f94e4e1de998837296e48a7dba037e1a93d959 /libavformat | |
parent | 0694d8702421e7aff1340038559c438b61bb30dd (diff) |
lavd: add new API for iterating input and output devices
This also adds an avpriv function to register devices in
libavformat
Diffstat (limited to 'libavformat')
-rw-r--r-- | libavformat/allformats.c | 42 | ||||
-rw-r--r-- | libavformat/format.c | 8 | ||||
-rw-r--r-- | libavformat/internal.h | 7 |
3 files changed, 55 insertions, 2 deletions
diff --git a/libavformat/allformats.c b/libavformat/allformats.c index 09c42136cc..9fd649bb4c 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -25,6 +25,9 @@ #include "rdt.h" #include "url.h" #include "version.h" +#if FF_API_NEXT +#include "internal.h" +#endif /* (de)muxers */ extern AVOutputFormat ff_a64_muxer; @@ -480,6 +483,7 @@ const AVOutputFormat *av_muxer_iterate(void **opaque) { uintptr_t i = (uintptr_t)*opaque; const AVOutputFormat *f = muxer_list[i]; + if (f) *opaque = (void*)(i + 1); return f; @@ -498,6 +502,9 @@ const AVInputFormat *av_demuxer_iterate(void **opaque){ FF_DISABLE_DEPRECATION_WARNINGS static AVOnce av_format_next_init = AV_ONCE_INIT; +static const AVInputFormat * const *indev_list = NULL; +static const AVOutputFormat * const *outdev_list = NULL; + static void av_format_init_next(void) { AVOutputFormat *prevout = NULL, *out; @@ -510,30 +517,61 @@ static void av_format_init_next(void) prevout = out; } + if (outdev_list) { + for (int j = 0; (out = (AVOutputFormat*)outdev_list[j]); j++) { + if (prevout) + prevout->next = out; + prevout = out; + } + } + i = 0; while ((in = (AVInputFormat*)av_demuxer_iterate(&i))) { if (previn) previn->next = in; previn = in; } + + if (indev_list) { + for (int j = 0; (in = (AVInputFormat*)indev_list[j]); j++) { + if (previn) + previn->next = in; + previn = in; + } + } + +} + +void avpriv_register_devices(const AVOutputFormat * const o[], const AVInputFormat * const i[]) +{ + static AVMutex avpriv_register_devices_mutex = AV_MUTEX_INITIALIZER; + ff_mutex_lock(&avpriv_register_devices_mutex); + outdev_list = o; + indev_list = i; + av_format_init_next(); + ff_mutex_unlock(&avpriv_register_devices_mutex); } AVInputFormat *av_iformat_next(const AVInputFormat *f) { ff_thread_once(&av_format_next_init, av_format_init_next); + if (f) return f->next; else - return demuxer_list[0]; + /* If there are no demuxers but input devices, then return the first input device. + * This will still return null if both there are both no demuxers or input devices. */ + return demuxer_list[0] ? (AVInputFormat*)demuxer_list[0] : (indev_list ? (AVInputFormat*)indev_list[0] : NULL); } AVOutputFormat *av_oformat_next(const AVOutputFormat *f) { ff_thread_once(&av_format_next_init, av_format_init_next); + if (f) return f->next; else - return muxer_list[0]; + return muxer_list[0] ? (AVOutputFormat*)muxer_list[0] : (outdev_list ? (AVOutputFormat*)outdev_list[0] : NULL); } void av_register_all(void) diff --git a/libavformat/format.c b/libavformat/format.c index 608af1b692..b8c5a90a92 100644 --- a/libavformat/format.c +++ b/libavformat/format.c @@ -118,10 +118,18 @@ enum AVCodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name, AVInputFormat *av_find_input_format(const char *short_name) { AVInputFormat *fmt = NULL; +#if FF_API_NEXT +FF_DISABLE_DEPRECATION_WARNINGS + while ((fmt = av_iformat_next(fmt))) + if (av_match_name(short_name, fmt->name)) + return fmt; +FF_ENABLE_DEPRECATION_WARNINGS +#else void *i = 0; while ((fmt = av_demuxer_iterate(&i))) if (av_match_name(short_name, fmt->name)) return fmt; +#endif return NULL; } diff --git a/libavformat/internal.h b/libavformat/internal.h index 1e2a3e05a1..0d08576c29 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -703,4 +703,11 @@ int ff_unlock_avformat(void); */ void ff_format_set_url(AVFormatContext *s, char *url); +#if FF_API_NEXT +/** + * Register devices in deprecated format linked list. + */ +void avpriv_register_devices(const AVOutputFormat * const o[], const AVInputFormat * const i[]); +#endif + #endif /* AVFORMAT_INTERNAL_H */ |