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 156 of file MPEG2TransportStreamFromESSource.cpp.

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

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

InputESSourceRecord::~InputESSourceRecord (  )  [virtual]

Definition at line 166 of file MPEG2TransportStreamFromESSource.cpp.

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

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


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 172 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().

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

Boolean InputESSourceRecord::deliverBufferToClient (  ) 

Definition at line 196 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().

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

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 225 of file MPEG2TransportStreamFromESSource.cpp.

References source.

Referenced by askForNewData().

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

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

Definition at line 233 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.

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


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 Wed Apr 23 16:16:18 2014 for live by  doxygen 1.5.2