| 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 | // Interleaving of MP3 ADUs |
| 19 | // C++ header |
| 20 | |
| 21 | #ifndef _MP3_ADU_INTERLEAVING_HH |
| 22 | #define _MP3_ADU_INTERLEAVING_HH |
| 23 | |
| 24 | #ifndef _FRAMED_FILTER_HH |
| 25 | #include "FramedFilter.hh" |
| 26 | #endif |
| 27 | |
| 28 | // A data structure used to represent an interleaving |
| 29 | #define MAX_CYCLE_SIZE 256 |
| 30 | class Interleaving { |
| 31 | public: |
| 32 | Interleaving(unsigned cycleSize, unsigned char const* cycleArray); |
| 33 | virtual ~Interleaving(); |
| 34 | |
| 35 | unsigned cycleSize() const {return fCycleSize;} |
| 36 | unsigned char lookupInverseCycle(unsigned char index) const { |
| 37 | return fInverseCycle[index]; |
| 38 | } |
| 39 | |
| 40 | private: |
| 41 | unsigned fCycleSize; |
| 42 | unsigned char fInverseCycle[MAX_CYCLE_SIZE]; |
| 43 | }; |
| 44 | |
| 45 | // This class is used only as a base for the following two: |
| 46 | |
| 47 | class MP3ADUinterleaverBase: public FramedFilter { |
| 48 | protected: |
| 49 | MP3ADUinterleaverBase(UsageEnvironment& env, |
| 50 | FramedSource* inputSource); |
| 51 | // abstract base class |
| 52 | virtual ~MP3ADUinterleaverBase(); |
| 53 | |
| 54 | static FramedSource* getInputSource(UsageEnvironment& env, |
| 55 | char const* inputSourceName); |
| 56 | static void afterGettingFrame(void* clientData, |
| 57 | unsigned numBytesRead, |
| 58 | unsigned numTruncatedBytes, |
| 59 | struct timeval presentationTime, |
| 60 | unsigned durationInMicroseconds); |
| 61 | virtual void afterGettingFrame(unsigned numBytesRead, |
| 62 | struct timeval presentationTime, |
| 63 | unsigned durationInMicroseconds) = 0; |
| 64 | }; |
| 65 | |
| 66 | // This class is used to convert an ADU sequence from non-interleaved |
| 67 | // to interleaved form: |
| 68 | |
| 69 | class MP3ADUinterleaver: public MP3ADUinterleaverBase { |
| 70 | public: |
| 71 | static MP3ADUinterleaver* createNew(UsageEnvironment& env, |
| 72 | Interleaving const& interleaving, |
| 73 | FramedSource* inputSource); |
| 74 | |
| 75 | protected: |
| 76 | MP3ADUinterleaver(UsageEnvironment& env, |
| 77 | Interleaving const& interleaving, |
| 78 | FramedSource* inputSource); |
| 79 | // called only by createNew() |
| 80 | virtual ~MP3ADUinterleaver(); |
| 81 | |
| 82 | private: |
| 83 | // redefined virtual functions: |
| 84 | virtual void doGetNextFrame(); |
| 85 | virtual void afterGettingFrame(unsigned numBytesRead, |
| 86 | struct timeval presentationTime, |
| 87 | unsigned durationInMicroseconds); |
| 88 | |
| 89 | private: |
| 90 | void releaseOutgoingFrame(); |
| 91 | |
| 92 | private: |
| 93 | Interleaving const fInterleaving; |
| 94 | class InterleavingFrames* fFrames; |
| 95 | unsigned char fPositionOfNextIncomingFrame; |
| 96 | unsigned fII, fICC; |
| 97 | }; |
| 98 | |
| 99 | // This class is used to convert an ADU sequence from interleaved |
| 100 | // to non-interleaved form: |
| 101 | |
| 102 | class MP3ADUdeinterleaver: public MP3ADUinterleaverBase { |
| 103 | public: |
| 104 | static MP3ADUdeinterleaver* createNew(UsageEnvironment& env, |
| 105 | FramedSource* inputSource); |
| 106 | |
| 107 | protected: |
| 108 | MP3ADUdeinterleaver(UsageEnvironment& env, |
| 109 | FramedSource* inputSource); |
| 110 | // called only by createNew() |
| 111 | virtual ~MP3ADUdeinterleaver(); |
| 112 | |
| 113 | private: |
| 114 | // redefined virtual functions: |
| 115 | virtual void doGetNextFrame(); |
| 116 | virtual void afterGettingFrame(unsigned numBytesRead, |
| 117 | struct timeval presentationTime, |
| 118 | unsigned durationInMicroseconds); |
| 119 | |
| 120 | private: |
| 121 | void releaseOutgoingFrame(); |
| 122 | |
| 123 | private: |
| 124 | class DeinterleavingFrames* fFrames; |
| 125 | unsigned fIIlastSeen, fICClastSeen; |
| 126 | }; |
| 127 | |
| 128 | #endif |
| 129 | |
| 130 | |