Chromium Code Reviews| Index: content/common/gpu/media/vaapi_jpeg_parser.h |
| diff --git a/content/common/gpu/media/vaapi_jpeg_parser.h b/content/common/gpu/media/vaapi_jpeg_parser.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..cf7f962373d15012a765121bac9ca7c037a5ae24 |
| --- /dev/null |
| +++ b/content/common/gpu/media/vaapi_jpeg_parser.h |
| @@ -0,0 +1,109 @@ |
| +// 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. |
| +// |
| +#ifndef CONTENT_COMMON_GPU_MEDIA_VAAPI_JPEG_PARSER_H_ |
| +#define CONTENT_COMMON_GPU_MEDIA_VAAPI_JPEG_PARSER_H_ |
| + |
| +#include "base/big_endian.h" |
| +#include "base/macros.h" |
| +#include "content/common/content_export.h" |
| + |
| +namespace content { |
| + |
| +static const int kJpegHuffmanTableNum_baseline = 2; |
| +static const int kJpegComponentNum = 4; |
| +static const int kJpegQuantizationTableNum = 4; |
| + |
| +enum JpegMarker { |
| + SOF0 = 0xC0, // start of image (baseline) |
|
wuchengli
2014/12/17 09:03:02
s/image/frame/
kcwu
2014/12/24 11:32:37
Done.
|
| + DHT = 0xC4, // define huffman table |
| + SOI = 0xD8, // start of image |
| + SOS = 0xDA, // start of scan |
| + DQT = 0xDB, // define quantization table |
| + DRI = 0xDD, // define restart internal |
| + MARKER1 = 0xFF, // jpeg marker prefix |
| +}; |
| + |
| +// Parsing result of JPEG DHT marker |
| +struct JpegHuffmanTable { |
| + bool valid; |
| + uint8_t code_length[16]; |
| + uint8_t code_value[256]; |
| +}; |
| + |
| +// Parsing result of JPEG DQT marker |
| +struct JpegQuantizationTable { |
| + bool valid; |
| + uint8_t value[64]; // only support 8 bits quantization table |
| +}; |
| + |
| +// Parsing result of a JPEG component |
| +struct JpegComponent { |
| + uint8_t id; |
| + uint8_t horizontal_sampling_factor; |
| + uint8_t vertical_sampling_factor; |
| + uint8_t quantization_table_selector; |
| +}; |
| + |
| +// Parsing result of JPEG SOS marker |
| +struct JpegScan { |
| + uint8_t num_component; |
| + struct Component { |
| + uint8_t component_selector; |
| + uint8_t dc_selector; |
| + uint8_t ac_selector; |
| + } components[kJpegComponentNum]; |
| + const char* data; |
| + size_t data_size; |
| +}; |
| + |
| +struct JpegParseResult { |
| + uint16_t visible_width; |
| + uint16_t visible_height; |
| + uint8_t num_component; |
| + JpegComponent components[kJpegComponentNum]; |
| + JpegHuffmanTable dc_table[kJpegHuffmanTableNum_baseline]; |
| + JpegHuffmanTable ac_table[kJpegHuffmanTableNum_baseline]; |
| + JpegQuantizationTable q_table[kJpegQuantizationTableNum]; |
| + uint16_t restart_interval; |
| + JpegScan scan; |
| +}; |
| + |
| +// VaapiJpegParser parses JPEG header. It's not a full feature JPEG parser |
| +// implememtation. It only parses subset of JPEG baseline mode needed by |
| +// VAAPI JPEG decoder. For explanations of each struct and its members, |
| +// see JPEG specification at http://www.w3.org/Graphics/JPEG/itu-t81.pdf. |
| +class CONTENT_EXPORT VaapiJpegParser { |
| + public: |
| + // JPEG buffer and its size. The parser doesn't own the memory. |
| + VaapiJpegParser(const uint8_t* buffer, size_t length); |
| + ~VaapiJpegParser(); |
| + |
| + // Parse JPEG header. Returns the parsed result iff header is valid and |
| + // supported by VAAPI. Otherwise returns NULL. The parser still owns |
| + // the returned result memory. |
| + const JpegParseResult* Parse(); |
| + |
| + private: |
| + bool ParseSOF(base::BigEndianReader reader); |
| + bool ParseDQT(base::BigEndianReader reader); |
| + bool ParseDHT(base::BigEndianReader reader); |
| + bool ParseDRI(base::BigEndianReader reader); |
| + bool ParseSOS(base::BigEndianReader reader); |
| + bool ParseSOI(base::BigEndianReader reader); |
| + |
| + // JPEG buffer. It is still owned by caller. |
|
wuchengli
2014/12/17 09:03:02
It's not obviously who the caller is here. Maybe c
kcwu
2014/12/24 11:32:37
Done.
|
| + const uint8_t* buffer_; |
| + // Length of data in buffer |
| + size_t length_; |
| + |
| + // Parsed result |
| + JpegParseResult result_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(VaapiJpegParser); |
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_JPEG_PARSER_H_ |