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 DV video (RFC 3189)
19// (Thanks to Ben Hutchings for prototyping this.)
20// Implementation
21
22#include "DVVideoRTPSink.hh"
23
24////////// DVVideoRTPSink implementation //////////
25
26DVVideoRTPSink
27::DVVideoRTPSink(UsageEnvironment& env, Groupsock* RTPgs, unsigned char rtpPayloadFormat)
28 : VideoRTPSink(env, RTPgs, rtpPayloadFormat, 90000, "DV"),
29 fFmtpSDPLine(NULL) {
30}
31
32DVVideoRTPSink::~DVVideoRTPSink() {
33 delete[] fFmtpSDPLine;
34}
35
36DVVideoRTPSink*
37DVVideoRTPSink::createNew(UsageEnvironment& env, Groupsock* RTPgs, unsigned char rtpPayloadFormat) {
38 return new DVVideoRTPSink(env, RTPgs, rtpPayloadFormat);
39}
40
41Boolean DVVideoRTPSink::sourceIsCompatibleWithUs(MediaSource& source) {
42 // Our source must be an appropriate framer:
43 return source.isDVVideoStreamFramer();
44}
45
46void DVVideoRTPSink::doSpecialFrameHandling(unsigned fragmentationOffset,
47 unsigned char* /*frameStart*/,
48 unsigned /*numBytesInFrame*/,
49 struct timeval framePresentationTime,
50 unsigned numRemainingBytes) {
51 if (numRemainingBytes == 0) {
52 // This packet contains the last (or only) fragment of the frame.
53 // Set the RTP 'M' ('marker') bit:
54 setMarkerBit();
55 }
56
57 // Also set the RTP timestamp:
58 setTimestamp(framePresentationTime);
59}
60
61unsigned DVVideoRTPSink::computeOverflowForNewFrame(unsigned newFrameSize) const {
62 unsigned initialOverflow = MultiFramedRTPSink::computeOverflowForNewFrame(newFrameSize);
63
64 // Adjust (increase) this overflow, if necessary, so that the amount of frame data that we use is an integral number
65 // of DIF blocks:
66 unsigned numFrameBytesUsed = newFrameSize - initialOverflow;
67 initialOverflow += numFrameBytesUsed%DV_DIF_BLOCK_SIZE;
68
69 return initialOverflow;
70}
71
72char const* DVVideoRTPSink::auxSDPLine() {
73 // Generate a new "a=fmtp:" line each time, using parameters from
74 // our framer source (in case they've changed since the last time that
75 // we were called):
76 DVVideoStreamFramer* framerSource = (DVVideoStreamFramer*)fSource;
77 if (framerSource == NULL) return NULL; // we don't yet have a source
78
79 return auxSDPLineFromFramer(framerSource);
80}
81
82char const* DVVideoRTPSink::auxSDPLineFromFramer(DVVideoStreamFramer* framerSource) {
83 char const* const profileName = framerSource->profileName();
84 if (profileName == NULL) return NULL;
85
86 char const* const fmtpSDPFmt = "a=fmtp:%d encode=%s;audio=bundled\r\n";
87 unsigned fmtpSDPFmtSize = strlen(fmtpSDPFmt)
88 + 3 // max payload format code length
89 + strlen(profileName);
90 delete[] fFmtpSDPLine; // if it already exists
91 fFmtpSDPLine = new char[fmtpSDPFmtSize];
92 sprintf(fFmtpSDPLine, fmtpSDPFmt, rtpPayloadType(), profileName);
93
94 return fFmtpSDPLine;
95}
96