1 /*
2 * Copyright (C) 2022 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 OMX_CODEC_UTIL_H
17 #define OMX_CODEC_UTIL_H
18
19 #include <memory>
20 #include <gst/gst.h>
21 #include <gst/video/gstvideodecoder.h>
22 #include "securec.h"
23 #include "i_gst_codec.h"
24 #include "OMX_Core.h"
25 #include "OMX_Component.h"
26 #include "display_type.h"
27 #include "codec_component_if.h"
28 #include "codec_omx_ext.h"
29
30 namespace OHOS {
31 namespace Media {
32 class HdiCodecUtil {
33 public:
34 static OMX_VIDEO_CODINGTYPE CompressionGstToHdi(GstCompressionFormat format);
35 static PixelFormat FormatGstToHdi(GstVideoFormat format);
36 static GstVideoFormat FormatHdiToGst(PixelFormat format);
37 static OMX_COLOR_FORMATTYPE FormatGstToOmx(GstVideoFormat format);
38 static GstVideoFormat FormatOmxToGst(OMX_COLOR_FORMATTYPE format);
39 private:
40 HdiCodecUtil() = delete;
41 ~HdiCodecUtil() = delete;
42 };
43
44 template <typename T>
InitParam(T & param,CompVerInfo & verInfo)45 inline void InitParam(T ¶m, CompVerInfo &verInfo)
46 {
47 memset_s(¶m, sizeof(param), 0x0, sizeof(param));
48 param.nSize = sizeof(param);
49 param.nVersion = verInfo.compVersion;
50 }
51
52 template <typename T>
InitHdiParam(T & param,CompVerInfo & verInfo)53 inline void InitHdiParam(T ¶m, CompVerInfo &verInfo)
54 {
55 memset_s(¶m, sizeof(param), 0x0, sizeof(param));
56 param.size = sizeof(param);
57 param.version = verInfo.compVersion;
58 }
59
60 template <typename T, typename U>
HdiSetParameter(T * handle,uint32_t paramIndex,U & param)61 inline int32_t HdiSetParameter(T *handle, uint32_t paramIndex, U ¶m)
62 {
63 return handle->SetParameter(handle, paramIndex, reinterpret_cast<int8_t *>(¶m), sizeof(param));
64 }
65
66 template <typename T, typename U>
HdiGetParameter(T * handle,uint32_t paramIndex,U & param)67 inline int32_t HdiGetParameter(T *handle, uint32_t paramIndex, U ¶m)
68 {
69 return handle->GetParameter(handle, paramIndex, reinterpret_cast<int8_t *>(¶m), sizeof(param));
70 }
71
72 template <typename T, typename U>
HdiGetConfig(T * handle,uint32_t paramIndex,U & param)73 inline int32_t HdiGetConfig(T *handle, uint32_t paramIndex, U ¶m)
74 {
75 return handle->GetConfig(handle, paramIndex, reinterpret_cast<int8_t *>(¶m), sizeof(param));
76 }
77
78 template <typename T, typename U>
HdiSetConfig(T * handle,uint32_t paramIndex,U & param)79 inline int32_t HdiSetConfig(T *handle, uint32_t paramIndex, U ¶m)
80 {
81 return handle->SetConfig(handle, paramIndex, reinterpret_cast<int8_t *>(¶m), sizeof(param));
82 }
83
84 template <typename T, typename U>
HdiSendCommand(T * handle,OMX_COMMANDTYPE cmd,uint32_t param,U && cmdData)85 inline int32_t HdiSendCommand(T *handle, OMX_COMMANDTYPE cmd, uint32_t param, U &&cmdData)
86 {
87 return handle->SendCommand(handle, cmd, param, reinterpret_cast<int8_t *>(&cmdData), sizeof(cmdData));
88 }
89
90 template <typename T, typename U>
HdiFillThisBuffer(T * handle,U * buffer)91 inline int32_t HdiFillThisBuffer(T *handle, U *buffer)
92 {
93 return handle->FillThisBuffer(handle, buffer);
94 }
95
96 template <typename T, typename U>
HdiEmptyThisBuffer(T * handle,U * buffer)97 inline int32_t HdiEmptyThisBuffer(T *handle, U *buffer)
98 {
99 return handle->EmptyThisBuffer(handle, buffer);
100 }
101
102 template <typename T>
EmptyList(T & list)103 inline void EmptyList(T &list)
104 {
105 T temp;
106 list.swap(temp);
107 }
108 } // namespace Media
109 } // namespace OHOS
110 #endif // OMX_CODEC_UTIL_H