plugin: Implement support for initializers and finalizers
This commit is contained in:
+42
-30
@@ -31,44 +31,56 @@ extern "C" {
|
|||||||
#pragma warning(pop)
|
#pragma warning(pop)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initializers and finalizers.
|
||||||
|
std::list<std::function<void()>> obsffmpeg::initializers;
|
||||||
|
|
||||||
|
std::list<std::function<void()>> obsffmpeg::finalizers;
|
||||||
|
|
||||||
static std::map<AVCodec*, std::shared_ptr<encoder::generic_factory>> generic_factories;
|
static std::map<AVCodec*, std::shared_ptr<encoder::generic_factory>> generic_factories;
|
||||||
|
|
||||||
MODULE_EXPORT bool obs_module_load(void)
|
MODULE_EXPORT bool obs_module_load(void)
|
||||||
{
|
try {
|
||||||
try {
|
// Initialize avcodec.
|
||||||
avcodec_register_all();
|
avcodec_register_all();
|
||||||
|
|
||||||
// Register all codecs.
|
// Run all initializers.
|
||||||
AVCodec* cdc = nullptr;
|
for (auto func : obsffmpeg::initializers) {
|
||||||
while ((cdc = av_codec_next(cdc)) != nullptr) {
|
func();
|
||||||
if (!av_codec_is_encoder(cdc))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if ((cdc->type == AVMediaType::AVMEDIA_TYPE_AUDIO)
|
|
||||||
|| (cdc->type == AVMediaType::AVMEDIA_TYPE_VIDEO)) {
|
|
||||||
auto ptr = std::make_shared<encoder::generic_factory>(cdc);
|
|
||||||
ptr->register_encoder();
|
|
||||||
generic_factories.emplace(cdc, ptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
obsffmpeg::encoder::prores_aw::initialize();
|
|
||||||
return true;
|
|
||||||
} catch (std::exception ex) {
|
|
||||||
PLOG_ERROR("Exception during initalization: %s.", ex.what());
|
|
||||||
} catch (...) {
|
|
||||||
PLOG_ERROR("Unrecognized exception during initalization.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Register all codecs.
|
||||||
|
AVCodec* cdc = nullptr;
|
||||||
|
while ((cdc = av_codec_next(cdc)) != nullptr) {
|
||||||
|
if (!av_codec_is_encoder(cdc))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if ((cdc->type == AVMediaType::AVMEDIA_TYPE_AUDIO) || (cdc->type == AVMediaType::AVMEDIA_TYPE_VIDEO)) {
|
||||||
|
auto ptr = std::make_shared<encoder::generic_factory>(cdc);
|
||||||
|
ptr->register_encoder();
|
||||||
|
generic_factories.emplace(cdc, ptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
obsffmpeg::encoder::prores_aw::initialize();
|
||||||
|
return true;
|
||||||
|
} catch (std::exception ex) {
|
||||||
|
PLOG_ERROR("Exception during initalization: %s.", ex.what());
|
||||||
|
return false;
|
||||||
|
} catch (...) {
|
||||||
|
PLOG_ERROR("Unrecognized exception during initalization.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
MODULE_EXPORT void obs_module_unload(void)
|
MODULE_EXPORT void obs_module_unload(void)
|
||||||
{
|
try {
|
||||||
try {
|
obsffmpeg::encoder::prores_aw::finalize();
|
||||||
obsffmpeg::encoder::prores_aw::finalize();
|
|
||||||
} catch (std::exception ex) {
|
// Run all finalizers.
|
||||||
PLOG_ERROR("Exception during finalizing: %s.", ex.what());
|
for (auto func : obsffmpeg::finalizers) {
|
||||||
} catch (...) {
|
func();
|
||||||
PLOG_ERROR("Unrecognized exception during finalizing.");
|
|
||||||
}
|
}
|
||||||
|
} catch (std::exception ex) {
|
||||||
|
PLOG_ERROR("Exception during finalizing: %s.", ex.what());
|
||||||
|
} catch (...) {
|
||||||
|
PLOG_ERROR("Unrecognized exception during finalizing.");
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-5
@@ -1,5 +1,5 @@
|
|||||||
// FFMPEG Video Encoder Integration for OBS Studio
|
// FFMPEG Video Encoder Integration for OBS Studio
|
||||||
// Copyright (C) 2018 - 2018 Michael Fabian Dirks
|
// Copyright (C) 2018 - 2019 Michael Fabian Dirks
|
||||||
//
|
//
|
||||||
// This program is free software; you can redistribute it and/or modify
|
// This program is free software; you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU General Public License as published by
|
// it under the terms of the GNU General Public License as published by
|
||||||
@@ -15,16 +15,18 @@
|
|||||||
// along with this program; if not, write to the Free Software
|
// along with this program; if not, write to the Free Software
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||||
|
|
||||||
#ifndef OBS_FFMPEG_PLUGIN_HPP
|
|
||||||
#define OBS_FFMPEG_PLUGIN_HPP
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <memory>
|
||||||
|
#include <obs-module.h>
|
||||||
|
|
||||||
namespace obsffmpeg {
|
namespace obsffmpeg {
|
||||||
|
extern std::list<std::function<void()>> initializers;
|
||||||
|
|
||||||
|
extern std::list<std::function<void()>> finalizers;
|
||||||
|
|
||||||
} // namespace obsffmpeg
|
} // namespace obsffmpeg
|
||||||
|
|
||||||
#endif OBS_FFMPEG_PLUGIN_HPP
|
MODULE_EXPORT bool obs_module_load(void);
|
||||||
|
MODULE_EXPORT void obs_module_unload(void);
|
||||||
|
|||||||
Reference in New Issue
Block a user