1 /*
2 * Copyright (c) 2021 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 "audio_adapter_info_common.h"
17 #include "audio_proxy_common.h"
18 #include "audio_uhdf_log.h"
19
20 #define HDF_LOG_TAG HDF_AUDIO_HAL_PROXY
21
AudioProxyCaptureCtrl(int cmId,const AudioHandle handle)22 static int32_t AudioProxyCaptureCtrl(int cmId, const AudioHandle handle)
23 {
24 struct HdfSBuf *data = NULL;
25 struct HdfSBuf *reply = NULL;
26 struct AudioHwCapture *hwCapture = (struct AudioHwCapture *)handle;
27 if (hwCapture == NULL || hwCapture->proxyRemoteHandle == NULL) {
28 AUDIO_FUNC_LOGE("The pointer is null");
29 return AUDIO_HAL_ERR_INVALID_PARAM;
30 }
31 if (AudioProxyPreprocessCapture(hwCapture, &data, &reply) < 0) {
32 AUDIO_FUNC_LOGE("AudioProxyPreprocessCapture failed.");
33 return AUDIO_HAL_ERR_INTERNAL;
34 }
35 int32_t ret = AudioProxyDispatchCall(hwCapture->proxyRemoteHandle, cmId, data, reply);
36 AudioProxyBufReplyRecycle(data, reply);
37 return ret;
38 }
39
AudioProxyCaptureStart(const AudioHandle handle)40 int32_t AudioProxyCaptureStart(const AudioHandle handle)
41 {
42 AUDIO_FUNC_LOGI();
43 int32_t ret = AudioCheckCaptureAddr(handle);
44 if (ret < 0) {
45 AUDIO_FUNC_LOGE("The proxy capture address passed in is invalid");
46 return ret;
47 }
48 return AudioProxyCaptureCtrl(AUDIO_HDI_CAPTURE_START, handle);
49 }
50
AudioProxyCaptureStop(const AudioHandle handle)51 int32_t AudioProxyCaptureStop(const AudioHandle handle)
52 {
53 AUDIO_FUNC_LOGI();
54 int32_t ret = AudioCheckCaptureAddr(handle);
55 if (ret < 0) {
56 AUDIO_FUNC_LOGE("The proxy capture address passed in is invalid");
57 return ret;
58 }
59 return AudioProxyCaptureCtrl(AUDIO_HDI_CAPTURE_STOP, handle);
60 }
61
AudioProxyCapturePause(const AudioHandle handle)62 int32_t AudioProxyCapturePause(const AudioHandle handle)
63 {
64 AUDIO_FUNC_LOGI();
65 int32_t ret = AudioCheckCaptureAddr(handle);
66 if (ret < 0) {
67 AUDIO_FUNC_LOGE("The proxy capture address passed in is invalid");
68 return ret;
69 }
70 return AudioProxyCaptureCtrl(AUDIO_HDI_CAPTURE_PAUSE, handle);
71 }
72
AudioProxyCaptureResume(const AudioHandle handle)73 int32_t AudioProxyCaptureResume(const AudioHandle handle)
74 {
75 AUDIO_FUNC_LOGI();
76 int32_t ret = AudioCheckCaptureAddr(handle);
77 if (ret < 0) {
78 AUDIO_FUNC_LOGE("The proxy capture address passed in is invalid");
79 return ret;
80 }
81 return AudioProxyCaptureCtrl(AUDIO_HDI_CAPTURE_RESUME, handle);
82 }
83
AudioProxyCaptureFlush(const AudioHandle handle)84 int32_t AudioProxyCaptureFlush(const AudioHandle handle)
85 {
86 AUDIO_FUNC_LOGI();
87 int32_t ret = AudioCheckCaptureAddr(handle);
88 if (ret < 0) {
89 AUDIO_FUNC_LOGE("The proxy capture address passed in is invalid, ret = %{public}d", ret);
90 return ret;
91 }
92 struct AudioHwCapture *hwCapture = (struct AudioHwCapture *)handle;
93 if (hwCapture == NULL) {
94 return AUDIO_HAL_ERR_INVALID_PARAM;
95 }
96 return AUDIO_HAL_ERR_NOT_SUPPORT;
97 }
98
AudioProxyCaptureGetFrameParameter(int cmId,const AudioHandle handle,uint64_t * param)99 static int32_t AudioProxyCaptureGetFrameParameter(int cmId, const AudioHandle handle, uint64_t *param)
100 {
101 if (param == NULL) {
102 return AUDIO_HAL_ERR_INVALID_PARAM;
103 }
104 struct HdfSBuf *data = NULL;
105 struct HdfSBuf *reply = NULL;
106 struct AudioHwCapture *hwCapture = (struct AudioHwCapture *)handle;
107 if (hwCapture == NULL || hwCapture->proxyRemoteHandle == NULL) {
108 AUDIO_FUNC_LOGE("The pointer is empty");
109 return AUDIO_HAL_ERR_INVALID_PARAM;
110 }
111 if (AudioProxyPreprocessCapture(hwCapture, &data, &reply) < 0) {
112 return AUDIO_HAL_ERR_INTERNAL;
113 }
114 int32_t ret = AudioProxyDispatchCall(hwCapture->proxyRemoteHandle, cmId, data, reply);
115 if (ret < 0) {
116 AUDIO_FUNC_LOGE("AudioCaptureGetFrameSize FAIL");
117 AudioProxyBufReplyRecycle(data, reply);
118 return ret;
119 }
120 if (!HdfSbufReadUint64(reply, param)) {
121 AudioProxyBufReplyRecycle(data, reply);
122 return AUDIO_HAL_ERR_INTERNAL;
123 }
124 AudioProxyBufReplyRecycle(data, reply);
125 return ret;
126 }
127
AudioProxyCaptureGetFrameSize(const AudioHandle handle,uint64_t * size)128 int32_t AudioProxyCaptureGetFrameSize(const AudioHandle handle, uint64_t *size)
129 {
130 int32_t ret = AudioCheckCaptureAddr(handle);
131 if (ret < 0) {
132 AUDIO_FUNC_LOGE("The proxy capture address passed in is invalid");
133 return ret;
134 }
135 return AudioProxyCaptureGetFrameParameter(AUDIO_HDI_CAPTURE_GET_FRAME_SIZE, handle, size);
136 }
137
AudioProxyCaptureGetFrameCount(const AudioHandle handle,uint64_t * count)138 int32_t AudioProxyCaptureGetFrameCount(const AudioHandle handle, uint64_t *count)
139 {
140 int32_t ret = AudioCheckCaptureAddr(handle);
141 if (ret < 0) {
142 AUDIO_FUNC_LOGE("The proxy capture address passed in is invalid");
143 return ret;
144 }
145 return AudioProxyCaptureGetFrameParameter(AUDIO_HDI_CAPTURE_GET_FRAME_COUNT, handle, count);
146 }
147
AudioProxyCaptureSetSampleAttributes(const AudioHandle handle,const struct AudioSampleAttributes * attrs)148 int32_t AudioProxyCaptureSetSampleAttributes(const AudioHandle handle, const struct AudioSampleAttributes *attrs)
149 {
150 int32_t ret = AudioCheckCaptureAddr(handle);
151 if (ret < 0) {
152 AUDIO_FUNC_LOGE("The proxy capture address passed in is invalid");
153 return ret;
154 }
155 if (handle == NULL || attrs == NULL) {
156 return AUDIO_HAL_ERR_INVALID_PARAM;
157 }
158 struct HdfSBuf *data = NULL;
159 struct HdfSBuf *reply = NULL;
160 struct AudioHwCapture *hwCapture = (struct AudioHwCapture *)handle;
161 if (hwCapture->proxyRemoteHandle == NULL) {
162 AUDIO_FUNC_LOGE("hwCapture or hwCapture->proxyRemoteHandle is NULL");
163 return AUDIO_HAL_ERR_INVALID_PARAM;
164 }
165 if (AudioProxyPreprocessCapture(hwCapture, &data, &reply) < 0) {
166 AUDIO_FUNC_LOGE("AudioProxyPreprocessCapture Fail");
167 return AUDIO_HAL_ERR_INTERNAL;
168 }
169 if (AudioProxyWriteSampleAttributes(data, attrs) < 0) {
170 AudioProxyBufReplyRecycle(data, reply);
171 return AUDIO_HAL_ERR_INTERNAL;
172 }
173 ret = AudioProxyDispatchCall(hwCapture->proxyRemoteHandle, AUDIO_HDI_CAPTURE_SET_SAMPLE_ATTR, data, reply);
174 AudioProxyBufReplyRecycle(data, reply);
175 return ret;
176 }
177
AudioProxyCaptureGetSampleAttributes(const AudioHandle handle,struct AudioSampleAttributes * attrs)178 int32_t AudioProxyCaptureGetSampleAttributes(const AudioHandle handle, struct AudioSampleAttributes *attrs)
179 {
180 int32_t ret = AudioCheckCaptureAddr(handle);
181 if (ret < 0) {
182 AUDIO_FUNC_LOGE("The proxy capture address passed in is invalid");
183 return ret;
184 }
185 if (attrs == NULL) {
186 return AUDIO_HAL_ERR_INVALID_PARAM;
187 }
188 struct HdfSBuf *data = NULL;
189 struct HdfSBuf *reply = NULL;
190 struct AudioHwCapture *hwCapture = (struct AudioHwCapture *)handle;
191 if (hwCapture == NULL || hwCapture->proxyRemoteHandle == NULL) {
192 AUDIO_FUNC_LOGE("The Invalid is pointer");
193 return AUDIO_HAL_ERR_INVALID_PARAM;
194 }
195 if (AudioProxyPreprocessCapture(hwCapture, &data, &reply) < 0) {
196 return AUDIO_HAL_ERR_INTERNAL;
197 }
198 ret = AudioProxyDispatchCall(hwCapture->proxyRemoteHandle, AUDIO_HDI_CAPTURE_GET_SAMPLE_ATTR, data, reply);
199 if (ret < 0) {
200 AUDIO_FUNC_LOGE("AudioCaptureGetSampleAttributes FAIL");
201 AudioProxyBufReplyRecycle(data, reply);
202 return ret;
203 }
204 if (AudioProxyReadSapmleAttrbutes(reply, attrs) < 0) {
205 AudioProxyBufReplyRecycle(data, reply);
206 return AUDIO_HAL_ERR_INTERNAL;
207 }
208 AudioProxyBufReplyRecycle(data, reply);
209 return AUDIO_HAL_SUCCESS;
210 }
211
AudioProxyCaptureGetCurrentChannelId(const AudioHandle handle,uint32_t * channelId)212 int32_t AudioProxyCaptureGetCurrentChannelId(const AudioHandle handle, uint32_t *channelId)
213 {
214 int32_t ret = AudioCheckCaptureAddr(handle);
215 if (ret < 0) {
216 AUDIO_FUNC_LOGE("The proxy capture address passed in is invalid");
217 return ret;
218 }
219 if (channelId == NULL) {
220 return AUDIO_HAL_ERR_INVALID_PARAM;
221 }
222 struct HdfSBuf *data = NULL;
223 struct HdfSBuf *reply = NULL;
224 struct AudioHwCapture *hwCapture = (struct AudioHwCapture *)handle;
225 if (hwCapture == NULL || hwCapture->proxyRemoteHandle == NULL) {
226 AUDIO_FUNC_LOGE("hwCapture parameter is invalid");
227 return AUDIO_HAL_ERR_INVALID_PARAM;
228 }
229 if (AudioProxyPreprocessCapture(hwCapture, &data, &reply) < 0) {
230 return AUDIO_HAL_ERR_INTERNAL;
231 }
232 ret = AudioProxyDispatchCall(hwCapture->proxyRemoteHandle,
233 AUDIO_HDI_CAPTURE_GET_CUR_CHANNEL_ID, data, reply);
234 if (ret < 0) {
235 AUDIO_FUNC_LOGE("AudioCaptureGetFrameSize FAIL");
236 AudioProxyBufReplyRecycle(data, reply);
237 return ret;
238 }
239 if (!HdfSbufReadUint32(reply, channelId)) {
240 AUDIO_FUNC_LOGE("Read reply FAIL");
241 AudioProxyBufReplyRecycle(data, reply);
242 return AUDIO_HAL_ERR_INTERNAL;
243 }
244 AudioProxyBufReplyRecycle(data, reply);
245 return AUDIO_HAL_SUCCESS;
246 }
247
AudioProxyCaptureCheckSceneCapability(const AudioHandle handle,const struct AudioSceneDescriptor * scene,bool * supported)248 int32_t AudioProxyCaptureCheckSceneCapability(const AudioHandle handle,
249 const struct AudioSceneDescriptor *scene, bool *supported)
250 {
251 int32_t ret = AudioCheckCaptureAddr(handle);
252 if (ret < 0) {
253 AUDIO_FUNC_LOGE("The proxy capture address passed in is invalid");
254 return ret;
255 }
256 if (scene == NULL || supported == NULL) {
257 return AUDIO_HAL_ERR_INVALID_PARAM;
258 }
259 uint32_t tempPins;
260 uint32_t tempSupported = 0;
261 struct HdfSBuf *data = NULL;
262 struct HdfSBuf *reply = NULL;
263 struct AudioHwCapture *hwCapture = (struct AudioHwCapture *)handle;
264 if (hwCapture == NULL || hwCapture->proxyRemoteHandle == NULL) {
265 AUDIO_FUNC_LOGE("pointer invalid");
266 return AUDIO_HAL_ERR_INVALID_PARAM;
267 }
268 if (AudioProxyPreprocessCapture(hwCapture, &data, &reply) < 0) {
269 return AUDIO_HAL_ERR_INTERNAL;
270 }
271 if (!HdfSbufWriteUint32(data, scene->scene.id)) {
272 AUDIO_FUNC_LOGE("write scene.id failed");
273 AudioProxyBufReplyRecycle(data, reply);
274 return AUDIO_HAL_ERR_INTERNAL;
275 }
276 tempPins = scene->desc.pins;
277 if (!HdfSbufWriteUint32(data, tempPins)) {
278 AUDIO_FUNC_LOGE("write pins failed");
279 AudioProxyBufReplyRecycle(data, reply);
280 return AUDIO_HAL_ERR_INTERNAL;
281 }
282 ret = AudioProxyDispatchCall(hwCapture->proxyRemoteHandle,
283 AUDIO_HDI_CAPTURE_CHECK_SCENE_CAPABILITY, data, reply);
284 if (ret < 0) {
285 AUDIO_FUNC_LOGE("AudioProxyCaptureCheckSceneCapability FAIL");
286 AudioProxyBufReplyRecycle(data, reply);
287 return ret;
288 }
289 if (!HdfSbufReadUint32(reply, &tempSupported)) {
290 AUDIO_FUNC_LOGE("write reply failed");
291 AudioProxyBufReplyRecycle(data, reply);
292 return AUDIO_HAL_ERR_INTERNAL;
293 }
294 *supported = (bool)tempSupported;
295 AudioProxyBufReplyRecycle(data, reply);
296 return AUDIO_HAL_SUCCESS;
297 }
298
AudioProxyCaptureSelectScene(const AudioHandle handle,const struct AudioSceneDescriptor * scene)299 int32_t AudioProxyCaptureSelectScene(const AudioHandle handle, const struct AudioSceneDescriptor *scene)
300 {
301 int32_t ret = AudioCheckCaptureAddr(handle);
302 if (ret < 0) {
303 AUDIO_FUNC_LOGE("The proxy capture address passed in is invalid");
304 return ret;
305 }
306 if (scene == NULL) {
307 return AUDIO_HAL_ERR_INVALID_PARAM;
308 }
309 struct HdfSBuf *data = NULL;
310 struct HdfSBuf *reply = NULL;
311 struct AudioHwCapture *hwCapture = (struct AudioHwCapture *)handle;
312 if (hwCapture == NULL || hwCapture->proxyRemoteHandle == NULL) {
313 AUDIO_FUNC_LOGE("The hwCapture pointer is null");
314 return AUDIO_HAL_ERR_INVALID_PARAM;
315 }
316 if (AudioProxyPreprocessCapture(hwCapture, &data, &reply) < 0) {
317 return AUDIO_HAL_ERR_INTERNAL;
318 }
319 if (!HdfSbufWriteUint32(data, (enum AudioCategory)scene->scene.id)) {
320 AudioProxyBufReplyRecycle(data, reply);
321 return AUDIO_HAL_ERR_INTERNAL;
322 }
323 uint32_t tempPins = scene->desc.pins;
324 if (!HdfSbufWriteUint32(data, tempPins)) {
325 AudioProxyBufReplyRecycle(data, reply);
326 return AUDIO_HAL_ERR_INTERNAL;
327 }
328 ret = AudioProxyDispatchCall(hwCapture->proxyRemoteHandle, AUDIO_HDI_CAPTURE_SELECT_SCENE, data, reply);
329 AudioProxyBufReplyRecycle(data, reply);
330 return ret;
331 }
332
AudioProxyCaptureSetMute(const AudioHandle handle,bool mute)333 int32_t AudioProxyCaptureSetMute(const AudioHandle handle, bool mute)
334 {
335 int32_t ret = AudioCheckCaptureAddr(handle);
336 if (ret < 0) {
337 AUDIO_FUNC_LOGE("The proxy capture address passed in is invalid");
338 return ret;
339 }
340 struct HdfSBuf *data = NULL;
341 struct HdfSBuf *reply = NULL;
342 struct AudioHwCapture *hwCapture = (struct AudioHwCapture *)handle;
343 if (hwCapture == NULL || hwCapture->proxyRemoteHandle == NULL) {
344 AUDIO_FUNC_LOGE("The hwCapture parameter is null");
345 return AUDIO_HAL_ERR_INVALID_PARAM;
346 }
347 if (AudioProxyPreprocessCapture(hwCapture, &data, &reply) < 0) {
348 return AUDIO_HAL_ERR_INTERNAL;
349 }
350 uint32_t tempMute = (uint32_t)mute;
351 if (!HdfSbufWriteUint32(data, tempMute)) {
352 AudioProxyBufReplyRecycle(data, reply);
353 return AUDIO_HAL_ERR_INTERNAL;
354 }
355 ret = AudioProxyDispatchCall(hwCapture->proxyRemoteHandle, AUDIO_HDI_CAPTURE_SET_MUTE, data, reply);
356 AudioProxyBufReplyRecycle(data, reply);
357 return ret;
358 }
359
AudioProxyCaptureGetMute(const AudioHandle handle,bool * mute)360 int32_t AudioProxyCaptureGetMute(const AudioHandle handle, bool *mute)
361 {
362 int32_t ret = AudioCheckCaptureAddr(handle);
363 if (ret < 0) {
364 AUDIO_FUNC_LOGE("The proxy capture address passed in is invalid");
365 return ret;
366 }
367 struct HdfSBuf *data = NULL;
368 struct HdfSBuf *reply = NULL;
369 if (mute == NULL) {
370 return AUDIO_HAL_ERR_INVALID_PARAM;
371 }
372 struct AudioHwCapture *hwCapture = (struct AudioHwCapture *)handle;
373 if (hwCapture == NULL || hwCapture->proxyRemoteHandle == NULL) {
374 AUDIO_FUNC_LOGE("The hwCapture parameter is null");
375 return AUDIO_HAL_ERR_INVALID_PARAM;
376 }
377 if (AudioProxyPreprocessCapture(hwCapture, &data, &reply) < 0) {
378 return AUDIO_HAL_ERR_INTERNAL;
379 }
380 ret = AudioProxyDispatchCall(hwCapture->proxyRemoteHandle, AUDIO_HDI_CAPTURE_GET_MUTE, data, reply);
381 if (ret < 0) {
382 AUDIO_FUNC_LOGE("AudioCaptureGetMute FAIL");
383 AudioProxyBufReplyRecycle(data, reply);
384 return ret;
385 }
386 uint32_t tempMute = 0;
387 if (!HdfSbufReadUint32(reply, &tempMute)) {
388 AudioProxyBufReplyRecycle(data, reply);
389 return AUDIO_HAL_ERR_INTERNAL;
390 }
391 *mute = (bool)tempMute;
392 AudioProxyBufReplyRecycle(data, reply);
393 return AUDIO_HAL_SUCCESS;
394 }
395
AudioProxyCaptureSetVolume(const AudioHandle handle,float volume)396 int32_t AudioProxyCaptureSetVolume(const AudioHandle handle, float volume)
397 {
398 int32_t ret = AudioCheckCaptureAddr(handle);
399 if (ret < 0) {
400 AUDIO_FUNC_LOGE("The proxy capture address passed in is invalid");
401 return ret;
402 }
403 return AudioProxyCommonSetCaptureCtrlParam(AUDIO_HDI_CAPTURE_SET_VOLUME, handle, volume);
404 }
405
AudioProxyCaptureGetVolume(const AudioHandle handle,float * volume)406 int32_t AudioProxyCaptureGetVolume(const AudioHandle handle, float *volume)
407 {
408 int32_t ret = AudioCheckCaptureAddr(handle);
409 if (ret < 0) {
410 AUDIO_FUNC_LOGE("The proxy capture address passed in is invalid");
411 return ret;
412 }
413 return AudioProxyCommonGetCaptureCtrlParam(AUDIO_HDI_CAPTURE_GET_VOLUME, handle, volume);
414 }
415
AudioProxyCaptureGetGainThreshold(const AudioHandle handle,float * min,float * max)416 int32_t AudioProxyCaptureGetGainThreshold(const AudioHandle handle, float *min, float *max)
417 {
418 int32_t ret = AudioCheckCaptureAddr(handle);
419 if (ret < 0) {
420 AUDIO_FUNC_LOGE("The proxy capture address passed in is invalid");
421 return ret;
422 }
423 if (min == NULL || max == NULL) {
424 return AUDIO_HAL_ERR_INVALID_PARAM;
425 }
426 struct HdfSBuf *data = NULL;
427 struct HdfSBuf *reply = NULL;
428 struct AudioHwCapture *hwCapture = (struct AudioHwCapture *)handle;
429 if (hwCapture == NULL || hwCapture->proxyRemoteHandle == NULL) {
430 AUDIO_FUNC_LOGE("The hwCapture pointer is invalid");
431 return AUDIO_HAL_ERR_INVALID_PARAM;
432 }
433 if (AudioProxyPreprocessCapture(hwCapture, &data, &reply) < 0) {
434 return AUDIO_HAL_ERR_INTERNAL;
435 }
436 ret = AudioProxyDispatchCall(hwCapture->proxyRemoteHandle,
437 AUDIO_HDI_CAPTURE_GET_GAIN_THRESHOLD, data, reply);
438 if (ret < 0) {
439 AUDIO_FUNC_LOGE("AudioCaptureGetGainThreshold FAIL");
440 AudioProxyBufReplyRecycle(data, reply);
441 return ret;
442 }
443 uint32_t temp = 0;
444 if (!HdfSbufReadUint32(reply, &temp)) {
445 AudioProxyBufReplyRecycle(data, reply);
446 return AUDIO_HAL_ERR_INTERNAL;
447 }
448 *min = temp;
449 if (!HdfSbufReadUint32(reply, &temp)) {
450 AudioProxyBufReplyRecycle(data, reply);
451 return AUDIO_HAL_ERR_INTERNAL;
452 }
453 *max = temp;
454 AudioProxyBufReplyRecycle(data, reply);
455 return AUDIO_HAL_SUCCESS;
456 }
457
AudioProxyCaptureGetGain(const AudioHandle handle,float * gain)458 int32_t AudioProxyCaptureGetGain(const AudioHandle handle, float *gain)
459 {
460 int32_t ret = AudioCheckCaptureAddr(handle);
461 if (ret < 0) {
462 AUDIO_FUNC_LOGE("The proxy capture address passed in is invalid");
463 return ret;
464 }
465 return AudioProxyCommonGetCaptureCtrlParam(AUDIO_HDI_CAPTURE_GET_GAIN, handle, gain);
466 }
467
AudioProxyCaptureSetGain(const AudioHandle handle,float gain)468 int32_t AudioProxyCaptureSetGain(const AudioHandle handle, float gain)
469 {
470 int32_t ret = AudioCheckCaptureAddr(handle);
471 if (ret < 0) {
472 AUDIO_FUNC_LOGE("The proxy capture address passed in is invalid");
473 return ret;
474 }
475 return AudioProxyCommonSetCaptureCtrlParam(AUDIO_HDI_CAPTURE_SET_GAIN, handle, gain);
476 }
477
AudioProxyCaptureCaptureFrameSplit(struct AudioCapture * capture,uint64_t requestBytes,struct HdfSBuf ** data,struct HdfSBuf ** reply)478 static int32_t AudioProxyCaptureCaptureFrameSplit(struct AudioCapture *capture,
479 uint64_t requestBytes, struct HdfSBuf **data, struct HdfSBuf **reply)
480 {
481 struct AudioHwCapture *hwCapture = (struct AudioHwCapture *)capture;
482 if (hwCapture == NULL || hwCapture->proxyRemoteHandle == NULL || data == NULL || reply == NULL) {
483 AUDIO_FUNC_LOGE("The pointer is empty");
484 return AUDIO_HAL_ERR_INVALID_PARAM;
485 }
486 if (AudioProxyPreprocessCapture(hwCapture, data, reply) < 0) {
487 return AUDIO_HAL_ERR_INTERNAL;
488 }
489 if (!HdfSbufWriteUint64(*data, requestBytes)) {
490 return AUDIO_HAL_ERR_INTERNAL;
491 }
492 int32_t ret = AudioProxyDispatchCall(hwCapture->proxyRemoteHandle, AUDIO_HDI_CAPTURE_CAPTURE_FRAME, *data, *reply);
493 if (ret < 0) {
494 if (ret != AUDIO_HAL_ERR_INVALID_OBJECT) {
495 AUDIO_FUNC_LOGE("AudioCaptureCaptureFrame FAIL");
496 }
497 return ret;
498 }
499 return AUDIO_HAL_SUCCESS;
500 }
501
AudioProxyCaptureCaptureFrame(struct AudioCapture * capture,void * frame,uint64_t requestBytes,uint64_t * replyBytes)502 int32_t AudioProxyCaptureCaptureFrame(struct AudioCapture *capture, void *frame,
503 uint64_t requestBytes, uint64_t *replyBytes)
504 {
505 int32_t ret = AudioCheckCaptureAddr((AudioHandle)capture);
506 if (ret < 0) {
507 AUDIO_FUNC_LOGE("The proxy capture address passed in is invalid");
508 return ret;
509 }
510 const char *buffer = NULL;
511 uint32_t length = 0;
512 if (frame == NULL || replyBytes == NULL) {
513 AUDIO_FUNC_LOGE("capture Frame Paras is NULL!");
514 return AUDIO_HAL_ERR_INVALID_PARAM;
515 }
516 struct HdfSBuf *data = NULL;
517 struct HdfSBuf *reply = NULL;
518 ret = AudioProxyCaptureCaptureFrameSplit(capture, requestBytes, &data, &reply);
519 if (ret < 0) {
520 AudioProxyBufReplyRecycle(data, reply);
521 return ret;
522 }
523 if (!HdfSbufReadBuffer(reply, (const void **)&buffer, &length)) {
524 AudioProxyBufReplyRecycle(data, reply);
525 return AUDIO_HAL_ERR_INTERNAL;
526 }
527 if ((uint64_t)length > requestBytes) {
528 AudioProxyBufReplyRecycle(data, reply);
529 return AUDIO_HAL_ERR_INTERNAL;
530 }
531 ret = memcpy_s(frame, (size_t)requestBytes, buffer, (size_t)length);
532 if (ret != EOK) {
533 AudioProxyBufReplyRecycle(data, reply);
534 return AUDIO_HAL_ERR_INTERNAL;
535 }
536 if (!HdfSbufReadUint64(reply, replyBytes)) {
537 AudioProxyBufReplyRecycle(data, reply);
538 return AUDIO_HAL_ERR_INTERNAL;
539 }
540 AudioProxyBufReplyRecycle(data, reply);
541 return AUDIO_HAL_SUCCESS;
542 }
543
AudioProxyCaptureGetCapturePosition(struct AudioCapture * capture,uint64_t * frames,struct AudioTimeStamp * time)544 int32_t AudioProxyCaptureGetCapturePosition(struct AudioCapture *capture,
545 uint64_t *frames, struct AudioTimeStamp *time)
546 {
547 int32_t ret = AudioCheckCaptureAddr((AudioHandle)capture);
548 if (ret < 0) {
549 AUDIO_FUNC_LOGE("The proxy capture address passed in is invalid");
550 return ret;
551 }
552 if (frames == NULL || time == NULL) {
553 return AUDIO_HAL_ERR_INVALID_PARAM;
554 }
555 struct HdfSBuf *data = NULL;
556 struct HdfSBuf *reply = NULL;
557 struct AudioHwCapture *hwCapture = (struct AudioHwCapture *)capture;
558 if (hwCapture == NULL || hwCapture->proxyRemoteHandle == NULL) {
559 AUDIO_FUNC_LOGE("The hwCapture parameter is null");
560 return AUDIO_HAL_ERR_INVALID_PARAM;
561 }
562 if (AudioProxyPreprocessCapture(hwCapture, &data, &reply) < 0) {
563 return AUDIO_HAL_ERR_INTERNAL;
564 }
565 ret = AudioProxyDispatchCall(hwCapture->proxyRemoteHandle,
566 AUDIO_HDI_CAPTURE_GET_CAPTURE_POSITION, data, reply);
567 if (ret < 0) {
568 AUDIO_FUNC_LOGE("AudioCaptureGetCapturePosition FAIL");
569 AudioProxyBufReplyRecycle(data, reply);
570 return ret;
571 }
572 if (AudioProxyGetMmapPositionRead(reply, frames, time) < 0) {
573 AudioProxyBufReplyRecycle(data, reply);
574 return AUDIO_HAL_ERR_INTERNAL;
575 }
576 AudioProxyBufReplyRecycle(data, reply);
577 return AUDIO_HAL_SUCCESS;
578 }
AudioProxyCaptureSetExtraParams(const AudioHandle handle,const char * keyValueList)579 int32_t AudioProxyCaptureSetExtraParams(const AudioHandle handle, const char *keyValueList)
580 {
581 int32_t ret = AudioCheckCaptureAddr(handle);
582 if (ret < 0) {
583 AUDIO_FUNC_LOGE("The proxy capture address passed in is invalid");
584 return ret;
585 }
586 if (handle == NULL || keyValueList == NULL) {
587 return AUDIO_HAL_ERR_INVALID_PARAM;
588 }
589 struct HdfSBuf *data = NULL;
590 struct HdfSBuf *reply = NULL;
591 struct AudioHwCapture *hwCapture = (struct AudioHwCapture *)handle;
592 if (hwCapture->proxyRemoteHandle == NULL) {
593 AUDIO_FUNC_LOGE("hwCapture or hwCapture->proxyRemoteHandle is NULL");
594 return AUDIO_HAL_ERR_INVALID_PARAM;
595 }
596 if (AudioProxyPreprocessCapture((AudioHandle)hwCapture, &data, &reply) < 0) {
597 return AUDIO_HAL_ERR_INTERNAL;
598 }
599 if (!HdfSbufWriteString(data, keyValueList)) {
600 AudioProxyBufReplyRecycle(data, reply);
601 return AUDIO_HAL_ERR_INTERNAL;
602 }
603 ret = AudioProxyDispatchCall(hwCapture->proxyRemoteHandle, AUDIO_HDI_CAPTURE_SET_EXTRA_PARAMS, data, reply);
604 AudioProxyBufReplyRecycle(data, reply);
605 return ret;
606 }
AudioProxyCaptureGetExtraParams(const AudioHandle handle,char * keyValueList,int32_t listLenth)607 int32_t AudioProxyCaptureGetExtraParams(const AudioHandle handle, char *keyValueList, int32_t listLenth)
608 {
609 int32_t ret = AudioCheckCaptureAddr(handle);
610 if (ret < 0) {
611 AUDIO_FUNC_LOGE("The proxy capture address passed in is invalid");
612 return ret;
613 }
614 if (handle == NULL || keyValueList == NULL || listLenth <= 0) {
615 return AUDIO_HAL_ERR_INVALID_PARAM;
616 }
617 struct HdfSBuf *data = NULL;
618 struct HdfSBuf *reply = NULL;
619 struct AudioHwCapture *hwCapture = (struct AudioHwCapture *)handle;
620 if (hwCapture->proxyRemoteHandle == NULL) {
621 AUDIO_FUNC_LOGE("The parameter is null");
622 return AUDIO_HAL_ERR_INVALID_PARAM;
623 }
624 if (AudioProxyPreprocessCapture((AudioHandle)hwCapture, &data, &reply) < 0) {
625 AUDIO_FUNC_LOGE("AudioProxyCaptureGetExtraParams FAIL");
626 return AUDIO_HAL_ERR_INTERNAL;
627 }
628 if (!HdfSbufWriteInt32(data, listLenth)) {
629 AudioProxyBufReplyRecycle(data, reply);
630 return AUDIO_HAL_ERR_INTERNAL;
631 }
632 ret = AudioProxyDispatchCall(hwCapture->proxyRemoteHandle, AUDIO_HDI_CAPTURE_GET_EXTRA_PARAMS, data, reply);
633 if (ret < 0) {
634 AUDIO_FUNC_LOGE("AudioProxyCaptureGetExtraParams FAIL");
635 AudioProxyBufReplyRecycle(data, reply);
636 return ret;
637 }
638 const char *strKeyValueList = NULL;
639 if ((strKeyValueList = HdfSbufReadString(reply)) == NULL) {
640 AUDIO_FUNC_LOGE("keyValueList Is NULL");
641 AudioProxyBufReplyRecycle(data, reply);
642 return AUDIO_HAL_ERR_INTERNAL;
643 }
644 ret = strncpy_s(keyValueList, listLenth, strKeyValueList, strlen(strKeyValueList));
645 if (ret != 0) {
646 AUDIO_FUNC_LOGE("strncpy_s failed!");
647 AudioProxyBufReplyRecycle(data, reply);
648 return AUDIO_HAL_ERR_INTERNAL;
649 }
650 AudioProxyBufReplyRecycle(data, reply);
651 return ret;
652 }
AudioProxyCaptureReqMmapBuffer(const AudioHandle handle,int32_t reqSize,struct AudioMmapBufferDescripter * desc)653 int32_t AudioProxyCaptureReqMmapBuffer(const AudioHandle handle,
654 int32_t reqSize, struct AudioMmapBufferDescripter *desc)
655 {
656 int32_t ret = AudioCheckCaptureAddr(handle);
657 if (ret < 0) {
658 AUDIO_FUNC_LOGE("The proxy capture address passed in is invalid");
659 return ret;
660 }
661 if (handle == NULL || desc == NULL) {
662 return AUDIO_HAL_ERR_INVALID_PARAM;
663 }
664 struct HdfSBuf *data = NULL;
665 struct HdfSBuf *reply = NULL;
666 struct AudioHwCapture *hwCapture = (struct AudioHwCapture *)handle;
667 if (hwCapture->proxyRemoteHandle == NULL) {
668 AUDIO_FUNC_LOGE("hwCapture parameter is null");
669 return AUDIO_HAL_ERR_INVALID_PARAM;
670 }
671 if (AudioProxyPreprocessCapture((AudioHandle)hwCapture, &data, &reply) < 0) {
672 AUDIO_FUNC_LOGE("AudioProxyCaptureReqMmapBuffer FAIL");
673 return AUDIO_HAL_ERR_INTERNAL;
674 }
675 if (AudioProxyReqMmapBufferWrite(data, reqSize, desc) < 0) {
676 AudioProxyBufReplyRecycle(data, reply);
677 return AUDIO_HAL_ERR_INTERNAL;
678 }
679 ret = AudioProxyDispatchCall(hwCapture->proxyRemoteHandle, AUDIO_HDI_CAPTURE_REQ_MMAP_BUFFER, data, reply);
680 if (ret < 0) {
681 AUDIO_FUNC_LOGE("AudioProxyCaptureReqMmapBuffer FAIL");
682 AudioProxyBufReplyRecycle(data, reply);
683 return ret;
684 }
685
686 AudioProxyBufReplyRecycle(data, reply);
687 return ret;
688 }
689
AudioProxyCaptureGetMmapPosition(const AudioHandle handle,uint64_t * frames,struct AudioTimeStamp * time)690 int32_t AudioProxyCaptureGetMmapPosition(const AudioHandle handle, uint64_t *frames, struct AudioTimeStamp *time)
691 {
692 int32_t ret = AudioCheckCaptureAddr(handle);
693 if (ret < 0) {
694 AUDIO_FUNC_LOGE("The proxy capture address passed in is invalid");
695 return ret;
696 }
697 if (handle == NULL || frames == NULL || time == NULL) {
698 return AUDIO_HAL_ERR_INVALID_PARAM;
699 }
700 struct HdfSBuf *data = NULL;
701 struct HdfSBuf *reply = NULL;
702 struct AudioHwCapture *hwCapture = (struct AudioHwCapture *)handle;
703 if (hwCapture->proxyRemoteHandle == NULL) {
704 AUDIO_FUNC_LOGE("The parameter is empty");
705 return AUDIO_HAL_ERR_INVALID_PARAM;
706 }
707 if (AudioProxyPreprocessCapture((AudioHandle)hwCapture, &data, &reply) < 0) {
708 AUDIO_FUNC_LOGE("AudioProxyCaptureGetMmapPosition FAIL");
709 return AUDIO_HAL_ERR_INTERNAL;
710 }
711 ret = AudioProxyDispatchCall(hwCapture->proxyRemoteHandle,
712 AUDIO_HDI_CAPTURE_GET_MMAP_POSITION, data, reply);
713 if (ret < 0) {
714 AudioProxyBufReplyRecycle(data, reply);
715 AUDIO_FUNC_LOGE("AudioProxyCaptureGetMmapPosition FAIL");
716 return ret;
717 }
718 if (AudioProxyGetMmapPositionRead(reply, frames, time) < 0) {
719 AudioProxyBufReplyRecycle(data, reply);
720 AUDIO_FUNC_LOGE("AudioProxyGetMmapPositionRead FAIL");
721 return AUDIO_HAL_ERR_INTERNAL;
722 }
723 AudioProxyBufReplyRecycle(data, reply);
724 return AUDIO_HAL_SUCCESS;
725 }
726
AudioProxyCaptureAddEffect(AudioHandle handle,uint64_t effectid)727 int32_t AudioProxyCaptureAddEffect(AudioHandle handle, uint64_t effectid)
728 {
729 struct HdfSBuf *data = NULL;
730 struct HdfSBuf *reply = NULL;
731 struct AudioHwCapture *hwCapture = NULL;
732 int32_t ret = AudioCheckCaptureAddr(handle);
733 if (ret < 0) {
734 AUDIO_FUNC_LOGE("The proxy capture address passed in is invalid");
735 return ret;
736 }
737 if (handle == NULL) {
738 AUDIO_FUNC_LOGE("The handle is null");
739 return AUDIO_HAL_ERR_INVALID_PARAM;
740 }
741 hwCapture = (struct AudioHwCapture *)handle;
742 if (hwCapture->proxyRemoteHandle == NULL) {
743 AUDIO_FUNC_LOGE("The pointer is null");
744 return AUDIO_HAL_ERR_INVALID_PARAM;
745 }
746 if (AudioProxyPreprocessCapture(hwCapture, &data, &reply) < 0) {
747 AUDIO_FUNC_LOGE("AudioProxyPreprocessCapture failed.");
748 return AUDIO_HAL_ERR_INTERNAL;
749 }
750 if (!HdfSbufWriteUint64(data, effectid)) {
751 AudioProxyBufReplyRecycle(data, reply);
752 return AUDIO_HAL_ERR_INTERNAL;
753 }
754 ret = AudioProxyDispatchCall(hwCapture->proxyRemoteHandle, AUDIO_HDI_CAPTURE_ADD_EFFECT, data, reply);
755 if (ret < 0) {
756 AUDIO_FUNC_LOGE("Dispatch AudioProxyCaptureAddEffect FAIL ret = %{public}d", ret);
757 AudioProxyBufReplyRecycle(data, reply);
758 return ret;
759 }
760
761 AudioProxyBufReplyRecycle(data, reply);
762 return AUDIO_HAL_SUCCESS;
763 }
764
AudioProxyCaptureRemoveEffect(AudioHandle handle,uint64_t effectid)765 int32_t AudioProxyCaptureRemoveEffect(AudioHandle handle, uint64_t effectid)
766 {
767 int32_t ret = AudioCheckCaptureAddr(handle);
768 if (ret < 0) {
769 AUDIO_FUNC_LOGE("The proxy capture address passed in is invalid");
770 return ret;
771 }
772 if (handle == NULL) {
773 AUDIO_FUNC_LOGE("The capture handle is empty");
774 return AUDIO_HAL_ERR_INVALID_PARAM;
775 }
776 struct HdfSBuf *reply = NULL;
777 struct HdfSBuf *data = NULL;
778 struct AudioHwCapture *hwCapture = (struct AudioHwCapture *)handle;
779 if (hwCapture->proxyRemoteHandle == NULL) {
780 AUDIO_FUNC_LOGE("The pointer is null");
781 return AUDIO_HAL_ERR_INVALID_PARAM;
782 }
783 if (AudioProxyPreprocessCapture(hwCapture, &data, &reply) < 0) {
784 return AUDIO_HAL_ERR_INTERNAL;
785 }
786 if (!HdfSbufWriteUint64(data, effectid)) {
787 AudioProxyBufReplyRecycle(data, reply);
788 return AUDIO_HAL_ERR_INTERNAL;
789 }
790 ret = AudioProxyDispatchCall(hwCapture->proxyRemoteHandle, AUDIO_HDI_CAPTURE_REMOVE_EFFECT, data, reply);
791 if (ret < 0) {
792 AUDIO_FUNC_LOGE("Dispatch AudioProxyCaptureRemoveEffect FAIL ret = %{public}d", ret);
793 AudioProxyBufReplyRecycle(data, reply);
794 return ret;
795 }
796
797 AudioProxyBufReplyRecycle(data, reply);
798 return AUDIO_HAL_SUCCESS;
799 }
800
AudioProxyCaptureTurnStandbyMode(const AudioHandle handle)801 int32_t AudioProxyCaptureTurnStandbyMode(const AudioHandle handle)
802 {
803 int32_t ret = AudioCheckCaptureAddr(handle);
804 if (ret < 0) {
805 AUDIO_FUNC_LOGE("The proxy capture address passed in is invalid");
806 return ret;
807 }
808 if (handle == NULL) {
809 return AUDIO_HAL_ERR_INVALID_PARAM;
810 }
811 struct HdfSBuf *data = NULL;
812 struct HdfSBuf *reply = NULL;
813 struct AudioHwCapture *hwCapture = (struct AudioHwCapture *)handle;
814 if (hwCapture->proxyRemoteHandle == NULL) {
815 AUDIO_FUNC_LOGE("The hwCapture parameter is empty");
816 return AUDIO_HAL_ERR_INVALID_PARAM;
817 }
818 if (AudioProxyPreprocessCapture((AudioHandle)hwCapture, &data, &reply) < 0) {
819 AUDIO_FUNC_LOGE("AudioProxyCaptureTurnStandbyMode FAIL");
820 return AUDIO_HAL_ERR_INTERNAL;
821 }
822 ret = AudioProxyDispatchCall(hwCapture->proxyRemoteHandle,
823 AUDIO_HDI_CAPTURE_TURN_STAND_BY_MODE, data, reply);
824 if (ret < 0) {
825 AUDIO_FUNC_LOGE("AudioProxyCaptureTurnStandbyMode FAIL");
826 AudioProxyBufReplyRecycle(data, reply);
827 return ret;
828 }
829 AudioProxyBufReplyRecycle(data, reply);
830 return ret;
831 }
AudioProxyCaptureAudioDevDump(const AudioHandle handle,int32_t range,int32_t fd)832 int32_t AudioProxyCaptureAudioDevDump(const AudioHandle handle, int32_t range, int32_t fd)
833 {
834 int32_t ret = AudioCheckCaptureAddr(handle);
835 if (ret < 0) {
836 AUDIO_FUNC_LOGE("The proxy capture address passed in is invalid");
837 return ret;
838 }
839 if (handle == NULL) {
840 AUDIO_FUNC_LOGE("handle is null");
841 return AUDIO_HAL_ERR_INVALID_PARAM;
842 }
843 struct HdfSBuf *data = NULL;
844 struct HdfSBuf *reply = NULL;
845 struct AudioHwCapture *hwCapture = (struct AudioHwCapture *)handle;
846 if (hwCapture->proxyRemoteHandle == NULL) {
847 AUDIO_FUNC_LOGE("hwCapture parameter is empty");
848 return AUDIO_HAL_ERR_INVALID_PARAM;
849 }
850
851 if (AudioProxyPreprocessCapture((AudioHandle)hwCapture, &data, &reply) < 0) {
852 AUDIO_FUNC_LOGE("AudioProxyCaptureAudioDevDump FAIL");
853 return AUDIO_HAL_ERR_INTERNAL;
854 }
855 if (!HdfSbufWriteInt32(data, range)) {
856 AudioProxyBufReplyRecycle(data, reply);
857 return AUDIO_HAL_ERR_INTERNAL;
858 }
859 if (!HdfSbufWriteFileDescriptor(data, fd)) {
860 AudioProxyBufReplyRecycle(data, reply);
861 return AUDIO_HAL_ERR_INTERNAL;
862 }
863 ret = AudioProxyDispatchCall(hwCapture->proxyRemoteHandle, AUDIO_HDI_CAPTURE_DEV_DUMP, data, reply);
864 if (ret < 0) {
865 AUDIO_FUNC_LOGE("AudioProxyCaptureAudioDevDump FAIL");
866 AudioProxyBufReplyRecycle(data, reply);
867 return ret;
868 }
869 AudioProxyBufReplyRecycle(data, reply);
870 return ret;
871 }
872
873