2 * This file is part of FFmpeg.
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #include "libavutil/avassert.h"
23 unsigned avdevice_version(void)
25 av_assert0(LIBAVDEVICE_VERSION_MICRO >= 100);
26 return LIBAVDEVICE_VERSION_INT;
29 const char * avdevice_configuration(void)
31 return FFMPEG_CONFIGURATION;
34 const char * avdevice_license(void)
36 #define LICENSE_PREFIX "libavdevice license: "
37 return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1;
40 static void *av_device_next(void *prev, int output,
41 AVClassCategory c1, AVClassCategory c2)
44 AVClassCategory category = AV_CLASS_CATEGORY_NA;
47 if (!(prev = av_oformat_next(prev)))
49 pc = ((AVOutputFormat *)prev)->priv_class;
51 if (!(prev = av_iformat_next(prev)))
53 pc = ((AVInputFormat *)prev)->priv_class;
57 category = pc->category;
58 } while (category != c1 && category != c2);
62 AVInputFormat *av_input_audio_device_next(AVInputFormat *d)
64 return av_device_next(d, 0, AV_CLASS_CATEGORY_DEVICE_AUDIO_INPUT,
65 AV_CLASS_CATEGORY_DEVICE_INPUT);
68 AVInputFormat *av_input_video_device_next(AVInputFormat *d)
70 return av_device_next(d, 0, AV_CLASS_CATEGORY_DEVICE_VIDEO_INPUT,
71 AV_CLASS_CATEGORY_DEVICE_INPUT);
74 AVOutputFormat *av_output_audio_device_next(AVOutputFormat *d)
76 return av_device_next(d, 1, AV_CLASS_CATEGORY_DEVICE_AUDIO_OUTPUT,
77 AV_CLASS_CATEGORY_DEVICE_OUTPUT);
80 AVOutputFormat *av_output_video_device_next(AVOutputFormat *d)
82 return av_device_next(d, 1, AV_CLASS_CATEGORY_DEVICE_VIDEO_OUTPUT,
83 AV_CLASS_CATEGORY_DEVICE_OUTPUT);
86 int avdevice_app_to_dev_control_message(struct AVFormatContext *s, enum AVAppToDevMessageType type,
87 void *data, size_t data_size)
89 if (!s->oformat || !s->oformat->control_message)
90 return AVERROR(ENOSYS);
91 return s->oformat->control_message(s, type, data, data_size);
94 int avdevice_dev_to_app_control_message(struct AVFormatContext *s, enum AVDevToAppMessageType type,
95 void *data, size_t data_size)
97 if (!s->control_message_cb)
98 return AVERROR(ENOSYS);
99 return s->control_message_cb(s, type, data, data_size);
102 int avdevice_list_devices(AVFormatContext *s, AVDeviceInfoList **device_list)
106 av_assert0(device_list);
107 av_assert0(s->oformat || s->iformat);
108 if ((s->oformat && !s->oformat->get_device_list) ||
109 (s->iformat && !s->iformat->get_device_list)) {
111 return AVERROR(ENOSYS);
113 *device_list = av_mallocz(sizeof(AVDeviceInfoList));
115 return AVERROR(ENOMEM);
117 ret = s->oformat->get_device_list(s, *device_list);
119 ret = s->iformat->get_device_list(s, *device_list);
121 avdevice_free_list_devices(device_list);
125 void avdevice_free_list_devices(AVDeviceInfoList **device_list)
127 AVDeviceInfoList *list;
131 av_assert0(device_list);
136 for (i = 0; i < list->nb_devices; i++) {
137 dev = list->devices[i];
139 av_free(dev->device_name);
140 av_free(dev->device_description);
144 av_free(list->devices);
145 av_freep(device_list);