Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
* Copyright (c) 2016 The CyanogenMod Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define LOG_TAG "audio_amplifier"
#include <log/log.h>
#include <dlfcn.h>
#include <stdbool.h>
#include <stdlib.h>
#include "audio_hw.h"
#include "platform.h"
struct amplifier_data {
struct audio_device* adev;
amplifier_device_t* hw;
};
struct amplifier_data amp;
int amplifier_open(void* adev) {
int rc;
amplifier_module_t* module;
amp.adev = (struct audio_device*)adev;
rc = hw_get_module(AMPLIFIER_HARDWARE_MODULE_ID, (const hw_module_t**)&module);
if (rc) {
ALOGV("%s: Failed to obtain reference to amplifier module: %s\n", __func__, strerror(-rc));
return -ENODEV;
}
rc = amplifier_device_open((const hw_module_t*)module, &.hw);
if (rc) {
ALOGV("%s: Failed to open amplifier hardware device: %s\n", __func__, strerror(-rc));
amp.hw = NULL;
return -ENODEV;
}
if (amp.hw->calibrate) {
rc = amp.hw->calibrate(amp.hw, amp.adev);
if (rc) {
ALOGV("%s: Failed to do amplifier hardware calibration %s\n", __func__, strerror(-rc));
}
}
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
return 0;
}
int amplifier_set_input_devices(uint32_t devices) {
if (amp.hw && amp.hw->set_input_devices) return amp.hw->set_input_devices(amp.hw, devices);
return 0;
}
int amplifier_set_output_devices(uint32_t devices) {
if (amp.hw && amp.hw->set_output_devices) return amp.hw->set_output_devices(amp.hw, devices);
return 0;
}
int amplifier_enable_devices(uint32_t devices, bool enable) {
bool is_output = devices < SND_DEVICE_OUT_END;
if (amp.hw && amp.hw->enable_output_devices && is_output)
return amp.hw->enable_output_devices(amp.hw, devices, enable);
if (amp.hw && amp.hw->enable_input_devices && !is_output)
return amp.hw->enable_input_devices(amp.hw, devices, enable);
return 0;
}
int amplifier_set_mode(audio_mode_t mode) {
if (amp.hw && amp.hw->set_mode) return amp.hw->set_mode(amp.hw, mode);
return 0;
}
int amplifier_output_stream_start(struct audio_stream_out* stream, bool offload) {
if (amp.hw && amp.hw->output_stream_start)
return amp.hw->output_stream_start(amp.hw, stream, offload);
return 0;
}
int amplifier_input_stream_start(struct audio_stream_in* stream) {
if (amp.hw && amp.hw->input_stream_start) return amp.hw->input_stream_start(amp.hw, stream);
return 0;
}
int amplifier_output_stream_standby(struct audio_stream_out* stream) {
if (amp.hw && amp.hw->output_stream_standby)
return amp.hw->output_stream_standby(amp.hw, stream);
return 0;
}
int amplifier_input_stream_standby(struct audio_stream_in* stream) {
if (amp.hw && amp.hw->input_stream_standby) return amp.hw->input_stream_standby(amp.hw, stream);
return 0;
}
int amplifier_set_parameters(struct str_parms* parms) {
if (amp.hw && amp.hw->set_parameters) return amp.hw->set_parameters(amp.hw, parms);
return 0;
}
int amplifier_out_set_parameters(struct str_parms* parms) {
if (amp.hw && amp.hw->out_set_parameters) return amp.hw->out_set_parameters(amp.hw, parms);
return 0;
}
int amplifier_in_set_parameters(struct str_parms* parms) {
if (amp.hw && amp.hw->in_set_parameters) return amp.hw->in_set_parameters(amp.hw, parms);
return 0;
}
int amplifier_set_feedback(void* adev, uint32_t devices, bool enable) {
amp.adev = (struct audio_device*)adev;
if (amp.hw && amp.hw->set_feedback)
return amp.hw->set_feedback(amp.hw, amp.adev, devices, enable);
return 0;
}
int amplifier_close(void) {
if (amp.hw) amplifier_device_close(amp.hw);
amp.hw = NULL;
return 0;
}