blob: 30c4f256f8720b1d2f7b81830b318c107a7066fa [file] [log] [blame]
philipel34852cf2016-11-03 04:03:01 -07001/*
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_VIDEO_CODING_H264_SPS_PPS_TRACKER_H_
12#define MODULES_VIDEO_CODING_H264_SPS_PPS_TRACKER_H_
philipel34852cf2016-11-03 04:03:01 -070013
Danil Chapovalovfbec2ec2019-10-28 13:27:05 +010014#include <cstddef>
philipel34852cf2016-11-03 04:03:01 -070015#include <cstdint>
16#include <map>
17#include <memory>
philipel022b54e2016-12-20 04:15:59 -080018#include <vector>
philipel34852cf2016-11-03 04:03:01 -070019
Danil Chapovalovfbec2ec2019-10-28 13:27:05 +010020#include "api/array_view.h"
21#include "modules/rtp_rtcp/source/rtp_video_header.h"
Danil Chapovalove3c48842019-12-02 15:54:27 +010022#include "rtc_base/copy_on_write_buffer.h"
Danil Chapovalovfbec2ec2019-10-28 13:27:05 +010023
philipel34852cf2016-11-03 04:03:01 -070024namespace webrtc {
philipel34852cf2016-11-03 04:03:01 -070025namespace video_coding {
26
27class H264SpsPpsTracker {
28 public:
philipela75d12d2016-11-07 05:11:28 -080029 enum PacketAction { kInsert, kDrop, kRequestKeyframe };
Danil Chapovalovfbec2ec2019-10-28 13:27:05 +010030 struct FixedBitstream {
31 PacketAction action;
Danil Chapovalove3c48842019-12-02 15:54:27 +010032 rtc::CopyOnWriteBuffer bitstream;
Danil Chapovalovfbec2ec2019-10-28 13:27:05 +010033 };
philipela75d12d2016-11-07 05:11:28 -080034
Mirko Bonadei8fdcac32018-08-28 16:30:18 +020035 H264SpsPpsTracker();
36 ~H264SpsPpsTracker();
37
Danil Chapovalovfbec2ec2019-10-28 13:27:05 +010038 // Returns fixed bitstream and modifies |video_header|.
39 FixedBitstream CopyAndFixBitstream(rtc::ArrayView<const uint8_t> bitstream,
40 RTPVideoHeader* video_header);
johand2b092f2017-01-24 02:38:17 -080041
42 void InsertSpsPpsNalus(const std::vector<uint8_t>& sps,
43 const std::vector<uint8_t>& pps);
philipel34852cf2016-11-03 04:03:01 -070044
45 private:
46 struct PpsInfo {
Mirko Bonadei8fdcac32018-08-28 16:30:18 +020047 PpsInfo();
48 PpsInfo(PpsInfo&& rhs);
49 PpsInfo& operator=(PpsInfo&& rhs);
50 ~PpsInfo();
51
philipel34852cf2016-11-03 04:03:01 -070052 int sps_id = -1;
53 size_t size = 0;
54 std::unique_ptr<uint8_t[]> data;
55 };
56
57 struct SpsInfo {
Mirko Bonadei8fdcac32018-08-28 16:30:18 +020058 SpsInfo();
59 SpsInfo(SpsInfo&& rhs);
60 SpsInfo& operator=(SpsInfo&& rhs);
61 ~SpsInfo();
62
philipel34852cf2016-11-03 04:03:01 -070063 size_t size = 0;
philipel6585f702017-03-17 06:12:33 -070064 int width = -1;
65 int height = -1;
philipel34852cf2016-11-03 04:03:01 -070066 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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020076#endif // MODULES_VIDEO_CODING_H264_SPS_PPS_TRACKER_H_