1 /* 2 * Copyright (C) 2023 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 STREAM_PARSER_MANAGER_H 17 #define STREAM_PARSER_MANAGER_H 18 19 #include <string> 20 #include <map> 21 #include <memory> 22 #include <mutex> 23 #include "stream_parser.h" 24 25 namespace OHOS { 26 namespace Media { 27 namespace Plugins { 28 enum StreamType { 29 HEVC = 0, 30 VVC = 1, 31 }; 32 using CreateFunc = StreamParser *(*)(); 33 using DestroyFunc = void (*)(StreamParser *); 34 class StreamParserManager { 35 public: 36 static std::shared_ptr<StreamParserManager> Create(StreamType streamType); 37 StreamParserManager(); 38 StreamParserManager(const StreamParserManager &) = delete; 39 StreamParserManager operator=(const StreamParserManager &) = delete; 40 ~StreamParserManager(); 41 static bool Init(StreamType streamType); 42 43 void ParseExtraData(const uint8_t *sample, int32_t size, uint8_t **extraDataBuf, int32_t *extraDataSize); 44 bool IsHdrVivid(); 45 bool IsSyncFrame(const uint8_t *sample, int32_t size); 46 bool GetColorRange(); 47 uint8_t GetColorPrimaries(); 48 uint8_t GetColorTransfer(); 49 uint8_t GetColorMatrixCoeff(); 50 uint8_t GetProfileIdc(); 51 uint8_t GetLevelIdc(); 52 uint32_t GetChromaLocation(); 53 uint32_t GetPicWidInLumaSamples(); 54 uint32_t GetPicHetInLumaSamples(); 55 void ResetXPSSendStatus(); 56 bool ConvertExtraDataToAnnexb(uint8_t *extraData, int32_t extraDataSize); 57 void ConvertPacketToAnnexb(uint8_t **hvccPacket, int32_t &hvccPacketSize, uint8_t *sideData, 58 size_t sideDataSize, bool isExtradata); 59 void ParseAnnexbExtraData(const uint8_t *sample, int32_t size); 60 61 private: 62 StreamParser *streamParser_ {nullptr}; 63 // .so initialize 64 static void *LoadPluginFile(const std::string &path); 65 static bool CheckSymbol(void *handler, StreamType streamType); 66 StreamType streamType_; 67 static std::mutex mtx_; 68 static std::map<StreamType, void *> handlerMap_; 69 static std::map<StreamType, CreateFunc> createFuncMap_; 70 static std::map<StreamType, DestroyFunc> destroyFuncMap_; 71 }; 72 } // namespace Plugins 73 } // namespace Media 74 } // namespace OHOS 75 #endif // STREAM_PARSER_MANAGER_H