blob: 78adfef2a0e5c3715c0daf581d3911b35888eb19 [file] [log] [blame]
Mikhail Naganove4f1f632016-08-31 11:35:10 -07001/*
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
Mikhail Naganova0c91332016-09-19 10:01:12 -070017#define LOG_TAG "DeviceHalLocal"
Mikhail Naganove4f1f632016-08-31 11:35:10 -070018//#define LOG_NDEBUG 0
19
20#include <utils/Log.h>
21
22#include "DeviceHalLocal.h"
Mikhail Naganov1dc98672016-08-18 17:50:29 -070023#include "StreamHalLocal.h"
Mikhail Naganove4f1f632016-08-31 11:35:10 -070024
25namespace android {
26
27DeviceHalLocal::DeviceHalLocal(audio_hw_device_t *dev)
28 : mDev(dev) {
29}
30
31DeviceHalLocal::~DeviceHalLocal() {
32 int status = audio_hw_device_close(mDev);
33 ALOGW_IF(status, "Error closing audio hw device %p: %s", mDev, strerror(-status));
34 mDev = 0;
35}
36
37status_t DeviceHalLocal::getSupportedDevices(uint32_t *devices) {
38 if (mDev->get_supported_devices == NULL) return INVALID_OPERATION;
39 *devices = mDev->get_supported_devices(mDev);
40 return OK;
41}
42
Mikhail Naganove4f1f632016-08-31 11:35:10 -070043status_t DeviceHalLocal::initCheck() {
44 return mDev->init_check(mDev);
45}
46
47status_t DeviceHalLocal::setVoiceVolume(float volume) {
48 return mDev->set_voice_volume(mDev, volume);
49}
50
51status_t DeviceHalLocal::setMasterVolume(float volume) {
52 if (mDev->set_master_volume == NULL) return INVALID_OPERATION;
53 return mDev->set_master_volume(mDev, volume);
54}
55
56status_t DeviceHalLocal::getMasterVolume(float *volume) {
57 if (mDev->get_master_volume == NULL) return INVALID_OPERATION;
58 return mDev->get_master_volume(mDev, volume);
59}
60
61status_t DeviceHalLocal::setMode(audio_mode_t mode) {
62 return mDev->set_mode(mDev, mode);
63}
64
65status_t DeviceHalLocal::setMicMute(bool state) {
66 return mDev->set_mic_mute(mDev, state);
67}
68
69status_t DeviceHalLocal::getMicMute(bool *state) {
70 return mDev->get_mic_mute(mDev, state);
71}
72
73status_t DeviceHalLocal::setMasterMute(bool state) {
74 if (mDev->set_master_mute == NULL) return INVALID_OPERATION;
75 return mDev->set_master_mute(mDev, state);
76}
77
78status_t DeviceHalLocal::getMasterMute(bool *state) {
79 if (mDev->get_master_mute == NULL) return INVALID_OPERATION;
80 return mDev->get_master_mute(mDev, state);
81}
82
83status_t DeviceHalLocal::setParameters(const String8& kvPairs) {
84 return mDev->set_parameters(mDev, kvPairs.string());
85}
86
87status_t DeviceHalLocal::getParameters(const String8& keys, String8 *values) {
Mikhail Naganov1dc98672016-08-18 17:50:29 -070088 char *halValues = mDev->get_parameters(mDev, keys.string());
89 if (halValues != NULL) {
90 values->setTo(halValues);
91 free(halValues);
Mikhail Naganove4f1f632016-08-31 11:35:10 -070092 } else {
93 values->clear();
94 }
95 return OK;
96}
97
98status_t DeviceHalLocal::getInputBufferSize(
99 const struct audio_config *config, size_t *size) {
100 *size = mDev->get_input_buffer_size(mDev, config);
101 return OK;
102}
103
Mikhail Naganov1dc98672016-08-18 17:50:29 -0700104status_t DeviceHalLocal::openOutputStream(
105 audio_io_handle_t handle,
106 audio_devices_t devices,
107 audio_output_flags_t flags,
108 struct audio_config *config,
109 const char *address,
110 sp<StreamOutHalInterface> *outStream) {
111 audio_stream_out_t *halStream;
112 int openResut = mDev->open_output_stream(
113 mDev, handle, devices, flags, config, &halStream, address);
114 if (openResut == OK) {
115 *outStream = new StreamOutHalLocal(halStream, this);
116 }
117 return openResut;
118}
119
120status_t DeviceHalLocal::openInputStream(
121 audio_io_handle_t handle,
122 audio_devices_t devices,
123 struct audio_config *config,
124 audio_input_flags_t flags,
125 const char *address,
126 audio_source_t source,
127 sp<StreamInHalInterface> *inStream) {
128 audio_stream_in_t *halStream;
129 int openResult = mDev->open_input_stream(
130 mDev, handle, devices, config, &halStream, flags, address, source);
131 if (openResult == OK) {
132 *inStream = new StreamInHalLocal(halStream, this);
133 }
134 return openResult;
135}
136
Mikhail Naganov9ee05402016-10-13 15:58:17 -0700137status_t DeviceHalLocal::supportsAudioPatches(bool *supportsPatches) {
138 *supportsPatches = version() >= AUDIO_DEVICE_API_VERSION_3_0;
139 return OK;
140}
141
Mikhail Naganove4f1f632016-08-31 11:35:10 -0700142status_t DeviceHalLocal::createAudioPatch(
143 unsigned int num_sources,
144 const struct audio_port_config *sources,
145 unsigned int num_sinks,
146 const struct audio_port_config *sinks,
147 audio_patch_handle_t *patch) {
Mikhail Naganov9ee05402016-10-13 15:58:17 -0700148 if (version() >= AUDIO_DEVICE_API_VERSION_3_0) {
149 return mDev->create_audio_patch(
150 mDev, num_sources, sources, num_sinks, sinks, patch);
151 } else {
152 return INVALID_OPERATION;
153 }
Mikhail Naganove4f1f632016-08-31 11:35:10 -0700154}
155
156status_t DeviceHalLocal::releaseAudioPatch(audio_patch_handle_t patch) {
Mikhail Naganov9ee05402016-10-13 15:58:17 -0700157 if (version() >= AUDIO_DEVICE_API_VERSION_3_0) {
158 return mDev->release_audio_patch(mDev, patch);
159 } else {
160 return INVALID_OPERATION;
161 }
Mikhail Naganove4f1f632016-08-31 11:35:10 -0700162}
163
164status_t DeviceHalLocal::getAudioPort(struct audio_port *port) {
165 return mDev->get_audio_port(mDev, port);
166}
167
168status_t DeviceHalLocal::setAudioPortConfig(const struct audio_port_config *config) {
Mikhail Naganov9ee05402016-10-13 15:58:17 -0700169 if (version() >= AUDIO_DEVICE_API_VERSION_3_0)
170 return mDev->set_audio_port_config(mDev, config);
171 else
172 return INVALID_OPERATION;
Mikhail Naganove4f1f632016-08-31 11:35:10 -0700173}
174
175status_t DeviceHalLocal::dump(int fd) {
176 return mDev->dump(mDev, fd);
177}
178
Mikhail Naganov1dc98672016-08-18 17:50:29 -0700179void DeviceHalLocal::closeOutputStream(struct audio_stream_out *stream_out) {
Mikhail Naganove4f1f632016-08-31 11:35:10 -0700180 mDev->close_output_stream(mDev, stream_out);
Mikhail Naganove4f1f632016-08-31 11:35:10 -0700181}
182
Mikhail Naganov1dc98672016-08-18 17:50:29 -0700183void DeviceHalLocal::closeInputStream(struct audio_stream_in *stream_in) {
Mikhail Naganove4f1f632016-08-31 11:35:10 -0700184 mDev->close_input_stream(mDev, stream_in);
Mikhail Naganove4f1f632016-08-31 11:35:10 -0700185}
186
187} // namespace android