From ab94946038bfb3c1f666e632a5cf5b20ac800154 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Pali=20Roh=C3=A1r?= Date: Sun, 23 Dec 2018 11:40:17 +0100 Subject: [PATCH] a2dp-codecs: Define a2dp_vendor_codec_t struct in endian neutral way And define new macros A2DP_GET_VENDOR_ID(), A2DP_GET_CODEC_ID() and A2DP_SET_VENDOR_ID_CODEC_ID() for easily filling a2dp_vendor_codec_t struct. Change-Id: Ia517e52fce660b3e5f073a3009e460da0ca7a15a Signed-off-by: himanshu --- android/a2dp.c | 8 ++++---- android/avdtp.c | 6 ++++-- android/hal-audio-aptx.c | 18 ++++++------------ profiles/audio/a2dp-codecs.h | 24 ++++++++++++++++++++++-- profiles/audio/a2dp.c | 9 +++++---- tools/avinfo.c | 4 ++-- 6 files changed, 43 insertions(+), 26 deletions(-) diff --git a/android/a2dp.c b/android/a2dp.c index f219042..8bcdfd2 100755 --- a/android/a2dp.c +++ b/android/a2dp.c @@ -417,8 +417,8 @@ static int check_capabilities(struct a2dp_preset *preset, preset->len); case A2DP_CODEC_VENDOR: vndcodec = (void *) codec->data; - if (btohl(vndcodec->vendor_id) == APTX_VENDOR_ID && - btohs(vndcodec->codec_id) == APTX_CODEC_ID) + if (A2DP_GET_VENDOR_ID(*vndcodec) == APTX_VENDOR_ID && + A2DP_GET_CODEC_ID(*vndcodec) == APTX_CODEC_ID) return aptx_check_config(codec->data, codec_len, preset->data, preset->len); return -EINVAL; @@ -1344,8 +1344,8 @@ static uint8_t register_endpoint(const uint8_t *uuid, uint8_t codec, a2dp_vendor_codec_t *vndcodec = (void *) endpoint->caps->data; avdtp_sep_set_vendor_codec(endpoint->sep, - btohl(vndcodec->vendor_id), - btohs(vndcodec->codec_id)); + A2DP_GET_VENDOR_ID(*vndcodec), + A2DP_GET_CODEC_ID(*vndcodec)); } endpoints = g_slist_append(endpoints, endpoint); diff --git a/android/avdtp.c b/android/avdtp.c index 34caf3d..7fb8cb7 100755 --- a/android/avdtp.c +++ b/android/avdtp.c @@ -1103,10 +1103,12 @@ struct avdtp_remote_sep *avdtp_find_remote_sep(struct avdtp *session, a2dp_vendor_codec_t *vndcodec = (void *) codec_data->data; - if (btohl(vndcodec->vendor_id) != lsep->vndcodec_vendor) + if (A2DP_GET_VENDOR_ID(*vndcodec) != + lsep->vndcodec_vendor) continue; - if (btohs(vndcodec->codec_id) != lsep->vndcodec_codec) + if (A2DP_GET_CODEC_ID(*vndcodec) != + lsep->vndcodec_codec) continue; } diff --git a/android/hal-audio-aptx.c b/android/hal-audio-aptx.c index a800075..4707f59 100755 --- a/android/hal-audio-aptx.c +++ b/android/hal-audio-aptx.c @@ -36,27 +36,21 @@ struct aptx_data { static const a2dp_aptx_t aptx_presets[] = { { - .info = { - .vendor_id = APTX_VENDOR_ID, - .codec_id = APTX_CODEC_ID, - }, + .info = + A2DP_SET_VENDOR_ID_CODEC_ID(APTX_VENDOR_ID, APTX_CODEC_ID), .frequency = APTX_SAMPLING_FREQ_44100 | APTX_SAMPLING_FREQ_48000, .channel_mode = APTX_CHANNEL_MODE_STEREO, }, { - .info = { - .vendor_id = APTX_VENDOR_ID, - .codec_id = APTX_CODEC_ID, - }, + .info = + A2DP_SET_VENDOR_ID_CODEC_ID(APTX_VENDOR_ID, APTX_CODEC_ID), .frequency = APTX_SAMPLING_FREQ_48000, .channel_mode = APTX_CHANNEL_MODE_STEREO, }, { - .info = { - .vendor_id = APTX_VENDOR_ID, - .codec_id = APTX_CODEC_ID, - }, + .info = + A2DP_SET_VENDOR_ID_CODEC_ID(APTX_VENDOR_ID, APTX_CODEC_ID), .frequency = APTX_SAMPLING_FREQ_44100, .channel_mode = APTX_CHANNEL_MODE_STEREO, }, diff --git a/profiles/audio/a2dp-codecs.h b/profiles/audio/a2dp-codecs.h index 47030bc..a310efe 100755 --- a/profiles/audio/a2dp-codecs.h +++ b/profiles/audio/a2dp-codecs.h @@ -198,10 +198,30 @@ #define LDAC_CODEC_ID 0x00aa typedef struct { - uint32_t vendor_id; - uint16_t codec_id; + uint8_t vendor_id4; + uint8_t vendor_id3; + uint8_t vendor_id2; + uint8_t vendor_id1; + uint8_t codec_id2; + uint8_t codec_id1; } __attribute__ ((packed)) a2dp_vendor_codec_t; +#define A2DP_GET_VENDOR_ID(a) ( \ + (((uint32_t)(a).vendor_id4) << 0) | \ + (((uint32_t)(a).vendor_id3) << 8) | \ + (((uint32_t)(a).vendor_id2) << 16) | \ + (((uint32_t)(a).vendor_id1) << 24) \ + ) +#define A2DP_GET_CODEC_ID(a) ((a).codec_id2 | (((uint16_t)(a).codec_id1) << 8)) +#define A2DP_SET_VENDOR_ID_CODEC_ID(v, c) ((a2dp_vendor_codec_t){ \ + .vendor_id4 = (((v) >> 0) & 0xff), \ + .vendor_id3 = (((v) >> 8) & 0xff), \ + .vendor_id2 = (((v) >> 16) & 0xff), \ + .vendor_id1 = (((v) >> 24) & 0xff), \ + .codec_id2 = (((c) >> 0) & 0xff), \ + .codec_id1 = (((c) >> 8) & 0xff), \ + }) + #if __BYTE_ORDER == __LITTLE_ENDIAN typedef struct { diff --git a/profiles/audio/a2dp.c b/profiles/audio/a2dp.c index ea98af6..973dc8a 100644 --- a/profiles/audio/a2dp.c +++ b/profiles/audio/a2dp.c @@ -580,14 +580,15 @@ static gboolean endpoint_match_codec_ind(struct avdtp *session, local_codec = (a2dp_vendor_codec_t *) capabilities; remote_codec = (a2dp_vendor_codec_t *) codec->data; - if (remote_codec->vendor_id != local_codec->vendor_id) + if (A2DP_GET_VENDOR_ID(*remote_codec) != + A2DP_GET_VENDOR_ID(*local_codec)) return FALSE; - if (remote_codec->codec_id != local_codec->codec_id) + if (A2DP_GET_CODEC_ID(*remote_codec) != A2DP_GET_CODEC_ID(*local_codec)) return FALSE; - DBG("vendor 0x%08x codec 0x%04x", btohl(remote_codec->vendor_id), - btohs(remote_codec->codec_id)); + DBG("vendor 0x%08x codec 0x%04x", A2DP_GET_VENDOR_ID(*remote_codec), + A2DP_GET_CODEC_ID(*remote_codec)); return TRUE; } diff --git a/tools/avinfo.c b/tools/avinfo.c index 2398cc5..424221f 100755 --- a/tools/avinfo.c +++ b/tools/avinfo.c @@ -221,8 +221,8 @@ static void print_vendor(a2dp_vendor_codec_t *vendor, uint8_t size) return; } - vendor_id = btohl(vendor->vendor_id); - codec_id = btohs(vendor->codec_id); + vendor_id = A2DP_GET_VENDOR_ID(*vendor); + codec_id = A2DP_GET_CODEC_ID(*vendor); printf("\tMedia Codec: Vendor Specific A2DP Codec"); -- 2.7.4