FFmpeg  4.4.4
avdevice.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
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.
8  *
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.
13  *
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
17  */
18 
19 #include "libavutil/avassert.h"
20 #include "libavutil/samplefmt.h"
21 #include "libavutil/pixfmt.h"
22 #include "libavcodec/avcodec.h"
23 #include "avdevice.h"
24 #include "internal.h"
25 #include "config.h"
26 
27 #include "libavutil/ffversion.h"
28 const char av_device_ffversion[] = "FFmpeg version " FFMPEG_VERSION;
29 
30 #if FF_API_DEVICE_CAPABILITIES
32  { NULL }
33 };
34 #endif
35 
36 unsigned avdevice_version(void)
37 {
40 }
41 
42 const char * avdevice_configuration(void)
43 {
44  return FFMPEG_CONFIGURATION;
45 }
46 
47 const char * avdevice_license(void)
48 {
49 #define LICENSE_PREFIX "libavdevice license: "
50  return &LICENSE_PREFIX FFMPEG_LICENSE[sizeof(LICENSE_PREFIX) - 1];
51 }
52 
54  void *data, size_t data_size)
55 {
56  if (!s->oformat || !s->oformat->control_message)
57  return AVERROR(ENOSYS);
58  return s->oformat->control_message(s, type, data, data_size);
59 }
60 
62  void *data, size_t data_size)
63 {
64  if (!s->control_message_cb)
65  return AVERROR(ENOSYS);
66  return s->control_message_cb(s, type, data, data_size);
67 }
68 
69 #if FF_API_DEVICE_CAPABILITIES
71  AVDictionary **device_options)
72 {
73  return AVERROR(ENOSYS);
74 }
75 
77 {
78  return;
79 }
80 #endif
81 
83 {
84  int ret;
85  av_assert0(s);
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)) {
90  *device_list = NULL;
91  return AVERROR(ENOSYS);
92  }
93  *device_list = av_mallocz(sizeof(AVDeviceInfoList));
94  if (!(*device_list))
95  return AVERROR(ENOMEM);
96  /* no default device by default */
97  (*device_list)->default_device = -1;
98  if (s->oformat)
99  ret = s->oformat->get_device_list(s, *device_list);
100  else
101  ret = s->iformat->get_device_list(s, *device_list);
102  if (ret < 0)
103  avdevice_free_list_devices(device_list);
104  return ret;
105 }
106 
108  AVDeviceInfoList **device_list)
109 {
110  AVDictionary *tmp = NULL;
111  int ret;
112 
113  av_dict_copy(&tmp, options, 0);
114  if ((ret = av_opt_set_dict2(s, &tmp, AV_OPT_SEARCH_CHILDREN)) < 0)
115  goto fail;
116  ret = avdevice_list_devices(s, device_list);
117  fail:
118  av_dict_free(&tmp);
120  return ret;
121 }
122 
123 int avdevice_list_input_sources(AVInputFormat *device, const char *device_name,
124  AVDictionary *device_options, AVDeviceInfoList **device_list)
125 {
127  int ret;
128 
129  if ((ret = ff_alloc_input_device_context(&s, device, device_name)) < 0)
130  return ret;
131  return list_devices_for_context(s, device_options, device_list);
132 }
133 
134 int avdevice_list_output_sinks(AVOutputFormat *device, const char *device_name,
135  AVDictionary *device_options, AVDeviceInfoList **device_list)
136 {
138  int ret;
139 
140  if ((ret = avformat_alloc_output_context2(&s, device, device_name, NULL)) < 0)
141  return ret;
142  return list_devices_for_context(s, device_options, device_list);
143 }
144 
146 {
147  AVDeviceInfoList *list;
148  AVDeviceInfo *dev;
149  int i;
150 
151  av_assert0(device_list);
152  list = *device_list;
153  if (!list)
154  return;
155 
156  for (i = 0; i < list->nb_devices; i++) {
157  dev = list->devices[i];
158  if (dev) {
159  av_freep(&dev->device_name);
161  av_free(dev);
162  }
163  }
164  av_freep(&list->devices);
165  av_freep(device_list);
166 }
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
Libavcodec external API header.
static int list_devices_for_context(AVFormatContext *s, AVDictionary *options, AVDeviceInfoList **device_list)
Definition: avdevice.c:107
const char av_device_ffversion[]
Definition: avdevice.c:28
#define LICENSE_PREFIX
Main libavdevice API header.
int avformat_alloc_output_context2(AVFormatContext **ctx, ff_const59 AVOutputFormat *oformat, const char *format_name, const char *filename)
Allocate an AVFormatContext for an output format.
Definition: mux.c:136
#define s(width, name)
Definition: cbs_vp9.c:257
#define fail()
Definition: checkasm.h:133
#define FFMPEG_CONFIGURATION
Definition: config.h:4
#define FFMPEG_LICENSE
Definition: config.h:5
#define NULL
Definition: coverity.c:32
const OptionDef options[]
#define FFMPEG_VERSION
Definition: ffversion.h:4
int av_opt_set_dict2(void *obj, AVDictionary **options, int search_flags)
Set all the options from a given dictionary on an object.
Definition: opt.c:1631
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
Definition: opt.h:560
void avdevice_capabilities_free(AVDeviceCapabilitiesQuery **caps, AVFormatContext *s)
Free resources created by avdevice_capabilities_create()
Definition: avdevice.c:76
const char * avdevice_license(void)
Return the libavdevice license.
Definition: avdevice.c:47
AVAppToDevMessageType
Message types used by avdevice_app_to_dev_control_message().
Definition: avdevice.h:119
int avdevice_list_input_sources(AVInputFormat *device, const char *device_name, AVDictionary *device_options, AVDeviceInfoList **device_list)
List devices.
Definition: avdevice.c:123
int avdevice_list_output_sinks(AVOutputFormat *device, const char *device_name, AVDictionary *device_options, AVDeviceInfoList **device_list)
Definition: avdevice.c:134
int avdevice_list_devices(AVFormatContext *s, AVDeviceInfoList **device_list)
List devices.
Definition: avdevice.c:82
void avdevice_free_list_devices(AVDeviceInfoList **device_list)
Convenient function to free result of avdevice_list_devices().
Definition: avdevice.c:145
int avdevice_app_to_dev_control_message(struct AVFormatContext *s, enum AVAppToDevMessageType type, void *data, size_t data_size)
Send control message from application to device.
Definition: avdevice.c:53
unsigned avdevice_version(void)
Return the LIBAVDEVICE_VERSION_INT constant.
Definition: avdevice.c:36
const char * avdevice_configuration(void)
Return the libavdevice build-time configuration.
Definition: avdevice.c:42
const AVOption av_device_capabilities[]
AVOption table used by devices to implement device capabilities API.
Definition: avdevice.c:31
int avdevice_capabilities_create(AVDeviceCapabilitiesQuery **caps, AVFormatContext *s, AVDictionary **device_options)
Initialize capabilities probing API based on AVOption API.
Definition: avdevice.c:70
AVDevToAppMessageType
Message types used by avdevice_dev_to_app_control_message().
Definition: avdevice.h:198
int avdevice_dev_to_app_control_message(struct AVFormatContext *s, enum AVDevToAppMessageType type, void *data, size_t data_size)
Send control message from device to application.
Definition: avdevice.c:61
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
Definition: utils.c:4436
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
Definition: dict.c:203
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition: dict.c:217
#define AVERROR(e)
Definition: error.h:43
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:237
cl_device_type type
int i
Definition: input.c:407
av_warn_unused_result int ff_alloc_input_device_context(struct AVFormatContext **avctx, struct AVInputFormat *iformat, const char *format)
Definition: utils.c:23
#define LIBAVDEVICE_VERSION_INT
Definition: version.h:34
#define LIBAVDEVICE_VERSION_MICRO
Definition: version.h:32
common internal API header
const char data[16]
Definition: mxf.c:142
pixel format definitions
Following API allows user to probe device capabilities (supported codecs, pixel formats,...
Definition: avdevice.h:401
List of devices.
Definition: avdevice.h:465
int nb_devices
number of autodetected devices
Definition: avdevice.h:467
AVDeviceInfo ** devices
list of autodetected devices
Definition: avdevice.h:466
Structure describes basic parameters of the device.
Definition: avdevice.h:457
char * device_description
human friendly name
Definition: avdevice.h:459
char * device_name
device name, format depends on device
Definition: avdevice.h:458
Format I/O context.
Definition: avformat.h:1232
AVOption.
Definition: opt.h:248
#define av_free(p)
#define av_freep(p)
static uint8_t tmp[11]
Definition: aes_ctr.c:27