]> git.sesse.net Git - ffmpeg/blob - libavdevice/alldevices.c
Merge commit 'caecb85014fc81f8734560a150073627eedab78c'
[ffmpeg] / libavdevice / alldevices.c
1 /*
2  * Register all the grabbing devices.
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20
21 #include "config.h"
22 #include "libavutil/thread.h"
23 #include "avdevice.h"
24
25 #if FF_API_NEXT
26 #include "libavformat/internal.h"
27 #endif
28
29 /* devices */
30 extern AVInputFormat  ff_alsa_demuxer;
31 extern AVOutputFormat ff_alsa_muxer;
32 extern AVInputFormat  ff_avfoundation_demuxer;
33 extern AVInputFormat  ff_bktr_demuxer;
34 extern AVOutputFormat ff_caca_muxer;
35 extern AVInputFormat  ff_decklink_demuxer;
36 extern AVOutputFormat ff_decklink_muxer;
37 extern AVInputFormat  ff_libndi_newtek_demuxer;
38 extern AVOutputFormat ff_libndi_newtek_muxer;
39 extern AVInputFormat  ff_dshow_demuxer;
40 extern AVInputFormat  ff_fbdev_demuxer;
41 extern AVOutputFormat ff_fbdev_muxer;
42 extern AVInputFormat  ff_gdigrab_demuxer;
43 extern AVInputFormat  ff_iec61883_demuxer;
44 extern AVInputFormat  ff_jack_demuxer;
45 extern AVInputFormat  ff_kmsgrab_demuxer;
46 extern AVInputFormat  ff_lavfi_demuxer;
47 extern AVInputFormat  ff_openal_demuxer;
48 extern AVOutputFormat ff_opengl_muxer;
49 extern AVInputFormat  ff_oss_demuxer;
50 extern AVOutputFormat ff_oss_muxer;
51 extern AVInputFormat  ff_pulse_demuxer;
52 extern AVOutputFormat ff_pulse_muxer;
53 extern AVOutputFormat ff_sdl2_muxer;
54 extern AVInputFormat  ff_sndio_demuxer;
55 extern AVOutputFormat ff_sndio_muxer;
56 extern AVInputFormat  ff_v4l2_demuxer;
57 extern AVOutputFormat ff_v4l2_muxer;
58 extern AVInputFormat  ff_vfwcap_demuxer;
59 extern AVInputFormat  ff_xcbgrab_demuxer;
60 extern AVOutputFormat ff_xv_muxer;
61
62 /* external libraries */
63 extern AVInputFormat  ff_libcdio_demuxer;
64 extern AVInputFormat  ff_libdc1394_demuxer;
65
66 #include "libavdevice/outdev_list.c"
67 #include "libavdevice/indev_list.c"
68
69 const AVOutputFormat *av_outdev_iterate(void **opaque)
70 {
71     uintptr_t i = (uintptr_t)*opaque;
72     const AVOutputFormat *f = outdev_list[i];
73
74     if (f)
75         *opaque = (void*)(i + 1);
76     return f;
77 }
78
79 const AVInputFormat *av_indev_iterate(void **opaque)
80 {
81     uintptr_t i = (uintptr_t)*opaque;
82     const AVInputFormat *f = indev_list[i];
83
84     if (f)
85         *opaque = (void*)(i + 1);
86     return f;
87 }
88
89 #if FF_API_NEXT
90 FF_DISABLE_DEPRECATION_WARNINGS
91 static AVOnce av_device_next_init = AV_ONCE_INIT;
92
93 static void av_device_init_next(void)
94 {
95     AVOutputFormat *prevout = NULL, *out;
96     AVInputFormat *previn = NULL, *in;
97     void *i = 0;
98
99     while ((out = (AVOutputFormat*)av_outdev_iterate(&i))) {
100         if (prevout)
101             prevout->next = out;
102         prevout = out;
103     }
104
105     i = 0;
106     while ((in = (AVInputFormat*)av_indev_iterate(&i))) {
107         if (previn)
108             previn->next = in;
109         previn = in;
110     }
111
112     avpriv_register_devices(outdev_list, indev_list);
113 }
114
115 void avdevice_register_all(void)
116 {
117     ff_thread_once(&av_device_next_init, av_device_init_next);
118 }
119
120 static void *device_next(void *prev, int output,
121                          AVClassCategory c1, AVClassCategory c2)
122 {
123     const AVClass *pc;
124     AVClassCategory category = AV_CLASS_CATEGORY_NA;
125
126     ff_thread_once(&av_device_next_init, av_device_init_next);
127
128     if (!prev && !(prev = (output ? (void*)outdev_list[0] : (void*)indev_list[0])))
129         return NULL;
130
131     do {
132         if (output) {
133             if (!(prev = ((AVOutputFormat *)prev)->next))
134                 break;
135             pc = ((AVOutputFormat *)prev)->priv_class;
136         } else {
137             if (!(prev = ((AVInputFormat *)prev)->next))
138                 break;
139             pc = ((AVInputFormat *)prev)->priv_class;
140         }
141         if (!pc)
142             continue;
143         category = pc->category;
144     } while (category != c1 && category != c2);
145     return prev;
146 }
147
148 AVInputFormat *av_input_audio_device_next(AVInputFormat  *d)
149 {
150     return device_next(d, 0, AV_CLASS_CATEGORY_DEVICE_AUDIO_INPUT,
151                        AV_CLASS_CATEGORY_DEVICE_INPUT);
152 }
153
154 AVInputFormat *av_input_video_device_next(AVInputFormat  *d)
155 {
156     return device_next(d, 0, AV_CLASS_CATEGORY_DEVICE_VIDEO_INPUT,
157                        AV_CLASS_CATEGORY_DEVICE_INPUT);
158 }
159
160 AVOutputFormat *av_output_audio_device_next(AVOutputFormat *d)
161 {
162     return device_next(d, 1, AV_CLASS_CATEGORY_DEVICE_AUDIO_OUTPUT,
163                        AV_CLASS_CATEGORY_DEVICE_OUTPUT);
164 }
165
166 AVOutputFormat *av_output_video_device_next(AVOutputFormat *d)
167 {
168     return device_next(d, 1, AV_CLASS_CATEGORY_DEVICE_VIDEO_OUTPUT,
169                        AV_CLASS_CATEGORY_DEVICE_OUTPUT);
170 }
171 FF_DISABLE_DEPRECATION_WARNINGS
172 #endif
173