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..273a9be81a4fe651449a23af2de184ef1501c99b |
| --- /dev/null |
| +++ b/content/common/gpu/media/vaapi_jpeg_parser.h |
| @@ -0,0 +1,107 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
|
wuchengli
2014/12/08 09:25:11
- How big is content/test/data/jpeg/pixel-1280x720
kcwu
2014/12/16 06:23:54
it's 120KB.
|
| +// 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 = 4; |
| +static const int kJpegComponentNum = 4; |
| +static const int kJpegQuantizationTableNum = 4; |
| + |
| +enum JpegMarker { |
| + SOF0 = 0xC0, // start of image (baseline) |
| + 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 JPEG component |
|
wuchengli
2014/12/08 09:25:11
s/of JPEG/of a JPEG/
kcwu
2014/12/16 06:23:55
Done.
|
| +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]; |
| + JpegHuffmanTable ac_table[kJpegHuffmanTableNum]; |
| + 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 { |
|
wuchengli
2014/12/08 09:25:11
The only thing this only applies to vaapi is the m
kcwu
2014/12/16 06:23:54
And some sampling factor (see the end of ParseSOF)
|
| + public: |
| + VaapiJpegParser(const uint8_t* buffer, size_t length); |
|
wuchengli
2014/12/08 09:25:11
Document who's the owner of memory in |buffer|. Ad
kcwu
2014/12/16 06:23:54
Done.
|
| + ~VaapiJpegParser(); |
| + |
| + // Parse JPEG header. Returns true iff header is valid and supported by |
| + // VAAPI. |
| + bool Parse(); |
|
wuchengli
2014/12/08 09:25:11
add blank line
kcwu
2014/12/16 06:23:54
Acknowledged.
|
| + // Returns the parsed result. It's only valid after Parse() returned |
| + // true. |
| + const JpegParseResult* GetParsedResult() { return &result_; } |
|
wuchengli
2014/12/08 09:25:11
Can we combine Parse and GetParsedResult? Make Par
kcwu
2014/12/16 06:23:54
Done.
|
| + |
| + private: |
| + bool ParseSOI(base::BigEndianReader reader); |
|
wuchengli
2014/12/08 09:25:11
Keep the same order of functions in vaapi_jpeg_par
wuchengli
2014/12/08 09:25:11
Does it save a copy if we use const base::BigEndia
kcwu
2014/12/16 06:23:54
No, it is not constant since Read() will modify it
kcwu
2014/12/16 06:23:54
Done.
|
| + 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); |
| + |
| + const uint8_t* buffer_; |
| + size_t length_; |
|
wuchengli
2014/12/08 09:25:11
Need comments for buffer_ and length_. Who owns th
kcwu
2014/12/16 06:23:54
Done.
|
| + |
| + JpegParseResult result_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(VaapiJpegParser); |
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_JPEG_PARSER_H_ |