]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
V4L/DVB (6712): ivtv: ivtv yuv stream handling change
authorIan Armstrong <ian@iarmst.demon.co.uk>
Tue, 16 Oct 2007 06:21:46 +0000 (03:21 -0300)
committerMauro Carvalho Chehab <mchehab@infradead.org>
Fri, 25 Jan 2008 21:03:09 +0000 (19:03 -0200)
Currently the yuv output stream buffer is divided into blocks whose size
depend on the broadcast standard selected during the driver init phase.
However, the standard can be changed after the init phase. This effectively
breaks the yuv output stream handler, since it relies on the different yuv
planes being block aligned.

This patch changes the setup, so that the block size is always the same. The
decoder dma function has been modified to cope with the fact that the second
yuv plane may no longer be block aligned. The start of the yuv frame must
still be at the beginning of a block, so the stream write function has also
been modified to ensure this is always true.

Also, the stream write function will now initiate a yuv dma transfer as soon
as a full frame is ready. It will not wait until the current write request
has completed, or the stream buffer becomes full.

Signed-off-by: Ian Armstrong <ian@iarmst.demon.co.uk>
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
drivers/media/video/ivtv/ivtv-driver.c
drivers/media/video/ivtv/ivtv-driver.h
drivers/media/video/ivtv/ivtv-fileops.c
drivers/media/video/ivtv/ivtv-irq.c

index 04179b7d1af0fcb0b5be6c986f854b22f3490eff..48db22cc1bd826e3a9ad419a5d2011978b7a4f85 100644 (file)
@@ -970,7 +970,6 @@ static int __devinit ivtv_probe(struct pci_dev *dev,
                                const struct pci_device_id *pci_id)
 {
        int retval = 0;
-       int yuv_buf_size;
        int vbi_buf_size;
        struct ivtv *itv;
 
@@ -1122,11 +1121,8 @@ static int __devinit ivtv_probe(struct pci_dev *dev,
        itv->stream_buf_size[IVTV_ENC_STREAM_TYPE_MPG] = 0x08000;
        itv->stream_buf_size[IVTV_ENC_STREAM_TYPE_PCM] = 0x01200;
        itv->stream_buf_size[IVTV_DEC_STREAM_TYPE_MPG] = 0x10000;
-
-       /* 0x15180 == 720 * 480 / 4, 0x19500 == 720 * 576 / 4 */
-       yuv_buf_size = itv->is_60hz ? 0x15180 : 0x19500;
-       itv->stream_buf_size[IVTV_DEC_STREAM_TYPE_YUV] = yuv_buf_size / 2;
-       itv->stream_buf_size[IVTV_ENC_STREAM_TYPE_YUV] = yuv_buf_size / 8;
+       itv->stream_buf_size[IVTV_DEC_STREAM_TYPE_YUV] = 0x10000;
+       itv->stream_buf_size[IVTV_ENC_STREAM_TYPE_YUV] = 0x08000;
 
        /* Setup VBI Raw Size. Should be big enough to hold PAL.
           It is possible to switch between PAL and NTSC, so we need to
index 49ce14d14a54b69eeaa5f04ca200840030d1dad2..b6dd2360e610097ffb8db27250e19adb72902f0f 100644 (file)
@@ -485,6 +485,8 @@ struct yuv_playback_info
 
        void *blanking_ptr;
        dma_addr_t blanking_dmaptr;
+
+       int stream_size;
 };
 
 #define IVTV_VBI_FRAMES 32
index a200a8a95a2dc2ee125e6b32a94ab69b96727973..58ad0d9c680a89ca4183dc9ef8cc8570be58fd01 100644 (file)
@@ -542,6 +542,7 @@ ssize_t ivtv_v4l2_write(struct file *filp, const char __user *user_buf, size_t c
        struct ivtv_open_id *id = filp->private_data;
        struct ivtv *itv = id->itv;
        struct ivtv_stream *s = &itv->streams[id->type];
+       struct yuv_playback_info *yi = &itv->yuv_info;
        struct ivtv_buffer *buf;
        struct ivtv_queue q;
        int bytes_written = 0;
@@ -604,9 +605,16 @@ retry:
 
        /* copy user data into buffers */
        while ((buf = ivtv_dequeue(s, &q))) {
-               /* Make sure we really got all the user data */
-               rc = ivtv_buf_copy_from_user(s, buf, user_buf, count);
+               /* yuv is a pain. Don't copy more data than needed for a single
+                  frame, otherwise we lose sync with the incoming stream */
+               if (s->type == IVTV_DEC_STREAM_TYPE_YUV &&
+                   yi->stream_size + count > itv->dma_data_req_size)
+                       rc  = ivtv_buf_copy_from_user(s, buf, user_buf,
+                               itv->dma_data_req_size - yi->stream_size);
+               else
+                       rc = ivtv_buf_copy_from_user(s, buf, user_buf, count);
 
+               /* Make sure we really got all the user data */
                if (rc < 0) {
                        ivtv_queue_move(s, &q, NULL, &s->q_free, 0);
                        return rc;
@@ -615,6 +623,16 @@ retry:
                count -= rc;
                bytes_written += rc;
 
+               if (s->type == IVTV_DEC_STREAM_TYPE_YUV) {
+                       yi->stream_size += rc;
+                       /* If we have a complete yuv frame, break loop now */
+                       if (yi->stream_size == itv->dma_data_req_size) {
+                               ivtv_enqueue(s, buf, &s->q_full);
+                               yi->stream_size = 0;
+                               break;
+                       }
+               }
+
                if (buf->bytesused != s->buf_size) {
                        /* incomplete, leave in q_io for next time */
                        ivtv_enqueue(s, buf, &s->q_io);
@@ -922,10 +940,15 @@ static int ivtv_serialized_open(struct ivtv_stream *s, struct file *filp)
        }
 
        /* YUV or MPG Decoding Mode? */
-       if (s->type == IVTV_DEC_STREAM_TYPE_MPG)
+       if (s->type == IVTV_DEC_STREAM_TYPE_MPG) {
                clear_bit(IVTV_F_I_DEC_YUV, &itv->i_flags);
-       else if (s->type == IVTV_DEC_STREAM_TYPE_YUV)
+       } else if (s->type == IVTV_DEC_STREAM_TYPE_YUV) {
                set_bit(IVTV_F_I_DEC_YUV, &itv->i_flags);
+               /* For yuv, we need to know the dma size before we start */
+               itv->dma_data_req_size =
+                               itv->params.width * itv->params.height * 3 / 2;
+               itv->yuv_info.stream_size = 0;
+       }
        return 0;
 }
 
index fd1688e4757dc1fefa51f4a49461a4af0039a3aa..bcf1c85991af38491392b8af18b4dd8e286a448e 100644 (file)
@@ -313,15 +313,28 @@ void ivtv_dma_stream_dec_prepare(struct ivtv_stream *s, u32 offset, int lock)
        IVTV_DEBUG_HI_DMA("DEC PREPARE DMA %s: %08x %08x\n", s->name, s->q_predma.bytesused, offset);
        list_for_each_entry(buf, &s->q_predma.list, list) {
                /* YUV UV Offset from Y Buffer */
-               if (s->type == IVTV_DEC_STREAM_TYPE_YUV && !y_done && bytes_written >= y_size) {
+               if (s->type == IVTV_DEC_STREAM_TYPE_YUV && !y_done &&
+                               (bytes_written + buf->bytesused) >= y_size) {
+                       s->sg_pending[idx].src = buf->dma_handle;
+                       s->sg_pending[idx].dst = offset;
+                       s->sg_pending[idx].size = y_size - bytes_written;
                        offset = uv_offset;
+                       if (s->sg_pending[idx].size != buf->bytesused) {
+                               idx++;
+                               s->sg_pending[idx].src =
+                                 buf->dma_handle + s->sg_pending[idx - 1].size;
+                               s->sg_pending[idx].dst = offset;
+                               s->sg_pending[idx].size =
+                                  buf->bytesused - s->sg_pending[idx - 1].size;
+                               offset += s->sg_pending[idx].size;
+                       }
                        y_done = 1;
+               } else {
+                       s->sg_pending[idx].src = buf->dma_handle;
+                       s->sg_pending[idx].dst = offset;
+                       s->sg_pending[idx].size = buf->bytesused;
+                       offset += buf->bytesused;
                }
-               s->sg_pending[idx].src = buf->dma_handle;
-               s->sg_pending[idx].dst = offset;
-               s->sg_pending[idx].size = buf->bytesused;
-
-               offset += buf->bytesused;
                bytes_written += buf->bytesused;
 
                /* Sync SG buffers */