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> |
Danil Chapovalov | af36644 | 2021-04-22 15:20:28 +0200 | [diff] [blame] | 15 | #include <vector> |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 16 | |
Elad Alon | f5b216a | 2019-01-28 14:25:17 +0100 | [diff] [blame] | 17 | #include "absl/types/optional.h" |
Jonas Oreland | e62c2f2 | 2022-03-29 11:04:48 +0200 | [diff] [blame] | 18 | #include "api/field_trials_view.h" |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 19 | #include "api/video_codecs/video_encoder.h" |
Stefan Holmer | dbdb3a0 | 2018-07-17 16:03:46 +0200 | [diff] [blame] | 20 | #include "call/rtp_config.h" |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 21 | #include "modules/rtp_rtcp/source/rtp_generic_frame_descriptor.h" |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 22 | #include "modules/rtp_rtcp/source/rtp_video_header.h" |
Danil Chapovalov | 4b860c1 | 2020-05-19 14:48:19 +0200 | [diff] [blame] | 23 | #include "modules/video_coding/chain_diff_calculator.h" |
Danil Chapovalov | 02d71fb | 2020-02-10 16:22:57 +0100 | [diff] [blame] | 24 | #include "modules/video_coding/frame_dependencies_calculator.h" |
Elad Alon | f5b216a | 2019-01-28 14:25:17 +0100 | [diff] [blame] | 25 | #include "modules/video_coding/include/video_codec_interface.h" |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 26 | |
| 27 | namespace webrtc { |
| 28 | |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 29 | // State for setting picture id and tl0 pic idx, for VP8 and VP9 |
| 30 | // TODO(nisse): Make these properties not codec specific. |
| 31 | class RtpPayloadParams final { |
| 32 | public: |
Ali Tofigh | 6223809 | 2022-01-25 13:27:19 +0100 | [diff] [blame] | 33 | RtpPayloadParams(uint32_t ssrc, |
Erik Språng | cbc0cba | 2020-04-18 14:36:59 +0200 | [diff] [blame] | 34 | const RtpPayloadState* state, |
Jonas Oreland | e62c2f2 | 2022-03-29 11:04:48 +0200 | [diff] [blame] | 35 | const FieldTrialsView& trials); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 36 | RtpPayloadParams(const RtpPayloadParams& other); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 37 | ~RtpPayloadParams(); |
| 38 | |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 39 | RTPVideoHeader GetRtpVideoHeader(const EncodedImage& image, |
| 40 | const CodecSpecificInfo* codec_specific_info, |
| 41 | int64_t shared_frame_id); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 42 | |
Danil Chapovalov | 5b298ab | 2022-06-08 11:18:51 +0200 | [diff] [blame] | 43 | // Returns structure that aligns with simulated generic info generated by |
| 44 | // `GetRtpVideoHeader` for the `codec_specific_info` |
| 45 | absl::optional<FrameDependencyStructure> GenericStructure( |
| 46 | const CodecSpecificInfo* codec_specific_info); |
Danil Chapovalov | 748550d | 2021-04-29 11:42:54 +0200 | [diff] [blame] | 47 | |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 48 | uint32_t ssrc() const; |
| 49 | |
| 50 | RtpPayloadState state() const; |
| 51 | |
| 52 | private: |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 53 | void SetCodecSpecific(RTPVideoHeader* rtp_video_header, |
| 54 | bool first_frame_in_picture); |
Danil Chapovalov | 02d71fb | 2020-02-10 16:22:57 +0100 | [diff] [blame] | 55 | RTPVideoHeader::GenericDescriptorInfo GenericDescriptorFromFrameInfo( |
| 56 | const GenericFrameInfo& frame_info, |
Danil Chapovalov | cf1308f | 2020-11-18 18:27:37 +0100 | [diff] [blame] | 57 | int64_t frame_id); |
Elad Alon | f5b216a | 2019-01-28 14:25:17 +0100 | [diff] [blame] | 58 | void SetGeneric(const CodecSpecificInfo* codec_specific_info, |
| 59 | int64_t frame_id, |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 60 | bool is_keyframe, |
| 61 | RTPVideoHeader* rtp_video_header); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 62 | |
Elad Alon | f5b216a | 2019-01-28 14:25:17 +0100 | [diff] [blame] | 63 | void Vp8ToGeneric(const CodecSpecificInfoVP8& vp8_info, |
| 64 | int64_t shared_frame_id, |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 65 | bool is_keyframe, |
| 66 | RTPVideoHeader* rtp_video_header); |
| 67 | |
Danil Chapovalov | af36644 | 2021-04-22 15:20:28 +0200 | [diff] [blame] | 68 | void Vp9ToGeneric(const CodecSpecificInfoVP9& vp9_info, |
| 69 | int64_t shared_frame_id, |
| 70 | RTPVideoHeader& rtp_video_header); |
| 71 | |
philipel | 8aba8fe | 2019-06-13 15:13:16 +0200 | [diff] [blame] | 72 | void H264ToGeneric(const CodecSpecificInfoH264& h264_info, |
| 73 | int64_t shared_frame_id, |
| 74 | bool is_keyframe, |
| 75 | RTPVideoHeader* rtp_video_header); |
| 76 | |
| 77 | void GenericToGeneric(int64_t shared_frame_id, |
| 78 | bool is_keyframe, |
| 79 | RTPVideoHeader* rtp_video_header); |
| 80 | |
Qingsi Wang | 1c1b99e | 2020-01-07 19:16:33 +0000 | [diff] [blame] | 81 | // TODO(bugs.webrtc.org/10242): Delete SetDependenciesVp8Deprecated() and move |
| 82 | // the logic in SetDependenciesVp8New() into Vp8ToGeneric() once all hardware |
| 83 | // wrappers have been updated. |
| 84 | void SetDependenciesVp8Deprecated( |
| 85 | const CodecSpecificInfoVP8& vp8_info, |
| 86 | int64_t shared_frame_id, |
| 87 | bool is_keyframe, |
| 88 | int spatial_index, |
| 89 | int temporal_index, |
| 90 | bool layer_sync, |
| 91 | RTPVideoHeader::GenericDescriptorInfo* generic); |
| 92 | void SetDependenciesVp8New(const CodecSpecificInfoVP8& vp8_info, |
| 93 | int64_t shared_frame_id, |
| 94 | bool is_keyframe, |
| 95 | bool layer_sync, |
| 96 | RTPVideoHeader::GenericDescriptorInfo* generic); |
| 97 | |
Danil Chapovalov | 02d71fb | 2020-02-10 16:22:57 +0100 | [diff] [blame] | 98 | FrameDependenciesCalculator dependencies_calculator_; |
Danil Chapovalov | 4b860c1 | 2020-05-19 14:48:19 +0200 | [diff] [blame] | 99 | ChainDiffCalculator chains_calculator_; |
Elad Alon | f5b216a | 2019-01-28 14:25:17 +0100 | [diff] [blame] | 100 | // TODO(bugs.webrtc.org/10242): Remove once all encoder-wrappers are updated. |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 101 | // Holds the last shared frame id for a given (spatial, temporal) layer. |
| 102 | std::array<std::array<int64_t, RtpGenericFrameDescriptor::kMaxTemporalLayers>, |
| 103 | RtpGenericFrameDescriptor::kMaxSpatialLayers> |
| 104 | last_shared_frame_id_; |
Danil Chapovalov | af36644 | 2021-04-22 15:20:28 +0200 | [diff] [blame] | 105 | // circular buffer of frame ids for the last 128 vp9 pictures. |
| 106 | // ids for the `picture_id` are stored at the index `picture_id % 128`. |
| 107 | std::vector<std::array<int64_t, RtpGenericFrameDescriptor::kMaxSpatialLayers>> |
| 108 | last_vp9_frame_id_; |
| 109 | // Last frame id for each chain |
| 110 | std::array<int64_t, RtpGenericFrameDescriptor::kMaxSpatialLayers> |
| 111 | chain_last_frame_id_; |
Elad Alon | f5b216a | 2019-01-28 14:25:17 +0100 | [diff] [blame] | 112 | |
| 113 | // TODO(eladalon): When additional codecs are supported, |
| 114 | // set kMaxCodecBuffersCount to the max() of these codecs' buffer count. |
| 115 | static constexpr size_t kMaxCodecBuffersCount = |
| 116 | CodecSpecificInfoVP8::kBuffersCount; |
| 117 | |
| 118 | // Maps buffer IDs to the frame-ID stored in them. |
| 119 | std::array<int64_t, kMaxCodecBuffersCount> buffer_id_to_frame_id_; |
| 120 | |
Qingsi Wang | 1c1b99e | 2020-01-07 19:16:33 +0000 | [diff] [blame] | 121 | // Until we remove SetDependenciesVp8Deprecated(), we should make sure |
| 122 | // that, for a given object, we either always use |
| 123 | // SetDependenciesVp8Deprecated(), or always use SetDependenciesVp8New(). |
| 124 | // TODO(bugs.webrtc.org/10242): Remove. |
| 125 | absl::optional<bool> new_version_used_; |
| 126 | |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 127 | const uint32_t ssrc_; |
| 128 | RtpPayloadState state_; |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 129 | |
| 130 | const bool generic_picture_id_experiment_; |
Danil Chapovalov | 5b298ab | 2022-06-08 11:18:51 +0200 | [diff] [blame] | 131 | const bool simulate_generic_structure_; |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 132 | }; |
| 133 | } // namespace webrtc |
| 134 | #endif // CALL_RTP_PAYLOAD_PARAMS_H_ |