liveMedia/MP3Internals.hh

Go to the documentation of this file.
00001 /**********
00002 This library is free software; you can redistribute it and/or modify it under
00003 the terms of the GNU Lesser General Public License as published by the
00004 Free Software Foundation; either version 2.1 of the License, or (at your
00005 option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
00006 
00007 This library is distributed in the hope that it will be useful, but WITHOUT
00008 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00009 FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
00010 more details.
00011 
00012 You should have received a copy of the GNU Lesser General Public License
00013 along with this library; if not, write to the Free Software Foundation, Inc.,
00014 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
00015 **********/
00016 // "liveMedia"
00017 // Copyright (c) 1996-2012 Live Networks, Inc.  All rights reserved.
00018 // MP3 internal implementation details
00019 // C++ header
00020 
00021 #ifndef _MP3_INTERNALS_HH
00022 #define _MP3_INTERNALS_HH
00023 
00024 #ifndef _BOOLEAN_HH
00025 #include "Boolean.hh"
00026 #endif
00027 #ifndef _BIT_VECTOR_HH
00028 #include "BitVector.hh"
00029 #endif
00030 
00031 typedef struct MP3SideInfo {
00032   unsigned main_data_begin;
00033   unsigned private_bits;
00034   typedef struct gr_info_s {
00035     int scfsi;
00036     unsigned part2_3_length;
00037     unsigned big_values;
00038     unsigned global_gain;
00039     unsigned scalefac_compress;
00040     unsigned window_switching_flag;
00041     unsigned block_type;
00042     unsigned mixed_block_flag;
00043     unsigned table_select[3];
00044     unsigned region0_count;
00045     unsigned region1_count;
00046     unsigned subblock_gain[3];
00047     unsigned maxband[3];
00048     unsigned maxbandl;
00049     unsigned maxb;
00050     unsigned region1start;
00051     unsigned region2start;
00052     unsigned preflag;
00053     unsigned scalefac_scale;
00054     unsigned count1table_select;
00055     double *full_gain[3];
00056     double *pow2gain;
00057   } gr_info_s_t;
00058   struct {
00059     gr_info_s_t gr[2];
00060   } ch[2];
00061 } MP3SideInfo_t;
00062 
00063 #define SBLIMIT 32
00064 #define MAX_MP3_FRAME_SIZE 2500 /* also big enough for an 'ADU'ized frame */
00065 
00066 class MP3FrameParams {
00067 public:
00068   MP3FrameParams();
00069   ~MP3FrameParams();
00070 
00071   // 4-byte MPEG header:
00072   unsigned hdr;
00073 
00074   // a buffer that can be used to hold the rest of the frame:
00075   unsigned char frameBytes[MAX_MP3_FRAME_SIZE];
00076 
00077   // public parameters derived from the header
00078   void setParamsFromHeader(); // this sets them
00079   Boolean isMPEG2;
00080   unsigned layer; // currently only 3 is supported
00081   unsigned bitrate; // in kbps
00082   unsigned samplingFreq;
00083   Boolean isStereo;
00084   Boolean isFreeFormat;
00085   unsigned frameSize; // doesn't include the initial 4-byte header
00086   unsigned sideInfoSize;
00087   Boolean hasCRC;
00088 
00089   void setBytePointer(unsigned char const* restOfFrame,
00090                       unsigned totNumBytes) {// called during setup
00091     bv.setup((unsigned char*)restOfFrame, 0, 8*totNumBytes);
00092   }
00093 
00094   // other, public parameters used when parsing input (perhaps get rid of)
00095   unsigned oldHdr, firstHdr;
00096 
00097   // Extract (unpack) the side info from the frame into a struct:
00098   void getSideInfo(MP3SideInfo& si);
00099 
00100   // The bit pointer used for reading data from frame data
00101   unsigned getBits(unsigned numBits) { return bv.getBits(numBits); }
00102   unsigned get1Bit() { return bv.get1Bit(); }
00103 
00104 private:
00105   BitVector bv;
00106 
00107   // other, private parameters derived from the header
00108   unsigned bitrateIndex;
00109   unsigned samplingFreqIndex;
00110   Boolean isMPEG2_5;
00111   Boolean padding;
00112   Boolean extension;
00113   unsigned mode;
00114   unsigned mode_ext;
00115   Boolean copyright;
00116   Boolean original;
00117   unsigned emphasis;
00118   unsigned stereo;
00119 
00120 private:
00121   unsigned computeSideInfoSize();
00122 };
00123 
00124 unsigned ComputeFrameSize(unsigned bitrate, unsigned samplingFreq,
00125                           Boolean usePadding, Boolean isMPEG2,
00126                           unsigned char layer);
00127 
00128 Boolean GetADUInfoFromMP3Frame(unsigned char const* framePtr,
00129                                unsigned totFrameSize,
00130                                unsigned& hdr, unsigned& frameSize,
00131                                MP3SideInfo& sideInfo, unsigned& sideInfoSize,
00132                                unsigned& backpointer, unsigned& aduSize);
00133 
00134 Boolean ZeroOutMP3SideInfo(unsigned char* framePtr, unsigned totFrameSize,
00135                            unsigned newBackpointer);
00136 
00137 unsigned TranscodeMP3ADU(unsigned char const* fromPtr, unsigned fromSize,
00138                       unsigned toBitrate,
00139                       unsigned char* toPtr, unsigned toMaxSize,
00140                       unsigned& availableBytesForBackpointer);
00141   // returns the size of the resulting ADU (0 on failure)
00142 
00143 #endif

Generated on Thu May 17 07:11:46 2012 for live by  doxygen 1.5.2