ffmpeg: Apply coding guidelines

This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2021-06-08 04:12:55 +02:00
parent 67e122eb65
commit 4ead07c23a
18 changed files with 82 additions and 78 deletions

View file

@ -115,7 +115,7 @@ ffmpeg_instance::ffmpeg_instance(obs_data_t* settings, obs_encoder_t* self, bool
#ifdef WIN32 #ifdef WIN32
auto gctx = gs::context(); auto gctx = gs::context();
if (gs_get_device_type() == GS_DEVICE_DIRECT3D_11) { if (gs_get_device_type() == GS_DEVICE_DIRECT3D_11) {
_hwapi = std::make_shared<::ffmpeg::hwapi::d3d11>(); _hwapi = std::make_shared<::streamfx::ffmpeg::hwapi::d3d11>();
} }
#endif #endif
if (!_hwapi) { if (!_hwapi) {
@ -150,7 +150,7 @@ ffmpeg_instance::ffmpeg_instance(obs_data_t* settings, obs_encoder_t* self, bool
auto gctx = gs::context(); auto gctx = gs::context();
int res = avcodec_open2(_context, _codec, NULL); int res = avcodec_open2(_context, _codec, NULL);
if (res < 0) { if (res < 0) {
throw std::runtime_error(::ffmpeg::tools::get_error_description(res)); throw std::runtime_error(::streamfx::ffmpeg::tools::get_error_description(res));
} }
} }
@ -230,7 +230,7 @@ bool ffmpeg_instance::update(obs_data_t* settings)
} }
// Apply GPU Selection // Apply GPU Selection
if (!_hwinst && ::ffmpeg::tools::can_hardware_encode(_codec)) { if (!_hwinst && ::streamfx::ffmpeg::tools::can_hardware_encode(_codec)) {
av_opt_set_int(_context, "gpu", (int)obs_data_get_int(settings, ST_KEY_FFMPEG_GPU), AV_OPT_SEARCH_CHILDREN); av_opt_set_int(_context, "gpu", (int)obs_data_get_int(settings, ST_KEY_FFMPEG_GPU), AV_OPT_SEARCH_CHILDREN);
} }
@ -276,24 +276,26 @@ bool ffmpeg_instance::update(obs_data_t* settings)
DLOG_INFO("[%s] Custom Settings: %s", _codec->name, DLOG_INFO("[%s] Custom Settings: %s", _codec->name,
obs_data_get_string(settings, ST_KEY_FFMPEG_CUSTOMSETTINGS)); obs_data_get_string(settings, ST_KEY_FFMPEG_CUSTOMSETTINGS));
DLOG_INFO("[%s] Standard Compliance: %s", _codec->name, DLOG_INFO("[%s] Standard Compliance: %s", _codec->name,
::ffmpeg::tools::get_std_compliance_name(_context->strict_std_compliance)); ::streamfx::ffmpeg::tools::get_std_compliance_name(_context->strict_std_compliance));
DLOG_INFO("[%s] Threading: %s (with %i threads)", _codec->name, DLOG_INFO("[%s] Threading: %s (with %i threads)", _codec->name,
::ffmpeg::tools::get_thread_type_name(_context->thread_type), _context->thread_count); ::streamfx::ffmpeg::tools::get_thread_type_name(_context->thread_type), _context->thread_count);
DLOG_INFO("[%s] Video:", _codec->name); DLOG_INFO("[%s] Video:", _codec->name);
if (_hwinst) { if (_hwinst) {
DLOG_INFO("[%s] Texture: %" PRId32 "x%" PRId32 " %s %s %s", _codec->name, _context->width, DLOG_INFO("[%s] Texture: %" PRId32 "x%" PRId32 " %s %s %s", _codec->name, _context->width,
_context->height, ::ffmpeg::tools::get_pixel_format_name(_context->sw_pix_fmt), _context->height, ::streamfx::ffmpeg::tools::get_pixel_format_name(_context->sw_pix_fmt),
::ffmpeg::tools::get_color_space_name(_context->colorspace), ::streamfx::ffmpeg::tools::get_color_space_name(_context->colorspace),
av_color_range_name(_context->color_range)); av_color_range_name(_context->color_range));
} else { } else {
DLOG_INFO("[%s] Input: %" PRId32 "x%" PRId32 " %s %s %s", _codec->name, _scaler.get_source_width(), DLOG_INFO("[%s] Input: %" PRId32 "x%" PRId32 " %s %s %s", _codec->name, _scaler.get_source_width(),
_scaler.get_source_height(), ::ffmpeg::tools::get_pixel_format_name(_scaler.get_source_format()), _scaler.get_source_height(),
::ffmpeg::tools::get_color_space_name(_scaler.get_source_colorspace()), ::streamfx::ffmpeg::tools::get_pixel_format_name(_scaler.get_source_format()),
::streamfx::ffmpeg::tools::get_color_space_name(_scaler.get_source_colorspace()),
_scaler.is_source_full_range() ? "Full" : "Partial"); _scaler.is_source_full_range() ? "Full" : "Partial");
DLOG_INFO("[%s] Output: %" PRId32 "x%" PRId32 " %s %s %s", _codec->name, _scaler.get_target_width(), DLOG_INFO("[%s] Output: %" PRId32 "x%" PRId32 " %s %s %s", _codec->name, _scaler.get_target_width(),
_scaler.get_target_height(), ::ffmpeg::tools::get_pixel_format_name(_scaler.get_target_format()), _scaler.get_target_height(),
::ffmpeg::tools::get_color_space_name(_scaler.get_target_colorspace()), ::streamfx::ffmpeg::tools::get_pixel_format_name(_scaler.get_target_format()),
::streamfx::ffmpeg::tools::get_color_space_name(_scaler.get_target_colorspace()),
_scaler.is_target_full_range() ? "Full" : "Partial"); _scaler.is_target_full_range() ? "Full" : "Partial");
if (!_hwinst) if (!_hwinst)
DLOG_INFO("[%s] On GPU Index: %lli", _codec->name, obs_data_get_int(settings, ST_KEY_FFMPEG_GPU)); DLOG_INFO("[%s] On GPU Index: %lli", _codec->name, obs_data_get_int(settings, ST_KEY_FFMPEG_GPU));
@ -372,8 +374,8 @@ bool ffmpeg_instance::encode_video(struct encoder_frame* frame, struct encoder_p
int res = _scaler.convert(reinterpret_cast<uint8_t**>(frame->data), reinterpret_cast<int*>(frame->linesize), int res = _scaler.convert(reinterpret_cast<uint8_t**>(frame->data), reinterpret_cast<int*>(frame->linesize),
0, _context->height, vframe->data, vframe->linesize); 0, _context->height, vframe->data, vframe->linesize);
if (res <= 0) { if (res <= 0) {
DLOG_ERROR("Failed to convert frame: %s (%" PRId32 ").", ::ffmpeg::tools::get_error_description(res), DLOG_ERROR("Failed to convert frame: %s (%" PRId32 ").",
res); ::streamfx::ffmpeg::tools::get_error_description(res), res);
return false; return false;
} }
} }
@ -422,13 +424,13 @@ void ffmpeg_instance::initialize_sw(obs_data_t* settings)
auto voi = video_output_get_info(obs_encoder_video(_self)); auto voi = video_output_get_info(obs_encoder_video(_self));
// Find a suitable Pixel Format. // Find a suitable Pixel Format.
AVPixelFormat _pixfmt_source = ::ffmpeg::tools::obs_videoformat_to_avpixelformat(voi->format); AVPixelFormat _pixfmt_source = ::streamfx::ffmpeg::tools::obs_videoformat_to_avpixelformat(voi->format);
AVPixelFormat _pixfmt_target = AVPixelFormat _pixfmt_target =
static_cast<AVPixelFormat>(obs_data_get_int(settings, ST_KEY_FFMPEG_COLORFORMAT)); static_cast<AVPixelFormat>(obs_data_get_int(settings, ST_KEY_FFMPEG_COLORFORMAT));
if (_pixfmt_target == AV_PIX_FMT_NONE) { if (_pixfmt_target == AV_PIX_FMT_NONE) {
// Find the best conversion format. // Find the best conversion format.
if (_codec->pix_fmts) { if (_codec->pix_fmts) {
_pixfmt_target = ::ffmpeg::tools::get_least_lossy_format(_codec->pix_fmts, _pixfmt_source); _pixfmt_target = ::streamfx::ffmpeg::tools::get_least_lossy_format(_codec->pix_fmts, _pixfmt_source);
} else { // If there are no supported formats, just pass in the current one. } else { // If there are no supported formats, just pass in the current one.
_pixfmt_target = _pixfmt_source; _pixfmt_target = _pixfmt_source;
} }
@ -446,14 +448,14 @@ void ffmpeg_instance::initialize_sw(obs_data_t* settings)
if (!is_format_supported) { if (!is_format_supported) {
std::stringstream sstr; std::stringstream sstr;
sstr << "Color Format '" << ::ffmpeg::tools::get_pixel_format_name(_pixfmt_target) sstr << "Color Format '" << ::streamfx::ffmpeg::tools::get_pixel_format_name(_pixfmt_target)
<< "' is not supported by the encoder."; << "' is not supported by the encoder.";
throw std::runtime_error(sstr.str().c_str()); throw std::runtime_error(sstr.str().c_str());
} }
} }
// Setup from OBS information. // Setup from OBS information.
::ffmpeg::tools::context_setup_from_obs(voi, _context); ::streamfx::ffmpeg::tools::context_setup_from_obs(voi, _context);
// Override with other information. // Override with other information.
_context->width = static_cast<int>(obs_encoder_get_width(_self)); _context->width = static_cast<int>(obs_encoder_get_width(_self));
@ -477,9 +479,10 @@ void ffmpeg_instance::initialize_sw(obs_data_t* settings)
if (!_scaler.initialize(SWS_POINT)) { if (!_scaler.initialize(SWS_POINT)) {
std::stringstream sstr; std::stringstream sstr;
sstr << "Initializing scaler failed for conversion from '" sstr << "Initializing scaler failed for conversion from '"
<< ::ffmpeg::tools::get_pixel_format_name(_scaler.get_source_format()) << "' to '" << ::streamfx::ffmpeg::tools::get_pixel_format_name(_scaler.get_source_format()) << "' to '"
<< ::ffmpeg::tools::get_pixel_format_name(_scaler.get_target_format()) << "' with color space '" << ::streamfx::ffmpeg::tools::get_pixel_format_name(_scaler.get_target_format())
<< ::ffmpeg::tools::get_color_space_name(_scaler.get_source_colorspace()) << "' and " << "' with color space '"
<< ::streamfx::ffmpeg::tools::get_color_space_name(_scaler.get_source_colorspace()) << "' and "
<< (_scaler.is_source_full_range() ? "full" : "partial") << " range."; << (_scaler.is_source_full_range() ? "full" : "partial") << " range.";
throw std::runtime_error(sstr.str()); throw std::runtime_error(sstr.str());
} }
@ -495,7 +498,7 @@ void ffmpeg_instance::initialize_hw(obs_data_t*)
const video_output_info* voi = video_output_get_info(obs_encoder_video(_self)); const video_output_info* voi = video_output_get_info(obs_encoder_video(_self));
// Apply pixel format settings. // Apply pixel format settings.
::ffmpeg::tools::context_setup_from_obs(voi, _context); ::streamfx::ffmpeg::tools::context_setup_from_obs(voi, _context);
_context->sw_pix_fmt = _context->pix_fmt; _context->sw_pix_fmt = _context->pix_fmt;
_context->pix_fmt = AV_PIX_FMT_D3D11; _context->pix_fmt = AV_PIX_FMT_D3D11;
@ -516,7 +519,7 @@ void ffmpeg_instance::initialize_hw(obs_data_t*)
std::array<char, 2048> buffer; std::array<char, 2048> buffer;
size_t len = static_cast<size_t>(snprintf(buffer.data(), buffer.size(), size_t len = static_cast<size_t>(snprintf(buffer.data(), buffer.size(),
"Initializing hardware context failed with error: %s (%" PRIu32 ")", "Initializing hardware context failed with error: %s (%" PRIu32 ")",
::ffmpeg::tools::get_error_description(res), res)); ::streamfx::ffmpeg::tools::get_error_description(res), res));
throw std::runtime_error(std::string(buffer.data(), buffer.data() + len)); throw std::runtime_error(std::string(buffer.data(), buffer.data() + len));
} }
#endif #endif
@ -557,7 +560,7 @@ std::shared_ptr<AVFrame> ffmpeg_instance::pop_free_frame()
int res = av_frame_get_buffer(frame.get(), 32); int res = av_frame_get_buffer(frame.get(), 32);
if (res < 0) { if (res < 0) {
throw std::runtime_error(::ffmpeg::tools::get_error_description(res)); throw std::runtime_error(::streamfx::ffmpeg::tools::get_error_description(res));
} }
} }
} }
@ -601,7 +604,7 @@ void ffmpeg_instance::get_video_info(struct video_scale_info* info)
{ {
if (!is_hardware_encode()) { if (!is_hardware_encode()) {
// Override input with supported format if software encode. // Override input with supported format if software encode.
info->format = ::ffmpeg::tools::avpixelformat_to_obs_videoformat(_scaler.get_source_format()); info->format = ::streamfx::ffmpeg::tools::avpixelformat_to_obs_videoformat(_scaler.get_source_format());
} }
} }
@ -720,8 +723,8 @@ bool ffmpeg_instance::encode_avframe(std::shared_ptr<AVFrame> frame, encoder_pac
sent_frame = true; sent_frame = true;
break; break;
default: default:
DLOG_ERROR("Failed to encode frame: %s (%" PRId32 ").", ::ffmpeg::tools::get_error_description(res), DLOG_ERROR("Failed to encode frame: %s (%" PRId32 ").",
res); ::streamfx::ffmpeg::tools::get_error_description(res), res);
return false; return false;
} }
} }
@ -746,8 +749,8 @@ bool ffmpeg_instance::encode_avframe(std::shared_ptr<AVFrame> frame, encoder_pac
} }
break; break;
default: default:
DLOG_ERROR("Failed to receive packet: %s (%" PRId32 ").", ::ffmpeg::tools::get_error_description(res), DLOG_ERROR("Failed to receive packet: %s (%" PRId32 ").",
res); ::streamfx::ffmpeg::tools::get_error_description(res), res);
return false; return false;
} }
} }
@ -895,7 +898,7 @@ void ffmpeg_instance::parse_ffmpeg_commandline(std::string text)
int res = av_opt_set(_context, key.c_str(), value.c_str(), AV_OPT_SEARCH_CHILDREN); int res = av_opt_set(_context, key.c_str(), value.c_str(), AV_OPT_SEARCH_CHILDREN);
if (res < 0) { if (res < 0) {
DLOG_WARNING("Option '%s' (key: '%s', value: '%s') encountered error: %s", opt.c_str(), key.c_str(), DLOG_WARNING("Option '%s' (key: '%s', value: '%s') encountered error: %s", opt.c_str(), key.c_str(),
value.c_str(), ::ffmpeg::tools::get_error_description(res)); value.c_str(), ::streamfx::ffmpeg::tools::get_error_description(res));
} }
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
DLOG_ERROR("Option '%s' encountered exception: %s", opt.c_str(), ex.what()); DLOG_ERROR("Option '%s' encountered exception: %s", opt.c_str(), ex.what());
@ -1091,7 +1094,8 @@ obs_properties_t* ffmpeg_factory::get_properties2(instance_t* data)
OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT); OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT);
obs_property_list_add_int(p, D_TRANSLATE(S_STATE_AUTOMATIC), static_cast<int64_t>(AV_PIX_FMT_NONE)); obs_property_list_add_int(p, D_TRANSLATE(S_STATE_AUTOMATIC), static_cast<int64_t>(AV_PIX_FMT_NONE));
for (auto ptr = _avcodec->pix_fmts; *ptr != AV_PIX_FMT_NONE; ptr++) { for (auto ptr = _avcodec->pix_fmts; *ptr != AV_PIX_FMT_NONE; ptr++) {
obs_property_list_add_int(p, ::ffmpeg::tools::get_pixel_format_name(*ptr), static_cast<int64_t>(*ptr)); obs_property_list_add_int(p, ::streamfx::ffmpeg::tools::get_pixel_format_name(*ptr),
static_cast<int64_t>(*ptr));
} }
} }

View file

@ -57,11 +57,11 @@ namespace streamfx::encoder::ffmpeg {
std::shared_ptr<handler::handler> _handler; std::shared_ptr<handler::handler> _handler;
::ffmpeg::swscale _scaler; ::streamfx::ffmpeg::swscale _scaler;
AVPacket _packet; AVPacket _packet;
std::shared_ptr<::ffmpeg::hwapi::base> _hwapi; std::shared_ptr<::streamfx::ffmpeg::hwapi::base> _hwapi;
std::shared_ptr<::ffmpeg::hwapi::instance> _hwinst; std::shared_ptr<::streamfx::ffmpeg::hwapi::instance> _hwinst;
std::size_t _lag_in_frames; std::size_t _lag_in_frames;
std::size_t _sent_frames; std::size_t _sent_frames;

View file

@ -131,10 +131,10 @@ void amf_h264_handler::log_options(obs_data_t* settings, const AVCodec* codec, A
amf::log_options(settings, codec, context); amf::log_options(settings, codec, context);
DLOG_INFO("[%s] H.264/AVC:", codec->name); DLOG_INFO("[%s] H.264/AVC:", codec->name);
::ffmpeg::tools::print_av_option_string2(context, context->priv_data, "profile", " Profile", ::streamfx::ffmpeg::tools::print_av_option_string2(context, context->priv_data, "profile", " Profile",
[](int64_t v, std::string_view o) { return std::string(o); }); [](int64_t v, std::string_view o) { return std::string(o); });
::ffmpeg::tools::print_av_option_string2(context, context->priv_data, "level", " Level", ::streamfx::ffmpeg::tools::print_av_option_string2(context, context->priv_data, "level", " Level",
[](int64_t v, std::string_view o) { return std::string(o); }); [](int64_t v, std::string_view o) { return std::string(o); });
} }
void amf_h264_handler::get_encoder_properties(obs_properties_t* props, const AVCodec* codec) void amf_h264_handler::get_encoder_properties(obs_properties_t* props, const AVCodec* codec)

View file

@ -138,12 +138,12 @@ void amf_hevc_handler::log_options(obs_data_t* settings, const AVCodec* codec, A
amf::log_options(settings, codec, context); amf::log_options(settings, codec, context);
DLOG_INFO("[%s] H.265/HEVC:", codec->name); DLOG_INFO("[%s] H.265/HEVC:", codec->name);
::ffmpeg::tools::print_av_option_string2(context, "profile", " Profile", ::streamfx::ffmpeg::tools::print_av_option_string2(context, "profile", " Profile",
[](int64_t v, std::string_view o) { return std::string(o); }); [](int64_t v, std::string_view o) { return std::string(o); });
::ffmpeg::tools::print_av_option_string2(context, "level", " Level", ::streamfx::ffmpeg::tools::print_av_option_string2(context, "level", " Level",
[](int64_t v, std::string_view o) { return std::string(o); }); [](int64_t v, std::string_view o) { return std::string(o); });
::ffmpeg::tools::print_av_option_string2(context, "tier", " Tier", ::streamfx::ffmpeg::tools::print_av_option_string2(context, "tier", " Tier",
[](int64_t v, std::string_view o) { return std::string(o); }); [](int64_t v, std::string_view o) { return std::string(o); });
} }
void amf_hevc_handler::get_encoder_properties(obs_properties_t* props, const AVCodec* codec) void amf_hevc_handler::get_encoder_properties(obs_properties_t* props, const AVCodec* codec)

View file

@ -425,7 +425,7 @@ void amf::update(obs_data_t* settings, const AVCodec* codec, AVCodecContext* con
void amf::log_options(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context) void amf::log_options(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context)
{ {
using namespace ::ffmpeg; using namespace ::streamfx::ffmpeg;
DLOG_INFO("[%s] AMD AMF:", codec->name); DLOG_INFO("[%s] AMD AMF:", codec->name);
tools::print_av_option_string2(context, "usage", " Usage", tools::print_av_option_string2(context, "usage", " Usage",

View file

@ -134,10 +134,10 @@ void nvenc_h264_handler::log_options(obs_data_t* settings, const AVCodec* codec,
nvenc::log_options(settings, codec, context); nvenc::log_options(settings, codec, context);
DLOG_INFO("[%s] H.264/AVC:", codec->name); DLOG_INFO("[%s] H.264/AVC:", codec->name);
::ffmpeg::tools::print_av_option_string2(context, context->priv_data, "profile", " Profile", ::streamfx::ffmpeg::tools::print_av_option_string2(context, context->priv_data, "profile", " Profile",
[](int64_t v, std::string_view o) { return std::string(o); }); [](int64_t v, std::string_view o) { return std::string(o); });
::ffmpeg::tools::print_av_option_string2(context, context->priv_data, "level", " Level", ::streamfx::ffmpeg::tools::print_av_option_string2(context, context->priv_data, "level", " Level",
[](int64_t v, std::string_view o) { return std::string(o); }); [](int64_t v, std::string_view o) { return std::string(o); });
} }
void nvenc_h264_handler::get_encoder_properties(obs_properties_t* props, const AVCodec* codec) void nvenc_h264_handler::get_encoder_properties(obs_properties_t* props, const AVCodec* codec)

View file

@ -140,12 +140,12 @@ void nvenc_hevc_handler::log_options(obs_data_t* settings, const AVCodec* codec,
nvenc::log_options(settings, codec, context); nvenc::log_options(settings, codec, context);
DLOG_INFO("[%s] H.265/HEVC:", codec->name); DLOG_INFO("[%s] H.265/HEVC:", codec->name);
::ffmpeg::tools::print_av_option_string2(context, "profile", " Profile", ::streamfx::ffmpeg::tools::print_av_option_string2(context, "profile", " Profile",
[](int64_t v, std::string_view o) { return std::string(o); }); [](int64_t v, std::string_view o) { return std::string(o); });
::ffmpeg::tools::print_av_option_string2(context, "level", " Level", ::streamfx::ffmpeg::tools::print_av_option_string2(context, "level", " Level",
[](int64_t v, std::string_view o) { return std::string(o); }); [](int64_t v, std::string_view o) { return std::string(o); });
::ffmpeg::tools::print_av_option_string2(context, "tier", " Tier", ::streamfx::ffmpeg::tools::print_av_option_string2(context, "tier", " Tier",
[](int64_t v, std::string_view o) { return std::string(o); }); [](int64_t v, std::string_view o) { return std::string(o); });
} }
void nvenc_hevc_handler::get_encoder_properties(obs_properties_t* props, const AVCodec* codec) void nvenc_hevc_handler::get_encoder_properties(obs_properties_t* props, const AVCodec* codec)

View file

@ -695,7 +695,7 @@ void nvenc::update(obs_data_t* settings, const AVCodec* codec, AVCodecContext* c
void nvenc::log_options(obs_data_t*, const AVCodec* codec, AVCodecContext* context) void nvenc::log_options(obs_data_t*, const AVCodec* codec, AVCodecContext* context)
{ {
using namespace ::ffmpeg; using namespace ::streamfx::ffmpeg;
DLOG_INFO("[%s] NVIDIA NVENC:", codec->name); DLOG_INFO("[%s] NVIDIA NVENC:", codec->name);
tools::print_av_option_string2(context, "preset", " Preset", tools::print_av_option_string2(context, "preset", " Preset",

View file

@ -102,7 +102,7 @@ void prores_aw_handler::update(obs_data_t* settings, const AVCodec*, AVCodecCont
void prores_aw_handler::log_options(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context) void prores_aw_handler::log_options(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context)
{ {
DLOG_INFO("[%s] Apple ProRes:", codec->name); DLOG_INFO("[%s] Apple ProRes:", codec->name);
::ffmpeg::tools::print_av_option_string(context, "profile", " Profile", [&codec](int64_t v) { ::streamfx::ffmpeg::tools::print_av_option_string(context, "profile", " Profile", [&codec](int64_t v) {
int val = static_cast<int>(v); int val = static_cast<int>(v);
for (auto ptr = codec->profiles; (ptr->profile != FF_PROFILE_UNKNOWN) && (ptr != nullptr); ptr++) { for (auto ptr = codec->profiles; (ptr->profile != FF_PROFILE_UNKNOWN) && (ptr != nullptr); ptr++) {
if (ptr->profile == val) { if (ptr->profile == val) {

View file

@ -22,7 +22,7 @@
#include "avframe-queue.hpp" #include "avframe-queue.hpp"
#include "tools.hpp" #include "tools.hpp"
using namespace ffmpeg; using namespace streamfx::ffmpeg;
std::shared_ptr<AVFrame> avframe_queue::create_frame() std::shared_ptr<AVFrame> avframe_queue::create_frame()
{ {

View file

@ -35,7 +35,7 @@ extern "C" {
#endif #endif
} }
namespace ffmpeg { namespace streamfx::ffmpeg {
class avframe_queue { class avframe_queue {
std::deque<std::shared_ptr<AVFrame>> _frames; std::deque<std::shared_ptr<AVFrame>> _frames;
std::mutex _lock; std::mutex _lock;
@ -71,4 +71,4 @@ namespace ffmpeg {
std::size_t size(); std::size_t size();
}; };
} // namespace ffmpeg } // namespace streamfx::ffmpeg

View file

@ -36,7 +36,7 @@ extern "C" {
#endif #endif
} }
namespace ffmpeg::hwapi { namespace streamfx::ffmpeg::hwapi {
struct device { struct device {
std::pair<int64_t, int64_t> id; std::pair<int64_t, int64_t> id;
std::string name; std::string name;
@ -67,4 +67,4 @@ namespace ffmpeg::hwapi {
virtual std::shared_ptr<hwapi::instance> create_from_obs() = 0; virtual std::shared_ptr<hwapi::instance> create_from_obs() = 0;
}; };
} // namespace ffmpeg::hwapi } // namespace streamfx::ffmpeg::hwapi

View file

@ -37,7 +37,7 @@ extern "C" {
#pragma warning(pop) #pragma warning(pop)
} }
using namespace ffmpeg::hwapi; using namespace streamfx::ffmpeg::hwapi;
d3d11::d3d11() : _dxgi_module(0), _d3d11_module(0) d3d11::d3d11() : _dxgi_module(0), _d3d11_module(0)
{ {

View file

@ -34,8 +34,8 @@
#pragma warning(pop) #pragma warning(pop)
#endif #endif
namespace ffmpeg::hwapi { namespace streamfx::ffmpeg::hwapi {
class d3d11 : public ffmpeg::hwapi::base { class d3d11 : public streamfx::ffmpeg::hwapi::base {
typedef HRESULT(__stdcall* CreateDXGIFactory_t)(REFIID, void**); typedef HRESULT(__stdcall* CreateDXGIFactory_t)(REFIID, void**);
typedef HRESULT(__stdcall* CreateDXGIFactory1_t)(REFIID, void**); typedef HRESULT(__stdcall* CreateDXGIFactory1_t)(REFIID, void**);
typedef HRESULT(__stdcall* D3D11CreateDevice_t)(IDXGIAdapter*, D3D_DRIVER_TYPE, HMODULE, UINT, typedef HRESULT(__stdcall* D3D11CreateDevice_t)(IDXGIAdapter*, D3D_DRIVER_TYPE, HMODULE, UINT,
@ -62,7 +62,7 @@ namespace ffmpeg::hwapi {
virtual std::shared_ptr<hwapi::instance> create_from_obs() override; virtual std::shared_ptr<hwapi::instance> create_from_obs() override;
}; };
class d3d11_instance : public ffmpeg::hwapi::instance { class d3d11_instance : public streamfx::ffmpeg::hwapi::instance {
ATL::CComPtr<ID3D11Device> _device; ATL::CComPtr<ID3D11Device> _device;
ATL::CComPtr<ID3D11DeviceContext> _context; ATL::CComPtr<ID3D11DeviceContext> _context;
@ -80,4 +80,4 @@ namespace ffmpeg::hwapi {
virtual std::shared_ptr<AVFrame> avframe_from_obs(AVBufferRef* frames, uint32_t handle, uint64_t lock_key, virtual std::shared_ptr<AVFrame> avframe_from_obs(AVBufferRef* frames, uint32_t handle, uint64_t lock_key,
uint64_t* next_lock_key) override; uint64_t* next_lock_key) override;
}; };
} // namespace ffmpeg::hwapi } // namespace streamfx::ffmpeg::hwapi

View file

@ -22,7 +22,7 @@
#include "swscale.hpp" #include "swscale.hpp"
#include <stdexcept> #include <stdexcept>
using namespace ffmpeg; using namespace streamfx::ffmpeg;
swscale::swscale() {} swscale::swscale() {}

View file

@ -35,7 +35,7 @@ extern "C" {
#endif #endif
} }
namespace ffmpeg { namespace streamfx::ffmpeg {
class swscale { class swscale {
std::pair<uint32_t, uint32_t> source_size; std::pair<uint32_t, uint32_t> source_size;
AVPixelFormat source_format = AV_PIX_FMT_NONE; AVPixelFormat source_format = AV_PIX_FMT_NONE;
@ -85,4 +85,4 @@ namespace ffmpeg {
int32_t convert(const uint8_t* const source_data[], const int source_stride[], int32_t source_row, int32_t convert(const uint8_t* const source_data[], const int source_stride[], int32_t source_row,
int32_t source_rows, uint8_t* const target_data[], const int target_stride[]); int32_t source_rows, uint8_t* const target_data[], const int target_stride[]);
}; };
} // namespace ffmpeg } // namespace streamfx::ffmpeg

View file

@ -34,7 +34,7 @@ extern "C" {
#pragma warning(pop) #pragma warning(pop)
} }
using namespace ffmpeg; using namespace streamfx::ffmpeg;
const char* tools::get_pixel_format_name(AVPixelFormat v) const char* tools::get_pixel_format_name(AVPixelFormat v)
{ {
@ -154,7 +154,7 @@ AVColorSpace tools::obs_to_av_color_space(video_colorspace v)
} }
} }
AVColorPrimaries ffmpeg::tools::obs_to_av_color_primary(video_colorspace v) AVColorPrimaries streamfx::ffmpeg::tools::obs_to_av_color_primary(video_colorspace v)
{ {
switch (v) { switch (v) {
case VIDEO_CS_601: // BT.601 case VIDEO_CS_601: // BT.601
@ -168,7 +168,7 @@ AVColorPrimaries ffmpeg::tools::obs_to_av_color_primary(video_colorspace v)
} }
} }
AVColorTransferCharacteristic ffmpeg::tools::obs_to_av_color_transfer_characteristics(video_colorspace v) AVColorTransferCharacteristic streamfx::ffmpeg::tools::obs_to_av_color_transfer_characteristics(video_colorspace v)
{ {
switch (v) { switch (v) {
case VIDEO_CS_601: // BT.601 case VIDEO_CS_601: // BT.601
@ -299,7 +299,7 @@ void tools::print_av_option_bool(AVCodecContext* ctx_codec, void* ctx_option, co
int64_t v = 0; int64_t v = 0;
if (int err = av_opt_get_int(ctx_option, option, AV_OPT_SEARCH_CHILDREN, &v); err != 0) { if (int err = av_opt_get_int(ctx_option, option, AV_OPT_SEARCH_CHILDREN, &v); err != 0) {
DLOG_INFO("[%s] %s: <Error: %s>", ctx_codec->codec->name, text.c_str(), DLOG_INFO("[%s] %s: <Error: %s>", ctx_codec->codec->name, text.c_str(),
ffmpeg::tools::get_error_description(err)); streamfx::ffmpeg::tools::get_error_description(err));
} else { } else {
DLOG_INFO("[%s] %s: %s%s", ctx_codec->codec->name, text.c_str(), DLOG_INFO("[%s] %s: %s%s", ctx_codec->codec->name, text.c_str(),
(inverse ? v != 0 : v == 0) ? "Disabled" : "Enabled", (inverse ? v != 0 : v == 0) ? "Disabled" : "Enabled",
@ -322,7 +322,7 @@ void tools::print_av_option_int(AVCodecContext* ctx_codec, void* ctx_option, con
DLOG_INFO("[%s] %s: <Default>", ctx_codec->codec->name, text.c_str()); DLOG_INFO("[%s] %s: <Default>", ctx_codec->codec->name, text.c_str());
} else { } else {
DLOG_INFO("[%s] %s: <Error: %s>", ctx_codec->codec->name, text.c_str(), DLOG_INFO("[%s] %s: <Error: %s>", ctx_codec->codec->name, text.c_str(),
ffmpeg::tools::get_error_description(err)); streamfx::ffmpeg::tools::get_error_description(err));
} }
} else { } else {
DLOG_INFO("[%s] %s: %" PRId64 " %s%s", ctx_codec->codec->name, text.c_str(), v, suffix.c_str(), DLOG_INFO("[%s] %s: %" PRId64 " %s%s", ctx_codec->codec->name, text.c_str(), v, suffix.c_str(),
@ -342,7 +342,7 @@ void tools::print_av_option_string(AVCodecContext* ctx_codec, void* ctx_option,
int64_t v = 0; int64_t v = 0;
if (int err = av_opt_get_int(ctx_option, option, AV_OPT_SEARCH_CHILDREN, &v); err != 0) { if (int err = av_opt_get_int(ctx_option, option, AV_OPT_SEARCH_CHILDREN, &v); err != 0) {
DLOG_INFO("[%s] %s: <Error: %s>", ctx_codec->codec->name, text.c_str(), DLOG_INFO("[%s] %s: <Error: %s>", ctx_codec->codec->name, text.c_str(),
ffmpeg::tools::get_error_description(err)); streamfx::ffmpeg::tools::get_error_description(err));
} else { } else {
std::string name = "<Unknown>"; std::string name = "<Unknown>";
if (decoder) if (decoder)

View file

@ -35,7 +35,7 @@ extern "C" {
#endif #endif
} }
namespace ffmpeg::tools { namespace streamfx::ffmpeg::tools {
const char* get_pixel_format_name(AVPixelFormat v); const char* get_pixel_format_name(AVPixelFormat v);
const char* get_color_space_name(AVColorSpace v); const char* get_color_space_name(AVColorSpace v);
@ -80,4 +80,4 @@ namespace ffmpeg::tools {
void print_av_option_string2(AVCodecContext* ctx_codec, void* ctx_option, std::string_view option, void print_av_option_string2(AVCodecContext* ctx_codec, void* ctx_option, std::string_view option,
std::string_view text, std::function<std::string(int64_t, std::string_view)> decoder); std::string_view text, std::function<std::string(int64_t, std::string_view)> decoder);
} // namespace ffmpeg::tools } // namespace streamfx::ffmpeg::tools