Beispiel #1
0
static int alloc(struct vidsrc_st **stp, const struct vidsrc *vs,
		 struct media_ctx **ctx, struct vidsrc_prm *prm,
		 const struct vidsz *size, const char *fmt,
		 const char *dev, vidsrc_frame_h *frameh,
		 vidsrc_error_h *errorh, void *arg)
{
	struct vidsrc_st *st;
	int err;

	(void)ctx;
	(void)prm;
	(void)fmt;
	(void)errorh;

	if (!stp || !size || !frameh)
		return EINVAL;

	if (!str_isset(dev))
		dev = "/dev/video0";

	st = mem_zalloc(sizeof(*st), destructor);
	if (!st)
		return ENOMEM;

	st->vs = vs;
	st->fd = -1;
	st->sz = *size;
	st->frameh = frameh;
	st->arg    = arg;
	st->pixfmt = 0;

	err = vd_open(st, dev);
	if (err)
		goto out;

	err = v4l2_init_device(st, dev, size->w, size->h);
	if (err)
		goto out;

	print_video_input(st);

	err = start_capturing(st);
	if (err)
		goto out;

	st->run = true;
	err = pthread_create(&st->thread, NULL, read_thread, st);
	if (err) {
		st->run = false;
		goto out;
	}

 out:
	if (err)
		mem_deref(st);
	else
		*stp = st;

	return err;
}
Beispiel #2
0
/*
 * Initializes camera for streaming
 */
int init_camera(void)
{
	/* Declare properties for camera */
	camera.memory_mode = V4L2_MEMORY_MMAP;
	camera.num_buffers = 3;
	strcpy(camera.dev_name,"/dev/video0");
	strcpy(camera.name,"Camera");
	camera.buffers = NULL;
	camera.fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
	camera.width = 640;
	camera.height = 480;

	/* Initialize the v4l2 capture devices */
	if (v4l2_init_device(&camera) < 0) goto Error;

	/* Enable streaming for the v4l2 capture devices */
	if (v4l2_stream_on(&camera) < 0) goto Error;

	return 0;

Error:
	close_camera();
	return -1;
}