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