Skip to content

Commit

Permalink
a2dp-codecs: Define a2dp_vendor_codec_t struct in endian neutral way
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pali authored and Vudentz committed Dec 28, 2018
1 parent 86c7f72 commit f29a5de
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 26 deletions.
8 changes: 4 additions & 4 deletions android/a2dp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions android/avdtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
18 changes: 6 additions & 12 deletions android/hal-audio-aptx.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,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,
},
Expand Down
24 changes: 22 additions & 2 deletions profiles/audio/a2dp-codecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 5 additions & 4 deletions profiles/audio/a2dp.c
Original file line number Diff line number Diff line change
Expand Up @@ -523,14 +523,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;
}

Expand Down
4 changes: 2 additions & 2 deletions tools/avinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down

0 comments on commit f29a5de

Please sign in to comment.