OLD | NEW |
---|---|
(Empty) | |
1 // 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.
| |
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 = 4; | |
15 static const int kJpegComponentNum = 4; | |
16 static const int kJpegQuantizationTableNum = 4; | |
17 | |
18 enum JpegMarker { | |
19 SOF0 = 0xC0, // start of image (baseline) | |
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 JPEG component | |
wuchengli
2014/12/08 09:25:11
s/of JPEG/of a JPEG/
kcwu
2014/12/16 06:23:55
Done.
| |
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]; | |
67 JpegHuffmanTable ac_table[kJpegHuffmanTableNum]; | |
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 { | |
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)
| |
78 public: | |
79 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.
| |
80 ~VaapiJpegParser(); | |
81 | |
82 // Parse JPEG header. Returns true iff header is valid and supported by | |
83 // VAAPI. | |
84 bool Parse(); | |
wuchengli
2014/12/08 09:25:11
add blank line
kcwu
2014/12/16 06:23:54
Acknowledged.
| |
85 // Returns the parsed result. It's only valid after Parse() returned | |
86 // true. | |
87 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.
| |
88 | |
89 private: | |
90 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.
| |
91 bool ParseSOF(base::BigEndianReader reader); | |
92 bool ParseDQT(base::BigEndianReader reader); | |
93 bool ParseDHT(base::BigEndianReader reader); | |
94 bool ParseDRI(base::BigEndianReader reader); | |
95 bool ParseSOS(base::BigEndianReader reader); | |
96 | |
97 const uint8_t* buffer_; | |
98 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.
| |
99 | |
100 JpegParseResult result_; | |
101 | |
102 DISALLOW_COPY_AND_ASSIGN(VaapiJpegParser); | |
103 }; | |
104 | |
105 } // namespace content | |
106 | |
107 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_JPEG_PARSER_H_ | |
OLD | NEW |