• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Shenzhen Kaihong DID 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 "codec_component_type_service.h"
17 #include <hdf_base.h>
18 #include <hdf_log.h>
19 #include <osal_mem.h>
20 #include <securec.h>
21 #include <unistd.h>
22 #include "codec_adapter_interface.h"
23 #include "codec_component_type_stub.h"
24 struct CodecComponentTypeService {
25     struct CodecComponentTypeStub stub;
26     struct CodecComponentNode *codecNode;
27 };
28 #define HDF_LOG_TAG codec_hdi_server
29 
CodecComponentTypeGetComponentVersion(struct CodecComponentType * self,struct CompVerInfo * verInfo)30 static int32_t CodecComponentTypeGetComponentVersion(struct CodecComponentType *self, struct CompVerInfo *verInfo)
31 {
32     HDF_LOGI("%{public}s, service impl!", __func__);
33     struct CodecComponentTypeService *service = (struct CodecComponentTypeService *)self;
34     return OmxAdapterComponentVersion(service->codecNode, verInfo);
35 }
36 
CodecComponentTypeSendCommand(struct CodecComponentType * self,enum OMX_COMMANDTYPE cmd,uint32_t param,int8_t * cmdData,uint32_t cmdDataLen)37 static int32_t CodecComponentTypeSendCommand(struct CodecComponentType *self,
38     enum OMX_COMMANDTYPE cmd, uint32_t param, int8_t *cmdData, uint32_t cmdDataLen)
39 {
40     HDF_LOGI("%{public}s, service impl!", __func__);
41 
42     struct CodecComponentTypeService *service = (struct CodecComponentTypeService *)self;
43     return OmxAdapterSendCommand(service->codecNode, cmd, param, cmdData, cmdDataLen);
44 }
45 
CodecComponentTypeGetParameter(struct CodecComponentType * self,uint32_t paramIndex,int8_t * paramStruct,uint32_t paramStructLen)46 static int32_t CodecComponentTypeGetParameter(struct CodecComponentType *self,
47     uint32_t paramIndex, int8_t *paramStruct, uint32_t paramStructLen)
48 {
49     HDF_LOGI("%{public}s, service impl!", __func__);
50 
51     struct CodecComponentTypeService *service = (struct CodecComponentTypeService *)self;
52     int32_t err = OmxAdapterGetParameter(service->codecNode, paramIndex, paramStruct, paramStructLen);
53     if (err != HDF_SUCCESS) {
54         HDF_LOGE("%{public}s, OmxAdapterGetParameter,index [%{public}u], ret value [%{public}x]!", __func__, paramIndex,
55                  err);
56     }
57 
58     return err;
59 }
60 
CodecComponentTypeSetParameter(struct CodecComponentType * self,uint32_t index,int8_t * paramStruct,uint32_t paramStructLen)61 static int32_t CodecComponentTypeSetParameter(struct CodecComponentType *self,
62     uint32_t index, int8_t *paramStruct, uint32_t paramStructLen)
63 {
64     HDF_LOGI("%{public}s, service impl!", __func__);
65 
66     struct CodecComponentTypeService *service = (struct CodecComponentTypeService *)self;
67     int32_t err = OmxAdapterSetParameter(service->codecNode, index, paramStruct, paramStructLen);
68     if (err != HDF_SUCCESS) {
69         HDF_LOGE("%{public}s, OmxAdapterSetParameter,index [%{public}u], ret value [%{public}x]!", __func__, index,
70                  err);
71     }
72     return err;
73 }
74 
CodecComponentTypeGetConfig(struct CodecComponentType * self,uint32_t index,int8_t * cfgStruct,uint32_t cfgStructLen)75 static int32_t CodecComponentTypeGetConfig(struct CodecComponentType *self,
76     uint32_t index, int8_t *cfgStruct, uint32_t cfgStructLen)
77 {
78     HDF_LOGI("%{public}s, service impl!", __func__);
79 
80     struct CodecComponentTypeService *service = (struct CodecComponentTypeService *)self;
81     int32_t err = OmxAdapterGetConfig(service->codecNode, index, cfgStruct, cfgStructLen);
82     if (err != HDF_SUCCESS) {
83         HDF_LOGE("%{public}s, OmxAdapterGetConfig,index [%{public}u], ret value [%{public}x]!", __func__, index, err);
84     }
85     return err;
86 }
87 
CodecComponentTypeSetConfig(struct CodecComponentType * self,uint32_t index,int8_t * cfgStruct,uint32_t cfgStructLen)88 static int32_t CodecComponentTypeSetConfig(struct CodecComponentType *self,
89     uint32_t index, int8_t *cfgStruct, uint32_t cfgStructLen)
90 {
91     HDF_LOGI("%{public}s, service impl!", __func__);
92 
93     struct CodecComponentTypeService *service = (struct CodecComponentTypeService *)self;
94     int32_t err = OmxAdapterSetConfig(service->codecNode, index, cfgStruct, cfgStructLen);
95     if (err != HDF_SUCCESS) {
96         HDF_LOGE("%{public}s, OmxAdapterGetConfig,index [%{public}u], ret value [%{public}x]!", __func__, index, err);
97     }
98     return err;
99 }
100 
CodecComponentTypeGetExtensionIndex(struct CodecComponentType * self,const char * paramName,uint32_t * indexType)101 static int32_t CodecComponentTypeGetExtensionIndex(struct CodecComponentType *self,
102     const char *paramName, uint32_t *indexType)
103 {
104     HDF_LOGI("%{public}s, service impl!", __func__);
105     struct CodecComponentTypeService *service = (struct CodecComponentTypeService *)self;
106     return OmxAdapterGetExtensionIndex(service->codecNode, paramName, (enum OMX_INDEXTYPE *)indexType);
107 }
108 
CodecComponentTypeGetState(struct CodecComponentType * self,enum OMX_STATETYPE * state)109 static int32_t CodecComponentTypeGetState(struct CodecComponentType *self, enum OMX_STATETYPE *state)
110 {
111     HDF_LOGI("%{public}s, service impl!", __func__);
112 
113     struct CodecComponentTypeService *service = (struct CodecComponentTypeService *)self;
114     return OmxAdapterGetState(service->codecNode, state);
115 }
116 
CodecComponentTypeComponentTunnelRequest(struct CodecComponentType * self,uint32_t port,int32_t tunneledComp,uint32_t tunneledPort,struct OMX_TUNNELSETUPTYPE * tunnelSetup)117 static int32_t CodecComponentTypeComponentTunnelRequest(struct CodecComponentType *self,
118     uint32_t port, int32_t tunneledComp, uint32_t tunneledPort,
119     struct OMX_TUNNELSETUPTYPE *tunnelSetup)
120 {
121     HDF_LOGI("%{public}s, service impl!", __func__);
122 
123     struct CodecComponentTypeService *service = (struct CodecComponentTypeService *)self;
124     return OmxAdapterComponentTunnelRequest(service->codecNode, port, tunneledComp, tunneledPort, tunnelSetup);
125 }
126 
CodecComponentTypeUseBuffer(struct CodecComponentType * self,uint32_t portIndex,struct OmxCodecBuffer * buffer)127 static int32_t CodecComponentTypeUseBuffer(struct CodecComponentType *self,
128     uint32_t portIndex, struct OmxCodecBuffer *buffer)
129 {
130     HDF_LOGI("%{public}s, service impl!", __func__);
131 
132     struct CodecComponentTypeService *service = (struct CodecComponentTypeService *)self;
133     return OmxAdapterUseBuffer(service->codecNode, portIndex, buffer);
134 }
135 
CodecComponentTypeAllocateBuffer(struct CodecComponentType * self,uint32_t portIndex,struct OmxCodecBuffer * buffer)136 static int32_t CodecComponentTypeAllocateBuffer(struct CodecComponentType *self,
137     uint32_t portIndex, struct OmxCodecBuffer *buffer)
138 {
139     HDF_LOGI("%{public}s, service impl!", __func__);
140 
141     struct CodecComponentTypeService *service = (struct CodecComponentTypeService *)self;
142     return OmxAdapterAllocateBuffer(service->codecNode, portIndex, buffer);
143 }
144 
CodecComponentTypeFreeBuffer(struct CodecComponentType * self,uint32_t portIndex,const struct OmxCodecBuffer * buffer)145 static int32_t CodecComponentTypeFreeBuffer(struct CodecComponentType *self, uint32_t portIndex,
146     const struct OmxCodecBuffer *buffer)
147 {
148     HDF_LOGI("%{public}s, service impl!", __func__);
149 
150     struct CodecComponentTypeService *service = (struct CodecComponentTypeService *)self;
151     return OmxAdapterFreeBuffer(service->codecNode, portIndex, (struct OmxCodecBuffer *)buffer);
152 }
153 
CodecComponentTypeEmptyThisBuffer(struct CodecComponentType * self,const struct OmxCodecBuffer * buffer)154 static int32_t CodecComponentTypeEmptyThisBuffer(struct CodecComponentType *self,
155     const struct OmxCodecBuffer *buffer)
156 {
157     struct CodecComponentTypeService *service = (struct CodecComponentTypeService *)self;
158     return OmxAdapterEmptyThisBuffer(service->codecNode, (struct OmxCodecBuffer *)buffer);
159 }
160 
CodecComponentTypeFillThisBuffer(struct CodecComponentType * self,const struct OmxCodecBuffer * buffer)161 static int32_t CodecComponentTypeFillThisBuffer(struct CodecComponentType *self,
162     const struct OmxCodecBuffer *buffer)
163 {
164     struct CodecComponentTypeService *service = (struct CodecComponentTypeService *)self;
165     return OmxAdapterFillThisBuffer(service->codecNode, (struct OmxCodecBuffer *)buffer);
166 }
167 
CodecComponentTypeSetCallbacks(struct CodecComponentType * self,struct CodecCallbackType * callback,int64_t appData)168 static int32_t CodecComponentTypeSetCallbacks(struct CodecComponentType *self, struct CodecCallbackType *callback,
169                                               int64_t appData)
170 {
171     HDF_LOGI("%{public}s, service impl!", __func__);
172 
173     struct CodecComponentTypeService *service = (struct CodecComponentTypeService *)self;
174     return OmxAdapterSetCallbacks(service->codecNode, callback, appData);
175 }
176 
CodecComponentTypeComponentDeInit(struct CodecComponentType * self)177 static int32_t CodecComponentTypeComponentDeInit(struct CodecComponentType *self)
178 {
179     HDF_LOGI("%{public}s, service impl!", __func__);
180 
181     struct CodecComponentTypeService *service = (struct CodecComponentTypeService *)self;
182     return OmxAdapterDeInit(service->codecNode);
183 }
184 
CodecComponentTypeUseEglImage(struct CodecComponentType * self,struct OmxCodecBuffer * buffer,uint32_t portIndex,int8_t * eglImage,uint32_t eglImageLen)185 static int32_t CodecComponentTypeUseEglImage(struct CodecComponentType *self,
186     struct OmxCodecBuffer *buffer, uint32_t portIndex, int8_t *eglImage, uint32_t eglImageLen)
187 {
188     HDF_LOGI("%{public}s, service impl!", __func__);
189 
190     struct CodecComponentTypeService *service = (struct CodecComponentTypeService *)self;
191     return OmxAdapterUseEglImage(service->codecNode, buffer, portIndex, eglImage, eglImageLen);
192 }
193 
CodecComponentTypeComponentRoleEnum(struct CodecComponentType * self,uint8_t * role,uint32_t roleLen,uint32_t index)194 static int32_t CodecComponentTypeComponentRoleEnum(struct CodecComponentType *self,
195     uint8_t *role, uint32_t roleLen, uint32_t index)
196 {
197     HDF_LOGI("%{public}s, service impl!", __func__);
198 
199     struct CodecComponentTypeService *service = (struct CodecComponentTypeService *)self;
200     return OmxAdapterComponentRoleEnum(service->codecNode, role, roleLen, index);
201 }
202 
CodecComponentTypeServiceConstruct(struct CodecComponentType * instance)203 void CodecComponentTypeServiceConstruct(struct CodecComponentType *instance)
204 {
205     instance->GetComponentVersion = CodecComponentTypeGetComponentVersion;
206     instance->SendCommand = CodecComponentTypeSendCommand;
207     instance->GetParameter = CodecComponentTypeGetParameter;
208     instance->SetParameter = CodecComponentTypeSetParameter;
209     instance->GetConfig = CodecComponentTypeGetConfig;
210     instance->SetConfig = CodecComponentTypeSetConfig;
211     instance->GetExtensionIndex = CodecComponentTypeGetExtensionIndex;
212     instance->GetState = CodecComponentTypeGetState;
213     instance->ComponentTunnelRequest = CodecComponentTypeComponentTunnelRequest;
214     instance->UseBuffer = CodecComponentTypeUseBuffer;
215     instance->AllocateBuffer = CodecComponentTypeAllocateBuffer;
216     instance->FreeBuffer = CodecComponentTypeFreeBuffer;
217     instance->EmptyThisBuffer = CodecComponentTypeEmptyThisBuffer;
218     instance->FillThisBuffer = CodecComponentTypeFillThisBuffer;
219     instance->SetCallbacks = CodecComponentTypeSetCallbacks;
220     instance->ComponentDeInit = CodecComponentTypeComponentDeInit;
221     instance->UseEglImage = CodecComponentTypeUseEglImage;
222     instance->ComponentRoleEnum = CodecComponentTypeComponentRoleEnum;
223 }
CodecComponentTypeServiceGet(void)224 struct CodecComponentType *CodecComponentTypeServiceGet(void)
225 {
226     struct CodecComponentTypeService *service =
227         (struct CodecComponentTypeService *)OsalMemCalloc(sizeof(struct CodecComponentTypeService));
228     if (service == NULL) {
229         HDF_LOGE("%{public}s: malloc FooService obj failed!", __func__);
230         return NULL;
231     }
232 
233     if (!CodecComponentTypeStubConstruct(&service->stub)) {
234         HDF_LOGE("%{public}s: construct FooStub obj failed!", __func__);
235         OsalMemFree(service);
236         return NULL;
237     }
238     CodecComponentTypeServiceConstruct(&service->stub.interface);
239     return &service->stub.interface;
240 }
241 
CodecComponentTypeServiceRelease(struct CodecComponentType * self)242 void CodecComponentTypeServiceRelease(struct CodecComponentType *self)
243 {
244     struct CodecComponentTypeService *service = (struct CodecComponentTypeService *)self;
245     if (service == NULL) {
246         return;
247     }
248 
249     CodecComponentTypeStubRelease(&service->stub);
250     service->codecNode = NULL;
251     OsalMemFree(service);
252 }
253 
CodecComponentTypeServiceSetCodecNode(struct CodecComponentType * self,struct CodecComponentNode * codecNode)254 void CodecComponentTypeServiceSetCodecNode(struct CodecComponentType *self, struct CodecComponentNode *codecNode)
255 {
256     struct CodecComponentTypeService *service = (struct CodecComponentTypeService *)self;
257     if (service == NULL) {
258         return;
259     }
260     service->codecNode = codecNode;
261 }
262 
CodecComponentTypeServiceGetCodecNode(struct CodecComponentType * self)263 struct CodecComponentNode *CodecComponentTypeServiceGetCodecNode(struct CodecComponentType *self)
264 {
265     struct CodecComponentTypeService *service = (struct CodecComponentTypeService *)self;
266     if (service == NULL) {
267         return NULL;
268     }
269     return service->codecNode;
270 }