• 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 #include <hdf_log.h>
16 #include "audio_internal.h"
17 #include "audio_adapter_info_common.h"
18 #include "audio_adapter.h"
19 namespace OHOS::HDI::Audio_Bluetooth {
20 constexpr int CONFIG_CHANNEL_COUNT = 2; // two channels
21 constexpr float GAIN_MAX = 50.0;
22 
23 constexpr int DEFAULT_RENDER_SAMPLING_RATE = 48000;
24 constexpr int DEEP_BUFFER_RENDER_PERIOD_SIZE = 4096;
25 constexpr int DEEP_BUFFER_RENDER_PERIOD_COUNT = 8;
26 constexpr const char *TYPE_RENDER = "Render";
27 constexpr const char *TYPE_CAPTURE = "Capture";
28 constexpr const int SHIFT_RIGHT_31_BITS = 31;
29 
GetAudioRenderFunc(struct AudioHwRender * hwRender)30 int32_t GetAudioRenderFunc(struct AudioHwRender *hwRender)
31 {
32     if (hwRender == NULL) {
33         return HDF_FAILURE;
34     }
35     hwRender->common.control.Start = AudioRenderStart;
36     hwRender->common.control.Stop = AudioRenderStop;
37     hwRender->common.control.Pause = AudioRenderPause;
38     hwRender->common.control.Resume = AudioRenderResume;
39     hwRender->common.control.Flush = AudioRenderFlush;
40     hwRender->common.control.TurnStandbyMode = AudioRenderTurnStandbyMode;
41     hwRender->common.control.AudioDevDump = AudioRenderAudioDevDump;
42     hwRender->common.attr.GetFrameSize = AudioRenderGetFrameSize;
43     hwRender->common.attr.GetFrameCount = AudioRenderGetFrameCount;
44     hwRender->common.attr.SetSampleAttributes = AudioRenderSetSampleAttributes;
45     hwRender->common.attr.GetSampleAttributes = AudioRenderGetSampleAttributes;
46     hwRender->common.attr.GetCurrentChannelId = AudioRenderGetCurrentChannelId;
47     hwRender->common.attr.SetExtraParams = AudioRenderSetExtraParams;
48     hwRender->common.attr.GetExtraParams = AudioRenderGetExtraParams;
49     hwRender->common.attr.ReqMmapBuffer = AudioRenderReqMmapBuffer;
50     hwRender->common.attr.GetMmapPosition = AudioRenderGetMmapPosition;
51     hwRender->common.scene.CheckSceneCapability = AudioRenderCheckSceneCapability;
52     hwRender->common.scene.SelectScene = AudioRenderSelectScene;
53     hwRender->common.volume.SetMute = AudioRenderSetMute;
54     hwRender->common.volume.GetMute = AudioRenderGetMute;
55     hwRender->common.volume.SetVolume = AudioRenderSetVolume;
56     hwRender->common.volume.GetVolume = AudioRenderGetVolume;
57     hwRender->common.volume.GetGainThreshold = AudioRenderGetGainThreshold;
58     hwRender->common.volume.GetGain = AudioRenderGetGain;
59     hwRender->common.volume.SetGain = AudioRenderSetGain;
60     hwRender->common.GetLatency = AudioRenderGetLatency;
61     hwRender->common.RenderFrame = AudioRenderRenderFrame;
62     hwRender->common.GetRenderPosition = AudioRenderGetRenderPosition;
63     hwRender->common.SetRenderSpeed = AudioRenderSetRenderSpeed;
64     hwRender->common.GetRenderSpeed = AudioRenderGetRenderSpeed;
65     hwRender->common.SetChannelMode = AudioRenderSetChannelMode;
66     hwRender->common.GetChannelMode = AudioRenderGetChannelMode;
67     hwRender->common.RegCallback = AudioRenderRegCallback;
68     hwRender->common.DrainBuffer = AudioRenderDrainBuffer;
69     return HDF_SUCCESS;
70 }
71 
CheckParaDesc(const struct AudioDeviceDescriptor * desc,const char * type)72 int32_t CheckParaDesc(const struct AudioDeviceDescriptor *desc, const char *type)
73 {
74     if (desc == NULL || type == NULL) {
75         return HDF_FAILURE;
76     }
77     if ((desc->portId) >> SHIFT_RIGHT_31_BITS) {
78         return HDF_ERR_NOT_SUPPORT;
79     }
80     AudioPortPin pins = desc->pins;
81     if (!strcmp(type, TYPE_CAPTURE)) {
82         if (pins == PIN_IN_MIC || pins == PIN_IN_HS_MIC || pins == PIN_IN_LINEIN) {
83             return HDF_SUCCESS;
84         } else {
85             return HDF_ERR_NOT_SUPPORT;
86         }
87     } else if (!strcmp(type, TYPE_RENDER)) {
88         if (pins == PIN_OUT_SPEAKER || pins == PIN_OUT_HEADSET || pins == PIN_OUT_LINEOUT || pins == PIN_OUT_HDMI) {
89             return HDF_SUCCESS;
90         } else {
91             return HDF_ERR_NOT_SUPPORT;
92         }
93     }
94     return HDF_ERR_NOT_SUPPORT;
95 }
96 
CheckParaAttr(const struct AudioSampleAttributes * attrs)97 int32_t CheckParaAttr(const struct AudioSampleAttributes *attrs)
98 {
99     if (attrs == NULL) {
100         return HDF_FAILURE;
101     }
102     int32_t ret = ((attrs->sampleRate) >> SHIFT_RIGHT_31_BITS) + ((attrs->channelCount) >> SHIFT_RIGHT_31_BITS) +
103         ((attrs->period) >> SHIFT_RIGHT_31_BITS) + ((attrs->frameSize) >> SHIFT_RIGHT_31_BITS) +
104         ((attrs->startThreshold) >> SHIFT_RIGHT_31_BITS) + ((attrs->stopThreshold) >> SHIFT_RIGHT_31_BITS) +
105         ((attrs->silenceThreshold) >> SHIFT_RIGHT_31_BITS);
106     if (ret > 0) {
107         return HDF_ERR_NOT_SUPPORT;
108     }
109     AudioCategory audioCategory = attrs->type;
110     if (AUDIO_IN_MEDIA != audioCategory && AUDIO_IN_COMMUNICATION != audioCategory) {
111         return HDF_ERR_NOT_SUPPORT;
112     }
113     AudioFormat audioFormat = attrs->format;
114     return CheckAttrFormat(audioFormat);
115 }
116 
AttrFormatToBit(const struct AudioSampleAttributes * attrs,int32_t * format)117 int32_t AttrFormatToBit(const struct AudioSampleAttributes *attrs, int32_t *format)
118 {
119     if (attrs == NULL || format == NULL) {
120         return HDF_FAILURE;
121     }
122     AudioFormat audioFormat = attrs->format;
123     switch (audioFormat) {
124         case AUDIO_FORMAT_TYPE_PCM_8_BIT:
125             *format = BIT_NUM_8;
126             return HDF_SUCCESS;
127         case AUDIO_FORMAT_TYPE_PCM_16_BIT:
128             *format = BIT_NUM_16;
129             return HDF_SUCCESS;
130         case AUDIO_FORMAT_TYPE_PCM_24_BIT:
131             *format = BIT_NUM_24;
132             return HDF_SUCCESS;
133         case AUDIO_FORMAT_TYPE_PCM_32_BIT:
134             *format = BIT_NUM_32;
135             return HDF_SUCCESS;
136         default:
137             return HDF_ERR_NOT_SUPPORT;
138     }
139 }
140 
InitHwRenderParam(struct AudioHwRender * hwRender,const struct AudioDeviceDescriptor * desc,const struct AudioSampleAttributes * attrs)141 int32_t InitHwRenderParam(struct AudioHwRender *hwRender, const struct AudioDeviceDescriptor *desc,
142                           const struct AudioSampleAttributes *attrs)
143 {
144     if (hwRender == NULL || desc == NULL || attrs == NULL) {
145         HDF_LOGE("InitHwRenderParam param Is NULL");
146         return HDF_FAILURE;
147     }
148     int32_t ret = CheckParaDesc(desc, TYPE_RENDER);
149     if (ret != HDF_SUCCESS) {
150         HDF_LOGE("CheckParaDesc Fail");
151         return ret;
152     }
153     ret = CheckParaAttr(attrs);
154     if (ret != HDF_SUCCESS) {
155         HDF_LOGE("CheckParaAttr Fail");
156         return ret;
157     }
158     int32_t formatValue = -1;
159     ret = AttrFormatToBit(attrs, &formatValue);
160     if (ret != HDF_SUCCESS) {
161         HDF_LOGE("AttrFormatToBit Fail");
162         return ret;
163     }
164     if (attrs->channelCount == 0) {
165         return HDF_FAILURE;
166     }
167     hwRender->renderParam.renderMode.hwInfo.deviceDescript = *desc;
168     hwRender->renderParam.frameRenderMode.attrs = *attrs;
169     hwRender->renderParam.renderMode.ctlParam.audioGain.gainMax = GAIN_MAX;  // init gainMax
170     hwRender->renderParam.renderMode.ctlParam.audioGain.gainMin = 0;
171     hwRender->renderParam.frameRenderMode.frames = 0;
172     hwRender->renderParam.frameRenderMode.time.tvNSec = 0;
173     hwRender->renderParam.frameRenderMode.time.tvSec = 0;
174     hwRender->renderParam.frameRenderMode.byteRate = DEFAULT_RENDER_SAMPLING_RATE;
175     hwRender->renderParam.frameRenderMode.periodSize = DEEP_BUFFER_RENDER_PERIOD_SIZE;
176     hwRender->renderParam.frameRenderMode.periodCount = DEEP_BUFFER_RENDER_PERIOD_COUNT;
177     hwRender->renderParam.frameRenderMode.attrs.period = attrs->period;
178     hwRender->renderParam.frameRenderMode.attrs.frameSize = attrs->frameSize;
179     hwRender->renderParam.frameRenderMode.attrs.startThreshold = attrs->startThreshold;
180     hwRender->renderParam.frameRenderMode.attrs.stopThreshold = attrs->stopThreshold;
181     hwRender->renderParam.frameRenderMode.attrs.silenceThreshold = attrs->silenceThreshold;
182     hwRender->renderParam.frameRenderMode.attrs.isBigEndian = attrs->isBigEndian;
183     hwRender->renderParam.frameRenderMode.attrs.isSignedData = attrs->isSignedData;
184     return HDF_SUCCESS;
185 }
186 
187 AudioFormat g_formatIdZero = AUDIO_FORMAT_TYPE_PCM_16_BIT;
InitForGetPortCapability(struct AudioPort portIndex,struct AudioPortCapability * capabilityIndex)188 int32_t InitForGetPortCapability(struct AudioPort portIndex, struct AudioPortCapability *capabilityIndex)
189 {
190     if (capabilityIndex == NULL) {
191         HDF_LOGE("capabilityIndex Is NULL");
192         return HDF_FAILURE;
193     }
194     /* get capabilityIndex from driver or default */
195     if (portIndex.dir != PORT_OUT) {
196         capabilityIndex->hardwareMode = true;
197         capabilityIndex->channelMasks = AUDIO_CHANNEL_STEREO;
198         capabilityIndex->channelCount = CONFIG_CHANNEL_COUNT;
199         return HDF_SUCCESS;
200     }
201     if (portIndex.portId == 0) {
202         capabilityIndex->hardwareMode = true;
203         capabilityIndex->channelMasks = AUDIO_CHANNEL_STEREO;
204         capabilityIndex->channelCount = CONFIG_CHANNEL_COUNT;
205         capabilityIndex->deviceType = portIndex.dir;
206         capabilityIndex->deviceId = PIN_OUT_SPEAKER;
207         capabilityIndex->formatNum = 1;
208         capabilityIndex->formats = &g_formatIdZero;
209         capabilityIndex->sampleRateMasks = AUDIO_SAMPLE_RATE_MASK_16000;
210         capabilityIndex->subPortsNum = 1;
211         capabilityIndex->subPorts =
212             reinterpret_cast<struct AudioSubPortCapability *>(calloc(capabilityIndex->subPortsNum,
213             sizeof(struct AudioSubPortCapability)));
214         if (capabilityIndex->subPorts == NULL) {
215             HDF_LOGE("capabilityIndex subPorts is NULL!");
216             return HDF_FAILURE;
217         }
218         capabilityIndex->subPorts->portId = portIndex.portId;
219         capabilityIndex->subPorts->desc = portIndex.portName;
220         capabilityIndex->subPorts->mask = PORT_PASSTHROUGH_LPCM;
221         return HDF_SUCCESS;
222     }
223     if (portIndex.portId == 1) {
224         capabilityIndex->hardwareMode = true;
225         capabilityIndex->channelMasks = AUDIO_CHANNEL_STEREO;
226         capabilityIndex->channelCount = CONFIG_CHANNEL_COUNT;
227         capabilityIndex->deviceType = portIndex.dir;
228         capabilityIndex->deviceId = PIN_OUT_HEADSET;
229         capabilityIndex->formatNum = 1;
230         capabilityIndex->formats = &g_formatIdZero;
231         capabilityIndex->sampleRateMasks = AUDIO_SAMPLE_RATE_MASK_16000 | AUDIO_SAMPLE_RATE_MASK_8000;
232         return HDF_SUCCESS;
233     }
234     if (portIndex.portId == HDMI_PORT_ID) {
235         return HdmiPortInit(portIndex, capabilityIndex);
236     }
237     return HDF_FAILURE;
238 }
239 
AudioAdapterReleaseCapSubPorts(const struct AudioPortAndCapability * portCapabilitys,int32_t num)240 void AudioAdapterReleaseCapSubPorts(const struct AudioPortAndCapability *portCapabilitys, int32_t num)
241 {
242     int32_t i = 0;
243     if (portCapabilitys == NULL) {
244         return;
245     }
246     while (i < num) {
247         if (&portCapabilitys[i] == NULL) {
248             break;
249         }
250         AudioMemFree((void **)(&portCapabilitys[i].capability.subPorts));
251         i++;
252     }
253     return;
254 }
255 
AudioAdapterInitAllPorts(struct AudioAdapter * adapter)256 int32_t AudioAdapterInitAllPorts(struct AudioAdapter *adapter)
257 {
258     struct AudioHwAdapter *hwAdapter = reinterpret_cast<struct AudioHwAdapter *>(adapter);
259     if (hwAdapter == NULL) {
260         HDF_LOGE("hwAdapter Is NULL");
261         return AUDIO_HAL_ERR_INVALID_PARAM;
262     }
263     if (hwAdapter->portCapabilitys != NULL) {
264         HDF_LOGE("portCapabilitys already Init!");
265         return AUDIO_HAL_SUCCESS;
266     }
267     uint32_t portNum = hwAdapter->adapterDescriptor.portNum;
268     struct AudioPort *ports = hwAdapter->adapterDescriptor.ports;
269     if (ports == NULL) {
270         HDF_LOGE("ports is NULL!");
271         return AUDIO_HAL_ERR_INTERNAL;
272     }
273     if (portNum == 0) {
274         return AUDIO_HAL_ERR_INTERNAL;
275     }
276     struct AudioPortAndCapability *portCapability =
277         reinterpret_cast<struct AudioPortAndCapability *>(calloc(portNum, sizeof(struct AudioPortAndCapability)));
278     if (portCapability == NULL) {
279         HDF_LOGE("portCapability is NULL!");
280         return AUDIO_HAL_ERR_INTERNAL;
281     }
282     for (uint32_t i = 0; i < portNum; i++) {
283         portCapability[i].port = ports[i];
284         if (InitForGetPortCapability(ports[i], &portCapability[i].capability)) {
285             HDF_LOGE("ports Init Fail!");
286             AudioAdapterReleaseCapSubPorts(portCapability, portNum);
287             AudioMemFree((void **)&portCapability);
288             return AUDIO_HAL_ERR_INTERNAL;
289         }
290     }
291     hwAdapter->portCapabilitys = portCapability;
292     hwAdapter->portCapabilitys->mode = PORT_PASSTHROUGH_LPCM;
293     return AUDIO_HAL_SUCCESS;
294 }
295 
AudioReleaseRenderHandle(struct AudioHwRender * hwRender)296 void AudioReleaseRenderHandle(struct AudioHwRender *hwRender)
297 {
298     return;
299 }
300 
AudioAdapterCreateRenderPre(struct AudioHwRender * hwRender,const struct AudioDeviceDescriptor * desc,const struct AudioSampleAttributes * attrs,const struct AudioHwAdapter * hwAdapter)301 int32_t AudioAdapterCreateRenderPre(struct AudioHwRender *hwRender, const struct AudioDeviceDescriptor *desc,
302                                     const struct AudioSampleAttributes *attrs, const struct AudioHwAdapter *hwAdapter)
303 {
304     HDF_LOGI("%s", __func__);
305     if (hwAdapter == NULL || hwRender == NULL || desc == NULL || attrs == NULL) {
306         HDF_LOGE("Pointer is null!");
307         return HDF_FAILURE;
308     }
309 
310     if (GetAudioRenderFunc(hwRender) < 0) {
311         return HDF_FAILURE;
312     }
313     /* Fill hwRender para */
314     if (InitHwRenderParam(hwRender, desc, attrs) < 0) {
315         return HDF_FAILURE;
316     }
317     /* Select Path */
318     if (hwAdapter->adapterDescriptor.adapterName == NULL) {
319         HDF_LOGE("pointer is null!");
320         return HDF_FAILURE;
321     }
322     uint32_t adapterNameLen = strlen(hwAdapter->adapterDescriptor.adapterName);
323     if (adapterNameLen == 0) {
324         HDF_LOGE("adapterNameLen is null!");
325         return HDF_FAILURE;
326     }
327     /* Get Adapter name */
328     int32_t ret = strncpy_s(hwRender->renderParam.renderMode.hwInfo.adapterName, NAME_LEN - 1,
329                             hwAdapter->adapterDescriptor.adapterName, adapterNameLen);
330     if (ret != EOK) {
331         HDF_LOGE("copy fail");
332         return HDF_FAILURE;
333     }
334     return HDF_SUCCESS;
335 }
336 
AudioAdapterCreateRender(struct AudioAdapter * adapter,const struct AudioDeviceDescriptor * desc,const struct AudioSampleAttributes * attrs,struct AudioRender ** render)337 int32_t AudioAdapterCreateRender(struct AudioAdapter *adapter, const struct AudioDeviceDescriptor *desc,
338                                  const struct AudioSampleAttributes *attrs, struct AudioRender **render)
339 {
340     struct AudioHwAdapter *hwAdapter = reinterpret_cast<struct AudioHwAdapter *>(adapter);
341     if (hwAdapter == NULL || desc == NULL || attrs == NULL || render == NULL) {
342         return AUDIO_HAL_ERR_INVALID_PARAM;
343     }
344     if (hwAdapter->adapterMgrRenderFlag > 0) {
345         HDF_LOGE("Create render repeatedly!");
346         return AUDIO_HAL_ERR_INTERNAL;
347     }
348     struct AudioHwRender *hwRender = reinterpret_cast<struct AudioHwRender *>(calloc(1, sizeof(*hwRender)));
349     if (hwRender == NULL) {
350         HDF_LOGE("hwRender is NULL!");
351         return AUDIO_HAL_ERR_MALLOC_FAIL;
352     }
353     int32_t ret = AudioAdapterCreateRenderPre(hwRender, desc, attrs, hwAdapter);
354     if (ret != 0) {
355         HDF_LOGE("AudioAdapterCreateRenderPre fail");
356         AudioMemFree(reinterpret_cast<void **>(&hwRender));
357         return AUDIO_HAL_ERR_INTERNAL;
358     }
359     hwAdapter->adapterMgrRenderFlag++;
360     *render = &hwRender->common;
361     return AUDIO_HAL_SUCCESS;
362 }
363 
AudioAdapterDestroyRender(struct AudioAdapter * adapter,struct AudioRender * render)364 int32_t AudioAdapterDestroyRender(struct AudioAdapter *adapter, struct AudioRender *render)
365 {
366     struct AudioHwAdapter *hwAdapter = reinterpret_cast<struct AudioHwAdapter *>(adapter);
367     if (hwAdapter == NULL || render == NULL) {
368         return AUDIO_HAL_ERR_INVALID_PARAM;
369     }
370     if (hwAdapter->adapterMgrRenderFlag > 0) {
371         hwAdapter->adapterMgrRenderFlag--;
372     }
373     struct AudioHwRender *hwRender = reinterpret_cast<struct AudioHwRender *>(render);
374     if (hwRender == NULL) {
375         return AUDIO_HAL_ERR_INTERNAL;
376     }
377     if (hwRender->renderParam.frameRenderMode.buffer != NULL) {
378         int ret = render->control.Stop((AudioHandle)render);
379         if (ret < 0) {
380             HDF_LOGE("render Stop failed");
381         }
382     }
383     AudioReleaseRenderHandle(hwRender);
384     AudioMemFree(reinterpret_cast<void **>(&hwRender->renderParam.frameRenderMode.buffer));
385     AudioMemFree(reinterpret_cast<void **>(&render));
386     return AUDIO_HAL_SUCCESS;
387 }
388 
AudioAdapterGetPortCapability(struct AudioAdapter * adapter,const struct AudioPort * port,struct AudioPortCapability * capability)389 int32_t AudioAdapterGetPortCapability(struct AudioAdapter *adapter, const struct AudioPort *port,
390                                       struct AudioPortCapability *capability)
391 {
392     struct AudioHwAdapter *hwAdapter = reinterpret_cast<struct AudioHwAdapter *>(adapter);
393     if (hwAdapter == NULL || port == NULL || port->portName == NULL || capability == NULL) {
394         return AUDIO_HAL_ERR_INVALID_PARAM;
395     }
396     if (port->portId < 0) {
397         return AUDIO_HAL_ERR_INTERNAL;
398     }
399     struct AudioPortAndCapability *hwAdapterPortCapabilitys = hwAdapter->portCapabilitys;
400     if (hwAdapterPortCapabilitys == NULL) {
401         HDF_LOGE("hwAdapter portCapabilitys is NULL!");
402         return AUDIO_HAL_ERR_INTERNAL;
403     }
404     int32_t portNum = hwAdapter->adapterDescriptor.portNum;
405     while (hwAdapterPortCapabilitys != NULL && portNum) {
406         if (hwAdapterPortCapabilitys->port.portId == port->portId) {
407             *capability = hwAdapterPortCapabilitys->capability;
408             return AUDIO_HAL_SUCCESS;
409         }
410         hwAdapterPortCapabilitys++;
411         portNum--;
412     }
413     return AUDIO_HAL_ERR_INTERNAL;
414 }
415 
AudioAdapterSetPassthroughMode(struct AudioAdapter * adapter,const struct AudioPort * port,AudioPortPassthroughMode mode)416 int32_t AudioAdapterSetPassthroughMode(struct AudioAdapter *adapter,
417     const struct AudioPort *port, AudioPortPassthroughMode mode)
418 {
419     if (adapter == NULL || port == NULL || port->portName == NULL) {
420         return AUDIO_HAL_ERR_INVALID_PARAM;
421     }
422     if (port->dir != PORT_OUT || port->portId < 0 || strcmp(port->portName, "AOP") != 0) {
423         return AUDIO_HAL_ERR_INTERNAL;
424     }
425     struct AudioHwAdapter *hwAdapter = reinterpret_cast<struct AudioHwAdapter *>(adapter);
426     if (hwAdapter->portCapabilitys == NULL) {
427         HDF_LOGE("The pointer is null!");
428         return AUDIO_HAL_ERR_INTERNAL;
429     }
430     struct AudioPortAndCapability *portCapabilityTemp = hwAdapter->portCapabilitys;
431     struct AudioPortCapability *portCapability = NULL;
432     int32_t portNum = hwAdapter->adapterDescriptor.portNum;
433     while (portCapabilityTemp != NULL && portNum > 0) {
434         if (portCapabilityTemp->port.portId == port->portId) {
435             portCapability = &portCapabilityTemp->capability;
436             break;
437         }
438         portCapabilityTemp++;
439         portNum--;
440     }
441     if (portCapability == NULL || portNum <= 0) {
442         HDF_LOGE("hwAdapter portCapabilitys is Not Find!");
443         return AUDIO_HAL_ERR_INTERNAL;
444     }
445     struct AudioSubPortCapability *subPortCapability = portCapability->subPorts;
446     if (subPortCapability == NULL) {
447         HDF_LOGE("portCapability->subPorts is NULL!");
448         return AUDIO_HAL_ERR_INTERNAL;
449     }
450     int32_t subPortNum = portCapability->subPortsNum;
451     while (subPortCapability != NULL && subPortNum > 0) {
452         if (subPortCapability->mask == mode) {
453             portCapabilityTemp->mode = mode;
454             break;
455         }
456         subPortCapability++;
457         subPortNum--;
458     }
459     if (subPortNum > 0) {
460         return AUDIO_HAL_SUCCESS;
461     }
462     return AUDIO_HAL_ERR_INTERNAL;
463 }
464 
AudioAdapterGetPassthroughMode(struct AudioAdapter * adapter,const struct AudioPort * port,AudioPortPassthroughMode * mode)465 int32_t AudioAdapterGetPassthroughMode(struct AudioAdapter *adapter, const struct AudioPort *port,
466                                        AudioPortPassthroughMode *mode)
467 {
468     if (adapter == NULL || port == NULL || port->portName == NULL || mode == NULL) {
469         return AUDIO_HAL_ERR_INVALID_PARAM;
470     }
471     if (port->dir != PORT_OUT || port->portId < 0 || strcmp(port->portName, "AOP") != 0) {
472         return AUDIO_HAL_ERR_INTERNAL;
473     }
474     struct AudioHwAdapter *hwAdapter = reinterpret_cast<struct AudioHwAdapter *>(adapter);
475     if (hwAdapter->portCapabilitys == NULL) {
476         HDF_LOGE("portCapabilitys pointer is null!");
477         return AUDIO_HAL_ERR_INTERNAL;
478     }
479     struct AudioPortAndCapability *portCapabilitys = hwAdapter->portCapabilitys;
480     int32_t portNum = hwAdapter->adapterDescriptor.portNum;
481     while (portCapabilitys != NULL && portNum > 0) {
482         if (portCapabilitys->port.portId == port->portId) {
483             *mode = portCapabilitys->mode;
484             return AUDIO_HAL_SUCCESS;
485         }
486         portCapabilitys++;
487         portNum--;
488     }
489     return AUDIO_HAL_ERR_INTERNAL;
490 }
491 
AudioAdapterSetExtraParams(struct AudioAdapter * adapter,enum AudioExtParamKey key,const char * condition,const char * value)492 int32_t AudioAdapterSetExtraParams(struct AudioAdapter *adapter, enum AudioExtParamKey key,
493                                    const char *condition, const char *value)
494 {
495     (void)adapter;
496     (void)key;
497     (void)condition;
498     (void)value;
499     return HDF_ERR_NOT_SUPPORT;
500 }
501 
AudioAdapterGetExtraParams(struct AudioAdapter * adapter,enum AudioExtParamKey key,const char * condition,char * value,int32_t length)502 int32_t AudioAdapterGetExtraParams(struct AudioAdapter *adapter, enum AudioExtParamKey key,
503                                    const char *condition, char *value, int32_t length)
504 {
505     (void)adapter;
506     (void)key;
507     (void)condition;
508     (void)value;
509     (void)length;
510     return HDF_ERR_NOT_SUPPORT;
511 }
512 
513 }