liveMedia/MPEG2TransportStreamFromPESSource.cpp

Go to the documentation of this file.
00001 /**********
00002 This library is free software; you can redistribute it and/or modify it under
00003 the terms of the GNU Lesser General Public License as published by the
00004 Free Software Foundation; either version 2.1 of the License, or (at your
00005 option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
00006 
00007 This library is distributed in the hope that it will be useful, but WITHOUT
00008 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00009 FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
00010 more details.
00011 
00012 You should have received a copy of the GNU Lesser General Public License
00013 along with this library; if not, write to the Free Software Foundation, Inc.,
00014 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
00015 **********/
00016 // "liveMedia"
00017 // Copyright (c) 1996-2012 Live Networks, Inc.  All rights reserved.
00018 // A filter for converting a stream of MPEG PES packets to a MPEG-2 Transport Stream
00019 // Implementation
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* /*oldBuffer*/) {
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 /*numTruncatedBytes*/,
00068                      struct timeval /*presentationTime*/,
00069                      unsigned /*durationInMicroseconds*/) {
00070   if (frameSize < 4) return;
00071 
00072   handleNewBuffer(fInputBuffer, frameSize,
00073                   fInputSource->mpegVersion(), fInputSource->lastSeenSCR());
00074 }

Generated on Thu May 17 07:11:47 2012 for live by  doxygen 1.5.2