mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-21 22:20:57 +00:00
btstack_audio: split audio interface into source / sink
This commit is contained in:
parent
bcbbbb4271
commit
e39d945b26
@ -386,9 +386,9 @@ static int media_processing_init(avdtp_media_codec_configuration_sbc_t configura
|
|||||||
btstack_resample_init(&resample_instance, configuration.num_channels);
|
btstack_resample_init(&resample_instance, configuration.num_channels);
|
||||||
|
|
||||||
// setup audio playback
|
// setup audio playback
|
||||||
const btstack_audio_t * audio = btstack_audio_get_instance();
|
const btstack_audio_sink_t * audio = btstack_audio_sink_get_instance();
|
||||||
if (audio){
|
if (audio){
|
||||||
audio->init(NUM_CHANNELS, configuration.sampling_frequency, &playback_handler, NULL);
|
audio->init(NUM_CHANNELS, configuration.sampling_frequency, &playback_handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
audio_stream_started = 0;
|
audio_stream_started = 0;
|
||||||
@ -415,7 +415,7 @@ static void media_processing_close(void){
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// stop audio playback
|
// stop audio playback
|
||||||
const btstack_audio_t * audio = btstack_audio_get_instance();
|
const btstack_audio_sink_t * audio = btstack_audio_sink_get_instance();
|
||||||
if (audio){
|
if (audio){
|
||||||
audio->close();
|
audio->close();
|
||||||
}
|
}
|
||||||
@ -442,7 +442,7 @@ static void handle_l2cap_media_data_packet(uint8_t seid, uint8_t *packet, uint16
|
|||||||
avdtp_sbc_codec_header_t sbc_header;
|
avdtp_sbc_codec_header_t sbc_header;
|
||||||
if (!read_sbc_header(packet, size, &pos, &sbc_header)) return;
|
if (!read_sbc_header(packet, size, &pos, &sbc_header)) return;
|
||||||
|
|
||||||
const btstack_audio_t * audio = btstack_audio_get_instance();
|
const btstack_audio_sink_t * audio = btstack_audio_sink_get_instance();
|
||||||
|
|
||||||
// process data right away if there's no audio implementation active, e.g. on posix systems to store as .wav
|
// process data right away if there's no audio implementation active, e.g. on posix systems to store as .wav
|
||||||
if (!audio){
|
if (!audio){
|
||||||
|
@ -42,20 +42,39 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static const btstack_audio_t * btstack_audio_instance;
|
static const btstack_audio_sink_t * btstack_audio_sink_instance;
|
||||||
|
|
||||||
|
static const btstack_audio_source_t * btstack_audio_source_instance;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get BTstack Audio Instance
|
* @brief Get BTstack Audio Sink Instance
|
||||||
* @returns btstack_audio implementation
|
* @returns btstack_audio_sink implementation
|
||||||
*/
|
*/
|
||||||
const btstack_audio_t * btstack_audio_get_instance(void){
|
const btstack_audio_sink_t * btstack_audio_sink_get_instance(void){
|
||||||
return btstack_audio_instance;
|
return btstack_audio_sink_instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get BTstack Audio Instance
|
* @brief Get BTstack Audio Source Instance
|
||||||
* @param btstack_audio implementation
|
* @returns btstack_audio_source implementation
|
||||||
*/
|
*/
|
||||||
void btstack_audio_set_instance(const btstack_audio_t * audio_impl){
|
const btstack_audio_source_t * btstack_audio_source_get_instance(void){
|
||||||
btstack_audio_instance = audio_impl;
|
return btstack_audio_source_instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get BTstack Audio Sink Instance
|
||||||
|
* @param btstack_audio_sink implementation
|
||||||
|
*/
|
||||||
|
void btstack_audio_sink_set_instance(const btstack_audio_sink_t * audio_sink_impl){
|
||||||
|
btstack_audio_sink_instance = audio_sink_impl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get BTstack Audio Source Instance
|
||||||
|
* @param btstack_audio_source implementation
|
||||||
|
*/
|
||||||
|
void btstack_audio_source_set_instance(const btstack_audio_source_t * audio_source_impl){
|
||||||
|
btstack_audio_source_instance = audio_source_impl;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -52,48 +52,98 @@ extern "C" {
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Setup audio codec for specified samplerate and number of channels
|
* @brief Setup audio codec for specified samplerate and number of channels
|
||||||
* @param Channels (1=mono, 2=stereo)
|
* @param Channels (1=mono, 2=stereo)
|
||||||
* @param Sample rate
|
* @param Sample rate
|
||||||
* @param Playback callback
|
* @param Playback callback
|
||||||
* @param Recording callback
|
|
||||||
* @return 1 on success
|
* @return 1 on success
|
||||||
*/
|
*/
|
||||||
int (*init)(uint8_t channels,
|
int (*init)(uint8_t channels,
|
||||||
uint32_t samplerate,
|
uint32_t samplerate,
|
||||||
void (*playback) ( int16_t * buffer, uint16_t num_samples),
|
void (*playback) ( int16_t * buffer, uint16_t num_samples));
|
||||||
void (*recording)(const int16_t * buffer, uint16_t num_samples));
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Start stream
|
* @brief Start stream
|
||||||
*/
|
*/
|
||||||
void (*start_stream)(void);
|
void (*start_stream)(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @brief Stop stream
|
||||||
|
*/
|
||||||
|
void (*stop_stream)(void);
|
||||||
|
|
||||||
|
/**
|
||||||
* @brief Close audio codec
|
* @brief Close audio codec
|
||||||
*/
|
*/
|
||||||
void (*close)(void);
|
void (*close)(void);
|
||||||
|
|
||||||
} btstack_audio_t;
|
} btstack_audio_sink_t;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Setup audio codec for specified samplerate and number of channels
|
||||||
|
* @param Channels (1=mono, 2=stereo)
|
||||||
|
* @param Sample rate
|
||||||
|
* @param Recording callback
|
||||||
|
* @return 1 on success
|
||||||
|
*/
|
||||||
|
int (*init)(uint8_t channels,
|
||||||
|
uint32_t samplerate,
|
||||||
|
void (*recording)(const int16_t * buffer, uint16_t num_samples));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Start stream
|
||||||
|
*/
|
||||||
|
void (*start_stream)(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Stop stream
|
||||||
|
*/
|
||||||
|
void (*stop_stream)(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Close audio codec
|
||||||
|
*/
|
||||||
|
void (*close)(void);
|
||||||
|
|
||||||
|
} btstack_audio_source_t;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get BTstack Audio Instance
|
* @brief Get BTstack Audio Sink Instance
|
||||||
* @returns btstack_audio implementation
|
* @returns btstack_audio_sink implementation
|
||||||
*/
|
*/
|
||||||
const btstack_audio_t * btstack_audio_get_instance(void);
|
const btstack_audio_sink_t * btstack_audio_sink_get_instance(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get BTstack Audio Instance
|
* @brief Get BTstack Audio Source Instance
|
||||||
* @param btstack_audio implementation
|
* @returns btstack_audio_source implementation
|
||||||
*/
|
*/
|
||||||
void btstack_audio_set_instance(const btstack_audio_t * audio_impl);
|
const btstack_audio_source_t * btstack_audio_source_get_instance(void);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get BTstack Audio Sink Instance
|
||||||
|
* @param btstack_audio_sink implementation
|
||||||
|
*/
|
||||||
|
void btstack_audio_sink_set_instance(const btstack_audio_sink_t * audio_sink_impl);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get BTstack Audio Source Instance
|
||||||
|
* @param btstack_audio_source implementation
|
||||||
|
*/
|
||||||
|
void btstack_audio_source_set_instance(const btstack_audio_source_t * audio_source_impl);
|
||||||
|
|
||||||
|
|
||||||
// common implementations
|
// common implementations
|
||||||
const btstack_audio_t * btstack_audio_portaudio_get_instance(void);
|
const btstack_audio_sink_t * btstack_audio_portaudio_sink_get_instance(void);
|
||||||
const btstack_audio_t * btstack_audio_embedded_get_instance(void);
|
const btstack_audio_source_t * btstack_audio_portaudio_source_get_instance(void);
|
||||||
const btstack_audio_t * btstack_audio_esp32_get_instance(void);
|
|
||||||
|
//const btstack_audio_t * btstack_audio_embedded_get_instance(void);
|
||||||
|
//const btstack_audio_t * btstack_audio_esp32_get_instance(void);
|
||||||
|
|
||||||
#if defined __cplusplus
|
#if defined __cplusplus
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user