blob: 20fdbbce49c0111f70e174e23b1c441fd0fa4d05
1 | #ifndef AML_MPEG12_PARSER_H |
2 | #define AML_MPEG12_PARSER_H |
3 | |
4 | #include "../utils/pixfmt.h" |
5 | #include "../utils/common.h" |
6 | #include "../utils/get_bits.h" |
7 | #include "../utils/put_bits.h" |
8 | |
9 | #define FF_PROFILE_MJPEG_HUFFMAN_BASELINE_DCT 0xc0 |
10 | #define FF_PROFILE_MJPEG_HUFFMAN_EXTENDED_SEQUENTIAL_DCT 0xc1 |
11 | #define FF_PROFILE_MJPEG_HUFFMAN_PROGRESSIVE_DCT 0xc2 |
12 | #define FF_PROFILE_MJPEG_HUFFMAN_LOSSLESS 0xc3 |
13 | #define FF_PROFILE_MJPEG_JPEG_LS 0xf7 |
14 | |
15 | #define FF_CODEC_PROPERTY_LOSSLESS 0x00000001 |
16 | #define FF_CODEC_PROPERTY_CLOSED_CAPTIONS 0x00000002 |
17 | |
18 | #define MAX_COMPONENTS 4 |
19 | |
20 | /* JPEG marker codes */ |
21 | enum JpegMarker { |
22 | /* start of frame */ |
23 | SOF0 = 0xc0, /* baseline */ |
24 | SOF1 = 0xc1, /* extended sequential, huffman */ |
25 | SOF2 = 0xc2, /* progressive, huffman */ |
26 | SOF3 = 0xc3, /* lossless, huffman */ |
27 | |
28 | SOF5 = 0xc5, /* differential sequential, huffman */ |
29 | SOF6 = 0xc6, /* differential progressive, huffman */ |
30 | SOF7 = 0xc7, /* differential lossless, huffman */ |
31 | JPG = 0xc8, /* reserved for JPEG extension */ |
32 | SOF9 = 0xc9, /* extended sequential, arithmetic */ |
33 | SOF10 = 0xca, /* progressive, arithmetic */ |
34 | SOF11 = 0xcb, /* lossless, arithmetic */ |
35 | |
36 | SOF13 = 0xcd, /* differential sequential, arithmetic */ |
37 | SOF14 = 0xce, /* differential progressive, arithmetic */ |
38 | SOF15 = 0xcf, /* differential lossless, arithmetic */ |
39 | |
40 | DHT = 0xc4, /* define huffman tables */ |
41 | |
42 | DAC = 0xcc, /* define arithmetic-coding conditioning */ |
43 | |
44 | /* restart with modulo 8 count "m" */ |
45 | RST0 = 0xd0, |
46 | RST1 = 0xd1, |
47 | RST2 = 0xd2, |
48 | RST3 = 0xd3, |
49 | RST4 = 0xd4, |
50 | RST5 = 0xd5, |
51 | RST6 = 0xd6, |
52 | RST7 = 0xd7, |
53 | |
54 | SOI = 0xd8, /* start of image */ |
55 | EOI = 0xd9, /* end of image */ |
56 | SOS = 0xda, /* start of scan */ |
57 | DQT = 0xdb, /* define quantization tables */ |
58 | DNL = 0xdc, /* define number of lines */ |
59 | DRI = 0xdd, /* define restart interval */ |
60 | DHP = 0xde, /* define hierarchical progression */ |
61 | EXP = 0xdf, /* expand reference components */ |
62 | |
63 | APP0 = 0xe0, |
64 | APP1 = 0xe1, |
65 | APP2 = 0xe2, |
66 | APP3 = 0xe3, |
67 | APP4 = 0xe4, |
68 | APP5 = 0xe5, |
69 | APP6 = 0xe6, |
70 | APP7 = 0xe7, |
71 | APP8 = 0xe8, |
72 | APP9 = 0xe9, |
73 | APP10 = 0xea, |
74 | APP11 = 0xeb, |
75 | APP12 = 0xec, |
76 | APP13 = 0xed, |
77 | APP14 = 0xee, |
78 | APP15 = 0xef, |
79 | |
80 | JPG0 = 0xf0, |
81 | JPG1 = 0xf1, |
82 | JPG2 = 0xf2, |
83 | JPG3 = 0xf3, |
84 | JPG4 = 0xf4, |
85 | JPG5 = 0xf5, |
86 | JPG6 = 0xf6, |
87 | SOF48 = 0xf7, ///< JPEG-LS |
88 | LSE = 0xf8, ///< JPEG-LS extension parameters |
89 | JPG9 = 0xf9, |
90 | JPG10 = 0xfa, |
91 | JPG11 = 0xfb, |
92 | JPG12 = 0xfc, |
93 | JPG13 = 0xfd, |
94 | |
95 | COM = 0xfe, /* comment */ |
96 | |
97 | TEM = 0x01, /* temporary private use for arithmetic coding */ |
98 | |
99 | /* 0x02 -> 0xbf reserved */ |
100 | }; |
101 | |
102 | struct VLC { |
103 | int bits; |
104 | short (*table)[2]; ///< code, bits |
105 | int table_size, table_allocated; |
106 | }; |
107 | |
108 | struct MJpegDecodeContext { |
109 | struct get_bits_context gb; |
110 | int buf_size; |
111 | |
112 | int start_code; /* current start code */ |
113 | int buffer_size; |
114 | u8 *buffer; |
115 | |
116 | u16 quant_matrixes[4][64]; |
117 | struct VLC vlcs[3][4]; |
118 | int qscale[4]; ///< quantizer scale calculated from quant_matrixes |
119 | |
120 | int first_picture; /* true if decoding first picture */ |
121 | int interlaced; /* true if interlaced */ |
122 | int bottom_field; /* true if bottom field */ |
123 | int lossless; |
124 | int ls; |
125 | int progressive; |
126 | u8 upscale_h[4]; |
127 | u8 upscale_v[4]; |
128 | int bits; /* bits per component */ |
129 | int adobe_transform; |
130 | |
131 | int width, height; |
132 | int mb_width, mb_height; |
133 | int nb_components; |
134 | int block_stride[MAX_COMPONENTS]; |
135 | int component_id[MAX_COMPONENTS]; |
136 | int h_count[MAX_COMPONENTS]; /* horizontal and vertical count for each component */ |
137 | int v_count[MAX_COMPONENTS]; |
138 | int h_scount[MAX_COMPONENTS]; |
139 | int v_scount[MAX_COMPONENTS]; |
140 | int h_max, v_max; /* maximum h and v counts */ |
141 | int quant_index[4]; /* quant table index for each component */ |
142 | int got_picture; ///< we found a SOF and picture is valid, too. |
143 | int restart_interval; |
144 | int restart_count; |
145 | int cur_scan; /* current scan, used by JPEG-LS */ |
146 | |
147 | // Raw stream data for hwaccel use. |
148 | const u8 *raw_image_buffer; |
149 | int raw_image_buffer_size; |
150 | |
151 | int profile; |
152 | u32 properties; |
153 | }; |
154 | |
155 | struct mjpeg_param_sets { |
156 | bool head_parsed; |
157 | /* currently active parameter sets */ |
158 | struct MJpegDecodeContext dec_ps; |
159 | }; |
160 | |
161 | int mjpeg_decode_extradata_ps(u8 *buf, int size, struct mjpeg_param_sets *ps); |
162 | |
163 | #endif |
164 |