Lines Matching refs:adev
66 static void update_estimated_rate(struct open_dev *adev, in update_estimated_rate() argument
71 struct cras_iodev *dev = adev->dev; in update_estimated_rate()
122 adev->coarse_rate_adjust); in update_estimated_rate()
133 struct open_dev *adev; in count_non_empty_dev() local
134 DL_FOREACH (adevs, adev) { in count_non_empty_dev()
135 if (!adev->empty_pi || !pic_interval_elapsed(adev->empty_pi)) in count_non_empty_dev()
195 static int fetch_streams(struct open_dev *adev) in fetch_streams() argument
198 struct cras_iodev *odev = adev->dev; in fetch_streams()
206 DL_FOREACH (adev->dev->streams, dev_stream) { in fetch_streams()
273 struct open_dev *adev; in input_delay_frames() local
277 DL_FOREACH (adevs, adev) { in input_delay_frames()
278 if (!cras_iodev_is_open(adev->dev)) in input_delay_frames()
280 delay = cras_iodev_delay_frames(adev->dev); in input_delay_frames()
293 static unsigned int set_stream_delay(struct open_dev *adev) in set_stream_delay() argument
299 delay = input_delay_frames(adev); in set_stream_delay()
301 DL_FOREACH (adev->dev->streams, stream) { in set_stream_delay()
320 static unsigned int get_stream_limit(struct open_dev *adev, in get_stream_limit() argument
331 DL_FOREACH (adev->dev->streams, stream) { in get_stream_limit()
339 adev->dev->info.idx, rstream->stream_id, in get_stream_limit()
368 static int get_input_dev_max_wake_ts(struct open_dev *adev, in get_input_dev_max_wake_ts() argument
375 if (!adev || !adev->dev || !adev->dev->format || in get_input_dev_max_wake_ts()
376 !adev->dev->format->frame_rate || !adev->dev->buffer_size) in get_input_dev_max_wake_ts()
381 dev_rate = adev->dev->format->frame_rate; in get_input_dev_max_wake_ts()
382 half_buffer_size = adev->dev->buffer_size / 2; in get_input_dev_max_wake_ts()
425 static int set_input_dev_wake_ts(struct open_dev *adev, bool *need_to_drop) in set_input_dev_wake_ts() argument
439 adev->wake_ts = min_ts; in set_input_dev_wake_ts()
441 rc = cras_iodev_frames_queued(adev->dev, &level_tstamp); in set_input_dev_wake_ts()
454 if (input_devices_can_drop_samples(adev->dev) && in set_input_dev_wake_ts()
455 (rc >= adev->dev->largest_cb_level * 1.5 || in set_input_dev_wake_ts()
456 rc >= adev->dev->buffer_size * 0.5) && in set_input_dev_wake_ts()
457 cras_frames_to_ms(rc, adev->dev->format->frame_rate) >= in set_input_dev_wake_ts()
461 cap_limit = get_stream_limit(adev, UINT_MAX, &cap_limit_stream); in set_input_dev_wake_ts()
467 DL_FOREACH (adev->dev->streams, stream) { in set_input_dev_wake_ts()
490 if (adev->dev->active_node && in set_input_dev_wake_ts()
491 adev->dev->active_node->type != CRAS_NODE_TYPE_HOTWORD && in set_input_dev_wake_ts()
493 rc = get_input_dev_max_wake_ts(adev, curr_level, &dev_wake_ts); in set_input_dev_wake_ts()
504 adev->wake_ts = min_ts; in set_input_dev_wake_ts()
513 static int capture_to_streams(struct open_dev *adev, struct open_dev *odev_list) in capture_to_streams() argument
515 struct cras_iodev *idev = adev->dev; in capture_to_streams()
522 DL_FOREACH (adev->dev->streams, stream) in capture_to_streams()
538 adev->coarse_rate_adjust = 1; in capture_to_streams()
540 adev->coarse_rate_adjust = -1; in capture_to_streams()
542 adev->coarse_rate_adjust = 0; in capture_to_streams()
557 update_estimated_rate(adev, odev_list, self_rate_need_update); in capture_to_streams()
560 cap_limit = get_stream_limit(adev, hw_level, &cap_limit_stream); in capture_to_streams()
561 set_stream_delay(adev); in capture_to_streams()
581 DL_FOREACH (adev->dev->streams, stream) { in capture_to_streams()
648 struct open_dev *adev, uint8_t *dst, in write_streams() argument
651 struct cras_iodev *odev = adev->dev; in write_streams()
662 DL_FOREACH (adev->dev->streams, curr) { in write_streams()
702 DL_FOREACH (adev->dev->streams, curr) { in write_streams()
736 void update_dev_wakeup_time(struct open_dev *adev, unsigned int *hw_level) in update_dev_wakeup_time() argument
746 adev->dev, hw_level, &adev->wake_ts); in update_dev_wakeup_time()
747 if (!timespec_is_nonzero(&adev->wake_ts)) in update_dev_wakeup_time()
748 adev->wake_ts = now; in update_dev_wakeup_time()
750 if (cras_iodev_state(adev->dev) == CRAS_IODEV_STATE_NORMAL_RUN) in update_dev_wakeup_time()
751 cras_iodev_update_highest_hw_level(adev->dev, *hw_level); in update_dev_wakeup_time()
753 est_rate = adev->dev->format->frame_rate * in update_dev_wakeup_time()
754 cras_iodev_get_est_rate_ratio(adev->dev); in update_dev_wakeup_time()
756 ATLOG(atlog, AUDIO_THREAD_SET_DEV_WAKE, adev->dev->info.idx, *hw_level, in update_dev_wakeup_time()
762 add_timespecs(&adev->wake_ts, &sleep_time); in update_dev_wakeup_time()
764 ATLOG(atlog, AUDIO_THREAD_DEV_SLEEP_TIME, adev->dev->info.idx, in update_dev_wakeup_time()
765 adev->wake_ts.tv_sec, adev->wake_ts.tv_nsec); in update_dev_wakeup_time()
769 int write_output_samples(struct open_dev **odevs, struct open_dev *adev, in write_output_samples() argument
772 struct cras_iodev *odev = adev->dev; in write_output_samples()
800 ATLOG(atlog, AUDIO_THREAD_FILL_AUDIO_TSTAMP, adev->dev->info.idx, in write_output_samples()
804 adev->coarse_rate_adjust = 1; in write_output_samples()
806 adev->coarse_rate_adjust = -1; in write_output_samples()
808 adev->coarse_rate_adjust = 0; in write_output_samples()
811 update_estimated_rate(adev, NULL, true); in write_output_samples()
813 ATLOG(atlog, AUDIO_THREAD_FILL_AUDIO, adev->dev->info.idx, hw_level, in write_output_samples()
832 written = write_streams(odevs, adev, dst, frames); in write_output_samples()
841 if (!adev->non_empty_check_pi) { in write_output_samples()
842 adev->non_empty_check_pi = pic_polled_interval_create( in write_output_samples()
848 if (adev->empty_pi || in write_output_samples()
849 pic_interval_elapsed(adev->non_empty_check_pi)) { in write_output_samples()
851 pic_interval_reset(adev->non_empty_check_pi); in write_output_samples()
861 if (non_empty && adev->empty_pi) { in write_output_samples()
864 pic_polled_interval_destroy(&adev->empty_pi); in write_output_samples()
867 if (non_empty_ptr && !non_empty && !adev->empty_pi) in write_output_samples()
870 adev->empty_pi = pic_polled_interval_create( in write_output_samples()
887 struct open_dev *adev; in get_input_devices_drop_time() local
896 DL_FOREACH (idev_list, adev) { in get_input_devices_drop_time()
897 iodev = adev->dev; in get_input_devices_drop_time()
930 struct open_dev *adev; in dev_io_drop_samples() local
941 DL_FOREACH (idev_list, adev) { in dev_io_drop_samples()
942 if (!input_devices_can_drop_samples(adev->dev)) in dev_io_drop_samples()
945 rc = cras_iodev_drop_frames_by_time(adev->dev, drop_time); in dev_io_drop_samples()
949 adev->dev->info.idx, rc); in dev_io_drop_samples()
965 struct open_dev *adev; in dev_io_send_captured_samples() local
970 DL_FOREACH (idev_list, adev) { in dev_io_send_captured_samples()
973 if (!cras_iodev_is_open(adev->dev)) in dev_io_send_captured_samples()
977 DL_FOREACH (adev->dev->streams, stream) { in dev_io_send_captured_samples()
982 rc = set_input_dev_wake_ts(adev, &need_to_drop); in dev_io_send_captured_samples()
994 struct open_dev *adev) in handle_dev_err() argument
999 ATLOG(atlog, AUDIO_THREAD_SEVERE_UNDERRUN, adev->dev->info.idx, in handle_dev_err()
1001 cras_iodev_reset_request(adev->dev); in handle_dev_err()
1005 adev->dev->direction == CRAS_STREAM_OUTPUT ? "output" : in handle_dev_err()
1007 adev->dev->info.name); in handle_dev_err()
1013 cras_iodev_reset_request(adev->dev); in handle_dev_err()
1015 cras_device_monitor_error_close(adev->dev->info.idx); in handle_dev_err()
1019 syslog(LOG_ERR, "Dev %s err %d", adev->dev->info.name, err_rc); in handle_dev_err()
1022 dev_io_rm_open_dev(odevs, adev); in handle_dev_err()
1029 struct open_dev *adev; in dev_io_capture() local
1032 DL_FOREACH (idev_list, adev) { in dev_io_capture()
1033 if (!cras_iodev_is_open(adev->dev)) in dev_io_capture()
1035 rc = capture_to_streams(adev, odev_list); in dev_io_capture()
1037 handle_dev_err(rc, list, adev); in dev_io_capture()
1044 static void dev_io_check_dev_stream_start(struct open_dev *adev) in dev_io_check_dev_stream_start() argument
1050 DL_FOREACH (adev->dev->streams, dev_stream) { in dev_io_check_dev_stream_start()
1054 cras_iodev_start_stream(adev->dev, dev_stream); in dev_io_check_dev_stream_start()
1060 struct open_dev *adev; in dev_io_playback_fetch() local
1063 DL_FOREACH (odev_list, adev) { in dev_io_playback_fetch()
1064 if (!cras_iodev_is_open(adev->dev)) in dev_io_playback_fetch()
1066 dev_io_check_dev_stream_start(adev); in dev_io_playback_fetch()
1069 DL_FOREACH (odev_list, adev) { in dev_io_playback_fetch()
1070 if (!cras_iodev_is_open(adev->dev)) in dev_io_playback_fetch()
1072 fetch_streams(adev); in dev_io_playback_fetch()
1079 struct open_dev *adev; in dev_io_playback_write() local
1086 adev = *odevs; in dev_io_playback_write()
1087 if (adev && adev->next) { in dev_io_playback_write()
1088 DL_FOREACH (*odevs, adev) { in dev_io_playback_write()
1089 DL_FOREACH (adev->dev->streams, curr) in dev_io_playback_write()
1094 DL_FOREACH (*odevs, adev) { in dev_io_playback_write()
1095 if (!cras_iodev_is_open(adev->dev)) in dev_io_playback_write()
1098 rc = write_output_samples(odevs, adev, output_converter); in dev_io_playback_write()
1100 handle_dev_err(rc, odevs, adev); in dev_io_playback_write()
1108 if (!cras_iodev_odev_should_wake(adev->dev)) in dev_io_playback_write()
1115 update_dev_wakeup_time(adev, &hw_level); in dev_io_playback_write()
1129 adev->dev, hw_level, total_written); in dev_io_playback_write()
1131 handle_dev_err(rc, odevs, adev); in dev_io_playback_write()
1133 update_dev_wakeup_time(adev, &hw_level); in dev_io_playback_write()
1140 DL_FOREACH (*odevs, adev) { in dev_io_playback_write()
1142 if (!cras_iodev_is_open(adev->dev)) in dev_io_playback_write()
1144 DL_FOREACH (adev->dev->streams, stream) { in dev_io_playback_write()
1155 struct open_dev *adev; in update_longest_wake() local
1158 DL_FOREACH (dev_list, adev) { in update_longest_wake()
1159 if (adev->dev->streams == NULL) in update_longest_wake()
1165 if (adev->last_wake.tv_sec) { in update_longest_wake()
1166 subtract_timespecs(ts, &adev->last_wake, in update_longest_wake()
1168 if (timespec_after(&wake_interval, &adev->longest_wake)) in update_longest_wake()
1169 adev->longest_wake = wake_interval; in update_longest_wake()
1171 adev->last_wake = *ts; in update_longest_wake()
1191 static int input_adev_ignore_wake(const struct open_dev *adev) in input_adev_ignore_wake() argument
1193 if (!cras_iodev_is_open(adev->dev)) in input_adev_ignore_wake()
1196 if (!adev->dev->active_node) in input_adev_ignore_wake()
1199 if (adev->dev->active_node->type == CRAS_NODE_TYPE_HOTWORD && in input_adev_ignore_wake()
1200 !cras_iodev_input_streaming(adev->dev)) in input_adev_ignore_wake()
1208 struct open_dev *adev; in dev_io_next_input_wake() local
1211 DL_FOREACH (*idevs, adev) { in dev_io_next_input_wake()
1212 if (input_adev_ignore_wake(adev)) in dev_io_next_input_wake()
1215 ATLOG(atlog, AUDIO_THREAD_DEV_SLEEP_TIME, adev->dev->info.idx, in dev_io_next_input_wake()
1216 adev->wake_ts.tv_sec, adev->wake_ts.tv_nsec); in dev_io_next_input_wake()
1217 if (timespec_after(min_ts, &adev->wake_ts)) in dev_io_next_input_wake()
1218 *min_ts = adev->wake_ts; in dev_io_next_input_wake()
1257 struct open_dev *adev; in dev_io_next_output_wake() local
1260 DL_FOREACH (*odevs, adev) in dev_io_next_output_wake()
1261 ret += get_next_stream_wake_from_list(adev->dev->streams, in dev_io_next_output_wake()
1264 DL_FOREACH (*odevs, adev) { in dev_io_next_output_wake()
1265 if (!cras_iodev_odev_should_wake(adev->dev)) in dev_io_next_output_wake()
1269 if (timespec_after(min_ts, &adev->wake_ts)) in dev_io_next_output_wake()
1270 *min_ts = adev->wake_ts; in dev_io_next_output_wake()