Exemple #1
0
static int v4l2_case_take_pic(void* user_ptr, int test_num)
{
	FUNC_ENTER()
	BLTS_DEBUG("Test number %i:\n", test_num);
	v4l2_data* data = (v4l2_data*)user_ptr;

	if(!open_device (data->device))
	{
		BLTS_ERROR("Can't open device %s\n", data->device->dev_name);
		return -1;
	}

	if(init_device (data->device, data->device->requested_format.fmt.pix.width, data->device->requested_format.fmt.pix.height))
	{
		if(data->snapshot_filename != NULL)
		{
			free(data->snapshot_filename);
			data->snapshot_filename = NULL;
		}
		data->snapshot_filename = create_picture_filename(data->device);
		BLTS_DEBUG("Filename to create: '%s'\n", data->snapshot_filename);
		BLTS_DEBUG("Maximum resolution is: %ix%i\n", data->device->format.fmt.pix.width, data->device->format.fmt.pix.height);

		if(!start_capturing (data->device))
			goto err;
		if(!mainloop (data->device, 0))
			goto err;
		BLTS_DEBUG("Taking picture %s\n", data->snapshot_filename);
		if(!do_snapshot (data->device, data->snapshot_filename))
			goto err;
		// ensure that image is actual JPEG
		if(read_jpeg_image(data->snapshot_filename))
		{
			BLTS_DEBUG("Error, image %s is not JPEG standard.\n", data->snapshot_filename);
			return -1;
		}


		stop_capturing (data->device);
		uninit_device (data->device);
	}
	else
	{
		BLTS_ERROR("Can't initialize device\n");
		goto err;
	}

	close_device (data->device);
	FUNC_LEAVE()
	return 0;

err:

	stop_capturing(data->device);
	uninit_device(data->device);
	close_device(data->device);
	FUNC_LEAVE()
	return -1;
}
Exemple #2
0
static int v4l2_run_stream(v4l2_data *data, int do_crop)
{
	int loops = 50;

	int screen_height = SCREEN_WIDTH;
	int screen_width = SCREEN_HEIGHT;

	if (!open_device(data->device))	{
			BLTS_DEBUG("Can't open device %s\n", data->device->dev_name);
			return -1;
	}

	data->device->use_streaming = 1;
	if (init_device(data->device, screen_width, screen_height)) {
		int w = data->device->format.fmt.pix.width;
		int h = data->device->format.fmt.pix.height;
		xvideo_init(w, h, 0);

 		if (!start_capturing(data->device))
				goto err;

		if (do_crop) {
			if (!crop_corners(data->device, loops))
				goto err;
		} else {
			if (!stream_image_xv(data->device, loops))
				goto err;
		}

		stop_capturing(data->device);
		uninit_device(data->device);
	} else {
		close_device(data->device);
		BLTS_DEBUG("Could not open device\n");
		data->device->use_streaming = 0;
		return -1;
	}
	data->device->use_streaming = 0;

	close_device(data->device);
	xvideo_deinit();

	return 0;
err:

	data->device->use_streaming = 0;
	stop_capturing(data->device);
	uninit_device(data->device);
	close_device(data->device);
	xvideo_deinit();

	return -1;

}
Exemple #3
0
void life_cycle() {

  fprintf(stderr, "Beginning life cycle\n");

        if (!dev_name) {
          if (vendor >= 0 || product >= 0) {
            if (vendor < 0 || product < 0) {
              err("Either give both vendor and product ID or none");
            }
            int dev_id = find_camera(vendor, product);
            if (dev_id >= 0) {
              snprintf(dev_name_buf, FULLNAME_MAX_LEN, "/dev/video%d", dev_id);
              dev_name = &dev_name_buf[0];
            } else {
              err("Could not find device");
            }
          } else {
            dev_name = "/dev/video0";
          }
        }
        fprintf(stderr, "Using device %s\n", dev_name);

        open_device();
        init_device();
        start_capturing();
        mainloop();
        stop_capturing();
        uninit_device();
        close_device();

  fprintf(stderr, "Finishing life cycle\n");

}
Exemple #4
0
void camera_uninit(int *fd, camera_buffer *camera_buffers, int camera_count){
	int i;
	for (i=0;i<camera_count;i++){
		stop_capturing(fd[i]);
		uninit_device(&camera_buffers[i]);
		close_device(&fd[i]);
	}
}
Exemple #5
0
void v4l2_close(struct camera *cam) {
	stop_capturing(cam);
	uninit_camera(cam);
	close_camera(cam);
	free(cam);
	close_file();
	close_encoder();
}
Exemple #6
0
void V4L2W_finalize(V4L2WHandler_t * handle)
{
    stop_capturing (handle);
    uninit_device (handle);
    close_device (handle);
    free(handle->outimg);
    free(handle);
}
Exemple #7
0
int videodev_stop (void) {
	printf("videocapture: exit\n");
	stop_capturing();
	close_device();
	uninit_device();
	SDL_FreeSurface(data_sf);
	free(buffer_sdl);
	return 0;
}
Exemple #8
0
int ExitImage()
{
    stop_capturing();
    uninit_device();
    close_device();

    printf ("ExitImage success\n");
    return (0);
}
Exemple #9
0
void video_cleanup( IMAGE_CONTEXT *v1, IMAGE_CONTEXT *v2 )
{
    stop_capturing();
    uninit_device();
    close_device();

    image_destroy( v1 );
    image_destroy( v2 );
}
int main(int argc, char **argv)
{
	int ret = 0;

#ifdef TEST_CONTROLS
	if (argc != 8) {
		printf
		    ("%s width height num_of_frames bright contrast saturation sharpness\n",
		     argv[0]);
		printf("EX)  $ %s 640 480  3  0 0 0 24612 \n", argv[0]);
		goto err;
	}
#else
	if (argc != 4) {
		printf
		    ("%s width height num_of_frames bright contrast saturation sharpness\n",
		     argv[0]);
		printf("EX)  $ %s 640 480  3\n", argv[0]);
		goto err;
	}
#endif

	g_pix_width = atoi(argv[1]);
	g_pix_height = atoi(argv[2]);
	g_file_count = atoi(argv[3]) + 1;

#ifdef TEST_CONTROLS
	g_brightness = atoi(argv[4]);
	g_contrast = atoi(argv[5]);
	g_saturation = atoi(argv[6]);
	g_sharpness = atoi(argv[7]);
#endif

	g_img_buf = malloc(g_pix_width * g_pix_height * 3 * sizeof(char));

	open_device();
	set_input_chann(0);
	init_v4l2_device();
	ret = init_mmap(&n_buffers);

	if (ret)
		errno_exit("init_mmap error !!!");

#ifdef TEST_CONTROLS
	start_control_testing();
#endif
	start_capturing(buffers);
	mainloop();
	stop_capturing();
	close_mmap();
	close_device();
	free(g_img_buf);
	exit(EXIT_SUCCESS);

 err:
	return ret;
}
Exemple #11
0
void Webcam::close_device()
{
   if( isStreaming() )
     stop_capturing();

   if( fd != -1 )
     close(fd);
   //assure
    fd=-1;
}
Exemple #12
0
static int test_frame_rate(v4l2_dev_data *dev, float* fps, float* calculated_fps)
{
	int loops = 100;
	int screen_height = SCREEN_WIDTH;
	int screen_width = SCREEN_HEIGHT;

	dev->use_streaming = 1;

	if (init_device(dev, screen_width, screen_height))
	{
		xvideo_init(dev->format.fmt.pix.width, dev->format.fmt.pix.height, 0);

		if (!start_capturing(dev))
			goto err;

		if (!stream_image_xv(dev, loops))
			goto err;

		*calculated_fps = dev->calculated_frame_rate;

		stop_capturing(dev);
		uninit_device(dev);
		xvideo_deinit();
	}
	else
	{
		close_device(dev);
		BLTS_DEBUG("Could not open device\n");
		dev->use_streaming = 0;
		return -1;
	}

	return 0;
err:

	dev->use_streaming = 0;
	stop_capturing(dev);
	uninit_device(dev);
	xvideo_deinit();

	return -1;

}
Exemple #13
0
void video_close()
{
	pthread_cancel(video_thread);
	stop_capturing();
	uninit_device();
	close_device();
	
	if(save)
		fclose(file_fd);
}
Exemple #14
0
static int v4l2_case_read_with_poll(void* user_ptr, int test_num)
{
	v4l2_data* data = (v4l2_data*)user_ptr;
	if (!open_device(data->device))	{
		BLTS_ERROR("Can't open device %s\n",
			data->device->dev_name);
		return -1;
	}

	if (!init_device(data->device,
		data->device->requested_format.fmt.pix.width,
		data->device->requested_format.fmt.pix.height))	{
		BLTS_ERROR("Can't initialize device\n");
		goto err;
	}

	BLTS_DEBUG("Resolution used: %ix%i\n",
		data->device->format.fmt.pix.width,
		data->device->format.fmt.pix.height);

	if (!start_capturing(data->device))
		goto err;

	BLTS_DEBUG("Starting polled reads\n");
	if (!mainloop(data->device, LOOPS))
		goto err;

	stop_capturing(data->device);
	uninit_device(data->device);
	if (!close_device(data->device))
		return -1;

	return 0;

err:
	stop_capturing(data->device);
	uninit_device(data->device);
	close_device(data->device);

	return -1;
}
int main()
{
	int fd;
	fd = open_camer_device();
	init_camer_device(fd);
	start_capturing(fd);
	mainloop(fd);
	stop_capturing(fd);
	uninit_camer_device(fd);
	close_camer_device(fd);
	return 0;
}
Exemple #16
0
int pointit_destroy_cap(void) {
    if (stop_capturing() != 0) return -1;
    if (uninit_device() != 0)  return -1;
    if (close_device() != 0)   return -1;
#ifdef POINTIT_SDL
    free_sdl_surf();
#endif

    free(rgb_img);

    return 0;
}
Exemple #17
0
int main(int argc, char *argv[])
{
    //strcpy(output_file, argv[1]);
    open_device();		// ビデオバイスをオープン
    init_device();		// ビデオデバイスを初期化
    start_capturing();		// 画像キャプチャ開始
    mainloop();			// メインループ処理
    stop_capturing();		// 画像キャプチャ停止
    uninit_device();		// 初期化前の状態に戻す
    close_device();		// ビデオデバイスをクローズ
    return 0;
}
void
video_driver::restart_video ()
{
  stop_capturing ();
  uninit_device ();
  close_device ();

  open_device ();
  init_device ();
  start_capturing ();

}
Exemple #19
0
void stop_camera(int* fd, int* rgb_buffer, int* y_buffer) {
    stop_capturing(*fd);
    uninit_device();
    close_device(fd);

    if(rgb_buffer) {
        free(rgb_buffer);
    }

    if(y_buffer) {
        free(y_buffer);
    }
}
Exemple #20
0
static int v4l2_case_measure_resolution(void* user_ptr, int test_num)
{
	v4l2_data* data = (v4l2_data*)user_ptr;

	BLTS_DEBUG("Test number %i:\n", test_num);

	if(!open_device (data->device))
	{
		BLTS_DEBUG("Can't open device %s\n", data->device->dev_name);
		return -1;
	}

	if(init_device (data->device, data->device->requested_format.fmt.pix.width, data->device->requested_format.fmt.pix.height))
	{
		BLTS_DEBUG("Resolution gained: %ix%i\n", data->device->format.fmt.pix.width, data->device->format.fmt.pix.height);
		if(!start_capturing (data->device))
			goto err;
		if(!mainloop(data->device, LOOPS))
			goto err;

		stop_capturing (data->device);
		uninit_device (data->device);
	}
	else
	{
		BLTS_DEBUG("Can't initialize device\n");
		goto err;
	}

	close_device (data->device);
	return 0;

err:
	stop_capturing(data->device);
	uninit_device(data->device);
	close_device(data->device);
	return -1;

}
int main() {
	open_device();
	init_device();
	init_mmap();

	start_capturing();
	mainloop();
	stop_capturing();

	uninit_mmap();
	close_device();

	return EXIT_SUCCESS;
}
/** The DeInitialization function 
 */
OMX_ERRORTYPE omx_videosrc_component_Deinit(OMX_COMPONENTTYPE *openmaxStandComp) {

  omx_videosrc_component_PrivateType* omx_videosrc_component_Private = openmaxStandComp->pComponentPrivate;

  DEBUG(DEB_LEV_FUNCTION_NAME, "In %s \n",__func__);

  stop_capturing(omx_videosrc_component_Private);

  /** closing input file */
  omx_videosrc_component_Private->videoReady = OMX_FALSE;
  tsem_reset(omx_videosrc_component_Private->videoSyncSem);

  return OMX_ErrorNone;
}
Exemple #23
0
static void destructor(void *arg)
{
	struct vidsrc_st *st = arg;

	if (st->run) {
		st->run = false;
		pthread_join(st->thread, NULL);
	}

	stop_capturing(st);
	uninit_device(st);

	if (st->fd >= 0)
		v4l2_close(st->fd);
}
Exemple #24
0
void* startcapture(void* dev) {
	can_stop = 1;
	capture* d = get_cap();
	dev_name = d->device;
	wigth = d->weigth;
	heigth = d->height;
	open_device();
	init_device();
	start_capturing();
	mainloop(d->refresh);
	stop_capturing();
	uninit_device();
	close_device();
	return 0;
}
Exemple #25
0
int internal_main( output_callback_func_ptr callback_ptr )
{
  output = OUTPUT_CALLBACK;

  output_callback_ptr = callback_ptr;

  device_open();
  init_device();
  start_capturing();
 
  capture_loop();
 
  stop_capturing();
  uninit_device();
  device_close();

  return 0;
}
Exemple #26
0
void usb_cam_camera_shutdown(void)
{
  stop_capturing();
  uninit_device();
  close_device();

  if (avcodec_context) {
    avcodec_close(avcodec_context);
    av_free(avcodec_context);
    avcodec_context = NULL;
  }
  if (avframe_camera)
    av_free(avframe_camera);
  avframe_camera = NULL;
  if (avframe_rgb)
    av_free(avframe_rgb);
  avframe_rgb = NULL;
}
int main(int argc, char **argv)
{
    dev_name = "/dev/video";
    for (;;) {
	int index;
	int c;
	c = getopt_long(argc, argv, short_options, long_options, &index);
	if (-1 == c)
	    break;
	switch (c) {
	    case 0:		/* getopt_long() flag */
		break;
	    case 'd':
		dev_name = optarg;
		break;
	    case 'h':
		usage(stdout, argc, argv);
		exit(EXIT_SUCCESS);
	    case 'm':
		io = IO_METHOD_MMAP;
		break;
	    case 'r':
		io = IO_METHOD_READ;
		break;
	    case 'u':
		io = IO_METHOD_USERPTR;
		break;
	    default:
		usage(stderr, argc, argv);
		exit(EXIT_FAILURE);
	}
    }
    open_device();
    init_device();
    start_capturing();
    mainloop();
    stop_capturing();
    uninit_device();
    close_device();
    fputc('\n', stdout);
    exit(EXIT_SUCCESS);
    return 0;
}
Exemple #28
0
V4LCapture::~V4LCapture() {
	if(param.replay_mode) {
		free(buffers->start);
		free(buffers);
	}else{
		stop_capturing();
		uninit_device();
		close_device(); 
	}
	if(video_rec){
		fclose(video_rec);
	}
	if(time_rec){
		fclose(time_rec);
	}
	if(dev_name){
		free(dev_name);
	}
};
Exemple #29
0
static void enc_destructor(void *arg)
{
	struct videnc_state *st = arg;

	if (st->fd >=0 ) {
		info("v4l2_codec: encoder stats"
		     " (keyframes:%u, deltaframes:%u)\n",
		     st->stats.n_key, st->stats.n_delta);
	}

	stop_capturing(st->fd);

	if (st->buffer)
		munmap(st->buffer, st->buffer_len);

	if (st->fd >= 0) {
		fd_close(st->fd);
		close(st->fd);
	}
}
Exemple #30
0
static void
finalize (GObject *object)
{
 GeglProperties *o = GEGL_PROPERTIES (object);

  if (o->user_data)
    {
      Priv *p = (Priv*)o->user_data;
      if (p->fd)
      {
	      stop_capturing(p);
        uninit_device (p);
        close_device (p);
        p->fd = 0;
      }
      g_clear_pointer (&o->user_data, g_free);
    }

  G_OBJECT_CLASS (gegl_op_parent_class)->finalize (object);
}