summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/FrameDump.cpp
diff options
context:
space:
mode:
authorShawn Hoffman <godisgovernment@gmail.com>2022-03-24 04:47:43 -0700
committerShawn Hoffman <godisgovernment@gmail.com>2022-03-29 17:27:59 -0700
commitdecaea8f9b8f2705617e5a4782e72161e7afad22 (patch)
tree6ee6bb5909e86fcddddff692a785d705059da1ae /Source/Core/VideoCommon/FrameDump.cpp
parent09432ef098e1ce0d37b6d7d66b144e3679df72ce (diff)
FrameDump: improve debug logging
Diffstat (limited to 'Source/Core/VideoCommon/FrameDump.cpp')
-rw-r--r--Source/Core/VideoCommon/FrameDump.cpp43
1 files changed, 39 insertions, 4 deletions
diff --git a/Source/Core/VideoCommon/FrameDump.cpp b/Source/Core/VideoCommon/FrameDump.cpp
index 26bdd6bbf5..8e1ac75297 100644
--- a/Source/Core/VideoCommon/FrameDump.cpp
+++ b/Source/Core/VideoCommon/FrameDump.cpp
@@ -7,6 +7,7 @@
#define __STDC_CONSTANT_MACROS 1
#endif
+#include <array>
#include <sstream>
#include <string>
@@ -16,6 +17,8 @@
extern "C" {
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
+#include <libavutil/error.h>
+#include <libavutil/log.h>
#include <libavutil/mathematics.h>
#include <libswscale/swscale.h>
}
@@ -69,8 +72,33 @@ void InitAVCodec()
static bool first_run = true;
if (first_run)
{
+ av_log_set_level(AV_LOG_DEBUG);
+ av_log_set_callback([](void* ptr, int level, const char* fmt, va_list vl) {
+ if (level < 0)
+ level = AV_LOG_DEBUG;
+ if (level >= 0)
+ level &= 0xff;
+
+ if (level > av_log_get_level())
+ return;
+
+ auto log_level = Common::Log::LogLevel::LNOTICE;
+ if (level >= AV_LOG_ERROR && level < AV_LOG_WARNING)
+ log_level = Common::Log::LogLevel::LERROR;
+ else if (level >= AV_LOG_WARNING && level < AV_LOG_INFO)
+ log_level = Common::Log::LogLevel::LWARNING;
+ else if (level >= AV_LOG_INFO && level < AV_LOG_DEBUG)
+ log_level = Common::Log::LogLevel::LINFO;
+ else if (level >= AV_LOG_DEBUG)
+ // keep libav debug messages visible in release build of dolphin
+ log_level = Common::Log::LogLevel::LINFO;
+
+ GENERIC_LOG(Common::Log::LogType::FRAMEDUMP, log_level, fmt, vl);
+ });
+
// TODO: We never call avformat_network_deinit.
avformat_network_init();
+
first_run = false;
}
}
@@ -106,6 +134,13 @@ std::string GetDumpPath(const std::string& extension, std::time_t time, u32 inde
return path;
}
+std::string AVErrorString(int error)
+{
+ std::array<char, AV_ERROR_MAX_STRING_SIZE> msg;
+ av_make_error_string(&msg[0], msg.size(), error);
+ return fmt::format("{:8x} {}", (u32)error, &msg[0]);
+}
+
} // namespace
bool FrameDump::Start(int w, int h, u64 start_ticks)
@@ -322,7 +357,7 @@ void FrameDump::AddFrame(const FrameData& frame)
if (const int error = avcodec_send_frame(m_context->codec, m_context->scaled_frame))
{
- ERROR_LOG_FMT(FRAMEDUMP, "Error while encoding video: {}", error);
+ ERROR_LOG_FMT(FRAMEDUMP, "Error while encoding video: {}", AVErrorString(error));
return;
}
@@ -352,7 +387,7 @@ void FrameDump::ProcessPackets()
if (receive_error)
{
- ERROR_LOG_FMT(FRAMEDUMP, "Error receiving packet: {}", receive_error);
+ ERROR_LOG_FMT(FRAMEDUMP, "Error receiving packet: {}", AVErrorString(receive_error));
break;
}
@@ -361,7 +396,7 @@ void FrameDump::ProcessPackets()
if (const int write_error = av_interleaved_write_frame(m_context->format, pkt.get()))
{
- ERROR_LOG_FMT(FRAMEDUMP, "Error writing packet: {}", write_error);
+ ERROR_LOG_FMT(FRAMEDUMP, "Error writing packet: {}", AVErrorString(write_error));
break;
}
}
@@ -374,7 +409,7 @@ void FrameDump::Stop()
// Signal end of stream to encoder.
if (const int flush_error = avcodec_send_frame(m_context->codec, nullptr))
- WARN_LOG_FMT(FRAMEDUMP, "Error sending flush packet: {}", flush_error);
+ WARN_LOG_FMT(FRAMEDUMP, "Error sending flush packet: {}", AVErrorString(flush_error));
ProcessPackets();
av_write_trailer(m_context->format);