Skip to content
Snippets Groups Projects
Commit 3293e02a authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Reduce the number of PCM data reads for aptX and aptX HD"

parents f5d6545f fbfffe53
No related branches found
No related tags found
No related merge requests found
...@@ -61,7 +61,7 @@ static tAPTX_ENCODER_SIZEOF_PARAMS aptx_encoder_sizeof_params_func; ...@@ -61,7 +61,7 @@ static tAPTX_ENCODER_SIZEOF_PARAMS aptx_encoder_sizeof_params_func;
#define A2DP_APTX_OFFSET (AVDT_MEDIA_OFFSET - AVDT_MEDIA_HDR_SIZE) #define A2DP_APTX_OFFSET (AVDT_MEDIA_OFFSET - AVDT_MEDIA_HDR_SIZE)
#endif #endif
#define A2DP_APTX_MAX_PCM_BYTES_PER_READ 1024 #define A2DP_APTX_MAX_PCM_BYTES_PER_READ 4096
typedef struct { typedef struct {
uint64_t sleep_time_ns; uint64_t sleep_time_ns;
...@@ -391,34 +391,38 @@ void a2dp_vendor_aptx_send_frames(uint64_t timestamp_us) { ...@@ -391,34 +391,38 @@ void a2dp_vendor_aptx_send_frames(uint64_t timestamp_us) {
// //
// Read the PCM data and encode it // Read the PCM data and encode it
// //
LOG_VERBOSE(LOG_TAG, "%s: %u PCM reads of size %u", __func__, uint16_t read_buffer16[A2DP_APTX_MAX_PCM_BYTES_PER_READ / sizeof(uint16_t)];
framing_params->pcm_reads, framing_params->pcm_bytes_per_read); uint32_t expected_read_bytes =
framing_params->pcm_reads * framing_params->pcm_bytes_per_read;
size_t encoded_ptr_index = 0; size_t encoded_ptr_index = 0;
size_t pcm_bytes_encoded = 0; size_t pcm_bytes_encoded = 0;
uint32_t bytes_read = 0; uint32_t bytes_read = 0;
a2dp_aptx_encoder_cb.stats.media_read_total_expected_packets++; a2dp_aptx_encoder_cb.stats.media_read_total_expected_packets++;
a2dp_aptx_encoder_cb.stats.media_read_total_expected_reads_count += a2dp_aptx_encoder_cb.stats.media_read_total_expected_reads_count++;
framing_params->pcm_reads;
a2dp_aptx_encoder_cb.stats.media_read_total_expected_read_bytes += a2dp_aptx_encoder_cb.stats.media_read_total_expected_read_bytes +=
framing_params->pcm_reads * framing_params->pcm_bytes_per_read; expected_read_bytes;
for (size_t reads = 0; reads < framing_params->pcm_reads; reads++) {
uint16_t read_buffer16[A2DP_APTX_MAX_PCM_BYTES_PER_READ / sizeof(uint16_t)]; LOG_VERBOSE(LOG_TAG, "%s: PCM read of size %u", __func__,
size_t pcm_bytes_read = a2dp_aptx_encoder_cb.read_callback( expected_read_bytes);
(uint8_t*)read_buffer16, framing_params->pcm_bytes_per_read); bytes_read = a2dp_aptx_encoder_cb.read_callback((uint8_t*)read_buffer16,
bytes_read += pcm_bytes_read; expected_read_bytes);
a2dp_aptx_encoder_cb.stats.media_read_total_actual_read_bytes += a2dp_aptx_encoder_cb.stats.media_read_total_actual_read_bytes += bytes_read;
pcm_bytes_read; if (bytes_read < expected_read_bytes) {
if (pcm_bytes_read < framing_params->pcm_bytes_per_read) { LOG_WARN(LOG_TAG,
LOG_WARN(LOG_TAG, "%s: underflow at PCM reading: read %u bytes instead of %u",
"%s: underflow at PCM reading iteration %zu: read %zu " __func__, bytes_read, expected_read_bytes);
"instead of %d", a2dp_aptx_encoder_cb.stats.media_read_total_dropped_packets++;
__func__, reads, pcm_bytes_read, osi_free(p_buf);
framing_params->pcm_bytes_per_read); return;
break; }
} a2dp_aptx_encoder_cb.stats.media_read_total_actual_reads_count++;
a2dp_aptx_encoder_cb.stats.media_read_total_actual_reads_count++;
for (uint32_t reads = 0, offset = 0; reads < framing_params->pcm_reads;
reads++, offset +=
(framing_params->pcm_bytes_per_read / sizeof(uint16_t))) {
pcm_bytes_encoded += aptx_encode_16bit(framing_params, &encoded_ptr_index, pcm_bytes_encoded += aptx_encode_16bit(framing_params, &encoded_ptr_index,
read_buffer16, encoded_ptr); read_buffer16 + offset, encoded_ptr);
} }
// Compute the number of encoded bytes // Compute the number of encoded bytes
......
...@@ -61,7 +61,7 @@ static tAPTX_HD_ENCODER_SIZEOF_PARAMS aptx_hd_encoder_sizeof_params_func; ...@@ -61,7 +61,7 @@ static tAPTX_HD_ENCODER_SIZEOF_PARAMS aptx_hd_encoder_sizeof_params_func;
#define A2DP_APTX_HD_OFFSET AVDT_MEDIA_OFFSET #define A2DP_APTX_HD_OFFSET AVDT_MEDIA_OFFSET
#endif #endif
#define A2DP_APTX_HD_MAX_PCM_BYTES_PER_READ 1024 #define A2DP_APTX_HD_MAX_PCM_BYTES_PER_READ 4096
typedef struct { typedef struct {
uint64_t sleep_time_ns; uint64_t sleep_time_ns;
...@@ -376,35 +376,41 @@ void a2dp_vendor_aptx_hd_send_frames(uint64_t timestamp_us) { ...@@ -376,35 +376,41 @@ void a2dp_vendor_aptx_hd_send_frames(uint64_t timestamp_us) {
// //
// Read the PCM data and encode it // Read the PCM data and encode it
// //
LOG_VERBOSE(LOG_TAG, "%s: %u PCM reads of size %u", __func__, uint32_t
framing_params->pcm_reads, framing_params->pcm_bytes_per_read); read_buffer32[A2DP_APTX_HD_MAX_PCM_BYTES_PER_READ / sizeof(uint32_t)];
uint32_t expected_read_bytes =
framing_params->pcm_reads * framing_params->pcm_bytes_per_read;
size_t encoded_ptr_index = 0; size_t encoded_ptr_index = 0;
size_t pcm_bytes_encoded = 0; size_t pcm_bytes_encoded = 0;
uint32_t bytes_read = 0; uint32_t bytes_read = 0;
a2dp_aptx_hd_encoder_cb.stats.media_read_total_expected_packets++; a2dp_aptx_hd_encoder_cb.stats.media_read_total_expected_packets++;
a2dp_aptx_hd_encoder_cb.stats.media_read_total_expected_reads_count += a2dp_aptx_hd_encoder_cb.stats.media_read_total_expected_reads_count++;
framing_params->pcm_reads;
a2dp_aptx_hd_encoder_cb.stats.media_read_total_expected_read_bytes += a2dp_aptx_hd_encoder_cb.stats.media_read_total_expected_read_bytes +=
framing_params->pcm_reads * framing_params->pcm_bytes_per_read; expected_read_bytes;
for (size_t reads = 0; reads < framing_params->pcm_reads; reads++) {
uint32_t LOG_VERBOSE(LOG_TAG, "%s: PCM read of size %u", __func__,
read_buffer32[A2DP_APTX_HD_MAX_PCM_BYTES_PER_READ / sizeof(uint32_t)]; expected_read_bytes);
size_t pcm_bytes_read = a2dp_aptx_hd_encoder_cb.read_callback( bytes_read = a2dp_aptx_hd_encoder_cb.read_callback((uint8_t*)read_buffer32,
(uint8_t*)read_buffer32, framing_params->pcm_bytes_per_read); expected_read_bytes);
bytes_read += pcm_bytes_read; a2dp_aptx_hd_encoder_cb.stats.media_read_total_actual_read_bytes +=
a2dp_aptx_hd_encoder_cb.stats.media_read_total_actual_read_bytes += bytes_read;
pcm_bytes_read; if (bytes_read < expected_read_bytes) {
if (pcm_bytes_read < framing_params->pcm_bytes_per_read) { LOG_WARN(LOG_TAG,
LOG_WARN(LOG_TAG, "%s: underflow at PCM reading: read %u bytes instead of %u",
"%s: underflow at PCM reading iteration %zu: read %zu " __func__, bytes_read, expected_read_bytes);
"instead of %d", a2dp_aptx_hd_encoder_cb.stats.media_read_total_dropped_packets++;
__func__, reads, pcm_bytes_read, osi_free(p_buf);
framing_params->pcm_bytes_per_read); return;
break; }
} a2dp_aptx_hd_encoder_cb.stats.media_read_total_actual_reads_count++;
a2dp_aptx_hd_encoder_cb.stats.media_read_total_actual_reads_count++;
pcm_bytes_encoded += aptx_hd_encode_24bit( for (uint32_t reads = 0, offset = 0; reads < framing_params->pcm_reads;
framing_params, &encoded_ptr_index, read_buffer32, encoded_ptr); reads++, offset +=
framing_params->pcm_bytes_per_read / sizeof(uint32_t)) {
pcm_bytes_encoded +=
aptx_hd_encode_24bit(framing_params, &encoded_ptr_index,
read_buffer32 + offset, encoded_ptr);
} }
// Compute the number of encoded bytes // Compute the number of encoded bytes
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment