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 #include "plugin/core/codec.h"
17 #include <memory>
18 #include "foundation/pre_defines.h"
19 #include "plugin/interface/codec_plugin.h"
20 
21 namespace OHOS {
22 namespace Media {
23 namespace Plugin {
Codec(uint32_t pkgVer,uint32_t apiVer,std::shared_ptr<CodecPlugin> plugin)24 Codec::Codec(uint32_t pkgVer, uint32_t apiVer, std::shared_ptr<CodecPlugin> plugin)
25     : Base(pkgVer, apiVer, plugin), codec_(std::move(plugin))
26 {
27 }
28 
QueueInputBuffer(const std::shared_ptr<Buffer> & inputBuffer,int32_t timeoutMs)29 Status Codec::QueueInputBuffer(const std::shared_ptr<Buffer>& inputBuffer, int32_t timeoutMs)
30 {
31     return codec_->QueueInputBuffer(inputBuffer, timeoutMs);
32 }
33 
QueueOutputBuffer(const std::shared_ptr<Buffer> & outputBuffers,int32_t timeoutMs)34 Status Codec::QueueOutputBuffer(const std::shared_ptr<Buffer>& outputBuffers, int32_t timeoutMs)
35 {
36     return codec_->QueueOutputBuffer(outputBuffers, timeoutMs);
37 }
38 
Flush()39 Status Codec::Flush()
40 {
41     return codec_->Flush();
42 }
43 
44 struct DataCallbackWrapper : DataCallback {
DataCallbackWrapperOHOS::Media::Plugin::DataCallbackWrapper45 DataCallbackWrapper(uint32_t pkgVersion, DataCallbackHelper* dataCallback)
46     : version(pkgVersion), dataCallbackHelper(dataCallback)
47 {
48 }
49 
50 ~DataCallbackWrapper() override = default;
51 
OnInputBufferDoneOHOS::Media::Plugin::DataCallbackWrapper52 void OnInputBufferDone(const std::shared_ptr<Buffer>& input) override
53 {
54     dataCallbackHelper->OnInputBufferDone(input);
55 }
56 
OnOutputBufferDoneOHOS::Media::Plugin::DataCallbackWrapper57 void OnOutputBufferDone(const std::shared_ptr<Buffer>& output) override
58 {
59     dataCallbackHelper->OnOutputBufferDone(output);
60 }
61 
62 private:
63     MEDIA_UNUSED uint32_t version;
64     DataCallbackHelper* dataCallbackHelper;
65 };
66 
SetDataCallback(DataCallbackHelper * dataCallback)67 Status Codec::SetDataCallback(DataCallbackHelper* dataCallback)
68 {
69     dataCallback_ = std::make_shared<DataCallbackWrapper>(pkgVersion_, dataCallback);
70     return codec_->SetDataCallback(dataCallback_.get());
71 }
72 } // namespace Plugin
73 } // namespace Media
74 } // namespace OHOS