Lines Matching refs:common
116 struct a2dp_stream_common common; member
123 struct a2dp_stream_common common; member
145 static void a2dp_open_ctrl_path(struct a2dp_stream_common *common);
333 static int a2dp_ctrl_receive(struct a2dp_stream_common *common, void* buffer, int length) in a2dp_ctrl_receive() argument
339 OSI_NO_INTR(ret = recv(common->ctrl_fd, buffer, length, MSG_NOSIGNAL)); in a2dp_ctrl_receive()
358 skt_disconnect(common->ctrl_fd); in a2dp_ctrl_receive()
359 common->ctrl_fd = AUDIO_SKT_DISCONNECTED; in a2dp_ctrl_receive()
364 static int a2dp_command(struct a2dp_stream_common *common, char cmd) in a2dp_command() argument
370 if (common->ctrl_fd == AUDIO_SKT_DISCONNECTED) { in a2dp_command()
372 a2dp_open_ctrl_path(common); in a2dp_command()
373 if (common->ctrl_fd == AUDIO_SKT_DISCONNECTED) { in a2dp_command()
381 OSI_NO_INTR(sent = send(common->ctrl_fd, &cmd, 1, MSG_NOSIGNAL)); in a2dp_command()
385 skt_disconnect(common->ctrl_fd); in a2dp_command()
386 common->ctrl_fd = AUDIO_SKT_DISCONNECTED; in a2dp_command()
391 if (a2dp_ctrl_receive(common, &ack, 1) < 0) { in a2dp_command()
408 static int check_a2dp_ready(struct a2dp_stream_common *common) in check_a2dp_ready() argument
410 if (a2dp_command(common, A2DP_CTRL_CMD_CHECK_READY) < 0) in check_a2dp_ready()
418 static int a2dp_read_audio_config(struct a2dp_stream_common *common) in a2dp_read_audio_config() argument
423 if (a2dp_command(common, A2DP_CTRL_GET_AUDIO_CONFIG) < 0) in a2dp_read_audio_config()
429 if (a2dp_ctrl_receive(common, &sample_rate, 4) < 0) in a2dp_read_audio_config()
431 if (a2dp_ctrl_receive(common, &channel_count, 1) < 0) in a2dp_read_audio_config()
434 …common->cfg.channel_flags = (channel_count == 1 ? AUDIO_CHANNEL_IN_MONO : AUDIO_CHANNEL_IN_STEREO); in a2dp_read_audio_config()
435 common->cfg.format = AUDIO_STREAM_DEFAULT_FORMAT; in a2dp_read_audio_config()
436 common->cfg.rate = sample_rate; in a2dp_read_audio_config()
438 INFO("got config %d %d", common->cfg.format, common->cfg.rate); in a2dp_read_audio_config()
443 static void a2dp_open_ctrl_path(struct a2dp_stream_common *common) in a2dp_open_ctrl_path() argument
451 if ((common->ctrl_fd = skt_connect(A2DP_CTRL_PATH, common->buffer_sz)) > 0) in a2dp_open_ctrl_path()
454 if (check_a2dp_ready(common) == 0) in a2dp_open_ctrl_path()
459 skt_disconnect(common->ctrl_fd); in a2dp_open_ctrl_path()
460 common->ctrl_fd = AUDIO_SKT_DISCONNECTED; in a2dp_open_ctrl_path()
474 static void a2dp_stream_common_init(struct a2dp_stream_common *common) in a2dp_stream_common_init() argument
482 pthread_mutex_init(&common->lock, &lock_attr); in a2dp_stream_common_init()
484 common->ctrl_fd = AUDIO_SKT_DISCONNECTED; in a2dp_stream_common_init()
485 common->audio_fd = AUDIO_SKT_DISCONNECTED; in a2dp_stream_common_init()
486 common->state = AUDIO_A2DP_STATE_STOPPED; in a2dp_stream_common_init()
489 common->buffer_sz = AUDIO_STREAM_OUTPUT_BUFFER_SZ; in a2dp_stream_common_init()
492 static int start_audio_datapath(struct a2dp_stream_common *common) in start_audio_datapath() argument
494 INFO("state %d", common->state); in start_audio_datapath()
496 int oldstate = common->state; in start_audio_datapath()
497 common->state = AUDIO_A2DP_STATE_STARTING; in start_audio_datapath()
499 int a2dp_status = a2dp_command(common, A2DP_CTRL_CMD_START); in start_audio_datapath()
512 if (common->audio_fd == AUDIO_SKT_DISCONNECTED) in start_audio_datapath()
514 common->audio_fd = skt_connect(A2DP_DATA_PATH, common->buffer_sz); in start_audio_datapath()
515 if (common->audio_fd < 0) in start_audio_datapath()
521 common->state = AUDIO_A2DP_STATE_STARTED; in start_audio_datapath()
525 common->state = oldstate; in start_audio_datapath()
529 static int stop_audio_datapath(struct a2dp_stream_common *common) in stop_audio_datapath() argument
531 int oldstate = common->state; in stop_audio_datapath()
533 INFO("state %d", common->state); in stop_audio_datapath()
537 common->state = AUDIO_A2DP_STATE_STOPPING; in stop_audio_datapath()
539 if (a2dp_command(common, A2DP_CTRL_CMD_STOP) < 0) in stop_audio_datapath()
542 common->state = oldstate; in stop_audio_datapath()
546 common->state = AUDIO_A2DP_STATE_STOPPED; in stop_audio_datapath()
549 skt_disconnect(common->audio_fd); in stop_audio_datapath()
550 common->audio_fd = AUDIO_SKT_DISCONNECTED; in stop_audio_datapath()
555 static int suspend_audio_datapath(struct a2dp_stream_common *common, bool standby) in suspend_audio_datapath() argument
557 INFO("state %d", common->state); in suspend_audio_datapath()
559 if (common->state == AUDIO_A2DP_STATE_STOPPING) in suspend_audio_datapath()
562 if (a2dp_command(common, A2DP_CTRL_CMD_SUSPEND) < 0) in suspend_audio_datapath()
566 common->state = AUDIO_A2DP_STATE_STANDBY; in suspend_audio_datapath()
568 common->state = AUDIO_A2DP_STATE_SUSPENDED; in suspend_audio_datapath()
571 skt_disconnect(common->audio_fd); in suspend_audio_datapath()
573 common->audio_fd = AUDIO_SKT_DISCONNECTED; in suspend_audio_datapath()
592 DEBUG("write %zu bytes (fd %d)", bytes, out->common.audio_fd); in out_write()
594 pthread_mutex_lock(&out->common.lock); in out_write()
595 if (out->common.state == AUDIO_A2DP_STATE_SUSPENDED || in out_write()
596 out->common.state == AUDIO_A2DP_STATE_STOPPING) { in out_write()
602 if ((out->common.state == AUDIO_A2DP_STATE_STOPPED) || in out_write()
603 (out->common.state == AUDIO_A2DP_STATE_STANDBY)) in out_write()
605 if (start_audio_datapath(&out->common) < 0) in out_write()
610 else if (out->common.state != AUDIO_A2DP_STATE_STARTED) in out_write()
616 pthread_mutex_unlock(&out->common.lock); in out_write()
617 sent = skt_write(out->common.audio_fd, buffer, bytes); in out_write()
618 pthread_mutex_lock(&out->common.lock); in out_write()
621 skt_disconnect(out->common.audio_fd); in out_write()
622 out->common.audio_fd = AUDIO_SKT_DISCONNECTED; in out_write()
623 if ((out->common.state != AUDIO_A2DP_STATE_SUSPENDED) && in out_write()
624 (out->common.state != AUDIO_A2DP_STATE_STOPPING)) { in out_write()
625 out->common.state = AUDIO_A2DP_STATE_STOPPED; in out_write()
635 pthread_mutex_unlock(&out->common.lock); in out_write()
639 pthread_mutex_unlock(&out->common.lock); in out_write()
640 us_delay = calc_audiotime(out->common.cfg, bytes); in out_write()
653 DEBUG("rate %" PRIu32,out->common.cfg.rate); in out_get_sample_rate()
655 return out->common.cfg.rate; in out_get_sample_rate()
670 out->common.cfg.rate = rate; in out_set_sample_rate()
679 const size_t period_size = out->common.buffer_sz / AUDIO_STREAM_OUTPUT_BUFFER_PERIODS; in out_get_buffer_size()
682 DEBUG("socket buffer size: %zu period size: %zu", out->common.buffer_sz, period_size); in out_get_buffer_size()
694 DEBUG("channels 0x%" PRIx32, out->common.cfg.channel_flags); in out_get_channels()
696 return out->common.cfg.channel_flags; in out_get_channels()
702 DEBUG("format 0x%x", out->common.cfg.format); in out_get_format()
703 return out->common.cfg.format; in out_get_format()
721 pthread_mutex_lock(&out->common.lock); in out_standby()
723 if (out->common.state != AUDIO_A2DP_STATE_SUSPENDED) in out_standby()
724 retVal = suspend_audio_datapath(&out->common, true); in out_standby()
726 pthread_mutex_unlock (&out->common.lock); in out_standby()
743 INFO("state %d", out->common.state); in out_set_parameters()
751 pthread_mutex_lock(&out->common.lock); in out_set_parameters()
761 out->common.state = AUDIO_A2DP_STATE_STOPPING; in out_set_parameters()
768 if (out->common.state == AUDIO_A2DP_STATE_STARTED) in out_set_parameters()
769 status = suspend_audio_datapath(&out->common, false); in out_set_parameters()
776 if (out->common.state == AUDIO_A2DP_STATE_SUSPENDED) in out_set_parameters()
777 out->common.state = AUDIO_A2DP_STATE_STANDBY; in out_set_parameters()
781 pthread_mutex_unlock(&out->common.lock); in out_set_parameters()
806 latency_us = ((out->common.buffer_sz * 1000 ) / in out_get_latency()
808 out->common.cfg.rate) * 1000; in out_get_latency()
838 pthread_mutex_lock(&out->common.lock); in out_get_presentation_position()
839 uint64_t latency_frames = (uint64_t)out_get_latency(stream) * out->common.cfg.rate / 1000; in out_get_presentation_position()
845 pthread_mutex_unlock(&out->common.lock); in out_get_presentation_position()
858 pthread_mutex_lock(&out->common.lock); in out_get_render_position()
859 uint64_t latency_frames = (uint64_t)out_get_latency(stream) * out->common.cfg.rate / 1000; in out_get_render_position()
865 pthread_mutex_unlock(&out->common.lock); in out_get_render_position()
896 return in->common.cfg.rate; in in_get_sample_rate()
905 if (in->common.cfg.rate > 0 && in->common.cfg.rate == rate) in in_set_sample_rate()
924 return in->common.cfg.channel_flags; in in_get_channels()
999 DEBUG("read %zu bytes, state: %d", bytes, in->common.state); in in_read()
1001 pthread_mutex_lock(&in->common.lock); in in_read()
1002 if (in->common.state == AUDIO_A2DP_STATE_SUSPENDED || in in_read()
1003 in->common.state == AUDIO_A2DP_STATE_STOPPING) in in_read()
1010 if ((in->common.state == AUDIO_A2DP_STATE_STOPPED) || in in_read()
1011 (in->common.state == AUDIO_A2DP_STATE_STANDBY)) in in_read()
1013 if (start_audio_datapath(&in->common) < 0) in in_read()
1018 else if (in->common.state != AUDIO_A2DP_STATE_STARTED) in in_read()
1024 pthread_mutex_unlock(&in->common.lock); in in_read()
1025 read = skt_read(in->common.audio_fd, buffer, bytes); in in_read()
1026 pthread_mutex_lock(&in->common.lock); in in_read()
1029 skt_disconnect(in->common.audio_fd); in in_read()
1030 in->common.audio_fd = AUDIO_SKT_DISCONNECTED; in in_read()
1031 if ((in->common.state != AUDIO_A2DP_STATE_SUSPENDED) && in in_read()
1032 (in->common.state != AUDIO_A2DP_STATE_STOPPING)) { in in_read()
1033 in->common.state = AUDIO_A2DP_STATE_STOPPED; in in_read()
1043 pthread_mutex_unlock(&in->common.lock); in in_read()
1049 pthread_mutex_unlock(&in->common.lock); in in_read()
1051 us_delay = calc_audiotime(in->common.cfg, bytes); in in_read()
1109 out->stream.common.get_sample_rate = out_get_sample_rate; in adev_open_output_stream()
1110 out->stream.common.set_sample_rate = out_set_sample_rate; in adev_open_output_stream()
1111 out->stream.common.get_buffer_size = out_get_buffer_size; in adev_open_output_stream()
1112 out->stream.common.get_channels = out_get_channels; in adev_open_output_stream()
1113 out->stream.common.get_format = out_get_format; in adev_open_output_stream()
1114 out->stream.common.set_format = out_set_format; in adev_open_output_stream()
1115 out->stream.common.standby = out_standby; in adev_open_output_stream()
1116 out->stream.common.dump = out_dump; in adev_open_output_stream()
1117 out->stream.common.set_parameters = out_set_parameters; in adev_open_output_stream()
1118 out->stream.common.get_parameters = out_get_parameters; in adev_open_output_stream()
1119 out->stream.common.add_audio_effect = out_add_audio_effect; in adev_open_output_stream()
1120 out->stream.common.remove_audio_effect = out_remove_audio_effect; in adev_open_output_stream()
1129 a2dp_stream_common_init(&out->common); in adev_open_output_stream()
1131 out->common.cfg.channel_flags = AUDIO_STREAM_DEFAULT_CHANNEL_FLAG; in adev_open_output_stream()
1132 out->common.cfg.format = AUDIO_STREAM_DEFAULT_FORMAT; in adev_open_output_stream()
1133 out->common.cfg.rate = AUDIO_STREAM_DEFAULT_RATE; in adev_open_output_stream()
1145 a2dp_open_ctrl_path(&out->common); in adev_open_output_stream()
1146 if (out->common.ctrl_fd == AUDIO_SKT_DISCONNECTED) in adev_open_output_stream()
1173 INFO("closing output (state %d)", out->common.state); in adev_close_output_stream()
1175 pthread_mutex_lock(&out->common.lock); in adev_close_output_stream()
1176 if ((out->common.state == AUDIO_A2DP_STATE_STARTED) || in adev_close_output_stream()
1177 (out->common.state == AUDIO_A2DP_STATE_STOPPING)) { in adev_close_output_stream()
1178 stop_audio_datapath(&out->common); in adev_close_output_stream()
1181 skt_disconnect(out->common.ctrl_fd); in adev_close_output_stream()
1182 out->common.ctrl_fd = AUDIO_SKT_DISCONNECTED; in adev_close_output_stream()
1185 pthread_mutex_unlock(&out->common.lock); in adev_close_output_stream()
1199 INFO("state %d", out->common.state); in adev_set_parameters()
1201 retval = out->stream.common.set_parameters((struct audio_stream *)out, kvpairs); in adev_set_parameters()
1315 in->stream.common.get_sample_rate = in_get_sample_rate; in adev_open_input_stream()
1316 in->stream.common.set_sample_rate = in_set_sample_rate; in adev_open_input_stream()
1317 in->stream.common.get_buffer_size = in_get_buffer_size; in adev_open_input_stream()
1318 in->stream.common.get_channels = in_get_channels; in adev_open_input_stream()
1319 in->stream.common.get_format = in_get_format; in adev_open_input_stream()
1320 in->stream.common.set_format = in_set_format; in adev_open_input_stream()
1321 in->stream.common.standby = in_standby; in adev_open_input_stream()
1322 in->stream.common.dump = in_dump; in adev_open_input_stream()
1323 in->stream.common.set_parameters = in_set_parameters; in adev_open_input_stream()
1324 in->stream.common.get_parameters = in_get_parameters; in adev_open_input_stream()
1325 in->stream.common.add_audio_effect = in_add_audio_effect; in adev_open_input_stream()
1326 in->stream.common.remove_audio_effect = in_remove_audio_effect; in adev_open_input_stream()
1332 a2dp_stream_common_init(&in->common); in adev_open_input_stream()
1337 a2dp_open_ctrl_path(&in->common); in adev_open_input_stream()
1338 if (in->common.ctrl_fd == AUDIO_SKT_DISCONNECTED) in adev_open_input_stream()
1345 if (a2dp_read_audio_config(&in->common) < 0) { in adev_open_input_stream()
1367 a2dp_state_t state = in->common.state; in adev_close_input_stream()
1372 stop_audio_datapath(&in->common); in adev_close_input_stream()
1374 skt_disconnect(in->common.ctrl_fd); in adev_close_input_stream()
1375 in->common.ctrl_fd = AUDIO_SKT_DISCONNECTED; in adev_close_input_stream()
1419 adev->device.common.tag = HARDWARE_DEVICE_TAG; in adev_open()
1420 adev->device.common.version = AUDIO_DEVICE_API_VERSION_2_0; in adev_open()
1421 adev->device.common.module = (struct hw_module_t *) module; in adev_open()
1422 adev->device.common.close = adev_close; in adev_open()
1442 *device = &adev->device.common; in adev_open()
1453 .common = {