H264or5VideoStreamFramer.hh 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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-2020 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,
  48. Boolean includeStartCodeInOutput, Boolean insertAccessUnitDelimiters);
  49. // We're an abstract base class.
  50. virtual ~H264or5VideoStreamFramer();
  51. void saveCopyOfVPS(u_int8_t* from, unsigned size);
  52. void saveCopyOfSPS(u_int8_t* from, unsigned size);
  53. void saveCopyOfPPS(u_int8_t* from, unsigned size);
  54. void setPresentationTime();
  55. Boolean isVPS(u_int8_t nal_unit_type);
  56. Boolean isSPS(u_int8_t nal_unit_type);
  57. Boolean isPPS(u_int8_t nal_unit_type);
  58. Boolean isVCL(u_int8_t nal_unit_type);
  59. protected: // redefined virtual functions
  60. virtual void doGetNextFrame();
  61. protected:
  62. int fHNumber;
  63. Boolean fIncludeStartCodeInOutput, fInsertAccessUnitDelimiters;
  64. u_int8_t* fLastSeenVPS;
  65. unsigned fLastSeenVPSSize;
  66. u_int8_t* fLastSeenSPS;
  67. unsigned fLastSeenSPSSize;
  68. u_int8_t* fLastSeenPPS;
  69. unsigned fLastSeenPPSSize;
  70. struct timeval fNextPresentationTime; // the presentation time to be used for the next NAL unit to be parsed/delivered after this
  71. friend class H264or5VideoStreamParser; // hack
  72. };
  73. // A general routine for making a copy of a (H.264 or H.265) NAL unit,
  74. // removing 'emulation' bytes from the copy:
  75. unsigned removeH264or5EmulationBytes(u_int8_t* to, unsigned toMaxSize,
  76. u_int8_t const* from, unsigned fromSize);
  77. // returns the size of the copy; it will be <= min(toMaxSize,fromSize)
  78. #endif