• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "parameter.h"
16 #include "securec.h"
17 #include "resampleLoader.h"
18 #define LD_ABS_PATH_LEN 80
19 #define PRO_RESAMPLER_NAME_LEN 40
20 #if (defined(__aarch64__) || defined(__x86_64__))
21     const static char *libPath = "/system/lib64/";
22 #else
23     const static char *libPath = "/system/lib/";
24 #endif
LoadProResampler(int (** func_ptr_addr)(pa_resampler * r))25 bool LoadProResampler(int (**func_ptr_addr)(pa_resampler *r))
26 {
27     CHECK_AND_RETURN_RET_LOG(*func_ptr_addr == NULL, true, "ProResampler has already been loaded!");
28 
29     char libProResamplerName[PRO_RESAMPLER_NAME_LEN];
30     char absolutePath[LD_ABS_PATH_LEN] = {0};
31     int ret = GetParameter("const.multimedia.audio.lib_proresampler_name", "-1", libProResamplerName,
32         sizeof(libProResamplerName));
33     CHECK_AND_RETURN_RET_LOG(ret > 0, false, "LoadProResampler GetSysPara fail, use speeX!");
34 
35     ret = strcat_s(absolutePath, LD_ABS_PATH_LEN, libPath);
36     CHECK_AND_RETURN_RET_LOG(ret == 0, false, "LoadProResampler: strcat_s libPath failed!");
37 
38     ret = strcat_s(absolutePath, LD_ABS_PATH_LEN, libProResamplerName);
39     CHECK_AND_RETURN_RET_LOG(ret == 0, false, "LoadProResampler: strcat_s libProResamplerName failed!");
40 
41     AUDIO_INFO_LOG("LoadProResampler: absolutePath is %{public}s", absolutePath);
42 
43     ret = access(absolutePath, F_OK);
44     CHECK_AND_RETURN_RET_LOG(ret == 0, false, "ProResampler does not exist! use SpeeX resampler!");
45 
46     void *handle = dlopen(absolutePath, 1);
47     CHECK_AND_RETURN_RET_LOG(handle != NULL, false, "dlopen lib ProResampler fail!, error: [%{public}s]", dlerror());
48 
49     AUDIO_INFO_LOG("dlopen lib ProResampler successful!");
50 
51     *func_ptr_addr = (int (*)(pa_resampler *r))(dlsym(handle, PRORESAMPLERINIT_SYM_AS_STR));
52     if (*func_ptr_addr == NULL) {
53         AUDIO_ERR_LOG("dlsym lib ProResampler failed! error: [%{public}s]", dlerror());
54         CHECK_AND_RETURN_RET_LOG(dlclose(handle) == 0, false, "dlclose libProResampler fail!, error: [%{public}s]",
55             dlerror());
56         return false;
57     }
58     AUDIO_INFO_LOG("dlsym lib ProResampler success!");
59     return true;
60 }