audio_bluetooth_hw.cc 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * Copyright 2019 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #define LOG_TAG "BTAudioHw"
  17. #include <android-base/logging.h>
  18. #include <errno.h>
  19. #include <hardware/audio.h>
  20. #include <hardware/hardware.h>
  21. #include <log/log.h>
  22. #include <malloc.h>
  23. #include <string.h>
  24. #include <system/audio.h>
  25. #include "stream_apis.h"
  26. #include "utils.h"
  27. static int adev_set_parameters(struct audio_hw_device* dev,
  28. const char* kvpairs) {
  29. LOG(VERBOSE) << __func__ << ": kevpairs=[" << kvpairs << "]";
  30. return -ENOSYS;
  31. }
  32. static char* adev_get_parameters(const struct audio_hw_device* dev,
  33. const char* keys) {
  34. LOG(VERBOSE) << __func__ << ": keys=[" << keys << "]";
  35. return strdup("");
  36. }
  37. static int adev_init_check(const struct audio_hw_device* dev) { return 0; }
  38. static int adev_set_voice_volume(struct audio_hw_device* dev, float volume) {
  39. LOG(VERBOSE) << __func__ << ": volume=" << volume;
  40. return -ENOSYS;
  41. }
  42. static int adev_set_master_volume(struct audio_hw_device* dev, float volume) {
  43. LOG(VERBOSE) << __func__ << ": volume=" << volume;
  44. return -ENOSYS;
  45. }
  46. static int adev_get_master_volume(struct audio_hw_device* dev, float* volume) {
  47. return -ENOSYS;
  48. }
  49. static int adev_set_master_mute(struct audio_hw_device* dev, bool muted) {
  50. LOG(VERBOSE) << __func__ << ": mute=" << muted;
  51. return -ENOSYS;
  52. }
  53. static int adev_get_master_mute(struct audio_hw_device* dev, bool* muted) {
  54. return -ENOSYS;
  55. }
  56. static int adev_set_mode(struct audio_hw_device* dev, audio_mode_t mode) {
  57. LOG(VERBOSE) << __func__ << ": mode=" << mode;
  58. return 0;
  59. }
  60. static int adev_set_mic_mute(struct audio_hw_device* dev, bool state) {
  61. LOG(VERBOSE) << __func__ << ": state=" << state;
  62. return -ENOSYS;
  63. }
  64. static int adev_get_mic_mute(const struct audio_hw_device* dev, bool* state) {
  65. return -ENOSYS;
  66. }
  67. static int adev_dump(const audio_hw_device_t* device, int fd) { return 0; }
  68. static int adev_close(hw_device_t* device) {
  69. free(device);
  70. return 0;
  71. }
  72. static int adev_open(const hw_module_t* module, const char* name,
  73. hw_device_t** device) {
  74. LOG(VERBOSE) << __func__ << ": name=[" << name << "]";
  75. if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0) return -EINVAL;
  76. struct audio_hw_device* adev =
  77. (struct audio_hw_device*)calloc(1, sizeof(struct audio_hw_device));
  78. if (!adev) return -ENOMEM;
  79. adev->common.tag = HARDWARE_DEVICE_TAG;
  80. adev->common.version = AUDIO_DEVICE_API_VERSION_2_0;
  81. adev->common.module = (struct hw_module_t*)module;
  82. adev->common.close = adev_close;
  83. adev->init_check = adev_init_check;
  84. adev->set_voice_volume = adev_set_voice_volume;
  85. adev->set_master_volume = adev_set_master_volume;
  86. adev->get_master_volume = adev_get_master_volume;
  87. adev->set_mode = adev_set_mode;
  88. adev->set_mic_mute = adev_set_mic_mute;
  89. adev->get_mic_mute = adev_get_mic_mute;
  90. adev->set_parameters = adev_set_parameters;
  91. adev->get_parameters = adev_get_parameters;
  92. adev->get_input_buffer_size = adev_get_input_buffer_size;
  93. adev->open_output_stream = adev_open_output_stream;
  94. adev->close_output_stream = adev_close_output_stream;
  95. adev->open_input_stream = adev_open_input_stream;
  96. adev->close_input_stream = adev_close_input_stream;
  97. adev->dump = adev_dump;
  98. adev->set_master_mute = adev_set_master_mute;
  99. adev->get_master_mute = adev_get_master_mute;
  100. *device = &adev->common;
  101. return 0;
  102. }
  103. static struct hw_module_methods_t hal_module_methods = {
  104. .open = adev_open,
  105. };
  106. struct audio_module HAL_MODULE_INFO_SYM = {
  107. .common =
  108. {
  109. .tag = HARDWARE_MODULE_TAG,
  110. .module_api_version = AUDIO_MODULE_API_VERSION_0_1,
  111. .hal_api_version = HARDWARE_HAL_API_VERSION,
  112. .id = AUDIO_HARDWARE_MODULE_ID,
  113. .name = "Bluetooth Audio HW HAL",
  114. .author = "The Android Open Source Project",
  115. .methods = &hal_module_methods,
  116. },
  117. };