if-av.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // SPDX-License-Identifier: Apache-2.0
  2. /*
  3. * Copyright (C) 2013 Intel Corporation
  4. *
  5. */
  6. #define _GNU_SOURCE
  7. #include "if-main.h"
  8. #include "../hal-utils.h"
  9. const btav_interface_t *if_av = NULL;
  10. SINTMAP(btav_connection_state_t, -1, "(unknown)")
  11. DELEMENT(BTAV_CONNECTION_STATE_DISCONNECTED),
  12. DELEMENT(BTAV_CONNECTION_STATE_CONNECTING),
  13. DELEMENT(BTAV_CONNECTION_STATE_CONNECTED),
  14. DELEMENT(BTAV_CONNECTION_STATE_DISCONNECTING),
  15. ENDMAP
  16. SINTMAP(btav_audio_state_t, -1, "(unknown)")
  17. DELEMENT(BTAV_AUDIO_STATE_REMOTE_SUSPEND),
  18. DELEMENT(BTAV_AUDIO_STATE_STOPPED),
  19. DELEMENT(BTAV_AUDIO_STATE_STARTED),
  20. ENDMAP
  21. static char last_addr[MAX_ADDR_STR_LEN];
  22. static void connection_state(btav_connection_state_t state,
  23. bt_bdaddr_t *bd_addr)
  24. {
  25. haltest_info("%s: connection_state=%s remote_bd_addr=%s\n", __func__,
  26. btav_connection_state_t2str(state),
  27. bt_bdaddr_t2str(bd_addr, last_addr));
  28. }
  29. static void audio_state(btav_audio_state_t state, bt_bdaddr_t *bd_addr)
  30. {
  31. haltest_info("%s: audio_state=%s remote_bd_addr=%s\n", __func__,
  32. btav_audio_state_t2str(state),
  33. bt_bdaddr_t2str(bd_addr, last_addr));
  34. }
  35. #if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
  36. static void audio_config(bt_bdaddr_t *bd_addr, uint32_t sample_rate,
  37. uint8_t channel_count) {
  38. haltest_info("%s: remote_addr=%s\n sample_rate=%d\n channel_count=%d\n",
  39. __func__, bt_bdaddr_t2str(bd_addr, last_addr),
  40. sample_rate, channel_count);
  41. }
  42. #endif
  43. static btav_callbacks_t av_cbacks = {
  44. .size = sizeof(av_cbacks),
  45. .connection_state_cb = connection_state,
  46. .audio_state_cb = audio_state,
  47. #if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
  48. .audio_config_cb = audio_config,
  49. #endif
  50. };
  51. /* init */
  52. static void init_p(int argc, const char **argv)
  53. {
  54. RETURN_IF_NULL(if_av);
  55. EXEC(if_av->init, &av_cbacks);
  56. }
  57. /* connect */
  58. static void connect_c(int argc, const char **argv, enum_func *enum_func,
  59. void **user)
  60. {
  61. if (argc == 3) {
  62. *user = NULL;
  63. *enum_func = enum_devices;
  64. }
  65. }
  66. static void connect_p(int argc, const char **argv)
  67. {
  68. bt_bdaddr_t addr;
  69. RETURN_IF_NULL(if_av);
  70. VERIFY_ADDR_ARG(2, &addr);
  71. EXEC(if_av->connect, &addr);
  72. }
  73. /* disconnect */
  74. static void disconnect_c(int argc, const char **argv, enum_func *enum_func,
  75. void **user)
  76. {
  77. if (argc == 3) {
  78. *user = last_addr;
  79. *enum_func = enum_one_string;
  80. }
  81. }
  82. static void disconnect_p(int argc, const char **argv)
  83. {
  84. bt_bdaddr_t addr;
  85. RETURN_IF_NULL(if_av);
  86. VERIFY_ADDR_ARG(2, &addr);
  87. EXEC(if_av->disconnect, &addr);
  88. }
  89. /* cleanup */
  90. static void cleanup_p(int argc, const char **argv)
  91. {
  92. RETURN_IF_NULL(if_av);
  93. EXECV(if_av->cleanup);
  94. if_av = NULL;
  95. }
  96. static struct method methods[] = {
  97. STD_METHOD(init),
  98. STD_METHODCH(connect, "<addr>"),
  99. STD_METHODCH(disconnect, "<addr>"),
  100. STD_METHOD(cleanup),
  101. END_METHOD
  102. };
  103. const struct interface av_if = {
  104. .name = "av",
  105. .methods = methods
  106. };