Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 1 | /* |
| 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 Alon | f5b216a | 2019-01-28 14:25:17 +0100 | [diff] [blame] | 14 | #include <array> |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 15 | |
Elad Alon | f5b216a | 2019-01-28 14:25:17 +0100 | [diff] [blame] | 16 | #include "absl/types/optional.h" |
Erik Språng | cbc0cba | 2020-04-18 14:36:59 +0200 | [diff] [blame] | 17 | #include "api/transport/webrtc_key_value_config.h" |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 18 | #include "api/video_codecs/video_encoder.h" |
Stefan Holmer | dbdb3a0 | 2018-07-17 16:03:46 +0200 | [diff] [blame] | 19 | #include "call/rtp_config.h" |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 20 | #include "modules/rtp_rtcp/source/rtp_generic_frame_descriptor.h" |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 21 | #include "modules/rtp_rtcp/source/rtp_video_header.h" |
Danil Chapovalov | 4b860c1 | 2020-05-19 14:48:19 +0200 | [diff] [blame] | 22 | #include "modules/video_coding/chain_diff_calculator.h" |
Danil Chapovalov | 02d71fb | 2020-02-10 16:22:57 +0100 | [diff] [blame] | 23 | #include "modules/video_coding/frame_dependencies_calculator.h" |
Elad Alon | f5b216a | 2019-01-28 14:25:17 +0100 | [diff] [blame] | 24 | #include "modules/video_coding/include/video_codec_interface.h" |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 25 | |
| 26 | namespace webrtc { |
| 27 | |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 28 | class RtpRtcp; |
| 29 | |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 30 | // State for setting picture id and tl0 pic idx, for VP8 and VP9 |
| 31 | // TODO(nisse): Make these properties not codec specific. |
| 32 | class RtpPayloadParams final { |
| 33 | public: |
Erik Språng | cbc0cba | 2020-04-18 14:36:59 +0200 | [diff] [blame] | 34 | RtpPayloadParams(const uint32_t ssrc, |
| 35 | const RtpPayloadState* state, |
| 36 | const WebRtcKeyValueConfig& trials); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 37 | RtpPayloadParams(const RtpPayloadParams& other); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 38 | ~RtpPayloadParams(); |
| 39 | |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 40 | RTPVideoHeader GetRtpVideoHeader(const EncodedImage& image, |
| 41 | const CodecSpecificInfo* codec_specific_info, |
| 42 | int64_t shared_frame_id); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 43 | |
| 44 | uint32_t ssrc() const; |
| 45 | |
| 46 | RtpPayloadState state() const; |
| 47 | |
| 48 | private: |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 49 | void SetCodecSpecific(RTPVideoHeader* rtp_video_header, |
| 50 | bool first_frame_in_picture); |
Danil Chapovalov | 02d71fb | 2020-02-10 16:22:57 +0100 | [diff] [blame] | 51 | RTPVideoHeader::GenericDescriptorInfo GenericDescriptorFromFrameInfo( |
| 52 | const GenericFrameInfo& frame_info, |
Danil Chapovalov | cf1308f | 2020-11-18 18:27:37 +0100 | [diff] [blame] | 53 | int64_t frame_id); |
Elad Alon | f5b216a | 2019-01-28 14:25:17 +0100 | [diff] [blame] | 54 | void SetGeneric(const CodecSpecificInfo* codec_specific_info, |
| 55 | int64_t frame_id, |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 56 | bool is_keyframe, |
| 57 | RTPVideoHeader* rtp_video_header); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 58 | |
Elad Alon | f5b216a | 2019-01-28 14:25:17 +0100 | [diff] [blame] | 59 | void Vp8ToGeneric(const CodecSpecificInfoVP8& vp8_info, |
| 60 | int64_t shared_frame_id, |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 61 | bool is_keyframe, |
| 62 | RTPVideoHeader* rtp_video_header); |
| 63 | |
philipel | 8aba8fe | 2019-06-13 15:13:16 +0200 | [diff] [blame] | 64 | 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 Wang | 1c1b99e | 2020-01-07 19:16:33 +0000 | [diff] [blame] | 73 | // 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 Chapovalov | 02d71fb | 2020-02-10 16:22:57 +0100 | [diff] [blame] | 90 | FrameDependenciesCalculator dependencies_calculator_; |
Danil Chapovalov | 4b860c1 | 2020-05-19 14:48:19 +0200 | [diff] [blame] | 91 | ChainDiffCalculator chains_calculator_; |
Elad Alon | f5b216a | 2019-01-28 14:25:17 +0100 | [diff] [blame] | 92 | // TODO(bugs.webrtc.org/10242): Remove once all encoder-wrappers are updated. |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 93 | // Holds the last shared frame id for a given (spatial, temporal) layer. |
| 94 | std::array<std::array<int64_t, RtpGenericFrameDescriptor::kMaxTemporalLayers>, |
| 95 | RtpGenericFrameDescriptor::kMaxSpatialLayers> |
| 96 | last_shared_frame_id_; |
Elad Alon | f5b216a | 2019-01-28 14:25:17 +0100 | [diff] [blame] | 97 | |
| 98 | // TODO(eladalon): When additional codecs are supported, |
| 99 | // set kMaxCodecBuffersCount to the max() of these codecs' buffer count. |
| 100 | static constexpr size_t kMaxCodecBuffersCount = |
| 101 | CodecSpecificInfoVP8::kBuffersCount; |
| 102 | |
| 103 | // Maps buffer IDs to the frame-ID stored in them. |
| 104 | std::array<int64_t, kMaxCodecBuffersCount> buffer_id_to_frame_id_; |
| 105 | |
Qingsi Wang | 1c1b99e | 2020-01-07 19:16:33 +0000 | [diff] [blame] | 106 | // Until we remove SetDependenciesVp8Deprecated(), we should make sure |
| 107 | // that, for a given object, we either always use |
| 108 | // SetDependenciesVp8Deprecated(), or always use SetDependenciesVp8New(). |
| 109 | // TODO(bugs.webrtc.org/10242): Remove. |
| 110 | absl::optional<bool> new_version_used_; |
| 111 | |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 112 | const uint32_t ssrc_; |
| 113 | RtpPayloadState state_; |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 114 | |
| 115 | const bool generic_picture_id_experiment_; |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 116 | }; |
| 117 | } // namespace webrtc |
| 118 | #endif // CALL_RTP_PAYLOAD_PARAMS_H_ |