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"
20 #include "libavutil/samplefmt.h"
21 #include "libavutil/pixfmt.h"
22 #include "libavcodec/avcodec.h"
27 #include "libavutil/ffversion.h"
28 const char av_device_ffversion[] = "FFmpeg version " FFMPEG_VERSION;
30 #if FF_API_DEVICE_CAPABILITIES
31 const AVOption av_device_capabilities[] = {
36 unsigned avdevice_version(void)
38 av_assert0(LIBAVDEVICE_VERSION_MICRO >= 100);
39 return LIBAVDEVICE_VERSION_INT;
42 const char * avdevice_configuration(void)
44 return FFMPEG_CONFIGURATION;
47 const char * avdevice_license(void)
49 #define LICENSE_PREFIX "libavdevice license: "
50 return &LICENSE_PREFIX FFMPEG_LICENSE[sizeof(LICENSE_PREFIX) - 1];
53 int avdevice_app_to_dev_control_message(struct AVFormatContext *s, enum AVAppToDevMessageType type,
54 void *data, size_t data_size)
56 if (!s->oformat || !s->oformat->control_message)
57 return AVERROR(ENOSYS);
58 return s->oformat->control_message(s, type, data, data_size);
61 int avdevice_dev_to_app_control_message(struct AVFormatContext *s, enum AVDevToAppMessageType type,
62 void *data, size_t data_size)
64 if (!s->control_message_cb)
65 return AVERROR(ENOSYS);
66 return s->control_message_cb(s, type, data, data_size);
69 #if FF_API_DEVICE_CAPABILITIES
70 int avdevice_capabilities_create(AVDeviceCapabilitiesQuery **caps, AVFormatContext *s,
71 AVDictionary **device_options)
73 return AVERROR(ENOSYS);
76 void avdevice_capabilities_free(AVDeviceCapabilitiesQuery **caps, AVFormatContext *s)
82 int avdevice_list_devices(AVFormatContext *s, AVDeviceInfoList **device_list)
86 av_assert0(device_list);
87 av_assert0(s->oformat || s->iformat);
88 if ((s->oformat && !s->oformat->get_device_list) ||
89 (s->iformat && !s->iformat->get_device_list)) {
91 return AVERROR(ENOSYS);
93 *device_list = av_mallocz(sizeof(AVDeviceInfoList));
95 return AVERROR(ENOMEM);
96 /* no default device by default */
97 (*device_list)->default_device = -1;
99 ret = s->oformat->get_device_list(s, *device_list);
101 ret = s->iformat->get_device_list(s, *device_list);
103 avdevice_free_list_devices(device_list);
107 static int list_devices_for_context(AVFormatContext *s, AVDictionary *options,
108 AVDeviceInfoList **device_list)
110 AVDictionary *tmp = NULL;
113 av_dict_copy(&tmp, options, 0);
114 if ((ret = av_opt_set_dict2(s, &tmp, AV_OPT_SEARCH_CHILDREN)) < 0)
116 ret = avdevice_list_devices(s, device_list);
119 avformat_free_context(s);
123 int avdevice_list_input_sources(AVInputFormat *device, const char *device_name,
124 AVDictionary *device_options, AVDeviceInfoList **device_list)
126 AVFormatContext *s = NULL;
129 if ((ret = ff_alloc_input_device_context(&s, device, device_name)) < 0)
131 return list_devices_for_context(s, device_options, device_list);
134 int avdevice_list_output_sinks(AVOutputFormat *device, const char *device_name,
135 AVDictionary *device_options, AVDeviceInfoList **device_list)
137 AVFormatContext *s = NULL;
140 if ((ret = avformat_alloc_output_context2(&s, device, device_name, NULL)) < 0)
142 return list_devices_for_context(s, device_options, device_list);
145 void avdevice_free_list_devices(AVDeviceInfoList **device_list)
147 AVDeviceInfoList *list;
151 av_assert0(device_list);
156 for (i = 0; i < list->nb_devices; i++) {
157 dev = list->devices[i];
159 av_freep(&dev->device_name);
160 av_freep(&dev->device_description);
164 av_freep(&list->devices);
165 av_freep(device_list);