live
MP3Internals.hh
Go to the documentation of this file.
1 /**********
2 This library is free software; you can redistribute it and/or modify it under
3 the terms of the GNU Lesser General Public License as published by the
4 Free Software Foundation; either version 3 of the License, or (at your
5 option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
6 
7 This library is distributed in the hope that it will be useful, but WITHOUT
8 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
10 more details.
11 
12 You should have received a copy of the GNU Lesser General Public License
13 along with this library; if not, write to the Free Software Foundation, Inc.,
14 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15 **********/
16 // "liveMedia"
17 // Copyright (c) 1996-2017 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 
31 typedef struct MP3SideInfo {
32  unsigned main_data_begin;
33  unsigned private_bits;
34  typedef struct gr_info_s {
35  int scfsi;
36  unsigned part2_3_length;
37  unsigned big_values;
38  unsigned global_gain;
41  unsigned block_type;
42  unsigned mixed_block_flag;
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;
53  unsigned scalefac_scale;
55  double *full_gain[3];
56  double *pow2gain;
57  } gr_info_s_t;
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 
67 public:
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:
98  void getSideInfo(MP3SideInfo& si);
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 
104 private:
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 
120 private:
121  unsigned computeSideInfoSize();
122 };
123 
124 unsigned ComputeFrameSize(unsigned bitrate, unsigned samplingFreq,
125  Boolean usePadding, Boolean isMPEG2,
126  unsigned char layer);
127 
128 Boolean GetADUInfoFromMP3Frame(unsigned char const* framePtr,
129  unsigned totFrameSize,
130  unsigned& hdr, unsigned& frameSize,
131  MP3SideInfo& sideInfo, unsigned& sideInfoSize,
132  unsigned& backpointer, unsigned& aduSize);
133 
134 Boolean ZeroOutMP3SideInfo(unsigned char* framePtr, unsigned totFrameSize,
135  unsigned newBackpointer);
136 
137 unsigned 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
Boolean ZeroOutMP3SideInfo(unsigned char *framePtr, unsigned totFrameSize, unsigned newBackpointer)
unsigned emphasis
struct MP3SideInfo::@4 ch[2]
#define MAX_MP3_FRAME_SIZE
Definition: MP3Internals.hh:64
unsigned getBits(unsigned numBits)
unsigned TranscodeMP3ADU(unsigned char const *fromPtr, unsigned fromSize, unsigned toBitrate, unsigned char *toPtr, unsigned toMaxSize, unsigned &availableBytesForBackpointer)
unsigned char frameBytes[MAX_MP3_FRAME_SIZE]
Definition: MP3Internals.hh:75
unsigned layer
Definition: MP3Internals.hh:80
unsigned get1Bit()
unsigned table_select[3]
Definition: MP3Internals.hh:43
Boolean isFreeFormat
Definition: MP3Internals.hh:84
unsigned frameSize
Definition: MP3Internals.hh:85
unsigned firstHdr
Definition: MP3Internals.hh:95
void setup(unsigned char *baseBytePtr, unsigned baseBitOffset, unsigned totNumBits)
unsigned getBits(unsigned numBits)
struct MP3SideInfo::gr_info_s gr_info_s_t
Boolean GetADUInfoFromMP3Frame(unsigned char const *framePtr, unsigned totFrameSize, unsigned &hdr, unsigned &frameSize, MP3SideInfo &sideInfo, unsigned &sideInfoSize, unsigned &backpointer, unsigned &aduSize)
unsigned samplingFreqIndex
unsigned main_data_begin
Definition: MP3Internals.hh:32
unsigned bitrateIndex
unsigned computeSideInfoSize()
unsigned ComputeFrameSize(unsigned bitrate, unsigned samplingFreq, Boolean usePadding, Boolean isMPEG2, unsigned char layer)
Boolean isStereo
Definition: MP3Internals.hh:83
unsigned samplingFreq
Definition: MP3Internals.hh:82
struct MP3SideInfo MP3SideInfo_t
unsigned sideInfoSize
Definition: MP3Internals.hh:86
void getSideInfo(MP3SideInfo &si)
void setParamsFromHeader()
unsigned private_bits
Definition: MP3Internals.hh:33
unsigned bitrate
Definition: MP3Internals.hh:81
unsigned window_switching_flag
Definition: MP3Internals.hh:40
unsigned mode_ext
void setBytePointer(unsigned char const *restOfFrame, unsigned totNumBytes)
Definition: MP3Internals.hh:89
gr_info_s_t gr[2]
Definition: MP3Internals.hh:59
unsigned oldHdr
Definition: MP3Internals.hh:95
unsigned subblock_gain[3]
Definition: MP3Internals.hh:46
unsigned get1Bit()