1 /* 2 * Copyright (C) 2025 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 MULTI_STREAM_PARSER_MANAGER_H 17 #define MULTI_STREAM_PARSER_MANAGER_H 18 19 #include <string> 20 #include <map> 21 #include <memory> 22 #include <mutex> 23 #include "stream_parser.h" 24 #include "common/status.h" 25 26 namespace OHOS { 27 namespace Media { 28 namespace Plugins { 29 using CreateFunc = StreamParser *(*)(); 30 using DestroyFunc = void (*)(StreamParser *); 31 class MultiStreamParserManager { 32 public: MultiStreamParserManager()33 MultiStreamParserManager() {}; 34 ~MultiStreamParserManager(); 35 Status Create(uint32_t trackId, VideoStreamType videoStreamType); 36 37 bool ParserIsCreated(uint32_t trackId); 38 bool ParserIsInited(uint32_t trackId); 39 bool AllParserInited(); 40 41 bool IsHdrVivid(uint32_t trackId); 42 bool IsSyncFrame(uint32_t trackId, const uint8_t *sample, int32_t size); 43 bool GetColorRange(uint32_t trackId); 44 uint8_t GetColorPrimaries(uint32_t trackId); 45 uint8_t GetColorTransfer(uint32_t trackId); 46 uint8_t GetColorMatrixCoeff(uint32_t trackId); 47 uint8_t GetProfileIdc(uint32_t trackId); 48 uint8_t GetLevelIdc(uint32_t trackId); 49 uint32_t GetChromaLocation(uint32_t trackId); 50 uint32_t GetPicWidInLumaSamples(uint32_t trackId); 51 uint32_t GetPicHetInLumaSamples(uint32_t trackId); 52 53 void ResetXPSSendStatus(uint32_t trackId); 54 bool ConvertExtraDataToAnnexb(uint32_t trackId, uint8_t *extraData, int32_t extraDataSize); 55 void ConvertPacketToAnnexb(uint32_t trackId, uint8_t **hvccPacket, int32_t &hvccPacketSize, uint8_t *sideData, 56 size_t sideDataSize, bool isExtradata); 57 void ParseAnnexbExtraData(uint32_t trackId, const uint8_t *sample, int32_t size); 58 59 private: 60 static std::mutex mtx_; 61 62 // .so initialize 63 static void *LoadLib(const std::string &path); 64 static bool CheckSymbol(void *handler, VideoStreamType videoStreamType); 65 66 // parser manage 67 static std::map<VideoStreamType, void *> handlerMap_; 68 static std::map<VideoStreamType, CreateFunc> createFuncMap_; 69 static std::map<VideoStreamType, DestroyFunc> destroyFuncMap_; 70 71 // stream manage 72 struct StreamInfo { 73 VideoStreamType type; 74 StreamParser *parser; 75 bool inited; ~StreamInfoStreamInfo76 ~StreamInfo() 77 { 78 if (parser != nullptr) { 79 parser = nullptr; 80 } 81 } 82 }; 83 std::map<uint32_t, StreamInfo> streamMap_ {}; 84 85 bool Init(VideoStreamType videoStreamType); 86 }; 87 } // namespace Plugins 88 } // namespace Media 89 } // namespace OHOS 90 #endif // MULTI_STREAM_PARSER_MANAGER_H