• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #define LOG_TAG "audio_hw_extn"
18 /*#define LOG_NDEBUG 0*/
19 #define LOG_NDDEBUG 0
20 
21 #include <stdlib.h>
22 #include <errno.h>
23 #include <dlfcn.h>
24 #include <cutils/properties.h>
25 #include <cutils/log.h>
26 
27 #include "audio_hw.h"
28 #include "audio_extn.h"
29 #include "platform.h"
30 #include "platform_api.h"
31 
32 
33 
34 #ifdef KPI_OPTIMIZE_ENABLED
35 typedef int (*perf_lock_acquire_t)(int, int, int*, int);
36 typedef int (*perf_lock_release_t)(int);
37 
38 static void *qcopt_handle;
39 static perf_lock_acquire_t perf_lock_acq;
40 static perf_lock_release_t perf_lock_rel;
41 
42 static int perf_lock_handle;
43 char opt_lib_path[PROPERTY_VALUE_MAX] = {0};
44 
45 int perf_lock_opts[] = {0x101, 0x20E, 0x30E};
46 
audio_extn_perf_lock_init(void)47 int audio_extn_perf_lock_init(void)
48 {
49     int ret = 0;
50     if (qcopt_handle == NULL) {
51         if (property_get("ro.vendor.extension_library",
52                          opt_lib_path, NULL) <= 0) {
53             ALOGE("%s: Failed getting perf property", __func__);
54             ret = -EINVAL;
55             goto err;
56         }
57         if ((qcopt_handle = dlopen(opt_lib_path, RTLD_NOW)) == NULL) {
58             ALOGE("%s: Failed to open perf handle", __func__);
59             ret = -EINVAL;
60             goto err;
61         } else {
62             perf_lock_acq = (perf_lock_acquire_t)dlsym(qcopt_handle,
63                                                        "perf_lock_acq");
64             if (perf_lock_acq == NULL) {
65                 ALOGE("%s: Perf lock Acquire NULL", __func__);
66                 ret = -EINVAL;
67                 goto err;
68             }
69             perf_lock_rel = (perf_lock_release_t)dlsym(qcopt_handle,
70                                                        "perf_lock_rel");
71             if (perf_lock_rel == NULL) {
72                 ALOGE("%s: Perf lock Release NULL", __func__);
73                 ret = -EINVAL;
74                 goto err;
75             }
76             ALOGD("%s: Perf lock handles Success", __func__);
77         }
78     }
79 err:
80     return ret;
81 }
82 
audio_extn_perf_lock_acquire(void)83 void audio_extn_perf_lock_acquire(void)
84 {
85     if (perf_lock_acq) {
86         perf_lock_handle = perf_lock_acq(perf_lock_handle, 0, perf_lock_opts, 3);
87         ALOGV("%s: Perf lock acquired", __func__);
88     } else {
89         ALOGE("%s: Perf lock acquire error", __func__);
90     }
91 }
92 
audio_extn_perf_lock_release(void)93 void audio_extn_perf_lock_release(void)
94 {
95     if (perf_lock_rel && perf_lock_handle) {
96         perf_lock_rel(perf_lock_handle);
97         perf_lock_handle = 0;
98         ALOGV("%s: Perf lock released", __func__);
99     } else {
100         ALOGE("%s: Perf lock release error", __func__);
101     }
102 }
103 #endif /* KPI_OPTIMIZE_ENABLED */
104