• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023-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 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 using CreateFunc = StreamParser *(*)();
29 using DestroyFunc = void (*)(StreamParser *);
30 class StreamParserManager {
31 public:
32     static std::shared_ptr<StreamParserManager> Create(VideoStreamType videoStreamType);
33     StreamParserManager();
34     StreamParserManager(const StreamParserManager &) = delete;
35     StreamParserManager operator=(const StreamParserManager &) = delete;
36     ~StreamParserManager();
37     static bool Init(VideoStreamType videoStreamType);
38 
39     void ParseExtraData(const uint8_t *sample, int32_t size, uint8_t **extraDataBuf, int32_t *extraDataSize);
40     bool IsHdrVivid();
41     bool IsSyncFrame(const uint8_t *sample, int32_t size);
42     bool GetColorRange();
43     uint8_t GetColorPrimaries();
44     uint8_t GetColorTransfer();
45     uint8_t GetColorMatrixCoeff();
46     uint8_t GetProfileIdc();
47     uint8_t GetLevelIdc();
48     uint32_t GetChromaLocation();
49     uint32_t GetPicWidInLumaSamples();
50     uint32_t GetPicHetInLumaSamples();
51     void ResetXPSSendStatus();
52     bool ConvertExtraDataToAnnexb(uint8_t *extraData, int32_t extraDataSize);
53     void ConvertPacketToAnnexb(uint8_t **hvccPacket, int32_t &hvccPacketSize, uint8_t *sideData,
54         size_t sideDataSize, bool isExtradata);
55     void ParseAnnexbExtraData(const uint8_t *sample, int32_t size);
56     std::vector<uint8_t> GetLogInfo();
57     uint32_t GetMaxReorderPic();
58 
59 private:
60     StreamParser *streamParser_ {nullptr};
61     // .so initialize
62     static void *LoadPluginFile(const std::string &path);
63     static bool CheckSymbol(void *handler, VideoStreamType videoStreamType);
64     VideoStreamType videoStreamType_;
65     static std::mutex mtx_;
66     static std::map<VideoStreamType, void *> handlerMap_;
67     static std::map<VideoStreamType, CreateFunc> createFuncMap_;
68     static std::map<VideoStreamType, DestroyFunc> destroyFuncMap_;
69 };
70 } // namespace Plugins
71 } // namespace Media
72 } // namespace OHOS
73 #endif // STREAM_PARSER_MANAGER_H