blob: c5df8c8ccea19ff8c74d3df741c80f91ab1381c6 [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
43status_t DeviceHalLocal::getVersion(uint32_t *version) {
44 *version = mDev->common.version;
45 return OK;
46}
47
48status_t DeviceHalLocal::initCheck() {
49 return mDev->init_check(mDev);
50}
51
52status_t DeviceHalLocal::setVoiceVolume(float volume) {
53 return mDev->set_voice_volume(mDev, volume);
54}
55
56status_t DeviceHalLocal::setMasterVolume(float volume) {
57 if (mDev->set_master_volume == NULL) return INVALID_OPERATION;
58 return mDev->set_master_volume(mDev, volume);
59}
60
61status_t DeviceHalLocal::getMasterVolume(float *volume) {
62 if (mDev->get_master_volume == NULL) return INVALID_OPERATION;
63 return mDev->get_master_volume(mDev, volume);
64}
65
66status_t DeviceHalLocal::setMode(audio_mode_t mode) {
67 return mDev->set_mode(mDev, mode);
68}
69
70status_t DeviceHalLocal::setMicMute(bool state) {
71 return mDev->set_mic_mute(mDev, state);
72}
73
74status_t DeviceHalLocal::getMicMute(bool *state) {
75 return mDev->get_mic_mute(mDev, state);
76}
77
78status_t DeviceHalLocal::setMasterMute(bool state) {
79 if (mDev->set_master_mute == NULL) return INVALID_OPERATION;
80 return mDev->set_master_mute(mDev, state);
81}
82
83status_t DeviceHalLocal::getMasterMute(bool *state) {
84 if (mDev->get_master_mute == NULL) return INVALID_OPERATION;
85 return mDev->get_master_mute(mDev, state);
86}
87
88status_t DeviceHalLocal::setParameters(const String8& kvPairs) {
89 return mDev->set_parameters(mDev, kvPairs.string());
90}
91
92status_t DeviceHalLocal::getParameters(const String8& keys, String8 *values) {
Mikhail Naganov1dc98672016-08-18 17:50:29 -070093 char *halValues = mDev->get_parameters(mDev, keys.string());
94 if (halValues != NULL) {
95 values->setTo(halValues);
96 free(halValues);
Mikhail Naganove4f1f632016-08-31 11:35:10 -070097 } else {
98 values->clear();
99 }
100 return OK;
101}
102
103status_t DeviceHalLocal::getInputBufferSize(
104 const struct audio_config *config, size_t *size) {
105 *size = mDev->get_input_buffer_size(mDev, config);
106 return OK;
107}
108
Mikhail Naganov1dc98672016-08-18 17:50:29 -0700109status_t DeviceHalLocal::openOutputStream(
110 audio_io_handle_t handle,
111 audio_devices_t devices,
112 audio_output_flags_t flags,
113 struct audio_config *config,
114 const char *address,
115 sp<StreamOutHalInterface> *outStream) {
116 audio_stream_out_t *halStream;
117 int openResut = mDev->open_output_stream(
118 mDev, handle, devices, flags, config, &halStream, address);
119 if (openResut == OK) {
120 *outStream = new StreamOutHalLocal(halStream, this);
121 }
122 return openResut;
123}
124
125status_t DeviceHalLocal::openInputStream(
126 audio_io_handle_t handle,
127 audio_devices_t devices,
128 struct audio_config *config,
129 audio_input_flags_t flags,
130 const char *address,
131 audio_source_t source,
132 sp<StreamInHalInterface> *inStream) {
133 audio_stream_in_t *halStream;
134 int openResult = mDev->open_input_stream(
135 mDev, handle, devices, config, &halStream, flags, address, source);
136 if (openResult == OK) {
137 *inStream = new StreamInHalLocal(halStream, this);
138 }
139 return openResult;
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) {
148 return mDev->create_audio_patch(mDev, num_sources, sources, num_sinks, sinks, patch);
149}
150
151status_t DeviceHalLocal::releaseAudioPatch(audio_patch_handle_t patch) {
152 return mDev->release_audio_patch(mDev, patch);
153}
154
155status_t DeviceHalLocal::getAudioPort(struct audio_port *port) {
156 return mDev->get_audio_port(mDev, port);
157}
158
159status_t DeviceHalLocal::setAudioPortConfig(const struct audio_port_config *config) {
160 return mDev->set_audio_port_config(mDev, config);
161}
162
163status_t DeviceHalLocal::dump(int fd) {
164 return mDev->dump(mDev, fd);
165}
166
Mikhail Naganov1dc98672016-08-18 17:50:29 -0700167void DeviceHalLocal::closeOutputStream(struct audio_stream_out *stream_out) {
Mikhail Naganove4f1f632016-08-31 11:35:10 -0700168 mDev->close_output_stream(mDev, stream_out);
Mikhail Naganove4f1f632016-08-31 11:35:10 -0700169}
170
Mikhail Naganov1dc98672016-08-18 17:50:29 -0700171void DeviceHalLocal::closeInputStream(struct audio_stream_in *stream_in) {
Mikhail Naganove4f1f632016-08-31 11:35:10 -0700172 mDev->close_input_stream(mDev, stream_in);
Mikhail Naganove4f1f632016-08-31 11:35:10 -0700173}
174
175} // namespace android