Coverage for linuxpy/codegen/video.py: 0%

10 statements  

« prev     ^ index     » next       coverage.py v7.6.8, created at 2025-05-27 13:54 +0200

1# 

2# This file is part of the linuxpy project 

3# 

4# Copyright (c) 2023 Tiago Coutinho 

5# Distributed under the GPLv3 license. See LICENSE for more info. 

6 

7import pathlib 

8 

9from .base import CEnum, run 

10 

11this_dir = pathlib.Path(__file__).parent 

12 

13 

14HEADERS = [ 

15 "/usr/include/linux/v4l2-common.h", 

16 "/usr/include/linux/v4l2-controls.h", 

17 "/usr/include/linux/videodev2.h", 

18 "/usr/include/linux/v4l2-mediabus.h", 

19 "/usr/include/linux/v4l2-dv-timings.h", 

20 "/usr/include/linux/v4l2-subdev.h", 

21] 

22 

23 

24TEMPLATE = """\ 

25# 

26# This file is part of the linuxpy project 

27# 

28# Copyright (c) 2023 Tiago Coutinho 

29# Distributed under the GPLv3 license. See LICENSE for more info. 

30 

31# This file has been generated by {name} 

32# Date: {date} 

33# System: {system} 

34# Release: {release} 

35# Version: {version} 

36 

37import enum 

38 

39from linuxpy.ctypes import ( 

40 POINTER, 

41 Struct, 

42 Union, 

43 cchar, 

44 cint, 

45 clonglong, 

46 cuint, 

47 culong, 

48 culonglong, 

49 i16, 

50 timespec, 

51 timeval, 

52 u8, 

53 u16, 

54 u32, 

55 u64, 

56) 

57from linuxpy.ioctl import IO as _IO, IOR as _IOR, IOW as _IOW, IOWR as _IOWR 

58from linuxpy.video.util import v4l2_fourcc, v4l2_fourcc_be 

59 

60v4l2_std_id = u64 

61 

62{enums_body} 

63 

64 

65{structs_body} 

66 

67# STD macros are too complicated to auto generate 

68 

69class StandardID(enum.IntFlag): 

70 PAL_B = 0x00000001 

71 PAL_B1 = 0x00000002 

72 PAL_G = 0x00000004 

73 PAL_H = 0x00000008 

74 PAL_I = 0x00000010 

75 PAL_D = 0x00000020 

76 PAL_D1 = 0x00000040 

77 PAL_K = 0x00000080 

78 PAL_M = 0x00000100 

79 PAL_N = 0x00000200 

80 PAL_Nc = 0x00000400 

81 PAL_60 = 0x00000800 

82 NTSC_M = 0x00001000 # BTSC 

83 NTSC_M_JP = 0x00002000 # EIA-J 

84 NTSC_443 = 0x00004000 

85 NTSC_M_KR = 0x00008000 # FM A2 

86 SECAM_B = 0x00010000 

87 SECAM_D = 0x00020000 

88 SECAM_G = 0x00040000 

89 SECAM_H = 0x00080000 

90 SECAM_K = 0x00100000 

91 SECAM_K1 = 0x00200000 

92 SECAM_L = 0x00400000 

93 SECAM_LC = 0x00800000 

94 ATSC_8_VSB = 0x01000000 

95 ATSC_16_VSB = 0x02000000 

96 

97{iocs_body}""" 

98 

99 

100# macros from #define statements 

101MACRO_ENUMS = [ 

102 CEnum("SelectionFlag", "V4L2_SEL_FLAG_", "IntFlag"), 

103 CEnum("SelectionTarget", "V4L2_SEL_TGT_"), 

104 CEnum("Capability", "V4L2_CAP_", "IntFlag"), 

105 CEnum("PixelFormat", "V4L2_PIX_FMT_"), 

106 CEnum("MetaFormat", "V4L2_META_FMT_"), 

107 CEnum("TouchFormat", "V4L2_TCH_FMT_"), 

108 CEnum("SDRFormat", "V4L2_SDR_FMT_"), 

109 CEnum("BufferFlag", "V4L2_BUF_FLAG_", "IntFlag"), 

110 CEnum("ImageFormatFlag", "V4L2_FMT_FLAG_", "IntFlag"), 

111 CEnum("InputStatus", "V4L2_IN_ST_", "IntFlag"), 

112 CEnum("InputType", "V4L2_INPUT_TYPE_"), 

113 CEnum("OutputType", "V4L2_OUTPUT_TYPE_"), 

114 CEnum("InputCapabilities", "V4L2_IN_CAP_", "IntFlag"), 

115 CEnum("OutputCapabilities", "V4L2_OUT_CAP_", "IntFlag"), 

116 CEnum("ControlClass", "V4L2_CTRL_CLASS_"), 

117 CEnum("ControlID", "V4L2_CID_"), 

118 CEnum("ControlFlag", "V4L2_CTRL_FLAG_", "IntFlag"), 

119 CEnum("ControlWhichValue", "V4L2_CTRL_WHICH_"), 

120 CEnum("TimeCodeType", "V4L2_TC_TYPE_"), 

121 CEnum("TimeCodeFlag", "V4L2_TC_FLAG_", "IntFlag"), 

122 CEnum("EventSubscriptionFlag", "V4L2_EVENT_SUB_FL_", "IntFlag"), 

123 CEnum("EventControlChange", "V4L2_EVENT_CTRL_CH_"), 

124 CEnum("EventType", "V4L2_EVENT_"), 

125 CEnum("MbusFrameFormatFlag", "V4L2_MBUS_FRAMEFMT_", "IntFlag"), 

126 # It is very dificult to match just only these two values using prefix, so put whole name there 

127 CEnum("Interlaced", ["V4L2_DV_PROGRESSIVE", "V4L2_DV_INTERLACED"], with_prefix=True), 

128 # It is very dificult to match just only these two values using prefix, so put whole name there 

129 CEnum("PositivePolarityFlag", ["V4L2_DV_VSYNC_POS_POL", "V4L2_DV_HSYNC_POS_POL"], "IntFlag", with_prefix=True), 

130 CEnum("DVTimingsStandardFlag", "V4L2_DV_BT_STD_", "IntFlag"), 

131 CEnum("DVTimingsFlag", "V4L2_DV_FL_", "IntFlag"), 

132 CEnum("DVTimingsCapabilities", "V4L2_DV_BT_CAP_", "IntFlag"), 

133 CEnum("IOC", "VIDIOC_"), 

134] 

135 

136 

137def main(output=this_dir.parent / "video" / "raw.py"): 

138 run(__name__, HEADERS, TEMPLATE, MACRO_ENUMS, output=output) 

139 

140 

141if __name__ == "__main__": 

142 main()