aboutsummaryrefslogtreecommitdiffstats
path: root/wsutil
diff options
context:
space:
mode:
Diffstat (limited to 'wsutil')
-rw-r--r--wsutil/mpeg-audio.c27
-rw-r--r--wsutil/mpeg-audio.h3
2 files changed, 30 insertions, 0 deletions
diff --git a/wsutil/mpeg-audio.c b/wsutil/mpeg-audio.c
index 00ac78d8bd..e22bef38c8 100644
--- a/wsutil/mpeg-audio.c
+++ b/wsutil/mpeg-audio.c
@@ -81,6 +81,33 @@ mpa_padding(const struct mpa *mpa)
return(mpa->padding ? mpa_padding_data[mpa_layers[mpa->layer]] : 0);
}
+/* Decode an ID3v2 synchsafe integer.
+ * See https://id3.org/id3v2.4.0-structure section 6.2.
+ */
+guint32
+decode_synchsafe_int(guint32 input)
+{
+ guint32 value;
+
+ /* High-order byte */
+ value = (input >> 24) & 0x7f;
+ /* Shift the result left to make room for the next 7 bits */
+ value <<= 7;
+
+ /* Now OR in the 2nd byte */
+ value |= (input >> 16) & 0x7f;
+ value <<= 7;
+
+ /* ... and the 3rd */
+ value |= (input >> 8) & 0x7f;
+ value <<= 7;
+
+ /* For the 4th byte don't do the shift */
+ value |= input & 0x7f;
+
+ return value;
+}
+
/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*
diff --git a/wsutil/mpeg-audio.h b/wsutil/mpeg-audio.h
index ced51ff745..e496a9b10d 100644
--- a/wsutil/mpeg-audio.h
+++ b/wsutil/mpeg-audio.h
@@ -11,6 +11,7 @@
#ifndef MPA_H
#define MPA_H 1
+#include <glib.h>
#include "ws_symbol_export.h"
struct mpa {
@@ -71,6 +72,8 @@ WS_DLL_PUBLIC
unsigned int mpa_frequency(const struct mpa *);
WS_DLL_PUBLIC
unsigned int mpa_padding(const struct mpa *);
+WS_DLL_PUBLIC
+guint32 decode_synchsafe_int(guint32);
#define MPA_DATA_BYTES(mpa) (mpa_bitrate(mpa) * mpa_samples(mpa) \
/ mpa_frequency(mpa) / 8)