OutPacketBuffer Class Reference

#include <MediaSink.hh>


Public Member Functions

 OutPacketBuffer (unsigned preferredPacketSize, unsigned maxPacketSize)
 ~OutPacketBuffer ()
unsigned char * curPtr () const
unsigned totalBytesAvailable () const
unsigned totalBufferSize () const
unsigned char * packet () const
unsigned curPacketSize () const
void increment (unsigned numBytes)
void enqueue (unsigned char const *from, unsigned numBytes)
void enqueueWord (u_int32_t word)
void insert (unsigned char const *from, unsigned numBytes, unsigned toPosition)
void insertWord (u_int32_t word, unsigned toPosition)
void extract (unsigned char *to, unsigned numBytes, unsigned fromPosition)
u_int32_t extractWord (unsigned fromPosition)
void skipBytes (unsigned numBytes)
Boolean isPreferredSize () const
Boolean wouldOverflow (unsigned numBytes) const
unsigned numOverflowBytes (unsigned numBytes) const
Boolean isTooBigForAPacket (unsigned numBytes) const
void setOverflowData (unsigned overflowDataOffset, unsigned overflowDataSize, struct timeval const &presentationTime, unsigned durationInMicroseconds)
unsigned overflowDataSize () const
timeval overflowPresentationTime () const
unsigned overflowDurationInMicroseconds () const
Boolean haveOverflowData () const
void useOverflowData ()
void adjustPacketStart (unsigned numBytes)
void resetPacketStart ()
void resetOffset ()
void resetOverflowData ()

Static Public Attributes

static unsigned maxSize = 60000

Private Attributes

unsigned fPacketStart
unsigned fCurOffset
unsigned fPreferred
unsigned fMax
unsigned fLimit
unsigned char * fBuf
unsigned fOverflowDataOffset
unsigned fOverflowDataSize
timeval fOverflowPresentationTime
unsigned fOverflowDurationInMicroseconds


Detailed Description

Definition at line 70 of file MediaSink.hh.


Constructor & Destructor Documentation

OutPacketBuffer::OutPacketBuffer ( unsigned  preferredPacketSize,
unsigned  maxPacketSize 
)

Definition at line 109 of file MediaSink.cpp.

References fBuf, fLimit, maxSize, resetOffset(), resetOverflowData(), and resetPacketStart().

00111   : fPreferred(preferredPacketSize), fMax(maxPacketSize),
00112     fOverflowDataSize(0) {
00113   unsigned maxNumPackets = (maxSize + (maxPacketSize-1))/maxPacketSize;
00114   fLimit = maxNumPackets*maxPacketSize;
00115   fBuf = new unsigned char[fLimit];
00116   resetPacketStart();
00117   resetOffset();
00118   resetOverflowData();
00119 }

OutPacketBuffer::~OutPacketBuffer (  ) 

Definition at line 121 of file MediaSink.cpp.

References fBuf.

00121                                   {
00122   delete[] fBuf;
00123 }


Member Function Documentation

unsigned char* OutPacketBuffer::curPtr (  )  const [inline]

Definition at line 77 of file MediaSink.hh.

References fBuf, fCurOffset, and fPacketStart.

Referenced by MultiFramedRTPSink::afterGettingFrame1(), enqueue(), and MultiFramedRTPSink::packFrame().

00077 {return &fBuf[fPacketStart + fCurOffset];}

unsigned OutPacketBuffer::totalBytesAvailable (  )  const [inline]

Definition at line 78 of file MediaSink.hh.

References fCurOffset, fLimit, and fPacketStart.

Referenced by MultiFramedRTPSink::afterGettingFrame1(), enqueue(), MultiFramedRTPSink::packFrame(), MultiFramedRTPSink::sendPacketIfNecessary(), and skipBytes().

00078                                        {
00079     return fLimit - (fPacketStart + fCurOffset);
00080   }

unsigned OutPacketBuffer::totalBufferSize (  )  const [inline]

Definition at line 81 of file MediaSink.hh.

References fLimit.

Referenced by MultiFramedRTPSink::sendPacketIfNecessary().

00081 { return fLimit; }

unsigned char* OutPacketBuffer::packet (  )  const [inline]

Definition at line 82 of file MediaSink.hh.

References fBuf, and fPacketStart.

Referenced by RTCPInstance::sendBuiltPacket(), and MultiFramedRTPSink::sendPacketIfNecessary().

00082 {return &fBuf[fPacketStart];}

unsigned OutPacketBuffer::curPacketSize (  )  const [inline]

Definition at line 83 of file MediaSink.hh.

References fCurOffset.

Referenced by RTCPInstance::addSDES(), MultiFramedRTPSink::afterGettingFrame1(), MultiFramedRTPSink::buildAndSendPacket(), MultiFramedRTPSink::packFrame(), RTCPInstance::sendBuiltPacket(), and MultiFramedRTPSink::sendPacketIfNecessary().

00083 {return fCurOffset;}

void OutPacketBuffer::increment ( unsigned  numBytes  )  [inline]

Definition at line 85 of file MediaSink.hh.

References fCurOffset.

Referenced by MultiFramedRTPSink::afterGettingFrame1(), enqueue(), and skipBytes().

00085 {fCurOffset += numBytes;}

void OutPacketBuffer::enqueue ( unsigned char const *  from,
unsigned  numBytes 
)

Definition at line 125 of file MediaSink.cpp.

References curPtr(), increment(), and totalBytesAvailable().

Referenced by RTCPInstance::addSDES(), enqueueWord(), MultiFramedRTPSink::setFramePadding(), and useOverflowData().

00125                                                                           {
00126   if (numBytes > totalBytesAvailable()) {
00127 #ifdef DEBUG
00128     fprintf(stderr, "OutPacketBuffer::enqueue() warning: %d > %d\n", numBytes, totalBytesAvailable());
00129 #endif
00130     numBytes = totalBytesAvailable();
00131   }
00132 
00133   if (curPtr() != from) memmove(curPtr(), from, numBytes);
00134   increment(numBytes);
00135 }

void OutPacketBuffer::enqueueWord ( u_int32_t  word  ) 

Definition at line 137 of file MediaSink.cpp.

References enqueue().

Referenced by RTCPInstance::addBYE(), RTCPInstance::addSDES(), RTCPInstance::addSR(), MultiFramedRTPSink::buildAndSendPacket(), and RTCPInstance::enqueueReportBlock().

00137                                                 {
00138   u_int32_t nWord = htonl(word);
00139   enqueue((unsigned char*)&nWord, 4);
00140 }

void OutPacketBuffer::insert ( unsigned char const *  from,
unsigned  numBytes,
unsigned  toPosition 
)

Definition at line 142 of file MediaSink.cpp.

References fBuf, fCurOffset, fLimit, and fPacketStart.

Referenced by insertWord(), MultiFramedRTPSink::setFrameSpecificHeaderBytes(), and MultiFramedRTPSink::setSpecialHeaderBytes().

00143                                                   {
00144   unsigned realToPosition = fPacketStart + toPosition;
00145   if (realToPosition + numBytes > fLimit) {
00146     if (realToPosition > fLimit) return; // we can't do this
00147     numBytes = fLimit - realToPosition;
00148   }
00149 
00150   memmove(&fBuf[realToPosition], from, numBytes);
00151   if (toPosition + numBytes > fCurOffset) {
00152     fCurOffset = toPosition + numBytes;
00153   }
00154 }

void OutPacketBuffer::insertWord ( u_int32_t  word,
unsigned  toPosition 
)

Definition at line 156 of file MediaSink.cpp.

References insert().

Referenced by MultiFramedRTPSink::setFramePadding(), MultiFramedRTPSink::setFrameSpecificHeaderWord(), MultiFramedRTPSink::setMarkerBit(), MultiFramedRTPSink::setSpecialHeaderWord(), and MultiFramedRTPSink::setTimestamp().

00156                                                                     {
00157   u_int32_t nWord = htonl(word);
00158   insert((unsigned char*)&nWord, 4, toPosition);
00159 }

void OutPacketBuffer::extract ( unsigned char *  to,
unsigned  numBytes,
unsigned  fromPosition 
)

Definition at line 161 of file MediaSink.cpp.

References fBuf, fLimit, and fPacketStart.

Referenced by extractWord().

00162                                                      {
00163   unsigned realFromPosition = fPacketStart + fromPosition;
00164   if (realFromPosition + numBytes > fLimit) { // sanity check
00165     if (realFromPosition > fLimit) return; // we can't do this
00166     numBytes = fLimit - realFromPosition;
00167   }
00168 
00169   memmove(to, &fBuf[realFromPosition], numBytes);
00170 }

u_int32_t OutPacketBuffer::extractWord ( unsigned  fromPosition  ) 

Definition at line 172 of file MediaSink.cpp.

References extract().

Referenced by MultiFramedRTPSink::setFramePadding(), and MultiFramedRTPSink::setMarkerBit().

00172                                                             {
00173   u_int32_t nWord;
00174   extract((unsigned char*)&nWord, 4, fromPosition);
00175   return ntohl(nWord);
00176 }

void OutPacketBuffer::skipBytes ( unsigned  numBytes  ) 

Definition at line 178 of file MediaSink.cpp.

References increment(), and totalBytesAvailable().

Referenced by MultiFramedRTPSink::buildAndSendPacket(), and MultiFramedRTPSink::packFrame().

00178                                                  {
00179   if (numBytes > totalBytesAvailable()) {
00180     numBytes = totalBytesAvailable();
00181   }
00182 
00183   increment(numBytes);
00184 }

Boolean OutPacketBuffer::isPreferredSize (  )  const [inline]

Definition at line 96 of file MediaSink.hh.

References fCurOffset, and fPreferred.

Referenced by MultiFramedRTPSink::afterGettingFrame1().

00096 {return fCurOffset >= fPreferred;}

Boolean OutPacketBuffer::wouldOverflow ( unsigned  numBytes  )  const [inline]

Definition at line 97 of file MediaSink.hh.

References fCurOffset, and fMax.

Referenced by MultiFramedRTPSink::afterGettingFrame1().

00097                                                  {
00098     return (fCurOffset+numBytes) > fMax;
00099   }

unsigned OutPacketBuffer::numOverflowBytes ( unsigned  numBytes  )  const [inline]

Definition at line 100 of file MediaSink.hh.

References fCurOffset, and fMax.

Referenced by MultiFramedRTPSink::computeOverflowForNewFrame().

00100                                                      {
00101     return (fCurOffset+numBytes) - fMax;
00102   }

Boolean OutPacketBuffer::isTooBigForAPacket ( unsigned  numBytes  )  const [inline]

Definition at line 103 of file MediaSink.hh.

References fMax.

Referenced by MultiFramedRTPSink::isTooBigForAPacket().

00103                                                       {
00104     return numBytes > fMax;
00105   }

void OutPacketBuffer::setOverflowData ( unsigned  overflowDataOffset,
unsigned  overflowDataSize,
struct timeval const &  presentationTime,
unsigned  durationInMicroseconds 
)

Definition at line 187 of file MediaSink.cpp.

References fOverflowDataOffset, fOverflowDataSize, fOverflowDurationInMicroseconds, and fOverflowPresentationTime.

Referenced by MultiFramedRTPSink::afterGettingFrame1().

00190                                                    {
00191   fOverflowDataOffset = overflowDataOffset;
00192   fOverflowDataSize = overflowDataSize;
00193   fOverflowPresentationTime = presentationTime;
00194   fOverflowDurationInMicroseconds = durationInMicroseconds;
00195 }

unsigned OutPacketBuffer::overflowDataSize (  )  const [inline]

Definition at line 111 of file MediaSink.hh.

References fOverflowDataSize.

Referenced by MultiFramedRTPSink::packFrame().

00111 {return fOverflowDataSize;}

struct timeval OutPacketBuffer::overflowPresentationTime (  )  const [inline, read]

Definition at line 112 of file MediaSink.hh.

References fOverflowPresentationTime.

Referenced by MultiFramedRTPSink::packFrame().

00112 {return fOverflowPresentationTime;}

unsigned OutPacketBuffer::overflowDurationInMicroseconds (  )  const [inline]

Definition at line 113 of file MediaSink.hh.

References fOverflowDurationInMicroseconds.

Referenced by MultiFramedRTPSink::packFrame().

Boolean OutPacketBuffer::haveOverflowData (  )  const [inline]

Definition at line 114 of file MediaSink.hh.

References fOverflowDataSize.

Referenced by MultiFramedRTPSink::packFrame(), and MultiFramedRTPSink::sendPacketIfNecessary().

00114 {return fOverflowDataSize > 0;}

void OutPacketBuffer::useOverflowData (  ) 

Definition at line 197 of file MediaSink.cpp.

References enqueue(), fBuf, fCurOffset, fOverflowDataOffset, fOverflowDataSize, fPacketStart, and resetOverflowData().

Referenced by MultiFramedRTPSink::packFrame().

00197                                       {
00198   enqueue(&fBuf[fPacketStart + fOverflowDataOffset], fOverflowDataSize);
00199   fCurOffset -= fOverflowDataSize; // undoes increment performed by "enqueue"
00200   resetOverflowData();
00201 }

void OutPacketBuffer::adjustPacketStart ( unsigned  numBytes  ) 

Definition at line 203 of file MediaSink.cpp.

References fOverflowDataOffset, fOverflowDataSize, and fPacketStart.

Referenced by MultiFramedRTPSink::sendPacketIfNecessary().

00203                                                          {
00204   fPacketStart += numBytes;
00205   if (fOverflowDataOffset >= numBytes) {
00206     fOverflowDataOffset -= numBytes;
00207   } else {
00208     fOverflowDataOffset = 0;
00209     fOverflowDataSize = 0; // an error otherwise
00210   }
00211 }

void OutPacketBuffer::resetPacketStart (  ) 

Definition at line 213 of file MediaSink.cpp.

References fOverflowDataOffset, fOverflowDataSize, and fPacketStart.

Referenced by OutPacketBuffer(), MultiFramedRTPSink::sendPacketIfNecessary(), and MultiFramedRTPSink::stopPlaying().

00213                                        {
00214   if (fOverflowDataSize > 0) {
00215     fOverflowDataOffset += fPacketStart;
00216   }
00217   fPacketStart = 0;
00218 }

void OutPacketBuffer::resetOffset (  )  [inline]

Definition at line 119 of file MediaSink.hh.

References fCurOffset.

Referenced by OutPacketBuffer(), RTCPInstance::sendBuiltPacket(), MultiFramedRTPSink::sendPacketIfNecessary(), and MultiFramedRTPSink::stopPlaying().

00119 { fCurOffset = 0; }

void OutPacketBuffer::resetOverflowData (  )  [inline]

Definition at line 120 of file MediaSink.hh.

References fOverflowDataOffset, and fOverflowDataSize.

Referenced by OutPacketBuffer(), MultiFramedRTPSink::stopPlaying(), and useOverflowData().


Field Documentation

unsigned OutPacketBuffer::maxSize = 60000 [static]

Definition at line 75 of file MediaSink.hh.

Referenced by MultiFramedRTPSink::afterGettingFrame1(), H264VideoRTPSink::continuePlaying(), createNewSMS(), H264VideoMatroskaFileServerMediaSubsession::createNewStreamSource(), main(), OutPacketBuffer(), and RTCPInstance::RTCPInstance().

unsigned OutPacketBuffer::fPacketStart [private]

Definition at line 123 of file MediaSink.hh.

Referenced by adjustPacketStart(), curPtr(), extract(), insert(), packet(), resetPacketStart(), totalBytesAvailable(), and useOverflowData().

unsigned OutPacketBuffer::fCurOffset [private]

Definition at line 123 of file MediaSink.hh.

Referenced by curPacketSize(), curPtr(), increment(), insert(), isPreferredSize(), numOverflowBytes(), resetOffset(), totalBytesAvailable(), useOverflowData(), and wouldOverflow().

unsigned OutPacketBuffer::fPreferred [private]

Definition at line 123 of file MediaSink.hh.

Referenced by isPreferredSize().

unsigned OutPacketBuffer::fMax [private]

Definition at line 123 of file MediaSink.hh.

Referenced by isTooBigForAPacket(), numOverflowBytes(), and wouldOverflow().

unsigned OutPacketBuffer::fLimit [private]

Definition at line 123 of file MediaSink.hh.

Referenced by extract(), insert(), OutPacketBuffer(), totalBufferSize(), and totalBytesAvailable().

unsigned char* OutPacketBuffer::fBuf [private]

Definition at line 124 of file MediaSink.hh.

Referenced by curPtr(), extract(), insert(), OutPacketBuffer(), packet(), useOverflowData(), and ~OutPacketBuffer().

unsigned OutPacketBuffer::fOverflowDataOffset [private]

Definition at line 126 of file MediaSink.hh.

Referenced by adjustPacketStart(), resetOverflowData(), resetPacketStart(), setOverflowData(), and useOverflowData().

unsigned OutPacketBuffer::fOverflowDataSize [private]

Definition at line 126 of file MediaSink.hh.

Referenced by adjustPacketStart(), haveOverflowData(), overflowDataSize(), resetOverflowData(), resetPacketStart(), setOverflowData(), and useOverflowData().

struct timeval OutPacketBuffer::fOverflowPresentationTime [read, private]

Definition at line 127 of file MediaSink.hh.

Referenced by overflowPresentationTime(), and setOverflowData().

unsigned OutPacketBuffer::fOverflowDurationInMicroseconds [private]

Definition at line 128 of file MediaSink.hh.

Referenced by overflowDurationInMicroseconds(), and setOverflowData().


The documentation for this class was generated from the following files:
Generated on Thu Feb 2 23:55:42 2012 for live by  doxygen 1.5.2