liveMedia/include/MPEG1or2Demux.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-2012 Live Networks, Inc.  All rights reserved.
00018 // Demultiplexer for a MPEG 1 or 2 Program Stream
00019 // C++ header
00020 
00021 #ifndef _MPEG_1OR2_DEMUX_HH
00022 #define _MPEG_1OR2_DEMUX_HH
00023 
00024 #ifndef _FRAMED_SOURCE_HH
00025 #include "FramedSource.hh"
00026 #endif
00027 
00028 class MPEG1or2DemuxedElementaryStream; // forward
00029 
00030 class MPEG1or2Demux: public Medium {
00031 public:
00032   static MPEG1or2Demux* createNew(UsageEnvironment& env,
00033                                   FramedSource* inputSource,
00034                                   Boolean reclaimWhenLastESDies = False);
00035   // If "reclaimWhenLastESDies" is True, the the demux is deleted when
00036   // all "MPEG1or2DemuxedElementaryStream"s that we created get deleted.
00037 
00038   MPEG1or2DemuxedElementaryStream* newElementaryStream(u_int8_t streamIdTag);
00039 
00040   // Specialized versions of the above for audio and video:
00041   MPEG1or2DemuxedElementaryStream* newAudioStream();
00042   MPEG1or2DemuxedElementaryStream* newVideoStream();
00043 
00044   // A hack for getting raw, undemuxed PES packets from the Program Stream:
00045   MPEG1or2DemuxedElementaryStream* newRawPESStream();
00046 
00047   void getNextFrame(u_int8_t streamIdTag,
00048                     unsigned char* to, unsigned maxSize,
00049                     FramedSource::afterGettingFunc* afterGettingFunc,
00050                     void* afterGettingClientData,
00051                     FramedSource::onCloseFunc* onCloseFunc,
00052                     void* onCloseClientData);
00053       // similar to FramedSource::getNextFrame(), except that it also
00054       // takes a stream id tag as parameter.
00055 
00056   void stopGettingFrames(u_int8_t streamIdTag);
00057       // similar to FramedSource::stopGettingFrames(), except that it also
00058       // takes a stream id tag as parameter.
00059 
00060   static void handleClosure(void* clientData);
00061       // This should be called (on ourself) if the source is discovered
00062       // to be closed (i.e., no longer readable)
00063 
00064   FramedSource* inputSource() const { return fInputSource; }
00065 
00066   class SCR {
00067   public:
00068     SCR();
00069 
00070     u_int8_t highBit;
00071     u_int32_t remainingBits;
00072     u_int16_t extension;
00073 
00074     Boolean isValid;
00075   };
00076   SCR& lastSeenSCR() { return fLastSeenSCR; }
00077 
00078   unsigned char mpegVersion() const { return fMPEGversion; }
00079 
00080   void flushInput(); // should be called before any 'seek' on the underlying source
00081 
00082 private:
00083   MPEG1or2Demux(UsageEnvironment& env,
00084                 FramedSource* inputSource, Boolean reclaimWhenLastESDies);
00085       // called only by createNew()
00086   virtual ~MPEG1or2Demux();
00087 
00088   void registerReadInterest(u_int8_t streamIdTag,
00089                             unsigned char* to, unsigned maxSize,
00090                             FramedSource::afterGettingFunc* afterGettingFunc,
00091                             void* afterGettingClientData,
00092                             FramedSource::onCloseFunc* onCloseFunc,
00093                             void* onCloseClientData);
00094 
00095   Boolean useSavedData(u_int8_t streamIdTag,
00096                        unsigned char* to, unsigned maxSize,
00097                        FramedSource::afterGettingFunc* afterGettingFunc,
00098                        void* afterGettingClientData);
00099 
00100   static void continueReadProcessing(void* clientData,
00101                                      unsigned char* ptr, unsigned size,
00102                                      struct timeval presentationTime);
00103   void continueReadProcessing();
00104 
00105 private:
00106   friend class MPEG1or2DemuxedElementaryStream;
00107   void noteElementaryStreamDeletion(MPEG1or2DemuxedElementaryStream* es);
00108 
00109 private:
00110   FramedSource* fInputSource;
00111   SCR fLastSeenSCR;
00112   unsigned char fMPEGversion;
00113 
00114   unsigned char fNextAudioStreamNumber;
00115   unsigned char fNextVideoStreamNumber;
00116   Boolean fReclaimWhenLastESDies;
00117   unsigned fNumOutstandingESs;
00118 
00119   // A descriptor for each possible stream id tag:
00120   typedef struct OutputDescriptor {
00121     // input parameters
00122     unsigned char* to; unsigned maxSize;
00123     FramedSource::afterGettingFunc* fAfterGettingFunc;
00124     void* afterGettingClientData;
00125     FramedSource::onCloseFunc* fOnCloseFunc;
00126     void* onCloseClientData;
00127 
00128     // output parameters
00129     unsigned frameSize; struct timeval presentationTime;
00130     class SavedData; // forward
00131     SavedData* savedDataHead;
00132     SavedData* savedDataTail;
00133     unsigned savedDataTotalSize;
00134 
00135     // status parameters
00136     Boolean isPotentiallyReadable;
00137     Boolean isCurrentlyActive;
00138     Boolean isCurrentlyAwaitingData;
00139   } OutputDescriptor_t;
00140   OutputDescriptor_t fOutput[256];
00141 
00142   unsigned fNumPendingReads;
00143   Boolean fHaveUndeliveredData;
00144 
00145 private: // parsing state
00146   class MPEGProgramStreamParser* fParser;
00147   friend class MPEGProgramStreamParser; // hack
00148 };
00149 
00150 #endif

Generated on Thu Feb 2 23:51:30 2012 for live by  doxygen 1.5.2