| 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 |
| 14 | #include <array> |
| 15 | #include <vector> |
| 16 |
| 17 | #include "absl/types/optional.h" |
| 18 | #include "api/transport/webrtc_key_value_config.h" |
| 19 | #include "api/video_codecs/video_encoder.h" |
| 20 | #include "call/rtp_config.h" |
| 21 | #include "modules/rtp_rtcp/source/rtp_generic_frame_descriptor.h" |
| 22 | #include "modules/rtp_rtcp/source/rtp_video_header.h" |
| 23 | #include "modules/video_coding/chain_diff_calculator.h" |
| 24 | #include "modules/video_coding/frame_dependencies_calculator.h" |
| 25 | #include "modules/video_coding/include/video_codec_interface.h" |
| 26 |
| 27 | namespace webrtc { |
| 28 |
| 29 | class RtpRtcp; |
| 30 |
| 31 | // State for setting picture id and tl0 pic idx, for VP8 and VP9 |
| 32 | // TODO(nisse): Make these properties not codec specific. |
| 33 | class RtpPayloadParams final { |
| 34 | public: |
| 35 | RtpPayloadParams(const uint32_t ssrc, |
| 36 | const RtpPayloadState* state, |
| 37 | const WebRtcKeyValueConfig& trials); |
| 38 | RtpPayloadParams(const RtpPayloadParams& other); |
| 39 | ~RtpPayloadParams(); |
| 40 |
| 41 | RTPVideoHeader GetRtpVideoHeader(const EncodedImage& image, |
| 42 | const CodecSpecificInfo* codec_specific_info, |
| 43 | int64_t shared_frame_id); |
| 44 |
| 45 | // Returns structure that aligns with simulated generic info. The templates |
| 46 | // allow to produce valid dependency descriptor for any stream where |
| 47 | // `num_spatial_layers` * `num_temporal_layers` <= 32 (limited by |
| 48 | // https://aomediacodec.github.io/av1-rtp-spec/#a82-syntax, see |
| 49 | // template_fdiffs()). The set of the templates is not tuned for any paricular |
| 50 | // structure thus dependency descriptor would use more bytes on the wire than |
| 51 | // with tuned templates. |
| 52 | static FrameDependencyStructure MinimalisticStructure( |
| 53 | int num_spatial_layers, |
| 54 | int num_temporal_layers); |
| 55 |
| 56 | uint32_t ssrc() const; |
| 57 |
| 58 | RtpPayloadState state() const; |
| 59 |
| 60 | private: |
| 61 | void SetCodecSpecific(RTPVideoHeader* rtp_video_header, |
| 62 | bool first_frame_in_picture); |
| 63 | RTPVideoHeader::GenericDescriptorInfo GenericDescriptorFromFrameInfo( |
| 64 | const GenericFrameInfo& frame_info, |
| 65 | int64_t frame_id); |
| 66 | void SetGeneric(const CodecSpecificInfo* codec_specific_info, |
| 67 | int64_t frame_id, |
| 68 | bool is_keyframe, |
| 69 | RTPVideoHeader* rtp_video_header); |
| 70 |
| 71 | void Vp8ToGeneric(const CodecSpecificInfoVP8& vp8_info, |
| 72 | int64_t shared_frame_id, |
| 73 | bool is_keyframe, |
| 74 | RTPVideoHeader* rtp_video_header); |
| 75 |
| 76 | void Vp9ToGeneric(const CodecSpecificInfoVP9& vp9_info, |
| 77 | int64_t shared_frame_id, |
| 78 | RTPVideoHeader& rtp_video_header); |
| 79 |
| 80 | void H264ToGeneric(const CodecSpecificInfoH264& h264_info, |
| 81 | int64_t shared_frame_id, |
| 82 | bool is_keyframe, |
| 83 | RTPVideoHeader* rtp_video_header); |
| 84 |
| 85 | void GenericToGeneric(int64_t shared_frame_id, |
| 86 | bool is_keyframe, |
| 87 | RTPVideoHeader* rtp_video_header); |
| 88 |
| 89 | // TODO(bugs.webrtc.org/10242): Delete SetDependenciesVp8Deprecated() and move |
| 90 | // the logic in SetDependenciesVp8New() into Vp8ToGeneric() once all hardware |
| 91 | // wrappers have been updated. |
| 92 | void SetDependenciesVp8Deprecated( |
| 93 | const CodecSpecificInfoVP8& vp8_info, |
| 94 | int64_t shared_frame_id, |
| 95 | bool is_keyframe, |
| 96 | int spatial_index, |
| 97 | int temporal_index, |
| 98 | bool layer_sync, |
| 99 | RTPVideoHeader::GenericDescriptorInfo* generic); |
| 100 | void SetDependenciesVp8New(const CodecSpecificInfoVP8& vp8_info, |
| 101 | int64_t shared_frame_id, |
| 102 | bool is_keyframe, |
| 103 | bool layer_sync, |
| 104 | RTPVideoHeader::GenericDescriptorInfo* generic); |
| 105 |
| 106 | FrameDependenciesCalculator dependencies_calculator_; |
| 107 | ChainDiffCalculator chains_calculator_; |
| 108 | // TODO(bugs.webrtc.org/10242): Remove once all encoder-wrappers are updated. |
| 109 | // Holds the last shared frame id for a given (spatial, temporal) layer. |
| 110 | std::array<std::array<int64_t, RtpGenericFrameDescriptor::kMaxTemporalLayers>, |
| 111 | RtpGenericFrameDescriptor::kMaxSpatialLayers> |
| 112 | last_shared_frame_id_; |
| 113 | // circular buffer of frame ids for the last 128 vp9 pictures. |
| 114 | // ids for the `picture_id` are stored at the index `picture_id % 128`. |
| 115 | std::vector<std::array<int64_t, RtpGenericFrameDescriptor::kMaxSpatialLayers>> |
| 116 | last_vp9_frame_id_; |
| 117 | // Last frame id for each chain |
| 118 | std::array<int64_t, RtpGenericFrameDescriptor::kMaxSpatialLayers> |
| 119 | chain_last_frame_id_; |
| 120 |
| 121 | // TODO(eladalon): When additional codecs are supported, |
| 122 | // set kMaxCodecBuffersCount to the max() of these codecs' buffer count. |
| 123 | static constexpr size_t kMaxCodecBuffersCount = |
| 124 | CodecSpecificInfoVP8::kBuffersCount; |
| 125 |
| 126 | // Maps buffer IDs to the frame-ID stored in them. |
| 127 | std::array<int64_t, kMaxCodecBuffersCount> buffer_id_to_frame_id_; |
| 128 |
| 129 | // Until we remove SetDependenciesVp8Deprecated(), we should make sure |
| 130 | // that, for a given object, we either always use |
| 131 | // SetDependenciesVp8Deprecated(), or always use SetDependenciesVp8New(). |
| 132 | // TODO(bugs.webrtc.org/10242): Remove. |
| 133 | absl::optional<bool> new_version_used_; |
| 134 |
| 135 | const uint32_t ssrc_; |
| 136 | RtpPayloadState state_; |
| 137 |
| 138 | const bool generic_picture_id_experiment_; |
| 139 | }; |
| 140 | } // namespace webrtc |
| 141 | #endif // CALL_RTP_PAYLOAD_PARAMS_H_ |
| 142 |