| 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 for VP9. |
| 46 | // The templates allow to produce valid dependency descriptor for any vp9 |
| 47 | // stream with up to 4 temporal layers. The set of the templates is not tuned |
| 48 | // for any paricular structure thus dependency descriptor would use more bytes |
| 49 | // on the wire than with tuned templates. |
| 50 | static FrameDependencyStructure MinimalisticVp9Structure( |
| 51 | const CodecSpecificInfoVP9& vp9); |
| 52 |
| 53 | uint32_t ssrc() const; |
| 54 |
| 55 | RtpPayloadState state() const; |
| 56 |
| 57 | private: |
| 58 | void SetCodecSpecific(RTPVideoHeader* rtp_video_header, |
| 59 | bool first_frame_in_picture); |
| 60 | RTPVideoHeader::GenericDescriptorInfo GenericDescriptorFromFrameInfo( |
| 61 | const GenericFrameInfo& frame_info, |
| 62 | int64_t frame_id); |
| 63 | void SetGeneric(const CodecSpecificInfo* codec_specific_info, |
| 64 | int64_t frame_id, |
| 65 | bool is_keyframe, |
| 66 | RTPVideoHeader* rtp_video_header); |
| 67 |
| 68 | void Vp8ToGeneric(const CodecSpecificInfoVP8& vp8_info, |
| 69 | int64_t shared_frame_id, |
| 70 | bool is_keyframe, |
| 71 | RTPVideoHeader* rtp_video_header); |
| 72 |
| 73 | void Vp9ToGeneric(const CodecSpecificInfoVP9& vp9_info, |
| 74 | int64_t shared_frame_id, |
| 75 | RTPVideoHeader& rtp_video_header); |
| 76 |
| 77 | void H264ToGeneric(const CodecSpecificInfoH264& h264_info, |
| 78 | int64_t shared_frame_id, |
| 79 | bool is_keyframe, |
| 80 | RTPVideoHeader* rtp_video_header); |
| 81 |
| 82 | void GenericToGeneric(int64_t shared_frame_id, |
| 83 | bool is_keyframe, |
| 84 | RTPVideoHeader* rtp_video_header); |
| 85 |
| 86 | // TODO(bugs.webrtc.org/10242): Delete SetDependenciesVp8Deprecated() and move |
| 87 | // the logic in SetDependenciesVp8New() into Vp8ToGeneric() once all hardware |
| 88 | // wrappers have been updated. |
| 89 | void SetDependenciesVp8Deprecated( |
| 90 | const CodecSpecificInfoVP8& vp8_info, |
| 91 | int64_t shared_frame_id, |
| 92 | bool is_keyframe, |
| 93 | int spatial_index, |
| 94 | int temporal_index, |
| 95 | bool layer_sync, |
| 96 | RTPVideoHeader::GenericDescriptorInfo* generic); |
| 97 | void SetDependenciesVp8New(const CodecSpecificInfoVP8& vp8_info, |
| 98 | int64_t shared_frame_id, |
| 99 | bool is_keyframe, |
| 100 | bool layer_sync, |
| 101 | RTPVideoHeader::GenericDescriptorInfo* generic); |
| 102 |
| 103 | FrameDependenciesCalculator dependencies_calculator_; |
| 104 | ChainDiffCalculator chains_calculator_; |
| 105 | // TODO(bugs.webrtc.org/10242): Remove once all encoder-wrappers are updated. |
| 106 | // Holds the last shared frame id for a given (spatial, temporal) layer. |
| 107 | std::array<std::array<int64_t, RtpGenericFrameDescriptor::kMaxTemporalLayers>, |
| 108 | RtpGenericFrameDescriptor::kMaxSpatialLayers> |
| 109 | last_shared_frame_id_; |
| 110 | // circular buffer of frame ids for the last 128 vp9 pictures. |
| 111 | // ids for the `picture_id` are stored at the index `picture_id % 128`. |
| 112 | std::vector<std::array<int64_t, RtpGenericFrameDescriptor::kMaxSpatialLayers>> |
| 113 | last_vp9_frame_id_; |
| 114 | // Last frame id for each chain |
| 115 | std::array<int64_t, RtpGenericFrameDescriptor::kMaxSpatialLayers> |
| 116 | chain_last_frame_id_; |
| 117 |
| 118 | // TODO(eladalon): When additional codecs are supported, |
| 119 | // set kMaxCodecBuffersCount to the max() of these codecs' buffer count. |
| 120 | static constexpr size_t kMaxCodecBuffersCount = |
| 121 | CodecSpecificInfoVP8::kBuffersCount; |
| 122 |
| 123 | // Maps buffer IDs to the frame-ID stored in them. |
| 124 | std::array<int64_t, kMaxCodecBuffersCount> buffer_id_to_frame_id_; |
| 125 |
| 126 | // Until we remove SetDependenciesVp8Deprecated(), we should make sure |
| 127 | // that, for a given object, we either always use |
| 128 | // SetDependenciesVp8Deprecated(), or always use SetDependenciesVp8New(). |
| 129 | // TODO(bugs.webrtc.org/10242): Remove. |
| 130 | absl::optional<bool> new_version_used_; |
| 131 |
| 132 | const uint32_t ssrc_; |
| 133 | RtpPayloadState state_; |
| 134 |
| 135 | const bool generic_picture_id_experiment_; |
| 136 | const bool simulate_generic_vp9_; |
| 137 | }; |
| 138 | } // namespace webrtc |
| 139 | #endif // CALL_RTP_PAYLOAD_PARAMS_H_ |
| 140 |