From: Mikel Astiz <mikel.astiz.oss@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: Mikel Astiz <mikel.astiz@bmw-carit.de>
Subject: [RFC v4 5/9] media: Watch interface state changes in transport
Date: Fri, 14 Sep 2012 14:03:12 +0200 [thread overview]
Message-ID: <1347624196-11281-6-git-send-email-mikel.astiz.oss@gmail.com> (raw)
In-Reply-To: <1347624196-11281-1-git-send-email-mikel.astiz.oss@gmail.com>
From: Mikel Astiz <mikel.astiz@bmw-carit.de>
Install watches to keep track whether the audio is streaming or not.
This should be relevant if the transport needs to reflect this state.
---
audio/transport.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 103 insertions(+), 0 deletions(-)
diff --git a/audio/transport.c b/audio/transport.c
index 410601f..639c87f 100644
--- a/audio/transport.c
+++ b/audio/transport.c
@@ -45,6 +45,8 @@
#include "a2dp.h"
#include "headset.h"
#include "gateway.h"
+#include "sink.h"
+#include "source.h"
#include "avrcp.h"
#define MEDIA_TRANSPORT_INTERFACE "org.bluez.MediaTransport"
@@ -101,6 +103,10 @@ struct media_transport {
uint16_t omtu; /* Transport output mtu */
transport_lock_t lock;
transport_state_t state;
+ guint hs_watch;
+ guint ag_watch;
+ guint source_watch;
+ guint sink_watch;
guint (*resume) (struct media_transport *transport,
struct media_owner *owner);
guint (*suspend) (struct media_transport *transport,
@@ -173,6 +179,18 @@ void media_transport_destroy(struct media_transport *transport)
{
char *path;
+ if (transport->hs_watch)
+ headset_remove_state_cb(transport->hs_watch);
+
+ if (transport->ag_watch)
+ gateway_remove_state_cb(transport->ag_watch);
+
+ if (transport->sink_watch)
+ sink_remove_state_cb(transport->sink_watch);
+
+ if (transport->source_watch)
+ source_remove_state_cb(transport->source_watch);
+
path = g_strdup(transport->path);
g_dbus_unregister_interface(transport->conn, path,
MEDIA_TRANSPORT_INTERFACE);
@@ -1083,6 +1101,76 @@ static void headset_nrec_changed(struct audio_device *dev, gboolean nrec,
DBUS_TYPE_BOOLEAN, &nrec);
}
+static void transport_update_playing(struct media_transport *transport,
+ gboolean playing)
+{
+ DBG("%s Playing=%d", transport->path, playing);
+}
+
+static void headset_state_changed(struct audio_device *dev,
+ headset_state_t old_state,
+ headset_state_t new_state,
+ void *user_data)
+{
+ struct media_transport *transport = user_data;
+
+ if (dev != transport->device)
+ return;
+
+ if (new_state == HEADSET_STATE_PLAYING)
+ transport_update_playing(transport, TRUE);
+ else
+ transport_update_playing(transport, FALSE);
+}
+
+static void gateway_state_changed(struct audio_device *dev,
+ gateway_state_t old_state,
+ gateway_state_t new_state,
+ void *user_data)
+{
+ struct media_transport *transport = user_data;
+
+ if (dev != transport->device)
+ return;
+
+ if (new_state == GATEWAY_STATE_PLAYING)
+ transport_update_playing(transport, TRUE);
+ else
+ transport_update_playing(transport, FALSE);
+}
+
+static void sink_state_changed(struct audio_device *dev,
+ sink_state_t old_state,
+ sink_state_t new_state,
+ void *user_data)
+{
+ struct media_transport *transport = user_data;
+
+ if (dev != transport->device)
+ return;
+
+ if (new_state == SINK_STATE_PLAYING)
+ transport_update_playing(transport, TRUE);
+ else
+ transport_update_playing(transport, FALSE);
+}
+
+static void source_state_changed(struct audio_device *dev,
+ source_state_t old_state,
+ source_state_t new_state,
+ void *user_data)
+{
+ struct media_transport *transport = user_data;
+
+ if (dev != transport->device)
+ return;
+
+ if (new_state == SOURCE_STATE_PLAYING)
+ transport_update_playing(transport, TRUE);
+ else
+ transport_update_playing(transport, FALSE);
+}
+
struct media_transport *media_transport_create(DBusConnection *conn,
struct media_endpoint *endpoint,
struct audio_device *device,
@@ -1118,6 +1206,15 @@ struct media_transport *media_transport_create(DBusConnection *conn,
transport->set_property = set_property_a2dp;
transport->data = a2dp;
transport->destroy = destroy_a2dp;
+
+ if (strcasecmp(uuid, A2DP_SOURCE_UUID) == 0)
+ transport->sink_watch = sink_add_state_cb(
+ sink_state_changed,
+ transport);
+ else
+ transport->source_watch = source_add_state_cb(
+ source_state_changed,
+ transport);
} else if (strcasecmp(uuid, HFP_AG_UUID) == 0 ||
strcasecmp(uuid, HSP_AG_UUID) == 0) {
struct headset_transport *headset;
@@ -1135,6 +1232,9 @@ struct media_transport *media_transport_create(DBusConnection *conn,
transport->set_property = set_property_headset;
transport->data = headset;
transport->destroy = destroy_headset;
+ transport->hs_watch = headset_add_state_cb(
+ headset_state_changed,
+ transport);
} else if (strcasecmp(uuid, HFP_HS_UUID) == 0 ||
strcasecmp(uuid, HSP_HS_UUID) == 0) {
transport->resume = resume_gateway;
@@ -1142,6 +1242,9 @@ struct media_transport *media_transport_create(DBusConnection *conn,
transport->cancel = cancel_gateway;
transport->get_properties = get_properties_gateway;
transport->set_property = set_property_gateway;
+ transport->ag_watch = gateway_add_state_cb(
+ gateway_state_changed,
+ transport);
} else
goto fail;
--
1.7.7.6
next prev parent reply other threads:[~2012-09-14 12:03 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-14 12:03 [RFC v4 0/9] Optional acquire in Media API and related Mikel Astiz
2012-09-14 12:03 ` [RFC v4 1/9] media: Fix accesstype comparison Mikel Astiz
2012-09-14 12:03 ` [RFC v4 2/9] media: Add a2dp_sep_is_playing() to internal API Mikel Astiz
2012-09-14 12:03 ` [RFC v4 3/9] media: Add gateway_get_state() " Mikel Astiz
2012-09-14 12:03 ` [RFC v4 4/9] media: Replace transport->in_use flag with state Mikel Astiz
2012-09-14 12:03 ` Mikel Astiz [this message]
2012-09-14 12:03 ` [RFC v4 6/9] media: Split transport state based on playing flag Mikel Astiz
2012-09-14 12:03 ` [RFC v4 7/9] media: Expose transport state in D-Bus Mikel Astiz
2012-09-14 12:03 ` [RFC v4 8/9] media: Automatically release transport when HUP Mikel Astiz
2012-09-14 12:03 ` [RFC v4 9/9] media: Extend media API with optional acquire Mikel Astiz
2012-09-14 12:16 ` [RFC v4 0/9] Optional acquire in Media API and related Maxim Levitsky
2012-09-14 12:40 ` Mikel Astiz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1347624196-11281-6-git-send-email-mikel.astiz.oss@gmail.com \
--to=mikel.astiz.oss@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=mikel.astiz@bmw-carit.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox