fix(logging): fix logging statements not using the logger singleton

Signed-off-by: k4yt3x <i@k4yt3x.com>
This commit is contained in:
k4yt3x 2025-01-04 00:00:00 +00:00
parent 7c867b1b97
commit f38452ff94
No known key found for this signature in database
4 changed files with 25 additions and 24 deletions

View File

@ -27,7 +27,7 @@ AVRational get_video_frame_rate(AVFormatContext* ifmt_ctx, int in_vstream_idx) {
frame_rate = ifmt_ctx->streams[in_vstream_idx]->time_base;
}
if (frame_rate.num == 0 && frame_rate.den == 0) {
spdlog::warn("Unable to determine the video's frame rate");
logger()->warn("Unable to determine the video's frame rate");
}
return frame_rate;
}
@ -36,10 +36,10 @@ int64_t get_video_frame_count(AVFormatContext* ifmt_ctx, int in_vstream_idx) {
// Use the 'nb_frames' field if it is available
int64_t nb_frames = ifmt_ctx->streams[in_vstream_idx]->nb_frames;
if (nb_frames != AV_NOPTS_VALUE && nb_frames > 0) {
spdlog::debug("Read total number of frames from 'nb_frames': {}", nb_frames);
logger()->debug("Read total number of frames from 'nb_frames': {}", nb_frames);
return nb_frames;
}
spdlog::warn("Estimating the total number of frames using duration * fps");
logger()->warn("Estimating the total number of frames using duration * fps");
// Get the duration of the video
double duration_secs = 0.0;
@ -50,18 +50,18 @@ int64_t get_video_frame_count(AVFormatContext* ifmt_ctx, int in_vstream_idx) {
av_q2d(ifmt_ctx->streams[in_vstream_idx]->time_base);
}
if (duration_secs <= 0) {
spdlog::warn("Unable to determine the video's duration");
logger()->warn("Unable to determine the video's duration");
return -1;
}
spdlog::debug("Video duration: {}s", duration_secs);
logger()->debug("Video duration: {}s", duration_secs);
// Calculate average FPS
double fps = av_q2d(get_video_frame_rate(ifmt_ctx, in_vstream_idx));
if (fps <= 0) {
spdlog::warn("Unable to estimate the video's average frame rate");
logger()->warn("Unable to estimate the video's average frame rate");
return -1;
}
spdlog::debug("Video average frame rate: {}", fps);
logger()->debug("Video average frame rate: {}", fps);
// Estimate and return the total number of frames
return static_cast<int64_t>(duration_secs * fps);
@ -85,10 +85,11 @@ AVPixelFormat get_encoder_default_pix_fmt(const AVCodec* encoder, AVPixelFormat
if (supported_pix_fmts == nullptr) {
if (target_pix_fmt == AV_PIX_FMT_NONE) {
spdlog::warn("Encoder supports all pixel formats; defaulting to yuv420p");
logger()->warn("Encoder supports all pixel formats; defaulting to yuv420p");
return AV_PIX_FMT_YUV420P;
} else {
spdlog::warn("Encoder supports all pixel formats; defaulting to the decoder's format");
logger()->warn("Encoder supports all pixel formats; defaulting to the decoder's format"
);
return target_pix_fmt;
}
}
@ -124,7 +125,7 @@ AVPixelFormat get_encoder_default_pix_fmt(const AVCodec* encoder, AVPixelFormat
}
if (target_pix_fmt != AV_PIX_FMT_NONE && best_pix_fmt != target_pix_fmt) {
spdlog::warn(
logger()->warn(
"Incompatible pixel format '%s' for encoder '%s'; auto-selecting format '%s'",
av_get_pix_fmt_name(target_pix_fmt),
encoder->name,

View File

@ -126,7 +126,7 @@ int Encoder::init(
logger()->error("Could not get the default pixel format for the encoder");
return AVERROR(EINVAL);
}
spdlog::debug("Auto-selected pixel format: {}", av_get_pix_fmt_name(enc_ctx_->pix_fmt));
logger()->debug("Auto-selected pixel format: {}", av_get_pix_fmt_name(enc_ctx_->pix_fmt));
}
if (frm_rate_mul > 0) {
@ -153,13 +153,13 @@ int Encoder::init(
for (const auto& [opt_name, opt_value] : enc_cfg.extra_opts) {
std::string opt_name_str = fsutils::wstring_to_u8string(opt_name);
std::string opt_value_str = fsutils::wstring_to_u8string(opt_value);
spdlog::debug("Setting encoder option '{}' to '{}'", opt_name_str, opt_value_str);
logger()->debug("Setting encoder option '{}' to '{}'", opt_name_str, opt_value_str);
ret = av_opt_set(enc_ctx_->priv_data, opt_name_str.c_str(), opt_value_str.c_str(), 0);
if (ret < 0) {
char errbuf[AV_ERROR_MAX_STRING_SIZE];
av_strerror(ret, errbuf, sizeof(errbuf));
spdlog::warn(
logger()->warn(
"Failed to set encoder option '{}' to '{}': {}", opt_name_str, opt_value_str, errbuf
);
}
@ -214,7 +214,7 @@ int Encoder::init(
if (in_codecpar->codec_type != AVMEDIA_TYPE_AUDIO &&
in_codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE) {
stream_map_[i] = -1;
spdlog::warn("Skipping unsupported stream type at index: {}", i);
logger()->warn("Skipping unsupported stream type at index: {}", i);
continue;
}
@ -237,7 +237,7 @@ int Encoder::init(
out_stream->time_base = in_stream->time_base;
// Map input stream index to output stream index
spdlog::debug("Stream mapping: {} (in) -> {} (out)", i, out_stream->index);
logger()->debug("Stream mapping: {} (in) -> {} (out)", i, out_stream->index);
stream_map_[i] = out_stream->index;
}
}

View File

@ -71,17 +71,17 @@ int init_libplacebo(
if (av_opt_find(&priv_class_copy_ptr, "colorspace", NULL, 0, AV_OPT_SEARCH_FAKE_OBJ)) {
args += ":colorspace=" + std::to_string(dec_ctx->colorspace);
} else {
spdlog::warn("Option 'colorspace' is not supported by the buffer filter.");
logger()->warn("Option 'colorspace' is not supported by the buffer filter.");
}
// Check if the range option is supported
if (av_opt_find(&priv_class_copy_ptr, "range", NULL, 0, AV_OPT_SEARCH_FAKE_OBJ)) {
args += ":range=" + std::to_string(dec_ctx->color_range);
} else {
spdlog::warn("Option 'range' is not supported by the buffer filter.");
logger()->warn("Option 'range' is not supported by the buffer filter.");
}
spdlog::debug("Buffer source args: {}", args);
logger()->debug("Buffer source args: {}", args);
ret = avfilter_graph_create_filter(buffersrc_ctx, buffersrc, "in", args.c_str(), NULL, graph);
if (ret < 0) {
logger()->error("Cannot create buffer source.");

View File

@ -179,14 +179,14 @@ int VideoProcessor::process_frames(
}
// Set the total number of frames in the VideoProcessingContext
spdlog::debug("Estimating the total number of frames to process");
logger()->debug("Estimating the total number of frames to process");
total_frames_ = avutils::get_video_frame_count(ifmt_ctx, in_vstream_idx);
if (total_frames_ <= 0) {
spdlog::warn("Unable to determine the total number of frames");
logger()->warn("Unable to determine the total number of frames");
total_frames_ = 0;
} else {
spdlog::debug("{} frames to process", total_frames_.load());
logger()->debug("{} frames to process", total_frames_.load());
}
// Set total frames for interpolation
@ -199,7 +199,7 @@ int VideoProcessor::process_frames(
ret = av_read_frame(ifmt_ctx, packet.get());
if (ret < 0) {
if (ret == AVERROR_EOF) {
spdlog::debug("Reached end of file");
logger()->debug("Reached end of file");
break;
}
av_strerror(ret, errbuf, sizeof(errbuf));
@ -257,7 +257,7 @@ int VideoProcessor::process_frames(
}
av_frame_unref(frame.get());
frame_idx_++;
spdlog::debug("Processed frame {}/{}", frame_idx_.load(), total_frames_.load());
logger()->debug("Processed frame {}/{}", frame_idx_.load(), total_frames_.load());
}
} else if (enc_cfg_.copy_streams && stream_map[packet->stream_index] >= 0) {
ret = write_raw_packet(packet.get(), ifmt_ctx, ofmt_ctx, stream_map);
@ -392,7 +392,7 @@ int VideoProcessor::process_interpolation(
if (proc_cfg_.scn_det_thresh < 100.0 && prev_frame.get() != nullptr) {
float frame_diff = avutils::get_frame_diff(prev_frame.get(), frame);
if (frame_diff > proc_cfg_.scn_det_thresh) {
spdlog::debug(
logger()->debug(
"Scene change detected ({:.2f}%), skipping frame {}", frame_diff, frame_idx_.load()
);
skip_frame = true;