Streaming and Using HW Merge Example Code.
This example shows you how to create a streaming application that uses the hardware merging capabilities on host the PCIE Fibre card.
#include "stdint.h"
#include "stdlib.h"
#include "stdio.h"
#if defined(_WIN32) || defined(_WINDOWS)
#include "windows.h"
#else
#include "unistd.h"
#include "string.h"
#endif
#include "wchar.h"
#define FLI_TEST_MAX_SUPPORTED_CAMERAS (4)
static int32_t SetFrameInfo(int32_t iDeviceHandle);
static int32_t CheckReferenceMetaData(FILE* pFile);
static int32_t SendHWMergeReferenceFiles(int32_t iHandle, const char* pDSNUFileName, const char* pPRNUFileName, uint32_t uiWidth, uint32_t uiHeight);
static int32_t s_iDeviceHandle;
uint32_t uiNumDetectedDevices;
static FPRODEVICEINFO s_camDeviceInfo[FLI_TEST_MAX_SUPPORTED_CAMERAS];
#define STREAMER_PATH_MAX (1024)
static wchar_t s_wcStreamerPath[STREAMER_PATH_MAX];
static wchar_t s_wcStreamerPrefix[STREAMER_PATH_MAX];
int main()
{
int32_t iResult;
uiNumDetectedDevices = FLI_TEST_MAX_SUPPORTED_CAMERAS;
if ((iResult >= 0) && (uiNumDetectedDevices > 0))
{
s_iDeviceHandle = -1;
iResult =
FPROCam_Open(&s_camDeviceInfo[0], &s_iDeviceHandle);
if ((iResult >= 0) && (s_iDeviceHandle >= 0))
{
if (iResult >= 0)
iResult = SetFrameInfo(s_iDeviceHandle);
}
}
return 0;
}
{
int32_t iResult;
uint32_t uiFramSizeInBytes;
uint32_t uiNumFrames;
if (iResult >= 0)
{
if (iResult >= 0)
{
uiNumFrames = 10;
#if defined(_WIN32) || defined(_WINDOWS)
wcscpy_s(s_wcStreamerPath, STREAMER_PATH_MAX, L"./StreamerFiles");
wcscpy_s(s_wcStreamerPrefix, STREAMER_PATH_MAX, L"myFiles");
#else
wcscpy(s_wcStreamerPath, L"./StreamerFiles");
wcscpy(s_wcStreamerPrefix, L"myFiles");
#endif
if (iResult >= 0)
{
if (iResult >= 0)
{
while ((iResult >= 0) &&
{
#if defined(_WIN32) || defined(_WINDOWS)
Sleep(1000);
#else
sleep(1);
#endif
fflush(stdout);
}
printf("\n");
{
printf("Stream Error\n");
}
}
}
}
}
}
int32_t
SetFrameInfo(int32_t iDeviceHandle)
{
int32_t iResult;
iResult = 0;
if (iResult >= 0)
if (iResult >= 0)
return(iResult);
}
int32_t CheckReferenceMetaData(FILE* pFile)
{
int32_t iResult;
size_t uiBytesRead;
uint32_t uiMetaSize;
uint32_t uiFileSize;
uint8_t uiMetaCheck[6];
iResult = -1;
fseek(pFile, 0L, SEEK_END);
uiFileSize = ftell(pFile);
fseek(pFile, 0L, SEEK_SET);
#if defined(_WIN32) || defined(_WINDOWS)
uiBytesRead = fread_s(uiMetaCheck, 6, 1, 6, pFile);
#else
uiBytesRead= fread(uiMetaCheck, 1, 6, pFile);
#endif
if (uiBytesRead == 6)
{
if ((uiMetaCheck[0] == 'M') && (uiMetaCheck[1] == 'e') && (uiMetaCheck[2] == 't') && (uiMetaCheck[3] == 'a'))
{
uiMetaSize = ((uint32_t)uiMetaCheck[4] & 0xFF) << 8;
uiMetaSize |= (uint32_t)uiMetaCheck[5] & 0xFF;
if (uiMetaSize < uiFileSize)
{
iResult = 0;
fseek(pFile, uiMetaSize, SEEK_SET);
}
}
}
return(iResult);
}
int32_t SendHWMergeReferenceFiles(int32_t iHandle, const char* pDSNUFileName, const char* pPRNUFileName, uint32_t uiWidth, uint32_t uiHeight)
{
int32_t iResult;
FILE* pDSNUFile;
FILE* pPRNUFile;
uint32_t uiFrameSize;
size_t uiBytesRead;
iResult = 0;
memset(&refFrames, 0, sizeof(refFrames));
pDSNUFile = NULL;
pPRNUFile = NULL;
if (pDSNUFileName)
{
#if defined(_WIN32) || defined(_WINDOWS)
fopen_s(&pDSNUFile, pDSNUFileName, "r+b");
#else
pDSNUFile= fopen(pDSNUFileName, "r+b");
#endif
iResult = CheckReferenceMetaData(pDSNUFile);
}
if ((pPRNUFileName) && (iResult >= 0))
{
#if defined(_WIN32) || defined(_WINDOWS)
fopen_s(&pPRNUFile, pPRNUFileName, "r+b");
#else
pPRNUFile= fopen(pPRNUFileName, "r+b");
#endif
iResult = CheckReferenceMetaData(pPRNUFile);
}
if (iResult >= 0)
{
iResult = 0;
if (pDSNUFile)
{
{
uiFrameSize = uiWidth * uiHeight * sizeof(uint16_t);
#if defined(_WIN32) || defined(_WINDOWS)
uiBytesRead = fread_s(refFrames.
pAdditiveLowGain, uiFrameSize, 1, uiFrameSize, pDSNUFile);
#else
#endif
if (uiBytesRead != uiFrameSize)
iResult = -1;
if (iResult >= 0)
{
#if defined(_WIN32) || defined(_WINDOWS)
uiBytesRead = fread_s(refFrames.
pAdditiveHighGain, uiFrameSize, 1, uiFrameSize, pDSNUFile);
#else
#endif
if (uiBytesRead != uiFrameSize)
iResult = -1;
}
}
}
if (pPRNUFile)
{
{
if (iResult >= 0)
{
#if defined(_WIN32) || defined(_WINDOWS)
#else
#endif
if (uiBytesRead != uiFrameSize)
iResult = -1;
}
if (iResult >= 0)
{
#if defined(_WIN32) || defined(_WINDOWS)
#else
#endif
if (uiBytesRead != uiFrameSize)
iResult = -1;
}
}
}
if (iResult >= 0)
{
}
if (pDSNUFile)
fclose(pDSNUFile);
if (pPRNUFile)
fclose(pPRNUFile);
}
return(iResult);
}