liveMedia/MP3ADUTranscoder.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 // Transcoder for ADUized MP3 frames
00019 // Implementation
00020 
00021 #include "MP3ADUTranscoder.hh"
00022 #include "MP3Internals.hh"
00023 #include <string.h>
00024 
00025 MP3ADUTranscoder::MP3ADUTranscoder(UsageEnvironment& env,
00026                                    unsigned outBitrate /* in kbps */,
00027                                    FramedSource* inputSource)
00028   : FramedFilter(env, inputSource),
00029     fOutBitrate(outBitrate),
00030     fAvailableBytesForBackpointer(0),
00031     fOrigADU(new unsigned char[MAX_MP3_FRAME_SIZE]) {
00032 }
00033 
00034 MP3ADUTranscoder::~MP3ADUTranscoder() {
00035   delete[] fOrigADU;
00036 }
00037 
00038 MP3ADUTranscoder* MP3ADUTranscoder::createNew(UsageEnvironment& env,
00039                                               unsigned outBitrate /* in kbps */,
00040                                               FramedSource* inputSource) {
00041   // The source must be an MP3 ADU source:
00042   if (strcmp(inputSource->MIMEtype(), "audio/MPA-ROBUST") != 0) {
00043     env.setResultMsg(inputSource->name(), " is not an MP3 ADU source");
00044     return NULL;
00045   }
00046 
00047   return new MP3ADUTranscoder(env, outBitrate, inputSource);
00048 }
00049 
00050 void MP3ADUTranscoder::getAttributes() const {
00051   // Begin by getting the attributes from our input source:
00052   fInputSource->getAttributes();
00053 
00054   // Then modify them by appending the corrected bandwidth
00055   char buffer[30];
00056   sprintf(buffer, " bandwidth %d", outBitrate());
00057   envir().appendToResultMsg(buffer);
00058 }
00059 
00060 void MP3ADUTranscoder::doGetNextFrame() {
00061   fInputSource->getNextFrame(fOrigADU, MAX_MP3_FRAME_SIZE,
00062                              afterGettingFrame, this, handleClosure, this);
00063 }
00064 
00065 void MP3ADUTranscoder::afterGettingFrame(void* clientData,
00066                                          unsigned numBytesRead,
00067                                          unsigned numTruncatedBytes,
00068                                          struct timeval presentationTime,
00069                                          unsigned durationInMicroseconds) {
00070   MP3ADUTranscoder* transcoder = (MP3ADUTranscoder*)clientData;
00071   transcoder->afterGettingFrame1(numBytesRead, numTruncatedBytes,
00072                                  presentationTime, durationInMicroseconds);
00073 }
00074 
00075 void MP3ADUTranscoder::afterGettingFrame1(unsigned numBytesRead,
00076                                           unsigned numTruncatedBytes,
00077                                           struct timeval presentationTime,
00078                                           unsigned durationInMicroseconds) {
00079   fNumTruncatedBytes = numTruncatedBytes; // but can we handle this being >0? #####
00080   fPresentationTime = presentationTime;
00081   fDurationInMicroseconds = durationInMicroseconds;
00082   fFrameSize = TranscodeMP3ADU(fOrigADU, numBytesRead, fOutBitrate,
00083                             fTo, fMaxSize, fAvailableBytesForBackpointer);
00084   if (fFrameSize == 0) { // internal error - bad ADU data?
00085     handleClosure(this);
00086     return;
00087   }
00088 
00089   // Call our own 'after getting' function.  Because we're not a 'leaf'
00090   // source, we can call this directly, without risking infinite recursion.
00091   afterGetting(this);
00092 }

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