static ssize_t camera_core_read(struct file *file, char *data, size_t count, loff_t *ppos) { struct camera_fh *fh = file->private_data; struct camera_device *cam = fh->cam; int err; unsigned long irqflags; long timeout; #if 0 /* use video_buf to do capture */ int i; for (i = 0; i < 14; i++) videobuf_read_one(file, &fh->vbq, data, count, ppos); i = videobuf_read_one(file, &fh->vbq, data, count, ppos); return i; #endif if (!cam->capture_base) { cam->capture_base = (unsigned long)dma_alloc_coherent(NULL, cam->pix.sizeimage, (dma_addr_t *) &cam->capture_base_phys, GFP_KERNEL | GFP_DMA); } if (!cam->capture_base) { printk(KERN_ERR CAM_NAME ": cannot allocate capture buffer\n"); return 0; } spin_lock_irqsave(&cam->capture_lock, irqflags); cam->reading = fh; cam->capture_started = 1; sg_dma_address(&cam->capture_sglist) = cam->capture_base_phys; sg_dma_len(&cam->capture_sglist)= cam->pix.sizeimage; spin_unlock_irqrestore(&cam->capture_lock, irqflags); err = camera_core_sgdma_queue(cam, &cam->capture_sglist, 1, camera_core_capture_callback, NULL); /* Wait till DMA is completed */ timeout = HZ * 10; cam->capture_completed = 0; while (cam->capture_completed == 0) { timeout = interruptible_sleep_on_timeout (&cam->new_video_frame, timeout); if (timeout == 0) { printk(KERN_ERR CAM_NAME ": timeout waiting video frame\n"); return -EIO; /* time out */ } } /* copy the data to the user buffer */ err = copy_to_user(data, (void *)cam->capture_base, count); return (count - err); }
static ssize_t video_read(struct file *file, char __user * data, size_t count, loff_t * ppos) { struct cx25821_fh *fh = file->private_data; switch (fh->type) { case V4L2_BUF_TYPE_VIDEO_CAPTURE: if (res_locked(fh->dev, RESOURCE_VIDEO1)) return -EBUSY; return videobuf_read_one(&fh->vidq, data, count, ppos, file->f_flags & O_NONBLOCK); default: BUG(); return 0; } }
static ssize_t video_read(struct file *file, char __user *data, size_t count, loff_t *ppos) { struct saa7146_fh *fh = file->private_data; struct saa7146_dev *dev = fh->dev; struct saa7146_vv *vv = dev->vv_data; ssize_t ret = 0; DEB_EE(("called.\n")); if ((vv->video_status & STATUS_CAPTURE) != 0) { /* fixme: should we allow read() captures while streaming capture? */ if (vv->video_fh == fh) { DEB_S(("already capturing.\n")); return -EBUSY; } DEB_S(("already capturing in another open.\n")); return -EBUSY; } ret = video_begin(fh); if( 0 != ret) { goto out; } ret = videobuf_read_one(&fh->video_q , data, count, ppos, file->f_flags & O_NONBLOCK); if (ret != 0) { video_end(fh, file); } else { ret = video_end(fh, file); } out: /* restart overlay if it was active before */ if (vv->ov_suspend != NULL) { saa7146_start_preview(vv->ov_suspend); vv->ov_suspend = NULL; } return ret; }