• Home
  • Raw
  • Download

Lines Matching full:info

112 	int (*read_cb)(struct hfp_info *info);
113 int (*write_cb)(struct hfp_info *info);
127 int hfp_info_add_iodev(struct hfp_info *info, in hfp_info_add_iodev() argument
132 if (info->output_format_bytes) in hfp_info_add_iodev()
134 info->output_format_bytes = cras_get_format_bytes(format); in hfp_info_add_iodev()
136 buf_reset(info->playback_buf); in hfp_info_add_iodev()
138 if (info->input_format_bytes) in hfp_info_add_iodev()
140 info->input_format_bytes = cras_get_format_bytes(format); in hfp_info_add_iodev()
142 buf_reset(info->capture_buf); in hfp_info_add_iodev()
151 int hfp_info_rm_iodev(struct hfp_info *info, in hfp_info_rm_iodev() argument
154 if (direction == CRAS_STREAM_OUTPUT && info->output_format_bytes) { in hfp_info_rm_iodev()
155 memset(info->playback_buf->bytes, 0, in hfp_info_rm_iodev()
156 info->playback_buf->used_size); in hfp_info_rm_iodev()
157 info->output_format_bytes = 0; in hfp_info_rm_iodev()
158 } else if (direction == CRAS_STREAM_INPUT && info->input_format_bytes) { in hfp_info_rm_iodev()
159 info->input_format_bytes = 0; in hfp_info_rm_iodev()
167 int hfp_info_has_iodev(struct hfp_info *info) in hfp_info_has_iodev() argument
169 return info->output_format_bytes || info->input_format_bytes; in hfp_info_has_iodev()
172 void hfp_buf_acquire(struct hfp_info *info, in hfp_buf_acquire() argument
179 if (direction == CRAS_STREAM_OUTPUT && info->output_format_bytes) { in hfp_buf_acquire()
180 *buf = buf_write_pointer_size(info->playback_buf, &buf_avail); in hfp_buf_acquire()
181 format_bytes = info->output_format_bytes; in hfp_buf_acquire()
182 } else if (direction == CRAS_STREAM_INPUT && info->input_format_bytes) { in hfp_buf_acquire()
183 *buf = buf_read_pointer_size(info->capture_buf, &buf_avail); in hfp_buf_acquire()
184 format_bytes = info->input_format_bytes; in hfp_buf_acquire()
194 int hfp_buf_size(struct hfp_info *info, enum CRAS_STREAM_DIRECTION direction) in hfp_buf_size() argument
196 if (direction == CRAS_STREAM_OUTPUT && info->output_format_bytes) in hfp_buf_size()
197 return info->playback_buf->used_size / in hfp_buf_size()
198 info->output_format_bytes; in hfp_buf_size()
199 else if (direction == CRAS_STREAM_INPUT && info->input_format_bytes) in hfp_buf_size()
200 return info->capture_buf->used_size / info->input_format_bytes; in hfp_buf_size()
204 void hfp_buf_release(struct hfp_info *info, in hfp_buf_release() argument
208 if (direction == CRAS_STREAM_OUTPUT && info->output_format_bytes) in hfp_buf_release()
209 buf_increment_write(info->playback_buf, in hfp_buf_release()
210 written_frames * info->output_format_bytes); in hfp_buf_release()
211 else if (direction == CRAS_STREAM_INPUT && info->input_format_bytes) in hfp_buf_release()
212 buf_increment_read(info->capture_buf, in hfp_buf_release()
213 written_frames * info->input_format_bytes); in hfp_buf_release()
218 int hfp_buf_queued(struct hfp_info *info, enum CRAS_STREAM_DIRECTION direction) in hfp_buf_queued() argument
220 if (direction == CRAS_STREAM_OUTPUT && info->output_format_bytes) in hfp_buf_queued()
221 return buf_queued(info->playback_buf) / in hfp_buf_queued()
222 info->output_format_bytes; in hfp_buf_queued()
223 else if (direction == CRAS_STREAM_INPUT && info->input_format_bytes) in hfp_buf_queued()
224 return buf_queued(info->capture_buf) / info->input_format_bytes; in hfp_buf_queued()
229 int hfp_fill_output_with_zeros(struct hfp_info *info, unsigned int nframes) in hfp_fill_output_with_zeros() argument
237 if (info->output_format_bytes) { in hfp_fill_output_with_zeros()
238 nbytes = nframes * info->output_format_bytes; in hfp_fill_output_with_zeros()
241 buf = buf_write_pointer_size(info->playback_buf, in hfp_fill_output_with_zeros()
247 buf_increment_write(info->playback_buf, buf_avail); in hfp_fill_output_with_zeros()
249 ret += buf_avail / info->output_format_bytes; in hfp_fill_output_with_zeros()
255 void hfp_force_output_level(struct hfp_info *info, unsigned int level) in hfp_force_output_level() argument
257 if (info->output_format_bytes) { in hfp_force_output_level()
258 level *= info->output_format_bytes; in hfp_force_output_level()
260 buf_adjust_readable(info->playback_buf, level); in hfp_force_output_level()
264 int hfp_write_msbc(struct hfp_info *info) in hfp_write_msbc() argument
273 if (info->write_rp + info->packet_size <= info->write_wp) in hfp_write_msbc()
277 samples = buf_read_pointer_size(info->playback_buf, &pcm_avail); in hfp_write_msbc()
284 wp = buf_write_pointer_size(info->playback_buf, &pcm_avail); in hfp_write_msbc()
286 buf_increment_write(info->playback_buf, to_write); in hfp_write_msbc()
288 samples = buf_read_pointer_size(info->playback_buf, &pcm_avail); in hfp_write_msbc()
294 wp = info->write_buf + info->write_wp; in hfp_write_msbc()
296 wp[1] = h2_header_frames_count[info->msbc_num_out_frames % 4]; in hfp_write_msbc()
297 pcm_encoded = info->msbc_write->encode( in hfp_write_msbc()
298 info->msbc_write, samples, pcm_avail, wp + MSBC_H2_HEADER_LEN, in hfp_write_msbc()
304 buf_increment_read(info->playback_buf, pcm_encoded); in hfp_write_msbc()
306 info->write_wp += MSBC_PKT_SIZE; in hfp_write_msbc()
307 info->msbc_num_out_frames++; in hfp_write_msbc()
309 if (info->write_rp + info->packet_size > info->write_wp) in hfp_write_msbc()
313 err = send(info->fd, info->write_buf + info->write_rp, in hfp_write_msbc()
314 info->packet_size, 0); in hfp_write_msbc()
320 if (err != (int)info->packet_size) { in hfp_write_msbc()
324 info->write_rp += info->packet_size; in hfp_write_msbc()
325 if (info->write_rp == info->write_wp) { in hfp_write_msbc()
326 info->write_rp = 0; in hfp_write_msbc()
327 info->write_wp = 0; in hfp_write_msbc()
333 int hfp_write(struct hfp_info *info) in hfp_write() argument
340 samples = buf_read_pointer_size(info->playback_buf, &to_send); in hfp_write()
341 if (to_send < info->packet_size) in hfp_write()
343 to_send = info->packet_size; in hfp_write()
346 err = send(info->fd, samples, to_send, 0); in hfp_write()
354 if (err != (int)info->packet_size) { in hfp_write()
357 info->packet_size); in hfp_write()
361 buf_increment_read(info->playback_buf, to_send); in hfp_write()
410 static void log_wbs_packet_received(struct hfp_info *info) in log_wbs_packet_received() argument
412 if (info->wbs_logger) in log_wbs_packet_received()
413 packet_status_logger_update(info->wbs_logger, 0); in log_wbs_packet_received()
417 static void log_wbs_packet_lost(struct hfp_info *info) in log_wbs_packet_lost() argument
419 if (info->wbs_logger) in log_wbs_packet_lost()
420 packet_status_logger_update(info->wbs_logger, 1); in log_wbs_packet_lost()
426 * info - The hfp_info instance holding mSBC codec and PLC objects.
428 static int handle_packet_loss(struct hfp_info *info) in handle_packet_loss() argument
436 info->msbc_num_in_frames++; in handle_packet_loss()
437 info->msbc_num_lost_frames++; in handle_packet_loss()
439 log_wbs_packet_lost(info); in handle_packet_loss()
441 in_bytes = buf_write_pointer_size(info->capture_buf, &pcm_avail); in handle_packet_loss()
445 decoded = cras_msbc_plc_handle_bad_frames(info->msbc_plc, in handle_packet_loss()
446 info->msbc_read, in_bytes); in handle_packet_loss()
450 buf_increment_write(info->capture_buf, decoded); in handle_packet_loss()
465 int hfp_read_msbc(struct hfp_info *info) in hfp_read_msbc() argument
487 iov.iov_base = info->read_buf + info->read_wp; in hfp_read_msbc()
488 iov.iov_len = info->packet_size; in hfp_read_msbc()
492 err = recvmsg(info->fd, &msg, 0); in hfp_read_msbc()
503 if (err != (int)info->packet_size) { in hfp_read_msbc()
510 if (info->read_align_cb) { in hfp_read_msbc()
511 if (!info->read_align_cb(info->read_buf)) in hfp_read_msbc()
514 info->read_align_cb = NULL; in hfp_read_msbc()
516 info->read_wp += err; in hfp_read_msbc()
539 if (info->read_rp + MSBC_PKT_SIZE >= info->read_wp) in hfp_read_msbc()
540 info->msbc_read_current_corrupted |= (pkt_status > 0); in hfp_read_msbc()
543 if (info->read_rp + MSBC_PKT_SIZE > info->read_wp) in hfp_read_msbc()
546 if (info->msbc_read_current_corrupted) { in hfp_read_msbc()
548 info->msbc_read_current_corrupted = 0; in hfp_read_msbc()
552 extract_msbc_frame(info->read_buf + info->read_rp, in hfp_read_msbc()
553 info->read_wp - info->read_rp, &seq); in hfp_read_msbc()
562 info->read_rp += MSBC_PKT_SIZE; in hfp_read_msbc()
563 if (info->read_rp == info->read_wp) { in hfp_read_msbc()
564 info->read_rp = 0; in hfp_read_msbc()
565 info->read_wp = 0; in hfp_read_msbc()
568 return handle_packet_loss(info); in hfp_read_msbc()
573 while (seq != (info->msbc_num_in_frames % 4)) { in hfp_read_msbc()
575 err = handle_packet_loss(info); in hfp_read_msbc()
582 capture_buf = buf_write_pointer_size(info->capture_buf, &pcm_avail); in hfp_read_msbc()
586 decoded = info->msbc_read->decode(info->msbc_read, in hfp_read_msbc()
596 err = handle_packet_loss(info); in hfp_read_msbc()
602 log_wbs_packet_received(info); in hfp_read_msbc()
603 buf_increment_write(info->capture_buf, pcm_decoded); in hfp_read_msbc()
604 info->msbc_num_in_frames++; in hfp_read_msbc()
605 cras_msbc_plc_handle_good_frames(info->msbc_plc, capture_buf, in hfp_read_msbc()
612 int hfp_read(struct hfp_info *info) in hfp_read() argument
618 capture_buf = buf_write_pointer_size(info->capture_buf, &to_read); in hfp_read()
620 if (to_read < info->packet_size) in hfp_read()
622 to_read = info->packet_size; in hfp_read()
625 err = recv(info->fd, capture_buf, to_read, 0); in hfp_read()
634 if (err != (int)info->packet_size) { in hfp_read()
640 if (err && (info->packet_size == info->mtu)) { in hfp_read()
641 info->packet_size = err; in hfp_read()
645 err, info->packet_size); in hfp_read()
650 buf_increment_write(info->capture_buf, err); in hfp_read()
666 struct hfp_info *info = (struct hfp_info *)arg; in hfp_info_callback() local
669 if (!info->started) in hfp_info_callback()
674 err = info->read_cb(info); in hfp_info_callback()
681 if (!info->input_format_bytes) in hfp_info_callback()
682 buf_increment_read(info->capture_buf, err); in hfp_info_callback()
693 if (!info->output_format_bytes) in hfp_info_callback()
694 buf_increment_write(info->playback_buf, in hfp_info_callback()
695 info->msbc_write ? err : info->packet_size); in hfp_info_callback()
697 err = info->write_cb(info); in hfp_info_callback()
710 audio_thread_rm_callback(info->fd); in hfp_info_callback()
711 close(info->fd); in hfp_info_callback()
712 info->fd = 0; in hfp_info_callback()
713 info->started = 0; in hfp_info_callback()
720 struct hfp_info *info; in hfp_info_create() local
721 info = (struct hfp_info *)calloc(1, sizeof(*info)); in hfp_info_create()
722 if (!info) in hfp_info_create()
725 info->capture_buf = byte_buffer_create(MAX_HFP_BUF_SIZE_BYTES); in hfp_info_create()
726 if (!info->capture_buf) in hfp_info_create()
729 info->playback_buf = byte_buffer_create(MAX_HFP_BUF_SIZE_BYTES); in hfp_info_create()
730 if (!info->playback_buf) in hfp_info_create()
733 return info; in hfp_info_create()
736 if (info) { in hfp_info_create()
737 if (info->capture_buf) in hfp_info_create()
738 byte_buffer_destroy(&info->capture_buf); in hfp_info_create()
739 if (info->playback_buf) in hfp_info_create()
740 byte_buffer_destroy(&info->playback_buf); in hfp_info_create()
741 free(info); in hfp_info_create()
746 void hfp_info_set_wbs_logger(struct hfp_info *info, in hfp_info_set_wbs_logger() argument
749 info->wbs_logger = wbs_logger; in hfp_info_set_wbs_logger()
752 int hfp_info_running(struct hfp_info *info) in hfp_info_running() argument
754 return info->started; in hfp_info_running()
757 int hfp_info_start(int fd, unsigned int mtu, int codec, struct hfp_info *info) in hfp_info_start() argument
759 info->fd = fd; in hfp_info_start()
760 info->mtu = mtu; in hfp_info_start()
763 info->packet_size = mtu; in hfp_info_start()
764 buf_reset(info->playback_buf); in hfp_info_start()
765 buf_reset(info->capture_buf); in hfp_info_start()
770 if (info->packet_size == wbs_supported_packet_size[i]) in hfp_info_start()
777 info->packet_size); in hfp_info_start()
780 info->packet_size = wbs_supported_packet_size[i]; in hfp_info_start()
781 info->write_buf = (uint8_t *)malloc(wbs_hci_sco_buffer_size[i]); in hfp_info_start()
782 info->read_buf = (uint8_t *)malloc(wbs_hci_sco_buffer_size[i]); in hfp_info_start()
784 info->write_cb = hfp_write_msbc; in hfp_info_start()
785 info->read_cb = hfp_read_msbc; in hfp_info_start()
786 info->msbc_read = cras_msbc_codec_create(); in hfp_info_start()
787 info->msbc_write = cras_msbc_codec_create(); in hfp_info_start()
788 info->msbc_plc = cras_msbc_plc_create(); in hfp_info_start()
790 packet_status_logger_init(info->wbs_logger); in hfp_info_start()
792 info->write_cb = hfp_write; in hfp_info_start()
793 info->read_cb = hfp_read; in hfp_info_start()
796 audio_thread_add_events_callback(info->fd, hfp_info_callback, info, in hfp_info_start()
799 info->started = 1; in hfp_info_start()
800 info->msbc_num_out_frames = 0; in hfp_info_start()
801 info->msbc_num_in_frames = 0; in hfp_info_start()
802 info->msbc_num_lost_frames = 0; in hfp_info_start()
803 info->write_rp = 0; in hfp_info_start()
804 info->write_wp = 0; in hfp_info_start()
805 info->read_rp = 0; in hfp_info_start()
806 info->read_wp = 0; in hfp_info_start()
809 info->read_align_cb = in hfp_info_start()
810 (info->packet_size == MSBC_PKT_SIZE) ? NULL : msbc_frame_align; in hfp_info_start()
811 info->msbc_read_current_corrupted = 0; in hfp_info_start()
816 int hfp_info_stop(struct hfp_info *info) in hfp_info_stop() argument
818 if (!info->started) in hfp_info_stop()
822 info->fd); in hfp_info_stop()
824 close(info->fd); in hfp_info_stop()
825 info->fd = 0; in hfp_info_stop()
826 info->started = 0; in hfp_info_stop()
829 info->write_cb = NULL; in hfp_info_stop()
830 info->read_cb = NULL; in hfp_info_stop()
832 if (info->write_buf) in hfp_info_stop()
833 free(info->write_buf); in hfp_info_stop()
834 if (info->read_buf) in hfp_info_stop()
835 free(info->read_buf); in hfp_info_stop()
837 if (info->msbc_read) { in hfp_info_stop()
838 cras_sbc_codec_destroy(info->msbc_read); in hfp_info_stop()
839 info->msbc_read = NULL; in hfp_info_stop()
841 if (info->msbc_write) { in hfp_info_stop()
842 cras_sbc_codec_destroy(info->msbc_write); in hfp_info_stop()
843 info->msbc_write = NULL; in hfp_info_stop()
845 if (info->msbc_plc) { in hfp_info_stop()
846 cras_msbc_plc_destroy(info->msbc_plc); in hfp_info_stop()
847 info->msbc_plc = NULL; in hfp_info_stop()
850 if (info->msbc_num_in_frames) { in hfp_info_stop()
852 (float)info->msbc_num_lost_frames / in hfp_info_stop()
853 info->msbc_num_in_frames); in hfp_info_stop()
859 void hfp_info_destroy(struct hfp_info *info) in hfp_info_destroy() argument
861 if (info->capture_buf) in hfp_info_destroy()
862 byte_buffer_destroy(&info->capture_buf); in hfp_info_destroy()
864 if (info->playback_buf) in hfp_info_destroy()
865 byte_buffer_destroy(&info->playback_buf); in hfp_info_destroy()
867 free(info); in hfp_info_destroy()