blob: b602f16977bddd4099c94392b598b6febe481c45 [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
17#define LOG_TAG "AudioFlinger::DeviceHalLocal"
18//#define LOG_NDEBUG 0
19
20#include <utils/Log.h>
21
22#include "DeviceHalLocal.h"
23
24namespace android {
25
26DeviceHalLocal::DeviceHalLocal(audio_hw_device_t *dev)
27 : mDev(dev) {
28}
29
30DeviceHalLocal::~DeviceHalLocal() {
31 int status = audio_hw_device_close(mDev);
32 ALOGW_IF(status, "Error closing audio hw device %p: %s", mDev, strerror(-status));
33 mDev = 0;
34}
35
36status_t DeviceHalLocal::getSupportedDevices(uint32_t *devices) {
37 if (mDev->get_supported_devices == NULL) return INVALID_OPERATION;
38 *devices = mDev->get_supported_devices(mDev);
39 return OK;
40}
41
42status_t DeviceHalLocal::getVersion(uint32_t *version) {
43 *version = mDev->common.version;
44 return OK;
45}
46
47status_t DeviceHalLocal::initCheck() {
48 return mDev->init_check(mDev);
49}
50
51status_t DeviceHalLocal::setVoiceVolume(float volume) {
52 return mDev->set_voice_volume(mDev, volume);
53}
54
55status_t DeviceHalLocal::setMasterVolume(float volume) {
56 if (mDev->set_master_volume == NULL) return INVALID_OPERATION;
57 return mDev->set_master_volume(mDev, volume);
58}
59
60status_t DeviceHalLocal::getMasterVolume(float *volume) {
61 if (mDev->get_master_volume == NULL) return INVALID_OPERATION;
62 return mDev->get_master_volume(mDev, volume);
63}
64
65status_t DeviceHalLocal::setMode(audio_mode_t mode) {
66 return mDev->set_mode(mDev, mode);
67}
68
69status_t DeviceHalLocal::setMicMute(bool state) {
70 return mDev->set_mic_mute(mDev, state);
71}
72
73status_t DeviceHalLocal::getMicMute(bool *state) {
74 return mDev->get_mic_mute(mDev, state);
75}
76
77status_t DeviceHalLocal::setMasterMute(bool state) {
78 if (mDev->set_master_mute == NULL) return INVALID_OPERATION;
79 return mDev->set_master_mute(mDev, state);
80}
81
82status_t DeviceHalLocal::getMasterMute(bool *state) {
83 if (mDev->get_master_mute == NULL) return INVALID_OPERATION;
84 return mDev->get_master_mute(mDev, state);
85}
86
87status_t DeviceHalLocal::setParameters(const String8& kvPairs) {
88 return mDev->set_parameters(mDev, kvPairs.string());
89}
90
91status_t DeviceHalLocal::getParameters(const String8& keys, String8 *values) {
92 char *c_values = mDev->get_parameters(mDev, keys.string());
93 if (c_values != NULL) {
94 values->setTo(c_values);
95 free(c_values);
96 } else {
97 values->clear();
98 }
99 return OK;
100}
101
102status_t DeviceHalLocal::getInputBufferSize(
103 const struct audio_config *config, size_t *size) {
104 *size = mDev->get_input_buffer_size(mDev, config);
105 return OK;
106}
107
108status_t DeviceHalLocal::createAudioPatch(
109 unsigned int num_sources,
110 const struct audio_port_config *sources,
111 unsigned int num_sinks,
112 const struct audio_port_config *sinks,
113 audio_patch_handle_t *patch) {
114 return mDev->create_audio_patch(mDev, num_sources, sources, num_sinks, sinks, patch);
115}
116
117status_t DeviceHalLocal::releaseAudioPatch(audio_patch_handle_t patch) {
118 return mDev->release_audio_patch(mDev, patch);
119}
120
121status_t DeviceHalLocal::getAudioPort(struct audio_port *port) {
122 return mDev->get_audio_port(mDev, port);
123}
124
125status_t DeviceHalLocal::setAudioPortConfig(const struct audio_port_config *config) {
126 return mDev->set_audio_port_config(mDev, config);
127}
128
129status_t DeviceHalLocal::dump(int fd) {
130 return mDev->dump(mDev, fd);
131}
132
133status_t DeviceHalLocal::openOutputStream(
134 audio_io_handle_t handle,
135 audio_devices_t devices,
136 audio_output_flags_t flags,
137 struct audio_config *config,
138 const char *address,
139 struct audio_stream_out **stream_out) {
140 return mDev->open_output_stream(mDev, handle, devices, flags, config, stream_out, address);
141}
142
143status_t DeviceHalLocal::closeOutputStream(struct audio_stream_out *stream_out) {
144 mDev->close_output_stream(mDev, stream_out);
145 return OK;
146}
147
148status_t DeviceHalLocal::openInputStream(
149 audio_io_handle_t handle,
150 audio_devices_t devices,
151 struct audio_config *config,
152 audio_input_flags_t flags,
153 const char *address,
154 audio_source_t source,
155 struct audio_stream_in **stream_in) {
156 return mDev->open_input_stream(
157 mDev, handle, devices, config, stream_in, flags, address, source);
158}
159
160status_t DeviceHalLocal::closeInputStream(struct audio_stream_in *stream_in) {
161 mDev->close_input_stream(mDev, stream_in);
162 return OK;
163}
164
165} // namespace android