| Wireshark 4.7.3 The Wireshark network protocol analyzer

Loading...
Searching...
No Matches
mpeg-audio.h
Go to the documentation of this file.
1
10
11#ifndef MPA_H
12#define MPA_H 1
13
14#include <stdint.h>
15#include "ws_symbol_export.h"
16
20 struct mpa {
21 unsigned int emphasis :2;
22 unsigned int original :1;
23 unsigned int copyright :1;
24 unsigned int modeext :2;
25 unsigned int mode :2;
26 unsigned int priv :1;
27 unsigned int padding :1;
28 unsigned int frequency :2;
29 unsigned int bitrate :4;
30 unsigned int protection :1;
31 unsigned int layer :2;
32 unsigned int version :2;
33 unsigned int sync :11;
34};
35
36#define MPA_UNMARSHAL_SYNC(n) ((n) >> 21 & 0x7ff)
37#define MPA_UNMARSHAL_VERSION(n) ((n) >> 19 & 0x3)
38#define MPA_UNMARSHAL_LAYER(n) ((n) >> 17 & 0x3)
39#define MPA_UNMARSHAL_PROTECTION(n) ((n) >> 16 & 0x1)
40#define MPA_UNMARSHAL_BITRATE(n) ((n) >> 12 & 0xf)
41#define MPA_UNMARSHAL_FREQUENCY(n) ((n) >> 10 & 0x3)
42#define MPA_UNMARSHAL_PADDING(n) ((n) >> 9 & 0x1)
43#define MPA_UNMARSHAL_PRIVATE(n) ((n) >> 8 & 0x1)
44#define MPA_UNMARSHAL_MODE(n) ((n) >> 6 & 0x3)
45#define MPA_UNMARSHAL_MODEEXT(n) ((n) >> 4 & 0x3)
46#define MPA_UNMARSHAL_COPYRIGHT(n) ((n) >> 3 & 0x1)
47#define MPA_UNMARSHAL_ORIGINAL(n) ((n) >> 2 & 0x1)
48#define MPA_UNMARSHAL_EMPHASIS(n) ((n) >> 0 & 0x3)
49
50#define MPA_UNMARSHAL(mpa, n) do { \
51 (mpa)->sync = MPA_UNMARSHAL_SYNC(n); \
52 (mpa)->version = MPA_UNMARSHAL_VERSION(n); \
53 (mpa)->layer = MPA_UNMARSHAL_LAYER(n); \
54 (mpa)->protection = MPA_UNMARSHAL_PROTECTION(n); \
55 (mpa)->bitrate = MPA_UNMARSHAL_BITRATE(n); \
56 (mpa)->frequency = MPA_UNMARSHAL_FREQUENCY(n); \
57 (mpa)->padding = MPA_UNMARSHAL_PADDING(n); \
58 (mpa)->priv = MPA_UNMARSHAL_PRIVATE(n); \
59 (mpa)->mode = MPA_UNMARSHAL_MODE(n); \
60 (mpa)->modeext = MPA_UNMARSHAL_MODEEXT(n); \
61 (mpa)->copyright = MPA_UNMARSHAL_COPYRIGHT(n); \
62 (mpa)->original = MPA_UNMARSHAL_ORIGINAL(n); \
63 (mpa)->emphasis = MPA_UNMARSHAL_EMPHASIS(n); \
64 } while (0)
65
74WS_DLL_PUBLIC int mpa_version(const struct mpa *mpa);
75
84WS_DLL_PUBLIC int mpa_layer(const struct mpa *mpa);
85
94WS_DLL_PUBLIC unsigned int mpa_samples(const struct mpa *mpa);
95
104WS_DLL_PUBLIC unsigned int mpa_bitrate(const struct mpa *mpa);
105
114WS_DLL_PUBLIC unsigned int mpa_frequency(const struct mpa *mpa);
115
124WS_DLL_PUBLIC unsigned int mpa_padding(const struct mpa *mpa);
125
135WS_DLL_PUBLIC uint32_t decode_synchsafe_int(uint32_t val);
136
147#define MPA_DATA_BYTES(mpa) (mpa_bitrate(mpa) * mpa_samples(mpa) \
148 / mpa_frequency(mpa) / 8)
149
159#define MPA_BYTES(mpa) (MPA_DATA_BYTES(mpa) + mpa_padding(mpa))
160
170#define MPA_DURATION_NS(mpa) \
171 (1000000000 / mpa_frequency(mpa) * mpa_samples(mpa))
172
174 enum {
175 MPA_SYNC = 0x7ff
176};
177
182#define MPA_SYNC_VALID(mpa) ((mpa)->sync == MPA_SYNC)
183
188#define MPA_VERSION_VALID(mpa) (mpa_version(mpa) >= 0)
189
194#define MPA_LAYER_VALID(mpa) (mpa_layer(mpa) >= 0)
195
200#define MPA_BITRATE_VALID(mpa) (mpa_bitrate(mpa) > 0)
201
206#define MPA_FREQUENCY_VALID(mpa) (mpa_frequency(mpa) > 0)
207
216#define MPA_VALID(mpa) (MPA_SYNC_VALID(mpa) \
217 && MPA_VERSION_VALID(mpa) \
218 && MPA_LAYER_VALID(mpa) \
219 && MPA_BITRATE_VALID(mpa) \
220 && MPA_FREQUENCY_VALID(mpa))
221
222#endif
mpa_version
WS_DLL_PUBLIC int mpa_version(const struct mpa *mpa)
Extracts the MPEG audio version from the given header.
Definition mpeg-audio.c:49
mpa_layer
WS_DLL_PUBLIC int mpa_layer(const struct mpa *mpa)
Extracts the MPEG audio layer from the given header.
Definition mpeg-audio.c:55
mpa_samples
WS_DLL_PUBLIC unsigned int mpa_samples(const struct mpa *mpa)
Returns the number of audio samples per frame.
Definition mpeg-audio.c:61
decode_synchsafe_int
WS_DLL_PUBLIC uint32_t decode_synchsafe_int(uint32_t val)
Decodes a synchsafe integer from ID3 metadata.
Definition mpeg-audio.c:88
mpa_padding
WS_DLL_PUBLIC unsigned int mpa_padding(const struct mpa *mpa)
Checks whether padding is present in the MPEG audio frame.
Definition mpeg-audio.c:79
mpa_bitrate
WS_DLL_PUBLIC unsigned int mpa_bitrate(const struct mpa *mpa)
Extracts the bitrate from the MPEG audio header.
Definition mpeg-audio.c:67
mpa_frequency
WS_DLL_PUBLIC unsigned int mpa_frequency(const struct mpa *mpa)
Extracts the sampling frequency from the MPEG audio header.
Definition mpeg-audio.c:73
MPA_SYNC
@ MPA_SYNC
Definition mpeg-audio.h:175
mpa
Represents the decoded fields of an MPEG Audio (MP1/MP2/MP3) frame header, laid out as a packed bitfi...
Definition mpeg-audio.h:20
mpa::mode
unsigned int mode
Definition mpeg-audio.h:25
mpa::bitrate
unsigned int bitrate
Definition mpeg-audio.h:29
mpa::padding
unsigned int padding
Definition mpeg-audio.h:27
mpa::original
unsigned int original
Definition mpeg-audio.h:22
mpa::sync
unsigned int sync
Definition mpeg-audio.h:33
mpa::version
unsigned int version
Definition mpeg-audio.h:32
mpa::copyright
unsigned int copyright
Definition mpeg-audio.h:23
mpa::emphasis
unsigned int emphasis
Definition mpeg-audio.h:21
mpa::protection
unsigned int protection
Definition mpeg-audio.h:30
mpa::priv
unsigned int priv
Definition mpeg-audio.h:26
mpa::frequency
unsigned int frequency
Definition mpeg-audio.h:28
mpa::layer
unsigned int layer
Definition mpeg-audio.h:31
mpa::modeext
unsigned int modeext
Definition mpeg-audio.h:24