SegmentQueue Class Reference

Collaboration diagram for SegmentQueue:

Collaboration graph
[legend]

Public Member Functions

 SegmentQueue (Boolean directionIsToADU, Boolean includeADUdescriptors)
unsigned headIndex ()
SegmentheadSegment ()
unsigned nextFreeIndex ()
SegmentnextFreeSegment ()
Boolean isEmpty ()
Boolean isFull ()
unsigned totalDataSize ()
void enqueueNewSegment (FramedSource *inputSource, FramedSource *usingSource)
Boolean dequeue ()
Boolean insertDummyBeforeTail (unsigned backpointer)
void reset ()

Static Public Member Functions

static unsigned nextIndex (unsigned ix)
static unsigned prevIndex (unsigned ix)

Data Fields

Segment s [SegmentQueueSize]

Private Member Functions

Boolean sqAfterGettingCommon (Segment &seg, unsigned numBytesRead)
Boolean isEmptyOrFull ()

Static Private Member Functions

static void sqAfterGettingSegment (void *clientData, unsigned numBytesRead, unsigned numTruncatedBytes, struct timeval presentationTime, unsigned durationInMicroseconds)

Private Attributes

unsigned fHeadIndex
unsigned fNextFreeIndex
unsigned fTotalDataSize
FramedSourcefUsingSource
Boolean fDirectionIsToADU
Boolean fIncludeADUdescriptors

Detailed Description

Definition at line 54 of file MP3ADU.cpp.


Constructor & Destructor Documentation

SegmentQueue::SegmentQueue ( Boolean  directionIsToADU,
Boolean  includeADUdescriptors 
) [inline]

Definition at line 56 of file MP3ADU.cpp.

References reset().

00057     : fDirectionIsToADU(directionIsToADU),
00058       fIncludeADUdescriptors(includeADUdescriptors) {
00059     reset();
00060   }


Member Function Documentation

unsigned SegmentQueue::headIndex (  )  [inline]

Definition at line 64 of file MP3ADU.cpp.

References fHeadIndex.

Referenced by dequeue(), ADUFromMP3Source::doGetNextFrame1(), MP3FromADUSource::generateFrameFromHeadADU(), MP3FromADUSource::insertDummyADUsIfNecessary(), isEmptyOrFull(), and MP3FromADUSource::needToGetAnADU().

00064 {return fHeadIndex;}

Segment& SegmentQueue::headSegment (  )  [inline]

Definition at line 65 of file MP3ADU.cpp.

References fHeadIndex, and s.

Referenced by MP3FromADUSource::generateFrameFromHeadADU(), and MP3FromADUSource::needToGetAnADU().

00065 {return s[fHeadIndex];}

unsigned SegmentQueue::nextFreeIndex (  )  [inline]

Definition at line 67 of file MP3ADU.cpp.

References fNextFreeIndex.

Referenced by ADUFromMP3Source::doGetNextFrame1(), MP3FromADUSource::generateFrameFromHeadADU(), MP3FromADUSource::insertDummyADUsIfNecessary(), insertDummyBeforeTail(), isEmptyOrFull(), and MP3FromADUSource::needToGetAnADU().

00067 {return fNextFreeIndex;}

Segment& SegmentQueue::nextFreeSegment (  )  [inline]

Definition at line 68 of file MP3ADU.cpp.

References fNextFreeIndex, and s.

Referenced by enqueueNewSegment(), and sqAfterGettingSegment().

00068 {return s[fNextFreeIndex];}

Boolean SegmentQueue::isEmpty (  )  [inline]

Definition at line 69 of file MP3ADU.cpp.

References isEmptyOrFull(), and totalDataSize().

Referenced by dequeue(), ADUFromMP3Source::doGetNextFrame1(), MP3FromADUSource::generateFrameFromHeadADU(), MP3FromADUSource::insertDummyADUsIfNecessary(), and MP3FromADUSource::needToGetAnADU().

00069 {return isEmptyOrFull() && totalDataSize() == 0;}

Boolean SegmentQueue::isFull (  )  [inline]

Definition at line 70 of file MP3ADU.cpp.

References isEmptyOrFull(), and totalDataSize().

Referenced by enqueueNewSegment().

00070 {return isEmptyOrFull() && totalDataSize() > 0;}

static unsigned SegmentQueue::nextIndex ( unsigned  ix  )  [inline, static]

Definition at line 72 of file MP3ADU.cpp.

References SegmentQueueSize.

Referenced by dequeue(), ADUFromMP3Source::doGetNextFrame1(), MP3FromADUSource::generateFrameFromHeadADU(), MP3FromADUSource::needToGetAnADU(), and sqAfterGettingCommon().

00072 {return (ix+1)%SegmentQueueSize;}

static unsigned SegmentQueue::prevIndex ( unsigned  ix  )  [inline, static]

Definition at line 73 of file MP3ADU.cpp.

References SegmentQueueSize.

Referenced by ADUFromMP3Source::doGetNextFrame1(), MP3FromADUSource::insertDummyADUsIfNecessary(), and insertDummyBeforeTail().

00073 {return (ix+SegmentQueueSize-1)%SegmentQueueSize;}

unsigned SegmentQueue::totalDataSize (  )  [inline]

Definition at line 75 of file MP3ADU.cpp.

References fTotalDataSize.

Referenced by ADUFromMP3Source::doGetNextFrame(), isEmpty(), and isFull().

00075 {return fTotalDataSize;}

void SegmentQueue::enqueueNewSegment ( FramedSource inputSource,
FramedSource usingSource 
)

Definition at line 512 of file MP3ADU.cpp.

References Segment::buf, Medium::envir(), fUsingSource, FramedSource::getNextFrame(), FramedSource::handleClosure(), isFull(), nextFreeSegment(), and sqAfterGettingSegment().

Referenced by MP3FromADUSource::doGetNextFrame(), and ADUFromMP3Source::doGetNextFrame().

00513                                                                 {
00514   if (isFull()) {
00515     usingSource->envir() << "SegmentQueue::enqueueNewSegment() overflow\n";
00516     FramedSource::handleClosure(usingSource);
00517     return;
00518   }
00519 
00520   fUsingSource = usingSource;
00521 
00522   Segment& seg = nextFreeSegment();
00523   inputSource->getNextFrame(seg.buf, sizeof seg.buf,
00524                             sqAfterGettingSegment, this,
00525                             FramedSource::handleClosure, usingSource);
00526 }

Boolean SegmentQueue::dequeue (  ) 

Definition at line 588 of file MP3ADU.cpp.

References Segment::dataHere(), Medium::envir(), False, fHeadIndex, fTotalDataSize, fUsingSource, headIndex(), isEmpty(), nextIndex(), s, and True.

Referenced by ADUFromMP3Source::doGetNextFrame1(), and MP3FromADUSource::generateFrameFromHeadADU().

00588                               {
00589   if (isEmpty()) {
00590     fUsingSource->envir() << "SegmentQueue::dequeue(): underflow!\n";
00591     return False;
00592   }
00593 
00594   Segment& seg = s[headIndex()];
00595   fTotalDataSize -= seg.dataHere();
00596   fHeadIndex = nextIndex(fHeadIndex);
00597   return True;
00598 }

Boolean SegmentQueue::insertDummyBeforeTail ( unsigned  backpointer  ) 

Definition at line 600 of file MP3ADU.cpp.

References Segment::buf, Segment::descriptorSize, False, fIncludeADUdescriptors, Segment::frameSize, ADUdescriptor::generateDescriptor(), ADUdescriptor::generateTwoByteDescriptor(), Segment::headerSize, isEmptyOrFull(), nextFreeIndex(), prevIndex(), s, Segment::sideInfoSize, sqAfterGettingCommon(), and ZeroOutMP3SideInfo().

Referenced by MP3FromADUSource::insertDummyADUsIfNecessary().

00600                                                                 {
00601   if (isEmptyOrFull()) return False;
00602 
00603   // Copy the current tail segment to its new position, then modify the
00604   // old tail segment to be a 'dummy' ADU
00605 
00606   unsigned newTailIndex = nextFreeIndex();
00607   Segment& newTailSeg = s[newTailIndex];
00608 
00609   unsigned oldTailIndex = prevIndex(newTailIndex);
00610   Segment& oldTailSeg = s[oldTailIndex];
00611 
00612   newTailSeg = oldTailSeg; // structure copy
00613 
00614   // Begin by setting (replacing) the ADU descriptor of the dummy ADU:
00615   unsigned char* ptr = oldTailSeg.buf;
00616   if (fIncludeADUdescriptors) {
00617     unsigned remainingFrameSize
00618       = oldTailSeg.headerSize + oldTailSeg.sideInfoSize + 0 /* 0-size ADU */;
00619     unsigned currentDescriptorSize = oldTailSeg.descriptorSize;
00620 
00621     if (currentDescriptorSize == 2) {
00622       ADUdescriptor::generateTwoByteDescriptor(ptr, remainingFrameSize);
00623     } else {
00624       (void)ADUdescriptor::generateDescriptor(ptr, remainingFrameSize);
00625     }
00626   }
00627 
00628   // Then zero out the side info of the dummy frame:
00629   if (!ZeroOutMP3SideInfo(ptr, oldTailSeg.frameSize,
00630                           backpointer)) return False;
00631 
00632   unsigned dummyNumBytesRead
00633     = oldTailSeg.descriptorSize + 4/*header size*/ + oldTailSeg.sideInfoSize;
00634   return sqAfterGettingCommon(oldTailSeg, dummyNumBytesRead);
00635 }

void SegmentQueue::reset (  )  [inline]

Definition at line 83 of file MP3ADU.cpp.

References fHeadIndex, fNextFreeIndex, and fTotalDataSize.

Referenced by ADUFromMP3Source::resetInput(), and SegmentQueue().

void SegmentQueue::sqAfterGettingSegment ( void *  clientData,
unsigned  numBytesRead,
unsigned  numTruncatedBytes,
struct timeval  presentationTime,
unsigned  durationInMicroseconds 
) [static, private]

Definition at line 528 of file MP3ADU.cpp.

References Segment::aduSize, Segment::backpointer, Segment::dataHere(), Segment::descriptorSize, FramedSource::doGetNextFrame(), Segment::durationInMicroseconds, fDirectionIsToADU, Segment::frameSize, fUsingSource, nextFreeSegment(), Segment::presentationTime, Segment::sideInfoSize, and sqAfterGettingCommon().

Referenced by enqueueNewSegment().

00532                                                                           {
00533   SegmentQueue* segQueue = (SegmentQueue*)clientData;
00534   Segment& seg = segQueue->nextFreeSegment();
00535 
00536   seg.presentationTime = presentationTime;
00537   seg.durationInMicroseconds = durationInMicroseconds;
00538 
00539   if (segQueue->sqAfterGettingCommon(seg, numBytesRead)) {
00540 #ifdef DEBUG
00541     char const* direction = segQueue->fDirectionIsToADU ? "m->a" : "a->m";
00542     fprintf(stderr, "%s:read frame %d<-%d, fs:%d, sis:%d, dh:%d, (descriptor size: %d)\n", direction, seg.aduSize, seg.backpointer, seg.frameSize, seg.sideInfoSize, seg.dataHere(), seg.descriptorSize);
00543 #endif
00544   }
00545 
00546   // Continue our original calling source where it left off:
00547   segQueue->fUsingSource->doGetNextFrame();
00548 }

Boolean SegmentQueue::sqAfterGettingCommon ( Segment seg,
unsigned  numBytesRead 
) [private]

Definition at line 551 of file MP3ADU.cpp.

References Segment::aduSize, Segment::backpointer, Segment::buf, Segment::dataHere(), Segment::descriptorSize, False, fDirectionIsToADU, fIncludeADUdescriptors, fNextFreeIndex, Segment::frameSize, fTotalDataSize, GetADUInfoFromMP3Frame(), ADUdescriptor::getRemainingFrameSize(), nextIndex(), Segment::sideInfoSize, and True.

Referenced by insertDummyBeforeTail(), and sqAfterGettingSegment().

00552                                                                   {
00553   unsigned char* fromPtr = seg.buf;
00554 
00555   if (fIncludeADUdescriptors) {
00556     // The newly-read data is assumed to be an ADU with a descriptor
00557     // in front
00558     (void)ADUdescriptor::getRemainingFrameSize(fromPtr);
00559     seg.descriptorSize = (unsigned)(fromPtr-seg.buf);
00560   } else {
00561     seg.descriptorSize = 0;
00562   }
00563 
00564   // parse the MP3-specific info in the frame to get the ADU params
00565   unsigned hdr;
00566   MP3SideInfo sideInfo;
00567   if (!GetADUInfoFromMP3Frame(fromPtr, numBytesRead,
00568                               hdr, seg.frameSize,
00569                               sideInfo, seg.sideInfoSize,
00570                               seg.backpointer, seg.aduSize)) {
00571     return False;
00572   }
00573 
00574   // If we've just read an ADU (rather than a regular MP3 frame), then use the
00575   // entire "numBytesRead" data for the 'aduSize', so that we include any
00576   // 'ancillary data' that may be present at the end of the ADU:
00577   if (!fDirectionIsToADU) {
00578     unsigned newADUSize
00579       = numBytesRead - seg.descriptorSize - 4/*header size*/ - seg.sideInfoSize;
00580     if (newADUSize > seg.aduSize) seg.aduSize = newADUSize;
00581   }
00582   fTotalDataSize += seg.dataHere();
00583   fNextFreeIndex = nextIndex(fNextFreeIndex);
00584 
00585   return True;
00586 }

Boolean SegmentQueue::isEmptyOrFull (  )  [inline, private]

Definition at line 93 of file MP3ADU.cpp.

References headIndex(), and nextFreeIndex().

Referenced by insertDummyBeforeTail(), isEmpty(), and isFull().

00093 {return headIndex() == nextFreeIndex();}


Field Documentation

Segment SegmentQueue::s[SegmentQueueSize]

Definition at line 62 of file MP3ADU.cpp.

Referenced by dequeue(), ADUFromMP3Source::doGetNextFrame1(), MP3FromADUSource::generateFrameFromHeadADU(), headSegment(), MP3FromADUSource::insertDummyADUsIfNecessary(), insertDummyBeforeTail(), MP3FromADUSource::needToGetAnADU(), and nextFreeSegment().

unsigned SegmentQueue::fHeadIndex [private]

Definition at line 95 of file MP3ADU.cpp.

Referenced by dequeue(), headIndex(), headSegment(), and reset().

unsigned SegmentQueue::fNextFreeIndex [private]

Definition at line 95 of file MP3ADU.cpp.

Referenced by nextFreeIndex(), nextFreeSegment(), reset(), and sqAfterGettingCommon().

unsigned SegmentQueue::fTotalDataSize [private]

Definition at line 95 of file MP3ADU.cpp.

Referenced by dequeue(), reset(), sqAfterGettingCommon(), and totalDataSize().

FramedSource* SegmentQueue::fUsingSource [private]

Definition at line 98 of file MP3ADU.cpp.

Referenced by dequeue(), enqueueNewSegment(), and sqAfterGettingSegment().

Boolean SegmentQueue::fDirectionIsToADU [private]

Definition at line 102 of file MP3ADU.cpp.

Referenced by sqAfterGettingCommon(), and sqAfterGettingSegment().

Boolean SegmentQueue::fIncludeADUdescriptors [private]

Definition at line 106 of file MP3ADU.cpp.

Referenced by insertDummyBeforeTail(), and sqAfterGettingCommon().


The documentation for this class was generated from the following file:
Generated on Thu May 17 07:16:18 2012 for live by  doxygen 1.5.2