| Wireshark 4.7.0 The Wireshark network protocol analyzer

Loading...
Searching...
No Matches
mpeg-audio.h
Go to the documentation of this file.
1
11#ifndef MPA_H
12#define MPA_H 1
13
14#include <stdint.h>
15#include "ws_symbol_export.h"
16
17 struct mpa {
18 unsigned int emphasis :2;
19 unsigned int original :1;
20 unsigned int copyright :1;
21 unsigned int modeext :2;
22 unsigned int mode :2;
23 unsigned int priv :1;
24 unsigned int padding :1;
25 unsigned int frequency :2;
26 unsigned int bitrate :4;
27 unsigned int protection :1;
28 unsigned int layer :2;
29 unsigned int version :2;
30 unsigned int sync :11;
31};
32
33#define MPA_UNMARSHAL_SYNC(n) ((n) >> 21 & 0x7ff)
34#define MPA_UNMARSHAL_VERSION(n) ((n) >> 19 & 0x3)
35#define MPA_UNMARSHAL_LAYER(n) ((n) >> 17 & 0x3)
36#define MPA_UNMARSHAL_PROTECTION(n) ((n) >> 16 & 0x1)
37#define MPA_UNMARSHAL_BITRATE(n) ((n) >> 12 & 0xf)
38#define MPA_UNMARSHAL_FREQUENCY(n) ((n) >> 10 & 0x3)
39#define MPA_UNMARSHAL_PADDING(n) ((n) >> 9 & 0x1)
40#define MPA_UNMARSHAL_PRIVATE(n) ((n) >> 8 & 0x1)
41#define MPA_UNMARSHAL_MODE(n) ((n) >> 6 & 0x3)
42#define MPA_UNMARSHAL_MODEEXT(n) ((n) >> 4 & 0x3)
43#define MPA_UNMARSHAL_COPYRIGHT(n) ((n) >> 3 & 0x1)
44#define MPA_UNMARSHAL_ORIGINAL(n) ((n) >> 2 & 0x1)
45#define MPA_UNMARSHAL_EMPHASIS(n) ((n) >> 0 & 0x3)
46
47#define MPA_UNMARSHAL(mpa, n) do { \
48 (mpa)->sync = MPA_UNMARSHAL_SYNC(n); \
49 (mpa)->version = MPA_UNMARSHAL_VERSION(n); \
50 (mpa)->layer = MPA_UNMARSHAL_LAYER(n); \
51 (mpa)->protection = MPA_UNMARSHAL_PROTECTION(n); \
52 (mpa)->bitrate = MPA_UNMARSHAL_BITRATE(n); \
53 (mpa)->frequency = MPA_UNMARSHAL_FREQUENCY(n); \
54 (mpa)->padding = MPA_UNMARSHAL_PADDING(n); \
55 (mpa)->priv = MPA_UNMARSHAL_PRIVATE(n); \
56 (mpa)->mode = MPA_UNMARSHAL_MODE(n); \
57 (mpa)->modeext = MPA_UNMARSHAL_MODEEXT(n); \
58 (mpa)->copyright = MPA_UNMARSHAL_COPYRIGHT(n); \
59 (mpa)->original = MPA_UNMARSHAL_ORIGINAL(n); \
60 (mpa)->emphasis = MPA_UNMARSHAL_EMPHASIS(n); \
61 } while (0)
62
71WS_DLL_PUBLIC int mpa_version(const struct mpa *mpa);
72
81WS_DLL_PUBLIC int mpa_layer(const struct mpa *mpa);
82
91WS_DLL_PUBLIC unsigned int mpa_samples(const struct mpa *mpa);
92
101WS_DLL_PUBLIC unsigned int mpa_bitrate(const struct mpa *mpa);
102
111WS_DLL_PUBLIC unsigned int mpa_frequency(const struct mpa *mpa);
112
121WS_DLL_PUBLIC unsigned int mpa_padding(const struct mpa *mpa);
122
132WS_DLL_PUBLIC uint32_t decode_synchsafe_int(uint32_t val);
133
144#define MPA_DATA_BYTES(mpa) (mpa_bitrate(mpa) * mpa_samples(mpa) \
145 / mpa_frequency(mpa) / 8)
146
156#define MPA_BYTES(mpa) (MPA_DATA_BYTES(mpa) + mpa_padding(mpa))
157
167#define MPA_DURATION_NS(mpa) \
168 (1000000000 / mpa_frequency(mpa) * mpa_samples(mpa))
169
170enum { MPA_SYNC = 0x7ff };
171
172#define MPA_SYNC_VALID(mpa) ((mpa)->sync == MPA_SYNC)
173#define MPA_VERSION_VALID(mpa) (mpa_version(mpa) >= 0)
174#define MPA_LAYER_VALID(mpa) (mpa_layer(mpa) >= 0)
175#define MPA_BITRATE_VALID(mpa) (mpa_bitrate(mpa) > 0)
176#define MPA_FREQUENCY_VALID(mpa) (mpa_frequency(mpa) > 0)
177#define MPA_VALID(mpa) (MPA_SYNC_VALID(mpa) \
178 && MPA_VERSION_VALID(mpa) && MPA_LAYER_VALID(mpa) \
179 && MPA_BITRATE_VALID(mpa) && MPA_FREQUENCY_VALID(mpa))
180
181#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
Definition mpeg-audio.h:17