InputESSourceRecord Class Reference

Collaboration diagram for InputESSourceRecord:

Collaboration graph
[legend]

Public Member Functions

 InputESSourceRecord (MPEG2TransportStreamFromESSource &parent, FramedSource *inputSource, u_int8_t streamId, int mpegVersion, InputESSourceRecord *next)
virtual ~InputESSourceRecord ()
InputESSourceRecordnext () const
FramedSourceinputSource () const
void askForNewData ()
Boolean deliverBufferToClient ()
unsigned char * buffer () const
void reset ()

Private Member Functions

void afterGettingFrame1 (unsigned frameSize, unsigned numTruncatedBytes, struct timeval presentationTime)

Static Private Member Functions

static void afterGettingFrame (void *clientData, unsigned frameSize, unsigned numTruncatedBytes, struct timeval presentationTime, unsigned durationInMicroseconds)

Private Attributes

InputESSourceRecordfNext
MPEG2TransportStreamFromESSourcefParent
FramedSourcefInputSource
u_int8_t fStreamId
int fMPEGVersion
unsigned char * fInputBuffer
unsigned fInputBufferBytesAvailable
Boolean fInputBufferInUse
MPEG1or2Demux::SCR fSCR

Detailed Description

Definition at line 31 of file MPEG2TransportStreamFromESSource.cpp.


Constructor & Destructor Documentation

InputESSourceRecord::InputESSourceRecord ( MPEG2TransportStreamFromESSource parent,
FramedSource inputSource,
u_int8_t  streamId,
int  mpegVersion,
InputESSourceRecord next 
)

Definition at line 155 of file MPEG2TransportStreamFromESSource.cpp.

References MPEG2TransportStreamMultiplexor::fInputBuffer, INPUT_BUFFER_SIZE, and reset().

00159   : fNext(next), fParent(parent), fInputSource(inputSource),
00160     fStreamId(streamId), fMPEGVersion(mpegVersion) {
00161   fInputBuffer = new unsigned char[INPUT_BUFFER_SIZE];
00162   reset();
00163 }

InputESSourceRecord::~InputESSourceRecord (  )  [virtual]

Definition at line 165 of file MPEG2TransportStreamFromESSource.cpp.

References Medium::close(), fInputBuffer, fInputSource, and fNext.

00165                                           {
00166   Medium::close(fInputSource);
00167   delete[] fInputBuffer;
00168   delete fNext;
00169 }


Member Function Documentation

InputESSourceRecord* InputESSourceRecord::next (  )  const [inline]

Definition at line 39 of file MPEG2TransportStreamFromESSource.cpp.

References fNext.

Referenced by MPEG2TransportStreamFromESSource::awaitNewBuffer().

00039 { return fNext; }

FramedSource* InputESSourceRecord::inputSource (  )  const [inline]

Definition at line 40 of file MPEG2TransportStreamFromESSource.cpp.

References fInputSource.

00040 { return fInputSource; }

void InputESSourceRecord::askForNewData (  ) 

Definition at line 171 of file MPEG2TransportStreamFromESSource.cpp.

References afterGettingFrame(), fInputBuffer, fInputBufferBytesAvailable, fInputBufferInUse, fInputSource, fParent, fStreamId, FramedSource::getNextFrame(), FramedSource::handleClosure(), INPUT_BUFFER_SIZE, FramedSource::isCurrentlyAwaitingData(), LOW_WATER_MARK, and SIMPLE_PES_HEADER_SIZE.

Referenced by MPEG2TransportStreamFromESSource::awaitNewBuffer().

00171                                         {
00172   if (fInputBufferInUse) return;
00173 
00174   if (fInputBufferBytesAvailable == 0) {
00175     // Reset our buffer, by adding a simple PES header at the start:
00176     fInputBuffer[0] = 0; fInputBuffer[1] = 0; fInputBuffer[2] = 1;
00177     fInputBuffer[3] = fStreamId;
00178     fInputBuffer[4] = 0; fInputBuffer[5] = 0; // fill in later with the length
00179     fInputBuffer[6] = 0x80;
00180     fInputBuffer[7] = 0x80; // include a PTS
00181     fInputBuffer[8] = 5; // PES_header_data_length (enough for a PTS)
00182     // fInputBuffer[9..13] will be the PTS; fill this in later
00183     fInputBufferBytesAvailable = SIMPLE_PES_HEADER_SIZE;
00184   }
00185   if (fInputBufferBytesAvailable < LOW_WATER_MARK &&
00186       !fInputSource->isCurrentlyAwaitingData()) {
00187     // We don't yet have enough data in our buffer.  Arrange to read more:
00188     fInputSource->getNextFrame(&fInputBuffer[fInputBufferBytesAvailable],
00189                                INPUT_BUFFER_SIZE-fInputBufferBytesAvailable,
00190                                afterGettingFrame, this,
00191                                FramedSource::handleClosure, &fParent);
00192   }
00193 }

Boolean InputESSourceRecord::deliverBufferToClient (  ) 

Definition at line 195 of file MPEG2TransportStreamFromESSource.cpp.

References False, fInputBuffer, fInputBufferBytesAvailable, fInputBufferInUse, fMPEGVersion, fParent, fSCR, MPEG2TransportStreamMultiplexor::handleNewBuffer(), MPEG1or2Demux::SCR::highBit, LOW_WATER_MARK, MPEG1or2Demux::SCR::remainingBits, and True.

Referenced by MPEG2TransportStreamFromESSource::awaitNewBuffer().

00195                                                    {
00196   if (fInputBufferInUse || fInputBufferBytesAvailable < LOW_WATER_MARK) return False;
00197 
00198   // Fill in the PES_packet_length field that we left unset before:
00199   unsigned PES_packet_length = fInputBufferBytesAvailable - 6;
00200   if (PES_packet_length > 0xFFFF) {
00201     // Set the PES_packet_length field to 0.  This indicates an unbounded length (see ISO 13818-1, 2.4.3.7)
00202     PES_packet_length = 0;
00203   }
00204   fInputBuffer[4] = PES_packet_length>>8;
00205   fInputBuffer[5] = PES_packet_length;
00206 
00207   // Fill in the PES PTS (from our SCR):
00208   fInputBuffer[9] = 0x20|(fSCR.highBit<<3)|(fSCR.remainingBits>>29)|0x01;
00209   fInputBuffer[10] = fSCR.remainingBits>>22;
00210   fInputBuffer[11] = (fSCR.remainingBits>>14)|0x01;
00211   fInputBuffer[12] = fSCR.remainingBits>>7;
00212   fInputBuffer[13] = (fSCR.remainingBits<<1)|0x01;
00213 
00214   fInputBufferInUse = True;
00215 
00216   // Do the delivery:
00217   fParent.handleNewBuffer(fInputBuffer, fInputBufferBytesAvailable,
00218                          fMPEGVersion, fSCR);
00219 
00220   return True;
00221 }

unsigned char* InputESSourceRecord::buffer (  )  const [inline]

Definition at line 45 of file MPEG2TransportStreamFromESSource.cpp.

References fInputBuffer.

Referenced by MPEG2TransportStreamFromESSource::awaitNewBuffer().

00045 { return fInputBuffer; }

void InputESSourceRecord::reset (  )  [inline]

Definition at line 46 of file MPEG2TransportStreamFromESSource.cpp.

References False, fInputBufferBytesAvailable, and fInputBufferInUse.

Referenced by MPEG2TransportStreamFromESSource::awaitNewBuffer().

00046                {
00047     // Reset the buffer for future use:
00048     fInputBufferBytesAvailable = 0;
00049     fInputBufferInUse = False;
00050   }

void InputESSourceRecord::afterGettingFrame ( void *  clientData,
unsigned  frameSize,
unsigned  numTruncatedBytes,
struct timeval  presentationTime,
unsigned  durationInMicroseconds 
) [static, private]

Definition at line 224 of file MPEG2TransportStreamFromESSource.cpp.

References afterGettingFrame1().

Referenced by askForNewData().

00227                                                          {
00228   InputESSourceRecord* source = (InputESSourceRecord*)clientData;
00229   source->afterGettingFrame1(frameSize, numTruncatedBytes, presentationTime);
00230 }

void InputESSourceRecord::afterGettingFrame1 ( unsigned  frameSize,
unsigned  numTruncatedBytes,
struct timeval  presentationTime 
) [private]

Definition at line 232 of file MPEG2TransportStreamFromESSource.cpp.

References MPEG2TransportStreamFromESSource::awaitNewBuffer(), Medium::envir(), MPEG1or2Demux::SCR::extension, fInputBufferBytesAvailable, fParent, FramedSource::fPresentationTime, fSCR, fStreamId, MPEG1or2Demux::SCR::highBit, NULL, MPEG1or2Demux::SCR::remainingBits, and SIMPLE_PES_HEADER_SIZE.

Referenced by afterGettingFrame().

00233                                                       {
00234   if (numTruncatedBytes > 0) {
00235     fParent.envir() << "MPEG2TransportStreamFromESSource: input buffer too small; increase \"MAX_INPUT_ES_FRAME_SIZE\" in \"MPEG2TransportStreamFromESSource\" by at least "
00236                     << numTruncatedBytes << " bytes!\n";
00237   }
00238 
00239   if (fInputBufferBytesAvailable == SIMPLE_PES_HEADER_SIZE) {
00240     // Use this presentationTime for our SCR:
00241     fSCR.highBit
00242       = ((presentationTime.tv_sec*45000 + (presentationTime.tv_usec*9)/200)&
00243          0x80000000) != 0;
00244     fSCR.remainingBits
00245       = presentationTime.tv_sec*90000 + (presentationTime.tv_usec*9)/100;
00246     fSCR.extension = (presentationTime.tv_usec*9)%100;
00247 #ifdef DEBUG_SCR
00248     fprintf(stderr, "PES header: stream_id 0x%02x, pts: %u.%06u => SCR 0x%x%08x:%03x\n", fStreamId, (unsigned)presentationTime.tv_sec, (unsigned)presentationTime.tv_usec, fSCR.highBit, fSCR.remainingBits, fSCR.extension);
00249 #endif
00250   }
00251 
00252   fInputBufferBytesAvailable += frameSize;
00253 
00254   fParent.fPresentationTime = presentationTime;
00255 
00256   // Now that we have new input data, check if we can deliver to the client:
00257   fParent.awaitNewBuffer(NULL);
00258 }


Field Documentation

InputESSourceRecord* InputESSourceRecord::fNext [private]

Definition at line 62 of file MPEG2TransportStreamFromESSource.cpp.

Referenced by next(), and ~InputESSourceRecord().

MPEG2TransportStreamFromESSource& InputESSourceRecord::fParent [private]

Definition at line 63 of file MPEG2TransportStreamFromESSource.cpp.

Referenced by afterGettingFrame1(), askForNewData(), and deliverBufferToClient().

FramedSource* InputESSourceRecord::fInputSource [private]

Definition at line 64 of file MPEG2TransportStreamFromESSource.cpp.

Referenced by askForNewData(), inputSource(), and ~InputESSourceRecord().

u_int8_t InputESSourceRecord::fStreamId [private]

Definition at line 65 of file MPEG2TransportStreamFromESSource.cpp.

Referenced by afterGettingFrame1(), and askForNewData().

int InputESSourceRecord::fMPEGVersion [private]

Definition at line 66 of file MPEG2TransportStreamFromESSource.cpp.

Referenced by deliverBufferToClient().

unsigned char* InputESSourceRecord::fInputBuffer [private]

Definition at line 67 of file MPEG2TransportStreamFromESSource.cpp.

Referenced by askForNewData(), buffer(), deliverBufferToClient(), and ~InputESSourceRecord().

unsigned InputESSourceRecord::fInputBufferBytesAvailable [private]

Definition at line 68 of file MPEG2TransportStreamFromESSource.cpp.

Referenced by afterGettingFrame1(), askForNewData(), deliverBufferToClient(), and reset().

Boolean InputESSourceRecord::fInputBufferInUse [private]

Definition at line 69 of file MPEG2TransportStreamFromESSource.cpp.

Referenced by askForNewData(), deliverBufferToClient(), and reset().

MPEG1or2Demux::SCR InputESSourceRecord::fSCR [private]

Definition at line 70 of file MPEG2TransportStreamFromESSource.cpp.

Referenced by afterGettingFrame1(), and deliverBufferToClient().


The documentation for this class was generated from the following file:
Generated on Tue Oct 7 15:39:44 2008 for live by  doxygen 1.5.2