H264or5VideoStreamFramer.hh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. This library is distributed in the hope that it will be useful, but WITHOUT
  7. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
  9. more details.
  10. You should have received a copy of the GNU Lesser General Public License
  11. along with this library; if not, write to the Free Software Foundation, Inc.,
  12. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  13. **********/
  14. // "liveMedia"
  15. // Copyright (c) 1996-2019 Live Networks, Inc. All rights reserved.
  16. // A filter that breaks up a H.264 or H.265 Video Elementary Stream into NAL units.
  17. // C++ header
  18. #ifndef _H264_OR_5_VIDEO_STREAM_FRAMER_HH
  19. #define _H264_OR_5_VIDEO_STREAM_FRAMER_HH
  20. #ifndef _MPEG_VIDEO_STREAM_FRAMER_HH
  21. #include "MPEGVideoStreamFramer.hh"
  22. #endif
  23. class H264or5VideoStreamFramer: public MPEGVideoStreamFramer {
  24. public:
  25. void getVPSandSPSandPPS(u_int8_t*& vps, unsigned& vpsSize,
  26. u_int8_t*& sps, unsigned& spsSize,
  27. u_int8_t*& pps, unsigned& ppsSize) const {
  28. // Returns pointers to copies of the most recently seen VPS (video parameter set)
  29. // SPS (sequence parameter set) and PPS (picture parameter set) NAL units.
  30. // (NULL pointers are returned if the NAL units have not yet been seen.)
  31. vps = fLastSeenVPS; vpsSize = fLastSeenVPSSize;
  32. sps = fLastSeenSPS; spsSize = fLastSeenSPSSize;
  33. pps = fLastSeenPPS; ppsSize = fLastSeenPPSSize;
  34. }
  35. void setVPSandSPSandPPS(u_int8_t* vps, unsigned vpsSize,
  36. u_int8_t* sps, unsigned spsSize,
  37. u_int8_t* pps, unsigned ppsSize) {
  38. // Assigns copies of the VPS, SPS and PPS NAL units. If this function is not called,
  39. // then these NAL units are assigned only if/when they appear in the input stream.
  40. saveCopyOfVPS(vps, vpsSize);
  41. saveCopyOfSPS(sps, spsSize);
  42. saveCopyOfPPS(pps, ppsSize);
  43. }
  44. protected:
  45. H264or5VideoStreamFramer(int hNumber, // 264 or 265
  46. UsageEnvironment& env, FramedSource* inputSource,
  47. Boolean createParser, Boolean includeStartCodeInOutput);
  48. // We're an abstract base class.
  49. virtual ~H264or5VideoStreamFramer();
  50. void saveCopyOfVPS(u_int8_t* from, unsigned size);
  51. void saveCopyOfSPS(u_int8_t* from, unsigned size);
  52. void saveCopyOfPPS(u_int8_t* from, unsigned size);
  53. void setPresentationTime() { fPresentationTime = fNextPresentationTime; }
  54. Boolean isVPS(u_int8_t nal_unit_type);
  55. Boolean isSPS(u_int8_t nal_unit_type);
  56. Boolean isPPS(u_int8_t nal_unit_type);
  57. Boolean isVCL(u_int8_t nal_unit_type);
  58. protected:
  59. int fHNumber;
  60. u_int8_t* fLastSeenVPS;
  61. unsigned fLastSeenVPSSize;
  62. u_int8_t* fLastSeenSPS;
  63. unsigned fLastSeenSPSSize;
  64. u_int8_t* fLastSeenPPS;
  65. unsigned fLastSeenPPSSize;
  66. struct timeval fNextPresentationTime; // the presentation time to be used for the next NAL unit to be parsed/delivered after this
  67. friend class H264or5VideoStreamParser; // hack
  68. };
  69. // A general routine for making a copy of a (H.264 or H.265) NAL unit,
  70. // removing 'emulation' bytes from the copy:
  71. unsigned removeH264or5EmulationBytes(u_int8_t* to, unsigned toMaxSize,
  72. u_int8_t const* from, unsigned fromSize);
  73. // returns the size of the copy; it will be <= min(toMaxSize,fromSize)
  74. #endif