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_AAC_AUDIO_CONFIG_PARSER_H 17 #define HISTREAMER_AAC_AUDIO_CONFIG_PARSER_H 18 19 #include <cstdint> 20 #include <string> 21 #include "bit_reader.h" 22 #include "plugin/common/plugin_audio_tags.h" 23 24 namespace OHOS { 25 namespace Media { 26 namespace Plugin { 27 namespace Ffmpeg { 28 class AACAudioConfigParser final { 29 public: 30 AACAudioConfigParser(const uint8_t* audioConfig, size_t len); 31 32 ~AACAudioConfigParser() = default; 33 34 bool ParseConfigs(); 35 36 uint32_t GetLevel() const; 37 38 AudioAacProfile GetProfile() const; 39 40 private: 41 struct AudioSpecificConfig { 42 uint8_t audioObjectType {0xFF}; 43 uint8_t channelConfig {0xFF}; 44 uint32_t sampleRate {0}; 45 uint32_t level {0}; 46 AudioAacProfile profile {AudioAacProfile::NONE}; 47 }; 48 49 void Reset(); 50 51 bool ParseObjectType(); 52 53 bool ParseSampleRate(); 54 55 bool ParseChannel(); 56 57 bool ParseObjectTypeFull(); 58 59 bool ExtractChannelElements(int& sceCnt, int& cpeCnt, int& lfeCnt, int& indepCce, int& depCce); 60 61 bool ExtractReferencePRCU(int& refPcu, int& refRcu); 62 63 bool CalculateProfile(int channelCnt, int pcu, int rcu); 64 65 bool ParseLevel(); 66 67 bool ParseProfile(); 68 69 BitReader bitReader_; 70 bool isConfigValid_; 71 AudioSpecificConfig audioConfig_; 72 }; 73 } // namespace Ffmpeg 74 } // namespace Plugin 75 } // namespace Media 76 } // namespace OHOS 77 #endif // HISTREAMER_AAC_AUDIO_CONFIG_PARSER_H 78