mirror of
https://github.com/k4yt3x/video2x.git
synced 2026-02-04 03:22:07 +08:00
feat(logger): add logger manager to provide unified logging (#1267)
Signed-off-by: k4yt3x <i@k4yt3x.com>
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include "logger_manager.h"
|
||||
|
||||
namespace video2x {
|
||||
namespace conversions {
|
||||
|
||||
@@ -12,7 +14,7 @@ namespace conversions {
|
||||
AVFrame *convert_avframe_pix_fmt(AVFrame *src_frame, AVPixelFormat pix_fmt) {
|
||||
AVFrame *dst_frame = av_frame_alloc();
|
||||
if (dst_frame == nullptr) {
|
||||
spdlog::error("Failed to allocate destination AVFrame.");
|
||||
logger()->error("Failed to allocate destination AVFrame.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -22,7 +24,7 @@ AVFrame *convert_avframe_pix_fmt(AVFrame *src_frame, AVPixelFormat pix_fmt) {
|
||||
|
||||
// Allocate memory for the converted frame
|
||||
if (av_frame_get_buffer(dst_frame, 32) < 0) {
|
||||
spdlog::error("Failed to allocate memory for AVFrame.");
|
||||
logger()->error("Failed to allocate memory for AVFrame.");
|
||||
av_frame_free(&dst_frame);
|
||||
return nullptr;
|
||||
}
|
||||
@@ -42,7 +44,7 @@ AVFrame *convert_avframe_pix_fmt(AVFrame *src_frame, AVPixelFormat pix_fmt) {
|
||||
);
|
||||
|
||||
if (sws_ctx == nullptr) {
|
||||
spdlog::error("Failed to initialize swscale context.");
|
||||
logger()->error("Failed to initialize swscale context.");
|
||||
av_frame_free(&dst_frame);
|
||||
return nullptr;
|
||||
}
|
||||
@@ -72,7 +74,7 @@ ncnn::Mat avframe_to_ncnn_mat(AVFrame *frame) {
|
||||
if (frame->format != AV_PIX_FMT_BGR24) {
|
||||
converted_frame = convert_avframe_pix_fmt(frame, AV_PIX_FMT_BGR24);
|
||||
if (!converted_frame) {
|
||||
spdlog::error("Failed to convert AVFrame to BGR24.");
|
||||
logger()->error("Failed to convert AVFrame to BGR24.");
|
||||
return ncnn::Mat();
|
||||
}
|
||||
} else {
|
||||
@@ -110,7 +112,7 @@ AVFrame *ncnn_mat_to_avframe(const ncnn::Mat &mat, AVPixelFormat pix_fmt) {
|
||||
// Step 1: Allocate a destination AVFrame for the specified pixel format
|
||||
AVFrame *dst_frame = av_frame_alloc();
|
||||
if (!dst_frame) {
|
||||
spdlog::error("Failed to allocate destination AVFrame.");
|
||||
logger()->error("Failed to allocate destination AVFrame.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -120,7 +122,7 @@ AVFrame *ncnn_mat_to_avframe(const ncnn::Mat &mat, AVPixelFormat pix_fmt) {
|
||||
|
||||
// Allocate memory for the frame buffer
|
||||
if (av_frame_get_buffer(dst_frame, 32) < 0) {
|
||||
spdlog::error("Failed to allocate memory for destination AVFrame.");
|
||||
logger()->error("Failed to allocate memory for destination AVFrame.");
|
||||
av_frame_free(&dst_frame);
|
||||
return nullptr;
|
||||
}
|
||||
@@ -128,7 +130,7 @@ AVFrame *ncnn_mat_to_avframe(const ncnn::Mat &mat, AVPixelFormat pix_fmt) {
|
||||
// Step 2: Convert ncnn::Mat to BGR AVFrame
|
||||
AVFrame *bgr_frame = av_frame_alloc();
|
||||
if (!bgr_frame) {
|
||||
spdlog::error("Failed to allocate intermediate BGR AVFrame.");
|
||||
logger()->error("Failed to allocate intermediate BGR AVFrame.");
|
||||
av_frame_free(&dst_frame);
|
||||
return nullptr;
|
||||
}
|
||||
@@ -139,7 +141,7 @@ AVFrame *ncnn_mat_to_avframe(const ncnn::Mat &mat, AVPixelFormat pix_fmt) {
|
||||
|
||||
// Allocate memory for the intermediate BGR frame
|
||||
if (av_frame_get_buffer(bgr_frame, 32) < 0) {
|
||||
spdlog::error("Failed to allocate memory for BGR AVFrame.");
|
||||
logger()->error("Failed to allocate memory for BGR AVFrame.");
|
||||
av_frame_free(&dst_frame);
|
||||
av_frame_free(&bgr_frame);
|
||||
return nullptr;
|
||||
@@ -169,7 +171,7 @@ AVFrame *ncnn_mat_to_avframe(const ncnn::Mat &mat, AVPixelFormat pix_fmt) {
|
||||
);
|
||||
|
||||
if (sws_ctx == nullptr) {
|
||||
spdlog::error("Failed to initialize swscale context.");
|
||||
logger()->error("Failed to initialize swscale context.");
|
||||
av_frame_free(&bgr_frame);
|
||||
av_frame_free(&dst_frame);
|
||||
return nullptr;
|
||||
@@ -191,7 +193,7 @@ AVFrame *ncnn_mat_to_avframe(const ncnn::Mat &mat, AVPixelFormat pix_fmt) {
|
||||
av_frame_free(&bgr_frame);
|
||||
|
||||
if (ret != dst_frame->height) {
|
||||
spdlog::error("Failed to convert BGR AVFrame to destination pixel format.");
|
||||
logger()->error("Failed to convert BGR AVFrame to destination pixel format.");
|
||||
av_frame_free(&dst_frame);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user