1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
// SPDX-License-Identifier: Apache-2.0
/*
* Copyright (C) 2013 Intel Corporation
*
*/
#define _GNU_SOURCE
#include "if-main.h"
#include "../hal-utils.h"
const btav_interface_t *if_av = 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("%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("%s: audio_state=%s remote_bd_addr=%s\n", __func__,
btav_audio_state_t2str(state),
bt_bdaddr_t2str(bd_addr, last_addr));
}
#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
static void audio_config(bt_bdaddr_t *bd_addr, uint32_t sample_rate,
uint8_t channel_count) {
haltest_info("%s: remote_addr=%s\n sample_rate=%d\n channel_count=%d\n",
__func__, bt_bdaddr_t2str(bd_addr, last_addr),
sample_rate, channel_count);
}
#endif
static btav_callbacks_t av_cbacks = {
.size = sizeof(av_cbacks),
.connection_state_cb = connection_state,
.audio_state_cb = audio_state,
#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
.audio_config_cb = audio_config,
#endif
};
/* init */
static void init_p(int argc, const char **argv)
{
RETURN_IF_NULL(if_av);
EXEC(if_av->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);
VERIFY_ADDR_ARG(2, &addr);
EXEC(if_av->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);
VERIFY_ADDR_ARG(2, &addr);
EXEC(if_av->disconnect, &addr);
}
/* cleanup */
static void cleanup_p(int argc, const char **argv)
{
RETURN_IF_NULL(if_av);
EXECV(if_av->cleanup);
if_av = 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_if = {
.name = "av",
.methods = methods
};
|