1 /* 2 * Copyright (c) 2023-2023 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 #if defined(VIDEO_SUPPORT) 17 18 #ifndef HISTREAMER_PLUGIN_CODEC_CMD_EXECUTOR_H 19 #define HISTREAMER_PLUGIN_CODEC_CMD_EXECUTOR_H 20 #include <map> 21 #include <vector> 22 #include "v4_0/icodec_component.h" 23 #include "v4_0/codec_types.h" 24 #include "foundation/osal/thread/condition_variable.h" 25 #include "foundation/osal/thread/mutex.h" 26 #include "plugin/common/any.h" 27 #include "plugin/common/plugin_types.h" 28 #include "plugin/interface/plugin_base.h" 29 #include "OMX_Core.h" 30 31 namespace OHOS { 32 namespace Media { 33 namespace Plugin { 34 namespace CodecAdapter { 35 namespace CodecHDI = OHOS::HDI::Codec::V4_0; 36 enum Result { 37 INVALID, 38 SUCCESS, 39 FAIL 40 }; 41 class CodecCmdExecutor { 42 public: 43 CodecCmdExecutor(sptr<CodecHDI::ICodecComponent>& component, uint32_t inPortIndex); 44 ~CodecCmdExecutor() = default; 45 46 Status OnEvent(CodecHDI::CodecEventType event, const CodecHDI::EventInfo& info); 47 Status SendCmd(OMX_COMMANDTYPE cmd, const Plugin::Any& param); 48 bool WaitCmdResult(OMX_COMMANDTYPE cmd, const Plugin::Any& param); 49 Status SetCallback(Callback* cb); 50 private: 51 void HandleEventCmdComplete(uint32_t data1, uint32_t data2); 52 void HandleEventPortSettingsChanged(OMX_U32 data1, OMX_U32 data2); 53 void HandleEventBufferFlag(OMX_U32 data1, OMX_U32 data2); 54 void HandleEventError(OMX_U32 data1, OMX_U32 data2); 55 56 Callback* callback_ {nullptr}; 57 58 sptr<CodecHDI::ICodecComponent> codecComp_ {nullptr}; 59 uint32_t inPortIndex_; 60 OSAL::Mutex mutex_; 61 OSAL::ConditionVariable cond_; 62 63 int lastCmd_ = -2; // -1 for error cmd and -2 for invaild 64 std::map<OMX_COMMANDTYPE, Any> resultMap_{}; 65 }; 66 } // namespace CodecAdapter 67 } // namespace Plugin 68 } // namespace Media 69 } // namespace OHOS 70 #endif // HISTREAMER_PLUGIN_CODEC_CMD_EXECUTOR_H 71 #endif