1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
/*****************************************************************************
**
** Name: a2d_m24.c
**
** Description:utility functions to help build and parse MPEG-2, 4 AAC
** Codec Information Element and Media Payload.
** Copyright (c) 2002-2004, WIDCOMM Inc., All Rights Reserved.
** WIDCOMM Bluetooth Core. Proprietary and confidential.
**
*****************************************************************************/
#include "bt_target.h"
#if (A2D_M24_INCLUDED == TRUE)
#include "a2d_api.h"
#include "a2d_int.h"
#include "a2d_m24.h"
/******************************************************************************
**
** Function A2D_BldM24Info
**
** Description This function is called by an application to build
** the MPEG-2, 4 AAC Media Codec Capabilities byte sequence
** beginning from the LOSC octet.
** Input Parameters:
** media_type: Indicates Audio, or Multimedia.
**
** p_ie: MPEG-2, 4 AAC Codec Information Element information.
**
** Output Parameters:
** p_result: the resulting codec info byte sequence.
**
** Returns A2D_SUCCESS if function execution succeeded.
** Error status code, otherwise.
******************************************************************************/
tA2D_STATUS A2D_BldM24Info(UINT8 media_type, tA2D_M24_CIE *p_ie, UINT8 *p_result)
{
tA2D_STATUS status;
UINT16 bitrate45;
if( p_ie == NULL || p_result == NULL ||
(p_ie->obj_type & ~A2D_M24_IE_OBJ_MSK) ||
(p_ie->samp_freq & ~A2D_M24_IE_SAMP_FREQ_MSK) ||
(p_ie->chnl & ~A2D_M24_IE_CHNL_MSK) ||
(p_ie->bitrate & ~A2D_M24_IE_BITRATE_MSK))
{
/* if any unused bit is set */
status = A2D_INVALID_PARAMS;
}
else
{
status = A2D_SUCCESS;
*p_result++ = A2D_M24_INFO_LEN;
*p_result++ = media_type;
*p_result++ = A2D_MEDIA_CT_M24;
/* Media Codec Specific Information Element */
*p_result++ = p_ie->obj_type;
UINT16_TO_BE_STREAM(p_result, p_ie->samp_freq);
p_result--;
*p_result++ |= p_ie->chnl;
*p_result = (p_ie->bitrate & A2D_M24_IE_BITRATE3_MSK) >> 16;
if(p_ie->vbr)
*p_result |= A2D_M24_IE_VBR_MSK;
p_result++;
bitrate45 = (UINT16)(p_ie->bitrate & A2D_M24_IE_BITRATE45_MSK);
UINT16_TO_BE_STREAM(p_result, bitrate45);
}
return status;
}
/******************************************************************************
**
** Function A2D_ParsM24Info
**
** Description This function is called by an application to parse
** the MPEG-2, 4 AAC Media Codec Capabilities byte sequence
** beginning from the LOSC octet.
** Input Parameters:
** p_info: the byte sequence to parse.
**
** for_caps: TRUE, if the byte sequence is for get capabilities response.
**
** Output Parameters:
** p_ie: MPEG-2, 4 AAC Codec Information Element information.
**
** Returns A2D_SUCCESS if function execution succeeded.
** Error status code, otherwise.
******************************************************************************/
tA2D_STATUS A2D_ParsM24Info(tA2D_M24_CIE *p_ie, UINT8 *p_info, BOOLEAN for_caps)
{
tA2D_STATUS status;
UINT8 vbr;
UINT16 u16;
UINT8 losc;
UINT8 mt;
if( p_ie == NULL || p_info == NULL)
status = A2D_INVALID_PARAMS;
else
{
losc = *p_info++;
mt = *p_info++;
/* If the function is called for the wrong Media Type or Media Codec Type */
if(losc != A2D_M24_INFO_LEN || *p_info != A2D_MEDIA_CT_M24)
status = A2D_WRONG_CODEC;
else
{
p_info++;
p_ie->obj_type = *p_info++;
BE_STREAM_TO_UINT16(p_ie->samp_freq, p_info);
p_ie->chnl = p_ie->samp_freq & A2D_M24_IE_CHNL_MSK;
p_ie->samp_freq &= A2D_M24_IE_SAMP_FREQ_MSK;
vbr = *p_info++;
BE_STREAM_TO_UINT16(u16, p_info); /* u16 contains the octect4, 5 of bterate */
p_ie->vbr = (vbr & A2D_M24_IE_VBR_MSK) >> 7;
vbr &= ~A2D_M24_IE_VBR_MSK; /* vbr has become the octect3 of bitrate */
p_ie->bitrate = vbr;
p_ie->bitrate <<= 16;
p_ie->bitrate += u16;
status = A2D_SUCCESS;
if(for_caps == FALSE)
{
if(A2D_BitsSet(p_ie->obj_type) != A2D_SET_ONE_BIT)
status = A2D_BAD_OBJ_TYPE;
if((A2D_BitsSet((UINT8)(p_ie->samp_freq&0xFF)) +
A2D_BitsSet((UINT8)((p_ie->samp_freq&0xFF00)>>8)))!= A2D_SET_ONE_BIT)
status = A2D_BAD_SAMP_FREQ;
if(A2D_BitsSet(p_ie->chnl) != A2D_SET_ONE_BIT)
status = A2D_BAD_CHANNEL;
/* BitRate must be greater than zero when specifying AAC configuration */
if (p_ie->bitrate == 0)
status = A2D_BAD_BIT_RATE;
}
}
}
return status;
}
#endif /* (A2D_M24_INCLUDED == TRUE) */
|