aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/v4l2-core/v4l2-common.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/v4l2-core/v4l2-common.c')
-rw-r--r--drivers/media/v4l2-core/v4l2-common.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/drivers/media/v4l2-core/v4l2-common.c b/drivers/media/v4l2-core/v4l2-common.c
index a5ea1f5..9faa775 100644
--- a/drivers/media/v4l2-core/v4l2-common.c
+++ b/drivers/media/v4l2-core/v4l2-common.c
@@ -405,3 +405,75 @@ void v4l2_get_timestamp(struct timeval *tv)
tv->tv_usec = ts.tv_nsec / NSEC_PER_USEC;
}
EXPORT_SYMBOL_GPL(v4l2_get_timestamp);
+
+void v4l2_ext_buffer_to_buffer(const struct v4l2_ext_buffer *e,
+ struct v4l2_buffer *b)
+{
+ u64 nsecs;
+
+ b->index = e->index;
+ b->type = e->type;
+ b->flags = e->flags;
+ b->field = e->field;
+ b->sequence = e->sequence;
+ b->memory = e->memory;
+ b->timestamp.tv_sec = div64_u64_rem(e->timestamp, NSEC_PER_SEC, &nsecs);
+ b->timestamp.tv_usec = (u32)nsecs / NSEC_PER_USEC;
+ if (V4L2_TYPE_IS_MULTIPLANAR(b->type)) {
+ unsigned int i;
+
+ b->length = e->num_planes;
+ for (i = 0; i < e->num_planes; i++) {
+ b->m.planes[i].length = e->planes[i].length;
+ b->m.planes[i].bytesused = e->planes[i].bytesused;
+ b->m.planes[i].m.userptr = e->planes[i].m.userptr;
+ b->m.planes[i].data_offset = e->planes[i].data_offset;
+ memset(b->m.planes[i].reserved, 0,
+ sizeof(b->m.planes[i].reserved));
+ }
+ } else {
+ b->bytesused = e->planes[0].bytesused;
+ b->length = e->planes[0].length;
+ b->m.userptr = e->planes[0].m.userptr;
+ }
+ b->reserved2 = b->reserved = 0;
+ memset(&b->timecode, 0, sizeof(b->timecode));
+}
+EXPORT_SYMBOL_GPL(v4l2_ext_buffer_to_buffer);
+
+int v4l2_buffer_to_ext_buffer(const struct v4l2_buffer *b,
+ struct v4l2_ext_buffer *e)
+{
+ e->index = b->index;
+ e->type = b->type;
+ e->flags = b->flags;
+ e->field = b->field;
+ e->sequence = b->sequence;
+ e->memory = b->memory;
+ e->timestamp = b->timestamp.tv_sec * NSEC_PER_SEC +
+ b->timestamp.tv_usec * NSEC_PER_USEC;
+ if (V4L2_TYPE_IS_MULTIPLANAR(b->type)) {
+ unsigned int i;
+
+ if (b->m.planes == NULL)
+ return -EINVAL;
+ e->num_planes = b->length;
+ for (i = 0; i < e->num_planes; i++) {
+ e->planes[i].length = b->m.planes[i].length;
+ e->planes[i].bytesused = b->m.planes[i].bytesused;
+ e->planes[i].m.userptr = b->m.planes[i].m.userptr;
+ e->planes[i].data_offset = b->m.planes[i].data_offset;
+ memset(e->planes[i].reserved, 0,
+ sizeof(e->planes[i].reserved));
+ }
+ } else {
+ e->num_planes = 1;
+ e->planes[0].bytesused = b->bytesused;
+ e->planes[0].length = b->length;
+ e->planes[0].m.userptr = b->m.userptr;
+ e->planes[0].data_offset = 0;
+ }
+ memset(&e->reserved, 0, sizeof(e->reserved));
+ return 0;
+}
+EXPORT_SYMBOL_GPL(v4l2_buffer_to_ext_buffer);

Privacy Policy