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 #ifndef CONTENT_COMMON_GPU_MEDIA_VAAPI_JPEG_PARSER_H_ | |
6 #define CONTENT_COMMON_GPU_MEDIA_VAAPI_JPEG_PARSER_H_ | |
7 | |
8 #include "base/big_endian.h" | |
9 #include "base/macros.h" | |
10 #include "content/common/content_export.h" | |
11 | |
12 namespace content { | |
13 | |
14 static const int kJpegHuffmanTableNum_baseline = 2; | |
15 static const int kJpegComponentNum = 4; | |
16 static const int kJpegQuantizationTableNum = 4; | |
17 | |
18 enum JpegMarker { | |
19 SOF0 = 0xC0, // start of image (baseline) | |
wuchengli
2014/12/17 09:03:02
s/image/frame/
kcwu
2014/12/24 11:32:37
Done.
| |
20 DHT = 0xC4, // define huffman table | |
21 SOI = 0xD8, // start of image | |
22 SOS = 0xDA, // start of scan | |
23 DQT = 0xDB, // define quantization table | |
24 DRI = 0xDD, // define restart internal | |
25 MARKER1 = 0xFF, // jpeg marker prefix | |
26 }; | |
27 | |
28 // Parsing result of JPEG DHT marker | |
29 struct JpegHuffmanTable { | |
30 bool valid; | |
31 uint8_t code_length[16]; | |
32 uint8_t code_value[256]; | |
33 }; | |
34 | |
35 // Parsing result of JPEG DQT marker | |
36 struct JpegQuantizationTable { | |
37 bool valid; | |
38 uint8_t value[64]; // only support 8 bits quantization table | |
39 }; | |
40 | |
41 // Parsing result of a JPEG component | |
42 struct JpegComponent { | |
43 uint8_t id; | |
44 uint8_t horizontal_sampling_factor; | |
45 uint8_t vertical_sampling_factor; | |
46 uint8_t quantization_table_selector; | |
47 }; | |
48 | |
49 // Parsing result of JPEG SOS marker | |
50 struct JpegScan { | |
51 uint8_t num_component; | |
52 struct Component { | |
53 uint8_t component_selector; | |
54 uint8_t dc_selector; | |
55 uint8_t ac_selector; | |
56 } components[kJpegComponentNum]; | |
57 const char* data; | |
58 size_t data_size; | |
59 }; | |
60 | |
61 struct JpegParseResult { | |
62 uint16_t visible_width; | |
63 uint16_t visible_height; | |
64 uint8_t num_component; | |
65 JpegComponent components[kJpegComponentNum]; | |
66 JpegHuffmanTable dc_table[kJpegHuffmanTableNum_baseline]; | |
67 JpegHuffmanTable ac_table[kJpegHuffmanTableNum_baseline]; | |
68 JpegQuantizationTable q_table[kJpegQuantizationTableNum]; | |
69 uint16_t restart_interval; | |
70 JpegScan scan; | |
71 }; | |
72 | |
73 // VaapiJpegParser parses JPEG header. It's not a full feature JPEG parser | |
74 // implememtation. It only parses subset of JPEG baseline mode needed by | |
75 // VAAPI JPEG decoder. For explanations of each struct and its members, | |
76 // see JPEG specification at http://www.w3.org/Graphics/JPEG/itu-t81.pdf. | |
77 class CONTENT_EXPORT VaapiJpegParser { | |
78 public: | |
79 // JPEG buffer and its size. The parser doesn't own the memory. | |
80 VaapiJpegParser(const uint8_t* buffer, size_t length); | |
81 ~VaapiJpegParser(); | |
82 | |
83 // Parse JPEG header. Returns the parsed result iff header is valid and | |
84 // supported by VAAPI. Otherwise returns NULL. The parser still owns | |
85 // the returned result memory. | |
86 const JpegParseResult* Parse(); | |
87 | |
88 private: | |
89 bool ParseSOF(base::BigEndianReader reader); | |
90 bool ParseDQT(base::BigEndianReader reader); | |
91 bool ParseDHT(base::BigEndianReader reader); | |
92 bool ParseDRI(base::BigEndianReader reader); | |
93 bool ParseSOS(base::BigEndianReader reader); | |
94 bool ParseSOI(base::BigEndianReader reader); | |
95 | |
96 // 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.
| |
97 const uint8_t* buffer_; | |
98 // Length of data in buffer | |
99 size_t length_; | |
100 | |
101 // Parsed result | |
102 JpegParseResult result_; | |
103 | |
104 DISALLOW_COPY_AND_ASSIGN(VaapiJpegParser); | |
105 }; | |
106 | |
107 } // namespace content | |
108 | |
109 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_JPEG_PARSER_H_ | |
OLD | NEW |