Wireshark 4.5.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
17struct 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
63WS_DLL_PUBLIC
64int mpa_version(const struct mpa *);
65WS_DLL_PUBLIC
66int mpa_layer(const struct mpa *);
67WS_DLL_PUBLIC
68unsigned int mpa_samples(const struct mpa *);
69WS_DLL_PUBLIC
70unsigned int mpa_bitrate(const struct mpa *);
71WS_DLL_PUBLIC
72unsigned int mpa_frequency(const struct mpa *);
73WS_DLL_PUBLIC
74unsigned int mpa_padding(const struct mpa *);
75WS_DLL_PUBLIC
76uint32_t decode_synchsafe_int(uint32_t);
77
78#define MPA_DATA_BYTES(mpa) (mpa_bitrate(mpa) * mpa_samples(mpa) \
79 / mpa_frequency(mpa) / 8)
80#define MPA_BYTES(mpa) (MPA_DATA_BYTES(mpa) + mpa_padding(mpa))
81#define MPA_DURATION_NS(mpa) \
82 (1000000000 / mpa_frequency(mpa) * mpa_samples(mpa))
83
84enum { MPA_SYNC = 0x7ff };
85
86#define MPA_SYNC_VALID(mpa) ((mpa)->sync == MPA_SYNC)
87#define MPA_VERSION_VALID(mpa) (mpa_version(mpa) >= 0)
88#define MPA_LAYER_VALID(mpa) (mpa_layer(mpa) >= 0)
89#define MPA_BITRATE_VALID(mpa) (mpa_bitrate(mpa) > 0)
90#define MPA_FREQUENCY_VALID(mpa) (mpa_frequency(mpa) > 0)
91#define MPA_VALID(mpa) (MPA_SYNC_VALID(mpa) \
92 && MPA_VERSION_VALID(mpa) && MPA_LAYER_VALID(mpa) \
93 && MPA_BITRATE_VALID(mpa) && MPA_FREQUENCY_VALID(mpa))
94
95#endif
Definition mpeg-audio.h:17