OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 #include "webrtc/video/video_send_stream.h" | 11 #include "webrtc/video/video_send_stream.h" |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
14 #include <sstream> | 14 #include <sstream> |
15 #include <string> | 15 #include <string> |
16 #include <vector> | 16 #include <vector> |
17 | 17 |
18 #include "webrtc/base/checks.h" | 18 #include "webrtc/base/checks.h" |
19 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 19 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
20 #include "webrtc/modules/pacing/include/packet_router.h" | 20 #include "webrtc/modules/pacing/include/packet_router.h" |
21 #include "webrtc/system_wrappers/interface/logging.h" | 21 #include "webrtc/system_wrappers/interface/logging.h" |
22 #include "webrtc/system_wrappers/interface/trace_event.h" | 22 #include "webrtc/system_wrappers/interface/trace_event.h" |
23 #include "webrtc/video/video_capture_input.h" | 23 #include "webrtc/video/video_capture_input.h" |
24 #include "webrtc/video_engine/call_stats.h" | 24 #include "webrtc/video_engine/call_stats.h" |
| 25 #include "webrtc/video_engine/encoder_state_feedback.h" |
25 #include "webrtc/video_engine/payload_router.h" | 26 #include "webrtc/video_engine/payload_router.h" |
26 #include "webrtc/video_engine/vie_channel.h" | 27 #include "webrtc/video_engine/vie_channel.h" |
27 #include "webrtc/video_engine/vie_channel_group.h" | 28 #include "webrtc/video_engine/vie_channel_group.h" |
28 #include "webrtc/video_engine/vie_defines.h" | 29 #include "webrtc/video_engine/vie_defines.h" |
29 #include "webrtc/video_engine/vie_encoder.h" | 30 #include "webrtc/video_engine/vie_encoder.h" |
30 #include "webrtc/video_send_stream.h" | 31 #include "webrtc/video_send_stream.h" |
31 | 32 |
32 namespace webrtc { | 33 namespace webrtc { |
33 | 34 |
34 class BitrateAllocator; | 35 class BitrateAllocator; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 ss << ", suspend_below_min_bitrate: " << (suspend_below_min_bitrate ? "on" | 105 ss << ", suspend_below_min_bitrate: " << (suspend_below_min_bitrate ? "on" |
105 : "off"); | 106 : "off"); |
106 ss << '}'; | 107 ss << '}'; |
107 return ss.str(); | 108 return ss.str(); |
108 } | 109 } |
109 | 110 |
110 namespace internal { | 111 namespace internal { |
111 VideoSendStream::VideoSendStream( | 112 VideoSendStream::VideoSendStream( |
112 int num_cpu_cores, | 113 int num_cpu_cores, |
113 ProcessThread* module_process_thread, | 114 ProcessThread* module_process_thread, |
| 115 CallStats* call_stats, |
114 ChannelGroup* channel_group, | 116 ChannelGroup* channel_group, |
115 const VideoSendStream::Config& config, | 117 const VideoSendStream::Config& config, |
116 const VideoEncoderConfig& encoder_config, | 118 const VideoEncoderConfig& encoder_config, |
117 const std::map<uint32_t, RtpState>& suspended_ssrcs) | 119 const std::map<uint32_t, RtpState>& suspended_ssrcs) |
118 : transport_adapter_(config.send_transport), | 120 : transport_adapter_(config.send_transport), |
119 encoded_frame_proxy_(config.post_encode_callback), | 121 encoded_frame_proxy_(config.post_encode_callback), |
120 config_(config), | 122 config_(config), |
121 suspended_ssrcs_(suspended_ssrcs), | 123 suspended_ssrcs_(suspended_ssrcs), |
122 module_process_thread_(module_process_thread), | 124 module_process_thread_(module_process_thread), |
| 125 call_stats_(call_stats), |
123 channel_group_(channel_group), | 126 channel_group_(channel_group), |
| 127 encoder_feedback_(new EncoderStateFeedback()), |
124 use_config_bitrate_(true), | 128 use_config_bitrate_(true), |
125 stats_proxy_(Clock::GetRealTimeClock(), config) { | 129 stats_proxy_(Clock::GetRealTimeClock(), config) { |
126 LOG(LS_INFO) << "VideoSendStream: " << config_.ToString(); | 130 LOG(LS_INFO) << "VideoSendStream: " << config_.ToString(); |
127 RTC_DCHECK(!config_.rtp.ssrcs.empty()); | 131 RTC_DCHECK(!config_.rtp.ssrcs.empty()); |
128 | 132 |
129 // Set up Call-wide sequence numbers, if configured for this send stream. | 133 // Set up Call-wide sequence numbers, if configured for this send stream. |
130 TransportFeedbackObserver* transport_feedback_observer = nullptr; | 134 TransportFeedbackObserver* transport_feedback_observer = nullptr; |
131 for (const RtpExtension& extension : config.rtp.extensions) { | 135 for (const RtpExtension& extension : config.rtp.extensions) { |
132 if (extension.name == RtpExtension::kTransportSequenceNumber) { | 136 if (extension.name == RtpExtension::kTransportSequenceNumber) { |
133 transport_feedback_observer = | 137 transport_feedback_observer = |
134 channel_group_->GetTransportFeedbackObserver(); | 138 channel_group_->GetTransportFeedbackObserver(); |
135 break; | 139 break; |
136 } | 140 } |
137 } | 141 } |
138 | 142 |
139 const std::vector<uint32_t>& ssrcs = config.rtp.ssrcs; | 143 const std::vector<uint32_t>& ssrcs = config.rtp.ssrcs; |
140 | 144 |
141 vie_encoder_.reset(new ViEEncoder( | 145 vie_encoder_.reset(new ViEEncoder( |
142 num_cpu_cores, module_process_thread_, &stats_proxy_, | 146 num_cpu_cores, module_process_thread_, &stats_proxy_, |
143 config.pre_encode_callback, channel_group_->pacer(), | 147 config.pre_encode_callback, channel_group_->pacer(), |
144 channel_group_->bitrate_allocator())); | 148 channel_group_->bitrate_allocator())); |
145 RTC_CHECK(vie_encoder_->Init()); | 149 RTC_CHECK(vie_encoder_->Init()); |
146 | 150 |
147 vie_channel_.reset(new ViEChannel( | 151 vie_channel_.reset(new ViEChannel( |
148 num_cpu_cores, config.send_transport, module_process_thread_, | 152 num_cpu_cores, config.send_transport, module_process_thread_, |
149 channel_group_->GetRtcpIntraFrameObserver(), | 153 encoder_feedback_->GetRtcpIntraFrameObserver(), |
150 channel_group_->GetBitrateController()->CreateRtcpBandwidthObserver(), | 154 channel_group_->GetBitrateController()->CreateRtcpBandwidthObserver(), |
151 transport_feedback_observer, | 155 transport_feedback_observer, |
152 channel_group_->GetRemoteBitrateEstimator(false), | 156 channel_group_->GetRemoteBitrateEstimator(false), |
153 channel_group_->GetCallStats()->rtcp_rtt_stats(), channel_group_->pacer(), | 157 call_stats_->rtcp_rtt_stats(), channel_group_->pacer(), |
154 channel_group_->packet_router(), ssrcs.size(), true)); | 158 channel_group_->packet_router(), ssrcs.size(), true)); |
155 RTC_CHECK(vie_channel_->Init() == 0); | 159 RTC_CHECK(vie_channel_->Init() == 0); |
156 | 160 |
157 channel_group_->GetCallStats()->RegisterStatsObserver( | 161 call_stats_->RegisterStatsObserver(vie_channel_->GetStatsObserver()); |
158 vie_channel_->GetStatsObserver()); | |
159 | 162 |
160 vie_encoder_->StartThreadsAndSetSharedMembers( | 163 vie_encoder_->StartThreadsAndSetSharedMembers( |
161 vie_channel_->send_payload_router(), | 164 vie_channel_->send_payload_router(), |
162 vie_channel_->vcm_protection_callback()); | 165 vie_channel_->vcm_protection_callback()); |
163 | 166 |
164 std::vector<uint32_t> first_ssrc(1, ssrcs[0]); | 167 std::vector<uint32_t> first_ssrc(1, ssrcs[0]); |
165 vie_encoder_->SetSsrcs(first_ssrc); | 168 vie_encoder_->SetSsrcs(first_ssrc); |
166 | 169 |
167 for (size_t i = 0; i < config_.rtp.extensions.size(); ++i) { | 170 for (size_t i = 0; i < config_.rtp.extensions.size(); ++i) { |
168 const std::string& extension = config_.rtp.extensions[i].name; | 171 const std::string& extension = config_.rtp.extensions[i].name; |
169 int id = config_.rtp.extensions[i].id; | 172 int id = config_.rtp.extensions[i].id; |
170 // One-byte-extension local identifiers are in the range 1-14 inclusive. | 173 // One-byte-extension local identifiers are in the range 1-14 inclusive. |
171 RTC_DCHECK_GE(id, 1); | 174 RTC_DCHECK_GE(id, 1); |
172 RTC_DCHECK_LE(id, 14); | 175 RTC_DCHECK_LE(id, 14); |
173 if (extension == RtpExtension::kTOffset) { | 176 if (extension == RtpExtension::kTOffset) { |
174 RTC_CHECK_EQ(0, vie_channel_->SetSendTimestampOffsetStatus(true, id)); | 177 RTC_CHECK_EQ(0, vie_channel_->SetSendTimestampOffsetStatus(true, id)); |
175 } else if (extension == RtpExtension::kAbsSendTime) { | 178 } else if (extension == RtpExtension::kAbsSendTime) { |
176 RTC_CHECK_EQ(0, vie_channel_->SetSendAbsoluteSendTimeStatus(true, id)); | 179 RTC_CHECK_EQ(0, vie_channel_->SetSendAbsoluteSendTimeStatus(true, id)); |
177 } else if (extension == RtpExtension::kVideoRotation) { | 180 } else if (extension == RtpExtension::kVideoRotation) { |
178 RTC_CHECK_EQ(0, vie_channel_->SetSendVideoRotationStatus(true, id)); | 181 RTC_CHECK_EQ(0, vie_channel_->SetSendVideoRotationStatus(true, id)); |
179 } else if (extension == RtpExtension::kTransportSequenceNumber) { | 182 } else if (extension == RtpExtension::kTransportSequenceNumber) { |
180 RTC_CHECK_EQ(0, vie_channel_->SetSendTransportSequenceNumber(true, id)); | 183 RTC_CHECK_EQ(0, vie_channel_->SetSendTransportSequenceNumber(true, id)); |
181 } else { | 184 } else { |
182 RTC_NOTREACHED() << "Registering unsupported RTP extension."; | 185 RTC_NOTREACHED() << "Registering unsupported RTP extension."; |
183 } | 186 } |
184 } | 187 } |
185 | 188 |
186 // TODO(pbos): Consider configuring REMB in Call. | 189 channel_group_->SetChannelRembStatus(true, false, vie_channel_->rtp_rtcp()); |
187 channel_group_->SetChannelRembStatus(true, false, vie_channel_.get()); | |
188 | 190 |
189 // Enable NACK, FEC or both. | 191 // Enable NACK, FEC or both. |
190 const bool enable_protection_nack = config_.rtp.nack.rtp_history_ms > 0; | 192 const bool enable_protection_nack = config_.rtp.nack.rtp_history_ms > 0; |
191 const bool enable_protection_fec = config_.rtp.fec.red_payload_type != -1; | 193 const bool enable_protection_fec = config_.rtp.fec.red_payload_type != -1; |
192 // TODO(changbin): Should set RTX for RED mapping in RTP sender in future. | 194 // TODO(changbin): Should set RTX for RED mapping in RTP sender in future. |
193 vie_channel_->SetProtectionMode(enable_protection_nack, enable_protection_fec, | 195 vie_channel_->SetProtectionMode(enable_protection_nack, enable_protection_fec, |
194 config_.rtp.fec.red_payload_type, | 196 config_.rtp.fec.red_payload_type, |
195 config_.rtp.fec.ulpfec_payload_type); | 197 config_.rtp.fec.ulpfec_payload_type); |
196 vie_encoder_->UpdateProtectionMethod(enable_protection_nack, | 198 vie_encoder_->UpdateProtectionMethod(enable_protection_nack, |
197 enable_protection_fec); | 199 enable_protection_fec); |
(...skipping 21 matching lines...) Expand all Loading... |
219 RTC_CHECK(ReconfigureVideoEncoder(encoder_config)); | 221 RTC_CHECK(ReconfigureVideoEncoder(encoder_config)); |
220 | 222 |
221 vie_channel_->RegisterSendSideDelayObserver(&stats_proxy_); | 223 vie_channel_->RegisterSendSideDelayObserver(&stats_proxy_); |
222 | 224 |
223 if (config_.post_encode_callback) | 225 if (config_.post_encode_callback) |
224 vie_encoder_->RegisterPostEncodeImageCallback(&encoded_frame_proxy_); | 226 vie_encoder_->RegisterPostEncodeImageCallback(&encoded_frame_proxy_); |
225 | 227 |
226 if (config_.suspend_below_min_bitrate) | 228 if (config_.suspend_below_min_bitrate) |
227 vie_encoder_->SuspendBelowMinBitrate(); | 229 vie_encoder_->SuspendBelowMinBitrate(); |
228 | 230 |
229 channel_group_->AddEncoder(ssrcs, vie_encoder_.get()); | 231 channel_group_->AddEncoder(vie_encoder_.get()); |
| 232 encoder_feedback_->AddEncoder(ssrcs, vie_encoder_.get()); |
230 | 233 |
231 vie_channel_->RegisterSendChannelRtcpStatisticsCallback(&stats_proxy_); | 234 vie_channel_->RegisterSendChannelRtcpStatisticsCallback(&stats_proxy_); |
232 vie_channel_->RegisterSendChannelRtpStatisticsCallback(&stats_proxy_); | 235 vie_channel_->RegisterSendChannelRtpStatisticsCallback(&stats_proxy_); |
233 vie_channel_->RegisterRtcpPacketTypeCounterObserver(&stats_proxy_); | 236 vie_channel_->RegisterRtcpPacketTypeCounterObserver(&stats_proxy_); |
234 vie_channel_->RegisterSendBitrateObserver(&stats_proxy_); | 237 vie_channel_->RegisterSendBitrateObserver(&stats_proxy_); |
235 vie_channel_->RegisterSendFrameCountObserver(&stats_proxy_); | 238 vie_channel_->RegisterSendFrameCountObserver(&stats_proxy_); |
236 } | 239 } |
237 | 240 |
238 VideoSendStream::~VideoSendStream() { | 241 VideoSendStream::~VideoSendStream() { |
239 LOG(LS_INFO) << "~VideoSendStream: " << config_.ToString(); | 242 LOG(LS_INFO) << "~VideoSendStream: " << config_.ToString(); |
240 vie_channel_->RegisterSendFrameCountObserver(nullptr); | 243 vie_channel_->RegisterSendFrameCountObserver(nullptr); |
241 vie_channel_->RegisterSendBitrateObserver(nullptr); | 244 vie_channel_->RegisterSendBitrateObserver(nullptr); |
242 vie_channel_->RegisterRtcpPacketTypeCounterObserver(nullptr); | 245 vie_channel_->RegisterRtcpPacketTypeCounterObserver(nullptr); |
243 vie_channel_->RegisterSendChannelRtpStatisticsCallback(nullptr); | 246 vie_channel_->RegisterSendChannelRtpStatisticsCallback(nullptr); |
244 vie_channel_->RegisterSendChannelRtcpStatisticsCallback(nullptr); | 247 vie_channel_->RegisterSendChannelRtcpStatisticsCallback(nullptr); |
245 | 248 |
246 // Remove capture input (thread) so that it's not running after the current | 249 // Remove capture input (thread) so that it's not running after the current |
247 // channel is deleted. | 250 // channel is deleted. |
248 input_.reset(); | 251 input_.reset(); |
249 | 252 |
250 vie_encoder_->DeRegisterExternalEncoder( | 253 vie_encoder_->DeRegisterExternalEncoder( |
251 config_.encoder_settings.payload_type); | 254 config_.encoder_settings.payload_type); |
252 | 255 |
253 channel_group_->GetCallStats()->DeregisterStatsObserver( | 256 call_stats_->DeregisterStatsObserver(vie_channel_->GetStatsObserver()); |
254 vie_channel_->GetStatsObserver()); | 257 channel_group_->SetChannelRembStatus(false, false, vie_channel_->rtp_rtcp()); |
255 channel_group_->SetChannelRembStatus(false, false, vie_channel_.get()); | |
256 | 258 |
257 // Remove the feedback, stop all encoding threads and processing. This must be | 259 // Remove the feedback, stop all encoding threads and processing. This must be |
258 // done before deleting the channel. | 260 // done before deleting the channel. |
259 channel_group_->RemoveEncoder(vie_encoder_.get()); | 261 channel_group_->RemoveEncoder(vie_encoder_.get()); |
| 262 encoder_feedback_->RemoveEncoder(vie_encoder_.get()); |
260 vie_encoder_->StopThreadsAndRemoveSharedMembers(); | 263 vie_encoder_->StopThreadsAndRemoveSharedMembers(); |
261 | 264 |
262 uint32_t remote_ssrc = vie_channel_->GetRemoteSSRC(); | 265 uint32_t remote_ssrc = vie_channel_->GetRemoteSSRC(); |
263 channel_group_->GetRemoteBitrateEstimator(false)->RemoveStream(remote_ssrc); | 266 channel_group_->GetRemoteBitrateEstimator(false)->RemoveStream(remote_ssrc); |
264 } | 267 } |
265 | 268 |
266 VideoCaptureInput* VideoSendStream::Input() { | 269 VideoCaptureInput* VideoSendStream::Input() { |
267 return input_.get(); | 270 return input_.get(); |
268 } | 271 } |
269 | 272 |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 vie_channel_->IsSendingFecEnabled()); | 552 vie_channel_->IsSendingFecEnabled()); |
550 | 553 |
551 // Restart the media flow | 554 // Restart the media flow |
552 vie_encoder_->Restart(); | 555 vie_encoder_->Restart(); |
553 | 556 |
554 return true; | 557 return true; |
555 } | 558 } |
556 | 559 |
557 } // namespace internal | 560 } // namespace internal |
558 } // namespace webrtc | 561 } // namespace webrtc |
OLD | NEW |