3 #include "AudioConfig.h"
4 #include "AudioTools/CoreAudio/AudioBasic/Collections/Vector.h"
5 #include "AudioTools/CoreAudio/Buffers.h"
6 #include "AudioTools/CoreAudio/AudioBasic/StrView.h"
21 AudioBLEStream(
int defaultMTU) { max_transfer_size = defaultMTU; };
23 virtual void end() = 0;
25 virtual bool connected() = 0;
28 if (is_audio_info_active && this->info != info) {
31 writeAudioInfoCharacteristic(info);
35 operator bool() {
return connected(); }
37 void setServiceUUID(
const char *uuid) { BLE_AUDIO_SERVICE_UUID = uuid; }
39 void setRxUUID(
const char *uuid) { BLE_CH2_UUID = uuid; }
41 void setTxUUID(
const char *uuid) { BLE_CH1_UUID = uuid; }
43 void setAudioInfoUUID(
const char *uuid) { BLE_INFO_UUID = uuid; }
45 void setAudioInfoActive(
bool flag) { is_audio_info_active = flag; }
47 void setFramed(
bool flag) { is_framed = flag; }
49 StrView toStr(AudioInfo info) {
50 snprintf(audio_info_str, 40,
"%d:%d:%d", info.sample_rate, info.channels,
51 info.bits_per_sample);
52 return StrView(audio_info_str);
55 AudioInfo toInfo(
const uint8_t *str) {
57 sscanf((
char*)str,
"%d:%d:%d", &result.sample_rate, &result.channels, &result.bits_per_sample);
63 AudioBLEStream(AudioBLEStream
const &other) =
delete;
65 void operator=(AudioBLEStream
const &other) =
delete;
66 const char *ble_server_name =
nullptr;
67 uint16_t max_transfer_size = 0;
68 bool is_started =
false;
69 bool is_audio_info_active =
false;
70 bool is_framed =
false;
71 char audio_info_str[40];
75 const char *BLE_AUDIO_SERVICE_UUID =
"6e400001-b5a3-f393-e0a9-e50e24dcca9e";
76 const char *BLE_CH1_UUID =
"6e400002-b5a3-f393-e0a9-e50e24dcca9e";
77 const char *BLE_CH2_UUID =
"6e400003-b5a3-f393-e0a9-e50e24dcca9e";
78 const char *BLE_INFO_UUID =
"6e400004-b5a3-f393-e0a9-e50e24dcca9e";
80 virtual int getMTU() = 0;
83 virtual void setAudioInfo(
const uint8_t *data,
size_t size) {
84 if (is_audio_info_active) {
85 AudioInfo ai = toInfo(data);
90 virtual void writeAudioInfoCharacteristic(AudioInfo info) = 0;