MPEG2TransportFileServerMediaSubsession.hh 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. // A 'ServerMediaSubsession' object that creates new, unicast, "RTPSink"s
  17. // on demand, from a MPEG-2 Transport Stream file.
  18. // C++ header
  19. #ifndef _MPEG2_TRANSPORT_FILE_SERVER_MEDIA_SUBSESSION_HH
  20. #define _MPEG2_TRANSPORT_FILE_SERVER_MEDIA_SUBSESSION_HH
  21. #ifndef _FILE_SERVER_MEDIA_SUBSESSION_HH
  22. #include "FileServerMediaSubsession.hh"
  23. #endif
  24. #ifndef _MPEG2_TRANSPORT_STREAM_FRAMER_HH
  25. #include "MPEG2TransportStreamFramer.hh"
  26. #endif
  27. #ifndef _BYTE_STREAM_FILE_SOURCE_HH
  28. #include "ByteStreamFileSource.hh"
  29. #endif
  30. #ifndef _MPEG2_TRANSPORT_STREAM_TRICK_MODE_FILTER_HH
  31. #include "MPEG2TransportStreamTrickModeFilter.hh"
  32. #endif
  33. #ifndef _MPEG2_TRANSPORT_STREAM_FROM_ES_SOURCE_HH
  34. #include "MPEG2TransportStreamFromESSource.hh"
  35. #endif
  36. class ClientTrickPlayState; // forward
  37. class MPEG2TransportFileServerMediaSubsession: public FileServerMediaSubsession {
  38. public:
  39. static MPEG2TransportFileServerMediaSubsession*
  40. createNew(UsageEnvironment& env,
  41. char const* dataFileName, char const* indexFileName,
  42. Boolean reuseFirstSource);
  43. protected:
  44. MPEG2TransportFileServerMediaSubsession(UsageEnvironment& env,
  45. char const* fileName,
  46. MPEG2TransportStreamIndexFile* indexFile,
  47. Boolean reuseFirstSource);
  48. // called only by createNew();
  49. virtual ~MPEG2TransportFileServerMediaSubsession();
  50. virtual ClientTrickPlayState* newClientTrickPlayState();
  51. private: // redefined virtual functions
  52. // Note that because - to implement 'trick play' operations - we're operating on
  53. // more than just the input source, we reimplement some functions that are
  54. // already implemented in "OnDemandServerMediaSubsession", rather than
  55. // reimplementing "seekStreamSource()" and "setStreamSourceScale()":
  56. virtual void startStream(unsigned clientSessionId, void* streamToken,
  57. TaskFunc* rtcpRRHandler,
  58. void* rtcpRRHandlerClientData,
  59. unsigned short& rtpSeqNum,
  60. unsigned& rtpTimestamp,
  61. ServerRequestAlternativeByteHandler* serverRequestAlternativeByteHandler,
  62. void* serverRequestAlternativeByteHandlerClientData);
  63. virtual void pauseStream(unsigned clientSessionId, void* streamToken);
  64. virtual void seekStream(unsigned clientSessionId, void* streamToken, double& seekNPT, double streamDuration, u_int64_t& numBytes);
  65. virtual void setStreamScale(unsigned clientSessionId, void* streamToken, float scale);
  66. virtual void deleteStream(unsigned clientSessionId, void*& streamToken);
  67. // The virtual functions that are usually implemented by "ServerMediaSubsession"s:
  68. virtual FramedSource* createNewStreamSource(unsigned clientSessionId,
  69. unsigned& estBitrate);
  70. virtual RTPSink* createNewRTPSink(Groupsock* rtpGroupsock,
  71. unsigned char rtpPayloadTypeIfDynamic,
  72. FramedSource* inputSource);
  73. virtual void testScaleFactor(float& scale);
  74. virtual float duration() const;
  75. private:
  76. ClientTrickPlayState* lookupClient(unsigned clientSessionId);
  77. private:
  78. MPEG2TransportStreamIndexFile* fIndexFile;
  79. float fDuration;
  80. HashTable* fClientSessionHashTable; // indexed by client session id
  81. };
  82. // This class encapsulates the 'trick play' state for each current client (for
  83. // a given "MPEG2TransportFileServerMediaSubsession" - i.e., Transport Stream file).
  84. // It is used only within the implementation of "MPEG2TransportFileServerMediaSubsession", but is included here,
  85. // in case subclasses of "MPEG2TransportFileServerMediaSubsession" want to use it.
  86. class ClientTrickPlayState {
  87. public:
  88. ClientTrickPlayState(MPEG2TransportStreamIndexFile* indexFile);
  89. // Functions to bring "fNPT", "fTSRecordNum" and "fIxRecordNum" in sync:
  90. unsigned long updateStateFromNPT(double npt, double seekDuration);
  91. void updateStateOnScaleChange();
  92. void updateStateOnPlayChange(Boolean reverseToPreviousVSH);
  93. void handleStreamDeletion();
  94. void setSource(MPEG2TransportStreamFramer* framer);
  95. void setNextScale(float nextScale) { fNextScale = nextScale; }
  96. Boolean areChangingScale() const { return fNextScale != fScale; }
  97. protected:
  98. void updateTSRecordNum();
  99. void reseekOriginalTransportStreamSource();
  100. protected:
  101. MPEG2TransportStreamIndexFile* fIndexFile;
  102. ByteStreamFileSource* fOriginalTransportStreamSource;
  103. MPEG2TransportStreamTrickModeFilter* fTrickModeFilter;
  104. MPEG2TransportStreamFromESSource* fTrickPlaySource;
  105. MPEG2TransportStreamFramer* fFramer;
  106. float fScale, fNextScale, fNPT;
  107. unsigned long fTSRecordNum, fIxRecordNum;
  108. };
  109. #endif