From 773e415dff51a471a83e6a4e3bd227b3c445eb99 Mon Sep 17 00:00:00 2001 From: Alex X Date: Thu, 9 Jan 2025 07:18:36 +0300 Subject: [PATCH] Code refactoring for v4l2 device --- pkg/v4l2/device/README.md | 12 +++++++----- pkg/v4l2/device/{arch.c => videodev2_arch.c} | 20 ++++++++++---------- 2 files changed, 17 insertions(+), 15 deletions(-) rename pkg/v4l2/device/{arch.c => videodev2_arch.c} (88%) diff --git a/pkg/v4l2/device/README.md b/pkg/v4l2/device/README.md index a816b23e..802eca93 100644 --- a/pkg/v4l2/device/README.md +++ b/pkg/v4l2/device/README.md @@ -1,3 +1,5 @@ +# Video For Linux Two + Build on Ubuntu ```bash @@ -7,11 +9,11 @@ sudo apt install gcc-aarch64-linux-gnu binutils sudo apt install gcc-arm-linux-gnueabihf sudo apt install gcc-mipsel-linux-gnu -x86_64-linux-gnu-gcc -w -static arch.c -o arch_x86_64 -i686-linux-gnu-gcc -w -static arch.c -o arch_i686 -aarch64-linux-gnu-gcc -w -static arch.c -o arch_aarch64 -arm-linux-gnueabihf-gcc -w -static arch.c -o arch_armhf -mipsel-linux-gnu-gcc -static arch.c -o arch_mipsel +x86_64-linux-gnu-gcc -w -static videodev2_arch.c -o videodev2_x86_64 +i686-linux-gnu-gcc -w -static videodev2_arch.c -o videodev2_i686 +aarch64-linux-gnu-gcc -w -static videodev2_arch.c -o videodev2_aarch64 +arm-linux-gnueabihf-gcc -w -static videodev2_arch.c -o videodev2_armhf +mipsel-linux-gnu-gcc -w -static videodev2_arch.c -o videodev2_mipsel ``` ## Useful links diff --git a/pkg/v4l2/device/arch.c b/pkg/v4l2/device/videodev2_arch.c similarity index 88% rename from pkg/v4l2/device/arch.c rename to pkg/v4l2/device/videodev2_arch.c index 0b119584..1053a088 100644 --- a/pkg/v4l2/device/arch.c +++ b/pkg/v4l2/device/videodev2_arch.c @@ -7,8 +7,8 @@ #define printstruct(str) printf("type %s struct { // size %lu\n", #str, sizeof(struct str)) #define printmember(str, mem, typ) printf("\t%s %s // offset %lu, size %lu\n", #mem == "type" ? "typ" : #mem, typ, offsetof(struct str, mem), sizeof((struct str){0}.mem)) #define printunimem(str, uni, mem, typ) printf("\t%s %s // offset %lu, size %lu\n", #mem, typ, offsetof(struct str, uni.mem), sizeof((struct str){0}.uni.mem)) -#define printalign1(str, mem2, mem1, siz1) printf("\t_ [%lu]byte // align\n", offsetof(struct str, mem2) - offsetof(struct str, mem1) - siz1) -#define printfiller(str, mem1, siz1) printf("\t_ [%lu]byte // filler\n", sizeof(struct str) - offsetof(struct str, mem1) - siz1) +#define printalign1(str, mem2, mem1) printf("\t_ [%lu]byte // align\n", offsetof(struct str, mem2) - offsetof(struct str, mem1) - sizeof((struct str){0}.mem1)) +#define printfiller(str, mem) printf("\t_ [%lu]byte // filler\n", sizeof(struct str) - offsetof(struct str, mem) - sizeof((struct str){0}.mem)) int main() { printf("const (\n"); @@ -51,9 +51,9 @@ int main() { printstruct(v4l2_format); printmember(v4l2_format, type, "uint32"); - printalign1(v4l2_format, fmt, type, 4); + printalign1(v4l2_format, fmt, type); printunimem(v4l2_format, fmt, pix, "v4l2_pix_format"); - printfiller(v4l2_format, fmt, sizeof(struct v4l2_pix_format)); + printfiller(v4l2_format, fmt.pix); printf("}\n\n"); printstruct(v4l2_pix_format); @@ -74,7 +74,7 @@ int main() { printstruct(v4l2_streamparm); printmember(v4l2_streamparm, type, "uint32"); printunimem(v4l2_streamparm, parm, capture, "v4l2_captureparm"); - printfiller(v4l2_streamparm, parm, sizeof(struct v4l2_captureparm)); + printfiller(v4l2_streamparm, parm.capture); printf("}\n\n"); printstruct(v4l2_captureparm); @@ -106,14 +106,14 @@ int main() { printmember(v4l2_buffer, bytesused, "uint32"); printmember(v4l2_buffer, flags, "uint32"); printmember(v4l2_buffer, field, "uint32"); - printalign1(v4l2_buffer, timecode, field, 4); + printalign1(v4l2_buffer, timecode, field); printmember(v4l2_buffer, timecode, "v4l2_timecode"); printmember(v4l2_buffer, sequence, "uint32"); printmember(v4l2_buffer, memory, "uint32"); printunimem(v4l2_buffer, m, offset, "uint32"); - printalign1(v4l2_buffer, length, m, 4); + printalign1(v4l2_buffer, length, m.offset); printmember(v4l2_buffer, length, "uint32"); - printfiller(v4l2_buffer, length, 4); + printfiller(v4l2_buffer, length); printf("}\n\n"); printstruct(v4l2_timecode); @@ -141,7 +141,7 @@ int main() { printmember(v4l2_frmsizeenum, pixel_format, "uint32"); printmember(v4l2_frmsizeenum, type, "uint32"); printmember(v4l2_frmsizeenum, discrete, "v4l2_frmsize_discrete"); - printfiller(v4l2_frmsizeenum, discrete, sizeof(struct v4l2_frmsize_discrete)); + printfiller(v4l2_frmsizeenum, discrete); printf("}\n\n"); printstruct(v4l2_frmsize_discrete); @@ -156,7 +156,7 @@ int main() { printmember(v4l2_frmivalenum, height, "uint32"); printmember(v4l2_frmivalenum, type, "uint32"); printmember(v4l2_frmivalenum, discrete, "v4l2_fract"); - printfiller(v4l2_frmivalenum, discrete, sizeof(struct v4l2_fract)); + printfiller(v4l2_frmivalenum, discrete); printf("}\n\n"); return 0;