Chromium Code Reviews| Index: content/common/gpu/media/vaapi_jpeg_decoder.cc |
| diff --git a/content/common/gpu/media/vaapi_jpeg_decoder.cc b/content/common/gpu/media/vaapi_jpeg_decoder.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5bef6869161208a81e1c8c52bee3dff92ff14c65 |
| --- /dev/null |
| +++ b/content/common/gpu/media/vaapi_jpeg_decoder.cc |
| @@ -0,0 +1,243 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/common/gpu/media/vaapi_jpeg_decoder.h" |
| + |
| +#include <algorithm> |
|
Owen Lin
2015/01/13 06:17:58
not used?
kcwu
2015/01/16 15:12:54
Done.
|
| +#include <limits> |
|
Owen Lin
2015/01/13 06:17:58
not used?
kcwu
2015/01/16 15:12:54
Done.
|
| + |
| +namespace media { |
| + |
| +// K.3.3.1 "Specification of typical tables for DC difference coding" |
| +static JpegHuffmanTable default_dc_table[kJpegMaxHuffmanTableNum_baseline] = { |
| + // luminance DC coefficients |
| + { |
| + true, |
| + {0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0}, |
| + {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b}, |
| + }, |
| + // chrominance DC coefficients |
| + { |
| + true, |
| + {0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}, |
| + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb}, |
| + }, |
| +}; |
| + |
| +// K.3.3.2 "Specification of typical tables for AC coefficient coding" |
| +static JpegHuffmanTable default_ac_table[kJpegMaxHuffmanTableNum_baseline] = { |
| + // luminance AC coefficients |
| + { |
| + true, |
| + {0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d}, |
| + {0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, |
| + 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07, |
| + 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08, |
| + 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0, |
| + 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16, |
| + 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28, |
| + 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, |
| + 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, |
| + 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, |
| + 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, |
| + 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, |
| + 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, |
| + 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, |
| + 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, |
| + 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, |
| + 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5, |
| + 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, |
| + 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2, |
| + 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, |
| + 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, |
| + 0xf9, 0xfa}, |
| + }, |
| + // chrominance AC coefficients |
| + { |
| + true, |
| + {0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77}, |
| + {0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, |
| + 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71, |
| + 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91, |
| + 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0, |
| + 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34, |
| + 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26, |
| + 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38, |
| + 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, |
| + 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, |
| + 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, |
| + 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, |
| + 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, |
| + 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, |
| + 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, |
| + 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, |
| + 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, |
| + 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, |
| + 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, |
| + 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, |
| + 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, |
| + 0xf9, 0xfa}, |
| + }, |
| +}; |
| + |
| +} // namespace media |
| + |
| +namespace content { |
| + |
| +VaapiJpegDecoder::VaapiJpegDecoder( |
| + 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
|
| + const ReportErrorToUmaCB& report_error_to_uma_cb) |
| + : vaapi_wrapper_(vaapi_wrapper), |
| + report_error_to_uma_cb_(report_error_to_uma_cb) { |
| +} |
| + |
| +VaapiJpegDecoder::~VaapiJpegDecoder() { |
| +} |
| + |
| +VaapiJpegDecoder::DecodeStatus VaapiJpegDecoder::Decode( |
| + const uint8* buffer, |
| + size_t buffer_size, |
| + gfx::Size* output_size, |
| + VASurfaceID* output_surface_id) { |
| + media::JpegParseResult parse_result; |
| + 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.
|
| + return PARSE_ERROR; |
| + |
| + // 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.
|
| + std::vector<VASurfaceID> va_surfaces; |
| + gfx::Size size(parse_result.visible_width, parse_result.visible_height); |
| + 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
|
| + return VAAPI_ERROR; |
| + |
| + // 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.
|
| + VAPictureParameterBufferJPEGBaseline pic_param; |
| + memset(&pic_param, 0, sizeof(pic_param)); |
| + pic_param.picture_width = parse_result.visible_width; |
| + pic_param.picture_height = parse_result.visible_height; |
| + pic_param.num_components = parse_result.num_components; |
| + |
| + for (int i = 0; i < pic_param.num_components; i++) { |
| + pic_param.components[i].component_id = parse_result.components[i].id; |
| + pic_param.components[i].h_sampling_factor = |
| + parse_result.components[i].horizontal_sampling_factor; |
| + pic_param.components[i].v_sampling_factor = |
| + parse_result.components[i].vertical_sampling_factor; |
| + pic_param.components[i].quantiser_table_selector = |
| + parse_result.components[i].quantization_table_selector; |
| + } |
| + |
| + if (!vaapi_wrapper_->SubmitBuffer(VAPictureParameterBufferType, |
| + sizeof(pic_param), &pic_param)) |
| + return VAAPI_ERROR; |
| + |
| + // 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.
|
| + VAIQMatrixBufferJPEGBaseline iq_matrix; |
| + memset(&iq_matrix, 0, sizeof(iq_matrix)); |
| + static_assert(media::kJpegMaxQuantizationTableNum == |
| + arraysize(iq_matrix.load_quantiser_table), |
| + "max number of quantization table mismatched"); |
| + for (size_t i = 0; i < media::kJpegMaxQuantizationTableNum; i++) { |
| + if (!parse_result.q_table[i].valid) |
| + continue; |
| + iq_matrix.load_quantiser_table[i] = 1; |
| + for (int j = 0; j < 64; j++) |
| + iq_matrix.quantiser_table[i][j] = parse_result.q_table[i].value[j]; |
| + } |
| + |
| + if (!vaapi_wrapper_->SubmitBuffer(VAIQMatrixBufferType, sizeof(iq_matrix), |
| + &iq_matrix)) |
| + return VAAPI_ERROR; |
| + |
| + // Use default huffman tables if not specified in header. |
| + const media::JpegHuffmanTable* dc_table = media::default_dc_table; |
| + const media::JpegHuffmanTable* ac_table = media::default_ac_table; |
| + for (size_t i = 0; i < media::kJpegMaxHuffmanTableNum_baseline; i++) { |
| + if (parse_result.dc_table[i].valid || parse_result.ac_table[i].valid) { |
| + dc_table = parse_result.dc_table; |
| + ac_table = parse_result.ac_table; |
| + break; |
| + } |
| + } |
| + |
| + // Set huffman table |
| + VAHuffmanTableBufferJPEGBaseline huffman_table; |
| + memset(&huffman_table, 0, sizeof(huffman_table)); |
| + static_assert(media::kJpegMaxHuffmanTableNum_baseline == |
| + arraysize(huffman_table.load_huffman_table), |
| + "max number of huffman table mismatched"); |
| + static_assert(sizeof(huffman_table.huffman_table[0].num_dc_codes) == |
| + sizeof(dc_table[0].code_length), |
| + "size of huffman table code length mismatch"); |
| + static_assert(sizeof(huffman_table.huffman_table[0].dc_values[0]) == |
| + sizeof(dc_table[0].code_value[0]), |
| + "size of huffman table code value mismatch"); |
| + for (size_t i = 0; i < media::kJpegMaxHuffmanTableNum_baseline; i++) { |
| + if (!dc_table[i].valid || !ac_table[i].valid) |
| + continue; |
| + huffman_table.load_huffman_table[i] = 1; |
| + |
| + memcpy(huffman_table.huffman_table[i].num_dc_codes, dc_table[i].code_length, |
| + sizeof(huffman_table.huffman_table[i].num_dc_codes)); |
| + memcpy(huffman_table.huffman_table[i].dc_values, dc_table[i].code_value, |
| + sizeof(huffman_table.huffman_table[i].dc_values)); |
| + memcpy(huffman_table.huffman_table[i].num_ac_codes, ac_table[i].code_length, |
| + sizeof(huffman_table.huffman_table[i].num_ac_codes)); |
| + memcpy(huffman_table.huffman_table[i].ac_values, ac_table[i].code_value, |
| + sizeof(huffman_table.huffman_table[i].ac_values)); |
| + } |
| + |
| + if (!vaapi_wrapper_->SubmitBuffer(VAHuffmanTableBufferType, |
| + sizeof(huffman_table), &huffman_table)) |
| + return VAAPI_ERROR; |
| + |
| + // Set slice parameter |
| + VASliceParameterBufferJPEGBaseline slice_param; |
| + memset(&slice_param, 0, sizeof(slice_param)); |
| + int max_h_factor = parse_result.components[0].horizontal_sampling_factor; |
| + int max_v_factor = parse_result.components[0].vertical_sampling_factor; |
| + slice_param.slice_data_size = parse_result.scan.data_size; |
| + slice_param.slice_data_offset = 0; |
| + slice_param.slice_data_flag = VA_SLICE_DATA_FLAG_ALL; |
| + slice_param.slice_horizontal_position = 0; |
| + slice_param.slice_vertical_position = 0; |
| + slice_param.num_components = parse_result.scan.num_components; |
| + for (int i = 0; i < slice_param.num_components; i++) { |
| + slice_param.components[i].component_selector = |
| + parse_result.scan.components[i].component_selector; |
| + slice_param.components[i].dc_table_selector = |
| + parse_result.scan.components[i].dc_selector; |
| + slice_param.components[i].ac_table_selector = |
| + parse_result.scan.components[i].ac_selector; |
| + } |
| + slice_param.restart_interval = parse_result.restart_interval; |
| + int mcu_cols = |
| + (parse_result.visible_width + max_h_factor * 8 - 1) / (max_h_factor * 8); |
| + int mcu_rows = |
| + (parse_result.visible_height + max_v_factor * 8 - 1) / (max_v_factor * 8); |
| + slice_param.num_mcus = mcu_rows * mcu_cols; |
| + |
| + if (!vaapi_wrapper_->SubmitBuffer(VASliceParameterBufferType, |
| + sizeof(slice_param), &slice_param)) |
| + return VAAPI_ERROR; |
| + |
| + // Set scan data |
| + if (!vaapi_wrapper_->SubmitBuffer(VASliceDataBufferType, |
| + parse_result.scan.data_size, |
| + const_cast<char*>(parse_result.scan.data))) |
| + return VAAPI_ERROR; |
| + |
| + if (!vaapi_wrapper_->ExecuteAndDestroyPendingBuffers(va_surfaces[0])) |
| + return VAAPI_ERROR; |
| + |
| + *output_size = size; |
| + *output_surface_id = va_surfaces[0]; |
| + |
| + return SUCCESS; |
| +} |
| + |
| +void VaapiJpegDecoder::DecodeDone() { |
| + vaapi_wrapper_->DestroySurfaces(); |
| +} |
| + |
| +} // namespace content |