[PATCH v2 4/5] android/hal-audio: Use payload length for codec init

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

 



It makes more sense to pass maximum payload length to codec since this
is actually used for calculations. MTU value is used only to allocate
proper buffer.
---
 android/hal-audio.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/android/hal-audio.c b/android/hal-audio.c
index 78f89bd..5a69b52 100644
--- a/android/hal-audio.c
+++ b/android/hal-audio.c
@@ -387,11 +387,10 @@ static void sbc_init_encoder(struct sbc_data *sbc_data)
 			in->min_bitpool, in->max_bitpool);
 }
 
-static int sbc_codec_init(struct audio_preset *preset, uint16_t mtu,
+static int sbc_codec_init(struct audio_preset *preset, uint16_t payload_len,
 							void **codec_data)
 {
 	struct sbc_data *sbc_data;
-	size_t hdr_len = sizeof(struct media_packet);
 	size_t in_frame_len;
 	size_t out_frame_len;
 	size_t num_frames;
@@ -411,7 +410,7 @@ static int sbc_codec_init(struct audio_preset *preset, uint16_t mtu,
 
 	in_frame_len = sbc_get_codesize(&sbc_data->enc);
 	out_frame_len = sbc_get_frame_length(&sbc_data->enc);
-	num_frames = (mtu - hdr_len) / out_frame_len;
+	num_frames = payload_len / out_frame_len;
 
 	sbc_data->in_frame_len = in_frame_len;
 	sbc_data->in_buf_size = num_frames * in_frame_len;
@@ -421,8 +420,8 @@ static int sbc_codec_init(struct audio_preset *preset, uint16_t mtu,
 	sbc_data->frame_duration = sbc_get_frame_duration(&sbc_data->enc);
 	sbc_data->frames_per_packet = num_frames;
 
-	DBG("mtu=%u in_frame_len=%zu out_frame_len=%zu frames_per_packet=%zu",
-			mtu, in_frame_len, out_frame_len, num_frames);
+	DBG("in_frame_len=%zu out_frame_len=%zu frames_per_packet=%zu",
+				in_frame_len, out_frame_len, num_frames);
 
 	*codec_data = sbc_data;
 
@@ -887,6 +886,7 @@ static bool open_endpoint(struct audio_endpoint *ep,
 	struct audio_preset *preset;
 	const struct audio_codec *codec;
 	uint16_t mtu;
+	uint16_t payload_len;
 	int fd;
 
 	if (ipc_open_stream_cmd(ep->id, &mtu, &fd, &preset) !=
@@ -896,10 +896,14 @@ static bool open_endpoint(struct audio_endpoint *ep,
 	if (set_blocking(fd) < 0)
 		goto failed;
 
+	DBG("mtu=%u", mtu);
+
+	payload_len = mtu - sizeof(*ep->mp);
+
 	ep->fd = fd;
 
 	codec = ep->codec;
-	codec->init(preset, mtu, &ep->codec_data);
+	codec->init(preset, payload_len, &ep->codec_data);
 	codec->get_config(ep->codec_data, cfg);
 
 	ep->mp = calloc(mtu, 1);
@@ -909,7 +913,7 @@ static bool open_endpoint(struct audio_endpoint *ep,
 	ep->mp->hdr.pt = 1;
 	ep->mp->hdr.ssrc = htonl(1);
 
-	ep->mp_data_len = mtu - sizeof(*ep->mp);
+	ep->mp_data_len = payload_len;
 
 	free(preset);
 
-- 
1.8.5.4

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux