xref: /aosp_15_r20/external/v4l2_codec2/common/include/v4l2_codec2/common/H264NalParser.h (revision 0ec5a0ec62797f775085659156625e7f1bdb369f)
1 // Copyright 2021 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 ANDROID_V4L2_CODEC2_COMMON_H264NALPARSER_H
6 #define ANDROID_V4L2_CODEC2_COMMON_H264NALPARSER_H
7 
8 #include <stdint.h>
9 
10 #include <v4l2_codec2/common/NalParser.h>
11 
12 namespace android {
13 
14 // Helper class to parse H264 NAL units from data.
15 class H264NalParser : public NalParser {
16 public:
17     // Type of a IDR Slice NAL unit.
18     static constexpr uint8_t kIDRType = 5;
19     // Type of a SPS NAL unit.
20     static constexpr uint8_t kSPSType = 7;
21     // Type of a PPS NAL unit.
22     static constexpr uint8_t kPPSType = 8;
23 
24     H264NalParser(const uint8_t* data, size_t length);
25     ~H264NalParser() = default;
26 
27     // Locate the sequence parameter set (SPS).
28     bool locateSPS() override;
29     bool locateIDR() override;
30 
31     // Get the type of the current NAL unit.
32     uint8_t type() const;
33 
34     // Find the H.264 video's color aspects in the current SPS NAL.
35     bool findCodedColorAspects(ColorAspects* colorAspects) override;
36 };
37 
38 }  // namespace android
39 
40 #endif  // ANDROID_V4L2_CODEC2_COMMON_H264NALPARSER_H
41