openh264/test/DataGenerator.cpp
Martin Storsjö dca9d628f7 Include time.h in DataGenerator.cpp
This fixes building on MSVC.
2014-03-14 15:16:34 +02:00

67 lines
1.7 KiB
C++

#include <string.h>//memset/memcpy
#include <time.h>
#include "utils/DataGenerator.h"
#include "utils/BufferedData.h"
#include "utils/FileInputStream.h"
using namespace std;
bool YUVPixelDataGenerator( uint8_t* pPointer, int32_t iWidth, int32_t iHeight, int32_t iStride )
{
#define SRC_FRAME_WIDTH (160)
#define SRC_FRAME_HEIGHT (96)
if ( SRC_FRAME_WIDTH-iWidth <= 0 || SRC_FRAME_HEIGHT-iHeight <= 0 ) {
return false;
}
const int32_t kiFrameSize = SRC_FRAME_WIDTH*SRC_FRAME_HEIGHT;
BufferedData sBuf;
sBuf.SetLength(kiFrameSize);
if (sBuf.Length() != kiFrameSize) {
return false;
}
FileInputStream fileStream;
if (!fileStream.Open("res/CiscoVT2people_160x96_6fps.yuv")) {
return false;
}
if (fileStream.read(sBuf.data(), kiFrameSize) == kiFrameSize) {
srand((uint32_t)time(NULL));
int32_t iStartPosX = rand()%(SRC_FRAME_WIDTH-iWidth);
int32_t iStartPosY = rand()%(SRC_FRAME_HEIGHT-iHeight);
uint8_t* pSrcPointer = sBuf.data() + iStartPosX + iStartPosY*SRC_FRAME_WIDTH;
uint8_t* pLocalPointer = pPointer;
for (int j=0;j<iHeight;j++) {
memcpy(pLocalPointer, pSrcPointer, iWidth*sizeof(uint8_t));
pLocalPointer += iStride;
pSrcPointer += SRC_FRAME_WIDTH;
}
return true;
}
return false;
}
void RandomPixelDataGenerator( uint8_t* pPointer, int32_t iWidth, int32_t iHeight, int32_t iStride )
{
uint8_t* pLocalPointer = pPointer;
for (int32_t j=0;j<iHeight;j++) {
for (int32_t i=0;i<iWidth;i++) {
pLocalPointer[i] = rand()%256;
}
pLocalPointer += iStride;
}
}
void RandomResidueDataGenerator( uint16_t* pPointer, int32_t iWidth, int32_t iHeight, int32_t iStride )
{
}
void RandomCoeffDataGenerator( uint16_t* pPointer, int32_t iWidth, int32_t iHeight, int32_t iStride )
{
}