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 // A class encapsulating the state of a MP3 stream 00019 // C++ header 00020 00021 #ifndef _MP3_STREAM_STATE_HH 00022 #define _MP3_STREAM_STATE_HH 00023 00024 #ifndef _USAGE_ENVIRONMENT_HH 00025 #include "UsageEnvironment.hh" 00026 #endif 00027 #ifndef _BOOLEAN_HH 00028 #include "Boolean.hh" 00029 #endif 00030 #ifndef _MP3_INTERNALS_HH 00031 #include "MP3Internals.hh" 00032 #endif 00033 #ifndef _NET_COMMON_H 00034 #include "NetCommon.h" 00035 #endif 00036 00037 #include <stdio.h> 00038 00039 #define XING_TOC_LENGTH 100 00040 00041 class MP3StreamState { 00042 public: 00043 MP3StreamState(UsageEnvironment& env); 00044 virtual ~MP3StreamState(); 00045 00046 void assignStream(FILE* fid, unsigned fileSize); 00047 00048 unsigned findNextHeader(struct timeval& presentationTime); 00049 Boolean readFrame(unsigned char* outBuf, unsigned outBufSize, 00050 unsigned& resultFrameSize, 00051 unsigned& resultDurationInMicroseconds); 00052 // called after findNextHeader() 00053 00054 void getAttributes(char* buffer, unsigned bufferSize) const; 00055 00056 void writeGetCmd(char const* hostName, unsigned short portNum, 00057 char const* fileName); 00058 00059 float filePlayTime() const; // in seconds 00060 unsigned fileSize() const { return fFileSize; } 00061 void setPresentationTimeScale(unsigned scale) { fPresentationTimeScale = scale; } 00062 unsigned getByteNumberFromPositionFraction(float fraction); // 0.0 <= fraction <= 1.0 00063 void seekWithinFile(unsigned seekByteNumber); 00064 00065 void checkForXingHeader(); // hack for Xing VBR files 00066 00067 protected: // private->protected requested by Pierre l'Hussiez 00068 unsigned readFromStream(unsigned char* buf, unsigned numChars); 00069 00070 private: 00071 MP3FrameParams& fr() {return fCurrentFrame;} 00072 MP3FrameParams const& fr() const {return fCurrentFrame;} 00073 00074 struct timeval currentFramePlayTime() const; 00075 00076 Boolean findNextFrame(); 00077 00078 private: 00079 UsageEnvironment& fEnv; 00080 FILE* fFid; 00081 Boolean fFidIsReallyASocket; 00082 unsigned fFileSize; 00083 unsigned fNumFramesInFile; 00084 unsigned fPresentationTimeScale; 00085 // used if we're streaming at other than the normal rate 00086 Boolean fIsVBR, fHasXingTOC; 00087 u_int8_t fXingTOC[XING_TOC_LENGTH]; // set iff "fHasXingTOC" is True 00088 00089 MP3FrameParams fCurrentFrame; 00090 struct timeval fNextFramePresentationTime; 00091 }; 00092 00093 #endif
1.5.2