struct media_transport *media_transport_create(struct btd_device *device, uint8_t *configuration, size_t size, void *data) { struct media_endpoint *endpoint = data; struct media_transport *transport; const char *uuid; static int fd = 0; transport = g_new0(struct media_transport, 1); transport->device = device; transport->endpoint = endpoint; transport->configuration = g_new(uint8_t, size); memcpy(transport->configuration, configuration, size); transport->size = size; transport->path = g_strdup_printf("%s/fd%d", device_get_path(device), fd++); transport->fd = -1; uuid = media_endpoint_get_uuid(endpoint); if (strcasecmp(uuid, A2DP_SOURCE_UUID) == 0) { if (media_transport_init_source(transport) < 0) goto fail; } else if (strcasecmp(uuid, A2DP_SINK_UUID) == 0) { if (media_transport_init_sink(transport) < 0) goto fail; } else goto fail; if (g_dbus_register_interface(btd_get_dbus_connection(), transport->path, MEDIA_TRANSPORT_INTERFACE, transport_methods, NULL, transport_properties, transport, media_transport_free) == FALSE) { error("Could not register transport %s", transport->path); goto fail; } transports = g_slist_append(transports, transport); return transport; fail: media_transport_free(transport); return NULL; }
struct media_transport *media_transport_create(DBusConnection *conn, struct media_endpoint *endpoint, struct audio_device *device, uint8_t *configuration, size_t size) { struct media_transport *transport; const char *uuid; static int fd = 0; transport = g_new0(struct media_transport, 1); transport->conn = dbus_connection_ref(conn); transport->device = device; transport->endpoint = endpoint; transport->configuration = g_new(uint8_t, size); memcpy(transport->configuration, configuration, size); transport->size = size; transport->path = g_strdup_printf("%s/fd%d", device->path, fd++); transport->fd = -1; uuid = media_endpoint_get_uuid(endpoint); if (strcasecmp(uuid, A2DP_SOURCE_UUID) == 0 || strcasecmp(uuid, A2DP_SINK_UUID) == 0) { transport->resume = resume_a2dp; transport->suspend = suspend_a2dp; transport->cancel = cancel_a2dp; transport->get_properties = get_properties_a2dp; transport->set_property = set_property_a2dp; } else if (strcasecmp(uuid, HFP_AG_UUID) == 0 || strcasecmp(uuid, HSP_AG_UUID) == 0) { transport->resume = resume_headset; transport->suspend = suspend_headset; transport->cancel = cancel_headset; transport->get_properties = get_properties_headset; transport->set_property = set_property_headset; transport->nrec_id = headset_add_nrec_cb(device, headset_nrec_changed, transport); } else if (strcasecmp(uuid, HFP_HS_UUID) == 0 || strcasecmp(uuid, HSP_HS_UUID) == 0) { transport->resume = resume_gateway; transport->suspend = suspend_gateway; transport->cancel = cancel_gateway; transport->get_properties = get_properties_gateway; transport->set_property = set_property_gateway; } else goto fail; if (g_dbus_register_interface(transport->conn, transport->path, MEDIA_TRANSPORT_INTERFACE, transport_methods, transport_signals, NULL, transport, media_transport_free) == FALSE) { error("Could not register transport %s", transport->path); goto fail; } return transport; fail: media_transport_free(transport); return NULL; }