1 /*
2  * Copyright (c) 2021-2021 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 HISTREAMER_PLUGIN_CORE_CODEC_H
17 #define HISTREAMER_PLUGIN_CORE_CODEC_H
18 
19 #include <memory>
20 
21 #include "plugin/common/plugin_types.h"
22 #include "plugin/common/plugin_tags.h"
23 #include "plugin/common/plugin_buffer.h"
24 #include "plugin/core/base.h"
25 
26 namespace OHOS {
27 namespace Media {
28 namespace Plugin {
29 struct DataCallbackHelper {
30     virtual ~DataCallbackHelper() = default;
31     virtual void OnInputBufferDone(const std::shared_ptr<Buffer> &input) = 0;
32     virtual void OnOutputBufferDone(const std::shared_ptr<Buffer> &output) = 0;
33 };
34 
35 struct CodecPlugin;
36 
37 struct DataCallback;
38 
39 class Codec : public Base {
40 public:
41     Codec(const Codec &) = delete;
42 
43     Codec operator=(const Codec &) = delete;
44 
45     ~Codec() override = default;
46 
47     Status QueueInputBuffer(const std::shared_ptr<Buffer>& inputBuffer, int32_t timeoutMs);
48 
49     Status QueueOutputBuffer(const std::shared_ptr<Buffer>& outputBuffers, int32_t timeoutMs);
50 
51     Status Flush();
52 
53     Status SetDataCallback(DataCallbackHelper* dataCallback);
54 
55 private:
56     friend class PluginManager;
57 
58     Codec(uint32_t pkgVer, uint32_t apiVer, std::shared_ptr<CodecPlugin> plugin);
59 
60 private:
61     std::shared_ptr<CodecPlugin> codec_;
62 
63     std::shared_ptr<DataCallback> dataCallback_;
64 };
65 } // namespace Plugin
66 } // namespace Media
67 } // namespace OHOS
68 #endif // HISTREAMER_PLUGIN_CORE_CODEC_H
69