?? main.cpp
字號:
/*
* this src is used for testing the v4l and the sdl .
* Beside this,it provides a simple wrap of v4l and sdl .
* You can use it any where,but should keep this header.
* Any suggestion is appreicated.
*
* Tianjin University , China.
*
* vinqosky@gmail.com
*/
#include <unistd.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include "v4l_layer.h"
#include "sdl_layer.h"
#include "rgb2yuv.h"
#include "main.h"
#define noDEBUG_YUV_FRAME
int closeFlag;
//signal handler
void closeHandler(int sig)
{
//fprintf(stdout,"test closeHandler.\n");
closeFlag = 1;
}
int main(int argc,char **argv)
{
int width = 320;
int height = 240;
int ysize = width*height;
int uvsize = ysize/4;
closeFlag = 0;
signal (SIGINT, closeHandler);
u_int8_t *pRgbImage = NULL;
u_int8_t *pY = NULL;
u_int8_t *pU = NULL;
u_int8_t *pV = NULL;
pRgbImage = (u_int8_t *)malloc(ysize*3);
pY = (u_int8_t*)malloc(ysize);
pU = (u_int8_t*)malloc(uvsize);
pV = (u_int8_t*)malloc(uvsize);
CV4lSrc mySrc;
CSDLDisplay myDisplay;
if(mySrc.init("/dev/video0",width,height)<0)
{
//ERROR
return -1;
}
mySrc.setFrame(width,height);
if(myDisplay.init(width,height)<0)
{
//ERROR
return -1;
}
while(!closeFlag)
{
//get a frame
if(mySrc.getAFrame(pRgbImage)<0)
{
//ERROR
fprintf(stdout,"Error in get a frame.\n");
break;
}
//convert rgb to yuv
if(RGB2YUV(width,height,pRgbImage,pY,pU,pV,1)!=0)
{
//ERROR
fprintf(stdout,"error in rgb2yuv.\n");
break;
}
#ifdef DEBUG_YUV_FRAME
//save a yuv
static int inc = 0;
char filestr[128];
sprintf(filestr,"yuv-%d.tst",inc);
FILE *yuvFile;
if((yuvFile = fopen(filestr,"w+")) == NULL)
{
//ERROR
exit(1);
}
fwrite((unsigned char *)pY,ysize,1,yuvFile);
fwrite((unsigned char *)pU,uvsize,1,yuvFile);
fwrite((unsigned char *)pV,uvsize,1,yuvFile);
inc++;
fclose(yuvFile);
#endif //DEBUG_YUV_FRAME
myDisplay.display(pY,pU, pV);
usleep(1000/30);
}
mySrc.closeIt();
myDisplay.closeIt();
if(pU!=NULL)
free(pU);
if(pY!=NULL)
free(pY);
if(pV!=NULL)
free(pV);
return 0;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -