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 108 of file MediaSink.cpp.

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

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

OutPacketBuffer::~OutPacketBuffer (  ) 

Definition at line 120 of file MediaSink.cpp.

References fBuf.

00120                                   {
00121   delete[] fBuf;
00122 }


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 124 of file MediaSink.cpp.

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

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

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

void OutPacketBuffer::enqueueWord ( u_int32_t  word  ) 

Definition at line 136 of file MediaSink.cpp.

References enqueue().

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

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

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

Definition at line 141 of file MediaSink.cpp.

References fBuf, fCurOffset, fLimit, and fPacketStart.

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

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

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

Definition at line 155 of file MediaSink.cpp.

References insert().

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

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

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

Definition at line 160 of file MediaSink.cpp.

References fBuf, fLimit, and fPacketStart.

Referenced by extractWord().

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

u_int32_t OutPacketBuffer::extractWord ( unsigned  fromPosition  ) 

Definition at line 171 of file MediaSink.cpp.

References extract().

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

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

void OutPacketBuffer::skipBytes ( unsigned  numBytes  ) 

Definition at line 177 of file MediaSink.cpp.

References increment(), and totalBytesAvailable().

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

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

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 186 of file MediaSink.cpp.

References fOverflowDataOffset, fOverflowDataSize, fOverflowDurationInMicroseconds, and fOverflowPresentationTime.

Referenced by MultiFramedRTPSink::afterGettingFrame1().

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

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 196 of file MediaSink.cpp.

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

Referenced by MultiFramedRTPSink::packFrame().

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

void OutPacketBuffer::adjustPacketStart ( unsigned  numBytes  ) 

Definition at line 202 of file MediaSink.cpp.

References fOverflowDataOffset, fOverflowDataSize, and fPacketStart.

Referenced by MultiFramedRTPSink::sendPacketIfNecessary().

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

void OutPacketBuffer::resetPacketStart (  ) 

Definition at line 212 of file MediaSink.cpp.

References fOverflowDataOffset, fOverflowDataSize, and fPacketStart.

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

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

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 Mon Apr 29 13:32:14 2013 for live by  doxygen 1.5.2