File: h26x_packet_buffer.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (109 lines) | stat: -rw-r--r-- 3,787 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
 *  Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#ifndef MODULES_VIDEO_CODING_H26X_PACKET_BUFFER_H_
#define MODULES_VIDEO_CODING_H26X_PACKET_BUFFER_H_

#include <array>
#include <cstddef>
#include <cstdint>
#include <map>
#include <memory>
#include <string>
#include <vector>

#include "absl/base/attributes.h"
#include "modules/video_coding/packet_buffer.h"

namespace webrtc {

class H26xPacketBuffer {
 public:
  // The H26xPacketBuffer does the same job as the PacketBuffer but for H264 and
  // H265 only. To make it fit in with surronding code the PacketBuffer
  // input/output classes are used.
  using Packet = video_coding::PacketBuffer::Packet;
  using InsertResult = video_coding::PacketBuffer::InsertResult;

  // |h264_idr_only_keyframes_allowed| is ignored if H.265 is used.
  explicit H26xPacketBuffer(bool h264_idr_only_keyframes_allowed);

  ABSL_MUST_USE_RESULT InsertResult
  InsertPacket(std::unique_ptr<Packet> packet);
  ABSL_MUST_USE_RESULT InsertResult InsertPadding(uint16_t unwrapped_seq_num);

  // Out of band supplied codec parameters for H.264.
  void SetSpropParameterSets(const std::string& sprop_parameter_sets);

 private:
  // Stores PPS payload and the active SPS ID.
  struct PpsInfo {
    PpsInfo() = default;
    PpsInfo(PpsInfo&& rhs) = default;
    PpsInfo& operator=(PpsInfo&& rhs) = default;
    ~PpsInfo() = default;

    // The value of sps_seq_parameter_set_id for the active SPS.
    uint32_t sps_id = 0;
    // Payload size.
    size_t size = 0;
    std::unique_ptr<uint8_t[]> payload;
  };

  // Stores SPS payload and picture size.
  struct SpsInfo {
    SpsInfo() = default;
    SpsInfo(SpsInfo&& rhs) = default;
    SpsInfo& operator=(SpsInfo&& rhs) = default;
    ~SpsInfo() = default;

    // The width and height of decoded pictures.
    int width = -1;
    int height = -1;
    // Payload size.
    size_t size = 0;
    std::unique_ptr<uint8_t[]> payload;
  };

  static constexpr int kBufferSize = 2048;
  static constexpr int kNumTrackedSequences = 5;

  std::unique_ptr<Packet>& GetPacket(int64_t unwrapped_seq_num);
  bool BeginningOfStream(const Packet& packet) const;
  InsertResult FindFrames(int64_t unwrapped_seq_num);
  bool MaybeAssembleFrame(int64_t start_seq_num_unwrapped,
                          int64_t end_sequence_number_unwrapped,
                          InsertResult& result);
  // Store SPS and PPS nalus. They will be used later when an IDR frame is
  // received without SPS/PPS.
  void InsertSpsPpsNalus(const std::vector<uint8_t>& sps,
                         const std::vector<uint8_t>& pps);
  // Insert start code and paramter sets for H.264 payload, also update header
  // if parameter sets are inserted. Return false if required SPS or PPS is not
  // found.
  bool FixH264Packet(Packet& packet);

  // Indicates whether IDR frames without SPS and PPS are allowed.
  const bool h264_idr_only_keyframes_allowed_;
  std::array<std::unique_ptr<Packet>, kBufferSize> buffer_;
  std::array<int64_t, kNumTrackedSequences> last_continuous_in_sequence_;
  int64_t last_continuous_in_sequence_index_ = 0;

  // Map from pps_pic_parameter_set_id to the PPS payload associated with this
  // ID.
  std::map<int, PpsInfo> pps_data_;
  // Map from sps_video_parameter_set_id to the SPS payload associated with this
  // ID.
  std::map<int, SpsInfo> sps_data_;
};

}  // namespace webrtc

#endif  // MODULES_VIDEO_CODING_H26X_PACKET_BUFFER_H_