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"
26 #define E AV_OPT_FLAG_ENCODING_PARAM
27 #define D AV_OPT_FLAG_DECODING_PARAM
28 #define A AV_OPT_FLAG_AUDIO_PARAM
29 #define V AV_OPT_FLAG_VIDEO_PARAM
30 #define OFFSET(x) offsetof(AVDeviceCapabilitiesQuery, x)
32 const AVOption av_device_capabilities
[] = {
33 { "codec", "codec", OFFSET(codec
), AV_OPT_TYPE_INT
,
34 {.i64
= AV_CODEC_ID_NONE
}, AV_CODEC_ID_NONE
, INT_MAX
, E
|D
|A
|V
},
35 { "sample_format", "sample format", OFFSET(sample_format
), AV_OPT_TYPE_INT
,
36 {.i64
= AV_SAMPLE_FMT_NONE
}, -1, INT_MAX
, E
|D
|A
},
37 { "sample_rate", "sample rate", OFFSET(sample_rate
), AV_OPT_TYPE_INT
,
38 {.i64
= -1}, -1, INT_MAX
, E
|D
|A
},
39 { "channels", "channels", OFFSET(channels
), AV_OPT_TYPE_INT
,
40 {.i64
= -1}, -1, INT_MAX
, E
|D
|A
},
41 { "channel_layout", "channel layout", OFFSET(channel_layout
), AV_OPT_TYPE_INT64
,
42 {.i64
= -1}, -1, INT_MAX
, E
|D
|A
},
43 { "pixel_format", "pixel format", OFFSET(pixel_format
), AV_OPT_TYPE_INT
,
44 {.i64
= AV_PIX_FMT_NONE
}, -1, INT_MAX
, E
|D
|V
},
45 { "window_size", "window size", OFFSET(window_width
), AV_OPT_TYPE_IMAGE_SIZE
,
46 {.str
= NULL
}, -1, INT_MAX
, E
|D
|V
},
47 { "frame_size", "frame size", OFFSET(frame_width
), AV_OPT_TYPE_IMAGE_SIZE
,
48 {.str
= NULL
}, -1, INT_MAX
, E
|D
|V
},
49 { "fps", "fps", OFFSET(fps
), AV_OPT_TYPE_RATIONAL
,
50 {.dbl
= -1}, -1, INT_MAX
, E
|D
|V
},
60 unsigned avdevice_version(void)
62 av_assert0(LIBAVDEVICE_VERSION_MICRO
>= 100);
63 return LIBAVDEVICE_VERSION_INT
;
66 const char * avdevice_configuration(void)
68 return FFMPEG_CONFIGURATION
;
71 const char * avdevice_license(void)
73 #define LICENSE_PREFIX "libavdevice license: "
74 return LICENSE_PREFIX FFMPEG_LICENSE
+ sizeof(LICENSE_PREFIX
) - 1;
77 static void *av_device_next(void *prev
, int output
,
78 AVClassCategory c1
, AVClassCategory c2
)
81 AVClassCategory category
= AV_CLASS_CATEGORY_NA
;
84 if (!(prev
= av_oformat_next(prev
)))
86 pc
= ((AVOutputFormat
*)prev
)->priv_class
;
88 if (!(prev
= av_iformat_next(prev
)))
90 pc
= ((AVInputFormat
*)prev
)->priv_class
;
94 category
= pc
->category
;
95 } while (category
!= c1
&& category
!= c2
);
99 AVInputFormat
*av_input_audio_device_next(AVInputFormat
*d
)
101 return av_device_next(d
, 0, AV_CLASS_CATEGORY_DEVICE_AUDIO_INPUT
,
102 AV_CLASS_CATEGORY_DEVICE_INPUT
);
105 AVInputFormat
*av_input_video_device_next(AVInputFormat
*d
)
107 return av_device_next(d
, 0, AV_CLASS_CATEGORY_DEVICE_VIDEO_INPUT
,
108 AV_CLASS_CATEGORY_DEVICE_INPUT
);
111 AVOutputFormat
*av_output_audio_device_next(AVOutputFormat
*d
)
113 return av_device_next(d
, 1, AV_CLASS_CATEGORY_DEVICE_AUDIO_OUTPUT
,
114 AV_CLASS_CATEGORY_DEVICE_OUTPUT
);
117 AVOutputFormat
*av_output_video_device_next(AVOutputFormat
*d
)
119 return av_device_next(d
, 1, AV_CLASS_CATEGORY_DEVICE_VIDEO_OUTPUT
,
120 AV_CLASS_CATEGORY_DEVICE_OUTPUT
);
123 int avdevice_app_to_dev_control_message(struct AVFormatContext
*s
, enum AVAppToDevMessageType type
,
124 void *data
, size_t data_size
)
126 if (!s
->oformat
|| !s
->oformat
->control_message
)
127 return AVERROR(ENOSYS
);
128 return s
->oformat
->control_message(s
, type
, data
, data_size
);
131 int avdevice_dev_to_app_control_message(struct AVFormatContext
*s
, enum AVDevToAppMessageType type
,
132 void *data
, size_t data_size
)
134 if (!s
->control_message_cb
)
135 return AVERROR(ENOSYS
);
136 return s
->control_message_cb(s
, type
, data
, data_size
);
139 int avdevice_capabilities_create(AVDeviceCapabilitiesQuery
**caps
, AVFormatContext
*s
,
140 AVDictionary
**device_options
)
143 av_assert0(s
&& caps
);
144 av_assert0(s
->iformat
|| s
->oformat
);
145 if ((s
->oformat
&& !s
->oformat
->create_device_capabilities
) ||
146 (s
->iformat
&& !s
->iformat
->create_device_capabilities
))
147 return AVERROR(ENOSYS
);
148 *caps
= av_mallocz(sizeof(**caps
));
150 return AVERROR(ENOMEM
);
151 (*caps
)->device_context
= s
;
152 if (((ret
= av_opt_set_dict(s
->priv_data
, device_options
)) < 0))
155 if ((ret
= s
->iformat
->create_device_capabilities(s
, *caps
)) < 0)
158 if ((ret
= s
->oformat
->create_device_capabilities(s
, *caps
)) < 0)
161 av_opt_set_defaults(*caps
);
168 void avdevice_capabilities_free(AVDeviceCapabilitiesQuery
**caps
, AVFormatContext
*s
)
170 if (!s
|| !caps
|| !(*caps
))
172 av_assert0(s
->iformat
|| s
->oformat
);
174 if (s
->iformat
->free_device_capabilities
)
175 s
->iformat
->free_device_capabilities(s
, *caps
);
177 if (s
->oformat
->free_device_capabilities
)
178 s
->oformat
->free_device_capabilities(s
, *caps
);
183 int avdevice_list_devices(AVFormatContext
*s
, AVDeviceInfoList
**device_list
)
187 av_assert0(device_list
);
188 av_assert0(s
->oformat
|| s
->iformat
);
189 if ((s
->oformat
&& !s
->oformat
->get_device_list
) ||
190 (s
->iformat
&& !s
->iformat
->get_device_list
)) {
192 return AVERROR(ENOSYS
);
194 *device_list
= av_mallocz(sizeof(AVDeviceInfoList
));
196 return AVERROR(ENOMEM
);
197 /* no default device by default */
198 (*device_list
)->default_device
= -1;
200 ret
= s
->oformat
->get_device_list(s
, *device_list
);
202 ret
= s
->iformat
->get_device_list(s
, *device_list
);
204 avdevice_free_list_devices(device_list
);
208 void avdevice_free_list_devices(AVDeviceInfoList
**device_list
)
210 AVDeviceInfoList
*list
;
214 av_assert0(device_list
);
219 for (i
= 0; i
< list
->nb_devices
; i
++) {
220 dev
= list
->devices
[i
];
222 av_free(dev
->device_name
);
223 av_free(dev
->device_description
);
227 av_free(list
->devices
);
228 av_freep(device_list
);