Skip to content

Commit

Permalink
lavf: add function to load devices
Browse files Browse the repository at this point in the history
  • Loading branch information
jdek committed Jan 3, 2018
1 parent dc5138d commit faca849
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
6 changes: 5 additions & 1 deletion libavdevice/alldevices.c
Expand Up @@ -105,6 +105,8 @@ static void av_device_init_next(void)
}
if (previn)
previn->next = NULL;

avpriv_register_devices(outdev_list, indev_list);
}

void avdevice_register_all(void)
Expand All @@ -115,9 +117,11 @@ void avdevice_register_all(void)
static void *device_next(void *prev, int output,
AVClassCategory c1, AVClassCategory c2)
{
pthread_once(&av_device_next_init, av_device_init_next);
const AVClass *pc;
AVClassCategory category = AV_CLASS_CATEGORY_NA;

pthread_once(&av_device_next_init, av_device_init_next);

if (!prev && !(prev = (output ? (void*)outdev_list[0] : (void*)indev_list[0])))
return NULL;

Expand Down
30 changes: 22 additions & 8 deletions libavformat/allformats.c
Expand Up @@ -501,6 +501,9 @@ const AVInputFormat *av_demuxer_iterate(void **opaque){
#if FF_API_NEXT
pthread_once_t av_format_next_init = PTHREAD_ONCE_INIT;

static AVInputFormat **indev_list = NULL;
static AVOutputFormat **outdev_list = NULL;

static void av_format_init_next(void)
{
AVOutputFormat *prevout = NULL, *out;
Expand All @@ -513,10 +516,12 @@ static void av_format_init_next(void)
prevout = out;
}

for (i = 0; (out = (AVOutputFormat*)av_outdev_iterate(&i));) {
if (prevout)
prevout->next = out;
prevout = out;
if (outdev_list) {
for (i = 0; (out = (AVOutputFormat*)outdev_list[(int)i]); i = (void*)(i + 1)) {
if (prevout)
prevout->next = out;
prevout = out;
}
}

if (prevout)
Expand All @@ -528,16 +533,25 @@ static void av_format_init_next(void)
previn = in;
}

for (i = 0; (in = (AVInputFormat*)av_indev_iterate(&i));) {
if (previn)
previn->next = in;
previn = in;
if (indev_list) {
for (i = 0; (in = (AVInputFormat*)indev_list[(int)i]); i = (void*)(i + 1)) {
if (previn)
previn->next = in;
previn = in;
}
}

if (previn)
previn->next = NULL;
}

void avpriv_register_devices(AVOutputFormat *o[], AVInputFormat *i[])
{
outdev_list = o;
indev_list = i;
av_format_init_next();
}

AVInputFormat *av_iformat_next(const AVInputFormat *f)
{
void *i = 0;
Expand Down
4 changes: 4 additions & 0 deletions libavformat/avformat.h
Expand Up @@ -2013,6 +2013,10 @@ int avformat_network_init(void);
int avformat_network_deinit(void);

#if FF_API_NEXT
/**
* Register devices in deprecated format linked list.
*/
void avpriv_register_devices(AVOutputFormat *o[], AVInputFormat *i[]);
/**
* If f is NULL, returns the first registered input format,
* if f is non-NULL, returns the next registered input format after f
Expand Down

0 comments on commit faca849

Please sign in to comment.