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