1 /* |
|
2 * Copyright (c) 2010 Ixonos Plc. |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - Initial contribution |
|
11 * |
|
12 * Contributors: |
|
13 * Ixonos Plc |
|
14 * |
|
15 * Description: |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 /************************************************************************** |
|
21 mpheader.h - MPEG-1 and MPEG-2 bit field (header) parsing functions. |
|
22 |
|
23 Author(s): Juha Ojanpera |
|
24 Copyright (c) 1999-2004 by Nokia Research Center, Speech and Audio Systems. |
|
25 *************************************************************************/ |
|
26 |
|
27 #ifndef MPHEADER_H_ |
|
28 #define MPHEADER_H_ |
|
29 |
|
30 /*-- Project Headers. --*/ |
|
31 #include "mpaud.h" |
|
32 #include "mp3tables.h" |
|
33 #include "defines.h" |
|
34 |
|
35 /* Checks whether window switching is used in layer III. */ |
|
36 inline BOOL win_switch(TGranule_Info *gr_info) |
|
37 { return ((BOOL)(gr_info->flags & WINDOW_SWITCHING_FLAG)); } |
|
38 |
|
39 /* Checks whether short blocks are used in layer III. */ |
|
40 inline BOOL short_block(TGranule_Info *gr_info) |
|
41 { return ((gr_info->flags & 3) == 2); } |
|
42 |
|
43 /* Checks whether mixed blocks are present in layer III. */ |
|
44 inline BOOL mixed_block(TGranule_Info *gr_info) |
|
45 { return ((BOOL)(gr_info->flags & MIXED_BLOCK_FLAG)); } |
|
46 |
|
47 /* Checks whether 'scalefac_scale' bit is set in layer III. */ |
|
48 inline BOOL scalefac_scale(TGranule_Info *gr_info) |
|
49 { return ((BOOL)((gr_info->flags & SCALEFAC_SCALE) ? 1 : 0)); } |
|
50 |
|
51 /* Returns the status of 'pre_flag' bit of layer III. */ |
|
52 inline BOOL pre_flag(TGranule_Info *gr_info) |
|
53 { return ((BOOL)((gr_info->flags & PRE_FLAG) ? 1 : 0)); } |
|
54 |
|
55 /*-- Common header parsing functions. --*/ |
|
56 |
|
57 /* MPEG-1 or MPEG-2 */ |
|
58 inline int16 version(TMPEG_Header *mpheader) |
|
59 {return ((BOOL)((mpheader->header >> 19) & 1));} |
|
60 |
|
61 /* Checks whether the current stream is of type MPEG-2.5. */ |
|
62 inline BOOL mp25version(TMPEG_Header *mpheader) |
|
63 { return ((BOOL)((mpheader->header & 0x100000) ? FALSE : TRUE)); } |
|
64 |
|
65 /* Layer (1, 2 or 3) */ |
|
66 inline int16 layer_number(TMPEG_Header *mpheader) |
|
67 { return (int16)((4 - (mpheader->header >> 17) & 3)); } |
|
68 |
|
69 /* Checks if error protection is used in the bitstream. */ |
|
70 inline BOOL error_protection(TMPEG_Header *mpheader) |
|
71 { return (!((mpheader->header >> 16) & 1)); } |
|
72 |
|
73 /* Sampling frequency index */ |
|
74 inline int16 sfreq(TMPEG_Header *mpheader) |
|
75 { return (int16)((mpheader->header >> 10) & 3);} |
|
76 |
|
77 /* Checks whether padding bit is set. */ |
|
78 inline BOOL padding(TMPEG_Header *mpheader) |
|
79 { return (BOOL)((mpheader->header >> 9) & 1); } |
|
80 |
|
81 /* Checks if private bit is set. */ |
|
82 inline BOOL private_bit(TMPEG_Header *mpheader) |
|
83 { return (BOOL)((mpheader->header >> 8) & 1); } |
|
84 |
|
85 /* Mono, stereo, joint or dual */ |
|
86 inline int16 mode(TMPEG_Header *mpheader) |
|
87 { return (int16)((mpheader->header >> 6) & 3); } |
|
88 |
|
89 /* Value of mode extension field */ |
|
90 inline int16 mode_extension(TMPEG_Header *mpheader) |
|
91 { return (int16)((mpheader->header >> 4) & 3); } |
|
92 |
|
93 /* Checks whether copyright bit is set. */ |
|
94 inline BOOL copyright(TMPEG_Header *mpheader) |
|
95 { return (BOOL)((mpheader->header >> 3) & 1); } |
|
96 |
|
97 /* Checks whether original bit. */ |
|
98 inline BOOL original(TMPEG_Header *mpheader) |
|
99 { return (BOOL)((mpheader->header >> 2) & 1); } |
|
100 |
|
101 /* Value of bitrate field */ |
|
102 inline int16 bit_rate_idx(TMPEG_Header *mpheader) |
|
103 { return ((int16)((mpheader->header >> 12) & 0xF)); } |
|
104 |
|
105 /* Bitrate */ |
|
106 inline int16 bit_rate(TMPEG_Header *mpheader) |
|
107 { return (bitrate[version(mpheader)][(int16)((mpheader->header >> 12) & 0xF)]); } |
|
108 |
|
109 /* Number of channels; 1 for mono, 2 for stereo */ |
|
110 inline int16 channels(TMPEG_Header *mpheader) |
|
111 { return ((int16)((mode(mpheader) == MPG_MD_MONO) ? (int16)1 : (int16)2));} |
|
112 |
|
113 inline const int16 *GetBitRateTable(TMPEG_Header *mpheader) |
|
114 { return (&bitrate[version(mpheader)][0]); } |
|
115 |
|
116 /* Sampling frequency */ |
|
117 inline int32 frequency(TMPEG_Header *mpheader) |
|
118 { return (s_freq[(mpheader->header & 0x100000) ? version(mpheader):2][sfreq(mpheader)]); } |
|
119 |
|
120 /* Frame length in milliseconds */ |
|
121 inline int32 GetFrameTime(TMPEG_Header *mpheader) |
|
122 { return (framelength[sfreq(mpheader) + (mp25version(mpheader)) * 3]); } |
|
123 |
|
124 #endif /* MPHEADER_H_ */ |
|