1
1
/*
2
2
* test-a2dp.c
3
- * Copyright (c) 2016-2023 Arkadiusz Bokowy
3
+ * Copyright (c) 2016-2024 Arkadiusz Bokowy
4
4
*
5
5
* This file is a part of bluez-alsa.
6
6
*
23
23
24
24
#include "a2dp.h"
25
25
#include "a2dp-aac.h"
26
+ #include "a2dp-aptx.h"
26
27
#include "a2dp-sbc.h"
27
28
#include "ba-transport.h"
28
29
#include "ba-transport-pcm.h"
@@ -78,22 +79,24 @@ CK_START_TEST(test_a2dp_codecs_init) {
78
79
79
80
CK_START_TEST (test_a2dp_codec_cmp ) {
80
81
81
- struct a2dp_codec codec1 = { .dir = A2DP_SOURCE , .codec_id = A2DP_CODEC_SBC };
82
- struct a2dp_codec codec2 = { .dir = A2DP_SOURCE , .codec_id = A2DP_CODEC_MPEG24 };
83
- struct a2dp_codec codec3 = { .dir = A2DP_SOURCE , .codec_id = A2DP_CODEC_VENDOR_APTX };
84
- struct a2dp_codec codec4 = { .dir = A2DP_SINK , .codec_id = A2DP_CODEC_SBC };
85
- struct a2dp_codec codec5 = { .dir = A2DP_SINK , .codec_id = A2DP_CODEC_VENDOR_APTX };
86
- struct a2dp_codec codec6 = { .dir = A2DP_SINK , .codec_id = 0xFFFF };
82
+ struct a2dp_codec c1 = { .dir = A2DP_SOURCE , .codec_id = A2DP_CODEC_SBC };
83
+ struct a2dp_codec c2 = { .dir = A2DP_SOURCE , .codec_id = A2DP_CODEC_MPEG24 };
84
+ struct a2dp_codec c3 = { .dir = A2DP_SOURCE , .codec_id = A2DP_CODEC_VENDOR_APTX };
85
+ struct a2dp_codec c4 = { .dir = A2DP_SINK , .codec_id = A2DP_CODEC_SBC };
86
+ struct a2dp_codec c5 = { .dir = A2DP_SINK , .codec_id = A2DP_CODEC_VENDOR_APTX };
87
+ struct a2dp_codec c6 = { .dir = A2DP_SINK , .codec_id = A2DP_CODEC_VENDOR_LDAC };
88
+ struct a2dp_codec c7 = { .dir = A2DP_SINK , .codec_id = 0xFFFF };
87
89
88
- struct a2dp_codec * codecs [] = { & codec3 , & codec1 , & codec6 , & codec4 , & codec5 , & codec2 };
90
+ struct a2dp_codec * codecs [] = { & c3 , & c1 , & c6 , & c4 , & c7 , & c5 , & c2 };
89
91
qsort (codecs , ARRAYSIZE (codecs ), sizeof (* codecs ), QSORT_COMPAR (a2dp_codec_ptr_cmp ));
90
92
91
- ck_assert_ptr_eq (codecs [0 ], & codec1 );
92
- ck_assert_ptr_eq (codecs [1 ], & codec2 );
93
- ck_assert_ptr_eq (codecs [2 ], & codec3 );
94
- ck_assert_ptr_eq (codecs [3 ], & codec4 );
95
- ck_assert_ptr_eq (codecs [4 ], & codec5 );
96
- ck_assert_ptr_eq (codecs [5 ], & codec6 );
93
+ ck_assert_ptr_eq (codecs [0 ], & c1 );
94
+ ck_assert_ptr_eq (codecs [1 ], & c2 );
95
+ ck_assert_ptr_eq (codecs [2 ], & c3 );
96
+ ck_assert_ptr_eq (codecs [3 ], & c4 );
97
+ ck_assert_ptr_eq (codecs [4 ], & c5 );
98
+ ck_assert_ptr_eq (codecs [5 ], & c6 );
99
+ ck_assert_ptr_eq (codecs [6 ], & c7 );
97
100
98
101
} CK_END_TEST
99
102
@@ -149,6 +152,9 @@ CK_START_TEST(test_a2dp_check_configuration) {
149
152
.max_bitpool = 62 ,
150
153
};
151
154
155
+ ck_assert_int_eq (a2dp_check_configuration (& a2dp_sbc_source ,
156
+ & cfg_valid , sizeof (cfg_valid ) + 1 ), A2DP_CHECK_ERR_SIZE );
157
+
152
158
ck_assert_int_eq (a2dp_check_configuration (& a2dp_sbc_source ,
153
159
& cfg_valid , sizeof (cfg_valid )), A2DP_CHECK_OK );
154
160
@@ -174,9 +180,14 @@ CK_START_TEST(test_a2dp_check_configuration) {
174
180
175
181
} CK_END_TEST
176
182
183
+ CK_START_TEST (test_a2dp_check_strerror ) {
184
+ ck_assert_str_eq (a2dp_check_strerror (A2DP_CHECK_ERR_SIZE ), "Invalid size" );
185
+ ck_assert_str_eq (a2dp_check_strerror (0xFFFF ), "Check error" );
186
+ } CK_END_TEST
187
+
177
188
CK_START_TEST (test_a2dp_filter_capabilities ) {
178
189
179
- a2dp_sbc_t caps = {
190
+ a2dp_sbc_t caps_sbc = {
180
191
.frequency = SBC_SAMPLING_FREQ_44100 ,
181
192
.channel_mode = SBC_CHANNEL_MODE_MONO | SBC_CHANNEL_MODE_STEREO ,
182
193
.block_length = SBC_BLOCK_LENGTH_4 | SBC_BLOCK_LENGTH_8 ,
@@ -186,23 +197,42 @@ CK_START_TEST(test_a2dp_filter_capabilities) {
186
197
.max_bitpool = 255 ,
187
198
};
188
199
200
+ #if ENABLE_APTX
201
+ a2dp_aptx_t caps_aptx = {
202
+ .info = A2DP_VENDOR_INFO_INIT (APTX_VENDOR_ID , APTX_CODEC_ID ),
203
+ .frequency = APTX_SAMPLING_FREQ_32000 | APTX_SAMPLING_FREQ_44100 ,
204
+ .channel_mode = APTX_CHANNEL_MODE_MONO | APTX_CHANNEL_MODE_STEREO ,
205
+ };
206
+ #endif
207
+
189
208
ck_assert_int_eq (a2dp_filter_capabilities (& a2dp_sbc_source ,
190
- & a2dp_sbc_source .capabilities , & caps , sizeof (caps ) + 1 ), -1 );
209
+ & a2dp_sbc_source .capabilities , & caps_sbc , sizeof (caps_sbc ) + 1 ), -1 );
191
210
ck_assert_int_eq (errno , EINVAL );
192
211
193
- hexdump ("Capabilities A" , & caps , sizeof (caps ), true);
194
- hexdump ("Capabilities B" , & a2dp_sbc_source .capabilities , sizeof (caps ), true);
212
+ hexdump ("Capabilities A" , & caps_sbc , sizeof (caps_sbc ), true);
213
+ hexdump ("Capabilities B" , & a2dp_sbc_source .capabilities , sizeof (caps_sbc ), true);
195
214
ck_assert_int_eq (a2dp_filter_capabilities (& a2dp_sbc_source ,
196
- & a2dp_sbc_source .capabilities , & caps , sizeof (caps )), 0 );
197
-
198
- hexdump ("filterion" , & caps , sizeof (caps ), true);
199
- ck_assert_int_eq (caps .frequency , SBC_SAMPLING_FREQ_44100 );
200
- ck_assert_int_eq (caps .channel_mode , SBC_CHANNEL_MODE_MONO | SBC_CHANNEL_MODE_STEREO );
201
- ck_assert_int_eq (caps .block_length , SBC_BLOCK_LENGTH_4 | SBC_BLOCK_LENGTH_8 );
202
- ck_assert_int_eq (caps .subbands , SBC_SUBBANDS_4 );
203
- ck_assert_int_eq (caps .allocation_method , SBC_ALLOCATION_SNR );
204
- ck_assert_int_eq (caps .min_bitpool , MAX (SBC_MIN_BITPOOL , 42 ));
205
- ck_assert_int_eq (caps .max_bitpool , MIN (SBC_MAX_BITPOOL , 255 ));
215
+ & a2dp_sbc_source .capabilities , & caps_sbc , sizeof (caps_sbc )), 0 );
216
+
217
+ hexdump ("Capabilities filtered" , & caps_sbc , sizeof (caps_sbc ), true);
218
+ ck_assert_int_eq (caps_sbc .frequency , SBC_SAMPLING_FREQ_44100 );
219
+ ck_assert_int_eq (caps_sbc .channel_mode , SBC_CHANNEL_MODE_MONO | SBC_CHANNEL_MODE_STEREO );
220
+ ck_assert_int_eq (caps_sbc .block_length , SBC_BLOCK_LENGTH_4 | SBC_BLOCK_LENGTH_8 );
221
+ ck_assert_int_eq (caps_sbc .subbands , SBC_SUBBANDS_4 );
222
+ ck_assert_int_eq (caps_sbc .allocation_method , SBC_ALLOCATION_SNR );
223
+ ck_assert_int_eq (caps_sbc .min_bitpool , MAX (SBC_MIN_BITPOOL , 42 ));
224
+ ck_assert_int_eq (caps_sbc .max_bitpool , MIN (SBC_MAX_BITPOOL , 255 ));
225
+
226
+ #if ENABLE_APTX
227
+ /* Check whether generic bitwise AND filtering works correctly. */
228
+ hexdump ("Capabilities A" , & caps_aptx , sizeof (caps_aptx ), true);
229
+ hexdump ("Capabilities B" , & a2dp_aptx_source .capabilities , sizeof (caps_aptx ), true);
230
+ ck_assert_int_eq (a2dp_filter_capabilities (& a2dp_aptx_source ,
231
+ & a2dp_aptx_source .capabilities , & caps_aptx , sizeof (caps_aptx )), 0 );
232
+ hexdump ("Capabilities filtered" , & caps_aptx , sizeof (caps_aptx ), true);
233
+ ck_assert_int_eq (caps_aptx .frequency , APTX_SAMPLING_FREQ_32000 | APTX_SAMPLING_FREQ_44100 );
234
+ ck_assert_int_eq (caps_aptx .channel_mode , APTX_CHANNEL_MODE_STEREO );
235
+ #endif
206
236
207
237
} CK_END_TEST
208
238
@@ -252,12 +282,31 @@ CK_START_TEST(test_a2dp_select_configuration) {
252
282
ck_assert_int_eq (cfg .max_bitpool , 250 );
253
283
254
284
#if ENABLE_AAC
255
- a2dp_aac_t cfg_aac = {
256
- /* FDK-AAC encoder does not support AAC Long Term Prediction */
257
- .object_type = AAC_OBJECT_TYPE_MPEG4_LTP ,
285
+
286
+ a2dp_aac_t cfg_aac ;
287
+ const a2dp_aac_t cfg_aac_ = {
288
+ .object_type = AAC_OBJECT_TYPE_MPEG2_LC | AAC_OBJECT_TYPE_MPEG4_LC ,
258
289
A2DP_AAC_INIT_FREQUENCY (AAC_SAMPLING_FREQ_44100 | AAC_SAMPLING_FREQ_96000 )
259
- .channels = AAC_CHANNELS_1 };
290
+ .channels = AAC_CHANNELS_1 ,
291
+ .vbr = 1 };
292
+
293
+ cfg_aac = cfg_aac_ ;
294
+ ck_assert_int_eq (a2dp_select_configuration (& a2dp_aac_source , & cfg_aac , sizeof (cfg_aac )), 0 );
295
+ ck_assert_int_eq (cfg_aac .object_type , AAC_OBJECT_TYPE_MPEG4_LC );
296
+ ck_assert_int_eq (A2DP_AAC_GET_FREQUENCY (cfg_aac ), AAC_SAMPLING_FREQ_44100 );
297
+ ck_assert_int_eq (cfg_aac .channels , AAC_CHANNELS_1 );
298
+ ck_assert_int_eq (cfg_aac .vbr , 0 );
299
+
300
+ cfg_aac = cfg_aac_ ;
301
+ config .aac_prefer_vbr = true;
302
+ ck_assert_int_eq (a2dp_select_configuration (& a2dp_aac_source , & cfg_aac , sizeof (cfg_aac )), 0 );
303
+ ck_assert_int_eq (cfg_aac .vbr , 1 );
304
+
305
+ cfg_aac = cfg_aac_ ;
306
+ /* FDK-AAC encoder does not support AAC Long Term Prediction */
307
+ cfg_aac .object_type = AAC_OBJECT_TYPE_MPEG4_LTP ;
260
308
ck_assert_int_eq (a2dp_select_configuration (& a2dp_aac_source , & cfg_aac , sizeof (cfg_aac )), -1 );
309
+
261
310
#endif
262
311
263
312
} CK_END_TEST
@@ -281,6 +330,7 @@ int main(void) {
281
330
tcase_add_test (tc , test_a2dp_codec_lookup );
282
331
tcase_add_test (tc , test_a2dp_get_vendor_codec_id );
283
332
tcase_add_test (tc , test_a2dp_check_configuration );
333
+ tcase_add_test (tc , test_a2dp_check_strerror );
284
334
tcase_add_test (tc , test_a2dp_filter_capabilities );
285
335
tcase_add_test (tc , test_a2dp_select_configuration );
286
336
0 commit comments