• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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 <math.h>
17 #include <sys/mman.h>
18 #include "hdf_types.h"
19 #include "osal_mem.h"
20 #include "audio_adapter_info_common.h"
21 #include "audio_common.h"
22 #include "audio_interface_lib_capture.h"
23 #include "audio_internal.h"
24 #include "audio_uhdf_log.h"
25 #include "v1_0/iaudio_capture.h"
26 #include "securec.h"
27 
28 #define HDF_LOG_TAG HDF_AUDIO_PRIMARY_IMPL
29 
30 #define FRAME_SIZE        1024
31 #define CONFIG_FRAME_SIZE ((FRAME_SIZE) * 2)
32 
33 #define CONFIG_FRAME_COUNT ((8000 * 2 + ((CONFIG_FRAME_SIZE) - 1)) / (CONFIG_FRAME_SIZE))
34 #define BITS_TO_FROMAT    3
35 #define VOLUME_AVERAGE    2
36 #define INTEGER_TO_DEC    10
37 #define DECIMAL_PART      5
38 
39 /* add For Capture Bytes To Frames */
AudioCaptureStart(struct IAudioCapture * handle)40 int32_t AudioCaptureStart(struct IAudioCapture *handle)
41 {
42     struct AudioHwCapture *hwCapture = (struct AudioHwCapture *)handle;
43     if (hwCapture == NULL) {
44         AUDIO_FUNC_LOGE("The hwCapture is NULL");
45         return AUDIO_ERR_INVALID_PARAM;
46     }
47 
48     InterfaceLibModeCapturePassthrough *pInterfaceLibModeCapture = AudioPassthroughGetInterfaceLibModeCapture();
49     if (pInterfaceLibModeCapture == NULL || *pInterfaceLibModeCapture == NULL) {
50         AUDIO_FUNC_LOGE("pInterfaceLibModeCapture Fail!");
51         return AUDIO_ERR_INTERNAL;
52     }
53     if (hwCapture->captureParam.frameCaptureMode.buffer != NULL) {
54         AUDIO_FUNC_LOGE("IAudioCapture already start!");
55         return AUDIO_SUCCESS; // capture is busy now
56     }
57     if (hwCapture->devDataHandle == NULL) {
58         AUDIO_FUNC_LOGE("CaptureStart Bind Fail!");
59         return AUDIO_ERR_INTERNAL;
60     }
61 
62     int32_t ret = (*pInterfaceLibModeCapture)(
63         hwCapture->devDataHandle, &hwCapture->captureParam, AUDIO_DRV_PCM_IOCTRL_START_CAPTURE);
64     if (ret < 0) {
65         AUDIO_FUNC_LOGE("AudioCaptureStart SetParams FAIL");
66         return AUDIO_ERR_INTERNAL;
67     }
68 
69     char *tbuffer = (char *)OsalMemCalloc(FRAME_DATA);
70     if (tbuffer == NULL) {
71         AUDIO_FUNC_LOGE("Calloc Capture tbuffer Fail!");
72         return AUDIO_ERR_MALLOC_FAIL;
73     }
74 
75     hwCapture->captureParam.frameCaptureMode.buffer = tbuffer;
76 
77     AudioLogRecord(AUDIO_INFO, "[%s]-[%s]-[%d] :> [%s]", __FILE__, __func__, __LINE__, "Audio Capture Start");
78     return AUDIO_SUCCESS;
79 }
80 
AudioCaptureStop(struct IAudioCapture * handle)81 int32_t AudioCaptureStop(struct IAudioCapture *handle)
82 {
83     struct AudioHwCapture *hwCapture = (struct AudioHwCapture *)handle;
84     if (hwCapture == NULL) {
85         AUDIO_FUNC_LOGE("hwCapture is null");
86         return AUDIO_ERR_INVALID_PARAM;
87     }
88     if (hwCapture->devDataHandle == NULL) {
89         AUDIO_FUNC_LOGE("CaptureStart Bind Fail!");
90         return AUDIO_ERR_INTERNAL;
91     }
92     if (hwCapture->captureParam.frameCaptureMode.buffer != NULL) {
93         AudioMemFree((void **)&hwCapture->captureParam.frameCaptureMode.buffer);
94     } else {
95         AUDIO_FUNC_LOGE("Repeat invalid stop operation!");
96         return AUDIO_SUCCESS;
97     }
98 
99     InterfaceLibModeCapturePassthrough *pInterfaceLibModeCapture = AudioPassthroughGetInterfaceLibModeCapture();
100     if (pInterfaceLibModeCapture == NULL || *pInterfaceLibModeCapture == NULL) {
101         AUDIO_FUNC_LOGE("pInterfaceLibModeCapture Fail!");
102         return AUDIO_ERR_INTERNAL;
103     }
104 
105     int32_t ret = (*pInterfaceLibModeCapture)(
106         hwCapture->devDataHandle, &hwCapture->captureParam, AUDIO_DRV_PCM_IOCTRL_STOP_CAPTURE);
107     if (ret < 0) {
108         AUDIO_FUNC_LOGE("AudioCaptureStop SetParams FAIL");
109         return AUDIO_ERR_INTERNAL;
110     }
111 
112     AudioLogRecord(AUDIO_INFO, "[%s]-[%s]-[%d] :> [%s]", __FILE__, __func__, __LINE__, "Audio Capture Stop");
113     return AUDIO_SUCCESS;
114 }
115 
AudioCapturePause(struct IAudioCapture * handle)116 int32_t AudioCapturePause(struct IAudioCapture *handle)
117 {
118     struct AudioHwCapture *hwCapture = (struct AudioHwCapture *)handle;
119     if (hwCapture == NULL) {
120         AUDIO_FUNC_LOGE("hwCapture is empty");
121         return AUDIO_ERR_INVALID_PARAM;
122     }
123     if (hwCapture->captureParam.frameCaptureMode.buffer == NULL) {
124         AUDIO_FUNC_LOGE("IAudioCapture already stop!");
125         return AUDIO_ERR_INTERNAL;
126     }
127     if (hwCapture->captureParam.captureMode.ctlParam.pause) {
128         AUDIO_FUNC_LOGE("Audio capture is already pause!");
129         return AUDIO_ERR_NOT_SUPPORT;
130     }
131     if (hwCapture->devDataHandle == NULL) {
132         AUDIO_FUNC_LOGE("CaptureStart Bind Fail!");
133         return AUDIO_ERR_INTERNAL;
134     }
135 
136     InterfaceLibModeCapturePassthrough *pInterfaceLibModeCapture = AudioPassthroughGetInterfaceLibModeCapture();
137     if (pInterfaceLibModeCapture == NULL || *pInterfaceLibModeCapture == NULL) {
138         AUDIO_FUNC_LOGE("pInterfaceLibModeCapture Fail!");
139         return AUDIO_ERR_INTERNAL;
140     }
141 
142     bool pauseStatus = hwCapture->captureParam.captureMode.ctlParam.pause;
143     hwCapture->captureParam.captureMode.ctlParam.pause = true;
144 
145     int32_t ret = (*pInterfaceLibModeCapture)(
146         hwCapture->devDataHandle, &hwCapture->captureParam, AUDIODRV_CTL_IOCTL_PAUSE_WRITE_CAPTURE);
147     if (ret < 0) {
148         AUDIO_FUNC_LOGE("Audio Capture Pause FAIL!");
149         hwCapture->captureParam.captureMode.ctlParam.pause = pauseStatus;
150         return AUDIO_ERR_INTERNAL;
151     }
152 
153     AudioLogRecord(AUDIO_INFO, "[%s]-[%s]-[%d] :> [%s]", __FILE__, __func__, __LINE__, "Audio Capture Pause");
154     return AUDIO_SUCCESS;
155 }
156 
AudioCaptureResume(struct IAudioCapture * handle)157 int32_t AudioCaptureResume(struct IAudioCapture *handle)
158 {
159     struct AudioHwCapture *hwCapture = (struct AudioHwCapture *)handle;
160     if (hwCapture == NULL) {
161         AUDIO_FUNC_LOGE("hwCapture is empty");
162         return AUDIO_ERR_INVALID_PARAM;
163     }
164     if (!hwCapture->captureParam.captureMode.ctlParam.pause) {
165         AUDIO_FUNC_LOGE("Audio capture is already Resume !");
166         return AUDIO_ERR_NOT_SUPPORT;
167     }
168     if (hwCapture->devDataHandle == NULL) {
169         AUDIO_FUNC_LOGE("Capture Start Bind Fail!");
170         return AUDIO_ERR_INTERNAL;
171     }
172 
173     InterfaceLibModeCapturePassthrough *pInterfaceLibModeCapture = AudioPassthroughGetInterfaceLibModeCapture();
174     if (pInterfaceLibModeCapture == NULL || *pInterfaceLibModeCapture == NULL) {
175         AUDIO_FUNC_LOGE("pInterfaceLibModeCapture Fail!");
176         return AUDIO_ERR_INTERNAL;
177     }
178 
179     bool resumeStatus = hwCapture->captureParam.captureMode.ctlParam.pause;
180     hwCapture->captureParam.captureMode.ctlParam.pause = false;
181 
182     int32_t ret = (*pInterfaceLibModeCapture)(
183         hwCapture->devDataHandle, &hwCapture->captureParam, AUDIODRV_CTL_IOCTL_PAUSE_WRITE_CAPTURE);
184     if (ret < 0) {
185         AUDIO_FUNC_LOGE("Audio capture Resume FAIL!");
186         hwCapture->captureParam.captureMode.ctlParam.pause = resumeStatus;
187         return AUDIO_ERR_INTERNAL;
188     }
189 
190     AudioLogRecord(AUDIO_INFO, "[%s]-[%s]-[%d] :> [%s]", __FILE__, __func__, __LINE__, "Audio Capture Resume");
191     return AUDIO_SUCCESS;
192 }
193 
AudioCaptureFlush(struct IAudioCapture * handle)194 int32_t AudioCaptureFlush(struct IAudioCapture *handle)
195 {
196     struct AudioHwCapture *hwCapture = (struct AudioHwCapture *)handle;
197     if (hwCapture == NULL) {
198         AUDIO_FUNC_LOGE("hwCapture is empty");
199         return AUDIO_ERR_INVALID_PARAM;
200     }
201     return AUDIO_ERR_NOT_SUPPORT;
202 }
203 
AudioCaptureGetFrameSize(struct IAudioCapture * handle,uint64_t * size)204 int32_t AudioCaptureGetFrameSize(struct IAudioCapture *handle, uint64_t *size)
205 {
206     struct AudioHwCapture *hwCapture = (struct AudioHwCapture *)handle;
207     if (hwCapture == NULL || size == NULL) {
208         AUDIO_FUNC_LOGE("Parameter error!");
209         return AUDIO_ERR_INVALID_PARAM;
210     }
211 
212     uint32_t channelCount = hwCapture->captureParam.frameCaptureMode.attrs.channelCount;
213     enum AudioFormat format = hwCapture->captureParam.frameCaptureMode.attrs.format;
214     uint32_t formatBitsCapture = 0;
215 
216     int32_t ret = FormatToBits(format, &formatBitsCapture);
217     if (ret != AUDIO_SUCCESS) {
218         return ret;
219     }
220 
221     *size = FRAME_SIZE * channelCount * (formatBitsCapture >> BITS_TO_FROMAT);
222     return AUDIO_SUCCESS;
223 }
224 
AudioCaptureGetFrameCount(struct IAudioCapture * handle,uint64_t * count)225 int32_t AudioCaptureGetFrameCount(struct IAudioCapture *handle, uint64_t *count)
226 {
227     struct AudioHwCapture *hwCapture = (struct AudioHwCapture *)handle;
228     if (hwCapture == NULL || count == NULL) {
229         AUDIO_FUNC_LOGE("Parameter error!");
230         return AUDIO_ERR_INVALID_PARAM;
231     }
232 
233     *count = hwCapture->captureParam.frameCaptureMode.frames;
234     return AUDIO_SUCCESS;
235 }
236 
AudioCaptureSetSampleAttributes(struct IAudioCapture * handle,const struct AudioSampleAttributes * attrs)237 int32_t AudioCaptureSetSampleAttributes(struct IAudioCapture *handle, const struct AudioSampleAttributes *attrs)
238 {
239     struct AudioHwCapture *hwCapture = (struct AudioHwCapture *)handle;
240     if (hwCapture == NULL || attrs == NULL) {
241         AUDIO_FUNC_LOGE("Parameter error!");
242         return AUDIO_ERR_INVALID_PARAM;
243     }
244 
245     int32_t ret = AudioCheckParaAttr(attrs);
246     if (ret != AUDIO_SUCCESS) {
247         AUDIO_FUNC_LOGE("AudioCheckParaAttr error!");
248         return ret;
249     }
250 
251     struct AudioSampleAttributes tempAttrs = hwCapture->captureParam.frameCaptureMode.attrs;
252     hwCapture->captureParam.frameCaptureMode.attrs = *attrs;
253 
254     InterfaceLibModeCapturePassthrough *pInterfaceLibModeCapture = AudioPassthroughGetInterfaceLibModeCapture();
255     if (pInterfaceLibModeCapture == NULL || *pInterfaceLibModeCapture == NULL) {
256         hwCapture->captureParam.frameCaptureMode.attrs = tempAttrs;
257         AUDIO_FUNC_LOGE("pInterfaceLibModeCapture Fail!");
258         return AUDIO_ERR_INTERNAL;
259     }
260     if (hwCapture->devDataHandle == NULL) {
261         hwCapture->captureParam.frameCaptureMode.attrs = tempAttrs;
262         return AUDIO_ERR_INTERNAL;
263     }
264 
265     ret = (*pInterfaceLibModeCapture)
266         (hwCapture->devDataHandle, &hwCapture->captureParam, AUDIO_DRV_PCM_IOCTL_HW_PARAMS);
267     if (ret < 0) {
268         AUDIO_FUNC_LOGE("CaptureSetSampleAttributes FAIL");
269         hwCapture->captureParam.frameCaptureMode.attrs = tempAttrs;
270         return AUDIO_ERR_INTERNAL;
271     }
272     return AUDIO_SUCCESS;
273 }
274 
AudioCaptureGetSampleAttributes(struct IAudioCapture * handle,struct AudioSampleAttributes * attrs)275 int32_t AudioCaptureGetSampleAttributes(struct IAudioCapture *handle, struct AudioSampleAttributes *attrs)
276 {
277     struct AudioHwCapture *hwCapture = (struct AudioHwCapture *)handle;
278     if (hwCapture == NULL || attrs == NULL) {
279         AUDIO_FUNC_LOGE("Parameter error!");
280         return AUDIO_ERR_INVALID_PARAM;
281     }
282     attrs->format = hwCapture->captureParam.frameCaptureMode.attrs.format;
283     attrs->sampleRate = hwCapture->captureParam.frameCaptureMode.attrs.sampleRate;
284     attrs->channelCount = hwCapture->captureParam.frameCaptureMode.attrs.channelCount;
285     attrs->interleaved = hwCapture->captureParam.frameCaptureMode.attrs.interleaved;
286     attrs->type = hwCapture->captureParam.frameCaptureMode.attrs.type;
287     attrs->period = hwCapture->captureParam.frameCaptureMode.attrs.period;
288     attrs->frameSize = hwCapture->captureParam.frameCaptureMode.attrs.frameSize;
289     attrs->isBigEndian = hwCapture->captureParam.frameCaptureMode.attrs.isBigEndian;
290     attrs->isSignedData = hwCapture->captureParam.frameCaptureMode.attrs.isSignedData;
291     attrs->startThreshold = hwCapture->captureParam.frameCaptureMode.attrs.startThreshold;
292     attrs->stopThreshold = hwCapture->captureParam.frameCaptureMode.attrs.stopThreshold;
293     attrs->silenceThreshold = hwCapture->captureParam.frameCaptureMode.attrs.silenceThreshold;
294     return AUDIO_SUCCESS;
295 }
296 
AudioCaptureGetCurrentChannelId(struct IAudioCapture * handle,uint32_t * channelId)297 int32_t AudioCaptureGetCurrentChannelId(struct IAudioCapture *handle, uint32_t *channelId)
298 {
299     struct AudioHwCapture *hwCapture = (struct AudioHwCapture *)handle;
300     if (hwCapture == NULL || channelId == NULL) {
301         AUDIO_FUNC_LOGE("Parameter error!");
302         return AUDIO_ERR_INVALID_PARAM;
303     }
304 
305     *channelId = hwCapture->captureParam.frameCaptureMode.attrs.channelCount;
306     return AUDIO_SUCCESS;
307 }
308 
AudioCaptureCheckSceneCapability(struct IAudioCapture * handle,const struct AudioSceneDescriptor * scene,bool * supported)309 int32_t AudioCaptureCheckSceneCapability(
310     struct IAudioCapture *handle, const struct AudioSceneDescriptor *scene, bool *supported)
311 {
312     struct AudioHwCapture *hwCapture = (struct AudioHwCapture *)handle;
313     if (hwCapture == NULL || scene == NULL || supported == NULL) {
314         AUDIO_FUNC_LOGE("Parameter error!");
315         return AUDIO_ERR_INVALID_PARAM;
316     }
317 #ifndef AUDIO_HAL_NOTSUPPORT_PATHSELECT
318     *supported = false;
319     /* Temporary storage does not save the structure */
320     struct AudioHwCaptureParam captureParam = hwCapture->captureParam;
321     captureParam.frameCaptureMode.attrs.type = (enum AudioCategory)scene->scene.id;
322     captureParam.captureMode.hwInfo.deviceDescript.pins = scene->desc.pins;
323 
324     PathSelAnalysisJson *pPathSelAnalysisJson = AudioPassthroughGetPathSelAnalysisJson();
325     if (pPathSelAnalysisJson == NULL || *pPathSelAnalysisJson == NULL) {
326         AUDIO_FUNC_LOGE("pPathSelAnalysisJson Is NULL!");
327         return AUDIO_ERR_NOT_SUPPORT;
328     }
329 
330     int32_t ret = (*pPathSelAnalysisJson)((void *)&captureParam, CHECKSCENE_PATH_SELECT_CAPTURE);
331     if (ret < 0) {
332         if (ret == AUDIO_ERR_NOT_SUPPORT) {
333             AUDIO_FUNC_LOGE("AudioCaptureCheckSceneCapability not Support!");
334             return AUDIO_ERR_NOT_SUPPORT;
335         } else {
336             AUDIO_FUNC_LOGE("AudioCaptureCheckSceneCapability fail!");
337             return AUDIO_ERR_INTERNAL;
338         }
339     }
340     *supported = true;
341     return AUDIO_SUCCESS;
342 #else
343     return AUDIO_ERR_NOT_SUPPORT;
344 #endif
345 }
346 
AudioCaptureSelectScene(struct IAudioCapture * handle,const struct AudioSceneDescriptor * scene)347 int32_t AudioCaptureSelectScene(struct IAudioCapture *handle, const struct AudioSceneDescriptor *scene)
348 {
349     struct AudioHwCapture *hwCapture = (struct AudioHwCapture *)handle;
350     if (hwCapture == NULL || scene == NULL) {
351         AUDIO_FUNC_LOGE("Parameter error!");
352         return AUDIO_ERR_INVALID_PARAM;
353     }
354     if (hwCapture->devCtlHandle == NULL) {
355         AUDIO_FUNC_LOGE("CaptureSelectScene Bind Fail!");
356         return AUDIO_ERR_INTERNAL;
357     }
358 #ifndef AUDIO_HAL_NOTSUPPORT_PATHSELECT
359     PathSelAnalysisJson *pPathSelAnalysisJson = AudioPassthroughGetPathSelAnalysisJson();
360     if (pPathSelAnalysisJson == NULL || *pPathSelAnalysisJson == NULL) {
361         AUDIO_FUNC_LOGE("pPathSelAnalysisJson Is NULL!");
362         return AUDIO_ERR_NOT_SUPPORT;
363     }
364 
365     enum AudioCategory typeTemp = hwCapture->captureParam.frameCaptureMode.attrs.type;
366     enum AudioPortPin pinsTemp = hwCapture->captureParam.captureMode.hwInfo.deviceDescript.pins;
367 
368     hwCapture->captureParam.frameCaptureMode.attrs.type = (enum AudioCategory)(scene->scene.id);
369     hwCapture->captureParam.captureMode.hwInfo.deviceDescript.pins = scene->desc.pins;
370     if ((*pPathSelAnalysisJson)((void *)&hwCapture->captureParam, CAPTURE_PATH_SELECT) < 0) {
371         AUDIO_FUNC_LOGE("AudioCaptureSelectScene Fail!");
372         hwCapture->captureParam.frameCaptureMode.attrs.type = typeTemp;
373         hwCapture->captureParam.captureMode.hwInfo.deviceDescript.pins = pinsTemp;
374         return AUDIO_ERR_INTERNAL;
375     }
376 
377     InterfaceLibModeCapturePassthrough *pInterfaceLibModeCapture = AudioPassthroughGetInterfaceLibModeCapture();
378     if (pInterfaceLibModeCapture == NULL || *pInterfaceLibModeCapture == NULL) {
379         AUDIO_FUNC_LOGE("pInterfaceLibModeCapture Is NULL");
380         hwCapture->captureParam.frameCaptureMode.attrs.type = typeTemp;
381         hwCapture->captureParam.captureMode.hwInfo.deviceDescript.pins = pinsTemp;
382         return AUDIO_ERR_INTERNAL;
383     }
384 
385     int32_t ret = (*pInterfaceLibModeCapture)(
386         hwCapture->devCtlHandle, &hwCapture->captureParam, AUDIODRV_CTL_IOCTL_SCENESELECT_CAPTURE);
387     if (ret < 0) {
388         AUDIO_FUNC_LOGE("SetSelectSceneParams FAIL!");
389         hwCapture->captureParam.frameCaptureMode.attrs.type = typeTemp;
390         hwCapture->captureParam.captureMode.hwInfo.deviceDescript.pins = pinsTemp;
391         return AUDIO_ERR_INTERNAL;
392     }
393     return AUDIO_SUCCESS;
394 #else
395     return AUDIO_ERR_NOT_SUPPORT;
396 #endif
397 }
398 
AudioCaptureSetMute(struct IAudioCapture * handle,bool mute)399 int32_t AudioCaptureSetMute(struct IAudioCapture *handle, bool mute)
400 {
401     struct AudioHwCapture *impl = (struct AudioHwCapture *)handle;
402     if (impl == NULL) {
403         AUDIO_FUNC_LOGE("Parameter error!");
404         return AUDIO_ERR_INVALID_PARAM;
405     }
406     if (impl->devCtlHandle == NULL) {
407         AUDIO_FUNC_LOGE("CaptureSetMute Bind Fail!");
408         return AUDIO_ERR_INTERNAL;
409     }
410 
411     InterfaceLibModeCapturePassthrough *pInterfaceLibModeCapture = AudioPassthroughGetInterfaceLibModeCapture();
412     if (pInterfaceLibModeCapture == NULL || *pInterfaceLibModeCapture == NULL) {
413         AUDIO_FUNC_LOGE("pInterfaceLibModeCapture Fail!");
414         return AUDIO_ERR_INTERNAL;
415     }
416 
417     bool muteStatus = impl->captureParam.captureMode.ctlParam.mute;
418     impl->captureParam.captureMode.ctlParam.mute = mute;
419 
420     int32_t ret =
421         (*pInterfaceLibModeCapture)(impl->devCtlHandle, &impl->captureParam, AUDIODRV_CTL_IOCTL_MUTE_WRITE_CAPTURE);
422     if (ret < 0) {
423         AUDIO_FUNC_LOGE("SetMute SetParams FAIL");
424         impl->captureParam.captureMode.ctlParam.mute = muteStatus;
425         return AUDIO_ERR_INTERNAL;
426     }
427 
428     AudioLogRecord(AUDIO_INFO, "[%s]-[%s]-[%d] :> [Setmute = %d]", __FILE__, __func__, __LINE__, mute);
429     return AUDIO_SUCCESS;
430 }
431 
AudioCaptureGetMute(struct IAudioCapture * handle,bool * mute)432 int32_t AudioCaptureGetMute(struct IAudioCapture *handle, bool *mute)
433 {
434     struct AudioHwCapture *impl = (struct AudioHwCapture *)handle;
435     if (impl == NULL || mute == NULL) {
436         AUDIO_FUNC_LOGE("Parameter error!");
437         return AUDIO_ERR_INVALID_PARAM;
438     }
439     if (impl->devCtlHandle == NULL) {
440         AUDIO_FUNC_LOGE("CaptureGetMute Bind Fail!");
441         return AUDIO_ERR_INTERNAL;
442     }
443 
444     InterfaceLibModeCapturePassthrough *pInterfaceLibModeCapture = AudioPassthroughGetInterfaceLibModeCapture();
445     if (pInterfaceLibModeCapture == NULL || *pInterfaceLibModeCapture == NULL) {
446         AUDIO_FUNC_LOGE("pInterfaceLibModeCapture Fail!");
447         return AUDIO_ERR_INTERNAL;
448     }
449 
450     int32_t ret =
451         (*pInterfaceLibModeCapture)(impl->devCtlHandle, &impl->captureParam, AUDIODRV_CTL_IOCTL_MUTE_READ_CAPTURE);
452     if (ret < 0) {
453         AUDIO_FUNC_LOGE("GetMute SetParams FAIL");
454         return AUDIO_ERR_INTERNAL;
455     }
456 
457     *mute = impl->captureParam.captureMode.ctlParam.mute;
458 
459     AUDIO_FUNC_LOGI("Get Mute SUCCESS!");
460     return AUDIO_SUCCESS;
461 }
462 
AudioCaptureSetVolume(struct IAudioCapture * handle,float volume)463 int32_t AudioCaptureSetVolume(struct IAudioCapture *handle, float volume)
464 {
465     struct AudioHwCapture *hwCapture = (struct AudioHwCapture *)handle;
466     if (hwCapture == NULL) {
467         AUDIO_FUNC_LOGE("Parameter error!");
468         return AUDIO_ERR_INVALID_PARAM;
469     }
470 
471     float volumeTemp = hwCapture->captureParam.captureMode.ctlParam.volume;
472     float volMax = (float)hwCapture->captureParam.captureMode.ctlParam.volThreshold.volMax;
473     float volMin = (float)hwCapture->captureParam.captureMode.ctlParam.volThreshold.volMin;
474     if (hwCapture->devCtlHandle == NULL) {
475         AUDIO_FUNC_LOGE("Bind Fail!");
476         return AUDIO_ERR_INTERNAL;
477     }
478     if (volume < 0 || volume > 1) {
479         AUDIO_FUNC_LOGE("volume param Is error!");
480         return AUDIO_ERR_INVALID_PARAM;
481     }
482 
483     InterfaceLibModeCapturePassthrough *pInterfaceLibModeCapture = AudioPassthroughGetInterfaceLibModeCapture();
484     if (pInterfaceLibModeCapture == NULL || *pInterfaceLibModeCapture == NULL) {
485         AUDIO_FUNC_LOGE("pInterfaceLibModeCapture Fail!");
486         return AUDIO_ERR_INTERNAL;
487     }
488 
489     volume = (volume == 0) ? 1 : (volume * VOLUME_CHANGE);
490 
491     /* change volume to db */
492     float volTemp = ((volMax - volMin) / 2) * log10(volume) + volMin;
493     if (volTemp < volMin || volTemp > volMax) {
494         AUDIO_FUNC_LOGE("volTemp fail");
495         return AUDIO_ERR_INTERNAL;
496     }
497 
498     hwCapture->captureParam.captureMode.ctlParam.volume = volTemp;
499 
500     int32_t ret = (*pInterfaceLibModeCapture)(
501         hwCapture->devCtlHandle, &hwCapture->captureParam, AUDIODRV_CTL_IOCTL_ELEM_WRITE_CAPTURE);
502     if (ret < 0) {
503         AUDIO_FUNC_LOGE("SetParams FAIL!");
504         hwCapture->captureParam.captureMode.ctlParam.volume = volumeTemp;
505         return AUDIO_ERR_INTERNAL;
506     }
507     return AUDIO_SUCCESS;
508 }
509 
AudioCaptureGetVolume(struct IAudioCapture * handle,float * volume)510 int32_t AudioCaptureGetVolume(struct IAudioCapture *handle, float *volume)
511 {
512     struct AudioHwCapture *hwCapture = (struct AudioHwCapture *)handle;
513     if (hwCapture == NULL || volume == NULL) {
514         AUDIO_FUNC_LOGE("Parameter error!");
515         return AUDIO_ERR_INVALID_PARAM;
516     }
517 
518     if (hwCapture->devCtlHandle == NULL) {
519         AUDIO_FUNC_LOGE("CaptureStart Bind Fail!");
520         return AUDIO_ERR_INTERNAL;
521     }
522 
523     InterfaceLibModeCapturePassthrough *pInterfaceLibModeCapture = AudioPassthroughGetInterfaceLibModeCapture();
524     if (pInterfaceLibModeCapture == NULL || *pInterfaceLibModeCapture == NULL) {
525         AUDIO_FUNC_LOGE("pInterfaceLibModeCapture Fail!");
526         return AUDIO_ERR_INTERNAL;
527     }
528 
529     int32_t ret = (*pInterfaceLibModeCapture)(
530         hwCapture->devCtlHandle, &hwCapture->captureParam, AUDIODRV_CTL_IOCTL_ELEM_READ_CAPTURE);
531     if (ret < 0) {
532         AUDIO_FUNC_LOGE("Get Volume FAIL!");
533         return AUDIO_ERR_INTERNAL;
534     }
535 
536     float volumeTemp = hwCapture->captureParam.captureMode.ctlParam.volume;
537     float volMax = (float)hwCapture->captureParam.captureMode.ctlParam.volThreshold.volMax;
538     float volMin = (float)hwCapture->captureParam.captureMode.ctlParam.volThreshold.volMin;
539     if ((volMax - volMin) == 0) {
540         AUDIO_FUNC_LOGE("Divisor cannot be zero!");
541         return AUDIO_ERR_INTERNAL;
542     }
543     volumeTemp = (volumeTemp - volMin) / ((volMax - volMin) / VOLUME_AVERAGE);
544 
545     int volumeT = (int)((pow(INTEGER_TO_DEC, volumeTemp) + DECIMAL_PART) / INTEGER_TO_DEC); // delet 0.X num
546 
547     *volume = (float)volumeT / INTEGER_TO_DEC;                                               // get volume (0-1)
548     return AUDIO_SUCCESS;
549 }
550 
AudioCaptureGetGainThreshold(struct IAudioCapture * handle,float * min,float * max)551 int32_t AudioCaptureGetGainThreshold(struct IAudioCapture *handle, float *min, float *max)
552 {
553     struct AudioHwCapture *hwCapture = (struct AudioHwCapture *)handle;
554     if (hwCapture == NULL || min == NULL || max == NULL) {
555         AUDIO_FUNC_LOGE("Parameter error!");
556         return AUDIO_ERR_INVALID_PARAM;
557     }
558     if (hwCapture->devCtlHandle == NULL) {
559         AUDIO_FUNC_LOGE("AudioCaptureGetGainThreshold Bind Fail!");
560         return AUDIO_ERR_INTERNAL;
561     }
562 
563     InterfaceLibModeCapturePassthrough *pInterfaceLibModeCapture = AudioPassthroughGetInterfaceLibModeCapture();
564     if (pInterfaceLibModeCapture == NULL || *pInterfaceLibModeCapture == NULL) {
565         AUDIO_FUNC_LOGE("pInterfaceLibModeCapture Is NULL");
566         return AUDIO_ERR_INTERNAL;
567     }
568 
569     int32_t ret = (*pInterfaceLibModeCapture)(
570         hwCapture->devCtlHandle, &hwCapture->captureParam, AUDIODRV_CTL_IOCTL_GAINTHRESHOLD_CAPTURE);
571     if (ret < 0) {
572         AUDIO_FUNC_LOGE("SetParams FAIL!");
573         return AUDIO_ERR_INTERNAL;
574     }
575 
576     *max = hwCapture->captureParam.captureMode.ctlParam.audioGain.gainMax;
577     *min = hwCapture->captureParam.captureMode.ctlParam.audioGain.gainMin;
578     return AUDIO_SUCCESS;
579 }
580 
AudioCaptureGetGain(struct IAudioCapture * handle,float * gain)581 int32_t AudioCaptureGetGain(struct IAudioCapture *handle, float *gain)
582 {
583     struct AudioHwCapture *impl = (struct AudioHwCapture *)handle;
584     if (impl == NULL || gain == NULL) {
585         AUDIO_FUNC_LOGE("Parameter error!");
586         return AUDIO_ERR_INVALID_PARAM;
587     }
588     if (impl->devCtlHandle == NULL) {
589         AUDIO_FUNC_LOGE("CaptureStart Bind Fail!");
590         return AUDIO_ERR_INTERNAL;
591     }
592 
593     InterfaceLibModeCapturePassthrough *pInterfaceLibModeCapture = AudioPassthroughGetInterfaceLibModeCapture();
594     if (pInterfaceLibModeCapture == NULL || *pInterfaceLibModeCapture == NULL) {
595         AUDIO_FUNC_LOGE("pInterfaceLibModeCapture Fail!");
596         return AUDIO_ERR_INTERNAL;
597     }
598 
599     int32_t ret =
600         (*pInterfaceLibModeCapture)(impl->devCtlHandle, &impl->captureParam, AUDIODRV_CTL_IOCTL_GAIN_READ_CAPTURE);
601     if (ret < 0) {
602         AUDIO_FUNC_LOGE("Get Volume FAIL!");
603         return AUDIO_ERR_INTERNAL;
604     }
605 
606     *gain = impl->captureParam.captureMode.ctlParam.audioGain.gain;
607     return AUDIO_SUCCESS;
608 }
609 
AudioCaptureSetGain(struct IAudioCapture * handle,float gain)610 int32_t AudioCaptureSetGain(struct IAudioCapture *handle, float gain)
611 {
612     struct AudioHwCapture *impl = (struct AudioHwCapture *)handle;
613     if (impl == NULL || gain < 0) {
614         AUDIO_FUNC_LOGE("Parameter error!");
615         return AUDIO_ERR_INVALID_PARAM;
616     }
617     if (impl->devCtlHandle == NULL) {
618         AUDIO_FUNC_LOGE("CaptureSetGain Bind Fail!");
619         return AUDIO_ERR_INTERNAL;
620     }
621 
622     float gainTemp = impl->captureParam.captureMode.ctlParam.audioGain.gain;
623     impl->captureParam.captureMode.ctlParam.audioGain.gain = gain;
624 
625     InterfaceLibModeCapturePassthrough *pInterfaceLibModeCapture = AudioPassthroughGetInterfaceLibModeCapture();
626     if (pInterfaceLibModeCapture == NULL || *pInterfaceLibModeCapture == NULL) {
627         AUDIO_FUNC_LOGE("pInterfaceLibModeCapture Fail!");
628         impl->captureParam.captureMode.ctlParam.audioGain.gain = gainTemp;
629         return AUDIO_ERR_INTERNAL;
630     }
631 
632     int32_t ret =
633         (*pInterfaceLibModeCapture)(impl->devCtlHandle, &impl->captureParam, AUDIODRV_CTL_IOCTL_GAIN_WRITE_CAPTURE);
634     if (ret < 0) {
635         AUDIO_FUNC_LOGE("CaptureSetGain FAIL!");
636         impl->captureParam.captureMode.ctlParam.audioGain.gain = gainTemp;
637         return AUDIO_ERR_INTERNAL;
638     }
639     return AUDIO_SUCCESS;
640 }
641 
LogErrorGetRensonAndTime(struct AudioHwCapture * hwCapture,int errorReason)642 static int32_t LogErrorGetRensonAndTime(struct AudioHwCapture *hwCapture, int errorReason)
643 {
644     if (hwCapture == NULL) {
645         AUDIO_FUNC_LOGE("Parameter error!");
646         return AUDIO_ERR_INVALID_PARAM;
647     }
648     if (hwCapture->errorLog.iter >= ERROR_LOG_MAX_NUM) {
649         AUDIO_FUNC_LOGE("Capture item more then %{public}d.", ERROR_LOG_MAX_NUM);
650         return AUDIO_ERR_INTERNAL;
651     }
652     if (hwCapture->errorLog.errorDump[hwCapture->errorLog.iter].reason == NULL) {
653         hwCapture->errorLog.errorDump[hwCapture->errorLog.iter].reason = (char *)OsalMemCalloc(ERROR_REASON_DESC_LEN);
654         if (hwCapture->errorLog.errorDump[hwCapture->errorLog.iter].reason == NULL) {
655             AUDIO_FUNC_LOGE("Calloc reasonDesc Fail!");
656             return AUDIO_ERR_MALLOC_FAIL;
657         }
658     }
659 
660     if (hwCapture->errorLog.errorDump[hwCapture->errorLog.iter].currentTime == NULL) {
661         hwCapture->errorLog.errorDump[hwCapture->errorLog.iter].currentTime =
662             (char *)OsalMemCalloc(ERROR_REASON_DESC_LEN);
663         if (hwCapture->errorLog.errorDump[hwCapture->errorLog.iter].currentTime == NULL) {
664             AUDIO_FUNC_LOGE("Calloc time Fail!");
665             return AUDIO_ERR_MALLOC_FAIL;
666         }
667     }
668 
669     memset_s(hwCapture->errorLog.errorDump[hwCapture->errorLog.iter].reason, ERROR_REASON_DESC_LEN, 0,
670         ERROR_REASON_DESC_LEN);
671     memset_s(hwCapture->errorLog.errorDump[hwCapture->errorLog.iter].currentTime, ERROR_REASON_DESC_LEN, 0,
672         ERROR_REASON_DESC_LEN);
673 
674     int32_t ret = GetErrorReason(errorReason, hwCapture->errorLog.errorDump[hwCapture->errorLog.iter].reason);
675     if (ret < 0) {
676         AUDIO_FUNC_LOGE("Capture GetErrorReason failed!");
677         return AUDIO_ERR_INTERNAL;
678     }
679 
680     ret = GetCurrentTime(hwCapture->errorLog.errorDump[hwCapture->errorLog.iter].currentTime);
681     if (ret < 0) {
682         AUDIO_FUNC_LOGE("Capture GetCurrentTime failed!");
683         return AUDIO_ERR_INTERNAL;
684     }
685     return AUDIO_SUCCESS;
686 }
687 
LogErrorCapture(AudioHandle handle,int errorCode,int reason)688 static void LogErrorCapture(AudioHandle handle, int errorCode, int reason)
689 {
690     struct AudioHwCapture *hwCapture = (struct AudioHwCapture *)handle;
691     if (hwCapture == NULL) {
692         AUDIO_FUNC_LOGE("Parameter error!");
693         return;
694     }
695 
696     hwCapture->errorLog.totalErrors++;
697     if (hwCapture->errorLog.iter >= ERROR_LOG_MAX_NUM) {
698         hwCapture->errorLog.iter = 0;
699     }
700 
701     int32_t ret = LogErrorGetRensonAndTime(hwCapture, reason);
702     if (ret < 0) {
703         return;
704     }
705     if (errorCode == WRITE_FRAME_ERROR_CODE) {
706         hwCapture->errorLog.errorDump[hwCapture->errorLog.iter].errorCode = errorCode;
707         hwCapture->errorLog.errorDump[hwCapture->errorLog.iter].count = hwCapture->errorLog.iter;
708         hwCapture->errorLog.errorDump[hwCapture->errorLog.iter].frames =
709             hwCapture->captureParam.frameCaptureMode.frames;
710         hwCapture->errorLog.iter++;
711     }
712 }
713 
AudioCaptureCaptureFrame(struct IAudioCapture * capture,int8_t * frame,uint32_t * frameLen,uint64_t * replyBytes)714 int32_t AudioCaptureCaptureFrame(
715     struct IAudioCapture *capture, int8_t *frame, uint32_t *frameLen, uint64_t *replyBytes)
716 {
717     struct AudioHwCapture *hwCapture = (struct AudioHwCapture *)capture;
718     if (hwCapture == NULL || frame == NULL || frameLen == NULL ||
719         hwCapture->captureParam.frameCaptureMode.buffer == NULL) {
720         AUDIO_FUNC_LOGE("Param is NULL Fail!");
721         return AUDIO_ERR_INVALID_PARAM;
722     }
723 
724     InterfaceLibModeCapturePassthrough *pInterfaceLibModeCapture = AudioPassthroughGetInterfaceLibModeCapture();
725     if (pInterfaceLibModeCapture == NULL || *pInterfaceLibModeCapture == NULL) {
726         AUDIO_FUNC_LOGE("pInterfaceLibModeCapture Fail!");
727         return AUDIO_ERR_INTERNAL;
728     }
729     if (hwCapture->devDataHandle == NULL) {
730         return AUDIO_ERR_INTERNAL;
731     }
732 
733     int32_t ret =
734         (*pInterfaceLibModeCapture)(hwCapture->devDataHandle, &hwCapture->captureParam, AUDIO_DRV_PCM_IOCTL_READ);
735     if (ret < 0) {
736         AUDIO_FUNC_LOGE("Capture Frame FAIL!");
737         LogErrorCapture(capture, WRITE_FRAME_ERROR_CODE, ret);
738         return AUDIO_ERR_INTERNAL;
739     }
740     if (*frameLen < hwCapture->captureParam.frameCaptureMode.bufferSize) {
741         AUDIO_FUNC_LOGE("Capture Frame frameLen too little!");
742         return AUDIO_ERR_INTERNAL;
743     }
744 
745     ret = memcpy_s(frame, (size_t)*frameLen, hwCapture->captureParam.frameCaptureMode.buffer,
746         (size_t)hwCapture->captureParam.frameCaptureMode.bufferSize);
747     if (ret != EOK) {
748         AUDIO_FUNC_LOGE("memcpy_s fail");
749         return AUDIO_ERR_INTERNAL;
750     }
751 
752     *replyBytes = (uint32_t)hwCapture->captureParam.frameCaptureMode.bufferSize;
753 
754     hwCapture->captureParam.frameCaptureMode.frames += hwCapture->captureParam.frameCaptureMode.bufferFrameSize;
755     if (hwCapture->captureParam.frameCaptureMode.attrs.sampleRate == 0) {
756         AUDIO_FUNC_LOGE("Divisor cannot be zero!");
757         return AUDIO_ERR_INTERNAL;
758     }
759     if (TimeToAudioTimeStamp(hwCapture->captureParam.frameCaptureMode.bufferFrameSize,
760         &hwCapture->captureParam.frameCaptureMode.time,
761         hwCapture->captureParam.frameCaptureMode.attrs.sampleRate) == HDF_FAILURE) {
762         AUDIO_FUNC_LOGE("Frame is NULL");
763         return AUDIO_ERR_INTERNAL;
764     }
765     return AUDIO_SUCCESS;
766 }
767 
AudioCaptureGetCapturePosition(struct IAudioCapture * capture,uint64_t * frames,struct AudioTimeStamp * time)768 int32_t AudioCaptureGetCapturePosition(struct IAudioCapture *capture, uint64_t *frames, struct AudioTimeStamp *time)
769 {
770     struct AudioHwCapture *impl = (struct AudioHwCapture *)capture;
771     if (impl == NULL || frames == NULL || time == NULL) {
772         AUDIO_FUNC_LOGE("Parameter error!");
773         return AUDIO_ERR_INVALID_PARAM;
774     }
775 
776     *frames = impl->captureParam.frameCaptureMode.frames;
777     *time = impl->captureParam.frameCaptureMode.time;
778     return AUDIO_SUCCESS;
779 }
780 
SetValueCapture(struct ExtraParams mExtraParams,struct AudioHwCapture * capture)781 static int32_t SetValueCapture(struct ExtraParams mExtraParams, struct AudioHwCapture *capture)
782 {
783     if (capture == NULL) {
784         AUDIO_FUNC_LOGE("Parameter error!");
785         return HDF_FAILURE;
786     }
787     if (mExtraParams.route != -1) {
788         capture->captureParam.captureMode.hwInfo.pathroute = mExtraParams.route;
789     }
790     if (mExtraParams.format != -1) {
791         capture->captureParam.frameCaptureMode.attrs.format = mExtraParams.format;
792     }
793     if (mExtraParams.channels != 0) {
794         capture->captureParam.frameCaptureMode.attrs.channelCount = mExtraParams.channels;
795     }
796     if (mExtraParams.flag) {
797         capture->captureParam.frameCaptureMode.frames = mExtraParams.frames;
798     }
799     if (mExtraParams.sampleRate != 0) {
800         capture->captureParam.frameCaptureMode.attrs.sampleRate = mExtraParams.sampleRate;
801     }
802     return HDF_SUCCESS;
803 }
804 
AudioCaptureSetExtraParams(struct IAudioCapture * handle,const char * keyValueList)805 int32_t AudioCaptureSetExtraParams(struct IAudioCapture *handle, const char *keyValueList)
806 {
807     int32_t check = 0;
808     int32_t count = 0;
809     struct ExtraParams mExtraParams;
810 
811     struct AudioHwCapture *capture = (struct AudioHwCapture *)handle;
812     if (capture == NULL || keyValueList == NULL) {
813         AUDIO_FUNC_LOGE("Parameter error!");
814         return AUDIO_ERR_INVALID_PARAM;
815     }
816 
817     if (AudioSetExtraParams(keyValueList, &count, &mExtraParams, &check) < 0) {
818         return AUDIO_ERR_INTERNAL;
819     }
820     if (count != 0 && check == count) {
821         SetValueCapture(mExtraParams, capture);
822         return AUDIO_SUCCESS;
823     } else {
824         AUDIO_FUNC_LOGE("AudioSetExtraParams error!");
825         return AUDIO_ERR_INTERNAL;
826     }
827 }
828 
AudioCaptureGetExtraParams(struct IAudioCapture * handle,char * keyValueList,uint32_t listLenth)829 int32_t AudioCaptureGetExtraParams(struct IAudioCapture *handle, char *keyValueList, uint32_t listLenth)
830 {
831     int32_t ret;
832     struct AudioHwCapture *capture = (struct AudioHwCapture *)handle;
833     if (capture == NULL || keyValueList == NULL || listLenth == 0) {
834         AUDIO_FUNC_LOGE("Parameter error!");
835         return AUDIO_ERR_INVALID_PARAM;
836     }
837 
838     uint32_t bufferSize = strlen(ROUTE_SAMPLE) + strlen(FORMAT_SAMPLE) + strlen(CHANNELS_SAMPLE) +
839         strlen(FRAME_COUNT_SAMPLE) + strlen(SAMPLING_RATE_SAMPLE) + 1;
840     if (listLenth < bufferSize) {
841         AUDIO_FUNC_LOGE("listLenth < bufferSize error!");
842         return AUDIO_ERR_INTERNAL;
843     }
844 
845     ret = AddElementToList(
846         keyValueList, listLenth, AUDIO_ATTR_PARAM_ROUTE, &capture->captureParam.captureMode.hwInfo.pathroute);
847     if (ret < 0) {
848         AUDIO_FUNC_LOGE("AddElementToList hwInfo.pathroute failed!");
849         return AUDIO_ERR_INTERNAL;
850     }
851 
852     ret = AddElementToList(
853         keyValueList, listLenth, AUDIO_ATTR_PARAM_FORMAT, &capture->captureParam.frameCaptureMode.attrs.format);
854     if (ret < 0) {
855         AUDIO_FUNC_LOGE("AddElementToList attrs.format failed!");
856         return AUDIO_ERR_INTERNAL;
857     }
858 
859     ret = AddElementToList(
860         keyValueList, listLenth, AUDIO_ATTR_PARAM_CHANNELS, &capture->captureParam.frameCaptureMode.attrs.channelCount);
861     if (ret < 0) {
862         AUDIO_FUNC_LOGE("AddElementToList attrs.channelCount failed!");
863         return AUDIO_ERR_INTERNAL;
864     }
865 
866     ret = AddElementToList(
867         keyValueList, listLenth, AUDIO_ATTR_PARAM_FRAME_COUNT, &capture->captureParam.frameCaptureMode.frames);
868     if (ret < 0) {
869         AUDIO_FUNC_LOGE("AddElementToList frameCaptureMode.frames failed!");
870         return AUDIO_ERR_INTERNAL;
871     }
872 
873     ret = AddElementToList(keyValueList, listLenth, AUDIO_ATTR_PARAM_SAMPLING_RATE,
874         &capture->captureParam.frameCaptureMode.attrs.sampleRate);
875     if (ret < 0) {
876         AUDIO_FUNC_LOGE("AddElementToList attrs.sampleRate failed!");
877         return AUDIO_ERR_INTERNAL;
878     }
879     return AUDIO_SUCCESS;
880 }
881 
AudioCaptureReqMmapBuffer(struct IAudioCapture * handle,int32_t reqSize,struct AudioMmapBufferDescriptor * desc)882 int32_t AudioCaptureReqMmapBuffer(
883     struct IAudioCapture *handle, int32_t reqSize, struct AudioMmapBufferDescriptor *desc)
884 {
885     (void)handle;
886     (void)reqSize;
887     (void)desc;
888     return HDF_ERR_NOT_SUPPORT;
889 }
890 
AudioCaptureGetMmapPosition(struct IAudioCapture * handle,uint64_t * frames,struct AudioTimeStamp * time)891 int32_t AudioCaptureGetMmapPosition(struct IAudioCapture *handle, uint64_t *frames, struct AudioTimeStamp *time)
892 {
893     struct AudioHwCapture *capture = (struct AudioHwCapture *)handle;
894     if (capture == NULL || frames == NULL || time == NULL) {
895         AUDIO_FUNC_LOGE("Parameter error!");
896         return AUDIO_ERR_INVALID_PARAM;
897     }
898 
899     InterfaceLibModeCapturePassthrough *pInterfaceLibModeCapture = AudioPassthroughGetInterfaceLibModeCapture();
900     if (pInterfaceLibModeCapture == NULL || *pInterfaceLibModeCapture == NULL) {
901         AUDIO_FUNC_LOGE("pInterfaceLibModeCapture Fail!");
902         return AUDIO_ERR_INTERNAL;
903     }
904 
905     if (capture->devDataHandle == NULL) {
906         return AUDIO_ERR_INTERNAL;
907     }
908 
909     int32_t ret = (*pInterfaceLibModeCapture)(
910         capture->devDataHandle, &capture->captureParam, AUDIO_DRV_PCM_IOCTL_MMAP_POSITION_CAPTURE);
911     if (ret < 0) {
912         AUDIO_FUNC_LOGE("GetMmapPosition SetParams FAIL");
913         return AUDIO_ERR_INTERNAL;
914     }
915 
916     *frames = capture->captureParam.frameCaptureMode.frames;
917 
918     capture->captureParam.frameCaptureMode.time.tvSec = (int64_t)(capture->captureParam.frameCaptureMode.frames /
919         capture->captureParam.frameCaptureMode.attrs.sampleRate);
920 
921     uint64_t lastBufFrames =
922         capture->captureParam.frameCaptureMode.frames % capture->captureParam.frameCaptureMode.attrs.sampleRate;
923 
924     capture->captureParam.frameCaptureMode.time.tvNSec =
925         (int64_t)((lastBufFrames * SEC_TO_NSEC) / capture->captureParam.frameCaptureMode.attrs.sampleRate);
926 
927     *time = capture->captureParam.frameCaptureMode.time;
928     return AUDIO_SUCCESS;
929 }
930 
AudioCaptureTurnStandbyMode(struct IAudioCapture * handle)931 int32_t AudioCaptureTurnStandbyMode(struct IAudioCapture *handle)
932 {
933     struct AudioHwCapture *capture = (struct AudioHwCapture *)handle;
934     if (capture == NULL) {
935         AUDIO_FUNC_LOGE("capture is null");
936         return AUDIO_ERR_INVALID_PARAM;
937     }
938 
939     capture->captureParam.captureMode.hwInfo.deviceDescript.pins = PIN_NONE;
940 
941     int32_t ret = AudioCaptureStop((AudioHandle)capture);
942     if (ret < 0) {
943         return AUDIO_ERR_INTERNAL;
944     }
945     return AUDIO_SUCCESS;
946 }
947 
AudioCaptureAudioDevDump(struct IAudioCapture * handle,int32_t range,int32_t fd)948 int32_t AudioCaptureAudioDevDump(struct IAudioCapture *handle, int32_t range, int32_t fd)
949 {
950     struct AudioHwCapture *capture = (struct AudioHwCapture *)handle;
951     if (capture == NULL) {
952         AUDIO_FUNC_LOGE("Parameter error!");
953         return AUDIO_ERR_INVALID_PARAM;
954     }
955 
956     dprintf(fd, "%s%d\n", "Number of errors: ", capture->errorLog.totalErrors);
957 
958     if (range < RANGE_MIN - 1 || range > RANGE_MAX) {
959         dprintf(fd, "%s\n", "Out of range, invalid output");
960         return AUDIO_SUCCESS;
961     }
962 
963     uint32_t mSize = capture->errorLog.iter;
964     if (range < RANGE_MIN) {
965         dprintf(fd, "%-5s  %-10s  %s\n", "count", "errorCode", "Time");
966         for (uint32_t i = 0; i < mSize; i++) {
967             dprintf(fd, FORMAT_TWO, capture->errorLog.errorDump[i].count + 1, capture->errorLog.errorDump[i].errorCode,
968                 capture->errorLog.errorDump[i].currentTime);
969         }
970     } else {
971         dprintf(fd, "%-5s  %-10s  %-20s  %-15s  %s\n", "count", "errorCode", "frames", "fail reason", "Time");
972         for (uint32_t i = 0; i < mSize; i++) {
973             dprintf(fd, FORMAT_ONE, capture->errorLog.errorDump[i].count + 1, capture->errorLog.errorDump[i].errorCode,
974                 capture->errorLog.errorDump[i].frames, capture->errorLog.errorDump[i].reason,
975                 capture->errorLog.errorDump[i].currentTime);
976         }
977     }
978     return AUDIO_SUCCESS;
979 }
980 
AudioCaptureRelease(struct IAudioCapture * instance)981 void AudioCaptureRelease(struct IAudioCapture *instance)
982 {
983     (void)instance;
984 }
985