Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_VIDEO_H_ | 11 #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_VIDEO_H_ |
| 12 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_VIDEO_H_ | 12 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_VIDEO_H_ |
| 13 | 13 |
| 14 #include <list> | 14 #include <map> |
| 15 #include <memory> | 15 #include <memory> |
| 16 #include <vector> | |
| 17 | 16 |
| 18 #include "webrtc/common_types.h" | 17 #include "webrtc/common_types.h" |
| 19 #include "webrtc/modules/rtp_rtcp/include/flexfec_sender.h" | 18 #include "webrtc/modules/rtp_rtcp/include/flexfec_sender.h" |
| 20 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" | 19 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
| 21 #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_config.h" | 20 #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_config.h" |
| 22 #include "webrtc/modules/rtp_rtcp/source/rtp_sender.h" | 21 #include "webrtc/modules/rtp_rtcp/source/rtp_sender.h" |
| 23 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" | 22 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" |
| 24 #include "webrtc/modules/rtp_rtcp/source/ulpfec_generator.h" | 23 #include "webrtc/modules/rtp_rtcp/source/ulpfec_generator.h" |
| 25 #include "webrtc/modules/rtp_rtcp/source/video_codec_information.h" | 24 #include "webrtc/modules/rtp_rtcp/source/video_codec_information.h" |
| 26 #include "webrtc/rtc_base/criticalsection.h" | 25 #include "webrtc/rtc_base/criticalsection.h" |
| 27 #include "webrtc/rtc_base/onetimeevent.h" | 26 #include "webrtc/rtc_base/onetimeevent.h" |
| 28 #include "webrtc/rtc_base/optional.h" | 27 #include "webrtc/rtc_base/optional.h" |
| 29 #include "webrtc/rtc_base/rate_statistics.h" | 28 #include "webrtc/rtc_base/rate_statistics.h" |
| 30 #include "webrtc/rtc_base/sequenced_task_checker.h" | 29 #include "webrtc/rtc_base/sequenced_task_checker.h" |
| 31 #include "webrtc/rtc_base/thread_annotations.h" | 30 #include "webrtc/rtc_base/thread_annotations.h" |
| 32 #include "webrtc/typedefs.h" | 31 #include "webrtc/typedefs.h" |
| 33 | 32 |
| 34 namespace webrtc { | 33 namespace webrtc { |
| 34 class RtpPacketizer; | |
| 35 class RtpPacketToSend; | 35 class RtpPacketToSend; |
| 36 | 36 |
| 37 class RTPSenderVideo { | 37 class RTPSenderVideo { |
| 38 public: | 38 public: |
| 39 static constexpr int64_t kTLRateWindowSizeMs = 2500; | |
| 40 | |
| 39 RTPSenderVideo(Clock* clock, | 41 RTPSenderVideo(Clock* clock, |
| 40 RTPSender* rtpSender, | 42 RTPSender* rtpSender, |
| 41 FlexfecSender* flexfec_sender); | 43 FlexfecSender* flexfec_sender); |
| 42 virtual ~RTPSenderVideo(); | 44 virtual ~RTPSenderVideo(); |
| 43 | 45 |
| 44 virtual RtpVideoCodecTypes VideoCodecType() const; | 46 virtual RtpVideoCodecTypes VideoCodecType() const; |
| 45 | 47 |
| 46 static RtpUtility::Payload* CreateVideoPayload( | 48 static RtpUtility::Payload* CreateVideoPayload( |
| 47 const char payload_name[RTP_PAYLOAD_NAME_SIZE], | 49 const char payload_name[RTP_PAYLOAD_NAME_SIZE], |
| 48 int8_t payload_type); | 50 int8_t payload_type); |
| 49 | 51 |
| 50 bool SendVideo(RtpVideoCodecTypes video_type, | 52 bool SendVideo(RtpVideoCodecTypes video_type, |
| 51 FrameType frame_type, | 53 FrameType frame_type, |
| 52 int8_t payload_type, | 54 int8_t payload_type, |
| 53 uint32_t capture_timestamp, | 55 uint32_t capture_timestamp, |
| 54 int64_t capture_time_ms, | 56 int64_t capture_time_ms, |
| 55 const uint8_t* payload_data, | 57 const uint8_t* payload_data, |
| 56 size_t payload_size, | 58 size_t payload_size, |
| 57 const RTPFragmentationHeader* fragmentation, | 59 const RTPFragmentationHeader* fragmentation, |
| 58 const RTPVideoHeader* video_header); | 60 const RTPVideoHeader* video_header, |
| 61 int64_t expected_retransmission_time_ms); | |
| 59 | 62 |
| 60 void SetVideoCodecType(RtpVideoCodecTypes type); | 63 void SetVideoCodecType(RtpVideoCodecTypes type); |
| 61 | 64 |
| 62 // ULPFEC. | 65 // ULPFEC. |
| 63 void SetUlpfecConfig(int red_payload_type, int ulpfec_payload_type); | 66 void SetUlpfecConfig(int red_payload_type, int ulpfec_payload_type); |
| 64 void GetUlpfecConfig(int* red_payload_type, int* ulpfec_payload_type) const; | 67 void GetUlpfecConfig(int* red_payload_type, int* ulpfec_payload_type) const; |
| 65 | 68 |
| 66 // FlexFEC/ULPFEC. | 69 // FlexFEC/ULPFEC. |
| 67 void SetFecParameters(const FecProtectionParams& delta_params, | 70 void SetFecParameters(const FecProtectionParams& delta_params, |
| 68 const FecProtectionParams& key_params); | 71 const FecProtectionParams& key_params); |
| 69 | 72 |
| 70 // FlexFEC. | 73 // FlexFEC. |
| 71 rtc::Optional<uint32_t> FlexfecSsrc() const; | 74 rtc::Optional<uint32_t> FlexfecSsrc() const; |
| 72 | 75 |
| 73 uint32_t VideoBitrateSent() const; | 76 uint32_t VideoBitrateSent() const; |
| 74 uint32_t FecOverheadRate() const; | 77 uint32_t FecOverheadRate() const; |
| 75 | 78 |
| 76 int SelectiveRetransmissions() const; | 79 int SelectiveRetransmissions() const; |
| 77 void SetSelectiveRetransmissions(uint8_t settings); | 80 void SetSelectiveRetransmissions(uint8_t settings); |
| 78 | 81 |
| 82 protected: | |
| 83 uint8_t GetTemporalId(const RTPVideoHeader& header) const; | |
|
danilchap
2017/09/04 09:03:05
look like this one can be static or free function
sprang_webrtc
2017/09/04 11:09:28
Made it static. Call from unit test.
| |
| 84 StorageType GetStorageType(uint8_t temporal_id, | |
| 85 int32_t retransmission_settings, | |
| 86 RtpPacketizer* packetizer, | |
| 87 int64_t expected_retransmission_time); | |
| 88 | |
| 79 private: | 89 private: |
| 90 struct TemporalLayerStats { | |
| 91 TemporalLayerStats() | |
| 92 : frame_rate_fp1000s(kTLRateWindowSizeMs, 1000 * 1000), | |
|
brandtr
2017/09/04 10:29:22
Nice unit :)
sprang_webrtc
2017/09/04 11:09:28
Hehe, thanks :)
Maybe I'll add a comment explicitl
| |
| 93 last_frame_time(0) {} | |
| 94 RateStatistics frame_rate_fp1000s; | |
| 95 int64_t last_frame_time; | |
|
danilchap
2017/09/04 09:03:05
add _ms
sprang_webrtc
2017/09/04 11:09:28
Done.
| |
| 96 }; | |
| 97 | |
| 80 size_t CalculateFecPacketOverhead() const EXCLUSIVE_LOCKS_REQUIRED(crit_); | 98 size_t CalculateFecPacketOverhead() const EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| 81 | 99 |
| 82 void SendVideoPacket(std::unique_ptr<RtpPacketToSend> packet, | 100 void SendVideoPacket(std::unique_ptr<RtpPacketToSend> packet, |
| 83 StorageType storage); | 101 StorageType storage); |
| 84 | 102 |
| 85 void SendVideoPacketAsRedMaybeWithUlpfec( | 103 void SendVideoPacketAsRedMaybeWithUlpfec( |
| 86 std::unique_ptr<RtpPacketToSend> media_packet, | 104 std::unique_ptr<RtpPacketToSend> media_packet, |
| 87 StorageType media_packet_storage, | 105 StorageType media_packet_storage, |
| 88 bool protect_media_packet); | 106 bool protect_media_packet); |
| 89 | 107 |
| 90 // TODO(brandtr): Remove the FlexFEC functions when FlexfecSender has been | 108 // TODO(brandtr): Remove the FlexFEC functions when FlexfecSender has been |
| 91 // moved to PacedSender. | 109 // moved to PacedSender. |
| 92 void SendVideoPacketWithFlexfec(std::unique_ptr<RtpPacketToSend> media_packet, | 110 void SendVideoPacketWithFlexfec(std::unique_ptr<RtpPacketToSend> media_packet, |
| 93 StorageType media_packet_storage, | 111 StorageType media_packet_storage, |
| 94 bool protect_media_packet); | 112 bool protect_media_packet); |
| 95 | 113 |
| 96 bool red_enabled() const EXCLUSIVE_LOCKS_REQUIRED(crit_) { | 114 bool red_enabled() const EXCLUSIVE_LOCKS_REQUIRED(crit_) { |
| 97 return red_payload_type_ >= 0; | 115 return red_payload_type_ >= 0; |
| 98 } | 116 } |
| 99 | 117 |
| 100 bool ulpfec_enabled() const EXCLUSIVE_LOCKS_REQUIRED(crit_) { | 118 bool ulpfec_enabled() const EXCLUSIVE_LOCKS_REQUIRED(crit_) { |
| 101 return ulpfec_payload_type_ >= 0; | 119 return ulpfec_payload_type_ >= 0; |
| 102 } | 120 } |
| 103 | 121 |
| 104 bool flexfec_enabled() const { return flexfec_sender_ != nullptr; } | 122 bool flexfec_enabled() const { return flexfec_sender_ != nullptr; } |
| 105 | 123 |
| 124 bool UpdateConditionalRetransmit(uint8_t temporal_id, | |
| 125 int64_t expected_retransmission_time_ms) | |
| 126 EXCLUSIVE_LOCKS_REQUIRED(stats_crit_); | |
| 127 | |
| 106 RTPSender* const rtp_sender_; | 128 RTPSender* const rtp_sender_; |
| 107 Clock* const clock_; | 129 Clock* const clock_; |
| 108 | 130 |
| 109 // Should never be held when calling out of this class. | 131 // Should never be held when calling out of this class. |
| 110 rtc::CriticalSection crit_; | 132 rtc::CriticalSection crit_; |
| 111 | 133 |
| 112 RtpVideoCodecTypes video_type_; | 134 RtpVideoCodecTypes video_type_; |
| 113 int32_t retransmission_settings_ GUARDED_BY(crit_); | 135 int32_t retransmission_settings_ GUARDED_BY(crit_); |
| 114 VideoRotation last_rotation_ GUARDED_BY(crit_); | 136 VideoRotation last_rotation_ GUARDED_BY(crit_); |
| 115 | 137 |
| 116 // RED/ULPFEC. | 138 // RED/ULPFEC. |
| 117 int red_payload_type_ GUARDED_BY(crit_); | 139 int red_payload_type_ GUARDED_BY(crit_); |
| 118 int ulpfec_payload_type_ GUARDED_BY(crit_); | 140 int ulpfec_payload_type_ GUARDED_BY(crit_); |
| 119 UlpfecGenerator ulpfec_generator_ GUARDED_BY(crit_); | 141 UlpfecGenerator ulpfec_generator_ GUARDED_BY(crit_); |
| 120 | 142 |
| 121 // FlexFEC. | 143 // FlexFEC. |
| 122 FlexfecSender* const flexfec_sender_; | 144 FlexfecSender* const flexfec_sender_; |
| 123 | 145 |
| 124 // FEC parameters, applicable to either ULPFEC or FlexFEC. | 146 // FEC parameters, applicable to either ULPFEC or FlexFEC. |
| 125 FecProtectionParams delta_fec_params_ GUARDED_BY(crit_); | 147 FecProtectionParams delta_fec_params_ GUARDED_BY(crit_); |
| 126 FecProtectionParams key_fec_params_ GUARDED_BY(crit_); | 148 FecProtectionParams key_fec_params_ GUARDED_BY(crit_); |
| 127 | 149 |
| 128 rtc::CriticalSection stats_crit_; | 150 rtc::CriticalSection stats_crit_; |
| 129 // Bitrate used for FEC payload, RED headers, RTP headers for FEC packets | 151 // Bitrate used for FEC payload, RED headers, RTP headers for FEC packets |
| 130 // and any padding overhead. | 152 // and any padding overhead. |
| 131 RateStatistics fec_bitrate_ GUARDED_BY(stats_crit_); | 153 RateStatistics fec_bitrate_ GUARDED_BY(stats_crit_); |
| 132 // Bitrate used for video payload and RTP headers. | 154 // Bitrate used for video payload and RTP headers. |
| 133 RateStatistics video_bitrate_ GUARDED_BY(stats_crit_); | 155 RateStatistics video_bitrate_ GUARDED_BY(stats_crit_); |
| 156 | |
| 157 std::map<int, TemporalLayerStats> frame_stats_by_temporal_layer_ | |
| 158 GUARDED_BY(stats_crit_); | |
| 159 | |
| 134 OneTimeEvent first_frame_sent_; | 160 OneTimeEvent first_frame_sent_; |
| 135 }; | 161 }; |
| 136 | 162 |
| 137 } // namespace webrtc | 163 } // namespace webrtc |
| 138 | 164 |
| 139 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_VIDEO_H_ | 165 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_VIDEO_H_ |
| OLD | NEW |