xref: /aosp_15_r20/hardware/libhardware_legacy/audio/audio_hw_hal.cpp (revision 79330504eb3d14022296e3b041867f86289dd52c)
1*79330504STreehugger Robot /*
2*79330504STreehugger Robot  * Copyright (C) 2011 The Android Open Source Project
3*79330504STreehugger Robot  *
4*79330504STreehugger Robot  * Licensed under the Apache License, Version 2.0 (the "License");
5*79330504STreehugger Robot  * you may not use this file except in compliance with the License.
6*79330504STreehugger Robot  * You may obtain a copy of the License at
7*79330504STreehugger Robot  *
8*79330504STreehugger Robot  *      http://www.apache.org/licenses/LICENSE-2.0
9*79330504STreehugger Robot  *
10*79330504STreehugger Robot  * Unless required by applicable law or agreed to in writing, software
11*79330504STreehugger Robot  * distributed under the License is distributed on an "AS IS" BASIS,
12*79330504STreehugger Robot  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*79330504STreehugger Robot  * See the License for the specific language governing permissions and
14*79330504STreehugger Robot  * limitations under the License.
15*79330504STreehugger Robot  */
16*79330504STreehugger Robot 
17*79330504STreehugger Robot #define LOG_TAG "legacy_audio_hw_hal"
18*79330504STreehugger Robot //#define LOG_NDEBUG 0
19*79330504STreehugger Robot 
20*79330504STreehugger Robot #include <stdint.h>
21*79330504STreehugger Robot 
22*79330504STreehugger Robot #include <hardware/hardware.h>
23*79330504STreehugger Robot #include <system/audio.h>
24*79330504STreehugger Robot #include <hardware/audio.h>
25*79330504STreehugger Robot 
26*79330504STreehugger Robot #include <hardware_legacy/AudioHardwareInterface.h>
27*79330504STreehugger Robot #include <hardware_legacy/AudioSystemLegacy.h>
28*79330504STreehugger Robot 
29*79330504STreehugger Robot namespace android_audio_legacy {
30*79330504STreehugger Robot 
31*79330504STreehugger Robot class AudioHardwareInterface;
32*79330504STreehugger Robot 
33*79330504STreehugger Robot extern "C" {
34*79330504STreehugger Robot 
35*79330504STreehugger Robot struct legacy_audio_module {
36*79330504STreehugger Robot     struct audio_module module;
37*79330504STreehugger Robot };
38*79330504STreehugger Robot 
39*79330504STreehugger Robot struct legacy_audio_device {
40*79330504STreehugger Robot     struct audio_hw_device device;
41*79330504STreehugger Robot 
42*79330504STreehugger Robot     AudioHardwareInterface *hwif;
43*79330504STreehugger Robot };
44*79330504STreehugger Robot 
45*79330504STreehugger Robot struct legacy_stream_out {
46*79330504STreehugger Robot     struct audio_stream_out stream;
47*79330504STreehugger Robot 
48*79330504STreehugger Robot     AudioStreamOut *legacy_out;
49*79330504STreehugger Robot };
50*79330504STreehugger Robot 
51*79330504STreehugger Robot struct legacy_stream_in {
52*79330504STreehugger Robot     struct audio_stream_in stream;
53*79330504STreehugger Robot 
54*79330504STreehugger Robot     AudioStreamIn *legacy_in;
55*79330504STreehugger Robot };
56*79330504STreehugger Robot 
57*79330504STreehugger Robot 
58*79330504STreehugger Robot enum {
59*79330504STreehugger Robot     HAL_API_REV_1_0,
60*79330504STreehugger Robot     HAL_API_REV_2_0,
61*79330504STreehugger Robot     HAL_API_REV_NUM
62*79330504STreehugger Robot } hal_api_rev;
63*79330504STreehugger Robot 
64*79330504STreehugger Robot static uint32_t audio_device_conv_table[][HAL_API_REV_NUM] =
65*79330504STreehugger Robot {
66*79330504STreehugger Robot     /* output devices */
67*79330504STreehugger Robot     { AudioSystem::DEVICE_OUT_EARPIECE, AUDIO_DEVICE_OUT_EARPIECE },
68*79330504STreehugger Robot     { AudioSystem::DEVICE_OUT_SPEAKER, AUDIO_DEVICE_OUT_SPEAKER },
69*79330504STreehugger Robot     { AudioSystem::DEVICE_OUT_WIRED_HEADSET, AUDIO_DEVICE_OUT_WIRED_HEADSET },
70*79330504STreehugger Robot     { AudioSystem::DEVICE_OUT_WIRED_HEADPHONE, AUDIO_DEVICE_OUT_WIRED_HEADPHONE },
71*79330504STreehugger Robot     { AudioSystem::DEVICE_OUT_BLUETOOTH_SCO, AUDIO_DEVICE_OUT_BLUETOOTH_SCO },
72*79330504STreehugger Robot     { AudioSystem::DEVICE_OUT_BLUETOOTH_SCO_HEADSET, AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET },
73*79330504STreehugger Robot     { AudioSystem::DEVICE_OUT_BLUETOOTH_SCO_CARKIT, AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT },
74*79330504STreehugger Robot     { AudioSystem::DEVICE_OUT_BLUETOOTH_A2DP, AUDIO_DEVICE_OUT_BLUETOOTH_A2DP },
75*79330504STreehugger Robot     { AudioSystem::DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES, AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES },
76*79330504STreehugger Robot     { AudioSystem::DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER, AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER },
77*79330504STreehugger Robot     { AudioSystem::DEVICE_OUT_AUX_DIGITAL, AUDIO_DEVICE_OUT_AUX_DIGITAL },
78*79330504STreehugger Robot     { AudioSystem::DEVICE_OUT_ANLG_DOCK_HEADSET, AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET },
79*79330504STreehugger Robot     { AudioSystem::DEVICE_OUT_DGTL_DOCK_HEADSET, AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET },
80*79330504STreehugger Robot     { AudioSystem::DEVICE_OUT_DEFAULT, AUDIO_DEVICE_OUT_DEFAULT },
81*79330504STreehugger Robot     /* input devices */
82*79330504STreehugger Robot     { AudioSystem::DEVICE_IN_COMMUNICATION, AUDIO_DEVICE_IN_COMMUNICATION },
83*79330504STreehugger Robot     { AudioSystem::DEVICE_IN_AMBIENT, AUDIO_DEVICE_IN_AMBIENT },
84*79330504STreehugger Robot     { AudioSystem::DEVICE_IN_BUILTIN_MIC, AUDIO_DEVICE_IN_BUILTIN_MIC },
85*79330504STreehugger Robot     { AudioSystem::DEVICE_IN_BLUETOOTH_SCO_HEADSET, AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET },
86*79330504STreehugger Robot     { AudioSystem::DEVICE_IN_WIRED_HEADSET, AUDIO_DEVICE_IN_WIRED_HEADSET },
87*79330504STreehugger Robot     { AudioSystem::DEVICE_IN_AUX_DIGITAL, AUDIO_DEVICE_IN_AUX_DIGITAL },
88*79330504STreehugger Robot     { AudioSystem::DEVICE_IN_VOICE_CALL, AUDIO_DEVICE_IN_VOICE_CALL },
89*79330504STreehugger Robot     { AudioSystem::DEVICE_IN_BACK_MIC, AUDIO_DEVICE_IN_BACK_MIC },
90*79330504STreehugger Robot     { AudioSystem::DEVICE_IN_DEFAULT, AUDIO_DEVICE_IN_DEFAULT },
91*79330504STreehugger Robot };
92*79330504STreehugger Robot 
convert_audio_device(uint32_t from_device,int from_rev,int to_rev)93*79330504STreehugger Robot static audio_devices_t convert_audio_device(uint32_t from_device, int from_rev, int to_rev)
94*79330504STreehugger Robot {
95*79330504STreehugger Robot     const uint32_t k_num_devices = sizeof(audio_device_conv_table)/sizeof(uint32_t)/HAL_API_REV_NUM;
96*79330504STreehugger Robot     audio_devices_t to_device = AUDIO_DEVICE_NONE;
97*79330504STreehugger Robot     uint32_t in_bit = 0;
98*79330504STreehugger Robot 
99*79330504STreehugger Robot     if (from_rev != HAL_API_REV_1_0) {
100*79330504STreehugger Robot         in_bit = from_device & AUDIO_DEVICE_BIT_IN;
101*79330504STreehugger Robot         from_device &= ~AUDIO_DEVICE_BIT_IN;
102*79330504STreehugger Robot     }
103*79330504STreehugger Robot 
104*79330504STreehugger Robot     while (from_device) {
105*79330504STreehugger Robot         uint32_t i = 31 - __builtin_clz(from_device);
106*79330504STreehugger Robot         uint32_t cur_device = (1 << i) | in_bit;
107*79330504STreehugger Robot 
108*79330504STreehugger Robot         for (i = 0; i < k_num_devices; i++) {
109*79330504STreehugger Robot             if (audio_device_conv_table[i][from_rev] == cur_device) {
110*79330504STreehugger Robot                 to_device = (audio_devices_t)(to_device | audio_device_conv_table[i][to_rev]);
111*79330504STreehugger Robot                 break;
112*79330504STreehugger Robot             }
113*79330504STreehugger Robot         }
114*79330504STreehugger Robot         from_device &= ~cur_device;
115*79330504STreehugger Robot     }
116*79330504STreehugger Robot     return to_device;
117*79330504STreehugger Robot }
118*79330504STreehugger Robot 
119*79330504STreehugger Robot 
120*79330504STreehugger Robot /** audio_stream_out implementation **/
out_get_sample_rate(const struct audio_stream * stream)121*79330504STreehugger Robot static uint32_t out_get_sample_rate(const struct audio_stream *stream)
122*79330504STreehugger Robot {
123*79330504STreehugger Robot     const struct legacy_stream_out *out =
124*79330504STreehugger Robot         reinterpret_cast<const struct legacy_stream_out *>(stream);
125*79330504STreehugger Robot     return out->legacy_out->sampleRate();
126*79330504STreehugger Robot }
127*79330504STreehugger Robot 
out_set_sample_rate(struct audio_stream * stream,uint32_t rate)128*79330504STreehugger Robot static int out_set_sample_rate(struct audio_stream *stream, uint32_t rate)
129*79330504STreehugger Robot {
130*79330504STreehugger Robot     struct legacy_stream_out *out =
131*79330504STreehugger Robot         reinterpret_cast<struct legacy_stream_out *>(stream);
132*79330504STreehugger Robot 
133*79330504STreehugger Robot     ALOGE("(%s:%d) %s: Implement me!", __FILE__, __LINE__, __func__);
134*79330504STreehugger Robot     /* TODO: implement this */
135*79330504STreehugger Robot     return 0;
136*79330504STreehugger Robot }
137*79330504STreehugger Robot 
out_get_buffer_size(const struct audio_stream * stream)138*79330504STreehugger Robot static size_t out_get_buffer_size(const struct audio_stream *stream)
139*79330504STreehugger Robot {
140*79330504STreehugger Robot     const struct legacy_stream_out *out =
141*79330504STreehugger Robot         reinterpret_cast<const struct legacy_stream_out *>(stream);
142*79330504STreehugger Robot     return out->legacy_out->bufferSize();
143*79330504STreehugger Robot }
144*79330504STreehugger Robot 
out_get_channels(const struct audio_stream * stream)145*79330504STreehugger Robot static audio_channel_mask_t out_get_channels(const struct audio_stream *stream)
146*79330504STreehugger Robot {
147*79330504STreehugger Robot     const struct legacy_stream_out *out =
148*79330504STreehugger Robot         reinterpret_cast<const struct legacy_stream_out *>(stream);
149*79330504STreehugger Robot     return (audio_channel_mask_t) out->legacy_out->channels();
150*79330504STreehugger Robot }
151*79330504STreehugger Robot 
out_get_format(const struct audio_stream * stream)152*79330504STreehugger Robot static audio_format_t out_get_format(const struct audio_stream *stream)
153*79330504STreehugger Robot {
154*79330504STreehugger Robot     const struct legacy_stream_out *out =
155*79330504STreehugger Robot         reinterpret_cast<const struct legacy_stream_out *>(stream);
156*79330504STreehugger Robot     // legacy API, don't change return type
157*79330504STreehugger Robot     return (audio_format_t) out->legacy_out->format();
158*79330504STreehugger Robot }
159*79330504STreehugger Robot 
out_set_format(struct audio_stream * stream,audio_format_t format)160*79330504STreehugger Robot static int out_set_format(struct audio_stream *stream, audio_format_t format)
161*79330504STreehugger Robot {
162*79330504STreehugger Robot     struct legacy_stream_out *out =
163*79330504STreehugger Robot         reinterpret_cast<struct legacy_stream_out *>(stream);
164*79330504STreehugger Robot     ALOGE("(%s:%d) %s: Implement me!", __FILE__, __LINE__, __func__);
165*79330504STreehugger Robot     /* TODO: implement me */
166*79330504STreehugger Robot     return 0;
167*79330504STreehugger Robot }
168*79330504STreehugger Robot 
out_standby(struct audio_stream * stream)169*79330504STreehugger Robot static int out_standby(struct audio_stream *stream)
170*79330504STreehugger Robot {
171*79330504STreehugger Robot     struct legacy_stream_out *out =
172*79330504STreehugger Robot         reinterpret_cast<struct legacy_stream_out *>(stream);
173*79330504STreehugger Robot     return out->legacy_out->standby();
174*79330504STreehugger Robot }
175*79330504STreehugger Robot 
out_dump(const struct audio_stream * stream,int fd)176*79330504STreehugger Robot static int out_dump(const struct audio_stream *stream, int fd)
177*79330504STreehugger Robot {
178*79330504STreehugger Robot     const struct legacy_stream_out *out =
179*79330504STreehugger Robot         reinterpret_cast<const struct legacy_stream_out *>(stream);
180*79330504STreehugger Robot     Vector<String16> args;
181*79330504STreehugger Robot     return out->legacy_out->dump(fd, args);
182*79330504STreehugger Robot }
183*79330504STreehugger Robot 
out_set_parameters(struct audio_stream * stream,const char * kvpairs)184*79330504STreehugger Robot static int out_set_parameters(struct audio_stream *stream, const char *kvpairs)
185*79330504STreehugger Robot {
186*79330504STreehugger Robot     struct legacy_stream_out *out =
187*79330504STreehugger Robot         reinterpret_cast<struct legacy_stream_out *>(stream);
188*79330504STreehugger Robot     int val;
189*79330504STreehugger Robot     String8 s8 = String8(kvpairs);
190*79330504STreehugger Robot     AudioParameter parms = AudioParameter(String8(kvpairs));
191*79330504STreehugger Robot 
192*79330504STreehugger Robot     if (parms.getInt(String8(AUDIO_PARAMETER_STREAM_ROUTING), val) == NO_ERROR) {
193*79330504STreehugger Robot         val = convert_audio_device(val, HAL_API_REV_2_0, HAL_API_REV_1_0);
194*79330504STreehugger Robot         parms.remove(String8(AUDIO_PARAMETER_STREAM_ROUTING));
195*79330504STreehugger Robot         parms.addInt(String8(AUDIO_PARAMETER_STREAM_ROUTING), val);
196*79330504STreehugger Robot         s8 = parms.toString();
197*79330504STreehugger Robot     }
198*79330504STreehugger Robot 
199*79330504STreehugger Robot     return out->legacy_out->setParameters(s8);
200*79330504STreehugger Robot }
201*79330504STreehugger Robot 
out_get_parameters(const struct audio_stream * stream,const char * keys)202*79330504STreehugger Robot static char * out_get_parameters(const struct audio_stream *stream, const char *keys)
203*79330504STreehugger Robot {
204*79330504STreehugger Robot     const struct legacy_stream_out *out =
205*79330504STreehugger Robot         reinterpret_cast<const struct legacy_stream_out *>(stream);
206*79330504STreehugger Robot     String8 s8;
207*79330504STreehugger Robot     int val;
208*79330504STreehugger Robot 
209*79330504STreehugger Robot     s8 = out->legacy_out->getParameters(String8(keys));
210*79330504STreehugger Robot 
211*79330504STreehugger Robot     AudioParameter parms = AudioParameter(s8);
212*79330504STreehugger Robot     if (parms.getInt(String8(AUDIO_PARAMETER_STREAM_ROUTING), val) == NO_ERROR) {
213*79330504STreehugger Robot         val = convert_audio_device(val, HAL_API_REV_1_0, HAL_API_REV_2_0);
214*79330504STreehugger Robot         parms.remove(String8(AUDIO_PARAMETER_STREAM_ROUTING));
215*79330504STreehugger Robot         parms.addInt(String8(AUDIO_PARAMETER_STREAM_ROUTING), val);
216*79330504STreehugger Robot         s8 = parms.toString();
217*79330504STreehugger Robot     }
218*79330504STreehugger Robot 
219*79330504STreehugger Robot     return strdup(s8.c_str());
220*79330504STreehugger Robot }
221*79330504STreehugger Robot 
out_get_latency(const struct audio_stream_out * stream)222*79330504STreehugger Robot static uint32_t out_get_latency(const struct audio_stream_out *stream)
223*79330504STreehugger Robot {
224*79330504STreehugger Robot     const struct legacy_stream_out *out =
225*79330504STreehugger Robot         reinterpret_cast<const struct legacy_stream_out *>(stream);
226*79330504STreehugger Robot     return out->legacy_out->latency();
227*79330504STreehugger Robot }
228*79330504STreehugger Robot 
out_set_volume(struct audio_stream_out * stream,float left,float right)229*79330504STreehugger Robot static int out_set_volume(struct audio_stream_out *stream, float left,
230*79330504STreehugger Robot                           float right)
231*79330504STreehugger Robot {
232*79330504STreehugger Robot     struct legacy_stream_out *out =
233*79330504STreehugger Robot         reinterpret_cast<struct legacy_stream_out *>(stream);
234*79330504STreehugger Robot     return out->legacy_out->setVolume(left, right);
235*79330504STreehugger Robot }
236*79330504STreehugger Robot 
out_write(struct audio_stream_out * stream,const void * buffer,size_t bytes)237*79330504STreehugger Robot static ssize_t out_write(struct audio_stream_out *stream, const void* buffer,
238*79330504STreehugger Robot                          size_t bytes)
239*79330504STreehugger Robot {
240*79330504STreehugger Robot     struct legacy_stream_out *out =
241*79330504STreehugger Robot         reinterpret_cast<struct legacy_stream_out *>(stream);
242*79330504STreehugger Robot     return out->legacy_out->write(buffer, bytes);
243*79330504STreehugger Robot }
244*79330504STreehugger Robot 
out_get_render_position(const struct audio_stream_out * stream,uint32_t * dsp_frames)245*79330504STreehugger Robot static int out_get_render_position(const struct audio_stream_out *stream,
246*79330504STreehugger Robot                                    uint32_t *dsp_frames)
247*79330504STreehugger Robot {
248*79330504STreehugger Robot     const struct legacy_stream_out *out =
249*79330504STreehugger Robot         reinterpret_cast<const struct legacy_stream_out *>(stream);
250*79330504STreehugger Robot     return out->legacy_out->getRenderPosition(dsp_frames);
251*79330504STreehugger Robot }
252*79330504STreehugger Robot 
out_get_next_write_timestamp(const struct audio_stream_out * stream,int64_t * timestamp)253*79330504STreehugger Robot static int out_get_next_write_timestamp(const struct audio_stream_out *stream,
254*79330504STreehugger Robot                                         int64_t *timestamp)
255*79330504STreehugger Robot {
256*79330504STreehugger Robot     const struct legacy_stream_out *out =
257*79330504STreehugger Robot         reinterpret_cast<const struct legacy_stream_out *>(stream);
258*79330504STreehugger Robot     return out->legacy_out->getNextWriteTimestamp(timestamp);
259*79330504STreehugger Robot }
260*79330504STreehugger Robot 
out_add_audio_effect(const struct audio_stream * stream,effect_handle_t effect)261*79330504STreehugger Robot static int out_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
262*79330504STreehugger Robot {
263*79330504STreehugger Robot     return 0;
264*79330504STreehugger Robot }
265*79330504STreehugger Robot 
out_remove_audio_effect(const struct audio_stream * stream,effect_handle_t effect)266*79330504STreehugger Robot static int out_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
267*79330504STreehugger Robot {
268*79330504STreehugger Robot     return 0;
269*79330504STreehugger Robot }
270*79330504STreehugger Robot 
271*79330504STreehugger Robot /** audio_stream_in implementation **/
in_get_sample_rate(const struct audio_stream * stream)272*79330504STreehugger Robot static uint32_t in_get_sample_rate(const struct audio_stream *stream)
273*79330504STreehugger Robot {
274*79330504STreehugger Robot     const struct legacy_stream_in *in =
275*79330504STreehugger Robot         reinterpret_cast<const struct legacy_stream_in *>(stream);
276*79330504STreehugger Robot     return in->legacy_in->sampleRate();
277*79330504STreehugger Robot }
278*79330504STreehugger Robot 
in_set_sample_rate(struct audio_stream * stream,uint32_t rate)279*79330504STreehugger Robot static int in_set_sample_rate(struct audio_stream *stream, uint32_t rate)
280*79330504STreehugger Robot {
281*79330504STreehugger Robot     struct legacy_stream_in *in =
282*79330504STreehugger Robot         reinterpret_cast<struct legacy_stream_in *>(stream);
283*79330504STreehugger Robot 
284*79330504STreehugger Robot     ALOGE("(%s:%d) %s: Implement me!", __FILE__, __LINE__, __func__);
285*79330504STreehugger Robot     /* TODO: implement this */
286*79330504STreehugger Robot     return 0;
287*79330504STreehugger Robot }
288*79330504STreehugger Robot 
in_get_buffer_size(const struct audio_stream * stream)289*79330504STreehugger Robot static size_t in_get_buffer_size(const struct audio_stream *stream)
290*79330504STreehugger Robot {
291*79330504STreehugger Robot     const struct legacy_stream_in *in =
292*79330504STreehugger Robot         reinterpret_cast<const struct legacy_stream_in *>(stream);
293*79330504STreehugger Robot     return in->legacy_in->bufferSize();
294*79330504STreehugger Robot }
295*79330504STreehugger Robot 
in_get_channels(const struct audio_stream * stream)296*79330504STreehugger Robot static audio_channel_mask_t in_get_channels(const struct audio_stream *stream)
297*79330504STreehugger Robot {
298*79330504STreehugger Robot     const struct legacy_stream_in *in =
299*79330504STreehugger Robot         reinterpret_cast<const struct legacy_stream_in *>(stream);
300*79330504STreehugger Robot     return (audio_channel_mask_t) in->legacy_in->channels();
301*79330504STreehugger Robot }
302*79330504STreehugger Robot 
in_get_format(const struct audio_stream * stream)303*79330504STreehugger Robot static audio_format_t in_get_format(const struct audio_stream *stream)
304*79330504STreehugger Robot {
305*79330504STreehugger Robot     const struct legacy_stream_in *in =
306*79330504STreehugger Robot         reinterpret_cast<const struct legacy_stream_in *>(stream);
307*79330504STreehugger Robot     // legacy API, don't change return type
308*79330504STreehugger Robot     return (audio_format_t) in->legacy_in->format();
309*79330504STreehugger Robot }
310*79330504STreehugger Robot 
in_set_format(struct audio_stream * stream,audio_format_t format)311*79330504STreehugger Robot static int in_set_format(struct audio_stream *stream, audio_format_t format)
312*79330504STreehugger Robot {
313*79330504STreehugger Robot     struct legacy_stream_in *in =
314*79330504STreehugger Robot         reinterpret_cast<struct legacy_stream_in *>(stream);
315*79330504STreehugger Robot     ALOGE("(%s:%d) %s: Implement me!", __FILE__, __LINE__, __func__);
316*79330504STreehugger Robot     /* TODO: implement me */
317*79330504STreehugger Robot     return 0;
318*79330504STreehugger Robot }
319*79330504STreehugger Robot 
in_standby(struct audio_stream * stream)320*79330504STreehugger Robot static int in_standby(struct audio_stream *stream)
321*79330504STreehugger Robot {
322*79330504STreehugger Robot     struct legacy_stream_in *in = reinterpret_cast<struct legacy_stream_in *>(stream);
323*79330504STreehugger Robot     return in->legacy_in->standby();
324*79330504STreehugger Robot }
325*79330504STreehugger Robot 
in_dump(const struct audio_stream * stream,int fd)326*79330504STreehugger Robot static int in_dump(const struct audio_stream *stream, int fd)
327*79330504STreehugger Robot {
328*79330504STreehugger Robot     const struct legacy_stream_in *in =
329*79330504STreehugger Robot         reinterpret_cast<const struct legacy_stream_in *>(stream);
330*79330504STreehugger Robot     Vector<String16> args;
331*79330504STreehugger Robot     return in->legacy_in->dump(fd, args);
332*79330504STreehugger Robot }
333*79330504STreehugger Robot 
in_set_parameters(struct audio_stream * stream,const char * kvpairs)334*79330504STreehugger Robot static int in_set_parameters(struct audio_stream *stream, const char *kvpairs)
335*79330504STreehugger Robot {
336*79330504STreehugger Robot     struct legacy_stream_in *in =
337*79330504STreehugger Robot         reinterpret_cast<struct legacy_stream_in *>(stream);
338*79330504STreehugger Robot     int val;
339*79330504STreehugger Robot     AudioParameter parms = AudioParameter(String8(kvpairs));
340*79330504STreehugger Robot     String8 s8 = String8(kvpairs);
341*79330504STreehugger Robot 
342*79330504STreehugger Robot     if (parms.getInt(String8(AUDIO_PARAMETER_STREAM_ROUTING), val) == NO_ERROR) {
343*79330504STreehugger Robot         val = convert_audio_device(val, HAL_API_REV_2_0, HAL_API_REV_1_0);
344*79330504STreehugger Robot         parms.remove(String8(AUDIO_PARAMETER_STREAM_ROUTING));
345*79330504STreehugger Robot         parms.addInt(String8(AUDIO_PARAMETER_STREAM_ROUTING), val);
346*79330504STreehugger Robot         s8 = parms.toString();
347*79330504STreehugger Robot     }
348*79330504STreehugger Robot 
349*79330504STreehugger Robot     return in->legacy_in->setParameters(s8);
350*79330504STreehugger Robot }
351*79330504STreehugger Robot 
in_get_parameters(const struct audio_stream * stream,const char * keys)352*79330504STreehugger Robot static char * in_get_parameters(const struct audio_stream *stream,
353*79330504STreehugger Robot                                 const char *keys)
354*79330504STreehugger Robot {
355*79330504STreehugger Robot     const struct legacy_stream_in *in =
356*79330504STreehugger Robot         reinterpret_cast<const struct legacy_stream_in *>(stream);
357*79330504STreehugger Robot     String8 s8;
358*79330504STreehugger Robot     int val;
359*79330504STreehugger Robot 
360*79330504STreehugger Robot     s8 = in->legacy_in->getParameters(String8(keys));
361*79330504STreehugger Robot 
362*79330504STreehugger Robot     AudioParameter parms = AudioParameter(s8);
363*79330504STreehugger Robot     if (parms.getInt(String8(AUDIO_PARAMETER_STREAM_ROUTING), val) == NO_ERROR) {
364*79330504STreehugger Robot         val = convert_audio_device(val, HAL_API_REV_1_0, HAL_API_REV_2_0);
365*79330504STreehugger Robot         parms.remove(String8(AUDIO_PARAMETER_STREAM_ROUTING));
366*79330504STreehugger Robot         parms.addInt(String8(AUDIO_PARAMETER_STREAM_ROUTING), val);
367*79330504STreehugger Robot         s8 = parms.toString();
368*79330504STreehugger Robot     }
369*79330504STreehugger Robot 
370*79330504STreehugger Robot     return strdup(s8.c_str());
371*79330504STreehugger Robot }
372*79330504STreehugger Robot 
in_set_gain(struct audio_stream_in * stream,float gain)373*79330504STreehugger Robot static int in_set_gain(struct audio_stream_in *stream, float gain)
374*79330504STreehugger Robot {
375*79330504STreehugger Robot     struct legacy_stream_in *in =
376*79330504STreehugger Robot         reinterpret_cast<struct legacy_stream_in *>(stream);
377*79330504STreehugger Robot     return in->legacy_in->setGain(gain);
378*79330504STreehugger Robot }
379*79330504STreehugger Robot 
in_read(struct audio_stream_in * stream,void * buffer,size_t bytes)380*79330504STreehugger Robot static ssize_t in_read(struct audio_stream_in *stream, void* buffer,
381*79330504STreehugger Robot                        size_t bytes)
382*79330504STreehugger Robot {
383*79330504STreehugger Robot     struct legacy_stream_in *in =
384*79330504STreehugger Robot         reinterpret_cast<struct legacy_stream_in *>(stream);
385*79330504STreehugger Robot     return in->legacy_in->read(buffer, bytes);
386*79330504STreehugger Robot }
387*79330504STreehugger Robot 
in_get_input_frames_lost(struct audio_stream_in * stream)388*79330504STreehugger Robot static uint32_t in_get_input_frames_lost(struct audio_stream_in *stream)
389*79330504STreehugger Robot {
390*79330504STreehugger Robot     struct legacy_stream_in *in =
391*79330504STreehugger Robot         reinterpret_cast<struct legacy_stream_in *>(stream);
392*79330504STreehugger Robot     return in->legacy_in->getInputFramesLost();
393*79330504STreehugger Robot }
394*79330504STreehugger Robot 
in_add_audio_effect(const struct audio_stream * stream,effect_handle_t effect)395*79330504STreehugger Robot static int in_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
396*79330504STreehugger Robot {
397*79330504STreehugger Robot     const struct legacy_stream_in *in =
398*79330504STreehugger Robot         reinterpret_cast<const struct legacy_stream_in *>(stream);
399*79330504STreehugger Robot     return in->legacy_in->addAudioEffect(effect);
400*79330504STreehugger Robot }
401*79330504STreehugger Robot 
in_remove_audio_effect(const struct audio_stream * stream,effect_handle_t effect)402*79330504STreehugger Robot static int in_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
403*79330504STreehugger Robot {
404*79330504STreehugger Robot     const struct legacy_stream_in *in =
405*79330504STreehugger Robot         reinterpret_cast<const struct legacy_stream_in *>(stream);
406*79330504STreehugger Robot     return in->legacy_in->removeAudioEffect(effect);
407*79330504STreehugger Robot }
408*79330504STreehugger Robot 
409*79330504STreehugger Robot /** audio_hw_device implementation **/
to_ladev(struct audio_hw_device * dev)410*79330504STreehugger Robot static inline struct legacy_audio_device * to_ladev(struct audio_hw_device *dev)
411*79330504STreehugger Robot {
412*79330504STreehugger Robot     return reinterpret_cast<struct legacy_audio_device *>(dev);
413*79330504STreehugger Robot }
414*79330504STreehugger Robot 
to_cladev(const struct audio_hw_device * dev)415*79330504STreehugger Robot static inline const struct legacy_audio_device * to_cladev(const struct audio_hw_device *dev)
416*79330504STreehugger Robot {
417*79330504STreehugger Robot     return reinterpret_cast<const struct legacy_audio_device *>(dev);
418*79330504STreehugger Robot }
419*79330504STreehugger Robot 
adev_init_check(const struct audio_hw_device * dev)420*79330504STreehugger Robot static int adev_init_check(const struct audio_hw_device *dev)
421*79330504STreehugger Robot {
422*79330504STreehugger Robot     const struct legacy_audio_device *ladev = to_cladev(dev);
423*79330504STreehugger Robot 
424*79330504STreehugger Robot     return ladev->hwif->initCheck();
425*79330504STreehugger Robot }
426*79330504STreehugger Robot 
adev_set_voice_volume(struct audio_hw_device * dev,float volume)427*79330504STreehugger Robot static int adev_set_voice_volume(struct audio_hw_device *dev, float volume)
428*79330504STreehugger Robot {
429*79330504STreehugger Robot     struct legacy_audio_device *ladev = to_ladev(dev);
430*79330504STreehugger Robot     return ladev->hwif->setVoiceVolume(volume);
431*79330504STreehugger Robot }
432*79330504STreehugger Robot 
adev_set_master_volume(struct audio_hw_device * dev,float volume)433*79330504STreehugger Robot static int adev_set_master_volume(struct audio_hw_device *dev, float volume)
434*79330504STreehugger Robot {
435*79330504STreehugger Robot     struct legacy_audio_device *ladev = to_ladev(dev);
436*79330504STreehugger Robot     return ladev->hwif->setMasterVolume(volume);
437*79330504STreehugger Robot }
438*79330504STreehugger Robot 
adev_get_master_volume(struct audio_hw_device * dev,float * volume)439*79330504STreehugger Robot static int adev_get_master_volume(struct audio_hw_device *dev, float* volume)
440*79330504STreehugger Robot {
441*79330504STreehugger Robot     struct legacy_audio_device *ladev = to_ladev(dev);
442*79330504STreehugger Robot     return ladev->hwif->getMasterVolume(volume);
443*79330504STreehugger Robot }
444*79330504STreehugger Robot 
adev_set_mode(struct audio_hw_device * dev,audio_mode_t mode)445*79330504STreehugger Robot static int adev_set_mode(struct audio_hw_device *dev, audio_mode_t mode)
446*79330504STreehugger Robot {
447*79330504STreehugger Robot     struct legacy_audio_device *ladev = to_ladev(dev);
448*79330504STreehugger Robot     // as this is the legacy API, don't change it to use audio_mode_t instead of int
449*79330504STreehugger Robot     return ladev->hwif->setMode((int) mode);
450*79330504STreehugger Robot }
451*79330504STreehugger Robot 
adev_set_mic_mute(struct audio_hw_device * dev,bool state)452*79330504STreehugger Robot static int adev_set_mic_mute(struct audio_hw_device *dev, bool state)
453*79330504STreehugger Robot {
454*79330504STreehugger Robot     struct legacy_audio_device *ladev = to_ladev(dev);
455*79330504STreehugger Robot     return ladev->hwif->setMicMute(state);
456*79330504STreehugger Robot }
457*79330504STreehugger Robot 
adev_get_mic_mute(const struct audio_hw_device * dev,bool * state)458*79330504STreehugger Robot static int adev_get_mic_mute(const struct audio_hw_device *dev, bool *state)
459*79330504STreehugger Robot {
460*79330504STreehugger Robot     const struct legacy_audio_device *ladev = to_cladev(dev);
461*79330504STreehugger Robot     return ladev->hwif->getMicMute(state);
462*79330504STreehugger Robot }
463*79330504STreehugger Robot 
adev_set_parameters(struct audio_hw_device * dev,const char * kvpairs)464*79330504STreehugger Robot static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs)
465*79330504STreehugger Robot {
466*79330504STreehugger Robot     struct legacy_audio_device *ladev = to_ladev(dev);
467*79330504STreehugger Robot     return ladev->hwif->setParameters(String8(kvpairs));
468*79330504STreehugger Robot }
469*79330504STreehugger Robot 
adev_get_parameters(const struct audio_hw_device * dev,const char * keys)470*79330504STreehugger Robot static char * adev_get_parameters(const struct audio_hw_device *dev,
471*79330504STreehugger Robot                                   const char *keys)
472*79330504STreehugger Robot {
473*79330504STreehugger Robot     const struct legacy_audio_device *ladev = to_cladev(dev);
474*79330504STreehugger Robot     String8 s8;
475*79330504STreehugger Robot 
476*79330504STreehugger Robot     s8 = ladev->hwif->getParameters(String8(keys));
477*79330504STreehugger Robot     return strdup(s8.c_str());
478*79330504STreehugger Robot }
479*79330504STreehugger Robot 
adev_get_input_buffer_size(const struct audio_hw_device * dev,const struct audio_config * config)480*79330504STreehugger Robot static size_t adev_get_input_buffer_size(const struct audio_hw_device *dev,
481*79330504STreehugger Robot                                          const struct audio_config *config)
482*79330504STreehugger Robot {
483*79330504STreehugger Robot     const struct legacy_audio_device *ladev = to_cladev(dev);
484*79330504STreehugger Robot     return ladev->hwif->getInputBufferSize(config->sample_rate, (int) config->format,
485*79330504STreehugger Robot                                            audio_channel_count_from_in_mask(config->channel_mask));
486*79330504STreehugger Robot }
487*79330504STreehugger Robot 
adev_open_output_stream(struct audio_hw_device * dev,audio_io_handle_t handle,audio_devices_t devices,audio_output_flags_t flags,struct audio_config * config,struct audio_stream_out ** stream_out,const char * address __unused)488*79330504STreehugger Robot static int adev_open_output_stream(struct audio_hw_device *dev,
489*79330504STreehugger Robot                                    audio_io_handle_t handle,
490*79330504STreehugger Robot                                    audio_devices_t devices,
491*79330504STreehugger Robot                                    audio_output_flags_t flags,
492*79330504STreehugger Robot                                    struct audio_config *config,
493*79330504STreehugger Robot                                    struct audio_stream_out **stream_out,
494*79330504STreehugger Robot                                    const char *address __unused)
495*79330504STreehugger Robot {
496*79330504STreehugger Robot     struct legacy_audio_device *ladev = to_ladev(dev);
497*79330504STreehugger Robot     status_t status;
498*79330504STreehugger Robot     struct legacy_stream_out *out;
499*79330504STreehugger Robot     int ret;
500*79330504STreehugger Robot 
501*79330504STreehugger Robot     out = (struct legacy_stream_out *)calloc(1, sizeof(*out));
502*79330504STreehugger Robot     if (!out)
503*79330504STreehugger Robot         return -ENOMEM;
504*79330504STreehugger Robot 
505*79330504STreehugger Robot     devices = convert_audio_device(devices, HAL_API_REV_2_0, HAL_API_REV_1_0);
506*79330504STreehugger Robot 
507*79330504STreehugger Robot     uint32_t raw_channel_mask = config->channel_mask;
508*79330504STreehugger Robot     out->legacy_out = ladev->hwif->openOutputStreamWithFlags(devices, flags,
509*79330504STreehugger Robot                                                     (int *) &config->format,
510*79330504STreehugger Robot                                                     &raw_channel_mask,
511*79330504STreehugger Robot                                                     &config->sample_rate, &status);
512*79330504STreehugger Robot     if (!out->legacy_out) {
513*79330504STreehugger Robot         ret = status;
514*79330504STreehugger Robot         goto err_open;
515*79330504STreehugger Robot     }
516*79330504STreehugger Robot     config->channel_mask = (audio_channel_mask_t)raw_channel_mask;
517*79330504STreehugger Robot 
518*79330504STreehugger Robot     out->stream.common.get_sample_rate = out_get_sample_rate;
519*79330504STreehugger Robot     out->stream.common.set_sample_rate = out_set_sample_rate;
520*79330504STreehugger Robot     out->stream.common.get_buffer_size = out_get_buffer_size;
521*79330504STreehugger Robot     out->stream.common.get_channels = out_get_channels;
522*79330504STreehugger Robot     out->stream.common.get_format = out_get_format;
523*79330504STreehugger Robot     out->stream.common.set_format = out_set_format;
524*79330504STreehugger Robot     out->stream.common.standby = out_standby;
525*79330504STreehugger Robot     out->stream.common.dump = out_dump;
526*79330504STreehugger Robot     out->stream.common.set_parameters = out_set_parameters;
527*79330504STreehugger Robot     out->stream.common.get_parameters = out_get_parameters;
528*79330504STreehugger Robot     out->stream.common.add_audio_effect = out_add_audio_effect;
529*79330504STreehugger Robot     out->stream.common.remove_audio_effect = out_remove_audio_effect;
530*79330504STreehugger Robot     out->stream.get_latency = out_get_latency;
531*79330504STreehugger Robot     out->stream.set_volume = out_set_volume;
532*79330504STreehugger Robot     out->stream.write = out_write;
533*79330504STreehugger Robot     out->stream.get_render_position = out_get_render_position;
534*79330504STreehugger Robot     out->stream.get_next_write_timestamp = out_get_next_write_timestamp;
535*79330504STreehugger Robot 
536*79330504STreehugger Robot     *stream_out = &out->stream;
537*79330504STreehugger Robot     return 0;
538*79330504STreehugger Robot 
539*79330504STreehugger Robot err_open:
540*79330504STreehugger Robot     free(out);
541*79330504STreehugger Robot     *stream_out = NULL;
542*79330504STreehugger Robot     return ret;
543*79330504STreehugger Robot }
544*79330504STreehugger Robot 
adev_close_output_stream(struct audio_hw_device * dev,struct audio_stream_out * stream)545*79330504STreehugger Robot static void adev_close_output_stream(struct audio_hw_device *dev,
546*79330504STreehugger Robot                                      struct audio_stream_out* stream)
547*79330504STreehugger Robot {
548*79330504STreehugger Robot     struct legacy_audio_device *ladev = to_ladev(dev);
549*79330504STreehugger Robot     struct legacy_stream_out *out = reinterpret_cast<struct legacy_stream_out *>(stream);
550*79330504STreehugger Robot 
551*79330504STreehugger Robot     ladev->hwif->closeOutputStream(out->legacy_out);
552*79330504STreehugger Robot     free(out);
553*79330504STreehugger Robot }
554*79330504STreehugger Robot 
555*79330504STreehugger Robot /** This method creates and opens the audio hardware input stream */
adev_open_input_stream(struct audio_hw_device * dev,audio_io_handle_t handle,audio_devices_t devices,struct audio_config * config,struct audio_stream_in ** stream_in,audio_input_flags_t flags __unused,const char * address __unused,audio_source_t source __unused)556*79330504STreehugger Robot static int adev_open_input_stream(struct audio_hw_device *dev,
557*79330504STreehugger Robot                                   audio_io_handle_t handle,
558*79330504STreehugger Robot                                   audio_devices_t devices,
559*79330504STreehugger Robot                                   struct audio_config *config,
560*79330504STreehugger Robot                                   struct audio_stream_in **stream_in,
561*79330504STreehugger Robot                                   audio_input_flags_t flags __unused,
562*79330504STreehugger Robot                                   const char *address __unused,
563*79330504STreehugger Robot                                   audio_source_t source __unused)
564*79330504STreehugger Robot {
565*79330504STreehugger Robot     struct legacy_audio_device *ladev = to_ladev(dev);
566*79330504STreehugger Robot     status_t status;
567*79330504STreehugger Robot     struct legacy_stream_in *in;
568*79330504STreehugger Robot     int ret;
569*79330504STreehugger Robot 
570*79330504STreehugger Robot     in = (struct legacy_stream_in *)calloc(1, sizeof(*in));
571*79330504STreehugger Robot     if (!in)
572*79330504STreehugger Robot         return -ENOMEM;
573*79330504STreehugger Robot 
574*79330504STreehugger Robot     devices = convert_audio_device(devices, HAL_API_REV_2_0, HAL_API_REV_1_0);
575*79330504STreehugger Robot 
576*79330504STreehugger Robot     uint32_t raw_channel_mask = config->channel_mask;
577*79330504STreehugger Robot     in->legacy_in = ladev->hwif->openInputStream(devices, (int *) &config->format,
578*79330504STreehugger Robot                                                  &raw_channel_mask, &config->sample_rate,
579*79330504STreehugger Robot                                                  &status, (AudioSystem::audio_in_acoustics)0);
580*79330504STreehugger Robot     if (!in->legacy_in) {
581*79330504STreehugger Robot         ret = status;
582*79330504STreehugger Robot         goto err_open;
583*79330504STreehugger Robot     }
584*79330504STreehugger Robot     config->channel_mask = (audio_channel_mask_t)raw_channel_mask;
585*79330504STreehugger Robot 
586*79330504STreehugger Robot     in->stream.common.get_sample_rate = in_get_sample_rate;
587*79330504STreehugger Robot     in->stream.common.set_sample_rate = in_set_sample_rate;
588*79330504STreehugger Robot     in->stream.common.get_buffer_size = in_get_buffer_size;
589*79330504STreehugger Robot     in->stream.common.get_channels = in_get_channels;
590*79330504STreehugger Robot     in->stream.common.get_format = in_get_format;
591*79330504STreehugger Robot     in->stream.common.set_format = in_set_format;
592*79330504STreehugger Robot     in->stream.common.standby = in_standby;
593*79330504STreehugger Robot     in->stream.common.dump = in_dump;
594*79330504STreehugger Robot     in->stream.common.set_parameters = in_set_parameters;
595*79330504STreehugger Robot     in->stream.common.get_parameters = in_get_parameters;
596*79330504STreehugger Robot     in->stream.common.add_audio_effect = in_add_audio_effect;
597*79330504STreehugger Robot     in->stream.common.remove_audio_effect = in_remove_audio_effect;
598*79330504STreehugger Robot     in->stream.set_gain = in_set_gain;
599*79330504STreehugger Robot     in->stream.read = in_read;
600*79330504STreehugger Robot     in->stream.get_input_frames_lost = in_get_input_frames_lost;
601*79330504STreehugger Robot 
602*79330504STreehugger Robot     *stream_in = &in->stream;
603*79330504STreehugger Robot     return 0;
604*79330504STreehugger Robot 
605*79330504STreehugger Robot err_open:
606*79330504STreehugger Robot     free(in);
607*79330504STreehugger Robot     *stream_in = NULL;
608*79330504STreehugger Robot     return ret;
609*79330504STreehugger Robot }
610*79330504STreehugger Robot 
adev_close_input_stream(struct audio_hw_device * dev,struct audio_stream_in * stream)611*79330504STreehugger Robot static void adev_close_input_stream(struct audio_hw_device *dev,
612*79330504STreehugger Robot                                struct audio_stream_in *stream)
613*79330504STreehugger Robot {
614*79330504STreehugger Robot     struct legacy_audio_device *ladev = to_ladev(dev);
615*79330504STreehugger Robot     struct legacy_stream_in *in =
616*79330504STreehugger Robot         reinterpret_cast<struct legacy_stream_in *>(stream);
617*79330504STreehugger Robot 
618*79330504STreehugger Robot     ladev->hwif->closeInputStream(in->legacy_in);
619*79330504STreehugger Robot     free(in);
620*79330504STreehugger Robot }
621*79330504STreehugger Robot 
adev_dump(const struct audio_hw_device * dev,int fd)622*79330504STreehugger Robot static int adev_dump(const struct audio_hw_device *dev, int fd)
623*79330504STreehugger Robot {
624*79330504STreehugger Robot     const struct legacy_audio_device *ladev = to_cladev(dev);
625*79330504STreehugger Robot     Vector<String16> args;
626*79330504STreehugger Robot 
627*79330504STreehugger Robot     return ladev->hwif->dumpState(fd, args);
628*79330504STreehugger Robot }
629*79330504STreehugger Robot 
legacy_adev_close(hw_device_t * device)630*79330504STreehugger Robot static int legacy_adev_close(hw_device_t* device)
631*79330504STreehugger Robot {
632*79330504STreehugger Robot     struct audio_hw_device *hwdev =
633*79330504STreehugger Robot                         reinterpret_cast<struct audio_hw_device *>(device);
634*79330504STreehugger Robot     struct legacy_audio_device *ladev = to_ladev(hwdev);
635*79330504STreehugger Robot 
636*79330504STreehugger Robot     if (!ladev)
637*79330504STreehugger Robot         return 0;
638*79330504STreehugger Robot 
639*79330504STreehugger Robot     if (ladev->hwif)
640*79330504STreehugger Robot         delete ladev->hwif;
641*79330504STreehugger Robot 
642*79330504STreehugger Robot     free(ladev);
643*79330504STreehugger Robot     return 0;
644*79330504STreehugger Robot }
645*79330504STreehugger Robot 
legacy_adev_open(const hw_module_t * module,const char * name,hw_device_t ** device)646*79330504STreehugger Robot static int legacy_adev_open(const hw_module_t* module, const char* name,
647*79330504STreehugger Robot                             hw_device_t** device)
648*79330504STreehugger Robot {
649*79330504STreehugger Robot     struct legacy_audio_device *ladev;
650*79330504STreehugger Robot     int ret;
651*79330504STreehugger Robot 
652*79330504STreehugger Robot     if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0)
653*79330504STreehugger Robot         return -EINVAL;
654*79330504STreehugger Robot 
655*79330504STreehugger Robot     ladev = (struct legacy_audio_device *)calloc(1, sizeof(*ladev));
656*79330504STreehugger Robot     if (!ladev)
657*79330504STreehugger Robot         return -ENOMEM;
658*79330504STreehugger Robot 
659*79330504STreehugger Robot     ladev->device.common.tag = HARDWARE_DEVICE_TAG;
660*79330504STreehugger Robot     ladev->device.common.version = AUDIO_DEVICE_API_VERSION_2_0;
661*79330504STreehugger Robot     ladev->device.common.module = const_cast<hw_module_t*>(module);
662*79330504STreehugger Robot     ladev->device.common.close = legacy_adev_close;
663*79330504STreehugger Robot 
664*79330504STreehugger Robot     ladev->device.init_check = adev_init_check;
665*79330504STreehugger Robot     ladev->device.set_voice_volume = adev_set_voice_volume;
666*79330504STreehugger Robot     ladev->device.set_master_volume = adev_set_master_volume;
667*79330504STreehugger Robot     ladev->device.get_master_volume = adev_get_master_volume;
668*79330504STreehugger Robot     ladev->device.set_mode = adev_set_mode;
669*79330504STreehugger Robot     ladev->device.set_mic_mute = adev_set_mic_mute;
670*79330504STreehugger Robot     ladev->device.get_mic_mute = adev_get_mic_mute;
671*79330504STreehugger Robot     ladev->device.set_parameters = adev_set_parameters;
672*79330504STreehugger Robot     ladev->device.get_parameters = adev_get_parameters;
673*79330504STreehugger Robot     ladev->device.get_input_buffer_size = adev_get_input_buffer_size;
674*79330504STreehugger Robot     ladev->device.open_output_stream = adev_open_output_stream;
675*79330504STreehugger Robot     ladev->device.close_output_stream = adev_close_output_stream;
676*79330504STreehugger Robot     ladev->device.open_input_stream = adev_open_input_stream;
677*79330504STreehugger Robot     ladev->device.close_input_stream = adev_close_input_stream;
678*79330504STreehugger Robot     ladev->device.dump = adev_dump;
679*79330504STreehugger Robot 
680*79330504STreehugger Robot     ladev->hwif = createAudioHardware();
681*79330504STreehugger Robot     if (!ladev->hwif) {
682*79330504STreehugger Robot         ret = -EIO;
683*79330504STreehugger Robot         goto err_create_audio_hw;
684*79330504STreehugger Robot     }
685*79330504STreehugger Robot 
686*79330504STreehugger Robot     *device = &ladev->device.common;
687*79330504STreehugger Robot 
688*79330504STreehugger Robot     return 0;
689*79330504STreehugger Robot 
690*79330504STreehugger Robot err_create_audio_hw:
691*79330504STreehugger Robot     free(ladev);
692*79330504STreehugger Robot     return ret;
693*79330504STreehugger Robot }
694*79330504STreehugger Robot 
695*79330504STreehugger Robot static struct hw_module_methods_t legacy_audio_module_methods = {
696*79330504STreehugger Robot         open: legacy_adev_open
697*79330504STreehugger Robot };
698*79330504STreehugger Robot 
699*79330504STreehugger Robot struct legacy_audio_module HAL_MODULE_INFO_SYM = {
700*79330504STreehugger Robot     module: {
701*79330504STreehugger Robot         common: {
702*79330504STreehugger Robot             tag: HARDWARE_MODULE_TAG,
703*79330504STreehugger Robot             module_api_version: AUDIO_MODULE_API_VERSION_0_1,
704*79330504STreehugger Robot             hal_api_version: HARDWARE_HAL_API_VERSION,
705*79330504STreehugger Robot             id: AUDIO_HARDWARE_MODULE_ID,
706*79330504STreehugger Robot             name: "LEGACY Audio HW HAL",
707*79330504STreehugger Robot             author: "The Android Open Source Project",
708*79330504STreehugger Robot             methods: &legacy_audio_module_methods,
709*79330504STreehugger Robot             dso : NULL,
710*79330504STreehugger Robot             reserved : {0},
711*79330504STreehugger Robot         },
712*79330504STreehugger Robot     },
713*79330504STreehugger Robot };
714*79330504STreehugger Robot 
715*79330504STreehugger Robot }; // extern "C"
716*79330504STreehugger Robot 
717*79330504STreehugger Robot }; // namespace android_audio_legacy
718