OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/common/gpu/media/vaapi_jpeg_decoder.h" | |
6 | |
7 #include <algorithm> | |
Owen Lin
2015/01/13 06:17:58
not used?
kcwu
2015/01/16 15:12:54
Done.
| |
8 #include <limits> | |
Owen Lin
2015/01/13 06:17:58
not used?
kcwu
2015/01/16 15:12:54
Done.
| |
9 | |
10 namespace media { | |
11 | |
12 // K.3.3.1 "Specification of typical tables for DC difference coding" | |
13 static JpegHuffmanTable default_dc_table[kJpegMaxHuffmanTableNum_baseline] = { | |
14 // luminance DC coefficients | |
15 { | |
16 true, | |
17 {0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0}, | |
18 {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b}, | |
19 }, | |
20 // chrominance DC coefficients | |
21 { | |
22 true, | |
23 {0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}, | |
24 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb}, | |
25 }, | |
26 }; | |
27 | |
28 // K.3.3.2 "Specification of typical tables for AC coefficient coding" | |
29 static JpegHuffmanTable default_ac_table[kJpegMaxHuffmanTableNum_baseline] = { | |
30 // luminance AC coefficients | |
31 { | |
32 true, | |
33 {0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d}, | |
34 {0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, | |
35 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07, | |
36 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08, | |
37 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0, | |
38 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16, | |
39 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28, | |
40 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, | |
41 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, | |
42 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, | |
43 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, | |
44 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, | |
45 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, | |
46 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, | |
47 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, | |
48 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, | |
49 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5, | |
50 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, | |
51 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2, | |
52 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, | |
53 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, | |
54 0xf9, 0xfa}, | |
55 }, | |
56 // chrominance AC coefficients | |
57 { | |
58 true, | |
59 {0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77}, | |
60 {0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, | |
61 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71, | |
62 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91, | |
63 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0, | |
64 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34, | |
65 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26, | |
66 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38, | |
67 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, | |
68 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, | |
69 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, | |
70 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, | |
71 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, | |
72 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, | |
73 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, | |
74 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, | |
75 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, | |
76 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, | |
77 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, | |
78 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, | |
79 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, | |
80 0xf9, 0xfa}, | |
81 }, | |
82 }; | |
83 | |
84 } // namespace media | |
85 | |
86 namespace content { | |
87 | |
88 VaapiJpegDecoder::VaapiJpegDecoder( | |
89 VaapiWrapper* vaapi_wrapper, | |
wuchengli
2015/01/12 09:08:51
VaapiWrapper creation should be done in this class
kcwu
2015/01/16 15:12:54
This class is modeled after VaapiH264Decoder which
| |
90 const ReportErrorToUmaCB& report_error_to_uma_cb) | |
91 : vaapi_wrapper_(vaapi_wrapper), | |
92 report_error_to_uma_cb_(report_error_to_uma_cb) { | |
93 } | |
94 | |
95 VaapiJpegDecoder::~VaapiJpegDecoder() { | |
96 } | |
97 | |
98 VaapiJpegDecoder::DecodeStatus VaapiJpegDecoder::Decode( | |
99 const uint8* buffer, | |
100 size_t buffer_size, | |
101 gfx::Size* output_size, | |
102 VASurfaceID* output_surface_id) { | |
103 media::JpegParseResult parse_result; | |
104 if (!media::JpegParser::Parse(buffer, buffer_size, &parse_result)) | |
wuchengli
2015/01/12 09:08:52
add a DLOG(ERROR) here.
kcwu
2015/01/16 15:12:54
Done.
| |
105 return PARSE_ERROR; | |
106 | |
107 // Create surfaces | |
wuchengli
2015/01/12 09:08:51
s/surfaces/a surface/. This only creates one surfa
kcwu
2015/01/16 15:12:54
Done.
| |
108 std::vector<VASurfaceID> va_surfaces; | |
109 gfx::Size size(parse_result.visible_width, parse_result.visible_height); | |
110 if (!vaapi_wrapper_->CreateSurfaces(size, 1, &va_surfaces)) | |
wuchengli
2015/01/12 13:48:04
We should reuse the surface to optimize for MJPEG.
Owen Lin
2015/01/13 06:17:58
I believe the difficulty is that we need to parse
kcwu
2015/01/16 15:12:54
Done.
I moved the responsibility of surface creati
| |
111 return VAAPI_ERROR; | |
112 | |
113 // Set picture parameter | |
wuchengli
2015/01/12 09:08:52
Add periods for all comments. s/parameter/paramete
kcwu
2015/01/16 15:12:54
Done.
| |
114 VAPictureParameterBufferJPEGBaseline pic_param; | |
115 memset(&pic_param, 0, sizeof(pic_param)); | |
116 pic_param.picture_width = parse_result.visible_width; | |
117 pic_param.picture_height = parse_result.visible_height; | |
118 pic_param.num_components = parse_result.num_components; | |
119 | |
120 for (int i = 0; i < pic_param.num_components; i++) { | |
121 pic_param.components[i].component_id = parse_result.components[i].id; | |
122 pic_param.components[i].h_sampling_factor = | |
123 parse_result.components[i].horizontal_sampling_factor; | |
124 pic_param.components[i].v_sampling_factor = | |
125 parse_result.components[i].vertical_sampling_factor; | |
126 pic_param.components[i].quantiser_table_selector = | |
127 parse_result.components[i].quantization_table_selector; | |
128 } | |
129 | |
130 if (!vaapi_wrapper_->SubmitBuffer(VAPictureParameterBufferType, | |
131 sizeof(pic_param), &pic_param)) | |
132 return VAAPI_ERROR; | |
133 | |
134 // Set quantization table | |
wuchengli
2015/01/12 09:08:52
Break this function into smaller functions. This f
kcwu
2015/01/16 15:12:54
Done.
| |
135 VAIQMatrixBufferJPEGBaseline iq_matrix; | |
136 memset(&iq_matrix, 0, sizeof(iq_matrix)); | |
137 static_assert(media::kJpegMaxQuantizationTableNum == | |
138 arraysize(iq_matrix.load_quantiser_table), | |
139 "max number of quantization table mismatched"); | |
140 for (size_t i = 0; i < media::kJpegMaxQuantizationTableNum; i++) { | |
141 if (!parse_result.q_table[i].valid) | |
142 continue; | |
143 iq_matrix.load_quantiser_table[i] = 1; | |
144 for (int j = 0; j < 64; j++) | |
145 iq_matrix.quantiser_table[i][j] = parse_result.q_table[i].value[j]; | |
146 } | |
147 | |
148 if (!vaapi_wrapper_->SubmitBuffer(VAIQMatrixBufferType, sizeof(iq_matrix), | |
149 &iq_matrix)) | |
150 return VAAPI_ERROR; | |
151 | |
152 // Use default huffman tables if not specified in header. | |
153 const media::JpegHuffmanTable* dc_table = media::default_dc_table; | |
154 const media::JpegHuffmanTable* ac_table = media::default_ac_table; | |
155 for (size_t i = 0; i < media::kJpegMaxHuffmanTableNum_baseline; i++) { | |
156 if (parse_result.dc_table[i].valid || parse_result.ac_table[i].valid) { | |
157 dc_table = parse_result.dc_table; | |
158 ac_table = parse_result.ac_table; | |
159 break; | |
160 } | |
161 } | |
162 | |
163 // Set huffman table | |
164 VAHuffmanTableBufferJPEGBaseline huffman_table; | |
165 memset(&huffman_table, 0, sizeof(huffman_table)); | |
166 static_assert(media::kJpegMaxHuffmanTableNum_baseline == | |
167 arraysize(huffman_table.load_huffman_table), | |
168 "max number of huffman table mismatched"); | |
169 static_assert(sizeof(huffman_table.huffman_table[0].num_dc_codes) == | |
170 sizeof(dc_table[0].code_length), | |
171 "size of huffman table code length mismatch"); | |
172 static_assert(sizeof(huffman_table.huffman_table[0].dc_values[0]) == | |
173 sizeof(dc_table[0].code_value[0]), | |
174 "size of huffman table code value mismatch"); | |
175 for (size_t i = 0; i < media::kJpegMaxHuffmanTableNum_baseline; i++) { | |
176 if (!dc_table[i].valid || !ac_table[i].valid) | |
177 continue; | |
178 huffman_table.load_huffman_table[i] = 1; | |
179 | |
180 memcpy(huffman_table.huffman_table[i].num_dc_codes, dc_table[i].code_length, | |
181 sizeof(huffman_table.huffman_table[i].num_dc_codes)); | |
182 memcpy(huffman_table.huffman_table[i].dc_values, dc_table[i].code_value, | |
183 sizeof(huffman_table.huffman_table[i].dc_values)); | |
184 memcpy(huffman_table.huffman_table[i].num_ac_codes, ac_table[i].code_length, | |
185 sizeof(huffman_table.huffman_table[i].num_ac_codes)); | |
186 memcpy(huffman_table.huffman_table[i].ac_values, ac_table[i].code_value, | |
187 sizeof(huffman_table.huffman_table[i].ac_values)); | |
188 } | |
189 | |
190 if (!vaapi_wrapper_->SubmitBuffer(VAHuffmanTableBufferType, | |
191 sizeof(huffman_table), &huffman_table)) | |
192 return VAAPI_ERROR; | |
193 | |
194 // Set slice parameter | |
195 VASliceParameterBufferJPEGBaseline slice_param; | |
196 memset(&slice_param, 0, sizeof(slice_param)); | |
197 int max_h_factor = parse_result.components[0].horizontal_sampling_factor; | |
198 int max_v_factor = parse_result.components[0].vertical_sampling_factor; | |
199 slice_param.slice_data_size = parse_result.scan.data_size; | |
200 slice_param.slice_data_offset = 0; | |
201 slice_param.slice_data_flag = VA_SLICE_DATA_FLAG_ALL; | |
202 slice_param.slice_horizontal_position = 0; | |
203 slice_param.slice_vertical_position = 0; | |
204 slice_param.num_components = parse_result.scan.num_components; | |
205 for (int i = 0; i < slice_param.num_components; i++) { | |
206 slice_param.components[i].component_selector = | |
207 parse_result.scan.components[i].component_selector; | |
208 slice_param.components[i].dc_table_selector = | |
209 parse_result.scan.components[i].dc_selector; | |
210 slice_param.components[i].ac_table_selector = | |
211 parse_result.scan.components[i].ac_selector; | |
212 } | |
213 slice_param.restart_interval = parse_result.restart_interval; | |
214 int mcu_cols = | |
215 (parse_result.visible_width + max_h_factor * 8 - 1) / (max_h_factor * 8); | |
216 int mcu_rows = | |
217 (parse_result.visible_height + max_v_factor * 8 - 1) / (max_v_factor * 8); | |
218 slice_param.num_mcus = mcu_rows * mcu_cols; | |
219 | |
220 if (!vaapi_wrapper_->SubmitBuffer(VASliceParameterBufferType, | |
221 sizeof(slice_param), &slice_param)) | |
222 return VAAPI_ERROR; | |
223 | |
224 // Set scan data | |
225 if (!vaapi_wrapper_->SubmitBuffer(VASliceDataBufferType, | |
226 parse_result.scan.data_size, | |
227 const_cast<char*>(parse_result.scan.data))) | |
228 return VAAPI_ERROR; | |
229 | |
230 if (!vaapi_wrapper_->ExecuteAndDestroyPendingBuffers(va_surfaces[0])) | |
231 return VAAPI_ERROR; | |
232 | |
233 *output_size = size; | |
234 *output_surface_id = va_surfaces[0]; | |
235 | |
236 return SUCCESS; | |
237 } | |
238 | |
239 void VaapiJpegDecoder::DecodeDone() { | |
240 vaapi_wrapper_->DestroySurfaces(); | |
241 } | |
242 | |
243 } // namespace content | |
OLD | NEW |