Coverage Report

Created: 2026-06-30 07:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wireshark/wsutil/mpeg-audio.c
Line
Count
Source
1
/* mpeg-audio.c
2
 *
3
 * MPEG Audio header dissection
4
 * Written by Shaun Jackman <sjackman@gmail.com>
5
 * Copyright 2007 Shaun Jackman
6
 *
7
 * Wiretap Library
8
 * SPDX-License-Identifier: GPL-2.0-or-later
9
 */
10
11
#include "mpeg-audio.h"
12
13
static const int mpa_versions[4] = { 2, -1, 1, 0 };
14
static const int mpa_layers[4] = { -1, 2, 1, 0 };
15
16
static const unsigned int mpa_samples_data[3][3] = {
17
  { 384, 1152, 1152 },
18
  { 384, 1152, 576 },
19
  { 384, 1152, 576 },
20
};
21
22
static const unsigned int mpa_bitrates[3][3][16] = { /* kb/s */
23
  {
24
    { 0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448 },
25
    { 0, 32, 48, 56,  64,  80,  96, 112, 128, 160, 192, 224, 256, 320, 384 },
26
    { 0, 32, 40, 48,  56,  64,  80,  96, 112, 128, 160, 192, 224, 256, 320 },
27
  },
28
  {
29
    { 0, 32, 48, 56,  64,  80,  96, 112, 128, 144, 160, 176, 192, 224, 256 },
30
    { 0,  8, 16, 24,  32,  40,  48,  56,  64,  80,  96, 112, 128, 144, 160 },
31
    { 0,  8, 16, 24,  32,  40,  48,  56,  64,  80,  96, 112, 128, 144, 160 },
32
  },
33
  {
34
    { 0, 32, 48, 56,  64,  80,  96, 112, 128, 144, 160, 176, 192, 224, 256 },
35
    { 0,  8, 16, 24,  32,  40,  48,  56,  64,  80,  96, 112, 128, 144, 160 },
36
    { 0,  8, 16, 24,  32,  40,  48,  56,  64,  80,  96, 112, 128, 144, 160 },
37
  },
38
};
39
40
static const unsigned int mpa_frequencies[3][4] = {
41
  { 44100, 48000, 32000 },
42
  { 22050, 24000, 16000 },
43
  { 11025, 12000, 8000 },
44
};
45
46
static const unsigned int mpa_padding_data[3] = { 4, 1, 1 };
47
48
int
49
mpa_version(const struct mpa *mpa)
50
0
{
51
0
  return mpa_versions[mpa->version];
52
0
}
53
54
int
55
mpa_layer(const struct mpa *mpa)
56
0
{
57
0
  return mpa_layers[mpa->layer];
58
0
}
59
60
unsigned
61
mpa_samples(const struct mpa *mpa)
62
0
{
63
0
  return mpa_samples_data[mpa_versions[mpa->version]][mpa_layer(mpa)];
64
0
}
65
66
unsigned
67
mpa_bitrate(const struct mpa *mpa)
68
0
{
69
0
  return (1000 * (mpa_bitrates[mpa_versions[mpa->version]][mpa_layers[mpa->layer]][mpa->bitrate]));
70
0
}
71
72
unsigned
73
mpa_frequency(const struct mpa *mpa)
74
0
{
75
0
  return(mpa_frequencies[mpa_versions[mpa->version]][mpa->frequency]);
76
0
}
77
78
unsigned
79
mpa_padding(const struct mpa *mpa)
80
0
{
81
0
  return(mpa->padding ? mpa_padding_data[mpa_layers[mpa->layer]] : 0);
82
0
}
83
84
/* Decode an ID3v2 synchsafe integer.
85
 * See https://id3.org/id3v2.4.0-structure section 6.2.
86
 */
87
uint32_t
88
decode_synchsafe_int(uint32_t input)
89
0
{
90
0
  uint32_t value;
91
92
  /* High-order byte */
93
0
  value = (input >> 24) & 0x7f;
94
  /* Shift the result left to make room for the next 7 bits */
95
0
  value <<= 7;
96
97
  /* Now OR in the 2nd byte */
98
0
  value |= (input >> 16) & 0x7f;
99
0
  value <<= 7;
100
101
  /* ... and the 3rd */
102
0
  value |= (input >> 8) & 0x7f;
103
0
  value <<= 7;
104
105
  /* For the 4th byte don't do the shift */
106
0
  value |= input & 0x7f;
107
108
0
  return value;
109
0
}
110
111
/*
112
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
113
 *
114
 * Local variables:
115
 * c-basic-offset: 8
116
 * tab-width: 8
117
 * indent-tabs-mode: t
118
 * End:
119
 *
120
 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
121
 * :indentSize=8:tabSize=8:noTabs=false:
122
 */