1/**********
2This library is free software; you can redistribute it and/or modify it under
3the terms of the GNU Lesser General Public License as published by the
4Free Software Foundation; either version 3 of the License, or (at your
5option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
6
7This library is distributed in the hope that it will be useful, but WITHOUT
8ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
10more details.
11
12You should have received a copy of the GNU Lesser General Public License
13along with this library; if not, write to the Free Software Foundation, Inc.,
1451 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15**********/
16// "liveMedia"
17// Copyright (c) 1996-2020 Live Networks, Inc. All rights reserved.
18// RTP sink for T.140 text (RFC 2793)
19// C++ header
20
21#ifndef _T140_TEXT_RTP_SINK_HH
22#define _T140_TEXT_RTP_SINK_HH
23
24#ifndef _TEXT_RTP_SINK_HH
25#include "TextRTPSink.hh"
26#endif
27#ifndef _FRAMED_FILTER_HH
28#include "FramedFilter.hh"
29#endif
30
31class T140IdleFilter;
32
33class T140TextRTPSink: public TextRTPSink {
34public:
35 static T140TextRTPSink* createNew(UsageEnvironment& env, Groupsock* RTPgs, unsigned char rtpPayloadFormat);
36
37protected:
38 T140TextRTPSink(UsageEnvironment& env, Groupsock* RTPgs, unsigned char rtpPayloadFormat);
39 // called only by createNew()
40
41 virtual ~T140TextRTPSink();
42
43protected: // redefined virtual functions:
44 virtual Boolean continuePlaying();
45 virtual void doSpecialFrameHandling(unsigned fragmentationOffset,
46 unsigned char* frameStart,
47 unsigned numBytesInFrame,
48 struct timeval framePresentationTime,
49 unsigned numRemainingBytes);
50 virtual Boolean frameCanAppearAfterPacketStart(unsigned char const* frameStart,
51 unsigned numBytesInFrame) const;
52
53protected:
54 T140IdleFilter* fOurIdleFilter;
55 Boolean fAreInIdlePeriod;
56};
57
58
59////////// T140IdleFilter definition //////////
60
61// Because the T.140 text RTP payload format specification recommends that (empty) RTP packets be sent during 'idle periods'
62// when no new text is available, we implement "T140TextRTPSink" using a separate "T140IdleFilter" class - sitting in front
63// - that delivers, to the "T140TextRTPSink", a continuous sequence of (possibly) empty frames.
64// (Note: This class should be used only by "T140TextRTPSink", or a subclass.)
65
66class T140IdleFilter: public FramedFilter {
67public:
68 T140IdleFilter(UsageEnvironment& env, FramedSource* inputSource);
69 virtual ~T140IdleFilter();
70
71private: // redefined virtual functions:
72 virtual void doGetNextFrame();
73 virtual void doStopGettingFrames();
74
75private:
76 static void afterGettingFrame(void* clientData, unsigned frameSize,
77 unsigned numTruncatedBytes,
78 struct timeval presentationTime,
79 unsigned durationInMicroseconds);
80 void afterGettingFrame(unsigned frameSize,
81 unsigned numTruncatedBytes,
82 struct timeval presentationTime,
83 unsigned durationInMicroseconds);
84
85 static void handleIdleTimeout(void* clientData);
86 void handleIdleTimeout();
87
88 void deliverFromBuffer();
89 void deliverEmptyFrame();
90
91 static void onSourceClosure(void* clientData);
92 void onSourceClosure();
93
94private:
95 TaskToken fIdleTimerTask;
96 unsigned fBufferSize, fNumBufferedBytes;
97 char* fBuffer;
98 unsigned fBufferedNumTruncatedBytes; // a count of truncated bytes from the upstream
99 struct timeval fBufferedDataPresentationTime;
100 unsigned fBufferedDataDurationInMicroseconds;
101};
102
103#endif
104