liveMedia/MP3ADUdescriptor.cpp

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-2013 Live Networks, Inc.  All rights reserved.
00018 // Descriptor preceding frames of 'ADU' MP3 streams (for improved loss-tolerance)
00019 // Implementation
00020 
00021 #include "MP3ADUdescriptor.hh"
00022 
00024 
00025 //##### NOTE: For now, ignore fragmentation.  Fix this later! #####
00026 
00027 #define TWO_BYTE_DESCR_FLAG 0x40
00028 
00029 unsigned ADUdescriptor::generateDescriptor(unsigned char*& toPtr,
00030                                            unsigned remainingFrameSize) {
00031   unsigned descriptorSize = ADUdescriptor::computeSize(remainingFrameSize);
00032   switch (descriptorSize) {
00033   case 1: {
00034     *toPtr++ = (unsigned char)remainingFrameSize;
00035     break;
00036   }
00037   case 2: {
00038     generateTwoByteDescriptor(toPtr, remainingFrameSize);
00039     break;
00040   }
00041   }
00042 
00043   return descriptorSize;
00044 }
00045 
00046 void ADUdescriptor::generateTwoByteDescriptor(unsigned char*& toPtr,
00047                                               unsigned remainingFrameSize) {
00048   *toPtr++ = (TWO_BYTE_DESCR_FLAG|(unsigned char)(remainingFrameSize>>8));
00049   *toPtr++ = (unsigned char)(remainingFrameSize&0xFF);
00050 }
00051 
00052 unsigned ADUdescriptor::getRemainingFrameSize(unsigned char*& fromPtr) {
00053   unsigned char firstByte = *fromPtr++;
00054 
00055   if (firstByte&TWO_BYTE_DESCR_FLAG) {
00056     // This is a 2-byte descriptor
00057     unsigned char secondByte = *fromPtr++;
00058 
00059     return ((firstByte&0x3F)<<8) | secondByte;
00060   } else {
00061     // This is a 1-byte descriptor
00062     return (firstByte&0x3F);
00063   }
00064 }
00065 

Generated on Mon Apr 29 13:28:01 2013 for live by  doxygen 1.5.2