live
MP3Internals.hh
Go to the documentation of this file.
1/**********
2This library is free software; you can redistribute it and/or modify it under
3the terms of the GNU Lesser General Public License as published by the
4Free Software Foundation; either version 3 of the License, or (at your
5option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
6
7This library is distributed in the hope that it will be useful, but WITHOUT
8ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
10more details.
11
12You should have received a copy of the GNU Lesser General Public License
13along with this library; if not, write to the Free Software Foundation, Inc.,
1451 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15**********/
16// "liveMedia"
17// Copyright (c) 1996-2024 Live Networks, Inc. All rights reserved.
18// MP3 internal implementation details
19// C++ header
20
21#ifndef _MP3_INTERNALS_HH
22#define _MP3_INTERNALS_HH
23
24#ifndef _BOOLEAN_HH
25#include "Boolean.hh"
26#endif
27#ifndef _BIT_VECTOR_HH
28#include "BitVector.hh"
29#endif
30
31typedef struct MP3SideInfo {
33 unsigned private_bits;
34 typedef struct gr_info_s {
35 int scfsi;
37 unsigned big_values;
38 unsigned global_gain;
41 unsigned block_type;
43 unsigned table_select[3];
44 unsigned region0_count;
45 unsigned region1_count;
46 unsigned subblock_gain[3];
47 unsigned maxband[3];
48 unsigned maxbandl;
49 unsigned maxb;
50 unsigned region1start;
51 unsigned region2start;
52 unsigned preflag;
55 double *full_gain[3];
56 double *pow2gain;
58 struct {
60 } ch[2];
62
63#define SBLIMIT 32
64#define MAX_MP3_FRAME_SIZE 2500 /* also big enough for an 'ADU'ized frame */
65
67public:
70
71 // 4-byte MPEG header:
72 unsigned hdr;
73
74 // a buffer that can be used to hold the rest of the frame:
76
77 // public parameters derived from the header
78 void setParamsFromHeader(); // this sets them
80 unsigned layer; // currently only 3 is supported
81 unsigned bitrate; // in kbps
82 unsigned samplingFreq;
85 unsigned frameSize; // doesn't include the initial 4-byte header
86 unsigned sideInfoSize;
88
89 void setBytePointer(unsigned char const* restOfFrame,
90 unsigned totNumBytes) {// called during setup
91 bv.setup((unsigned char*)restOfFrame, 0, 8*totNumBytes);
92 }
93
94 // other, public parameters used when parsing input (perhaps get rid of)
95 unsigned oldHdr, firstHdr;
96
97 // Extract (unpack) the side info from the frame into a struct:
99
100 // The bit pointer used for reading data from frame data
101 unsigned getBits(unsigned numBits) { return bv.getBits(numBits); }
102 unsigned get1Bit() { return bv.get1Bit(); }
103
104private:
106
107 // other, private parameters derived from the header
108 unsigned bitrateIndex;
113 unsigned mode;
114 unsigned mode_ext;
117 unsigned emphasis;
118 unsigned stereo;
119
120private:
122};
123
124unsigned ComputeFrameSize(unsigned bitrate, unsigned samplingFreq,
125 Boolean usePadding, Boolean isMPEG2,
126 unsigned char layer);
127
128Boolean GetADUInfoFromMP3Frame(unsigned char const* framePtr,
129 unsigned totFrameSize,
130 unsigned& hdr, unsigned& frameSize,
131 MP3SideInfo& sideInfo, unsigned& sideInfoSize,
132 unsigned& backpointer, unsigned& aduSize);
133
134Boolean ZeroOutMP3SideInfo(unsigned char* framePtr, unsigned totFrameSize,
135 unsigned newBackpointer);
136
137unsigned TranscodeMP3ADU(unsigned char const* fromPtr, unsigned fromSize,
138 unsigned toBitrate,
139 unsigned char* toPtr, unsigned toMaxSize,
140 unsigned& availableBytesForBackpointer);
141 // returns the size of the resulting ADU (0 on failure)
142
143#endif
unsigned char Boolean
Definition: Boolean.hh:25
unsigned TranscodeMP3ADU(unsigned char const *fromPtr, unsigned fromSize, unsigned toBitrate, unsigned char *toPtr, unsigned toMaxSize, unsigned &availableBytesForBackpointer)
#define MAX_MP3_FRAME_SIZE
Definition: MP3Internals.hh:64
struct MP3SideInfo MP3SideInfo_t
Boolean GetADUInfoFromMP3Frame(unsigned char const *framePtr, unsigned totFrameSize, unsigned &hdr, unsigned &frameSize, MP3SideInfo &sideInfo, unsigned &sideInfoSize, unsigned &backpointer, unsigned &aduSize)
Boolean ZeroOutMP3SideInfo(unsigned char *framePtr, unsigned totFrameSize, unsigned newBackpointer)
unsigned ComputeFrameSize(unsigned bitrate, unsigned samplingFreq, Boolean usePadding, Boolean isMPEG2, unsigned char layer)
unsigned get1Bit()
void setup(unsigned char *baseBytePtr, unsigned baseBitOffset, unsigned totNumBits)
unsigned getBits(unsigned numBits)
unsigned sideInfoSize
Definition: MP3Internals.hh:86
unsigned bitrateIndex
unsigned computeSideInfoSize()
unsigned char frameBytes[MAX_MP3_FRAME_SIZE]
Definition: MP3Internals.hh:75
unsigned samplingFreqIndex
Boolean isStereo
Definition: MP3Internals.hh:83
unsigned getBits(unsigned numBits)
unsigned oldHdr
Definition: MP3Internals.hh:95
unsigned frameSize
Definition: MP3Internals.hh:85
unsigned bitrate
Definition: MP3Internals.hh:81
unsigned emphasis
unsigned firstHdr
Definition: MP3Internals.hh:95
unsigned mode_ext
void getSideInfo(MP3SideInfo &si)
unsigned get1Bit()
Boolean isFreeFormat
Definition: MP3Internals.hh:84
void setBytePointer(unsigned char const *restOfFrame, unsigned totNumBytes)
Definition: MP3Internals.hh:89
void setParamsFromHeader()
unsigned samplingFreq
Definition: MP3Internals.hh:82
unsigned layer
Definition: MP3Internals.hh:80
unsigned subblock_gain[3]
Definition: MP3Internals.hh:46
unsigned table_select[3]
Definition: MP3Internals.hh:43
unsigned window_switching_flag
Definition: MP3Internals.hh:40
struct MP3SideInfo::@4 ch[2]
unsigned private_bits
Definition: MP3Internals.hh:33
gr_info_s_t gr[2]
Definition: MP3Internals.hh:59
struct MP3SideInfo::gr_info_s gr_info_s_t
unsigned main_data_begin
Definition: MP3Internals.hh:32