From df0f7657d039c180f646c6359018f92e0df19c3b Mon Sep 17 00:00:00 2001 From: Chris Burgener Date: Wed, 24 Aug 2016 13:00:25 -0400 Subject: [PATCH 1/2] Fix frame dump issues where frame dumping stops before next drawn frame --- Source/Core/VideoCommon/AVIDump.cpp | 14 ++++++++++++++ Source/Core/VideoCommon/AVIDump.h | 1 + 2 files changed, 15 insertions(+) diff --git a/Source/Core/VideoCommon/AVIDump.cpp b/Source/Core/VideoCommon/AVIDump.cpp index 708c943822..1a7183a8e3 100644 --- a/Source/Core/VideoCommon/AVIDump.cpp +++ b/Source/Core/VideoCommon/AVIDump.cpp @@ -48,6 +48,9 @@ static int s_current_width; static int s_current_height; static int s_file_index = 0; static AVIDump::DumpFormat s_current_format; +static const u8* s_stored_frame_data; +static int s_stored_frame_width; +static int s_stored_frame_height; static void InitAVCodec() { @@ -177,6 +180,8 @@ static void PreparePacket(AVPacket* pkt) void AVIDump::AddFrame(const u8* data, int width, int height) { + // Store current frame data in case frame dumping stops before next frame update + StoreFrameData(data, width, height); CheckResolution(width, height); s_src_frame->data[0] = const_cast(data); s_src_frame->linesize[0] = width * s_bytes_per_pixel; @@ -252,6 +257,8 @@ void AVIDump::AddFrame(const u8* data, int width, int height) void AVIDump::Stop() { + // Write the last stored frame just in case frame dumping stops before the next frame update + AddFrame(s_stored_frame_data, s_stored_frame_width, s_stored_frame_height); av_write_trailer(s_format_context); CloseFile(); s_file_index = 0; @@ -311,3 +318,10 @@ void AVIDump::CheckResolution(int width, int height) s_current_height = height; } } + +void AVIDump::StoreFrameData(const u8* data, int width, int height) +{ + s_stored_frame_data = data; + s_stored_frame_width = width; + s_stored_frame_height = height; +} diff --git a/Source/Core/VideoCommon/AVIDump.h b/Source/Core/VideoCommon/AVIDump.h index b4b87f90de..6b0837f789 100644 --- a/Source/Core/VideoCommon/AVIDump.h +++ b/Source/Core/VideoCommon/AVIDump.h @@ -12,6 +12,7 @@ private: static bool CreateFile(); static void CloseFile(); static void CheckResolution(int width, int height); + static void StoreFrameData(const u8* data, int width, int height); public: enum class DumpFormat From 69eed562567e2158219ab249db08b527468c88e1 Mon Sep 17 00:00:00 2001 From: Chris Burgener Date: Tue, 6 Sep 2016 22:45:50 -0400 Subject: [PATCH 2/2] Fix recursive code --- Source/Core/VideoCommon/AVIDump.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Source/Core/VideoCommon/AVIDump.cpp b/Source/Core/VideoCommon/AVIDump.cpp index 1a7183a8e3..cb38026f7d 100644 --- a/Source/Core/VideoCommon/AVIDump.cpp +++ b/Source/Core/VideoCommon/AVIDump.cpp @@ -43,6 +43,7 @@ static int s_width; static int s_height; static u64 s_last_frame; static bool s_start_dumping = false; +static bool s_stop_dumping = false; static u64 s_last_pts; static int s_current_width; static int s_current_height; @@ -85,6 +86,8 @@ bool AVIDump::Start(int w, int h, DumpFormat format) s_last_frame = CoreTiming::GetTicks(); s_last_pts = 0; + s_stop_dumping = false; + InitAVCodec(); bool success = CreateFile(); if (!success) @@ -181,7 +184,8 @@ static void PreparePacket(AVPacket* pkt) void AVIDump::AddFrame(const u8* data, int width, int height) { // Store current frame data in case frame dumping stops before next frame update - StoreFrameData(data, width, height); + if (!s_stop_dumping) + StoreFrameData(data, width, height); CheckResolution(width, height); s_src_frame->data[0] = const_cast(data); s_src_frame->linesize[0] = width * s_bytes_per_pixel; @@ -257,6 +261,7 @@ void AVIDump::AddFrame(const u8* data, int width, int height) void AVIDump::Stop() { + s_stop_dumping = true; // Write the last stored frame just in case frame dumping stops before the next frame update AddFrame(s_stored_frame_data, s_stored_frame_width, s_stored_frame_height); av_write_trailer(s_format_context);