Example #1
0
/* query informations of camera device */
void camera_open_query(CameraDevice *thiz)
{
    assert(thiz != NULL);

    camera_open_device(thiz);
    camera_query_cap(thiz);
    camera_query_cur_fps(thiz);
    camera_query_support_format(thiz);
}
Example #2
0
int main(int argc, char **argv)
{
    int opt, has_gui = 0, count = DEFAULT_FRAME_COUNT;
    struct v4l2_camera *cam = NULL;

    cam = camera_create_object();
    if (!cam) {
        LOGE(DUMP_NONE, "Out of memory\n");
        exit(EXIT_FAILURE);
    }

    LOGI("Parsing command line args:\n");
    while ((opt = getopt(argc, argv, "?vgp:w:h:f:n:")) != -1) {
        switch(opt){
            case 'v':
                LOGI("Verbose log\n");
                set_log_level(DEBUG);
                break;
            case 'g':
                LOGI("Gui mode\n");
                has_gui = 1;
                break;
            case 'p':
                cam->dev_name = optarg;
                LOGI("Device path: %s\n", cam->dev_name);
                break;
            case 'w':
                cam->fmt.fmt.pix.width = atoi(optarg);
                LOGI("Width: %d\n", cam->fmt.fmt.pix.width);
                break;
            case 'h':
                cam->fmt.fmt.pix.height = atoi(optarg);
                LOGI("Height: %d\n", cam->fmt.fmt.pix.height);
                break;
            case 'n':
                if ((count = atoi(optarg)) <= 0)
                    count = DEFAULT_FRAME_COUNT;
                LOGI("Frame total: %d\n", count);
                break;
            case 'f':
                switch (*optarg) {
                    case '1':
                        cam->fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_MJPEG;
                        break;
                    case '2':
                        cam->fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_H264;
                        break;
                    case '0': /* default, fall through */
                    default:
                        cam->fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
                }
                LOGI("Format: %d\n", cam->fmt.fmt.pix.pixelformat);
                break;
            case '?':
            default:
                help();
                goto out_free;
        }
    }
    LOGI("Parsing command line args done\n");
    if (camera_open_device(cam))
        goto out_free;
    if (camera_query_cap(cam))
        goto out_close;
    if(!(cam->cap.capabilities & V4L2_CAP_VIDEO_CAPTURE))
    {
        LOGE(DUMP_NONE, "%s is no video capture device\n", cam->dev_name);
        goto out_close;
    }
    if(!(cam->cap.capabilities & V4L2_CAP_STREAMING))
    {
        LOGE(DUMP_NONE, "%s does not support streaming i/o\n", cam->dev_name);
        goto out_close;
    }
    camera_query_support_control(cam);
    camera_query_support_format(cam);

    if (camera_set_output_format(cam))
        goto out_close;

    /* Note VIDIOC_S_FMT may change width and height. */
    camera_get_output_format(cam);

    if (camera_request_and_map_buffer(cam))
        goto out_close;

    if (!has_gui) {
        mainloop_noui(cam, count);
    } else {
#ifdef __HAS_GUI__
        cam->priv = window_create(cam->fmt.fmt.pix.width, cam->fmt.fmt.pix.height);
        mainloop(cam);
        window_destory((struct window *)cam->priv);
#else
        LOGE(DUMP_NONE, "GUI build is disabled\n");
#endif
    }

    camera_return_and_unmap_buffer(cam);

out_close:
    camera_close_device(cam);
out_free:
    camera_free_object(cam);
    return CAMERA_RETURN_SUCCESS;
}