summaryrefslogtreecommitdiff
path: root/android/client
diff options
context:
space:
mode:
authorJakub Tyszkowski <jakub.tyszkowski@tieto.com>2014-11-24 09:46:47 +0100
committerSzymon Janc <szymon.janc@tieto.com>2014-11-27 18:07:15 +0100
commitaa043e8586d26bcad34efd6ce1dc944024dde7c7 (patch)
tree10cdc3e458fed2a7c341becd95fd4ab27829ad1b /android/client
parent7217d1f5b1287084b0184f32437511665c245466 (diff)
downloadbluez-aa043e8586d26bcad34efd6ce1dc944024dde7c7.tar.gz
android/client: Add a2dp sink support
This adds support for a2dp sink HAL, which is almost identical to source role.
Diffstat (limited to 'android/client')
-rw-r--r--android/client/haltest.c2
-rw-r--r--android/client/if-av-sink.c139
-rw-r--r--android/client/if-bt.c3
-rw-r--r--android/client/if-main.h2
4 files changed, 146 insertions, 0 deletions
diff --git a/android/client/haltest.c b/android/client/haltest.c
index add197894..72771b3ee 100644
--- a/android/client/haltest.c
+++ b/android/client/haltest.c
@@ -52,6 +52,7 @@ const struct interface *interfaces[] = {
&hf_client_if,
&mce_if,
&ctrl_rc_if,
+ &av_sink_if,
#endif
NULL
};
@@ -401,6 +402,7 @@ static void init(void)
BT_PROFILE_HANDSFREE_CLIENT_ID,
BT_PROFILE_MAP_CLIENT_ID,
BT_PROFILE_AV_RC_CTRL_ID,
+ BT_PROFILE_ADVANCED_AUDIO_SINK_ID,
#endif
};
const struct method *m;
diff --git a/android/client/if-av-sink.c b/android/client/if-av-sink.c
new file mode 100644
index 000000000..3087dcfb1
--- /dev/null
+++ b/android/client/if-av-sink.c
@@ -0,0 +1,139 @@
+/*
+ * Copyright (C) 2014 Intel Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "if-main.h"
+#include "../hal-utils.h"
+
+const btav_interface_t *if_av_sink = NULL;
+
+SINTMAP(btav_connection_state_t, -1, "(unknown)")
+ DELEMENT(BTAV_CONNECTION_STATE_DISCONNECTED),
+ DELEMENT(BTAV_CONNECTION_STATE_CONNECTING),
+ DELEMENT(BTAV_CONNECTION_STATE_CONNECTED),
+ DELEMENT(BTAV_CONNECTION_STATE_DISCONNECTING),
+ENDMAP
+
+SINTMAP(btav_audio_state_t, -1, "(unknown)")
+ DELEMENT(BTAV_AUDIO_STATE_REMOTE_SUSPEND),
+ DELEMENT(BTAV_AUDIO_STATE_STOPPED),
+ DELEMENT(BTAV_AUDIO_STATE_STARTED),
+ENDMAP
+
+static char last_addr[MAX_ADDR_STR_LEN];
+
+static void connection_state(btav_connection_state_t state,
+ bt_bdaddr_t *bd_addr)
+{
+ haltest_info("(sink) %s: connection_state=%s remote_bd_addr=%s\n",
+ __func__, btav_connection_state_t2str(state),
+ bt_bdaddr_t2str(bd_addr, last_addr));
+}
+
+static void audio_state(btav_audio_state_t state, bt_bdaddr_t *bd_addr)
+{
+ haltest_info("(sink) %s: audio_state=%s remote_bd_addr=%s\n", __func__,
+ btav_audio_state_t2str(state),
+ bt_bdaddr_t2str(bd_addr, last_addr));
+}
+
+static void audio_config(bt_bdaddr_t *bd_addr, uint32_t sample_rate,
+ uint8_t channel_count) {
+ haltest_info("(sink) %s: addr=%s\n sample_rate=%d\n channel_count=%d\n",
+ __func__, bt_bdaddr_t2str(bd_addr, last_addr),
+ sample_rate, channel_count);
+}
+
+static btav_callbacks_t av_cbacks = {
+ .size = sizeof(av_cbacks),
+ .connection_state_cb = connection_state,
+ .audio_state_cb = audio_state,
+ .audio_config_cb = audio_config,
+};
+
+/* init */
+
+static void init_p(int argc, const char **argv)
+{
+ RETURN_IF_NULL(if_av_sink);
+
+ EXEC(if_av_sink->init, &av_cbacks);
+}
+
+/* connect */
+
+static void connect_c(int argc, const char **argv, enum_func *enum_func,
+ void **user)
+{
+ if (argc == 3) {
+ *user = NULL;
+ *enum_func = enum_devices;
+ }
+}
+
+static void connect_p(int argc, const char **argv)
+{
+ bt_bdaddr_t addr;
+
+ RETURN_IF_NULL(if_av_sink);
+ VERIFY_ADDR_ARG(2, &addr);
+
+ EXEC(if_av_sink->connect, &addr);
+}
+
+/* disconnect */
+
+static void disconnect_c(int argc, const char **argv, enum_func *enum_func,
+ void **user)
+{
+ if (argc == 3) {
+ *user = last_addr;
+ *enum_func = enum_one_string;
+ }
+}
+
+static void disconnect_p(int argc, const char **argv)
+{
+ bt_bdaddr_t addr;
+
+ RETURN_IF_NULL(if_av_sink);
+ VERIFY_ADDR_ARG(2, &addr);
+
+ EXEC(if_av_sink->disconnect, &addr);
+}
+
+/* cleanup */
+
+static void cleanup_p(int argc, const char **argv)
+{
+ RETURN_IF_NULL(if_av_sink);
+
+ EXECV(if_av_sink->cleanup);
+ if_av_sink = NULL;
+}
+
+static struct method methods[] = {
+ STD_METHOD(init),
+ STD_METHODCH(connect, "<addr>"),
+ STD_METHODCH(disconnect, "<addr>"),
+ STD_METHOD(cleanup),
+ END_METHOD
+};
+
+const struct interface av_sink_if = {
+ .name = "av-sink",
+ .methods = methods
+};
diff --git a/android/client/if-bt.c b/android/client/if-bt.c
index bfb2e4763..4f1a9d996 100644
--- a/android/client/if-bt.c
+++ b/android/client/if-bt.c
@@ -832,6 +832,7 @@ static void get_profile_interface_c(int argc, const char **argv,
BT_PROFILE_HANDSFREE_CLIENT_ID,
BT_PROFILE_MAP_CLIENT_ID,
BT_PROFILE_AV_RC_CTRL_ID,
+ BT_PROFILE_ADVANCED_AUDIO_SINK_ID,
#endif
NULL
};
@@ -878,6 +879,8 @@ static void get_profile_interface_p(int argc, const char **argv)
pif = (const void **) &if_hf_client;
else if (strcmp(BT_PROFILE_MAP_CLIENT_ID, id) == 0)
pif = (const void **) &if_mce;
+ else if (strcmp(BT_PROFILE_ADVANCED_AUDIO_SINK_ID, id) == 0)
+ pif = (const void **) &if_av_sink;
#endif
else
haltest_error("%s is not correct for get_profile_interface\n",
diff --git a/android/client/if-main.h b/android/client/if-main.h
index 96409aa45..7fc8dad81 100644
--- a/android/client/if-main.h
+++ b/android/client/if-main.h
@@ -68,6 +68,7 @@ extern const btgatt_client_interface_t *if_gatt_client;
extern const btrc_ctrl_interface_t *if_rc_ctrl;
extern const bthf_client_interface_t *if_hf_client;
extern const btmce_interface_t *if_mce;
+extern const btav_interface_t *if_av_sink;
#endif
/*
@@ -96,6 +97,7 @@ extern const struct interface hl_if;
extern const struct interface ctrl_rc_if;
extern const struct interface hf_client_if;
extern const struct interface mce_if;
+extern const struct interface av_sink_if;
#endif
/* Interfaces that will show up in tool (first part of command line) */