Skip to content

Commit 71d59b1

Browse files
Bluetooth: A2DP: implement reconfig and optimize codes
Implement the bt_a2dp_stream_reconfig: Modify reconfig_req callback to pass codec_cfg to application. Remove reconfig_rsp callback, config_rsp is used. Remove reconfigured callback, configured callback is used. move the status to common struct bt_avdtp_req, use same bt_avdtp_ctrl_params to process control-like avdtp cmds (start, open etc), use the same a2dp_ctrl_ind to process control-like cmds (start, open etc), use the same bt_a2dp_ctrl_cb to process control-like cmds (start, open etc), use the same bt_avdtp_ctrl to process control-like cmds (start, open etc), optimize getting a2dp conn by index, use sem to replace mutex and optimze the lock codes to be based on context/instance. Signed-off-by: Mark Wang <[email protected]>
1 parent efb3629 commit 71d59b1

File tree

5 files changed

+575
-622
lines changed

5 files changed

+575
-622
lines changed

include/zephyr/bluetooth/classic/a2dp.h

Lines changed: 31 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@
2121
extern "C" {
2222
#endif
2323

24-
#define BT_A2DP_STREAM_BUF_RESERVE (12u + BT_L2CAP_BUF_SIZE(0))
24+
#define BT_A2DP_STREAM_BUF_RESERVE (12U + BT_L2CAP_BUF_SIZE(0))
2525

2626
/** SBC IE length */
27-
#define BT_A2DP_SBC_IE_LENGTH (4u)
27+
#define BT_A2DP_SBC_IE_LENGTH (4U)
2828
/** MPEG1,2 IE length */
29-
#define BT_A2DP_MPEG_1_2_IE_LENGTH (4u)
29+
#define BT_A2DP_MPEG_1_2_IE_LENGTH (4U)
3030
/** MPEG2,4 IE length */
31-
#define BT_A2DP_MPEG_2_4_IE_LENGTH (6u)
31+
#define BT_A2DP_MPEG_2_4_IE_LENGTH (6U)
3232
/** The max IE (Codec Info Element) length */
33-
#define A2DP_MAX_IE_LENGTH (8U)
33+
#define BT_A2DP_MAX_IE_LENGTH (8U)
3434

3535
/** @brief define the audio endpoint
3636
* @param _role BT_AVDTP_SOURCE or BT_AVDTP_SINK.
@@ -314,7 +314,7 @@ struct bt_a2dp_codec_ie {
314314
/** Length of codec_cap */
315315
uint8_t len;
316316
/** codec information element */
317-
uint8_t codec_ie[A2DP_MAX_IE_LENGTH];
317+
uint8_t codec_ie[BT_A2DP_MAX_IE_LENGTH];
318318
};
319319

320320
/** @brief The endpoint configuration */
@@ -432,7 +432,21 @@ struct bt_a2dp_cb {
432432
int (*config_req)(struct bt_a2dp *a2dp, struct bt_a2dp_ep *ep,
433433
struct bt_a2dp_codec_cfg *codec_cfg, struct bt_a2dp_stream **stream,
434434
uint8_t *rsp_err_code);
435-
/** @brief Callback function for bt_a2dp_stream_config()
435+
/**
436+
* @brief Endpoint config request callback
437+
*
438+
* The callback is called whenever an endpoint is requested to be
439+
* reconfigured.
440+
*
441+
* @param[in] stream Pointer to stream object.
442+
* @param[out] rsp_err_code give the error code if response error.
443+
* bt_a2dp_err_code or bt_avdtp_err_code
444+
*
445+
* @return 0 in case of success or negative value in case of error.
446+
*/
447+
int (*reconfig_req)(struct bt_a2dp_stream *stream, struct bt_a2dp_codec_cfg *codec_cfg,
448+
uint8_t *rsp_err_code);
449+
/** @brief Callback function for bt_a2dp_stream_config() and bt_a2dp_stream_reconfig()
436450
*
437451
* Called when the codec configure operation is completed.
438452
*
@@ -442,7 +456,7 @@ struct bt_a2dp_cb {
442456
*/
443457
void (*config_rsp)(struct bt_a2dp_stream *stream, uint8_t rsp_err_code);
444458
/**
445-
* @brief stream establishment request callback
459+
* @brief Stream establishment request callback
446460
*
447461
* The callback is called whenever an stream is requested to be
448462
* established (open cmd and create the stream l2cap channel).
@@ -465,7 +479,7 @@ struct bt_a2dp_cb {
465479
*/
466480
void (*establish_rsp)(struct bt_a2dp_stream *stream, uint8_t rsp_err_code);
467481
/**
468-
* @brief stream release request callback
482+
* @brief Stream release request callback
469483
*
470484
* The callback is called whenever an stream is requested to be
471485
* released (release cmd and release the l2cap channel)
@@ -488,7 +502,7 @@ struct bt_a2dp_cb {
488502
*/
489503
void (*release_rsp)(struct bt_a2dp_stream *stream, uint8_t rsp_err_code);
490504
/**
491-
* @brief stream start request callback
505+
* @brief Stream start request callback
492506
*
493507
* The callback is called whenever an stream is requested to be
494508
* started.
@@ -510,7 +524,7 @@ struct bt_a2dp_cb {
510524
*/
511525
void (*start_rsp)(struct bt_a2dp_stream *stream, uint8_t rsp_err_code);
512526
/**
513-
* @brief Endpoint suspend request callback
527+
* @brief Stream suspend request callback
514528
*
515529
* The callback is called whenever an stream is requested to be
516530
* suspended.
@@ -531,28 +545,6 @@ struct bt_a2dp_cb {
531545
* bt_a2dp_err_code or bt_avdtp_err_code
532546
*/
533547
void (*suspend_rsp)(struct bt_a2dp_stream *stream, uint8_t rsp_err_code);
534-
/**
535-
* @brief Endpoint config request callback
536-
*
537-
* The callback is called whenever an endpoint is requested to be
538-
* reconfigured.
539-
*
540-
* @param[in] stream Pointer to stream object.
541-
* @param[out] rsp_err_code give the error code if response error.
542-
* bt_a2dp_err_code or bt_avdtp_err_code
543-
*
544-
* @return 0 in case of success or negative value in case of error.
545-
*/
546-
int (*reconfig_req)(struct bt_a2dp_stream *stream, uint8_t *rsp_err_code);
547-
/** @brief Callback function for bt_a2dp_stream_reconfig()
548-
*
549-
* Called when the reconfig operation is completed.
550-
*
551-
* @param[in] stream Pointer to stream object.
552-
* @param[in] rsp_err_code the remote responded error code
553-
* bt_a2dp_err_code or bt_avdtp_err_code
554-
*/
555-
void (*reconfig_rsp)(struct bt_a2dp_stream *stream, uint8_t rsp_err_code);
556548
};
557549

558550
/** @brief A2DP Connect.
@@ -585,12 +577,12 @@ int bt_a2dp_disconnect(struct bt_a2dp *a2dp);
585577
/** @brief Endpoint Registration.
586578
*
587579
* @param ep Pointer to bt_a2dp_ep structure.
588-
* @param media_type Media type that the Endpoint is.
589-
* @param role Role of Endpoint.
580+
* @param media_type Media type that the Endpoint is, #bt_avdtp_media_type.
581+
* @param sep_type Stream endpoint type, #bt_avdtp_sep_type.
590582
*
591583
* @return 0 in case of success and error code in case of error.
592584
*/
593-
int bt_a2dp_register_ep(struct bt_a2dp_ep *ep, uint8_t media_type, uint8_t role);
585+
int bt_a2dp_register_ep(struct bt_a2dp_ep *ep, uint8_t media_type, uint8_t sep_type);
594586

595587
/** @brief register callback.
596588
*
@@ -632,7 +624,7 @@ struct bt_a2dp_stream_ops {
632624
/**
633625
* @brief Stream configured callback
634626
*
635-
* The callback is called whenever an Audio Stream has been configured.
627+
* The callback is called whenever an Audio Stream has been configured or reconfigured.
636628
*
637629
* @param stream Stream object that has been configured.
638630
*/
@@ -649,6 +641,7 @@ struct bt_a2dp_stream_ops {
649641
* @brief Stream release callback
650642
*
651643
* The callback is called whenever an Audio Stream has been released.
644+
* After released, the stream becomes invalid.
652645
*
653646
* @param stream Stream object that has been released.
654647
*/
@@ -669,14 +662,6 @@ struct bt_a2dp_stream_ops {
669662
* @param stream Stream object that has been suspended.
670663
*/
671664
void (*suspended)(struct bt_a2dp_stream *stream);
672-
/**
673-
* @brief Stream reconfigured callback
674-
*
675-
* The callback is called whenever an Audio Stream has been reconfigured.
676-
*
677-
* @param stream Stream object that has been reconfigured.
678-
*/
679-
void (*reconfigured)(struct bt_a2dp_stream *stream);
680665
#if defined(CONFIG_BT_A2DP_SINK)
681666
/** @brief the media streaming data, only for sink
682667
*
@@ -746,6 +731,7 @@ int bt_a2dp_stream_establish(struct bt_a2dp_stream *stream);
746731
/** @brief release a2dp streamer.
747732
*
748733
* This function sends the AVDTP_CLOSE command and release the l2cap channel.
734+
* After release, the stream becomes invalid.
749735
*
750736
* @param stream The stream object.
751737
*

include/zephyr/bluetooth/classic/avdtp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ struct bt_avdtp_sep {
128128
struct bt_l2cap_br_chan chan;
129129
/** the endpoint media data */
130130
void (*media_data_cb)(struct bt_avdtp_sep *sep, struct net_buf *buf);
131+
/* semaphore for lock/unlock */
132+
struct k_sem sem_lock;
131133
/** avdtp session */
132134
struct bt_avdtp *session;
133135
/** SEP state */

0 commit comments

Comments
 (0)