| 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 | // 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 | |
| 26 | class ADUBufferedPacket: public BufferedPacket { |
| 27 | private: // redefined virtual functions |
| 28 | virtual unsigned nextEnclosedFrameSize(unsigned char*& framePtr, |
| 29 | unsigned dataSize); |
| 30 | }; |
| 31 | |
| 32 | class ADUBufferedPacketFactory: public BufferedPacketFactory { |
| 33 | private: // redefined virtual functions |
| 34 | virtual BufferedPacket* createNewPacket(MultiFramedRTPSource* ourSource); |
| 35 | }; |
| 36 | |
| 37 | ///////// MP3ADURTPSource implementation //////// |
| 38 | |
| 39 | MP3ADURTPSource* |
| 40 | MP3ADURTPSource::createNew(UsageEnvironment& env, Groupsock* RTPgs, |
| 41 | unsigned char rtpPayloadFormat, |
| 42 | unsigned rtpTimestampFrequency) { |
| 43 | return new MP3ADURTPSource(env, RTPgs, rtpPayloadFormat, |
| 44 | rtpTimestampFrequency); |
| 45 | } |
| 46 | |
| 47 | MP3ADURTPSource::MP3ADURTPSource(UsageEnvironment& env, Groupsock* RTPgs, |
| 48 | unsigned char rtpPayloadFormat, |
| 49 | unsigned rtpTimestampFrequency) |
| 50 | : MultiFramedRTPSource(env, RTPgs, |
| 51 | rtpPayloadFormat, rtpTimestampFrequency, |
| 52 | new ADUBufferedPacketFactory) { |
| 53 | } |
| 54 | |
| 55 | MP3ADURTPSource::~MP3ADURTPSource() { |
| 56 | } |
| 57 | |
| 58 | char const* MP3ADURTPSource::MIMEtype() const { |
| 59 | return "audio/MPA-ROBUST" ; |
| 60 | } |
| 61 | |
| 62 | ////////// ADUBufferedPacket and ADUBufferredPacketFactory implementation |
| 63 | |
| 64 | unsigned 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 | |
| 77 | BufferedPacket* ADUBufferedPacketFactory |
| 78 | ::createNewPacket(MultiFramedRTPSource* /*ourSource*/) { |
| 79 | return new ADUBufferedPacket; |
| 80 | } |
| 81 | |