| 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 a H.264 or H.265 Video Elementary Stream into NAL units. | 
|---|
| 19 | // C++ header | 
|---|
| 20 |  | 
|---|
| 21 | #ifndef _H264_OR_5_VIDEO_STREAM_FRAMER_HH | 
|---|
| 22 | #define _H264_OR_5_VIDEO_STREAM_FRAMER_HH | 
|---|
| 23 |  | 
|---|
| 24 | #ifndef _MPEG_VIDEO_STREAM_FRAMER_HH | 
|---|
| 25 | #include "MPEGVideoStreamFramer.hh" | 
|---|
| 26 | #endif | 
|---|
| 27 |  | 
|---|
| 28 | class H264or5VideoStreamFramer: public MPEGVideoStreamFramer { | 
|---|
| 29 | public: | 
|---|
| 30 | void getVPSandSPSandPPS(u_int8_t*& vps, unsigned& vpsSize, | 
|---|
| 31 | u_int8_t*& sps, unsigned& spsSize, | 
|---|
| 32 | u_int8_t*& pps, unsigned& ppsSize) const { | 
|---|
| 33 | // Returns pointers to copies of the most recently seen VPS (video parameter set) | 
|---|
| 34 | // SPS (sequence parameter set) and PPS (picture parameter set) NAL units. | 
|---|
| 35 | // (NULL pointers are returned if the NAL units have not yet been seen.) | 
|---|
| 36 | vps = fLastSeenVPS; vpsSize = fLastSeenVPSSize; | 
|---|
| 37 | sps = fLastSeenSPS; spsSize = fLastSeenSPSSize; | 
|---|
| 38 | pps = fLastSeenPPS; ppsSize = fLastSeenPPSSize; | 
|---|
| 39 | } | 
|---|
| 40 |  | 
|---|
| 41 | void setVPSandSPSandPPS(u_int8_t* vps, unsigned vpsSize, | 
|---|
| 42 | u_int8_t* sps, unsigned spsSize, | 
|---|
| 43 | u_int8_t* pps, unsigned ppsSize) { | 
|---|
| 44 | // Assigns copies of the VPS, SPS and PPS NAL units.  If this function is not called, | 
|---|
| 45 | // then these NAL units are assigned only if/when they appear in the input stream. | 
|---|
| 46 | saveCopyOfVPS(vps, vpsSize); | 
|---|
| 47 | saveCopyOfSPS(sps, spsSize); | 
|---|
| 48 | saveCopyOfPPS(pps, ppsSize); | 
|---|
| 49 | } | 
|---|
| 50 |  | 
|---|
| 51 | protected: | 
|---|
| 52 | H264or5VideoStreamFramer(int hNumber, // 264 or 265 | 
|---|
| 53 | UsageEnvironment& env, FramedSource* inputSource, | 
|---|
| 54 | Boolean createParser, | 
|---|
| 55 | Boolean includeStartCodeInOutput, Boolean insertAccessUnitDelimiters); | 
|---|
| 56 | // We're an abstract base class. | 
|---|
| 57 | virtual ~H264or5VideoStreamFramer(); | 
|---|
| 58 |  | 
|---|
| 59 | void saveCopyOfVPS(u_int8_t* from, unsigned size); | 
|---|
| 60 | void saveCopyOfSPS(u_int8_t* from, unsigned size); | 
|---|
| 61 | void saveCopyOfPPS(u_int8_t* from, unsigned size); | 
|---|
| 62 |  | 
|---|
| 63 | void setPresentationTime() { fPresentationTime = fNextPresentationTime; } | 
|---|
| 64 |  | 
|---|
| 65 | Boolean isVPS(u_int8_t nal_unit_type); | 
|---|
| 66 | Boolean isSPS(u_int8_t nal_unit_type); | 
|---|
| 67 | Boolean isPPS(u_int8_t nal_unit_type); | 
|---|
| 68 | Boolean isVCL(u_int8_t nal_unit_type); | 
|---|
| 69 |  | 
|---|
| 70 | protected: // redefined virtual functions | 
|---|
| 71 | virtual void doGetNextFrame(); | 
|---|
| 72 |  | 
|---|
| 73 | protected: | 
|---|
| 74 | int fHNumber; | 
|---|
| 75 | Boolean fIncludeStartCodeInOutput, fInsertAccessUnitDelimiters; | 
|---|
| 76 | u_int8_t* fLastSeenVPS; | 
|---|
| 77 | unsigned fLastSeenVPSSize; | 
|---|
| 78 | u_int8_t* fLastSeenSPS; | 
|---|
| 79 | unsigned fLastSeenSPSSize; | 
|---|
| 80 | u_int8_t* fLastSeenPPS; | 
|---|
| 81 | unsigned fLastSeenPPSSize; | 
|---|
| 82 | struct timeval fNextPresentationTime; // the presentation time to be used for the next NAL unit to be parsed/delivered after this | 
|---|
| 83 | friend class H264or5VideoStreamParser; // hack | 
|---|
| 84 | }; | 
|---|
| 85 |  | 
|---|
| 86 | // A general routine for making a copy of a (H.264 or H.265) NAL unit, | 
|---|
| 87 | // removing 'emulation' bytes from the copy: | 
|---|
| 88 | unsigned removeH264or5EmulationBytes(u_int8_t* to, unsigned toMaxSize, | 
|---|
| 89 | u_int8_t const* from, unsigned fromSize); | 
|---|
| 90 | // returns the size of the copy; it will be <= min(toMaxSize,fromSize) | 
|---|
| 91 |  | 
|---|
| 92 | #endif | 
|---|
| 93 |  | 
|---|