stream_apis.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. #pragma once
  17. #include <hardware/audio.h>
  18. #include <system/audio.h>
  19. #include "device_port_proxy.h"
  20. constexpr unsigned int kBluetoothDefaultSampleRate = 44100;
  21. constexpr audio_format_t kBluetoothDefaultAudioFormatBitsPerSample =
  22. AUDIO_FORMAT_PCM_16_BIT;
  23. constexpr unsigned int kBluetoothDefaultInputBufferMs = 20;
  24. constexpr unsigned int kBluetoothDefaultOutputBufferMs = 10;
  25. constexpr audio_channel_mask_t kBluetoothDefaultOutputChannelModeMask =
  26. AUDIO_CHANNEL_OUT_STEREO;
  27. enum class BluetoothStreamState : uint8_t {
  28. DISABLED = 0, // This stream is closing or set param "suspend=true"
  29. STANDBY,
  30. STARTING,
  31. STARTED,
  32. SUSPENDING,
  33. UNKNOWN,
  34. };
  35. std::ostream& operator<<(std::ostream& os, const BluetoothStreamState& state);
  36. struct BluetoothStreamOut {
  37. // Must be the first member so it can be cast from audio_stream
  38. // or audio_stream_out pointer
  39. audio_stream_out stream_out_;
  40. ::android::bluetooth::audio::BluetoothAudioPortOut bluetooth_output_;
  41. int64_t last_write_time_us_;
  42. // Audio PCM Configs
  43. uint32_t sample_rate_;
  44. audio_channel_mask_t channel_mask_;
  45. audio_format_t format_;
  46. // frame is the number of samples per channel
  47. // frames count per tick
  48. size_t frames_count_;
  49. // total frames written, reset on standby
  50. uint64_t frames_rendered_;
  51. // total frames written after opened, never reset
  52. uint64_t frames_presented_;
  53. mutable std::mutex mutex_;
  54. };
  55. int adev_open_output_stream(struct audio_hw_device* dev,
  56. audio_io_handle_t handle, audio_devices_t devices,
  57. audio_output_flags_t flags,
  58. struct audio_config* config,
  59. struct audio_stream_out** stream_out,
  60. const char* address __unused);
  61. void adev_close_output_stream(struct audio_hw_device* dev,
  62. struct audio_stream_out* stream);
  63. size_t adev_get_input_buffer_size(const struct audio_hw_device* dev,
  64. const struct audio_config* config);
  65. int adev_open_input_stream(struct audio_hw_device* dev,
  66. audio_io_handle_t handle, audio_devices_t devices,
  67. struct audio_config* config,
  68. struct audio_stream_in** stream_in,
  69. audio_input_flags_t flags __unused,
  70. const char* address __unused,
  71. audio_source_t source __unused);
  72. void adev_close_input_stream(struct audio_hw_device* dev,
  73. struct audio_stream_in* in);