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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 num_cpu_cores_(num_cpu_cores), | 199 num_cpu_cores_(num_cpu_cores), |
200 protected_by_flexfec_(protected_by_flexfec), | 200 protected_by_flexfec_(protected_by_flexfec), |
201 process_thread_(process_thread), | 201 process_thread_(process_thread), |
202 clock_(Clock::GetRealTimeClock()), | 202 clock_(Clock::GetRealTimeClock()), |
203 decode_thread_(DecodeThreadFunction, this, "DecodingThread"), | 203 decode_thread_(DecodeThreadFunction, this, "DecodingThread"), |
204 congestion_controller_(congestion_controller), | 204 congestion_controller_(congestion_controller), |
205 call_stats_(call_stats), | 205 call_stats_(call_stats), |
206 timing_(new VCMTiming(clock_)), | 206 timing_(new VCMTiming(clock_)), |
207 video_receiver_(clock_, nullptr, this, timing_.get(), this, this), | 207 video_receiver_(clock_, nullptr, this, timing_.get(), this, this), |
208 stats_proxy_(&config_, clock_), | 208 stats_proxy_(&config_, clock_), |
209 rtp_stream_receiver_(&video_receiver_, | 209 rtp_stream_receiver_(congestion_controller_->GetRemoteBitrateEstimator( |
210 congestion_controller_->GetRemoteBitrateEstimator( | |
211 UseSendSideBwe(config_)), | 210 UseSendSideBwe(config_)), |
212 &transport_adapter_, | 211 &transport_adapter_, |
213 call_stats_->rtcp_rtt_stats(), | 212 call_stats_->rtcp_rtt_stats(), |
214 packet_router, | 213 packet_router, |
215 remb, | 214 remb, |
216 &config_, | 215 &config_, |
217 &stats_proxy_, | 216 &stats_proxy_, |
218 process_thread_, | 217 process_thread_, |
219 this, // NackSender | 218 this, // NackSender |
220 this, // KeyFrameRequestSender | 219 this, // KeyFrameRequestSender |
221 this, // OnCompleteFrameCallback | 220 this, // OnCompleteFrameCallback |
222 timing_.get()), | 221 timing_.get()), |
223 rtp_stream_sync_(this), | 222 rtp_stream_sync_(this) { |
224 jitter_buffer_experiment_( | |
225 field_trial::FindFullName("WebRTC-NewVideoJitterBuffer") == | |
226 "Enabled") { | |
227 LOG(LS_INFO) << "VideoReceiveStream: " << config_.ToString(); | 223 LOG(LS_INFO) << "VideoReceiveStream: " << config_.ToString(); |
228 | 224 |
229 RTC_DCHECK(process_thread_); | 225 RTC_DCHECK(process_thread_); |
230 RTC_DCHECK(congestion_controller_); | 226 RTC_DCHECK(congestion_controller_); |
231 RTC_DCHECK(call_stats_); | 227 RTC_DCHECK(call_stats_); |
232 | 228 |
233 module_process_thread_checker_.DetachFromThread(); | 229 module_process_thread_checker_.DetachFromThread(); |
234 | 230 |
235 RTC_DCHECK(!config_.decoders.empty()); | 231 RTC_DCHECK(!config_.decoders.empty()); |
236 std::set<int> decoder_payload_types; | 232 std::set<int> decoder_payload_types; |
237 for (const Decoder& decoder : config_.decoders) { | 233 for (const Decoder& decoder : config_.decoders) { |
238 RTC_CHECK(decoder.decoder); | 234 RTC_CHECK(decoder.decoder); |
239 RTC_CHECK(decoder_payload_types.find(decoder.payload_type) == | 235 RTC_CHECK(decoder_payload_types.find(decoder.payload_type) == |
240 decoder_payload_types.end()) | 236 decoder_payload_types.end()) |
241 << "Duplicate payload type (" << decoder.payload_type | 237 << "Duplicate payload type (" << decoder.payload_type |
242 << ") for different decoders."; | 238 << ") for different decoders."; |
243 decoder_payload_types.insert(decoder.payload_type); | 239 decoder_payload_types.insert(decoder.payload_type); |
244 } | 240 } |
245 | 241 |
246 video_receiver_.SetRenderDelay(config.render_delay_ms); | 242 video_receiver_.SetRenderDelay(config.render_delay_ms); |
247 | 243 |
248 if (jitter_buffer_experiment_) { | 244 jitter_estimator_.reset(new VCMJitterEstimator(clock_)); |
249 jitter_estimator_.reset(new VCMJitterEstimator(clock_)); | 245 frame_buffer_.reset(new video_coding::FrameBuffer( |
250 frame_buffer_.reset(new video_coding::FrameBuffer( | 246 clock_, jitter_estimator_.get(), timing_.get(), &stats_proxy_)); |
251 clock_, jitter_estimator_.get(), timing_.get())); | |
252 } | |
253 | 247 |
254 process_thread_->RegisterModule(&video_receiver_); | 248 process_thread_->RegisterModule(&video_receiver_); |
255 process_thread_->RegisterModule(&rtp_stream_sync_); | 249 process_thread_->RegisterModule(&rtp_stream_sync_); |
256 } | 250 } |
257 | 251 |
258 VideoReceiveStream::~VideoReceiveStream() { | 252 VideoReceiveStream::~VideoReceiveStream() { |
259 RTC_DCHECK_RUN_ON(&worker_thread_checker_); | 253 RTC_DCHECK_RUN_ON(&worker_thread_checker_); |
260 LOG(LS_INFO) << "~VideoReceiveStream: " << config_.ToString(); | 254 LOG(LS_INFO) << "~VideoReceiveStream: " << config_.ToString(); |
261 Stop(); | 255 Stop(); |
262 | 256 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 } | 288 } |
295 | 289 |
296 void VideoReceiveStream::Start() { | 290 void VideoReceiveStream::Start() { |
297 RTC_DCHECK_RUN_ON(&worker_thread_checker_); | 291 RTC_DCHECK_RUN_ON(&worker_thread_checker_); |
298 if (decode_thread_.IsRunning()) | 292 if (decode_thread_.IsRunning()) |
299 return; | 293 return; |
300 | 294 |
301 bool protected_by_fec = | 295 bool protected_by_fec = |
302 protected_by_flexfec_ || rtp_stream_receiver_.IsUlpfecEnabled(); | 296 protected_by_flexfec_ || rtp_stream_receiver_.IsUlpfecEnabled(); |
303 | 297 |
304 if (jitter_buffer_experiment_) { | 298 frame_buffer_->Start(); |
305 frame_buffer_->Start(); | 299 call_stats_->RegisterStatsObserver(&rtp_stream_receiver_); |
306 call_stats_->RegisterStatsObserver(&rtp_stream_receiver_); | |
307 | 300 |
308 if (rtp_stream_receiver_.IsRetransmissionsEnabled() && protected_by_fec) { | 301 if (rtp_stream_receiver_.IsRetransmissionsEnabled() && protected_by_fec) { |
309 frame_buffer_->SetProtectionMode(kProtectionNackFEC); | 302 frame_buffer_->SetProtectionMode(kProtectionNackFEC); |
310 } | |
311 } | 303 } |
| 304 |
312 transport_adapter_.Enable(); | 305 transport_adapter_.Enable(); |
313 rtc::VideoSinkInterface<VideoFrame>* renderer = nullptr; | 306 rtc::VideoSinkInterface<VideoFrame>* renderer = nullptr; |
314 if (config_.renderer) { | 307 if (config_.renderer) { |
315 if (config_.disable_prerenderer_smoothing) { | 308 if (config_.disable_prerenderer_smoothing) { |
316 renderer = this; | 309 renderer = this; |
317 } else { | 310 } else { |
318 incoming_video_stream_.reset( | 311 incoming_video_stream_.reset( |
319 new IncomingVideoStream(config_.render_delay_ms, this)); | 312 new IncomingVideoStream(config_.render_delay_ms, this)); |
320 renderer = incoming_video_stream_.get(); | 313 renderer = incoming_video_stream_.get(); |
321 } | 314 } |
(...skipping 23 matching lines...) Expand all Loading... |
345 } | 338 } |
346 | 339 |
347 void VideoReceiveStream::Stop() { | 340 void VideoReceiveStream::Stop() { |
348 RTC_DCHECK_RUN_ON(&worker_thread_checker_); | 341 RTC_DCHECK_RUN_ON(&worker_thread_checker_); |
349 rtp_stream_receiver_.StopReceive(); | 342 rtp_stream_receiver_.StopReceive(); |
350 // TriggerDecoderShutdown will release any waiting decoder thread and make it | 343 // TriggerDecoderShutdown will release any waiting decoder thread and make it |
351 // stop immediately, instead of waiting for a timeout. Needs to be called | 344 // stop immediately, instead of waiting for a timeout. Needs to be called |
352 // before joining the decoder thread thread. | 345 // before joining the decoder thread thread. |
353 video_receiver_.TriggerDecoderShutdown(); | 346 video_receiver_.TriggerDecoderShutdown(); |
354 | 347 |
355 if (jitter_buffer_experiment_) { | 348 frame_buffer_->Stop(); |
356 frame_buffer_->Stop(); | 349 call_stats_->DeregisterStatsObserver(&rtp_stream_receiver_); |
357 call_stats_->DeregisterStatsObserver(&rtp_stream_receiver_); | |
358 } | |
359 | 350 |
360 if (decode_thread_.IsRunning()) { | 351 if (decode_thread_.IsRunning()) { |
361 decode_thread_.Stop(); | 352 decode_thread_.Stop(); |
362 // Deregister external decoders so they are no longer running during | 353 // Deregister external decoders so they are no longer running during |
363 // destruction. This effectively stops the VCM since the decoder thread is | 354 // destruction. This effectively stops the VCM since the decoder thread is |
364 // stopped, the VCM is deregistered and no asynchronous decoder threads are | 355 // stopped, the VCM is deregistered and no asynchronous decoder threads are |
365 // running. | 356 // running. |
366 for (const Decoder& decoder : config_.decoders) | 357 for (const Decoder& decoder : config_.decoders) |
367 video_receiver_.RegisterExternalDecoder(nullptr, decoder.payload_type); | 358 video_receiver_.RegisterExternalDecoder(nullptr, decoder.payload_type); |
368 } | 359 } |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 RTC_DCHECK_RUN_ON(&module_process_thread_checker_); | 493 RTC_DCHECK_RUN_ON(&module_process_thread_checker_); |
503 video_receiver_.SetMinimumPlayoutDelay(delay_ms); | 494 video_receiver_.SetMinimumPlayoutDelay(delay_ms); |
504 } | 495 } |
505 | 496 |
506 bool VideoReceiveStream::DecodeThreadFunction(void* ptr) { | 497 bool VideoReceiveStream::DecodeThreadFunction(void* ptr) { |
507 static_cast<VideoReceiveStream*>(ptr)->Decode(); | 498 static_cast<VideoReceiveStream*>(ptr)->Decode(); |
508 return true; | 499 return true; |
509 } | 500 } |
510 | 501 |
511 void VideoReceiveStream::Decode() { | 502 void VideoReceiveStream::Decode() { |
512 static const int kMaxDecodeWaitTimeMs = 50; | 503 static const int kMaxWaitForFrameMs = 3000; |
513 if (jitter_buffer_experiment_) { | 504 std::unique_ptr<video_coding::FrameObject> frame; |
514 static const int kMaxWaitForFrameMs = 3000; | 505 video_coding::FrameBuffer::ReturnReason res = |
515 std::unique_ptr<video_coding::FrameObject> frame; | 506 frame_buffer_->NextFrame(kMaxWaitForFrameMs, &frame); |
516 video_coding::FrameBuffer::ReturnReason res = | |
517 frame_buffer_->NextFrame(kMaxWaitForFrameMs, &frame); | |
518 | 507 |
519 if (res == video_coding::FrameBuffer::ReturnReason::kStopped) | 508 if (res == video_coding::FrameBuffer::ReturnReason::kStopped) |
520 return; | 509 return; |
521 | 510 |
522 if (frame) { | 511 if (frame) { |
523 if (video_receiver_.Decode(frame.get()) == VCM_OK) | 512 if (video_receiver_.Decode(frame.get()) == VCM_OK) |
524 rtp_stream_receiver_.FrameDecoded(frame->picture_id); | 513 rtp_stream_receiver_.FrameDecoded(frame->picture_id); |
525 } else { | |
526 LOG(LS_WARNING) << "No decodable frame in " << kMaxWaitForFrameMs | |
527 << " ms, requesting keyframe."; | |
528 RequestKeyFrame(); | |
529 } | |
530 } else { | 514 } else { |
531 video_receiver_.Decode(kMaxDecodeWaitTimeMs); | 515 LOG(LS_WARNING) << "No decodable frame in " << kMaxWaitForFrameMs |
| 516 << " ms, requesting keyframe."; |
| 517 RequestKeyFrame(); |
532 } | 518 } |
533 } | 519 } |
534 } // namespace internal | 520 } // namespace internal |
535 } // namespace webrtc | 521 } // namespace webrtc |
OLD | NEW |