From 9b4b9b6549e54f54789bb5628a17d7aecb67e4b7 Mon Sep 17 00:00:00 2001 From: mjbudd77 Date: Thu, 29 Apr 2021 06:21:16 -0400 Subject: [PATCH] Successful recording of small avi in RGB24 format. --- src/drivers/Qt/AviRecord.cpp | 74 ++++++++++++++++++++++++++++---- src/drivers/Qt/AviRecord.h | 4 ++ src/drivers/Qt/ConsoleWindow.cpp | 14 +++++- src/drivers/Qt/avi/avi-utils.cpp | 2 +- src/drivers/Qt/fceuWrapper.cpp | 2 + 5 files changed, 85 insertions(+), 11 deletions(-) diff --git a/src/drivers/Qt/AviRecord.cpp b/src/drivers/Qt/AviRecord.cpp index 850dffb8..a5acdc76 100644 --- a/src/drivers/Qt/AviRecord.cpp +++ b/src/drivers/Qt/AviRecord.cpp @@ -11,30 +11,54 @@ static gwavi_t *gwavi = NULL; static bool recordEnable = false; //************************************************************************************** -static void convertRgb_32_to_24( const char *src, char *dest, int nPix ) +static void convertRgb_32_to_24( const unsigned char *src, unsigned char *dest, int w, int h, int nPix ) { - int i=0, j=0, s; + int i=0, j=0, x, y; - s = nPix * 4; + // Uncompressed RGB needs to be flipped vertically + y = h-1; - while ( i < s ) + while ( y >= 0 ) { - dest[j] = src[i]; i++; j++; - dest[j] = src[i]; i++; j++; - dest[j] = src[i]; i++; j++; - i++; + x = 0; + i = y*w*4; + + while ( x < w ) + { + dest[j] = src[i]; i++; j++; + dest[j] = src[i]; i++; j++; + dest[j] = src[i]; i++; j++; + i++; + x++; + } + y--; } } //************************************************************************************** int aviRecordOpenFile( const char *filepath, int format, int width, int height ) { + char fourcc[8]; + gwavi_audio_t audioConfig; + if ( gwavi != NULL ) { delete gwavi; gwavi = NULL; } + audioConfig.channels = 1; + audioConfig.bits = 16; + audioConfig.samples_per_second = 48000; + + memset( fourcc, 0, sizeof(fourcc) ); gwavi = new gwavi_t(); + if ( gwavi->open( "/tmp/test.avi", nes_shm->video.ncol, nes_shm->video.nrow, fourcc, 60, &audioConfig ) ) + { + printf("Error: Failed to open AVI file.\n"); + recordEnable = false; + return -1; + } + recordEnable = true; return 0; } @@ -55,20 +79,52 @@ int aviRecordAddFrame( void ) numPixels = nes_shm->video.ncol * nes_shm->video.nrow; bufferSize = numPixels * sizeof(uint32_t); - //gwavi-> + { + unsigned char rgb24[bufferSize]; + convertRgb_32_to_24( (const unsigned char*)nes_shm->pixbuf, rgb24, + nes_shm->video.ncol, nes_shm->video.nrow, numPixels ); + gwavi->add_frame( rgb24, numPixels*3 ); + } return 0; } //************************************************************************************** +int aviRecordAddAudioFrame( int32_t *buf, int numSamples ) +{ + if ( !recordEnable ) + { + return -1; + } + + if ( gwavi == NULL ) + { + return -1; + } + int16_t lclBuf[numSamples]; + + for (int i=0; iadd_audio( (unsigned char *)lclBuf, numSamples*2); +} +//************************************************************************************** int aviRecordClose(void) { recordEnable = false; if ( gwavi != NULL ) { + gwavi->close(); + delete gwavi; gwavi = NULL; } return 0; } //************************************************************************************** +bool aviRecordRunning(void) +{ + return recordEnable; +} +//************************************************************************************** diff --git a/src/drivers/Qt/AviRecord.h b/src/drivers/Qt/AviRecord.h index 93d2dea0..599393b3 100644 --- a/src/drivers/Qt/AviRecord.h +++ b/src/drivers/Qt/AviRecord.h @@ -1,9 +1,13 @@ // AviRecord.h // +#include int aviRecordOpenFile( const char *filepath, int format, int width, int height ); int aviRecordAddFrame( void ); +int aviRecordAddAudioFrame( int32_t *buf, int numSamples ); + int aviRecordClose(void); +bool aviRecordRunning(void); diff --git a/src/drivers/Qt/ConsoleWindow.cpp b/src/drivers/Qt/ConsoleWindow.cpp index 7474bab2..ed733f11 100644 --- a/src/drivers/Qt/ConsoleWindow.cpp +++ b/src/drivers/Qt/ConsoleWindow.cpp @@ -3096,7 +3096,19 @@ void consoleWin_t::recordMovieAs(void) void consoleWin_t::aviOpen(void) { - aviRecordOpenFile( NULL, 0, 256, 240 ); + printf("AVI!!!\n"); + if ( aviRecordRunning() ) + { + fceuWrapperLock(); + aviRecordClose(); + fceuWrapperUnLock(); + } + else + { + fceuWrapperLock(); + aviRecordOpenFile( NULL, 0, 256, 240 ); + fceuWrapperUnLock(); + } } void consoleWin_t::aboutFCEUX(void) diff --git a/src/drivers/Qt/avi/avi-utils.cpp b/src/drivers/Qt/avi/avi-utils.cpp index c8989d38..835bbb97 100644 --- a/src/drivers/Qt/avi/avi-utils.cpp +++ b/src/drivers/Qt/avi/avi-utils.cpp @@ -531,7 +531,7 @@ gwavi_t::check_fourcc(const char *fourcc) "NVT0 NVT1 NVT2 NVT3 NVT4 NVT5" "PDVC PGVV PHMO PIM1 PIM2 PIMJ PIXL PJPG PVEZ PVMM PVW2" "QPEG QPEQ" - "RGBT RLE RLE4 RLE8 RMP4 RPZA RT21 RV20 RV30 RV40 S422 SAN3" + "RGB2 RGBT RLE RLE4 RLE8 RMP4 RPZA RT21 RV20 RV30 RV40 S422 SAN3" "SDCC SEDG SFMC SMP4 SMSC SMSD SMSV SP40 SP44 SP54 SPIG SQZ2" "STVA STVB STVC STVX STVY SV10 SVQ1 SVQ3" "TLMS TLST TM20 TM2X TMIC TMOT TR20 TSCC TV10 TVJP TVMJ TY0N" diff --git a/src/drivers/Qt/fceuWrapper.cpp b/src/drivers/Qt/fceuWrapper.cpp index 04c1cf85..dd705fc8 100644 --- a/src/drivers/Qt/fceuWrapper.cpp +++ b/src/drivers/Qt/fceuWrapper.cpp @@ -36,6 +36,7 @@ #include "Qt/sdl-video.h" #include "Qt/nes_shm.h" #include "Qt/unix-netplay.h" +#include "Qt/AviRecord.h" #include "Qt/HexEditor.h" #include "Qt/SymbolicDebug.h" #include "Qt/CodeDataLogger.h" @@ -981,6 +982,7 @@ FCEUD_Update(uint8 *XBuf, return; } #endif + aviRecordAddAudioFrame( Buffer, Count ); int ocount = Count; // apply frame scaling to Count