• Home
  • Raw
  • Download

Lines Matching refs:thread

180 static int audio_thread_send_response(struct audio_thread *thread, int rc)  in audio_thread_send_response()  argument
182 return write(thread->to_main_fds[1], &rc, sizeof(rc)); in audio_thread_send_response()
224 static int audio_thread_read_command(struct audio_thread *thread, in audio_thread_read_command() argument
233 thread->to_thread_fds[0], buf, sizeof(msg->length)); in audio_thread_read_command()
241 rc = read_until_finished(thread->to_thread_fds[0], in audio_thread_read_command()
255 static int append_stream(struct audio_thread *thread, in append_stream() argument
270 DL_SEARCH_SCALAR(thread->open_devs[stream->direction], open_dev, in append_stream()
347 DL_FOREACH(thread->open_devs[stream->direction], open_dev) { in append_stream()
362 static int thread_add_open_dev(struct audio_thread *thread, in thread_add_open_dev() argument
367 DL_SEARCH_SCALAR(thread->open_devs[iodev->direction], in thread_add_open_dev()
384 DL_APPEND(thread->open_devs[iodev->direction], adev); in thread_add_open_dev()
390 static int thread_rm_open_dev(struct audio_thread *thread, in thread_rm_open_dev() argument
394 thread->open_devs[iodev->direction], iodev); in thread_rm_open_dev()
398 dev_io_rm_open_dev(&thread->open_devs[iodev->direction], adev); in thread_rm_open_dev()
406 static int thread_is_dev_open(struct audio_thread *thread, in thread_is_dev_open() argument
410 thread->open_devs[iodev->direction], iodev); in thread_is_dev_open()
415 static int thread_dev_start_ramp(struct audio_thread *thread, in thread_dev_start_ramp() argument
421 thread->open_devs[iodev->direction], iodev); in thread_dev_start_ramp()
429 static int thread_find_stream(struct audio_thread *thread, in thread_find_stream() argument
435 DL_FOREACH(thread->open_devs[rstream->direction], open_dev) { in thread_find_stream()
445 static int thread_disconnect_stream(struct audio_thread* thread, in thread_disconnect_stream() argument
451 if (!thread_find_stream(thread, stream)) in thread_disconnect_stream()
454 rc = dev_io_remove_stream(&thread->open_devs[stream->direction], in thread_disconnect_stream()
465 static int thread_drain_stream_ms_remaining(struct audio_thread *thread, in thread_drain_stream_ms_remaining() argument
488 static int thread_drain_stream(struct audio_thread *thread, in thread_drain_stream() argument
493 if (!thread_find_stream(thread, rstream)) in thread_drain_stream()
496 ms_left = thread_drain_stream_ms_remaining(thread, rstream); in thread_drain_stream()
498 dev_io_remove_stream(&thread->open_devs[rstream->direction], in thread_drain_stream()
505 static int thread_add_stream(struct audio_thread *thread, in thread_add_stream() argument
512 rc = append_stream(thread, stream, iodevs, num_iodevs); in thread_add_stream()
522 static int thread_set_aec_dump(struct audio_thread *thread, in thread_set_aec_dump() argument
527 struct open_dev *idev_list = thread->open_devs[CRAS_STREAM_INPUT]; in thread_set_aec_dump()
608 static int handle_playback_thread_message(struct audio_thread *thread) in handle_playback_thread_message() argument
615 err = audio_thread_read_command(thread, buf, 256); in handle_playback_thread_message()
627 ret = thread_add_stream(thread, amsg->stream, amsg->devs, in handle_playback_thread_message()
636 ret = thread_disconnect_stream(thread, rmsg->stream, in handle_playback_thread_message()
644 ret = thread_add_open_dev(thread, rmsg->dev); in handle_playback_thread_message()
651 ret = thread_rm_open_dev(thread, rmsg->dev); in handle_playback_thread_message()
658 ret = thread_is_dev_open(thread, rmsg->dev); in handle_playback_thread_message()
663 err = audio_thread_send_response(thread, ret); in handle_playback_thread_message()
681 DL_FOREACH(thread->open_devs[CRAS_STREAM_OUTPUT], adev) { in handle_playback_thread_message()
693 DL_FOREACH(thread->open_devs[CRAS_STREAM_INPUT], adev) { in handle_playback_thread_message()
717 ret = thread_drain_stream(thread, rmsg->stream); in handle_playback_thread_message()
733 rsp = (void *)thread->remix_converter; in handle_playback_thread_message()
736 thread->remix_converter = rmsg->fmt_conv; in handle_playback_thread_message()
738 return write(thread->to_main_fds[1], &rsp, sizeof(rsp)); in handle_playback_thread_message()
744 ret = thread_dev_start_ramp(thread, rmsg->dev, rmsg->request); in handle_playback_thread_message()
750 ret = thread_set_aec_dump(thread, rmsg->stream_id, in handle_playback_thread_message()
759 err = audio_thread_send_response(thread, ret); in handle_playback_thread_message()
821 static int fill_next_sleep_interval(struct audio_thread *thread, in fill_next_sleep_interval() argument
835 ret = get_next_output_wake(&thread->open_devs[CRAS_STREAM_OUTPUT], in fill_next_sleep_interval()
837 ret += dev_io_next_input_wake(&thread->open_devs[CRAS_STREAM_INPUT], in fill_next_sleep_interval()
845 static struct pollfd *add_pollfd(struct audio_thread *thread, in add_pollfd() argument
848 thread->pollfds[thread->num_pollfds].fd = fd; in add_pollfd()
850 thread->pollfds[thread->num_pollfds].events = POLLOUT; in add_pollfd()
852 thread->pollfds[thread->num_pollfds].events = POLLIN; in add_pollfd()
853 thread->num_pollfds++; in add_pollfd()
854 if (thread->num_pollfds >= thread->pollfds_size) { in add_pollfd()
855 thread->pollfds_size *= 2; in add_pollfd()
856 thread->pollfds = in add_pollfd()
857 (struct pollfd *)realloc(thread->pollfds, in add_pollfd()
858 sizeof(*thread->pollfds) * in add_pollfd()
859 thread->pollfds_size); in add_pollfd()
863 return &thread->pollfds[thread->num_pollfds - 1]; in add_pollfd()
891 struct audio_thread *thread = (struct audio_thread *)arg; in audio_io_thread() local
898 msg_fd = thread->to_thread_fds[0]; in audio_io_thread()
908 thread->pollfds[0].fd = msg_fd; in audio_io_thread()
909 thread->pollfds[0].events = POLLIN; in audio_io_thread()
916 thread->num_pollfds = 1; in audio_io_thread()
919 dev_io_run(&thread->open_devs[CRAS_STREAM_OUTPUT], in audio_io_thread()
920 &thread->open_devs[CRAS_STREAM_INPUT], in audio_io_thread()
921 thread->remix_converter); in audio_io_thread()
923 if (fill_next_sleep_interval(thread, &ts)) in audio_io_thread()
927 thread->num_pollfds = 1; in audio_io_thread()
932 iodev_cb->pollfd = add_pollfd(thread, iodev_cb->fd, in audio_io_thread()
939 DL_FOREACH(thread->open_devs[CRAS_STREAM_OUTPUT], adev) { in audio_io_thread()
944 if (!add_pollfd(thread, fd, 0)) in audio_io_thread()
948 DL_FOREACH(thread->open_devs[CRAS_STREAM_INPUT], adev) { in audio_io_thread()
953 if (!add_pollfd(thread, fd, 0)) in audio_io_thread()
970 rc = ppoll(thread->pollfds, thread->num_pollfds, wait_ts, NULL); in audio_io_thread()
976 if (thread->pollfds[0].revents & POLLIN) { in audio_io_thread()
977 rc = handle_playback_thread_message(thread); in audio_io_thread()
1006 static int audio_thread_post_message(struct audio_thread *thread, in audio_thread_post_message() argument
1011 err = write(thread->to_thread_fds[1], msg, msg->length); in audio_thread_post_message()
1017 err = read_until_finished(thread->to_main_fds[0], &rsp, sizeof(rsp)); in audio_thread_post_message()
1083 int audio_thread_add_stream(struct audio_thread *thread, in audio_thread_add_stream() argument
1090 assert(thread && stream); in audio_thread_add_stream()
1092 if (!thread->started) in audio_thread_add_stream()
1097 return audio_thread_post_message(thread, &msg.header); in audio_thread_add_stream()
1100 int audio_thread_disconnect_stream(struct audio_thread *thread, in audio_thread_disconnect_stream() argument
1106 assert(thread && stream); in audio_thread_disconnect_stream()
1110 return audio_thread_post_message(thread, &msg.header); in audio_thread_disconnect_stream()
1113 int audio_thread_drain_stream(struct audio_thread *thread, in audio_thread_drain_stream() argument
1118 assert(thread && stream); in audio_thread_drain_stream()
1122 return audio_thread_post_message(thread, &msg.header); in audio_thread_drain_stream()
1125 int audio_thread_dump_thread_info(struct audio_thread *thread, in audio_thread_dump_thread_info() argument
1131 return audio_thread_post_message(thread, &msg.header); in audio_thread_dump_thread_info()
1134 int audio_thread_set_aec_dump(struct audio_thread *thread, in audio_thread_set_aec_dump() argument
1147 return audio_thread_post_message(thread, &msg.header); in audio_thread_set_aec_dump()
1150 int audio_thread_rm_callback_sync(struct audio_thread *thread, int fd) { in audio_thread_rm_callback_sync() argument
1158 return audio_thread_post_message(thread, &msg.header); in audio_thread_rm_callback_sync()
1161 int audio_thread_config_global_remix(struct audio_thread *thread, in audio_thread_config_global_remix() argument
1197 err = write(thread->to_thread_fds[1], &msg, msg.header.length); in audio_thread_config_global_remix()
1203 err = read_until_finished(thread->to_main_fds[0], &rsp, sizeof(rsp)); in audio_thread_config_global_remix()
1217 struct audio_thread *thread; in audio_thread_create() local
1219 thread = (struct audio_thread *)calloc(1, sizeof(*thread)); in audio_thread_create()
1220 if (!thread) in audio_thread_create()
1223 thread->to_thread_fds[0] = -1; in audio_thread_create()
1224 thread->to_thread_fds[1] = -1; in audio_thread_create()
1225 thread->to_main_fds[0] = -1; in audio_thread_create()
1226 thread->to_main_fds[1] = -1; in audio_thread_create()
1229 rc = pipe(thread->to_thread_fds); in audio_thread_create()
1232 free(thread); in audio_thread_create()
1235 rc = pipe(thread->to_main_fds); in audio_thread_create()
1238 free(thread); in audio_thread_create()
1244 thread->pollfds_size = 32; in audio_thread_create()
1245 thread->pollfds = in audio_thread_create()
1246 (struct pollfd *)malloc(sizeof(*thread->pollfds) in audio_thread_create()
1247 * thread->pollfds_size); in audio_thread_create()
1249 return thread; in audio_thread_create()
1252 int audio_thread_add_open_dev(struct audio_thread *thread, in audio_thread_add_open_dev() argument
1257 assert(thread && dev); in audio_thread_add_open_dev()
1259 if (!thread->started) in audio_thread_add_open_dev()
1263 return audio_thread_post_message(thread, &msg.header); in audio_thread_add_open_dev()
1266 int audio_thread_rm_open_dev(struct audio_thread *thread, in audio_thread_rm_open_dev() argument
1271 assert(thread && dev); in audio_thread_rm_open_dev()
1272 if (!thread->started) in audio_thread_rm_open_dev()
1276 return audio_thread_post_message(thread, &msg.header); in audio_thread_rm_open_dev()
1279 int audio_thread_is_dev_open(struct audio_thread *thread, in audio_thread_is_dev_open() argument
1288 return audio_thread_post_message(thread, &msg.header); in audio_thread_is_dev_open()
1291 int audio_thread_dev_start_ramp(struct audio_thread *thread, in audio_thread_dev_start_ramp() argument
1297 assert(thread && dev); in audio_thread_dev_start_ramp()
1299 if (!thread->started) in audio_thread_dev_start_ramp()
1304 return audio_thread_post_message(thread, &msg.header); in audio_thread_dev_start_ramp()
1307 int audio_thread_start(struct audio_thread *thread) in audio_thread_start() argument
1311 rc = pthread_create(&thread->tid, NULL, audio_io_thread, thread); in audio_thread_start()
1317 thread->started = 1; in audio_thread_start()
1322 void audio_thread_destroy(struct audio_thread *thread) in audio_thread_destroy() argument
1324 if (thread->started) { in audio_thread_destroy()
1329 audio_thread_post_message(thread, &msg); in audio_thread_destroy()
1330 pthread_join(thread->tid, NULL); in audio_thread_destroy()
1333 free(thread->pollfds); in audio_thread_destroy()
1337 if (thread->to_thread_fds[0] != -1) { in audio_thread_destroy()
1338 close(thread->to_thread_fds[0]); in audio_thread_destroy()
1339 close(thread->to_thread_fds[1]); in audio_thread_destroy()
1341 if (thread->to_main_fds[0] != -1) { in audio_thread_destroy()
1342 close(thread->to_main_fds[0]); in audio_thread_destroy()
1343 close(thread->to_main_fds[1]); in audio_thread_destroy()
1346 if (thread->remix_converter) in audio_thread_destroy()
1347 cras_fmt_conv_destroy(&thread->remix_converter); in audio_thread_destroy()
1349 free(thread); in audio_thread_destroy()