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 source for 'ADUized' MP3 frames ("mpa-robust")
19// Implementation
20
21#include "MP3ADURTPSource.hh"
22#include "MP3ADUdescriptor.hh"
23
24////////// ADUBufferedPacket and ADUBufferedPacketFactory //////////
25
26class ADUBufferedPacket: public BufferedPacket {
27private: // redefined virtual functions
28 virtual unsigned nextEnclosedFrameSize(unsigned char*& framePtr,
29 unsigned dataSize);
30};
31
32class ADUBufferedPacketFactory: public BufferedPacketFactory {
33private: // redefined virtual functions
34 virtual BufferedPacket* createNewPacket(MultiFramedRTPSource* ourSource);
35};
36
37///////// MP3ADURTPSource implementation ////////
38
39MP3ADURTPSource*
40MP3ADURTPSource::createNew(UsageEnvironment& env, Groupsock* RTPgs,
41 unsigned char rtpPayloadFormat,
42 unsigned rtpTimestampFrequency) {
43 return new MP3ADURTPSource(env, RTPgs, rtpPayloadFormat,
44 rtpTimestampFrequency);
45}
46
47MP3ADURTPSource::MP3ADURTPSource(UsageEnvironment& env, Groupsock* RTPgs,
48 unsigned char rtpPayloadFormat,
49 unsigned rtpTimestampFrequency)
50 : MultiFramedRTPSource(env, RTPgs,
51 rtpPayloadFormat, rtpTimestampFrequency,
52 new ADUBufferedPacketFactory) {
53}
54
55MP3ADURTPSource::~MP3ADURTPSource() {
56}
57
58char const* MP3ADURTPSource::MIMEtype() const {
59 return "audio/MPA-ROBUST";
60}
61
62////////// ADUBufferedPacket and ADUBufferredPacketFactory implementation
63
64unsigned ADUBufferedPacket
65::nextEnclosedFrameSize(unsigned char*& framePtr, unsigned dataSize) {
66 // Return the size of the next MP3 'ADU', on the assumption that
67 // the input data is ADU-encoded MP3 frames.
68 unsigned char* frameDataPtr = framePtr;
69 unsigned remainingFrameSize
70 = ADUdescriptor::getRemainingFrameSize(frameDataPtr);
71 unsigned descriptorSize = (unsigned)(frameDataPtr - framePtr);
72 unsigned fullADUSize = descriptorSize + remainingFrameSize;
73
74 return (fullADUSize <= dataSize) ? fullADUSize : dataSize;
75}
76
77BufferedPacket* ADUBufferedPacketFactory
78::createNewPacket(MultiFramedRTPSource* /*ourSource*/) {
79 return new ADUBufferedPacket;
80}
81