00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "MPEG2TransportStreamFromPESSource.hh"
00022
00023 #define MAX_PES_PACKET_SIZE (6+65535)
00024
00025 MPEG2TransportStreamFromPESSource* MPEG2TransportStreamFromPESSource
00026 ::createNew(UsageEnvironment& env, MPEG1or2DemuxedElementaryStream* inputSource) {
00027 return new MPEG2TransportStreamFromPESSource(env, inputSource);
00028 }
00029
00030 MPEG2TransportStreamFromPESSource
00031 ::MPEG2TransportStreamFromPESSource(UsageEnvironment& env,
00032 MPEG1or2DemuxedElementaryStream* inputSource)
00033 : MPEG2TransportStreamMultiplexor(env),
00034 fInputSource(inputSource) {
00035 fInputBuffer = new unsigned char[MAX_PES_PACKET_SIZE];
00036 }
00037
00038 MPEG2TransportStreamFromPESSource::~MPEG2TransportStreamFromPESSource() {
00039 Medium::close(fInputSource);
00040 delete[] fInputBuffer;
00041 }
00042
00043 void MPEG2TransportStreamFromPESSource::doStopGettingFrames() {
00044 fInputSource->stopGettingFrames();
00045 }
00046
00047 void MPEG2TransportStreamFromPESSource
00048 ::awaitNewBuffer(unsigned char* ) {
00049 fInputSource->getNextFrame(fInputBuffer, MAX_PES_PACKET_SIZE,
00050 afterGettingFrame, this,
00051 FramedSource::handleClosure, this);
00052 }
00053
00054 void MPEG2TransportStreamFromPESSource
00055 ::afterGettingFrame(void* clientData, unsigned frameSize,
00056 unsigned numTruncatedBytes,
00057 struct timeval presentationTime,
00058 unsigned durationInMicroseconds) {
00059 MPEG2TransportStreamFromPESSource* source
00060 = (MPEG2TransportStreamFromPESSource*)clientData;
00061 source->afterGettingFrame1(frameSize, numTruncatedBytes,
00062 presentationTime, durationInMicroseconds);
00063 }
00064
00065 void MPEG2TransportStreamFromPESSource
00066 ::afterGettingFrame1(unsigned frameSize,
00067 unsigned ,
00068 struct timeval ,
00069 unsigned ) {
00070 if (frameSize < 4) return;
00071
00072 handleNewBuffer(fInputBuffer, frameSize,
00073 fInputSource->mpegVersion(), fInputSource->lastSeenSCR());
00074 }