FFmpeg
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 "avdevice.h"
23 #include "internal.h"
24 #include "config.h"
25 
26 #include "libavutil/ffversion.h"
27 const char av_device_ffversion[] = "FFmpeg version " FFMPEG_VERSION;
28 
29 #if FF_API_DEVICE_CAPABILITIES
31  { NULL }
32 };
33 #endif
34 
35 unsigned avdevice_version(void)
36 {
39 }
40 
41 const char * avdevice_configuration(void)
42 {
43  return FFMPEG_CONFIGURATION;
44 }
45 
46 const char * avdevice_license(void)
47 {
48 #define LICENSE_PREFIX "libavdevice license: "
49  return &LICENSE_PREFIX FFMPEG_LICENSE[sizeof(LICENSE_PREFIX) - 1];
50 }
51 
53  void *data, size_t data_size)
54 {
55  if (!s->oformat || !s->oformat->control_message)
56  return AVERROR(ENOSYS);
57  return s->oformat->control_message(s, type, data, data_size);
58 }
59 
61  void *data, size_t data_size)
62 {
63  if (!s->control_message_cb)
64  return AVERROR(ENOSYS);
65  return s->control_message_cb(s, type, data, data_size);
66 }
67 
68 #if FF_API_DEVICE_CAPABILITIES
70  AVDictionary **device_options)
71 {
72  return AVERROR(ENOSYS);
73 }
74 
76 {
77  return;
78 }
79 #endif
80 
82 {
83  int ret;
84  av_assert0(s);
85  av_assert0(device_list);
86  av_assert0(s->oformat || s->iformat);
87  if ((s->oformat && !s->oformat->get_device_list) ||
88  (s->iformat && !s->iformat->get_device_list)) {
89  *device_list = NULL;
90  return AVERROR(ENOSYS);
91  }
92  *device_list = av_mallocz(sizeof(AVDeviceInfoList));
93  if (!(*device_list))
94  return AVERROR(ENOMEM);
95  /* no default device by default */
96  (*device_list)->default_device = -1;
97  if (s->oformat)
98  ret = s->oformat->get_device_list(s, *device_list);
99  else
100  ret = s->iformat->get_device_list(s, *device_list);
101  if (ret < 0)
102  avdevice_free_list_devices(device_list);
103  return ret;
104 }
105 
107  AVDeviceInfoList **device_list)
108 {
109  AVDictionary *tmp = NULL;
110  int ret;
111 
112  av_dict_copy(&tmp, options, 0);
114  goto fail;
115  ret = avdevice_list_devices(s, device_list);
116  fail:
117  av_dict_free(&tmp);
119  return ret;
120 }
121 
122 int avdevice_list_input_sources(const AVInputFormat *device, const char *device_name,
123  AVDictionary *device_options, AVDeviceInfoList **device_list)
124 {
126  int ret;
127 
128  if ((ret = ff_alloc_input_device_context(&s, device, device_name)) < 0)
129  return ret;
130  return list_devices_for_context(s, device_options, device_list);
131 }
132 
133 int avdevice_list_output_sinks(const AVOutputFormat *device, const char *device_name,
134  AVDictionary *device_options, AVDeviceInfoList **device_list)
135 {
137  int ret;
138 
139  if ((ret = avformat_alloc_output_context2(&s, device, device_name, NULL)) < 0)
140  return ret;
141  return list_devices_for_context(s, device_options, device_list);
142 }
143 
145 {
147  AVDeviceInfo *dev;
148  int i;
149 
150  av_assert0(device_list);
151  list = *device_list;
152  if (!list)
153  return;
154 
155  for (i = 0; i < list->nb_devices; i++) {
156  dev = list->devices[i];
157  if (dev) {
158  av_freep(&dev->device_name);
160  av_free(dev);
161  }
162  }
163  av_freep(&list->devices);
164  av_freep(device_list);
165 }
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
LIBAVDEVICE_VERSION_INT
#define LIBAVDEVICE_VERSION_INT
Definition: version.h:34
AVDeviceInfo::device_name
char * device_name
device name, format depends on device
Definition: avdevice.h:458
AVDeviceCapabilitiesQuery
Following API allows user to probe device capabilities (supported codecs, pixel formats,...
Definition: avdevice.h:401
avdevice_list_devices
int avdevice_list_devices(AVFormatContext *s, AVDeviceInfoList **device_list)
List devices.
Definition: avdevice.c:81
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:26
av_device_capabilities
const AVOption av_device_capabilities[]
AVOption table used by devices to implement device capabilities API.
Definition: avdevice.c:30
avdevice_capabilities_create
int avdevice_capabilities_create(AVDeviceCapabilitiesQuery **caps, AVFormatContext *s, AVDictionary **device_options)
Initialize capabilities probing API based on AVOption API.
Definition: avdevice.c:69
AVOption
AVOption.
Definition: opt.h:247
AVAppToDevMessageType
AVAppToDevMessageType
Message types used by avdevice_app_to_dev_control_message().
Definition: avdevice.h:119
data
const char data[16]
Definition: mxf.c:143
avdevice_dev_to_app_control_message
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:60
AVDictionary
Definition: dict.c:30
LIBAVDEVICE_VERSION_MICRO
#define LIBAVDEVICE_VERSION_MICRO
Definition: version.h:32
avdevice_list_output_sinks
int avdevice_list_output_sinks(const AVOutputFormat *device, const char *device_name, AVDictionary *device_options, AVDeviceInfoList **device_list)
Definition: avdevice.c:133
fail
#define fail()
Definition: checkasm.h:136
samplefmt.h
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
avassert.h
AVInputFormat
Definition: avformat.h:626
avdevice_list_input_sources
int avdevice_list_input_sources(const AVInputFormat *device, const char *device_name, AVDictionary *device_options, AVDeviceInfoList **device_list)
List devices.
Definition: avdevice.c:122
s
#define s(width, name)
Definition: cbs_vp9.c:257
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
avdevice_license
const char * avdevice_license(void)
Return the libavdevice license.
Definition: avdevice.c:46
AVFormatContext
Format I/O context.
Definition: avformat.h:1107
list_devices_for_context
static int list_devices_for_context(AVFormatContext *s, AVDictionary *options, AVDeviceInfoList **device_list)
Definition: avdevice.c:106
NULL
#define NULL
Definition: coverity.c:32
internal.h
avdevice_configuration
const char * avdevice_configuration(void)
Return the libavdevice build-time configuration.
Definition: avdevice.c:41
list
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining list
Definition: filter_design.txt:25
avdevice_capabilities_free
void avdevice_capabilities_free(AVDeviceCapabilitiesQuery **caps, AVFormatContext *s)
Free resources created by avdevice_capabilities_create()
Definition: avdevice.c:75
options
const OptionDef options[]
AVDeviceInfo
Structure describes basic parameters of the device.
Definition: avdevice.h:457
avdevice.h
avdevice_free_list_devices
void avdevice_free_list_devices(AVDeviceInfoList **device_list)
Convenient function to free result of avdevice_list_devices().
Definition: avdevice.c:144
AV_OPT_SEARCH_CHILDREN
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
Definition: opt.h:559
av_device_ffversion
const char av_device_ffversion[]
Definition: avdevice.c:27
av_opt_set_dict2
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
av_dict_free
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
Definition: dict.c:203
AVDevToAppMessageType
AVDevToAppMessageType
Message types used by avdevice_dev_to_app_control_message().
Definition: avdevice.h:198
AVDeviceInfo::device_description
char * device_description
human friendly name
Definition: avdevice.h:459
LICENSE_PREFIX
#define LICENSE_PREFIX
avdevice_version
unsigned avdevice_version(void)
Return the LIBAVDEVICE_VERSION_INT constant.
Definition: avdevice.c:35
i
int i
Definition: input.c:406
AVOutputFormat
Definition: avformat.h:495
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:243
ret
ret
Definition: filter_design.txt:187
pixfmt.h
AVDeviceInfoList
List of devices.
Definition: avdevice.h:465
ff_alloc_input_device_context
av_warn_unused_result int ff_alloc_input_device_context(struct AVFormatContext **avctx, const AVInputFormat *iformat, const char *format)
Definition: utils.c:23
avformat_free_context
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
Definition: utils.c:4301
avdevice_app_to_dev_control_message
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:52
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
av_dict_copy
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition: dict.c:217
avformat_alloc_output_context2
int avformat_alloc_output_context2(AVFormatContext **ctx, const AVOutputFormat *oformat, const char *format_name, const char *filename)
Allocate an AVFormatContext for an output format.
Definition: mux.c:137