blob: dfbb6b2698f2dc75912048de6dddcc8044ad14e3 [file] [log] [blame]
Kevin Rocard4bcd67f2018-02-28 14:33:38 -08001/*
2 * Copyright (C) 2016 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 "DeviceHalLocal"
18//#define LOG_NDEBUG 0
19
20#include <utils/Log.h>
21
22#include "DeviceHalLocal.h"
23#include "StreamHalLocal.h"
24
25namespace android {
Kevin Rocard070e7512018-05-22 09:29:13 -070026namespace CPP_VERSION {
Kevin Rocard4bcd67f2018-02-28 14:33:38 -080027
28DeviceHalLocal::DeviceHalLocal(audio_hw_device_t *dev)
29 : mDev(dev) {
30}
31
32DeviceHalLocal::~DeviceHalLocal() {
33 int status = audio_hw_device_close(mDev);
34 ALOGW_IF(status, "Error closing audio hw device %p: %s", mDev, strerror(-status));
35 mDev = 0;
36}
37
38status_t DeviceHalLocal::getSupportedDevices(uint32_t *devices) {
39 if (mDev->get_supported_devices == NULL) return INVALID_OPERATION;
40 *devices = mDev->get_supported_devices(mDev);
41 return OK;
42}
43
44status_t DeviceHalLocal::initCheck() {
45 return mDev->init_check(mDev);
46}
47
48status_t DeviceHalLocal::setVoiceVolume(float volume) {
49 return mDev->set_voice_volume(mDev, volume);
50}
51
52status_t DeviceHalLocal::setMasterVolume(float volume) {
53 if (mDev->set_master_volume == NULL) return INVALID_OPERATION;
54 return mDev->set_master_volume(mDev, volume);
55}
56
57status_t DeviceHalLocal::getMasterVolume(float *volume) {
58 if (mDev->get_master_volume == NULL) return INVALID_OPERATION;
59 return mDev->get_master_volume(mDev, volume);
60}
61
62status_t DeviceHalLocal::setMode(audio_mode_t mode) {
63 return mDev->set_mode(mDev, mode);
64}
65
66status_t DeviceHalLocal::setMicMute(bool state) {
67 return mDev->set_mic_mute(mDev, state);
68}
69
70status_t DeviceHalLocal::getMicMute(bool *state) {
71 return mDev->get_mic_mute(mDev, state);
72}
73
74status_t DeviceHalLocal::setMasterMute(bool state) {
75 if (mDev->set_master_mute == NULL) return INVALID_OPERATION;
76 return mDev->set_master_mute(mDev, state);
77}
78
79status_t DeviceHalLocal::getMasterMute(bool *state) {
80 if (mDev->get_master_mute == NULL) return INVALID_OPERATION;
81 return mDev->get_master_mute(mDev, state);
82}
83
84status_t DeviceHalLocal::setParameters(const String8& kvPairs) {
85 return mDev->set_parameters(mDev, kvPairs.string());
86}
87
88status_t DeviceHalLocal::getParameters(const String8& keys, String8 *values) {
89 char *halValues = mDev->get_parameters(mDev, keys.string());
90 if (halValues != NULL) {
91 values->setTo(halValues);
92 free(halValues);
93 } else {
94 values->clear();
95 }
96 return OK;
97}
98
99status_t DeviceHalLocal::getInputBufferSize(
100 const struct audio_config *config, size_t *size) {
101 *size = mDev->get_input_buffer_size(mDev, config);
102 return OK;
103}
104
105status_t DeviceHalLocal::openOutputStream(
106 audio_io_handle_t handle,
jiabinc0106832019-10-24 14:58:31 -0700107 audio_devices_t deviceType,
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800108 audio_output_flags_t flags,
109 struct audio_config *config,
110 const char *address,
111 sp<StreamOutHalInterface> *outStream) {
112 audio_stream_out_t *halStream;
113 ALOGV("open_output_stream handle: %d devices: %x flags: %#x"
114 "srate: %d format %#x channels %x address %s",
jiabinc0106832019-10-24 14:58:31 -0700115 handle, deviceType, flags,
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800116 config->sample_rate, config->format, config->channel_mask,
117 address);
118 int openResut = mDev->open_output_stream(
jiabinc0106832019-10-24 14:58:31 -0700119 mDev, handle, deviceType, flags, config, &halStream, address);
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800120 if (openResut == OK) {
121 *outStream = new StreamOutHalLocal(halStream, this);
122 }
123 ALOGV("open_output_stream status %d stream %p", openResut, halStream);
124 return openResut;
125}
126
127status_t DeviceHalLocal::openInputStream(
128 audio_io_handle_t handle,
129 audio_devices_t devices,
130 struct audio_config *config,
131 audio_input_flags_t flags,
132 const char *address,
133 audio_source_t source,
Mikhail Naganovb4e037e2019-01-14 15:56:33 -0800134 audio_devices_t /*outputDevice*/,
135 const char */*outputDeviceAddress*/,
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800136 sp<StreamInHalInterface> *inStream) {
137 audio_stream_in_t *halStream;
138 ALOGV("open_input_stream handle: %d devices: %x flags: %#x "
139 "srate: %d format %#x channels %x address %s source %d",
140 handle, devices, flags,
141 config->sample_rate, config->format, config->channel_mask,
142 address, source);
143 int openResult = mDev->open_input_stream(
144 mDev, handle, devices, config, &halStream, flags, address, source);
145 if (openResult == OK) {
146 *inStream = new StreamInHalLocal(halStream, this);
147 }
148 ALOGV("open_input_stream status %d stream %p", openResult, inStream);
149 return openResult;
150}
151
152status_t DeviceHalLocal::supportsAudioPatches(bool *supportsPatches) {
153 *supportsPatches = version() >= AUDIO_DEVICE_API_VERSION_3_0;
154 return OK;
155}
156
157status_t DeviceHalLocal::createAudioPatch(
158 unsigned int num_sources,
159 const struct audio_port_config *sources,
160 unsigned int num_sinks,
161 const struct audio_port_config *sinks,
162 audio_patch_handle_t *patch) {
163 if (version() >= AUDIO_DEVICE_API_VERSION_3_0) {
164 return mDev->create_audio_patch(
165 mDev, num_sources, sources, num_sinks, sinks, patch);
166 } else {
167 return INVALID_OPERATION;
168 }
169}
170
171status_t DeviceHalLocal::releaseAudioPatch(audio_patch_handle_t patch) {
172 if (version() >= AUDIO_DEVICE_API_VERSION_3_0) {
173 return mDev->release_audio_patch(mDev, patch);
174 } else {
175 return INVALID_OPERATION;
176 }
177}
178
179status_t DeviceHalLocal::getAudioPort(struct audio_port *port) {
180 return mDev->get_audio_port(mDev, port);
181}
182
183status_t DeviceHalLocal::setAudioPortConfig(const struct audio_port_config *config) {
184 if (version() >= AUDIO_DEVICE_API_VERSION_3_0)
185 return mDev->set_audio_port_config(mDev, config);
186 else
187 return INVALID_OPERATION;
188}
189
Kevin Rocard070e7512018-05-22 09:29:13 -0700190#if MAJOR_VERSION == 2
191status_t DeviceHalLocal::getMicrophones(
192 std::vector<media::MicrophoneInfo> *microphones __unused) {
193 return INVALID_OPERATION;
194}
Kevin Rocard3d48dce2018-11-08 17:16:57 -0800195#elif MAJOR_VERSION >= 4
jiabin9ff780e2018-03-19 18:19:52 -0700196status_t DeviceHalLocal::getMicrophones(std::vector<media::MicrophoneInfo> *microphones) {
197 if (mDev->get_microphones == NULL) return INVALID_OPERATION;
198 size_t actual_mics = AUDIO_MICROPHONE_MAX_COUNT;
199 audio_microphone_characteristic_t mic_array[AUDIO_MICROPHONE_MAX_COUNT];
200 status_t status = mDev->get_microphones(mDev, &mic_array[0], &actual_mics);
201 for (size_t i = 0; i < actual_mics; i++) {
202 media::MicrophoneInfo microphoneInfo = media::MicrophoneInfo(mic_array[i]);
203 microphones->push_back(microphoneInfo);
204 }
205 return status;
206}
Kevin Rocard070e7512018-05-22 09:29:13 -0700207#endif
jiabin9ff780e2018-03-19 18:19:52 -0700208
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800209status_t DeviceHalLocal::dump(int fd) {
210 return mDev->dump(mDev, fd);
211}
212
213void DeviceHalLocal::closeOutputStream(struct audio_stream_out *stream_out) {
214 mDev->close_output_stream(mDev, stream_out);
215}
216
217void DeviceHalLocal::closeInputStream(struct audio_stream_in *stream_in) {
218 mDev->close_input_stream(mDev, stream_in);
219}
220
Kevin Rocard070e7512018-05-22 09:29:13 -0700221} // namespace CPP_VERSION
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800222} // namespace android