Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PlayStation Camera frame parser more at https://psxdev.github.io/luke2.html
/*
* OrbisEyeCam library
* Copyright (C) 2013,2014,2019 Antonio Jose Ramos Marquez (aka bigboss) @psxdev on twitter
*
* Repository https://github.com/psxdev/OrbisEyeCam
typedef struct OrbisEyeCamFrame
{
BYTE* header;
BYTE* audio;
BYTE* videoFrame[2];
BYTE* videoFrameHigh[2];
BYTE* videoFrameMedium[2];
BYTE* videoFrameLow[2];
BYTE* mode;
}OrbisEyeCamFrame;
//Declare your frame
OrbisEyeCamFrame eyeFrame;
//Reserve memory for each frame pointer where you want
eyeFrame.header = (BYTE *)malloc(32*800);
eyeFrame.audio = (BYTE*)malloc(64*800);
eyeFrame.videoFrame[0] = (BYTE*)malloc(1280 * 800 * 2);
eyeFrame.videoFrame[1] = (BYTE*)malloc(1280 * 800 * 2);
eyeFrame.videoFrameHigh[0] = (BYTE*)malloc(640 * 400 * 2);
eyeFrame.videoFrameHigh[1] = (BYTE*)malloc(640 * 400 * 2);
eyeFrame.videoFrameMedium[0] = (BYTE*)malloc(320 * 200 * 2);
eyeFrame.videoFrameMedium[1] = (BYTE*)malloc(320 * 200 * 2);
eyeFrame.videoFrameLow[0] = (BYTE*)malloc(160 * 100 * 2);
eyeFrame.videoFrameLow[1] = (BYTE*)malloc(160 * 100 * 2);
//get frames with Windows Media Framework and call to getFrame to populate each frame pointer as you like :P
void getFrame(const BYTE* raw, int lineSize, int size_x, int size_y)
{
int i;
int j = 0;
for (i = 0; i < size_y; i++)
{
memcpy(&eyeFrame.header[32 * i], &raw[lineSize * 2 * i], 32);
memcpy(&eyeFrame.audio[64 * i], &raw[lineSize * 2 * i + 32], 64);
memcpy(&eyeFrame.videoFrame[0][1280 * 2 * i], &raw[lineSize * 2 * i + 32 + 64], 1280 * 2);
memcpy(&eyeFrame.videoFrame[1][1280 * 2 * i], &raw[lineSize * 2 * i + 32 + 64 + 1280 * 2], 1280 * 2);
if (i <size_y-1)
{
memcpy(&eyeFrame.videoFrameHigh[0][320*2 * i], &raw[lineSize * 2 * (i + 1) + 32 + 64 + 1280 * 2 + 1280 * 2], 320 * 2 );
memcpy(&eyeFrame.videoFrameHigh[0][320*2* (i+1)], &raw[lineSize * 2 * (i) + 32 + 64 + 1280 * 2 + 1280 * 2], 320 * 2 );
memcpy(&eyeFrame.videoFrameHigh[1][320 * 2 * i], &raw[lineSize * 2 * (i + 1) + 32 + 64 + 1280 * 2 + 1280 * 2 + 320 * 2], 320 * 2);
memcpy(&eyeFrame.videoFrameHigh[1][320 * 2 * (i + 1)], &raw[lineSize * 2 * (i)+32 + 64 + 1280 * 2 + 1280 * 2 + 320 * 2], 320 * 2);
}
if (i < size_y-3)
{
memcpy(&eyeFrame.videoFrameMedium[0][80 * 2 * i], &raw[lineSize * 2 * (i+3) + 32 + 64 + 1280 * 2 + 1280 * 2 + 320 * 2 + 320 * 2], 80 * 2);
memcpy(&eyeFrame.videoFrameMedium[0][80 * 2 * (i + 1)], &raw[lineSize * 2 * (i + 2) + 32 + 64 + 1280 * 2 + 1280 * 2 + 320 * 2 + 320 * 2], 80 * 2);
memcpy(&eyeFrame.videoFrameMedium[0][80 * 2 * (i + 2)], &raw[lineSize * 2 * (i + 1) + 32 + 64 + 1280 * 2 + 1280 * 2 + 320 * 2 + 320 * 2], 80 * 2);
memcpy(&eyeFrame.videoFrameMedium[0][80 * 2 * (i + 3)], &raw[lineSize * 2 * (i + 0) + 32 + 64 + 1280 * 2 + 1280 * 2 + 320 * 2 + 320 * 2], 80 * 2);
memcpy(&eyeFrame.videoFrameMedium[1][80 * 2 * i], &raw[lineSize * 2 * (i + 3) + 32 + 64 + 1280 * 2 + 1280 * 2 + 320 * 2 + 320 * 2 + 80 * 2], 80 * 2);
memcpy(&eyeFrame.videoFrameMedium[1][80 * 2 * (i + 1)], &raw[lineSize * 2 * (i + 2) + 32 + 64 + 1280 * 2 + 1280 * 2 + 320 * 2 + 320 * 2 + 80 * 2], 80 * 2);
memcpy(&eyeFrame.videoFrameMedium[1][80 * 2 * (i + 2)], &raw[lineSize * 2 * (i + 1) + 32 + 64 + 1280 * 2 + 1280 * 2 + 320 * 2 + 320 * 2 + 80 * 2], 80 * 2);
memcpy(&eyeFrame.videoFrameMedium[1][80 * 2 * (i + 3)], &raw[lineSize * 2 * (i + 0) + 32 + 64 + 1280 * 2 + 1280 * 2 + 320 * 2 + 320 * 2 + 80 * 2], 80 * 2);
}
if (i < size_y - 7)
{
memcpy(&eyeFrame.videoFrameLow[0][20 * 2 * i], &raw[lineSize * 2 * (i + 7) + 32 + 64 + 1280 * 2 + 1280 * 2 + 320 * 2 + 320 * 2 + 160 * 2], 20 * 2);
memcpy(&eyeFrame.videoFrameLow[0][20 * 2 * (i + 1)], &raw[lineSize * 2 * (i + 6) + 32 + 64 + 1280 * 2 + 1280 * 2 + 320 * 2 + 320 * 2 + 160 * 2], 20 * 2);
memcpy(&eyeFrame.videoFrameLow[0][20 * 2 * (i + 2)], &raw[lineSize * 2 * (i + 5) + 32 + 64 + 1280 * 2 + 1280 * 2 + 320 * 2 + 320 * 2 + 160 * 2], 20 * 2);
memcpy(&eyeFrame.videoFrameLow[0][20 * 2 * (i + 3)], &raw[lineSize * 2 * (i + 4) + 32 + 64 + 1280 * 2 + 1280 * 2 + 320 * 2 + 320 * 2 + 160 * 2], 20 * 2);
memcpy(&eyeFrame.videoFrameLow[0][20 * 2 * (i + 4)], &raw[lineSize * 2 * (i + 3) + 32 + 64 + 1280 * 2 + 1280 * 2 + 320 * 2 + 320 * 2 + 160 * 2], 20 * 2);
memcpy(&eyeFrame.videoFrameLow[0][20 * 2 * (i + 5)], &raw[lineSize * 2 * (i + 2) + 32 + 64 + 1280 * 2 + 1280 * 2 + 320 * 2 + 320 * 2 + 160 * 2], 20 * 2);
memcpy(&eyeFrame.videoFrameLow[0][20 * 2 * (i + 6)], &raw[lineSize * 2 * (i + 1) + 32 + 64 + 1280 * 2 + 1280 * 2 + 320 * 2 + 320 * 2 + 160 * 2], 20 * 2);
memcpy(&eyeFrame.videoFrameLow[0][20 * 2 * (i + 7)], &raw[lineSize * 2 * (i + 0) + 32 + 64 + 1280 * 2 + 1280 * 2 + 320 * 2 + 320 * 2 + 160 * 2], 20 * 2);
memcpy(&eyeFrame.videoFrameLow[1][20 * 2 * i], &raw[lineSize * 2 * (i + 7) + 32 + 64 + 1280 * 2 + 1280 * 2 + 320 * 2 + 320 * 2 + 160 * 2 + 20 * 2], 20 * 2);
memcpy(&eyeFrame.videoFrameLow[1][20 * 2 * (i + 1)], &raw[lineSize * 2 * (i + 6) + 32 + 64 + 1280 * 2 + 1280 * 2 + 320 * 2 + 320 * 2 + 160 * 2 + 20 * 2], 20 * 2);
memcpy(&eyeFrame.videoFrameLow[1][20 * 2 * (i + 2)], &raw[lineSize * 2 * (i + 5) + 32 + 64 + 1280 * 2 + 1280 * 2 + 320 * 2 + 320 * 2 + 160 * 2 + 20 * 2], 20 * 2);
memcpy(&eyeFrame.videoFrameLow[1][20 * 2 * (i + 3)], &raw[lineSize * 2 * (i + 4) + 32 + 64 + 1280 * 2 + 1280 * 2 + 320 * 2 + 320 * 2 + 160 * 2 + 20 * 2], 20 * 2);
memcpy(&eyeFrame.videoFrameLow[1][20 * 2 * (i + 4)], &raw[lineSize * 2 * (i + 3) + 32 + 64 + 1280 * 2 + 1280 * 2 + 320 * 2 + 320 * 2 + 160 * 2 + 20 * 2], 20 * 2);
memcpy(&eyeFrame.videoFrameLow[1][20 * 2 * (i + 5)], &raw[lineSize * 2 * (i + 2) + 32 + 64 + 1280 * 2 + 1280 * 2 + 320 * 2 + 320 * 2 + 160 * 2 + 20 * 2], 20 * 2);
memcpy(&eyeFrame.videoFrameLow[1][20 * 2 * (i + 6)], &raw[lineSize * 2 * (i + 1) + 32 + 64 + 1280 * 2 + 1280 * 2 + 320 * 2 + 320 * 2 + 160 * 2 + 20 * 2], 20 * 2);
memcpy(&eyeFrame.videoFrameLow[1][20 * 2 * (i + 7)], &raw[lineSize * 2 * (i + 0) + 32 + 64 + 1280 * 2 + 1280 * 2 + 320 * 2 + 320 * 2 + 160 * 2 + 20 * 2], 20 * 2);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment