-
Notifications
You must be signed in to change notification settings - Fork 589
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support mips arch for v4l2 source
- Loading branch information
Showing
11 changed files
with
725 additions
and
286 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
//go:build !(linux && (386 || arm || amd64 || arm64)) | ||
//go:build !linux | ||
|
||
package v4l2 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
//go:build linux && (386 || arm || amd64 || arm64) | ||
|
||
package v4l2 | ||
|
||
import ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Build on Ubuntu | ||
|
||
```bash | ||
sudo apt install gcc-x86-64-linux-gnu | ||
sudo apt install gcc-i686-linux-gnu | ||
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 | ||
``` | ||
|
||
## Useful links | ||
|
||
- https://github.com/torvalds/linux/blob/master/include/uapi/linux/videodev2.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
#include <stdio.h> | ||
#include <stddef.h> | ||
#include <linux/videodev2.h> | ||
|
||
#define printconst1(con) printf("\t%s = 0x%08lx\n", #con, con) | ||
#define printconst2(con) printf("\t%s = %d\n", #con, con) | ||
#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) | ||
|
||
int main() { | ||
printf("const (\n"); | ||
printconst1(VIDIOC_QUERYCAP); | ||
printconst1(VIDIOC_ENUM_FMT); | ||
printconst1(VIDIOC_G_FMT); | ||
printconst1(VIDIOC_S_FMT); | ||
printconst1(VIDIOC_REQBUFS); | ||
printconst1(VIDIOC_QUERYBUF); | ||
printf("\n"); | ||
printconst1(VIDIOC_QBUF); | ||
printconst1(VIDIOC_DQBUF); | ||
printconst1(VIDIOC_STREAMON); | ||
printconst1(VIDIOC_STREAMOFF); | ||
printconst1(VIDIOC_G_PARM); | ||
printconst1(VIDIOC_S_PARM); | ||
printf("\n"); | ||
printconst1(VIDIOC_ENUM_FRAMESIZES); | ||
printconst1(VIDIOC_ENUM_FRAMEINTERVALS); | ||
printf(")\n\n"); | ||
|
||
printf("const (\n"); | ||
printconst2(V4L2_BUF_TYPE_VIDEO_CAPTURE); | ||
printconst2(V4L2_COLORSPACE_DEFAULT); | ||
printconst2(V4L2_FIELD_NONE); | ||
printconst2(V4L2_FRMIVAL_TYPE_DISCRETE); | ||
printconst2(V4L2_FRMSIZE_TYPE_DISCRETE); | ||
printconst2(V4L2_MEMORY_MMAP); | ||
printf(")\n\n"); | ||
|
||
printstruct(v4l2_capability); | ||
printmember(v4l2_capability, driver, "[16]byte"); | ||
printmember(v4l2_capability, card, "[32]byte"); | ||
printmember(v4l2_capability, bus_info, "[32]byte"); | ||
printmember(v4l2_capability, version, "uint32"); | ||
printmember(v4l2_capability, capabilities, "uint32"); | ||
printmember(v4l2_capability, device_caps, "uint32"); | ||
printmember(v4l2_capability, reserved, "[3]uint32"); | ||
printf("}\n\n"); | ||
|
||
printstruct(v4l2_format); | ||
printmember(v4l2_format, type, "uint32"); | ||
printalign1(v4l2_format, fmt, type, 4); | ||
printunimem(v4l2_format, fmt, pix, "v4l2_pix_format"); | ||
printfiller(v4l2_format, fmt, sizeof(struct v4l2_pix_format)); | ||
printf("}\n\n"); | ||
|
||
printstruct(v4l2_pix_format); | ||
printmember(v4l2_pix_format, width, "uint32"); | ||
printmember(v4l2_pix_format, height, "uint32"); | ||
printmember(v4l2_pix_format, pixelformat, "uint32"); | ||
printmember(v4l2_pix_format, field, "uint32"); | ||
printmember(v4l2_pix_format, bytesperline, "uint32"); | ||
printmember(v4l2_pix_format, sizeimage, "uint32"); | ||
printmember(v4l2_pix_format, colorspace, "uint32"); | ||
printmember(v4l2_pix_format, priv, "uint32"); | ||
printmember(v4l2_pix_format, flags, "uint32"); | ||
printmember(v4l2_pix_format, ycbcr_enc, "uint32"); | ||
printmember(v4l2_pix_format, quantization, "uint32"); | ||
printmember(v4l2_pix_format, xfer_func, "uint32"); | ||
printf("}\n\n"); | ||
|
||
printstruct(v4l2_streamparm); | ||
printmember(v4l2_streamparm, type, "uint32"); | ||
printunimem(v4l2_streamparm, parm, capture, "v4l2_captureparm"); | ||
printfiller(v4l2_streamparm, parm, sizeof(struct v4l2_captureparm)); | ||
printf("}\n\n"); | ||
|
||
printstruct(v4l2_captureparm); | ||
printmember(v4l2_captureparm, capability, "uint32"); | ||
printmember(v4l2_captureparm, capturemode, "uint32"); | ||
printmember(v4l2_captureparm, timeperframe, "v4l2_fract"); | ||
printmember(v4l2_captureparm, extendedmode, "uint32"); | ||
printmember(v4l2_captureparm, readbuffers, "uint32"); | ||
printmember(v4l2_captureparm, reserved, "[4]uint32"); | ||
printf("}\n\n"); | ||
|
||
printstruct(v4l2_fract); | ||
printmember(v4l2_fract, numerator, "uint32"); | ||
printmember(v4l2_fract, denominator, "uint32"); | ||
printf("}\n\n"); | ||
|
||
printstruct(v4l2_requestbuffers); | ||
printmember(v4l2_requestbuffers, count, "uint32"); | ||
printmember(v4l2_requestbuffers, type, "uint32"); | ||
printmember(v4l2_requestbuffers, memory, "uint32"); | ||
printmember(v4l2_requestbuffers, capabilities, "uint32"); | ||
printmember(v4l2_requestbuffers, flags, "uint8"); | ||
printmember(v4l2_requestbuffers, reserved, "[3]uint8"); | ||
printf("}\n\n"); | ||
|
||
printstruct(v4l2_buffer); | ||
printmember(v4l2_buffer, index, "uint32"); | ||
printmember(v4l2_buffer, type, "uint32"); | ||
printmember(v4l2_buffer, bytesused, "uint32"); | ||
printmember(v4l2_buffer, flags, "uint32"); | ||
printmember(v4l2_buffer, field, "uint32"); | ||
printalign1(v4l2_buffer, timecode, field, 4); | ||
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); | ||
printmember(v4l2_buffer, length, "uint32"); | ||
printfiller(v4l2_buffer, length, 4); | ||
printf("}\n\n"); | ||
|
||
printstruct(v4l2_timecode); | ||
printmember(v4l2_timecode, type, "uint32"); | ||
printmember(v4l2_timecode, flags, "uint32"); | ||
printmember(v4l2_timecode, frames, "uint8"); | ||
printmember(v4l2_timecode, seconds, "uint8"); | ||
printmember(v4l2_timecode, minutes, "uint8"); | ||
printmember(v4l2_timecode, hours, "uint8"); | ||
printmember(v4l2_timecode, userbits, "[4]uint8"); | ||
printf("}\n\n"); | ||
|
||
printstruct(v4l2_fmtdesc); | ||
printmember(v4l2_fmtdesc, index, "uint32"); | ||
printmember(v4l2_fmtdesc, type, "uint32"); | ||
printmember(v4l2_fmtdesc, flags, "uint32"); | ||
printmember(v4l2_fmtdesc, description, "[32]byte"); | ||
printmember(v4l2_fmtdesc, pixelformat, "uint32"); | ||
printmember(v4l2_fmtdesc, mbus_code, "uint32"); | ||
printmember(v4l2_fmtdesc, reserved, "[3]uint32"); | ||
printf("}\n\n"); | ||
|
||
printstruct(v4l2_frmsizeenum); | ||
printmember(v4l2_frmsizeenum, index, "uint32"); | ||
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)); | ||
printf("}\n\n"); | ||
|
||
printstruct(v4l2_frmsize_discrete); | ||
printmember(v4l2_frmsize_discrete, width, "uint32"); | ||
printmember(v4l2_frmsize_discrete, height, "uint32"); | ||
printf("}\n\n"); | ||
|
||
printstruct(v4l2_frmivalenum); | ||
printmember(v4l2_frmivalenum, index, "uint32"); | ||
printmember(v4l2_frmivalenum, pixel_format, "uint32"); | ||
printmember(v4l2_frmivalenum, width, "uint32"); | ||
printmember(v4l2_frmivalenum, height, "uint32"); | ||
printmember(v4l2_frmivalenum, type, "uint32"); | ||
printmember(v4l2_frmivalenum, discrete, "v4l2_fract"); | ||
printfiller(v4l2_frmivalenum, discrete, sizeof(struct v4l2_fract)); | ||
printf("}\n\n"); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
package device | ||
|
||
const ( | ||
VIDIOC_QUERYCAP = 0x80685600 | ||
VIDIOC_ENUM_FMT = 0xc0405602 | ||
VIDIOC_G_FMT = 0xc0cc5604 | ||
VIDIOC_S_FMT = 0xc0cc5605 | ||
VIDIOC_REQBUFS = 0xc0145608 | ||
VIDIOC_QUERYBUF = 0xc0445609 | ||
|
||
VIDIOC_QBUF = 0xc044560f | ||
VIDIOC_DQBUF = 0xc0445611 | ||
VIDIOC_STREAMON = 0x40045612 | ||
VIDIOC_STREAMOFF = 0x40045613 | ||
VIDIOC_G_PARM = 0xc0cc5615 | ||
VIDIOC_S_PARM = 0xc0cc5616 | ||
|
||
VIDIOC_ENUM_FRAMESIZES = 0xc02c564a | ||
VIDIOC_ENUM_FRAMEINTERVALS = 0xc034564b | ||
) | ||
|
||
const ( | ||
V4L2_BUF_TYPE_VIDEO_CAPTURE = 1 | ||
V4L2_COLORSPACE_DEFAULT = 0 | ||
V4L2_FIELD_NONE = 1 | ||
V4L2_FRMIVAL_TYPE_DISCRETE = 1 | ||
V4L2_FRMSIZE_TYPE_DISCRETE = 1 | ||
V4L2_MEMORY_MMAP = 1 | ||
) | ||
|
||
type v4l2_capability struct { // size 104 | ||
driver [16]byte // offset 0, size 16 | ||
card [32]byte // offset 16, size 32 | ||
bus_info [32]byte // offset 48, size 32 | ||
version uint32 // offset 80, size 4 | ||
capabilities uint32 // offset 84, size 4 | ||
device_caps uint32 // offset 88, size 4 | ||
reserved [3]uint32 // offset 92, size 12 | ||
} | ||
|
||
type v4l2_format struct { // size 204 | ||
typ uint32 // offset 0, size 4 | ||
_ [0]byte // align | ||
pix v4l2_pix_format // offset 4, size 48 | ||
_ [152]byte // filler | ||
} | ||
|
||
type v4l2_pix_format struct { // size 48 | ||
width uint32 // offset 0, size 4 | ||
height uint32 // offset 4, size 4 | ||
pixelformat uint32 // offset 8, size 4 | ||
field uint32 // offset 12, size 4 | ||
bytesperline uint32 // offset 16, size 4 | ||
sizeimage uint32 // offset 20, size 4 | ||
colorspace uint32 // offset 24, size 4 | ||
priv uint32 // offset 28, size 4 | ||
flags uint32 // offset 32, size 4 | ||
ycbcr_enc uint32 // offset 36, size 4 | ||
quantization uint32 // offset 40, size 4 | ||
xfer_func uint32 // offset 44, size 4 | ||
} | ||
|
||
type v4l2_streamparm struct { // size 204 | ||
typ uint32 // offset 0, size 4 | ||
capture v4l2_captureparm // offset 4, size 40 | ||
_ [160]byte // filler | ||
} | ||
|
||
type v4l2_captureparm struct { // size 40 | ||
capability uint32 // offset 0, size 4 | ||
capturemode uint32 // offset 4, size 4 | ||
timeperframe v4l2_fract // offset 8, size 8 | ||
extendedmode uint32 // offset 16, size 4 | ||
readbuffers uint32 // offset 20, size 4 | ||
reserved [4]uint32 // offset 24, size 16 | ||
} | ||
|
||
type v4l2_fract struct { // size 8 | ||
numerator uint32 // offset 0, size 4 | ||
denominator uint32 // offset 4, size 4 | ||
} | ||
|
||
type v4l2_requestbuffers struct { // size 20 | ||
count uint32 // offset 0, size 4 | ||
typ uint32 // offset 4, size 4 | ||
memory uint32 // offset 8, size 4 | ||
capabilities uint32 // offset 12, size 4 | ||
flags uint8 // offset 16, size 1 | ||
reserved [3]uint8 // offset 17, size 3 | ||
} | ||
|
||
type v4l2_buffer struct { // size 68 | ||
index uint32 // offset 0, size 4 | ||
typ uint32 // offset 4, size 4 | ||
bytesused uint32 // offset 8, size 4 | ||
flags uint32 // offset 12, size 4 | ||
field uint32 // offset 16, size 4 | ||
_ [8]byte // align | ||
timecode v4l2_timecode // offset 28, size 16 | ||
sequence uint32 // offset 44, size 4 | ||
memory uint32 // offset 48, size 4 | ||
offset uint32 // offset 52, size 4 | ||
_ [0]byte // align | ||
length uint32 // offset 56, size 4 | ||
_ [8]byte // filler | ||
} | ||
|
||
type v4l2_timecode struct { // size 16 | ||
typ uint32 // offset 0, size 4 | ||
flags uint32 // offset 4, size 4 | ||
frames uint8 // offset 8, size 1 | ||
seconds uint8 // offset 9, size 1 | ||
minutes uint8 // offset 10, size 1 | ||
hours uint8 // offset 11, size 1 | ||
userbits [4]uint8 // offset 12, size 4 | ||
} | ||
|
||
type v4l2_fmtdesc struct { // size 64 | ||
index uint32 // offset 0, size 4 | ||
typ uint32 // offset 4, size 4 | ||
flags uint32 // offset 8, size 4 | ||
description [32]byte // offset 12, size 32 | ||
pixelformat uint32 // offset 44, size 4 | ||
mbus_code uint32 // offset 48, size 4 | ||
reserved [3]uint32 // offset 52, size 12 | ||
} | ||
|
||
type v4l2_frmsizeenum struct { // size 44 | ||
index uint32 // offset 0, size 4 | ||
pixel_format uint32 // offset 4, size 4 | ||
typ uint32 // offset 8, size 4 | ||
discrete v4l2_frmsize_discrete // offset 12, size 8 | ||
_ [24]byte // filler | ||
} | ||
|
||
type v4l2_frmsize_discrete struct { // size 8 | ||
width uint32 // offset 0, size 4 | ||
height uint32 // offset 4, size 4 | ||
} | ||
|
||
type v4l2_frmivalenum struct { // size 52 | ||
index uint32 // offset 0, size 4 | ||
pixel_format uint32 // offset 4, size 4 | ||
width uint32 // offset 8, size 4 | ||
height uint32 // offset 12, size 4 | ||
typ uint32 // offset 16, size 4 | ||
discrete v4l2_fract // offset 20, size 8 | ||
_ [24]byte // filler | ||
} |
Oops, something went wrong.