]> git.sesse.net Git - ffmpeg/blob - libavdevice/alldevices.c
Merge commit 'a5e011c8dcbf6968cc60f883d33382ba46147e90'
[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_android_camera_demuxer;
33 extern AVInputFormat  ff_avfoundation_demuxer;
34 extern AVInputFormat  ff_bktr_demuxer;
35 extern AVOutputFormat ff_caca_muxer;
36 extern AVInputFormat  ff_decklink_demuxer;
37 extern AVOutputFormat ff_decklink_muxer;
38 extern AVInputFormat  ff_libndi_newtek_demuxer;
39 extern AVOutputFormat ff_libndi_newtek_muxer;
40 extern AVInputFormat  ff_dshow_demuxer;
41 extern AVInputFormat  ff_fbdev_demuxer;
42 extern AVOutputFormat ff_fbdev_muxer;
43 extern AVInputFormat  ff_gdigrab_demuxer;
44 extern AVInputFormat  ff_iec61883_demuxer;
45 extern AVInputFormat  ff_jack_demuxer;
46 extern AVInputFormat  ff_kmsgrab_demuxer;
47 extern AVInputFormat  ff_lavfi_demuxer;
48 extern AVInputFormat  ff_openal_demuxer;
49 extern AVOutputFormat ff_opengl_muxer;
50 extern AVInputFormat  ff_oss_demuxer;
51 extern AVOutputFormat ff_oss_muxer;
52 extern AVInputFormat  ff_pulse_demuxer;
53 extern AVOutputFormat ff_pulse_muxer;
54 extern AVOutputFormat ff_sdl2_muxer;
55 extern AVInputFormat  ff_sndio_demuxer;
56 extern AVOutputFormat ff_sndio_muxer;
57 extern AVInputFormat  ff_v4l2_demuxer;
58 extern AVOutputFormat ff_v4l2_muxer;
59 extern AVInputFormat  ff_vfwcap_demuxer;
60 extern AVInputFormat  ff_xcbgrab_demuxer;
61 extern AVOutputFormat ff_xv_muxer;
62
63 /* external libraries */
64 extern AVInputFormat  ff_libcdio_demuxer;
65 extern AVInputFormat  ff_libdc1394_demuxer;
66
67 #include "libavdevice/outdev_list.c"
68 #include "libavdevice/indev_list.c"
69
70 const AVOutputFormat *av_outdev_iterate(void **opaque)
71 {
72     uintptr_t i = (uintptr_t)*opaque;
73     const AVOutputFormat *f = outdev_list[i];
74
75     if (f)
76         *opaque = (void*)(i + 1);
77     return f;
78 }
79
80 const AVInputFormat *av_indev_iterate(void **opaque)
81 {
82     uintptr_t i = (uintptr_t)*opaque;
83     const AVInputFormat *f = indev_list[i];
84
85     if (f)
86         *opaque = (void*)(i + 1);
87     return f;
88 }
89
90 #if FF_API_NEXT
91 FF_DISABLE_DEPRECATION_WARNINGS
92 static AVOnce av_device_next_init = AV_ONCE_INIT;
93
94 static void av_device_init_next(void)
95 {
96     AVOutputFormat *prevout = NULL, *out;
97     AVInputFormat *previn = NULL, *in;
98     void *i = 0;
99
100     while ((out = (AVOutputFormat*)av_outdev_iterate(&i))) {
101         if (prevout)
102             prevout->next = out;
103         prevout = out;
104     }
105
106     i = 0;
107     while ((in = (AVInputFormat*)av_indev_iterate(&i))) {
108         if (previn)
109             previn->next = in;
110         previn = in;
111     }
112
113     avpriv_register_devices(outdev_list, indev_list);
114 }
115
116 void avdevice_register_all(void)
117 {
118     ff_thread_once(&av_device_next_init, av_device_init_next);
119 }
120
121 static void *device_next(void *prev, int output,
122                          AVClassCategory c1, AVClassCategory c2)
123 {
124     const AVClass *pc;
125     AVClassCategory category = AV_CLASS_CATEGORY_NA;
126
127     ff_thread_once(&av_device_next_init, av_device_init_next);
128
129     if (!prev && !(prev = (output ? (void*)outdev_list[0] : (void*)indev_list[0])))
130         return NULL;
131
132     do {
133         if (output) {
134             if (!(prev = ((AVOutputFormat *)prev)->next))
135                 break;
136             pc = ((AVOutputFormat *)prev)->priv_class;
137         } else {
138             if (!(prev = ((AVInputFormat *)prev)->next))
139                 break;
140             pc = ((AVInputFormat *)prev)->priv_class;
141         }
142         if (!pc)
143             continue;
144         category = pc->category;
145     } while (category != c1 && category != c2);
146     return prev;
147 }
148
149 AVInputFormat *av_input_audio_device_next(AVInputFormat  *d)
150 {
151     return device_next(d, 0, AV_CLASS_CATEGORY_DEVICE_AUDIO_INPUT,
152                        AV_CLASS_CATEGORY_DEVICE_INPUT);
153 }
154
155 AVInputFormat *av_input_video_device_next(AVInputFormat  *d)
156 {
157     return device_next(d, 0, AV_CLASS_CATEGORY_DEVICE_VIDEO_INPUT,
158                        AV_CLASS_CATEGORY_DEVICE_INPUT);
159 }
160
161 AVOutputFormat *av_output_audio_device_next(AVOutputFormat *d)
162 {
163     return device_next(d, 1, AV_CLASS_CATEGORY_DEVICE_AUDIO_OUTPUT,
164                        AV_CLASS_CATEGORY_DEVICE_OUTPUT);
165 }
166
167 AVOutputFormat *av_output_video_device_next(AVOutputFormat *d)
168 {
169     return device_next(d, 1, AV_CLASS_CATEGORY_DEVICE_VIDEO_OUTPUT,
170                        AV_CLASS_CATEGORY_DEVICE_OUTPUT);
171 }
172 FF_DISABLE_DEPRECATION_WARNINGS
173 #endif
174