diff options
author | Jordan Crouse <jordan.crouse@amd.com> | 2008-03-11 16:21:58 -0600 |
---|---|---|
committer | Jordan Crouse <jordan.crouse@amd.com> | 2008-03-14 14:16:42 -0600 |
commit | 1fd63467e3fa71f289f80dba013046d0065ff3f3 (patch) | |
tree | 7fb9b02c9c387818ece447b82ad2d183d423cd15 /src/z4l.c | |
parent | ec8edd1393f482ca42b401463f0f09580aa263a0 (diff) |
Massive coding style fixup - move to X coding style,
remove trailing whitespace, zap unused files and
remove blocks of ifdefed out code.
Diffstat (limited to 'src/z4l.c')
-rw-r--r-- | src/z4l.c | 1184 |
1 files changed, 592 insertions, 592 deletions
@@ -185,7 +185,7 @@ IoCtl(int fd, unsigned int fn, void *arg, int flag) errno = 0; ret = ioctl(fd, fn, arg); if (ret != 0 && flag != 0) - DBLOG(0, "ioctl(%08x)=%d\n", fn, ret); + DBLOG(0, "ioctl(%08x)=%d\n", fn, ret); return ret; } @@ -197,15 +197,15 @@ z4l_ovly_unmap(Z4lPortPrivRec * pPriv) nbfrs = pPriv->nbfrs; for (i = 0; i < nbfrs; ++i) { - if (pPriv->bfrs[i].start != NULL) { - munmap(pPriv->bfrs[i].start, pPriv->bfrs[i].length); - pPriv->bfrs[i].start = NULL; - } + if (pPriv->bfrs[i].start != NULL) { + munmap(pPriv->bfrs[i].start, pPriv->bfrs[i].length); + pPriv->bfrs[i].start = NULL; + } } #else if (pPriv->bfrs[0].start != NULL) { - munmap((void *)pPriv->bfrs[0].start, pPriv->bufsz); - pPriv->bfrs[0].start = NULL; + munmap((void *)pPriv->bfrs[0].start, pPriv->bufsz); + pPriv->bfrs[0].start = NULL; } #endif pPriv->nbfrs = -1; @@ -221,10 +221,10 @@ z4l_ovly_map(Z4lPortPrivRec * pPriv, int dir) struct v4l2_buffer bfr; struct v4l2_requestbuffers req; int type = dir >= 0 ? - V4L2_BUF_TYPE_VIDEO_CAPTURE : V4L2_BUF_TYPE_VIDEO_OVERLAY; + V4L2_BUF_TYPE_VIDEO_CAPTURE : V4L2_BUF_TYPE_VIDEO_OVERLAY; if (pPriv->run > 0) { - DBLOG(1, "busy\n"); - return; + DBLOG(1, "busy\n"); + return; } fd = pPriv->fd; memset(&req, 0, sizeof(req)); @@ -232,62 +232,62 @@ z4l_ovly_map(Z4lPortPrivRec * pPriv, int dir) req.memory = V4L2_MEMORY_MMAP; req.count = MAX_BUFFERS; if (ioctl(fd, VIDIOC_REQBUFS, &req) < 0) - goto xit; + goto xit; pPriv->nbfrs = req.count; if (pPriv->nbfrs <= 0) { - DBLOG(1, "no vidmem\n"); - return; + DBLOG(1, "no vidmem\n"); + return; } memset(&pPriv->bfrs, 0, sizeof(pPriv->bfrs)); for (i = 0; i < pPriv->nbfrs; ++i) { - memset(&bfr, 0, sizeof(bfr)); - bfr.type = type; - bfr.index = i; - if (ioctl(fd, VIDIOC_QUERYBUF, &bfr) < 0) - goto xit; - offset = bfr.m.offset; - pPriv->bfrs[i].offset = offset; - pPriv->bfrs[i].length = bfr.length; - bsz = offset + bfr.length; - if (pPriv->bufsz < bsz) - pPriv->bufsz = bsz; + memset(&bfr, 0, sizeof(bfr)); + bfr.type = type; + bfr.index = i; + if (ioctl(fd, VIDIOC_QUERYBUF, &bfr) < 0) + goto xit; + offset = bfr.m.offset; + pPriv->bfrs[i].offset = offset; + pPriv->bfrs[i].length = bfr.length; + bsz = offset + bfr.length; + if (pPriv->bufsz < bsz) + pPriv->bufsz = bsz; } #ifdef LINUX_2_6 for (i = 0; i < pPriv->nbfrs; ++i) { - pPriv->bfrs[i].start = mmap(NULL, bfr.length, PROT_READ | PROT_WRITE, - MAP_SHARED, fd, pPriv->bfrs[i].offset); - if (pPriv->bfrs[i].start == MAP_FAILED) - goto xit; + pPriv->bfrs[i].start = mmap(NULL, bfr.length, PROT_READ | PROT_WRITE, + MAP_SHARED, fd, pPriv->bfrs[i].offset); + if (pPriv->bfrs[i].start == MAP_FAILED) + goto xit; } #else pPriv->bfrs[0].offset = 0; pPriv->bfrs[0].start = - mmap(NULL, pPriv->bufsz, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + mmap(NULL, pPriv->bufsz, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (pPriv->bfrs[0].start == MAP_FAILED) { - pPriv->bfrs[0].start = NULL; - goto xit; + pPriv->bfrs[0].start = NULL; + goto xit; } offset = (unsigned long)pPriv->bfrs[0].start; for (i = 1; i < pPriv->nbfrs; ++i) - pPriv->bfrs[i].start = (void *)(offset + pPriv->bfrs[i].offset); + pPriv->bfrs[i].start = (void *)(offset + pPriv->bfrs[i].offset); #endif for (i = 0; i < pPriv->nbfrs; ++i) { - DBLOG(3, "bfr %d ofs %#lx adr %p sz %lu\n", i, pPriv->bfrs[i].offset, - pPriv->bfrs[i].start, (unsigned long)pPriv->bfrs[i].length); - memset(pPriv->bfrs[i].start, 0x80, pPriv->bfrs[i].length); + DBLOG(3, "bfr %d ofs %#lx adr %p sz %lu\n", i, pPriv->bfrs[i].offset, + pPriv->bfrs[i].start, (unsigned long)pPriv->bfrs[i].length); + memset(pPriv->bfrs[i].start, 0x80, pPriv->bfrs[i].length); } pPriv->last = 0; while (pPriv->last < pPriv->nbfrs - 1) { - bfr.index = pPriv->last++; - bfr.type = type; - if (ioctl(fd, VIDIOC_QBUF, &bfr) < 0) - goto xit; + bfr.index = pPriv->last++; + bfr.type = type; + if (ioctl(fd, VIDIOC_QBUF, &bfr) < 0) + goto xit; } return; @@ -311,7 +311,7 @@ z4l_ovly_dqbuf(Z4lPortPrivRec * pPriv) tmo.tv_sec = 0; tmo.tv_usec = 0; if (select(fd + 1, &dqset, NULL, NULL, &tmo) <= 0) - return -1; + return -1; #endif memset(&bfr, 0, sizeof(bfr)); bfr.type = V4L2_BUF_TYPE_VIDEO_OVERLAY; @@ -327,15 +327,15 @@ z4l_open_device(Z4lPortPrivRec * pPriv) int enable; if (pPriv->fd < 0) { - pPriv->fd = open(&pPriv->dev_path[0], O_RDWR, 0); - DBLOG(1, "open(%s)=%d\n", &pPriv->dev_path[0], pPriv->fd); - enable = 1; + pPriv->fd = open(&pPriv->dev_path[0], O_RDWR, 0); + DBLOG(1, "open(%s)=%d\n", &pPriv->dev_path[0], pPriv->fd); + enable = 1; #ifdef NONBLK_IO - if (IoCtl(pPriv->fd, FIONBIO, &enable, 1) != 0) { - DBLOG(1, "open cant enable nonblocking\n"); - close(pPriv->fd); - pPriv->fd = -1; - } + if (IoCtl(pPriv->fd, FIONBIO, &enable, 1) != 0) { + DBLOG(1, "open cant enable nonblocking\n"); + close(pPriv->fd); + pPriv->fd = -1; + } #endif } return pPriv->fd; @@ -347,13 +347,13 @@ z4l_close_device(Z4lPortPrivRec * pPriv) int ret = 0; if (pPriv->fd >= 0) { - ret = close(pPriv->fd); - pPriv->fd = -1; - DBLOG(1, "close()=%d\n", ret); + ret = close(pPriv->fd); + pPriv->fd = -1; + DBLOG(1, "close()=%d\n", ret); } if (pPriv->run > 0) { - z4l_ovly_unmap(pPriv); - pPriv->run = -1; + z4l_ovly_unmap(pPriv); + pPriv->run = -1; } return ret; @@ -365,8 +365,8 @@ z4l_ovly_reset(Z4lPortPrivRec * pPriv) int ret = 0; if (pPriv->run > 0) { - z4l_close_device(pPriv); - ret = z4l_open_device(pPriv); + z4l_close_device(pPriv); + ret = z4l_open_device(pPriv); } return ret; @@ -379,18 +379,18 @@ z4l_fourcc_pixfmt(int fourcc) switch (fourcc) { case FOURCC_UYVY: - pixfmt = V4L2_PIX_FMT_UYVY; - break; + pixfmt = V4L2_PIX_FMT_UYVY; + break; case FOURCC_YV12: - pixfmt = V4L2_PIX_FMT_YVU420; - break; + pixfmt = V4L2_PIX_FMT_YVU420; + break; case FOURCC_Y800: case FOURCC_I420: - pixfmt = V4L2_PIX_FMT_YUV420; - break; + pixfmt = V4L2_PIX_FMT_YUV420; + break; case FOURCC_YUY2: - pixfmt = V4L2_PIX_FMT_YUYV; - break; + pixfmt = V4L2_PIX_FMT_YUYV; + break; } return pixfmt; @@ -442,60 +442,60 @@ z4l_ovly_rect(Z4lPortPrivRec * pPriv, pPriv->drw_h = drw_h; if ((drw_x -= z4l_x_offset) < 0) { - if ((w = pPriv->drw_w) <= 0) - w = 1; - x = -drw_x; - dx = x * pPriv->src_w / w; - src_x = pPriv->src_x + dx; - src_w = pPriv->src_w - dx; - drw_w = pPriv->drw_w - x; - drw_x = 0; + if ((w = pPriv->drw_w) <= 0) + w = 1; + x = -drw_x; + dx = x * pPriv->src_w / w; + src_x = pPriv->src_x + dx; + src_w = pPriv->src_w - dx; + drw_w = pPriv->drw_w - x; + drw_x = 0; } if ((drw_y -= z4l_y_offset) < 0) { - if ((h = pPriv->drw_h) <= 0) - h = 1; - y = -drw_y; - dy = y * pPriv->src_h / h; - src_y = pPriv->src_y + dy; - src_h = pPriv->src_h - dy; - drw_h = pPriv->drw_h - y; - drw_y = 0; + if ((h = pPriv->drw_h) <= 0) + h = 1; + y = -drw_y; + dy = y * pPriv->src_h / h; + src_y = pPriv->src_y + dy; + src_h = pPriv->src_h - dy; + drw_h = pPriv->drw_h - y; + drw_y = 0; } memset(&fmt, 0, sizeof(fmt)); fmt.type = 0x100; IoCtl(pPriv->fd, VIDIOC_G_FMT, &fmt, 1); if (pPriv->src_is_set != 0) { - if (src_x != fmt.fmt.win.w.left || src_y != fmt.fmt.win.w.top || - src_w != fmt.fmt.win.w.width || src_h != fmt.fmt.win.w.height) - pPriv->src_is_set = 0; + if (src_x != fmt.fmt.win.w.left || src_y != fmt.fmt.win.w.top || + src_w != fmt.fmt.win.w.width || src_h != fmt.fmt.win.w.height) + pPriv->src_is_set = 0; } if (pPriv->src_is_set == 0) { - pPriv->src_is_set = 1; - fmt.fmt.win.w.left = src_x; - fmt.fmt.win.w.top = src_y; - fmt.fmt.win.w.width = src_w; - fmt.fmt.win.w.height = src_h; - IoCtl(pPriv->fd, VIDIOC_S_FMT, &fmt, 1); - DBLOG(3, " set src %d,%d %dx%d\n", src_x, src_y, src_w, src_h); + pPriv->src_is_set = 1; + fmt.fmt.win.w.left = src_x; + fmt.fmt.win.w.top = src_y; + fmt.fmt.win.w.width = src_w; + fmt.fmt.win.w.height = src_h; + IoCtl(pPriv->fd, VIDIOC_S_FMT, &fmt, 1); + DBLOG(3, " set src %d,%d %dx%d\n", src_x, src_y, src_w, src_h); } memset(&fmt, 0, sizeof(fmt)); fmt.type = 0x101; IoCtl(pPriv->fd, VIDIOC_G_FMT, &fmt, 1); if (pPriv->drw_is_set != 0) { - if (drw_x != fmt.fmt.win.w.left || drw_y != fmt.fmt.win.w.top || - drw_w != fmt.fmt.win.w.width || drw_h != fmt.fmt.win.w.height) - pPriv->drw_is_set = 0; + if (drw_x != fmt.fmt.win.w.left || drw_y != fmt.fmt.win.w.top || + drw_w != fmt.fmt.win.w.width || drw_h != fmt.fmt.win.w.height) + pPriv->drw_is_set = 0; } if (pPriv->drw_is_set == 0) { - pPriv->drw_is_set = 1; - fmt.fmt.win.w.left = drw_x; - fmt.fmt.win.w.top = drw_y; - fmt.fmt.win.w.width = drw_w; - fmt.fmt.win.w.height = drw_h; - IoCtl(pPriv->fd, VIDIOC_S_FMT, &fmt, 1); - DBLOG(3, " set drw %d,%d %dx%d\n", drw_x, drw_y, drw_w, drw_h); + pPriv->drw_is_set = 1; + fmt.fmt.win.w.left = drw_x; + fmt.fmt.win.w.top = drw_y; + fmt.fmt.win.w.width = drw_w; + fmt.fmt.win.w.height = drw_h; + IoCtl(pPriv->fd, VIDIOC_S_FMT, &fmt, 1); + DBLOG(3, " set drw %d,%d %dx%d\n", drw_x, drw_y, drw_w, drw_h); } } @@ -510,22 +510,22 @@ z4l_ovly_pitch(unsigned int pixfmt, int w, int h, int *py_pitch, switch (pixfmt) { case V4L2_PIX_FMT_YVU420: case V4L2_PIX_FMT_YUV420: - is_420 = 1; - y_pitch = ((w + 1) / 2) * 2; - uv_pitch = (w + 1) / 2; - break; + is_420 = 1; + y_pitch = ((w + 1) / 2) * 2; + uv_pitch = (w + 1) / 2; + break; default: - is_420 = 0; - y_pitch = ((w + 1) / 2) * 4; - uv_pitch = 0; - break; + is_420 = 0; + y_pitch = ((w + 1) / 2) * 4; + uv_pitch = 0; + break; } offset1 = y_pitch * h; offset2 = uv_pitch * h; if (is_420 != 0) - offset2 /= 2; + offset2 /= 2; size = offset1 + 2 * offset2; *py_pitch = y_pitch; @@ -543,10 +543,10 @@ z4l_ovly_set_colorkey(Z4lPortPrivRec * pPriv, int key) memset(&fmt, 0, sizeof(fmt)); fmt.type = V4L2_BUF_TYPE_VIDEO_OVERLAY; if (IoCtl(pPriv->fd, VIDIOC_G_FMT, &fmt, 1) < 0) - return 0; + return 0; fmt.fmt.win.chromakey = key; if (IoCtl(pPriv->fd, VIDIOC_S_FMT, &fmt, 1) < 0) - return 0; + return 0; pPriv->colorkey = key; return 1; @@ -560,7 +560,7 @@ z4l_ovly_get_colorkey(Z4lPortPrivRec * pPriv, int *key) memset(&fmt, 0, sizeof(fmt)); fmt.type = V4L2_BUF_TYPE_VIDEO_OVERLAY; if (IoCtl(pPriv->fd, VIDIOC_G_FMT, &fmt, 1) < 0) - return 0; + return 0; *key = fmt.fmt.win.chromakey; return 1; @@ -573,16 +573,16 @@ z4l_ovly_set_keymode(Z4lPortPrivRec * pPriv, int enable) memset(&fbuf, 0, sizeof(fbuf)); if (IoCtl(pPriv->fd, VIDIOC_G_FBUF, &fbuf, 1) < 0) - return 0; + return 0; if (enable != 0) - fbuf.flags |= V4L2_FBUF_FLAG_CHROMAKEY; + fbuf.flags |= V4L2_FBUF_FLAG_CHROMAKEY; else - fbuf.flags &= ~V4L2_FBUF_FLAG_CHROMAKEY; + fbuf.flags &= ~V4L2_FBUF_FLAG_CHROMAKEY; fbuf.base = NULL; if (IoCtl(pPriv->fd, VIDIOC_S_FBUF, &fbuf, 1) < 0) - return 0; + return 0; pPriv->keymode = enable; return 1; @@ -595,7 +595,7 @@ z4l_ovly_get_keymode(Z4lPortPrivRec * pPriv, int *enable) memset(&fbuf, 0, sizeof(fbuf)); if (IoCtl(pPriv->fd, VIDIOC_G_FBUF, &fbuf, 1) < 0) - return 0; + return 0; *enable = (fbuf.flags & V4L2_FBUF_FLAG_CHROMAKEY) != 0 ? 1 : 0; return 1; @@ -616,7 +616,7 @@ z4l_ovly_set_encoding(Z4lPortPrivRec * pPriv, int id) adpt = pPriv->adpt; DBLOG(1, "z4l_ovly_set_encoding(%d)\n", id); if (id < 0 || id >= adpt->nEncodings) - return 0; + return 0; enc = &adpt->pEncodings[id]; cp = &enc->name[0]; n = sizeof(int) - 1; @@ -626,32 +626,32 @@ z4l_ovly_set_encoding(Z4lPortPrivRec * pPriv, int id) inp = sp->inp; DBLOG(1, " nm %s fmt %4.4s inp %d std %llx\n", - cp, (char *)&sp->fmt, sp->inp, sp->std); + cp, (char *)&sp->fmt, sp->inp, sp->std); if (IoCtl(pPriv->fd, VIDIOC_S_INPUT, &inp, 1) < 0) - return 0; + return 0; std = sp->std; if (IoCtl(pPriv->fd, VIDIOC_S_STD, &std, 1) < 0) - return 0; + return 0; memset(&fmt, 0, sizeof(fmt)); fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; if (IoCtl(pPriv->fd, VIDIOC_G_FMT, &fmt, 1) < 0) - return 0; + return 0; fmt.fmt.pix.pixelformat = sp->fmt; if (IoCtl(pPriv->fd, VIDIOC_S_FMT, &fmt, 1) < 0) - return 0; + return 0; memset(&fbuf, 0, sizeof(fbuf)); if (IoCtl(pPriv->fd, VIDIOC_G_FBUF, &fbuf, 1) < 0) - return 0; + return 0; fbuf.fmt.pixelformat = sp->fmt; fbuf.base = NULL; if (IoCtl(pPriv->fd, VIDIOC_S_FBUF, &fbuf, 1) < 0) - return 0; + return 0; pPriv->pixfmt = sp->fmt; pPriv->enc = enc; pPriv->src_is_set = pPriv->drw_is_set = 0; @@ -674,21 +674,21 @@ z4l_ovly_stop(Z4lPortPrivRec * pPriv) int type, enable, fd; if (pPriv->run < 0) - return; + return; fd = pPriv->fd; if (pPriv->dir > 0) { - type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - ioctl(fd, VIDIOC_STREAMOFF, &type); + type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + ioctl(fd, VIDIOC_STREAMOFF, &type); } if (pPriv->dir <= 0) { - enable = 0; - ioctl(fd, VIDIOC_OVERLAY, &enable); + enable = 0; + ioctl(fd, VIDIOC_OVERLAY, &enable); } if (pPriv->dir != 0) - z4l_ovly_unmap(pPriv); + z4l_ovly_unmap(pPriv); pPriv->run = -1; z4l_close_device(pPriv); @@ -700,16 +700,16 @@ z4l_ovly_start(Z4lPortPrivRec * pPriv, int dir) int enable; if (pPriv->run >= 0) - return; + return; if ((pPriv->dir = dir) != 0) - z4l_ovly_map(pPriv, dir); + z4l_ovly_map(pPriv, dir); enable = 1; if (IoCtl(pPriv->fd, VIDIOC_OVERLAY, &enable, 1) != 0) { - z4l_ovly_stop(pPriv); - return; + z4l_ovly_stop(pPriv); + return; } pPriv->run = 1; @@ -722,26 +722,26 @@ z4l_region_equal(RegionPtr ap, RegionPtr bp) BoxPtr abox, bbox; if (ap == NULL && bp == NULL) - return 1; + return 1; if (ap == NULL || bp == NULL) - return 0; + return 0; if ((nboxes = REGION_NUM_RECTS(ap)) != REGION_NUM_RECTS(bp) || - ap->extents.x1 != bp->extents.x1 || - ap->extents.x2 != bp->extents.x2 - || ap->extents.y1 != bp->extents.y1 - || ap->extents.y2 != bp->extents.y2) - return 0; + ap->extents.x1 != bp->extents.x1 || + ap->extents.x2 != bp->extents.x2 + || ap->extents.y1 != bp->extents.y1 + || ap->extents.y2 != bp->extents.y2) + return 0; abox = REGION_RECTS(ap); bbox = REGION_RECTS(bp); while (--nboxes >= 0) { - if (abox->x1 != bbox->x1 || abox->y1 != bbox->y1 || - abox->x2 != bbox->x2 || abox->y2 != bbox->y2) - return 0; - ++abox; - ++bbox; + if (abox->x1 != bbox->x1 || abox->y1 != bbox->y1 || + abox->x2 != bbox->x2 || abox->y2 != bbox->y2) + return 0; + ++abox; + ++bbox; } return 1; @@ -752,9 +752,9 @@ z4l_setup_colorkey(Z4lPortPrivRec * pPriv, ScreenPtr pScrn, RegionPtr clipBoxes) { if (pPriv->run > 0 && pPriv->dir <= 0 && pPriv->keymode != 0 && - z4l_region_equal(&pPriv->clips, clipBoxes) == 0) { - xf86XVFillKeyHelper(pScrn, pPriv->colorkey, clipBoxes); - REGION_COPY(pScrn, &pPriv->clips, clipBoxes); + z4l_region_equal(&pPriv->clips, clipBoxes) == 0) { + xf86XVFillKeyHelper(pScrn, pPriv->colorkey, clipBoxes); + REGION_COPY(pScrn, &pPriv->clips, clipBoxes); } } @@ -766,9 +766,9 @@ Z4lStopVideo(ScrnInfoPtr pScrni, pointer data, Bool exit) DBLOG(1, "Z4lStopVideo()\n"); if (exit != 0) - z4l_ovly_stop(pPriv); + z4l_ovly_stop(pPriv); else - pPriv->src_is_set = pPriv->drw_is_set = 0; + pPriv->src_is_set = pPriv->drw_is_set = 0; REGION_EMPTY(pScrni->pScreen, &pPriv->clips); } @@ -779,14 +779,14 @@ Z4lQueryBestSize(ScrnInfoPtr pScrni, Bool motion, unsigned int *p_w, unsigned int *p_h, pointer data) { if (drw_w > MAX_OVLY_WIDTH) - drw_w = MAX_OVLY_WIDTH; + drw_w = MAX_OVLY_WIDTH; if (drw_h > MAX_OVLY_HEIGHT) - drw_h = MAX_OVLY_HEIGHT; + drw_h = MAX_OVLY_HEIGHT; *p_w = drw_w; *p_h = drw_h; DBLOG(1, "Z4lQueryBestSize(%d, src %dx%d dst %dx%d)\n", motion, vid_w, - vid_h, drw_w, drw_h); + vid_h, drw_w, drw_h); } static int @@ -803,63 +803,63 @@ Z4lPutImage(ScrnInfoPtr pScrni, short src_x, short src_y, short drw_x, Z4lPortPrivRec *pPriv = (Z4lPortPrivRec *) data; if (pPriv->run > 0 && pPriv->dir >= 0) - return BadMatch; + return BadMatch; if (pPriv->fd < 0) { - z4l_open_device(pPriv); - if (pPriv->fd < 0) - return BadValue; + z4l_open_device(pPriv); + if (pPriv->fd < 0) + return BadValue; } fd = pPriv->fd; if (pPriv->run < 0) { - DBLOG(2, "PutImg id %#x src %d,%d %dx%d drw %d,%d %dx%d bfr %p " - "%dx%d data %p\n", id, src_x, src_y, src_w, src_h, drw_x, - drw_y, drw_w, drw_h, buf, width, height, data); - pPriv->pixfmt = pPriv->height = -1; - pPriv->src_is_set = pPriv->drw_is_set = 0; + DBLOG(2, "PutImg id %#x src %d,%d %dx%d drw %d,%d %dx%d bfr %p " + "%dx%d data %p\n", id, src_x, src_y, src_w, src_h, drw_x, + drw_y, drw_w, drw_h, buf, width, height, data); + pPriv->pixfmt = pPriv->height = -1; + pPriv->src_is_set = pPriv->drw_is_set = 0; } pixfmt = z4l_fourcc_pixfmt(id); if (pixfmt != pPriv->pixfmt) { - z4l_ovly_reset(pPriv); - z4l_ovly_pixfmt(pPriv, pixfmt); + z4l_ovly_reset(pPriv); + z4l_ovly_pixfmt(pPriv, pixfmt); } if (pPriv->width != width || pPriv->height != height) { - z4l_ovly_reset(pPriv); - z4l_ovly_bfr(pPriv, width, height); + z4l_ovly_reset(pPriv); + z4l_ovly_bfr(pPriv, width, height); } if (pPriv->src_is_set == 0 || pPriv->drw_is_set == 0 || - pPriv->src_x != src_x || pPriv->src_y != src_y || - pPriv->src_w != src_w || pPriv->src_h != src_h || - pPriv->drw_x != drw_x || pPriv->drw_y != drw_y || - pPriv->drw_w != drw_w || pPriv->drw_h != drw_h) - z4l_ovly_rect(pPriv, src_x, src_y, src_w, src_h, drw_x, drw_y, drw_w, - drw_h); + pPriv->src_x != src_x || pPriv->src_y != src_y || + pPriv->src_w != src_w || pPriv->src_h != src_h || + pPriv->drw_x != drw_x || pPriv->drw_y != drw_y || + pPriv->drw_w != drw_w || pPriv->drw_h != drw_h) + z4l_ovly_rect(pPriv, src_x, src_y, src_w, src_h, drw_x, drw_y, drw_w, + drw_h); if (pPriv->run < 0) { - z4l_ovly_start(pPriv, -1); - if (pPriv->run < 0) - return BadValue; + z4l_ovly_start(pPriv, -1); + if (pPriv->run < 0) + return BadValue; } if (pPriv->last < 0 && (pPriv->last = z4l_ovly_dqbuf(pPriv)) < 0) - return BadAlloc; + return BadAlloc; z4l_ovly_pitch(pixfmt, width, height, &y_pitch, &uv_pitch, - &offset1, &offset2, &size); + &offset1, &offset2, &size); src = buf; dst = (unsigned char *)pPriv->bfrs[pPriv->last].start; DBLOG(3, "cpy %4.4s src %p dst %p yp %d uvp %d o1 %d o2 %d sz %d\n", - (char *)&id, src, dst, y_pitch, uv_pitch, offset1, offset2, size); + (char *)&id, src, dst, y_pitch, uv_pitch, offset1, offset2, size); if (id == FOURCC_Y800) { - memcpy(dst, src, offset1); - src += offset1; - dst += offset1; - memset(dst, 0x80, 2 * offset2); + memcpy(dst, src, offset1); + src += offset1; + dst += offset1; + memset(dst, 0x80, 2 * offset2); } else - memcpy(dst, src, size); + memcpy(dst, src, size); memset(&bfr, 0, sizeof(bfr)); bfr.type = V4L2_BUF_TYPE_VIDEO_OVERLAY; @@ -868,7 +868,7 @@ Z4lPutImage(ScrnInfoPtr pScrni, short src_x, short src_y, short drw_x, bfr.timestamp.tv_usec = 0; bfr.flags |= V4L2_BUF_FLAG_TIMECODE; if (IoCtl(fd, VIDIOC_QBUF, &bfr, 1) != 0) - return BadAccess; + return BadAccess; pPriv->last = z4l_ovly_dqbuf(pPriv); z4l_setup_colorkey(pPriv, pScrni->pScreen, clipBoxes); @@ -887,36 +887,36 @@ Z4lQueryImageAttributes(ScrnInfoPtr pScrni, int id, unsigned short *width, w = *width; h = *height; if (w > MAX_OVLY_WIDTH) - w = MAX_OVLY_WIDTH; + w = MAX_OVLY_WIDTH; if (h > MAX_OVLY_HEIGHT) - h = MAX_OVLY_HEIGHT; + h = MAX_OVLY_HEIGHT; z4l_ovly_pitch(pixfmt, w, h, &y_pitch, &uv_pitch, - &offset1, &offset2, &size); + &offset1, &offset2, &size); if (offsets != NULL) - offsets[0] = 0; + offsets[0] = 0; if (pitches != NULL) - pitches[0] = y_pitch; + pitches[0] = y_pitch; switch (pixfmt) { case V4L2_PIX_FMT_YVU420: case V4L2_PIX_FMT_YUV420: - if (offsets != NULL) { - offsets[1] = offset1; - offsets[2] = offset1 + offset2; - } - if (pitches != NULL) - pitches[1] = pitches[2] = uv_pitch; - h = (h + 1) & ~1; - break; + if (offsets != NULL) { + offsets[1] = offset1; + offsets[2] = offset1 + offset2; + } + if (pitches != NULL) + pitches[1] = pitches[2] = uv_pitch; + h = (h + 1) & ~1; + break; } w = (w + 1) & ~1; *width = w; *height = h; DBLOG(1, "Z4lQueryImageAttributes(%4.4s) = %d, %dx%d %d/%d %d/%d\n", - (char *)&id, size, w, h, y_pitch, uv_pitch, offset1, offset2); + (char *)&id, size, w, h, y_pitch, uv_pitch, offset1, offset2); return size; } @@ -930,27 +930,27 @@ Z4lPutVideo(ScrnInfoPtr pScrni, short src_x, short src_y, short drw_x, Z4lPortPrivRec *pPriv = (Z4lPortPrivRec *) data; DBLOG(2, "PutVid src %d,%d %dx%d drw %d,%d %dx%d data %p\n", - src_x, src_y, src_w, src_h, drw_x, drw_y, drw_w, drw_h, data); + src_x, src_y, src_w, src_h, drw_x, drw_y, drw_w, drw_h, data); if (z4l_open_device(pPriv) >= 0) { - if (pPriv->run < 0) { - DBLOG(2, "PutVid start\n"); - z4l_ovly_get_encoding(pPriv, &id); - z4l_ovly_set_encoding(pPriv, id); - } - DBLOG(2, "PutVid priv %d,%d %dx%d drw %d,%d %dx%d\n", - pPriv->src_x, pPriv->src_y, pPriv->src_w, pPriv->src_h, - pPriv->drw_x, pPriv->drw_y, pPriv->drw_w, pPriv->drw_h); - if (pPriv->src_is_set == 0 || pPriv->drw_is_set == 0 || - pPriv->src_w != src_w || pPriv->src_h != src_h || - pPriv->drw_x != drw_x || pPriv->drw_y != drw_y || - pPriv->drw_w != drw_w || pPriv->drw_h != drw_h) - z4l_ovly_rect(pPriv, src_x, src_y, src_w, src_h, drw_x, drw_y, - drw_w, drw_h); - if (pPriv->run < 0) - z4l_ovly_start(pPriv, 0); - - z4l_setup_colorkey(pPriv, pScrni->pScreen, clipBoxes); + if (pPriv->run < 0) { + DBLOG(2, "PutVid start\n"); + z4l_ovly_get_encoding(pPriv, &id); + z4l_ovly_set_encoding(pPriv, id); + } + DBLOG(2, "PutVid priv %d,%d %dx%d drw %d,%d %dx%d\n", + pPriv->src_x, pPriv->src_y, pPriv->src_w, pPriv->src_h, + pPriv->drw_x, pPriv->drw_y, pPriv->drw_w, pPriv->drw_h); + if (pPriv->src_is_set == 0 || pPriv->drw_is_set == 0 || + pPriv->src_w != src_w || pPriv->src_h != src_h || + pPriv->drw_x != drw_x || pPriv->drw_y != drw_y || + pPriv->drw_w != drw_w || pPriv->drw_h != drw_h) + z4l_ovly_rect(pPriv, src_x, src_y, src_w, src_h, drw_x, drw_y, + drw_w, drw_h); + if (pPriv->run < 0) + z4l_ovly_start(pPriv, 0); + + z4l_setup_colorkey(pPriv, pScrni->pScreen, clipBoxes); } return Success; @@ -961,10 +961,10 @@ Z4lNewEncoding(XF86VideoEncodingPtr * encs, int *nencs) { XF86VideoEncodingPtr enc; XF86VideoEncodingPtr tencs = - (XF86VideoEncodingPtr) xrealloc(*encs, sizeof(*tencs) * (*nencs + 1)); + (XF86VideoEncodingPtr) xrealloc(*encs, sizeof(*tencs) * (*nencs + 1)); if (tencs == NULL) - return NULL; + return NULL; *encs = tencs; enc = &tencs[*nencs]; @@ -980,38 +980,38 @@ Z4lEncodingName(char *ename, int l, char *inp_name, char *std_name, char *fmt) int i, ch; while ((ch = *inp_name++) != 0) { - if (isalnum(ch) == 0) - continue; - if (--l <= 0) - goto xit; - *ename++ = ch; + if (isalnum(ch) == 0) + continue; + if (--l <= 0) + goto xit; + *ename++ = ch; } if (--l <= 0) - goto xit; + goto xit; *ename++ = '-'; while ((ch = *std_name++) != 0) { - if (isalnum(ch) == 0) - continue; - if (--l <= 0) - goto xit; - *ename++ = ch; + if (isalnum(ch) == 0) + continue; + if (--l <= 0) + goto xit; + *ename++ = ch; } if (--l <= 0) - goto xit; + goto xit; *ename++ = '-'; i = 4; while (--i >= 0 && (ch = *fmt++) != 0) { - if (isalnum(ch) == 0) - continue; - if (--l <= 0) - goto xit; - *ename++ = ch; + if (isalnum(ch) == 0) + continue; + if (--l <= 0) + goto xit; + *ename++ = ch; } xit: @@ -1033,7 +1033,7 @@ Z4lAddEncoding(XF86VideoEncodingPtr enc, char *name, int id, int width, cp = (char *)xalloc(n); if (cp == NULL) - return 0; + return 0; sp = (t_std_data *) (cp + l); enc->id = id; @@ -1056,10 +1056,10 @@ Z4lNewImage(XF86ImagePtr * imgs, int *nimgs) { XF86ImagePtr img; XF86ImagePtr timgs = - (XF86ImagePtr) xrealloc(*imgs, sizeof(*timgs) * (*nimgs + 1)); + (XF86ImagePtr) xrealloc(*imgs, sizeof(*timgs) * (*nimgs + 1)); if (timgs == NULL) - return NULL; + return NULL; *imgs = timgs; img = &timgs[*nimgs]; @@ -1082,10 +1082,10 @@ Z4lNewAttribute(XF86AttributePtr * attrs, int *nattrs) { XF86AttributePtr attr; XF86AttributePtr tattrs = - (XF86AttributePtr) xrealloc(*attrs, sizeof(*tattrs) * (*nattrs + 1)); + (XF86AttributePtr) xrealloc(*attrs, sizeof(*tattrs) * (*nattrs + 1)); if (tattrs == NULL) - return NULL; + return NULL; *attrs = tattrs; attr = &tattrs[*nattrs]; @@ -1102,22 +1102,22 @@ Z4lAttributeName(char *bp, int l, char *cp) char *atomNm = bp; if (l > 0) { - *bp++ = 'X'; - --l; + *bp++ = 'X'; + --l; } if (l > 0) { - *bp++ = 'V'; - --l; + *bp++ = 'V'; + --l; } if (l > 0) { - *bp++ = '_'; - --l; + *bp++ = '_'; + --l; } while (l > 0 && (ch = *cp++) != 0) { - if (isalnum(ch) == 0) - continue; - *bp++ = toupper(ch); + if (isalnum(ch) == 0) + continue; + *bp++ = toupper(ch); } *bp = 0; @@ -1131,7 +1131,7 @@ Z4lAddAttribute(XF86AttributePtr attr, char *name, char *cp = (char *)xalloc(strlen((char *)&name[0]) + 1); if (cp == NULL) - return 0; + return 0; attr->name = cp; strcpy(&attr->name[0], name); @@ -1151,10 +1151,10 @@ Z4lNewAdaptor(XF86VideoAdaptorPtr ** adpts, int *nadpts, int nattrs) XF86VideoAdaptorPtr adpt, *tadpts; tadpts = (XF86VideoAdaptorPtr *) xrealloc(*adpts, - sizeof(*tadpts) * (*nadpts + 1)); + sizeof(*tadpts) * (*nadpts + 1)); if (tadpts == NULL) - return NULL; + return NULL; *adpts = tadpts; n = sizeof(*adpt) + sizeof(*pPriv) + 1 * sizeof(*adpt->pPortPrivates); @@ -1162,7 +1162,7 @@ Z4lNewAdaptor(XF86VideoAdaptorPtr ** adpts, int *nadpts, int nattrs) adpt = (XF86VideoAdaptorPtr) xalloc(n); if (adpt == NULL) - return NULL; + return NULL; memset(adpt, 0, n); tadpts[*nadpts] = adpt; @@ -1189,50 +1189,50 @@ Z4lSetPortAttribute(ScrnInfoPtr pScrni, Atom attribute, INT32 value, int old_fd = pPriv->fd; DBLOG(1, "Z4lSetPortAttribute(%#lx,%d) '%s'\n", (unsigned long)attribute, - (int)value, name != NULL ? name : "_null_"); + (int)value, name != NULL ? name : "_null_"); if (name == NULL) - return BadImplementation; + return BadImplementation; if (old_fd < 0 && z4l_open_device(pPriv) < 0) - return BadAccess; + return BadAccess; adpt = pPriv->adpt; attr = adpt->pAttributes; nattrs = adpt->nAttributes; for (i = 0; i < nattrs; ++i, ++attr) - if (strcmp(attr->name, name) == 0) - break; + if (strcmp(attr->name, name) == 0) + break; if (i >= nattrs) - return BadMatch; + return BadMatch; attrId = pPriv->attrIds[i]; val = value; switch (attrId) { case ATTR_ENCODING_ID: - z4l_ovly_set_encoding(pPriv, val); - break; + z4l_ovly_set_encoding(pPriv, val); + break; case ATTR_KEYMODE_ID: - z4l_ovly_set_keymode(pPriv, val); - REGION_EMPTY(pScrni->pScreen, &pPriv->clips); - z4l_setup_colorkey(pPriv, pScrni->pScreen, &pPriv->clips); - break; + z4l_ovly_set_keymode(pPriv, val); + REGION_EMPTY(pScrni->pScreen, &pPriv->clips); + z4l_setup_colorkey(pPriv, pScrni->pScreen, &pPriv->clips); + break; case ATTR_COLORKEY_ID: - z4l_ovly_set_colorkey(pPriv, val); - break; + z4l_ovly_set_colorkey(pPriv, val); + break; default: - memset(&ctrl, 0, sizeof(ctrl)); - ctrl.id = attrId + V4L2_CID_BASE; - ctrl.value = val; - if (IoCtl(pPriv->fd, VIDIOC_S_CTRL, &ctrl, 1) != 0) - return BadMatch; - break; + memset(&ctrl, 0, sizeof(ctrl)); + ctrl.id = attrId + V4L2_CID_BASE; + ctrl.value = val; + if (IoCtl(pPriv->fd, VIDIOC_S_CTRL, &ctrl, 1) != 0) + return BadMatch; + break; } if (old_fd < 0) - z4l_close_device(pPriv); + z4l_close_device(pPriv); return Success; } @@ -1250,50 +1250,50 @@ Z4lGetPortAttribute(ScrnInfoPtr pScrni, Atom attribute, INT32 * value, int old_fd = pPriv->fd; DBLOG(1, "Z4lGetPortAttribute(%#lx) '%s'\n", - (unsigned long)attribute, name != NULL ? name : "_null_"); + (unsigned long)attribute, name != NULL ? name : "_null_"); if (name == NULL) - return BadImplementation; + return BadImplementation; if (old_fd < 0 && z4l_open_device(pPriv) < 0) - return BadAccess; + return BadAccess; adpt = pPriv->adpt; attr = adpt->pAttributes; nattrs = adpt->nAttributes; for (i = 0; i < nattrs; ++i, ++attr) - if (strcmp(attr->name, name) == 0) - break; + if (strcmp(attr->name, name) == 0) + break; if (i >= nattrs) - return BadMatch; + return BadMatch; attrId = pPriv->attrIds[i]; val = 0; switch (attrId) { case ATTR_ENCODING_ID: - z4l_ovly_get_encoding(pPriv, &val); - *value = val; - break; + z4l_ovly_get_encoding(pPriv, &val); + *value = val; + break; case ATTR_KEYMODE_ID: - z4l_ovly_get_keymode(pPriv, &val); - *value = val; - break; + z4l_ovly_get_keymode(pPriv, &val); + *value = val; + break; case ATTR_COLORKEY_ID: - z4l_ovly_get_colorkey(pPriv, &val); - break; + z4l_ovly_get_colorkey(pPriv, &val); + break; default: - memset(&ctrl, 0, sizeof(ctrl)); - ctrl.id = attrId + V4L2_CID_BASE; - if (IoCtl(pPriv->fd, VIDIOC_G_CTRL, &ctrl, 1) != 0) - return BadMatch; - val = ctrl.value; - break; + memset(&ctrl, 0, sizeof(ctrl)); + ctrl.id = attrId + V4L2_CID_BASE; + if (IoCtl(pPriv->fd, VIDIOC_G_CTRL, &ctrl, 1) != 0) + return BadMatch; + val = ctrl.value; + break; } if (old_fd < 0) - z4l_close_device(pPriv); + z4l_close_device(pPriv); *value = val; @@ -1316,14 +1316,14 @@ Z4lAdjustFrame(int scrnIndex, int x, int y, int flags) /* xv adjust does not handle putvideo case */ for (i = 0; i < Z4l_nAdaptors; ++i) { - adpt = Z4l_pAdaptors[i]; - pPriv = (Z4lPortPrivRec *) adpt->pPortPrivates[0].ptr; - if (pPriv->run > 0) { - pPriv->drw_is_set = 0; - z4l_ovly_rect(pPriv, - pPriv->src_x, pPriv->src_y, pPriv->src_w, pPriv->src_h, - pPriv->drw_x, pPriv->drw_y, pPriv->drw_w, pPriv->drw_h); - } + adpt = Z4l_pAdaptors[i]; + pPriv = (Z4lPortPrivRec *) adpt->pPortPrivates[0].ptr; + if (pPriv->run > 0) { + pPriv->drw_is_set = 0; + z4l_ovly_rect(pPriv, + pPriv->src_x, pPriv->src_y, pPriv->src_w, pPriv->src_h, + pPriv->drw_x, pPriv->drw_y, pPriv->drw_w, pPriv->drw_h); + } } } @@ -1354,8 +1354,8 @@ Z4lInit(ScrnInfoPtr pScrni, XF86VideoAdaptorPtr ** adaptors) DBLOG(1, "Init\n"); if (oldAdjustFrame == NULL) { - oldAdjustFrame = pScrni->AdjustFrame; - pScrni->AdjustFrame = Z4lAdjustFrame; + oldAdjustFrame = pScrni->AdjustFrame; + pScrni->AdjustFrame = Z4lAdjustFrame; } fd = -1; @@ -1374,254 +1374,254 @@ Z4lInit(ScrnInfoPtr pScrni, XF86VideoAdaptorPtr ** adaptors) has_video = has_image = has_colorkey = 0; for (dev = 0; z4l_dev_paths[dev] != NULL; ++dev) { - fd = open(z4l_dev_paths[dev], O_RDWR, 0); - if (fd < 0) - continue; - DBLOG(1, "%s open ok\n", z4l_dev_paths[dev]); - msg = NULL; - enable = 1; - if (IoCtl(fd, VIDIOC_QUERYCAP, &capability, 1) < 0) - msg = "bad querycap"; - else if ((capability.capabilities & V4L2_CAP_VIDEO_OVERLAY) == 0) - msg = "no overlay"; - else if ((capability.capabilities & V4L2_CAP_STREAMING) == 0) - msg = "no streaming"; + fd = open(z4l_dev_paths[dev], O_RDWR, 0); + if (fd < 0) + continue; + DBLOG(1, "%s open ok\n", z4l_dev_paths[dev]); + msg = NULL; + enable = 1; + if (IoCtl(fd, VIDIOC_QUERYCAP, &capability, 1) < 0) + msg = "bad querycap"; + else if ((capability.capabilities & V4L2_CAP_VIDEO_OVERLAY) == 0) + msg = "no overlay"; + else if ((capability.capabilities & V4L2_CAP_STREAMING) == 0) + msg = "no streaming"; #ifdef NONBLK_IO - else if (IoCtl(fd, FIONBIO, &enable, 1) != 0) - msg = "cant enable non-blocking io"; + else if (IoCtl(fd, FIONBIO, &enable, 1) != 0) + msg = "cant enable non-blocking io"; #endif - if (msg == NULL) { - memset(&format, 0, sizeof(format)); - format.type = 0x100; - if (IoCtl(fd, VIDIOC_G_FMT, &format, 1) != 0) - msg = "no src/dst ovly fmt"; - } - if (msg != NULL) { - DBLOG(0, "%s %s\n", z4l_dev_paths[dev], msg); - close(fd); - continue; - } - - memset(&cfmt, 0, sizeof(cfmt)); - cfmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - if (IoCtl(fd, VIDIOC_G_FMT, &cfmt, 1) < 0) - goto fail; - if (IoCtl(fd, VIDIOC_G_STD, &cstd_id, 1) < 0) - goto fail; - if (IoCtl(fd, VIDIOC_G_INPUT, &cinp, 1) < 0) - goto fail; - cpixfmt = cfmt.fmt.pix.pixelformat; - cenc = 0; - for (inp = 0;; ++inp) { - memset(&input, 0, sizeof(input)); - input.index = inp; - if (IoCtl(fd, VIDIOC_ENUMINPUT, &input, 0) < 0) - break; - id = inp; - if (IoCtl(fd, VIDIOC_S_INPUT, &id, 1) < 0) - goto fail; - for (std = 0;; ++std) { - memset(&standard, 0, sizeof(standard)); - standard.index = std; - if (IoCtl(fd, VIDIOC_ENUMSTD, &standard, 0) < 0) - break; - std_id = standard.id; - denom = standard.frameperiod.denominator; - numer = standard.frameperiod.numerator; - if (IoCtl(fd, VIDIOC_S_STD, &std_id, 1) < 0) - continue; - memset(&format, 0, sizeof(format)); - format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - if (IoCtl(fd, VIDIOC_G_FMT, &format, 1) < 0) - continue; - width = format.fmt.pix.width; - height = format.fmt.pix.height; - for (fmt = 0;; ++fmt) { - memset(&fmtdesc, 0, sizeof(fmtdesc)); - fmtdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - fmtdesc.index = fmt; - if (IoCtl(fd, VIDIOC_ENUM_FMT, &fmtdesc, 0) < 0) - break; - pixfmt = fmtdesc.pixelformat; - ip = &pixfmts[0]; - for (i = sizeof(pixfmts) / sizeof(pixfmts[0]); --i >= 0; - ++ip) - if (z4l_fourcc_pixfmt(ip->id) == pixfmt) - break; - - if (i >= 0) { - id = nencs; - has_video = 1; - if ((enc = Z4lNewEncoding(&encs, &nencs)) == NULL) - goto fail; - Z4lEncodingName(&enc_name[0], sizeof(enc_name), - (char *)&input.name[0], - (char *)&standard.name[0], (char *)&pixfmt); - if (Z4lAddEncoding(enc, &enc_name[0], id, width, - height, denom, numer, inp, std_id, - pixfmt) == 0) - goto fail; - if (std_id == cstd_id && inp == cinp - && pixfmt == cpixfmt) - cenc = id; - } - } - } - } - - if (IoCtl(fd, VIDIOC_S_INPUT, &cinp, 1) < 0) - goto fail; - if (IoCtl(fd, VIDIOC_S_STD, &cstd_id, 1) < 0) - goto fail; - if (IoCtl(fd, VIDIOC_S_FMT, &cfmt, 1) < 0) - goto fail; - - if (encs == NULL) { - DBLOG(0, "no encodings\n"); - goto fail; - } - - for (fmt = 0;; ++fmt) { - memset(&fmtdesc, 0, sizeof(fmtdesc)); - fmtdesc.type = V4L2_BUF_TYPE_VIDEO_OVERLAY; - fmtdesc.index = fmt; - if (IoCtl(fd, VIDIOC_ENUM_FMT, &fmtdesc, 0) < 0) - break; - pixfmt = fmtdesc.pixelformat; - ip = &pixfmts[0]; - for (i = sizeof(pixfmts) / sizeof(pixfmts[0]); --i >= 0; ++ip) - if (z4l_fourcc_pixfmt(ip->id) == pixfmt) - break; - - if (i >= 0) { - has_image = 1; - if ((img = Z4lNewImage(&imgs, &nimgs)) == NULL) - goto fail; - if (Z4lAddImage(img, ip) == 0) - goto fail; - } - } - - if (nimgs > 0) { - id = nencs; - if ((enc = Z4lNewEncoding(&encs, &nencs)) == NULL) - goto fail; - if (Z4lAddEncoding(enc, "XV_IMAGE", id, MAX_OVLY_WIDTH, - MAX_OVLY_HEIGHT, 0, 0, 0, 0, pixfmt) == 0) - goto fail; - } - - ctl = 0; - for (ctl = 0; ctl < (V4L2_CID_LASTP1 - V4L2_CID_BASE); ++ctl) { - memset(&queryctrl, 0, sizeof(queryctrl)); - queryctrl.id = V4L2_CID_BASE + ctl; - if (IoCtl(fd, VIDIOC_QUERYCTRL, &queryctrl, 0) < 0) - continue; - if (queryctrl.type != V4L2_CTRL_TYPE_INTEGER && - queryctrl.type != V4L2_CTRL_TYPE_BOOLEAN) - continue; - attrIds[nattrs] = ctl; - if ((attr = Z4lNewAttribute(&attrs, &nattrs)) == NULL) - goto fail; - Z4lAttributeName(&attr_name[0], sizeof(attr_name), - (char *)&queryctrl.name[0]); - if (Z4lAddAttribute(attr, &attr_name[0], - queryctrl.minimum, queryctrl.maximum, - XvSettable | XvGettable) == 0) - goto fail; - } - attrIds[nattrs] = ATTR_ENCODING_ID; - if ((attr = Z4lNewAttribute(&attrs, &nattrs)) == NULL) - goto fail; - Z4lAttributeName(&attr_name[0], sizeof(attr_name), ATTR_ENCODING); - if (Z4lAddAttribute(attr, &attr_name[0], 0, nencs - 1, - XvSettable | XvGettable) == 0) - goto fail; - memset(&fbuf, 0, sizeof(fbuf)); - if (IoCtl(fd, VIDIOC_G_FBUF, &fbuf, 1) < 0) - goto fail; - opixfmt = fbuf.fmt.pixelformat; - - if ((fbuf.capability & V4L2_FBUF_CAP_CHROMAKEY) != 0) { - attrIds[nattrs] = ATTR_KEYMODE_ID; - if ((attr = Z4lNewAttribute(&attrs, &nattrs)) == NULL) - goto fail; - Z4lAttributeName(&attr_name[0], sizeof(attr_name), ATTR_KEYMODE); - if (Z4lAddAttribute(attr, &attr_name[0], 0, 1, - XvSettable | XvGettable) == 0) - goto fail; - attrIds[nattrs] = ATTR_COLORKEY_ID; - if ((attr = Z4lNewAttribute(&attrs, &nattrs)) == NULL) - goto fail; - Z4lAttributeName(&attr_name[0], sizeof(attr_name), ATTR_COLORKEY); - if (Z4lAddAttribute(attr, &attr_name[0], 0, 0xffffff, - XvSettable | XvGettable) == 0) - goto fail; - has_colorkey = 1; - } - - dp = xalloc(strlen((char *)&capability.card[0]) + 1); - if (dp == NULL) - goto fail; - strcpy(dp, (char *)&capability.card[0]); - if ((adpt = Z4lNewAdaptor(&adpts, &nadpts, nattrs)) == NULL) - goto fail; - adpt->type = XvWindowMask | XvInputMask; - if (has_video != 0) - adpt->type |= XvVideoMask; - if (has_image != 0) - adpt->type |= XvImageMask; - adpt->flags = VIDEO_OVERLAID_IMAGES | VIDEO_CLIP_TO_VIEWPORT; - adpt->name = dp; - adpt->type = XvInputMask | XvWindowMask | XvVideoMask | XvImageMask; - adpt->pEncodings = encs; - adpt->nEncodings = nencs; - adpt->pFormats = &Formats[0]; - adpt->nFormats = sizeof(Formats) / sizeof(Formats[0]); - adpt->pAttributes = attrs; - adpt->nAttributes = nattrs; - attrs = NULL; - nattrs = 0; - adpt->pImages = imgs; - adpt->nImages = nimgs; - imgs = NULL; - nimgs = 0; - adpt->PutVideo = Z4lPutVideo; - adpt->StopVideo = Z4lStopVideo; - adpt->SetPortAttribute = Z4lSetPortAttribute; - adpt->GetPortAttribute = Z4lGetPortAttribute; - adpt->QueryBestSize = Z4lQueryBestSize; - adpt->PutImage = Z4lPutImage; - adpt->QueryImageAttributes = Z4lQueryImageAttributes; - pPriv = (Z4lPortPrivRec *) adpt->pPortPrivates[0].ptr; - pPriv->fd = fd; - pPriv->run = -1; - pPriv->dir = 0; - pPriv->nbfrs = -1; - pPriv->bufsz = -1; - pPriv->last = -1; - pPriv->pixfmt = opixfmt; + if (msg == NULL) { + memset(&format, 0, sizeof(format)); + format.type = 0x100; + if (IoCtl(fd, VIDIOC_G_FMT, &format, 1) != 0) + msg = "no src/dst ovly fmt"; + } + if (msg != NULL) { + DBLOG(0, "%s %s\n", z4l_dev_paths[dev], msg); + close(fd); + continue; + } + + memset(&cfmt, 0, sizeof(cfmt)); + cfmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + if (IoCtl(fd, VIDIOC_G_FMT, &cfmt, 1) < 0) + goto fail; + if (IoCtl(fd, VIDIOC_G_STD, &cstd_id, 1) < 0) + goto fail; + if (IoCtl(fd, VIDIOC_G_INPUT, &cinp, 1) < 0) + goto fail; + cpixfmt = cfmt.fmt.pix.pixelformat; + cenc = 0; + for (inp = 0;; ++inp) { + memset(&input, 0, sizeof(input)); + input.index = inp; + if (IoCtl(fd, VIDIOC_ENUMINPUT, &input, 0) < 0) + break; + id = inp; + if (IoCtl(fd, VIDIOC_S_INPUT, &id, 1) < 0) + goto fail; + for (std = 0;; ++std) { + memset(&standard, 0, sizeof(standard)); + standard.index = std; + if (IoCtl(fd, VIDIOC_ENUMSTD, &standard, 0) < 0) + break; + std_id = standard.id; + denom = standard.frameperiod.denominator; + numer = standard.frameperiod.numerator; + if (IoCtl(fd, VIDIOC_S_STD, &std_id, 1) < 0) + continue; + memset(&format, 0, sizeof(format)); + format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + if (IoCtl(fd, VIDIOC_G_FMT, &format, 1) < 0) + continue; + width = format.fmt.pix.width; + height = format.fmt.pix.height; + for (fmt = 0;; ++fmt) { + memset(&fmtdesc, 0, sizeof(fmtdesc)); + fmtdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + fmtdesc.index = fmt; + if (IoCtl(fd, VIDIOC_ENUM_FMT, &fmtdesc, 0) < 0) + break; + pixfmt = fmtdesc.pixelformat; + ip = &pixfmts[0]; + for (i = sizeof(pixfmts) / sizeof(pixfmts[0]); --i >= 0; + ++ip) + if (z4l_fourcc_pixfmt(ip->id) == pixfmt) + break; + + if (i >= 0) { + id = nencs; + has_video = 1; + if ((enc = Z4lNewEncoding(&encs, &nencs)) == NULL) + goto fail; + Z4lEncodingName(&enc_name[0], sizeof(enc_name), + (char *)&input.name[0], + (char *)&standard.name[0], (char *)&pixfmt); + if (Z4lAddEncoding(enc, &enc_name[0], id, width, + height, denom, numer, inp, std_id, + pixfmt) == 0) + goto fail; + if (std_id == cstd_id && inp == cinp + && pixfmt == cpixfmt) + cenc = id; + } + } + } + } + + if (IoCtl(fd, VIDIOC_S_INPUT, &cinp, 1) < 0) + goto fail; + if (IoCtl(fd, VIDIOC_S_STD, &cstd_id, 1) < 0) + goto fail; + if (IoCtl(fd, VIDIOC_S_FMT, &cfmt, 1) < 0) + goto fail; + + if (encs == NULL) { + DBLOG(0, "no encodings\n"); + goto fail; + } + + for (fmt = 0;; ++fmt) { + memset(&fmtdesc, 0, sizeof(fmtdesc)); + fmtdesc.type = V4L2_BUF_TYPE_VIDEO_OVERLAY; + fmtdesc.index = fmt; + if (IoCtl(fd, VIDIOC_ENUM_FMT, &fmtdesc, 0) < 0) + break; + pixfmt = fmtdesc.pixelformat; + ip = &pixfmts[0]; + for (i = sizeof(pixfmts) / sizeof(pixfmts[0]); --i >= 0; ++ip) + if (z4l_fourcc_pixfmt(ip->id) == pixfmt) + break; + + if (i >= 0) { + has_image = 1; + if ((img = Z4lNewImage(&imgs, &nimgs)) == NULL) + goto fail; + if (Z4lAddImage(img, ip) == 0) + goto fail; + } + } + + if (nimgs > 0) { + id = nencs; + if ((enc = Z4lNewEncoding(&encs, &nencs)) == NULL) + goto fail; + if (Z4lAddEncoding(enc, "XV_IMAGE", id, MAX_OVLY_WIDTH, + MAX_OVLY_HEIGHT, 0, 0, 0, 0, pixfmt) == 0) + goto fail; + } + + ctl = 0; + for (ctl = 0; ctl < (V4L2_CID_LASTP1 - V4L2_CID_BASE); ++ctl) { + memset(&queryctrl, 0, sizeof(queryctrl)); + queryctrl.id = V4L2_CID_BASE + ctl; + if (IoCtl(fd, VIDIOC_QUERYCTRL, &queryctrl, 0) < 0) + continue; + if (queryctrl.type != V4L2_CTRL_TYPE_INTEGER && + queryctrl.type != V4L2_CTRL_TYPE_BOOLEAN) + continue; + attrIds[nattrs] = ctl; + if ((attr = Z4lNewAttribute(&attrs, &nattrs)) == NULL) + goto fail; + Z4lAttributeName(&attr_name[0], sizeof(attr_name), + (char *)&queryctrl.name[0]); + if (Z4lAddAttribute(attr, &attr_name[0], + queryctrl.minimum, queryctrl.maximum, + XvSettable | XvGettable) == 0) + goto fail; + } + attrIds[nattrs] = ATTR_ENCODING_ID; + if ((attr = Z4lNewAttribute(&attrs, &nattrs)) == NULL) + goto fail; + Z4lAttributeName(&attr_name[0], sizeof(attr_name), ATTR_ENCODING); + if (Z4lAddAttribute(attr, &attr_name[0], 0, nencs - 1, + XvSettable | XvGettable) == 0) + goto fail; + memset(&fbuf, 0, sizeof(fbuf)); + if (IoCtl(fd, VIDIOC_G_FBUF, &fbuf, 1) < 0) + goto fail; + opixfmt = fbuf.fmt.pixelformat; + + if ((fbuf.capability & V4L2_FBUF_CAP_CHROMAKEY) != 0) { + attrIds[nattrs] = ATTR_KEYMODE_ID; + if ((attr = Z4lNewAttribute(&attrs, &nattrs)) == NULL) + goto fail; + Z4lAttributeName(&attr_name[0], sizeof(attr_name), ATTR_KEYMODE); + if (Z4lAddAttribute(attr, &attr_name[0], 0, 1, + XvSettable | XvGettable) == 0) + goto fail; + attrIds[nattrs] = ATTR_COLORKEY_ID; + if ((attr = Z4lNewAttribute(&attrs, &nattrs)) == NULL) + goto fail; + Z4lAttributeName(&attr_name[0], sizeof(attr_name), ATTR_COLORKEY); + if (Z4lAddAttribute(attr, &attr_name[0], 0, 0xffffff, + XvSettable | XvGettable) == 0) + goto fail; + has_colorkey = 1; + } + + dp = xalloc(strlen((char *)&capability.card[0]) + 1); + if (dp == NULL) + goto fail; + strcpy(dp, (char *)&capability.card[0]); + if ((adpt = Z4lNewAdaptor(&adpts, &nadpts, nattrs)) == NULL) + goto fail; + adpt->type = XvWindowMask | XvInputMask; + if (has_video != 0) + adpt->type |= XvVideoMask; + if (has_image != 0) + adpt->type |= XvImageMask; + adpt->flags = VIDEO_OVERLAID_IMAGES | VIDEO_CLIP_TO_VIEWPORT; + adpt->name = dp; + adpt->type = XvInputMask | XvWindowMask | XvVideoMask | XvImageMask; + adpt->pEncodings = encs; + adpt->nEncodings = nencs; + adpt->pFormats = &Formats[0]; + adpt->nFormats = sizeof(Formats) / sizeof(Formats[0]); + adpt->pAttributes = attrs; + adpt->nAttributes = nattrs; + attrs = NULL; + nattrs = 0; + adpt->pImages = imgs; + adpt->nImages = nimgs; + imgs = NULL; + nimgs = 0; + adpt->PutVideo = Z4lPutVideo; + adpt->StopVideo = Z4lStopVideo; + adpt->SetPortAttribute = Z4lSetPortAttribute; + adpt->GetPortAttribute = Z4lGetPortAttribute; + adpt->QueryBestSize = Z4lQueryBestSize; + adpt->PutImage = Z4lPutImage; + adpt->QueryImageAttributes = Z4lQueryImageAttributes; + pPriv = (Z4lPortPrivRec *) adpt->pPortPrivates[0].ptr; + pPriv->fd = fd; + pPriv->run = -1; + pPriv->dir = 0; + pPriv->nbfrs = -1; + pPriv->bufsz = -1; + pPriv->last = -1; + pPriv->pixfmt = opixfmt; #if defined(REGION_NULL) - REGION_NULL(pScrni->pScreen, &pPriv->clips); + REGION_NULL(pScrni->pScreen, &pPriv->clips); #else - REGION_INIT(pScrni->pScreen, &pPriv->clips, NullBox, 0); + REGION_INIT(pScrni->pScreen, &pPriv->clips, NullBox, 0); #endif - strncpy(&pPriv->dev_path[0], z4l_dev_paths[dev], - sizeof(pPriv->dev_path)); - pPriv->enc = &encs[cenc]; - for (i = 0; i < adpt->nAttributes; ++i) - pPriv->attrIds[i] = attrIds[i]; - DBLOG(1, "adpt %s\n", dp); - if (has_colorkey != 0) { - z4l_ovly_set_colorkey(pPriv, DEFAULT_COLORKEY); - z4l_ovly_set_keymode(pPriv, DEFAULT_KEYMODE); - } - close(fd); - pPriv->fd = -1; - adpt = NULL; - cenc = 0; - encs = NULL; - nencs = 0; + strncpy(&pPriv->dev_path[0], z4l_dev_paths[dev], + sizeof(pPriv->dev_path)); + pPriv->enc = &encs[cenc]; + for (i = 0; i < adpt->nAttributes; ++i) + pPriv->attrIds[i] = attrIds[i]; + DBLOG(1, "adpt %s\n", dp); + if (has_colorkey != 0) { + z4l_ovly_set_colorkey(pPriv, DEFAULT_COLORKEY); + z4l_ovly_set_keymode(pPriv, DEFAULT_KEYMODE); + } + close(fd); + pPriv->fd = -1; + adpt = NULL; + cenc = 0; + encs = NULL; + nencs = 0; } DBLOG(0, "init done, %d device(s) found\n", nadpts); @@ -1633,50 +1633,50 @@ Z4lInit(ScrnInfoPtr pScrni, XF86VideoAdaptorPtr ** adaptors) fail: if (attrs != NULL) { - for (i = 0; i < nattrs; ++i) - if (attrs[i].name != NULL) - free(attrs[i].name); - free(attrs); + for (i = 0; i < nattrs; ++i) + if (attrs[i].name != NULL) + free(attrs[i].name); + free(attrs); } if (encs != NULL) { - for (i = 0; i < nencs; ++i) { - if (encs[i].name != NULL) - free(encs[i].name); - } - free(encs); + for (i = 0; i < nencs; ++i) { + if (encs[i].name != NULL) + free(encs[i].name); + } + free(encs); } if (imgs != NULL) - free(imgs); + free(imgs); if (adpts != NULL) { - for (i = 0; i < nadpts; ++i) { - if ((adpt = adpts[i]) != NULL) { - if (adpt->name != NULL) - free(adpt->name); - if ((attrs = adpt->pAttributes) != NULL) { - for (i = 0; i < adpt->nAttributes; ++i) - if (attrs[i].name != NULL) - free(attrs[i].name); - free(attrs); - } - if ((encs = adpt->pEncodings) != NULL) { - for (i = 0; i < adpt->nEncodings; ++i, ++enc) - if (encs[i].name != NULL) - free(encs[i].name); - free(encs); - } - if ((imgs = adpt->pImages) != NULL) - free(imgs); - xfree(adpt); - } - } - free(adpts); + for (i = 0; i < nadpts; ++i) { + if ((adpt = adpts[i]) != NULL) { + if (adpt->name != NULL) + free(adpt->name); + if ((attrs = adpt->pAttributes) != NULL) { + for (i = 0; i < adpt->nAttributes; ++i) + if (attrs[i].name != NULL) + free(attrs[i].name); + free(attrs); + } + if ((encs = adpt->pEncodings) != NULL) { + for (i = 0; i < adpt->nEncodings; ++i, ++enc) + if (encs[i].name != NULL) + free(encs[i].name); + free(encs); + } + if ((imgs = adpt->pImages) != NULL) + free(imgs); + xfree(adpt); + } + } + free(adpts); } if (fd >= 0) - close(fd); + close(fd); return 0; } @@ -1686,7 +1686,7 @@ Z4lProbe(DriverPtr drv, int flags) { DBLOG(1, "Probe\n"); if (flags & PROBE_DETECT) - return TRUE; + return TRUE; xf86XVRegisterGenericAdaptorDriver(Z4lInit); drv->refCount++; @@ -1737,21 +1737,21 @@ z4lSetup(pointer module, pointer opts, int *errmaj, int *errmin) static Bool setupDone = FALSE; if (setupDone != FALSE) { - if (errmaj != NULL) - *errmaj = LDR_ONCEONLY; - return NULL; + if (errmaj != NULL) + *errmaj = LDR_ONCEONLY; + return NULL; } setupDone = TRUE; LoaderGetOS(&osname, NULL, NULL, NULL); if (osname == NULL || strcmp(osname, "linux") != 0) { - if (errmaj) - *errmaj = LDR_BADOS; - if (errmin) - *errmin = 0; + if (errmaj) + *errmaj = LDR_BADOS; + if (errmin) + *errmin = 0; - return NULL; + return NULL; } xf86AddDriver(&Z4l, module, 0); |