T140TextRTPSink.hh 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. // RTP sink for T.140 text (RFC 2793)
  17. // C++ header
  18. #ifndef _T140_TEXT_RTP_SINK_HH
  19. #define _T140_TEXT_RTP_SINK_HH
  20. #ifndef _TEXT_RTP_SINK_HH
  21. #include "TextRTPSink.hh"
  22. #endif
  23. #ifndef _FRAMED_FILTER_HH
  24. #include "FramedFilter.hh"
  25. #endif
  26. class T140IdleFilter;
  27. class T140TextRTPSink: public TextRTPSink {
  28. public:
  29. static T140TextRTPSink* createNew(UsageEnvironment& env, Groupsock* RTPgs, unsigned char rtpPayloadFormat);
  30. protected:
  31. T140TextRTPSink(UsageEnvironment& env, Groupsock* RTPgs, unsigned char rtpPayloadFormat);
  32. // called only by createNew()
  33. virtual ~T140TextRTPSink();
  34. protected: // redefined virtual functions:
  35. virtual Boolean continuePlaying();
  36. virtual void doSpecialFrameHandling(unsigned fragmentationOffset,
  37. unsigned char* frameStart,
  38. unsigned numBytesInFrame,
  39. struct timeval framePresentationTime,
  40. unsigned numRemainingBytes);
  41. virtual Boolean frameCanAppearAfterPacketStart(unsigned char const* frameStart,
  42. unsigned numBytesInFrame) const;
  43. protected:
  44. T140IdleFilter* fOurIdleFilter;
  45. Boolean fAreInIdlePeriod;
  46. };
  47. ////////// T140IdleFilter definition //////////
  48. // Because the T.140 text RTP payload format specification recommends that (empty) RTP packets be sent during 'idle periods'
  49. // when no new text is available, we implement "T140TextRTPSink" using a separate "T140IdleFilter" class - sitting in front
  50. // - that delivers, to the "T140TextRTPSink", a continuous sequence of (possibly) empty frames.
  51. // (Note: This class should be used only by "T140TextRTPSink", or a subclass.)
  52. class T140IdleFilter: public FramedFilter {
  53. public:
  54. T140IdleFilter(UsageEnvironment& env, FramedSource* inputSource);
  55. virtual ~T140IdleFilter();
  56. private: // redefined virtual functions:
  57. virtual void doGetNextFrame();
  58. virtual void doStopGettingFrames();
  59. private:
  60. static void afterGettingFrame(void* clientData, unsigned frameSize,
  61. unsigned numTruncatedBytes,
  62. struct timeval presentationTime,
  63. unsigned durationInMicroseconds);
  64. void afterGettingFrame(unsigned frameSize,
  65. unsigned numTruncatedBytes,
  66. struct timeval presentationTime,
  67. unsigned durationInMicroseconds);
  68. static void handleIdleTimeout(void* clientData);
  69. void handleIdleTimeout();
  70. void deliverFromBuffer();
  71. void deliverEmptyFrame();
  72. static void onSourceClosure(void* clientData);
  73. void onSourceClosure();
  74. private:
  75. TaskToken fIdleTimerTask;
  76. unsigned fBufferSize, fNumBufferedBytes;
  77. char* fBuffer;
  78. unsigned fBufferedNumTruncatedBytes; // a count of truncated bytes from the upstream
  79. struct timeval fBufferedDataPresentationTime;
  80. unsigned fBufferedDataDurationInMicroseconds;
  81. };
  82. #endif