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 "base.h" 22 #include "common/plugin_types.h" 23 #include "common/plugin_tags.h" 24 #include "common/plugin_buffer.h" 25 26 namespace OHOS { 27 namespace Media { 28 namespace Plugin { 29 struct DataCallbackHelper { 30 virtual ~DataCallbackHelper() = default; 31 virtual void OnInputBufferDone(std::shared_ptr<Buffer> &input) = 0; 32 virtual void OnOutputBufferDone(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 DequeueInputBuffer(std::shared_ptr<Buffer>& inputBuffer, int32_t timeoutMs); 50 51 Status QueueOutputBuffer(const std::shared_ptr<Buffer>& outputBuffers, int32_t timeoutMs); 52 53 Status DequeueOutputBuffer(std::shared_ptr<Buffer>& outputBuffers, int32_t timeoutMs); 54 55 Status Flush(); 56 57 Status SetDataCallback(DataCallbackHelper* dataCallback); 58 59 private: 60 friend class PluginManager; 61 62 Codec(uint32_t pkgVer, uint32_t apiVer, std::shared_ptr<CodecPlugin> plugin); 63 64 private: 65 std::shared_ptr<CodecPlugin> codec_; 66 67 std::shared_ptr<DataCallback> dataCallback_; 68 }; 69 } // namespace Plugin 70 } // namespace Media 71 } // namespace OHOS 72 #endif // HISTREAMER_PLUGIN_CORE_CODEC_H 73