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 <vector>
23 #include "codec_buffer_pool.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,CodecHDI::CompVerInfo & verInfo)46 inline void InitHdiParam(T& param, CodecHDI::CompVerInfo& verInfo)
47 {
48 memset_s(¶m, sizeof(param), 0x0, sizeof(param));
49 param.size = sizeof(param);
50 param.version.nVersion = verInfo.compVersion.nVersion;
51 }
52
53 template <typename T>
InitOmxParam(T & param,CodecHDI::CompVerInfo & verInfo)54 inline void InitOmxParam(T& param, CodecHDI::CompVerInfo& verInfo)
55 {
56 memset_s(¶m, sizeof(param), 0x0, sizeof(param));
57 param.nSize = sizeof(param);
58 param.nVersion.nVersion = verInfo.compVersion.nVersion;
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 const int8_t* p = reinterpret_cast<const int8_t*>(¶m);
65 std::vector<int8_t> inVec(p, p + sizeof(T));
66 return component->SetParameter(paramIndex, inVec);
67 }
68
69 template <typename T, typename U>
HdiGetParameter(T & component,uint32_t paramIndex,U & param)70 inline int32_t HdiGetParameter(T& component, uint32_t paramIndex, U& param)
71 {
72 std::vector<int8_t> inVec(reinterpret_cast<int8_t*>(¶m), reinterpret_cast<int8_t*>(¶m) + sizeof(T));
73 std::vector<int8_t> outVec;
74 auto ret = component->GetParameter(paramIndex, inVec, outVec);
75 if (ret != HDF_SUCCESS || outVec.size() != sizeof(T)) {
76 return HDF_FAILURE;
77 }
78 return (memcpy_s(¶m, sizeof(T), outVec.data(), outVec.size()) == EOK) ? HDF_SUCCESS : HDF_FAILURE;
79 }
80
81 template <typename T, typename U>
HdiSendCommand(T & component,OMX_COMMANDTYPE cmd,uint32_t param,U && cmdData)82 inline int32_t HdiSendCommand(T& component, OMX_COMMANDTYPE cmd, uint32_t param, U&& cmdData)
83 {
84 return component->SendCommand(static_cast<CodecHDI::CodecCommandType>(cmd), param, {});
85 }
86
87 template <typename T, typename U>
HdiFillThisBuffer(T & component,U & buffer)88 inline int32_t HdiFillThisBuffer(T& component, U& buffer)
89 {
90 return component->FillThisBuffer(buffer);
91 }
92
93 template <typename T, typename U>
HdiEmptyThisBuffer(T & component,U & buffer)94 inline int32_t HdiEmptyThisBuffer(T& component, U& buffer)
95 {
96 return component->EmptyThisBuffer(buffer);
97 }
98
99 } // namespace CodecAdapter
100 } // namespace Plugin
101 } // namespace Media
102 } // namespace OHOS
103 #endif // HISTREAMER_PLUGIN_PLUGINS_CODEC_UTILS_H
104 #endif