| Wireshark 4.7.3 The Wireshark network protocol analyzer

Loading...
Searching...
No Matches
Classes | Macros | Enumerations | Functions
mpeg-audio.h File Reference
`#include <stdint.h>`
`#include "ws_symbol_export.h"`

Go to the source code of this file.

## Classes
struct | mpa
| Represents the decoded fields of an MPEG Audio (MP1/MP2/MP3) frame header, laid out as a packed bitfield. More...

## Macros
#define | MPA_UNMARSHAL_SYNC(n)
#define | MPA_UNMARSHAL_VERSION(n)
#define | MPA_UNMARSHAL_LAYER(n)
#define | MPA_UNMARSHAL_PROTECTION(n)
#define | MPA_UNMARSHAL_BITRATE(n)
#define | MPA_UNMARSHAL_FREQUENCY(n)
#define | MPA_UNMARSHAL_PADDING(n)
#define | MPA_UNMARSHAL_PRIVATE(n)
#define | MPA_UNMARSHAL_MODE(n)
#define | MPA_UNMARSHAL_MODEEXT(n)
#define | MPA_UNMARSHAL_COPYRIGHT(n)
#define | MPA_UNMARSHAL_ORIGINAL(n)
#define | MPA_UNMARSHAL_EMPHASIS(n)
#define | MPA_UNMARSHAL(mpa, n)
#define | MPA_DATA_BYTES(mpa)
| Calculates the number of data bytes in an MPEG audio frame.
#define | MPA_BYTES(mpa)
| Calculates the total number of bytes in an MPEG audio frame.
#define | MPA_DURATION_NS(mpa)
| Calculates the duration of an MPEG audio frame in nanoseconds.
#define | MPA_SYNC_VALID(mpa)
| True if the sync field of an MPEG Audio frame header contains the required 0x7FF sync word.
#define | MPA_VERSION_VALID(mpa)
| True if the MPEG Audio version field encodes a recognised version (i.e. mpa_version() >= 0).
#define | MPA_LAYER_VALID(mpa)
| True if the MPEG Audio layer field encodes a recognised layer (i.e. mpa_layer() >= 0).
#define | MPA_BITRATE_VALID(mpa)
| True if the bitrate index encodes a non-zero, valid bitrate (i.e. mpa_bitrate() > 0).
#define | MPA_FREQUENCY_VALID(mpa)
| True if the sampling frequency index encodes a valid, non-zero frequency (i.e. mpa_frequency() > 0).
#define | MPA_VALID(mpa)
| True if all fields of an MPEG Audio frame header are simultaneously valid.

## Enumerations
enum | { MPA_SYNC = 0x7ff }
| Required sync word value in the MPEG Audio frame header (all 11 sync bits set). More...

## Functions
WS_DLL_PUBLIC int | mpa_version (const struct mpa *mpa)
| Extracts the MPEG audio version from the given header.
WS_DLL_PUBLIC int | mpa_layer (const struct mpa *mpa)
| Extracts the MPEG audio layer from the given header.
WS_DLL_PUBLIC unsigned int | mpa_samples (const struct mpa *mpa)
| Returns the number of audio samples per frame.
WS_DLL_PUBLIC unsigned int | mpa_bitrate (const struct mpa *mpa)
| Extracts the bitrate from the MPEG audio header.
WS_DLL_PUBLIC unsigned int | mpa_frequency (const struct mpa *mpa)
| Extracts the sampling frequency from the MPEG audio header.
WS_DLL_PUBLIC unsigned int | mpa_padding (const struct mpa *mpa)
| Checks whether padding is present in the MPEG audio frame.
WS_DLL_PUBLIC uint32_t | decode_synchsafe_int (uint32_t val)
| Decodes a synchsafe integer from ID3 metadata.

## Detailed Description

MPEG Audio header dissection Written by Shaun Jackman sjack.nosp@m.man@.nosp@m.gmail.nosp@m..com Copyright 2007 Shaun Jackman

Wiretap Library SPDX-License-Identifier: GPL-2.0-or-later

## Macro Definition Documentation

## ◆ MPA_BITRATE_VALID

#define MPA_BITRATE_VALID | ( |  | mpa | ) |

Value:
(mpa_bitrate(mpa) > 0)
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

True if the bitrate index encodes a non-zero, valid bitrate (i.e. mpa_bitrate() > 0).

Parameters

  mpa | Pointer to the MPEG Audio frame header struct.

## ◆ MPA_BYTES

#define MPA_BYTES | ( |  | mpa | ) |

Value:
(MPA_DATA_BYTES(mpa) + mpa_padding(mpa))
MPA_DATA_BYTES
#define MPA_DATA_BYTES(mpa)
Calculates the number of data bytes in an MPEG audio frame.
Definition mpeg-audio.h:147

Calculates the total number of bytes in an MPEG audio frame.

Includes both the audio payload and any padding bytes.

Parameters

  mpa | Pointer to the MPEG audio header structure.

Returns
  The total number of bytes in the frame.

## ◆ MPA_DATA_BYTES

#define MPA_DATA_BYTES | ( |  | mpa | ) |

Value:
(mpa_bitrate(mpa) * mpa_samples(mpa) \
/ mpa_frequency(mpa) / 8)

Calculates the number of data bytes in an MPEG audio frame.

Computes the size of the audio payload (excluding padding) based on bitrate, sample count, and sampling frequency.

Parameters

  mpa | Pointer to the MPEG audio header structure.

Returns
  The number of data bytes in the frame.

## ◆ MPA_DURATION_NS

#define MPA_DURATION_NS | ( |  | mpa | ) |

Value:
(1000000000 / mpa_frequency(mpa) * mpa_samples(mpa))

Calculates the duration of an MPEG audio frame in nanoseconds.

Uses the sample count and sampling frequency to compute the frame duration.

Parameters

  mpa | Pointer to the MPEG audio header structure.

Returns
  The duration of the frame in nanoseconds.

## ◆ MPA_FREQUENCY_VALID

#define MPA_FREQUENCY_VALID | ( |  | mpa | ) |

Value:
(mpa_frequency(mpa) > 0)

True if the sampling frequency index encodes a valid, non-zero frequency (i.e. mpa_frequency() > 0).

Parameters

  mpa | Pointer to the MPEG Audio frame header struct.

## ◆ MPA_LAYER_VALID

#define MPA_LAYER_VALID | ( |  | mpa | ) |

Value:
(mpa_layer(mpa) >= 0)

True if the MPEG Audio layer field encodes a recognised layer (i.e. mpa_layer() >= 0).

Parameters

  mpa | Pointer to the MPEG Audio frame header struct.

## ◆ MPA_SYNC_VALID

#define MPA_SYNC_VALID | ( |  | mpa | ) |

Value:
((mpa)->sync == MPA_SYNC)
MPA_SYNC
@ MPA_SYNC
Definition mpeg-audio.h:175

True if the sync field of an MPEG Audio frame header contains the required 0x7FF sync word.

Parameters

  mpa | Pointer to the MPEG Audio frame header struct.

## ◆ MPA_UNMARSHAL

#define MPA_UNMARSHAL | ( |  | mpa,
|  |  | n )

Value:
do { \
(mpa)->sync = MPA_UNMARSHAL_SYNC(n); \
(mpa)->version = MPA_UNMARSHAL_VERSION(n); \
(mpa)->layer = MPA_UNMARSHAL_LAYER(n); \
(mpa)->protection = MPA_UNMARSHAL_PROTECTION(n); \
(mpa)->bitrate = MPA_UNMARSHAL_BITRATE(n); \
(mpa)->frequency = MPA_UNMARSHAL_FREQUENCY(n); \
(mpa)->padding = MPA_UNMARSHAL_PADDING(n); \
(mpa)->priv = MPA_UNMARSHAL_PRIVATE(n); \
(mpa)->mode = MPA_UNMARSHAL_MODE(n); \
(mpa)->modeext = MPA_UNMARSHAL_MODEEXT(n); \
(mpa)->copyright = MPA_UNMARSHAL_COPYRIGHT(n); \
(mpa)->original = MPA_UNMARSHAL_ORIGINAL(n); \
(mpa)->emphasis = MPA_UNMARSHAL_EMPHASIS(n); \
} while (0)

## ◆ MPA_UNMARSHAL_BITRATE

#define MPA_UNMARSHAL_BITRATE | ( |  | n | ) |

Value:
((n) >> 12 & 0xf)

## ◆ MPA_UNMARSHAL_COPYRIGHT

#define MPA_UNMARSHAL_COPYRIGHT | ( |  | n | ) |

Value:
((n) >> 3 & 0x1)

## ◆ MPA_UNMARSHAL_EMPHASIS

#define MPA_UNMARSHAL_EMPHASIS | ( |  | n | ) |

Value:
((n) >> 0 & 0x3)

## ◆ MPA_UNMARSHAL_FREQUENCY

#define MPA_UNMARSHAL_FREQUENCY | ( |  | n | ) |

Value:
((n) >> 10 & 0x3)

## ◆ MPA_UNMARSHAL_LAYER

#define MPA_UNMARSHAL_LAYER | ( |  | n | ) |

Value:
((n) >> 17 & 0x3)

## ◆ MPA_UNMARSHAL_MODE

#define MPA_UNMARSHAL_MODE | ( |  | n | ) |

Value:
((n) >> 6 & 0x3)

## ◆ MPA_UNMARSHAL_MODEEXT

#define MPA_UNMARSHAL_MODEEXT | ( |  | n | ) |

Value:
((n) >> 4 & 0x3)

## ◆ MPA_UNMARSHAL_ORIGINAL

#define MPA_UNMARSHAL_ORIGINAL | ( |  | n | ) |

Value:
((n) >> 2 & 0x1)

## ◆ MPA_UNMARSHAL_PADDING

#define MPA_UNMARSHAL_PADDING | ( |  | n | ) |

Value:
((n) >> 9 & 0x1)

## ◆ MPA_UNMARSHAL_PRIVATE

#define MPA_UNMARSHAL_PRIVATE | ( |  | n | ) |

Value:
((n) >> 8 & 0x1)

## ◆ MPA_UNMARSHAL_PROTECTION

#define MPA_UNMARSHAL_PROTECTION | ( |  | n | ) |

Value:
((n) >> 16 & 0x1)

## ◆ MPA_UNMARSHAL_SYNC

#define MPA_UNMARSHAL_SYNC | ( |  | n | ) |

Value:
((n) >> 21 & 0x7ff)

## ◆ MPA_UNMARSHAL_VERSION

#define MPA_UNMARSHAL_VERSION | ( |  | n | ) |

Value:
((n) >> 19 & 0x3)

## ◆ MPA_VALID

#define MPA_VALID | ( |  | mpa | ) |

Value:
(MPA_SYNC_VALID(mpa) \
&& MPA_VERSION_VALID(mpa) \
&& MPA_LAYER_VALID(mpa) \
&& MPA_BITRATE_VALID(mpa) \
&& MPA_FREQUENCY_VALID(mpa))
MPA_FREQUENCY_VALID
#define MPA_FREQUENCY_VALID(mpa)
True if the sampling frequency index encodes a valid, non-zero frequency (i.e. mpa_frequency() > 0).
Definition mpeg-audio.h:206
MPA_SYNC_VALID
#define MPA_SYNC_VALID(mpa)
True if the sync field of an MPEG Audio frame header contains the required 0x7FF sync word.
Definition mpeg-audio.h:182
MPA_BITRATE_VALID
#define MPA_BITRATE_VALID(mpa)
True if the bitrate index encodes a non-zero, valid bitrate (i.e. mpa_bitrate() > 0).
Definition mpeg-audio.h:200
MPA_VERSION_VALID
#define MPA_VERSION_VALID(mpa)
True if the MPEG Audio version field encodes a recognised version (i.e. mpa_version() >= 0).
Definition mpeg-audio.h:188
MPA_LAYER_VALID
#define MPA_LAYER_VALID(mpa)
True if the MPEG Audio layer field encodes a recognised layer (i.e. mpa_layer() >= 0).
Definition mpeg-audio.h:194

True if all fields of an MPEG Audio frame header are simultaneously valid.

Evaluates to true only when the sync word, version, layer, bitrate, and sampling frequency fields all pass their individual validity checks.

Parameters

  mpa | Pointer to the MPEG Audio frame header struct.

## ◆ MPA_VERSION_VALID

#define MPA_VERSION_VALID | ( |  | mpa | ) |

Value:
(mpa_version(mpa) >= 0)

True if the MPEG Audio version field encodes a recognised version (i.e. mpa_version() >= 0).

Parameters

  mpa | Pointer to the MPEG Audio frame header struct.

## Enumeration Type Documentation

## ◆ anonymous enum

anonymous enum

Required sync word value in the MPEG Audio frame header (all 11 sync bits set).

Enumerator
MPA_SYNC | sync word value

## Function Documentation

## ◆ decode_synchsafe_int()

WS_DLL_PUBLIC uint32_t decode_synchsafe_int | ( | uint32_t | val | ) |

Decodes a synchsafe integer from ID3 metadata.

Converts a 32-bit synchsafe integer (used in ID3v2 tags) to its raw integer value. Synchsafe integers avoid false MPEG syncs by ensuring no byte has all bits set.

Parameters

  val | The synchsafe encoded 32-bit integer.

Returns
  The decoded raw integer value.

## ◆ mpa_bitrate()

WS_DLL_PUBLIC unsigned int mpa_bitrate | ( | const struct mpa * | mpa | ) |

Extracts the bitrate from the MPEG audio header.

Parses the header to determine the encoded bitrate in kilobits per second.

Parameters

  mpa | Pointer to the MPEG audio header structure.

Returns
  The bitrate in kbps.

## ◆ mpa_frequency()

WS_DLL_PUBLIC unsigned int mpa_frequency | ( | const struct mpa * | mpa | ) |

Extracts the sampling frequency from the MPEG audio header.

Parses the header to determine the sample rate in Hz.

Parameters

  mpa | Pointer to the MPEG audio header structure.

Returns
  The sampling frequency in Hz.

## ◆ mpa_layer()

WS_DLL_PUBLIC int mpa_layer | ( | const struct mpa * | mpa | ) |

Extracts the MPEG audio layer from the given header.

Parses the MPEG audio header and returns the layer identifier (e.g., Layer I, II, III).

Parameters

  mpa | Pointer to the MPEG audio header structure.

Returns
  The MPEG layer as an integer code.

## ◆ mpa_padding()

WS_DLL_PUBLIC unsigned int mpa_padding | ( | const struct mpa * | mpa | ) |

Checks whether padding is present in the MPEG audio frame.

Determines if the frame includes padding bits used to adjust frame size.

Parameters

  mpa | Pointer to the MPEG audio header structure.

Returns
  1 if padding is present, 0 otherwise.

## ◆ mpa_samples()

WS_DLL_PUBLIC unsigned int mpa_samples | ( | const struct mpa * | mpa | ) |

Returns the number of audio samples per frame.

Determines the sample count based on MPEG version and layer.

Parameters

  mpa | Pointer to the MPEG audio header structure.

Returns
  The number of samples per frame.

## ◆ mpa_version()

WS_DLL_PUBLIC int mpa_version | ( | const struct mpa * | mpa | ) |

Extracts the MPEG audio version from the given header.

Parses the MPEG audio header and returns the version identifier (e.g., MPEG-1, MPEG-2).

Parameters

  mpa | Pointer to the MPEG audio header structure.

Returns
  The MPEG version as an integer code.