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/base/logging.h" | 19 #include "webrtc/base/logging.h" |
20 #include "webrtc/base/trace_event.h" | 20 #include "webrtc/base/trace_event.h" |
21 #include "webrtc/call/congestion_controller.h" | 21 #include "webrtc/call/congestion_controller.h" |
22 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 22 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
23 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" | 23 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" |
24 #include "webrtc/modules/pacing/packet_router.h" | 24 #include "webrtc/modules/pacing/packet_router.h" |
25 #include "webrtc/video/call_stats.h" | 25 #include "webrtc/video/call_stats.h" |
26 #include "webrtc/video/encoder_state_feedback.h" | 26 #include "webrtc/video/encoder_state_feedback.h" |
27 #include "webrtc/video/payload_router.h" | |
28 #include "webrtc/video/video_capture_input.h" | 27 #include "webrtc/video/video_capture_input.h" |
29 #include "webrtc/video/vie_channel.h" | 28 #include "webrtc/video/vie_channel.h" |
30 #include "webrtc/video/vie_encoder.h" | 29 #include "webrtc/video/vie_encoder.h" |
31 #include "webrtc/video_send_stream.h" | 30 #include "webrtc/video_send_stream.h" |
32 | 31 |
33 namespace webrtc { | 32 namespace webrtc { |
34 | 33 |
35 class PacedSender; | 34 class PacedSender; |
36 class RtcpIntraFrameObserver; | 35 class RtcpIntraFrameObserver; |
37 class TransportFeedbackObserver; | 36 class TransportFeedbackObserver; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 const VideoSendStream::Config& config, | 116 const VideoSendStream::Config& config, |
118 const VideoEncoderConfig& encoder_config, | 117 const VideoEncoderConfig& encoder_config, |
119 const std::map<uint32_t, RtpState>& suspended_ssrcs) | 118 const std::map<uint32_t, RtpState>& suspended_ssrcs) |
120 : stats_proxy_(Clock::GetRealTimeClock(), | 119 : stats_proxy_(Clock::GetRealTimeClock(), |
121 config, | 120 config, |
122 encoder_config.content_type), | 121 encoder_config.content_type), |
123 transport_adapter_(config.send_transport), | 122 transport_adapter_(config.send_transport), |
124 encoded_frame_proxy_(config.post_encode_callback), | 123 encoded_frame_proxy_(config.post_encode_callback), |
125 config_(config), | 124 config_(config), |
126 suspended_ssrcs_(suspended_ssrcs), | 125 suspended_ssrcs_(suspended_ssrcs), |
127 module_process_thread_(module_process_thread), | |
128 call_stats_(call_stats), | 126 call_stats_(call_stats), |
129 congestion_controller_(congestion_controller), | 127 congestion_controller_(congestion_controller), |
130 encoder_feedback_(new EncoderStateFeedback()), | 128 encoder_feedback_(new EncoderStateFeedback()), |
131 use_config_bitrate_(true) { | 129 use_config_bitrate_(true) { |
132 LOG(LS_INFO) << "VideoSendStream: " << config_.ToString(); | 130 LOG(LS_INFO) << "VideoSendStream: " << config_.ToString(); |
133 RTC_DCHECK(!config_.rtp.ssrcs.empty()); | 131 RTC_DCHECK(!config_.rtp.ssrcs.empty()); |
134 | 132 |
135 // 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. |
136 TransportFeedbackObserver* transport_feedback_observer = nullptr; | 134 TransportFeedbackObserver* transport_feedback_observer = nullptr; |
137 for (const RtpExtension& extension : config.rtp.extensions) { | 135 for (const RtpExtension& extension : config.rtp.extensions) { |
138 if (extension.name == RtpExtension::kTransportSequenceNumber) { | 136 if (extension.name == RtpExtension::kTransportSequenceNumber) { |
139 transport_feedback_observer = | 137 transport_feedback_observer = |
140 congestion_controller_->GetTransportFeedbackObserver(); | 138 congestion_controller_->GetTransportFeedbackObserver(); |
141 break; | 139 break; |
142 } | 140 } |
143 } | 141 } |
144 | 142 |
145 const std::vector<uint32_t>& ssrcs = config.rtp.ssrcs; | 143 const std::vector<uint32_t>& ssrcs = config.rtp.ssrcs; |
146 | 144 |
147 vie_encoder_.reset(new ViEEncoder( | 145 vie_encoder_.reset(new ViEEncoder(num_cpu_cores, module_process_thread, |
148 num_cpu_cores, module_process_thread_, &stats_proxy_, | 146 &stats_proxy_, config.pre_encode_callback, |
149 config.pre_encode_callback, congestion_controller_->pacer(), | 147 congestion_controller_->pacer(), |
150 bitrate_allocator)); | 148 &payload_router_, bitrate_allocator)); |
| 149 vcm_ = vie_encoder_->vcm(); |
151 RTC_CHECK(vie_encoder_->Init()); | 150 RTC_CHECK(vie_encoder_->Init()); |
152 | 151 |
153 vie_channel_.reset(new ViEChannel( | 152 vie_channel_.reset(new ViEChannel( |
154 num_cpu_cores, config.send_transport, module_process_thread_, | 153 num_cpu_cores, config.send_transport, module_process_thread, |
155 encoder_feedback_->GetRtcpIntraFrameObserver(), | 154 &payload_router_, nullptr, encoder_feedback_->GetRtcpIntraFrameObserver(), |
156 congestion_controller_->GetBitrateController()-> | 155 congestion_controller_->GetBitrateController() |
157 CreateRtcpBandwidthObserver(), | 156 ->CreateRtcpBandwidthObserver(), |
158 transport_feedback_observer, | 157 transport_feedback_observer, |
159 congestion_controller_->GetRemoteBitrateEstimator(false), | 158 congestion_controller_->GetRemoteBitrateEstimator(false), |
160 call_stats_->rtcp_rtt_stats(), congestion_controller_->pacer(), | 159 call_stats_->rtcp_rtt_stats(), congestion_controller_->pacer(), |
161 congestion_controller_->packet_router(), ssrcs.size(), true)); | 160 congestion_controller_->packet_router(), ssrcs.size(), true)); |
162 RTC_CHECK(vie_channel_->Init() == 0); | 161 RTC_CHECK(vie_channel_->Init() == 0); |
163 | 162 |
| 163 vcm_->RegisterProtectionCallback(vie_channel_->vcm_protection_callback()); |
| 164 |
164 call_stats_->RegisterStatsObserver(vie_channel_->GetStatsObserver()); | 165 call_stats_->RegisterStatsObserver(vie_channel_->GetStatsObserver()); |
165 | 166 |
166 vie_encoder_->StartThreadsAndSetSharedMembers( | |
167 vie_channel_->send_payload_router(), | |
168 vie_channel_->vcm_protection_callback()); | |
169 | |
170 std::vector<uint32_t> first_ssrc(1, ssrcs[0]); | 167 std::vector<uint32_t> first_ssrc(1, ssrcs[0]); |
171 vie_encoder_->SetSsrcs(first_ssrc); | 168 vie_encoder_->SetSsrcs(first_ssrc); |
172 | 169 |
173 for (size_t i = 0; i < config_.rtp.extensions.size(); ++i) { | 170 for (size_t i = 0; i < config_.rtp.extensions.size(); ++i) { |
174 const std::string& extension = config_.rtp.extensions[i].name; | 171 const std::string& extension = config_.rtp.extensions[i].name; |
175 int id = config_.rtp.extensions[i].id; | 172 int id = config_.rtp.extensions[i].id; |
176 // 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. |
177 RTC_DCHECK_GE(id, 1); | 174 RTC_DCHECK_GE(id, 1); |
178 RTC_DCHECK_LE(id, 14); | 175 RTC_DCHECK_LE(id, 14); |
179 if (extension == RtpExtension::kTOffset) { | 176 if (extension == RtpExtension::kTOffset) { |
(...skipping 20 matching lines...) Expand all Loading... |
200 config_.rtp.fec.red_payload_type, | 197 config_.rtp.fec.red_payload_type, |
201 config_.rtp.fec.ulpfec_payload_type); | 198 config_.rtp.fec.ulpfec_payload_type); |
202 vie_encoder_->SetProtectionMethod(enable_protection_nack, | 199 vie_encoder_->SetProtectionMethod(enable_protection_nack, |
203 enable_protection_fec); | 200 enable_protection_fec); |
204 | 201 |
205 ConfigureSsrcs(); | 202 ConfigureSsrcs(); |
206 | 203 |
207 vie_channel_->SetRTCPCName(config_.rtp.c_name.c_str()); | 204 vie_channel_->SetRTCPCName(config_.rtp.c_name.c_str()); |
208 | 205 |
209 input_.reset(new internal::VideoCaptureInput( | 206 input_.reset(new internal::VideoCaptureInput( |
210 module_process_thread_, vie_encoder_.get(), config_.local_renderer, | 207 module_process_thread, vie_encoder_.get(), config_.local_renderer, |
211 &stats_proxy_, this, config_.encoding_time_observer)); | 208 &stats_proxy_, this, config_.encoding_time_observer)); |
212 | 209 |
213 // 28 to match packet overhead in ModuleRtpRtcpImpl. | 210 // 28 to match packet overhead in ModuleRtpRtcpImpl. |
214 RTC_DCHECK_LE(config_.rtp.max_packet_size, static_cast<size_t>(0xFFFF - 28)); | 211 RTC_DCHECK_LE(config_.rtp.max_packet_size, static_cast<size_t>(0xFFFF - 28)); |
215 vie_channel_->SetMTU(static_cast<uint16_t>(config_.rtp.max_packet_size + 28)); | 212 vie_channel_->SetMTU(static_cast<uint16_t>(config_.rtp.max_packet_size + 28)); |
216 | 213 |
217 RTC_DCHECK(config.encoder_settings.encoder != nullptr); | 214 RTC_DCHECK(config.encoder_settings.encoder != nullptr); |
218 RTC_DCHECK_GE(config.encoder_settings.payload_type, 0); | 215 RTC_DCHECK_GE(config.encoder_settings.payload_type, 0); |
219 RTC_DCHECK_LE(config.encoder_settings.payload_type, 127); | 216 RTC_DCHECK_LE(config.encoder_settings.payload_type, 127); |
220 RTC_CHECK_EQ(0, vie_encoder_->RegisterExternalEncoder( | 217 RTC_CHECK_EQ(0, vie_encoder_->RegisterExternalEncoder( |
(...skipping 16 matching lines...) Expand all Loading... |
237 | 234 |
238 vie_channel_->RegisterSendChannelRtcpStatisticsCallback(&stats_proxy_); | 235 vie_channel_->RegisterSendChannelRtcpStatisticsCallback(&stats_proxy_); |
239 vie_channel_->RegisterSendChannelRtpStatisticsCallback(&stats_proxy_); | 236 vie_channel_->RegisterSendChannelRtpStatisticsCallback(&stats_proxy_); |
240 vie_channel_->RegisterRtcpPacketTypeCounterObserver(&stats_proxy_); | 237 vie_channel_->RegisterRtcpPacketTypeCounterObserver(&stats_proxy_); |
241 vie_channel_->RegisterSendBitrateObserver(&stats_proxy_); | 238 vie_channel_->RegisterSendBitrateObserver(&stats_proxy_); |
242 vie_channel_->RegisterSendFrameCountObserver(&stats_proxy_); | 239 vie_channel_->RegisterSendFrameCountObserver(&stats_proxy_); |
243 } | 240 } |
244 | 241 |
245 VideoSendStream::~VideoSendStream() { | 242 VideoSendStream::~VideoSendStream() { |
246 LOG(LS_INFO) << "~VideoSendStream: " << config_.ToString(); | 243 LOG(LS_INFO) << "~VideoSendStream: " << config_.ToString(); |
| 244 // Remove vcm_protection_callback (part of vie_channel_) before destroying |
| 245 // ViEChannel. vcm_ is owned by ViEEncoder and the registered callback does |
| 246 // not outlive it. |
| 247 vcm_->RegisterProtectionCallback(nullptr); |
247 vie_channel_->RegisterSendFrameCountObserver(nullptr); | 248 vie_channel_->RegisterSendFrameCountObserver(nullptr); |
248 vie_channel_->RegisterSendBitrateObserver(nullptr); | 249 vie_channel_->RegisterSendBitrateObserver(nullptr); |
249 vie_channel_->RegisterRtcpPacketTypeCounterObserver(nullptr); | 250 vie_channel_->RegisterRtcpPacketTypeCounterObserver(nullptr); |
250 vie_channel_->RegisterSendChannelRtpStatisticsCallback(nullptr); | 251 vie_channel_->RegisterSendChannelRtpStatisticsCallback(nullptr); |
251 vie_channel_->RegisterSendChannelRtcpStatisticsCallback(nullptr); | 252 vie_channel_->RegisterSendChannelRtcpStatisticsCallback(nullptr); |
252 | 253 |
253 // Remove capture input (thread) so that it's not running after the current | 254 // Remove capture input (thread) so that it's not running after the current |
254 // channel is deleted. | 255 // channel is deleted. |
255 input_.reset(); | 256 input_.reset(); |
256 | 257 |
257 vie_encoder_->DeRegisterExternalEncoder( | 258 vie_encoder_->DeRegisterExternalEncoder( |
258 config_.encoder_settings.payload_type); | 259 config_.encoder_settings.payload_type); |
259 | 260 |
260 call_stats_->DeregisterStatsObserver(vie_channel_->GetStatsObserver()); | 261 call_stats_->DeregisterStatsObserver(vie_channel_->GetStatsObserver()); |
261 congestion_controller_->SetChannelRembStatus(false, false, | 262 congestion_controller_->SetChannelRembStatus(false, false, |
262 vie_channel_->rtp_rtcp()); | 263 vie_channel_->rtp_rtcp()); |
263 | 264 |
264 // Remove the feedback, stop all encoding threads and processing. This must be | 265 // Remove the feedback, stop all encoding threads and processing. This must be |
265 // done before deleting the channel. | 266 // done before deleting the channel. |
266 congestion_controller_->RemoveEncoder(vie_encoder_.get()); | 267 congestion_controller_->RemoveEncoder(vie_encoder_.get()); |
267 encoder_feedback_->RemoveEncoder(vie_encoder_.get()); | 268 encoder_feedback_->RemoveEncoder(vie_encoder_.get()); |
268 vie_encoder_->StopThreadsAndRemoveSharedMembers(); | |
269 | 269 |
270 uint32_t remote_ssrc = vie_channel_->GetRemoteSSRC(); | 270 uint32_t remote_ssrc = vie_channel_->GetRemoteSSRC(); |
271 congestion_controller_->GetRemoteBitrateEstimator(false)->RemoveStream( | 271 congestion_controller_->GetRemoteBitrateEstimator(false)->RemoveStream( |
272 remote_ssrc); | 272 remote_ssrc); |
273 } | 273 } |
274 | 274 |
275 VideoCaptureInput* VideoSendStream::Input() { | 275 VideoCaptureInput* VideoSendStream::Input() { |
276 return input_.get(); | 276 return input_.get(); |
277 } | 277 } |
278 | 278 |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 vie_encoder_->SetSsrcs(used_ssrcs); | 575 vie_encoder_->SetSsrcs(used_ssrcs); |
576 | 576 |
577 // Restart the media flow | 577 // Restart the media flow |
578 vie_encoder_->Restart(); | 578 vie_encoder_->Restart(); |
579 | 579 |
580 return true; | 580 return true; |
581 } | 581 } |
582 | 582 |
583 } // namespace internal | 583 } // namespace internal |
584 } // namespace webrtc | 584 } // namespace webrtc |
OLD | NEW |