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

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

Issue 1936503002: Removed SSRC knowledge from ViEEncoder. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@move_payload_router2
Patch Set: Rebased Created 4 years, 7 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_send_stream.h ('k') | webrtc/video/vie_encoder.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
11 #include "webrtc/video/video_send_stream.h" 11 #include "webrtc/video/video_send_stream.h"
12 12
13 #include <algorithm> 13 #include <algorithm>
14 #include <sstream> 14 #include <sstream>
15 #include <string> 15 #include <string>
16 #include <vector> 16 #include <vector>
17 17
18 #include "webrtc/base/checks.h" 18 #include "webrtc/base/checks.h"
19 #include "webrtc/base/logging.h" 19 #include "webrtc/base/logging.h"
20 #include "webrtc/base/trace_event.h" 20 #include "webrtc/base/trace_event.h"
21 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" 21 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
22 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" 22 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h"
23 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" 23 #include "webrtc/modules/congestion_controller/include/congestion_controller.h"
24 #include "webrtc/modules/pacing/packet_router.h" 24 #include "webrtc/modules/pacing/packet_router.h"
25 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" 25 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
26 #include "webrtc/modules/utility/include/process_thread.h" 26 #include "webrtc/modules/utility/include/process_thread.h"
27 #include "webrtc/modules/video_coding/utility/ivf_file_writer.h"
27 #include "webrtc/video/call_stats.h" 28 #include "webrtc/video/call_stats.h"
28 #include "webrtc/video/video_capture_input.h" 29 #include "webrtc/video/video_capture_input.h"
29 #include "webrtc/video/vie_remb.h" 30 #include "webrtc/video/vie_remb.h"
30 #include "webrtc/video_send_stream.h" 31 #include "webrtc/video_send_stream.h"
31 32
32 namespace webrtc { 33 namespace webrtc {
33 34
34 class RtcpIntraFrameObserver; 35 class RtcpIntraFrameObserver;
35 class TransportFeedbackObserver; 36 class TransportFeedbackObserver;
36 37
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 encoder_thread_(EncoderThreadFunction, this, "EncoderThread"), 370 encoder_thread_(EncoderThreadFunction, this, "EncoderThread"),
370 encoder_wakeup_event_(false, false), 371 encoder_wakeup_event_(false, false),
371 stop_encoder_thread_(0), 372 stop_encoder_thread_(0),
372 overuse_detector_( 373 overuse_detector_(
373 Clock::GetRealTimeClock(), 374 Clock::GetRealTimeClock(),
374 GetCpuOveruseOptions(config.encoder_settings.full_overuse_time), 375 GetCpuOveruseOptions(config.encoder_settings.full_overuse_time),
375 this, 376 this,
376 config.post_encode_callback, 377 config.post_encode_callback,
377 &stats_proxy_), 378 &stats_proxy_),
378 vie_encoder_(num_cpu_cores, 379 vie_encoder_(num_cpu_cores,
379 config_.rtp.ssrcs,
380 module_process_thread_, 380 module_process_thread_,
381 &stats_proxy_, 381 &stats_proxy_,
382 &overuse_detector_), 382 &overuse_detector_),
383 encoder_feedback_(Clock::GetRealTimeClock(),
384 config.rtp.ssrcs,
385 &vie_encoder_),
383 video_sender_(vie_encoder_.video_sender()), 386 video_sender_(vie_encoder_.video_sender()),
384 bandwidth_observer_(congestion_controller_->GetBitrateController() 387 bandwidth_observer_(congestion_controller_->GetBitrateController()
385 ->CreateRtcpBandwidthObserver()), 388 ->CreateRtcpBandwidthObserver()),
386 rtp_rtcp_modules_(CreateRtpRtcpModules( 389 rtp_rtcp_modules_(CreateRtpRtcpModules(
387 config.send_transport, 390 config.send_transport,
388 &encoder_feedback_, 391 &encoder_feedback_,
389 bandwidth_observer_.get(), 392 bandwidth_observer_.get(),
390 congestion_controller_->GetTransportFeedbackObserver(), 393 congestion_controller_->GetTransportFeedbackObserver(),
391 call_stats_->rtcp_rtt_stats(), 394 call_stats_->rtcp_rtt_stats(),
392 congestion_controller_->pacer(), 395 congestion_controller_->pacer(),
393 congestion_controller_->packet_router(), 396 congestion_controller_->packet_router(),
394 &stats_proxy_, 397 &stats_proxy_,
395 send_delay_stats, 398 send_delay_stats,
396 config_.rtp.ssrcs.size())), 399 config_.rtp.ssrcs.size())),
397 payload_router_(rtp_rtcp_modules_, config.encoder_settings.payload_type), 400 payload_router_(rtp_rtcp_modules_, config.encoder_settings.payload_type),
398 input_(&encoder_wakeup_event_, 401 input_(&encoder_wakeup_event_,
399 config_.local_renderer, 402 config_.local_renderer,
400 &stats_proxy_, 403 &stats_proxy_,
401 &overuse_detector_) { 404 &overuse_detector_) {
402 LOG(LS_INFO) << "VideoSendStream: " << config_.ToString(); 405 LOG(LS_INFO) << "VideoSendStream: " << config_.ToString();
403 406
404 RTC_DCHECK(!config_.rtp.ssrcs.empty()); 407 RTC_DCHECK(!config_.rtp.ssrcs.empty());
405 RTC_DCHECK(module_process_thread_); 408 RTC_DCHECK(module_process_thread_);
406 RTC_DCHECK(call_stats_); 409 RTC_DCHECK(call_stats_);
407 RTC_DCHECK(congestion_controller_); 410 RTC_DCHECK(congestion_controller_);
408 RTC_DCHECK(remb_); 411 RTC_DCHECK(remb_);
409 412
410 encoder_feedback_.Init(config_.rtp.ssrcs, &vie_encoder_);
411 413
412 // RTP/RTCP initialization. 414 // RTP/RTCP initialization.
413 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { 415 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) {
414 module_process_thread_->RegisterModule(rtp_rtcp); 416 module_process_thread_->RegisterModule(rtp_rtcp);
415 congestion_controller_->packet_router()->AddRtpModule(rtp_rtcp); 417 congestion_controller_->packet_router()->AddRtpModule(rtp_rtcp);
416 } 418 }
417 419
418 video_sender_->RegisterProtectionCallback(this); 420 video_sender_->RegisterProtectionCallback(this);
419 421
420 for (size_t i = 0; i < config_.rtp.extensions.size(); ++i) { 422 for (size_t i = 0; i < config_.rtp.extensions.size(); ++i) {
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 encoder_settings->video_codec.startBitrate = 562 encoder_settings->video_codec.startBitrate =
561 bitrate_allocator_->AddObserver( 563 bitrate_allocator_->AddObserver(
562 this, encoder_settings->video_codec.minBitrate * 1000, 564 this, encoder_settings->video_codec.minBitrate * 1000,
563 encoder_settings->video_codec.maxBitrate * 1000) / 565 encoder_settings->video_codec.maxBitrate * 1000) /
564 1000; 566 1000;
565 567
566 payload_router_.SetSendStreams(encoder_settings->streams); 568 payload_router_.SetSendStreams(encoder_settings->streams);
567 vie_encoder_.SetEncoder(encoder_settings->video_codec, 569 vie_encoder_.SetEncoder(encoder_settings->video_codec,
568 encoder_settings->min_transmit_bitrate_bps, 570 encoder_settings->min_transmit_bitrate_bps,
569 payload_router_.MaxPayloadLength(), this); 571 payload_router_.MaxPayloadLength(), this);
572
573 // Clear stats for disabled layers.
574 for (size_t i = encoder_settings->streams.size();
575 i < config_.rtp.ssrcs.size(); ++i) {
576 stats_proxy_.OnInactiveSsrc(config_.rtp.ssrcs[i]);
577 }
578
570 if (config_.suspend_below_min_bitrate) { 579 if (config_.suspend_below_min_bitrate) {
571 video_sender_->SuspendBelowMinBitrate(); 580 video_sender_->SuspendBelowMinBitrate();
572 bitrate_allocator_->EnforceMinBitrate(false); 581 bitrate_allocator_->EnforceMinBitrate(false);
573 } 582 }
574 // We might've gotten new settings while configuring the encoder settings, 583 // We might've gotten new settings while configuring the encoder settings,
575 // restart from the top to see if that's the case before trying to encode 584 // restart from the top to see if that's the case before trying to encode
576 // a frame (which might correspond to the last frame size). 585 // a frame (which might correspond to the last frame size).
577 encoder_wakeup_event_.Set(); 586 encoder_wakeup_event_.Set();
578 continue; 587 continue;
579 } 588 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 if (config_.overuse_callback) 629 if (config_.overuse_callback)
621 config_.overuse_callback->OnLoadUpdate(LoadObserver::kUnderuse); 630 config_.overuse_callback->OnLoadUpdate(LoadObserver::kUnderuse);
622 } 631 }
623 632
624 int32_t VideoSendStream::Encoded(const EncodedImage& encoded_image, 633 int32_t VideoSendStream::Encoded(const EncodedImage& encoded_image,
625 const CodecSpecificInfo* codec_specific_info, 634 const CodecSpecificInfo* codec_specific_info,
626 const RTPFragmentationHeader* fragmentation) { 635 const RTPFragmentationHeader* fragmentation) {
627 // |encoded_frame_proxy_| forwards frames to |config_.post_encode_callback|; 636 // |encoded_frame_proxy_| forwards frames to |config_.post_encode_callback|;
628 encoded_frame_proxy_.Encoded(encoded_image, codec_specific_info, 637 encoded_frame_proxy_.Encoded(encoded_image, codec_specific_info,
629 fragmentation); 638 fragmentation);
630 return payload_router_.Encoded(encoded_image, codec_specific_info, 639 int32_t return_value = payload_router_.Encoded(
631 fragmentation); 640 encoded_image, codec_specific_info, fragmentation);
641
642 if (kEnableFrameRecording) {
643 int layer = codec_specific_info->codecType == kVideoCodecVP8
644 ? codec_specific_info->codecSpecific.VP8.simulcastIdx
645 : 0;
646 IvfFileWriter* file_writer;
647 {
648 if (file_writers_[layer] == nullptr) {
649 std::ostringstream oss;
650 oss << "send_bitstream_ssrc";
651 for (uint32_t ssrc : config_.rtp.ssrcs)
652 oss << "_" << ssrc;
653 oss << "_layer" << layer << ".ivf";
654 file_writers_[layer] =
655 IvfFileWriter::Open(oss.str(), codec_specific_info->codecType);
656 }
657 file_writer = file_writers_[layer].get();
658 }
659 if (file_writer) {
660 bool ok = file_writer->WriteFrame(encoded_image);
661 RTC_DCHECK(ok);
662 }
663 }
664
665 return return_value;
632 } 666 }
633 667
634 void VideoSendStream::ConfigureProtection() { 668 void VideoSendStream::ConfigureProtection() {
635 // Enable NACK, FEC or both. 669 // Enable NACK, FEC or both.
636 const bool enable_protection_nack = config_.rtp.nack.rtp_history_ms > 0; 670 const bool enable_protection_nack = config_.rtp.nack.rtp_history_ms > 0;
637 bool enable_protection_fec = config_.rtp.fec.red_payload_type != -1; 671 bool enable_protection_fec = config_.rtp.fec.red_payload_type != -1;
638 // Payload types without picture ID cannot determine that a stream is complete 672 // Payload types without picture ID cannot determine that a stream is complete
639 // without retransmitting FEC, so using FEC + NACK for H.264 (for instance) is 673 // without retransmitting FEC, so using FEC + NACK for H.264 (for instance) is
640 // a waste of bandwidth since FEC packets still have to be transmitted. Note 674 // a waste of bandwidth since FEC packets still have to be transmitted. Note
641 // that this is not the case with FLEXFEC. 675 // that this is not the case with FLEXFEC.
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 &module_nack_rate); 808 &module_nack_rate);
775 *sent_video_rate_bps += module_video_rate; 809 *sent_video_rate_bps += module_video_rate;
776 *sent_nack_rate_bps += module_nack_rate; 810 *sent_nack_rate_bps += module_nack_rate;
777 *sent_fec_rate_bps += module_fec_rate; 811 *sent_fec_rate_bps += module_fec_rate;
778 } 812 }
779 return 0; 813 return 0;
780 } 814 }
781 815
782 } // namespace internal 816 } // namespace internal
783 } // namespace webrtc 817 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/video_send_stream.h ('k') | webrtc/video/vie_encoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698