| 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 |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 config_(std::move(config)), | 184 config_(std::move(config)), |
| 185 num_cpu_cores_(num_cpu_cores), | 185 num_cpu_cores_(num_cpu_cores), |
| 186 protected_by_flexfec_(protected_by_flexfec), | 186 protected_by_flexfec_(protected_by_flexfec), |
| 187 process_thread_(process_thread), | 187 process_thread_(process_thread), |
| 188 clock_(Clock::GetRealTimeClock()), | 188 clock_(Clock::GetRealTimeClock()), |
| 189 decode_thread_(DecodeThreadFunction, this, "DecodingThread"), | 189 decode_thread_(DecodeThreadFunction, this, "DecodingThread"), |
| 190 call_stats_(call_stats), | 190 call_stats_(call_stats), |
| 191 timing_(new VCMTiming(clock_)), | 191 timing_(new VCMTiming(clock_)), |
| 192 video_receiver_(clock_, nullptr, this, timing_.get(), this, this), | 192 video_receiver_(clock_, nullptr, this, timing_.get(), this, this), |
| 193 stats_proxy_(&config_, clock_), | 193 stats_proxy_(&config_, clock_), |
| 194 rtp_stream_receiver_(&transport_adapter_, | 194 rtp_stream_receiver_(&video_receiver_, |
| 195 &transport_adapter_, |
| 195 call_stats_->rtcp_rtt_stats(), | 196 call_stats_->rtcp_rtt_stats(), |
| 196 packet_router, | 197 packet_router, |
| 197 remb, | 198 remb, |
| 198 &config_, | 199 &config_, |
| 199 &stats_proxy_, | 200 &stats_proxy_, |
| 200 process_thread_, | 201 process_thread_, |
| 201 this, // NackSender | 202 this, // NackSender |
| 202 this, // KeyFrameRequestSender | 203 this, // KeyFrameRequestSender |
| 203 this, // OnCompleteFrameCallback | 204 this, // OnCompleteFrameCallback |
| 204 timing_.get()), | 205 timing_.get()), |
| 205 rtp_stream_sync_(this) { | 206 rtp_stream_sync_(this), |
| 207 jitter_buffer_experiment_( |
| 208 field_trial::FindFullName("WebRTC-NewVideoJitterBuffer") == |
| 209 "Enabled") { |
| 206 LOG(LS_INFO) << "VideoReceiveStream: " << config_.ToString(); | 210 LOG(LS_INFO) << "VideoReceiveStream: " << config_.ToString(); |
| 207 | 211 |
| 208 RTC_DCHECK(process_thread_); | 212 RTC_DCHECK(process_thread_); |
| 209 RTC_DCHECK(call_stats_); | 213 RTC_DCHECK(call_stats_); |
| 210 | 214 |
| 211 module_process_thread_checker_.DetachFromThread(); | 215 module_process_thread_checker_.DetachFromThread(); |
| 212 | 216 |
| 213 RTC_DCHECK(!config_.decoders.empty()); | 217 RTC_DCHECK(!config_.decoders.empty()); |
| 214 std::set<int> decoder_payload_types; | 218 std::set<int> decoder_payload_types; |
| 215 for (const Decoder& decoder : config_.decoders) { | 219 for (const Decoder& decoder : config_.decoders) { |
| 216 RTC_CHECK(decoder.decoder); | 220 RTC_CHECK(decoder.decoder); |
| 217 RTC_CHECK(decoder_payload_types.find(decoder.payload_type) == | 221 RTC_CHECK(decoder_payload_types.find(decoder.payload_type) == |
| 218 decoder_payload_types.end()) | 222 decoder_payload_types.end()) |
| 219 << "Duplicate payload type (" << decoder.payload_type | 223 << "Duplicate payload type (" << decoder.payload_type |
| 220 << ") for different decoders."; | 224 << ") for different decoders."; |
| 221 decoder_payload_types.insert(decoder.payload_type); | 225 decoder_payload_types.insert(decoder.payload_type); |
| 222 } | 226 } |
| 223 | 227 |
| 224 video_receiver_.SetRenderDelay(config.render_delay_ms); | 228 video_receiver_.SetRenderDelay(config.render_delay_ms); |
| 225 | 229 |
| 226 jitter_estimator_.reset(new VCMJitterEstimator(clock_)); | 230 if (jitter_buffer_experiment_) { |
| 227 frame_buffer_.reset(new video_coding::FrameBuffer( | 231 jitter_estimator_.reset(new VCMJitterEstimator(clock_)); |
| 228 clock_, jitter_estimator_.get(), timing_.get(), &stats_proxy_)); | 232 frame_buffer_.reset(new video_coding::FrameBuffer( |
| 233 clock_, jitter_estimator_.get(), timing_.get())); |
| 234 } |
| 229 | 235 |
| 230 process_thread_->RegisterModule(&video_receiver_); | 236 process_thread_->RegisterModule(&video_receiver_); |
| 231 process_thread_->RegisterModule(&rtp_stream_sync_); | 237 process_thread_->RegisterModule(&rtp_stream_sync_); |
| 232 } | 238 } |
| 233 | 239 |
| 234 VideoReceiveStream::~VideoReceiveStream() { | 240 VideoReceiveStream::~VideoReceiveStream() { |
| 235 RTC_DCHECK_RUN_ON(&worker_thread_checker_); | 241 RTC_DCHECK_RUN_ON(&worker_thread_checker_); |
| 236 LOG(LS_INFO) << "~VideoReceiveStream: " << config_.ToString(); | 242 LOG(LS_INFO) << "~VideoReceiveStream: " << config_.ToString(); |
| 237 Stop(); | 243 Stop(); |
| 238 | 244 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 267 } | 273 } |
| 268 | 274 |
| 269 void VideoReceiveStream::Start() { | 275 void VideoReceiveStream::Start() { |
| 270 RTC_DCHECK_RUN_ON(&worker_thread_checker_); | 276 RTC_DCHECK_RUN_ON(&worker_thread_checker_); |
| 271 if (decode_thread_.IsRunning()) | 277 if (decode_thread_.IsRunning()) |
| 272 return; | 278 return; |
| 273 | 279 |
| 274 bool protected_by_fec = | 280 bool protected_by_fec = |
| 275 protected_by_flexfec_ || rtp_stream_receiver_.IsUlpfecEnabled(); | 281 protected_by_flexfec_ || rtp_stream_receiver_.IsUlpfecEnabled(); |
| 276 | 282 |
| 277 frame_buffer_->Start(); | 283 if (jitter_buffer_experiment_) { |
| 278 call_stats_->RegisterStatsObserver(&rtp_stream_receiver_); | 284 frame_buffer_->Start(); |
| 285 call_stats_->RegisterStatsObserver(&rtp_stream_receiver_); |
| 279 | 286 |
| 280 if (rtp_stream_receiver_.IsRetransmissionsEnabled() && protected_by_fec) { | 287 if (rtp_stream_receiver_.IsRetransmissionsEnabled() && protected_by_fec) { |
| 281 frame_buffer_->SetProtectionMode(kProtectionNackFEC); | 288 frame_buffer_->SetProtectionMode(kProtectionNackFEC); |
| 289 } |
| 282 } | 290 } |
| 283 | |
| 284 transport_adapter_.Enable(); | 291 transport_adapter_.Enable(); |
| 285 rtc::VideoSinkInterface<VideoFrame>* renderer = nullptr; | 292 rtc::VideoSinkInterface<VideoFrame>* renderer = nullptr; |
| 286 if (config_.renderer) { | 293 if (config_.renderer) { |
| 287 if (config_.disable_prerenderer_smoothing) { | 294 if (config_.disable_prerenderer_smoothing) { |
| 288 renderer = this; | 295 renderer = this; |
| 289 } else { | 296 } else { |
| 290 incoming_video_stream_.reset( | 297 incoming_video_stream_.reset( |
| 291 new IncomingVideoStream(config_.render_delay_ms, this)); | 298 new IncomingVideoStream(config_.render_delay_ms, this)); |
| 292 renderer = incoming_video_stream_.get(); | 299 renderer = incoming_video_stream_.get(); |
| 293 } | 300 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 317 } | 324 } |
| 318 | 325 |
| 319 void VideoReceiveStream::Stop() { | 326 void VideoReceiveStream::Stop() { |
| 320 RTC_DCHECK_RUN_ON(&worker_thread_checker_); | 327 RTC_DCHECK_RUN_ON(&worker_thread_checker_); |
| 321 rtp_stream_receiver_.StopReceive(); | 328 rtp_stream_receiver_.StopReceive(); |
| 322 // TriggerDecoderShutdown will release any waiting decoder thread and make it | 329 // TriggerDecoderShutdown will release any waiting decoder thread and make it |
| 323 // stop immediately, instead of waiting for a timeout. Needs to be called | 330 // stop immediately, instead of waiting for a timeout. Needs to be called |
| 324 // before joining the decoder thread thread. | 331 // before joining the decoder thread thread. |
| 325 video_receiver_.TriggerDecoderShutdown(); | 332 video_receiver_.TriggerDecoderShutdown(); |
| 326 | 333 |
| 327 frame_buffer_->Stop(); | 334 if (jitter_buffer_experiment_) { |
| 328 call_stats_->DeregisterStatsObserver(&rtp_stream_receiver_); | 335 frame_buffer_->Stop(); |
| 336 call_stats_->DeregisterStatsObserver(&rtp_stream_receiver_); |
| 337 } |
| 329 | 338 |
| 330 if (decode_thread_.IsRunning()) { | 339 if (decode_thread_.IsRunning()) { |
| 331 decode_thread_.Stop(); | 340 decode_thread_.Stop(); |
| 332 // Deregister external decoders so they are no longer running during | 341 // Deregister external decoders so they are no longer running during |
| 333 // destruction. This effectively stops the VCM since the decoder thread is | 342 // destruction. This effectively stops the VCM since the decoder thread is |
| 334 // stopped, the VCM is deregistered and no asynchronous decoder threads are | 343 // stopped, the VCM is deregistered and no asynchronous decoder threads are |
| 335 // running. | 344 // running. |
| 336 for (const Decoder& decoder : config_.decoders) | 345 for (const Decoder& decoder : config_.decoders) |
| 337 video_receiver_.RegisterExternalDecoder(nullptr, decoder.payload_type); | 346 video_receiver_.RegisterExternalDecoder(nullptr, decoder.payload_type); |
| 338 } | 347 } |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 RTC_DCHECK_RUN_ON(&module_process_thread_checker_); | 481 RTC_DCHECK_RUN_ON(&module_process_thread_checker_); |
| 473 video_receiver_.SetMinimumPlayoutDelay(delay_ms); | 482 video_receiver_.SetMinimumPlayoutDelay(delay_ms); |
| 474 } | 483 } |
| 475 | 484 |
| 476 bool VideoReceiveStream::DecodeThreadFunction(void* ptr) { | 485 bool VideoReceiveStream::DecodeThreadFunction(void* ptr) { |
| 477 static_cast<VideoReceiveStream*>(ptr)->Decode(); | 486 static_cast<VideoReceiveStream*>(ptr)->Decode(); |
| 478 return true; | 487 return true; |
| 479 } | 488 } |
| 480 | 489 |
| 481 void VideoReceiveStream::Decode() { | 490 void VideoReceiveStream::Decode() { |
| 482 static const int kMaxWaitForFrameMs = 3000; | 491 static const int kMaxDecodeWaitTimeMs = 50; |
| 483 std::unique_ptr<video_coding::FrameObject> frame; | 492 if (jitter_buffer_experiment_) { |
| 484 video_coding::FrameBuffer::ReturnReason res = | 493 static const int kMaxWaitForFrameMs = 3000; |
| 485 frame_buffer_->NextFrame(kMaxWaitForFrameMs, &frame); | 494 std::unique_ptr<video_coding::FrameObject> frame; |
| 495 video_coding::FrameBuffer::ReturnReason res = |
| 496 frame_buffer_->NextFrame(kMaxWaitForFrameMs, &frame); |
| 486 | 497 |
| 487 if (res == video_coding::FrameBuffer::ReturnReason::kStopped) | 498 if (res == video_coding::FrameBuffer::ReturnReason::kStopped) |
| 488 return; | 499 return; |
| 489 | 500 |
| 490 if (frame) { | 501 if (frame) { |
| 491 if (video_receiver_.Decode(frame.get()) == VCM_OK) | 502 if (video_receiver_.Decode(frame.get()) == VCM_OK) |
| 492 rtp_stream_receiver_.FrameDecoded(frame->picture_id); | 503 rtp_stream_receiver_.FrameDecoded(frame->picture_id); |
| 504 } else { |
| 505 LOG(LS_WARNING) << "No decodable frame in " << kMaxWaitForFrameMs |
| 506 << " ms, requesting keyframe."; |
| 507 RequestKeyFrame(); |
| 508 } |
| 493 } else { | 509 } else { |
| 494 LOG(LS_WARNING) << "No decodable frame in " << kMaxWaitForFrameMs | 510 video_receiver_.Decode(kMaxDecodeWaitTimeMs); |
| 495 << " ms, requesting keyframe."; | |
| 496 RequestKeyFrame(); | |
| 497 } | 511 } |
| 498 } | 512 } |
| 499 } // namespace internal | 513 } // namespace internal |
| 500 } // namespace webrtc | 514 } // namespace webrtc |
| OLD | NEW |