21
21
#include <sys/ioctl.h>
22
22
#include <unistd.h>
23
23
24
- #include <glib.h>
25
-
26
24
#include <lhdcBT.h>
27
25
#include <lhdcBT_dec.h>
28
26
@@ -44,7 +42,7 @@ static const enum ba_transport_pcm_channel a2dp_lhdc_channel_map_stereo[] = {
44
42
BA_TRANSPORT_PCM_CHANNEL_FL , BA_TRANSPORT_PCM_CHANNEL_FR ,
45
43
};
46
44
47
- static const struct a2dp_bit_mapping a2dp_lhdc_samplings [] = {
45
+ static const struct a2dp_bit_mapping a2dp_lhdc_rates [] = {
48
46
{ LHDC_SAMPLING_FREQ_44100 , { 44100 } },
49
47
{ LHDC_SAMPLING_FREQ_48000 , { 48000 } },
50
48
{ LHDC_SAMPLING_FREQ_96000 , { 96000 } },
@@ -70,14 +68,14 @@ static int a2dp_lhdc_caps_foreach_channel_mode(
70
68
return -1 ;
71
69
}
72
70
73
- static int a2dp_lhdc_caps_foreach_sampling_freq (
71
+ static int a2dp_lhdc_caps_foreach_sample_rate (
74
72
const void * capabilities ,
75
73
enum a2dp_stream stream ,
76
74
a2dp_bit_mapping_foreach_func func ,
77
75
void * userdata ) {
78
76
const a2dp_lhdc_v3_t * caps = capabilities ;
79
77
if (stream == A2DP_MAIN )
80
- return a2dp_bit_mapping_foreach (a2dp_lhdc_samplings , caps -> sampling_freq , func , userdata );
78
+ return a2dp_bit_mapping_foreach (a2dp_lhdc_rates , caps -> sampling_freq , func , userdata );
81
79
return -1 ;
82
80
}
83
81
@@ -90,23 +88,23 @@ static void a2dp_lhdc_caps_select_channel_mode(
90
88
(void )channels ;
91
89
}
92
90
93
- static void a2dp_lhdc_caps_select_sampling_freq (
91
+ static void a2dp_lhdc_caps_select_sample_rate (
94
92
void * capabilities ,
95
93
enum a2dp_stream stream ,
96
- unsigned int frequency ) {
94
+ unsigned int rate ) {
97
95
a2dp_lhdc_v3_t * caps = capabilities ;
98
96
if (stream == A2DP_MAIN )
99
- caps -> sampling_freq = a2dp_bit_mapping_lookup_value (a2dp_lhdc_samplings ,
100
- caps -> sampling_freq , frequency );
97
+ caps -> sampling_freq = a2dp_bit_mapping_lookup_value (a2dp_lhdc_rates ,
98
+ caps -> sampling_freq , rate );
101
99
}
102
100
103
101
static struct a2dp_caps_helpers a2dp_lhdc_caps_helpers = {
104
102
.intersect = a2dp_lhdc_caps_intersect ,
105
103
.has_stream = a2dp_caps_has_main_stream_only ,
106
104
.foreach_channel_mode = a2dp_lhdc_caps_foreach_channel_mode ,
107
- .foreach_sampling_freq = a2dp_lhdc_caps_foreach_sampling_freq ,
105
+ .foreach_sample_rate = a2dp_lhdc_caps_foreach_sample_rate ,
108
106
.select_channel_mode = a2dp_lhdc_caps_select_channel_mode ,
109
- .select_sampling_freq = a2dp_lhdc_caps_select_sampling_freq ,
107
+ .select_sample_rate = a2dp_lhdc_caps_select_sample_rate ,
110
108
};
111
109
112
110
static LHDC_VERSION_SETUP get_version (const a2dp_lhdc_v3_t * configuration ) {
@@ -157,8 +155,9 @@ void *a2dp_lhdc_enc_thread(struct ba_transport_pcm *t_pcm) {
157
155
struct io_poll io = { .timeout = -1 };
158
156
159
157
const a2dp_lhdc_v3_t * configuration = & t -> a2dp .configuration .lhdc_v3 ;
158
+ const unsigned int bit_depth = get_bit_depth (configuration );
160
159
const unsigned int channels = t_pcm -> channels ;
161
- const unsigned int samplerate = t_pcm -> sampling ;
160
+ const unsigned int rate = t_pcm -> rate ;
162
161
163
162
HANDLE_LHDC_BT handle ;
164
163
if ((handle = lhdcBT_get_handle (get_version (configuration ))) == NULL ) {
@@ -168,22 +167,14 @@ void *a2dp_lhdc_enc_thread(struct ba_transport_pcm *t_pcm) {
168
167
169
168
pthread_cleanup_push (PTHREAD_CLEANUP (lhdcBT_free_handle ), handle );
170
169
171
- const unsigned int bitdepth = get_bit_depth (configuration );
172
170
173
171
lhdcBT_set_hasMinBitrateLimit (handle , configuration -> min_bitrate );
174
172
lhdcBT_set_max_bitrate (handle , get_max_bitrate (configuration ));
175
173
176
- struct {
177
- uint8_t seq_num ;
178
- uint8_t latency :2 ;
179
- uint8_t frames :6 ;
180
- } * lhdc_media_header ;
181
-
182
- rtp_header_t * rtp_header ;
183
-
184
- if (lhdcBT_init_encoder (handle , samplerate , bitdepth , config .lhdc_eqmid ,
185
- configuration -> ch_split_mode > LHDC_CH_SPLIT_MODE_NONE , 0 , t -> mtu_write - sizeof (* lhdc_media_header ) - RTP_HEADER_LEN ,
186
- get_interval (configuration )) == -1 ) {
174
+ if (lhdcBT_init_encoder (handle , rate , bit_depth , config .lhdc_eqmid ,
175
+ configuration -> ch_split_mode > LHDC_CH_SPLIT_MODE_NONE , 0 ,
176
+ t -> mtu_write - RTP_HEADER_LEN - sizeof (rtp_lhdc_media_header_t ),
177
+ get_interval (configuration )) == -1 ) {
187
178
error ("Couldn't initialize LHDC encoder" );
188
179
goto fail_init ;
189
180
}
@@ -208,13 +199,15 @@ void *a2dp_lhdc_enc_thread(struct ba_transport_pcm *t_pcm) {
208
199
goto fail_ffb ;
209
200
}
210
201
202
+ rtp_header_t * rtp_header ;
203
+ rtp_lhdc_media_header_t * rtp_lhdc_media_header ;
211
204
/* initialize RTP headers and get anchor for payload */
212
205
uint8_t * rtp_payload = rtp_a2dp_init (bt .data , & rtp_header ,
213
- (void * * )& lhdc_media_header , sizeof (* lhdc_media_header ));
206
+ (void * * )& rtp_lhdc_media_header , sizeof (* rtp_lhdc_media_header ));
214
207
215
208
struct rtp_state rtp = { .synced = false };
216
209
/* RTP clock frequency equal to audio sample rate */
217
- rtp_state_init (& rtp , samplerate , samplerate );
210
+ rtp_state_init (& rtp , rate , rate );
218
211
219
212
uint8_t seq_num = 0 ;
220
213
@@ -263,9 +256,9 @@ void *a2dp_lhdc_enc_thread(struct ba_transport_pcm *t_pcm) {
263
256
264
257
rtp_state_new_frame (& rtp , rtp_header );
265
258
266
- lhdc_media_header -> seq_num = seq_num ++ ;
267
- lhdc_media_header -> latency = 0 ;
268
- lhdc_media_header -> frames = frames ;
259
+ rtp_lhdc_media_header -> seq_number = seq_num ++ ;
260
+ rtp_lhdc_media_header -> latency = 0 ;
261
+ rtp_lhdc_media_header -> frame_count = frames ;
269
262
270
263
/* Try to get the number of bytes queued in the
271
264
* socket output buffer. */
@@ -337,12 +330,12 @@ void *a2dp_lhdc_dec_thread(struct ba_transport_pcm *t_pcm) {
337
330
const a2dp_lhdc_v3_t * configuration = & t -> a2dp .configuration .lhdc_v3 ;
338
331
const size_t sample_size = BA_TRANSPORT_PCM_FORMAT_BYTES (t_pcm -> format );
339
332
const unsigned int channels = t_pcm -> channels ;
340
- const unsigned int samplerate = t_pcm -> sampling ;
333
+ const unsigned int rate = t_pcm -> rate ;
341
334
const unsigned int bit_depth = get_bit_depth (configuration );
342
335
343
336
tLHDCV3_DEC_CONFIG dec_config = {
344
337
.version = get_decoder_version (configuration ),
345
- .sample_rate = samplerate ,
338
+ .sample_rate = rate ,
346
339
.bits_depth = bit_depth ,
347
340
};
348
341
@@ -366,7 +359,7 @@ void *a2dp_lhdc_dec_thread(struct ba_transport_pcm *t_pcm) {
366
359
367
360
struct rtp_state rtp = { .synced = false };
368
361
/* RTP clock frequency equal to audio sample rate */
369
- rtp_state_init (& rtp , samplerate , samplerate );
362
+ rtp_state_init (& rtp , rate , rate );
370
363
371
364
debug_transport_pcm_thread_loop (t_pcm , "START" );
372
365
for (ba_transport_pcm_state_set_running (t_pcm );;) {
@@ -380,8 +373,8 @@ void *a2dp_lhdc_dec_thread(struct ba_transport_pcm *t_pcm) {
380
373
}
381
374
382
375
const rtp_header_t * rtp_header = bt .data ;
383
- const void * lhdc_media_header ;
384
- if ((lhdc_media_header = rtp_a2dp_get_payload (rtp_header )) == NULL )
376
+ const rtp_lhdc_media_header_t * rtp_lhdc_media_header ;
377
+ if ((rtp_lhdc_media_header = rtp_a2dp_get_payload (rtp_header )) == NULL )
385
378
continue ;
386
379
387
380
int missing_rtp_frames = 0 ;
@@ -392,11 +385,10 @@ void *a2dp_lhdc_dec_thread(struct ba_transport_pcm *t_pcm) {
392
385
continue ;
393
386
}
394
387
395
- const uint8_t * rtp_payload = (uint8_t * ) lhdc_media_header ;
388
+ const uint8_t * rtp_payload = (uint8_t * )rtp_lhdc_media_header ;
396
389
size_t rtp_payload_len = len - (rtp_payload - (uint8_t * )bt .data );
397
390
398
- uint32_t decoded = 16 * 256 * sizeof (int32_t ) * channels ;
399
-
391
+ uint32_t decoded = ffb_blen_in (& pcm );
400
392
lhdcBT_dec_decode (rtp_payload , rtp_payload_len , pcm .data , & decoded , 24 );
401
393
402
394
const size_t samples = decoded / sample_size ;
@@ -442,11 +434,11 @@ static int a2dp_lhdc_configuration_select(
442
434
}
443
435
444
436
unsigned int sampling_freq = 0 ;
445
- if (a2dp_lhdc_caps_foreach_sampling_freq (caps , A2DP_MAIN ,
446
- a2dp_bit_mapping_foreach_get_best_sampling_freq , & sampling_freq ) != -1 )
437
+ if (a2dp_lhdc_caps_foreach_sample_rate (caps , A2DP_MAIN ,
438
+ a2dp_bit_mapping_foreach_get_best_sample_rate , & sampling_freq ) != -1 )
447
439
caps -> sampling_freq = sampling_freq ;
448
440
else {
449
- error ("LHDC: No supported sampling frequencies : %#x" , saved .sampling_freq );
441
+ error ("LHDC: No supported sample rates : %#x" , saved .sampling_freq );
450
442
return errno = ENOTSUP , -1 ;
451
443
}
452
444
@@ -463,18 +455,18 @@ static int a2dp_lhdc_configuration_check(
463
455
/* Validate configuration against BlueALSA capabilities. */
464
456
a2dp_lhdc_caps_intersect (& conf_v , & sep -> config .capabilities );
465
457
466
- if (a2dp_bit_mapping_lookup (a2dp_lhdc_samplings , conf_v .sampling_freq ) == -1 ) {
467
- debug ("LHDC: Invalid sampling frequency : %#x" , conf -> sampling_freq );
468
- return A2DP_CHECK_ERR_SAMPLING ;
458
+ if (a2dp_bit_mapping_lookup (a2dp_lhdc_rates , conf_v .sampling_freq ) == -1 ) {
459
+ debug ("LHDC: Invalid sample rate : %#x" , conf -> sampling_freq );
460
+ return A2DP_CHECK_ERR_RATE ;
469
461
}
470
462
471
463
return A2DP_CHECK_OK ;
472
464
}
473
465
474
466
static int a2dp_lhdc_transport_init (struct ba_transport * t ) {
475
467
476
- ssize_t sampling_i ;
477
- if ((sampling_i = a2dp_bit_mapping_lookup (a2dp_lhdc_samplings ,
468
+ ssize_t rate_i ;
469
+ if ((rate_i = a2dp_bit_mapping_lookup (a2dp_lhdc_rates ,
478
470
t -> a2dp .configuration .lhdc_v3 .sampling_freq )) == -1 )
479
471
return -1 ;
480
472
@@ -485,10 +477,10 @@ static int a2dp_lhdc_transport_init(struct ba_transport *t) {
485
477
}
486
478
487
479
t -> a2dp .pcm .channels = 2 ;
488
- t -> a2dp .pcm .sampling = a2dp_lhdc_samplings [ sampling_i ].value ;
480
+ t -> a2dp .pcm .rate = a2dp_lhdc_rates [ rate_i ].value ;
489
481
490
- memcpy (t -> a2dp .pcm .channel_map , a2dp_lhdc_channel_map_stereo ,
491
- t -> a2dp . pcm . channels * sizeof (* t -> a2dp . pcm . channel_map ));
482
+ memcpy (t -> a2dp .pcm .channel_map ,
483
+ a2dp_lhdc_channel_map_stereo , sizeof (a2dp_lhdc_channel_map_stereo ));
492
484
493
485
return 0 ;
494
486
}
0 commit comments