Commit 181b704f authored by Hans de Goede's avatar Hans de Goede Committed by Mauro Carvalho Chehab

V4L/DVB (9707): gspca: Remove the event counter and simplify the frame wait.

Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
Signed-off-by: default avatarJean-Francois Moine <moinejf@free.fr>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 3480130a
...@@ -300,7 +300,6 @@ struct gspca_frame *gspca_frame_add(struct gspca_dev *gspca_dev, ...@@ -300,7 +300,6 @@ struct gspca_frame *gspca_frame_add(struct gspca_dev *gspca_dev,
frame->v4l2_buf.bytesused = frame->data_end - frame->data; frame->v4l2_buf.bytesused = frame->data_end - frame->data;
frame->v4l2_buf.flags &= ~V4L2_BUF_FLAG_QUEUED; frame->v4l2_buf.flags &= ~V4L2_BUF_FLAG_QUEUED;
frame->v4l2_buf.flags |= V4L2_BUF_FLAG_DONE; frame->v4l2_buf.flags |= V4L2_BUF_FLAG_DONE;
atomic_inc(&gspca_dev->nevent);
wake_up_interruptible(&gspca_dev->wq); /* event = new frame */ wake_up_interruptible(&gspca_dev->wq); /* event = new frame */
i = (gspca_dev->fr_i + 1) % gspca_dev->nframes; i = (gspca_dev->fr_i + 1) % gspca_dev->nframes;
gspca_dev->fr_i = i; gspca_dev->fr_i = i;
...@@ -394,7 +393,6 @@ static int frame_alloc(struct gspca_dev *gspca_dev, ...@@ -394,7 +393,6 @@ static int frame_alloc(struct gspca_dev *gspca_dev,
gspca_dev->fr_i = gspca_dev->fr_o = gspca_dev->fr_q = 0; gspca_dev->fr_i = gspca_dev->fr_o = gspca_dev->fr_q = 0;
gspca_dev->last_packet_type = DISCARD_PACKET; gspca_dev->last_packet_type = DISCARD_PACKET;
gspca_dev->sequence = 0; gspca_dev->sequence = 0;
atomic_set(&gspca_dev->nevent, 0);
return 0; return 0;
} }
...@@ -628,7 +626,6 @@ static int gspca_init_transfer(struct gspca_dev *gspca_dev) ...@@ -628,7 +626,6 @@ static int gspca_init_transfer(struct gspca_dev *gspca_dev)
goto out; goto out;
} }
gspca_dev->streaming = 1; gspca_dev->streaming = 1;
atomic_set(&gspca_dev->nevent, 0);
/* some bulk transfers are started by the subdriver */ /* some bulk transfers are started by the subdriver */
if (gspca_dev->alt == 0 && gspca_dev->cam.bulk_nurbs == 0) if (gspca_dev->alt == 0 && gspca_dev->cam.bulk_nurbs == 0)
...@@ -669,7 +666,6 @@ static int gspca_set_alt0(struct gspca_dev *gspca_dev) ...@@ -669,7 +666,6 @@ static int gspca_set_alt0(struct gspca_dev *gspca_dev)
static void gspca_stream_off(struct gspca_dev *gspca_dev) static void gspca_stream_off(struct gspca_dev *gspca_dev)
{ {
gspca_dev->streaming = 0; gspca_dev->streaming = 0;
atomic_set(&gspca_dev->nevent, 0);
if (gspca_dev->present if (gspca_dev->present
&& gspca_dev->sd_desc->stopN) && gspca_dev->sd_desc->stopN)
gspca_dev->sd_desc->stopN(gspca_dev); gspca_dev->sd_desc->stopN(gspca_dev);
...@@ -1255,7 +1251,6 @@ static int vidioc_streamoff(struct file *file, void *priv, ...@@ -1255,7 +1251,6 @@ static int vidioc_streamoff(struct file *file, void *priv,
gspca_dev->fr_i = gspca_dev->fr_o = gspca_dev->fr_q = 0; gspca_dev->fr_i = gspca_dev->fr_o = gspca_dev->fr_q = 0;
gspca_dev->last_packet_type = DISCARD_PACKET; gspca_dev->last_packet_type = DISCARD_PACKET;
gspca_dev->sequence = 0; gspca_dev->sequence = 0;
atomic_set(&gspca_dev->nevent, 0);
ret = 0; ret = 0;
out: out:
mutex_unlock(&gspca_dev->queue_lock); mutex_unlock(&gspca_dev->queue_lock);
...@@ -1459,33 +1454,22 @@ static int frame_wait(struct gspca_dev *gspca_dev, ...@@ -1459,33 +1454,22 @@ static int frame_wait(struct gspca_dev *gspca_dev,
i = gspca_dev->fr_o; i = gspca_dev->fr_o;
j = gspca_dev->fr_queue[i]; j = gspca_dev->fr_queue[i];
frame = &gspca_dev->frame[j]; frame = &gspca_dev->frame[j];
if (frame->v4l2_buf.flags & V4L2_BUF_FLAG_DONE) {
atomic_dec(&gspca_dev->nevent); if (!(frame->v4l2_buf.flags & V4L2_BUF_FLAG_DONE)) {
goto ok; if (nonblock_ing)
}
if (nonblock_ing) /* no frame yet */
return -EAGAIN; return -EAGAIN;
/* wait till a frame is ready */ /* wait till a frame is ready */
for (;;) {
ret = wait_event_interruptible_timeout(gspca_dev->wq, ret = wait_event_interruptible_timeout(gspca_dev->wq,
atomic_read(&gspca_dev->nevent) > 0, (frame->v4l2_buf.flags & V4L2_BUF_FLAG_DONE) ||
!gspca_dev->streaming || !gspca_dev->present,
msecs_to_jiffies(3000)); msecs_to_jiffies(3000));
if (ret <= 0) {
if (ret < 0) if (ret < 0)
return ret; /* interrupt */ return ret;
return -EIO; /* timeout */ if (ret == 0 || !gspca_dev->streaming || !gspca_dev->present)
}
atomic_dec(&gspca_dev->nevent);
if (!gspca_dev->streaming || !gspca_dev->present)
return -EIO; return -EIO;
i = gspca_dev->fr_o;
j = gspca_dev->fr_queue[i];
frame = &gspca_dev->frame[j];
if (frame->v4l2_buf.flags & V4L2_BUF_FLAG_DONE)
break;
} }
ok:
gspca_dev->fr_o = (i + 1) % gspca_dev->nframes; gspca_dev->fr_o = (i + 1) % gspca_dev->nframes;
PDEBUG(D_FRAM, "frame wait q:%d i:%d o:%d", PDEBUG(D_FRAM, "frame wait q:%d i:%d o:%d",
gspca_dev->fr_q, gspca_dev->fr_q,
......
...@@ -155,7 +155,6 @@ struct gspca_dev { ...@@ -155,7 +155,6 @@ struct gspca_dev {
__u16 height; __u16 height;
__u32 sequence; /* frame sequence number */ __u32 sequence; /* frame sequence number */
atomic_t nevent; /* number of frames done */
wait_queue_head_t wq; /* wait queue */ wait_queue_head_t wq; /* wait queue */
struct mutex usb_lock; /* usb exchange protection */ struct mutex usb_lock; /* usb exchange protection */
struct mutex read_lock; /* read protection */ struct mutex read_lock; /* read protection */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment