
Public Member Functions | |
| SegmentQueue (Boolean directionIsToADU, Boolean includeADUdescriptors) | |
| unsigned | headIndex () |
| Segment & | headSegment () |
| unsigned | nextFreeIndex () |
| Segment & | nextFreeSegment () |
| 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 |
| FramedSource * | fUsingSource |
| Boolean | fDirectionIsToADU |
| Boolean | fIncludeADUdescriptors |
Definition at line 54 of file MP3ADU.cpp.
Definition at line 56 of file MP3ADU.cpp.
References reset().
00057 : fDirectionIsToADU(directionIsToADU), 00058 fIncludeADUdescriptors(includeADUdescriptors) { 00059 reset(); 00060 }
| 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 511 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().
00512 { 00513 if (isFull()) { 00514 usingSource->envir() << "SegmentQueue::enqueueNewSegment() overflow\n"; 00515 FramedSource::handleClosure(usingSource); 00516 return; 00517 } 00518 00519 fUsingSource = usingSource; 00520 00521 Segment& seg = nextFreeSegment(); 00522 inputSource->getNextFrame(seg.buf, sizeof seg.buf, 00523 sqAfterGettingSegment, this, 00524 FramedSource::handleClosure, usingSource); 00525 }
| Boolean SegmentQueue::dequeue | ( | ) |
Definition at line 587 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().
00587 { 00588 if (isEmpty()) { 00589 fUsingSource->envir() << "SegmentQueue::dequeue(): underflow!\n"; 00590 return False; 00591 } 00592 00593 Segment& seg = s[headIndex()]; 00594 fTotalDataSize -= seg.dataHere(); 00595 fHeadIndex = nextIndex(fHeadIndex); 00596 return True; 00597 }
| Boolean SegmentQueue::insertDummyBeforeTail | ( | unsigned | backpointer | ) |
Definition at line 599 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().
00599 { 00600 if (isEmptyOrFull()) return False; 00601 00602 // Copy the current tail segment to its new position, then modify the 00603 // old tail segment to be a 'dummy' ADU 00604 00605 unsigned newTailIndex = nextFreeIndex(); 00606 Segment& newTailSeg = s[newTailIndex]; 00607 00608 unsigned oldTailIndex = prevIndex(newTailIndex); 00609 Segment& oldTailSeg = s[oldTailIndex]; 00610 00611 newTailSeg = oldTailSeg; // structure copy 00612 00613 // Begin by setting (replacing) the ADU descriptor of the dummy ADU: 00614 unsigned char* ptr = oldTailSeg.buf; 00615 if (fIncludeADUdescriptors) { 00616 unsigned remainingFrameSize 00617 = oldTailSeg.headerSize + oldTailSeg.sideInfoSize + 0 /* 0-size ADU */; 00618 unsigned currentDescriptorSize = oldTailSeg.descriptorSize; 00619 00620 if (currentDescriptorSize == 2) { 00621 ADUdescriptor::generateTwoByteDescriptor(ptr, remainingFrameSize); 00622 } else { 00623 (void)ADUdescriptor::generateDescriptor(ptr, remainingFrameSize); 00624 } 00625 } 00626 00627 // Then zero out the side info of the dummy frame: 00628 if (!ZeroOutMP3SideInfo(ptr, oldTailSeg.frameSize, 00629 backpointer)) return False; 00630 00631 unsigned dummyNumBytesRead 00632 = oldTailSeg.descriptorSize + 4/*header size*/ + oldTailSeg.sideInfoSize; 00633 return sqAfterGettingCommon(oldTailSeg, dummyNumBytesRead); 00634 }
| void SegmentQueue::reset | ( | ) | [inline] |
Definition at line 83 of file MP3ADU.cpp.
References fHeadIndex, fNextFreeIndex, and fTotalDataSize.
Referenced by ADUFromMP3Source::resetInput(), and SegmentQueue().
00083 { fHeadIndex = fNextFreeIndex = fTotalDataSize = 0; }
| void SegmentQueue::sqAfterGettingSegment | ( | void * | clientData, | |
| unsigned | numBytesRead, | |||
| unsigned | numTruncatedBytes, | |||
| struct timeval | presentationTime, | |||
| unsigned | durationInMicroseconds | |||
| ) | [static, private] |
Definition at line 527 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().
00531 { 00532 SegmentQueue* segQueue = (SegmentQueue*)clientData; 00533 Segment& seg = segQueue->nextFreeSegment(); 00534 00535 seg.presentationTime = presentationTime; 00536 seg.durationInMicroseconds = durationInMicroseconds; 00537 00538 if (segQueue->sqAfterGettingCommon(seg, numBytesRead)) { 00539 #ifdef DEBUG 00540 char const* direction = segQueue->fDirectionIsToADU ? "m->a" : "a->m"; 00541 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); 00542 #endif 00543 } 00544 00545 // Continue our original calling source where it left off: 00546 segQueue->fUsingSource->doGetNextFrame(); 00547 }
Definition at line 550 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().
00551 { 00552 unsigned char* fromPtr = seg.buf; 00553 00554 if (fIncludeADUdescriptors) { 00555 // The newly-read data is assumed to be an ADU with a descriptor 00556 // in front 00557 (void)ADUdescriptor::getRemainingFrameSize(fromPtr); 00558 seg.descriptorSize = (unsigned)(fromPtr-seg.buf); 00559 } else { 00560 seg.descriptorSize = 0; 00561 } 00562 00563 // parse the MP3-specific info in the frame to get the ADU params 00564 unsigned hdr; 00565 MP3SideInfo sideInfo; 00566 if (!GetADUInfoFromMP3Frame(fromPtr, numBytesRead, 00567 hdr, seg.frameSize, 00568 sideInfo, seg.sideInfoSize, 00569 seg.backpointer, seg.aduSize)) { 00570 return False; 00571 } 00572 00573 // If we've just read an ADU (rather than a regular MP3 frame), then use the 00574 // entire "numBytesRead" data for the 'aduSize', so that we include any 00575 // 'ancillary data' that may be present at the end of the ADU: 00576 if (!fDirectionIsToADU) { 00577 unsigned newADUSize 00578 = numBytesRead - seg.descriptorSize - 4/*header size*/ - seg.sideInfoSize; 00579 if (newADUSize > seg.aduSize) seg.aduSize = newADUSize; 00580 } 00581 fTotalDataSize += seg.dataHere(); 00582 fNextFreeIndex = nextIndex(fNextFreeIndex); 00583 00584 return True; 00585 }
| 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();}
| 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().
1.5.2