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