Windows Port: Do some minor code cleanup related to commit 8763a61
.
This commit is contained in:
parent
8763a6169a
commit
b8c006b0b5
|
@ -111,41 +111,10 @@ AVIFileStream::~AVIFileStream()
|
||||||
ssem_free(this->_semQueue);
|
ssem_free(this->_semQueue);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t AVIFileStream::GetExpectedFrameSize(const BITMAPINFOHEADER *bmpFormat, const WAVEFORMATEX *wavFormat)
|
HRESULT AVIFileStream::InitBaseProperties(const char *fileName, BITMAPINFOHEADER *bmpFormat, WAVEFORMATEX *wavFormat, size_t pendingFrameCount)
|
||||||
{
|
|
||||||
size_t expectedFrameSize = 0; // The expected frame size is the video frame size plus the sum of the audio samples.
|
|
||||||
|
|
||||||
if (bmpFormat != NULL)
|
|
||||||
{
|
|
||||||
expectedFrameSize += bmpFormat->biSizeImage;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (wavFormat != NULL)
|
|
||||||
{
|
|
||||||
// Since the number of audio samples may not be exactly the same for each video frame,
|
|
||||||
// we double the expected size of the audio buffer for safety.
|
|
||||||
expectedFrameSize += ((wavFormat->nAvgBytesPerSec / 60) * 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
return expectedFrameSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
HRESULT AVIFileStream::Open(const char *fileName, BITMAPINFOHEADER *bmpFormat, WAVEFORMATEX *wavFormat, size_t pendingFrameCount)
|
|
||||||
{
|
{
|
||||||
HRESULT error = S_OK;
|
HRESULT error = S_OK;
|
||||||
|
|
||||||
// Initialize the AVI library if it hasn't already been initialized.
|
|
||||||
if (AVIFileStream::__needAviLibraryInit)
|
|
||||||
{
|
|
||||||
AVIFileInit();
|
|
||||||
AVIFileStream::__needAviLibraryInit = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
char workingFileName[MAX_PATH];
|
|
||||||
memset(workingFileName, '\0', sizeof(workingFileName));
|
|
||||||
|
|
||||||
if (this->_segmentNumber == 0)
|
|
||||||
{
|
|
||||||
// Generate the base file name. This will be used for the first segment.
|
// Generate the base file name. This will be used for the first segment.
|
||||||
const char *dot = strrchr(fileName, '.');
|
const char *dot = strrchr(fileName, '.');
|
||||||
if (dot && dot > strrchr(fileName, '/') && dot > strrchr(fileName, '\\'))
|
if (dot && dot > strrchr(fileName, '/') && dot > strrchr(fileName, '\\'))
|
||||||
|
@ -155,8 +124,6 @@ HRESULT AVIFileStream::Open(const char *fileName, BITMAPINFOHEADER *bmpFormat, W
|
||||||
strcpy(this->_baseFileNameExt, dot);
|
strcpy(this->_baseFileNameExt, dot);
|
||||||
strncpy(this->_baseFileName, fileName, baseNameSize);
|
strncpy(this->_baseFileName, fileName, baseNameSize);
|
||||||
this->_baseFileName[baseNameSize] = '\0'; // Even though the string should already be filled with \0, manually terminate again for safety's sake.
|
this->_baseFileName[baseNameSize] = '\0'; // Even though the string should already be filled with \0, manually terminate again for safety's sake.
|
||||||
|
|
||||||
sprintf(workingFileName, "%s%s", this->_baseFileName, this->_baseFileNameExt);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -179,9 +146,30 @@ HRESULT AVIFileStream::Open(const char *fileName, BITMAPINFOHEADER *bmpFormat, W
|
||||||
this->_streamInfo[AUDIO_STREAM].dwSampleSize = this->_wavFormat.nBlockAlign;
|
this->_streamInfo[AUDIO_STREAM].dwSampleSize = this->_wavFormat.nBlockAlign;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->_expectedFrameSize = AVIFileStream::GetExpectedFrameSize(bmpFormat, wavFormat);
|
this->_expectedFrameSize = NDSCaptureObject::GetExpectedFrameSize(bmpFormat, wavFormat);
|
||||||
|
|
||||||
_semQueue = ssem_new(pendingFrameCount);
|
_semQueue = ssem_new(pendingFrameCount);
|
||||||
|
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
HRESULT AVIFileStream::Open()
|
||||||
|
{
|
||||||
|
HRESULT error = S_OK;
|
||||||
|
|
||||||
|
// Initialize the AVI library if it hasn't already been initialized.
|
||||||
|
if (AVIFileStream::__needAviLibraryInit)
|
||||||
|
{
|
||||||
|
AVIFileInit();
|
||||||
|
AVIFileStream::__needAviLibraryInit = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
char workingFileName[MAX_PATH];
|
||||||
|
memset(workingFileName, '\0', sizeof(workingFileName));
|
||||||
|
|
||||||
|
if (this->_segmentNumber == 0)
|
||||||
|
{
|
||||||
|
sprintf(workingFileName, "%s%s", this->_baseFileName, this->_baseFileNameExt);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -356,7 +344,6 @@ bool AVIFileStream::IsValid()
|
||||||
void AVIFileStream::QueueAdd(u8 *srcVideo, const size_t videoBufferSize, u8 *srcAudio, const size_t audioBufferSize)
|
void AVIFileStream::QueueAdd(u8 *srcVideo, const size_t videoBufferSize, u8 *srcAudio, const size_t audioBufferSize)
|
||||||
{
|
{
|
||||||
AVIFileWriteParam newParam;
|
AVIFileWriteParam newParam;
|
||||||
newParam.fs = this;
|
|
||||||
newParam.srcVideo = srcVideo;
|
newParam.srcVideo = srcVideo;
|
||||||
newParam.videoBufferSize = videoBufferSize;
|
newParam.videoBufferSize = videoBufferSize;
|
||||||
newParam.srcAudio = srcAudio;
|
newParam.srcAudio = srcAudio;
|
||||||
|
@ -467,7 +454,7 @@ HRESULT AVIFileStream::WriteOneFrame(const AVIFileWriteParam ¶m)
|
||||||
this->Close(FSCA_DoNothing);
|
this->Close(FSCA_DoNothing);
|
||||||
this->_segmentNumber++;
|
this->_segmentNumber++;
|
||||||
|
|
||||||
error = this->Open(NULL, NULL, NULL, 0);
|
error = this->Open();
|
||||||
if (FAILED(error))
|
if (FAILED(error))
|
||||||
{
|
{
|
||||||
EMU_PrintError("Error creating new AVI segment.");
|
EMU_PrintError("Error creating new AVI segment.");
|
||||||
|
@ -570,7 +557,7 @@ NDSCaptureObject::NDSCaptureObject(size_t frameWidth, size_t frameHeight, const
|
||||||
_wavFormat = *wfex;
|
_wavFormat = *wfex;
|
||||||
}
|
}
|
||||||
|
|
||||||
const size_t expectedFrameSize = AVIFileStream::GetExpectedFrameSize(&_bmpFormat, wfex);
|
const size_t expectedFrameSize = NDSCaptureObject::GetExpectedFrameSize(&_bmpFormat, wfex);
|
||||||
_pendingBufferCount = MAX_PENDING_BUFFER_SIZE / expectedFrameSize;
|
_pendingBufferCount = MAX_PENDING_BUFFER_SIZE / expectedFrameSize;
|
||||||
|
|
||||||
if (_pendingBufferCount > MAX_PENDING_FRAME_COUNT)
|
if (_pendingBufferCount > MAX_PENDING_FRAME_COUNT)
|
||||||
|
@ -640,9 +627,36 @@ NDSCaptureObject::~NDSCaptureObject()
|
||||||
free(this->_pendingAudioWriteSize);
|
free(this->_pendingAudioWriteSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t NDSCaptureObject::GetExpectedFrameSize(const BITMAPINFOHEADER *bmpFormat, const WAVEFORMATEX *wavFormat)
|
||||||
|
{
|
||||||
|
size_t expectedFrameSize = 0; // The expected frame size is the video frame size plus the sum of the audio samples.
|
||||||
|
|
||||||
|
if (bmpFormat != NULL)
|
||||||
|
{
|
||||||
|
expectedFrameSize += bmpFormat->biSizeImage;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wavFormat != NULL)
|
||||||
|
{
|
||||||
|
// Since the number of audio samples may not be exactly the same for each video frame,
|
||||||
|
// we double the expected size of the audio buffer for safety.
|
||||||
|
expectedFrameSize += ((wavFormat->nAvgBytesPerSec / 60) * 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return expectedFrameSize;
|
||||||
|
}
|
||||||
|
|
||||||
HRESULT NDSCaptureObject::OpenFileStream(const char *fileName)
|
HRESULT NDSCaptureObject::OpenFileStream(const char *fileName)
|
||||||
{
|
{
|
||||||
return this->_fs->Open(fileName, &this->_bmpFormat, &this->_wavFormat, this->_pendingBufferCount);
|
HRESULT error = S_OK;
|
||||||
|
|
||||||
|
error = this->_fs->InitBaseProperties(fileName, &this->_bmpFormat, &this->_wavFormat, this->_pendingBufferCount);
|
||||||
|
if (FAILED(error))
|
||||||
|
{
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this->_fs->Open();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NDSCaptureObject::CloseFileStream()
|
void NDSCaptureObject::CloseFileStream()
|
||||||
|
|
|
@ -48,7 +48,6 @@ enum FileStreamCloseAction
|
||||||
};
|
};
|
||||||
|
|
||||||
class NDSCaptureObject;
|
class NDSCaptureObject;
|
||||||
class AVIFileStream;
|
|
||||||
|
|
||||||
struct VideoConvertParam
|
struct VideoConvertParam
|
||||||
{
|
{
|
||||||
|
@ -68,7 +67,6 @@ typedef struct VideoConvertParam VideoConvertParam;
|
||||||
|
|
||||||
struct AVIFileWriteParam
|
struct AVIFileWriteParam
|
||||||
{
|
{
|
||||||
AVIFileStream *fs;
|
|
||||||
u8 *srcVideo;
|
u8 *srcVideo;
|
||||||
u8 *srcAudio;
|
u8 *srcAudio;
|
||||||
size_t videoBufferSize;
|
size_t videoBufferSize;
|
||||||
|
@ -110,9 +108,8 @@ public:
|
||||||
AVIFileStream();
|
AVIFileStream();
|
||||||
~AVIFileStream();
|
~AVIFileStream();
|
||||||
|
|
||||||
static size_t GetExpectedFrameSize(const BITMAPINFOHEADER *bmpFormat, const WAVEFORMATEX *wavFormat);
|
HRESULT InitBaseProperties(const char *fileName, BITMAPINFOHEADER *bmpFormat, WAVEFORMATEX *wavFormat, size_t pendingFrameCount);
|
||||||
|
HRESULT Open();
|
||||||
HRESULT Open(const char *fileName, BITMAPINFOHEADER *bmpFormat, WAVEFORMATEX *wavFormat, size_t pendingFrameCount);
|
|
||||||
void Close(FileStreamCloseAction theAction);
|
void Close(FileStreamCloseAction theAction);
|
||||||
bool IsValid();
|
bool IsValid();
|
||||||
|
|
||||||
|
@ -150,6 +147,8 @@ public:
|
||||||
NDSCaptureObject(size_t videoWidth, size_t videoHeight, const WAVEFORMATEX *wfex);
|
NDSCaptureObject(size_t videoWidth, size_t videoHeight, const WAVEFORMATEX *wfex);
|
||||||
~NDSCaptureObject();
|
~NDSCaptureObject();
|
||||||
|
|
||||||
|
static size_t GetExpectedFrameSize(const BITMAPINFOHEADER *bmpFormat, const WAVEFORMATEX *wavFormat);
|
||||||
|
|
||||||
HRESULT OpenFileStream(const char *fileName);
|
HRESULT OpenFileStream(const char *fileName);
|
||||||
void CloseFileStream();
|
void CloseFileStream();
|
||||||
bool IsFileStreamValid();
|
bool IsFileStreamValid();
|
||||||
|
|
Loading…
Reference in New Issue