QVector<VideoMode> v4l2::getDeviceModes(QString devName) { QVector<VideoMode> modes; int error = 0; int fd = deviceOpen(devName, &error); if (fd < 0 || error != 0) return modes; v4l2_fmtdesc vfd{}; vfd.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; while (!ioctl(fd, VIDIOC_ENUM_FMT, &vfd)) { vfd.index++; v4l2_frmsizeenum vfse{}; vfse.pixel_format = vfd.pixelformat; while (!ioctl(fd, VIDIOC_ENUM_FRAMESIZES, &vfse)) { VideoMode mode; mode.pixel_format = vfse.pixel_format; switch (vfse.type) { case V4L2_FRMSIZE_TYPE_DISCRETE: mode.width = vfse.discrete.width; mode.height = vfse.discrete.height; break; case V4L2_FRMSIZE_TYPE_CONTINUOUS: case V4L2_FRMSIZE_TYPE_STEPWISE: mode.width = vfse.stepwise.max_width; mode.height = vfse.stepwise.max_height; break; default: continue; } QVector<unsigned short> rates = getDeviceModeFramerates(fd, mode.width, mode.height, vfd.pixelformat); for (unsigned short rate : rates) { mode.FPS = rate; if (!modes.contains(mode)) modes.append(std::move(mode)); } vfse.index++; } } return modes; }
int main(int argc, char* argv) { fb_init(); printf("after fb_init\n"); deviceOpen(); printf("after deviceOpen\n"); if(!deviceInit()) { return 0; } printf("after deviceInit\n"); captureStart(); printf("after captureStart\n"); while(1) { mainLoop(); printf("in mainLoop\n"); } printf("*****quit\n"); }
int main(int argc, char **argv) { for (;;) { int index, c = 0; c = getopt_long(argc, argv, short_options, long_options, &index); if (-1 == c) break; switch (c) { case 0: /* getopt_long() flag */ break; case 'd': deviceName = optarg; break; case 'h': // print help usage(stdout, argc, argv); exit(EXIT_SUCCESS); case 'o': // set jpeg filename jpegFilename = optarg; break; case 'q': // set jpeg quality jpegQuality = atoi(optarg); break; case 'm': #ifdef IO_MMAP io = IO_METHOD_MMAP; #else fprintf(stderr, "You didn't compile for mmap support.\n"); exit(EXIT_FAILURE); #endif break; case 'r': #ifdef IO_READ io = IO_METHOD_READ; #else fprintf(stderr, "You didn't compile for read support.\n"); exit(EXIT_FAILURE); #endif break; case 'u': #ifdef IO_USERPTR io = IO_METHOD_USERPTR; #else fprintf(stderr, "You didn't compile for userptr support.\n"); exit(EXIT_FAILURE); #endif break; case 'W': // set width width = atoi(optarg); break; case 'H': // set height height = atoi(optarg); break; case 'I': // set fps fps = atoi(optarg); break; case 'c': // set flag for continuous capture, interuptible by sigint continuous = 1; InstallSIGINTHandler(); break; case 'v': printf("Version: %s\n", VERSION); exit(EXIT_SUCCESS); break; default: usage(stderr, argc, argv); exit(EXIT_FAILURE); } } // check for need parameters if (!jpegFilename) { fprintf(stderr, "You have to specify JPEG output filename!\n\n"); usage(stdout, argc, argv); exit(EXIT_FAILURE); } if(continuous == 1) { int max_name_len = snprintf(NULL,0,continuousFilenameFmt,jpegFilename,UINT32_MAX,INT64_MAX); jpegFilenamePart = jpegFilename; jpegFilename = calloc(max_name_len+1,sizeof(char)); strcpy(jpegFilename,jpegFilenamePart); } // open and initialize device deviceOpen(); deviceInit(); // start capturing captureStart(); // process frames mainLoop(); // stop capturing captureStop(); // close device deviceUninit(); deviceClose(); if(jpegFilenamePart != 0) { free(jpegFilename); } exit(EXIT_SUCCESS); return 0; }
/* * ======== encode_decode ======== */ static Void encode_decode(VIDENC_Handle enc, VIDDEC_Handle dec, FILE *in, FILE *out) { Int n; Int32 status; VIDDEC_InArgs decInArgs; VIDDEC_OutArgs decOutArgs; VIDDEC_DynamicParams decDynParams; VIDDEC_Status decStatus; VIDENC_InArgs encInArgs; VIDENC_OutArgs encOutArgs; VIDENC_DynamicParams encDynParams; VIDENC_Status encStatus; XDM_BufDesc inBufDesc; XDAS_Int8 *src[XDM_MAX_IO_BUFFERS]; XDAS_Int32 inBufSizes[XDM_MAX_IO_BUFFERS]; XDM_BufDesc encodedBufDesc; XDAS_Int8 *encoded[XDM_MAX_IO_BUFFERS]; XDAS_Int32 encBufSizes[XDM_MAX_IO_BUFFERS]; XDM_BufDesc outBufDesc; XDAS_Int8 *dst[XDM_MAX_IO_BUFFERS]; XDAS_Int32 outBufSizes[XDM_MAX_IO_BUFFERS]; /* clear and initialize the buffer descriptors */ memset(src, 0, sizeof(src[0]) * XDM_MAX_IO_BUFFERS); memset(encoded, 0, sizeof(encoded[0]) * XDM_MAX_IO_BUFFERS); memset(dst, 0, sizeof(dst[0]) * XDM_MAX_IO_BUFFERS); src[0] = inBuf; encoded[0] = encodedBuf; dst[0] = outBuf; inBufDesc.numBufs = encodedBufDesc.numBufs = outBufDesc.numBufs = 1; inBufDesc.bufSizes = inBufSizes; encodedBufDesc.bufSizes = encBufSizes; outBufDesc.bufSizes = outBufSizes; //Note , this declaration is tell the memtab how much need to allocate the buf sizes inBufSizes[0] = IFRAMESIZE; encBufSizes[0] = EFRAMESIZE; outBufSizes[0] = OFRAMESIZE; inBufDesc.bufs = src; encodedBufDesc.bufs = encoded; outBufDesc.bufs = dst; /* initialize all "sized" fields */ encInArgs.size = sizeof(encInArgs); decInArgs.size = sizeof(decInArgs); encOutArgs.size = sizeof(encOutArgs); decOutArgs.size = sizeof(decOutArgs); encDynParams.size = sizeof(encDynParams); decDynParams.size = sizeof(decDynParams); encStatus.size = sizeof(encStatus); decStatus.size = sizeof(decStatus); /* * Query the encoder and decoder. * This app expects the encoder to provide 1 buf in and get 1 buf out, * and the buf sizes of the in and out buffer must be able to handle * NSAMPLES bytes of data. */ status = VIDENC_control(enc, XDM_GETSTATUS, &encDynParams, &encStatus); if (status != VIDENC_EOK) { /* failure, report error and exit */ GT_1trace(curMask, GT_7CLASS, "encode control status = 0x%x\n", status); return; } /* Validate this encoder codec will meet our buffer requirements */ if ((inBufDesc.numBufs < encStatus.bufInfo.minNumInBufs) || (IFRAMESIZE < encStatus.bufInfo.minInBufSize[0]) || (encodedBufDesc.numBufs < encStatus.bufInfo.minNumOutBufs) || (EFRAMESIZE < encStatus.bufInfo.minOutBufSize[0])) { /* failure, report error and exit */ GT_0trace(curMask, GT_7CLASS, "Error: encoder codec feature conflict\n"); return; } //#if 0 status = VIDDEC_control(dec, XDM_GETSTATUS, &decDynParams, &decStatus); if (status != VIDDEC_EOK) { /* failure, report error and exit */ GT_1trace(curMask, GT_7CLASS, "decode control status = 0x%x\n", status); return; } //#endif /* Validate this decoder codec will meet our buffer requirements */ if ((encodedBufDesc.numBufs < decStatus.bufInfo.minNumInBufs) || (EFRAMESIZE < decStatus.bufInfo.minInBufSize[0]) || (outBufDesc.numBufs < decStatus.bufInfo.minNumOutBufs) || (OFRAMESIZE < decStatus.bufInfo.minOutBufSize[0])) { /* failure, report error and exit */ GT_0trace(curMask, GT_7CLASS, "App-> ERROR: decoder does not meet buffer requirements.\n"); return; } /* * Read complete frames from in, encode, decode, and write to out. */ /* opencv create init image */ #ifdef USE_OPENCV_DISPLAY cvNamedWindow("sobel",CV_WINDOW_AUTOSIZE); cvResizeWindow("sobel",320,240);//怕畫面太大讓人看不完,所以顯示視窗設小一點 #endif CvSize size=cvSize(320,240); frame=cvCreateImage(size,IPL_DEPTH_8U,3); frame_gray=cvCreateImage(size,IPL_DEPTH_8U,1); frame_Smooth=cvCreateImage(size,IPL_DEPTH_8U,1); frame_sobel=cvCreateImage(size,IPL_DEPTH_16S,1); frame_sobel_8U=cvCreateImage(size,IPL_DEPTH_8U,1); /* v4l2 init */ int count=0; deviceOpen(); deviceInit(); /*start capturing*/ captureStart(); /*===============v4l2 grab frame by Camera======================*/ while(1){ mainLoop(); /*this is the v4l2grab frame*/ memcpy(inBuf,buffers[0].start,IFRAMESIZE); #ifdef CACHE_ENABLED #ifdef xdc_target__isaCompatible_64P /* * fread() on this processor is implemented using CCS's stdio, which * is known to write into the cache, not physical memory. To meet * xDAIS DMA Rule 7, we must writeback the cache into physical * memory. Also, per DMA Rule 7, we must invalidate the buffer's * cache before providing it to any xDAIS algorithm. */ Memory_cacheWbInv(inBuf, IFRAMESIZE); #else #error Unvalidated config - add appropriate fread-related cache maintenance #endif /* Per DMA Rule 7, our output buffer cache lines must be cleaned */ Memory_cacheInv(encodedBuf, EFRAMESIZE); #endif GT_1trace(curMask, GT_1CLASS, "App-> Processing frame %d...\n", count); /* encode the frame */ status = VIDENC_process(enc, &inBufDesc, &encodedBufDesc, &encInArgs, &encOutArgs); GT_2trace(curMask, GT_2CLASS, "App-> Encoder frame %d process returned - 0x%x)\n", count, status); #ifdef CACHE_ENABLED /* Writeback this outBuf from the previous call. Also, as encodedBuf * is an inBuf to the next process call, we must invalidate it also, to * clean buffer lines. */ Memory_cacheWbInv(encodedBuf, EFRAMESIZE); /* Per DMA Rule 7, our output buffer cache lines must be cleaned */ Memory_cacheInv(outBuf, OFRAMESIZE); #endif if (status != VIDENC_EOK) { GT_3trace(curMask, GT_7CLASS, "App-> Encoder frame %d processing FAILED, status = 0x%x, " "extendedError = 0x%x\n", count, status, encOutArgs.extendedError); break; } /***************************decode part (Unuse)***********************************/ /************************** decode the frame**************************************/ status = VIDDEC_process(dec, &encodedBufDesc, &outBufDesc, &decInArgs, &decOutArgs); GT_2trace(curMask, GT_2CLASS, "App-> Decoder frame %d process returned - 0x%x)\n", n, status); if (status != VIDDEC_EOK) { GT_3trace(curMask, GT_7CLASS, "App-> Decoder frame %d processing FAILED, status = 0x%x, " "extendedError = 0x%x\n", n, status, decOutArgs.extendedError); break; } #ifdef CACHE_ENABLED /* Writeback the outBuf. */ Memory_cacheWb(outBuf, OFRAMESIZE); #endif /* write to file */ //fwrite(encodedBuf, EFRAMESIZE, 1, out); frame->imageData = encoded[0]; frame_gray->imageData = dst[0]; //cvCvtColor(frame,frame_gray,CV_BGR2GRAY); #ifdef USE_OPENCV_DISPLAY cvShowImage("sobel",frame_gray); int key=cvWaitKey(33); #endif //cvSaveImage("22.bmp",frame_gray,0); printf("the %d frame are completed \n",count); count++; }/*end while*/ #ifdef USE_OPENCV_DISPLAY cvDestroyWindow("sobel"); #endif cvReleaseImage(&frame); cvReleaseImage(&frame_gray); cvReleaseImage(&frame_Smooth); cvReleaseImage(&frame_sobel); cvReleaseImage(&frame_sobel_8U); GT_1trace(curMask, GT_1CLASS, "%d frames encoded/decoded\n", n); }
void deviceInitOne(const char *ifname) { char interface[IFNAME_SIZE]; struct if_info *p; int trans; #ifdef _AIX char dev[IFNAME_SIZE]; int unit,j; unit = 0; for (j = 0; j < strlen(ifname); j++) { if (isalpha(ifname[j])) { dev[j] = ifname[j]; } else { if (isdigit(ifname[j])) { unit = unit*10 + ifname[j] - '0'; dev[j] = '\0'; } } } if ((strlen(dev) == 2) && (dev[0] == 'e') && ((dev[1] == 'n') || (dev[1] == 't'))) { snprintf(interface, sizeof(interface), "ent%d\0", unit); } else { snprintf(interface, sizeof(interface), "%s%d\0", dev, unit); } #else snprintf(interface, sizeof(interface), "%s", ifname); #endif /* _AIX */ /* Ok, init it just once */ p = iflist; for (p = iflist; p; p = p->next) { if (strcmp(p->if_name,interface) == 0) { return; } } if (!mopInteractive) syslog(LOG_INFO, "Initialized %s", interface); /* Ok, get transport information */ trans = pfTrans(interface); #ifndef NORC /* Start with MOP Remote Console */ switch (trans) { case TRANS_ETHER: deviceOpen(interface,MOP_K_PROTO_RC,TRANS_ETHER); break; case TRANS_8023: deviceOpen(interface,MOP_K_PROTO_RC,TRANS_8023); break; case TRANS_ETHER+TRANS_8023: deviceOpen(interface,MOP_K_PROTO_RC,TRANS_ETHER); deviceOpen(interface,MOP_K_PROTO_RC,TRANS_8023); break; case TRANS_ETHER+TRANS_8023+TRANS_AND: deviceOpen(interface,MOP_K_PROTO_RC,TRANS_ETHER+TRANS_8023); break; } #endif #ifndef NODL /* and next MOP Dump/Load */ switch (trans) { case TRANS_ETHER: deviceOpen(interface,MOP_K_PROTO_DL,TRANS_ETHER); break; case TRANS_8023: deviceOpen(interface,MOP_K_PROTO_DL,TRANS_8023); break; case TRANS_ETHER+TRANS_8023: deviceOpen(interface,MOP_K_PROTO_DL,TRANS_ETHER); deviceOpen(interface,MOP_K_PROTO_DL,TRANS_8023); break; case TRANS_ETHER+TRANS_8023+TRANS_AND: deviceOpen(interface,MOP_K_PROTO_DL,TRANS_ETHER+TRANS_8023); break; } #endif }
int main(int argc, char **argv) { for (;;) { int index, c = 0; c = getopt_long(argc, argv, short_options, long_options, &index); if (-1 == c) break; switch (c) { case 0: /* getopt_long() flag */ break; case 'd': deviceName = optarg; break; case 'h': // print help usage(stdout, argc, argv); exit(EXIT_SUCCESS); case 'o': // set jpeg filename jpegFilename = optarg; break; case 'q': // set jpeg quality jpegQuality = atoi(optarg); break; case 'm': #ifdef IO_MMAP io = IO_METHOD_MMAP; #else fprintf(stderr, "You didn't compile for mmap support.\n"); exit(EXIT_FAILURE); #endif break; case 'r': #ifdef IO_READ io = IO_METHOD_READ; #else fprintf(stderr, "You didn't compile for read support.\n"); exit(EXIT_FAILURE); #endif break; case 'u': #ifdef IO_USERPTR io = IO_METHOD_USERPTR; #else fprintf(stderr, "You didn't compile for userptr support.\n"); exit(EXIT_FAILURE); #endif break; case 'W': // set width width = atoi(optarg); break; case 'H': // set height height = atoi(optarg); break; case 'I': // set fps fps = atoi(optarg); break; case 'v': printf("Version: %s\n", VERSION); exit(EXIT_SUCCESS); break; default: usage(stderr, argc, argv); exit(EXIT_FAILURE); } } // check for need parameters if (!jpegFilename) { fprintf(stderr, "You have to specify JPEG output filename!\n\n"); usage(stdout, argc, argv); exit(EXIT_FAILURE); } // open and initialize device deviceOpen(); deviceInit(); // start capturing captureStart(); // process frames mainLoop(); // stop capturing captureStop(); // close device deviceUninit(); deviceClose(); exit(EXIT_SUCCESS); return 0; }