blob: 605e294e08b16f6dbc37c5927303cb9a3d838778 [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"
Elad Alonf5b216a2019-01-28 14:25:17 +010021#include "modules/video_coding/include/video_codec_interface.h"
Stefan Holmerf7044682018-07-17 10:16:41 +020022
23namespace webrtc {
24
25class RTPFragmentationHeader;
26class 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);
Elad Alonf5b216a2019-01-28 14:25:17 +010047 void SetGeneric(const CodecSpecificInfo* codec_specific_info,
48 int64_t frame_id,
philipelbf2b6202018-08-27 14:33:18 +020049 bool is_keyframe,
50 RTPVideoHeader* rtp_video_header);
Stefan Holmerf7044682018-07-17 10:16:41 +020051
Elad Alonf5b216a2019-01-28 14:25:17 +010052 void Vp8ToGeneric(const CodecSpecificInfoVP8& vp8_info,
53 int64_t shared_frame_id,
philipelbf2b6202018-08-27 14:33:18 +020054 bool is_keyframe,
55 RTPVideoHeader* rtp_video_header);
56
Elad Alonf5b216a2019-01-28 14:25:17 +010057 // TODO(bugs.webrtc.org/10242): Delete SetDependenciesVp8Deprecated() and move
58 // the logic in SetDependenciesVp8New() into Vp8ToGeneric() once all hardware
59 // wrappers have been updated.
60 void SetDependenciesVp8Deprecated(
61 const CodecSpecificInfoVP8& vp8_info,
62 int64_t shared_frame_id,
63 bool is_keyframe,
64 int spatial_index,
65 int temporal_index,
66 bool layer_sync,
67 RTPVideoHeader::GenericDescriptorInfo* generic);
68 void SetDependenciesVp8New(const CodecSpecificInfoVP8& vp8_info,
69 int64_t shared_frame_id,
70 bool is_keyframe,
71 bool layer_sync,
72 RTPVideoHeader::GenericDescriptorInfo* generic);
73
74 // TODO(bugs.webrtc.org/10242): Remove once all encoder-wrappers are updated.
philipelbf2b6202018-08-27 14:33:18 +020075 // Holds the last shared frame id for a given (spatial, temporal) layer.
76 std::array<std::array<int64_t, RtpGenericFrameDescriptor::kMaxTemporalLayers>,
77 RtpGenericFrameDescriptor::kMaxSpatialLayers>
78 last_shared_frame_id_;
Elad Alonf5b216a2019-01-28 14:25:17 +010079
80 // TODO(eladalon): When additional codecs are supported,
81 // set kMaxCodecBuffersCount to the max() of these codecs' buffer count.
82 static constexpr size_t kMaxCodecBuffersCount =
83 CodecSpecificInfoVP8::kBuffersCount;
84
85 // Maps buffer IDs to the frame-ID stored in them.
86 std::array<int64_t, kMaxCodecBuffersCount> buffer_id_to_frame_id_;
87
88 // Until we remove SetDependenciesVp8Deprecated(), we should make sure
89 // that, for a given object, we either always use
90 // SetDependenciesVp8Deprecated(), or always use SetDependenciesVp8New().
91 // TODO(bugs.webrtc.org/10242): Remove.
92 absl::optional<bool> new_version_used_;
93
Stefan Holmerf7044682018-07-17 10:16:41 +020094 const uint32_t ssrc_;
95 RtpPayloadState state_;
philipelbf2b6202018-08-27 14:33:18 +020096
97 const bool generic_picture_id_experiment_;
philipel569397f2018-09-26 12:25:31 +020098 const bool generic_descriptor_experiment_;
Stefan Holmerf7044682018-07-17 10:16:41 +020099};
100} // namespace webrtc
101#endif // CALL_RTP_PAYLOAD_PARAMS_H_