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 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
365 remb_(remb), | 365 remb_(remb), |
366 encoder_thread_(EncoderThreadFunction, this, "EncoderThread"), | 366 encoder_thread_(EncoderThreadFunction, this, "EncoderThread"), |
367 encoder_wakeup_event_(false, false), | 367 encoder_wakeup_event_(false, false), |
368 stop_encoder_thread_(0), | 368 stop_encoder_thread_(0), |
369 overuse_detector_( | 369 overuse_detector_( |
370 Clock::GetRealTimeClock(), | 370 Clock::GetRealTimeClock(), |
371 GetCpuOveruseOptions(config.encoder_settings.full_overuse_time), | 371 GetCpuOveruseOptions(config.encoder_settings.full_overuse_time), |
372 this, | 372 this, |
373 config.post_encode_callback, | 373 config.post_encode_callback, |
374 &stats_proxy_), | 374 &stats_proxy_), |
375 vie_encoder_( | 375 vie_encoder_(num_cpu_cores, |
376 num_cpu_cores, | 376 config_.rtp.ssrcs, |
377 config_.rtp.ssrcs, | 377 module_process_thread_, |
378 module_process_thread_, | 378 &stats_proxy_, |
379 &stats_proxy_, | 379 config.pre_encode_callback, |
380 config.pre_encode_callback, | 380 &overuse_detector_, |
381 &overuse_detector_, | 381 congestion_controller_->pacer()), |
382 congestion_controller_->pacer(), | |
383 &payload_router_, | |
384 config.post_encode_callback ? &encoded_frame_proxy_ : nullptr), | |
385 video_sender_(vie_encoder_.video_sender()), | 382 video_sender_(vie_encoder_.video_sender()), |
386 bandwidth_observer_(congestion_controller_->GetBitrateController() | 383 bandwidth_observer_(congestion_controller_->GetBitrateController() |
387 ->CreateRtcpBandwidthObserver()), | 384 ->CreateRtcpBandwidthObserver()), |
388 rtp_rtcp_modules_(CreateRtpRtcpModules( | 385 rtp_rtcp_modules_(CreateRtpRtcpModules( |
389 config.send_transport, | 386 config.send_transport, |
390 &encoder_feedback_, | 387 &encoder_feedback_, |
391 bandwidth_observer_.get(), | 388 bandwidth_observer_.get(), |
392 congestion_controller_->GetTransportFeedbackObserver(), | 389 congestion_controller_->GetTransportFeedbackObserver(), |
393 call_stats_->rtcp_rtt_stats(), | 390 call_stats_->rtcp_rtt_stats(), |
394 congestion_controller_->pacer(), | 391 congestion_controller_->pacer(), |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
492 } | 489 } |
493 | 490 |
494 VideoCaptureInput* VideoSendStream::Input() { | 491 VideoCaptureInput* VideoSendStream::Input() { |
495 return &input_; | 492 return &input_; |
496 } | 493 } |
497 | 494 |
498 void VideoSendStream::Start() { | 495 void VideoSendStream::Start() { |
499 if (payload_router_.active()) | 496 if (payload_router_.active()) |
500 return; | 497 return; |
501 TRACE_EVENT_INSTANT0("webrtc", "VideoSendStream::Start"); | 498 TRACE_EVENT_INSTANT0("webrtc", "VideoSendStream::Start"); |
502 vie_encoder_.Pause(); | |
503 payload_router_.set_active(true); | 499 payload_router_.set_active(true); |
504 // Was not already started, trigger a keyframe. | 500 // Was not already started, trigger a keyframe. |
505 vie_encoder_.SendKeyFrame(); | 501 vie_encoder_.SendKeyFrame(); |
506 vie_encoder_.Restart(); | 502 vie_encoder_.Start(); |
507 } | 503 } |
508 | 504 |
509 void VideoSendStream::Stop() { | 505 void VideoSendStream::Stop() { |
510 if (!payload_router_.active()) | 506 if (!payload_router_.active()) |
511 return; | 507 return; |
512 TRACE_EVENT_INSTANT0("webrtc", "VideoSendStream::Stop"); | 508 TRACE_EVENT_INSTANT0("webrtc", "VideoSendStream::Stop"); |
513 // TODO(pbos): Make sure the encoder stops here. | 509 vie_encoder_.Pause(); |
514 payload_router_.set_active(false); | 510 payload_router_.set_active(false); |
515 } | 511 } |
516 | 512 |
517 bool VideoSendStream::EncoderThreadFunction(void* obj) { | 513 bool VideoSendStream::EncoderThreadFunction(void* obj) { |
518 static_cast<VideoSendStream*>(obj)->EncoderProcess(); | 514 static_cast<VideoSendStream*>(obj)->EncoderProcess(); |
519 // We're done, return false to abort. | 515 // We're done, return false to abort. |
520 return false; | 516 return false; |
521 } | 517 } |
522 | 518 |
523 void VideoSendStream::EncoderProcess() { | 519 void VideoSendStream::EncoderProcess() { |
(...skipping 13 matching lines...) Expand all Loading... | |
537 encoder_settings = pending_encoder_settings_; | 533 encoder_settings = pending_encoder_settings_; |
538 pending_encoder_settings_ = rtc::Optional<EncoderSettings>(); | 534 pending_encoder_settings_ = rtc::Optional<EncoderSettings>(); |
539 } | 535 } |
540 } | 536 } |
541 if (encoder_settings) { | 537 if (encoder_settings) { |
542 encoder_settings->video_codec.startBitrate = | 538 encoder_settings->video_codec.startBitrate = |
543 bitrate_allocator_->AddObserver( | 539 bitrate_allocator_->AddObserver( |
544 this, encoder_settings->video_codec.minBitrate * 1000, | 540 this, encoder_settings->video_codec.minBitrate * 1000, |
545 encoder_settings->video_codec.maxBitrate * 1000) / | 541 encoder_settings->video_codec.maxBitrate * 1000) / |
546 1000; | 542 1000; |
543 | |
544 payload_router_.SetSendCodec(encoder_settings->video_codec); | |
pbos-webrtc
2016/04/22 15:24:20
Perhaps the encoder settings' VideoStreams can be
| |
547 vie_encoder_.SetEncoder(encoder_settings->video_codec, | 545 vie_encoder_.SetEncoder(encoder_settings->video_codec, |
548 encoder_settings->min_transmit_bitrate_bps); | 546 encoder_settings->min_transmit_bitrate_bps, |
547 payload_router_.MaxPayloadLength(), this); | |
549 if (config_.suspend_below_min_bitrate) { | 548 if (config_.suspend_below_min_bitrate) { |
550 video_sender_->SuspendBelowMinBitrate(); | 549 video_sender_->SuspendBelowMinBitrate(); |
551 bitrate_allocator_->EnforceMinBitrate(false); | 550 bitrate_allocator_->EnforceMinBitrate(false); |
552 } | 551 } |
553 // We might've gotten new settings while configuring the encoder settings, | 552 // We might've gotten new settings while configuring the encoder settings, |
554 // restart from the top to see if that's the case before trying to encode | 553 // restart from the top to see if that's the case before trying to encode |
555 // a frame (which might correspond to the last frame size). | 554 // a frame (which might correspond to the last frame size). |
556 encoder_wakeup_event_.Set(); | 555 encoder_wakeup_event_.Set(); |
557 continue; | 556 continue; |
558 } | 557 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
593 void VideoSendStream::OveruseDetected() { | 592 void VideoSendStream::OveruseDetected() { |
594 if (config_.overuse_callback) | 593 if (config_.overuse_callback) |
595 config_.overuse_callback->OnLoadUpdate(LoadObserver::kOveruse); | 594 config_.overuse_callback->OnLoadUpdate(LoadObserver::kOveruse); |
596 } | 595 } |
597 | 596 |
598 void VideoSendStream::NormalUsage() { | 597 void VideoSendStream::NormalUsage() { |
599 if (config_.overuse_callback) | 598 if (config_.overuse_callback) |
600 config_.overuse_callback->OnLoadUpdate(LoadObserver::kUnderuse); | 599 config_.overuse_callback->OnLoadUpdate(LoadObserver::kUnderuse); |
601 } | 600 } |
602 | 601 |
602 int32_t VideoSendStream::Encoded(const EncodedImage& encoded_image, | |
603 const CodecSpecificInfo* codec_specific_info, | |
604 const RTPFragmentationHeader* fragmentation) { | |
605 // |encoded_frame_proxy_| forwards frames to |config_.post_encode_callback|; | |
pbos-webrtc
2016/04/22 15:24:20
Should encoded_frame_proxy_ also contain payload_r
perkj_webrtc
2016/04/27 08:00:57
EncodedFrameProxy is used on the receive side and
| |
606 encoded_frame_proxy_.Encoded(encoded_image, codec_specific_info, | |
607 fragmentation); | |
608 return payload_router_.Encoded(encoded_image, codec_specific_info, | |
609 fragmentation); | |
610 } | |
611 | |
603 void VideoSendStream::ConfigureProtection() { | 612 void VideoSendStream::ConfigureProtection() { |
604 // Enable NACK, FEC or both. | 613 // Enable NACK, FEC or both. |
605 const bool enable_protection_nack = config_.rtp.nack.rtp_history_ms > 0; | 614 const bool enable_protection_nack = config_.rtp.nack.rtp_history_ms > 0; |
606 bool enable_protection_fec = config_.rtp.fec.red_payload_type != -1; | 615 bool enable_protection_fec = config_.rtp.fec.red_payload_type != -1; |
607 // Payload types without picture ID cannot determine that a stream is complete | 616 // Payload types without picture ID cannot determine that a stream is complete |
608 // without retransmitting FEC, so using FEC + NACK for H.264 (for instance) is | 617 // without retransmitting FEC, so using FEC + NACK for H.264 (for instance) is |
609 // a waste of bandwidth since FEC packets still have to be transmitted. Note | 618 // a waste of bandwidth since FEC packets still have to be transmitted. Note |
610 // that this is not the case with FLEXFEC. | 619 // that this is not the case with FLEXFEC. |
611 if (enable_protection_nack && | 620 if (enable_protection_nack && |
612 !PayloadTypeSupportsSkippingFecPackets( | 621 !PayloadTypeSupportsSkippingFecPackets( |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
729 } | 738 } |
730 } | 739 } |
731 | 740 |
732 int VideoSendStream::GetPaddingNeededBps() const { | 741 int VideoSendStream::GetPaddingNeededBps() const { |
733 return vie_encoder_.GetPaddingNeededBps(); | 742 return vie_encoder_.GetPaddingNeededBps(); |
734 } | 743 } |
735 | 744 |
736 void VideoSendStream::OnBitrateUpdated(uint32_t bitrate_bps, | 745 void VideoSendStream::OnBitrateUpdated(uint32_t bitrate_bps, |
737 uint8_t fraction_loss, | 746 uint8_t fraction_loss, |
738 int64_t rtt) { | 747 int64_t rtt) { |
748 payload_router_.SetTargetSendBitrate(bitrate_bps); | |
739 vie_encoder_.OnBitrateUpdated(bitrate_bps, fraction_loss, rtt); | 749 vie_encoder_.OnBitrateUpdated(bitrate_bps, fraction_loss, rtt); |
740 } | 750 } |
741 | 751 |
742 int VideoSendStream::ProtectionRequest(const FecProtectionParams* delta_params, | 752 int VideoSendStream::ProtectionRequest(const FecProtectionParams* delta_params, |
743 const FecProtectionParams* key_params, | 753 const FecProtectionParams* key_params, |
744 uint32_t* sent_video_rate_bps, | 754 uint32_t* sent_video_rate_bps, |
745 uint32_t* sent_nack_rate_bps, | 755 uint32_t* sent_nack_rate_bps, |
746 uint32_t* sent_fec_rate_bps) { | 756 uint32_t* sent_fec_rate_bps) { |
747 *sent_video_rate_bps = 0; | 757 *sent_video_rate_bps = 0; |
748 *sent_nack_rate_bps = 0; | 758 *sent_nack_rate_bps = 0; |
749 *sent_fec_rate_bps = 0; | 759 *sent_fec_rate_bps = 0; |
750 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { | 760 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { |
751 uint32_t not_used = 0; | 761 uint32_t not_used = 0; |
752 uint32_t module_video_rate = 0; | 762 uint32_t module_video_rate = 0; |
753 uint32_t module_fec_rate = 0; | 763 uint32_t module_fec_rate = 0; |
754 uint32_t module_nack_rate = 0; | 764 uint32_t module_nack_rate = 0; |
755 rtp_rtcp->SetFecParameters(delta_params, key_params); | 765 rtp_rtcp->SetFecParameters(delta_params, key_params); |
756 rtp_rtcp->BitrateSent(¬_used, &module_video_rate, &module_fec_rate, | 766 rtp_rtcp->BitrateSent(¬_used, &module_video_rate, &module_fec_rate, |
757 &module_nack_rate); | 767 &module_nack_rate); |
758 *sent_video_rate_bps += module_video_rate; | 768 *sent_video_rate_bps += module_video_rate; |
759 *sent_nack_rate_bps += module_nack_rate; | 769 *sent_nack_rate_bps += module_nack_rate; |
760 *sent_fec_rate_bps += module_fec_rate; | 770 *sent_fec_rate_bps += module_fec_rate; |
761 } | 771 } |
762 return 0; | 772 return 0; |
763 } | 773 } |
764 | 774 |
765 } // namespace internal | 775 } // namespace internal |
766 } // namespace webrtc | 776 } // namespace webrtc |
OLD | NEW |