code: Migrate encoder::ffmpeg to new dynamic loader
This commit is contained in:
parent
66698ef938
commit
acf4dde783
|
|
@ -84,7 +84,7 @@ ffmpeg_instance::ffmpeg_instance(obs_data_t* settings, obs_encoder_t* self, bool
|
||||||
|
|
||||||
_factory(reinterpret_cast<ffmpeg_factory*>(obs_encoder_get_type_data(self))),
|
_factory(reinterpret_cast<ffmpeg_factory*>(obs_encoder_get_type_data(self))),
|
||||||
|
|
||||||
_codec(_factory->get_avcodec()), _context(nullptr), _handler(ffmpeg_manager::get()->get_handler(_codec->name)),
|
_codec(_factory->get_avcodec()), _context(nullptr), _handler(ffmpeg_manager::instance()->get_handler(_codec->name)),
|
||||||
|
|
||||||
_scaler(), _packet(),
|
_scaler(), _packet(),
|
||||||
|
|
||||||
|
|
@ -958,7 +958,7 @@ ffmpeg_factory::ffmpeg_factory(const AVCodec* codec) : _avcodec(codec)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find any available handlers for this codec.
|
// Find any available handlers for this codec.
|
||||||
if (_handler = ffmpeg_manager::get()->get_handler(_avcodec->name); _handler) {
|
if (_handler = ffmpeg_manager::instance()->get_handler(_avcodec->name); _handler) {
|
||||||
// Override any found info with the one specified by the handler.
|
// Override any found info with the one specified by the handler.
|
||||||
_handler->adjust_info(this, _avcodec, _id, _name, _codec);
|
_handler->adjust_info(this, _avcodec, _id, _name, _codec);
|
||||||
|
|
||||||
|
|
@ -1213,22 +1213,28 @@ bool ffmpeg_manager::has_handler(std::string_view codec)
|
||||||
return (_handlers.find(codec.data()) != _handlers.end());
|
return (_handlers.find(codec.data()) != _handlers.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<ffmpeg_manager> _ffmepg_encoder_factory_instance = nullptr;
|
|
||||||
|
|
||||||
void ffmpeg_manager::initialize()
|
std::shared_ptr<ffmpeg_manager> ffmpeg_manager::instance()
|
||||||
{
|
{
|
||||||
if (!_ffmepg_encoder_factory_instance) {
|
static std::weak_ptr<ffmpeg_manager> winst;
|
||||||
_ffmepg_encoder_factory_instance = std::make_shared<ffmpeg_manager>();
|
static std::mutex mtx;
|
||||||
_ffmepg_encoder_factory_instance->register_encoders();
|
|
||||||
|
std::unique_lock<decltype(mtx)> lock(mtx);
|
||||||
|
auto instance = winst.lock();
|
||||||
|
if (!instance) {
|
||||||
|
instance = std::shared_ptr<ffmpeg_manager>(new ffmpeg_manager());
|
||||||
|
winst = instance;
|
||||||
}
|
}
|
||||||
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ffmpeg_manager::finalize()
|
static std::shared_ptr<ffmpeg_manager> loader_instance;
|
||||||
{
|
|
||||||
_ffmepg_encoder_factory_instance.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<ffmpeg_manager> ffmpeg_manager::get()
|
static auto loader = streamfx::loader(
|
||||||
{
|
[]() { // Initalizer
|
||||||
return _ffmepg_encoder_factory_instance;
|
loader_instance = ffmpeg_manager::instance();
|
||||||
}
|
},
|
||||||
|
[]() { // Finalizer
|
||||||
|
loader_instance.reset();
|
||||||
|
},
|
||||||
|
streamfx::loader_priority::NORMAL);
|
||||||
|
|
|
||||||
|
|
@ -160,6 +160,6 @@ namespace streamfx::encoder::ffmpeg {
|
||||||
|
|
||||||
static void finalize();
|
static void finalize();
|
||||||
|
|
||||||
static std::shared_ptr<ffmpeg_manager> get();
|
static std::shared_ptr<ffmpeg_manager> instance();
|
||||||
};
|
};
|
||||||
} // namespace streamfx::encoder::ffmpeg
|
} // namespace streamfx::encoder::ffmpeg
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,6 @@
|
||||||
#ifdef ENABLE_ENCODER_AOM_AV1
|
#ifdef ENABLE_ENCODER_AOM_AV1
|
||||||
#include "encoders/encoder-aom-av1.hpp"
|
#include "encoders/encoder-aom-av1.hpp"
|
||||||
#endif
|
#endif
|
||||||
#ifdef ENABLE_ENCODER_FFMPEG
|
|
||||||
#include "encoders/encoder-ffmpeg.hpp"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef ENABLE_FILTER_AUTOFRAMING
|
#ifdef ENABLE_FILTER_AUTOFRAMING
|
||||||
#include "filters/filter-autoframing.hpp"
|
#include "filters/filter-autoframing.hpp"
|
||||||
|
|
@ -158,10 +155,6 @@ MODULE_EXPORT bool obs_module_load(void)
|
||||||
{
|
{
|
||||||
#ifdef ENABLE_ENCODER_AOM_AV1
|
#ifdef ENABLE_ENCODER_AOM_AV1
|
||||||
streamfx::encoder::aom::av1::aom_av1_factory::initialize();
|
streamfx::encoder::aom::av1::aom_av1_factory::initialize();
|
||||||
#endif
|
|
||||||
#ifdef ENABLE_ENCODER_FFMPEG
|
|
||||||
using namespace streamfx::encoder::ffmpeg;
|
|
||||||
ffmpeg_manager::initialize();
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -301,9 +294,6 @@ MODULE_EXPORT void obs_module_unload(void)
|
||||||
|
|
||||||
// Encoders
|
// Encoders
|
||||||
{
|
{
|
||||||
#ifdef ENABLE_ENCODER_FFMPEG
|
|
||||||
streamfx::encoder::ffmpeg::ffmpeg_manager::finalize();
|
|
||||||
#endif
|
|
||||||
#ifdef ENABLE_ENCODER_AOM_AV1
|
#ifdef ENABLE_ENCODER_AOM_AV1
|
||||||
streamfx::encoder::aom::av1::aom_av1_factory::finalize();
|
streamfx::encoder::aom::av1::aom_av1_factory::finalize();
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue