mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-10 08:09:26 +01:00
FrameDump: improve debug logging
This commit is contained in:
parent
09432ef098
commit
decaea8f9b
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user