[hatari-devel] AVI recording helpers usage

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


Hi Nicolas,

Do following AVI recording helpers in the attached patches make sense to you?

(I would be using those helpers later on to extend my WIP autostart support also to AVI recording.)


	- Eero
From d243732840dbcc75d71c59b4421167b12eec5fb4 Mon Sep 17 00:00:00 2001
From: Eero Tamminen <oak@xxxxxxxxxxxxxx>
Date: Wed, 25 Jun 2025 01:22:27 +0300
Subject: [PATCH 2/6] Use "Avi_AreWeRecording()" everywhere

So that "bRecordingAvi" can be internal detail for "avi_record.c" as expected.
---
 src/avi_record.c          | 2 +-
 src/includes/avi_record.h | 4 ----
 src/sound.c               | 4 ++--
 src/statusbar.c           | 4 ++--
 src/video.c               | 2 +-
 5 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/src/avi_record.c b/src/avi_record.c
index 82d46a0c..d9c1e003 100644
--- a/src/avi_record.c
+++ b/src/avi_record.c
@@ -423,7 +423,7 @@ typedef struct {
 
 
 
-bool		bRecordingAvi = false;
+static bool bRecordingAvi = false;
 
 
 static RECORD_AVI_PARAMS	AviParams;
diff --git a/src/includes/avi_record.h b/src/includes/avi_record.h
index 89ca92e3..3e627210 100644
--- a/src/includes/avi_record.h
+++ b/src/includes/avi_record.h
@@ -15,10 +15,6 @@
 #define	AVI_RECORD_AUDIO_CODEC_PCM	1
 
 
-extern bool	bRecordingAvi;
-extern int	AviRecordDefaultVcodec;
-extern bool	AviRecordDefaultCrop;
-extern int	AviRecordDefaultFps;
 extern char	AviRecordFile[FILENAME_MAX];
 
 extern bool	Avi_RecordVideoStream ( void );
diff --git a/src/sound.c b/src/sound.c
index fbdc76ca..f8c57673 100644
--- a/src/sound.c
+++ b/src/sound.c
@@ -1796,7 +1796,7 @@ void Sound_Update(uint64_t CPU_Clock)
 	Audio_Unlock();
 
 	/* Save to WAV file, if open */
-	if (bRecordingWav)
+	if (Avi_AreWeRecording())
 		WAVFormat_Update(AudioMixBuffer, pos_write_prev, Samples_Nbr);
 }
 
@@ -1825,7 +1825,7 @@ void Sound_Update_VBL(void)
 	}
 	
 	/* Record AVI audio frame is necessary */
-	if ( bRecordingAvi )
+	if ( Avi_AreWeRecording() )
 	{
 		int Len;
 
diff --git a/src/statusbar.c b/src/statusbar.c
index 0b5bc17c..89ca3a9d 100644
--- a/src/statusbar.c
+++ b/src/statusbar.c
@@ -834,7 +834,7 @@ static SDL_Rect* Statusbar_OverlayDraw(SDL_Surface *surf)
 	Uint32 currentticks = SDL_GetTicks();
 	int i;
 
-	if (bRecordingYM || bRecordingWav || bRecordingAvi)
+	if (bRecordingYM || bRecordingWav || Avi_AreWeRecording())
 	{
 		Statusbar_OverlayDrawLed(surf, RecColorOn);
 	}
@@ -1019,7 +1019,7 @@ SDL_Rect* Statusbar_Update(SDL_Surface *surf, bool do_update)
 		}
 	}
 
-	if ((bRecordingYM || bRecordingWav || bRecordingAvi) != bOldRecording)
+	if ((bRecordingYM || bRecordingWav || Avi_AreWeRecording()) != bOldRecording)
 	{
 		bOldRecording = !bOldRecording;
 		if (bOldRecording)
diff --git a/src/video.c b/src/video.c
index b6a6592c..28f0e87b 100644
--- a/src/video.c
+++ b/src/video.c
@@ -4969,7 +4969,7 @@ void Video_InterruptHandler_VBL ( void )
 	IKBD_UpdateClockOnVBL ();
 
 	/* Record video frame is necessary */
-	if ( bRecordingAvi )
+	if ( Avi_AreWeRecording() )
 		Avi_RecordVideoStream ();
 
 	/* Store off PSG registers for YM file, is enabled */
-- 
2.39.5

From db40c25859d7571c381943c47405295b6ef6d6ee Mon Sep 17 00:00:00 2001
From: Eero Tamminen <oak@xxxxxxxxxxxxxx>
Date: Thu, 5 Jun 2025 01:50:09 +0300
Subject: [PATCH 1/6] Add helpers to simplify AVI recording start/stop

---
 src/avi_record.c          | 27 ++++++++++++++++++++++++---
 src/gui-osx/SDLMain.m     |  8 +-------
 src/gui-sdl/dlgScreen.c   |  8 +-------
 src/includes/avi_record.h |  3 ++-
 src/main.c                | 19 +++++--------------
 src/shortcut.c            | 12 +++---------
 6 files changed, 36 insertions(+), 41 deletions(-)

diff --git a/src/avi_record.c b/src/avi_record.c
index 6a15a144..82d46a0c 100644
--- a/src/avi_record.c
+++ b/src/avi_record.c
@@ -89,12 +89,14 @@ const char AVIRecord_fileid[] = "Hatari avi_record.c";
 #include "version.h"
 #include "audio.h"
 #include "configuration.h"
+#include "clocks_timings.h"
 #include "file.h"
 #include "log.h"
 #include "screen.h"
 #include "screenSnapShot.h"
 #include "sound.h"
 #include "statusbar.h"
+#include "video.h"
 #include "avi_record.h"
 
 /* after above that brings in config.h */
@@ -460,6 +462,7 @@ static void	Avi_BuildFileHeader ( RECORD_AVI_PARAMS *pAviParams , AVI_FILE_HEADE
 static bool	Avi_StartRecording_WithParams ( RECORD_AVI_PARAMS *pAviParams , char *AviFileName );
 static bool	Avi_StopRecording_WithParams ( RECORD_AVI_PARAMS *pAviParams );
 
+static bool	Avi_StartRecording ( char *FileName , bool CropGui , uint32_t Fps , uint32_t Fps_scale , int VideoCodec );
 
 
 static void	Avi_StoreU8 ( uint8_t *p , uint8_t val )
@@ -1432,7 +1435,6 @@ bool	Avi_AreWeRecording ( void )
         return bRecordingAvi;
 }
 
-
 /* PNG compression level, 0-9 */
 static int compression_level = 9;
 
@@ -1453,7 +1455,7 @@ bool Avi_SetCompressionLevel(const char *str)
 }
 
 
-bool	Avi_StartRecording ( char *FileName , bool CropGui , uint32_t Fps , uint32_t Fps_scale , int VideoCodec )
+static bool	Avi_StartRecording ( char *FileName , bool CropGui , uint32_t Fps , uint32_t Fps_scale , int VideoCodec )
 {
 	memset ( &AviParams , 0 , sizeof ( AviParams ) );
 
@@ -1497,6 +1499,17 @@ void Avi_SetSurface(SDL_Surface *surf)
 	AviParams.Surface = surf;
 }
 
+bool	Avi_StartRecording_WithConfig ( void )
+{
+	return Avi_StartRecording( ConfigureParams.Video.AviRecordFile ,
+				   ConfigureParams.Screen.bCrop ,
+				   ConfigureParams.Video.AviRecordFps == 0 ?
+				     ClocksTimings_GetVBLPerSec ( ConfigureParams.System.nMachineType , nScreenRefreshRate ) :
+				     ClocksTimings_GetVBLPerSec ( ConfigureParams.System.nMachineType , ConfigureParams.Video.AviRecordFps ) ,
+				   1 << CLOCKS_TIMINGS_SHIFT_VBL ,
+				   ConfigureParams.Video.AviRecordVcodec );
+}
+
 bool	Avi_StopRecording ( void )
 {
 	if (Avi_StopRecording_WithParams ( &AviParams ))
@@ -1507,4 +1520,12 @@ bool	Avi_StopRecording ( void )
 	return false;
 }
 
-
+bool Avi_StopRecording_WithMsg(void)
+{
+	if (!bRecordingAvi)
+		return true;
+	/* cleanly close the AVI file */
+	Statusbar_AddMessage("Finishing AVI file...", 100);
+	Statusbar_Update(sdlscrn, true);
+	return Avi_StopRecording();
+}
diff --git a/src/gui-osx/SDLMain.m b/src/gui-osx/SDLMain.m
index f4c6c4f1..dba7e392 100644
--- a/src/gui-osx/SDLMain.m
+++ b/src/gui-osx/SDLMain.m
@@ -31,7 +31,6 @@
 #import "video.h"
 #import "avi_record.h"
 #import "debugui.h"
-#import "clocks_timings.h"
 #import "change.h"
 
 extern void Main_RequestQuit(int exitval) ;
@@ -283,12 +282,7 @@ char szPath[FILENAME_MAX] ;											// for general use
 
 		if(path) {
 			GuiOsx_ExportPathString(path, ConfigureParams.Video.AviRecordFile, sizeof(ConfigureParams.Video.AviRecordFile));
-			Avi_StartRecording ( ConfigureParams.Video.AviRecordFile , ConfigureParams.Screen.bCrop ,
-					ConfigureParams.Video.AviRecordFps == 0 ?
-					ClocksTimings_GetVBLPerSec ( ConfigureParams.System.nMachineType , nScreenRefreshRate ) :
-					ClocksTimings_GetVBLPerSec ( ConfigureParams.System.nMachineType , ConfigureParams.Video.AviRecordFps ) ,
-				1 << CLOCKS_TIMINGS_SHIFT_VBL ,
-				ConfigureParams.Video.AviRecordVcodec );
+			Avi_StartRecording_WithConfig ();
 		}
 	} else {
 		Avi_StopRecording();
diff --git a/src/gui-sdl/dlgScreen.c b/src/gui-sdl/dlgScreen.c
index e1a0ff01..ad73b272 100644
--- a/src/gui-sdl/dlgScreen.c
+++ b/src/gui-sdl/dlgScreen.c
@@ -21,7 +21,6 @@ const char DlgScreen_fileid[] = "Hatari dlgScreen.c";
 #include "video.h"
 #include "avi_record.h"
 #include "statusbar.h"
-#include "clocks_timings.h"
 
 /* how many pixels to increment VDI mode
  * width/height on each click
@@ -456,12 +455,7 @@ void Dialog_WindowDlg(void)
 			else
 			{
 				ConfigureParams.Screen.bCrop = (windowdlg[DLGSCRN_CROP].state & SG_SELECTED);
-				Avi_StartRecording ( ConfigureParams.Video.AviRecordFile , ConfigureParams.Screen.bCrop ,
-					ConfigureParams.Video.AviRecordFps == 0 ?
-						ClocksTimings_GetVBLPerSec ( ConfigureParams.System.nMachineType , nScreenRefreshRate ) :
-						ClocksTimings_GetVBLPerSec ( ConfigureParams.System.nMachineType , ConfigureParams.Video.AviRecordFps ) ,
-					1 << CLOCKS_TIMINGS_SHIFT_VBL ,
-					ConfigureParams.Video.AviRecordVcodec );
+				Avi_StartRecording_WithConfig ();
 				windowdlg[DLGSCRN_RECANIM].txt = RECORD_STOP;
 			}
 			break;
diff --git a/src/includes/avi_record.h b/src/includes/avi_record.h
index 04b41c5a..89ca92e3 100644
--- a/src/includes/avi_record.h
+++ b/src/includes/avi_record.h
@@ -26,8 +26,9 @@ extern bool	Avi_RecordAudioStream ( int16_t pSamples[][2] , int SampleIndex , in
 
 extern bool	Avi_AreWeRecording ( void );
 extern bool	Avi_SetCompressionLevel(const char *str);
-extern bool	Avi_StartRecording ( char *FileName , bool CropGui , uint32_t Fps , uint32_t Fps_scale , int VideoCodec );
+extern bool	Avi_StartRecording_WithConfig ( void );
 extern bool	Avi_StopRecording ( void );
+extern bool	Avi_StopRecording_WithMsg ( void );
 extern void	Avi_SetSurface(SDL_Surface *surf);
 
 
diff --git a/src/main.c b/src/main.c
index 17028b49..56e51cad 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1067,26 +1067,17 @@ int main(int argc, char *argv[])
 	/* Check if SDL_Delay is accurate */
 	Main_CheckForAccurateDelays();
 
-	if ( AviRecordOnStartup )	/* Immediately starts avi recording ? */
-		Avi_StartRecording ( ConfigureParams.Video.AviRecordFile , ConfigureParams.Screen.bCrop ,
-			ConfigureParams.Video.AviRecordFps == 0 ?
-				ClocksTimings_GetVBLPerSec ( ConfigureParams.System.nMachineType , nScreenRefreshRate ) :
-				ClocksTimings_GetVBLPerSec ( ConfigureParams.System.nMachineType , ConfigureParams.Video.AviRecordFps ) ,
-			1 << CLOCKS_TIMINGS_SHIFT_VBL ,
-			ConfigureParams.Video.AviRecordVcodec );
+	/* Immediately start AVI recording ? */
+	if ( AviRecordOnStartup )
+		Avi_StartRecording_WithConfig();
 
 	/* Run emulation */
 	Main_UnPauseEmulation();
 	M68000_Start();                 /* Start emulation */
 
 	Control_RemoveFifo();
-	if (bRecordingAvi)
-	{
-		/* cleanly close the avi file */
-		Statusbar_AddMessage("Finishing AVI file...", 100);
-		Statusbar_Update(sdlscrn, true);
-		Avi_StopRecording();
-	}
+	/* cleanly close the AVI file, if needed */
+	Avi_StopRecording_WithMsg();
 	/* Un-init emulation system */
 	Main_UnInit();
 
diff --git a/src/shortcut.c b/src/shortcut.c
index 433c0c29..9855eb78 100644
--- a/src/shortcut.c
+++ b/src/shortcut.c
@@ -28,7 +28,6 @@ const char ShortCut_fileid[] = "Hatari shortcut.c";
 #include "sdlgui.h"
 #include "video.h"
 #include "avi_record.h"
-#include "clocks_timings.h"
 #include "statusbar.h"
 
 static SHORTCUTKEYIDX ShortCutKey = SHORTCUT_NONE;  /* current shortcut key */
@@ -124,17 +123,12 @@ static void ShortCut_RecordAnimation(void)
 	if (Avi_AreWeRecording())
 	{
 		/* Stop */
-		Avi_StopRecording();
+		Avi_StopRecording_WithMsg();
 	}
 	else
 	{
-		/* Start animation */
-		Avi_StartRecording ( ConfigureParams.Video.AviRecordFile , ConfigureParams.Screen.bCrop ,
-			ConfigureParams.Video.AviRecordFps == 0 ?
-				ClocksTimings_GetVBLPerSec ( ConfigureParams.System.nMachineType , nScreenRefreshRate ) :
-				ClocksTimings_GetVBLPerSec ( ConfigureParams.System.nMachineType , ConfigureParams.Video.AviRecordFps ) ,
-			1 << CLOCKS_TIMINGS_SHIFT_VBL ,
-			ConfigureParams.Video.AviRecordVcodec );
+		/* Start recording */
+		Avi_StartRecording_WithConfig();
 	}
 }
 
-- 
2.39.5



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/