Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 1 | /* |
| 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" |
Mikhail Naganov | 1dc9867 | 2016-08-18 17:50:29 -0700 | [diff] [blame] | 23 | #include "StreamHalLocal.h" |
Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 24 | |
| 25 | namespace android { |
| 26 | |
| 27 | DeviceHalLocal::DeviceHalLocal(audio_hw_device_t *dev) |
| 28 | : mDev(dev) { |
| 29 | } |
| 30 | |
| 31 | DeviceHalLocal::~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 | |
| 37 | status_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 | |
| 43 | status_t DeviceHalLocal::getVersion(uint32_t *version) { |
| 44 | *version = mDev->common.version; |
| 45 | return OK; |
| 46 | } |
| 47 | |
| 48 | status_t DeviceHalLocal::initCheck() { |
| 49 | return mDev->init_check(mDev); |
| 50 | } |
| 51 | |
| 52 | status_t DeviceHalLocal::setVoiceVolume(float volume) { |
| 53 | return mDev->set_voice_volume(mDev, volume); |
| 54 | } |
| 55 | |
| 56 | status_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 | |
| 61 | status_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 | |
| 66 | status_t DeviceHalLocal::setMode(audio_mode_t mode) { |
| 67 | return mDev->set_mode(mDev, mode); |
| 68 | } |
| 69 | |
| 70 | status_t DeviceHalLocal::setMicMute(bool state) { |
| 71 | return mDev->set_mic_mute(mDev, state); |
| 72 | } |
| 73 | |
| 74 | status_t DeviceHalLocal::getMicMute(bool *state) { |
| 75 | return mDev->get_mic_mute(mDev, state); |
| 76 | } |
| 77 | |
| 78 | status_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 | |
| 83 | status_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 | |
| 88 | status_t DeviceHalLocal::setParameters(const String8& kvPairs) { |
| 89 | return mDev->set_parameters(mDev, kvPairs.string()); |
| 90 | } |
| 91 | |
| 92 | status_t DeviceHalLocal::getParameters(const String8& keys, String8 *values) { |
Mikhail Naganov | 1dc9867 | 2016-08-18 17:50:29 -0700 | [diff] [blame] | 93 | char *halValues = mDev->get_parameters(mDev, keys.string()); |
| 94 | if (halValues != NULL) { |
| 95 | values->setTo(halValues); |
| 96 | free(halValues); |
Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 97 | } else { |
| 98 | values->clear(); |
| 99 | } |
| 100 | return OK; |
| 101 | } |
| 102 | |
| 103 | status_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 Naganov | 1dc9867 | 2016-08-18 17:50:29 -0700 | [diff] [blame] | 109 | status_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 | |
| 125 | status_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 Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 142 | status_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 | |
| 151 | status_t DeviceHalLocal::releaseAudioPatch(audio_patch_handle_t patch) { |
| 152 | return mDev->release_audio_patch(mDev, patch); |
| 153 | } |
| 154 | |
| 155 | status_t DeviceHalLocal::getAudioPort(struct audio_port *port) { |
| 156 | return mDev->get_audio_port(mDev, port); |
| 157 | } |
| 158 | |
| 159 | status_t DeviceHalLocal::setAudioPortConfig(const struct audio_port_config *config) { |
| 160 | return mDev->set_audio_port_config(mDev, config); |
| 161 | } |
| 162 | |
| 163 | status_t DeviceHalLocal::dump(int fd) { |
| 164 | return mDev->dump(mDev, fd); |
| 165 | } |
| 166 | |
Mikhail Naganov | 1dc9867 | 2016-08-18 17:50:29 -0700 | [diff] [blame] | 167 | void DeviceHalLocal::closeOutputStream(struct audio_stream_out *stream_out) { |
Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 168 | mDev->close_output_stream(mDev, stream_out); |
Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Mikhail Naganov | 1dc9867 | 2016-08-18 17:50:29 -0700 | [diff] [blame] | 171 | void DeviceHalLocal::closeInputStream(struct audio_stream_in *stream_in) { |
Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 172 | mDev->close_input_stream(mDev, stream_in); |
Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | } // namespace android |