⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zc030x_v4l.c

📁 中星微301摄想头最新驱动
💻 C
📖 第 1 页 / 共 2 页
字号:
                 vw->width, vw->height,vw->flags);            /* We don't accept capture window inside the captured area */            if (vw->x) ret = -EINVAL;            if (vw->y) ret = -EINVAL;            if (vw->width  != currentwidth) ret = -EINVAL;            if (vw->height != currentheight) ret = -EINVAL;            break;        }        /* Get the capture window */        case VIDIOCGWIN:        {            /* Convert the argument */            struct video_window *vw = arg;            /* Clear it */            memset(vw, 0, sizeof(struct video_window));            /* Fill it */            vw->x      = 0;            vw->y      = 0;            vw->width  = currentwidth;            vw->height = currentheight;            vw->flags  = 0;            /* Debug this */            PDEBUG (4, "VIDIOCGWIN: %dx%d", vw->width, vw->height);            /* Return  */            ret = 0;            break;        }        /* Get the video buffer */         case VIDIOCGMBUF:        {            /* Convert the argument */            struct video_mbuf *vm=arg;            /* Debug this */            PDEBUG (4, "VIDIOCGMBUF: %p - Set to %d frames", vm, ZC030X_NUMFRAMES);            /* Clear it */            memset(vm, 0, sizeof(struct video_mbuf));            /* Set the size */            vm->size = ZC030X_NUMFRAMES * MAX_VIDEODATA_SIZE;            /* And the number of frames */            vm->frames = ZC030X_NUMFRAMES;            /* Set the offset for each frame */            for(i = 0; i < ZC030X_NUMFRAMES; i++)            {                vm->offsets[i] = MAX_VIDEODATA_SIZE * i;            }            /* Okay, return */            ret = 0;            break;        }        /* Check the asked flags, change gamma & bn & constrast */        case VIDIOCSPICT:        {            /* Convert the argument */            struct video_picture *p = arg;            /* Check if the asked format is supported */            ret = zc030x_v4l_checkpalette(p->palette) ? 0 : -EINVAL;            /* Now get an approximate number of the asked brightness */            dev->Brightness = p->brightness;            dev->Contrast   = p->contrast;            zc030x_send_gamma(dev->udev, dev->Brightness, dev->Contrast, dev->Gamma);            break;        }        /* Start the capture */        case VIDIOCMCAPTURE:        {            /* Convert the argument */            struct video_mmap * vm = arg;            zc030x_frame      * frame = NULL;            /* Debug this */            PDEBUG(4, "VIDEOCMCAPTURE, format is %s", zc030x_v4l_getpalettename(vm->format));            PDEBUG(4, "frame: %d, size: %dx%d, format: %d", vm->frame, vm->width, vm->height, vm->format);            /* Check if asked palette is supported */            if (!zc030x_v4l_checkpalette(vm->format))            {                /* Invalid palette */                PDEBUG(1, "VIDIOCMCAPTURE: invalid format (%d)", vm->format);                up (&dev->sem);                return -EINVAL;            }            /* Set the video format to what is asked */            dev->VideoFormat = vm->format;            /* Check for the asked frame */            if ((vm->frame < 0) || (vm->frame > ZC030X_NUMFRAMES))            {                PDEBUG(1,"VIDIOCMCAPTURE: invalid frame (%d)", vm->frame);                up (&dev->sem);                return -EINVAL;            }            /* Check for the asked height */            /* TODO Handle change in height */            if (vm->width != currentwidth  || vm->height != currentheight)             {/*                if ((vm->width == SensorSizeList[dev->sensor_id].Width || vm->width == SensorSizeList[dev->sensor_id].Width / 2)                  && (vm->height == SensorSizeList[dev->sensor_id].Height || vm->height == SensorSizeList[dev->sensor_id].Height / 2))                 {                    PDEBUG(1,"VIDIOCMCAPTURE: wrong dimensions. Changing to asked size %dx%d", vm->width, vm->height);                                        if (zc030x_reg_setsize(dev, vm->width, vm->height, 0) != REG_OK)                    {                        PDEBUG(1, "Error while changing the size... LEAVING");                        up (&dev->sem);                        return -EINVAL;                    }                } else                {                */                    PDEBUG(1,"VIDIOCMCAPTURE: wrong dimensions. Sensor doesn't allow size %dx%d", vm->width, vm->height);                    up (&dev->sem);                    return -EINVAL;/*                }*/                            }#if 0                        /* TODO: Handle this better */            /* Mark all other frame as unavailable for grabbing */            down(&dev->buf_lock);            /* Get the frame */            frame = &dev->frame[vm->frame];            frame->Format= vm->format;            /* Set this frame to unused */            down(&frame->Lock);            /* Check if the frame is unused */            if (frame->GrabState != FRAME_GRABBING)            {                /* Now this frame is ready to be grabbed into */                frame->GrabState = FRAME_READY;            }            up(&frame->Lock);            up(&dev->buf_lock);                        /* TODO: Remove this */            /* Dumping the buffer state */            for (i = 0; i < ZC030X_NUMFRAMES; i++)            {                frame = &dev->frame[i];                down(&frame->Lock);                PDEBUG(4, "DUMPASK: [%d] Frame %d state is %d", vm->frame, i, frame->GrabState);                up(&frame->Lock);            }#endif/* Remove previous algorithm */#if 1            /* Get the frame */            frame = &dev->frame[vm->frame];            /* Lock it *///            down(&frame->Lock);            /* If the current frame is being grabbed, wait until it's done */             if (frame->GrabState == FRAME_GRABBING)            {                PDEBUG(4, "VIDEOCMCAPTURE: already grabbing");                /* Schedule until it's done */                /* Release it while waiting for it *///                up(&frame->Lock);                ret = wait_event_interruptible(frame->wq, (frame->GrabState != FRAME_GRABBING));                /* Were we interrupted ? */                if (ret)                {                    up (&dev->sem);                    return -EINTR;                }                /* Lock it */                down(&frame->Lock);                /* Set to ready */                frame->GrabState = FRAME_READY;                /* Unlock it */                up(&frame->Lock);            } else            {                /* Set to ready */                frame->GrabState = FRAME_READY;                /* Unlock it *///                up(&frame->Lock);            }#endif            /* Return */            ret = 0;            break;        }        /* Synchronize to the specified frame */        case VIDIOCSYNC:        {            /* Convert the argument */            unsigned int frameIndex = *((unsigned int *) arg);            zc030x_frame      * frame = NULL;            /* Debug this */            PDEBUG(4, "VIDIOCSYNC: syncing to frame %d", frameIndex);            /* Check the argument */            if (frameIndex >= ZC030X_NUMFRAMES)            {                up (&dev->sem);                return -EINVAL;            }                        /* TODO: Remove this */            /* Dumping the buffer state */            for (i = 0; i < ZC030X_NUMFRAMES; i++)            {                frame = &dev->frame[i];                down(&frame->Lock);                PDEBUG(4, "DUMPGET: [%d] Frame %d state is %d", frameIndex, i, frame->GrabState);                up(&frame->Lock);            }                        /* Get the Frame with the specified index */            frame = &dev->frame[frameIndex];            /* Lock it *///            down(&frame->Lock);            /* Check grabbing state *///            redo:            PDEBUG(4, "frame state %d", frame->GrabState);            switch (frame->GrabState)             {                /* This frame is not used */                case FRAME_UNUSED:                {//                    up (&frame->Lock);                    up (&dev->sem);                    return -EINVAL;                }                /* This frame is currently aborting */                case FRAME_ABORTING:                {//                    up (&frame->Lock);                    up (&dev->sem);                    return -ENODEV;                }                /* Is the frame ready, grabbing or in error ? */                case FRAME_READY:                case FRAME_GRABBING:                case FRAME_ERROR:                {                redo:                    /* Check if the device is still present */                    if (!dev->present)                    {//                        up (&frame->Lock);                        up (&dev->sem);                        return -EIO;                    }                    /* Release the lock before waiting for a frame *///                    up(&frame->Lock);                    ret = wait_event_interruptible(frame->wq, (frame->GrabState == FRAME_DONE));                    /* Were we interrupted ? */                    if (ret)                    {                        up (&dev->sem);                        return -EINTR;                    }                                        /* Synchronization is done *///                    down(&frame->Lock);                    PDEBUG(5,"Synched on frame %d, grabstate = %d", frameIndex, frame->GrabState);                                        /* Relock the frame */                    if (frame->GrabState == FRAME_ERROR)                        goto redo;                    /* Fallthrough.                    * We have waited in state FRAME_GRABBING until it                    * becomes FRAME_DONE, so now we can move along.                    */                }                /* Frame is already uncompressed */                case FRAME_DONE:                {                    PDEBUG(3,"Already synched %d\n", frameIndex);                    /* Release the current frame. This means that it                    * will be reused as soon as all other frames are                    * full, so the app better be done with it quickly.                    * Can this be avoided somehow?                    */                    frame->GrabState = FRAME_UNUSED;                    break;                }            }             /* Unlock the frame *///            up(&frame->Lock);                        /* Return */            ret = 0;            break;        }        default:        {            break;        }    }        /* unlock the device */    up (&dev->sem);        /* Okay, return */    PDEBUG(3,"<< zc030x_v4l_ioctl() : %d", ret);    return ret;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -