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 #include "player_xcollie.h"
30
31 namespace OHOS {
32 namespace Media {
33 class HdiCodecUtil {
34 public:
35 static OMX_VIDEO_CODINGTYPE CompressionGstToHdi(GstCompressionFormat format);
36 static PixelFormat FormatGstToHdi(GstVideoFormat format);
37 static GstVideoFormat FormatHdiToGst(PixelFormat format);
38 private:
39 HdiCodecUtil() = delete;
40 ~HdiCodecUtil() = delete;
41 };
42
43 template <typename T>
InitParam(T & param,CompVerInfo & verInfo)44 inline void InitParam(T ¶m, CompVerInfo &verInfo)
45 {
46 memset_s(¶m, sizeof(param), 0x0, sizeof(param));
47 param.nSize = sizeof(param);
48 param.nVersion = verInfo.compVersion;
49 }
50
51 template <typename T>
InitHdiParam(T & param,CompVerInfo & verInfo)52 inline void InitHdiParam(T ¶m, CompVerInfo &verInfo)
53 {
54 memset_s(¶m, sizeof(param), 0x0, sizeof(param));
55 param.size = sizeof(param);
56 param.version = verInfo.compVersion;
57 }
58
59 template <typename T, typename U>
HdiSetParameter(T * handle,uint32_t paramIndex,U & param)60 inline int32_t HdiSetParameter(T *handle, uint32_t paramIndex, U ¶m)
61 {
62 XcollieTimer xCollie("HdiSetParameter", PlayerXCollie::timerTimeout);
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 XcollieTimer xCollie("HdiGetParameter", PlayerXCollie::timerTimeout);
70 return handle->GetParameter(handle, paramIndex, reinterpret_cast<int8_t *>(¶m), sizeof(param));
71 }
72
73 template <typename T, typename U>
HdiGetConfig(T * handle,uint32_t paramIndex,U & param)74 inline int32_t HdiGetConfig(T *handle, uint32_t paramIndex, U ¶m)
75 {
76 XcollieTimer xCollie("HdiGetConfig", PlayerXCollie::timerTimeout);
77 return handle->GetConfig(handle, paramIndex, reinterpret_cast<int8_t *>(¶m), sizeof(param));
78 }
79
80 template <typename T, typename U>
HdiSetConfig(T * handle,uint32_t paramIndex,U & param)81 inline int32_t HdiSetConfig(T *handle, uint32_t paramIndex, U ¶m)
82 {
83 XcollieTimer xCollie("HdiSetConfig", PlayerXCollie::timerTimeout);
84 return handle->SetConfig(handle, paramIndex, reinterpret_cast<int8_t *>(¶m), sizeof(param));
85 }
86
87 template <typename T, typename U>
HdiSendCommand(T * handle,OMX_COMMANDTYPE cmd,uint32_t param,U && cmdData)88 inline int32_t HdiSendCommand(T *handle, OMX_COMMANDTYPE cmd, uint32_t param, U &&cmdData)
89 {
90 XcollieTimer xCollie("HdiSendCommand", PlayerXCollie::timerTimeout);
91 return handle->SendCommand(handle, cmd, param, reinterpret_cast<int8_t *>(&cmdData), sizeof(cmdData));
92 }
93
94 template <typename T, typename U>
HdiFillThisBuffer(T * handle,U * buffer)95 inline int32_t HdiFillThisBuffer(T *handle, U *buffer)
96 {
97 XcollieTimer xCollie("HdiFillThisBuffer", PlayerXCollie::timerTimeout);
98 return handle->FillThisBuffer(handle, buffer);
99 }
100
101 template <typename T, typename U>
HdiEmptyThisBuffer(T * handle,U * buffer)102 inline int32_t HdiEmptyThisBuffer(T *handle, U *buffer)
103 {
104 XcollieTimer xCollie("HdiEmptyThisBuffer", PlayerXCollie::timerTimeout);
105 return handle->EmptyThisBuffer(handle, buffer);
106 }
107
108 template <typename T>
EmptyList(T & list)109 inline void EmptyList(T &list)
110 {
111 T temp;
112 list.swap(temp);
113 }
114 } // namespace Media
115 } // namespace OHOS
116 #endif // OMX_CODEC_UTIL_H