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 static uint8_t GetTemporalId(const RTPVideoHeader& header); |
| 84 StorageType GetStorageType(uint8_t temporal_id, |
| 85 int32_t retransmission_settings, |
| 86 int64_t expected_retransmission_time_ms); |
| 87 |
79 private: | 88 private: |
| 89 struct TemporalLayerStats { |
| 90 TemporalLayerStats() |
| 91 : frame_rate_fp1000s(kTLRateWindowSizeMs, 1000 * 1000), |
| 92 last_frame_time_ms(0) {} |
| 93 // Frame rate, in frames per 1000 seconds. This essentially turns the fps |
| 94 // value into a fixed point value with three decimals. Improves precision at |
| 95 // low frame rates. |
| 96 RateStatistics frame_rate_fp1000s; |
| 97 int64_t last_frame_time_ms; |
| 98 }; |
| 99 |
80 size_t CalculateFecPacketOverhead() const EXCLUSIVE_LOCKS_REQUIRED(crit_); | 100 size_t CalculateFecPacketOverhead() const EXCLUSIVE_LOCKS_REQUIRED(crit_); |
81 | 101 |
82 void SendVideoPacket(std::unique_ptr<RtpPacketToSend> packet, | 102 void SendVideoPacket(std::unique_ptr<RtpPacketToSend> packet, |
83 StorageType storage); | 103 StorageType storage); |
84 | 104 |
85 void SendVideoPacketAsRedMaybeWithUlpfec( | 105 void SendVideoPacketAsRedMaybeWithUlpfec( |
86 std::unique_ptr<RtpPacketToSend> media_packet, | 106 std::unique_ptr<RtpPacketToSend> media_packet, |
87 StorageType media_packet_storage, | 107 StorageType media_packet_storage, |
88 bool protect_media_packet); | 108 bool protect_media_packet); |
89 | 109 |
90 // TODO(brandtr): Remove the FlexFEC functions when FlexfecSender has been | 110 // TODO(brandtr): Remove the FlexFEC functions when FlexfecSender has been |
91 // moved to PacedSender. | 111 // moved to PacedSender. |
92 void SendVideoPacketWithFlexfec(std::unique_ptr<RtpPacketToSend> media_packet, | 112 void SendVideoPacketWithFlexfec(std::unique_ptr<RtpPacketToSend> media_packet, |
93 StorageType media_packet_storage, | 113 StorageType media_packet_storage, |
94 bool protect_media_packet); | 114 bool protect_media_packet); |
95 | 115 |
96 bool red_enabled() const EXCLUSIVE_LOCKS_REQUIRED(crit_) { | 116 bool red_enabled() const EXCLUSIVE_LOCKS_REQUIRED(crit_) { |
97 return red_payload_type_ >= 0; | 117 return red_payload_type_ >= 0; |
98 } | 118 } |
99 | 119 |
100 bool ulpfec_enabled() const EXCLUSIVE_LOCKS_REQUIRED(crit_) { | 120 bool ulpfec_enabled() const EXCLUSIVE_LOCKS_REQUIRED(crit_) { |
101 return ulpfec_payload_type_ >= 0; | 121 return ulpfec_payload_type_ >= 0; |
102 } | 122 } |
103 | 123 |
104 bool flexfec_enabled() const { return flexfec_sender_ != nullptr; } | 124 bool flexfec_enabled() const { return flexfec_sender_ != nullptr; } |
105 | 125 |
| 126 bool UpdateConditionalRetransmit(uint8_t temporal_id, |
| 127 int64_t expected_retransmission_time_ms) |
| 128 EXCLUSIVE_LOCKS_REQUIRED(stats_crit_); |
| 129 |
106 RTPSender* const rtp_sender_; | 130 RTPSender* const rtp_sender_; |
107 Clock* const clock_; | 131 Clock* const clock_; |
108 | 132 |
109 // Should never be held when calling out of this class. | 133 // Should never be held when calling out of this class. |
110 rtc::CriticalSection crit_; | 134 rtc::CriticalSection crit_; |
111 | 135 |
112 RtpVideoCodecTypes video_type_; | 136 RtpVideoCodecTypes video_type_; |
113 int32_t retransmission_settings_ GUARDED_BY(crit_); | 137 int32_t retransmission_settings_ GUARDED_BY(crit_); |
114 VideoRotation last_rotation_ GUARDED_BY(crit_); | 138 VideoRotation last_rotation_ GUARDED_BY(crit_); |
115 | 139 |
116 // RED/ULPFEC. | 140 // RED/ULPFEC. |
117 int red_payload_type_ GUARDED_BY(crit_); | 141 int red_payload_type_ GUARDED_BY(crit_); |
118 int ulpfec_payload_type_ GUARDED_BY(crit_); | 142 int ulpfec_payload_type_ GUARDED_BY(crit_); |
119 UlpfecGenerator ulpfec_generator_ GUARDED_BY(crit_); | 143 UlpfecGenerator ulpfec_generator_ GUARDED_BY(crit_); |
120 | 144 |
121 // FlexFEC. | 145 // FlexFEC. |
122 FlexfecSender* const flexfec_sender_; | 146 FlexfecSender* const flexfec_sender_; |
123 | 147 |
124 // FEC parameters, applicable to either ULPFEC or FlexFEC. | 148 // FEC parameters, applicable to either ULPFEC or FlexFEC. |
125 FecProtectionParams delta_fec_params_ GUARDED_BY(crit_); | 149 FecProtectionParams delta_fec_params_ GUARDED_BY(crit_); |
126 FecProtectionParams key_fec_params_ GUARDED_BY(crit_); | 150 FecProtectionParams key_fec_params_ GUARDED_BY(crit_); |
127 | 151 |
128 rtc::CriticalSection stats_crit_; | 152 rtc::CriticalSection stats_crit_; |
129 // Bitrate used for FEC payload, RED headers, RTP headers for FEC packets | 153 // Bitrate used for FEC payload, RED headers, RTP headers for FEC packets |
130 // and any padding overhead. | 154 // and any padding overhead. |
131 RateStatistics fec_bitrate_ GUARDED_BY(stats_crit_); | 155 RateStatistics fec_bitrate_ GUARDED_BY(stats_crit_); |
132 // Bitrate used for video payload and RTP headers. | 156 // Bitrate used for video payload and RTP headers. |
133 RateStatistics video_bitrate_ GUARDED_BY(stats_crit_); | 157 RateStatistics video_bitrate_ GUARDED_BY(stats_crit_); |
| 158 |
| 159 std::map<int, TemporalLayerStats> frame_stats_by_temporal_layer_ |
| 160 GUARDED_BY(stats_crit_); |
| 161 |
134 OneTimeEvent first_frame_sent_; | 162 OneTimeEvent first_frame_sent_; |
135 }; | 163 }; |
136 | 164 |
137 } // namespace webrtc | 165 } // namespace webrtc |
138 | 166 |
139 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_VIDEO_H_ | 167 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_VIDEO_H_ |
OLD | NEW |