Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 174d5aed authored by Jakub Pawłowski's avatar Jakub Pawłowski Committed by Automerger Merge Worker
Browse files

Merge changes I5be2b934,I93806d54,Icc5c0f57,I96946895,Iec549a64 am: d2bedfe2 am: 464adaad

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/2036324

Change-Id: Iad3282a818468ff2db22c4ad3452b838fe979cd6
parents 2f52d18c 464adaad
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -561,7 +561,8 @@ class LeAudioBroadcasterImpl : public LeAudioBroadcaster, public BigCallbacks {
                          int initial_channel_offset, int pitch_samples,
                          int num_channels) {
      auto encoder_status =
          lc3_encode(encoder, (int16_t*)(data.data() + initial_channel_offset),
          lc3_encode(encoder, LC3_PCM_FORMAT_S16,
                     (int16_t*)(data.data() + initial_channel_offset),
                     pitch_samples, out_buffer.size(), out_buffer.data());
      if (encoder_status != 0) {
        LOG(ERROR) << "Error while encoding"
+22 −15
Original line number Diff line number Diff line
@@ -1912,22 +1912,26 @@ class LeAudioClientImpl : public LeAudioClient {
    LOG(INFO) << __func__ << " data size: " << (int)data.size()
              << " byte count: " << byte_count << " mono: " << mono;
    if (!mono) {
      lc3_encode(lc3_encoder_left, (const int16_t*)data.data(), 2,
                 chan_left_enc.size(), chan_left_enc.data());
      lc3_encode(lc3_encoder_right, ((const int16_t*)data.data()) + 1, 2,
                 chan_right_enc.size(), chan_right_enc.data());
      lc3_encode(lc3_encoder_left, LC3_PCM_FORMAT_S16,
                 (const int16_t*)data.data(), 2, chan_left_enc.size(),
                 chan_left_enc.data());
      lc3_encode(lc3_encoder_right, LC3_PCM_FORMAT_S16,
                 ((const int16_t*)data.data()) + 1, 2, chan_right_enc.size(),
                 chan_right_enc.data());
    } else {
      std::vector<int16_t> chan_mono;
      get_mono_stream(data, chan_mono);

      if (left_cis_handle) {
        lc3_encode(lc3_encoder_left, (const int16_t*)chan_mono.data(), 1,
                   chan_left_enc.size(), chan_left_enc.data());
        lc3_encode(lc3_encoder_left, LC3_PCM_FORMAT_S16,
                   (const int16_t*)chan_mono.data(), 1, chan_left_enc.size(),
                   chan_left_enc.data());
      }

      if (right_cis_handle) {
        lc3_encode(lc3_encoder_right, (const int16_t*)chan_mono.data(), 1,
                   chan_right_enc.size(), chan_right_enc.data());
        lc3_encode(lc3_encoder_right, LC3_PCM_FORMAT_S16,
                   (const int16_t*)chan_mono.data(), 1, chan_right_enc.size(),
                   chan_right_enc.data());
      }
    }

@@ -1968,17 +1972,20 @@ class LeAudioClientImpl : public LeAudioClient {
      std::vector<int16_t> chan_mono;
      get_mono_stream(data, chan_mono);

      auto err = lc3_encode(lc3_encoder_left, (const int16_t*)chan_mono.data(),
                            1, byte_count, chan_encoded.data());
      auto err = lc3_encode(lc3_encoder_left, LC3_PCM_FORMAT_S16,
                            (const int16_t*)chan_mono.data(), 1, byte_count,
                            chan_encoded.data());

      if (err < 0) {
        LOG(ERROR) << " error while encoding, error code: " << +err;
      }
    } else {
      lc3_encode(lc3_encoder_left, (const int16_t*)data.data(), 2, byte_count,
      lc3_encode(lc3_encoder_left, LC3_PCM_FORMAT_S16,
                 (const int16_t*)data.data(), 2, byte_count,
                 chan_encoded.data());
      lc3_encode(lc3_encoder_right, (const int16_t*)data.data() + 1, 2,
                 byte_count, chan_encoded.data() + byte_count);
      lc3_encode(lc3_encoder_right, LC3_PCM_FORMAT_S16,
                 (const int16_t*)data.data() + 1, 2, byte_count,
                 chan_encoded.data() + byte_count);
    }

    /* Send data to the controller */
@@ -2202,8 +2209,8 @@ class LeAudioClientImpl : public LeAudioClient {
    lc3_decoder_t decoder_to_use =
        is_left ? lc3_decoder_left : lc3_decoder_right;

    err = lc3_decode(decoder_to_use, data, size, pcm_data_decoded.data(),
                     1 /* pitch */);
    err = lc3_decode(decoder_to_use, data, size, LC3_PCM_FORMAT_S16,
                     pcm_data_decoded.data(), 1 /* pitch */);

    if (err < 0) {
      LOG(ERROR) << " bad decoding parameters: " << static_cast<int>(err);
+9 −5
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@
#include "include/lc3.h"

void TestEncoder(FuzzedDataProvider& fdp) {
  enum lc3_pcm_format pcm_format =
      fdp.PickValueInArray({LC3_PCM_FORMAT_S16, LC3_PCM_FORMAT_S24});
  int dt_us = fdp.PickValueInArray({10000, 7500});
  int sr_hz =
      fdp.PickValueInArray({8000, 16000, 24000, 32000, /*44100,*/ 48000});
@@ -39,8 +41,8 @@ void TestEncoder(FuzzedDataProvider& fdp) {
      lc3_setup_encoder(dt_us, sr_hz, 0, lc3_encoder_mem);

  std::vector<uint8_t> output(output_byte_count);
  lc3_encode(lc3_encoder, (const int16_t*)input_frames.data(), 1, output.size(),
             output.data());
  lc3_encode(lc3_encoder, pcm_format, (const int16_t*)input_frames.data(), 1,
             output.size(), output.data());

  free(lc3_encoder_mem);
  lc3_encoder_mem = nullptr;
@@ -48,6 +50,8 @@ void TestEncoder(FuzzedDataProvider& fdp) {
}

void TestDecoder(FuzzedDataProvider& fdp) {
  enum lc3_pcm_format pcm_format =
      fdp.PickValueInArray({LC3_PCM_FORMAT_S16, LC3_PCM_FORMAT_S24});
  int dt_us = fdp.PickValueInArray({10000, 7500});
  int sr_hz =
      fdp.PickValueInArray({8000, 16000, 24000, 32000, /*44100,*/ 48000});
@@ -68,11 +72,11 @@ void TestDecoder(FuzzedDataProvider& fdp) {
      lc3_setup_decoder(dt_us, sr_hz, 0, lc3_decoder_mem);

  std::vector<uint16_t> output(num_frames);
  lc3_decode(lc3_decoder, input.data(), input.size(), (int16_t*)output.data(),
             1);
  lc3_decode(lc3_decoder, input.data(), input.size(), pcm_format,
             (int16_t*)output.data(), 1);

  /* Empty input performs PLC (packet loss concealment) */
  lc3_decode(lc3_decoder, nullptr, 0, (int16_t*)output.data(), 1);
  lc3_decode(lc3_decoder, nullptr, 0, pcm_format, (int16_t*)output.data(), 1);

  free(lc3_decoder_mem);
  lc3_decoder_mem = nullptr;
+21 −6
Original line number Diff line number Diff line
@@ -144,6 +144,19 @@ extern "C" {
      ((sr) == 32000) || ((sr) == 48000)                       )


/**
 * PCM Sample Format
 *   S16  Signed 16 bits, in 16 bits words (int16_t)
 *   S24  Signed 24 bits, using low three bytes of 32 bits words (int32_t).
 *        The high byte sign extends the sample value (bits 31..24 set to b23).
 */

enum lc3_pcm_format {
    LC3_PCM_FORMAT_S16,
    LC3_PCM_FORMAT_S24,
};


/**
 * Handle
 */
@@ -231,13 +244,14 @@ lc3_encoder_t lc3_setup_encoder(
/**
 * Encode a frame
 * encoder         Handle of the encoder
 * pcm, pitch      Input PCM samples, and count between two consecutives
 * fmt             PCM input format
 * pcm, stride     Input PCM samples, and count between two consecutives
 * nbytes          Target size, in bytes, of the frame (20 to 400)
 * out             Output buffer of `nbytes` size
 * return          0: On success  -1: Wrong parameters
 */
int lc3_encode(lc3_encoder_t encoder,
    const int16_t *pcm, int pitch, int nbytes, void *out);
int lc3_encode(lc3_encoder_t encoder, enum lc3_pcm_format fmt,
    const void *pcm, int stride, int nbytes, void *out);

/**
 * Return size needed for an decoder
@@ -271,11 +285,12 @@ lc3_decoder_t lc3_setup_decoder(
 * Decode a frame
 * decoder         Handle of the decoder
 * in, nbytes      Input bitstream, and size in bytes, NULL performs PLC
 * pcm, pitch      Output PCM samples, and count between two consecutives
 * fmt             PCM output format
 * pcm, stride     Output PCM samples, and count between two consecutives
 * return          0: On success  1: PLC operated  -1: Wrong parameters
 */
int lc3_decode(lc3_decoder_t decoder,
    const void *in, int nbytes, int16_t *pcm, int pitch);
int lc3_decode(lc3_decoder_t decoder, const void *in, int nbytes,
    enum lc3_pcm_format fmt, void *pcm, int stride);


#ifdef __cplusplus
+2 −2
Original line number Diff line number Diff line
@@ -286,9 +286,9 @@ static inline unsigned lc3_get_symbol(
    const struct lc3_ac_symbol *symbols = model->s;
    struct lc3_bits_ac *ac = &bits->ac;

    uint16_t range = ac->range >> 10;
    unsigned range = (ac->range >> 10) & 0xffff;

    ac->error |= (ac->low >= ((unsigned)range << 10));
    ac->error |= (ac->low >= (range << 10));
    if (ac->error)
        ac->low = 0;

Loading