blob: 13b105037819f5da96247339d8d11f74d0863e78 [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>
Stefan Holmerf7044682018-07-17 10:16:41 +020015
Elad Alonf5b216a2019-01-28 14:25:17 +010016#include "absl/types/optional.h"
Erik Språngcbc0cba2020-04-18 14:36:59 +020017#include "api/transport/webrtc_key_value_config.h"
Stefan Holmerf7044682018-07-17 10:16:41 +020018#include "api/video_codecs/video_encoder.h"
Stefan Holmerdbdb3a02018-07-17 16:03:46 +020019#include "call/rtp_config.h"
philipelbf2b6202018-08-27 14:33:18 +020020#include "modules/rtp_rtcp/source/rtp_generic_frame_descriptor.h"
Stefan Holmerf7044682018-07-17 10:16:41 +020021#include "modules/rtp_rtcp/source/rtp_video_header.h"
Danil Chapovalov02d71fb2020-02-10 16:22:57 +010022#include "modules/video_coding/frame_dependencies_calculator.h"
Elad Alonf5b216a2019-01-28 14:25:17 +010023#include "modules/video_coding/include/video_codec_interface.h"
Stefan Holmerf7044682018-07-17 10:16:41 +020024
25namespace webrtc {
26
Stefan Holmerf7044682018-07-17 10:16:41 +020027class RtpRtcp;
28
Stefan Holmerf7044682018-07-17 10:16:41 +020029// State for setting picture id and tl0 pic idx, for VP8 and VP9
30// TODO(nisse): Make these properties not codec specific.
31class RtpPayloadParams final {
32 public:
Erik Språngcbc0cba2020-04-18 14:36:59 +020033 RtpPayloadParams(const uint32_t ssrc,
34 const RtpPayloadState* state,
35 const WebRtcKeyValueConfig& trials);
philipelbf2b6202018-08-27 14:33:18 +020036 RtpPayloadParams(const RtpPayloadParams& other);
Stefan Holmerf7044682018-07-17 10:16:41 +020037 ~RtpPayloadParams();
38
philipelbf2b6202018-08-27 14:33:18 +020039 RTPVideoHeader GetRtpVideoHeader(const EncodedImage& image,
40 const CodecSpecificInfo* codec_specific_info,
41 int64_t shared_frame_id);
Stefan Holmerf7044682018-07-17 10:16:41 +020042
43 uint32_t ssrc() const;
44
45 RtpPayloadState state() const;
46
47 private:
philipelbf2b6202018-08-27 14:33:18 +020048 void SetCodecSpecific(RTPVideoHeader* rtp_video_header,
49 bool first_frame_in_picture);
Danil Chapovalov02d71fb2020-02-10 16:22:57 +010050 RTPVideoHeader::GenericDescriptorInfo GenericDescriptorFromFrameInfo(
51 const GenericFrameInfo& frame_info,
52 int64_t frame_id,
53 VideoFrameType frame_type);
Elad Alonf5b216a2019-01-28 14:25:17 +010054 void SetGeneric(const CodecSpecificInfo* codec_specific_info,
55 int64_t frame_id,
philipelbf2b6202018-08-27 14:33:18 +020056 bool is_keyframe,
57 RTPVideoHeader* rtp_video_header);
Stefan Holmerf7044682018-07-17 10:16:41 +020058
Elad Alonf5b216a2019-01-28 14:25:17 +010059 void Vp8ToGeneric(const CodecSpecificInfoVP8& vp8_info,
60 int64_t shared_frame_id,
philipelbf2b6202018-08-27 14:33:18 +020061 bool is_keyframe,
62 RTPVideoHeader* rtp_video_header);
63
philipel8aba8fe2019-06-13 15:13:16 +020064 void H264ToGeneric(const CodecSpecificInfoH264& h264_info,
65 int64_t shared_frame_id,
66 bool is_keyframe,
67 RTPVideoHeader* rtp_video_header);
68
69 void GenericToGeneric(int64_t shared_frame_id,
70 bool is_keyframe,
71 RTPVideoHeader* rtp_video_header);
72
Qingsi Wang1c1b99e2020-01-07 19:16:33 +000073 // TODO(bugs.webrtc.org/10242): Delete SetDependenciesVp8Deprecated() and move
74 // the logic in SetDependenciesVp8New() into Vp8ToGeneric() once all hardware
75 // wrappers have been updated.
76 void SetDependenciesVp8Deprecated(
77 const CodecSpecificInfoVP8& vp8_info,
78 int64_t shared_frame_id,
79 bool is_keyframe,
80 int spatial_index,
81 int temporal_index,
82 bool layer_sync,
83 RTPVideoHeader::GenericDescriptorInfo* generic);
84 void SetDependenciesVp8New(const CodecSpecificInfoVP8& vp8_info,
85 int64_t shared_frame_id,
86 bool is_keyframe,
87 bool layer_sync,
88 RTPVideoHeader::GenericDescriptorInfo* generic);
89
Danil Chapovalov02d71fb2020-02-10 16:22:57 +010090 FrameDependenciesCalculator dependencies_calculator_;
Elad Alonf5b216a2019-01-28 14:25:17 +010091 // TODO(bugs.webrtc.org/10242): Remove once all encoder-wrappers are updated.
philipelbf2b6202018-08-27 14:33:18 +020092 // Holds the last shared frame id for a given (spatial, temporal) layer.
93 std::array<std::array<int64_t, RtpGenericFrameDescriptor::kMaxTemporalLayers>,
94 RtpGenericFrameDescriptor::kMaxSpatialLayers>
95 last_shared_frame_id_;
Elad Alonf5b216a2019-01-28 14:25:17 +010096
97 // TODO(eladalon): When additional codecs are supported,
98 // set kMaxCodecBuffersCount to the max() of these codecs' buffer count.
99 static constexpr size_t kMaxCodecBuffersCount =
100 CodecSpecificInfoVP8::kBuffersCount;
101
102 // Maps buffer IDs to the frame-ID stored in them.
103 std::array<int64_t, kMaxCodecBuffersCount> buffer_id_to_frame_id_;
104
Qingsi Wang1c1b99e2020-01-07 19:16:33 +0000105 // Until we remove SetDependenciesVp8Deprecated(), we should make sure
106 // that, for a given object, we either always use
107 // SetDependenciesVp8Deprecated(), or always use SetDependenciesVp8New().
108 // TODO(bugs.webrtc.org/10242): Remove.
109 absl::optional<bool> new_version_used_;
110
Stefan Holmerf7044682018-07-17 10:16:41 +0200111 const uint32_t ssrc_;
112 RtpPayloadState state_;
philipelbf2b6202018-08-27 14:33:18 +0200113
114 const bool generic_picture_id_experiment_;
philipel569397f2018-09-26 12:25:31 +0200115 const bool generic_descriptor_experiment_;
Stefan Holmerf7044682018-07-17 10:16:41 +0200116};
117} // namespace webrtc
118#endif // CALL_RTP_PAYLOAD_PARAMS_H_