Commit 858b92a1 authored by André Almeida's avatar André Almeida

Refactor buf operators and debug messages

parent fbe8e367
......@@ -87,6 +87,11 @@ void v4l2_s_fmt(int fd, struct context ctx){
fmt.fmt.pix_mp.pixelformat = ctx.pix_format;
fmt.fmt.pix_mp.num_planes = ctx.num_planes;
/* doesn't make difference, driver overwrite this data */
fmt.fmt.pix_mp.plane_fmt[0].sizeimage = 230400;
fmt.fmt.pix_mp.plane_fmt[1].sizeimage = 57600;
fmt.fmt.pix_mp.plane_fmt[2].sizeimage = 57600;
xioctl(fd, VIDIOC_S_FMT, &fmt);
}
......@@ -154,23 +159,30 @@ void v4l2_reqbuf(int fd, struct context ctx){
}
}
void v4l2_querybuf(int fd, struct context ctx, int i, struct v4l2_plane *planes, struct v4l2_buffer *buf){
void v4l2_querybuf(int fd, struct context ctx, int index, struct v4l2_plane *planes, struct v4l2_buffer *buf){
CLEAR(*buf);
CLEAR(*planes);
buf->type = ctx.buf_type;
buf->memory = ctx.mem_type;
buf->index = i;
buf->type = ctx.buf_type;
buf->memory = ctx.mem_type;
buf->index = index;
buf->m.planes = planes;
buf->length = ctx.num_planes;
xioctl(fd, VIDIOC_QUERYBUF, buf);
#ifdef DBG_PRINT
printf("buffer queried: %d\n", index);
for(int i = 0; i < ctx.num_planes; i++)
printf("plane[%d].length = %u\n", i,
buf->m.planes[i].length);
#endif
}
/* enqueue buffer of index i */
void v4l2_qbuf(int fd, struct context ctx, int i, struct v4l2_plane *planes, struct v4l2_buffer *buf){
void v4l2_qbuf(int fd, struct context ctx, int index, struct v4l2_plane *planes, struct v4l2_buffer *buf){
CLEAR(*buf);
CLEAR(*planes);
......@@ -179,7 +191,7 @@ void v4l2_qbuf(int fd, struct context ctx, int i, struct v4l2_plane *planes, str
buf->memory = ctx.mem_type;
buf->m.planes = planes;
buf->length = ctx.num_planes;
buf->index = i;
buf->index = index;
xioctl(fd, VIDIOC_QBUF, buf);
}
......@@ -262,11 +274,6 @@ int main(int argc, char **argv)
/* map planes offsets to buffers pointers */
for(j = 0; j < ctx.num_planes; j++){
#ifdef DBG_PRINT
printf("plane leng[%d][%d]: %u\n", i, j,
buf.m.planes[j].length);
#endif
buffers[i].length[j] = buf.m.planes[j].length;
buffers[i].start[j] = mmap(NULL, buffers[i].length[j],
PROT_READ | PROT_WRITE, MAP_SHARED,
......@@ -319,10 +326,13 @@ int main(int argc, char **argv)
/* dequeue buffer */
int index = v4l2_dqbuf(fd, ctx, planes, &buf);
/* query the dequeued buffer */
v4l2_querybuf(fd, ctx, index, planes, &buf);
/* write each plane in the file */
for(j = 0; j < ctx.num_planes; j++){
#ifdef DBG_PRINT
printf("bytesused: %d\n", buf.m.planes[j].bytesused);
printf("bytesused[%d]: %d\n", j, buf.m.planes[j].bytesused);
#endif
fwrite(buffers[buf.index].start[j],
......
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