bluez5: support packet loss concealment in codecs

LC3 and Opus have built-in support for packet loss concealment.

Add codec interface for that, and implement for LC3.

Extend media_codec interface so that packets not aligned with socket
reads can be handled, as in HFP. This is required for correct sequence
number counting, and for being able to run codec PLC *before* decoding
the next correctly received packet.
This commit is contained in:
Pauli Virtanen 2025-06-13 20:53:49 +03:00 committed by Wim Taymans
parent a2ede93479
commit d0680a2b3d
5 changed files with 76 additions and 5 deletions

View file

@ -26,7 +26,7 @@
#define SPA_TYPE_INTERFACE_Bluez5CodecMedia SPA_TYPE_INFO_INTERFACE_BASE "Bluez5:Codec:Media:Private"
#define SPA_VERSION_BLUEZ5_CODEC_MEDIA 14
#define SPA_VERSION_BLUEZ5_CODEC_MEDIA 15
struct spa_bluez5_codec_a2dp {
struct spa_interface iface;
@ -88,6 +88,10 @@ struct media_codec {
const struct media_codec *duplex_codec; /**< Codec for non-standard A2DP duplex channel */
const bool stream_pkt; /**< If true, socket data may contain multiple packets.
* After successful decode, start_decode() should be
* called again to parse the remaining data. */
int (*get_bis_config)(const struct media_codec *codec, uint8_t *caps,
uint8_t *caps_size, struct spa_dict *settings,
struct bap_codec_qos *qos);
@ -202,6 +206,16 @@ struct media_codec {
void *dst, size_t dst_size,
size_t *dst_out);
/**
* Generate audio data corresponding to one lost packet, using codec internal
* packet loss concealment.
*
* NULL if not available.
*
* \return number of bytes produced, or < 0 for error
*/
int (*produce_plc) (void *data, void *dst, size_t dst_size);
int (*reduce_bitpool) (void *data);
int (*increase_bitpool) (void *data);