• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <hdf_base.h>
17 #include <hdf_dlist.h>
18 #include <hdf_log.h>
19 #include <osal_mem.h>
20 #include "codec_adapter_if.h"
21 
22 #define HDF_LOG_TAG codec_hdi_passthrough
23 
ComponentTypeGetComponentVersion(struct CodecComponentType * self,struct CompVerInfo * verInfo)24 static int32_t ComponentTypeGetComponentVersion(struct CodecComponentType *self, struct CompVerInfo *verInfo)
25 {
26     struct CodecComponentTypeInfo *info = CONTAINER_OF(self, struct CodecComponentTypeInfo, instance);
27     if (info == NULL) {
28         HDF_LOGE("%{public}s: info is null", __func__);
29         return HDF_FAILURE;
30     }
31     return CodecAdapterGetComponentVersion(info->codecNode, verInfo);
32 }
33 
ComponentTypeSendCommand(struct CodecComponentType * self,enum OMX_COMMANDTYPE cmd,uint32_t param,int8_t * cmdData,uint32_t cmdDataLen)34 static int32_t ComponentTypeSendCommand(
35     struct CodecComponentType *self, enum OMX_COMMANDTYPE cmd, uint32_t param, int8_t *cmdData, uint32_t cmdDataLen)
36 {
37     struct CodecComponentTypeInfo *info = CONTAINER_OF(self, struct CodecComponentTypeInfo, instance);
38     if (info == NULL) {
39         HDF_LOGE("%{public}s: info is null", __func__);
40         return HDF_FAILURE;
41     }
42     return CodecAdapterSendCommand(info->codecNode, cmd, param, cmdData, cmdDataLen);
43 }
44 
ComponentTypeGetParameter(struct CodecComponentType * self,uint32_t paramIndex,int8_t * paramStruct,uint32_t paramStructLen)45 static int32_t ComponentTypeGetParameter(
46     struct CodecComponentType *self, uint32_t paramIndex, int8_t *paramStruct, uint32_t paramStructLen)
47 {
48     struct CodecComponentTypeInfo *info = CONTAINER_OF(self, struct CodecComponentTypeInfo, instance);
49     if (info == NULL) {
50         HDF_LOGE("%{public}s: info is null", __func__);
51         return HDF_FAILURE;
52     }
53     return CodecAdapterGetParameter(info->codecNode, paramIndex, paramStruct, paramStructLen);
54 }
55 
ComponentTypeSetParameter(struct CodecComponentType * self,uint32_t index,int8_t * paramStruct,uint32_t paramStructLen)56 static int32_t ComponentTypeSetParameter(
57     struct CodecComponentType *self, uint32_t index, int8_t *paramStruct, uint32_t paramStructLen)
58 {
59     struct CodecComponentTypeInfo *info = CONTAINER_OF(self, struct CodecComponentTypeInfo, instance);
60     if (info == NULL) {
61         HDF_LOGE("%{public}s: info is null", __func__);
62         return HDF_FAILURE;
63     }
64     return CodecAdapterSetParameter(info->codecNode, index, paramStruct, paramStructLen);
65 }
66 
ComponentTypeGetConfig(struct CodecComponentType * self,uint32_t index,int8_t * cfgStruct,uint32_t cfgStructLen)67 static int32_t ComponentTypeGetConfig(
68     struct CodecComponentType *self, uint32_t index, int8_t *cfgStruct, uint32_t cfgStructLen)
69 {
70     struct CodecComponentTypeInfo *info = CONTAINER_OF(self, struct CodecComponentTypeInfo, instance);
71     if (info == NULL) {
72         HDF_LOGE("%{public}s: info is null", __func__);
73         return HDF_FAILURE;
74     }
75     return CodecAdapterGetConfig(info->codecNode, index, cfgStruct, cfgStructLen);
76 }
77 
ComponentTypeSetConfig(struct CodecComponentType * self,uint32_t index,int8_t * cfgStruct,uint32_t cfgStructLen)78 static int32_t ComponentTypeSetConfig(
79     struct CodecComponentType *self, uint32_t index, int8_t *cfgStruct, uint32_t cfgStructLen)
80 {
81     struct CodecComponentTypeInfo *info = CONTAINER_OF(self, struct CodecComponentTypeInfo, instance);
82     if (info == NULL) {
83         HDF_LOGE("%{public}s: info is null", __func__);
84         return HDF_FAILURE;
85     }
86     return CodecAdapterSetConfig(info->codecNode, index, cfgStruct, cfgStructLen);
87 }
88 
ComponentTypeGetExtensionIndex(struct CodecComponentType * self,const char * paramName,uint32_t * indexType)89 static int32_t ComponentTypeGetExtensionIndex(
90     struct CodecComponentType *self, const char *paramName, uint32_t *indexType)
91 {
92     struct CodecComponentTypeInfo *info = CONTAINER_OF(self, struct CodecComponentTypeInfo, instance);
93     if (info == NULL) {
94         HDF_LOGE("%{public}s: info is null", __func__);
95         return HDF_FAILURE;
96     }
97     return CodecAdapterGetExtensionIndex(info->codecNode, paramName, indexType);
98 }
99 
ComponentTypeGetState(struct CodecComponentType * self,enum OMX_STATETYPE * state)100 static int32_t ComponentTypeGetState(struct CodecComponentType *self, enum OMX_STATETYPE *state)
101 {
102     struct CodecComponentTypeInfo *info = CONTAINER_OF(self, struct CodecComponentTypeInfo, instance);
103     if (info == NULL) {
104         HDF_LOGE("%{public}s: info is null", __func__);
105         return HDF_FAILURE;
106     }
107     return CodecAdapterGetState(info->codecNode, state);
108 }
109 
ComponentTypeComponentTunnelRequest(struct CodecComponentType * self,uint32_t port,int32_t tunneledComp,uint32_t tunneledPort,struct OMX_TUNNELSETUPTYPE * tunnelSetup)110 static int32_t ComponentTypeComponentTunnelRequest(struct CodecComponentType *self, uint32_t port, int32_t tunneledComp,
111     uint32_t tunneledPort, struct OMX_TUNNELSETUPTYPE *tunnelSetup)
112 {
113     struct CodecComponentTypeInfo *info = CONTAINER_OF(self, struct CodecComponentTypeInfo, instance);
114     if (info == NULL) {
115         HDF_LOGE("%{public}s: info is null", __func__);
116         return HDF_FAILURE;
117     }
118     return CodecAdapterComponentTunnelRequest(info->codecNode, port, tunneledComp, tunneledPort, tunnelSetup);
119 }
120 
ComponentTypeUseBuffer(struct CodecComponentType * self,uint32_t portIndex,struct OmxCodecBuffer * buffer)121 static int32_t ComponentTypeUseBuffer(
122     struct CodecComponentType *self, uint32_t portIndex, struct OmxCodecBuffer *buffer)
123 {
124     struct CodecComponentTypeInfo *info = CONTAINER_OF(self, struct CodecComponentTypeInfo, instance);
125     if (info == NULL) {
126         HDF_LOGE("%{public}s: info is null", __func__);
127         return HDF_FAILURE;
128     }
129     return CodecAdapterUseBuffer(info->codecNode, portIndex, buffer);
130 }
131 
ComponentTypeAllocateBuffer(struct CodecComponentType * self,uint32_t portIndex,struct OmxCodecBuffer * buffer)132 static int32_t ComponentTypeAllocateBuffer(
133     struct CodecComponentType *self, uint32_t portIndex, struct OmxCodecBuffer *buffer)
134 {
135     struct CodecComponentTypeInfo *info = CONTAINER_OF(self, struct CodecComponentTypeInfo, instance);
136     if (info == NULL) {
137         HDF_LOGE("%{public}s: info is null", __func__);
138         return HDF_FAILURE;
139     }
140     return CodecAdapterAllocateBuffer(info->codecNode, portIndex, buffer);
141 }
142 
ComponentTypeFreeBuffer(struct CodecComponentType * self,uint32_t portIndex,const struct OmxCodecBuffer * buffer)143 static int32_t ComponentTypeFreeBuffer(
144     struct CodecComponentType *self, uint32_t portIndex, const struct OmxCodecBuffer *buffer)
145 {
146     struct CodecComponentTypeInfo *info = CONTAINER_OF(self, struct CodecComponentTypeInfo, instance);
147     if (info == NULL) {
148         HDF_LOGE("%{public}s: info is null", __func__);
149         return HDF_FAILURE;
150     }
151     return CodecAdapterFreeBuffer(info->codecNode, portIndex, buffer);
152 }
153 
ComponentTypeEmptyThisBuffer(struct CodecComponentType * self,const struct OmxCodecBuffer * buffer)154 static int32_t ComponentTypeEmptyThisBuffer(struct CodecComponentType *self, const struct OmxCodecBuffer *buffer)
155 {
156     struct CodecComponentTypeInfo *info = CONTAINER_OF(self, struct CodecComponentTypeInfo, instance);
157     if (info == NULL) {
158         HDF_LOGE("%{public}s: info is null", __func__);
159         return HDF_FAILURE;
160     }
161     return CodecAdapterEmptyThisBuffer(info->codecNode, buffer);
162 }
163 
ComponentTypeFillThisBuffer(struct CodecComponentType * self,const struct OmxCodecBuffer * buffer)164 static int32_t ComponentTypeFillThisBuffer(struct CodecComponentType *self, const struct OmxCodecBuffer *buffer)
165 {
166     struct CodecComponentTypeInfo *info = CONTAINER_OF(self, struct CodecComponentTypeInfo, instance);
167     if (info == NULL) {
168         HDF_LOGE("%{public}s: info is null", __func__);
169         return HDF_FAILURE;
170     }
171     return CodecAdapterFillThisBuffer(info->codecNode, buffer);
172 }
173 
ComponentTypeSetCallbacks(struct CodecComponentType * self,struct CodecCallbackType * callback,int64_t appData)174 static int32_t ComponentTypeSetCallbacks(
175     struct CodecComponentType *self, struct CodecCallbackType *callback, int64_t appData)
176 {
177     struct CodecComponentTypeInfo *info = CONTAINER_OF(self, struct CodecComponentTypeInfo, instance);
178     if (info == NULL) {
179         HDF_LOGE("%{public}s: info is null", __func__);
180         return HDF_FAILURE;
181     }
182     return CodecAdapterSetCallbacks(info->codecNode, callback, appData);
183 }
184 
ComponentTypeComponentDeInit(struct CodecComponentType * self)185 static int32_t ComponentTypeComponentDeInit(struct CodecComponentType *self)
186 {
187     struct CodecComponentTypeInfo *info = CONTAINER_OF(self, struct CodecComponentTypeInfo, instance);
188     if (info == NULL) {
189         HDF_LOGE("%{public}s: info is null", __func__);
190         return HDF_FAILURE;
191     }
192     return CodecAdapterComponentDeInit(info->codecNode);
193 }
194 
ComponentTypeUseEglImage(struct CodecComponentType * self,struct OmxCodecBuffer * buffer,uint32_t portIndex,int8_t * eglImage,uint32_t eglImageLen)195 static int32_t ComponentTypeUseEglImage(struct CodecComponentType *self, struct OmxCodecBuffer *buffer,
196     uint32_t portIndex, int8_t *eglImage, uint32_t eglImageLen)
197 {
198     struct CodecComponentTypeInfo *info = CONTAINER_OF(self, struct CodecComponentTypeInfo, instance);
199     if (info == NULL) {
200         HDF_LOGE("%{public}s: info is null", __func__);
201         return HDF_FAILURE;
202     }
203     return CodecAdapterUseEglImage(info->codecNode, buffer, portIndex, eglImage, eglImageLen);
204 }
205 
ComponentTypeComponentRoleEnum(struct CodecComponentType * self,uint8_t * role,uint32_t roleLen,uint32_t index)206 static int32_t ComponentTypeComponentRoleEnum(
207     struct CodecComponentType *self, uint8_t *role, uint32_t roleLen, uint32_t index)
208 {
209     struct CodecComponentTypeInfo *info = CONTAINER_OF(self, struct CodecComponentTypeInfo, instance);
210     if (info == NULL) {
211         HDF_LOGE("%{public}s: info is null", __func__);
212         return HDF_FAILURE;
213     }
214     return CodecAdapterComponentRoleEnum(info->codecNode, role, roleLen, index);
215 }
216 
ComponentTypeConstruct(struct CodecComponentType * instance)217 static void ComponentTypeConstruct(struct CodecComponentType *instance)
218 {
219     instance->GetComponentVersion = ComponentTypeGetComponentVersion;
220     instance->SendCommand = ComponentTypeSendCommand;
221     instance->GetParameter = ComponentTypeGetParameter;
222     instance->SetParameter = ComponentTypeSetParameter;
223     instance->GetConfig = ComponentTypeGetConfig;
224     instance->SetConfig = ComponentTypeSetConfig;
225     instance->GetExtensionIndex = ComponentTypeGetExtensionIndex;
226     instance->GetState = ComponentTypeGetState;
227     instance->ComponentTunnelRequest = ComponentTypeComponentTunnelRequest;
228     instance->UseBuffer = ComponentTypeUseBuffer;
229     instance->AllocateBuffer = ComponentTypeAllocateBuffer;
230     instance->FreeBuffer = ComponentTypeFreeBuffer;
231     instance->EmptyThisBuffer = ComponentTypeEmptyThisBuffer;
232     instance->FillThisBuffer = ComponentTypeFillThisBuffer;
233     instance->SetCallbacks = ComponentTypeSetCallbacks;
234     instance->ComponentDeInit = ComponentTypeComponentDeInit;
235     instance->UseEglImage = ComponentTypeUseEglImage;
236     instance->ComponentRoleEnum = ComponentTypeComponentRoleEnum;
237 }
238 
CodecComponentTypeGet(struct HdfRemoteService * remote)239 struct CodecComponentType *CodecComponentTypeGet(struct HdfRemoteService *remote)
240 {
241     struct CodecComponentTypeInfo *info =
242         (struct CodecComponentTypeInfo *)OsalMemAlloc(sizeof(struct CodecComponentTypeInfo));
243     if (info == NULL) {
244         HDF_LOGE("%{public}s: OsalMemAlloc failed!", __func__);
245         return NULL;
246     }
247 
248     ComponentTypeConstruct(&info->instance);
249     return &info->instance;
250 }
251 
CodecComponentTypeRelease(struct CodecComponentType * instance)252 void CodecComponentTypeRelease(struct CodecComponentType *instance)
253 {
254     if (instance == NULL) {
255         HDF_LOGE("%{public}s: instanceis null", __func__);
256         return;
257     }
258     struct CodecComponentTypeInfo *info = CONTAINER_OF(instance, struct CodecComponentTypeInfo, instance);
259     if (info != NULL) {
260         HDF_LOGI("%{public}s: OsalMemFree info ", __func__);
261         OsalMemFree(info);
262         info = NULL;
263     }
264 }
265