HevcUtils.h revision 9aa87d4ef502c9700a31fe46dc6e1d6f99cf4e5e
1/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef HEVC_UTILS_H_
18
19#define HEVC_UTILS_H_
20
21#include <stdint.h>
22
23#include <media/stagefright/foundation/ABase.h>
24#include <media/stagefright/foundation/ABuffer.h>
25#include <utils/Errors.h>
26#include <utils/KeyedVector.h>
27#include <utils/StrongPointer.h>
28#include <utils/Vector.h>
29
30namespace android {
31
32enum {
33    kHevcNalUnitTypeVps = 32,
34    kHevcNalUnitTypeSps = 33,
35    kHevcNalUnitTypePps = 34,
36    kHevcNalUnitTypePrefixSei = 39,
37    kHevcNalUnitTypeSuffixSei = 40,
38};
39
40enum {
41    // uint8_t
42    kGeneralProfileSpace,
43    // uint8_t
44    kGeneralTierFlag,
45    // uint8_t
46    kGeneralProfileIdc,
47    // uint32_t
48    kGeneralProfileCompatibilityFlags,
49    // uint64_t
50    kGeneralConstraintIndicatorFlags,
51    // uint8_t
52    kGeneralLevelIdc,
53    // uint8_t
54    kChromaFormatIdc,
55    // uint8_t
56    kBitDepthLumaMinus8,
57    // uint8_t
58    kBitDepthChromaMinus8,
59};
60
61class HevcParameterSets {
62public:
63    HevcParameterSets();
64
65    status_t addNalUnit(const uint8_t* data, size_t size);
66
67    bool findParam8(uint32_t key, uint8_t *param);
68    bool findParam16(uint32_t key, uint16_t *param);
69    bool findParam32(uint32_t key, uint32_t *param);
70    bool findParam64(uint32_t key, uint64_t *param);
71
72    inline size_t getNumNalUnits() { return mNalUnits.size(); }
73    size_t getNumNalUnitsOfType(uint8_t type);
74    uint8_t getType(size_t index);
75    size_t getSize(size_t index);
76    // Note that this method does not write the start code.
77    bool write(size_t index, uint8_t* dest, size_t size);
78    status_t makeHvcc(uint8_t *hvcc, size_t *hvccSize, size_t nalSizeLength);
79
80private:
81    status_t parseVps(const uint8_t* data, size_t size);
82    status_t parseSps(const uint8_t* data, size_t size);
83    status_t parsePps(const uint8_t* data, size_t size);
84
85    KeyedVector<uint32_t, uint64_t> mParams;
86    Vector<sp<ABuffer>> mNalUnits;
87
88    DISALLOW_EVIL_CONSTRUCTORS(HevcParameterSets);
89};
90
91}  // namespace android
92
93#endif  // HEVC_UTILS_H_
94