| 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-2020 Live Networks, Inc. All rights reserved. |
| 18 | // A class encapsulating the state of a MP3 stream |
| 19 | // C++ header |
| 20 | |
| 21 | #ifndef _MP3_STREAM_STATE_HH |
| 22 | #define _MP3_STREAM_STATE_HH |
| 23 | |
| 24 | #ifndef _USAGE_ENVIRONMENT_HH |
| 25 | #include "UsageEnvironment.hh" |
| 26 | #endif |
| 27 | #ifndef _BOOLEAN_HH |
| 28 | #include "Boolean.hh" |
| 29 | #endif |
| 30 | #ifndef _MP3_INTERNALS_HH |
| 31 | #include "MP3Internals.hh" |
| 32 | #endif |
| 33 | #ifndef _NET_COMMON_H |
| 34 | #include "NetCommon.h" |
| 35 | #endif |
| 36 | |
| 37 | #include <stdio.h> |
| 38 | |
| 39 | #define XING_TOC_LENGTH 100 |
| 40 | |
| 41 | class MP3StreamState { |
| 42 | public: |
| 43 | MP3StreamState(UsageEnvironment& env); |
| 44 | virtual ~MP3StreamState(); |
| 45 | |
| 46 | void assignStream(FILE* fid, unsigned fileSize); |
| 47 | |
| 48 | unsigned (struct timeval& presentationTime); |
| 49 | Boolean readFrame(unsigned char* outBuf, unsigned outBufSize, |
| 50 | unsigned& resultFrameSize, |
| 51 | unsigned& resultDurationInMicroseconds); |
| 52 | // called after findNextHeader() |
| 53 | |
| 54 | void getAttributes(char* buffer, unsigned bufferSize) const; |
| 55 | |
| 56 | float filePlayTime() const; // in seconds |
| 57 | unsigned fileSize() const { return fFileSize; } |
| 58 | void setPresentationTimeScale(unsigned scale) { fPresentationTimeScale = scale; } |
| 59 | unsigned getByteNumberFromPositionFraction(float fraction); // 0.0 <= fraction <= 1.0 |
| 60 | void seekWithinFile(unsigned seekByteNumber); |
| 61 | |
| 62 | void (); // hack for Xing VBR files |
| 63 | |
| 64 | protected: // private->protected requested by Pierre l'Hussiez |
| 65 | unsigned readFromStream(unsigned char* buf, unsigned numChars); |
| 66 | |
| 67 | private: |
| 68 | MP3FrameParams& fr() {return fCurrentFrame;} |
| 69 | MP3FrameParams const& fr() const {return fCurrentFrame;} |
| 70 | |
| 71 | struct timeval currentFramePlayTime() const; |
| 72 | |
| 73 | Boolean findNextFrame(); |
| 74 | |
| 75 | private: |
| 76 | UsageEnvironment& fEnv; |
| 77 | FILE* fFid; |
| 78 | Boolean fFidIsReallyASocket; |
| 79 | unsigned fFileSize; |
| 80 | unsigned fNumFramesInFile; |
| 81 | unsigned fPresentationTimeScale; |
| 82 | // used if we're streaming at other than the normal rate |
| 83 | Boolean fIsVBR, fHasXingTOC; |
| 84 | u_int8_t fXingTOC[XING_TOC_LENGTH]; // set iff "fHasXingTOC" is True |
| 85 | |
| 86 | MP3FrameParams fCurrentFrame; |
| 87 | struct timeval fNextFramePresentationTime; |
| 88 | }; |
| 89 | |
| 90 | #endif |
| 91 | |