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 "avdevice.h"
21 #include "internal.h"
22 #include "libavformat/mux.h"
23 
25  void *data, size_t data_size)
26 {
27  if (!s->oformat || !ffofmt(s->oformat)->control_message)
28  return AVERROR(ENOSYS);
29  return ffofmt(s->oformat)->control_message(s, type, data, data_size);
30 }
31 
33  void *data, size_t data_size)
34 {
35  if (!s->control_message_cb)
36  return AVERROR(ENOSYS);
37  return s->control_message_cb(s, type, data, data_size);
38 }
39 
41 {
42  int ret;
43  av_assert0(s);
44  av_assert0(device_list);
45  av_assert0(s->oformat || s->iformat);
46  if ((s->oformat && !ffofmt(s->oformat)->get_device_list) ||
47  (s->iformat && !s->iformat->get_device_list)) {
48  *device_list = NULL;
49  return AVERROR(ENOSYS);
50  }
51  *device_list = av_mallocz(sizeof(AVDeviceInfoList));
52  if (!(*device_list))
53  return AVERROR(ENOMEM);
54  /* no default device by default */
55  (*device_list)->default_device = -1;
56  if (s->oformat)
57  ret = ffofmt(s->oformat)->get_device_list(s, *device_list);
58  else
59  ret = s->iformat->get_device_list(s, *device_list);
60  if (ret < 0) {
61  avdevice_free_list_devices(device_list);
62  return ret;
63  }
64  return (*device_list)->nb_devices;
65 }
66 
68  AVDeviceInfoList **device_list)
69 {
71  int ret;
72 
73  av_dict_copy(&tmp, options, 0);
75  goto fail;
76  ret = avdevice_list_devices(s, device_list);
77  fail:
78  av_dict_free(&tmp);
80  return ret;
81 }
82 
83 int avdevice_list_input_sources(const AVInputFormat *device, const char *device_name,
84  AVDictionary *device_options, AVDeviceInfoList **device_list)
85 {
87  int ret;
88 
89  if ((ret = ff_alloc_input_device_context(&s, device, device_name)) < 0)
90  return ret;
91  return list_devices_for_context(s, device_options, device_list);
92 }
93 
94 int avdevice_list_output_sinks(const AVOutputFormat *device, const char *device_name,
95  AVDictionary *device_options, AVDeviceInfoList **device_list)
96 {
98  int ret;
99 
100  if ((ret = avformat_alloc_output_context2(&s, device, device_name, NULL)) < 0)
101  return ret;
102  return list_devices_for_context(s, device_options, device_list);
103 }
104 
106 {
108  AVDeviceInfo *dev;
109  int i;
110 
111  av_assert0(device_list);
112  list = *device_list;
113  if (!list)
114  return;
115 
116  for (i = 0; i < list->nb_devices; i++) {
117  dev = list->devices[i];
118  if (dev) {
119  av_freep(&dev->device_name);
121  av_freep(&dev->media_types);
122  av_free(dev);
123  }
124  }
125  av_freep(&list->devices);
126  av_freep(device_list);
127 }
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
FFOutputFormat::get_device_list
int(* get_device_list)(AVFormatContext *s, struct AVDeviceInfoList *device_list)
Returns device list with it properties.
Definition: mux.h:104
AVDeviceInfo::device_name
char * device_name
device name, format depends on device
Definition: avdevice.h:334
FFOutputFormat::control_message
int(* control_message)(AVFormatContext *s, int type, void *data, size_t data_size)
Allows sending messages from application to device.
Definition: mux.h:87
avdevice_list_devices
int avdevice_list_devices(AVFormatContext *s, AVDeviceInfoList **device_list)
List devices.
Definition: avdevice.c:40
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
AVAppToDevMessageType
AVAppToDevMessageType
Message types used by avdevice_app_to_dev_control_message().
Definition: avdevice.h:125
data
const char data[16]
Definition: mxf.c:146
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:32
AVDictionary
Definition: dict.c: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:94
fail
#define fail()
Definition: checkasm.h:134
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:546
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:83
s
#define s(width, name)
Definition: cbs_vp9.c:256
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
ffofmt
static const FFOutputFormat * ffofmt(const AVOutputFormat *fmt)
Definition: mux.h:136
AVDeviceInfo::media_types
enum AVMediaType * media_types
array indicating what media types(s), if any, a device can provide.
Definition: avdevice.h:336
AVFormatContext
Format I/O context.
Definition: avformat.h:1104
list_devices_for_context
static int list_devices_for_context(AVFormatContext *s, AVDictionary *options, AVDeviceInfoList **device_list)
Definition: avdevice.c:67
NULL
#define NULL
Definition: coverity.c:32
internal.h
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
options
const OptionDef options[]
AVDeviceInfo
Structure describes basic parameters of the device.
Definition: avdevice.h:333
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:105
AV_OPT_SEARCH_CHILDREN
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
Definition: opt.h:563
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:1743
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:223
AVDevToAppMessageType
AVDevToAppMessageType
Message types used by avdevice_dev_to_app_control_message().
Definition: avdevice.h:204
AVDeviceInfo::device_description
char * device_description
human friendly name
Definition: avdevice.h:335
AVOutputFormat
Definition: avformat.h:507
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
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:254
ret
ret
Definition: filter_design.txt:187
AVDeviceInfoList
List of devices.
Definition: avdevice.h:343
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: avformat.c:96
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:24
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
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:237
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:91
mux.h