[PATCH v12 08/13] audio: Send transport path to telephony agent

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add the ability to set MediaTransport path to the HSP/HFP agent during
the call of the NewConnection method.
Accept MediaTransport property change from telephony agent in addition
to Media Endpoint.

This allows external program, implementing telephony agent, to change
Noise Reduction/Echo Cancellation (ECNR), Inband ringtone, speaker
and microphone volume settings of the audio system (i.e. Pulse Audio)
through the MediaTransport.
---
 audio/headset.c   |   29 +++++++++++++++++++++++++++++
 audio/headset.h   |    3 +++
 audio/media.c     |   17 +++++++++++++++++
 audio/telephony.c |   19 +++++++++++++++++++
 audio/telephony.h |    2 ++
 audio/transport.c |   23 +++++++++++++++++++++--
 6 files changed, 91 insertions(+), 2 deletions(-)

diff --git a/audio/headset.c b/audio/headset.c
index 2925642..ad3c2ae 100644
--- a/audio/headset.c
+++ b/audio/headset.c
@@ -109,6 +109,7 @@ struct headset {
 	GIOChannel *rfcomm;
 	GIOChannel *tmp_rfcomm;
 	const char *connecting_uuid;
+	const char *connecting_path;
 	GIOChannel *sco;
 	guint sco_id;
 
@@ -411,6 +412,8 @@ void headset_connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
 						hs->connecting_uuid);
 	hs->slc = telephony_device_connecting(chan, dev->btd_dev, dev, agent);
 	hs->connecting_uuid = NULL;
+	telephony_set_media_transport_path(hs->slc, hs->connecting_path);
+	hs->connecting_path = NULL;
 
 	DBG("%s: Connected to %s", dev->path, hs_address);
 
@@ -545,6 +548,7 @@ failed_not_supported:
 failed:
 	p->svclass = 0;
 	hs->connecting_uuid = NULL;
+	hs->connecting_path = NULL;
 	pending_connect_finalize(dev);
 	headset_set_state(dev, HEADSET_STATE_DISCONNECTED);
 }
@@ -1139,6 +1143,31 @@ void headset_set_connecting_uuid(struct audio_device *dev, const char *uuid)
 	hs->connecting_uuid = uuid;
 }
 
+void headset_set_media_transport_path(struct audio_device *dev,
+							const char *path)
+{
+	struct headset *hs = dev->headset;
+
+	DBG("MediaTransport path: %s", path);
+
+	if (hs->slc == NULL) {
+		hs->connecting_path = path;
+		return;
+	}
+
+	telephony_set_media_transport_path(hs->slc, path);
+}
+
+const char *headset_get_telephony_agent_name(struct audio_device *dev)
+{
+	struct headset *hs = dev->headset;
+
+	if (hs == NULL || hs->slc == NULL)
+		return NULL;
+
+	return telephony_get_agent_name(hs->slc);
+}
+
 int headset_connect_rfcomm(struct audio_device *dev, GIOChannel *io)
 {
 	struct headset *hs = dev->headset;
diff --git a/audio/headset.h b/audio/headset.h
index 706d90c..957f99c 100644
--- a/audio/headset.h
+++ b/audio/headset.h
@@ -105,3 +105,6 @@ void headset_shutdown(struct audio_device *dev);
 
 void headset_slc_complete(struct audio_device *dev);
 void headset_set_connecting_uuid(struct audio_device *dev, const char *uuid);
+void headset_set_media_transport_path(struct audio_device *dev,
+							const char *path);
+const char *headset_get_telephony_agent_name(struct audio_device *dev);
diff --git a/audio/media.c b/audio/media.c
index 00827d6..2253844 100644
--- a/audio/media.c
+++ b/audio/media.c
@@ -475,6 +475,7 @@ static void headset_state_changed(struct audio_device *dev,
 {
 	struct media_endpoint *endpoint = user_data;
 	struct media_transport *transport;
+	const char *path;
 
 	DBG("");
 
@@ -493,6 +494,13 @@ static void headset_state_changed(struct audio_device *dev,
 	case HEADSET_STATE_CONNECTING:
 		set_configuration(endpoint, dev, NULL, 0, headset_setconf_cb,
 								dev, NULL);
+
+		transport = find_device_transport(endpoint, dev);
+		if (transport == NULL)
+			break;
+
+		path = media_transport_get_path(transport);
+		headset_set_media_transport_path(dev, path);
 		break;
 	case HEADSET_STATE_CONNECTED:
 		break;
@@ -704,9 +712,18 @@ static gboolean endpoint_init_ag(struct media_endpoint *endpoint, int *err)
 
 	for (l = list; l != NULL; l = l->next) {
 		struct audio_device *dev = l->data;
+		struct media_transport *transport;
+		const char *path;
 
 		set_configuration(endpoint, dev, NULL, 0,
 						headset_setconf_cb, dev, NULL);
+
+		transport = find_device_transport(endpoint, dev);
+		if (transport == NULL)
+			break;
+
+		path = media_transport_get_path(transport);
+		headset_set_media_transport_path(dev, path);
 	}
 
 	g_slist_free(list);
diff --git a/audio/telephony.c b/audio/telephony.c
index 9998d04..914bb14 100644
--- a/audio/telephony.c
+++ b/audio/telephony.c
@@ -68,6 +68,7 @@ struct tel_device {
 	char			*path;		/* agent object path */
 	struct default_agent	*properties;
 	GIOChannel		*rfcomm;
+	const char		*transport_path;
 	uint16_t		version;
 	uint16_t		features;
 };
@@ -238,6 +239,10 @@ static gboolean agent_sendfd(struct tel_device *dev, int fd,
 		dict_append_entry(&dict, "Features", DBUS_TYPE_UINT16,
 							&dev->features);
 
+	if (dev->transport_path != NULL)
+		dict_append_entry(&dict, "Transport", DBUS_TYPE_OBJECT_PATH,
+							&dev->transport_path);
+
 	dbus_message_iter_close_container(&iter, &dict);
 
 	if (!dbus_connection_send_with_reply(connection, msg, &call, -1)) {
@@ -396,6 +401,20 @@ void telephony_device_disconnected(void *telephony_device)
 	DBG("telephony-dbus: device %p disconnected", telephony_device);
 }
 
+void telephony_set_media_transport_path(void *slc, const char *path)
+{
+	struct tel_device *dev = slc;
+
+	dev->transport_path = path;
+}
+
+const char *telephony_get_agent_name(void *slc)
+{
+	struct tel_device *dev = slc;
+
+	return dev->name;
+}
+
 static sdp_record_t *hsp_ag_record(struct tel_agent *agent)
 {
 	sdp_list_t *svclass_id, *pfseq, *apseq, *root;
diff --git a/audio/telephony.h b/audio/telephony.h
index 7b08c8d..695061d 100644
--- a/audio/telephony.h
+++ b/audio/telephony.h
@@ -53,6 +53,8 @@ void *telephony_device_connecting(GIOChannel *io, struct btd_device *dev,
 void telephony_device_connected(void *telephony_device);
 void telephony_device_disconnect(void *slc);
 void telephony_device_disconnected(void *telephony_device);
+void telephony_set_media_transport_path(void *slc, const char *path);
+const char *telephony_get_agent_name(void *slc);
 
 void *telephony_agent_by_uuid(void *adapter, const char *uuid);
 
diff --git a/audio/transport.c b/audio/transport.c
index 6d4ad55..7236e43 100644
--- a/audio/transport.c
+++ b/audio/transport.c
@@ -857,6 +857,18 @@ static int set_property_gateway(struct media_transport *transport,
 	return -EINVAL;
 }
 
+static gboolean check_telephony_agent_name(struct media_transport *transport,
+							const char *sender)
+{
+	const char *tel_agent;
+
+	tel_agent = headset_get_telephony_agent_name(transport->device);
+	if (tel_agent != NULL && g_strcmp0(tel_agent, sender) == 0)
+		return TRUE;
+
+	return FALSE;
+}
+
 static DBusMessage *set_property(DBusConnection *conn, DBusMessage *msg,
 								void *data)
 {
@@ -865,6 +877,7 @@ static DBusMessage *set_property(DBusConnection *conn, DBusMessage *msg,
 	DBusMessageIter value;
 	const char *property, *sender;
 	GSList *l;
+	gboolean sender_ok = FALSE;
 	int err;
 
 	if (!dbus_message_iter_init(msg, &iter))
@@ -888,12 +901,18 @@ static DBusMessage *set_property(DBusConnection *conn, DBusMessage *msg,
 		struct media_owner *owner = l->data;
 
 		if (g_strcmp0(owner->name, sender) == 0) {
-			err = transport->set_property(transport, property,
-								&value);
+			sender_ok = TRUE;
 			break;
 		}
 	}
 
+	/* Check if Telephony agent does this request */
+	if (!sender_ok)
+		sender_ok = check_telephony_agent_name(transport, sender);
+
+	if (sender_ok)
+		err = transport->set_property(transport, property, &value);
+
 	if (err < 0) {
 		if (err == -EINVAL)
 			return btd_error_invalid_args(msg);
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux