1 /*
2  * Copyright (C) 2024 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 REFERENCE_PARSER_MANAGER_H
17 #define REFERENCE_PARSER_MANAGER_H
18 
19 #include "reference_parser.h"
20 
21 namespace OHOS {
22 namespace Media {
23 namespace Plugins {
24 class ReferenceParserManager {
25 public:
26     static std::shared_ptr<ReferenceParserManager> Create(CodecType codecType, std::vector<uint32_t> &IFramePos);
ReferenceParserManager()27     ReferenceParserManager() {};
28     ReferenceParserManager(const ReferenceParserManager &) = delete;
29     ReferenceParserManager operator=(const ReferenceParserManager &) = delete;
30     ~ReferenceParserManager();
31     static bool Init();
32 
33     Status ParserNalUnits(uint8_t *nalData, int32_t nalDataSize, uint32_t frameId, int64_t dts);
34     Status ParserExtraData(uint8_t *extraData, int32_t extraDataSize);
35     Status ParserSdtpData(uint8_t *sdtpData, int32_t sdtpDataSize);
36     Status GetFrameLayerInfo(uint32_t frameId, FrameLayerInfo &frameLayerInfo);
37     Status GetFrameLayerInfo(int64_t dts, FrameLayerInfo &frameLayerInfo);
38     Status GetGopLayerInfo(uint32_t gopId, GopLayerInfo &gopLayerInfo);
39 
40 private:
41     RefParser *referenceParser_ {nullptr};
42     // .so initialize
43     static void *handler_;
44     static void *LoadPluginFile(const std::string &path);
45     static bool CheckSymbol(void *handler);
46     using CreateFunc = RefParser *(*)(CodecType, std::vector<uint32_t>&);
47     using DestroyFunc = void (*)(RefParser *);
48     static CreateFunc createFunc_;
49     static DestroyFunc destroyFunc_;
50     static std::mutex mtx_;
51 };
52 } // namespace Plugins
53 } // namespace Media
54 } // namespace OHOS
55 #endif // REFERENCE_PARSER_MANAGER_H