blob: 2f37400c5f6b0163bc35402902bccef914c06a85 [file] [log] [blame]
Stefan Holmerf7044682018-07-17 10:16:41 +02001/*
2 * Copyright (c) 2018 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 CALL_RTP_PAYLOAD_PARAMS_H_
12#define CALL_RTP_PAYLOAD_PARAMS_H_
13
Elad Alonf5b216a2019-01-28 14:25:17 +010014#include <array>
Danil Chapovalovaf366442021-04-22 15:20:28 +020015#include <vector>
Stefan Holmerf7044682018-07-17 10:16:41 +020016
Elad Alonf5b216a2019-01-28 14:25:17 +010017#include "absl/types/optional.h"
Erik Språngcbc0cba2020-04-18 14:36:59 +020018#include "api/transport/webrtc_key_value_config.h"
Stefan Holmerf7044682018-07-17 10:16:41 +020019#include "api/video_codecs/video_encoder.h"
Stefan Holmerdbdb3a02018-07-17 16:03:46 +020020#include "call/rtp_config.h"
philipelbf2b6202018-08-27 14:33:18 +020021#include "modules/rtp_rtcp/source/rtp_generic_frame_descriptor.h"
Stefan Holmerf7044682018-07-17 10:16:41 +020022#include "modules/rtp_rtcp/source/rtp_video_header.h"
Danil Chapovalov4b860c12020-05-19 14:48:19 +020023#include "modules/video_coding/chain_diff_calculator.h"
Danil Chapovalov02d71fb2020-02-10 16:22:57 +010024#include "modules/video_coding/frame_dependencies_calculator.h"
Elad Alonf5b216a2019-01-28 14:25:17 +010025#include "modules/video_coding/include/video_codec_interface.h"
Stefan Holmerf7044682018-07-17 10:16:41 +020026
27namespace webrtc {
28
Stefan Holmerf7044682018-07-17 10:16:41 +020029class RtpRtcp;
30
Stefan Holmerf7044682018-07-17 10:16:41 +020031// State for setting picture id and tl0 pic idx, for VP8 and VP9
32// TODO(nisse): Make these properties not codec specific.
33class RtpPayloadParams final {
34 public:
Erik Språngcbc0cba2020-04-18 14:36:59 +020035 RtpPayloadParams(const uint32_t ssrc,
36 const RtpPayloadState* state,
37 const WebRtcKeyValueConfig& trials);
philipelbf2b6202018-08-27 14:33:18 +020038 RtpPayloadParams(const RtpPayloadParams& other);
Stefan Holmerf7044682018-07-17 10:16:41 +020039 ~RtpPayloadParams();
40
philipelbf2b6202018-08-27 14:33:18 +020041 RTPVideoHeader GetRtpVideoHeader(const EncodedImage& image,
42 const CodecSpecificInfo* codec_specific_info,
43 int64_t shared_frame_id);
Stefan Holmerf7044682018-07-17 10:16:41 +020044
45 uint32_t ssrc() const;
46
47 RtpPayloadState state() const;
48
49 private:
philipelbf2b6202018-08-27 14:33:18 +020050 void SetCodecSpecific(RTPVideoHeader* rtp_video_header,
51 bool first_frame_in_picture);
Danil Chapovalov02d71fb2020-02-10 16:22:57 +010052 RTPVideoHeader::GenericDescriptorInfo GenericDescriptorFromFrameInfo(
53 const GenericFrameInfo& frame_info,
Danil Chapovalovcf1308f2020-11-18 18:27:37 +010054 int64_t frame_id);
Elad Alonf5b216a2019-01-28 14:25:17 +010055 void SetGeneric(const CodecSpecificInfo* codec_specific_info,
56 int64_t frame_id,
philipelbf2b6202018-08-27 14:33:18 +020057 bool is_keyframe,
58 RTPVideoHeader* rtp_video_header);
Stefan Holmerf7044682018-07-17 10:16:41 +020059
Elad Alonf5b216a2019-01-28 14:25:17 +010060 void Vp8ToGeneric(const CodecSpecificInfoVP8& vp8_info,
61 int64_t shared_frame_id,
philipelbf2b6202018-08-27 14:33:18 +020062 bool is_keyframe,
63 RTPVideoHeader* rtp_video_header);
64
Danil Chapovalovaf366442021-04-22 15:20:28 +020065 void Vp9ToGeneric(const CodecSpecificInfoVP9& vp9_info,
66 int64_t shared_frame_id,
67 RTPVideoHeader& rtp_video_header);
68
philipel8aba8fe2019-06-13 15:13:16 +020069 void H264ToGeneric(const CodecSpecificInfoH264& h264_info,
70 int64_t shared_frame_id,
71 bool is_keyframe,
72 RTPVideoHeader* rtp_video_header);
73
74 void GenericToGeneric(int64_t shared_frame_id,
75 bool is_keyframe,
76 RTPVideoHeader* rtp_video_header);
77
Qingsi Wang1c1b99e2020-01-07 19:16:33 +000078 // TODO(bugs.webrtc.org/10242): Delete SetDependenciesVp8Deprecated() and move
79 // the logic in SetDependenciesVp8New() into Vp8ToGeneric() once all hardware
80 // wrappers have been updated.
81 void SetDependenciesVp8Deprecated(
82 const CodecSpecificInfoVP8& vp8_info,
83 int64_t shared_frame_id,
84 bool is_keyframe,
85 int spatial_index,
86 int temporal_index,
87 bool layer_sync,
88 RTPVideoHeader::GenericDescriptorInfo* generic);
89 void SetDependenciesVp8New(const CodecSpecificInfoVP8& vp8_info,
90 int64_t shared_frame_id,
91 bool is_keyframe,
92 bool layer_sync,
93 RTPVideoHeader::GenericDescriptorInfo* generic);
94
Danil Chapovalov02d71fb2020-02-10 16:22:57 +010095 FrameDependenciesCalculator dependencies_calculator_;
Danil Chapovalov4b860c12020-05-19 14:48:19 +020096 ChainDiffCalculator chains_calculator_;
Elad Alonf5b216a2019-01-28 14:25:17 +010097 // TODO(bugs.webrtc.org/10242): Remove once all encoder-wrappers are updated.
philipelbf2b6202018-08-27 14:33:18 +020098 // Holds the last shared frame id for a given (spatial, temporal) layer.
99 std::array<std::array<int64_t, RtpGenericFrameDescriptor::kMaxTemporalLayers>,
100 RtpGenericFrameDescriptor::kMaxSpatialLayers>
101 last_shared_frame_id_;
Danil Chapovalovaf366442021-04-22 15:20:28 +0200102 // circular buffer of frame ids for the last 128 vp9 pictures.
103 // ids for the `picture_id` are stored at the index `picture_id % 128`.
104 std::vector<std::array<int64_t, RtpGenericFrameDescriptor::kMaxSpatialLayers>>
105 last_vp9_frame_id_;
106 // Last frame id for each chain
107 std::array<int64_t, RtpGenericFrameDescriptor::kMaxSpatialLayers>
108 chain_last_frame_id_;
Elad Alonf5b216a2019-01-28 14:25:17 +0100109
110 // TODO(eladalon): When additional codecs are supported,
111 // set kMaxCodecBuffersCount to the max() of these codecs' buffer count.
112 static constexpr size_t kMaxCodecBuffersCount =
113 CodecSpecificInfoVP8::kBuffersCount;
114
115 // Maps buffer IDs to the frame-ID stored in them.
116 std::array<int64_t, kMaxCodecBuffersCount> buffer_id_to_frame_id_;
117
Qingsi Wang1c1b99e2020-01-07 19:16:33 +0000118 // Until we remove SetDependenciesVp8Deprecated(), we should make sure
119 // that, for a given object, we either always use
120 // SetDependenciesVp8Deprecated(), or always use SetDependenciesVp8New().
121 // TODO(bugs.webrtc.org/10242): Remove.
122 absl::optional<bool> new_version_used_;
123
Stefan Holmerf7044682018-07-17 10:16:41 +0200124 const uint32_t ssrc_;
125 RtpPayloadState state_;
philipelbf2b6202018-08-27 14:33:18 +0200126
127 const bool generic_picture_id_experiment_;
Danil Chapovalovaf366442021-04-22 15:20:28 +0200128 const bool simulate_generic_vp9_;
Stefan Holmerf7044682018-07-17 10:16:41 +0200129};
130} // namespace webrtc
131#endif // CALL_RTP_PAYLOAD_PARAMS_H_