| 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 sink for MPEG audio (RFC 2250) | 
|---|
| 19 | // Implementation | 
|---|
| 20 |  | 
|---|
| 21 | #include "MPEG1or2AudioRTPSink.hh" | 
|---|
| 22 |  | 
|---|
| 23 | MPEG1or2AudioRTPSink::MPEG1or2AudioRTPSink(UsageEnvironment& env, Groupsock* RTPgs) | 
|---|
| 24 | : AudioRTPSink(env, RTPgs, 14, 90000, "MPA") { | 
|---|
| 25 | } | 
|---|
| 26 |  | 
|---|
| 27 | MPEG1or2AudioRTPSink::~MPEG1or2AudioRTPSink() { | 
|---|
| 28 | } | 
|---|
| 29 |  | 
|---|
| 30 | MPEG1or2AudioRTPSink* | 
|---|
| 31 | MPEG1or2AudioRTPSink::createNew(UsageEnvironment& env, Groupsock* RTPgs) { | 
|---|
| 32 | return new MPEG1or2AudioRTPSink(env, RTPgs); | 
|---|
| 33 | } | 
|---|
| 34 |  | 
|---|
| 35 | void MPEG1or2AudioRTPSink::doSpecialFrameHandling(unsigned fragmentationOffset, | 
|---|
| 36 | unsigned char* frameStart, | 
|---|
| 37 | unsigned numBytesInFrame, | 
|---|
| 38 | struct timeval framePresentationTime, | 
|---|
| 39 | unsigned numRemainingBytes) { | 
|---|
| 40 | // If this is the 1st frame in the 1st packet, set the RTP 'M' (marker) | 
|---|
| 41 | // bit (because this is considered the start of a talk spurt): | 
|---|
| 42 | if (isFirstPacket() && isFirstFrameInPacket()) { | 
|---|
| 43 | setMarkerBit(); | 
|---|
| 44 | } | 
|---|
| 45 |  | 
|---|
| 46 | // If this is the first frame in the packet, set the lower half of the | 
|---|
| 47 | // audio-specific header (to the "fragmentationOffset"): | 
|---|
| 48 | if (isFirstFrameInPacket()) { | 
|---|
| 49 | setSpecialHeaderWord(fragmentationOffset&0xFFFF); | 
|---|
| 50 | } | 
|---|
| 51 |  | 
|---|
| 52 | // Important: Also call our base class's doSpecialFrameHandling(), | 
|---|
| 53 | // to set the packet's timestamp: | 
|---|
| 54 | MultiFramedRTPSink::doSpecialFrameHandling(fragmentationOffset, | 
|---|
| 55 | frameStart, numBytesInFrame, | 
|---|
| 56 | framePresentationTime, | 
|---|
| 57 | numRemainingBytes); | 
|---|
| 58 | } | 
|---|
| 59 |  | 
|---|
| 60 | unsigned MPEG1or2AudioRTPSink::() const { | 
|---|
| 61 | // There's a 4 byte special audio header: | 
|---|
| 62 | return 4; | 
|---|
| 63 | } | 
|---|
| 64 |  | 
|---|