| 229 | } |
| 230 | |
| 231 | int avformat_open_input(AVFormatContext **ps, const char *filename, |
| 232 | const AVInputFormat *fmt, AVDictionary **options) |
| 233 | { |
| 234 | FormatContextInternal *fci; |
| 235 | AVFormatContext *s = *ps; |
| 236 | FFFormatContext *si; |
| 237 | AVDictionary *tmp = NULL; |
| 238 | ID3v2ExtraMeta *id3v2_extra_meta = NULL; |
| 239 | int ret = 0; |
| 240 | |
| 241 | if (!s && !(s = avformat_alloc_context())) |
| 242 | return AVERROR(ENOMEM); |
| 243 | fci = ff_fc_internal(s); |
| 244 | si = &fci->fc; |
| 245 | if (!s->av_class) { |
| 246 | av_log(NULL, AV_LOG_ERROR, "Input context has not been properly allocated by avformat_alloc_context() and is not NULL either\n"); |
| 247 | return AVERROR(EINVAL); |
| 248 | } |
| 249 | if (fmt) |
| 250 | s->iformat = fmt; |
| 251 | |
| 252 | if (options) |
| 253 | av_dict_copy(&tmp, *options, 0); |
| 254 | |
| 255 | if (s->pb) // must be before any goto fail |
| 256 | s->flags |= AVFMT_FLAG_CUSTOM_IO; |
| 257 | |
| 258 | if ((ret = av_opt_set_dict(s, &tmp)) < 0) |
| 259 | goto fail; |
| 260 | |
| 261 | if (!(s->url = av_strdup(filename ? filename : ""))) { |
| 262 | ret = AVERROR(ENOMEM); |
| 263 | goto fail; |
| 264 | } |
| 265 | |
| 266 | if ((ret = init_input(s, filename, &tmp)) < 0) |
| 267 | goto fail; |
| 268 | s->probe_score = ret; |
| 269 | |
| 270 | if (!s->protocol_whitelist && s->pb && s->pb->protocol_whitelist) { |
| 271 | s->protocol_whitelist = av_strdup(s->pb->protocol_whitelist); |
| 272 | if (!s->protocol_whitelist) { |
| 273 | ret = AVERROR(ENOMEM); |
| 274 | goto fail; |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | if (!s->protocol_blacklist && s->pb && s->pb->protocol_blacklist) { |
| 279 | s->protocol_blacklist = av_strdup(s->pb->protocol_blacklist); |
| 280 | if (!s->protocol_blacklist) { |
| 281 | ret = AVERROR(ENOMEM); |
| 282 | goto fail; |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | if (s->format_whitelist && av_match_list(s->iformat->name, s->format_whitelist, ',') <= 0) { |
| 287 | av_log(s, AV_LOG_ERROR, "Format not on whitelist \'%s\'\n", s->format_whitelist); |
| 288 | ret = AVERROR(EINVAL); |