#include #include #include #include #include #include #include #include #include #include "libyuv.h" #include "xmlparam.h" static bool gbRun = true; #define MAX_WIDHT 4096 #define MAX_HEIGHT 2160 #include "modulecomm.h" #include #include #include #include "zerobuffer.h" ZeroBuffer * gbuffer; extern char * gstrbuffer; extern QMutex gMutexLock; extern bool gbNewData; extern QWaitCondition gwc; static char * gstrwidth ="1280"; static char * gstrheight = "720"; int gnwidth,gnheight; extern void StartNVENC(char * strwidth,char * strheight); extern bool gbNewOut; extern QWaitCondition gwcout; extern char * gstrout; extern QMutex gWaitMutexout; extern QMutex gMutexout; extern int gnoutsize ; void * gpaout; void yuv_rotate_180(uint8_t* yuvbuf, uint8_t* dstbuf,int width,int height){ int idx = 0; //旋转180:将右下角的点作为第一个点,从右往左,从下往上取点 //Y 宽:[0,w-1] 高:[0,h-1] for (int i = height-1; i >=0; i--){ for (int j = width-1 ; j >= 0; j--){ dstbuf[idx++] = *(yuvbuf+(i*width+j)); } } uint8_t* uheader = yuvbuf + width*height; //U for (int i = height/2 - 1; i >= 0; i--){ for (int j = width/2-1 ; j >= 0; j--){ dstbuf[idx++] = *(uheader + (i*width / 2 + j)); } } uint8_t* vheader = uheader + width*height/4; //V for (int i = height / 2 - 1; i >= 0; i--){ for (int j = width / 2-1 ; j >=0; j--){ dstbuf[idx++] = *(vheader + (i*width / 2 + j)); } } } void threadcap( std::string dev,std::string name,std::int32_t width,std::int32_t height,bool bRotate) { printf("width=%d,height=%d\n",width,height); CV4l2Cam cam(dev,width,height); do{ if(cam.Init() < 0) { printf("camera init failed and retry after 3s\n"); sleep(3); } else { break; } }while(1); cam.startAcquire(); static unsigned char yuv[3*MAX_HEIGHT*MAX_WIDHT/2]; unsigned char * yuvrotate = new unsigned char[3*MAX_HEIGHT*MAX_WIDHT/2]; unsigned char *yuyv = NULL; int yuyvlen = 0; while(1) { if(cam.GrabImg(yuyv,yuyvlen) == 0) { libyuv::YUY2ToI420(yuyv,2*width, yuv,width, yuv+width*height,width/2, yuv+5*width*height/4,width/2, width, height); // std::cout<<" grab a img. time: "<RequireBuffer(&p,1000); if(nrtn < 0) { std::cout<<" Get Zero Buffer Fail."<UpdateDataSize(width*height*3/2); gbuffer->ReleaseBuffer(); // imgpub.Send(yuv,3*width*height/2); } } cam.stopAcquire(); cam.Release(); } void threadout() { char * strout = new char[10000000]; int nout = 0; while(1) { gWaitMutexout.lock(); gwcout.wait(&gWaitMutexout,10); gWaitMutexout.unlock(); if(gbNewOut) { gMutexout.lock(); memcpy(strout, gstrout,gnoutsize); nout = gnoutsize; gbNewOut = false; gMutexout.unlock(); // std::cout<<"send out. "<