int convertPixelFormatToV4L2Format(PixelFormat format)
{
    int nFormat = 0;

    switch (format) {
        case HAL_PIXEL_FORMAT_YCbCr_420_SP:
        case HAL_PIXEL_FORMAT_YCrCb_420_SP:
            nFormat = v4l2_fourcc('N', 'V', '1', '2');
            break;

        case HAL_PIXEL_FORMAT_YCbCr_420_P:
            nFormat = v4l2_fourcc('Y', 'U', '1', '2');
            break;

        case HAL_PIXEL_FORMAT_YCbCr_422_I:
            nFormat = v4l2_fourcc('Y', 'U', 'Y', 'V');
            break;

        default:
            FLOGE("Error: format:0x%x not supported!", format);
            break;
    }
    FLOGI("pixel format: 0x%x", nFormat);
    return nFormat;
}
예제 #2
0
status_t TVINDevice::setSupportedPreviewFormats(int *sfmt,
                                              int  slen,
                                              int *dfmt,
                                              int  dlen)
{
    if ((sfmt == NULL) || (slen == 0) || (dfmt == NULL) || (dlen == 0)) {
        FLOGE("setSupportedPreviewFormats invalid parameters");
        return BAD_VALUE;
    }

    char fmtStr[FORMAT_STRING_LEN];
    memset(fmtStr, 0, FORMAT_STRING_LEN);
    for (int i = 0; i < slen; i++) {
        for (int j = 0; j < dlen; j++) {
            // should report VPU support format.
            if (sfmt[i] == dfmt[j]) {
                if (sfmt[i] == v4l2_fourcc('Y', 'U', '1', '2')) {
                    strcat(fmtStr, "yuv420p");
                    strcat(fmtStr, ",");
                }
                else if (sfmt[i] == v4l2_fourcc('N', 'V', '1', '2')) {
                    strcat(fmtStr, "yuv420sp");
                    strcat(fmtStr, ",");
                }
                else if (sfmt[i] == v4l2_fourcc('Y', 'U', 'Y', 'V')) {
                    strcat(fmtStr, "yuv422i-yuyv");
                    strcat(fmtStr, ",");
                }
            }
        }
    }
    mParams.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FORMATS, fmtStr);

    return NO_ERROR;
}
예제 #3
0
void vidcap_cmd(int ch, char *optarg)
{
	__u32 colorspace, xfer_func, ycbcr, quantization;
	char *value, *subs;

	switch (ch) {
	case OptSetVideoFormat:
	case OptTryVideoFormat:
		set_fmts = parse_fmt(optarg, width, height, pixfmt, field, colorspace,
				xfer_func, ycbcr, quantization, flags, bytesperline);
		if (!set_fmts ||
		    (set_fmts & (FmtColorspace | FmtYCbCr | FmtQuantization | FmtXferFunc))) {
			vidcap_usage();
			exit(1);
		}
		break;
	case OptListFrameSizes:
		if (strlen(optarg) == 4)
			frmsize.pixel_format = v4l2_fourcc(optarg[0], optarg[1],
					optarg[2], optarg[3]);
		else
			frmsize.pixel_format = strtol(optarg, 0L, 0);
		break;
	case OptListFrameIntervals:
		subs = optarg;
		while (*subs != '\0') {
			static const char *const subopts[] = {
				"width",
				"height",
				"pixelformat",
				NULL
			};

			switch (parse_subopt(&subs, subopts, &value)) {
			case 0:
				frmival.width = strtol(value, 0L, 0);
				break;
			case 1:
				frmival.height = strtol(value, 0L, 0);
				break;
			case 2:
				if (strlen(value) == 4)
					frmival.pixel_format =
						v4l2_fourcc(value[0], value[1],
								value[2], value[3]);
				else
					frmival.pixel_format = strtol(value, 0L, 0);
				break;
			default:
				vidcap_usage();
				exit(1);
			}
		}
		break;
	}
}
예제 #4
0
파일: v4l2-cli.c 프로젝트: yucai/BLTS
static void *variant_args_dev_capfmt_io(struct boxed_value *args, void *user_ptr)
{
	v4l2_data* data = variant_args_dev(args, user_ptr);
	char *work = NULL;

	if (!data) {
		return NULL;
	}

	args = args->next; /* skip dev */
	if (!args) {
		BLTS_WARNING("Error: No arguments left to process in %s:%s\n",__FILE__,__func__);
		return user_ptr;
	}
	if (args->type != CONFIG_PARAM_STRING) {
		BLTS_ERROR("Error: Type mismatch in %s:%s\n",__FILE__,__func__);
		return NULL;
	}
	work = blts_config_boxed_value_get_string(args);

	data->device->requested_format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
	data->device->requested_format.fmt.pix.pixelformat = v4l2_fourcc(work[0], work[1],
		work[2], work[3]);

	data->device->fmt_a = work[0];
	data->device->fmt_b = work[1];
	data->device->fmt_c = work[2];
	data->device->fmt_d = work[3];

	args = args->next;
	if (!args) {
		BLTS_WARNING("Error: No arguments left to process in %s:%s\n",__FILE__,__func__);
		return user_ptr;
	}
	if (args->type != CONFIG_PARAM_STRING) {
		BLTS_ERROR("Error: Type mismatch in %s:%s\n",__FILE__,__func__);
		return NULL;
	}
	work = blts_config_boxed_value_get_string(args);

	if (!strcmp(work, "readwrite")) {
		data->device->io_method = IO_METHOD_READ;
	} else if (!strcmp(work, "MMAP")) {
		data->device->io_method = IO_METHOD_MMAP;

	} else if (!strcmp(work, "userptr")) {
		data->device->io_method = IO_METHOD_USERPTR;
	} else {
		BLTS_ERROR("Error: Invalid IO method \"%s\" in %s:%s\n",work,__FILE__,__func__);
		data = NULL;
	}

	return data;
}
int convertStringToV4L2Format(const char *pFormat)
{
    if (pFormat == NULL) {
        return 0;
    }

    if (!strcmp(pFormat, "yuv420p")) {
        return v4l2_fourcc('Y', 'U', '1', '2');
    }
    else if (!strcmp(pFormat, "yuv420sp")) {
        return v4l2_fourcc('N', 'V', '1', '2');
    }
    else if (!strcmp(pFormat, "yuv422i-yuyv")) {
        return v4l2_fourcc('Y', 'U', 'Y', 'V');
    }
    else {
        FLOGE("format %s is not supported", pFormat);
        return BAD_VALUE;
    }
}
status_t TVINDevice::changeSensorFormats(int *src, int len)
{
    if (src == NULL || len == 0) {
        return 0;
    }

    int k = 0;
    for (int i=0; i<len && i<MAX_SENSOR_FORMAT; i++) {
        switch (src[i]) {
            case v4l2_fourcc('N', 'V', '1', '2'):
                mAvailableFormats[k++] = HAL_PIXEL_FORMAT_YCbCr_420_SP;
                break;

            case v4l2_fourcc('Y', 'V', '1', '2'):
                mAvailableFormats[k++] = HAL_PIXEL_FORMAT_YCbCr_420_P;
                break;

            case v4l2_fourcc('Y', 'U', 'Y', 'V'):
                mAvailableFormats[k++] = HAL_PIXEL_FORMAT_YCbCr_422_I;
                break;

            case v4l2_fourcc('B', 'L', 'O', 'B'):
                mAvailableFormats[k++] = HAL_PIXEL_FORMAT_BLOB;
                break;

            case v4l2_fourcc('R', 'A', 'W', 'S'):
                mAvailableFormats[k++] = HAL_PIXEL_FORMAT_RAW_SENSOR;
                break;

            default:
                FLOGE("Error: format 0x%x not supported!", src[i]);
                break;
        }
    }

    return 0;
}
PixelFormat convertV4L2FormatToPixelFormat(unsigned int format)
{
    PixelFormat nFormat = 0;

    switch (format) {
        case v4l2_fourcc('N', 'V', '1', '2'):
            nFormat = HAL_PIXEL_FORMAT_YCbCr_420_SP;
            break;

        case v4l2_fourcc('Y', 'U', '1', '2'):
            nFormat = HAL_PIXEL_FORMAT_YCbCr_420_P;
            break;

        case v4l2_fourcc('Y', 'U', 'Y', 'V'):
            nFormat = HAL_PIXEL_FORMAT_YCbCr_422_I;
            break;

        default:
            FLOGE("Error: format:0x%x not supported!", format);
            break;
    }
    FLOGI("pixel format: 0x%x", nFormat);
    return nFormat;
}
예제 #8
0
static int imx_pd_bind(struct device *dev, struct device *master, void *data)
{
	struct drm_device *drm = data;
	struct device_node *np = dev->of_node;
	struct device_node *panel_node;
	const u8 *edidp;
	struct imx_parallel_display *imxpd;
	int ret;
	const char *fmt;

	imxpd = devm_kzalloc(dev, sizeof(*imxpd), GFP_KERNEL);
	if (!imxpd)
		return -ENOMEM;

	edidp = of_get_property(np, "edid", &imxpd->edid_len);
	if (edidp)
		imxpd->edid = kmemdup(edidp, imxpd->edid_len, GFP_KERNEL);

	ret = of_property_read_string(np, "interface-pix-fmt", &fmt);
	if (!ret) {
		if (!strcmp(fmt, "rgb24"))
			imxpd->interface_pix_fmt = V4L2_PIX_FMT_RGB24;
		else if (!strcmp(fmt, "rgb565"))
			imxpd->interface_pix_fmt = V4L2_PIX_FMT_RGB565;
		else if (!strcmp(fmt, "bgr666"))
			imxpd->interface_pix_fmt = V4L2_PIX_FMT_BGR666;
		else if (!strcmp(fmt, "lvds666"))
			imxpd->interface_pix_fmt =
					v4l2_fourcc('L', 'V', 'D', '6');
	}

	panel_node = of_parse_phandle(np, "fsl,panel", 0);
	if (panel_node)
		imxpd->panel = of_drm_find_panel(panel_node);

	imxpd->dev = dev;

	ret = imx_pd_register(drm, imxpd);
	if (ret)
		return ret;

	dev_set_drvdata(dev, imxpd);

	return 0;
}
/* Utility functions */
static int omx2ipu_pxlfmt(OMX_COLOR_FORMATTYPE omx_pxlfmt)
{
    int ipu_pxlfmt; // bit per pixel

    switch(omx_pxlfmt)
    {
    case  OMX_COLOR_Format16bitRGB565:
        ipu_pxlfmt = v4l2_fourcc('R', 'G', 'B', 'P');
        break;
    case  OMX_COLOR_Format24bitRGB888:
        ipu_pxlfmt = v4l2_fourcc('R', 'G', 'B', '3');
        break;
    case  OMX_COLOR_Format24bitBGR888:
        ipu_pxlfmt = v4l2_fourcc('B', 'G', 'R', '3');
        break;
    case  OMX_COLOR_Format32bitBGRA8888:
        ipu_pxlfmt = v4l2_fourcc('B', 'G', 'R', 'A');
        break;
    case  OMX_COLOR_Format32bitARGB8888:
        ipu_pxlfmt = v4l2_fourcc('R', 'G', 'B', 'A');
        break;
    case  OMX_COLOR_FormatYUV420Planar:
        ipu_pxlfmt = v4l2_fourcc('I', '4', '2', '0');
        break;

    case OMX_COLOR_FormatUnused:
    case  OMX_COLOR_FormatMonochrome:
    case  OMX_COLOR_Format8bitRGB332:
    case  OMX_COLOR_Format12bitRGB444:
    case  OMX_COLOR_Format16bitARGB4444:
    case  OMX_COLOR_Format16bitARGB1555:
    case  OMX_COLOR_Format16bitBGR565:
    case  OMX_COLOR_Format18bitRGB666:
    case  OMX_COLOR_Format18bitARGB1665:
    case  OMX_COLOR_Format19bitARGB1666:
    case  OMX_COLOR_Format24bitARGB1887:
    case  OMX_COLOR_Format25bitARGB1888:
    case  OMX_COLOR_FormatYUV411Planar:
    case  OMX_COLOR_FormatYUV411PackedPlanar:
    case  OMX_COLOR_FormatYUV420PackedPlanar:
    case  OMX_COLOR_FormatYUV420SemiPlanar:
    case  OMX_COLOR_FormatYUV422Planar:
    case  OMX_COLOR_FormatYUV422PackedPlanar:
    case  OMX_COLOR_FormatYUV422SemiPlanar:
    case  OMX_COLOR_FormatYCbYCr:
    case  OMX_COLOR_FormatYCrYCb:
    case  OMX_COLOR_FormatCbYCrY:
    case  OMX_COLOR_FormatCrYCbY:
    case  OMX_COLOR_FormatYUV444Interleaved:
    case  OMX_COLOR_FormatRawBayer8bit:
    case  OMX_COLOR_FormatRawBayer10bit:
    case  OMX_COLOR_FormatRawBayer8bitcompressed:
    case  OMX_COLOR_FormatL2:
    case  OMX_COLOR_FormatL4:
    case  OMX_COLOR_FormatL8:
    case  OMX_COLOR_FormatL16:
    case  OMX_COLOR_FormatL24:
    case  OMX_COLOR_FormatL32:
    case  OMX_COLOR_FormatYUV420PackedSemiPlanar:
    case  OMX_COLOR_FormatYUV422PackedSemiPlanar:
    case  OMX_COLOR_Format18BitBGR666:
    case  OMX_COLOR_Format24BitARGB6666:
    case  OMX_COLOR_Format24BitABGR6666:
    default:
        ipu_pxlfmt = 0;
        break;
    }

    return ipu_pxlfmt;
}
예제 #10
0
status_t TVINDevice::initParameters(CameraParameters& params,
                                  int              *supportRecordingFormat,
                                  int               rfmtLen,
                                  int              *supportPictureFormat,
                                  int               pfmtLen)
{
    int ret = 0, index = 0;
    int maxWait = 6;
    int sensorFormat[MAX_SENSOR_FORMAT];

    if (mCameraHandle < 0) {
        FLOGE("TVINDevice: initParameters sensor has not been opened");
        return BAD_VALUE;
    }
    if ((supportRecordingFormat == NULL) || (rfmtLen == 0) ||
        (supportPictureFormat == NULL) || (pfmtLen == 0)) {
        FLOGE("TVINDevice: initParameters invalid parameters");
        return BAD_VALUE;
    }

    // Get the PAL/NTSC STD
    do {
        ret = ioctl(mCameraHandle, VIDIOC_G_STD, &mSTD);
        if (ret < 0)
        {
            FLOGE("VIDIOC_G_STD failed with more try %d\n",
                  maxWait - 1);
            sleep(1);
        }
        maxWait --;
    }while ((ret != 0) || (maxWait <= 0));

    if (mSTD == V4L2_STD_PAL)
        FLOGI("Get current mode: PAL");
    else if (mSTD == V4L2_STD_NTSC)
        FLOGI("Get current mode: NTSC");
    else {
        FLOGI("Error!Get invalid mode: %llu", mSTD);
		return BAD_VALUE;
    }

	if (ioctl(mCameraHandle, VIDIOC_S_STD, &mSTD) < 0)
	{
		FLOGE("VIDIOC_S_STD failed\n");
		return BAD_VALUE;
	}

    // first read sensor format.
#if 0
    struct v4l2_fmtdesc vid_fmtdesc;
    while (ret == 0) {
        vid_fmtdesc.index = index;
        vid_fmtdesc.type  = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        ret               = ioctl(mCameraHandle, VIDIOC_ENUM_FMT, &vid_fmtdesc);
        FLOG_RUNTIME("index:%d,ret:%d, format:%c%c%c%c", index, ret,
                     vid_fmtdesc.pixelformat & 0xFF,
                     (vid_fmtdesc.pixelformat >> 8) & 0xFF,
                     (vid_fmtdesc.pixelformat >> 16) & 0xFF,
                     (vid_fmtdesc.pixelformat >> 24) & 0xFF);
        if (ret == 0) {
            sensorFormat[index++] = vid_fmtdesc.pixelformat;
        }
    }
#endif // if 0

    // v4l2 does not support enum format, now hard code here.
    sensorFormat[0] = v4l2_fourcc('N', 'V', '1', '2');
    sensorFormat[1] = v4l2_fourcc('Y', 'U', '1', '2');
    sensorFormat[2] = v4l2_fourcc('Y', 'U', 'Y', 'V');
    index           = 3;

    // second check match sensor format with vpu support format and picture
    // format.
    mPreviewPixelFormat = getMatchFormat(supportRecordingFormat,
                                         rfmtLen,
                                         sensorFormat,
                                         index);
    mPicturePixelFormat = getMatchFormat(supportPictureFormat,
                                         pfmtLen,
                                         sensorFormat,
                                         index);
    setPreviewStringFormat(mPreviewPixelFormat);
    ret = setSupportedPreviewFormats(supportRecordingFormat,
                                     rfmtLen,
                                     sensorFormat,
                                     index);
    if (ret) {
        FLOGE("setSupportedPreviewFormats failed");
        return ret;
    }

    index = 0;
    char TmpStr[20];
    int  previewCnt = 0, pictureCnt = 0;
    struct v4l2_frmsizeenum vid_frmsize;
    struct v4l2_frmivalenum vid_frmval;
    while (ret == 0) {
        memset(TmpStr, 0, 20);
        memset(&vid_frmsize, 0, sizeof(struct v4l2_frmsizeenum));
        vid_frmsize.index        = index++;
        vid_frmsize.pixel_format = v4l2_fourcc('N', 'V', '1', '2');
        ret                      = ioctl(mCameraHandle,
                                         VIDIOC_ENUM_FRAMESIZES,
                                         &vid_frmsize);
        if (ret == 0) {
            FLOG_RUNTIME("enum frame size w:%d, h:%d",
                         vid_frmsize.discrete.width, vid_frmsize.discrete.height);
            memset(&vid_frmval, 0, sizeof(struct v4l2_frmivalenum));
            vid_frmval.index        = 0;
            vid_frmval.pixel_format = vid_frmsize.pixel_format;
            vid_frmval.width        = vid_frmsize.discrete.width;
            vid_frmval.height       = vid_frmsize.discrete.height;

            // ret = ioctl(mCameraHandle, VIDIOC_ENUM_FRAMEINTERVALS,
            // &vid_frmval);
            // v4l2 does not support, now hard code here.
            if (ret == 0) {
                FLOG_RUNTIME("vid_frmval denominator:%d, numeraton:%d",
                             vid_frmval.discrete.denominator,
                             vid_frmval.discrete.numerator);
                if ((vid_frmsize.discrete.width > 1280) ||
                    (vid_frmsize.discrete.height > 720)) {
                    vid_frmval.discrete.denominator = 15;
                    vid_frmval.discrete.numerator   = 1;
                }
                else {
                    vid_frmval.discrete.denominator = 30;
                    vid_frmval.discrete.numerator   = 1;
                }

                sprintf(TmpStr,
                        "%dx%d",
                        vid_frmsize.discrete.width,
                        vid_frmsize.discrete.height);

                // Set default to be first enum w/h, since tvin may only
                // have one set
                if (pictureCnt == 0){
                    mParams.setPreviewSize(vid_frmsize.discrete.width,
                            vid_frmsize.discrete.height);
                    mParams.setPictureSize(vid_frmsize.discrete.width,
                            vid_frmsize.discrete.height);
                }

                if (pictureCnt == 0)
                    strncpy((char *)mSupportedPictureSizes,
                            TmpStr,
                            CAMER_PARAM_BUFFER_SIZE);
                else {
                    strncat(mSupportedPictureSizes,
                            PARAMS_DELIMITER,
                            CAMER_PARAM_BUFFER_SIZE);
                    strncat(mSupportedPictureSizes,
                            TmpStr,
                            CAMER_PARAM_BUFFER_SIZE);
                }
                pictureCnt++;

                if (vid_frmval.discrete.denominator /
                    vid_frmval.discrete.numerator >= 15) {
                    if (previewCnt == 0)
                        strncpy((char *)mSupportedPreviewSizes,
                                TmpStr,
                                CAMER_PARAM_BUFFER_SIZE);
                    else {
                        strncat(mSupportedPreviewSizes,
                                PARAMS_DELIMITER,
                                CAMER_PARAM_BUFFER_SIZE);
                        strncat(mSupportedPreviewSizes,
                                TmpStr,
                                CAMER_PARAM_BUFFER_SIZE);
                    }
                    previewCnt++;
                }
            }
        } // end if (ret == 0)
        else {
            FLOGI("enum frame size error %d", ret);
        }
    } // end while

    strcpy(mSupportedFPS, "15,30");
    FLOGI("SupportedPictureSizes is %s", mSupportedPictureSizes);
    FLOGI("SupportedPreviewSizes is %s", mSupportedPreviewSizes);
    FLOGI("SupportedFPS is %s", mSupportedFPS);

    mParams.set(CameraParameters::KEY_SUPPORTED_PICTURE_SIZES,
                mSupportedPictureSizes);
    mParams.set(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES,
                mSupportedPreviewSizes);
    mParams.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FRAME_RATES,
                mSupportedFPS);
    mParams.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FPS_RANGE,
                "(12000,17000),(25000,33000)");
    // Align the default FPS RANGE to the DEFAULT_PREVIEW_FPS
    mParams.set(CameraParameters::KEY_PREVIEW_FPS_RANGE, "12000,17000");
    mParams.setPreviewFrameRate(DEFAULT_PREVIEW_FPS);

    params = mParams;
    return NO_ERROR;
}
예제 #11
0
 */
typedef struct Fmt_decomp{
    __u32 pixelformat;                /*!< Format supported by a decompressor */
    Wg_cam_decompressor decompressor; /*!< Decompressor function*/
}Fmt_decomp;

/** 
* @brief Type big enough to store __u32 as string
*/
typedef wg_char u32str[sizeof (__u32) + 1]; 

/** 
* @brief Supported decompressors
*/
WG_STATIC Fmt_decomp supported_formats[] = {
    {v4l2_fourcc('Y', 'U', 'Y', 'V'), {img_yuyv_2_rgb24}},
    {v4l2_fourcc('M', 'J', 'P', 'G'), {img_jpeg_decompress}},
    {v4l2_fourcc('J', 'P', 'E', 'G'), {img_jpeg_decompress}}
};

WG_PRIVATE void
cam_print_u32_as_string(__u32 value, u32str cstr);

/** 
* @brief Select decompressor
*
* Supported formats YUYV, MJPEG, JPEG
* 
* @param cam         webcam instance
* @param pixelformat pixel format
* 
예제 #12
0
V4l2CsiDevice :: V4l2CsiDevice() {
    mSupportedFmt[0] = v4l2_fourcc('N','V','1','2');
    mSupportedFmt[1] = v4l2_fourcc('Y','U','1','2');
    mSupportedFmt[2] = v4l2_fourcc('Y','U','Y','V');

}
int process_cmdline(int argc, char **argv)
{
        int i;

        for (i = 1; i < argc; i++) {
                if (strcmp(argv[i], "-iw") == 0) {
                        g_in_width = atoi(argv[++i]);
                }
                else if (strcmp(argv[i], "-ih") == 0) {
                        g_in_height = atoi(argv[++i]);
                }
                else if (strcmp(argv[i], "-u") == 0) {
			g_mem_type = V4L2_MEMORY_USERPTR;
                }
                else if (strcmp(argv[i], "-ow") == 0) {
                        g_display_width = atoi(argv[++i]);
                }
                else if (strcmp(argv[i], "-oh") == 0) {
                        g_display_height = atoi(argv[++i]);
                }
                else if (strcmp(argv[i], "-ot") == 0) {
                        g_display_top = atoi(argv[++i]);
                }
                else if (strcmp(argv[i], "-ol") == 0) {
                        g_display_left = atoi(argv[++i]);
                }
                else if (strcmp(argv[i], "-d") == 0) {
                        g_dev = argv[++i];
                }
                else if (strcmp(argv[i], "-fg") == 0) {
                        g_overlay = 1;
                }
                else if (strcmp(argv[i], "-r") == 0) {
                        g_rotate = atoi(argv[++i]);
                }
                else if (strcmp(argv[i], "-vf") == 0) {
                        g_vflip = atoi(argv[++i]);
                }
                else if (strcmp(argv[i], "-hf") == 0) {
                        g_hflip = atoi(argv[++i]);
                }
                else if (strcmp(argv[i], "-v") == 0) {
			g_vdi_enable = 1;
                        g_vdi_motion = atoi(argv[++i]);
                }
                else if (strcmp(argv[i], "-fr") == 0) {
                        g_frame_period = atoi(argv[++i]);
                        g_frame_period = 1000000L / g_frame_period;
                }
                else if (strcmp(argv[i], "-l") == 0) {
                        g_loop_count = atoi(argv[++i]);
                }
                else if (strcmp(argv[i], "-cr") == 0) {
                        g_icrop_w = atoi(argv[++i]);
                        g_icrop_h = atoi(argv[++i]);
                        g_icrop_left = atoi(argv[++i]);
                        g_icrop_top = atoi(argv[++i]);
                }
                else if (strcmp(argv[i], "-f") == 0) {
                        i++;
                        g_in_fmt = v4l2_fourcc(argv[i][0], argv[i][1],argv[i][2],argv[i][3]);

                        if ( (g_in_fmt != V4L2_PIX_FMT_BGR24) &&
                             (g_in_fmt != V4L2_PIX_FMT_BGR32) &&
                             (g_in_fmt != V4L2_PIX_FMT_RGB565) &&
                             (g_in_fmt != 'PMBW') &&
                             (g_in_fmt != V4L2_PIX_FMT_UYVY) &&
			     (g_in_fmt != V4L2_PIX_FMT_YUYV) &&
			     (g_in_fmt != V4L2_PIX_FMT_YUV422P) &&
			     (g_in_fmt != IPU_PIX_FMT_YUV444P) &&
                             (g_in_fmt != V4L2_PIX_FMT_YUV420) &&
                             (g_in_fmt != V4L2_PIX_FMT_YVU420) &&
                             (g_in_fmt != IPU_PIX_FMT_TILED_NV12) &&
                             (g_in_fmt != IPU_PIX_FMT_TILED_NV12F) &&
                             (g_in_fmt != V4L2_PIX_FMT_NV12) )
                        {
                                return -1;
                        }
                        if (g_in_fmt == 'PMBW') {
                                g_bmp_header = 1;
                                g_in_fmt = V4L2_PIX_FMT_BGR24;
                        }
                }
        }

        printf("g_in_width = %d, g_in_height = %d\n", g_in_width, g_in_height);
        printf("g_display_width = %d, g_display_height = %d\n", g_display_width, g_display_height);

        if ((g_in_width == 0) || (g_in_height == 0)) {
                return -1;
        }
        return 0;
}
예제 #14
0
#define TS_HEADER(_PID, _PES_HDR, _COUNTER, _ADAPTATION_CTRL) ts_buffer[0] = TS_SYNC_BYTE; \
           ts_buffer[1] = (_PES_HDR ? 0x40:0) | (_PID >> 8); \
           ts_buffer[2] = _PID & 0xFF; \
           ts_buffer[3] = _ADAPTATION_CTRL << 4 | (_COUNTER & 0xf)

#define TS_PAYLOAD        0x1
#define TS_ADAPTATION_FIELD 0x2

#define SENDPATPMT_PACKETINTERVAL 500

static const short kVideoPid    = 301;
static const short kAudioPid    = 300;
static const short kTeletextPid = 305;
static const short kPCRPid      = 101;
static const uint32_t itv0 = v4l2_fourcc('i','t','v','0');
static const uint32_t ITV0 = v4l2_fourcc('I','T','V','0');


const unsigned char kPAT[TS_SIZE] = {
  0x47, 0x40, 0x00, 0x10, 0x00, 0x00, 0xb0, 0x0d,
  0x00, 0x00, 0xc1, 0x00, 0x00, 0x00, 0x01, 0xe0,
  0x84, 0xcc, 0x32, 0xcc, 0x32, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
예제 #15
0
void setPixFmt(char a, char b, char c, char d) {
  cntx->pix_fmt = v4l2_fourcc(a, b, c, d);
}
예제 #16
0
	.biBitCount = 24,
	.biCompression = V4L2_PIX_FMT_MJPEG,
	.biSizeImage = 640*480*2, //2 bytes per pixel (max buffer - use x3 for RGB)
	.biXPelsPerMeter = 0,
	.biYPelsPerMeter = 0,
	.biClrUsed = 0,
	.biClrImportant = 0
};

static vcodecs_data listSupVCodecs[] = //list of software supported formats
{
	{
		.avcodec      = FALSE,
		.valid        = TRUE,
		.compressor   = "MJPG",
		.mkv_4cc      = v4l2_fourcc('M','J','P','G'),
		.mkv_codec    = "V_MS/VFW/FOURCC",
		.mkv_codecPriv= &mkv_codecPriv,
		.description  = N_("MJPG - compressed"),
		.fps          = 0,
		.monotonic_pts= 0,
		.bit_rate     = 0,
		.qmax         = 0,
		.qmin         = 0,
		.max_qdiff    = 0,
		.dia          = 0,
		.pre_dia      = 0,
		.pre_me       = 0,
		.me_pre_cmp   = 0,
		.me_cmp       = 0,
		.me_sub_cmp   = 0,
예제 #17
0
int Iputool::parse_cmd_input(int argc, char **argv, Iputool::ipu_test_handle_t *test_handle){
        char opt;
        char fourcc[5];
        struct ipu_task *t = &test_handle->task;

        printf("pass cmdline %d, %s\n", argc, argv[0]);

        /*default settings*/
        t->priority = 0;
        t->task_id = 0;
        t->timeout = 1000;
        test_handle->fcount = 50;
        test_handle->loop_cnt = 1;
        t->input.width = 320;
        t->input.height = 240;
        t->input.format =  v4l2_fourcc('I', '4','2', '0');
        t->input.crop.pos.x = 0;
        t->input.crop.pos.y = 0;
        t->input.crop.w = 0;
        t->input.crop.h = 0;
        t->input.deinterlace.enable = 0;
        t->input.deinterlace.motion = 0;

        t->overlay_en = 0;
        t->overlay.width = 320;
        t->overlay.height = 240;
        t->overlay.format = v4l2_fourcc('I', '4','2', '0');
        t->overlay.crop.pos.x = 0;
        t->overlay.crop.pos.y = 0;
        t->overlay.crop.w = 0;
        t->overlay.crop.h = 0;
        t->overlay.alpha.mode = 0;
        t->overlay.alpha.gvalue = 0;
        t->overlay.colorkey.enable = 0;
        t->overlay.colorkey.value = 0x555555;

        t->output.width = 1024;
        t->output.height = 768;
        t->output.format = v4l2_fourcc('U', 'Y','V', 'Y');
        t->output.rotate = 180;
        t->output.crop.pos.x = 0;
        t->output.crop.pos.y = 0;
        t->output.crop.w = 0;
        t->output.crop.h = 0;

        test_handle->show_to_fb = 1;
        memcpy(test_handle->outfile,"ipu0-1st-ovfb",13);

        while((opt = getopt(argc, argv, options)) > 0)    //char * options = "p:d:t:c:l:i:o:O:s:f:h";
        {
                deb_printf("\nnew option : %c \n", opt);
                switch(opt)
                {
                        case 'p':/*priority*/
                                if(NULL == optarg)
                                        break;
                                t->priority = strtol(optarg, NULL, 10);
                                deb_printf("priority set %d \n",t->priority);
                                break;
                        case 'd': /*task id*/
                                if(NULL == optarg)
                                        break;
                                t->task_id = strtol(optarg, NULL, 10);
                                deb_printf("task id set %d \n",t->task_id);
                                break;
                        case 't':
                                if(NULL == optarg)
                                        break;
                                t->timeout = strtol(optarg, NULL, 10);
                        case 'c':
                                if(NULL == optarg)
                                        break;
                                test_handle->fcount = strtol(optarg, NULL, 10);
                                deb_printf("frame count set %d \n",test_handle->fcount);
                                break;
                        case 'l':
                                if(NULL == optarg)
                                        break;
                                test_handle->loop_cnt = strtol(optarg, NULL, 10);
                                deb_printf("loop count set %d \n",test_handle->loop_cnt);
                                break;
                        case 'i': /*input param*/
                                if(NULL == optarg)
                                        break;
                                memset(fourcc,0,sizeof(fourcc));
                                sscanf(optarg,"%d,%d,%c%c%c%c,%d,%d,%d,%d,%d,%d",
                                                &(t->input.width),&(t->input.height),
                                                &(fourcc[0]),&(fourcc[1]), &(fourcc[2]), &(fourcc[3]),
                                                &(t->input.crop.pos.x),&(t->input.crop.pos.y),
                                                &(t->input.crop.w), &(t->input.crop.h),
                                                (int *)&(t->input.deinterlace.enable), (int *)&(t->input.deinterlace.motion));
                                t->input.format = v4l2_fourcc(fourcc[0], fourcc[1],
                                                fourcc[2], fourcc[3]);
                                deb_printf("input w=%d,h=%d,fucc=%s,cpx=%d,cpy=%d,cpw=%d,cph=%d,de=%d,dm=%d\n",
                                                t->input.width,t->input.height,
                                                fourcc,t->input.crop.pos.x,t->input.crop.pos.y,
                                                t->input.crop.w, t->input.crop.h,
                                                t->input.deinterlace.enable, t->input.deinterlace.motion);
                                break;
                        case 'o':/*overlay setting*/
                                if(NULL == optarg)
                                        break;
                                memset(fourcc,0,sizeof(fourcc));
                                sscanf(optarg,"%d,%d,%d,%c%c%c%c,%d,%d,%d,%d,%d,%d,%d,%x",
                                                (int *)&(t->overlay_en),&(t->overlay.width),&(t->overlay.height),
                                                &(fourcc[0]),&(fourcc[1]), &(fourcc[2]), &(fourcc[3]),
                                                &(t->overlay.crop.pos.x),&(t->overlay.crop.pos.y),
                                                &(t->overlay.crop.w), &(t->overlay.crop.h),
                                                (int *)&(t->overlay.alpha.mode), (int *)&(t->overlay.alpha.gvalue),
                                                (int *)&(t->overlay.colorkey.enable),&(t->overlay.colorkey.value));
                                t->overlay.format = v4l2_fourcc(fourcc[0], fourcc[1],
                                                fourcc[2], fourcc[3]);
                                deb_printf("overlay en=%d,w=%d,h=%d,fourcc=%c%c%c%c,cpx=%d,\
                                                cpy=%d,cw=%d,ch=%d,am=%c,ag=%d,ce=%d,cv=%x\n",
                                                t->overlay_en, t->overlay.width,t->overlay.height,
                                                fourcc[0],fourcc[1], fourcc[2], fourcc[3],
                                                t->overlay.crop.pos.x,t->overlay.crop.pos.y,
                                                t->overlay.crop.w, t->overlay.crop.h,
                                                t->overlay.alpha.mode, t->overlay.alpha.gvalue,
                                                t->overlay.colorkey.enable,t->overlay.colorkey.value);
                                break;
                        case 'O':/*output setting*/
                                memset(fourcc,0,sizeof(fourcc));
                                if(NULL == optarg)
                                        break;
                                sscanf(optarg,"%d,%d,%c%c%c%c,%d,%d,%d,%d,%d",
                                                &(t->output.width),&(t->output.height),
                                                &(fourcc[0]),&(fourcc[1]), &(fourcc[2]), &(fourcc[3]),
                                                (int *)&(t->output.rotate),&(t->output.crop.pos.x),
                                                &(t->output.crop.pos.y),&(t->output.crop.w),
                                                &(t->output.crop.h));
                                t->output.format = v4l2_fourcc(fourcc[0],
                                                fourcc[1],fourcc[2], fourcc[3]);
                                deb_printf(optarg,"%d,%d,%s,%d,%d,%d,%d,%d\n",
                                                t->output.width,t->output.height,
                                                fourcc,t->output.rotate,t->output.crop.pos.x,
                                                t->output.crop.pos.y,t->output.crop.w,
                                                t->output.crop.h);
                                break;
                        case 's':/*fb setting*/
                                if(NULL == optarg)
                                        break;
                                test_handle->show_to_fb = strtol(optarg, NULL, 10);
                                deb_printf("show to fb %d\n", test_handle->show_to_fb);
                                break;
                        case 'f':/*output0 file name*/
                                if(NULL == optarg)
                                        break;
                                memset(test_handle->outfile,0,sizeof(test_handle->outfile));
                                sscanf(optarg,"%s",test_handle->outfile);
                                deb_printf("output file name %s \n",test_handle->outfile);
                                break;
                        case 'h':
                                util_help();
                                break;
                        default:
                                return 0;
                }
        }
        return 0;
}
status_t TVINDevice::initSensorInfo(const CameraInfo& /*info*/)
{
    if (mCameraHandle < 0) {
        FLOGE("TVINDevice: initParameters sensor has not been opened");
        return BAD_VALUE;
    }

    int res = 0;
    int maxWait = 6;
    // Get the PAL/NTSC STD
    do {
        res = ioctl(mCameraHandle, VIDIOC_G_STD, &mSTD);
        if (res < 0) {
            FLOGE("VIDIOC_G_STD failed with more try %d\n", maxWait - 1);
            sleep(1);
        }
        maxWait --;
    }while ((res != 0) || (maxWait <= 0));

    if (mSTD == V4L2_STD_PAL)
        FLOGI("Get current mode: PAL");
    else if (mSTD == V4L2_STD_NTSC)
        FLOGI("Get current mode: NTSC");
    else {
        FLOGI("Error!Get invalid mode: %llu", mSTD);
        return BAD_VALUE;
    }

    if (ioctl(mCameraHandle, VIDIOC_S_STD, &mSTD) < 0) {
        FLOGE("VIDIOC_S_STD failed\n");
        return BAD_VALUE;
    }


    // first read sensor format.
    int ret = 0, index = 0;
    int sensorFormats[MAX_SENSOR_FORMAT];
    memset(mAvailableFormats, 0, sizeof(mAvailableFormats));
    memset(sensorFormats, 0, sizeof(sensorFormats));
#if 0
    struct v4l2_fmtdesc vid_fmtdesc;
    while (ret == 0) {
        vid_fmtdesc.index = index;
        vid_fmtdesc.type  = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        ret               = ioctl(mCameraHandle, VIDIOC_ENUM_FMT, &vid_fmtdesc);
        FLOG_RUNTIME("index:%d,ret:%d, format:%c%c%c%c", index, ret,
                     vid_fmtdesc.pixelformat & 0xFF,
                     (vid_fmtdesc.pixelformat >> 8) & 0xFF,
                     (vid_fmtdesc.pixelformat >> 16) & 0xFF,
                     (vid_fmtdesc.pixelformat >> 24) & 0xFF);
        if (ret == 0) {
            sensorFormats[index++] = vid_fmtdesc.pixelformat;
        }
    }
    sensorFormats[index++] = v4l2_fourcc('B', 'L', 'O', 'B');
    sensorFormats[index++] = v4l2_fourcc('R', 'A', 'W', 'S');
#endif

    // v4l2 does not support enum format, now hard code here.
    sensorFormats[index++] = v4l2_fourcc('N', 'V', '1', '2');
    sensorFormats[index++] = v4l2_fourcc('Y', 'V', '1', '2');
    sensorFormats[index++] = v4l2_fourcc('B', 'L', 'O', 'B');
    sensorFormats[index++] = v4l2_fourcc('R', 'A', 'W', 'S');
    //mAvailableFormats[2] = v4l2_fourcc('Y', 'U', 'Y', 'V');
    mAvailableFormatCount = index;
    changeSensorFormats(sensorFormats, index);

    index = 0;
    char TmpStr[20];
    int  previewCnt = 0, pictureCnt = 0;
    struct v4l2_frmsizeenum vid_frmsize;
    struct v4l2_frmivalenum vid_frmval;
    while (ret == 0) {
        memset(TmpStr, 0, 20);
        memset(&vid_frmsize, 0, sizeof(struct v4l2_frmsizeenum));
        vid_frmsize.index        = index++;
        vid_frmsize.pixel_format = v4l2_fourcc('N', 'V', '1', '2');
        ret = ioctl(mCameraHandle,
                    VIDIOC_ENUM_FRAMESIZES, &vid_frmsize);
        if (ret == 0) {
            FLOG_RUNTIME("enum frame size w:%d, h:%d",
                         vid_frmsize.discrete.width, vid_frmsize.discrete.height);
            memset(&vid_frmval, 0, sizeof(struct v4l2_frmivalenum));
            vid_frmval.index        = 0;
            vid_frmval.pixel_format = vid_frmsize.pixel_format;
            vid_frmval.width        = vid_frmsize.discrete.width;
            vid_frmval.height       = vid_frmsize.discrete.height;

            // ret = ioctl(mCameraHandle, VIDIOC_ENUM_FRAMEINTERVALS,
            // &vid_frmval);
            // v4l2 does not support, now hard code here.
            if (ret == 0) {
                FLOG_RUNTIME("vid_frmval denominator:%d, numeraton:%d",
                             vid_frmval.discrete.denominator,
                             vid_frmval.discrete.numerator);
                if ((vid_frmsize.discrete.width > 1920) ||
                    (vid_frmsize.discrete.height > 1080)) {
                    vid_frmval.discrete.denominator = 15;
                    vid_frmval.discrete.numerator   = 1;
                }
                else {
                    vid_frmval.discrete.denominator = 30;
                    vid_frmval.discrete.numerator   = 1;
                }

                mPictureResolutions[pictureCnt++] = vid_frmsize.discrete.width;
                mPictureResolutions[pictureCnt++] = vid_frmsize.discrete.height;

                if (vid_frmval.discrete.denominator /
                    vid_frmval.discrete.numerator > 15) {
                    mPreviewResolutions[previewCnt++] = vid_frmsize.discrete.width;
                    mPreviewResolutions[previewCnt++] = vid_frmsize.discrete.height;;
                }
            }
        }
    } // end while

    mPreviewResolutionCount = previewCnt;
    mPictureResolutionCount = pictureCnt;

    mMinFrameDuration = 33331760L;
    mMaxFrameDuration = 30000000000L;
    int i;
    for (i=0; i<MAX_RESOLUTION_SIZE && i<pictureCnt; i+=2) {
        FLOGI("SupportedPictureSizes: %d x %d", mPictureResolutions[i], mPictureResolutions[i+1]);
    }

    adjustPreviewResolutions();
    for (i=0; i<MAX_RESOLUTION_SIZE && i<previewCnt; i+=2) {
        FLOGI("SupportedPreviewSizes: %d x %d", mPreviewResolutions[i], mPreviewResolutions[i+1]);
    }
    FLOGI("FrameDuration is %lld, %lld", mMinFrameDuration, mMaxFrameDuration);

    i = 0;
    mTargetFpsRange[i++] = 10;
    mTargetFpsRange[i++] = 15;
    mTargetFpsRange[i++] = 25;
    mTargetFpsRange[i++] = 30;

    setMaxPictureResolutions();
    FLOGI("mMaxWidth:%d, mMaxHeight:%d", mMaxWidth, mMaxHeight);
    mFocalLength = 10.001;

    return NO_ERROR;
}
예제 #19
0
int Iputool::parse_options(char *buf, Iputool::ipu_test_handle_t *test_handle)
{
        struct ipu_task *t = &test_handle->task;
        char *str;

        /* general */
        str = strstr(buf, "priority");
        if (str != NULL) {
                str = index(buf, '=');
                if (str != NULL) {
                        str++;
                        if (*str != '\0') {
                                t->priority = strtol(str, NULL, 10);
                                printf("priority\t= %d\n", t->priority);
                        }
                        return 0;
                }
        }
        str = strstr(buf, "task_id");
        if (str != NULL) {
                str = index(buf, '=');
                if (str != NULL) {
                        str++;
                        if (*str != '\0') {
                                t->task_id = strtol(str, NULL, 10);
                                printf("task_id\t\t= %d\n", t->task_id);
                        }
                        return 0;
                }
        }

        str = strstr(buf, "timeout");
        if (str != NULL) {
                str = index(buf, '=');
                if (str != NULL) {
                        str++;
                        if (*str != '\0') {
                                t->timeout = strtol(str, NULL, 10);
                                printf("timeout\t\t= %d\n", t->timeout);
                        }
                        return 0;
                }
        }

        str = strstr(buf, "fcount");
        if (str != NULL) {
                str = index(buf, '=');
                if (str != NULL) {
                        str++;
                        if (*str != '\0') {
                                test_handle->fcount = strtol(str, NULL, 10);
                                printf("fcount\t\t= %d\n", test_handle->fcount);
                        }
                        return 0;
                }
        }

        str = strstr(buf, "loop_cnt");
        if (str != NULL) {
                str = index(buf, '=');
                if (str != NULL) {
                        str++;
                        if (*str != '\0') {
                                test_handle->loop_cnt = strtol(str, NULL, 10);
                                printf("loop_cnt\t= %d\n", test_handle->loop_cnt);
                        }
                        return 0;
                }
        }

        /* input */
        str = strstr(buf, "in_width");
        if (str != NULL) {
                str = index(buf, '=');
                if (str != NULL) {
                        str++;
                        if (*str != '\0') {
                                t->input.width = strtol(str, NULL, 10);
                                printf("in_width\t= %d\n", t->input.width);
                        }
                        return 0;
                }
        }

        str = strstr(buf, "in_height");
        if (str != NULL) {
                str = index(buf, '=');
                if (str != NULL) {
                        str++;
                        if (*str != '\0') {
                                t->input.height = strtol(str, NULL, 10);
                                printf("in_height\t= %d\n", t->input.height);
                        }
                        return 0;
                }
        }

        str = strstr(buf, "in_fmt");
        if (str != NULL) {
                str = index(buf, '=');
                if (str != NULL) {
                        str++;
                        if (*str != '\0') {
                                t->input.format =
                                        v4l2_fourcc(str[0], str[1], str[2], str[3]);
                                printf("in_fmt\t\t= %s\n", str);
                        }
                        return 0;
                }
        }

        str = strstr(buf, "in_posx");
        if (str != NULL) {
                str = index(buf, '=');
                if (str != NULL) {
                        str++;
                        if (*str != '\0') {
                                t->input.crop.pos.x =
                                        strtol(str, NULL, 10);
                                printf("in_posx\t\t= %d\n",
                                        t->input.crop.pos.x);
                        }
                        return 0;
                }
        }

        str = strstr(buf, "in_posy");
        if (str != NULL) {
                str = index(buf, '=');
                if (str != NULL) {
                        str++;
                        if (*str != '\0') {
                                t->input.crop.pos.y =
                                        strtol(str, NULL, 10);
                                printf("in_posy\t\t= %d\n",
                                        t->input.crop.pos.y);
                        }
                        return 0;
                }
        }

        str = strstr(buf, "in_crop_w");
        if (str != NULL) {
                str = index(buf, '=');
                if (str != NULL) {
                        str++;
                        if (*str != '\0') {
                                t->input.crop.w =
                                        strtol(str, NULL, 10);
                                printf("in_crop_w\t= %d\n",
                                        t->input.crop.w);
                        }
                        return 0;
                }
        }

        str = strstr(buf, "in_crop_h");
        if (str != NULL) {
                str = index(buf, '=');
                if (str != NULL) {
                        str++;
                        if (*str != '\0') {
                                t->input.crop.h =
                                        strtol(str, NULL, 10);
                                printf("in_crop_h\t= %d\n",
                                        t->input.crop.h);
                        }
                        return 0;
                }
        }

        str = strstr(buf, "deinterlace_en");
        if (str != NULL) {
                str = index(buf, '=');
                if (str != NULL) {
                        str++;
                        if (*str != '\0') {
                                t->input.deinterlace.enable =
                                        strtol(str, NULL, 10);
                                printf("deinterlace_en\t= %d\n",
                                        t->input.deinterlace.enable);
                        }
                        return 0;
                }
        }

        str = strstr(buf, "motion_sel");
        if (str != NULL) {
                str = index(buf, '=');
                if (str != NULL) {
                        str++;
                        if (*str != '\0') {
                                t->input.deinterlace.motion =
                                        strtol(str, NULL, 10);
                                printf("motion_sel\t= %d\n",
                                        t->input.deinterlace.motion);
                        }
                        return 0;
                }
        }

        /* overlay */
        str = strstr(buf, "overlay_en");
        if (str != NULL) {
                str = index(buf, '=');
                if (str != NULL) {
                        str++;
                        if (*str != '\0') {
                                t->overlay_en = strtol(str, NULL, 10);
                                printf("overlay_en\t= %d\n", t->overlay_en);
                        }
                        return 0;
                }
        }

        str = strstr(buf, "ov_width");
        if (str != NULL) {
                str = index(buf, '=');
                if (str != NULL) {
                        str++;
                        if (*str != '\0') {
                                t->overlay.width = strtol(str, NULL, 10);
                                printf("ov_width\t= %d\n", t->overlay.width);
                        }
                        return 0;
                }
        }

        str = strstr(buf, "ov_height");
        if (str != NULL) {
                str = index(buf, '=');
                if (str != NULL) {
                        str++;
                        if (*str != '\0') {
                                t->overlay.height = strtol(str, NULL, 10);
                                printf("ov_height\t= %d\n", t->overlay.height);
                        }
                        return 0;
                }
        }

        str = strstr(buf, "ov_fmt");
        if (str != NULL) {
                str = index(buf, '=');
                if (str != NULL) {
                        str++;
                        if (*str != '\0') {
                                t->overlay.format =
                                        v4l2_fourcc(str[0], str[1], str[2], str[3]);
                                printf("ov_fmt\t\t= %s\n", str);
                        }
                        return 0;
                }
        }

        str = strstr(buf, "ov_posx");
        if (str != NULL) {
                str = index(buf, '=');
                if (str != NULL) {
                        str++;
                        if (*str != '\0') {
                                t->overlay.crop.pos.x =
                                        strtol(str, NULL, 10);
                                printf("ov_posx\t\t= %d\n",
                                        t->overlay.crop.pos.x);
                        }
                        return 0;
                }
        }

        str = strstr(buf, "ov_posy");
        if (str != NULL) {
                str = index(buf, '=');
                if (str != NULL) {
                        str++;
                        if (*str != '\0') {
                                t->overlay.crop.pos.y =
                                        strtol(str, NULL, 10);
                                printf("ov_posy\t\t= %d\n",
                                        t->overlay.crop.pos.y);
                        }
                        return 0;
                }
        }

        str = strstr(buf, "ov_crop_w");
        if (str != NULL) {
                str = index(buf, '=');
                if (str != NULL) {
                        str++;
                        if (*str != '\0') {
                                t->overlay.crop.w =
                                        strtol(str, NULL, 10);
                                printf("ov_crop_w\t= %d\n",
                                        t->overlay.crop.w);
                        }
                        return 0;
                }
        }

        str = strstr(buf, "ov_crop_h");
        if (str != NULL) {
                str = index(buf, '=');
                if (str != NULL) {
                        str++;
                        if (*str != '\0') {
                                t->overlay.crop.h =
                                        strtol(str, NULL, 10);
                                printf("ov_crop_h\t= %d\n",
                                        t->overlay.crop.h);
                        }
                        return 0;
                }
        }

        str = strstr(buf, "alpha_mode");
        if (str != NULL) {
                str = index(buf, '=');
                if (str != NULL) {
                        str++;
                        if (*str != '\0') {
                                t->overlay.alpha.mode =
                                        strtol(str, NULL, 10);
                                printf("alpha_mode\t= %d\n",
                                        t->overlay.alpha.mode);
                        }
                        return 0;
                }
        }

        str = strstr(buf, "alpha_value");
        if (str != NULL) {
                str = index(buf, '=');
                if (str != NULL) {
                        str++;
                        if (*str != '\0') {
                                t->overlay.alpha.gvalue =
                                        strtol(str, NULL, 10);
                                printf("alpha_value\t= %d\n",
                                        t->overlay.alpha.gvalue);
                        }
                        return 0;
                }
        }

        str = strstr(buf, "colorkey_en");
        if (str != NULL) {
                str = index(buf, '=');
                if (str != NULL) {
                        str++;
                        if (*str != '\0') {
                                t->overlay.colorkey.enable =
                                        strtol(str, NULL, 10);
                                printf("colorkey_en\t= %d\n",
                                        t->overlay.colorkey.enable);
                        }
                        return 0;
                }
        }

        str = strstr(buf, "colorkey_value");
        if (str != NULL) {
                str = index(buf, '=');
                if (str != NULL) {
                        str++;
                        if (*str != '\0') {
                                t->overlay.colorkey.value =
                                        strtol(str, NULL, 16);
                                printf("colorkey_value\t= 0x%x\n",
                                        t->overlay.colorkey.value);
                        }
                        return 0;
                }
        }

        /* output */
        str = strstr(buf, "out_width");
        if (str != NULL) {
                str = index(buf, '=');
                if (str != NULL) {
                        str++;
                        if (*str != '\0') {
                                t->output.width = strtol(str, NULL, 10);
                                printf("out_width\t= %d\n", t->output.width);
                        }
                        return 0;
                }
        }

        str = strstr(buf, "out_height");
        if (str != NULL) {
                str = index(buf, '=');
                if (str != NULL) {
                        str++;
                        if (*str != '\0') {
                                t->output.height = strtol(str, NULL, 10);
                                printf("out_height\t= %d\n", t->output.height);
                        }
                        return 0;
                }
        }

        str = strstr(buf, "out_fmt");
        if (str != NULL) {
                str = index(buf, '=');
                if (str != NULL) {
                        str++;
                        if (*str != '\0') {
                                t->output.format =
                                        v4l2_fourcc(str[0], str[1], str[2], str[3]);
                                printf("out_fmt\t\t= %s\n", str);
                        }
                        return 0;
                }
        }

        str = strstr(buf, "out_rot");
        if (str != NULL) {
                str = index(buf, '=');
                if (str != NULL) {
                        str++;
                        if (*str != '\0') {
                                t->output.rotate = strtol(str, NULL, 10);
                                printf("out_rot\t\t= %d\n", t->output.rotate);
                        }
                        return 0;
                }
        }

        str = strstr(buf, "out_posx");
        if (str != NULL) {
                str = index(buf, '=');
                if (str != NULL) {
                        str++;
                        if (*str != '\0') {
                                t->output.crop.pos.x = strtol(str, NULL, 10);
                                printf("out_posx\t= %d\n", t->output.crop.pos.x);
                        }
                        return 0;
                }
        }

        str = strstr(buf, "out_posy");
        if (str != NULL) {
                str = index(buf, '=');
                if (str != NULL) {
                        str++;
                        if (*str != '\0') {
                                t->output.crop.pos.y = strtol(str, NULL, 10);
                                printf("out_posy\t= %d\n", t->output.crop.pos.y);
                        }
                        return 0;
                }
        }

        str = strstr(buf, "out_crop_w");
        if (str != NULL) {
                str = index(buf, '=');
                if (str != NULL) {
                        str++;
                        if (*str != '\0') {
                                t->output.crop.w =
                                        strtol(str, NULL, 10);
                                printf("out_crop_w\t= %d\n",
                                        t->output.crop.w);
                        }
                        return 0;
                }
        }

        str = strstr(buf, "out_crop_h");
        if (str != NULL) {
                str = index(buf, '=');
                if (str != NULL) {
                        str++;
                        if (*str != '\0') {
                                t->output.crop.h =
                                        strtol(str, NULL, 10);
                                printf("out_crop_h\t= %d\n",
                                        t->output.crop.h);
                        }
                        return 0;
                }
        }

        str = strstr(buf, "out_to_fb");
        if (str != NULL) {
                str = index(buf, '=');
                if (str != NULL) {
                        str++;
                        if (*str != '\0') {
                                test_handle->show_to_fb = strtol(str, NULL, 10);
                                printf("out_to_fb\t= %d\n", test_handle->show_to_fb);
                        }
                        return 0;
                }
        }

        str = strstr(buf, "out_filename");
        if (str != NULL) {
                str = index(buf, '=');
                if (str != NULL) {
                        str++;
                        if (*str != '\0') {
                                memcpy(test_handle->outfile, str, strlen(str));
                                printf("out_filename\t= %s\n", test_handle->outfile);
                        }
                        return 0;
                }
        }

        return 0;
}
예제 #20
0
int main (int argc, char *argv[])
{
	int file_in;
	size_t filesize;
	void * raw_image;
	struct ipu_task task;
	struct timeval begin, end;
	struct fb_var_screeninfo fb_var;
	struct fb_fix_screeninfo fb_fix;
	dma_addr_t outpaddr;

	int sec, usec, run_time;
	int fd_ipu, fd_fb, isize, osize;
	int ret, i;
 
	void *inbuf = NULL;
	void *outbuf = NULL;

	// Clear &task	
	memset(&task, 0, sizeof(task));

	// Input image size and format
	task.input.width    = 320;
	task.input.height   = 240;
 
	// Output image size and format
	task.output.width   = 1024;
	task.output.height  = 768;
	task.output.format  = v4l2_fourcc('R', 'G', 'B', 'P');
	task.output.rotate = 1;

	// Open IPU device
	fd_ipu = open("/dev/mxc_ipu", O_RDWR, 0);
	if (fd_ipu < 0) {
		printf("open ipu dev fail\n");
		ret = -1;
		goto done;
	}

	// Open Framebuffer and gets its address
	if ((fd_fb = open("/dev/fb0", O_RDWR, 0)) < 0) {
		printf("Unable to open /dev/fb0\n");
		ret = -1;
		goto done;
	}

	// Unblank the display
	ioctl(fd_fb, FBIOBLANK, FB_BLANK_UNBLANK);

	if ( ioctl(fd_fb, FBIOGET_FSCREENINFO, &fb_fix) < 0) {
		printf("Get FB fix info failed!\n");
		ret = -1;
		goto done;
	}

	ioctl(fd_fb, FBIOGET_FSCREENINFO, &fb_fix);

	// Set IPU output address as framebuffer address
	outpaddr = fb_fix.smem_start;	
	task.output.paddr = outpaddr;

	// Create memory map for output image
	outbuf = mmap(0, osize, PROT_READ | PROT_WRITE,
	MAP_SHARED, fd_ipu, task.output.paddr);
	if (!outbuf) {
		printf("mmap fail\n");
		ret = -1;
		goto done;
	}

	// Open the raw image
	if ((file_in = open("../../../images/stefan_interlaced_320x240_1frame.yv12", O_RDWR, 0)) < 0) {
		printf("Unable to open file\n");
		ret = -1;
		goto done;
	}
	printf("\nOpening image file\n");
	
	filesize = lseek(file_in, 0, SEEK_END);
	raw_image = mmap(0, filesize, PROT_READ, MAP_SHARED, file_in, 0);

	// Setting the input image format
	task.input.format = v4l2_fourcc('N', 'V', '1', '2');

	// Calculate input size from image dimensions and bits-per-pixel
	// according to format
	isize = task.input.paddr =
		task.input.width * task.input.height
		* fmt_to_bpp(task.input.format)/8;

	// Allocate contingous physical memory for input image
	// input.paddr contains the amount needed
	// this value will be replaced with physical address on success
	ret = ioctl(fd_ipu, IPU_ALLOC, &task.input.paddr);
	if (ret < 0) {
		printf("ioctl IPU_ALLOC fail: (errno = %d)\n", errno);
		goto done;
	}

	// Create memory map and obtain the allocated memory virtual address
	inbuf = mmap(0, isize, PROT_READ | PROT_WRITE,
		MAP_SHARED, fd_ipu, task.input.paddr);
	if (!inbuf) {
		printf("mmap fail\n");
		ret = -1;
		goto done;
	}

	//Copy the raw image to the IPU buffer
	memcpy(inbuf, raw_image, isize);

	for (i=0; i < 10 ; i++) {

		task.input.deinterlace.enable = i & 0x1;

		gettimeofday(&begin, NULL);
	
		// Perform deinterlace 
		ret = ioctl(fd_ipu, IPU_QUEUE_TASK, &task);

		gettimeofday(&end, NULL);

		if (ret < 0) {
			printf("ioct IPU_QUEUE_TASK fail %x\n", ret);
			goto done;
		}

		sec = end.tv_sec - begin.tv_sec;
		usec = end.tv_usec - begin.tv_usec;
		if (usec < 0) {
			sec--;
			usec = usec + 1000000;
		}
		run_time = (sec * 1000000) + usec;

	 	printf("Color Space Conversion time: %d usecs\n", run_time);
		sleep(2);
	}

done:
	if (file_in)
		close(file_in);
	if (outbuf)
		munmap(outbuf, osize);
	if (task.output.paddr)
		ioctl(fd_ipu, IPU_FREE, &task.output.paddr);
	if (inbuf)
		munmap(inbuf, isize);
	if (task.input.paddr)
		ioctl(fd_ipu, IPU_FREE, &task.input.paddr);
	if (fd_ipu)
		close(fd_ipu);
	if (fd_fb)
		close(fd_fb);

	return ret;
}
예제 #21
0
status_t TVINDevice::setDeviceConfig(int         width,
                                        int         height,
                                        PixelFormat format,
                                        int         fps)
{
    if (mCameraHandle <= 0) {
        FLOGE("setDeviceConfig: DeviceAdapter uninitialized");
        return BAD_VALUE;
    }
    if ((width == 0) || (height == 0)) {
        FLOGE("setDeviceConfig: invalid parameters");
        return BAD_VALUE;
    }

    status_t ret = NO_ERROR;
    int input    = 1;
    ret = ioctl(mCameraHandle, VIDIOC_S_INPUT, &input);
    if (ret < 0) {
        FLOGE("Open: VIDIOC_S_INPUT Failed: %s", strerror(errno));
        return ret;
    }

    int vformat;
    vformat = convertPixelFormatToV4L2Format(format);

    FLOGI("Width * Height %d x %d format %d, fps: %d",
          width,
          height,
          vformat,
          fps);

    mVideoInfo->width       = width;
    mVideoInfo->height      = height;
    mVideoInfo->framesizeIn = (width * height << 1);
    mVideoInfo->formatIn    = vformat;

    mVideoInfo->param.type =
        V4L2_BUF_TYPE_VIDEO_CAPTURE;
    mVideoInfo->param.parm.capture.timeperframe.numerator   = 1;
    mVideoInfo->param.parm.capture.timeperframe.denominator = 0;
    mVideoInfo->param.parm.capture.capturemode = 0;
    ret = ioctl(mCameraHandle, VIDIOC_S_PARM, &mVideoInfo->param);
    if (ret < 0) {
        FLOGE("Open: VIDIOC_S_PARM Failed: %s", strerror(errno));
        return ret;
    }

    mVideoInfo->format.type                 = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    mVideoInfo->format.fmt.pix.width        = width & 0xFFFFFFF8;
    mVideoInfo->format.fmt.pix.height       = height & 0xFFFFFFF8;
    mVideoInfo->format.fmt.pix.pixelformat  = vformat;
    mVideoInfo->format.fmt.pix.field        = V4L2_FIELD_INTERLACED;
    mVideoInfo->format.fmt.pix.priv         = 0;
    mVideoInfo->format.fmt.pix.sizeimage    = 0;
    mVideoInfo->format.fmt.pix.bytesperline = 0;

    // Special stride alignment for YU12
    if (vformat == v4l2_fourcc('Y', 'U', '1', '2')){
        // Goolge define the the stride and c_stride for YUV420 format
        // y_size = stride * height
        // c_stride = ALIGN(stride/2, 16)
        // c_size = c_stride * height/2
        // size = y_size + c_size * 2
        // cr_offset = y_size
        // cb_offset = y_size + c_size
        // int stride = (width+15)/16*16;
        // int c_stride = (stride/2+16)/16*16;
        // y_size = stride * height
        // c_stride = ALIGN(stride/2, 16)
        // c_size = c_stride * height/2
        // size = y_size + c_size * 2
        // cr_offset = y_size
        // cb_offset = y_size + c_size

        // GPU and IPU take below stride calculation
        // GPU has the Y stride to be 32 alignment, and UV stride to be
        // 16 alignment.
        // IPU have the Y stride to be 2x of the UV stride alignment
        int stride = (width+31)/32*32;
        int c_stride = (stride/2+15)/16*16;
        mVideoInfo->format.fmt.pix.bytesperline = stride;
        mVideoInfo->format.fmt.pix.sizeimage    = stride*height+c_stride * height;
        FLOGI("Special handling for YV12 on Stride %d, size %d",
            mVideoInfo->format.fmt.pix.bytesperline,
            mVideoInfo->format.fmt.pix.sizeimage);
    }

    ret = ioctl(mCameraHandle, VIDIOC_S_FMT, &mVideoInfo->format);
    if (ret < 0) {
        FLOGE("Open: VIDIOC_S_FMT Failed: %s", strerror(errno));
        return ret;
    }

    return ret;
}