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 MEDIA_AVCODEC_LIST_H
17 #define MEDIA_AVCODEC_LIST_H
18 
19 #include <cstdint>
20 #include <memory>
21 #include "avcodec_info.h"
22 
23 namespace OHOS {
24 namespace MediaAVCodec {
25 class AVCodecList {
26 public:
27     virtual ~AVCodecList() = default;
28 
29     /**
30      * @brief Find the supported decoder name by format(must contains video or audio MIME).
31      * @param format Indicates a media description which contains required decoder capability.
32      * @return Returns decoder name, if not find, return empty string.
33      * @since 10
34      * @version 1.0
35      */
36     virtual std::string FindDecoder(const Format &format) = 0;
37 
38     /**
39      * @brief Find the supported encoder name by format(must contains video or audio MIME).
40      * @param format Indicates a media description which contains required encoder capability.
41      * @return Returns encoder name, if not find, return empty string.
42      * @since 10
43      * @version 1.0
44      */
45     virtual std::string FindEncoder(const Format &format) = 0;
46 
47     /**
48      * @brief Create a capability by codec name
49      * @param codeName Codec name
50      * @return Returns an array of supported video decoder capability, if not find, return invalid CapabilityData.
51      * @since 10
52      * @version 1.0
53      */
54     virtual CapabilityData *GetCapability(const std::string &mime, const bool isEncoder,
55                                          const AVCodecCategory &category) = 0;
56     virtual void *GetBuffer(const std::string &name, uint32_t sizeOfCap) = 0;
57     virtual void *NewBuffer(size_t bufSize) = 0;
58     virtual void DeleteBuffer(void *bufAddr) = 0;
59 };
60 
61 class __attribute__((visibility("default"))) AVCodecListFactory {
62 public:
63 #ifdef UNSUPPORT_CODECLIST
CreateAVCodecList()64     static std::shared_ptr<AVCodecList> CreateAVCodecList()
65     {
66         return nullptr;
67     }
68 #else
69     static std::shared_ptr<AVCodecList> CreateAVCodecList();
70 #endif
71 private:
72     AVCodecListFactory() = default;
73     ~AVCodecListFactory() = default;
74 };
75 } // namespace MediaAVCodec
76 } // namespace OHOS
77 #endif // MEDIA_AVCODEC_LIST_H
78