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_PLUGINS_CODEC_UTILS_H
19 #define HISTREAMER_PLUGIN_PLUGINS_CODEC_UTILS_H
20 
21 #include <iostream>
22 #include "codec_buffer_pool.h"
23 #include "display_type.h"
24 #include "OMX_Video.h"
25 
26 namespace OHOS {
27 namespace Media {
28 namespace Plugin {
29 namespace CodecAdapter {
30 std::string HdfStatus2String(int32_t status);
31 
32 std::string OmxErrorType2String(uint32_t errorType);
33 
34 Status TransHdiRetVal2Status(const int32_t& ret);
35 
36 uint32_t Translate2omxFlagSet(uint64_t pluginFlags);
37 
38 uint64_t Translate2PluginFlagSet(uint32_t omxBufFlag);
39 std::string OmxStateToString(OMX_STATETYPE state);
40 
41 OMX_VIDEO_CODINGTYPE CodingTypeHstToHdi(const std::string& format);
42 OMX_COLOR_FORMATTYPE FormatHstToOmx(const VideoPixelFormat format);
43 
44 uint32_t GetOmxBufferType(const MemoryType& bufMemType, bool isInput);
45 template <typename T>
InitHdiParam(T & param,CompVerInfo & verInfo)46 inline void InitHdiParam(T& param, CompVerInfo& verInfo)
47 {
48     memset_s(&param, sizeof(param), 0x0, sizeof(param));
49     param.size = sizeof(param);
50     param.version = verInfo.compVersion;
51 }
52 
53 template <typename T>
InitOmxParam(T & param,CompVerInfo & verInfo)54 inline void InitOmxParam(T& param, CompVerInfo& verInfo)
55 {
56     memset_s(&param, sizeof(param), 0x0, sizeof(param));
57     param.nSize = sizeof(param);
58     param.nVersion = verInfo.compVersion;
59 }
60 
61 template <typename T, typename U>
HdiSetParameter(T * component,uint32_t paramIndex,U & param)62 inline int32_t HdiSetParameter(T* component, uint32_t paramIndex, U& param)
63 {
64     return component->SetParameter(component, paramIndex, reinterpret_cast<int8_t*>(&param), sizeof(param));
65 }
66 
67 template <typename T, typename U>
HdiGetParameter(T * component,uint32_t paramIndex,U & param)68 inline int32_t HdiGetParameter(T* component, uint32_t paramIndex, U& param)
69 {
70     return component->GetParameter(component, paramIndex, reinterpret_cast<int8_t*>(&param), sizeof(param));
71 }
72 
73 template <typename T, typename U>
HdiSendCommand(T * component,OMX_COMMANDTYPE cmd,uint32_t param,U && cmdData)74 inline int32_t HdiSendCommand(T* component, OMX_COMMANDTYPE cmd, uint32_t param, U&& cmdData)
75 {
76     return component->SendCommand(component, cmd, param, reinterpret_cast<int8_t*>(&cmdData), sizeof(cmdData));
77 }
78 
79 template <typename T, typename U>
HdiFillThisBuffer(T * component,U * buffer)80 inline int32_t HdiFillThisBuffer(T* component, U* buffer)
81 {
82     return component->FillThisBuffer(component, buffer);
83 }
84 
85 template <typename T, typename U>
HdiEmptyThisBuffer(T * component,U * buffer)86 inline int32_t HdiEmptyThisBuffer(T* component, U* buffer)
87 {
88     return component->EmptyThisBuffer(component, buffer);
89 }
90 
91 } // namespace CodecAdapter
92 } // namespace Plugin
93 } // namespace Media
94 } // namespace OHOS
95 #endif // HISTREAMER_PLUGIN_PLUGINS_CODEC_UTILS_H
96 #endif