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 30 namespace android { 31 32 enum { 33 kHevcNalUnitTypeCodedSliceIdr = 19, 34 kHevcNalUnitTypeCodedSliceIdrNoLP = 20, 35 kHevcNalUnitTypeCodedSliceCra = 21, 36 37 kHevcNalUnitTypeVps = 32, 38 kHevcNalUnitTypeSps = 33, 39 kHevcNalUnitTypePps = 34, 40 kHevcNalUnitTypePrefixSei = 39, 41 kHevcNalUnitTypeSuffixSei = 40, 42 }; 43 44 enum { 45 // uint8_t 46 kGeneralProfileSpace, 47 // uint8_t 48 kGeneralTierFlag, 49 // uint8_t 50 kGeneralProfileIdc, 51 // uint32_t 52 kGeneralProfileCompatibilityFlags, 53 // uint64_t 54 kGeneralConstraintIndicatorFlags, 55 // uint8_t 56 kGeneralLevelIdc, 57 // uint8_t 58 kChromaFormatIdc, 59 // uint8_t 60 kBitDepthLumaMinus8, 61 // uint8_t 62 kBitDepthChromaMinus8, 63 // uint8_t 64 kVideoFullRangeFlag, 65 // uint8_t 66 kColourPrimaries, 67 // uint8_t 68 kTransferCharacteristics, 69 // uint8_t 70 kMatrixCoeffs, 71 }; 72 73 class HevcParameterSets { 74 public: 75 enum Info : uint32_t { 76 kInfoNone = 0, 77 kInfoIsHdr = 1 << 0, 78 kInfoHasColorDescription = 1 << 1, 79 }; 80 81 HevcParameterSets(); 82 83 status_t addNalUnit(const uint8_t* data, size_t size); 84 85 bool findParam8(uint32_t key, uint8_t *param); 86 bool findParam16(uint32_t key, uint16_t *param); 87 bool findParam32(uint32_t key, uint32_t *param); 88 bool findParam64(uint32_t key, uint64_t *param); 89 getNumNalUnits()90 inline size_t getNumNalUnits() { return mNalUnits.size(); } 91 size_t getNumNalUnitsOfType(uint8_t type); 92 uint8_t getType(size_t index); 93 size_t getSize(size_t index); 94 // Note that this method does not write the start code. 95 bool write(size_t index, uint8_t* dest, size_t size); 96 status_t makeHvcc(uint8_t *hvcc, size_t *hvccSize, size_t nalSizeLength); 97 void FindHEVCDimensions( 98 const sp<ABuffer> &SpsBuffer, int32_t *width, int32_t *height); 99 getInfo()100 Info getInfo() const { return mInfo; } 101 static bool IsHevcIDR(const uint8_t *data, size_t size); 102 103 private: 104 status_t parseVps(const uint8_t* data, size_t size); 105 status_t parseSps(const uint8_t* data, size_t size); 106 status_t parsePps(const uint8_t* data, size_t size); 107 108 KeyedVector<uint32_t, uint64_t> mParams; 109 Vector<sp<ABuffer>> mNalUnits; 110 Info mInfo; 111 112 DISALLOW_EVIL_CONSTRUCTORS(HevcParameterSets); 113 }; 114 115 } // namespace android 116 117 #endif // HEVC_UTILS_H_ 118