Tim Yao | e8c0d4a | 2019-11-27 14:47:35 -0800 | [diff] [blame] | 1 | #include <unistd.h> |
| 2 | #include <atomic> |
| 3 | #include <hardware/hardware.h> |
| 4 | #include <hardware/audio.h> |
| 5 | |
Tim Yao | aaa3bc5 | 2020-12-30 17:40:14 -0800 | [diff] [blame] | 6 | #include <IpcBuffer/audio_server_shmem.h> |
| 7 | #include <IpcBuffer/IpcBuffer.h> |
Tim Yao | e8c0d4a | 2019-11-27 14:47:35 -0800 | [diff] [blame] | 8 | #include "audio_client.h" |
| 9 | |
| 10 | #define LOG_TAG "audio_client" |
| 11 | #include <cutils/log.h> |
| 12 | |
| 13 | //#define DEBUG__ |
| 14 | |
| 15 | #ifdef DEBUG__ |
| 16 | #define TRACE_ENTRY() ALOGI("%s enter\n", __func__) |
| 17 | #define TRACE_EXIT() ALOGI("%s exit\n", __func__) |
| 18 | #else |
| 19 | #define TRACE_ENTRY() |
| 20 | #define TRACE_EXIT() |
| 21 | #endif |
| 22 | |
| 23 | Volume MakeVolume(float vol) |
| 24 | { |
| 25 | Volume v; |
| 26 | v.set_vol(vol); |
| 27 | return v; |
| 28 | } |
| 29 | |
| 30 | Mode MakeMode(audio_mode_t mode) |
| 31 | { |
| 32 | Mode m; |
| 33 | m.set_mode(mode); |
| 34 | return m; |
| 35 | } |
| 36 | |
| 37 | Mute MakeMute(bool state) |
| 38 | { |
| 39 | Mute m; |
| 40 | m.set_mute(state); |
| 41 | return m; |
| 42 | } |
| 43 | |
| 44 | Kv_pairs MakeKv_pairs(const char *pairs) |
| 45 | { |
| 46 | Kv_pairs p; |
| 47 | p.set_params(std::string(pairs)); |
| 48 | return p; |
| 49 | } |
| 50 | |
| 51 | Keys MakeKeys(const char *keys) |
| 52 | { |
| 53 | Keys k; |
| 54 | k.set_keys(std::string(keys)); |
| 55 | return k; |
| 56 | } |
| 57 | |
| 58 | StreamReadWrite MakeStreamReadWrite(char *name, size_t bytes) |
| 59 | { |
| 60 | StreamReadWrite rw; |
| 61 | rw.set_name(std::string(name)); |
| 62 | rw.set_size(bytes); |
| 63 | return rw; |
| 64 | } |
| 65 | |
| 66 | AudioConfig MakeAudioConfig(const struct audio_config *config) |
| 67 | { |
| 68 | AudioConfig c; |
| 69 | c.set_sample_rate(config->sample_rate); |
| 70 | c.set_channel_mask(config->channel_mask); |
| 71 | c.set_format(config->format); |
| 72 | c.set_frame_count(config->frame_count); |
| 73 | return c; |
| 74 | } |
| 75 | |
| 76 | Handle MakeHandle(int32_t handle) |
| 77 | { |
| 78 | Handle h; |
| 79 | h.set_handle(handle); |
| 80 | return h; |
| 81 | } |
| 82 | |
| 83 | StreamOutSetVolume MakeStreamOutSetVolume(char *name, float left, float right) |
| 84 | { |
| 85 | StreamOutSetVolume v; |
| 86 | v.set_name(std::string(name)); |
| 87 | v.set_left(left); |
| 88 | v.set_right(right); |
| 89 | return v; |
| 90 | } |
| 91 | |
| 92 | OpenOutputStream MakeOpenOutputStream(std::string name, |
| 93 | uint32_t size, |
| 94 | uint32_t handle, |
| 95 | uint32_t devices, |
| 96 | uint32_t flags, |
| 97 | const struct audio_config *config, |
| 98 | const char *address) |
| 99 | { |
| 100 | OpenOutputStream opt; |
| 101 | opt.set_name(name); |
| 102 | opt.set_size(size); |
| 103 | opt.set_handle(handle); |
| 104 | opt.set_devices(devices); |
| 105 | opt.mutable_config()->CopyFrom(MakeAudioConfig(config)); |
| 106 | opt.set_flags(flags); |
| 107 | opt.set_address(address ? std::string(address) : std::string("")); |
| 108 | return opt; |
| 109 | } |
| 110 | |
| 111 | OpenInputStream MakeOpenInputStream(std::string name, |
| 112 | uint32_t size, |
| 113 | uint32_t handle, |
| 114 | uint32_t devices, |
| 115 | const struct audio_config *config, |
| 116 | uint32_t flags, |
| 117 | const char *address, |
| 118 | uint32_t source) |
| 119 | { |
| 120 | OpenInputStream opt; |
| 121 | opt.set_name(name); |
| 122 | opt.set_size(size); |
| 123 | opt.set_handle(handle); |
| 124 | opt.set_devices(devices); |
| 125 | opt.mutable_config()->CopyFrom(MakeAudioConfig(config)); |
| 126 | opt.set_flags(flags); |
shu.zhang | f2bd59c | 2021-07-13 04:55:34 -0400 | [diff] [blame] | 127 | opt.set_address(address ? std::string(address) : std::string("")); |
Tim Yao | e8c0d4a | 2019-11-27 14:47:35 -0800 | [diff] [blame] | 128 | opt.set_source(source); |
| 129 | return opt; |
| 130 | } |
| 131 | |
| 132 | Stream MakeStream(std::string name) |
| 133 | { |
| 134 | Stream stream; |
| 135 | stream.set_name(name); |
| 136 | return stream; |
| 137 | } |
| 138 | |
| 139 | AudioPortConfig MakeAudioPortConfig(const struct audio_port_config *config) |
| 140 | { |
| 141 | AudioPortConfig c; |
| 142 | c.set_id(config->id); |
| 143 | c.set_role(config->role); |
| 144 | c.set_type(config->type); |
| 145 | c.set_config_mask(config->config_mask); |
| 146 | c.set_sample_rate(config->sample_rate); |
| 147 | c.set_channel_mask(config->channel_mask); |
| 148 | c.set_format(config->format); |
| 149 | AudioGainConfig *gain = c.mutable_gain(); |
| 150 | gain->set_index(config->gain.index); |
| 151 | gain->set_mode(config->gain.mode); |
| 152 | gain->set_channel_mask(config->gain.channel_mask); |
| 153 | for (int i = 0; i < sizeof(config->gain.values) / sizeof(int); i++) { |
| 154 | gain->add_values(config->gain.values[i]); |
| 155 | } |
| 156 | gain->set_ramp_duration_ms(config->gain.ramp_duration_ms); |
| 157 | if (config->type == AUDIO_PORT_TYPE_DEVICE) { |
| 158 | c.mutable_device()->set_hw_module(config->ext.device.hw_module); |
| 159 | c.mutable_device()->set_type(config->ext.device.type); |
| 160 | c.mutable_device()->set_address(std::string("null")); |
| 161 | } else if (config->type == AUDIO_PORT_TYPE_MIX) { |
| 162 | c.mutable_mix()->set_hw_module(config->ext.mix.hw_module); |
| 163 | c.mutable_mix()->set_handle(config->ext.mix.handle); |
| 164 | c.mutable_mix()->set_stream_source(config->ext.mix.usecase.stream); |
| 165 | } else if (config->type == AUDIO_PORT_TYPE_SESSION) { |
| 166 | c.mutable_session()->set_session(config->ext.session.session); |
| 167 | } |
yuliang.hu | 19fdc8d | 2024-07-29 17:42:10 +0800 | [diff] [blame] | 168 | /*coverity[UNINIT]: The definition is not in our code and cannot be changed*/ |
Tim Yao | e8c0d4a | 2019-11-27 14:47:35 -0800 | [diff] [blame] | 169 | return c; |
| 170 | } |
| 171 | |
| 172 | StreamSetParameters MakeStreamSetParameters(char *name, const char *kv_pairs) |
| 173 | { |
| 174 | StreamSetParameters p; |
| 175 | p.set_name(std::string(name)); |
| 176 | p.set_kv_pairs(std::string(kv_pairs)); |
| 177 | return p; |
| 178 | } |
| 179 | |
| 180 | StreamGetParameters MakeStreamGetParameters(char *name, const char *keys) |
| 181 | { |
| 182 | StreamGetParameters p; |
| 183 | p.set_name(std::string(name)); |
| 184 | p.set_keys(std::string(keys)); |
| 185 | return p; |
| 186 | } |
| 187 | |
cheng tong | 7d90788 | 2020-09-04 18:53:04 +0800 | [diff] [blame] | 188 | EffectParameters MakeEffectSetParameters(int type, effect_param_t *param) |
| 189 | { |
| 190 | EffectParameters p; |
| 191 | uint32_t psize = ((param->psize - 1) / sizeof(int) + 1) * sizeof(int) + param->vsize; |
| 192 | |
| 193 | p.set_type(type); |
| 194 | p.set_cmd_size(sizeof (effect_param_t) + psize); |
| 195 | p.set_cmd_data(param, sizeof (effect_param_t) + psize); |
| 196 | p.set_reply_size(sizeof(int)); |
| 197 | return p; |
| 198 | } |
| 199 | |
| 200 | EffectParameters MakeEffectGetParameters(int type, effect_param_t *param) |
| 201 | { |
| 202 | EffectParameters p; |
| 203 | uint32_t psize = sizeof(effect_param_t) + ((param->psize - 1) / sizeof(int) + 1) * sizeof(int) |
| 204 | + param->vsize; |
| 205 | |
| 206 | p.set_type(type); |
| 207 | p.set_cmd_size(sizeof (effect_param_t) + param->psize); |
| 208 | p.set_cmd_data(param, sizeof (effect_param_t) + param->psize); |
| 209 | p.set_reply_size(psize); |
| 210 | return p; |
| 211 | } |
| 212 | |
| 213 | |
Tim Yao | e8c0d4a | 2019-11-27 14:47:35 -0800 | [diff] [blame] | 214 | std::atomic_int AudioClient::stream_seq_; |
| 215 | |
| 216 | int AudioClient::Device_common_close(struct hw_device_t* device) |
| 217 | { |
| 218 | TRACE_ENTRY(); |
| 219 | ClientContext context; |
| 220 | StatusReturn r; |
| 221 | Status status = stub_->Device_common_close(&context, Empty(), &r); |
| 222 | return r.ret(); |
| 223 | } |
| 224 | |
| 225 | int AudioClient::Device_init_check(const struct audio_hw_device *dev) |
| 226 | { |
| 227 | TRACE_ENTRY(); |
| 228 | ClientContext context; |
| 229 | StatusReturn r; |
| 230 | Status status = stub_->Device_init_check(&context, Empty(), &r); |
wei.du | 850202b | 2024-06-20 10:56:19 +0800 | [diff] [blame] | 231 | if (status.ok()) { |
| 232 | return r.ret(); |
| 233 | } else { |
| 234 | return -1; |
| 235 | } |
Tim Yao | e8c0d4a | 2019-11-27 14:47:35 -0800 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | int AudioClient::Device_set_voice_volume(struct audio_hw_device *dev, float volume) |
| 239 | { |
| 240 | TRACE_ENTRY(); |
| 241 | ClientContext context; |
| 242 | StatusReturn r; |
| 243 | Status status = stub_->Device_set_voice_volume(&context, MakeVolume(volume), &r); |
| 244 | return r.ret(); |
| 245 | } |
| 246 | |
| 247 | int AudioClient::Device_set_master_volume(struct audio_hw_device *dev, float volume) |
| 248 | { |
| 249 | TRACE_ENTRY(); |
| 250 | ClientContext context; |
| 251 | StatusReturn r; |
| 252 | Status status = stub_->Device_set_master_volume(&context, MakeVolume(volume), &r); |
| 253 | return r.ret(); |
| 254 | } |
| 255 | |
| 256 | int AudioClient::Device_get_master_volume(struct audio_hw_device *dev, float *volume) |
| 257 | { |
| 258 | TRACE_ENTRY(); |
| 259 | ClientContext context; |
| 260 | StatusReturn r; |
| 261 | Status status = stub_->Device_get_master_volume(&context, Empty(), &r); |
| 262 | *volume = r.status_float(); |
| 263 | return r.ret(); |
| 264 | } |
| 265 | |
| 266 | int AudioClient::Device_set_mode(struct audio_hw_device *dev, audio_mode_t mode) |
| 267 | { |
| 268 | TRACE_ENTRY(); |
| 269 | ClientContext context; |
| 270 | StatusReturn r; |
| 271 | Status status = stub_->Device_set_mode(&context, MakeMode(mode), &r); |
| 272 | return r.ret(); |
| 273 | } |
| 274 | |
| 275 | int AudioClient::Device_set_mic_mute(struct audio_hw_device *dev, bool state) |
| 276 | { |
| 277 | TRACE_ENTRY(); |
| 278 | ClientContext context; |
| 279 | StatusReturn r; |
| 280 | Status status = stub_->Device_set_mic_mute(&context, MakeMute(state), &r); |
| 281 | return r.ret(); |
| 282 | } |
| 283 | |
| 284 | int AudioClient::Device_get_mic_mute(const struct audio_hw_device *dev, bool *state) |
| 285 | { |
| 286 | TRACE_ENTRY(); |
| 287 | ClientContext context; |
| 288 | StatusReturn r; |
| 289 | Status status = stub_->Device_get_mic_mute(&context, Empty(), &r); |
| 290 | *state = r.status_bool(); |
| 291 | return r.ret(); |
| 292 | } |
| 293 | |
| 294 | int AudioClient::Device_set_parameters(struct audio_hw_device *dev, const char *kv_pairs) |
| 295 | { |
| 296 | TRACE_ENTRY(); |
| 297 | ClientContext context; |
| 298 | StatusReturn r; |
| 299 | Status status = stub_->Device_set_parameters(&context, MakeKv_pairs(kv_pairs), &r); |
| 300 | return r.ret(); |
| 301 | } |
| 302 | |
| 303 | char * AudioClient::Device_get_parameters(const struct audio_hw_device *dev, const char *keys) |
| 304 | { |
| 305 | TRACE_ENTRY(); |
| 306 | ClientContext context; |
| 307 | StatusReturn r; |
| 308 | Status status = stub_->Device_get_parameters(&context, MakeKeys(keys), &r); |
| 309 | char *p = (char *)malloc(r.status_string().size() + 1); |
| 310 | if (p) { |
| 311 | strcpy(p, r.status_string().c_str()); |
| 312 | } |
| 313 | return p; |
| 314 | } |
| 315 | |
| 316 | size_t AudioClient::Device_get_input_buffer_size(const struct audio_hw_device *dev, |
| 317 | const struct audio_config *config) |
| 318 | { |
| 319 | TRACE_ENTRY(); |
| 320 | ClientContext context; |
| 321 | StatusReturn r; |
| 322 | Status status = stub_->Device_get_input_buffer_size(&context, MakeAudioConfig(config), &r); |
| 323 | return r.ret(); |
| 324 | } |
| 325 | |
| 326 | int AudioClient::Device_open_output_stream(struct audio_hw_device *dev, |
| 327 | audio_io_handle_t handle, |
| 328 | audio_devices_t devices, |
| 329 | audio_output_flags_t flags, |
| 330 | struct audio_config *config, |
| 331 | audio_stream_out_client_t *stream_out, |
| 332 | const char *address) |
| 333 | { |
| 334 | TRACE_ENTRY(); |
| 335 | ClientContext context; |
Tim Yao | 41ac587 | 2022-12-11 13:07:32 -0800 | [diff] [blame] | 336 | DeviceOpenStreamReturn r; |
Tim Yao | e8c0d4a | 2019-11-27 14:47:35 -0800 | [diff] [blame] | 337 | Status status = stub_->Device_open_output_stream(&context, |
| 338 | MakeOpenOutputStream(new_stream_name(stream_out->name, sizeof(stream_out->name)), |
| 339 | kSharedBufferSize, |
| 340 | handle, |
| 341 | devices, |
| 342 | flags, |
| 343 | config, |
| 344 | address), &r); |
Tim Yao | 41ac587 | 2022-12-11 13:07:32 -0800 | [diff] [blame] | 345 | update_stream_name(stream_out->name, sizeof(stream_out->name), r.client_id()); |
Tim Yao | e8c0d4a | 2019-11-27 14:47:35 -0800 | [diff] [blame] | 346 | return r.ret(); |
| 347 | } |
| 348 | |
| 349 | void AudioClient::Device_close_output_stream(struct audio_hw_device *dev, |
| 350 | struct audio_stream_out* stream_out) |
| 351 | { |
| 352 | TRACE_ENTRY(); |
| 353 | struct audio_stream_out_client *out = audio_stream_out_to_client(stream_out); |
| 354 | ClientContext context; |
| 355 | StatusReturn r; |
| 356 | Status status = stub_->Device_close_output_stream(&context, MakeStream(std::string(out->name)), &r); |
| 357 | return; |
| 358 | } |
| 359 | |
| 360 | int AudioClient::Device_open_input_stream(struct audio_hw_device *dev, |
| 361 | audio_io_handle_t handle, |
| 362 | audio_devices_t devices, |
| 363 | struct audio_config *config, |
| 364 | struct audio_stream_in_client *stream_in, |
| 365 | audio_input_flags_t flags, |
| 366 | const char *address, |
| 367 | audio_source_t source) |
| 368 | { |
| 369 | TRACE_ENTRY(); |
| 370 | ClientContext context; |
Tim Yao | 41ac587 | 2022-12-11 13:07:32 -0800 | [diff] [blame] | 371 | DeviceOpenStreamReturn r; |
Tim Yao | e8c0d4a | 2019-11-27 14:47:35 -0800 | [diff] [blame] | 372 | Status status = stub_->Device_open_input_stream(&context, |
| 373 | MakeOpenInputStream(new_stream_name(stream_in->name, sizeof(stream_in->name)), |
| 374 | kSharedBufferSize, |
| 375 | handle, |
| 376 | devices, |
| 377 | config, |
| 378 | flags, |
| 379 | address, |
| 380 | source), &r); |
Tim Yao | 41ac587 | 2022-12-11 13:07:32 -0800 | [diff] [blame] | 381 | update_stream_name(stream_in->name, sizeof(stream_in->name), r.client_id()); |
Tim Yao | e8c0d4a | 2019-11-27 14:47:35 -0800 | [diff] [blame] | 382 | return r.ret(); |
| 383 | } |
| 384 | |
| 385 | void AudioClient::Device_close_input_stream(struct audio_hw_device *dev, |
| 386 | struct audio_stream_in *stream_in) |
| 387 | { |
| 388 | TRACE_ENTRY(); |
| 389 | struct audio_stream_in_client *in = audio_stream_in_to_client(stream_in); |
| 390 | ClientContext context; |
| 391 | StatusReturn r; |
| 392 | Status status = stub_->Device_close_input_stream(&context, MakeStream(std::string(in->name)), &r); |
| 393 | } |
| 394 | |
Tim Yao | ab2a3a6 | 2020-10-29 15:33:55 -0700 | [diff] [blame] | 395 | char *AudioClient::Device_dump(const struct audio_hw_device *dev, int fd) |
Tim Yao | e8c0d4a | 2019-11-27 14:47:35 -0800 | [diff] [blame] | 396 | { |
| 397 | TRACE_ENTRY(); |
| 398 | ClientContext context; |
| 399 | StatusReturn r; |
| 400 | Status status = stub_->Device_dump(&context, Empty(), &r); |
Tim Yao | ab2a3a6 | 2020-10-29 15:33:55 -0700 | [diff] [blame] | 401 | char *p = (char *)malloc(r.status_string().size() + 1); |
| 402 | if (p) { |
| 403 | strcpy(p, r.status_string().c_str()); |
| 404 | } |
| 405 | return p; |
Tim Yao | e8c0d4a | 2019-11-27 14:47:35 -0800 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | int AudioClient::Device_set_master_mute(struct audio_hw_device *dev, bool mute) |
| 409 | { |
| 410 | TRACE_ENTRY(); |
| 411 | ClientContext context; |
| 412 | StatusReturn r; |
| 413 | Status status = stub_->Device_set_master_mute(&context, MakeMute(mute), &r); |
| 414 | return r.ret(); |
| 415 | } |
| 416 | |
| 417 | int AudioClient::Device_get_master_mute(struct audio_hw_device *dev, bool *mute) |
| 418 | { |
| 419 | TRACE_ENTRY(); |
| 420 | ClientContext context; |
| 421 | StatusReturn r; |
| 422 | Status status = stub_->Device_get_master_mute(&context, Empty(), &r); |
| 423 | *mute = r.status_bool(); |
| 424 | return r.ret(); |
| 425 | } |
| 426 | |
| 427 | int AudioClient::Device_create_audio_patch(struct audio_hw_device *dev, |
| 428 | unsigned int num_sources, |
| 429 | const struct audio_port_config *sources, |
| 430 | unsigned int num_sinks, |
| 431 | const struct audio_port_config *sinks, |
| 432 | audio_patch_handle_t *handle) |
| 433 | { |
| 434 | TRACE_ENTRY(); |
| 435 | ClientContext context; |
| 436 | StatusReturn r; |
| 437 | CreateAudioPatch request; |
| 438 | const struct audio_port_config *c; |
| 439 | |
| 440 | c = sources; |
| 441 | for (int i = 0; i < num_sources; i++, c++) { |
| 442 | AudioPortConfig *config = request.add_sources(); |
| 443 | config->CopyFrom(MakeAudioPortConfig(c)); |
| 444 | } |
| 445 | |
| 446 | c = sinks; |
| 447 | for (int i = 0; i < num_sinks; i++, c++) { |
| 448 | AudioPortConfig *config = request.add_sinks(); |
| 449 | config->CopyFrom(MakeAudioPortConfig(c)); |
| 450 | } |
| 451 | |
| 452 | Status status = stub_->Device_create_audio_patch(&context, request, &r); |
| 453 | *handle = r.status_32(); |
| 454 | return r.ret(); |
| 455 | } |
| 456 | |
| 457 | int AudioClient::Device_release_audio_patch(struct audio_hw_device *dev, |
| 458 | audio_patch_handle_t handle) |
| 459 | { |
| 460 | TRACE_ENTRY(); |
| 461 | ClientContext context; |
| 462 | StatusReturn r; |
| 463 | Status status = stub_->Device_release_audio_patch(&context, MakeHandle(handle), &r); |
| 464 | return r.ret(); |
| 465 | } |
| 466 | |
| 467 | int AudioClient::Device_set_audio_port_config(struct audio_hw_device *dev, |
| 468 | const struct audio_port_config *config) |
| 469 | { |
| 470 | TRACE_ENTRY(); |
| 471 | ClientContext context; |
| 472 | StatusReturn r; |
| 473 | Status status = stub_->Device_set_audio_port_config(&context, MakeAudioPortConfig(config), &r); |
| 474 | return r.ret(); |
| 475 | } |
| 476 | |
| 477 | int AudioClient::stream_in_set_gain(struct audio_stream_in *stream, float gain) |
| 478 | { |
| 479 | TRACE_ENTRY(); |
| 480 | ClientContext context; |
| 481 | StatusReturn r; |
| 482 | StreamGain request; |
| 483 | char *name = (audio_stream_in_to_client(stream))->name; |
| 484 | request.set_name(std::string(name)); |
| 485 | request.set_gain(gain); |
| 486 | Status status = stub_->StreamIn_set_gain(&context, request, &r); |
| 487 | return r.ret(); |
| 488 | } |
| 489 | |
| 490 | ssize_t AudioClient::stream_in_read(struct audio_stream_in *stream, |
| 491 | void* buffer, |
| 492 | size_t bytes) |
| 493 | { |
| 494 | TRACE_ENTRY(); |
| 495 | ClientContext context; |
| 496 | StatusReturn r; |
| 497 | char *name = (audio_stream_in_to_client(stream))->name; |
| 498 | Status status = stub_->StreamIn_read(&context, MakeStreamReadWrite(name, bytes), &r); |
| 499 | if (r.ret() > 0) { |
Tim Yao | aaa3bc5 | 2020-12-30 17:40:14 -0800 | [diff] [blame] | 500 | IpcBuffer *cb = audio_server_shmem::getInstance()->find<IpcBuffer>(name).first; |
Tim Yao | e8c0d4a | 2019-11-27 14:47:35 -0800 | [diff] [blame] | 501 | if (cb) { |
Tim Yao | aaa3bc5 | 2020-12-30 17:40:14 -0800 | [diff] [blame] | 502 | memcpy(buffer, cb->start_ptr(), r.ret()); |
Tim Yao | e8c0d4a | 2019-11-27 14:47:35 -0800 | [diff] [blame] | 503 | } |
| 504 | } |
| 505 | return r.ret(); |
| 506 | } |
| 507 | |
| 508 | uint32_t AudioClient::stream_in_get_input_frames_lost(struct audio_stream_in *stream) |
| 509 | { |
| 510 | TRACE_ENTRY(); |
| 511 | ClientContext context; |
| 512 | StatusReturn r; |
| 513 | char *name = (audio_stream_in_to_client(stream))->name; |
| 514 | Status status = stub_->StreamIn_get_input_frames_lost(&context, MakeStream(name), &r); |
| 515 | return r.ret(); |
| 516 | } |
| 517 | |
| 518 | int AudioClient::stream_in_get_capture_position(const struct audio_stream_in *stream, |
| 519 | int64_t *frames, int64_t *time) |
| 520 | { |
| 521 | TRACE_ENTRY(); |
| 522 | ClientContext context; |
| 523 | GetCapturePositionReturn r; |
| 524 | char *name = (audio_stream_in_to_client(stream))->name; |
| 525 | Status status = stub_->StreamIn_get_capture_position(&context, MakeStream(name), &r); |
| 526 | *frames = r.frames(); |
| 527 | *time = r.time(); |
| 528 | return r.ret(); |
| 529 | } |
| 530 | |
| 531 | uint32_t AudioClient::stream_out_get_latency(const struct audio_stream_out *stream) |
| 532 | { |
| 533 | TRACE_ENTRY(); |
| 534 | ClientContext context; |
| 535 | StatusReturn r; |
| 536 | char *name = (audio_stream_out_to_client(stream))->name; |
| 537 | Status status = stub_->StreamOut_get_latency(&context, MakeStream(name), &r); |
| 538 | return r.ret(); |
| 539 | } |
| 540 | |
| 541 | int AudioClient::stream_out_set_volume(struct audio_stream_out *stream, float left, float right) |
| 542 | { |
| 543 | TRACE_ENTRY(); |
| 544 | ClientContext context; |
| 545 | StatusReturn r; |
| 546 | char *name = (audio_stream_out_to_client(stream))->name; |
| 547 | Status status = stub_->StreamOut_set_volume(&context, MakeStreamOutSetVolume(name, left, right), &r); |
| 548 | return r.ret(); |
| 549 | } |
| 550 | |
| 551 | ssize_t AudioClient::stream_out_write(struct audio_stream_out *stream, const void* buffer, |
| 552 | size_t bytes) |
| 553 | { |
| 554 | TRACE_ENTRY(); |
| 555 | ClientContext context; |
| 556 | StatusReturn r; |
| 557 | char *name = (audio_stream_out_to_client(stream))->name; |
Tim Yao | aaa3bc5 | 2020-12-30 17:40:14 -0800 | [diff] [blame] | 558 | IpcBuffer *cb = audio_server_shmem::getInstance()->find<IpcBuffer>(name).first; |
Tim Yao | e8c0d4a | 2019-11-27 14:47:35 -0800 | [diff] [blame] | 559 | if (cb) { |
Tim Yao | aaa3bc5 | 2020-12-30 17:40:14 -0800 | [diff] [blame] | 560 | memcpy(cb->start_ptr(), buffer, std::min(bytes, cb->capacity())); |
Tim Yao | e8c0d4a | 2019-11-27 14:47:35 -0800 | [diff] [blame] | 561 | } |
| 562 | Status status = stub_->StreamOut_write(&context, MakeStreamReadWrite(name, bytes), &r); |
| 563 | return r.ret(); |
| 564 | } |
| 565 | |
| 566 | int AudioClient::stream_out_get_render_position(const struct audio_stream_out *stream, |
| 567 | uint32_t *dsp_frames) |
| 568 | { |
| 569 | TRACE_ENTRY(); |
| 570 | ClientContext context; |
| 571 | StatusReturn r; |
| 572 | char *name = (audio_stream_out_to_client(stream))->name; |
| 573 | Status status = stub_->StreamOut_get_render_position(&context, MakeStream(name), &r); |
| 574 | *dsp_frames = r.status_32(); |
| 575 | return r.ret(); |
| 576 | } |
| 577 | |
| 578 | int AudioClient::stream_out_get_next_write_timestamp(const struct audio_stream_out *stream, |
| 579 | int64_t *timestamp) |
| 580 | { |
| 581 | TRACE_ENTRY(); |
| 582 | ClientContext context; |
| 583 | StatusReturn r; |
| 584 | char *name = (audio_stream_out_to_client(stream))->name; |
| 585 | Status status = stub_->StreamOut_get_next_write_timestamp(&context, MakeStream(name), &r); |
| 586 | *timestamp = r.status_64(); |
| 587 | return r.ret(); |
| 588 | } |
| 589 | |
| 590 | int AudioClient::stream_out_pause(struct audio_stream_out* stream) |
| 591 | { |
| 592 | TRACE_ENTRY(); |
| 593 | ClientContext context; |
| 594 | StatusReturn r; |
| 595 | char *name = (audio_stream_out_to_client(stream))->name; |
| 596 | Status status = stub_->StreamOut_pause(&context, MakeStream(name), &r); |
| 597 | return r.ret(); |
| 598 | } |
| 599 | |
| 600 | int AudioClient::stream_out_resume(struct audio_stream_out* stream) |
| 601 | { |
| 602 | TRACE_ENTRY(); |
| 603 | ClientContext context; |
| 604 | StatusReturn r; |
| 605 | char *name = (audio_stream_out_to_client(stream))->name; |
| 606 | Status status = stub_->StreamOut_resume(&context, MakeStream(name), &r); |
| 607 | return r.ret(); |
| 608 | } |
| 609 | |
| 610 | int AudioClient::stream_out_flush(struct audio_stream_out* stream) |
| 611 | { |
| 612 | TRACE_ENTRY(); |
| 613 | ClientContext context; |
| 614 | StatusReturn r; |
| 615 | char *name = (audio_stream_out_to_client(stream))->name; |
| 616 | Status status = stub_->StreamOut_flush(&context, MakeStream(name), &r); |
| 617 | return r.ret(); |
| 618 | } |
| 619 | |
| 620 | int AudioClient::stream_out_get_presentation_position(const struct audio_stream_out *stream, |
| 621 | uint64_t *frames, |
| 622 | struct timespec *timestamp) |
| 623 | { |
| 624 | TRACE_ENTRY(); |
| 625 | ClientContext context; |
| 626 | GetFrameTimestampReturn r; |
| 627 | char *name = (audio_stream_out_to_client(stream))->name; |
| 628 | Status status = stub_->StreamOut_get_presentation_position(&context, MakeStream(name), &r); |
| 629 | *frames = r.frames(); |
| 630 | timestamp->tv_sec = r.timestamp().seconds(); |
| 631 | timestamp->tv_nsec = r.timestamp().nanos(); |
| 632 | return r.ret(); |
| 633 | } |
| 634 | |
| 635 | uint32_t AudioClient::stream_get_sample_rate(const struct audio_stream *stream) |
| 636 | { |
| 637 | TRACE_ENTRY(); |
| 638 | ClientContext context; |
| 639 | StatusReturn r; |
| 640 | char *name = (audio_stream_to_client(stream))->name; |
| 641 | Status status = stub_->Stream_get_sample_rate(&context, MakeStream(name), &r); |
| 642 | return r.ret(); |
| 643 | } |
| 644 | |
| 645 | size_t AudioClient::stream_get_buffer_size(const struct audio_stream *stream) |
| 646 | { |
| 647 | TRACE_ENTRY(); |
| 648 | ClientContext context; |
| 649 | StatusReturn r; |
| 650 | char *name = (audio_stream_to_client(stream))->name; |
| 651 | Status status = stub_->Stream_get_buffer_size(&context, MakeStream(name), &r); |
| 652 | return r.ret(); |
| 653 | } |
| 654 | |
| 655 | audio_channel_mask_t AudioClient::stream_get_channels(const struct audio_stream *stream) |
| 656 | { |
| 657 | TRACE_ENTRY(); |
| 658 | ClientContext context; |
| 659 | StatusReturn r; |
| 660 | char *name = (audio_stream_to_client(stream))->name; |
| 661 | Status status = stub_->Stream_get_channels(&context, MakeStream(name), &r); |
| 662 | return r.ret(); |
| 663 | } |
| 664 | |
| 665 | audio_format_t AudioClient::stream_get_format(const struct audio_stream *stream) |
| 666 | { |
| 667 | TRACE_ENTRY(); |
| 668 | ClientContext context; |
| 669 | StatusReturn r; |
| 670 | char *name = (audio_stream_to_client(stream))->name; |
| 671 | Status status = stub_->Stream_get_format(&context, MakeStream(name), &r); |
| 672 | return (audio_format_t)(r.ret()); |
| 673 | } |
| 674 | |
| 675 | int AudioClient::stream_standby(struct audio_stream *stream) |
| 676 | { |
| 677 | TRACE_ENTRY(); |
| 678 | ClientContext context; |
| 679 | StatusReturn r; |
| 680 | char *name = (audio_stream_to_client(stream))->name; |
| 681 | Status status = stub_->Stream_standby(&context, MakeStream(name), &r); |
| 682 | return r.ret(); |
| 683 | } |
| 684 | |
| 685 | int AudioClient::stream_dump(const struct audio_stream *stream, int fd) |
| 686 | { |
| 687 | TRACE_ENTRY(); |
| 688 | //TODO |
| 689 | return 0; |
| 690 | } |
| 691 | |
| 692 | audio_devices_t AudioClient::stream_get_device(const struct audio_stream *stream) |
| 693 | { |
| 694 | TRACE_ENTRY(); |
| 695 | ClientContext context; |
| 696 | StatusReturn r; |
| 697 | char *name = (audio_stream_to_client(stream))->name; |
| 698 | Status status = stub_->Stream_get_device(&context, MakeStream(name), &r); |
| 699 | return r.ret(); |
| 700 | } |
| 701 | |
| 702 | int AudioClient::stream_set_parameters(struct audio_stream *stream, const char *kv_pairs) |
| 703 | { |
| 704 | TRACE_ENTRY(); |
| 705 | ClientContext context; |
| 706 | StatusReturn r; |
| 707 | char *name = (audio_stream_to_client(stream))->name; |
| 708 | Status status = stub_->Stream_set_parameters(&context, MakeStreamSetParameters(name, kv_pairs), &r); |
| 709 | return r.ret(); |
| 710 | } |
| 711 | |
| 712 | char * AudioClient::stream_get_parameters(const struct audio_stream *stream, |
| 713 | const char *keys) |
| 714 | { |
| 715 | TRACE_ENTRY(); |
| 716 | ClientContext context; |
| 717 | StatusReturn r; |
| 718 | char *name = (audio_stream_to_client(stream))->name; |
| 719 | Status status = stub_->Stream_get_parameters(&context, MakeStreamGetParameters(name, keys), &r); |
| 720 | char *p = (char *)malloc(r.status_string().size() + 1); |
| 721 | if (p) { |
| 722 | strcpy(p, r.status_string().c_str()); |
| 723 | } |
| 724 | return p; |
| 725 | } |
cheng tong | 7d90788 | 2020-09-04 18:53:04 +0800 | [diff] [blame] | 726 | |
| 727 | int AudioClient::Effect_set_parameters(aml_audio_effect_type_e type, effect_param_t *param) |
| 728 | { |
| 729 | TRACE_ENTRY(); |
| 730 | ClientContext context; |
| 731 | StatusReturn r; |
| 732 | Status status = stub_->Effect_set_parameters(&context, MakeEffectSetParameters(type, param), &r); |
| 733 | param->status = r.status_32(); |
| 734 | return r.ret(); |
| 735 | } |
| 736 | |
| 737 | int AudioClient::Effect_get_parameters(aml_audio_effect_type_e type, effect_param_t *param) |
| 738 | { |
| 739 | TRACE_ENTRY(); |
| 740 | ClientContext context; |
| 741 | StatusReturn r; |
| 742 | Status status = stub_->Effect_get_parameters(&context, MakeEffectGetParameters(type, param), &r); |
| 743 | memcpy(param, r.status_bytes().data(), r.status_bytes().size()); |
| 744 | return r.ret(); |
| 745 | } |
| 746 | |