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 11 #ifndef MODULES_VIDEO_CODING_H264_SPS_PPS_TRACKER_H_ 12 #define MODULES_VIDEO_CODING_H264_SPS_PPS_TRACKER_H_ 13 14 #include <cstddef> 15 #include <cstdint> 16 #include <map> 17 #include <memory> 18 #include <vector> 19 20 #include "api/array_view.h" 21 #include "modules/rtp_rtcp/source/rtp_video_header.h" 22 #include "rtc_base/copy_on_write_buffer.h" 23 24 namespace webrtc { 25 namespace video_coding { 26 27 class H264SpsPpsTracker { 28 public: 29 enum PacketAction { kInsert, kDrop, kRequestKeyframe }; 30 struct FixedBitstream { 31 PacketAction action; 32 rtc::CopyOnWriteBuffer bitstream; 33 }; 34 35 H264SpsPpsTracker(); 36 ~H264SpsPpsTracker(); 37 38 // Returns fixed bitstream and modifies `video_header`. 39 FixedBitstream CopyAndFixBitstream(rtc::ArrayView<const uint8_t> bitstream, 40 RTPVideoHeader* video_header); 41 42 void InsertSpsPpsNalus(const std::vector<uint8_t>& sps, 43 const std::vector<uint8_t>& pps); 44 45 private: 46 struct PpsInfo { 47 PpsInfo(); 48 PpsInfo(PpsInfo&& rhs); 49 PpsInfo& operator=(PpsInfo&& rhs); 50 ~PpsInfo(); 51 52 int sps_id = -1; 53 size_t size = 0; 54 std::unique_ptr<uint8_t[]> data; 55 }; 56 57 struct SpsInfo { 58 SpsInfo(); 59 SpsInfo(SpsInfo&& rhs); 60 SpsInfo& operator=(SpsInfo&& rhs); 61 ~SpsInfo(); 62 63 size_t size = 0; 64 int width = -1; 65 int height = -1; 66 std::unique_ptr<uint8_t[]> data; 67 }; 68 69 std::map<uint32_t, PpsInfo> pps_data_; 70 std::map<uint32_t, SpsInfo> sps_data_; 71 }; 72 73 } // namespace video_coding 74 } // namespace webrtc 75 76 #endif // MODULES_VIDEO_CODING_H264_SPS_PPS_TRACKER_H_ 77