kinect-playground / hidecam2 / push2vloop.cpp

#include <sys/ioctl.h>
#include <linux/videodev2.h>
#include <fcntl.h>

#include "push2vloop.h"


# define VIDEO_DEVICE "/dev/video2"
# define FRAME_FORMAT V4L2_PIX_FMT_YUYV
//V4L2_PIX_FMT_UYVY
//V4L2_PIX_FMT_RGB24
# define FRAME_WIDTH  640
# define FRAME_HEIGHT 480

struct v4l2_capability vid_caps;
struct v4l2_format vid_format;
const char*video_device=VIDEO_DEVICE;
int fdwr;
size_t framesize = FRAME_WIDTH * FRAME_HEIGHT * 2; // *3 if using rgb
size_t linewidth = FRAME_WIDTH * 2;                // *3 if using rgb



void init_vloop(){
    printf("init video...\n");
	__u8*buffer;
	__u8*check_buffer;


	buffer=(__u8*)malloc(sizeof(__u8)*framesize);
	check_buffer=(__u8*)malloc(sizeof(__u8)*framesize);

	int i;
	memset(buffer, 0, framesize);
	memset(check_buffer, 0, framesize);

	fdwr = open(video_device, O_RDWR);
	printf("fdwr: %i\n",fdwr);
	//assert(fdwr >= 0);

	int ret_code = ioctl(fdwr, VIDIOC_QUERYCAP, &vid_caps);
	//assert(ret_code != -1);

	memset(&vid_format, 0, sizeof(vid_format));

	vid_format.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
	vid_format.fmt.pix.width = FRAME_WIDTH;
	vid_format.fmt.pix.height = FRAME_HEIGHT;
	vid_format.fmt.pix.pixelformat = FRAME_FORMAT;
	vid_format.fmt.pix.sizeimage = framesize;
	vid_format.fmt.pix.field = V4L2_FIELD_NONE;
	vid_format.fmt.pix.bytesperline = linewidth;
	vid_format.fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
	ret_code = ioctl(fdwr, VIDIOC_S_FMT, &vid_format);
    printf("video init done!\n");
}


void push2vloop(void *buf){
        //lock mutex for depth image
             //   pthread_mutex_lock( &mutex_depth );

                write(fdwr, buf, framesize);

                //unlock mutex for depth image
            //    pthread_mutex_unlock( &mutex_depth );
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.