MP3ADUinterleaving.hh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. This library is distributed in the hope that it will be useful, but WITHOUT
  7. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
  9. more details.
  10. You should have received a copy of the GNU Lesser General Public License
  11. along with this library; if not, write to the Free Software Foundation, Inc.,
  12. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  13. **********/
  14. // "liveMedia"
  15. // Copyright (c) 1996-2019 Live Networks, Inc. All rights reserved.
  16. // Interleaving of MP3 ADUs
  17. // C++ header
  18. #ifndef _MP3_ADU_INTERLEAVING_HH
  19. #define _MP3_ADU_INTERLEAVING_HH
  20. #ifndef _FRAMED_FILTER_HH
  21. #include "FramedFilter.hh"
  22. #endif
  23. // A data structure used to represent an interleaving
  24. #define MAX_CYCLE_SIZE 256
  25. class Interleaving {
  26. public:
  27. Interleaving(unsigned cycleSize, unsigned char const* cycleArray);
  28. virtual ~Interleaving();
  29. unsigned cycleSize() const {return fCycleSize;}
  30. unsigned char lookupInverseCycle(unsigned char index) const {
  31. return fInverseCycle[index];
  32. }
  33. private:
  34. unsigned fCycleSize;
  35. unsigned char fInverseCycle[MAX_CYCLE_SIZE];
  36. };
  37. // This class is used only as a base for the following two:
  38. class MP3ADUinterleaverBase: public FramedFilter {
  39. protected:
  40. MP3ADUinterleaverBase(UsageEnvironment& env,
  41. FramedSource* inputSource);
  42. // abstract base class
  43. virtual ~MP3ADUinterleaverBase();
  44. static FramedSource* getInputSource(UsageEnvironment& env,
  45. char const* inputSourceName);
  46. static void afterGettingFrame(void* clientData,
  47. unsigned numBytesRead,
  48. unsigned numTruncatedBytes,
  49. struct timeval presentationTime,
  50. unsigned durationInMicroseconds);
  51. virtual void afterGettingFrame(unsigned numBytesRead,
  52. struct timeval presentationTime,
  53. unsigned durationInMicroseconds) = 0;
  54. };
  55. // This class is used to convert an ADU sequence from non-interleaved
  56. // to interleaved form:
  57. class MP3ADUinterleaver: public MP3ADUinterleaverBase {
  58. public:
  59. static MP3ADUinterleaver* createNew(UsageEnvironment& env,
  60. Interleaving const& interleaving,
  61. FramedSource* inputSource);
  62. protected:
  63. MP3ADUinterleaver(UsageEnvironment& env,
  64. Interleaving const& interleaving,
  65. FramedSource* inputSource);
  66. // called only by createNew()
  67. virtual ~MP3ADUinterleaver();
  68. private:
  69. // redefined virtual functions:
  70. virtual void doGetNextFrame();
  71. virtual void afterGettingFrame(unsigned numBytesRead,
  72. struct timeval presentationTime,
  73. unsigned durationInMicroseconds);
  74. private:
  75. void releaseOutgoingFrame();
  76. private:
  77. Interleaving const fInterleaving;
  78. class InterleavingFrames* fFrames;
  79. unsigned char fPositionOfNextIncomingFrame;
  80. unsigned fII, fICC;
  81. };
  82. // This class is used to convert an ADU sequence from interleaved
  83. // to non-interleaved form:
  84. class MP3ADUdeinterleaver: public MP3ADUinterleaverBase {
  85. public:
  86. static MP3ADUdeinterleaver* createNew(UsageEnvironment& env,
  87. FramedSource* inputSource);
  88. protected:
  89. MP3ADUdeinterleaver(UsageEnvironment& env,
  90. FramedSource* inputSource);
  91. // called only by createNew()
  92. virtual ~MP3ADUdeinterleaver();
  93. private:
  94. // redefined virtual functions:
  95. virtual void doGetNextFrame();
  96. virtual void afterGettingFrame(unsigned numBytesRead,
  97. struct timeval presentationTime,
  98. unsigned durationInMicroseconds);
  99. private:
  100. void releaseOutgoingFrame();
  101. private:
  102. class DeinterleavingFrames* fFrames;
  103. unsigned fIIlastSeen, fICClastSeen;
  104. };
  105. #endif