Beispiel #1
0
static void discover_cb(struct avdtp *session, GSList *seps,
				struct avdtp_error *err, void *user_data)
{
	struct avdtp_service_capability *service;
	GSList *caps = NULL;
	int ret;

	remote_sep = avdtp_find_remote_sep(avdtp, local_sep);
	if (!remote_sep) {
		printf("Unable to find matching endpoint\n");
		avdtp_shutdown(session);
		return;
	}

	printf("Matching endpoint found\n");

	service = avdtp_service_cap_new(AVDTP_MEDIA_TRANSPORT, NULL, 0);
	caps = g_slist_append(caps, service);

	service = avdtp_service_cap_new(AVDTP_MEDIA_CODEC, sbc_codec,
							sizeof(sbc_codec));
	caps = g_slist_append(caps, service);

	ret = avdtp_set_configuration(avdtp, remote_sep, local_sep, caps,
								&avdtp_stream);

	g_slist_free_full(caps, g_free);

	if (ret < 0) {
		printf("Failed to set configuration (%s)\n", strerror(-ret));
		avdtp_shutdown(session);
	}
}
Beispiel #2
0
static gboolean a2dp_reconfigure(gpointer data)
{
    struct a2dp_setup *setup = data;
    struct avdtp_local_sep *lsep;
    struct avdtp_remote_sep *rsep;
    struct avdtp_service_capability *cap;
    struct avdtp_media_codec_capability *codec_cap = NULL;
    GSList *l;
    int posix_err;

    for (l = setup->client_caps; l != NULL; l = l->next) {
        cap = l->data;

        if (cap->category != AVDTP_MEDIA_CODEC)
            continue;

        codec_cap = (void *) cap->data;
        break;
    }

    if (!codec_cap) {
        error("Cannot find capabilities to reconfigure");
        posix_err = -EINVAL;
        goto failed;
    }

    posix_err = avdtp_get_seps(setup->session, AVDTP_SEP_TYPE_SINK,
                               codec_cap->media_type,
                               codec_cap->media_codec_type,
                               &lsep, &rsep);
    if (posix_err < 0) {
        error("No matching ACP and INT SEPs found");
        goto failed;
    }

    if (setup->rsep) {
        rsep = setup->rsep;
    }

    posix_err = avdtp_set_configuration(setup->session, rsep, lsep,
                                        setup->client_caps,
                                        &setup->stream);
    if (posix_err < 0) {
        error("avdtp_set_configuration: %s", strerror(-posix_err));
        goto failed;
    }

    return FALSE;

failed:
    finalize_config_errno(setup, posix_err);
    return FALSE;
}
Beispiel #3
0
static int select_configuration(struct a2dp_device *dev,
				struct a2dp_endpoint *endpoint,
				struct avdtp_remote_sep *rsep)
{
	struct a2dp_preset *preset;
	struct avdtp_stream *stream;
	struct avdtp_service_capability *service;
	struct avdtp_media_codec_capability *codec;
	GSList *caps;
	int err;

	preset = select_preset(endpoint, rsep);
	if (!preset) {
		error("Unable to select codec preset");
		return -EINVAL;
	}

	service = avdtp_service_cap_new(AVDTP_MEDIA_TRANSPORT, NULL, 0);
	caps = g_slist_append(NULL, service);

	codec = g_malloc0(sizeof(*codec) + preset->len);
	codec->media_type = AVDTP_MEDIA_TYPE_AUDIO;
	codec->media_codec_type = endpoint->codec;
	memcpy(codec->data, preset->data, preset->len);

	service = avdtp_service_cap_new(AVDTP_MEDIA_CODEC, codec,
						sizeof(*codec) + preset->len);
	caps = g_slist_append(caps, service);

	g_free(codec);

	err = avdtp_set_configuration(dev->session, rsep, endpoint->sep, caps,
								&stream);
	g_slist_free_full(caps, g_free);
	if (err < 0) {
		error("avdtp_set_configuration: %s", strerror(-err));
		return err;
	}

	setup_add(dev, endpoint, preset, stream);

	return 0;
}