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