liveMedia/VorbisAudioRTPSource.cpp

Go to the documentation of this file.
00001 /**********
00002 This library is free software; you can redistribute it and/or modify it under
00003 the terms of the GNU Lesser General Public License as published by the
00004 Free Software Foundation; either version 2.1 of the License, or (at your
00005 option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
00006 
00007 This library is distributed in the hope that it will be useful, but WITHOUT
00008 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00009 FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
00010 more details.
00011 
00012 You should have received a copy of the GNU Lesser General Public License
00013 along with this library; if not, write to the Free Software Foundation, Inc.,
00014 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
00015 **********/
00016 // "liveMedia"
00017 // Copyright (c) 1996-2013 Live Networks, Inc.  All rights reserved.
00018 // Vorbis Audio RTP Sources
00019 // Implementation
00020 
00021 #include "VorbisAudioRTPSource.hh"
00022 
00024 
00025 class VorbisBufferedPacket: public BufferedPacket {
00026 public:
00027   VorbisBufferedPacket();
00028   virtual ~VorbisBufferedPacket();
00029 
00030 private: // redefined virtual functions
00031   virtual unsigned nextEnclosedFrameSize(unsigned char*& framePtr,
00032                                          unsigned dataSize);
00033 };
00034 
00035 class VorbisBufferedPacketFactory: public BufferedPacketFactory {
00036 private: // redefined virtual functions
00037   virtual BufferedPacket* createNewPacket(MultiFramedRTPSource* ourSource);
00038 };
00039 
00040 
00042 
00043 VorbisAudioRTPSource*
00044 VorbisAudioRTPSource::createNew(UsageEnvironment& env, Groupsock* RTPgs,
00045                                 unsigned char rtpPayloadFormat,
00046                                 unsigned rtpTimestampFrequency) {
00047   return new VorbisAudioRTPSource(env, RTPgs, rtpPayloadFormat, rtpTimestampFrequency);
00048 }
00049 
00050 VorbisAudioRTPSource
00051 ::VorbisAudioRTPSource(UsageEnvironment& env, Groupsock* RTPgs,
00052                      unsigned char rtpPayloadFormat,
00053                      unsigned rtpTimestampFrequency)
00054   : MultiFramedRTPSource(env, RTPgs, rtpPayloadFormat, rtpTimestampFrequency,
00055                          new VorbisBufferedPacketFactory),
00056     fCurPacketIdent(0) {
00057 }
00058 
00059 VorbisAudioRTPSource::~VorbisAudioRTPSource() {
00060 }
00061 
00062 Boolean VorbisAudioRTPSource
00063 ::processSpecialHeader(BufferedPacket* packet,
00064                        unsigned& resultSpecialHeaderSize) {
00065   unsigned char* headerStart = packet->data();
00066   unsigned packetSize = packet->dataSize();
00067 
00068   resultSpecialHeaderSize = 4;
00069   if (packetSize < resultSpecialHeaderSize) return False; // packet was too small
00070 
00071   // The first 3 bytes of the header are the "Ident" field:
00072   fCurPacketIdent = (headerStart[0]<<16) | (headerStart[1]<<8) | headerStart[2];
00073 
00074   // The 4th byte is F|VDT|numPkts.
00075   // Reject any packet with VDT == 3:
00076   if ((headerStart[3]&0x30) == 0x30) return False;
00077 
00078   u_int8_t F = headerStart[3]>>6;
00079   fCurrentPacketBeginsFrame = F <= 1; // "Not Fragmented" or "Start Fragment"
00080   fCurrentPacketCompletesFrame = F == 0 || F == 3; // "Not Fragmented" or "End Fragment"
00081 
00082   return True;
00083 }
00084 
00085 char const* VorbisAudioRTPSource::MIMEtype() const {
00086   return "audio/VORBIS";
00087 }
00088 
00089 
00091 
00092 VorbisBufferedPacket::VorbisBufferedPacket() {
00093 }
00094 
00095 VorbisBufferedPacket::~VorbisBufferedPacket() {
00096 }
00097 
00098 unsigned VorbisBufferedPacket
00099 ::nextEnclosedFrameSize(unsigned char*& framePtr, unsigned dataSize) {
00100   if (dataSize < 2) {
00101     // There's not enough space for a 2-byte header.  TARFU!  Just return the data that's left:
00102     return dataSize;
00103   }
00104 
00105   unsigned frameSize = (framePtr[0]<<8) | framePtr[1];
00106   framePtr += 2;
00107   if (frameSize > dataSize - 2) return dataSize - 2; // inconsistent frame size => just return all the data that's left
00108 
00109   return frameSize;
00110 }
00111 
00112 BufferedPacket* VorbisBufferedPacketFactory
00113 ::createNewPacket(MultiFramedRTPSource* /*ourSource*/) {
00114   return new VorbisBufferedPacket();
00115 }

Generated on Mon Apr 29 13:28:03 2013 for live by  doxygen 1.5.2