20 #if defined (MSWindows)
21 #define FILENO_FUNCTION _fileno
23 #define FILENO_FUNCTION fileno
33 mHevcFileFrameCount (0),
35 mEncFileFrameCount (0),
37 mAiffFileFrameCount (0),
46 mYuvNumTotalFrames (0),
48 mRawFileFrameCount (0),
112 mHevcFd = fopen(inFileName.c_str(),
"wb");
117 mMaxHevcFrames = maxFrames;
136 if ((mHevcFd ==
NULL) ||
139 (mMaxHevcFrames == 0))
return;
141 if((mMaxHevcFrames != 0xffffffff) && (mHevcFileFrameCount > mMaxHevcFrames))
143 fseek (mHevcFd, 0, SEEK_SET);
144 mHevcFileFrameCount = 0;
147 fwrite(pBuffer, 1, bufferSize, mHevcFd);
148 mHevcFileFrameCount++;
161 mEncFd = fopen(inFileName.c_str(),
"w");
166 mMaxEncFrames = maxFrames;
185 if ((mEncFd ==
NULL) ||
188 (mMaxEncFrames == 0))
return;
190 if((mMaxEncFrames != 0xffffffff) && (mEncFileFrameCount > mMaxEncFrames))
192 fseek (mEncFd, 0, SEEK_SET);
193 mEncFileFrameCount = 0;
198 const char* pPicType =
"Unknown";
201 case 0: pPicType =
"I-frame";
break;
202 case 1: pPicType =
"P-frame";
break;
203 case 2: pPicType =
"B-frame";
break;
206 const char* pIdrState =
"Unknown";
209 case 0: pIdrState =
"false";
break;
210 case 1: pIdrState =
"true";
break;
211 case 3: pIdrState =
"command";
break;
219 fprintf(mEncFd,
"Serial number: %d Picture type: %s IDR state: %s Last frame: %s\n",
221 fprintf(mEncFd,
"Frame offset: 0x%0llx Frame Size: %d\n",
222 offset, pEncData->
esSize);
223 fprintf(mEncFd,
"PTS: %lld DTS: %lld\n",
225 fprintf(mEncFd,
"Temporal ID: %d NAL offset: 0x%x\n",
227 fprintf(mEncFd,
"CPB data size: %d Additional data: %d\n\n",
230 mEncFileFrameCount++;
243 mAiffFd = fopen(inFileName.c_str(),
"wb");
250 mAiffWriteBuffer =
new uint8_t [bufferSize];
251 if (mAiffWriteBuffer ==
NULL)
259 mAiffNumChannels = numChannels;
260 mMaxAiffFrames = maxFrames;
280 if (mAiffWriteBuffer !=
NULL)
282 delete [] mAiffWriteBuffer;
283 mAiffWriteBuffer =
NULL;
290 if (mAiffFd ==
NULL)
return;
292 fseek (mAiffFd, 0, SEEK_SET);
295 fprintf (mAiffFd,
"FORM");
296 fputc ((
int)((mAiffTotalSize >> 24) & 0xff), mAiffFd);
297 fputc ((
int)((mAiffTotalSize >> 16) & 0xff), mAiffFd);
298 fputc ((
int)((mAiffTotalSize >> 8) & 0xff), mAiffFd);
299 fputc ((
int)((mAiffTotalSize >> 0) & 0xff), mAiffFd);
300 fprintf (mAiffFd,
"AIFF");
305 fprintf (mAiffFd,
"COMM");
311 fputc (mAiffNumChannels, mAiffFd);
312 fputc ((
int)((mAiffNumSamples >> 24) & 0xff), mAiffFd);
313 fputc ((
int)((mAiffNumSamples >> 16) & 0xff), mAiffFd);
314 fputc ((
int)((mAiffNumSamples >> 8) & 0xff), mAiffFd);
315 fputc ((
int)((mAiffNumSamples >> 0) & 0xff), mAiffFd);
318 fputc (0x40, mAiffFd);
319 fputc (0x0e, mAiffFd);
320 fputc (0xbb, mAiffFd);
321 fputc (0x80, mAiffFd);
329 mAiffTotalSize += 26;
332 uint32_t chunkSize = 2*mAiffNumChannels*mAiffNumSamples + 8;
335 fprintf (mAiffFd,
"SSND");
336 fputc ((
int)((chunkSize >> 24) & 0xff), mAiffFd);
337 fputc ((
int)((chunkSize >> 16) & 0xff), mAiffFd);
338 fputc ((
int)((chunkSize >> 8) & 0xff), mAiffFd);
339 fputc ((
int)((chunkSize >> 0) & 0xff), mAiffFd);
349 mAiffTotalSize += 16;
357 uint8_t* pAudio = (uint8_t*)pBuffer;
358 uint8_t* pAiff = mAiffWriteBuffer;
360 if ((mAiffFd ==
NULL) ||
362 (numChannels == 0) ||
364 (mMaxAiffFrames == 0))
return;
366 if((mMaxAiffFrames != 0xffffffff) && (mAiffFileFrameCount > mMaxAiffFrames))
368 fseek (mAiffFd, 0, SEEK_SET);
369 mAiffFileFrameCount = 0;
373 for (uint32_t is = 0; is < numSamples; is++)
375 for (uint32_t ic = 0; ic < numChannels; ic++)
377 if (ic < mAiffNumChannels)
379 *pAiff++ = *(pAudio+3);
380 *pAiff++ = *(pAudio+2);
387 uint32_t audioSize = 2*mAiffNumChannels*numSamples;
390 fwrite(mAiffWriteBuffer, 1, audioSize, mAiffFd);
393 mAiffNumSamples += numSamples;
394 mAiffTotalSize += audioSize;
396 mAiffFileFrameCount++;
402 struct stat fileStat;
411 mYuvFd = fopen(inFileName.c_str(),
"rb");
419 mYuvFileSize = fileStat.st_size;
422 mYuvFrameWidth = width;
423 mYuvFrameHeight = height;
424 mYuvFrameSize = (width * height) + ((width * height) / 2);
425 mYuvNumTotalFrames = uint32_t(mYuvFileSize / mYuvFrameSize);
441 mYuvNumTotalFrames = 0;
450 if (numFrame > mYuvNumTotalFrames)
459 result = fread(pBuffer, 1, mYuvFrameSize, mYuvFd);
460 if (result != (mYuvFrameSize))
470 if (bufferSize != mYuvFrameSize)
474 memcpy(pDstBuffer, pSrcBuffer, (mYuvFrameWidth * mYuvFrameHeight));
480 srcCbPtr = (
char*)pSrcBuffer + (mYuvFrameWidth * mYuvFrameHeight);
481 srcCrPtr = (
char*)pSrcBuffer + (mYuvFrameWidth * mYuvFrameHeight) + ((mYuvFrameWidth * mYuvFrameHeight) / 4);
482 destCbCrPtr = (
char*)pDstBuffer + (mYuvFrameWidth * mYuvFrameHeight);
485 for (uint32_t i = 0; i< (mYuvFrameWidth * mYuvFrameHeight) / 4; i++)
487 *destCbCrPtr++ = *srcCbPtr++;
488 *destCbCrPtr++ = *srcCrPtr++;
504 mRawFd = fopen(inFileName.c_str(),
"wb");
509 mMaxRawFrames = maxFrames;
528 if ((mRawFd ==
NULL) ||
531 (mMaxRawFrames == 0))
return;
533 if((mMaxRawFrames != 0xffffffff) && (mRawFileFrameCount > mMaxRawFrames))
535 fseek (mRawFd, 0, SEEK_SET);
536 mRawFileFrameCount = 0;
539 fwrite(pBuffer, 1, bufferSize, mRawFd);
540 mRawFileFrameCount++;
546 if ((pBuffer ==
NULL) ||
548 (dataSize == 0))
return 0;
550 if (alignBytes == 0)
return dataSize;
553 uint32_t alignSize = ((dataSize - 1)/alignBytes + 1)*alignBytes;
554 if (alignSize > bufferSize)
return dataSize;
557 uint8_t* pData = (uint8_t*)pBuffer;
558 for (uint32_t i = dataSize; i < alignSize; i++)
610 videoFormat = sdiFormat;
627 pM31->GetMainState(&mainState, &encodeMode);
635 pM31->GetMainState(&mainState);
643 pM31->GetMainState(&mainState);
649 pM31->ClearAllParams();
652 if (!pM31->SetupCommonParams(preset,
M31_CH0))
659 pM31->GetMainState(&mainState);
665 if (!pM31->SetupVIParams(preset, encodeChannel))
667 if (!pM31->SetupVInParams(preset, encodeChannel))
669 if (!pM31->SetupVAParams(preset, encodeChannel))
671 if (!pM31->SetupEHParams(preset, encodeChannel))
685 pM31->GetVInState(&vInState, encodeChannel);
687 {cout <<
"## VIn didn't start = '" << vInState << endl; }
692 pM31->GetEHState(&ehState, encodeChannel);
694 { cout <<
"## EH didn't start = '" << ehState << endl; }
700 pM31->GetMainState(&mainState, &encodeMode);
708 pM31->GetMainState(&mainState);
716 pM31->GetMainState(&mainState);
723 pM31->ClearAllParams();
726 if (!pM31->LoadAllParams(preset))
730 if (!pM31->SetAllParams(
M31_CH0))
733 if (!pM31->SetAllParams(
M31_CH1))
736 if (!pM31->SetAllParams(
M31_CH2))
739 if (!pM31->SetAllParams(
M31_CH3))
760 pM31->GetMainState(&mainState);
768 pM31->GetVInState(&vInState,
M31_CH0);
770 {cout <<
"## VIn didn't start = '" << vInState << endl; }
775 pM31->GetEHState(&ehState,
M31_CH0);
777 {cout <<
"## EH didn't start = '" << ehState << endl; }