@@ -552,6 +552,43 @@ static int a2dp_aac_configuration_select(
552552 return 0 ;
553553}
554554
555+ static int a2dp_aac_configuration_check (
556+ const struct a2dp_codec * codec ,
557+ const void * configuration ) {
558+
559+ const a2dp_aac_t * conf = configuration ;
560+ a2dp_aac_t conf_v = * conf ;
561+
562+ /* validate configuration against BlueALSA capabilities */
563+ if (a2dp_filter_capabilities (codec , & codec -> capabilities ,
564+ & conf_v , sizeof (conf_v )) != 0 )
565+ return A2DP_CHECK_ERR_SIZE ;
566+
567+ switch (conf_v .object_type ) {
568+ case AAC_OBJECT_TYPE_MPEG2_AAC_LC :
569+ case AAC_OBJECT_TYPE_MPEG4_AAC_LC :
570+ case AAC_OBJECT_TYPE_MPEG4_AAC_LTP :
571+ case AAC_OBJECT_TYPE_MPEG4_AAC_SCA :
572+ break ;
573+ default :
574+ debug ("AAC: Invalid object type: %#x" , conf -> object_type );
575+ return A2DP_CHECK_ERR_OBJECT_TYPE ;
576+ }
577+
578+ const uint16_t conf_frequency = AAC_GET_FREQUENCY (conf_v );
579+ if (a2dp_sampling_lookup (a2dp_aac_samplings , conf_frequency ) == NULL ) {
580+ debug ("AAC: Invalid sampling frequency: %#x" , AAC_GET_FREQUENCY (* conf ));
581+ return A2DP_CHECK_ERR_SAMPLING ;
582+ }
583+
584+ if (a2dp_channel_mode_lookup (a2dp_aac_channels , conf_v .channels ) == NULL ) {
585+ debug ("AAC: Invalid channel mode: %#x" , conf -> channels );
586+ return A2DP_CHECK_ERR_CHANNEL_MODE ;
587+ }
588+
589+ return A2DP_CHECK_OK ;
590+ }
591+
555592static int a2dp_aac_transport_init (struct ba_transport * t ) {
556593
557594 const struct a2dp_channel_mode * chm ;
@@ -630,11 +667,10 @@ struct a2dp_codec a2dp_aac_source = {
630667 AAC_INIT_BITRATE (320000 )
631668 },
632669 .capabilities_size = sizeof (a2dp_aac_t ),
633- .channels [0 ] = a2dp_aac_channels ,
634- .samplings [0 ] = a2dp_aac_samplings ,
635670 .init = a2dp_aac_source_init ,
636671 .capabilities_filter = a2dp_aac_capabilities_filter ,
637672 .configuration_select = a2dp_aac_configuration_select ,
673+ .configuration_check = a2dp_aac_configuration_check ,
638674 .transport_init = a2dp_aac_transport_init ,
639675 .transport_start = a2dp_aac_source_transport_start ,
640676 .enabled = true,
@@ -691,11 +727,10 @@ struct a2dp_codec a2dp_aac_sink = {
691727 AAC_INIT_BITRATE (320000 )
692728 },
693729 .capabilities_size = sizeof (a2dp_aac_t ),
694- .channels [0 ] = a2dp_aac_channels ,
695- .samplings [0 ] = a2dp_aac_samplings ,
696730 .init = a2dp_aac_sink_init ,
697731 .capabilities_filter = a2dp_aac_capabilities_filter ,
698732 .configuration_select = a2dp_aac_configuration_select ,
733+ .configuration_check = a2dp_aac_configuration_check ,
699734 .transport_init = a2dp_aac_transport_init ,
700735 .transport_start = a2dp_aac_sink_transport_start ,
701736 .enabled = true,
0 commit comments