[media] vb2: Add support for non monotonic timestamps
authorKamil Debski <k.debski@samsung.com>
Fri, 25 Jan 2013 09:29:57 +0000 (06:29 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Tue, 5 Mar 2013 17:53:05 +0000 (14:53 -0300)
Not all drivers use monotonic timestamps. This patch adds a way to set the
timestamp type per every queue.
In addition, set proper timestamp type in drivers that I am sure that use
either MONOTONIC or COPY timestamps. Other drivers will correctly report
UNKNOWN timestamp type instead of assuming that all drivers use monotonic
timestamps.

Signed-off-by: Kamil Debski <k.debski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Reviewed-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
18 files changed:
drivers/media/platform/blackfin/bfin_capture.c
drivers/media/platform/davinci/vpbe_display.c
drivers/media/platform/davinci/vpif_capture.c
drivers/media/platform/davinci/vpif_display.c
drivers/media/platform/s3c-camif/camif-capture.c
drivers/media/platform/s5p-fimc/fimc-capture.c
drivers/media/platform/s5p-fimc/fimc-lite.c
drivers/media/platform/s5p-mfc/s5p_mfc.c
drivers/media/platform/soc_camera/atmel-isi.c
drivers/media/platform/soc_camera/mx2_camera.c
drivers/media/platform/soc_camera/mx3_camera.c
drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c
drivers/media/platform/vivi.c
drivers/media/usb/pwc/pwc-if.c
drivers/media/usb/stk1160/stk1160-v4l.c
drivers/media/usb/uvc/uvc_queue.c
drivers/media/v4l2-core/videobuf2-core.c
include/media/videobuf2-core.h

index 5f209d5810dc9f43bfa3b225f76b9d914030803f..8ffe42aabd85b9af7cb004e6ea2640b5b7945c4c 100644 (file)
@@ -1029,6 +1029,7 @@ static int bcap_probe(struct platform_device *pdev)
        q->buf_struct_size = sizeof(struct bcap_buffer);
        q->ops = &bcap_video_qops;
        q->mem_ops = &vb2_dma_contig_memops;
+       q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 
        vb2_queue_init(q);
 
index 5e6b0cab514b3f9be8321367bef86da849766c05..9f9f2c1a073f838cda52ad8caef82869ac57e0e7 100644 (file)
@@ -1404,6 +1404,7 @@ static int vpbe_display_reqbufs(struct file *file, void *priv,
        q->ops = &video_qops;
        q->mem_ops = &vb2_dma_contig_memops;
        q->buf_struct_size = sizeof(struct vpbe_disp_buffer);
+       q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 
        ret = vb2_queue_init(q);
        if (ret) {
index 5892d2bc8eeef5d844d53f144bca0ea35f1fde7a..1943e41f386628f5c8772c3b320c72e3d1fa5e7e 100644 (file)
@@ -1035,6 +1035,7 @@ static int vpif_reqbufs(struct file *file, void *priv,
        q->ops = &video_qops;
        q->mem_ops = &vb2_dma_contig_memops;
        q->buf_struct_size = sizeof(struct vpif_cap_buffer);
+       q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 
        ret = vb2_queue_init(q);
        if (ret) {
index dd249c96126dee69e6fd883f0459eefc26418baf..5477c2cb8653c199a893f35850f0ba618ae6f651 100644 (file)
@@ -1001,6 +1001,7 @@ static int vpif_reqbufs(struct file *file, void *priv,
        q->ops = &video_qops;
        q->mem_ops = &vb2_dma_contig_memops;
        q->buf_struct_size = sizeof(struct vpif_disp_buffer);
+       q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 
        ret = vb2_queue_init(q);
        if (ret) {
index a55793c3d8119904d473e179b3c3a98fde5ddb19..e91f350929ebef3f7bc29253531812ca1a85f82c 100644 (file)
@@ -1153,6 +1153,7 @@ int s3c_camif_register_video_node(struct camif_dev *camif, int idx)
        q->mem_ops = &vb2_dma_contig_memops;
        q->buf_struct_size = sizeof(struct camif_buffer);
        q->drv_priv = vp;
+       q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 
        ret = vb2_queue_init(q);
        if (ret)
index f553cc2a8ee8df146f8e300c7ace7171feb81ecc..87b68420f7716c7d8ff17f17bfd7fd5334feea67 100644 (file)
@@ -1797,6 +1797,7 @@ static int fimc_register_capture_device(struct fimc_dev *fimc,
        q->ops = &fimc_capture_qops;
        q->mem_ops = &vb2_dma_contig_memops;
        q->buf_struct_size = sizeof(struct fimc_vid_buffer);
+       q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 
        ret = vb2_queue_init(q);
        if (ret)
index bfc4206935c85a93fa75b6893e3afdcc8efb7c92..47fbf7bcf608fcd405df9a647b48a06dbd68a36f 100644 (file)
@@ -1325,6 +1325,7 @@ static int fimc_lite_subdev_registered(struct v4l2_subdev *sd)
        q->mem_ops = &vb2_dma_contig_memops;
        q->buf_struct_size = sizeof(struct flite_buffer);
        q->drv_priv = fimc;
+       q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 
        ret = vb2_queue_init(q);
        if (ret < 0)
index e84703c314ce0d50a9861cf674244b9a3342615f..92c6bf11af7411cf37f476d0b020b5276a790c25 100644 (file)
@@ -804,6 +804,7 @@ static int s5p_mfc_open(struct file *file)
                goto err_queue_init;
        }
        q->mem_ops = (struct vb2_mem_ops *)&vb2_dma_contig_memops;
+       q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_COPY;
        ret = vb2_queue_init(q);
        if (ret) {
                mfc_err("Failed to initialize videobuf2 queue(capture)\n");
@@ -825,6 +826,7 @@ static int s5p_mfc_open(struct file *file)
                goto err_queue_init;
        }
        q->mem_ops = (struct vb2_mem_ops *)&vb2_dma_contig_memops;
+       q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_COPY;
        ret = vb2_queue_init(q);
        if (ret) {
                mfc_err("Failed to initialize videobuf2 queue(output)\n");
index 82dbf99d347cc0b5d6b540ff338e6b8f4e2bc545..c314ff9b98dc51a3dbe5e4eba58c790829b9e1ac 100644 (file)
@@ -514,6 +514,7 @@ static int isi_camera_init_videobuf(struct vb2_queue *q,
        q->buf_struct_size = sizeof(struct frame_buffer);
        q->ops = &isi_video_qops;
        q->mem_ops = &vb2_dma_contig_memops;
+       q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 
        return vb2_queue_init(q);
 }
index ffba7d91f413acc9ac8f87e9d87e694fa619321c..048c26a27c341f3839e31bf9dbfa59b9533ea768 100644 (file)
@@ -797,6 +797,7 @@ static int mx2_camera_init_videobuf(struct vb2_queue *q,
        q->ops = &mx2_videobuf_ops;
        q->mem_ops = &vb2_dma_contig_memops;
        q->buf_struct_size = sizeof(struct mx2_buffer);
+       q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 
        return vb2_queue_init(q);
 }
index f5cbb92db545002e2f818c0257bb098851421ef4..2c3bd69fb38c909a64dc7cae8ef2fee944e94031 100644 (file)
@@ -455,6 +455,7 @@ static int mx3_camera_init_videobuf(struct vb2_queue *q,
        q->ops = &mx3_videobuf_ops;
        q->mem_ops = &vb2_dma_contig_memops;
        q->buf_struct_size = sizeof(struct mx3_camera_buffer);
+       q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 
        return vb2_queue_init(q);
 }
index bb08a46432f4e7493eaac8baad8ad974c54d67eb..973e72b24fa85f91ef86747826e76f765b340672 100644 (file)
@@ -2026,6 +2026,7 @@ static int sh_mobile_ceu_init_videobuf(struct vb2_queue *q,
        q->ops = &sh_mobile_ceu_videobuf_ops;
        q->mem_ops = &vb2_dma_contig_memops;
        q->buf_struct_size = sizeof(struct sh_mobile_ceu_buffer);
+       q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 
        return vb2_queue_init(q);
 }
index 8a33a712f480fe160b10fdaff32d01155aadfbe7..c46d2e8677a5b93e783b81a01672ec48ee9b2d55 100644 (file)
@@ -1429,6 +1429,7 @@ static int __init vivi_create_instance(int inst)
        q->buf_struct_size = sizeof(struct vivi_buffer);
        q->ops = &vivi_video_qops;
        q->mem_ops = &vb2_vmalloc_memops;
+       q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 
        ret = vb2_queue_init(q);
        if (ret)
index 5ec15cb1ed2608aeb5e7a58f2f9d00e0e558be90..77bbf788965953bbc67f8fa8b3ab18ccbe5806d8 100644 (file)
@@ -1001,6 +1001,7 @@ static int usb_pwc_probe(struct usb_interface *intf, const struct usb_device_id
        pdev->vb_queue.buf_struct_size = sizeof(struct pwc_frame_buf);
        pdev->vb_queue.ops = &pwc_vb_queue_ops;
        pdev->vb_queue.mem_ops = &vb2_vmalloc_memops;
+       pdev->vb_queue.timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
        rc = vb2_queue_init(&pdev->vb_queue);
        if (rc < 0) {
                PWC_ERROR("Oops, could not initialize vb2 queue.\n");
index 6694f9e2ca576c59fd0028992036b8cea101af04..5307a63e378fc57e60b8f6652d181a36a7391b31 100644 (file)
@@ -687,6 +687,7 @@ int stk1160_vb2_setup(struct stk1160 *dev)
        q->buf_struct_size = sizeof(struct stk1160_buffer);
        q->ops = &stk1160_video_qops;
        q->mem_ops = &vb2_vmalloc_memops;
+       q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 
        rc = vb2_queue_init(q);
        if (rc < 0)
index 6c233a54ce4095769a4f269c3d5b042627e5e6b3..cd962be860ca3ac14d87dfca467cce021cfa8f4f 100644 (file)
@@ -149,6 +149,7 @@ int uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type,
        queue->queue.buf_struct_size = sizeof(struct uvc_buffer);
        queue->queue.ops = &uvc_queue_qops;
        queue->queue.mem_ops = &vb2_vmalloc_memops;
+       queue->queue.timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
        ret = vb2_queue_init(&queue->queue);
        if (ret)
                return ret;
index db1235dcb3280e71413ad946be39163a6b3c3b2a..be0448161c60035cccd868dda1cd5937938e9ffd 100644 (file)
@@ -403,7 +403,7 @@ static void __fill_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b)
         * Clear any buffer state related flags.
         */
        b->flags &= ~V4L2_BUFFER_MASK_FLAGS;
-       b->flags |= V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
+       b->flags |= q->timestamp_type;
 
        switch (vb->state) {
        case VB2_BUF_STATE_QUEUED:
@@ -2039,9 +2039,13 @@ int vb2_queue_init(struct vb2_queue *q)
            WARN_ON(!q->type)             ||
            WARN_ON(!q->io_modes)         ||
            WARN_ON(!q->ops->queue_setup) ||
-           WARN_ON(!q->ops->buf_queue))
+           WARN_ON(!q->ops->buf_queue)   ||
+           WARN_ON(q->timestamp_type & ~V4L2_BUF_FLAG_TIMESTAMP_MASK))
                return -EINVAL;
 
+       /* Warn that the driver should choose an appropriate timestamp type */
+       WARN_ON(q->timestamp_type == V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN);
+
        INIT_LIST_HEAD(&q->queued_list);
        INIT_LIST_HEAD(&q->done_list);
        spin_lock_init(&q->done_lock);
index 9cfd4ee9e56f1eb7dec09704b15a4fabcbb976a4..a2d4274507805cbda90b10b0aa653d05cb2c8059 100644 (file)
@@ -326,6 +326,7 @@ struct vb2_queue {
        const struct vb2_mem_ops        *mem_ops;
        void                            *drv_priv;
        unsigned int                    buf_struct_size;
+       u32                             timestamp_type;
 
 /* private: internal use only */
        enum v4l2_memory                memory;