///Loads all the Camera related properties
status_t CameraProperties::loadProperties()
{
//    LOG_FUNCTION_NAME;

    status_t ret = NO_ERROR;

    //Must be re-initialized here, since loadProperties() could potentially be called more than once.
    mCamerasSupported = 0;

    // adapter updates capabilities and we update camera count
    const status_t err = CameraAdapter_Capabilities(mCameraProps, mCamerasSupported,
            MAX_CAMERAS_SUPPORTED, mCamerasSupported);

    if(err != NO_ERROR) {
        CAMHAL_LOGE("error while getting capabilities");
        ret = UNKNOWN_ERROR;
    } else if (mCamerasSupported == 0) {
        CAMHAL_LOGE("camera busy. properties not loaded. num_cameras = %d", mCamerasSupported);
        ret = UNKNOWN_ERROR;
    } else if (mCamerasSupported > MAX_CAMERAS_SUPPORTED) {
        CAMHAL_LOGE("returned too many adapaters");
        ret = UNKNOWN_ERROR;
    } else {
        CAMHAL_LOGI("num_cameras = %d", mCamerasSupported);

        for (int i = 0; i < mCamerasSupported; i++) {
            mCameraProps[i].setSensorIndex(i);
            mCameraProps[i].dump();
        }
    }

    CAMHAL_LOGV("mCamerasSupported = %d", mCamerasSupported);
//    LOG_FUNCTION_NAME_EXIT;
    return ret;
}
bool CameraHal::parsePair(const char *str, int *first, int *second, char delim)
{
    // Find the first integer.
    char *end;
    int w = (int)strtol(str, &end, 10);
    // If a delimeter does not immediately follow, give up.
    if (*end != delim) {
        CAMHAL_LOGE("Cannot find delimeter (%c) in str=%s", delim, str);
        return false;
    }

    // Find the second integer, immediately after the delimeter.
    int h = (int)strtol(end+1, &end, 10);

    *first = w;
    *second = h;

    return true;
}
Ejemplo n.º 3
0
status_t V4LCameraAdapter::getCaps(const int sensorId, CameraProperties::Properties* params,
                                   V4L_HANDLETYPE handle) {
    status_t status = NO_ERROR;
    V4L_TI_CAPTYPE caps;
    int i = 0;
    int j = 0;
    struct v4l2_fmtdesc fmtDesc;
    struct v4l2_frmsizeenum frmSizeEnum;
    struct v4l2_frmivalenum frmIvalEnum;

    //get supported pixel formats
    for ( i = 0; status == NO_ERROR; i++) {
        fmtDesc.index = i;
        fmtDesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        status = ioctl (handle, VIDIOC_ENUM_FMT, &fmtDesc);
        if (status == NO_ERROR) {
            CAMHAL_LOGDB("fmtDesc[%d].description::pixelformat::flags== (%s::%d::%d)",i, fmtDesc.description,fmtDesc.pixelformat,fmtDesc.flags);
            caps.ePreviewFormats[i] = fmtDesc.pixelformat;
        }
    }
    caps.ulPreviewFormatCount = i;

    //get preview sizes & capture image sizes
    status = NO_ERROR;
    for ( i = 0; status == NO_ERROR; i++) {
        frmSizeEnum.index = i;
        //Check for frame sizes for default pixel format
        //TODO: Check for frame sizes for all supported pixel formats
        frmSizeEnum.pixel_format = V4L2_PIX_FMT_YUYV;
        status = ioctl (handle, VIDIOC_ENUM_FRAMESIZES, &frmSizeEnum);
        if (status == NO_ERROR) {
            int width;
            int height;

            if(frmSizeEnum.type != V4L2_FRMSIZE_TYPE_DISCRETE) {
                CAMHAL_LOGDB("\nfrmSizeEnum.type = %d", frmSizeEnum.type);
                CAMHAL_LOGDB("\nmin_width x height = %d x %d ",frmSizeEnum.stepwise.min_width, frmSizeEnum.stepwise.min_height);
                CAMHAL_LOGDB("\nmax_width x height = %d x %d ",frmSizeEnum.stepwise.max_width, frmSizeEnum.stepwise.max_height);
                CAMHAL_LOGDB("\nstep width x height = %d x %d ",frmSizeEnum.stepwise.step_width,frmSizeEnum.stepwise.step_height);
                //TODO: validate populating the sizes when type = V4L2_FRMSIZE_TYPE_STEPWISE
                width = frmSizeEnum.stepwise.max_width;
                height = frmSizeEnum.stepwise.max_height;
            }
            else {
                CAMHAL_LOGDB("frmSizeEnum.index[%d].width x height == (%d x %d)", i, frmSizeEnum.discrete.width, frmSizeEnum.discrete.height);
                width = frmSizeEnum.discrete.width;
                height = frmSizeEnum.discrete.height;
            }

            caps.tCaptureRes[i].width = width;
            caps.tCaptureRes[i].height = height;
            caps.tPreviewRes[i].width =  width;
            caps.tPreviewRes[i].height = height;

            snprintf(caps.tPreviewRes[i].param, MAX_RES_STRING_LENGTH,"%dx%d",caps.tPreviewRes[i].width,caps.tPreviewRes[i].height);
            snprintf(caps.tCaptureRes[i].param, MAX_RES_STRING_LENGTH,"%dx%d",caps.tCaptureRes[i].width,caps.tCaptureRes[i].height);
        }
        else {
            caps.ulCaptureResCount = i;
            caps.ulPreviewResCount = i;
        }
    }

    //sort the preview sizes in ascending order
    sortAscend(caps, caps.ulPreviewResCount);

    //get supported frame rates
    bool fps30 = false;
    for ( j=caps.ulPreviewResCount-1; j >= 0; j--) {
        CAMHAL_LOGDB(" W x H = %d x %d", caps.tPreviewRes[j].width, caps.tPreviewRes[j].height);
        status = NO_ERROR;
        for ( i = 0; status == NO_ERROR; i++) {
            frmIvalEnum.index = i;
            //Check for supported frame rates for the default pixel format.
            frmIvalEnum.pixel_format = V4L2_PIX_FMT_YUYV;
            frmIvalEnum.width = caps.tPreviewRes[j].width;
            frmIvalEnum.height = caps.tPreviewRes[j].height;

            status = ioctl (handle, VIDIOC_ENUM_FRAMEINTERVALS, &frmIvalEnum);
            if (status == NO_ERROR) {
                if(frmIvalEnum.type != V4L2_FRMIVAL_TYPE_DISCRETE) {
                    CAMHAL_LOGDB("frmIvalEnum[%d].type = %d)", i, frmIvalEnum.type);
                    CAMHAL_LOGDB("frmIvalEnum[%d].stepwise.min = %d/%d)", i, frmIvalEnum.stepwise.min.denominator, frmIvalEnum.stepwise.min.numerator);
                    CAMHAL_LOGDB("frmIvalEnum[%d].stepwise.max = %d/%d)", i, frmIvalEnum.stepwise.max.denominator, frmIvalEnum.stepwise.max.numerator);
                    CAMHAL_LOGDB("frmIvalEnum[%d].stepwise.step = %d/%d)", i, frmIvalEnum.stepwise.step.denominator, frmIvalEnum.stepwise.step.numerator);
                    caps.ulFrameRates[i] = (frmIvalEnum.stepwise.max.denominator/frmIvalEnum.stepwise.max.numerator);
                }
                else {
                    CAMHAL_LOGDB("frmIvalEnum[%d].frame rate= %d)",i, (frmIvalEnum.discrete.denominator/frmIvalEnum.discrete.numerator));
                    caps.ulFrameRates[i] = (frmIvalEnum.discrete.denominator/frmIvalEnum.discrete.numerator);
                }

                if (caps.ulFrameRates[i] == 30) {
                    fps30 = true;
                }
            }
            else if (i == 0) {
                // Framerate reporting is not guaranteed in V4L2 implementation.
                caps.ulFrameRates[i] = 30;
                fps30 = true;
                caps.ulFrameRateCount = 1;
            } else {
                CAMHAL_LOGE("caps.ulFrameRateCount = %d",i);
                caps.ulFrameRateCount = i;
            }
        }
        if(fps30) {
            break;
        }
    }

    if(frmIvalEnum.type != V4L2_FRMIVAL_TYPE_DISCRETE) {
        //TODO: populate the frame rates when type = V4L2_FRMIVAL_TYPE_STEPWISE;
    }

    //update the preview resolution with the highest resolution which supports 30fps.
    /*  // for video preview the application choose the resolution from the mediaprofiles.xml.
        // so populating all supported preview resolution is required for video mode.
        caps.tPreviewRes[0].width = caps.tPreviewRes[j].width;
        caps.tPreviewRes[0].height = caps.tPreviewRes[j].height;
        snprintf(caps.tPreviewRes[0].param, MAX_RES_STRING_LENGTH,"%dx%d",caps.tPreviewRes[j].width,caps.tPreviewRes[j].height);
        caps.ulPreviewResCount = 1;
    */
    insertCapabilities (params, caps);
    return NO_ERROR;
}