📄 input_plugin.c
字号:
/* ============================================================================ Name : input_plugin.c Author : Zhang Yi Version : Copyright : Your copyright notice Description : Hello World in C, Ansi-style ============================================================================ */#include <string.h>#include <sys/types.h>#include <sys/stat.h>#include <sys/ioctl.h>#include <sys/mman.h>#include <linux/videodev.h>#include <fcntl.h>#include <unistd.h>#include <stdio.h>#include <errno.h>#include <stdlib.h>#include <signal.h>#include "input_plugin.h"#include "webserver.h"void *enc_handle= NULL;struct vdIn videoIn;extern globals pglobal;static int XDIM = 0;static int YDIM = 0;int init_videoIn(struct vdIn *vd, char *device, int width, int height, int format) { vd->width = width; vd->height = height; vd->formatIn = format; vd->buf=(unsigned char*)malloc(width*height*3); if ((vd->fd = open(device, O_RDWR)) == -1) { perror("ERROR opening camera device"); return -1; } if (ioctl(vd->fd, VIDIOCGCAP, &(vd->videocap)) == -1) { perror("ERROR opening video_capability"); return -1; } printf("Find camera: %s\n", vd->videocap.name); if (ioctl(vd ->fd, VIDIOCGPICT, &(vd->picture)) < 0) { perror("v4l_get_picture:"); return -1; } printf("colour:%d brightness:%d palette:%d depth:%d\n", vd->picture.colour, vd->picture.brightness, vd->picture.palette, vd->picture.depth); vd->picture.colour = 55535; //vd->picture.palette=21;//TODO vd->picture.brightness=6000; if (ioctl(vd->fd, VIDIOCSPICT, &(vd->picture)) < 0) { perror("ERROR setting video_picture"); return -1; } if (ioctl(vd->fd, VIDIOCGWIN, &(vd->videowin)) < 0) perror("get video_window failed"); vd->videowin.height = vd->height; vd->videowin.width = vd->width; if (ioctl(vd->fd, VIDIOCSWIN, &(vd->videowin)) < 0) perror("ERROR setting video_window"); if (ioctl(vd->fd, VIDIOCGWIN, &(vd->videowin)) < 0) perror("get video_window failed (after set)"); printf("VIDIOCSWIN height %d width %d \n", vd->videowin.height, vd->videowin.width); return 0;}void *input_run() { char *device= "/dev/video0"; int format= VIDEO_PALETTE_JPEG; int width=614, height=384; memset(&videoIn, 0, sizeof(struct vdIn)); if (init_videoIn(&videoIn, device, width, height, format) != 0) { exit(-1); } /* xvid init */ XDIM = width; YDIM = height; pglobal.buf = (unsigned char *) malloc(XDIM*YDIM*2); if (enc_init()) { perror("Encore INIT problem"); exit(-1); } /* Xvid encode */ pglobal.stop=0; while (!pglobal.stop) { int size=read(videoIn.fd, videoIn.buf, XDIM*YDIM*3); if (size<0) { perror("error read!\n"); continue; } pthread_mutex_lock( &pglobal.db); pglobal.size =enc_main(videoIn.buf, pglobal.buf); printf("enc_main\n"); if (pglobal.size < 0) { printf("erro in encode....\n"); } /* signal fresh_frame */ pthread_cond_broadcast(&pglobal.db_update); pthread_mutex_unlock( &pglobal.db); } if (enc_handle) if (enc_stop()) perror("Encore RELEASE problem\n"); exit(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -