Skip to content

Commit faca849

Browse files
author
Josh de Kock
committed
lavf: add function to load devices
1 parent dc5138d commit faca849

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

libavdevice/alldevices.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ static void av_device_init_next(void)
105105
}
106106
if (previn)
107107
previn->next = NULL;
108+
109+
avpriv_register_devices(outdev_list, indev_list);
108110
}
109111

110112
void avdevice_register_all(void)
@@ -115,9 +117,11 @@ void avdevice_register_all(void)
115117
static void *device_next(void *prev, int output,
116118
AVClassCategory c1, AVClassCategory c2)
117119
{
118-
pthread_once(&av_device_next_init, av_device_init_next);
119120
const AVClass *pc;
120121
AVClassCategory category = AV_CLASS_CATEGORY_NA;
122+
123+
pthread_once(&av_device_next_init, av_device_init_next);
124+
121125
if (!prev && !(prev = (output ? (void*)outdev_list[0] : (void*)indev_list[0])))
122126
return NULL;
123127

libavformat/allformats.c

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,9 @@ const AVInputFormat *av_demuxer_iterate(void **opaque){
501501
#if FF_API_NEXT
502502
pthread_once_t av_format_next_init = PTHREAD_ONCE_INIT;
503503

504+
static AVInputFormat **indev_list = NULL;
505+
static AVOutputFormat **outdev_list = NULL;
506+
504507
static void av_format_init_next(void)
505508
{
506509
AVOutputFormat *prevout = NULL, *out;
@@ -513,10 +516,12 @@ static void av_format_init_next(void)
513516
prevout = out;
514517
}
515518

516-
for (i = 0; (out = (AVOutputFormat*)av_outdev_iterate(&i));) {
517-
if (prevout)
518-
prevout->next = out;
519-
prevout = out;
519+
if (outdev_list) {
520+
for (i = 0; (out = (AVOutputFormat*)outdev_list[(int)i]); i = (void*)(i + 1)) {
521+
if (prevout)
522+
prevout->next = out;
523+
prevout = out;
524+
}
520525
}
521526

522527
if (prevout)
@@ -528,16 +533,25 @@ static void av_format_init_next(void)
528533
previn = in;
529534
}
530535

531-
for (i = 0; (in = (AVInputFormat*)av_indev_iterate(&i));) {
532-
if (previn)
533-
previn->next = in;
534-
previn = in;
536+
if (indev_list) {
537+
for (i = 0; (in = (AVInputFormat*)indev_list[(int)i]); i = (void*)(i + 1)) {
538+
if (previn)
539+
previn->next = in;
540+
previn = in;
541+
}
535542
}
536543

537544
if (previn)
538545
previn->next = NULL;
539546
}
540547

548+
void avpriv_register_devices(AVOutputFormat *o[], AVInputFormat *i[])
549+
{
550+
outdev_list = o;
551+
indev_list = i;
552+
av_format_init_next();
553+
}
554+
541555
AVInputFormat *av_iformat_next(const AVInputFormat *f)
542556
{
543557
void *i = 0;

libavformat/avformat.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2013,6 +2013,10 @@ int avformat_network_init(void);
20132013
int avformat_network_deinit(void);
20142014

20152015
#if FF_API_NEXT
2016+
/**
2017+
* Register devices in deprecated format linked list.
2018+
*/
2019+
void avpriv_register_devices(AVOutputFormat *o[], AVInputFormat *i[]);
20162020
/**
20172021
* If f is NULL, returns the first registered input format,
20182022
* if f is non-NULL, returns the next registered input format after f

0 commit comments

Comments
 (0)