1 /* 2 * Copyright (c) 2021-2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef HISTREAMER_AVC_CONFIG_DATA_PARSER_H 17 #define HISTREAMER_AVC_CONFIG_DATA_PARSER_H 18 19 #ifdef VIDEO_SUPPORT 20 21 #include <cstdint> 22 #include <string> 23 #include <memory> 24 #include "bit_reader.h" 25 #include "plugin/common/plugin_audio_tags.h" 26 27 namespace OHOS { 28 namespace Media { 29 namespace Plugin { 30 namespace Ffmpeg { 31 #define AVC_MAX_CONFIG_ITEM 256 32 33 class AVCConfigDataParser final { 34 public: 35 AVCConfigDataParser(const uint8_t* cfgData, const size_t cfgDataSize); 36 ~AVCConfigDataParser(); 37 38 bool ParseConfigData(); 39 bool IsNeedAddFrameHeader(); 40 bool GetNewConfigData(std::shared_ptr<uint8_t>& newCfgData, size_t& newCfgDataSize); 41 42 private: 43 // sps or pps 44 struct NalConfigItem { 45 uint32_t len; 46 uint8_t SpsOrPps[0]; 47 }; 48 49 struct NalConfigList { 50 uint32_t count; 51 NalConfigItem *items[AVC_MAX_CONFIG_ITEM]; 52 }; 53 54 NalConfigList cfgSet; 55 56 BitReader bitReader_; 57 const uint8_t* cfgData_; 58 const size_t cfgDataSize_; 59 60 uint8_t nalUnitLen_; 61 uint8_t version_; 62 uint8_t profile_; 63 uint8_t profile_compat_; 64 uint8_t level_; 65 bool needAddFrameHeader_; 66 67 std::shared_ptr<uint8_t> newCfgData_; 68 size_t newCfgDataSize_; 69 70 void ClearConfigSet(); 71 bool ParseNalUnitSizeLen(); 72 bool GetSpsOrPpsLen(uint32_t& len); 73 bool ParseNalHeader(); 74 bool CreateConfigSetItem(const uint32_t len); 75 bool ParseSpsOrPps(const uint32_t mask); 76 bool ParseNal(); 77 }; 78 } // namespace Ffmpeg 79 } // namespace Plugin 80 } // namespace Media 81 } // namespace OHOS 82 #endif 83 #endif // HISTREAMER_AVC_CONFIG_DATA_PARSER_H 84