Commit 7b44ca8b authored by Gerd Knorr's avatar Gerd Knorr Committed by Linus Torvalds

[PATCH] video-buf.c update

This updates the video-buf helper module.  It changes the field handling
a bit and adds code do deal better with alternating field capture (=
capture even and odd fields to separate video buffers).
parent 60e4b5d3
...@@ -339,6 +339,7 @@ videobuf_queue_init(struct videobuf_queue *q, ...@@ -339,6 +339,7 @@ videobuf_queue_init(struct videobuf_queue *q,
struct pci_dev *pci, struct pci_dev *pci,
spinlock_t *irqlock, spinlock_t *irqlock,
enum v4l2_buf_type type, enum v4l2_buf_type type,
enum v4l2_field field,
int msize) int msize)
{ {
memset(q,0,sizeof(*q)); memset(q,0,sizeof(*q));
...@@ -346,6 +347,7 @@ videobuf_queue_init(struct videobuf_queue *q, ...@@ -346,6 +347,7 @@ videobuf_queue_init(struct videobuf_queue *q,
q->irqlock = irqlock; q->irqlock = irqlock;
q->pci = pci; q->pci = pci;
q->type = type; q->type = type;
q->field = field;
q->msize = msize; q->msize = msize;
q->ops = ops; q->ops = ops;
...@@ -406,6 +408,25 @@ videobuf_queue_cancel(struct file *file, struct videobuf_queue *q) ...@@ -406,6 +408,25 @@ videobuf_queue_cancel(struct file *file, struct videobuf_queue *q)
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
enum v4l2_field
videobuf_next_field(struct videobuf_queue *q)
{
enum v4l2_field field = q->field;
BUG_ON(V4L2_FIELD_ANY == field);
if (V4L2_FIELD_ALTERNATE == field) {
if (V4L2_FIELD_TOP == q->last) {
field = V4L2_FIELD_TOP;
q->last = V4L2_FIELD_TOP;
} else {
field = V4L2_FIELD_BOTTOM;
q->last = V4L2_FIELD_BOTTOM;
}
}
return field;
}
void void
videobuf_status(struct v4l2_buffer *b, struct videobuf_buffer *vb, videobuf_status(struct v4l2_buffer *b, struct videobuf_buffer *vb,
enum v4l2_buf_type type) enum v4l2_buf_type type)
...@@ -486,6 +507,7 @@ videobuf_qbuf(struct file *file, struct videobuf_queue *q, ...@@ -486,6 +507,7 @@ videobuf_qbuf(struct file *file, struct videobuf_queue *q,
struct v4l2_buffer *b) struct v4l2_buffer *b)
{ {
struct videobuf_buffer *buf; struct videobuf_buffer *buf;
enum v4l2_field field;
unsigned long flags; unsigned long flags;
int retval; int retval;
...@@ -507,7 +529,8 @@ videobuf_qbuf(struct file *file, struct videobuf_queue *q, ...@@ -507,7 +529,8 @@ videobuf_qbuf(struct file *file, struct videobuf_queue *q,
buf->state == STATE_ACTIVE) buf->state == STATE_ACTIVE)
goto done; goto done;
retval = q->ops->buf_prepare(file,buf); field = videobuf_next_field(q);
retval = q->ops->buf_prepare(file,buf,field);
if (0 != retval) if (0 != retval)
goto done; goto done;
...@@ -613,6 +636,8 @@ static ssize_t ...@@ -613,6 +636,8 @@ static ssize_t
videobuf_read_zerocopy(struct file *file, struct videobuf_queue *q, videobuf_read_zerocopy(struct file *file, struct videobuf_queue *q,
char *data, size_t count, loff_t *ppos) char *data, size_t count, loff_t *ppos)
{ {
enum v4l2_field field;
unsigned long flags;
int retval; int retval;
/* setup stuff */ /* setup stuff */
...@@ -623,12 +648,15 @@ videobuf_read_zerocopy(struct file *file, struct videobuf_queue *q, ...@@ -623,12 +648,15 @@ videobuf_read_zerocopy(struct file *file, struct videobuf_queue *q,
q->read_buf->baddr = (unsigned long)data; q->read_buf->baddr = (unsigned long)data;
q->read_buf->bsize = count; q->read_buf->bsize = count;
retval = q->ops->buf_prepare(file,q->read_buf); field = videobuf_next_field(q);
retval = q->ops->buf_prepare(file,q->read_buf,field);
if (0 != retval) if (0 != retval)
goto done; goto done;
/* start capture & wait */ /* start capture & wait */
spin_lock_irqsave(q->irqlock,flags);
q->ops->buf_queue(file,q->read_buf); q->ops->buf_queue(file,q->read_buf);
spin_unlock_irqrestore(q->irqlock,flags);
retval = videobuf_waiton(q->read_buf,0,0); retval = videobuf_waiton(q->read_buf,0,0);
if (0 == retval) { if (0 == retval) {
videobuf_dma_pci_sync(q->pci,&q->read_buf->dma); videobuf_dma_pci_sync(q->pci,&q->read_buf->dma);
...@@ -646,6 +674,8 @@ videobuf_read_zerocopy(struct file *file, struct videobuf_queue *q, ...@@ -646,6 +674,8 @@ videobuf_read_zerocopy(struct file *file, struct videobuf_queue *q,
ssize_t videobuf_read_one(struct file *file, struct videobuf_queue *q, ssize_t videobuf_read_one(struct file *file, struct videobuf_queue *q,
char *data, size_t count, loff_t *ppos) char *data, size_t count, loff_t *ppos)
{ {
enum v4l2_field field;
unsigned long flags;
int retval, bytes, size, nbufs; int retval, bytes, size, nbufs;
down(&q->lock); down(&q->lock);
...@@ -668,10 +698,13 @@ ssize_t videobuf_read_one(struct file *file, struct videobuf_queue *q, ...@@ -668,10 +698,13 @@ ssize_t videobuf_read_one(struct file *file, struct videobuf_queue *q,
q->read_buf = videobuf_alloc(q->msize); q->read_buf = videobuf_alloc(q->msize);
if (NULL == q->read_buf) if (NULL == q->read_buf)
goto done; goto done;
retval = q->ops->buf_prepare(file,q->read_buf); field = videobuf_next_field(q);
retval = q->ops->buf_prepare(file,q->read_buf,field);
if (0 != retval) if (0 != retval)
goto done; goto done;
spin_lock_irqsave(q->irqlock,flags);
q->ops->buf_queue(file,q->read_buf); q->ops->buf_queue(file,q->read_buf);
spin_unlock_irqrestore(q->irqlock,flags);
q->read_off = 0; q->read_off = 0;
} }
...@@ -705,6 +738,7 @@ ssize_t videobuf_read_one(struct file *file, struct videobuf_queue *q, ...@@ -705,6 +738,7 @@ ssize_t videobuf_read_one(struct file *file, struct videobuf_queue *q,
int videobuf_read_start(struct file *file, struct videobuf_queue *q) int videobuf_read_start(struct file *file, struct videobuf_queue *q)
{ {
enum v4l2_field field;
unsigned long flags; unsigned long flags;
int count = 0, size = 0; int count = 0, size = 0;
int err, i; int err, i;
...@@ -720,7 +754,8 @@ int videobuf_read_start(struct file *file, struct videobuf_queue *q) ...@@ -720,7 +754,8 @@ int videobuf_read_start(struct file *file, struct videobuf_queue *q)
if (err) if (err)
return err; return err;
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
err = q->ops->buf_prepare(file,q->bufs[i]); field = videobuf_next_field(q);
err = q->ops->buf_prepare(file,q->bufs[i],field);
if (err) if (err)
return err; return err;
list_add_tail(&q->bufs[i]->stream, &q->stream); list_add_tail(&q->bufs[i]->stream, &q->stream);
...@@ -793,6 +828,7 @@ ssize_t videobuf_read_stream(struct file *file, struct videobuf_queue *q, ...@@ -793,6 +828,7 @@ ssize_t videobuf_read_stream(struct file *file, struct videobuf_queue *q,
fc = (unsigned int*)q->read_buf->dma.vmalloc; fc = (unsigned int*)q->read_buf->dma.vmalloc;
fc += (q->read_buf->size>>2) -1; fc += (q->read_buf->size>>2) -1;
*fc = q->read_buf->field_count >> 1; *fc = q->read_buf->field_count >> 1;
dprintk(1,"vbihack: %d\n",*fc);
} }
/* copy stuff */ /* copy stuff */
......
...@@ -154,7 +154,8 @@ struct videobuf_buffer { ...@@ -154,7 +154,8 @@ struct videobuf_buffer {
struct videobuf_queue_ops { struct videobuf_queue_ops {
int (*buf_setup)(struct file *file, int *count, int *size); int (*buf_setup)(struct file *file, int *count, int *size);
int (*buf_prepare)(struct file *file,struct videobuf_buffer *vb); int (*buf_prepare)(struct file *file,struct videobuf_buffer *vb,
enum v4l2_field field);
void (*buf_queue)(struct file *file,struct videobuf_buffer *vb); void (*buf_queue)(struct file *file,struct videobuf_buffer *vb);
void (*buf_release)(struct file *file,struct videobuf_buffer *vb); void (*buf_release)(struct file *file,struct videobuf_buffer *vb);
}; };
...@@ -166,6 +167,8 @@ struct videobuf_queue { ...@@ -166,6 +167,8 @@ struct videobuf_queue {
enum v4l2_buf_type type; enum v4l2_buf_type type;
int msize; int msize;
enum v4l2_field field;
enum v4l2_field last; /* for field=V4L2_FIELD_ALTERNATE */
struct videobuf_buffer *bufs[VIDEO_MAX_FRAME]; struct videobuf_buffer *bufs[VIDEO_MAX_FRAME];
struct videobuf_queue_ops *ops; struct videobuf_queue_ops *ops;
...@@ -186,7 +189,8 @@ int videobuf_iolock(struct pci_dev *pci, struct videobuf_buffer *vb); ...@@ -186,7 +189,8 @@ int videobuf_iolock(struct pci_dev *pci, struct videobuf_buffer *vb);
void videobuf_queue_init(struct videobuf_queue *q, void videobuf_queue_init(struct videobuf_queue *q,
struct videobuf_queue_ops *ops, struct videobuf_queue_ops *ops,
struct pci_dev *pci, spinlock_t *irqlock, struct pci_dev *pci, spinlock_t *irqlock,
enum v4l2_buf_type type, int msize); enum v4l2_buf_type type,
enum v4l2_field field, int msize);
int videobuf_queue_is_busy(struct videobuf_queue *q); int videobuf_queue_is_busy(struct videobuf_queue *q);
void videobuf_queue_cancel(struct file *file, struct videobuf_queue *q); void videobuf_queue_cancel(struct file *file, struct videobuf_queue *q);
......
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