liveMedia/include/MPEG2TransportStreamMultiplexor.hh

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-2013 Live Networks, Inc.  All rights reserved.
00018 // A class for generating MPEG-2 Transport Stream from one or more input
00019 // Elementary Stream data sources
00020 // C++ header
00021 
00022 #ifndef _MPEG2_TRANSPORT_STREAM_MULTIPLEXOR_HH
00023 #define _MPEG2_TRANSPORT_STREAM_MULTIPLEXOR_HH
00024 
00025 #ifndef _FRAMED_SOURCE_HH
00026 #include "FramedSource.hh"
00027 #endif
00028 #ifndef _MPEG_1OR2_DEMUX_HH
00029 #include "MPEG1or2Demux.hh" // for SCR
00030 #endif
00031 
00032 #define PID_TABLE_SIZE 256
00033 
00034 class MPEG2TransportStreamMultiplexor: public FramedSource {
00035 protected:
00036   MPEG2TransportStreamMultiplexor(UsageEnvironment& env);
00037   virtual ~MPEG2TransportStreamMultiplexor();
00038 
00039   virtual void awaitNewBuffer(unsigned char* oldBuffer) = 0;
00040       // implemented by subclasses
00041 
00042   void handleNewBuffer(unsigned char* buffer, unsigned bufferSize,
00043                        int mpegVersion, MPEG1or2Demux::SCR scr);
00044   // called by "awaitNewBuffer()"
00045   // Note: For MPEG-4 video, set "mpegVersion" to 4; for H.264 video, set "mpegVersion" to 5. 
00046 
00047 private:
00048   // Redefined virtual functions:
00049   virtual void doGetNextFrame();
00050 
00051 private:
00052   void deliverDataToClient(u_int8_t pid, unsigned char* buffer, unsigned bufferSize,
00053                            unsigned& startPositionInBuffer);
00054 
00055   void deliverPATPacket();
00056   void deliverPMTPacket(Boolean hasChanged);
00057 
00058   void setProgramStreamMap(unsigned frameSize);
00059 
00060 protected:
00061   Boolean fHaveVideoStreams;
00062 
00063 private:
00064   unsigned fOutgoingPacketCounter;
00065   unsigned fProgramMapVersion;
00066   u_int8_t fPreviousInputProgramMapVersion, fCurrentInputProgramMapVersion;
00067       // These two fields are used if we see "program_stream_map"s in the input.
00068   struct {
00069     unsigned counter;
00070     u_int8_t streamType; // for use in Program Maps
00071   } fPIDState[PID_TABLE_SIZE];
00072   u_int8_t fPCR_PID, fCurrentPID;
00073       // Note: We map 8-bit stream_ids directly to PIDs
00074   MPEG1or2Demux::SCR fPCR;
00075   unsigned char* fInputBuffer;
00076   unsigned fInputBufferSize, fInputBufferBytesUsed;
00077   Boolean fIsFirstAdaptationField;
00078 };
00079 
00080 #endif

Generated on Tue Jun 18 13:16:51 2013 for live by  doxygen 1.5.2