| 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/modules/utility/include/process_thread.h" | 25 #include "webrtc/modules/utility/include/process_thread.h" |
| 26 #include "webrtc/video/call_stats.h" | 26 #include "webrtc/video/call_stats.h" |
| 27 #include "webrtc/video/encoder_state_feedback.h" | |
| 28 #include "webrtc/video/video_capture_input.h" | 27 #include "webrtc/video/video_capture_input.h" |
| 29 #include "webrtc/video/vie_channel.h" | |
| 30 #include "webrtc/video/vie_encoder.h" | |
| 31 #include "webrtc/video/vie_remb.h" | 28 #include "webrtc/video/vie_remb.h" |
| 32 #include "webrtc/video_send_stream.h" | 29 #include "webrtc/video_send_stream.h" |
| 33 | 30 |
| 34 namespace webrtc { | 31 namespace webrtc { |
| 35 | 32 |
| 36 class PacedSender; | 33 class PacedSender; |
| 37 class RtcpIntraFrameObserver; | 34 class RtcpIntraFrameObserver; |
| 38 class TransportFeedbackObserver; | 35 class TransportFeedbackObserver; |
| 39 | 36 |
| 40 std::string | 37 std::string |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 module_process_thread_(module_process_thread), | 138 module_process_thread_(module_process_thread), |
| 142 call_stats_(call_stats), | 139 call_stats_(call_stats), |
| 143 congestion_controller_(congestion_controller), | 140 congestion_controller_(congestion_controller), |
| 144 remb_(remb), | 141 remb_(remb), |
| 145 overuse_detector_( | 142 overuse_detector_( |
| 146 Clock::GetRealTimeClock(), | 143 Clock::GetRealTimeClock(), |
| 147 GetCpuOveruseOptions(config.encoder_settings.full_overuse_time), | 144 GetCpuOveruseOptions(config.encoder_settings.full_overuse_time), |
| 148 this, | 145 this, |
| 149 config.post_encode_callback, | 146 config.post_encode_callback, |
| 150 &stats_proxy_), | 147 &stats_proxy_), |
| 151 encoder_feedback_(new EncoderStateFeedback()), | 148 vie_encoder_(num_cpu_cores, |
| 152 use_config_bitrate_(true) { | 149 module_process_thread_, |
| 150 &stats_proxy_, |
| 151 config.pre_encode_callback, |
| 152 &overuse_detector_, |
| 153 congestion_controller_->pacer(), |
| 154 &payload_router_, |
| 155 bitrate_allocator), |
| 156 vcm_(vie_encoder_.vcm()), |
| 157 vie_channel_(config.send_transport, |
| 158 module_process_thread_, |
| 159 &payload_router_, |
| 160 nullptr, |
| 161 encoder_feedback_.GetRtcpIntraFrameObserver(), |
| 162 congestion_controller_->GetBitrateController() |
| 163 ->CreateRtcpBandwidthObserver(), |
| 164 congestion_controller_->GetTransportFeedbackObserver(), |
| 165 nullptr, |
| 166 call_stats_->rtcp_rtt_stats(), |
| 167 congestion_controller_->pacer(), |
| 168 congestion_controller_->packet_router(), |
| 169 config_.rtp.ssrcs.size(), |
| 170 true), |
| 171 input_(&vie_encoder_, |
| 172 config_.local_renderer, |
| 173 &stats_proxy_, |
| 174 &overuse_detector_) { |
| 153 LOG(LS_INFO) << "VideoSendStream: " << config_.ToString(); | 175 LOG(LS_INFO) << "VideoSendStream: " << config_.ToString(); |
| 154 | 176 |
| 155 RTC_DCHECK(!config_.rtp.ssrcs.empty()); | 177 RTC_DCHECK(!config_.rtp.ssrcs.empty()); |
| 156 RTC_DCHECK(module_process_thread_); | 178 RTC_DCHECK(module_process_thread_); |
| 157 RTC_DCHECK(call_stats_); | 179 RTC_DCHECK(call_stats_); |
| 158 RTC_DCHECK(congestion_controller_); | 180 RTC_DCHECK(congestion_controller_); |
| 159 RTC_DCHECK(remb_); | 181 RTC_DCHECK(remb_); |
| 160 | 182 |
| 161 // Set up Call-wide sequence numbers, if configured for this send stream. | 183 RTC_CHECK(vie_encoder_.Init()); |
| 162 TransportFeedbackObserver* transport_feedback_observer = nullptr; | 184 RTC_CHECK(vie_channel_.Init() == 0); |
| 163 for (const RtpExtension& extension : config.rtp.extensions) { | |
| 164 if (extension.name == RtpExtension::kTransportSequenceNumber) { | |
| 165 transport_feedback_observer = | |
| 166 congestion_controller_->GetTransportFeedbackObserver(); | |
| 167 break; | |
| 168 } | |
| 169 } | |
| 170 | 185 |
| 171 const std::vector<uint32_t>& ssrcs = config.rtp.ssrcs; | 186 vcm_->RegisterProtectionCallback(vie_channel_.vcm_protection_callback()); |
| 172 | 187 |
| 173 vie_encoder_.reset(new ViEEncoder( | 188 call_stats_->RegisterStatsObserver(vie_channel_.GetStatsObserver()); |
| 174 num_cpu_cores, module_process_thread_, &stats_proxy_, | |
| 175 config.pre_encode_callback, &overuse_detector_, | |
| 176 congestion_controller_->pacer(), &payload_router_, bitrate_allocator)); | |
| 177 vcm_ = vie_encoder_->vcm(); | |
| 178 RTC_CHECK(vie_encoder_->Init()); | |
| 179 | 189 |
| 180 vie_channel_.reset(new ViEChannel( | 190 vie_encoder_.SetSsrcs(std::vector<uint32_t>(1, config_.rtp.ssrcs[0])); |
| 181 config.send_transport, module_process_thread_, &payload_router_, nullptr, | |
| 182 encoder_feedback_->GetRtcpIntraFrameObserver(), | |
| 183 congestion_controller_->GetBitrateController() | |
| 184 ->CreateRtcpBandwidthObserver(), | |
| 185 transport_feedback_observer, | |
| 186 congestion_controller_->GetRemoteBitrateEstimator(false), | |
| 187 call_stats_->rtcp_rtt_stats(), congestion_controller_->pacer(), | |
| 188 congestion_controller_->packet_router(), ssrcs.size(), true)); | |
| 189 RTC_CHECK(vie_channel_->Init() == 0); | |
| 190 | |
| 191 vcm_->RegisterProtectionCallback(vie_channel_->vcm_protection_callback()); | |
| 192 | |
| 193 call_stats_->RegisterStatsObserver(vie_channel_->GetStatsObserver()); | |
| 194 | |
| 195 std::vector<uint32_t> first_ssrc(1, ssrcs[0]); | |
| 196 vie_encoder_->SetSsrcs(first_ssrc); | |
| 197 | 191 |
| 198 for (size_t i = 0; i < config_.rtp.extensions.size(); ++i) { | 192 for (size_t i = 0; i < config_.rtp.extensions.size(); ++i) { |
| 199 const std::string& extension = config_.rtp.extensions[i].name; | 193 const std::string& extension = config_.rtp.extensions[i].name; |
| 200 int id = config_.rtp.extensions[i].id; | 194 int id = config_.rtp.extensions[i].id; |
| 201 // One-byte-extension local identifiers are in the range 1-14 inclusive. | 195 // One-byte-extension local identifiers are in the range 1-14 inclusive. |
| 202 RTC_DCHECK_GE(id, 1); | 196 RTC_DCHECK_GE(id, 1); |
| 203 RTC_DCHECK_LE(id, 14); | 197 RTC_DCHECK_LE(id, 14); |
| 204 if (extension == RtpExtension::kTOffset) { | 198 if (extension == RtpExtension::kTOffset) { |
| 205 RTC_CHECK_EQ(0, vie_channel_->SetSendTimestampOffsetStatus(true, id)); | 199 RTC_CHECK_EQ(0, vie_channel_.SetSendTimestampOffsetStatus(true, id)); |
| 206 } else if (extension == RtpExtension::kAbsSendTime) { | 200 } else if (extension == RtpExtension::kAbsSendTime) { |
| 207 RTC_CHECK_EQ(0, vie_channel_->SetSendAbsoluteSendTimeStatus(true, id)); | 201 RTC_CHECK_EQ(0, vie_channel_.SetSendAbsoluteSendTimeStatus(true, id)); |
| 208 } else if (extension == RtpExtension::kVideoRotation) { | 202 } else if (extension == RtpExtension::kVideoRotation) { |
| 209 RTC_CHECK_EQ(0, vie_channel_->SetSendVideoRotationStatus(true, id)); | 203 RTC_CHECK_EQ(0, vie_channel_.SetSendVideoRotationStatus(true, id)); |
| 210 } else if (extension == RtpExtension::kTransportSequenceNumber) { | 204 } else if (extension == RtpExtension::kTransportSequenceNumber) { |
| 211 RTC_CHECK_EQ(0, vie_channel_->SetSendTransportSequenceNumber(true, id)); | 205 RTC_CHECK_EQ(0, vie_channel_.SetSendTransportSequenceNumber(true, id)); |
| 212 } else { | 206 } else { |
| 213 RTC_NOTREACHED() << "Registering unsupported RTP extension."; | 207 RTC_NOTREACHED() << "Registering unsupported RTP extension."; |
| 214 } | 208 } |
| 215 } | 209 } |
| 216 | 210 |
| 217 RtpRtcp* rtp_module = vie_channel_->rtp_rtcp(); | 211 RtpRtcp* rtp_module = vie_channel_.rtp_rtcp(); |
| 218 remb_->AddRembSender(rtp_module); | 212 remb_->AddRembSender(rtp_module); |
| 219 rtp_module->SetREMBStatus(true); | 213 rtp_module->SetREMBStatus(true); |
| 220 | 214 |
| 221 // Enable NACK, FEC or both. | 215 // Enable NACK, FEC or both. |
| 222 const bool enable_protection_nack = config_.rtp.nack.rtp_history_ms > 0; | 216 const bool enable_protection_nack = config_.rtp.nack.rtp_history_ms > 0; |
| 223 const bool enable_protection_fec = config_.rtp.fec.red_payload_type != -1; | 217 const bool enable_protection_fec = config_.rtp.fec.red_payload_type != -1; |
| 224 // TODO(changbin): Should set RTX for RED mapping in RTP sender in future. | 218 // TODO(changbin): Should set RTX for RED mapping in RTP sender in future. |
| 225 vie_channel_->SetProtectionMode(enable_protection_nack, enable_protection_fec, | 219 vie_channel_.SetProtectionMode(enable_protection_nack, enable_protection_fec, |
| 226 config_.rtp.fec.red_payload_type, | 220 config_.rtp.fec.red_payload_type, |
| 227 config_.rtp.fec.ulpfec_payload_type); | 221 config_.rtp.fec.ulpfec_payload_type); |
| 228 vie_encoder_->SetProtectionMethod(enable_protection_nack, | 222 vie_encoder_.SetProtectionMethod(enable_protection_nack, |
| 229 enable_protection_fec); | 223 enable_protection_fec); |
| 230 | 224 |
| 231 ConfigureSsrcs(); | 225 ConfigureSsrcs(); |
| 232 | 226 |
| 233 vie_channel_->SetRTCPCName(config_.rtp.c_name.c_str()); | 227 vie_channel_.SetRTCPCName(config_.rtp.c_name.c_str()); |
| 234 | |
| 235 input_.reset(new internal::VideoCaptureInput( | |
| 236 vie_encoder_.get(), config_.local_renderer, &stats_proxy_, | |
| 237 &overuse_detector_)); | |
| 238 | 228 |
| 239 // 28 to match packet overhead in ModuleRtpRtcpImpl. | 229 // 28 to match packet overhead in ModuleRtpRtcpImpl. |
| 240 RTC_DCHECK_LE(config_.rtp.max_packet_size, static_cast<size_t>(0xFFFF - 28)); | 230 RTC_DCHECK_LE(config_.rtp.max_packet_size, static_cast<size_t>(0xFFFF - 28)); |
| 241 vie_channel_->SetMTU(static_cast<uint16_t>(config_.rtp.max_packet_size + 28)); | 231 vie_channel_.SetMTU(static_cast<uint16_t>(config_.rtp.max_packet_size + 28)); |
| 242 | 232 |
| 243 RTC_DCHECK(config.encoder_settings.encoder != nullptr); | 233 RTC_DCHECK(config.encoder_settings.encoder != nullptr); |
| 244 RTC_DCHECK_GE(config.encoder_settings.payload_type, 0); | 234 RTC_DCHECK_GE(config.encoder_settings.payload_type, 0); |
| 245 RTC_DCHECK_LE(config.encoder_settings.payload_type, 127); | 235 RTC_DCHECK_LE(config.encoder_settings.payload_type, 127); |
| 246 RTC_CHECK_EQ(0, vie_encoder_->RegisterExternalEncoder( | 236 RTC_CHECK_EQ(0, vie_encoder_.RegisterExternalEncoder( |
| 247 config.encoder_settings.encoder, | 237 config.encoder_settings.encoder, |
| 248 config.encoder_settings.payload_type, | 238 config.encoder_settings.payload_type, |
| 249 config.encoder_settings.internal_source)); | 239 config.encoder_settings.internal_source)); |
| 250 | 240 |
| 251 RTC_CHECK(ReconfigureVideoEncoder(encoder_config)); | 241 RTC_CHECK(ReconfigureVideoEncoder(encoder_config)); |
| 252 | 242 |
| 253 vie_channel_->RegisterSendSideDelayObserver(&stats_proxy_); | 243 vie_channel_.RegisterSendSideDelayObserver(&stats_proxy_); |
| 254 | 244 |
| 255 if (config_.post_encode_callback) | 245 if (config_.post_encode_callback) |
| 256 vie_encoder_->RegisterPostEncodeImageCallback(&encoded_frame_proxy_); | 246 vie_encoder_.RegisterPostEncodeImageCallback(&encoded_frame_proxy_); |
| 257 | 247 |
| 258 if (config_.suspend_below_min_bitrate) | 248 if (config_.suspend_below_min_bitrate) |
| 259 vie_encoder_->SuspendBelowMinBitrate(); | 249 vie_encoder_.SuspendBelowMinBitrate(); |
| 260 | 250 |
| 261 encoder_feedback_->AddEncoder(ssrcs, vie_encoder_.get()); | 251 encoder_feedback_.AddEncoder(config_.rtp.ssrcs, &vie_encoder_); |
| 262 | 252 |
| 263 vie_channel_->RegisterSendChannelRtcpStatisticsCallback(&stats_proxy_); | 253 vie_channel_.RegisterSendChannelRtcpStatisticsCallback(&stats_proxy_); |
| 264 vie_channel_->RegisterSendChannelRtpStatisticsCallback(&stats_proxy_); | 254 vie_channel_.RegisterSendChannelRtpStatisticsCallback(&stats_proxy_); |
| 265 vie_channel_->RegisterRtcpPacketTypeCounterObserver(&stats_proxy_); | 255 vie_channel_.RegisterRtcpPacketTypeCounterObserver(&stats_proxy_); |
| 266 vie_channel_->RegisterSendBitrateObserver(&stats_proxy_); | 256 vie_channel_.RegisterSendBitrateObserver(&stats_proxy_); |
| 267 vie_channel_->RegisterSendFrameCountObserver(&stats_proxy_); | 257 vie_channel_.RegisterSendFrameCountObserver(&stats_proxy_); |
| 268 | 258 |
| 269 module_process_thread_->RegisterModule(&overuse_detector_); | 259 module_process_thread_->RegisterModule(&overuse_detector_); |
| 270 } | 260 } |
| 271 | 261 |
| 272 VideoSendStream::~VideoSendStream() { | 262 VideoSendStream::~VideoSendStream() { |
| 273 LOG(LS_INFO) << "~VideoSendStream: " << config_.ToString(); | 263 LOG(LS_INFO) << "~VideoSendStream: " << config_.ToString(); |
| 274 module_process_thread_->DeRegisterModule(&overuse_detector_); | 264 module_process_thread_->DeRegisterModule(&overuse_detector_); |
| 275 // Remove vcm_protection_callback (part of vie_channel_) before destroying | 265 // Remove vcm_protection_callback (part of vie_channel_) before destroying |
| 276 // ViEChannel. vcm_ is owned by ViEEncoder and the registered callback does | 266 // ViEChannel. vcm_ is owned by ViEEncoder and the registered callback does |
| 277 // not outlive it. | 267 // not outlive it. |
| 278 vcm_->RegisterProtectionCallback(nullptr); | 268 vcm_->RegisterProtectionCallback(nullptr); |
| 279 vie_channel_->RegisterSendFrameCountObserver(nullptr); | 269 vie_channel_.RegisterSendFrameCountObserver(nullptr); |
| 280 vie_channel_->RegisterSendBitrateObserver(nullptr); | 270 vie_channel_.RegisterSendBitrateObserver(nullptr); |
| 281 vie_channel_->RegisterRtcpPacketTypeCounterObserver(nullptr); | 271 vie_channel_.RegisterRtcpPacketTypeCounterObserver(nullptr); |
| 282 vie_channel_->RegisterSendChannelRtpStatisticsCallback(nullptr); | 272 vie_channel_.RegisterSendChannelRtpStatisticsCallback(nullptr); |
| 283 vie_channel_->RegisterSendChannelRtcpStatisticsCallback(nullptr); | 273 vie_channel_.RegisterSendChannelRtcpStatisticsCallback(nullptr); |
| 284 | 274 |
| 285 // Remove capture input (thread) so that it's not running after the current | 275 vie_encoder_.DeRegisterExternalEncoder( |
| 286 // channel is deleted. | |
| 287 input_.reset(); | |
| 288 | |
| 289 vie_encoder_->DeRegisterExternalEncoder( | |
| 290 config_.encoder_settings.payload_type); | 276 config_.encoder_settings.payload_type); |
| 291 | 277 |
| 292 call_stats_->DeregisterStatsObserver(vie_channel_->GetStatsObserver()); | 278 call_stats_->DeregisterStatsObserver(vie_channel_.GetStatsObserver()); |
| 293 | 279 |
| 294 RtpRtcp* rtp_module = vie_channel_->rtp_rtcp(); | 280 RtpRtcp* rtp_module = vie_channel_.rtp_rtcp(); |
| 295 rtp_module->SetREMBStatus(false); | 281 rtp_module->SetREMBStatus(false); |
| 296 remb_->RemoveRembSender(rtp_module); | 282 remb_->RemoveRembSender(rtp_module); |
| 297 | 283 |
| 298 // Remove the feedback, stop all encoding threads and processing. This must be | 284 // Remove the feedback, stop all encoding threads and processing. This must be |
| 299 // done before deleting the channel. | 285 // done before deleting the channel. |
| 300 encoder_feedback_->RemoveEncoder(vie_encoder_.get()); | 286 encoder_feedback_.RemoveEncoder(&vie_encoder_); |
| 301 | 287 |
| 302 uint32_t remote_ssrc = vie_channel_->GetRemoteSSRC(); | 288 uint32_t remote_ssrc = vie_channel_.GetRemoteSSRC(); |
| 303 congestion_controller_->GetRemoteBitrateEstimator(false)->RemoveStream( | 289 congestion_controller_->GetRemoteBitrateEstimator(false)->RemoveStream( |
| 304 remote_ssrc); | 290 remote_ssrc); |
| 305 } | 291 } |
| 306 | 292 |
| 307 VideoCaptureInput* VideoSendStream::Input() { | 293 VideoCaptureInput* VideoSendStream::Input() { |
| 308 return input_.get(); | 294 return &input_; |
| 309 } | 295 } |
| 310 | 296 |
| 311 void VideoSendStream::Start() { | 297 void VideoSendStream::Start() { |
| 312 transport_adapter_.Enable(); | 298 transport_adapter_.Enable(); |
| 313 vie_encoder_->Pause(); | 299 vie_encoder_.Pause(); |
| 314 if (vie_channel_->StartSend() == 0) { | 300 if (vie_channel_.StartSend() == 0) { |
| 315 // Was not already started, trigger a keyframe. | 301 // Was not already started, trigger a keyframe. |
| 316 vie_encoder_->SendKeyFrame(); | 302 vie_encoder_.SendKeyFrame(); |
| 317 } | 303 } |
| 318 vie_encoder_->Restart(); | 304 vie_encoder_.Restart(); |
| 319 vie_channel_->StartReceive(); | 305 vie_channel_.StartReceive(); |
| 320 } | 306 } |
| 321 | 307 |
| 322 void VideoSendStream::Stop() { | 308 void VideoSendStream::Stop() { |
| 323 // TODO(pbos): Make sure the encoder stops here. | 309 // TODO(pbos): Make sure the encoder stops here. |
| 324 vie_channel_->StopSend(); | 310 vie_channel_.StopSend(); |
| 325 vie_channel_->StopReceive(); | 311 vie_channel_.StopReceive(); |
| 326 transport_adapter_.Disable(); | 312 transport_adapter_.Disable(); |
| 327 } | 313 } |
| 328 | 314 |
| 329 bool VideoSendStream::ReconfigureVideoEncoder( | 315 bool VideoSendStream::ReconfigureVideoEncoder( |
| 330 const VideoEncoderConfig& config) { | 316 const VideoEncoderConfig& config) { |
| 331 TRACE_EVENT0("webrtc", "VideoSendStream::(Re)configureVideoEncoder"); | 317 TRACE_EVENT0("webrtc", "VideoSendStream::(Re)configureVideoEncoder"); |
| 332 LOG(LS_INFO) << "(Re)configureVideoEncoder: " << config.ToString(); | 318 LOG(LS_INFO) << "(Re)configureVideoEncoder: " << config.ToString(); |
| 333 const std::vector<VideoStream>& streams = config.streams; | 319 const std::vector<VideoStream>& streams = config.streams; |
| 334 RTC_DCHECK(!streams.empty()); | 320 RTC_DCHECK(!streams.empty()); |
| 335 RTC_DCHECK_GE(config_.rtp.ssrcs.size(), streams.size()); | 321 RTC_DCHECK_GE(config_.rtp.ssrcs.size(), streams.size()); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 | 451 |
| 466 // Clear stats for disabled layers. | 452 // Clear stats for disabled layers. |
| 467 for (size_t i = video_codec.numberOfSimulcastStreams; | 453 for (size_t i = video_codec.numberOfSimulcastStreams; |
| 468 i < config_.rtp.ssrcs.size(); ++i) { | 454 i < config_.rtp.ssrcs.size(); ++i) { |
| 469 stats_proxy_.OnInactiveSsrc(config_.rtp.ssrcs[i]); | 455 stats_proxy_.OnInactiveSsrc(config_.rtp.ssrcs[i]); |
| 470 } | 456 } |
| 471 | 457 |
| 472 stats_proxy_.SetContentType(config.content_type); | 458 stats_proxy_.SetContentType(config.content_type); |
| 473 | 459 |
| 474 RTC_DCHECK_GE(config.min_transmit_bitrate_bps, 0); | 460 RTC_DCHECK_GE(config.min_transmit_bitrate_bps, 0); |
| 475 vie_encoder_->SetMinTransmitBitrate(config.min_transmit_bitrate_bps / 1000); | 461 vie_encoder_.SetMinTransmitBitrate(config.min_transmit_bitrate_bps / 1000); |
| 476 | 462 |
| 477 encoder_config_ = config; | 463 encoder_config_ = config; |
| 478 use_config_bitrate_ = false; | |
| 479 return true; | 464 return true; |
| 480 } | 465 } |
| 481 | 466 |
| 482 bool VideoSendStream::DeliverRtcp(const uint8_t* packet, size_t length) { | 467 bool VideoSendStream::DeliverRtcp(const uint8_t* packet, size_t length) { |
| 483 return vie_channel_->ReceivedRTCPPacket(packet, length) == 0; | 468 return vie_channel_.ReceivedRTCPPacket(packet, length) == 0; |
| 484 } | 469 } |
| 485 | 470 |
| 486 VideoSendStream::Stats VideoSendStream::GetStats() { | 471 VideoSendStream::Stats VideoSendStream::GetStats() { |
| 487 return stats_proxy_.GetStats(); | 472 return stats_proxy_.GetStats(); |
| 488 } | 473 } |
| 489 | 474 |
| 490 void VideoSendStream::OveruseDetected() { | 475 void VideoSendStream::OveruseDetected() { |
| 491 if (config_.overuse_callback) | 476 if (config_.overuse_callback) |
| 492 config_.overuse_callback->OnLoadUpdate(LoadObserver::kOveruse); | 477 config_.overuse_callback->OnLoadUpdate(LoadObserver::kOveruse); |
| 493 } | 478 } |
| 494 | 479 |
| 495 void VideoSendStream::NormalUsage() { | 480 void VideoSendStream::NormalUsage() { |
| 496 if (config_.overuse_callback) | 481 if (config_.overuse_callback) |
| 497 config_.overuse_callback->OnLoadUpdate(LoadObserver::kUnderuse); | 482 config_.overuse_callback->OnLoadUpdate(LoadObserver::kUnderuse); |
| 498 } | 483 } |
| 499 | 484 |
| 500 void VideoSendStream::ConfigureSsrcs() { | 485 void VideoSendStream::ConfigureSsrcs() { |
| 501 vie_channel_->SetSSRC(config_.rtp.ssrcs.front(), kViEStreamTypeNormal, 0); | 486 vie_channel_.SetSSRC(config_.rtp.ssrcs.front(), kViEStreamTypeNormal, 0); |
| 502 for (size_t i = 0; i < config_.rtp.ssrcs.size(); ++i) { | 487 for (size_t i = 0; i < config_.rtp.ssrcs.size(); ++i) { |
| 503 uint32_t ssrc = config_.rtp.ssrcs[i]; | 488 uint32_t ssrc = config_.rtp.ssrcs[i]; |
| 504 vie_channel_->SetSSRC(ssrc, kViEStreamTypeNormal, | 489 vie_channel_.SetSSRC(ssrc, kViEStreamTypeNormal, |
| 505 static_cast<unsigned char>(i)); | 490 static_cast<unsigned char>(i)); |
| 506 RtpStateMap::iterator it = suspended_ssrcs_.find(ssrc); | 491 RtpStateMap::iterator it = suspended_ssrcs_.find(ssrc); |
| 507 if (it != suspended_ssrcs_.end()) | 492 if (it != suspended_ssrcs_.end()) |
| 508 vie_channel_->SetRtpStateForSsrc(ssrc, it->second); | 493 vie_channel_.SetRtpStateForSsrc(ssrc, it->second); |
| 509 } | 494 } |
| 510 | 495 |
| 511 if (config_.rtp.rtx.ssrcs.empty()) { | 496 if (config_.rtp.rtx.ssrcs.empty()) { |
| 512 return; | 497 return; |
| 513 } | 498 } |
| 514 | 499 |
| 515 // Set up RTX. | 500 // Set up RTX. |
| 516 RTC_DCHECK_EQ(config_.rtp.rtx.ssrcs.size(), config_.rtp.ssrcs.size()); | 501 RTC_DCHECK_EQ(config_.rtp.rtx.ssrcs.size(), config_.rtp.ssrcs.size()); |
| 517 for (size_t i = 0; i < config_.rtp.rtx.ssrcs.size(); ++i) { | 502 for (size_t i = 0; i < config_.rtp.rtx.ssrcs.size(); ++i) { |
| 518 uint32_t ssrc = config_.rtp.rtx.ssrcs[i]; | 503 uint32_t ssrc = config_.rtp.rtx.ssrcs[i]; |
| 519 vie_channel_->SetSSRC(config_.rtp.rtx.ssrcs[i], kViEStreamTypeRtx, | 504 vie_channel_.SetSSRC(config_.rtp.rtx.ssrcs[i], kViEStreamTypeRtx, |
| 520 static_cast<unsigned char>(i)); | 505 static_cast<unsigned char>(i)); |
| 521 RtpStateMap::iterator it = suspended_ssrcs_.find(ssrc); | 506 RtpStateMap::iterator it = suspended_ssrcs_.find(ssrc); |
| 522 if (it != suspended_ssrcs_.end()) | 507 if (it != suspended_ssrcs_.end()) |
| 523 vie_channel_->SetRtpStateForSsrc(ssrc, it->second); | 508 vie_channel_.SetRtpStateForSsrc(ssrc, it->second); |
| 524 } | 509 } |
| 525 | 510 |
| 526 RTC_DCHECK_GE(config_.rtp.rtx.payload_type, 0); | 511 RTC_DCHECK_GE(config_.rtp.rtx.payload_type, 0); |
| 527 vie_channel_->SetRtxSendPayloadType(config_.rtp.rtx.payload_type, | 512 vie_channel_.SetRtxSendPayloadType(config_.rtp.rtx.payload_type, |
| 528 config_.encoder_settings.payload_type); | 513 config_.encoder_settings.payload_type); |
| 529 if (config_.rtp.fec.red_payload_type != -1 && | 514 if (config_.rtp.fec.red_payload_type != -1 && |
| 530 config_.rtp.fec.red_rtx_payload_type != -1) { | 515 config_.rtp.fec.red_rtx_payload_type != -1) { |
| 531 vie_channel_->SetRtxSendPayloadType(config_.rtp.fec.red_rtx_payload_type, | 516 vie_channel_.SetRtxSendPayloadType(config_.rtp.fec.red_rtx_payload_type, |
| 532 config_.rtp.fec.red_payload_type); | 517 config_.rtp.fec.red_payload_type); |
| 533 } | 518 } |
| 534 } | 519 } |
| 535 | 520 |
| 536 std::map<uint32_t, RtpState> VideoSendStream::GetRtpStates() const { | 521 std::map<uint32_t, RtpState> VideoSendStream::GetRtpStates() const { |
| 537 std::map<uint32_t, RtpState> rtp_states; | 522 std::map<uint32_t, RtpState> rtp_states; |
| 538 for (size_t i = 0; i < config_.rtp.ssrcs.size(); ++i) { | 523 for (size_t i = 0; i < config_.rtp.ssrcs.size(); ++i) { |
| 539 uint32_t ssrc = config_.rtp.ssrcs[i]; | 524 uint32_t ssrc = config_.rtp.ssrcs[i]; |
| 540 rtp_states[ssrc] = vie_channel_->GetRtpStateForSsrc(ssrc); | 525 rtp_states[ssrc] = vie_channel_.GetRtpStateForSsrc(ssrc); |
| 541 } | 526 } |
| 542 | 527 |
| 543 for (size_t i = 0; i < config_.rtp.rtx.ssrcs.size(); ++i) { | 528 for (size_t i = 0; i < config_.rtp.rtx.ssrcs.size(); ++i) { |
| 544 uint32_t ssrc = config_.rtp.rtx.ssrcs[i]; | 529 uint32_t ssrc = config_.rtp.rtx.ssrcs[i]; |
| 545 rtp_states[ssrc] = vie_channel_->GetRtpStateForSsrc(ssrc); | 530 rtp_states[ssrc] = vie_channel_.GetRtpStateForSsrc(ssrc); |
| 546 } | 531 } |
| 547 | 532 |
| 548 return rtp_states; | 533 return rtp_states; |
| 549 } | 534 } |
| 550 | 535 |
| 551 void VideoSendStream::SignalNetworkState(NetworkState state) { | 536 void VideoSendStream::SignalNetworkState(NetworkState state) { |
| 552 // When network goes up, enable RTCP status before setting transmission state. | 537 // When network goes up, enable RTCP status before setting transmission state. |
| 553 // When it goes down, disable RTCP afterwards. This ensures that any packets | 538 // When it goes down, disable RTCP afterwards. This ensures that any packets |
| 554 // sent due to the network state changed will not be dropped. | 539 // sent due to the network state changed will not be dropped. |
| 555 if (state == kNetworkUp) | 540 if (state == kNetworkUp) |
| 556 vie_channel_->SetRTCPMode(config_.rtp.rtcp_mode); | 541 vie_channel_.SetRTCPMode(config_.rtp.rtcp_mode); |
| 557 vie_encoder_->SetNetworkTransmissionState(state == kNetworkUp); | 542 vie_encoder_.SetNetworkTransmissionState(state == kNetworkUp); |
| 558 if (state == kNetworkDown) | 543 if (state == kNetworkDown) |
| 559 vie_channel_->SetRTCPMode(RtcpMode::kOff); | 544 vie_channel_.SetRTCPMode(RtcpMode::kOff); |
| 560 } | 545 } |
| 561 | 546 |
| 562 int64_t VideoSendStream::GetRtt() const { | 547 int64_t VideoSendStream::GetRtt() const { |
| 563 webrtc::RtcpStatistics rtcp_stats; | 548 webrtc::RtcpStatistics rtcp_stats; |
| 564 uint16_t frac_lost; | 549 uint16_t frac_lost; |
| 565 uint32_t cumulative_lost; | 550 uint32_t cumulative_lost; |
| 566 uint32_t extended_max_sequence_number; | 551 uint32_t extended_max_sequence_number; |
| 567 uint32_t jitter; | 552 uint32_t jitter; |
| 568 int64_t rtt_ms; | 553 int64_t rtt_ms; |
| 569 if (vie_channel_->GetSendRtcpStatistics(&frac_lost, &cumulative_lost, | 554 if (vie_channel_.GetSendRtcpStatistics(&frac_lost, &cumulative_lost, |
| 570 &extended_max_sequence_number, | 555 &extended_max_sequence_number, |
| 571 &jitter, &rtt_ms) == 0) { | 556 &jitter, &rtt_ms) == 0) { |
| 572 return rtt_ms; | 557 return rtt_ms; |
| 573 } | 558 } |
| 574 return -1; | 559 return -1; |
| 575 } | 560 } |
| 576 | 561 |
| 577 int VideoSendStream::GetPaddingNeededBps() const { | 562 int VideoSendStream::GetPaddingNeededBps() const { |
| 578 return vie_encoder_->GetPaddingNeededBps(); | 563 return vie_encoder_.GetPaddingNeededBps(); |
| 579 } | 564 } |
| 580 | 565 |
| 581 bool VideoSendStream::SetSendCodec(VideoCodec video_codec) { | 566 bool VideoSendStream::SetSendCodec(VideoCodec video_codec) { |
| 582 static const int kEncoderMinBitrate = 30; | 567 static const int kEncoderMinBitrate = 30; |
| 583 if (video_codec.maxBitrate == 0) { | 568 if (video_codec.maxBitrate == 0) { |
| 584 // Unset max bitrate -> cap to one bit per pixel. | 569 // Unset max bitrate -> cap to one bit per pixel. |
| 585 video_codec.maxBitrate = | 570 video_codec.maxBitrate = |
| 586 (video_codec.width * video_codec.height * video_codec.maxFramerate) / | 571 (video_codec.width * video_codec.height * video_codec.maxFramerate) / |
| 587 1000; | 572 1000; |
| 588 } | 573 } |
| 589 | 574 |
| 590 if (video_codec.minBitrate < kEncoderMinBitrate) | 575 if (video_codec.minBitrate < kEncoderMinBitrate) |
| 591 video_codec.minBitrate = kEncoderMinBitrate; | 576 video_codec.minBitrate = kEncoderMinBitrate; |
| 592 if (video_codec.maxBitrate < kEncoderMinBitrate) | 577 if (video_codec.maxBitrate < kEncoderMinBitrate) |
| 593 video_codec.maxBitrate = kEncoderMinBitrate; | 578 video_codec.maxBitrate = kEncoderMinBitrate; |
| 594 | 579 |
| 595 // Stop the media flow while reconfiguring. | 580 // Stop the media flow while reconfiguring. |
| 596 vie_encoder_->Pause(); | 581 vie_encoder_.Pause(); |
| 597 | 582 |
| 598 if (vie_encoder_->SetEncoder(video_codec) != 0) { | 583 if (vie_encoder_.SetEncoder(video_codec) != 0) { |
| 599 LOG(LS_ERROR) << "Failed to set encoder."; | 584 LOG(LS_ERROR) << "Failed to set encoder."; |
| 600 return false; | 585 return false; |
| 601 } | 586 } |
| 602 | 587 |
| 603 if (vie_channel_->SetSendCodec(video_codec, false) != 0) { | 588 if (vie_channel_.SetSendCodec(video_codec, false) != 0) { |
| 604 LOG(LS_ERROR) << "Failed to set send codec."; | 589 LOG(LS_ERROR) << "Failed to set send codec."; |
| 605 return false; | 590 return false; |
| 606 } | 591 } |
| 607 | 592 |
| 608 // Not all configured SSRCs have to be utilized (simulcast senders don't have | 593 // Not all configured SSRCs have to be utilized (simulcast senders don't have |
| 609 // to send on all SSRCs at once etc.) | 594 // to send on all SSRCs at once etc.) |
| 610 std::vector<uint32_t> used_ssrcs = config_.rtp.ssrcs; | 595 std::vector<uint32_t> used_ssrcs = config_.rtp.ssrcs; |
| 611 used_ssrcs.resize(static_cast<size_t>(video_codec.numberOfSimulcastStreams)); | 596 used_ssrcs.resize(static_cast<size_t>(video_codec.numberOfSimulcastStreams)); |
| 612 vie_encoder_->SetSsrcs(used_ssrcs); | 597 vie_encoder_.SetSsrcs(used_ssrcs); |
| 613 | 598 |
| 614 // Restart the media flow | 599 // Restart the media flow |
| 615 vie_encoder_->Restart(); | 600 vie_encoder_.Restart(); |
| 616 | 601 |
| 617 return true; | 602 return true; |
| 618 } | 603 } |
| 619 | |
| 620 } // namespace internal | 604 } // namespace internal |
| 621 } // namespace webrtc | 605 } // namespace webrtc |
| OLD | NEW |