code: Migrate encoder::ffmpeg::prores_aw to new loader

This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2023-05-16 01:13:16 +02:00 committed by Xaymar
parent 376a3d6233
commit 0fb670eba4
2 changed files with 58 additions and 63 deletions

View file

@ -2,7 +2,7 @@
// Copyright (C) 2020-2023 Michael Fabian 'Xaymar' Dirks <info@xaymar.com>
// AUTOGENERATED COPYRIGHT HEADER END
#include "prores_aw_handler.hpp"
#include "prores_aw.hpp"
#include "common.hpp"
#include "../codecs/prores.hpp"
#include "ffmpeg/tools.hpp"
@ -12,34 +12,9 @@
#include <array>
#include "warning-enable.hpp"
using namespace streamfx::encoder::ffmpeg::handler;
using namespace streamfx::encoder::ffmpeg;
using namespace streamfx::encoder::codec::prores;
void prores_aw_handler::override_colorformat(AVPixelFormat& target_format, obs_data_t* settings, const AVCodec* codec, AVCodecContext*)
{
static const std::array<std::pair<profile, AVPixelFormat>, static_cast<size_t>(profile::_COUNT)> profile_to_format_map{
std::pair{profile::APCO, AV_PIX_FMT_YUV422P10}, std::pair{profile::APCS, AV_PIX_FMT_YUV422P10}, std::pair{profile::APCN, AV_PIX_FMT_YUV422P10}, std::pair{profile::APCH, AV_PIX_FMT_YUV422P10}, std::pair{profile::AP4H, AV_PIX_FMT_YUV444P10}, std::pair{profile::AP4X, AV_PIX_FMT_YUV444P10},
};
const int64_t profile_id = obs_data_get_int(settings, S_CODEC_PRORES_PROFILE);
for (auto kv : profile_to_format_map) {
if (kv.first == static_cast<profile>(profile_id)) {
target_format = kv.second;
break;
}
}
}
void prores_aw_handler::get_defaults(obs_data_t* settings, const AVCodec*, AVCodecContext*, bool)
{
obs_data_set_default_int(settings, S_CODEC_PRORES_PROFILE, 0);
}
bool prores_aw_handler::has_pixel_format_support(ffmpeg_factory* instance)
{
return false;
}
inline const char* profile_to_name(const AVProfile* ptr)
{
switch (static_cast<profile>(ptr->profile)) {
@ -60,11 +35,25 @@ inline const char* profile_to_name(const AVProfile* ptr)
}
}
void prores_aw_handler::get_properties(obs_properties_t* props, const AVCodec* codec, AVCodecContext* context, bool)
prores_aw::prores_aw() : handler("prores_aw") {}
prores_aw::~prores_aw() {}
bool prores_aw::has_keyframes(ffmpeg_factory* instance)
{
if (!context) {
return false;
}
void prores_aw::defaults(ffmpeg_factory* factory, obs_data_t* settings)
{
obs_data_set_default_int(settings, S_CODEC_PRORES_PROFILE, 0);
}
void prores_aw::properties(ffmpeg_factory* factory, ffmpeg_instance* instance, obs_properties_t* props)
{
if (!instance) {
auto p = obs_properties_add_list(props, S_CODEC_PRORES_PROFILE, D_TRANSLATE(S_CODEC_PRORES_PROFILE), OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT);
for (auto ptr = codec->profiles; ptr->profile != FF_PROFILE_UNKNOWN; ptr++) {
for (auto ptr = factory->get_avcodec()->profiles; ptr->profile != FF_PROFILE_UNKNOWN; ptr++) {
obs_property_list_add_int(p, profile_to_name(ptr), static_cast<int64_t>(ptr->profile));
}
} else {
@ -72,17 +61,19 @@ void prores_aw_handler::get_properties(obs_properties_t* props, const AVCodec* c
}
}
void prores_aw_handler::update(obs_data_t* settings, const AVCodec*, AVCodecContext* context)
void prores_aw::update(ffmpeg_factory* factory, ffmpeg_instance* instance, obs_data_t* settings)
{
context->profile = static_cast<int>(obs_data_get_int(settings, S_CODEC_PRORES_PROFILE));
if (instance) {
instance->get_avcodeccontext()->profile = static_cast<int>(obs_data_get_int(settings, S_CODEC_PRORES_PROFILE));
}
}
void prores_aw_handler::log_options(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context)
void prores_aw::log(ffmpeg_factory* factory, ffmpeg_instance* instance, obs_data_t* settings)
{
DLOG_INFO("[%s] Apple ProRes:", codec->name);
::streamfx::ffmpeg::tools::print_av_option_string(context, "profile", " Profile", [&codec](int64_t v) {
DLOG_INFO("[%s] Apple ProRes:", factory->get_avcodec()->name);
::streamfx::ffmpeg::tools::print_av_option_string(instance->get_avcodeccontext(), "profile", " Profile", [&factory, &instance](int64_t v) {
int val = static_cast<int>(v);
for (auto ptr = codec->profiles; (ptr->profile != FF_PROFILE_UNKNOWN) && (ptr != nullptr); ptr++) {
for (auto ptr = factory->get_avcodec()->profiles; (ptr->profile != FF_PROFILE_UNKNOWN) && (ptr != nullptr); ptr++) {
if (ptr->profile == val) {
return std::string(profile_to_name(ptr));
}
@ -91,7 +82,19 @@ void prores_aw_handler::log_options(obs_data_t* settings, const AVCodec* codec,
});
}
bool prores_aw_handler::has_keyframe_support(ffmpeg_factory* instance)
void prores_aw::override_colorformat(ffmpeg_factory* factory, ffmpeg_instance* instance, obs_data_t* settings, AVPixelFormat& target_format)
{
return false;
static const std::array<std::pair<profile, AVPixelFormat>, static_cast<size_t>(profile::_COUNT)> profile_to_format_map{
std::pair{profile::APCO, AV_PIX_FMT_YUV422P10}, std::pair{profile::APCS, AV_PIX_FMT_YUV422P10}, std::pair{profile::APCN, AV_PIX_FMT_YUV422P10}, std::pair{profile::APCH, AV_PIX_FMT_YUV422P10}, std::pair{profile::AP4H, AV_PIX_FMT_YUV444P10}, std::pair{profile::AP4X, AV_PIX_FMT_YUV444P10},
};
const int64_t profile_id = obs_data_get_int(settings, S_CODEC_PRORES_PROFILE);
for (auto kv : profile_to_format_map) {
if (kv.first == static_cast<profile>(profile_id)) {
target_format = kv.second;
break;
}
}
}
static auto inst = prores_aw();

View file

@ -3,40 +3,32 @@
// AUTOGENERATED COPYRIGHT HEADER END
#pragma once
#include "handler.hpp"
#include "encoders/encoder-ffmpeg.hpp"
#include "encoders/ffmpeg/handler.hpp"
extern "C" {
#include "warning-disable.hpp"
extern "C" {
#include <libavcodec/avcodec.h>
#include "warning-enable.hpp"
}
#include "warning-enable.hpp"
namespace streamfx::encoder::ffmpeg::handler {
class prores_aw_handler : public handler {
namespace streamfx::encoder::ffmpeg {
class prores_aw : public handler {
public:
virtual ~prores_aw_handler(){};
prores_aw();
virtual ~prores_aw();
public /*factory*/:
void get_defaults(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context, bool hw_encode) override;
virtual bool has_keyframes(ffmpeg_factory* factory);
virtual std::string_view get_help_url(const AVCodec* codec) override
{
virtual std::string help(ffmpeg_factory* factory) {
return "https://github.com/Xaymar/obs-StreamFX/wiki/Encoder-FFmpeg-Apple-ProRes";
};
}
public /*support tests*/:
bool has_pixel_format_support(ffmpeg_factory* instance) override;
virtual void defaults(ffmpeg_factory* factory, obs_data_t* settings);
virtual void properties(ffmpeg_factory* factory, ffmpeg_instance* instance, obs_properties_t* props);
virtual void update(ffmpeg_factory* factory, ffmpeg_instance* instance, obs_data_t* settings);
virtual void log(ffmpeg_factory* factory, ffmpeg_instance* instance, obs_data_t* settings);
bool has_keyframe_support(ffmpeg_factory* instance) override;
public /*settings*/:
void get_properties(obs_properties_t* props, const AVCodec* codec, AVCodecContext* context, bool hw_encode) override;
void update(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context) override;
void log_options(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context) override;
public /*instance*/:
void override_colorformat(AVPixelFormat& target_format, obs_data_t* settings, const AVCodec* codec, AVCodecContext* context) override;
virtual void override_colorformat(ffmpeg_factory* factory, ffmpeg_instance* instance, obs_data_t* settings, AVPixelFormat& target_format);
};
} // namespace streamfx::encoder::ffmpeg::handler
} // namespace streamfx::encoder::ffmpeg