ffmpeg-encoder: Fix weird bug with std::map crashing in constructor

This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2020-01-14 10:36:04 +01:00
parent 109b1c9b0f
commit 96ac0bd11b
2 changed files with 22 additions and 16 deletions

View file

@ -70,22 +70,6 @@ ffmpeg_manager::ffmpeg_manager() : _factories(), _handlers(), _debug_handler()
register_handler("prores_aw", ::std::make_shared<handler::prores_aw_handler>());
register_handler("h264_nvenc", ::std::make_shared<handler::nvenc_h264_handler>());
register_handler("hevc_nvenc", ::std::make_shared<handler::nvenc_hevc_handler>());
// Encoders
void* iterator = nullptr;
const AVCodec* codec = nullptr;
for (codec = av_codec_iterate(&iterator); codec != nullptr; codec = av_codec_iterate(&iterator)) {
if (!av_codec_is_encoder(codec))
continue;
if ((codec->type == AVMediaType::AVMEDIA_TYPE_AUDIO) || (codec->type == AVMediaType::AVMEDIA_TYPE_VIDEO)) {
try {
auto factory = std::make_shared<ffmpeg_factory>(codec);
factory->register_encoder();
_factories.emplace(codec, factory);
} catch (...) {
}
}
}
}
ffmpeg_manager::~ffmpeg_manager()
@ -115,6 +99,25 @@ bool ffmpeg_manager::has_handler(std::string codec)
return (_handlers.find(codec) != _handlers.end());
}
void encoder::ffmpeg::ffmpeg_manager::register_encoders()
{
// Encoders
void* iterator = nullptr;
const AVCodec* codec = nullptr;
for (codec = av_codec_iterate(&iterator); codec != nullptr; codec = av_codec_iterate(&iterator)) {
if (!av_codec_is_encoder(codec))
continue;
if ((codec->type == AVMediaType::AVMEDIA_TYPE_AUDIO) || (codec->type == AVMediaType::AVMEDIA_TYPE_VIDEO)) {
try {
auto factory = std::make_shared<ffmpeg_factory>(codec);
factory->register_encoder();
_factories.emplace(codec, factory);
} catch (...) {
}
}
}
}
static void* _create(obs_data_t* settings, obs_encoder_t* encoder) noexcept
try {
return reinterpret_cast<void*>(new ffmpeg_instance(settings, encoder));

View file

@ -78,6 +78,7 @@ namespace encoder::ffmpeg {
static void initialize()
{
_instance = ::std::make_shared<ffmpeg_manager>();
_instance->register_encoders();
}
static void finalize()
@ -104,6 +105,8 @@ namespace encoder::ffmpeg {
std::shared_ptr<handler::handler> get_handler(std::string codec);
bool has_handler(std::string codec);
void register_encoders();
};
struct ffmpeg_info {