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