284
308
sink->connect = NULL;
285
pending_request_free(pending);
309
pending_request_free(sink->dev, pending);
290
314
avdtp_unref(sink->session);
291
315
sink->session = NULL;
292
if (avdtp_error_type(err) == AVDTP_ERROR_ERRNO
316
if (avdtp_error_category(err) == AVDTP_ERRNO
293
317
&& avdtp_error_posix_errno(err) != EHOSTDOWN) {
294
debug("connect:connect XCASE detected");
295
g_timeout_add_seconds(STREAM_SETUP_RETRY_TIMER,
296
stream_setup_retry, sink);
318
DBG("connect:connect XCASE detected");
319
sink->retry_id = g_timeout_add_seconds(STREAM_SETUP_RETRY_TIMER,
298
323
if (pending->msg)
299
324
error_failed(pending->conn, pending->msg, "Stream setup failed");
300
325
sink->connect = NULL;
301
pending_request_free(pending);
302
debug("Stream setup failed : %s", avdtp_strerror(err));
306
static uint8_t default_bitpool(uint8_t freq, uint8_t mode)
309
case SBC_SAMPLING_FREQ_16000:
310
case SBC_SAMPLING_FREQ_32000:
312
case SBC_SAMPLING_FREQ_44100:
314
case SBC_CHANNEL_MODE_MONO:
315
case SBC_CHANNEL_MODE_DUAL_CHANNEL:
317
case SBC_CHANNEL_MODE_STEREO:
318
case SBC_CHANNEL_MODE_JOINT_STEREO:
321
error("Invalid channel mode %u", mode);
324
case SBC_SAMPLING_FREQ_48000:
326
case SBC_CHANNEL_MODE_MONO:
327
case SBC_CHANNEL_MODE_DUAL_CHANNEL:
329
case SBC_CHANNEL_MODE_STEREO:
330
case SBC_CHANNEL_MODE_JOINT_STEREO:
333
error("Invalid channel mode %u", mode);
337
error("Invalid sampling freq %u", freq);
342
static gboolean select_sbc_params(struct sbc_codec_cap *cap,
343
struct sbc_codec_cap *supported)
345
unsigned int max_bitpool, min_bitpool;
347
memset(cap, 0, sizeof(struct sbc_codec_cap));
349
cap->cap.media_type = AVDTP_MEDIA_TYPE_AUDIO;
350
cap->cap.media_codec_type = A2DP_CODEC_SBC;
352
if (supported->frequency & SBC_SAMPLING_FREQ_44100)
353
cap->frequency = SBC_SAMPLING_FREQ_44100;
354
else if (supported->frequency & SBC_SAMPLING_FREQ_48000)
355
cap->frequency = SBC_SAMPLING_FREQ_48000;
356
else if (supported->frequency & SBC_SAMPLING_FREQ_32000)
357
cap->frequency = SBC_SAMPLING_FREQ_32000;
358
else if (supported->frequency & SBC_SAMPLING_FREQ_16000)
359
cap->frequency = SBC_SAMPLING_FREQ_16000;
361
error("No supported frequencies");
365
if (supported->channel_mode & SBC_CHANNEL_MODE_JOINT_STEREO)
366
cap->channel_mode = SBC_CHANNEL_MODE_JOINT_STEREO;
367
else if (supported->channel_mode & SBC_CHANNEL_MODE_STEREO)
368
cap->channel_mode = SBC_CHANNEL_MODE_STEREO;
369
else if (supported->channel_mode & SBC_CHANNEL_MODE_DUAL_CHANNEL)
370
cap->channel_mode = SBC_CHANNEL_MODE_DUAL_CHANNEL;
371
else if (supported->channel_mode & SBC_CHANNEL_MODE_MONO)
372
cap->channel_mode = SBC_CHANNEL_MODE_MONO;
374
error("No supported channel modes");
378
if (supported->block_length & SBC_BLOCK_LENGTH_16)
379
cap->block_length = SBC_BLOCK_LENGTH_16;
380
else if (supported->block_length & SBC_BLOCK_LENGTH_12)
381
cap->block_length = SBC_BLOCK_LENGTH_12;
382
else if (supported->block_length & SBC_BLOCK_LENGTH_8)
383
cap->block_length = SBC_BLOCK_LENGTH_8;
384
else if (supported->block_length & SBC_BLOCK_LENGTH_4)
385
cap->block_length = SBC_BLOCK_LENGTH_4;
387
error("No supported block lengths");
391
if (supported->subbands & SBC_SUBBANDS_8)
392
cap->subbands = SBC_SUBBANDS_8;
393
else if (supported->subbands & SBC_SUBBANDS_4)
394
cap->subbands = SBC_SUBBANDS_4;
396
error("No supported subbands");
400
if (supported->allocation_method & SBC_ALLOCATION_LOUDNESS)
401
cap->allocation_method = SBC_ALLOCATION_LOUDNESS;
402
else if (supported->allocation_method & SBC_ALLOCATION_SNR)
403
cap->allocation_method = SBC_ALLOCATION_SNR;
405
min_bitpool = MAX(MIN_BITPOOL, supported->min_bitpool);
406
max_bitpool = MIN(default_bitpool(cap->frequency, cap->channel_mode),
407
supported->max_bitpool);
409
cap->min_bitpool = min_bitpool;
410
cap->max_bitpool = max_bitpool;
415
static gboolean select_capabilities(struct avdtp *session,
416
struct avdtp_remote_sep *rsep,
419
struct avdtp_service_capability *media_transport, *media_codec;
420
struct sbc_codec_cap sbc_cap;
422
media_codec = avdtp_get_codec(rsep);
426
select_sbc_params(&sbc_cap, (struct sbc_codec_cap *) media_codec->data);
428
media_transport = avdtp_service_cap_new(AVDTP_MEDIA_TRANSPORT,
431
*caps = g_slist_append(*caps, media_transport);
433
media_codec = avdtp_service_cap_new(AVDTP_MEDIA_CODEC, &sbc_cap,
436
*caps = g_slist_append(*caps, media_codec);
326
pending_request_free(sink->dev, pending);
327
DBG("Stream setup failed : %s", avdtp_strerror(err));
331
static void select_complete(struct avdtp *session, struct a2dp_sep *sep,
332
GSList *caps, void *user_data)
334
struct sink *sink = user_data;
335
struct pending_request *pending;
338
pending = sink->connect;
341
id = a2dp_config(session, sep, stream_setup_complete, caps, sink);
350
error_failed(pending->conn, pending->msg, "Stream setup failed");
351
pending_request_free(sink->dev, pending);
352
sink->connect = NULL;
353
avdtp_unref(sink->session);
354
sink->session = NULL;
442
357
static void discovery_complete(struct avdtp *session, GSList *seps, struct avdtp_error *err,
445
360
struct sink *sink = user_data;
446
361
struct pending_request *pending;
447
struct avdtp_local_sep *lsep;
448
struct avdtp_remote_sep *rsep;
449
struct a2dp_sep *sep;
364
if (!sink->connect) {
365
avdtp_unref(sink->session);
366
sink->session = NULL;
453
370
pending = sink->connect;
456
373
avdtp_unref(sink->session);
457
374
sink->session = NULL;
458
if (avdtp_error_type(err) == AVDTP_ERROR_ERRNO
375
if (avdtp_error_category(err) == AVDTP_ERRNO
459
376
&& avdtp_error_posix_errno(err) != EHOSTDOWN) {
460
debug("connect:connect XCASE detected");
461
g_timeout_add_seconds(STREAM_SETUP_RETRY_TIMER,
462
stream_setup_retry, sink);
377
DBG("connect:connect XCASE detected");
379
g_timeout_add_seconds(STREAM_SETUP_RETRY_TIMER,
468
debug("Discovery complete");
470
if (avdtp_get_seps(session, AVDTP_SEP_TYPE_SINK, AVDTP_MEDIA_TYPE_AUDIO,
471
A2DP_CODEC_SBC, &lsep, &rsep) < 0) {
472
error("No matching ACP and INT SEPs found");
476
if (!select_capabilities(session, rsep, &caps)) {
477
error("Unable to select remote SEP capabilities");
481
sep = a2dp_source_get(session, rsep);
482
id = a2dp_source_config(sink->session, sep, stream_setup_complete,
387
DBG("Discovery complete");
389
id = a2dp_select_capabilities(sink->session, AVDTP_SEP_TYPE_SINK, NULL,
390
select_complete, sink);