1 /*
2  * Copyright (c) 2023-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 PLUGINS_CODEC_PLUGIN_H
17 #define PLUGINS_CODEC_PLUGIN_H
18 
19 #include <vector>
20 #include <memory>
21 #include "meta/media_types.h"
22 #include "buffer/avbuffer.h"
23 #include "plugin/plugin_base.h"
24 #include "plugin/plugin_event.h"
25 #include "plugin/plugin_definition.h"
26 #include "meta/meta.h"
27 #include "common/status.h"
28 
29 namespace OHOS {
30 namespace Media {
31 namespace Plugins {
32 class DataCallback {
33 public:
34     virtual ~DataCallback() = default;
35 
36     virtual void OnInputBufferDone(const std::shared_ptr<AVBuffer> &inputBuffer) = 0;
37 
38     virtual void OnOutputBufferDone(const std::shared_ptr<AVBuffer> &outputBuffer) = 0;
39 
40     virtual void OnEvent(const std::shared_ptr<Plugins::PluginEvent> event) = 0;
41 };
42 
43 class CodecPlugin : public Plugins::PluginBase {
44 public:
CodecPlugin(std::string name)45     explicit CodecPlugin(std::string name) : PluginBase(std::move(name)) {}
46     virtual Status GetInputBuffers(std::vector<std::shared_ptr<AVBuffer>> &inputBuffers) = 0;
47 
48     virtual Status GetOutputBuffers(std::vector<std::shared_ptr<AVBuffer>> &outputBuffers) = 0;
49 
50     virtual Status QueueInputBuffer(const std::shared_ptr<AVBuffer> &inputBuffer) = 0;
51 
52     virtual Status QueueOutputBuffer(std::shared_ptr<AVBuffer> &outputBuffer) = 0;
53 
54     virtual Status SetParameter(const std::shared_ptr<Meta> &parameter) = 0;
55 
56     virtual Status GetParameter(std::shared_ptr<Meta> &parameter) = 0;
57 
58     virtual Status Start() = 0;
59 
60     virtual Status Stop() = 0;
61 
62     virtual Status Flush() = 0;
63 
64     virtual Status Reset() = 0;
65 
66     virtual Status Release() = 0;
67 
68     virtual Status SetDataCallback(DataCallback *dataCallback) = 0;
69 };
70 
71 /// Codec plugin api major number.
72 #define CODEC_API_VERSION_MAJOR (1)
73 
74 /// Codec plugin api minor number
75 #define CODEC_API_VERSION_MINOR (0)
76 
77 /// Codec plugin version
78 #define CODEC_API_VERSION MAKE_VERSION(CODEC_API_VERSION_MAJOR, CODEC_API_VERSION_MINOR)
79 
80 /**
81  * @brief Describes the codec plugin information.
82  *
83  * @since 1.0
84  * @version 1.0
85  */
86 struct CodecPluginDef : public PluginDefBase {
CodecPluginDefCodecPluginDef87     CodecPluginDef()
88     {
89         apiVersion = CODEC_API_VERSION;         ///< Codec plugin version
90         pluginType = PluginType::AUDIO_DECODER; ///< Plugin type, MUST be AUDIO_DECODER.
91     }
92 };
93 } // namespace Plugins
94 } // namespace Media
95 } // namespace OHOS
96 #endif // PLUGINS_MEDIA_CODEC_PLUGIN_H
97