h264_sps_pps_tracker.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef MODULES_VIDEO_CODING_H264_SPS_PPS_TRACKER_H_
  11. #define MODULES_VIDEO_CODING_H264_SPS_PPS_TRACKER_H_
  12. #include <cstddef>
  13. #include <cstdint>
  14. #include <map>
  15. #include <memory>
  16. #include <vector>
  17. #include "api/array_view.h"
  18. #include "modules/rtp_rtcp/source/rtp_video_header.h"
  19. #include "rtc_base/copy_on_write_buffer.h"
  20. namespace webrtc {
  21. namespace video_coding {
  22. class H264SpsPpsTracker {
  23. public:
  24. enum PacketAction { kInsert, kDrop, kRequestKeyframe };
  25. struct FixedBitstream {
  26. PacketAction action;
  27. rtc::CopyOnWriteBuffer bitstream;
  28. };
  29. H264SpsPpsTracker();
  30. ~H264SpsPpsTracker();
  31. // Returns fixed bitstream and modifies |video_header|.
  32. FixedBitstream CopyAndFixBitstream(rtc::ArrayView<const uint8_t> bitstream,
  33. RTPVideoHeader* video_header);
  34. void InsertSpsPpsNalus(const std::vector<uint8_t>& sps,
  35. const std::vector<uint8_t>& pps);
  36. private:
  37. struct PpsInfo {
  38. PpsInfo();
  39. PpsInfo(PpsInfo&& rhs);
  40. PpsInfo& operator=(PpsInfo&& rhs);
  41. ~PpsInfo();
  42. int sps_id = -1;
  43. size_t size = 0;
  44. std::unique_ptr<uint8_t[]> data;
  45. };
  46. struct SpsInfo {
  47. SpsInfo();
  48. SpsInfo(SpsInfo&& rhs);
  49. SpsInfo& operator=(SpsInfo&& rhs);
  50. ~SpsInfo();
  51. size_t size = 0;
  52. int width = -1;
  53. int height = -1;
  54. std::unique_ptr<uint8_t[]> data;
  55. };
  56. std::map<uint32_t, PpsInfo> pps_data_;
  57. std::map<uint32_t, SpsInfo> sps_data_;
  58. };
  59. } // namespace video_coding
  60. } // namespace webrtc
  61. #endif // MODULES_VIDEO_CODING_H264_SPS_PPS_TRACKER_H_