blob: 2e0faeb5c9976bc0728763595e8545e91749388b [file] [log] [blame]
Stefan Holmerf7044682018-07-17 08:16:411/*
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 13:25:1714#include <array>
Stefan Holmerf7044682018-07-17 08:16:4115
Elad Alonf5b216a2019-01-28 13:25:1716#include "absl/types/optional.h"
Erik Språngcbc0cba2020-04-18 12:36:5917#include "api/transport/webrtc_key_value_config.h"
Stefan Holmerf7044682018-07-17 08:16:4118#include "api/video_codecs/video_encoder.h"
Stefan Holmerdbdb3a02018-07-17 14:03:4619#include "call/rtp_config.h"
philipelbf2b6202018-08-27 12:33:1820#include "modules/rtp_rtcp/source/rtp_generic_frame_descriptor.h"
Stefan Holmerf7044682018-07-17 08:16:4121#include "modules/rtp_rtcp/source/rtp_video_header.h"
Danil Chapovalov4b860c12020-05-19 12:48:1922#include "modules/video_coding/chain_diff_calculator.h"
Danil Chapovalov02d71fb2020-02-10 15:22:5723#include "modules/video_coding/frame_dependencies_calculator.h"
Elad Alonf5b216a2019-01-28 13:25:1724#include "modules/video_coding/include/video_codec_interface.h"
Stefan Holmerf7044682018-07-17 08:16:4125
26namespace webrtc {
27
Stefan Holmerf7044682018-07-17 08:16:4128class RtpRtcp;
29
Stefan Holmerf7044682018-07-17 08:16:4130// State for setting picture id and tl0 pic idx, for VP8 and VP9
31// TODO(nisse): Make these properties not codec specific.
32class RtpPayloadParams final {
33 public:
Erik Språngcbc0cba2020-04-18 12:36:5934 RtpPayloadParams(const uint32_t ssrc,
35 const RtpPayloadState* state,
36 const WebRtcKeyValueConfig& trials);
philipelbf2b6202018-08-27 12:33:1837 RtpPayloadParams(const RtpPayloadParams& other);
Stefan Holmerf7044682018-07-17 08:16:4138 ~RtpPayloadParams();
39
philipelbf2b6202018-08-27 12:33:1840 RTPVideoHeader GetRtpVideoHeader(const EncodedImage& image,
41 const CodecSpecificInfo* codec_specific_info,
42 int64_t shared_frame_id);
Stefan Holmerf7044682018-07-17 08:16:4143
44 uint32_t ssrc() const;
45
46 RtpPayloadState state() const;
47
48 private:
philipelbf2b6202018-08-27 12:33:1849 void SetCodecSpecific(RTPVideoHeader* rtp_video_header,
50 bool first_frame_in_picture);
Danil Chapovalov02d71fb2020-02-10 15:22:5751 RTPVideoHeader::GenericDescriptorInfo GenericDescriptorFromFrameInfo(
52 const GenericFrameInfo& frame_info,
53 int64_t frame_id,
54 VideoFrameType frame_type);
Elad Alonf5b216a2019-01-28 13:25:1755 void SetGeneric(const CodecSpecificInfo* codec_specific_info,
56 int64_t frame_id,
philipelbf2b6202018-08-27 12:33:1857 bool is_keyframe,
58 RTPVideoHeader* rtp_video_header);
Stefan Holmerf7044682018-07-17 08:16:4159
Elad Alonf5b216a2019-01-28 13:25:1760 void Vp8ToGeneric(const CodecSpecificInfoVP8& vp8_info,
61 int64_t shared_frame_id,
philipelbf2b6202018-08-27 12:33:1862 bool is_keyframe,
63 RTPVideoHeader* rtp_video_header);
64
philipel8aba8fe2019-06-13 13:13:1665 void H264ToGeneric(const CodecSpecificInfoH264& h264_info,
66 int64_t shared_frame_id,
67 bool is_keyframe,
68 RTPVideoHeader* rtp_video_header);
69
70 void GenericToGeneric(int64_t shared_frame_id,
71 bool is_keyframe,
72 RTPVideoHeader* rtp_video_header);
73
Qingsi Wang1c1b99e2020-01-07 19:16:3374 // TODO(bugs.webrtc.org/10242): Delete SetDependenciesVp8Deprecated() and move
75 // the logic in SetDependenciesVp8New() into Vp8ToGeneric() once all hardware
76 // wrappers have been updated.
77 void SetDependenciesVp8Deprecated(
78 const CodecSpecificInfoVP8& vp8_info,
79 int64_t shared_frame_id,
80 bool is_keyframe,
81 int spatial_index,
82 int temporal_index,
83 bool layer_sync,
84 RTPVideoHeader::GenericDescriptorInfo* generic);
85 void SetDependenciesVp8New(const CodecSpecificInfoVP8& vp8_info,
86 int64_t shared_frame_id,
87 bool is_keyframe,
88 bool layer_sync,
89 RTPVideoHeader::GenericDescriptorInfo* generic);
90
Danil Chapovalov02d71fb2020-02-10 15:22:5791 FrameDependenciesCalculator dependencies_calculator_;
Danil Chapovalov4b860c12020-05-19 12:48:1992 ChainDiffCalculator chains_calculator_;
Elad Alonf5b216a2019-01-28 13:25:1793 // TODO(bugs.webrtc.org/10242): Remove once all encoder-wrappers are updated.
philipelbf2b6202018-08-27 12:33:1894 // Holds the last shared frame id for a given (spatial, temporal) layer.
95 std::array<std::array<int64_t, RtpGenericFrameDescriptor::kMaxTemporalLayers>,
96 RtpGenericFrameDescriptor::kMaxSpatialLayers>
97 last_shared_frame_id_;
Elad Alonf5b216a2019-01-28 13:25:1798
99 // TODO(eladalon): When additional codecs are supported,
100 // set kMaxCodecBuffersCount to the max() of these codecs' buffer count.
101 static constexpr size_t kMaxCodecBuffersCount =
102 CodecSpecificInfoVP8::kBuffersCount;
103
104 // Maps buffer IDs to the frame-ID stored in them.
105 std::array<int64_t, kMaxCodecBuffersCount> buffer_id_to_frame_id_;
106
Qingsi Wang1c1b99e2020-01-07 19:16:33107 // Until we remove SetDependenciesVp8Deprecated(), we should make sure
108 // that, for a given object, we either always use
109 // SetDependenciesVp8Deprecated(), or always use SetDependenciesVp8New().
110 // TODO(bugs.webrtc.org/10242): Remove.
111 absl::optional<bool> new_version_used_;
112
Stefan Holmerf7044682018-07-17 08:16:41113 const uint32_t ssrc_;
114 RtpPayloadState state_;
philipelbf2b6202018-08-27 12:33:18115
116 const bool generic_picture_id_experiment_;
Stefan Holmerf7044682018-07-17 08:16:41117};
118} // namespace webrtc
119#endif // CALL_RTP_PAYLOAD_PARAMS_H_