[pulseaudio-discuss] [PATCH v8 07/12] bluetooth: Add A2DP aptX and aptX HD codecs support

Pali Rohár pali.rohar at gmail.com
Sat Apr 20 10:28:40 UTC 2019


On Friday 19 April 2019 12:52:56 Pali Rohár wrote:
> On Friday 19 April 2019 11:41:22 Tanu Kaskinen wrote:
> > On Sat, 2019-04-06 at 11:16 +0200, Pali Rohár wrote:
> > > +static size_t decode_buffer(void *codec_info, const uint8_t *input_buffer, size_t input_size, uint8_t *output_buffer, size_t output_size, size_t *processed) {
> > > +    struct aptx_context *aptx_c = (struct aptx_context *) codec_info;
> > > +
> > > +    const uint8_t *p;
> > > +    uint8_t *d;
> > > +    size_t to_write, to_decode;
> > > +
> > > +    p = input_buffer;
> > > +    to_decode = input_size;
> > > +
> > > +    d = output_buffer;
> > > +    to_write = output_size;
> > > +
> > > +    while (PA_LIKELY(to_decode > 0)) {
> > 
> > Is it intentional that encode_buffer() checks both to_encode and
> > to_write in the while loop condition, but decode_buffer() only checks
> > to_decode? If so, why does encode_buffer() need to be extra careful but
> > decode_buffer() doesn't?
> 
> These checks are similar/same as in SBC codec code. And SBC code was
> there prior to my work. So personally I do not know.

Ok, now I know reason. libsbc's function sbc_encode() encodes one frame.
Therefore to encode whole buffer it is needed to call sbc_encode() more
times in loop. Moreover SBC data in A2DP are encapsulated in RTP
protocol. And in RTP header is information about number of SBC frames.

On the other hand, libopenaptx's aptx_encode() encodes whole input
buffer. In aptX "frame" equivalent as smallest unit is 4 stereo samples.
And aptx_encode() process as much as possible input data.

FastStream in A2DP is SBC codec (so libsbc's sbc_encode() is used), with
some fixed encoder parameters, but SBC data are not encapsulated in RTP
protocol.

Decoder functions sbc_decode() and aptx_decode() works similarly like
their *_encode variants (sbc decodes one frame, aptx as much as possible
from input buffer).

So code for codecs can be simplified/changed, e.g. aptx functions doe
not have to be called in loop, ...

-- 
Pali Rohár
pali.rohar at gmail.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/pulseaudio-discuss/attachments/20190420/16eeb0a0/attachment.sig>


More information about the pulseaudio-discuss mailing list