List device callback must be able to return valid list without opening device.
This callback should return input values for open function, not vice-versa.
Read header funtion is very likey to fail without proper configuration provided.
Signed-off-by: Lukasz Marek <lukasz.m.luki2@gmail.com>
... | ... |
@@ -2076,9 +2076,7 @@ void *grow_array(void *array, int elem_size, int *size, int new_size) |
2076 | 2076 |
static int print_device_sources(AVInputFormat *fmt, AVDictionary *opts) |
2077 | 2077 |
{ |
2078 | 2078 |
int ret, i; |
2079 |
- AVFormatContext *dev = NULL; |
|
2080 | 2079 |
AVDeviceInfoList *device_list = NULL; |
2081 |
- AVDictionary *tmp_opts = NULL; |
|
2082 | 2080 |
|
2083 | 2081 |
if (!fmt || !fmt->priv_class || !AV_IS_INPUT_DEVICE(fmt->priv_class->category)) |
2084 | 2082 |
return AVERROR(EINVAL); |
... | ... |
@@ -2090,15 +2088,7 @@ static int print_device_sources(AVInputFormat *fmt, AVDictionary *opts) |
2090 | 2090 |
goto fail; |
2091 | 2091 |
} |
2092 | 2092 |
|
2093 |
- /* TODO: avformat_open_input calls read_header callback which is not necessary. |
|
2094 |
- Function like avformat_alloc_output_context2 for input could be helpful here. */ |
|
2095 |
- av_dict_copy(&tmp_opts, opts, 0); |
|
2096 |
- if ((ret = avformat_open_input(&dev, NULL, fmt, &tmp_opts)) < 0) { |
|
2097 |
- printf("Cannot open device: %s.\n", fmt->name); |
|
2098 |
- goto fail; |
|
2099 |
- } |
|
2100 |
- |
|
2101 |
- if ((ret = avdevice_list_devices(dev, &device_list)) < 0) { |
|
2093 |
+ if ((ret = avdevice_list_input_sources(fmt, NULL, opts, &device_list)) < 0) { |
|
2102 | 2094 |
printf("Cannot list sources.\n"); |
2103 | 2095 |
goto fail; |
2104 | 2096 |
} |
... | ... |
@@ -2109,18 +2099,14 @@ static int print_device_sources(AVInputFormat *fmt, AVDictionary *opts) |
2109 | 2109 |
} |
2110 | 2110 |
|
2111 | 2111 |
fail: |
2112 |
- av_dict_free(&tmp_opts); |
|
2113 | 2112 |
avdevice_free_list_devices(&device_list); |
2114 |
- avformat_close_input(&dev); |
|
2115 | 2113 |
return ret; |
2116 | 2114 |
} |
2117 | 2115 |
|
2118 | 2116 |
static int print_device_sinks(AVOutputFormat *fmt, AVDictionary *opts) |
2119 | 2117 |
{ |
2120 | 2118 |
int ret, i; |
2121 |
- AVFormatContext *dev = NULL; |
|
2122 | 2119 |
AVDeviceInfoList *device_list = NULL; |
2123 |
- AVDictionary *tmp_opts = NULL; |
|
2124 | 2120 |
|
2125 | 2121 |
if (!fmt || !fmt->priv_class || !AV_IS_OUTPUT_DEVICE(fmt->priv_class->category)) |
2126 | 2122 |
return AVERROR(EINVAL); |
... | ... |
@@ -2132,14 +2118,7 @@ static int print_device_sinks(AVOutputFormat *fmt, AVDictionary *opts) |
2132 | 2132 |
goto fail; |
2133 | 2133 |
} |
2134 | 2134 |
|
2135 |
- if ((ret = avformat_alloc_output_context2(&dev, fmt, NULL, NULL)) < 0) { |
|
2136 |
- printf("Cannot open device: %s.\n", fmt->name); |
|
2137 |
- goto fail; |
|
2138 |
- } |
|
2139 |
- av_dict_copy(&tmp_opts, opts, 0); |
|
2140 |
- av_opt_set_dict2(dev, &tmp_opts, AV_OPT_SEARCH_CHILDREN); |
|
2141 |
- |
|
2142 |
- if ((ret = avdevice_list_devices(dev, &device_list)) < 0) { |
|
2135 |
+ if ((ret = avdevice_list_output_sinks(fmt, NULL, opts, &device_list)) < 0) { |
|
2143 | 2136 |
printf("Cannot list sinks.\n"); |
2144 | 2137 |
goto fail; |
2145 | 2138 |
} |
... | ... |
@@ -2150,9 +2129,7 @@ static int print_device_sinks(AVOutputFormat *fmt, AVDictionary *opts) |
2150 | 2150 |
} |
2151 | 2151 |
|
2152 | 2152 |
fail: |
2153 |
- av_dict_free(&tmp_opts); |
|
2154 | 2153 |
avdevice_free_list_devices(&device_list); |
2155 |
- avformat_free_context(dev); |
|
2156 | 2154 |
return ret; |
2157 | 2155 |
} |
2158 | 2156 |
|