| 1 | /********** |
| 2 | This library is free software; you can redistribute it and/or modify it under |
| 3 | the terms of the GNU Lesser General Public License as published by the |
| 4 | Free Software Foundation; either version 3 of the License, or (at your |
| 5 | option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.) |
| 6 | |
| 7 | This library is distributed in the hope that it will be useful, but WITHOUT |
| 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for |
| 10 | more details. |
| 11 | |
| 12 | You should have received a copy of the GNU Lesser General Public License |
| 13 | along with this library; if not, write to the Free Software Foundation, Inc., |
| 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 15 | **********/ |
| 16 | // "liveMedia" |
| 17 | // Copyright (c) 1996-2020 Live Networks, Inc. All rights reserved. |
| 18 | // A filter that breaks up an MPEG video elementary stream into |
| 19 | // headers and frames |
| 20 | // C++ header |
| 21 | |
| 22 | #ifndef _MPEG_VIDEO_STREAM_FRAMER_HH |
| 23 | #define _MPEG_VIDEO_STREAM_FRAMER_HH |
| 24 | |
| 25 | #ifndef _FRAMED_FILTER_HH |
| 26 | #include "FramedFilter.hh" |
| 27 | #endif |
| 28 | |
| 29 | class TimeCode { |
| 30 | public: |
| 31 | TimeCode(); |
| 32 | virtual ~TimeCode(); |
| 33 | |
| 34 | int operator==(TimeCode const& arg2); |
| 35 | unsigned days, hours, minutes, seconds, pictures; |
| 36 | }; |
| 37 | |
| 38 | class MPEGVideoStreamFramer: public FramedFilter { |
| 39 | public: |
| 40 | Boolean& pictureEndMarker() { return fPictureEndMarker; } |
| 41 | // a hack for implementing the RTP 'M' bit |
| 42 | |
| 43 | void flushInput(); // called if there is a discontinuity (seeking) in the input |
| 44 | |
| 45 | protected: |
| 46 | MPEGVideoStreamFramer(UsageEnvironment& env, FramedSource* inputSource); |
| 47 | // we're an abstract base class |
| 48 | virtual ~MPEGVideoStreamFramer(); |
| 49 | |
| 50 | void computePresentationTime(unsigned numAdditionalPictures); |
| 51 | // sets "fPresentationTime" |
| 52 | void setTimeCode(unsigned hours, unsigned minutes, unsigned seconds, |
| 53 | unsigned pictures, unsigned picturesSinceLastGOP); |
| 54 | |
| 55 | protected: // redefined virtual functions |
| 56 | virtual void doGetNextFrame(); |
| 57 | virtual void doStopGettingFrames(); |
| 58 | |
| 59 | private: |
| 60 | void reset(); |
| 61 | |
| 62 | static void continueReadProcessing(void* clientData, |
| 63 | unsigned char* ptr, unsigned size, |
| 64 | struct timeval presentationTime); |
| 65 | void continueReadProcessing(); |
| 66 | |
| 67 | protected: |
| 68 | double fFrameRate; // Note: For MPEG-4, this is really a 'tick rate' |
| 69 | unsigned fPictureCount; // hack used to implement doGetNextFrame() |
| 70 | Boolean fPictureEndMarker; |
| 71 | struct timeval fPresentationTimeBase; |
| 72 | |
| 73 | // parsing state |
| 74 | class MPEGVideoStreamParser* fParser; |
| 75 | friend class MPEGVideoStreamParser; // hack |
| 76 | |
| 77 | private: |
| 78 | TimeCode fCurGOPTimeCode, fPrevGOPTimeCode; |
| 79 | unsigned fPicturesAdjustment; |
| 80 | double fPictureTimeBase; |
| 81 | unsigned fTcSecsBase; |
| 82 | Boolean fHaveSeenFirstTimeCode; |
| 83 | }; |
| 84 | |
| 85 | #endif |
| 86 | |