@@ -98,7 +98,7 @@ static struct bt_sdp_attribute a2dp_sink_attrs[] = {
9898 },
9999 {
100100 BT_SDP_TYPE_SIZE (BT_SDP_UINT16 ), /* 09 */
101- BT_SDP_ARRAY_16 (0X0100u ) /* AVDTP version: 01 00 */
101+ BT_SDP_ARRAY_16 (0x0100U ) /* AVDTP version: 01 00 */
102102 },
103103 )
104104 },
@@ -167,7 +167,7 @@ static struct bt_sdp_attribute a2dp_source_attrs[] = {
167167 },
168168 {
169169 BT_SDP_TYPE_SIZE (BT_SDP_UINT16 ),
170- BT_SDP_ARRAY_16 (0X0100u )
170+ BT_SDP_ARRAY_16 (0x0100U )
171171 },
172172 )
173173 },
@@ -306,21 +306,31 @@ int app_config_req(struct bt_a2dp *a2dp, struct bt_a2dp_ep *ep,
306306 struct bt_a2dp_codec_cfg * codec_cfg , struct bt_a2dp_stream * * stream ,
307307 uint8_t * rsp_err_code )
308308{
309+ uint32_t sample_rate ;
310+
309311 bt_a2dp_stream_cb_register (& sbc_stream , & stream_ops );
310312 * stream = & sbc_stream ;
311313 * rsp_err_code = 0 ;
312314
313315 shell_print (ctx_shell , "receive requesting config and accept" );
314- if (* rsp_err_code == 0 ) {
315- uint32_t sample_rate ;
316+ sample_rate = bt_a2dp_sbc_get_sampling_frequency (
317+ (struct bt_a2dp_codec_sbc_params * )& codec_cfg -> codec_config -> codec_ie [0 ]);
318+ shell_print (ctx_shell , "sample rate %dHz" , sample_rate );
319+
320+ return 0 ;
321+ }
322+
323+ int app_reconfig_req (struct bt_a2dp_stream * stream ,
324+ struct bt_a2dp_codec_cfg * codec_cfg , uint8_t * rsp_err_code )
325+ {
326+ uint32_t sample_rate ;
327+
328+ * rsp_err_code = 0 ;
329+ shell_print (ctx_shell , "receive requesting reconfig and accept" );
330+ sample_rate = bt_a2dp_sbc_get_sampling_frequency (
331+ (struct bt_a2dp_codec_sbc_params * )& codec_cfg -> codec_config -> codec_ie [0 ]);
332+ shell_print (ctx_shell , "sample rate %dHz" , sample_rate );
316333
317- shell_print (ctx_shell , "SBC configure success" );
318- sample_rate = bt_a2dp_sbc_get_sampling_frequency (
319- (struct bt_a2dp_codec_sbc_params * )& codec_cfg -> codec_config -> codec_ie [0 ]);
320- shell_print (ctx_shell , "sample rate %dHz" , sample_rate );
321- } else {
322- shell_print (ctx_shell , "configure err" );
323- }
324334 return 0 ;
325335}
326336
@@ -349,6 +359,22 @@ void app_establish_rsp(struct bt_a2dp_stream *stream, uint8_t rsp_err_code)
349359 }
350360}
351361
362+ int app_release_req (struct bt_a2dp_stream * stream , uint8_t * rsp_err_code )
363+ {
364+ * rsp_err_code = 0 ;
365+ shell_print (ctx_shell , "receive requesting release and accept" );
366+ return 0 ;
367+ }
368+
369+ void app_release_rsp (struct bt_a2dp_stream * stream , uint8_t rsp_err_code )
370+ {
371+ if (rsp_err_code == 0 ) {
372+ shell_print (ctx_shell , "success to release" );
373+ } else {
374+ shell_print (ctx_shell , "fail to release" );
375+ }
376+ }
377+
352378int app_start_req (struct bt_a2dp_stream * stream , uint8_t * rsp_err_code )
353379{
354380 * rsp_err_code = 0 ;
@@ -365,6 +391,22 @@ void app_start_rsp(struct bt_a2dp_stream *stream, uint8_t rsp_err_code)
365391 }
366392}
367393
394+ int app_suspend_req (struct bt_a2dp_stream * stream , uint8_t * rsp_err_code )
395+ {
396+ * rsp_err_code = 0 ;
397+ shell_print (ctx_shell , "receive requesting suspend and accept" );
398+ return 0 ;
399+ }
400+
401+ void app_suspend_rsp (struct bt_a2dp_stream * stream , uint8_t rsp_err_code )
402+ {
403+ if (rsp_err_code == 0 ) {
404+ shell_print (ctx_shell , "success to suspend" );
405+ } else {
406+ shell_print (ctx_shell , "fail to suspend" );
407+ }
408+ }
409+
368410void stream_configured (struct bt_a2dp_stream * stream )
369411{
370412 shell_print (ctx_shell , "stream configured" );
@@ -385,11 +427,24 @@ void stream_started(struct bt_a2dp_stream *stream)
385427 shell_print (ctx_shell , "stream started" );
386428}
387429
430+ void stream_suspended (struct bt_a2dp_stream * stream )
431+ {
432+ shell_print (ctx_shell , "stream suspended" );
433+ }
434+
435+ void stream_aborted (struct bt_a2dp_stream * stream )
436+ {
437+ shell_print (ctx_shell , "stream aborted" );
438+ }
439+
388440void sink_sbc_streamer_data (struct bt_a2dp_stream * stream , struct net_buf * buf ,
389441 uint16_t seq_num , uint32_t ts )
390442{
391443 uint8_t sbc_hdr ;
392444
445+ if (buf -> len < 1U ) {
446+ return ;
447+ }
393448 sbc_hdr = net_buf_pull_u8 (buf );
394449 shell_print (ctx_shell , "received, num of frames: %d, data length:%d" ,
395450 (uint8_t )BT_A2DP_SBC_MEDIA_HDR_NUM_FRAMES_GET (sbc_hdr ), buf -> len );
@@ -410,14 +465,13 @@ struct bt_a2dp_cb a2dp_cb = {
410465 .config_rsp = app_config_rsp ,
411466 .establish_req = app_establish_req ,
412467 .establish_rsp = app_establish_rsp ,
413- .release_req = NULL ,
414- .release_rsp = NULL ,
468+ .release_req = app_release_req ,
469+ .release_rsp = app_release_rsp ,
415470 .start_req = app_start_req ,
416471 .start_rsp = app_start_rsp ,
417- .suspend_req = NULL ,
418- .suspend_rsp = NULL ,
419- .reconfig_req = NULL ,
420- .reconfig_rsp = NULL ,
472+ .suspend_req = app_suspend_req ,
473+ .suspend_rsp = app_suspend_rsp ,
474+ .reconfig_req = app_reconfig_req ,
421475};
422476
423477static int cmd_register_cb (const struct shell * sh , int32_t argc , char * argv [])
@@ -539,8 +593,8 @@ static struct bt_a2dp_stream_ops stream_ops = {
539593 .established = stream_established ,
540594 .released = stream_released ,
541595 .started = stream_started ,
542- .suspended = NULL ,
543- .reconfigured = NULL ,
596+ .suspended = stream_suspended ,
597+ .aborted = stream_aborted ,
544598#if defined(CONFIG_BT_A2DP_SINK )
545599 .recv = stream_recv ,
546600#endif
@@ -584,6 +638,19 @@ static int cmd_configure(const struct shell *sh, int32_t argc, char *argv[])
584638 return 0 ;
585639}
586640
641+ static int cmd_reconfigure (const struct shell * sh , int32_t argc , char * argv [])
642+ {
643+ if (a2dp_initied == 0 ) {
644+ shell_print (sh , "need to register a2dp connection callbacks" );
645+ return - ENOEXEC ;
646+ }
647+
648+ if (bt_a2dp_stream_reconfig (& sbc_stream , & sbc_cfg_default ) != 0 ) {
649+ shell_print (sh , "fail" );
650+ }
651+ return 0 ;
652+ }
653+
587654static uint8_t bt_a2dp_discover_peer_endpoint_cb (struct bt_a2dp * a2dp ,
588655 struct bt_a2dp_ep_info * info , struct bt_a2dp_ep * * ep )
589656{
@@ -639,6 +706,19 @@ static int cmd_establish(const struct shell *sh, int32_t argc, char *argv[])
639706 return 0 ;
640707}
641708
709+ static int cmd_release (const struct shell * sh , int32_t argc , char * argv [])
710+ {
711+ if (a2dp_initied == 0 ) {
712+ shell_print (sh , "need to register a2dp connection callbacks" );
713+ return - ENOEXEC ;
714+ }
715+
716+ if (bt_a2dp_stream_release (& sbc_stream ) != 0 ) {
717+ shell_print (sh , "fail" );
718+ }
719+ return 0 ;
720+ }
721+
642722static int cmd_start (const struct shell * sh , int32_t argc , char * argv [])
643723{
644724 if (a2dp_initied == 0 ) {
@@ -652,6 +732,32 @@ static int cmd_start(const struct shell *sh, int32_t argc, char *argv[])
652732 return 0 ;
653733}
654734
735+ static int cmd_suspend (const struct shell * sh , int32_t argc , char * argv [])
736+ {
737+ if (a2dp_initied == 0 ) {
738+ shell_print (sh , "need to register a2dp connection callbacks" );
739+ return - ENOEXEC ;
740+ }
741+
742+ if (bt_a2dp_stream_suspend (& sbc_stream ) != 0 ) {
743+ shell_print (sh , "fail" );
744+ }
745+ return 0 ;
746+ }
747+
748+ static int cmd_abort (const struct shell * sh , int32_t argc , char * argv [])
749+ {
750+ if (a2dp_initied == 0 ) {
751+ shell_print (sh , "need to register a2dp connection callbacks" );
752+ return - ENOEXEC ;
753+ }
754+
755+ if (bt_a2dp_stream_abort (& sbc_stream ) != 0 ) {
756+ shell_print (sh , "fail" );
757+ }
758+ return 0 ;
759+ }
760+
655761static int cmd_send_media (const struct shell * sh , int32_t argc , char * argv [])
656762{
657763#if defined(CONFIG_BT_A2DP_SOURCE )
@@ -669,11 +775,11 @@ static int cmd_send_media(const struct shell *sh, int32_t argc, char *argv[])
669775 /* num of frames is 1 */
670776 net_buf_add_u8 (buf , (uint8_t )BT_A2DP_SBC_MEDIA_HDR_ENCODE (1 , 0 , 0 , 0 ));
671777 net_buf_add_mem (buf , media_data , sizeof (media_data ));
672- shell_print (sh , "num of frames: %d, data length: %d" , 1u , sizeof (media_data ));
778+ shell_print (sh , "num of frames: %d, data length: %d" , 1U , sizeof (media_data ));
673779 shell_print (sh , "data: %d, %d, %d, %d, %d, %d ......" , media_data [0 ],
674780 media_data [1 ], media_data [2 ], media_data [3 ], media_data [4 ], media_data [5 ]);
675781
676- ret = bt_a2dp_stream_send (& sbc_stream , buf , 0u , 0u );
782+ ret = bt_a2dp_stream_send (& sbc_stream , buf , 0U , 0U );
677783 if (ret < 0 ) {
678784 printk (" Failed to send SBC audio data on streams(%d)\n" , ret );
679785 net_buf_unref (buf );
@@ -692,9 +798,13 @@ SHELL_STATIC_SUBCMD_SET_CREATE(a2dp_cmds,
692798 SHELL_CMD_ARG (connect , NULL , HELP_NONE , cmd_connect , 1 , 0 ),
693799 SHELL_CMD_ARG (disconnect , NULL , HELP_NONE , cmd_disconnect , 1 , 0 ),
694800 SHELL_CMD_ARG (discover_peer_eps , NULL , HELP_NONE , cmd_get_peer_eps , 1 , 0 ),
695- SHELL_CMD_ARG (configure , NULL , HELP_NONE , cmd_configure , 1 , 0 ),
696- SHELL_CMD_ARG (establish , NULL , HELP_NONE , cmd_establish , 1 , 0 ),
697- SHELL_CMD_ARG (start , NULL , "\"start the default selected ep\"" , cmd_start , 1 , 0 ),
801+ SHELL_CMD_ARG (configure , NULL , "\"configure/enable the stream\"" , cmd_configure , 1 , 0 ),
802+ SHELL_CMD_ARG (establish , NULL , "\"establish the stream\"" , cmd_establish , 1 , 0 ),
803+ SHELL_CMD_ARG (reconfigure , NULL , "\"reconfigure the stream\"" , cmd_reconfigure , 1 , 0 ),
804+ SHELL_CMD_ARG (release , NULL , "\"release the stream\"" , cmd_release , 1 , 0 ),
805+ SHELL_CMD_ARG (start , NULL , "\"start the stream\"" , cmd_start , 1 , 0 ),
806+ SHELL_CMD_ARG (suspend , NULL , "\"suspend the stream\"" , cmd_suspend , 1 , 0 ),
807+ SHELL_CMD_ARG (abort , NULL , "\"abort the stream\"" , cmd_abort , 1 , 0 ),
698808 SHELL_CMD_ARG (send_media , NULL , HELP_NONE , cmd_send_media , 1 , 0 ),
699809 SHELL_SUBCMD_SET_END
700810);
0 commit comments