Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(586)

Side by Side Diff: webrtc/video/video_receive_stream.cc

Issue 2642753002: Reland of Make the new jitter buffer the default jitter buffer. (Closed)
Patch Set: Rebase Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/video/video_receive_stream.h ('k') | webrtc/video/video_stream_decoder.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 packet_router, 216 packet_router,
217 remb, 217 remb,
218 &config_, 218 &config_,
219 &stats_proxy_, 219 &stats_proxy_,
220 process_thread_, 220 process_thread_,
221 congestion_controller_->GetRetransmissionRateLimiter(), 221 congestion_controller_->GetRetransmissionRateLimiter(),
222 this, // NackSender 222 this, // NackSender
223 this, // KeyFrameRequestSender 223 this, // KeyFrameRequestSender
224 this, // OnCompleteFrameCallback 224 this, // OnCompleteFrameCallback
225 timing_.get()), 225 timing_.get()),
226 rtp_stream_sync_(&video_receiver_, &rtp_stream_receiver_), 226 rtp_stream_sync_(&video_receiver_, &rtp_stream_receiver_) {
227 jitter_buffer_experiment_(
228 field_trial::FindFullName("WebRTC-NewVideoJitterBuffer") ==
229 "Enabled") {
230 LOG(LS_INFO) << "VideoReceiveStream: " << config_.ToString(); 227 LOG(LS_INFO) << "VideoReceiveStream: " << config_.ToString();
231 228
232 RTC_DCHECK(process_thread_); 229 RTC_DCHECK(process_thread_);
233 RTC_DCHECK(congestion_controller_); 230 RTC_DCHECK(congestion_controller_);
234 RTC_DCHECK(call_stats_); 231 RTC_DCHECK(call_stats_);
235 232
236 RTC_DCHECK(!config_.decoders.empty()); 233 RTC_DCHECK(!config_.decoders.empty());
237 std::set<int> decoder_payload_types; 234 std::set<int> decoder_payload_types;
238 for (const Decoder& decoder : config_.decoders) { 235 for (const Decoder& decoder : config_.decoders) {
239 RTC_CHECK(decoder.decoder); 236 RTC_CHECK(decoder.decoder);
240 RTC_CHECK(decoder_payload_types.find(decoder.payload_type) == 237 RTC_CHECK(decoder_payload_types.find(decoder.payload_type) ==
241 decoder_payload_types.end()) 238 decoder_payload_types.end())
242 << "Duplicate payload type (" << decoder.payload_type 239 << "Duplicate payload type (" << decoder.payload_type
243 << ") for different decoders."; 240 << ") for different decoders.";
244 decoder_payload_types.insert(decoder.payload_type); 241 decoder_payload_types.insert(decoder.payload_type);
245 } 242 }
246 243
247 video_receiver_.SetRenderDelay(config.render_delay_ms); 244 video_receiver_.SetRenderDelay(config.render_delay_ms);
248 245
249 if (jitter_buffer_experiment_) { 246 jitter_estimator_.reset(new VCMJitterEstimator(clock_));
250 jitter_estimator_.reset(new VCMJitterEstimator(clock_)); 247 frame_buffer_.reset(new video_coding::FrameBuffer(
251 frame_buffer_.reset(new video_coding::FrameBuffer( 248 clock_, jitter_estimator_.get(), timing_.get(), &stats_proxy_));
252 clock_, jitter_estimator_.get(), timing_.get()));
253 }
254 249
255 process_thread_->RegisterModule(&video_receiver_); 250 process_thread_->RegisterModule(&video_receiver_);
256 process_thread_->RegisterModule(&rtp_stream_sync_); 251 process_thread_->RegisterModule(&rtp_stream_sync_);
257 } 252 }
258 253
259 VideoReceiveStream::~VideoReceiveStream() { 254 VideoReceiveStream::~VideoReceiveStream() {
260 LOG(LS_INFO) << "~VideoReceiveStream: " << config_.ToString(); 255 LOG(LS_INFO) << "~VideoReceiveStream: " << config_.ToString();
261 Stop(); 256 Stop();
262 257
263 process_thread_->DeRegisterModule(&rtp_stream_sync_); 258 process_thread_->DeRegisterModule(&rtp_stream_sync_);
(...skipping 19 matching lines...) Expand all
283 } 278 }
284 279
285 bool VideoReceiveStream::OnRecoveredPacket(const uint8_t* packet, 280 bool VideoReceiveStream::OnRecoveredPacket(const uint8_t* packet,
286 size_t length) { 281 size_t length) {
287 return rtp_stream_receiver_.OnRecoveredPacket(packet, length); 282 return rtp_stream_receiver_.OnRecoveredPacket(packet, length);
288 } 283 }
289 284
290 void VideoReceiveStream::Start() { 285 void VideoReceiveStream::Start() {
291 if (decode_thread_.IsRunning()) 286 if (decode_thread_.IsRunning())
292 return; 287 return;
293 if (jitter_buffer_experiment_) {
294 frame_buffer_->Start();
295 call_stats_->RegisterStatsObserver(&rtp_stream_receiver_);
296 288
297 if (rtp_stream_receiver_.IsRetransmissionsEnabled() && 289 frame_buffer_->Start();
298 rtp_stream_receiver_.IsUlpfecEnabled()) { 290 call_stats_->RegisterStatsObserver(&rtp_stream_receiver_);
299 frame_buffer_->SetProtectionMode(kProtectionNackFEC); 291
300 } 292 if (rtp_stream_receiver_.IsRetransmissionsEnabled() &&
293 rtp_stream_receiver_.IsUlpfecEnabled()) {
294 frame_buffer_->SetProtectionMode(kProtectionNackFEC);
301 } 295 }
296
302 transport_adapter_.Enable(); 297 transport_adapter_.Enable();
303 rtc::VideoSinkInterface<VideoFrame>* renderer = nullptr; 298 rtc::VideoSinkInterface<VideoFrame>* renderer = nullptr;
304 if (config_.renderer) { 299 if (config_.renderer) {
305 if (config_.disable_prerenderer_smoothing) { 300 if (config_.disable_prerenderer_smoothing) {
306 renderer = this; 301 renderer = this;
307 } else { 302 } else {
308 incoming_video_stream_.reset( 303 incoming_video_stream_.reset(
309 new IncomingVideoStream(config_.render_delay_ms, this)); 304 new IncomingVideoStream(config_.render_delay_ms, this));
310 renderer = incoming_video_stream_.get(); 305 renderer = incoming_video_stream_.get();
311 } 306 }
(...skipping 24 matching lines...) Expand all
336 rtp_stream_receiver_.StartReceive(); 331 rtp_stream_receiver_.StartReceive();
337 } 332 }
338 333
339 void VideoReceiveStream::Stop() { 334 void VideoReceiveStream::Stop() {
340 rtp_stream_receiver_.StopReceive(); 335 rtp_stream_receiver_.StopReceive();
341 // TriggerDecoderShutdown will release any waiting decoder thread and make it 336 // TriggerDecoderShutdown will release any waiting decoder thread and make it
342 // stop immediately, instead of waiting for a timeout. Needs to be called 337 // stop immediately, instead of waiting for a timeout. Needs to be called
343 // before joining the decoder thread thread. 338 // before joining the decoder thread thread.
344 video_receiver_.TriggerDecoderShutdown(); 339 video_receiver_.TriggerDecoderShutdown();
345 340
346 if (jitter_buffer_experiment_) { 341 frame_buffer_->Stop();
347 frame_buffer_->Stop(); 342 call_stats_->DeregisterStatsObserver(&rtp_stream_receiver_);
348 call_stats_->DeregisterStatsObserver(&rtp_stream_receiver_);
349 }
350 343
351 if (decode_thread_.IsRunning()) { 344 if (decode_thread_.IsRunning()) {
352 decode_thread_.Stop(); 345 decode_thread_.Stop();
353 // Deregister external decoders so they are no longer running during 346 // Deregister external decoders so they are no longer running during
354 // destruction. This effectively stops the VCM since the decoder thread is 347 // destruction. This effectively stops the VCM since the decoder thread is
355 // stopped, the VCM is deregistered and no asynchronous decoder threads are 348 // stopped, the VCM is deregistered and no asynchronous decoder threads are
356 // running. 349 // running.
357 for (const Decoder& decoder : config_.decoders) 350 for (const Decoder& decoder : config_.decoders)
358 video_receiver_.RegisterExternalDecoder(nullptr, decoder.payload_type); 351 video_receiver_.RegisterExternalDecoder(nullptr, decoder.payload_type);
359 } 352 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 428
436 return Result(Result::OK, encoded_image._timeStamp); 429 return Result(Result::OK, encoded_image._timeStamp);
437 } 430 }
438 431
439 bool VideoReceiveStream::DecodeThreadFunction(void* ptr) { 432 bool VideoReceiveStream::DecodeThreadFunction(void* ptr) {
440 static_cast<VideoReceiveStream*>(ptr)->Decode(); 433 static_cast<VideoReceiveStream*>(ptr)->Decode();
441 return true; 434 return true;
442 } 435 }
443 436
444 void VideoReceiveStream::Decode() { 437 void VideoReceiveStream::Decode() {
445 static const int kMaxDecodeWaitTimeMs = 50; 438 static const int kMaxWaitForFrameMs = 3000;
446 if (jitter_buffer_experiment_) { 439 std::unique_ptr<video_coding::FrameObject> frame;
447 static const int kMaxWaitForFrameMs = 3000; 440 video_coding::FrameBuffer::ReturnReason res =
448 std::unique_ptr<video_coding::FrameObject> frame; 441 frame_buffer_->NextFrame(kMaxWaitForFrameMs, &frame);
449 video_coding::FrameBuffer::ReturnReason res =
450 frame_buffer_->NextFrame(kMaxWaitForFrameMs, &frame);
451 442
452 if (res == video_coding::FrameBuffer::ReturnReason::kStopped) 443 if (res == video_coding::FrameBuffer::ReturnReason::kStopped)
453 return; 444 return;
454 445
455 if (frame) { 446 if (frame) {
456 if (video_receiver_.Decode(frame.get()) == VCM_OK) 447 if (video_receiver_.Decode(frame.get()) == VCM_OK)
457 rtp_stream_receiver_.FrameDecoded(frame->picture_id); 448 rtp_stream_receiver_.FrameDecoded(frame->picture_id);
458 } else {
459 LOG(LS_WARNING) << "No decodable frame in " << kMaxWaitForFrameMs
460 << " ms, requesting keyframe.";
461 RequestKeyFrame();
462 }
463 } else { 449 } else {
464 video_receiver_.Decode(kMaxDecodeWaitTimeMs); 450 LOG(LS_WARNING) << "No decodable frame in " << kMaxWaitForFrameMs
451 << " ms, requesting keyframe.";
452 RequestKeyFrame();
465 } 453 }
466 } 454 }
467 455
468 void VideoReceiveStream::SendNack( 456 void VideoReceiveStream::SendNack(
469 const std::vector<uint16_t>& sequence_numbers) { 457 const std::vector<uint16_t>& sequence_numbers) {
470 rtp_stream_receiver_.RequestPacketRetransmit(sequence_numbers); 458 rtp_stream_receiver_.RequestPacketRetransmit(sequence_numbers);
471 } 459 }
472 460
473 void VideoReceiveStream::EnableEncodedFrameRecording(rtc::PlatformFile file, 461 void VideoReceiveStream::EnableEncodedFrameRecording(rtc::PlatformFile file,
474 size_t byte_limit) { 462 size_t byte_limit) {
(...skipping 12 matching lines...) Expand all
487 RequestKeyFrame(); 475 RequestKeyFrame();
488 } 476 }
489 } 477 }
490 478
491 void VideoReceiveStream::RequestKeyFrame() { 479 void VideoReceiveStream::RequestKeyFrame() {
492 rtp_stream_receiver_.RequestKeyFrame(); 480 rtp_stream_receiver_.RequestKeyFrame();
493 } 481 }
494 482
495 } // namespace internal 483 } // namespace internal
496 } // namespace webrtc 484 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/video_receive_stream.h ('k') | webrtc/video/video_stream_decoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698