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_pathselect.h"
17 #include "audio_hal_log.h"
18
19 #define HDF_LOG_TAG hal_audio_pathselect
20
21 #define SPEAKER "Speaker"
22 #define HEADPHONES "headphones"
23 #define MIC "mic"
24 #define HS_MIC "micHs"
25 #define JSON_UNPRINT 1
26
27 static cJSON *g_cJsonObj = NULL;
28
29 /* Depend on Audio_types.h : enum AudioCategory */
30 enum AudioCategoryPathSel {
31 PATH_USE_IN_MEDIA = 0,
32 PATH_USE_IN_COMMUNICATION,
33 PATH_USE_TYPE_MAX,
34 };
35
36 enum AudioPortPinPathSel {
37 PATH_DEV_NONE = 0x0u, /* Invalid pin */
38 PATH_DEV_OUT_SPEAKER = 0x1u, /* Speaker output pin */
39 PATH_DEV_OUT_HEADSET = 0x2u, /* Wired headset pin for output */
40 PATH_DEV_OUT_LINEOUT = 0x4u, /* Line-out pin */
41 PATH_DEV_OUT_HDMI = 0x8u, /* HDMI output pin */
42 PATH_DEV_MID = 0x8000000u, /* Microphone input pin */
43 PATH_DEV_IN_MIC = 0x8000001u, /* Microphone input pin */
44 PATH_DEV_IN_HS_MIC = 0x8000002u, /* Wired headset microphone pin for input */
45 PATH_DEV_IN_LINEIN = 0x8000004u, /* Line-in pin */
46 PATH_DEV_MAX,
47 };
48
AudioPathSelGetConfToJsonObj()49 int32_t AudioPathSelGetConfToJsonObj()
50 {
51 FILE *fpJson = NULL;
52 char *pJsonStr = NULL;
53 if (g_cJsonObj != NULL) {
54 return HDF_SUCCESS;
55 }
56 fpJson = fopen(CJSONFILE_CONFIG_PATH, "r");
57 if (fpJson == NULL) {
58 LOG_FUN_ERR("parse.json file fail!");
59 return HDF_FAILURE;
60 }
61 if (fseek(fpJson, 0, SEEK_END) != HDF_SUCCESS) {
62 LOG_FUN_ERR("fseek fail!");
63 fclose(fpJson);
64 return HDF_FAILURE;
65 }
66 int32_t jsonStrSize = ftell(fpJson);
67 rewind(fpJson);
68 if (jsonStrSize <= 0) {
69 fclose(fpJson);
70 return HDF_FAILURE;
71 }
72 pJsonStr = (char *)calloc(1, jsonStrSize + 1);
73 if (pJsonStr == NULL) {
74 fclose(fpJson);
75 return HDF_FAILURE;
76 }
77 if (fread(pJsonStr, jsonStrSize, 1, fpJson) != 1) {
78 LOG_FUN_ERR("read to file fail!");
79 fclose(fpJson);
80 fpJson = NULL;
81 AudioMemFree((void **)&pJsonStr);
82 return HDF_FAILURE;
83 }
84 fclose(fpJson);
85 fpJson = NULL;
86 #ifndef JSON_UNPRINT
87 LOG_PARA_INFO("pJsonStr = %s", pJsonStr);
88 #endif
89 g_cJsonObj = cJSON_Parse(pJsonStr);
90 if (g_cJsonObj == NULL) {
91 LOG_FUN_ERR("cJSON_GetErrorPtr() = %s", cJSON_GetErrorPtr());
92 AudioMemFree((void **)&pJsonStr);
93 return HDF_FAILURE;
94 }
95 AudioMemFree((void **)&pJsonStr);
96 return HDF_SUCCESS;
97 }
98
AudioPathSelGetDeviceType(enum AudioPortPin pins)99 static const char *AudioPathSelGetDeviceType(enum AudioPortPin pins)
100 {
101 if (pins < PATH_DEV_NONE || pins > PATH_DEV_MAX) {
102 return NULL;
103 }
104 switch (pins) {
105 case PATH_DEV_OUT_SPEAKER:
106 return SPEAKER;
107 case PATH_DEV_OUT_HEADSET:
108 return HEADPHONES;
109 case PATH_DEV_IN_MIC:
110 return MIC;
111 case PATH_DEV_IN_HS_MIC:
112 return HS_MIC;
113 default:
114 LOG_FUN_ERR("UseCase not support!");
115 break;
116 }
117 return NULL;
118 }
119
AudioPathSelGetUseCase(enum AudioCategory type)120 const char *AudioPathSelGetUseCase(enum AudioCategory type)
121 {
122 static const char *usecaseType[PATH_USE_TYPE_MAX + 1] = {
123 [PATH_USE_IN_MEDIA] = "deep-buffer-playback",
124 [PATH_USE_IN_COMMUNICATION] = "low-latency-playback",
125 [PATH_USE_TYPE_MAX] = "none",
126 };
127
128 if (type < 0 || type > PATH_USE_TYPE_MAX) {
129 return NULL;
130 }
131 return usecaseType[type];
132 }
133
AudioPathSelGetPlanRenderScene(struct AudioHwRenderParam * renderSceneParam)134 static int32_t AudioPathSelGetPlanRenderScene(struct AudioHwRenderParam *renderSceneParam)
135 {
136 LOG_FUN_INFO();
137 int32_t ret;
138 if (renderSceneParam == NULL) {
139 LOG_FUN_ERR("AudioPathSelGetPlanRenderScene param Is NULL");
140 return HDF_FAILURE;
141 }
142 char pathName[PATH_NAME_LEN] = {0};
143 enum AudioPortPin pins = renderSceneParam->renderMode.hwInfo.deviceDescript.pins;
144 if (pins >= PATH_DEV_MAX || pins < PATH_DEV_NONE) {
145 LOG_FUN_ERR("deviceDescript pins error!");
146 return HDF_FAILURE;
147 }
148 enum AudioCategory type = renderSceneParam->frameRenderMode.attrs.type;
149 const char *useCase = AudioPathSelGetUseCase(type);
150 const char *deviceType = AudioPathSelGetDeviceType(pins);
151 if (useCase == NULL || deviceType == NULL) {
152 LOG_FUN_ERR("pins or type not support!");
153 return HDF_FAILURE;
154 }
155 if (snprintf_s(pathName, sizeof(pathName), sizeof(pathName) - 1, "%s %s", useCase, deviceType) < 0) {
156 LOG_FUN_ERR("snprintf_s Invalid!");
157 return HDF_FAILURE;
158 }
159 if (g_cJsonObj == NULL) {
160 LOG_FUN_ERR("g_cJsonObj is NULL!");
161 return HDF_FAILURE;
162 }
163 cJSON *pathNode = cJSON_GetObjectItem(g_cJsonObj, pathName);
164 if (pathNode == NULL) {
165 LOG_FUN_ERR("Get Object Invalid!");
166 return HDF_ERR_NOT_SUPPORT;
167 }
168 cJSON *deviceNode = cJSON_GetObjectItem(g_cJsonObj, deviceType);
169 if (deviceNode == NULL) {
170 LOG_FUN_ERR("Get Object Invalid!");
171 return HDF_ERR_NOT_SUPPORT;
172 }
173 ret = strncpy_s(renderSceneParam->renderMode.hwInfo.pathSelect.useCase,
174 NAME_LEN - 1, useCase, strlen(useCase) + 1);
175 if (ret != 0) {
176 LOG_FUN_ERR("strncpy_s failed!");
177 return HDF_FAILURE;
178 }
179 ret = strncpy_s(renderSceneParam->renderMode.hwInfo.pathSelect.deviceInfo.deviceType,
180 NAME_LEN - 1, deviceType, strlen(deviceType) + 1);
181 if (ret != 0) {
182 LOG_FUN_ERR("strncpy_s failed!");
183 return HDF_FAILURE;
184 }
185 return HDF_SUCCESS;
186 }
187
AudioPathSelGetPlanCaptureScene(struct AudioHwCaptureParam * captureSceneParam)188 static int32_t AudioPathSelGetPlanCaptureScene(struct AudioHwCaptureParam *captureSceneParam)
189 {
190 LOG_FUN_INFO();
191 int32_t ret;
192 if (captureSceneParam == NULL) {
193 LOG_FUN_ERR("AudioPathSelGetPlanCaptureScene param Is NULL");
194 return HDF_FAILURE;
195 }
196 char pathName[PATH_NAME_LEN] = {0};
197 enum AudioPortPin pins = captureSceneParam->captureMode.hwInfo.deviceDescript.pins;
198 if (pins >= PATH_DEV_MAX || pins < PATH_DEV_MID) {
199 LOG_FUN_ERR("deviceDescript pins error!");
200 return HDF_FAILURE;
201 }
202 enum AudioCategory type = captureSceneParam->frameCaptureMode.attrs.type;
203 const char *useCase = AudioPathSelGetUseCase(type);
204 const char *deviceType = AudioPathSelGetDeviceType(pins);
205 if (useCase == NULL || deviceType == NULL) {
206 LOG_FUN_ERR("pins or type not support!");
207 return HDF_FAILURE;
208 }
209 if (snprintf_s(pathName, sizeof(pathName), sizeof(pathName) - 1, "%s %s", useCase, deviceType) < 0) {
210 LOG_FUN_ERR("snprintf_s failed!");
211 return HDF_FAILURE;
212 }
213 if (g_cJsonObj == NULL) {
214 LOG_FUN_ERR("g_cJsonObj is NULL!");
215 return HDF_FAILURE;
216 }
217 cJSON *pathNode = cJSON_GetObjectItem(g_cJsonObj, pathName);
218 if (pathNode == NULL) {
219 LOG_FUN_ERR("Get Object Fail!");
220 return HDF_ERR_NOT_SUPPORT;
221 }
222 cJSON *deviceNode = cJSON_GetObjectItem(g_cJsonObj, deviceType);
223 if (deviceNode == NULL) {
224 LOG_FUN_ERR("Get Object Fail!");
225 return HDF_ERR_NOT_SUPPORT;
226 }
227 ret = strncpy_s(captureSceneParam->captureMode.hwInfo.pathSelect.useCase,
228 NAME_LEN - 1, useCase, strlen(useCase) + 1);
229 if (ret != 0) {
230 LOG_FUN_ERR("strncpy_s failed!");
231 return HDF_FAILURE;
232 }
233 ret = strncpy_s(captureSceneParam->captureMode.hwInfo.pathSelect.deviceInfo.deviceType,
234 NAME_LEN - 1, deviceType, strlen(deviceType) + 1);
235 if (ret != 0) {
236 LOG_FUN_ERR("strncpy_s failed!");
237 return HDF_FAILURE;
238 }
239 return HDF_SUCCESS;
240 }
241
242
AudioCapturePathSelGetUsecaseDevice(struct AudioHwCaptureParam * captureParam,const char * pathName)243 static int32_t AudioCapturePathSelGetUsecaseDevice(struct AudioHwCaptureParam *captureParam, const char *pathName)
244 {
245 if (captureParam == NULL || pathName == NULL || g_cJsonObj == NULL) {
246 LOG_FUN_ERR("AudioCapturePathSelGetUsecaseDevice param Is NULL");
247 return HDF_FAILURE;
248 }
249 int32_t pathIndex = 0;
250 char *pathKey = NULL;
251 int32_t ret;
252 cJSON *pathNode = cJSON_GetObjectItem(g_cJsonObj, pathName);
253 if (pathNode == NULL) {
254 LOG_FUN_ERR("AudioCapturePathSel Get Object Fail!");
255 return HDF_FAILURE;
256 }
257 cJSON *pathList = pathNode->child;
258 if (pathList == NULL) {
259 LOG_FUN_ERR("AudioCapturePathSel Get pathList Fail!");
260 return HDF_FAILURE;
261 }
262 while (pathList != NULL) {
263 cJSON *device = cJSON_GetObjectItem(pathList, "name");
264 if (device == NULL) {
265 LOG_FUN_ERR("Get Object Invalid!");
266 return HDF_FAILURE;
267 }
268 pathKey = device->valuestring;
269 if (pathKey == NULL) {
270 pathList = pathList->next;
271 continue;
272 }
273 device = cJSON_GetObjectItem(pathList, "value");
274 if (device == NULL) {
275 return HDF_FAILURE;
276 }
277 captureParam->captureMode.hwInfo.pathSelect.pathPlan[pathIndex].value = device->valueint;
278 ret = strncpy_s(captureParam->captureMode.hwInfo.pathSelect.pathPlan[pathIndex].pathPlanName,
279 PATHPLAN_LEN - 1, pathKey, strlen(pathKey) + 1);
280 if (ret != 0) {
281 LOG_FUN_ERR("strncpy_s failed!");
282 return HDF_FAILURE;
283 }
284 pathList = pathList->next;
285 pathIndex++;
286 }
287 if (pathIndex >= PATHPLAN_COUNT || pathIndex < 0) {
288 LOG_FUN_ERR("AudioCapturePathSel Get Object Fail!");
289 return HDF_FAILURE;
290 }
291 captureParam->captureMode.hwInfo.pathSelect.useCaseDeviceNum = pathIndex;
292 return HDF_SUCCESS;
293 }
294
AudioCapturePathSelGetDeviceSplit(struct AudioHwCaptureParam * captureParam,cJSON * deviceList)295 static int32_t AudioCapturePathSelGetDeviceSplit(struct AudioHwCaptureParam *captureParam, cJSON *deviceList)
296 {
297 LOG_FUN_INFO();
298 int32_t decIndex = 0;
299 char *decKey = NULL;
300 int32_t decValue;
301 int32_t ret;
302 cJSON *devObj = NULL;
303 if (captureParam == NULL || deviceList == NULL) {
304 LOG_FUN_ERR("param Is NULL");
305 return HDF_FAILURE;
306 }
307 while (deviceList != NULL) {
308 devObj = cJSON_GetObjectItem(deviceList, "name");
309 if (devObj == NULL) {
310 LOG_FUN_ERR("Get Object Fail!");
311 return HDF_FAILURE;
312 }
313 decKey = devObj->valuestring;
314 if (decKey == NULL) {
315 deviceList = deviceList->next;
316 continue;
317 }
318 devObj = cJSON_GetObjectItem(deviceList, "value");
319 if (devObj == NULL) {
320 return HDF_FAILURE;
321 }
322 decValue = devObj->valueint;
323 captureParam->captureMode.hwInfo.pathSelect.deviceInfo.deviceSwitchs[decIndex].value = decValue;
324 ret = strncpy_s(captureParam->captureMode.hwInfo.pathSelect.deviceInfo.deviceSwitchs[decIndex].deviceSwitch,
325 PATHPLAN_LEN - 1, decKey, strlen(decKey) + 1);
326 if (ret != 0) {
327 LOG_FUN_ERR("strncpy_s failed!");
328 return HDF_FAILURE;
329 }
330 deviceList = deviceList->next;
331 decIndex++;
332 }
333 if (decIndex >= PATHPLAN_COUNT || decIndex < 0) {
334 LOG_FUN_ERR("Get Object Fail!");
335 return HDF_FAILURE;
336 }
337 captureParam->captureMode.hwInfo.pathSelect.deviceInfo.deviceNum = decIndex;
338 return HDF_SUCCESS;
339 }
340
AudioCapturePathSelGetDevice(struct AudioHwCaptureParam * captureParam,const char * deviceType)341 static int32_t AudioCapturePathSelGetDevice(struct AudioHwCaptureParam *captureParam, const char *deviceType)
342 {
343 LOG_FUN_INFO();
344 if (captureParam == NULL || deviceType == NULL || g_cJsonObj == NULL) {
345 LOG_FUN_ERR("AudioCapturePathSelGetUsecaseDevice param Is NULL");
346 return HDF_FAILURE;
347 }
348 cJSON *deviceNode = cJSON_GetObjectItem(g_cJsonObj, deviceType);
349 if (deviceNode == NULL) {
350 LOG_FUN_ERR("Get deviceType Fail!");
351 return HDF_FAILURE;
352 }
353 cJSON *deviceList = deviceNode->child;
354 if (deviceList == NULL) {
355 LOG_FUN_ERR("Get deviceList Fail!");
356 return HDF_FAILURE;
357 }
358 if (AudioCapturePathSelGetDeviceSplit(captureParam, deviceList) < 0) {
359 LOG_FUN_ERR("AudioCapturePathSelGetDeviceSplit Fail!");
360 return HDF_FAILURE;
361 }
362 return HDF_SUCCESS;
363 }
364
AudioPathSelGetPlanCapture(struct AudioHwCaptureParam * captureParam)365 static int32_t AudioPathSelGetPlanCapture(struct AudioHwCaptureParam *captureParam)
366 {
367 LOG_FUN_INFO();
368 int32_t ret;
369 if (captureParam == NULL) {
370 LOG_FUN_ERR("AudioPathSelGetPlanCapture param Is NULL");
371 return HDF_FAILURE;
372 }
373 char pathName[PATH_NAME_LEN] = {0};
374 enum AudioPortPin pins = captureParam->captureMode.hwInfo.deviceDescript.pins;
375 if (pins <= PATH_DEV_MID) {
376 LOG_FUN_ERR("deviceDescript pins error!");
377 return HDF_FAILURE;
378 }
379 enum AudioCategory type = captureParam->frameCaptureMode.attrs.type;
380 const char *useCase = AudioPathSelGetUseCase(type);
381 const char *deviceType = AudioPathSelGetDeviceType(pins);
382 if (useCase == NULL || deviceType == NULL) {
383 LOG_FUN_ERR("pins or type not support!");
384 return HDF_FAILURE;
385 }
386 ret = strncpy_s(captureParam->captureMode.hwInfo.pathSelect.useCase,
387 NAME_LEN - 1, useCase, strlen(useCase) + 1);
388 if (ret != 0) {
389 LOG_FUN_ERR("strncpy_s failed!");
390 return HDF_FAILURE;
391 }
392 ret = strncpy_s(captureParam->captureMode.hwInfo.pathSelect.deviceInfo.deviceType,
393 NAME_LEN - 1, deviceType, strlen(deviceType) + 1);
394 if (ret != 0) {
395 LOG_FUN_ERR("strncpy_s failed!");
396 return HDF_FAILURE;
397 }
398 if (snprintf_s(pathName, sizeof(pathName), sizeof(pathName) - 1, "%s %s", useCase, deviceType) < 0) {
399 LOG_FUN_ERR("snprintf_s failed!");
400 return HDF_FAILURE;
401 }
402 if (AudioCapturePathSelGetUsecaseDevice(captureParam, pathName) < 0) {
403 LOG_FUN_ERR("AudioCapturePathSelGetUsecaseDevice failed!");
404 return HDF_FAILURE;
405 }
406 if (AudioCapturePathSelGetDevice(captureParam, deviceType) < 0) {
407 LOG_FUN_ERR("AudioCapturePathSelGetDevice failed!");
408 return HDF_FAILURE;
409 }
410 return HDF_SUCCESS;
411 }
412
AudioRenderPathSelGetUsecaseDevice(struct AudioHwRenderParam * renderParam,const char * pathName)413 static int32_t AudioRenderPathSelGetUsecaseDevice(struct AudioHwRenderParam *renderParam, const char *pathName)
414 {
415 if (renderParam == NULL || pathName == NULL || g_cJsonObj == NULL) {
416 LOG_FUN_ERR("AudioPathSelGetUsecaseDevice param Is NULL");
417 return HDF_FAILURE;
418 }
419 int32_t pathIndex = 0;
420 char *pathKey = NULL;
421 int32_t ret;
422 cJSON *pathNode = cJSON_GetObjectItem(g_cJsonObj, pathName);
423 if (pathNode == NULL) {
424 LOG_FUN_ERR("AudioRenderPathSel Get Object Fail!");
425 return HDF_FAILURE;
426 }
427 cJSON *pathList = pathNode->child;
428 if (pathList == NULL) {
429 LOG_FUN_ERR("AudioRenderPathSel Get pathList Fail!");
430 return HDF_FAILURE;
431 }
432 while (pathList != NULL) {
433 cJSON *device = cJSON_GetObjectItem(pathList, "name");
434 if (device == NULL) {
435 LOG_FUN_ERR("Get Object Fail!");
436 return HDF_FAILURE;
437 }
438 pathKey = device->valuestring;
439 if (pathKey == NULL) {
440 pathList = pathList->next;
441 continue;
442 }
443 device = cJSON_GetObjectItem(pathList, "value");
444 if (device == NULL) {
445 return HDF_FAILURE;
446 }
447 renderParam->renderMode.hwInfo.pathSelect.pathPlan[pathIndex].value = device->valueint;
448 ret = strncpy_s(renderParam->renderMode.hwInfo.pathSelect.pathPlan[pathIndex].pathPlanName,
449 PATHPLAN_LEN - 1, pathKey, strlen(pathKey));
450 if (ret != 0) {
451 LOG_FUN_ERR("strncpy_s is Fail!");
452 return HDF_FAILURE;
453 }
454 pathList = pathList->next;
455 pathIndex++;
456 }
457 if (pathIndex >= PATHPLAN_COUNT || pathIndex < 0) {
458 LOG_FUN_ERR("AudioRenderPathSel Get Object Fail!");
459 return HDF_FAILURE;
460 }
461 renderParam->renderMode.hwInfo.pathSelect.useCaseDeviceNum = pathIndex;
462 return HDF_SUCCESS;
463 }
464
AudioRenderPathSelGetDevice(struct AudioHwRenderParam * renderParam,const char * deviceType)465 static int32_t AudioRenderPathSelGetDevice(struct AudioHwRenderParam *renderParam, const char *deviceType)
466 {
467 if (renderParam == NULL || deviceType == NULL || g_cJsonObj == NULL) {
468 LOG_FUN_ERR("AudioPathSelGetDevice param Is NULL");
469 return HDF_FAILURE;
470 }
471 char *decKey = NULL;
472 int32_t decIndex = 0;
473 int32_t ret;
474 cJSON *deviceNode = cJSON_GetObjectItem(g_cJsonObj, deviceType);
475 if (deviceNode == NULL) {
476 LOG_FUN_ERR("Get Object Fail!");
477 return HDF_FAILURE;
478 }
479 cJSON *deviceList = deviceNode->child;
480 if (deviceList == NULL) {
481 LOG_FUN_ERR("deviceList is NULL!");
482 return HDF_FAILURE;
483 }
484 while (deviceList != NULL) {
485 cJSON *device = cJSON_GetObjectItem(deviceList, "name");
486 if (device == NULL) {
487 LOG_FUN_ERR("Get Object Invalid!");
488 return HDF_FAILURE;
489 }
490 decKey = device->valuestring;
491 if (decKey == NULL) {
492 deviceList = deviceList->next;
493 continue;
494 }
495 device = cJSON_GetObjectItem(deviceList, "value");
496 if (device == NULL) {
497 return HDF_FAILURE;
498 }
499 renderParam->renderMode.hwInfo.pathSelect.deviceInfo.deviceSwitchs[decIndex].value = device->valueint;
500 ret = strncpy_s(renderParam->renderMode.hwInfo.pathSelect.deviceInfo.deviceSwitchs[decIndex].deviceSwitch,
501 PATHPLAN_LEN - 1, decKey, strlen(decKey) + 1);
502 if (ret != 0) {
503 LOG_FUN_ERR("strncpy_s is Fail!");
504 return HDF_FAILURE;
505 }
506 deviceList = deviceList->next;
507 decIndex++;
508 }
509 if (decIndex >= PATHPLAN_COUNT || decIndex < 0) {
510 LOG_FUN_ERR("Get Object Fail!");
511 return HDF_FAILURE;
512 }
513 renderParam->renderMode.hwInfo.pathSelect.deviceInfo.deviceNum = decIndex;
514 return HDF_SUCCESS;
515 }
516
AudioPathSelGetPlanRender(struct AudioHwRenderParam * renderParam)517 static int32_t AudioPathSelGetPlanRender(struct AudioHwRenderParam *renderParam)
518 {
519 LOG_FUN_INFO();
520 int32_t ret;
521 if (renderParam == NULL) {
522 LOG_FUN_ERR("AudioPathSelGetPlanRender param Is NULL");
523 return HDF_FAILURE;
524 }
525 char pathName[PATH_NAME_LEN] = {0};
526 enum AudioPortPin pins = renderParam->renderMode.hwInfo.deviceDescript.pins;
527 if (pins >= PATH_DEV_MID) {
528 LOG_FUN_ERR("deviceDescript pins error!");
529 return HDF_FAILURE;
530 }
531 enum AudioCategory type = renderParam->frameRenderMode.attrs.type;
532 const char *useCase = AudioPathSelGetUseCase(type);
533 const char *deviceType = AudioPathSelGetDeviceType(pins);
534 if (useCase == NULL || deviceType == NULL) {
535 LOG_FUN_ERR("pins or type not support!");
536 return HDF_FAILURE;
537 }
538 ret = strncpy_s(renderParam->renderMode.hwInfo.pathSelect.useCase,
539 NAME_LEN - 1, useCase, strlen(useCase) + 1);
540 if (ret != 0) {
541 LOG_FUN_ERR("strncpy_s is Fail!");
542 return HDF_FAILURE;
543 }
544 ret = strncpy_s(renderParam->renderMode.hwInfo.pathSelect.deviceInfo.deviceType,
545 NAME_LEN - 1, deviceType, strlen(deviceType) + 1);
546 if (ret != 0) {
547 LOG_FUN_ERR("strncpy_s is Fail!");
548 return HDF_FAILURE;
549 }
550 if (snprintf_s(pathName, sizeof(pathName), sizeof(pathName) - 1, "%s %s", useCase, deviceType) < 0) {
551 LOG_FUN_ERR("snprintf_s failed!");
552 return HDF_FAILURE;
553 }
554 if (AudioRenderPathSelGetUsecaseDevice(renderParam, pathName) < 0) {
555 LOG_FUN_ERR("AudioRenderPathSelGetUsecaseDevice failed!");
556 return HDF_FAILURE;
557 }
558 if (AudioRenderPathSelGetDevice(renderParam, deviceType) < 0) {
559 LOG_FUN_ERR("AudioRenderPathSelGetDevice failed!");
560 return HDF_FAILURE;
561 }
562 return HDF_SUCCESS;
563 }
564
AudioPathSelAnalysisJson(const AudioHandle adapterParam,enum AudioAdaptType adaptType)565 int32_t AudioPathSelAnalysisJson(const AudioHandle adapterParam, enum AudioAdaptType adaptType)
566 {
567 LOG_FUN_INFO();
568 if (adaptType < 0 || adapterParam == NULL) {
569 LOG_FUN_ERR("Param Invaild!");
570 return HDF_FAILURE;
571 }
572 struct AudioHwRenderParam *renderParam = NULL;
573 struct AudioHwCaptureParam *captureParam = NULL;
574 struct AudioHwRenderParam *renderSceneCheck = NULL;
575 struct AudioHwCaptureParam *captureScenceCheck = NULL;
576 switch (adaptType) {
577 case RENDER_PATH_SELECT:
578 renderParam = (struct AudioHwRenderParam *)adapterParam;
579 return (AudioPathSelGetPlanRender(renderParam));
580 case CAPTURE_PATH_SELECT:
581 captureParam = (struct AudioHwCaptureParam *)adapterParam;
582 return (AudioPathSelGetPlanCapture(captureParam));
583 /* Scene is surport */
584 case CHECKSCENE_PATH_SELECT:
585 renderSceneCheck = (struct AudioHwRenderParam *)adapterParam;
586 return (AudioPathSelGetPlanRenderScene(renderSceneCheck));
587 case CHECKSCENE_PATH_SELECT_CAPTURE:
588 captureScenceCheck = (struct AudioHwCaptureParam *)adapterParam;
589 return (AudioPathSelGetPlanCaptureScene(captureScenceCheck));
590 default:
591 LOG_FUN_ERR("Path select mode invaild");
592 break;
593 }
594 return HDF_FAILURE;
595 }
596
597