Example #1
0
static void mainloop(struct v4l2_camera *cam)
{
    int ret;
    int save_flag = 0;
    int action, running = 1;
    camera_start_capturing(cam);
    while (running) {
        while((ret = read_frame(cam, display_frame, &save_flag)) == -EAGAIN);
        if (ret != CAMERA_RETURN_SUCCESS)
            break;
        action = window_get_event((struct window *)cam->priv);
        switch (action) {
            case ACTION_STOP:
                running = 0;
                break;
            case ACTION_SAVE_PICTURE:
                save_flag = 1;
                break;
            case ACTION_EDIT_CONTROL:
                edit_control(cam);
                break;
            case ACTION_NONE:
                //fall through
            default:
                save_flag = 0;;
         }

    }
    camera_stop_capturing(cam);
}
Example #2
0
static void mainloop_noui(struct v4l2_camera *cam, int count)
{
    int i = 0, ret;
    if (camera_start_capturing(cam))
        return;
    while(i++ < count)
    {
        /* EAGAIN - continue select loop. */
        while((ret = read_frame(cam, save_frame, NULL)) == -EAGAIN);
        if (ret == CAMERA_RETURN_FAILURE)
            break;
    }
    camera_stop_capturing(cam);
}
Example #3
0
static void * camera_thread(DirectThread *thread, void *arg)
{
	int camera_dev_num = 0;
	int second_dev_num = -1;
	int fid;
	struct stat st;
	bool same_sensor_flg = false;
	char *back = "b";
	char *front = "f";
	int cur_stat = 0;
	int *num = arg;
    int width = camera_pixel_width;
	int height = camera_pixel_height;
    
	printf("camera num = %d\n", *num);
	
	if (0 == stat("/dev/video3", &st))
	{
		printf("got two sensor at video0 video3\n");
		second_dev_num = 3;
	}
#ifndef __GS702C__
	else if (0 == stat("/dev/video1", &st))
	{

		printf("got two sensor at video0 video1\n");
		second_dev_num = 1;
	}
#endif
	if (second_dev_num < 0)
	{
		same_sensor_flg = true;
		printf("got two same sensor\n");
	}

	while(true)
	{
		do
		{
			if(open_camera_device(camera_dev_num, *num) == -1)
			{
				printf("open camera %d error\n", camera_dev_num);
				direct_thread_sleep( 1000000 );
				break;
			}
			if(init_camera_device(&width, &height) == -1)
			{
				printf("init camera %d error\n", camera_dev_num);
				close_camera_device();
				break;
			}
			camera_start_capturing();
			camera_mainloop();
			camera_stop_capturing();
			uninit_camera_device();
			close_camera_device();
		}while(0);
		
		if(same_sensor_flg)
		{
			fid = open("/sys/bus/platform/devices/camera_flag_device.0/front_back", O_WRONLY);
			if(0 == cur_stat)
			{
				write(fid,back,1);
				close(fid);
				cur_stat = 1;
			}
			else
			{
				write(fid,front,1);
				close(fid);
				cur_stat = 0;
			}
		}
		else
		{
			if(camera_dev_num)
			{
				camera_dev_num = 0;
				//printf("switch to video0, the rear camera \n");
			}
			else
			{
				camera_dev_num = second_dev_num;
				printf("switch to video%d, front-facing cameras \n", second_dev_num);
			}
		}
	}
}