- switch (resource_type) {
- case FFMPEG_Resource::FFMPEG_FILE:
- THROW_ON_ERROR2(avformat_open_input(&weak_context, u8(resource_name).c_str(), nullptr, nullptr), resource_name);
- break;
- case FFMPEG_Resource::FFMPEG_DEVICE:
- {
- AVDictionary* format_options = NULL;
- for (auto& option : vid_params)
- {
- av_dict_set(&format_options, option.first.c_str(), option.second.c_str(), 0);
- }
- AVInputFormat* input_format = av_find_input_format("dshow");
- THROW_ON_ERROR2(avformat_open_input(&weak_context, u8(resource_name).c_str(), input_format, &format_options), resource_name);
- if (format_options != nullptr)
- {
- std::string unsupported_tokens = "";
- AVDictionaryEntry *t = NULL;
- while ((t = av_dict_get(format_options, "", t, AV_DICT_IGNORE_SUFFIX)) != nullptr)
- {
- if (!unsupported_tokens.empty())
- unsupported_tokens += ", ";
- unsupported_tokens += t->key;
- }
- avformat_close_input(&weak_context);
- BOOST_THROW_EXCEPTION(ffmpeg_error() << msg_info(unsupported_tokens));
- }
- av_dict_free(&format_options);
- }
- break;
- case FFMPEG_Resource::FFMPEG_STREAM:
- {
- AVDictionary* format_options = NULL;
- for (auto& option : vid_params)
- {
- av_dict_set(&format_options, option.first.c_str(), option.second.c_str(), 0);
- }
- THROW_ON_ERROR2(avformat_open_input(&weak_context, u8(resource_name).c_str(), nullptr, &format_options), resource_name);
- if (format_options != nullptr)
- {
- std::string unsupported_tokens = "";
- AVDictionaryEntry *t = NULL;
- while ((t = av_dict_get(format_options, "", t, AV_DICT_IGNORE_SUFFIX)) != nullptr)
- {
- if (!unsupported_tokens.empty())
- unsupported_tokens += ", ";
- unsupported_tokens += t->key;
- }
- avformat_close_input(&weak_context);
- BOOST_THROW_EXCEPTION(ffmpeg_error() << msg_info(unsupported_tokens));
- }