Line |
Branch |
Exec |
Source |
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/demux.h" |
23 |
|
|
#include "libavformat/mux.h" |
24 |
|
|
|
25 |
|
✗ |
int avdevice_app_to_dev_control_message(struct AVFormatContext *s, enum AVAppToDevMessageType type, |
26 |
|
|
void *data, size_t data_size) |
27 |
|
|
{ |
28 |
|
✗ |
if (!s->oformat || !ffofmt(s->oformat)->control_message) |
29 |
|
✗ |
return AVERROR(ENOSYS); |
30 |
|
✗ |
return ffofmt(s->oformat)->control_message(s, type, data, data_size); |
31 |
|
|
} |
32 |
|
|
|
33 |
|
✗ |
int avdevice_dev_to_app_control_message(struct AVFormatContext *s, enum AVDevToAppMessageType type, |
34 |
|
|
void *data, size_t data_size) |
35 |
|
|
{ |
36 |
|
✗ |
if (!s->control_message_cb) |
37 |
|
✗ |
return AVERROR(ENOSYS); |
38 |
|
✗ |
return s->control_message_cb(s, type, data, data_size); |
39 |
|
|
} |
40 |
|
|
|
41 |
|
✗ |
int avdevice_list_devices(AVFormatContext *s, AVDeviceInfoList **device_list) |
42 |
|
|
{ |
43 |
|
|
int ret; |
44 |
|
✗ |
av_assert0(s); |
45 |
|
✗ |
av_assert0(device_list); |
46 |
|
✗ |
av_assert0(s->oformat || s->iformat); |
47 |
|
✗ |
if ((s->oformat && !ffofmt(s->oformat)->get_device_list) || |
48 |
|
✗ |
(s->iformat && !ffifmt(s->iformat)->get_device_list)) { |
49 |
|
✗ |
*device_list = NULL; |
50 |
|
✗ |
return AVERROR(ENOSYS); |
51 |
|
|
} |
52 |
|
✗ |
*device_list = av_mallocz(sizeof(AVDeviceInfoList)); |
53 |
|
✗ |
if (!(*device_list)) |
54 |
|
✗ |
return AVERROR(ENOMEM); |
55 |
|
|
/* no default device by default */ |
56 |
|
✗ |
(*device_list)->default_device = -1; |
57 |
|
✗ |
if (s->oformat) |
58 |
|
✗ |
ret = ffofmt(s->oformat)->get_device_list(s, *device_list); |
59 |
|
|
else |
60 |
|
✗ |
ret = ffifmt(s->iformat)->get_device_list(s, *device_list); |
61 |
|
✗ |
if (ret < 0) { |
62 |
|
✗ |
avdevice_free_list_devices(device_list); |
63 |
|
✗ |
return ret; |
64 |
|
|
} |
65 |
|
✗ |
return (*device_list)->nb_devices; |
66 |
|
|
} |
67 |
|
|
|
68 |
|
✗ |
static int list_devices_for_context(AVFormatContext *s, AVDictionary *options, |
69 |
|
|
AVDeviceInfoList **device_list) |
70 |
|
|
{ |
71 |
|
✗ |
AVDictionary *tmp = NULL; |
72 |
|
|
int ret; |
73 |
|
|
|
74 |
|
✗ |
av_dict_copy(&tmp, options, 0); |
75 |
|
✗ |
if ((ret = av_opt_set_dict2(s, &tmp, AV_OPT_SEARCH_CHILDREN)) < 0) |
76 |
|
✗ |
goto fail; |
77 |
|
✗ |
ret = avdevice_list_devices(s, device_list); |
78 |
|
✗ |
fail: |
79 |
|
✗ |
av_dict_free(&tmp); |
80 |
|
✗ |
avformat_free_context(s); |
81 |
|
✗ |
return ret; |
82 |
|
|
} |
83 |
|
|
|
84 |
|
✗ |
int avdevice_list_input_sources(const AVInputFormat *device, const char *device_name, |
85 |
|
|
AVDictionary *device_options, AVDeviceInfoList **device_list) |
86 |
|
|
{ |
87 |
|
✗ |
AVFormatContext *s = NULL; |
88 |
|
|
int ret; |
89 |
|
|
|
90 |
|
✗ |
if ((ret = ff_alloc_input_device_context(&s, device, device_name)) < 0) |
91 |
|
✗ |
return ret; |
92 |
|
✗ |
return list_devices_for_context(s, device_options, device_list); |
93 |
|
|
} |
94 |
|
|
|
95 |
|
✗ |
int avdevice_list_output_sinks(const AVOutputFormat *device, const char *device_name, |
96 |
|
|
AVDictionary *device_options, AVDeviceInfoList **device_list) |
97 |
|
|
{ |
98 |
|
✗ |
AVFormatContext *s = NULL; |
99 |
|
|
int ret; |
100 |
|
|
|
101 |
|
✗ |
if ((ret = avformat_alloc_output_context2(&s, device, device_name, NULL)) < 0) |
102 |
|
✗ |
return ret; |
103 |
|
✗ |
return list_devices_for_context(s, device_options, device_list); |
104 |
|
|
} |
105 |
|
|
|
106 |
|
✗ |
void avdevice_free_list_devices(AVDeviceInfoList **device_list) |
107 |
|
|
{ |
108 |
|
|
AVDeviceInfoList *list; |
109 |
|
|
AVDeviceInfo *dev; |
110 |
|
|
int i; |
111 |
|
|
|
112 |
|
✗ |
av_assert0(device_list); |
113 |
|
✗ |
list = *device_list; |
114 |
|
✗ |
if (!list) |
115 |
|
✗ |
return; |
116 |
|
|
|
117 |
|
✗ |
for (i = 0; i < list->nb_devices; i++) { |
118 |
|
✗ |
dev = list->devices[i]; |
119 |
|
✗ |
if (dev) { |
120 |
|
✗ |
av_freep(&dev->device_name); |
121 |
|
✗ |
av_freep(&dev->device_description); |
122 |
|
✗ |
av_freep(&dev->media_types); |
123 |
|
✗ |
av_free(dev); |
124 |
|
|
} |
125 |
|
|
} |
126 |
|
✗ |
av_freep(&list->devices); |
127 |
|
✗ |
av_freep(device_list); |
128 |
|
|
} |
129 |
|
|
|