rtp_payload_params.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. #ifndef CALL_RTP_PAYLOAD_PARAMS_H_
  11. #define CALL_RTP_PAYLOAD_PARAMS_H_
  12. #include <array>
  13. #include "absl/types/optional.h"
  14. #include "api/transport/webrtc_key_value_config.h"
  15. #include "api/video_codecs/video_encoder.h"
  16. #include "call/rtp_config.h"
  17. #include "modules/rtp_rtcp/source/rtp_generic_frame_descriptor.h"
  18. #include "modules/rtp_rtcp/source/rtp_video_header.h"
  19. #include "modules/video_coding/chain_diff_calculator.h"
  20. #include "modules/video_coding/frame_dependencies_calculator.h"
  21. #include "modules/video_coding/include/video_codec_interface.h"
  22. namespace webrtc {
  23. class RtpRtcp;
  24. // State for setting picture id and tl0 pic idx, for VP8 and VP9
  25. // TODO(nisse): Make these properties not codec specific.
  26. class RtpPayloadParams final {
  27. public:
  28. RtpPayloadParams(const uint32_t ssrc,
  29. const RtpPayloadState* state,
  30. const WebRtcKeyValueConfig& trials);
  31. RtpPayloadParams(const RtpPayloadParams& other);
  32. ~RtpPayloadParams();
  33. RTPVideoHeader GetRtpVideoHeader(const EncodedImage& image,
  34. const CodecSpecificInfo* codec_specific_info,
  35. int64_t shared_frame_id);
  36. uint32_t ssrc() const;
  37. RtpPayloadState state() const;
  38. private:
  39. void SetCodecSpecific(RTPVideoHeader* rtp_video_header,
  40. bool first_frame_in_picture);
  41. RTPVideoHeader::GenericDescriptorInfo GenericDescriptorFromFrameInfo(
  42. const GenericFrameInfo& frame_info,
  43. int64_t frame_id,
  44. VideoFrameType frame_type);
  45. void SetGeneric(const CodecSpecificInfo* codec_specific_info,
  46. int64_t frame_id,
  47. bool is_keyframe,
  48. RTPVideoHeader* rtp_video_header);
  49. void Vp8ToGeneric(const CodecSpecificInfoVP8& vp8_info,
  50. int64_t shared_frame_id,
  51. bool is_keyframe,
  52. RTPVideoHeader* rtp_video_header);
  53. void H264ToGeneric(const CodecSpecificInfoH264& h264_info,
  54. int64_t shared_frame_id,
  55. bool is_keyframe,
  56. RTPVideoHeader* rtp_video_header);
  57. void GenericToGeneric(int64_t shared_frame_id,
  58. bool is_keyframe,
  59. RTPVideoHeader* rtp_video_header);
  60. // TODO(bugs.webrtc.org/10242): Delete SetDependenciesVp8Deprecated() and move
  61. // the logic in SetDependenciesVp8New() into Vp8ToGeneric() once all hardware
  62. // wrappers have been updated.
  63. void SetDependenciesVp8Deprecated(
  64. const CodecSpecificInfoVP8& vp8_info,
  65. int64_t shared_frame_id,
  66. bool is_keyframe,
  67. int spatial_index,
  68. int temporal_index,
  69. bool layer_sync,
  70. RTPVideoHeader::GenericDescriptorInfo* generic);
  71. void SetDependenciesVp8New(const CodecSpecificInfoVP8& vp8_info,
  72. int64_t shared_frame_id,
  73. bool is_keyframe,
  74. bool layer_sync,
  75. RTPVideoHeader::GenericDescriptorInfo* generic);
  76. FrameDependenciesCalculator dependencies_calculator_;
  77. ChainDiffCalculator chains_calculator_;
  78. // TODO(bugs.webrtc.org/10242): Remove once all encoder-wrappers are updated.
  79. // Holds the last shared frame id for a given (spatial, temporal) layer.
  80. std::array<std::array<int64_t, RtpGenericFrameDescriptor::kMaxTemporalLayers>,
  81. RtpGenericFrameDescriptor::kMaxSpatialLayers>
  82. last_shared_frame_id_;
  83. // TODO(eladalon): When additional codecs are supported,
  84. // set kMaxCodecBuffersCount to the max() of these codecs' buffer count.
  85. static constexpr size_t kMaxCodecBuffersCount =
  86. CodecSpecificInfoVP8::kBuffersCount;
  87. // Maps buffer IDs to the frame-ID stored in them.
  88. std::array<int64_t, kMaxCodecBuffersCount> buffer_id_to_frame_id_;
  89. // Until we remove SetDependenciesVp8Deprecated(), we should make sure
  90. // that, for a given object, we either always use
  91. // SetDependenciesVp8Deprecated(), or always use SetDependenciesVp8New().
  92. // TODO(bugs.webrtc.org/10242): Remove.
  93. absl::optional<bool> new_version_used_;
  94. const uint32_t ssrc_;
  95. RtpPayloadState state_;
  96. const bool generic_picture_id_experiment_;
  97. };
  98. } // namespace webrtc
  99. #endif // CALL_RTP_PAYLOAD_PARAMS_H_