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 | } |
| 168 | return c; |
| 169 | } |
| 170 | |
| 171 | StreamSetParameters MakeStreamSetParameters(char *name, const char *kv_pairs) |
| 172 | { |
| 173 | StreamSetParameters p; |
| 174 | p.set_name(std::string(name)); |
| 175 | p.set_kv_pairs(std::string(kv_pairs)); |
| 176 | return p; |
| 177 | } |
| 178 | |
| 179 | StreamGetParameters MakeStreamGetParameters(char *name, const char *keys) |
| 180 | { |
| 181 | StreamGetParameters p; |
| 182 | p.set_name(std::string(name)); |
| 183 | p.set_keys(std::string(keys)); |
| 184 | return p; |
| 185 | } |
| 186 | |
cheng tong | 7d90788 | 2020-09-04 18:53:04 +0800 | [diff] [blame] | 187 | EffectParameters MakeEffectSetParameters(int type, effect_param_t *param) |
| 188 | { |
| 189 | EffectParameters p; |
| 190 | uint32_t psize = ((param->psize - 1) / sizeof(int) + 1) * sizeof(int) + param->vsize; |
| 191 | |
| 192 | p.set_type(type); |
| 193 | p.set_cmd_size(sizeof (effect_param_t) + psize); |
| 194 | p.set_cmd_data(param, sizeof (effect_param_t) + psize); |
| 195 | p.set_reply_size(sizeof(int)); |
| 196 | return p; |
| 197 | } |
| 198 | |
| 199 | EffectParameters MakeEffectGetParameters(int type, effect_param_t *param) |
| 200 | { |
| 201 | EffectParameters p; |
| 202 | uint32_t psize = sizeof(effect_param_t) + ((param->psize - 1) / sizeof(int) + 1) * sizeof(int) |
| 203 | + param->vsize; |
| 204 | |
| 205 | p.set_type(type); |
| 206 | p.set_cmd_size(sizeof (effect_param_t) + param->psize); |
| 207 | p.set_cmd_data(param, sizeof (effect_param_t) + param->psize); |
| 208 | p.set_reply_size(psize); |
| 209 | return p; |
| 210 | } |
| 211 | |
| 212 | |
Tim Yao | e8c0d4a | 2019-11-27 14:47:35 -0800 | [diff] [blame] | 213 | std::atomic_int AudioClient::stream_seq_; |
| 214 | |
| 215 | int AudioClient::Device_common_close(struct hw_device_t* device) |
| 216 | { |
| 217 | TRACE_ENTRY(); |
| 218 | ClientContext context; |
| 219 | StatusReturn r; |
| 220 | Status status = stub_->Device_common_close(&context, Empty(), &r); |
| 221 | return r.ret(); |
| 222 | } |
| 223 | |
| 224 | int AudioClient::Device_init_check(const struct audio_hw_device *dev) |
| 225 | { |
| 226 | TRACE_ENTRY(); |
| 227 | ClientContext context; |
| 228 | StatusReturn r; |
| 229 | Status status = stub_->Device_init_check(&context, Empty(), &r); |
| 230 | return r.ret(); |
| 231 | } |
| 232 | |
| 233 | int AudioClient::Device_set_voice_volume(struct audio_hw_device *dev, float volume) |
| 234 | { |
| 235 | TRACE_ENTRY(); |
| 236 | ClientContext context; |
| 237 | StatusReturn r; |
| 238 | Status status = stub_->Device_set_voice_volume(&context, MakeVolume(volume), &r); |
| 239 | return r.ret(); |
| 240 | } |
| 241 | |
| 242 | int AudioClient::Device_set_master_volume(struct audio_hw_device *dev, float volume) |
| 243 | { |
| 244 | TRACE_ENTRY(); |
| 245 | ClientContext context; |
| 246 | StatusReturn r; |
| 247 | Status status = stub_->Device_set_master_volume(&context, MakeVolume(volume), &r); |
| 248 | return r.ret(); |
| 249 | } |
| 250 | |
| 251 | int AudioClient::Device_get_master_volume(struct audio_hw_device *dev, float *volume) |
| 252 | { |
| 253 | TRACE_ENTRY(); |
| 254 | ClientContext context; |
| 255 | StatusReturn r; |
| 256 | Status status = stub_->Device_get_master_volume(&context, Empty(), &r); |
| 257 | *volume = r.status_float(); |
| 258 | return r.ret(); |
| 259 | } |
| 260 | |
| 261 | int AudioClient::Device_set_mode(struct audio_hw_device *dev, audio_mode_t mode) |
| 262 | { |
| 263 | TRACE_ENTRY(); |
| 264 | ClientContext context; |
| 265 | StatusReturn r; |
| 266 | Status status = stub_->Device_set_mode(&context, MakeMode(mode), &r); |
| 267 | return r.ret(); |
| 268 | } |
| 269 | |
| 270 | int AudioClient::Device_set_mic_mute(struct audio_hw_device *dev, bool state) |
| 271 | { |
| 272 | TRACE_ENTRY(); |
| 273 | ClientContext context; |
| 274 | StatusReturn r; |
| 275 | Status status = stub_->Device_set_mic_mute(&context, MakeMute(state), &r); |
| 276 | return r.ret(); |
| 277 | } |
| 278 | |
| 279 | int AudioClient::Device_get_mic_mute(const struct audio_hw_device *dev, bool *state) |
| 280 | { |
| 281 | TRACE_ENTRY(); |
| 282 | ClientContext context; |
| 283 | StatusReturn r; |
| 284 | Status status = stub_->Device_get_mic_mute(&context, Empty(), &r); |
| 285 | *state = r.status_bool(); |
| 286 | return r.ret(); |
| 287 | } |
| 288 | |
| 289 | int AudioClient::Device_set_parameters(struct audio_hw_device *dev, const char *kv_pairs) |
| 290 | { |
| 291 | TRACE_ENTRY(); |
| 292 | ClientContext context; |
| 293 | StatusReturn r; |
| 294 | Status status = stub_->Device_set_parameters(&context, MakeKv_pairs(kv_pairs), &r); |
| 295 | return r.ret(); |
| 296 | } |
| 297 | |
| 298 | char * AudioClient::Device_get_parameters(const struct audio_hw_device *dev, const char *keys) |
| 299 | { |
| 300 | TRACE_ENTRY(); |
| 301 | ClientContext context; |
| 302 | StatusReturn r; |
| 303 | Status status = stub_->Device_get_parameters(&context, MakeKeys(keys), &r); |
| 304 | char *p = (char *)malloc(r.status_string().size() + 1); |
| 305 | if (p) { |
| 306 | strcpy(p, r.status_string().c_str()); |
| 307 | } |
| 308 | return p; |
| 309 | } |
| 310 | |
| 311 | size_t AudioClient::Device_get_input_buffer_size(const struct audio_hw_device *dev, |
| 312 | const struct audio_config *config) |
| 313 | { |
| 314 | TRACE_ENTRY(); |
| 315 | ClientContext context; |
| 316 | StatusReturn r; |
| 317 | Status status = stub_->Device_get_input_buffer_size(&context, MakeAudioConfig(config), &r); |
| 318 | return r.ret(); |
| 319 | } |
| 320 | |
| 321 | int AudioClient::Device_open_output_stream(struct audio_hw_device *dev, |
| 322 | audio_io_handle_t handle, |
| 323 | audio_devices_t devices, |
| 324 | audio_output_flags_t flags, |
| 325 | struct audio_config *config, |
| 326 | audio_stream_out_client_t *stream_out, |
| 327 | const char *address) |
| 328 | { |
| 329 | TRACE_ENTRY(); |
| 330 | ClientContext context; |
Tim Yao | 41ac587 | 2022-12-11 13:07:32 -0800 | [diff] [blame^] | 331 | DeviceOpenStreamReturn r; |
Tim Yao | e8c0d4a | 2019-11-27 14:47:35 -0800 | [diff] [blame] | 332 | Status status = stub_->Device_open_output_stream(&context, |
| 333 | MakeOpenOutputStream(new_stream_name(stream_out->name, sizeof(stream_out->name)), |
| 334 | kSharedBufferSize, |
| 335 | handle, |
| 336 | devices, |
| 337 | flags, |
| 338 | config, |
| 339 | address), &r); |
Tim Yao | 41ac587 | 2022-12-11 13:07:32 -0800 | [diff] [blame^] | 340 | 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] | 341 | return r.ret(); |
| 342 | } |
| 343 | |
| 344 | void AudioClient::Device_close_output_stream(struct audio_hw_device *dev, |
| 345 | struct audio_stream_out* stream_out) |
| 346 | { |
| 347 | TRACE_ENTRY(); |
| 348 | struct audio_stream_out_client *out = audio_stream_out_to_client(stream_out); |
| 349 | ClientContext context; |
| 350 | StatusReturn r; |
| 351 | Status status = stub_->Device_close_output_stream(&context, MakeStream(std::string(out->name)), &r); |
| 352 | return; |
| 353 | } |
| 354 | |
| 355 | int AudioClient::Device_open_input_stream(struct audio_hw_device *dev, |
| 356 | audio_io_handle_t handle, |
| 357 | audio_devices_t devices, |
| 358 | struct audio_config *config, |
| 359 | struct audio_stream_in_client *stream_in, |
| 360 | audio_input_flags_t flags, |
| 361 | const char *address, |
| 362 | audio_source_t source) |
| 363 | { |
| 364 | TRACE_ENTRY(); |
| 365 | ClientContext context; |
Tim Yao | 41ac587 | 2022-12-11 13:07:32 -0800 | [diff] [blame^] | 366 | DeviceOpenStreamReturn r; |
Tim Yao | e8c0d4a | 2019-11-27 14:47:35 -0800 | [diff] [blame] | 367 | Status status = stub_->Device_open_input_stream(&context, |
| 368 | MakeOpenInputStream(new_stream_name(stream_in->name, sizeof(stream_in->name)), |
| 369 | kSharedBufferSize, |
| 370 | handle, |
| 371 | devices, |
| 372 | config, |
| 373 | flags, |
| 374 | address, |
| 375 | source), &r); |
Tim Yao | 41ac587 | 2022-12-11 13:07:32 -0800 | [diff] [blame^] | 376 | 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] | 377 | return r.ret(); |
| 378 | } |
| 379 | |
| 380 | void AudioClient::Device_close_input_stream(struct audio_hw_device *dev, |
| 381 | struct audio_stream_in *stream_in) |
| 382 | { |
| 383 | TRACE_ENTRY(); |
| 384 | struct audio_stream_in_client *in = audio_stream_in_to_client(stream_in); |
| 385 | ClientContext context; |
| 386 | StatusReturn r; |
| 387 | Status status = stub_->Device_close_input_stream(&context, MakeStream(std::string(in->name)), &r); |
| 388 | } |
| 389 | |
Tim Yao | ab2a3a6 | 2020-10-29 15:33:55 -0700 | [diff] [blame] | 390 | char *AudioClient::Device_dump(const struct audio_hw_device *dev, int fd) |
Tim Yao | e8c0d4a | 2019-11-27 14:47:35 -0800 | [diff] [blame] | 391 | { |
| 392 | TRACE_ENTRY(); |
| 393 | ClientContext context; |
| 394 | StatusReturn r; |
| 395 | Status status = stub_->Device_dump(&context, Empty(), &r); |
Tim Yao | ab2a3a6 | 2020-10-29 15:33:55 -0700 | [diff] [blame] | 396 | char *p = (char *)malloc(r.status_string().size() + 1); |
| 397 | if (p) { |
| 398 | strcpy(p, r.status_string().c_str()); |
| 399 | } |
| 400 | return p; |
Tim Yao | e8c0d4a | 2019-11-27 14:47:35 -0800 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | int AudioClient::Device_set_master_mute(struct audio_hw_device *dev, bool mute) |
| 404 | { |
| 405 | TRACE_ENTRY(); |
| 406 | ClientContext context; |
| 407 | StatusReturn r; |
| 408 | Status status = stub_->Device_set_master_mute(&context, MakeMute(mute), &r); |
| 409 | return r.ret(); |
| 410 | } |
| 411 | |
| 412 | int AudioClient::Device_get_master_mute(struct audio_hw_device *dev, bool *mute) |
| 413 | { |
| 414 | TRACE_ENTRY(); |
| 415 | ClientContext context; |
| 416 | StatusReturn r; |
| 417 | Status status = stub_->Device_get_master_mute(&context, Empty(), &r); |
| 418 | *mute = r.status_bool(); |
| 419 | return r.ret(); |
| 420 | } |
| 421 | |
| 422 | int AudioClient::Device_create_audio_patch(struct audio_hw_device *dev, |
| 423 | unsigned int num_sources, |
| 424 | const struct audio_port_config *sources, |
| 425 | unsigned int num_sinks, |
| 426 | const struct audio_port_config *sinks, |
| 427 | audio_patch_handle_t *handle) |
| 428 | { |
| 429 | TRACE_ENTRY(); |
| 430 | ClientContext context; |
| 431 | StatusReturn r; |
| 432 | CreateAudioPatch request; |
| 433 | const struct audio_port_config *c; |
| 434 | |
| 435 | c = sources; |
| 436 | for (int i = 0; i < num_sources; i++, c++) { |
| 437 | AudioPortConfig *config = request.add_sources(); |
| 438 | config->CopyFrom(MakeAudioPortConfig(c)); |
| 439 | } |
| 440 | |
| 441 | c = sinks; |
| 442 | for (int i = 0; i < num_sinks; i++, c++) { |
| 443 | AudioPortConfig *config = request.add_sinks(); |
| 444 | config->CopyFrom(MakeAudioPortConfig(c)); |
| 445 | } |
| 446 | |
| 447 | Status status = stub_->Device_create_audio_patch(&context, request, &r); |
| 448 | *handle = r.status_32(); |
| 449 | return r.ret(); |
| 450 | } |
| 451 | |
| 452 | int AudioClient::Device_release_audio_patch(struct audio_hw_device *dev, |
| 453 | audio_patch_handle_t handle) |
| 454 | { |
| 455 | TRACE_ENTRY(); |
| 456 | ClientContext context; |
| 457 | StatusReturn r; |
| 458 | Status status = stub_->Device_release_audio_patch(&context, MakeHandle(handle), &r); |
| 459 | return r.ret(); |
| 460 | } |
| 461 | |
| 462 | int AudioClient::Device_set_audio_port_config(struct audio_hw_device *dev, |
| 463 | const struct audio_port_config *config) |
| 464 | { |
| 465 | TRACE_ENTRY(); |
| 466 | ClientContext context; |
| 467 | StatusReturn r; |
| 468 | Status status = stub_->Device_set_audio_port_config(&context, MakeAudioPortConfig(config), &r); |
| 469 | return r.ret(); |
| 470 | } |
| 471 | |
| 472 | int AudioClient::stream_in_set_gain(struct audio_stream_in *stream, float gain) |
| 473 | { |
| 474 | TRACE_ENTRY(); |
| 475 | ClientContext context; |
| 476 | StatusReturn r; |
| 477 | StreamGain request; |
| 478 | char *name = (audio_stream_in_to_client(stream))->name; |
| 479 | request.set_name(std::string(name)); |
| 480 | request.set_gain(gain); |
| 481 | Status status = stub_->StreamIn_set_gain(&context, request, &r); |
| 482 | return r.ret(); |
| 483 | } |
| 484 | |
| 485 | ssize_t AudioClient::stream_in_read(struct audio_stream_in *stream, |
| 486 | void* buffer, |
| 487 | size_t bytes) |
| 488 | { |
| 489 | TRACE_ENTRY(); |
| 490 | ClientContext context; |
| 491 | StatusReturn r; |
| 492 | char *name = (audio_stream_in_to_client(stream))->name; |
| 493 | Status status = stub_->StreamIn_read(&context, MakeStreamReadWrite(name, bytes), &r); |
| 494 | if (r.ret() > 0) { |
Tim Yao | aaa3bc5 | 2020-12-30 17:40:14 -0800 | [diff] [blame] | 495 | IpcBuffer *cb = audio_server_shmem::getInstance()->find<IpcBuffer>(name).first; |
Tim Yao | e8c0d4a | 2019-11-27 14:47:35 -0800 | [diff] [blame] | 496 | if (cb) { |
Tim Yao | aaa3bc5 | 2020-12-30 17:40:14 -0800 | [diff] [blame] | 497 | memcpy(buffer, cb->start_ptr(), r.ret()); |
Tim Yao | e8c0d4a | 2019-11-27 14:47:35 -0800 | [diff] [blame] | 498 | } |
| 499 | } |
| 500 | return r.ret(); |
| 501 | } |
| 502 | |
| 503 | uint32_t AudioClient::stream_in_get_input_frames_lost(struct audio_stream_in *stream) |
| 504 | { |
| 505 | TRACE_ENTRY(); |
| 506 | ClientContext context; |
| 507 | StatusReturn r; |
| 508 | char *name = (audio_stream_in_to_client(stream))->name; |
| 509 | Status status = stub_->StreamIn_get_input_frames_lost(&context, MakeStream(name), &r); |
| 510 | return r.ret(); |
| 511 | } |
| 512 | |
| 513 | int AudioClient::stream_in_get_capture_position(const struct audio_stream_in *stream, |
| 514 | int64_t *frames, int64_t *time) |
| 515 | { |
| 516 | TRACE_ENTRY(); |
| 517 | ClientContext context; |
| 518 | GetCapturePositionReturn r; |
| 519 | char *name = (audio_stream_in_to_client(stream))->name; |
| 520 | Status status = stub_->StreamIn_get_capture_position(&context, MakeStream(name), &r); |
| 521 | *frames = r.frames(); |
| 522 | *time = r.time(); |
| 523 | return r.ret(); |
| 524 | } |
| 525 | |
| 526 | uint32_t AudioClient::stream_out_get_latency(const struct audio_stream_out *stream) |
| 527 | { |
| 528 | TRACE_ENTRY(); |
| 529 | ClientContext context; |
| 530 | StatusReturn r; |
| 531 | char *name = (audio_stream_out_to_client(stream))->name; |
| 532 | Status status = stub_->StreamOut_get_latency(&context, MakeStream(name), &r); |
| 533 | return r.ret(); |
| 534 | } |
| 535 | |
| 536 | int AudioClient::stream_out_set_volume(struct audio_stream_out *stream, float left, float right) |
| 537 | { |
| 538 | TRACE_ENTRY(); |
| 539 | ClientContext context; |
| 540 | StatusReturn r; |
| 541 | char *name = (audio_stream_out_to_client(stream))->name; |
| 542 | Status status = stub_->StreamOut_set_volume(&context, MakeStreamOutSetVolume(name, left, right), &r); |
| 543 | return r.ret(); |
| 544 | } |
| 545 | |
| 546 | ssize_t AudioClient::stream_out_write(struct audio_stream_out *stream, const void* buffer, |
| 547 | size_t bytes) |
| 548 | { |
| 549 | TRACE_ENTRY(); |
| 550 | ClientContext context; |
| 551 | StatusReturn r; |
| 552 | char *name = (audio_stream_out_to_client(stream))->name; |
Tim Yao | aaa3bc5 | 2020-12-30 17:40:14 -0800 | [diff] [blame] | 553 | IpcBuffer *cb = audio_server_shmem::getInstance()->find<IpcBuffer>(name).first; |
Tim Yao | e8c0d4a | 2019-11-27 14:47:35 -0800 | [diff] [blame] | 554 | if (cb) { |
Tim Yao | aaa3bc5 | 2020-12-30 17:40:14 -0800 | [diff] [blame] | 555 | memcpy(cb->start_ptr(), buffer, std::min(bytes, cb->capacity())); |
Tim Yao | e8c0d4a | 2019-11-27 14:47:35 -0800 | [diff] [blame] | 556 | } |
| 557 | Status status = stub_->StreamOut_write(&context, MakeStreamReadWrite(name, bytes), &r); |
| 558 | return r.ret(); |
| 559 | } |
| 560 | |
| 561 | int AudioClient::stream_out_get_render_position(const struct audio_stream_out *stream, |
| 562 | uint32_t *dsp_frames) |
| 563 | { |
| 564 | TRACE_ENTRY(); |
| 565 | ClientContext context; |
| 566 | StatusReturn r; |
| 567 | char *name = (audio_stream_out_to_client(stream))->name; |
| 568 | Status status = stub_->StreamOut_get_render_position(&context, MakeStream(name), &r); |
| 569 | *dsp_frames = r.status_32(); |
| 570 | return r.ret(); |
| 571 | } |
| 572 | |
| 573 | int AudioClient::stream_out_get_next_write_timestamp(const struct audio_stream_out *stream, |
| 574 | int64_t *timestamp) |
| 575 | { |
| 576 | TRACE_ENTRY(); |
| 577 | ClientContext context; |
| 578 | StatusReturn r; |
| 579 | char *name = (audio_stream_out_to_client(stream))->name; |
| 580 | Status status = stub_->StreamOut_get_next_write_timestamp(&context, MakeStream(name), &r); |
| 581 | *timestamp = r.status_64(); |
| 582 | return r.ret(); |
| 583 | } |
| 584 | |
| 585 | int AudioClient::stream_out_pause(struct audio_stream_out* stream) |
| 586 | { |
| 587 | TRACE_ENTRY(); |
| 588 | ClientContext context; |
| 589 | StatusReturn r; |
| 590 | char *name = (audio_stream_out_to_client(stream))->name; |
| 591 | Status status = stub_->StreamOut_pause(&context, MakeStream(name), &r); |
| 592 | return r.ret(); |
| 593 | } |
| 594 | |
| 595 | int AudioClient::stream_out_resume(struct audio_stream_out* stream) |
| 596 | { |
| 597 | TRACE_ENTRY(); |
| 598 | ClientContext context; |
| 599 | StatusReturn r; |
| 600 | char *name = (audio_stream_out_to_client(stream))->name; |
| 601 | Status status = stub_->StreamOut_resume(&context, MakeStream(name), &r); |
| 602 | return r.ret(); |
| 603 | } |
| 604 | |
| 605 | int AudioClient::stream_out_flush(struct audio_stream_out* stream) |
| 606 | { |
| 607 | TRACE_ENTRY(); |
| 608 | ClientContext context; |
| 609 | StatusReturn r; |
| 610 | char *name = (audio_stream_out_to_client(stream))->name; |
| 611 | Status status = stub_->StreamOut_flush(&context, MakeStream(name), &r); |
| 612 | return r.ret(); |
| 613 | } |
| 614 | |
| 615 | int AudioClient::stream_out_get_presentation_position(const struct audio_stream_out *stream, |
| 616 | uint64_t *frames, |
| 617 | struct timespec *timestamp) |
| 618 | { |
| 619 | TRACE_ENTRY(); |
| 620 | ClientContext context; |
| 621 | GetFrameTimestampReturn r; |
| 622 | char *name = (audio_stream_out_to_client(stream))->name; |
| 623 | Status status = stub_->StreamOut_get_presentation_position(&context, MakeStream(name), &r); |
| 624 | *frames = r.frames(); |
| 625 | timestamp->tv_sec = r.timestamp().seconds(); |
| 626 | timestamp->tv_nsec = r.timestamp().nanos(); |
| 627 | return r.ret(); |
| 628 | } |
| 629 | |
| 630 | uint32_t AudioClient::stream_get_sample_rate(const struct audio_stream *stream) |
| 631 | { |
| 632 | TRACE_ENTRY(); |
| 633 | ClientContext context; |
| 634 | StatusReturn r; |
| 635 | char *name = (audio_stream_to_client(stream))->name; |
| 636 | Status status = stub_->Stream_get_sample_rate(&context, MakeStream(name), &r); |
| 637 | return r.ret(); |
| 638 | } |
| 639 | |
| 640 | size_t AudioClient::stream_get_buffer_size(const struct audio_stream *stream) |
| 641 | { |
| 642 | TRACE_ENTRY(); |
| 643 | ClientContext context; |
| 644 | StatusReturn r; |
| 645 | char *name = (audio_stream_to_client(stream))->name; |
| 646 | Status status = stub_->Stream_get_buffer_size(&context, MakeStream(name), &r); |
| 647 | return r.ret(); |
| 648 | } |
| 649 | |
| 650 | audio_channel_mask_t AudioClient::stream_get_channels(const struct audio_stream *stream) |
| 651 | { |
| 652 | TRACE_ENTRY(); |
| 653 | ClientContext context; |
| 654 | StatusReturn r; |
| 655 | char *name = (audio_stream_to_client(stream))->name; |
| 656 | Status status = stub_->Stream_get_channels(&context, MakeStream(name), &r); |
| 657 | return r.ret(); |
| 658 | } |
| 659 | |
| 660 | audio_format_t AudioClient::stream_get_format(const struct audio_stream *stream) |
| 661 | { |
| 662 | TRACE_ENTRY(); |
| 663 | ClientContext context; |
| 664 | StatusReturn r; |
| 665 | char *name = (audio_stream_to_client(stream))->name; |
| 666 | Status status = stub_->Stream_get_format(&context, MakeStream(name), &r); |
| 667 | return (audio_format_t)(r.ret()); |
| 668 | } |
| 669 | |
| 670 | int AudioClient::stream_standby(struct audio_stream *stream) |
| 671 | { |
| 672 | TRACE_ENTRY(); |
| 673 | ClientContext context; |
| 674 | StatusReturn r; |
| 675 | char *name = (audio_stream_to_client(stream))->name; |
| 676 | Status status = stub_->Stream_standby(&context, MakeStream(name), &r); |
| 677 | return r.ret(); |
| 678 | } |
| 679 | |
| 680 | int AudioClient::stream_dump(const struct audio_stream *stream, int fd) |
| 681 | { |
| 682 | TRACE_ENTRY(); |
| 683 | //TODO |
| 684 | return 0; |
| 685 | } |
| 686 | |
| 687 | audio_devices_t AudioClient::stream_get_device(const struct audio_stream *stream) |
| 688 | { |
| 689 | TRACE_ENTRY(); |
| 690 | ClientContext context; |
| 691 | StatusReturn r; |
| 692 | char *name = (audio_stream_to_client(stream))->name; |
| 693 | Status status = stub_->Stream_get_device(&context, MakeStream(name), &r); |
| 694 | return r.ret(); |
| 695 | } |
| 696 | |
| 697 | int AudioClient::stream_set_parameters(struct audio_stream *stream, const char *kv_pairs) |
| 698 | { |
| 699 | TRACE_ENTRY(); |
| 700 | ClientContext context; |
| 701 | StatusReturn r; |
| 702 | char *name = (audio_stream_to_client(stream))->name; |
| 703 | Status status = stub_->Stream_set_parameters(&context, MakeStreamSetParameters(name, kv_pairs), &r); |
| 704 | return r.ret(); |
| 705 | } |
| 706 | |
| 707 | char * AudioClient::stream_get_parameters(const struct audio_stream *stream, |
| 708 | const char *keys) |
| 709 | { |
| 710 | TRACE_ENTRY(); |
| 711 | ClientContext context; |
| 712 | StatusReturn r; |
| 713 | char *name = (audio_stream_to_client(stream))->name; |
| 714 | Status status = stub_->Stream_get_parameters(&context, MakeStreamGetParameters(name, keys), &r); |
| 715 | char *p = (char *)malloc(r.status_string().size() + 1); |
| 716 | if (p) { |
| 717 | strcpy(p, r.status_string().c_str()); |
| 718 | } |
| 719 | return p; |
| 720 | } |
cheng tong | 7d90788 | 2020-09-04 18:53:04 +0800 | [diff] [blame] | 721 | |
| 722 | int AudioClient::Effect_set_parameters(aml_audio_effect_type_e type, effect_param_t *param) |
| 723 | { |
| 724 | TRACE_ENTRY(); |
| 725 | ClientContext context; |
| 726 | StatusReturn r; |
| 727 | Status status = stub_->Effect_set_parameters(&context, MakeEffectSetParameters(type, param), &r); |
| 728 | param->status = r.status_32(); |
| 729 | return r.ret(); |
| 730 | } |
| 731 | |
| 732 | int AudioClient::Effect_get_parameters(aml_audio_effect_type_e type, effect_param_t *param) |
| 733 | { |
| 734 | TRACE_ENTRY(); |
| 735 | ClientContext context; |
| 736 | StatusReturn r; |
| 737 | Status status = stub_->Effect_get_parameters(&context, MakeEffectGetParameters(type, param), &r); |
| 738 | memcpy(param, r.status_bytes().data(), r.status_bytes().size()); |
| 739 | return r.ret(); |
| 740 | } |
| 741 | |