| 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 |  | 
| Mikhail Naganov | a0c9133 | 2016-09-19 10:01:12 -0700 | [diff] [blame] | 17 | #define LOG_TAG "DeviceHalLocal" | 
| Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 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 |  | 
| Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 43 | status_t DeviceHalLocal::initCheck() { | 
 | 44 |     return mDev->init_check(mDev); | 
 | 45 | } | 
 | 46 |  | 
 | 47 | status_t DeviceHalLocal::setVoiceVolume(float volume) { | 
 | 48 |     return mDev->set_voice_volume(mDev, volume); | 
 | 49 | } | 
 | 50 |  | 
 | 51 | status_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 |  | 
 | 56 | status_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 |  | 
 | 61 | status_t DeviceHalLocal::setMode(audio_mode_t mode) { | 
 | 62 |     return mDev->set_mode(mDev, mode); | 
 | 63 | } | 
 | 64 |  | 
 | 65 | status_t DeviceHalLocal::setMicMute(bool state) { | 
 | 66 |     return mDev->set_mic_mute(mDev, state); | 
 | 67 | } | 
 | 68 |  | 
 | 69 | status_t DeviceHalLocal::getMicMute(bool *state) { | 
 | 70 |     return mDev->get_mic_mute(mDev, state); | 
 | 71 | } | 
 | 72 |  | 
 | 73 | status_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 |  | 
 | 78 | status_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 |  | 
 | 83 | status_t DeviceHalLocal::setParameters(const String8& kvPairs) { | 
 | 84 |     return mDev->set_parameters(mDev, kvPairs.string()); | 
 | 85 | } | 
 | 86 |  | 
 | 87 | status_t DeviceHalLocal::getParameters(const String8& keys, String8 *values) { | 
| Mikhail Naganov | 1dc9867 | 2016-08-18 17:50:29 -0700 | [diff] [blame] | 88 |     char *halValues = mDev->get_parameters(mDev, keys.string()); | 
 | 89 |     if (halValues != NULL) { | 
 | 90 |         values->setTo(halValues); | 
 | 91 |         free(halValues); | 
| Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 92 |     } else { | 
 | 93 |         values->clear(); | 
 | 94 |     } | 
 | 95 |     return OK; | 
 | 96 | } | 
 | 97 |  | 
 | 98 | status_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 Naganov | 1dc9867 | 2016-08-18 17:50:29 -0700 | [diff] [blame] | 104 | status_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 |  | 
 | 120 | status_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 Naganov | 9ee0540 | 2016-10-13 15:58:17 -0700 | [diff] [blame^] | 137 | status_t DeviceHalLocal::supportsAudioPatches(bool *supportsPatches) { | 
 | 138 |     *supportsPatches = version() >= AUDIO_DEVICE_API_VERSION_3_0; | 
 | 139 |     return OK; | 
 | 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) { | 
| Mikhail Naganov | 9ee0540 | 2016-10-13 15:58:17 -0700 | [diff] [blame^] | 148 |     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 Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 154 | } | 
 | 155 |  | 
 | 156 | status_t DeviceHalLocal::releaseAudioPatch(audio_patch_handle_t patch) { | 
| Mikhail Naganov | 9ee0540 | 2016-10-13 15:58:17 -0700 | [diff] [blame^] | 157 |     if (version() >= AUDIO_DEVICE_API_VERSION_3_0) { | 
 | 158 |         return mDev->release_audio_patch(mDev, patch); | 
 | 159 |     } else { | 
 | 160 |         return INVALID_OPERATION; | 
 | 161 |     } | 
| Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 162 | } | 
 | 163 |  | 
 | 164 | status_t DeviceHalLocal::getAudioPort(struct audio_port *port) { | 
 | 165 |     return mDev->get_audio_port(mDev, port); | 
 | 166 | } | 
 | 167 |  | 
 | 168 | status_t DeviceHalLocal::setAudioPortConfig(const struct audio_port_config *config) { | 
| Mikhail Naganov | 9ee0540 | 2016-10-13 15:58:17 -0700 | [diff] [blame^] | 169 |     if (version() >= AUDIO_DEVICE_API_VERSION_3_0) | 
 | 170 |         return mDev->set_audio_port_config(mDev, config); | 
 | 171 |     else | 
 | 172 |         return INVALID_OPERATION; | 
| Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 173 | } | 
 | 174 |  | 
 | 175 | status_t DeviceHalLocal::dump(int fd) { | 
 | 176 |     return mDev->dump(mDev, fd); | 
 | 177 | } | 
 | 178 |  | 
| Mikhail Naganov | 1dc9867 | 2016-08-18 17:50:29 -0700 | [diff] [blame] | 179 | void DeviceHalLocal::closeOutputStream(struct audio_stream_out *stream_out) { | 
| Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 180 |     mDev->close_output_stream(mDev, stream_out); | 
| Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 181 | } | 
 | 182 |  | 
| Mikhail Naganov | 1dc9867 | 2016-08-18 17:50:29 -0700 | [diff] [blame] | 183 | void DeviceHalLocal::closeInputStream(struct audio_stream_in *stream_in) { | 
| Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 184 |     mDev->close_input_stream(mDev, stream_in); | 
| Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 185 | } | 
 | 186 |  | 
 | 187 | } // namespace android |