Lines Matching full:stream
1 /* Bluetooth Audio Stream */
63 void bt_bap_stream_init(struct bt_bap_stream *stream) in bt_bap_stream_init() argument
68 /* Save the stream->ops and stream->user_data owned by API user */ in bt_bap_stream_init()
69 ops = stream->ops; in bt_bap_stream_init()
70 user_data = stream->user_data; in bt_bap_stream_init()
72 memset(stream, 0, sizeof(*stream)); in bt_bap_stream_init()
75 stream->ops = ops; in bt_bap_stream_init()
76 stream->user_data = user_data; in bt_bap_stream_init()
79 void bt_bap_stream_attach(struct bt_conn *conn, struct bt_bap_stream *stream, struct bt_bap_ep *ep, in bt_bap_stream_attach() argument
82 LOG_DBG("conn %p stream %p ep %p codec_cfg %p", (void *)conn, stream, ep, codec_cfg); in bt_bap_stream_attach()
85 __ASSERT(stream->conn == NULL || stream->conn == conn, in bt_bap_stream_attach()
86 "stream->conn %p already attached", (void *)stream->conn); in bt_bap_stream_attach()
87 if (stream->conn == NULL) { in bt_bap_stream_attach()
88 stream->conn = bt_conn_ref(conn); in bt_bap_stream_attach()
91 stream->codec_cfg = codec_cfg; in bt_bap_stream_attach()
92 stream->ep = ep; in bt_bap_stream_attach()
93 ep->stream = stream; in bt_bap_stream_attach()
96 struct bt_iso_chan *bt_bap_stream_iso_chan_get(struct bt_bap_stream *stream) in bt_bap_stream_iso_chan_get() argument
98 if (stream != NULL && stream->ep != NULL && stream->ep->iso != NULL) { in bt_bap_stream_iso_chan_get()
99 return &stream->ep->iso->chan; in bt_bap_stream_iso_chan_get()
105 void bt_bap_stream_cb_register(struct bt_bap_stream *stream, in bt_bap_stream_cb_register() argument
108 stream->ops = ops; in bt_bap_stream_cb_register()
144 if (IS_ENABLED(CONFIG_BT_AUDIO_TX) && ep->stream != NULL) { in bt_bap_ep_get_info()
153 if (ep->stream->conn != NULL) { in bt_bap_ep_get_info()
159 if (ep->stream->conn != NULL) { in bt_bap_ep_get_info()
341 static bool bt_bap_stream_can_send(const struct bt_bap_stream *stream) in bt_bap_stream_can_send() argument
346 if (stream == NULL || stream->ep == NULL) { in bt_bap_stream_can_send()
350 err = bt_bap_ep_get_info(stream->ep, &info); in bt_bap_stream_can_send()
358 static int bap_stream_send(struct bt_bap_stream *stream, struct net_buf *buf, uint16_t seq_num, in bap_stream_send() argument
365 if (stream == NULL) { in bap_stream_send()
366 LOG_DBG("stream is NULL"); in bap_stream_send()
370 if (stream->ep == NULL) { in bap_stream_send()
371 LOG_DBG("stream->ep %p is NULL", stream); in bap_stream_send()
375 if (!bt_bap_stream_can_send(stream)) { in bap_stream_send()
376 LOG_DBG("Stream is not configured for TX"); in bap_stream_send()
381 ep = stream->ep; in bap_stream_send()
384 LOG_DBG("Channel %p not ready for streaming (state: %s)", stream, in bap_stream_send()
389 iso_chan = bt_bap_stream_iso_chan_get(stream); in bap_stream_send()
402 if (stream->_prev_seq_num != 0U && seq_num != 0U && in bap_stream_send()
403 (stream->_prev_seq_num + 1U) != seq_num) { in bap_stream_send()
404 LOG_WRN("Unexpected seq_num diff between %u and %u for %p", stream->_prev_seq_num, in bap_stream_send()
405 seq_num, stream); in bap_stream_send()
408 stream->_prev_seq_num = seq_num; in bap_stream_send()
414 int bt_bap_stream_send(struct bt_bap_stream *stream, struct net_buf *buf, uint16_t seq_num) in bt_bap_stream_send() argument
416 return bap_stream_send(stream, buf, seq_num, 0, false); in bt_bap_stream_send()
419 int bt_bap_stream_send_ts(struct bt_bap_stream *stream, struct net_buf *buf, uint16_t seq_num, in bt_bap_stream_send_ts() argument
422 return bap_stream_send(stream, buf, seq_num, ts, true); in bt_bap_stream_send_ts()
425 int bt_bap_stream_get_tx_sync(struct bt_bap_stream *stream, struct bt_iso_tx_info *info) in bt_bap_stream_get_tx_sync() argument
429 CHECKIF(stream == NULL) { in bt_bap_stream_get_tx_sync()
430 LOG_DBG("stream is null"); in bt_bap_stream_get_tx_sync()
441 if (!bt_bap_stream_can_send(stream)) { in bt_bap_stream_get_tx_sync()
442 LOG_DBG("Stream is not configured for TX"); in bt_bap_stream_get_tx_sync()
447 iso_chan = bt_bap_stream_iso_chan_get(stream); in bt_bap_stream_get_tx_sync()
449 LOG_DBG("Could not get iso channel from stream %p", stream); in bt_bap_stream_get_tx_sync()
459 /** Checks if the stream can terminate the CIS
461 * If the CIS is used for another stream, or if the CIS is not in the connected
464 bool bt_bap_stream_can_disconnect(const struct bt_bap_stream *stream) in bt_bap_stream_can_disconnect() argument
469 if (stream == NULL) { in bt_bap_stream_can_disconnect()
473 stream_ep = stream->ep; in bt_bap_stream_can_disconnect()
497 static bool bt_bap_stream_is_broadcast(const struct bt_bap_stream *stream) in bt_bap_stream_is_broadcast() argument
500 bt_bap_ep_is_broadcast_src(stream->ep)) || in bt_bap_stream_is_broadcast()
501 (IS_ENABLED(CONFIG_BT_BAP_BROADCAST_SINK) && bt_bap_ep_is_broadcast_snk(stream->ep)); in bt_bap_stream_is_broadcast()
504 enum bt_bap_ascs_reason bt_bap_stream_verify_qos(const struct bt_bap_stream *stream, in bt_bap_stream_verify_qos() argument
507 const struct bt_bap_qos_cfg_pref *qos_pref = &stream->ep->qos_pref; in bt_bap_stream_verify_qos()
523 void bt_bap_stream_detach(struct bt_bap_stream *stream) in bt_bap_stream_detach() argument
525 const bool is_broadcast = bt_bap_stream_is_broadcast(stream); in bt_bap_stream_detach()
527 LOG_DBG("stream %p conn %p ep %p", stream, (void *)stream->conn, (void *)stream->ep); in bt_bap_stream_detach()
529 if (stream->conn != NULL) { in bt_bap_stream_detach()
530 bt_conn_unref(stream->conn); in bt_bap_stream_detach()
531 stream->conn = NULL; in bt_bap_stream_detach()
533 stream->codec_cfg = NULL; in bt_bap_stream_detach()
534 stream->ep->stream = NULL; in bt_bap_stream_detach()
535 stream->ep = NULL; in bt_bap_stream_detach()
538 const int err = bt_bap_stream_disconnect(stream); in bt_bap_stream_detach()
541 LOG_DBG("Failed to disconnect stream %p: %d", stream, err); in bt_bap_stream_detach()
546 int bt_bap_stream_disconnect(struct bt_bap_stream *stream) in bt_bap_stream_disconnect() argument
550 LOG_DBG("stream %p", stream); in bt_bap_stream_disconnect()
552 if (stream == NULL) { in bt_bap_stream_disconnect()
556 iso_chan = bt_bap_stream_iso_chan_get(stream); in bt_bap_stream_disconnect()
566 void bt_bap_stream_reset(struct bt_bap_stream *stream) in bt_bap_stream_reset() argument
568 LOG_DBG("stream %p", stream); in bt_bap_stream_reset()
570 if (stream == NULL) { in bt_bap_stream_reset()
574 if (stream->ep != NULL && stream->ep->iso != NULL) { in bt_bap_stream_reset()
575 bt_bap_iso_unbind_ep(stream->ep->iso, stream->ep); in bt_bap_stream_reset()
578 bt_bap_stream_detach(stream); in bt_bap_stream_reset()
594 int bt_bap_stream_config(struct bt_conn *conn, struct bt_bap_stream *stream, struct bt_bap_ep *ep, in bt_bap_stream_config() argument
600 LOG_DBG("conn %p stream %p, ep %p codec_cfg %p codec id 0x%02x " in bt_bap_stream_config()
601 "codec cid 0x%04x codec vid 0x%04x", (void *)conn, stream, ep, in bt_bap_stream_config()
605 CHECKIF(conn == NULL || stream == NULL || codec_cfg == NULL || ep == NULL) { in bt_bap_stream_config()
610 if (stream->conn != NULL) { in bt_bap_stream_config()
611 LOG_DBG("Stream already configured for conn %p", (void *)stream->conn); in bt_bap_stream_config()
634 bt_bap_stream_attach(conn, stream, ep, codec_cfg); in bt_bap_stream_config()
636 err = bt_bap_unicast_client_config(stream, codec_cfg); in bt_bap_stream_config()
638 LOG_DBG("Failed to configure stream: %d", err); in bt_bap_stream_config()
663 LOG_DBG("group stream list is empty"); in bt_bap_stream_qos()
675 LOG_DBG("Failed to configure stream: %d", err); in bt_bap_stream_qos()
682 int bt_bap_stream_enable(struct bt_bap_stream *stream, const uint8_t meta[], size_t meta_len) in bt_bap_stream_enable() argument
687 LOG_DBG("stream %p", stream); in bt_bap_stream_enable()
689 if (stream == NULL || stream->ep == NULL || stream->conn == NULL) { in bt_bap_stream_enable()
690 LOG_DBG("Invalid stream"); in bt_bap_stream_enable()
694 role = conn_get_role(stream->conn); in bt_bap_stream_enable()
701 if (stream->ep->status.state != BT_BAP_EP_STATE_QOS_CONFIGURED) { in bt_bap_stream_enable()
702 LOG_ERR("Invalid state: %s", bt_bap_ep_state_str(stream->ep->status.state)); in bt_bap_stream_enable()
706 err = bt_bap_unicast_client_enable(stream, meta, meta_len); in bt_bap_stream_enable()
708 LOG_DBG("Failed to enable stream: %d", err); in bt_bap_stream_enable()
715 int bt_bap_stream_stop(struct bt_bap_stream *stream) in bt_bap_stream_stop() argument
721 if (stream == NULL || stream->ep == NULL || stream->conn == NULL) { in bt_bap_stream_stop()
722 LOG_DBG("Invalid stream"); in bt_bap_stream_stop()
726 role = conn_get_role(stream->conn); in bt_bap_stream_stop()
732 ep = stream->ep; in bt_bap_stream_stop()
743 err = bt_bap_unicast_client_stop(stream); in bt_bap_stream_stop()
745 LOG_DBG("Stopping stream failed: %d", err); in bt_bap_stream_stop()
753 int bt_bap_stream_reconfig(struct bt_bap_stream *stream, in bt_bap_stream_reconfig() argument
760 LOG_DBG("stream %p codec_cfg %p", stream, codec_cfg); in bt_bap_stream_reconfig()
762 CHECKIF(stream == NULL || stream->ep == NULL || stream->conn == NULL) { in bt_bap_stream_reconfig()
763 LOG_DBG("Invalid stream"); in bt_bap_stream_reconfig()
772 state = stream->ep->status.state; in bt_bap_stream_reconfig()
786 role = conn_get_role(stream->conn); in bt_bap_stream_reconfig()
788 err = bt_bap_unicast_client_config(stream, codec_cfg); in bt_bap_stream_reconfig()
790 err = bt_bap_unicast_server_reconfig(stream, codec_cfg); in bt_bap_stream_reconfig()
796 LOG_DBG("reconfiguring stream failed: %d", err); in bt_bap_stream_reconfig()
798 stream->codec_cfg = codec_cfg; in bt_bap_stream_reconfig()
805 int bt_bap_stream_connect(struct bt_bap_stream *stream) in bt_bap_stream_connect() argument
809 LOG_DBG("stream %p ep %p", stream, stream == NULL ? NULL : stream->ep); in bt_bap_stream_connect()
811 CHECKIF(stream == NULL || stream->ep == NULL || stream->conn == NULL) { in bt_bap_stream_connect()
812 LOG_DBG("Invalid stream"); in bt_bap_stream_connect()
819 state = stream->ep->status.state; in bt_bap_stream_connect()
829 /* Only a unicast client can connect a stream */ in bt_bap_stream_connect()
830 if (conn_get_role(stream->conn) == BT_HCI_ROLE_CENTRAL) { in bt_bap_stream_connect()
831 return bt_bap_unicast_client_connect(stream); in bt_bap_stream_connect()
838 int bt_bap_stream_start(struct bt_bap_stream *stream) in bt_bap_stream_start() argument
844 LOG_DBG("stream %p ep %p", stream, stream == NULL ? NULL : stream->ep); in bt_bap_stream_start()
846 CHECKIF(stream == NULL || stream->ep == NULL || stream->conn == NULL) { in bt_bap_stream_start()
847 LOG_DBG("Invalid stream"); in bt_bap_stream_start()
851 state = stream->ep->status.state; in bt_bap_stream_start()
861 role = conn_get_role(stream->conn); in bt_bap_stream_start()
863 err = bt_bap_unicast_client_start(stream); in bt_bap_stream_start()
865 err = bt_bap_unicast_server_start(stream); in bt_bap_stream_start()
871 LOG_DBG("Starting stream failed: %d", err); in bt_bap_stream_start()
878 int bt_bap_stream_metadata(struct bt_bap_stream *stream, const uint8_t meta[], size_t meta_len) in bt_bap_stream_metadata() argument
884 LOG_DBG("stream %p meta_len %zu", stream, meta_len); in bt_bap_stream_metadata()
886 CHECKIF(stream == NULL || stream->ep == NULL || stream->conn == NULL) { in bt_bap_stream_metadata()
887 LOG_DBG("Invalid stream"); in bt_bap_stream_metadata()
896 state = stream->ep->status.state; in bt_bap_stream_metadata()
908 role = conn_get_role(stream->conn); in bt_bap_stream_metadata()
910 err = bt_bap_unicast_client_metadata(stream, meta, meta_len); in bt_bap_stream_metadata()
912 err = bt_bap_unicast_server_metadata(stream, meta, meta_len); in bt_bap_stream_metadata()
925 int bt_bap_stream_disable(struct bt_bap_stream *stream) in bt_bap_stream_disable() argument
931 LOG_DBG("stream %p", stream); in bt_bap_stream_disable()
933 CHECKIF(stream == NULL || stream->ep == NULL || stream->conn == NULL) { in bt_bap_stream_disable()
934 LOG_DBG("Invalid stream"); in bt_bap_stream_disable()
938 state = stream->ep->status.state; in bt_bap_stream_disable()
950 role = conn_get_role(stream->conn); in bt_bap_stream_disable()
952 err = bt_bap_unicast_client_disable(stream); in bt_bap_stream_disable()
954 err = bt_bap_unicast_server_disable(stream); in bt_bap_stream_disable()
960 LOG_DBG("Disabling stream failed: %d", err); in bt_bap_stream_disable()
967 int bt_bap_stream_release(struct bt_bap_stream *stream) in bt_bap_stream_release() argument
973 LOG_DBG("stream %p", stream); in bt_bap_stream_release()
975 CHECKIF(stream == NULL || stream->ep == NULL || stream->conn == NULL) { in bt_bap_stream_release()
976 LOG_DBG("Invalid stream (ep %p, conn %p)", stream->ep, (void *)stream->conn); in bt_bap_stream_release()
980 state = stream->ep->status.state; in bt_bap_stream_release()
998 role = conn_get_role(stream->conn); in bt_bap_stream_release()
1000 err = bt_bap_unicast_client_release(stream); in bt_bap_stream_release()
1002 err = bt_bap_unicast_server_release(stream); in bt_bap_stream_release()
1008 LOG_DBG("Releasing stream failed: %d", err); in bt_bap_stream_release()