Skip to content

Commit 959c3ef

Browse files
Junghak Sungmchehab
authored andcommitted
[media] media: videobuf2: Add copy_timestamp to struct vb2_queue
Add copy_timestamp to struct vb2_queue as a flag set if vb2-core should copy timestamps. Signed-off-by: Junghak Sung <[email protected]> Signed-off-by: Geunyoung Kim <[email protected]> Acked-by: Seung-Woo Kim <[email protected]> Acked-by: Inki Dae <[email protected]> Signed-off-by: Hans Verkuil <[email protected]> Signed-off-by: Mauro Carvalho Chehab <[email protected]>
1 parent d6dd645 commit 959c3ef

File tree

3 files changed

+17
-20
lines changed

3 files changed

+17
-20
lines changed

drivers/media/v4l2-core/videobuf2-core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,7 @@ int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb)
13991399
q->waiting_for_buffers = false;
14001400
vb->state = VB2_BUF_STATE_QUEUED;
14011401

1402-
call_bufop(q, set_timestamp, vb, pb);
1402+
call_bufop(q, copy_timestamp, vb, pb);
14031403

14041404
trace_vb2_qbuf(q, vb);
14051405

drivers/media/v4l2-core/videobuf2-v4l2.c

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ static int __verify_length(struct vb2_buffer *vb, const struct v4l2_buffer *b)
107107
return 0;
108108
}
109109

110-
static int __set_timestamp(struct vb2_buffer *vb, const void *pb)
110+
static int __copy_timestamp(struct vb2_buffer *vb, const void *pb)
111111
{
112112
const struct v4l2_buffer *b = pb;
113113
struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
@@ -118,8 +118,7 @@ static int __set_timestamp(struct vb2_buffer *vb, const void *pb)
118118
* For output buffers copy the timestamp if needed,
119119
* and the timecode field and flag if needed.
120120
*/
121-
if ((q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) ==
122-
V4L2_BUF_FLAG_TIMESTAMP_COPY)
121+
if (q->copy_timestamp)
123122
vb->timestamp = timeval_to_ns(&b->timestamp);
124123
vbuf->flags |= b->flags & V4L2_BUF_FLAG_TIMECODE;
125124
if (b->flags & V4L2_BUF_FLAG_TIMECODE)
@@ -238,8 +237,7 @@ static int __fill_v4l2_buffer(struct vb2_buffer *vb, void *pb)
238237
*/
239238
b->flags &= ~V4L2_BUFFER_MASK_FLAGS;
240239
b->flags |= q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK;
241-
if ((q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) !=
242-
V4L2_BUF_FLAG_TIMESTAMP_COPY) {
240+
if (!q->copy_timestamp) {
243241
/*
244242
* For non-COPY timestamps, drop timestamp source bits
245243
* and obtain the timestamp source from the queue.
@@ -403,8 +401,7 @@ static int __fill_vb2_buffer(struct vb2_buffer *vb,
403401

404402
/* Zero flags that the vb2 core handles */
405403
vbuf->flags = b->flags & ~V4L2_BUFFER_MASK_FLAGS;
406-
if ((vb->vb2_queue->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) !=
407-
V4L2_BUF_FLAG_TIMESTAMP_COPY || !V4L2_TYPE_IS_OUTPUT(b->type)) {
404+
if (!vb->vb2_queue->copy_timestamp || !V4L2_TYPE_IS_OUTPUT(b->type)) {
408405
/*
409406
* Non-COPY timestamps and non-OUTPUT queues will get
410407
* their timestamp and timestamp source flags from the
@@ -433,7 +430,7 @@ static int __fill_vb2_buffer(struct vb2_buffer *vb,
433430
static const struct vb2_buf_ops v4l2_buf_ops = {
434431
.fill_user_buffer = __fill_v4l2_buffer,
435432
.fill_vb2_buffer = __fill_vb2_buffer,
436-
.set_timestamp = __set_timestamp,
433+
.copy_timestamp = __copy_timestamp,
437434
};
438435

439436
/**
@@ -760,6 +757,8 @@ int vb2_queue_init(struct vb2_queue *q)
760757
q->buf_ops = &v4l2_buf_ops;
761758
q->is_multiplanar = V4L2_TYPE_IS_MULTIPLANAR(q->type);
762759
q->is_output = V4L2_TYPE_IS_OUTPUT(q->type);
760+
q->copy_timestamp = (q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK)
761+
== V4L2_BUF_FLAG_TIMESTAMP_COPY;
763762

764763
return vb2_core_queue_init(q);
765764
}
@@ -1114,12 +1113,10 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_
11141113
bool is_multiplanar = q->is_multiplanar;
11151114
/*
11161115
* When using write() to write data to an output video node the vb2 core
1117-
* should set timestamps if V4L2_BUF_FLAG_TIMESTAMP_COPY is set. Nobody
1116+
* should copy timestamps if V4L2_BUF_FLAG_TIMESTAMP_COPY is set. Nobody
11181117
* else is able to provide this information with the write() operation.
11191118
*/
1120-
bool set_timestamp = !read &&
1121-
(q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) ==
1122-
V4L2_BUF_FLAG_TIMESTAMP_COPY;
1119+
bool copy_timestamp = !read && q->copy_timestamp;
11231120
int ret, index;
11241121

11251122
dprintk(3, "mode %s, offset %ld, count %zd, %sblocking\n",
@@ -1236,7 +1233,7 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_
12361233
fileio->b.m.planes = &fileio->p;
12371234
fileio->b.length = 1;
12381235
}
1239-
if (set_timestamp)
1236+
if (copy_timestamp)
12401237
v4l2_get_timestamp(&fileio->b.timestamp);
12411238
ret = vb2_internal_qbuf(q, &fileio->b);
12421239
dprintk(5, "vb2_dbuf result: %d\n", ret);
@@ -1301,16 +1298,14 @@ static int vb2_thread(void *data)
13011298
struct vb2_queue *q = data;
13021299
struct vb2_threadio_data *threadio = q->threadio;
13031300
struct vb2_fileio_data *fileio = q->fileio;
1304-
bool set_timestamp = false;
1301+
bool copy_timestamp = false;
13051302
int prequeue = 0;
13061303
int index = 0;
13071304
int ret = 0;
13081305

13091306
if (q->is_output) {
13101307
prequeue = q->num_buffers;
1311-
set_timestamp =
1312-
(q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) ==
1313-
V4L2_BUF_FLAG_TIMESTAMP_COPY;
1308+
copy_timestamp = q->copy_timestamp;
13141309
}
13151310

13161311
set_freezable();
@@ -1343,7 +1338,7 @@ static int vb2_thread(void *data)
13431338
if (threadio->fnc(vb, threadio->priv))
13441339
break;
13451340
call_void_qop(q, wait_finish, q);
1346-
if (set_timestamp)
1341+
if (copy_timestamp)
13471342
v4l2_get_timestamp(&fileio->b.timestamp);
13481343
if (!threadio->stop)
13491344
ret = vb2_internal_qbuf(q, &fileio->b);

include/media/videobuf2-core.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ struct vb2_buf_ops {
373373
int (*fill_user_buffer)(struct vb2_buffer *vb, void *pb);
374374
int (*fill_vb2_buffer)(struct vb2_buffer *vb, const void *pb,
375375
struct vb2_plane *planes);
376-
int (*set_timestamp)(struct vb2_buffer *vb, const void *pb);
376+
int (*copy_timestamp)(struct vb2_buffer *vb, const void *pb);
377377
};
378378

379379
/**
@@ -436,6 +436,7 @@ struct vb2_buf_ops {
436436
* called since poll() needs to return POLLERR in that situation.
437437
* @is_multiplanar: set if buffer type is multiplanar
438438
* @is_output: set if buffer type is output
439+
* @copy_timestamp: set if vb2-core should set timestamps
439440
* @last_buffer_dequeued: used in poll() and DQBUF to immediately return if the
440441
* last decoded buffer was already dequeued. Set for capture queues
441442
* when a buffer with the V4L2_BUF_FLAG_LAST is dequeued.
@@ -485,6 +486,7 @@ struct vb2_queue {
485486
unsigned int waiting_for_buffers:1;
486487
unsigned int is_multiplanar:1;
487488
unsigned int is_output:1;
489+
unsigned int copy_timestamp:1;
488490
unsigned int last_buffer_dequeued:1;
489491

490492
struct vb2_fileio_data *fileio;

0 commit comments

Comments
 (0)