1 /*
2  *  Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #ifndef MODULES_VIDEO_CODING_UTILITY_VP9_UNCOMPRESSED_HEADER_PARSER_H_
12 #define MODULES_VIDEO_CODING_UTILITY_VP9_UNCOMPRESSED_HEADER_PARSER_H_
13 
14 #include <stddef.h>
15 #include <stdint.h>
16 #include "absl/types/optional.h"
17 
18 namespace webrtc {
19 
20 namespace vp9 {
21 
22 // Gets the QP, QP range: [0, 255].
23 // Returns true on success, false otherwise.
24 bool GetQp(const uint8_t* buf, size_t length, int* qp);
25 
26 // Bit depth per channel. Support varies by profile.
27 enum class BitDept : uint8_t {
28   k8Bit = 8,
29   k10Bit = 10,
30   k12Bit = 12,
31 };
32 
33 enum class ColorSpace : uint8_t {
34   CS_UNKNOWN = 0,    // Unknown (in this case the color space must be signaled
35                      // outside the VP9 bitstream).
36   CS_BT_601 = 1,     // CS_BT_601 Rec. ITU-R BT.601-7
37   CS_BT_709 = 2,     // Rec. ITU-R BT.709-6
38   CS_SMPTE_170 = 3,  // SMPTE-170
39   CS_SMPTE_240 = 4,  // SMPTE-240
40   CS_BT_2020 = 5,    // Rec. ITU-R BT.2020-2
41   CS_RESERVED = 6,   // Reserved
42   CS_RGB = 7,        // sRGB (IEC 61966-2-1)
43 };
44 
45 enum class ColorRange {
46   kStudio,  // Studio swing:
47             // For BitDepth equals 8:
48             //     Y is between 16 and 235 inclusive.
49             //     U and V are between 16 and 240 inclusive.
50             // For BitDepth equals 10:
51             //     Y is between 64 and 940 inclusive.
52             //     U and V are between 64 and 960 inclusive.
53             // For BitDepth equals 12:
54             //     Y is between 256 and 3760.
55             //     U and V are between 256 and 3840 inclusive.
56   kFull     // Full swing; no restriction on Y, U, V values.
57 };
58 
59 enum class YuvSubsampling {
60   k444,
61   k440,
62   k422,
63   k420,
64 };
65 
66 struct FrameInfo {
67   int profile = 0;  // Profile 0-3 are valid.
68   bool show_frame = false;
69   bool error_resilient = false;
70   BitDept bit_detph = BitDept::k8Bit;
71   ColorSpace color_space = ColorSpace::CS_UNKNOWN;
72   ColorRange color_range;
73   YuvSubsampling sub_sampling;
74   int frame_width = 0;
75   int frame_height = 0;
76   int render_width = 0;
77   int render_height = 0;
78 };
79 
80 // Parses frame information for a VP9 key-frame or all-intra frame from a
81 // bitstream. Returns nullopt on failure or if not a key-frame.
82 absl::optional<FrameInfo> ParseIntraFrameInfo(const uint8_t* buf,
83                                               size_t length);
84 
85 }  // namespace vp9
86 
87 }  // namespace webrtc
88 
89 #endif  // MODULES_VIDEO_CODING_UTILITY_VP9_UNCOMPRESSED_HEADER_PARSER_H_
90