live
H264or5VideoStreamFramer.hh
Go to the documentation of this file.
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-2019 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 
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
54  Boolean createParser, Boolean includeStartCodeInOutput);
55  // We're an abstract base class.
56  virtual ~H264or5VideoStreamFramer();
57 
58  void saveCopyOfVPS(u_int8_t* from, unsigned size);
59  void saveCopyOfSPS(u_int8_t* from, unsigned size);
60  void saveCopyOfPPS(u_int8_t* from, unsigned size);
61 
63 
64  Boolean isVPS(u_int8_t nal_unit_type);
65  Boolean isSPS(u_int8_t nal_unit_type);
66  Boolean isPPS(u_int8_t nal_unit_type);
67  Boolean isVCL(u_int8_t nal_unit_type);
68 
69 protected:
70  int fHNumber;
71  u_int8_t* fLastSeenVPS;
72  unsigned fLastSeenVPSSize;
73  u_int8_t* fLastSeenSPS;
74  unsigned fLastSeenSPSSize;
75  u_int8_t* fLastSeenPPS;
76  unsigned fLastSeenPPSSize;
77  struct timeval fNextPresentationTime; // the presentation time to be used for the next NAL unit to be parsed/delivered after this
78  friend class H264or5VideoStreamParser; // hack
79 };
80 
81 // A general routine for making a copy of a (H.264 or H.265) NAL unit,
82 // removing 'emulation' bytes from the copy:
83 unsigned removeH264or5EmulationBytes(u_int8_t* to, unsigned toMaxSize,
84  u_int8_t const* from, unsigned fromSize);
85  // returns the size of the copy; it will be <= min(toMaxSize,fromSize)
86 
87 #endif
unsigned char Boolean
Definition: Boolean.hh:25
Boolean isPPS(u_int8_t nal_unit_type)
void saveCopyOfSPS(u_int8_t *from, unsigned size)
Boolean isVPS(u_int8_t nal_unit_type)
H264or5VideoStreamFramer(int hNumber, UsageEnvironment &env, FramedSource *inputSource, Boolean createParser, Boolean includeStartCodeInOutput)
unsigned removeH264or5EmulationBytes(u_int8_t *to, unsigned toMaxSize, u_int8_t const *from, unsigned fromSize)
void setVPSandSPSandPPS(u_int8_t *vps, unsigned vpsSize, u_int8_t *sps, unsigned spsSize, u_int8_t *pps, unsigned ppsSize)
void saveCopyOfVPS(u_int8_t *from, unsigned size)
Boolean isVCL(u_int8_t nal_unit_type)
virtual ~H264or5VideoStreamFramer()
void saveCopyOfPPS(u_int8_t *from, unsigned size)
FramedSource * inputSource() const
Definition: FramedFilter.hh:30
struct timeval fPresentationTime
Definition: FramedSource.hh:79
void getVPSandSPSandPPS(u_int8_t *&vps, unsigned &vpsSize, u_int8_t *&sps, unsigned &spsSize, u_int8_t *&pps, unsigned &ppsSize) const
Boolean isSPS(u_int8_t nal_unit_type)