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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx

Attachment: signature.asc
Description: PGP signature

_______________________________________________
pulseaudio-discuss mailing list
pulseaudio-discuss@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss

[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux