| 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_receive_stream.h" | 11 #include "webrtc/video/video_receive_stream.h" |
| 12 | 12 |
| 13 #include <stdlib.h> | 13 #include <stdlib.h> |
| 14 | 14 |
| 15 #include <set> | 15 #include <set> |
| 16 #include <string> | 16 #include <string> |
| 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/common_video/libyuv/include/webrtc_libyuv.h" | 20 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
| 21 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" | 21 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" |
| 22 #include "webrtc/modules/utility/include/process_thread.h" | 22 #include "webrtc/modules/utility/include/process_thread.h" |
| 23 #include "webrtc/modules/video_coding/include/video_coding.h" | 23 #include "webrtc/modules/video_coding/include/video_coding.h" |
| 24 #include "webrtc/modules/video_coding/utility/ivf_file_writer.h" | 24 #include "webrtc/modules/video_coding/utility/ivf_file_writer.h" |
| 25 #include "webrtc/system_wrappers/include/clock.h" | 25 #include "webrtc/system_wrappers/include/clock.h" |
| 26 #include "webrtc/video/call_stats.h" | 26 #include "webrtc/video/call_stats.h" |
| 27 #include "webrtc/video/receive_statistics_proxy.h" | 27 #include "webrtc/video/receive_statistics_proxy.h" |
| 28 #include "webrtc/video/vie_remb.h" | |
| 29 #include "webrtc/video_receive_stream.h" | 28 #include "webrtc/video_receive_stream.h" |
| 30 | 29 |
| 31 namespace webrtc { | 30 namespace webrtc { |
| 32 | 31 |
| 33 static const bool kEnableFrameRecording = false; | 32 static const bool kEnableFrameRecording = false; |
| 34 | 33 |
| 35 static bool UseSendSideBwe(const VideoReceiveStream::Config& config) { | 34 static bool UseSendSideBwe(const VideoReceiveStream::Config& config) { |
| 36 if (!config.rtp.transport_cc) | 35 if (!config.rtp.transport_cc) |
| 37 return false; | 36 return false; |
| 38 for (const auto& extension : config.rtp.extensions) { | 37 for (const auto& extension : config.rtp.extensions) { |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 CallStats* call_stats, | 153 CallStats* call_stats, |
| 155 VieRemb* remb) | 154 VieRemb* remb) |
| 156 : transport_adapter_(config.rtcp_send_transport), | 155 : transport_adapter_(config.rtcp_send_transport), |
| 157 encoded_frame_proxy_(config.pre_decode_callback), | 156 encoded_frame_proxy_(config.pre_decode_callback), |
| 158 config_(config), | 157 config_(config), |
| 159 process_thread_(process_thread), | 158 process_thread_(process_thread), |
| 160 clock_(Clock::GetRealTimeClock()), | 159 clock_(Clock::GetRealTimeClock()), |
| 161 decode_thread_(DecodeThreadFunction, this, "DecodingThread"), | 160 decode_thread_(DecodeThreadFunction, this, "DecodingThread"), |
| 162 congestion_controller_(congestion_controller), | 161 congestion_controller_(congestion_controller), |
| 163 call_stats_(call_stats), | 162 call_stats_(call_stats), |
| 164 remb_(remb), | |
| 165 video_receiver_(clock_, nullptr, this, this, this), | 163 video_receiver_(clock_, nullptr, this, this, this), |
| 166 incoming_video_stream_(config.disable_prerenderer_smoothing), | 164 incoming_video_stream_(config.disable_prerenderer_smoothing), |
| 167 stats_proxy_(config_, clock_), | 165 stats_proxy_(config_, clock_), |
| 168 rtp_stream_receiver_(&video_receiver_, | 166 rtp_stream_receiver_(&video_receiver_, |
| 169 congestion_controller_->GetRemoteBitrateEstimator( | 167 congestion_controller_->GetRemoteBitrateEstimator( |
| 170 UseSendSideBwe(config_)), | 168 UseSendSideBwe(config_)), |
| 171 &transport_adapter_, | 169 &transport_adapter_, |
| 172 call_stats_->rtcp_rtt_stats(), | 170 call_stats_->rtcp_rtt_stats(), |
| 173 congestion_controller_->pacer(), | 171 congestion_controller_->pacer(), |
| 174 congestion_controller_->packet_router(), | 172 congestion_controller_->packet_router(), |
| 173 remb, |
| 175 config, | 174 config, |
| 176 &stats_proxy_), | 175 &stats_proxy_, |
| 176 process_thread_), |
| 177 video_stream_decoder_(&video_receiver_, | 177 video_stream_decoder_(&video_receiver_, |
| 178 &rtp_stream_receiver_, | 178 &rtp_stream_receiver_, |
| 179 &rtp_stream_receiver_, | 179 &rtp_stream_receiver_, |
| 180 config.rtp.nack.rtp_history_ms > 0, | 180 rtp_stream_receiver_.IsRetransmissionsEnabled(), |
| 181 rtp_stream_receiver_.IsFecEnabled(), |
| 181 &stats_proxy_, | 182 &stats_proxy_, |
| 182 &incoming_video_stream_, | 183 &incoming_video_stream_, |
| 183 this), | 184 this), |
| 184 vie_sync_(&video_receiver_), | 185 vie_sync_(&video_receiver_) { |
| 185 rtp_rtcp_(rtp_stream_receiver_.rtp_rtcp()) { | |
| 186 LOG(LS_INFO) << "VideoReceiveStream: " << config_.ToString(); | 186 LOG(LS_INFO) << "VideoReceiveStream: " << config_.ToString(); |
| 187 | 187 |
| 188 RTC_DCHECK(process_thread_); | 188 RTC_DCHECK(process_thread_); |
| 189 RTC_DCHECK(congestion_controller_); | 189 RTC_DCHECK(congestion_controller_); |
| 190 RTC_DCHECK(call_stats_); | 190 RTC_DCHECK(call_stats_); |
| 191 RTC_DCHECK(remb_); | |
| 192 RTC_DCHECK(config_.rtp.rtcp_mode != RtcpMode::kOff) | |
| 193 << "A stream should not be configured with RTCP disabled. This value is " | |
| 194 "reserved for internal usage."; | |
| 195 | 191 |
| 196 // Register the channel to receive stats updates. | 192 // Register the channel to receive stats updates. |
| 197 call_stats_->RegisterStatsObserver(&video_stream_decoder_); | 193 call_stats_->RegisterStatsObserver(&video_stream_decoder_); |
| 198 | 194 |
| 199 RTC_DCHECK(config_.rtp.remote_ssrc != 0); | |
| 200 // TODO(pbos): What's an appropriate local_ssrc for receive-only streams? | |
| 201 RTC_DCHECK(config_.rtp.local_ssrc != 0); | |
| 202 RTC_DCHECK(config_.rtp.remote_ssrc != config_.rtp.local_ssrc); | |
| 203 rtp_rtcp_->SetSSRC(config_.rtp.local_ssrc); | |
| 204 | |
| 205 // TODO(pbos): Support multiple RTX, per video payload. | |
| 206 for (const auto& kv : config_.rtp.rtx) { | |
| 207 RTC_DCHECK(kv.second.ssrc != 0); | |
| 208 RTC_DCHECK(kv.second.payload_type != 0); | |
| 209 | |
| 210 rtp_stream_receiver_.SetRtxSsrc(kv.second.ssrc); | |
| 211 rtp_stream_receiver_.SetRtxPayloadType(kv.second.payload_type, kv.first); | |
| 212 } | |
| 213 // TODO(holmer): When Chrome no longer depends on this being false by default, | |
| 214 // always use the mapping and remove this whole codepath. | |
| 215 rtp_stream_receiver_.SetUseRtxPayloadMappingOnRestore( | |
| 216 config_.rtp.use_rtx_payload_mapping_on_restore); | |
| 217 | |
| 218 if (config_.rtp.remb) { | |
| 219 rtp_rtcp_->SetREMBStatus(true); | |
| 220 remb_->AddReceiveChannel(rtp_rtcp_); | |
| 221 } | |
| 222 | |
| 223 for (size_t i = 0; i < config_.rtp.extensions.size(); ++i) { | |
| 224 const std::string& extension = config_.rtp.extensions[i].name; | |
| 225 int id = config_.rtp.extensions[i].id; | |
| 226 // One-byte-extension local identifiers are in the range 1-14 inclusive. | |
| 227 RTC_DCHECK_GE(id, 1); | |
| 228 RTC_DCHECK_LE(id, 14); | |
| 229 rtp_stream_receiver_.EnableReceiveRtpHeaderExtension(extension, id); | |
| 230 } | |
| 231 | |
| 232 if (config_.rtp.fec.ulpfec_payload_type != -1) { | |
| 233 // ULPFEC without RED doesn't make sense. | |
| 234 RTC_DCHECK(config_.rtp.fec.red_payload_type != -1); | |
| 235 VideoCodec codec; | |
| 236 memset(&codec, 0, sizeof(codec)); | |
| 237 codec.codecType = kVideoCodecULPFEC; | |
| 238 strncpy(codec.plName, "ulpfec", sizeof(codec.plName)); | |
| 239 codec.plType = config_.rtp.fec.ulpfec_payload_type; | |
| 240 RTC_CHECK(rtp_stream_receiver_.SetReceiveCodec(codec)); | |
| 241 } | |
| 242 if (config_.rtp.fec.red_payload_type != -1) { | |
| 243 VideoCodec codec; | |
| 244 memset(&codec, 0, sizeof(codec)); | |
| 245 codec.codecType = kVideoCodecRED; | |
| 246 strncpy(codec.plName, "red", sizeof(codec.plName)); | |
| 247 codec.plType = config_.rtp.fec.red_payload_type; | |
| 248 RTC_CHECK(rtp_stream_receiver_.SetReceiveCodec(codec)); | |
| 249 if (config_.rtp.fec.red_rtx_payload_type != -1) { | |
| 250 rtp_stream_receiver_.SetRtxPayloadType( | |
| 251 config_.rtp.fec.red_rtx_payload_type, | |
| 252 config_.rtp.fec.red_payload_type); | |
| 253 } | |
| 254 } | |
| 255 | |
| 256 if (config.rtp.rtcp_xr.receiver_reference_time_report) | |
| 257 rtp_rtcp_->SetRtcpXrRrtrStatus(true); | |
| 258 | |
| 259 // Stats callback for CNAME changes. | |
| 260 rtp_rtcp_->RegisterRtcpStatisticsCallback(&stats_proxy_); | |
| 261 | |
| 262 RTC_DCHECK(!config_.decoders.empty()); | 195 RTC_DCHECK(!config_.decoders.empty()); |
| 263 std::set<int> decoder_payload_types; | 196 std::set<int> decoder_payload_types; |
| 264 for (const Decoder& decoder : config_.decoders) { | 197 for (const Decoder& decoder : config_.decoders) { |
| 265 RTC_CHECK(decoder.decoder); | 198 RTC_CHECK(decoder.decoder); |
| 266 RTC_CHECK(decoder_payload_types.find(decoder.payload_type) == | 199 RTC_CHECK(decoder_payload_types.find(decoder.payload_type) == |
| 267 decoder_payload_types.end()) | 200 decoder_payload_types.end()) |
| 268 << "Duplicate payload type (" << decoder.payload_type | 201 << "Duplicate payload type (" << decoder.payload_type |
| 269 << ") for different decoders."; | 202 << ") for different decoders."; |
| 270 decoder_payload_types.insert(decoder.payload_type); | 203 decoder_payload_types.insert(decoder.payload_type); |
| 271 video_receiver_.RegisterExternalDecoder(decoder.decoder, | 204 video_receiver_.RegisterExternalDecoder(decoder.decoder, |
| 272 decoder.payload_type); | 205 decoder.payload_type); |
| 273 | 206 |
| 274 VideoCodec codec = CreateDecoderVideoCodec(decoder); | 207 VideoCodec codec = CreateDecoderVideoCodec(decoder); |
| 275 | |
| 276 RTC_CHECK(rtp_stream_receiver_.SetReceiveCodec(codec)); | 208 RTC_CHECK(rtp_stream_receiver_.SetReceiveCodec(codec)); |
| 277 RTC_CHECK_EQ(VCM_OK, video_receiver_.RegisterReceiveCodec( | 209 RTC_CHECK_EQ(VCM_OK, video_receiver_.RegisterReceiveCodec( |
| 278 &codec, num_cpu_cores, false)); | 210 &codec, num_cpu_cores, false)); |
| 279 } | 211 } |
| 280 | 212 |
| 281 video_receiver_.SetRenderDelay(config.render_delay_ms); | 213 video_receiver_.SetRenderDelay(config.render_delay_ms); |
| 282 incoming_video_stream_.SetExpectedRenderDelay(config.render_delay_ms); | 214 incoming_video_stream_.SetExpectedRenderDelay(config.render_delay_ms); |
| 283 incoming_video_stream_.SetExternalCallback(this); | 215 incoming_video_stream_.SetExternalCallback(this); |
| 284 | 216 |
| 285 process_thread_->RegisterModule(rtp_stream_receiver_.GetReceiveStatistics()); | |
| 286 process_thread_->RegisterModule(rtp_stream_receiver_.rtp_rtcp()); | |
| 287 process_thread_->RegisterModule(&video_receiver_); | 217 process_thread_->RegisterModule(&video_receiver_); |
| 288 process_thread_->RegisterModule(&vie_sync_); | 218 process_thread_->RegisterModule(&vie_sync_); |
| 289 } | 219 } |
| 290 | 220 |
| 291 VideoReceiveStream::~VideoReceiveStream() { | 221 VideoReceiveStream::~VideoReceiveStream() { |
| 292 LOG(LS_INFO) << "~VideoReceiveStream: " << config_.ToString(); | 222 LOG(LS_INFO) << "~VideoReceiveStream: " << config_.ToString(); |
| 293 Stop(); | 223 Stop(); |
| 294 | 224 |
| 295 process_thread_->DeRegisterModule(&vie_sync_); | 225 process_thread_->DeRegisterModule(&vie_sync_); |
| 296 process_thread_->DeRegisterModule(&video_receiver_); | 226 process_thread_->DeRegisterModule(&video_receiver_); |
| 297 process_thread_->DeRegisterModule(rtp_stream_receiver_.rtp_rtcp()); | |
| 298 process_thread_->DeRegisterModule( | |
| 299 rtp_stream_receiver_.GetReceiveStatistics()); | |
| 300 | 227 |
| 301 // Deregister external decoders so they are no longer running during | 228 // Deregister external decoders so they are no longer running during |
| 302 // destruction. This effectively stops the VCM since the decoder thread is | 229 // destruction. This effectively stops the VCM since the decoder thread is |
| 303 // stopped, the VCM is deregistered and no asynchronous decoder threads are | 230 // stopped, the VCM is deregistered and no asynchronous decoder threads are |
| 304 // running. | 231 // running. |
| 305 for (const Decoder& decoder : config_.decoders) | 232 for (const Decoder& decoder : config_.decoders) |
| 306 video_receiver_.RegisterExternalDecoder(nullptr, decoder.payload_type); | 233 video_receiver_.RegisterExternalDecoder(nullptr, decoder.payload_type); |
| 307 | 234 |
| 308 call_stats_->DeregisterStatsObserver(&video_stream_decoder_); | 235 call_stats_->DeregisterStatsObserver(&video_stream_decoder_); |
| 309 rtp_rtcp_->SetREMBStatus(false); | |
| 310 remb_->RemoveReceiveChannel(rtp_rtcp_); | |
| 311 | 236 |
| 312 congestion_controller_->GetRemoteBitrateEstimator(UseSendSideBwe(config_)) | 237 congestion_controller_->GetRemoteBitrateEstimator(UseSendSideBwe(config_)) |
| 313 ->RemoveStream(rtp_stream_receiver_.GetRemoteSsrc()); | 238 ->RemoveStream(rtp_stream_receiver_.GetRemoteSsrc()); |
| 314 } | 239 } |
| 315 | 240 |
| 316 void VideoReceiveStream::SignalNetworkState(NetworkState state) { | 241 void VideoReceiveStream::SignalNetworkState(NetworkState state) { |
| 317 rtp_rtcp_->SetRTCPStatus(state == kNetworkUp ? config_.rtp.rtcp_mode | 242 rtp_stream_receiver_.SignalNetworkState(state); |
| 318 : RtcpMode::kOff); | |
| 319 } | 243 } |
| 320 | 244 |
| 321 | 245 |
| 322 bool VideoReceiveStream::DeliverRtcp(const uint8_t* packet, size_t length) { | 246 bool VideoReceiveStream::DeliverRtcp(const uint8_t* packet, size_t length) { |
| 323 return rtp_stream_receiver_.DeliverRtcp(packet, length); | 247 return rtp_stream_receiver_.DeliverRtcp(packet, length); |
| 324 } | 248 } |
| 325 | 249 |
| 326 bool VideoReceiveStream::DeliverRtp(const uint8_t* packet, | 250 bool VideoReceiveStream::DeliverRtp(const uint8_t* packet, |
| 327 size_t length, | 251 size_t length, |
| 328 const PacketTime& packet_time) { | 252 const PacketTime& packet_time) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 345 rtp_stream_receiver_.StopReceive(); | 269 rtp_stream_receiver_.StopReceive(); |
| 346 video_receiver_.TriggerDecoderShutdown(); | 270 video_receiver_.TriggerDecoderShutdown(); |
| 347 decode_thread_.Stop(); | 271 decode_thread_.Stop(); |
| 348 transport_adapter_.Disable(); | 272 transport_adapter_.Disable(); |
| 349 } | 273 } |
| 350 | 274 |
| 351 void VideoReceiveStream::SetSyncChannel(VoiceEngine* voice_engine, | 275 void VideoReceiveStream::SetSyncChannel(VoiceEngine* voice_engine, |
| 352 int audio_channel_id) { | 276 int audio_channel_id) { |
| 353 if (voice_engine && audio_channel_id != -1) { | 277 if (voice_engine && audio_channel_id != -1) { |
| 354 VoEVideoSync* voe_sync_interface = VoEVideoSync::GetInterface(voice_engine); | 278 VoEVideoSync* voe_sync_interface = VoEVideoSync::GetInterface(voice_engine); |
| 355 vie_sync_.ConfigureSync(audio_channel_id, voe_sync_interface, rtp_rtcp_, | 279 vie_sync_.ConfigureSync(audio_channel_id, voe_sync_interface, |
| 280 rtp_stream_receiver_.rtp_rtcp(), |
| 356 rtp_stream_receiver_.GetRtpReceiver()); | 281 rtp_stream_receiver_.GetRtpReceiver()); |
| 357 voe_sync_interface->Release(); | 282 voe_sync_interface->Release(); |
| 358 return; | 283 } else { |
| 284 vie_sync_.ConfigureSync(-1, nullptr, rtp_stream_receiver_.rtp_rtcp(), |
| 285 rtp_stream_receiver_.GetRtpReceiver()); |
| 359 } | 286 } |
| 360 vie_sync_.ConfigureSync(-1, nullptr, rtp_rtcp_, | |
| 361 rtp_stream_receiver_.GetRtpReceiver()); | |
| 362 } | 287 } |
| 363 | 288 |
| 364 VideoReceiveStream::Stats VideoReceiveStream::GetStats() const { | 289 VideoReceiveStream::Stats VideoReceiveStream::GetStats() const { |
| 365 return stats_proxy_.GetStats(); | 290 return stats_proxy_.GetStats(); |
| 366 } | 291 } |
| 367 | 292 |
| 368 void VideoReceiveStream::FrameCallback(VideoFrame* video_frame) { | 293 void VideoReceiveStream::FrameCallback(VideoFrame* video_frame) { |
| 369 stats_proxy_.OnDecodedFrame(); | 294 stats_proxy_.OnDecodedFrame(); |
| 370 | 295 |
| 371 // Post processing is not supported if the frame is backed by a texture. | 296 // Post processing is not supported if the frame is backed by a texture. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 return true; | 345 return true; |
| 421 } | 346 } |
| 422 | 347 |
| 423 void VideoReceiveStream::Decode() { | 348 void VideoReceiveStream::Decode() { |
| 424 static const int kMaxDecodeWaitTimeMs = 50; | 349 static const int kMaxDecodeWaitTimeMs = 50; |
| 425 video_receiver_.Decode(kMaxDecodeWaitTimeMs); | 350 video_receiver_.Decode(kMaxDecodeWaitTimeMs); |
| 426 } | 351 } |
| 427 | 352 |
| 428 void VideoReceiveStream::SendNack( | 353 void VideoReceiveStream::SendNack( |
| 429 const std::vector<uint16_t>& sequence_numbers) { | 354 const std::vector<uint16_t>& sequence_numbers) { |
| 430 rtp_rtcp_->SendNack(sequence_numbers); | 355 rtp_stream_receiver_.RequestPacketRetransmit(sequence_numbers); |
| 431 } | 356 } |
| 432 | 357 |
| 433 void VideoReceiveStream::RequestKeyFrame() { | 358 void VideoReceiveStream::RequestKeyFrame() { |
| 434 rtp_rtcp_->RequestKeyFrame(); | 359 rtp_stream_receiver_.RequestKeyFrame(); |
| 435 } | 360 } |
| 436 | 361 |
| 437 } // namespace internal | 362 } // namespace internal |
| 438 } // namespace webrtc | 363 } // namespace webrtc |
| OLD | NEW |