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