TB2026-YDS Firmware
Loading...
Searching...
No Matches
sink_bluetooth.c File Reference

Bluetooth A2DP audio sink: bridge the push pipeline to the pull A2DP source. More...

#include "sink_bluetooth.h"
#include "bluetooth.h"
#include "decoder.h"
#include "freertos/FreeRTOS.h"
#include "freertos/stream_buffer.h"
#include "freertos/task.h"
#include "freertos/timers.h"
#include "freertos/semphr.h"
#include "esp_attr.h"
#include <string.h>
#include <stdint.h>

Macros

#define SINK_BT_RB_BYTES   (21 * 1024)
#define SINK_BT_WRITE_TO_MS   100 /* give up on a full ring after this (stalled link) */
#define SINK_BT_FRAME_BYTES   4 /* one 16-bit stereo frame in the ring */
#define SINK_BT_SUSPEND_DELAY_MS   3000 /* stop->SUSPEND grace: rides out skips and short pauses */

Functions

const audio_sink_tsink_bluetooth_get (void)
 Get the Bluetooth A2DP sink (PCM -> ring buffer -> A2DP source -> speaker).

Detailed Description

Bluetooth A2DP audio sink: bridge the push pipeline to the pull A2DP source.

The pipeline pushes PCM via write(); the A2DP source pulls PCM from its own task. A stream buffer decouples the two: write() paces the pipeline by accepting only what fits (the Bluetooth link is the real-time clock). The stack encodes SBC and paces transmission.

The media session outlives one start/stop pair: stop() only arms a deferred SUSPEND and start() cancels it, so a track change (stop+start back-to-back) keeps the stream running. The SUSPEND/CHECK_SRC_RDY/START media commands are asynchronous and unserialised in the stack; issuing a pair of them per skip both added ~1 s of latency and could interleave so the session ended up suspended while the player believed it was playing (silent tracks).

Note
Développé avec l'assistance de Claude Opus 4.8 (Anthropic), sous la direction de Y. Dos Santos : spécification, revue et validation sur cible par l'auteur.

Macro Definition Documentation

◆ SINK_BT_FRAME_BYTES

#define SINK_BT_FRAME_BYTES   4 /* one 16-bit stereo frame in the ring */

◆ SINK_BT_RB_BYTES

#define SINK_BT_RB_BYTES   (21 * 1024)

◆ SINK_BT_SUSPEND_DELAY_MS

#define SINK_BT_SUSPEND_DELAY_MS   3000 /* stop->SUSPEND grace: rides out skips and short pauses */

◆ SINK_BT_WRITE_TO_MS

#define SINK_BT_WRITE_TO_MS   100 /* give up on a full ring after this (stalled link) */

Function Documentation

◆ sink_bluetooth_get()

const audio_sink_t * sink_bluetooth_get ( void )

Get the Bluetooth A2DP sink (PCM -> ring buffer -> A2DP source -> speaker).

Returns
Pointer to the static sink vtable (never NULL). start() requires a live Bluetooth connection (see bluetooth_connect()).