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 
7 This library is distributed in the hope that it will be useful, but WITHOUT
8 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9 FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
10 more details.
11 
12 You should have received a copy of the GNU Lesser General Public License
13 along with this library; if not, write to the Free Software Foundation, Inc.,
14 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
15 **********/
16 // "liveMedia"
17 // Copyright (c) 1996-2020 Live Networks, Inc.  All rights reserved.
18 
19 #include "JPEG2000VideoRTPSink.hh"
20 
JPEG2000VideoRTPSink(UsageEnvironment & env,Groupsock * RTPgs)21 JPEG2000VideoRTPSink::JPEG2000VideoRTPSink(UsageEnvironment& env, Groupsock* RTPgs)
22   : VideoRTPSink(env, RTPgs, 98, 90000, "jpeg2000") {}
23 
~JPEG2000VideoRTPSink()24 JPEG2000VideoRTPSink::~JPEG2000VideoRTPSink() {}
25 
26 JPEG2000VideoRTPSink*
createNew(UsageEnvironment & env,Groupsock * RTPgs)27 JPEG2000VideoRTPSink::createNew(UsageEnvironment& env, Groupsock* RTPgs) {
28   return new JPEG2000VideoRTPSink(env, RTPgs);
29 }
30 
31 #define JPEG2000_PAYLOAD_HEADER_SIZE 8
32 
33 void JPEG2000VideoRTPSink
doSpecialFrameHandling(unsigned fragmentationOffset,unsigned char * frameStart,unsigned numBytesInFrame,struct timeval framePresentationTime,unsigned numRemainingBytes)34 ::doSpecialFrameHandling(unsigned fragmentationOffset,
35 			 unsigned char* frameStart,
36 			 unsigned numBytesInFrame,
37 			 struct timeval framePresentationTime,
38 			 unsigned numRemainingBytes) {
39   // Fill in the Payload Header:
40   u_int8_t payloadHeader[JPEG2000_PAYLOAD_HEADER_SIZE];
41 
42   // For "tp", assume for now that the payload is progressively scanned (i.e., tp = 0)
43   // For "MHF", assume that a whole main header is present (i.e., MHF = 3), *unless* we're
44   //   the second or later packet of a fragment, in which case we assume that it's not (i.e. MHF = 0)
45   // For "mh_id", set this to 0 (as specified in RFC 5371).
46   // For "T" (Tile field invalidation flag), set this to 0 (we don't set the "tile number" field).
47   payloadHeader[0] = fragmentationOffset > 0 ? 0x00 : 0x30;
48 
49   // Set the "priority" field to 255, as specified in RFC 5371:
50   payloadHeader[1] = 255;
51 
52   // Set the "tile number" field to 0:
53   payloadHeader[2] = payloadHeader[3] = 0;
54 
55   // Set the "reserved" field to 0, as specified in RFC 5371:
56   payloadHeader[4] = 0;
57 
58   // Set the "fragmentation offset" field to the value of our "fragmentationOffset" parameter:
59   payloadHeader[5] = (u_int8_t)(fragmentationOffset>>16);
60   payloadHeader[6] = (u_int8_t)(fragmentationOffset>>8);
61   payloadHeader[7] = (u_int8_t)(fragmentationOffset);
62 
63   // Write the payload header to the outgoing packet:
64   setSpecialHeaderBytes(payloadHeader, sizeof payloadHeader);
65 
66   if (numRemainingBytes == 0) {
67     // This packet contains the last (or only) fragment of the frame.
68     // Set the RTP 'M' ('marker') bit
69     setMarkerBit();
70   }
71 
72   // Also set the RTP timestamp:
73   setTimestamp(framePresentationTime);
74 }
75 
specialHeaderSize() const76 unsigned JPEG2000VideoRTPSink::specialHeaderSize() const {
77   return JPEG2000_PAYLOAD_HEADER_SIZE;
78 }
79