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