Skip to content
This repository has been archived by the owner on Jan 25, 2021. It is now read-only.

Commit

Permalink
Fix write_block_size,read_block_size calculations
Browse files Browse the repository at this point in the history
Fix #11 (partially)

Clean up & reformat some lines.
  • Loading branch information
EHfive committed Oct 15, 2018
1 parent a228264 commit de703bb
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/modules/bluetooth/a2dp/a2dp_aptx.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ static size_t
pa_dual_decode(const void *read_buf, size_t read_buf_size, void *write_buf, size_t write_buf_size, size_t *_decoded,
uint32_t *timestamp, void **codec_data) {
const struct rtp_header *header;
const void *p;
void *p;
int ret, i;
AVPacket *pkt;
size_t to_decode;
Expand Down Expand Up @@ -167,15 +167,19 @@ pa_dual_decode(const void *read_buf, size_t read_buf_size, void *write_buf, size
ret = avcodec_send_packet_func(aptx_info->av_codec_ctx, pkt);
if (PA_UNLIKELY(ret < 0)) {
pa_log_debug("Error submitting the packet to the decoder");
total_written = 0;
goto done;
}
ret = avcodec_receive_frame_func(aptx_info->av_codec_ctx, av_frame);
if (PA_UNLIKELY(ret < 0)) {
pa_log_debug("Error during decoding");
goto done;
}

*_decoded = aptx_info->aptx_frame_size * av_frame->nb_samples / 4;

total_written = (size_t) av_frame->nb_samples * (4 * 2);

pa_assert_fp(_decoded <= read_buf_size);
pa_assert_fp(total_written <= write_buf_size);

for (i = 0; i < av_frame->nb_samples * sizeof(uint32_t); i += sizeof(uint32_t)) {
Expand Down Expand Up @@ -332,11 +336,11 @@ static void pa_dual_get_read_block_size(size_t read_link_mtu, size_t *read_block
size_t rtp_use_size = aptx_info->is_hd ? sizeof(struct rtp_header) : 0;
pa_assert(aptx_info);

/* 8*N APTX frame,
* PCM 32-bit, 2 channel (4 bytes * 2)
* PCM frames/APTX frames == 4
* */
*read_block_size = (read_link_mtu - rtp_use_size) / (8 * aptx_frame_size) * 8 * (4 * 2) * 4;
/*
 * PCM 32-bit, 2 channel (4 bytes * 2)
 * PCM frames/APTX frames == 4
 * */
*read_block_size = (read_link_mtu - rtp_use_size) / aptx_frame_size * (4 * 2) * 4;
aptx_info->block_size = *read_block_size;
};

Expand All @@ -346,12 +350,11 @@ static void pa_dual_get_write_block_size(size_t write_link_mtu, size_t *write_bl
size_t rtp_use_size = aptx_info->is_hd ? sizeof(struct rtp_header) : 0;
pa_assert(aptx_info);

/* 8*N APTX frames,
/*
* PCM 32-bit, 2 channel (4 bytes * 2)
* PCM frames/APTX frames == 4
* */
*write_block_size = (write_link_mtu - rtp_use_size) / (8 * aptx_frame_size) * 8 * (4 * 2) * 4;
pa_log_error("write_block_size %lu", *write_block_size);
*write_block_size = (write_link_mtu - rtp_use_size) / aptx_frame_size * (4 * 2) * 4;
aptx_info->block_size = *write_block_size;
};

Expand Down

0 comments on commit de703bb

Please sign in to comment.