blob: 95a9cb762a03bd61f562d716b3220fbe54083ed6 [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"
Stefan Holmerf7044682018-07-17 10:16:41 +020017#include "api/video_codecs/video_encoder.h"
Stefan Holmerdbdb3a02018-07-17 16:03:46 +020018#include "call/rtp_config.h"
philipelbf2b6202018-08-27 14:33:18 +020019#include "modules/rtp_rtcp/source/rtp_generic_frame_descriptor.h"
Stefan Holmerf7044682018-07-17 10:16:41 +020020#include "modules/rtp_rtcp/source/rtp_video_header.h"
Danil Chapovalov02d71fb2020-02-10 16:22:57 +010021#include "modules/video_coding/frame_dependencies_calculator.h"
Elad Alonf5b216a2019-01-28 14:25:17 +010022#include "modules/video_coding/include/video_codec_interface.h"
Stefan Holmerf7044682018-07-17 10:16:41 +020023
24namespace webrtc {
25
Stefan Holmerf7044682018-07-17 10:16:41 +020026class RtpRtcp;
27
Stefan Holmerf7044682018-07-17 10:16:41 +020028// State for setting picture id and tl0 pic idx, for VP8 and VP9
29// TODO(nisse): Make these properties not codec specific.
30class RtpPayloadParams final {
31 public:
32 RtpPayloadParams(const uint32_t ssrc, const RtpPayloadState* state);
philipelbf2b6202018-08-27 14:33:18 +020033 RtpPayloadParams(const RtpPayloadParams& other);
Stefan Holmerf7044682018-07-17 10:16:41 +020034 ~RtpPayloadParams();
35
philipelbf2b6202018-08-27 14:33:18 +020036 RTPVideoHeader GetRtpVideoHeader(const EncodedImage& image,
37 const CodecSpecificInfo* codec_specific_info,
38 int64_t shared_frame_id);
Stefan Holmerf7044682018-07-17 10:16:41 +020039
40 uint32_t ssrc() const;
41
42 RtpPayloadState state() const;
43
44 private:
philipelbf2b6202018-08-27 14:33:18 +020045 void SetCodecSpecific(RTPVideoHeader* rtp_video_header,
46 bool first_frame_in_picture);
Danil Chapovalov02d71fb2020-02-10 16:22:57 +010047 RTPVideoHeader::GenericDescriptorInfo GenericDescriptorFromFrameInfo(
48 const GenericFrameInfo& frame_info,
49 int64_t frame_id,
50 VideoFrameType frame_type);
Elad Alonf5b216a2019-01-28 14:25:17 +010051 void SetGeneric(const CodecSpecificInfo* codec_specific_info,
52 int64_t frame_id,
philipelbf2b6202018-08-27 14:33:18 +020053 bool is_keyframe,
54 RTPVideoHeader* rtp_video_header);
Stefan Holmerf7044682018-07-17 10:16:41 +020055
Elad Alonf5b216a2019-01-28 14:25:17 +010056 void Vp8ToGeneric(const CodecSpecificInfoVP8& vp8_info,
57 int64_t shared_frame_id,
philipelbf2b6202018-08-27 14:33:18 +020058 bool is_keyframe,
59 RTPVideoHeader* rtp_video_header);
60
philipel8aba8fe2019-06-13 15:13:16 +020061 void H264ToGeneric(const CodecSpecificInfoH264& h264_info,
62 int64_t shared_frame_id,
63 bool is_keyframe,
64 RTPVideoHeader* rtp_video_header);
65
66 void GenericToGeneric(int64_t shared_frame_id,
67 bool is_keyframe,
68 RTPVideoHeader* rtp_video_header);
69
Qingsi Wang1c1b99e2020-01-07 19:16:33 +000070 // TODO(bugs.webrtc.org/10242): Delete SetDependenciesVp8Deprecated() and move
71 // the logic in SetDependenciesVp8New() into Vp8ToGeneric() once all hardware
72 // wrappers have been updated.
73 void SetDependenciesVp8Deprecated(
74 const CodecSpecificInfoVP8& vp8_info,
75 int64_t shared_frame_id,
76 bool is_keyframe,
77 int spatial_index,
78 int temporal_index,
79 bool layer_sync,
80 RTPVideoHeader::GenericDescriptorInfo* generic);
81 void SetDependenciesVp8New(const CodecSpecificInfoVP8& vp8_info,
82 int64_t shared_frame_id,
83 bool is_keyframe,
84 bool layer_sync,
85 RTPVideoHeader::GenericDescriptorInfo* generic);
86
Danil Chapovalov02d71fb2020-02-10 16:22:57 +010087 FrameDependenciesCalculator dependencies_calculator_;
Elad Alonf5b216a2019-01-28 14:25:17 +010088 // TODO(bugs.webrtc.org/10242): Remove once all encoder-wrappers are updated.
philipelbf2b6202018-08-27 14:33:18 +020089 // Holds the last shared frame id for a given (spatial, temporal) layer.
90 std::array<std::array<int64_t, RtpGenericFrameDescriptor::kMaxTemporalLayers>,
91 RtpGenericFrameDescriptor::kMaxSpatialLayers>
92 last_shared_frame_id_;
Elad Alonf5b216a2019-01-28 14:25:17 +010093
94 // TODO(eladalon): When additional codecs are supported,
95 // set kMaxCodecBuffersCount to the max() of these codecs' buffer count.
96 static constexpr size_t kMaxCodecBuffersCount =
97 CodecSpecificInfoVP8::kBuffersCount;
98
99 // Maps buffer IDs to the frame-ID stored in them.
100 std::array<int64_t, kMaxCodecBuffersCount> buffer_id_to_frame_id_;
101
Qingsi Wang1c1b99e2020-01-07 19:16:33 +0000102 // Until we remove SetDependenciesVp8Deprecated(), we should make sure
103 // that, for a given object, we either always use
104 // SetDependenciesVp8Deprecated(), or always use SetDependenciesVp8New().
105 // TODO(bugs.webrtc.org/10242): Remove.
106 absl::optional<bool> new_version_used_;
107
Stefan Holmerf7044682018-07-17 10:16:41 +0200108 const uint32_t ssrc_;
109 RtpPayloadState state_;
philipelbf2b6202018-08-27 14:33:18 +0200110
111 const bool generic_picture_id_experiment_;
philipel569397f2018-09-26 12:25:31 +0200112 const bool generic_descriptor_experiment_;
Stefan Holmerf7044682018-07-17 10:16:41 +0200113};
114} // namespace webrtc
115#endif // CALL_RTP_PAYLOAD_PARAMS_H_