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 |
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 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
366 encoder_thread_(EncoderThreadFunction, this, "EncoderThread"), | 367 encoder_thread_(EncoderThreadFunction, this, "EncoderThread"), |
367 encoder_wakeup_event_(false, false), | 368 encoder_wakeup_event_(false, false), |
368 stop_encoder_thread_(0), | 369 stop_encoder_thread_(0), |
369 overuse_detector_( | 370 overuse_detector_( |
370 Clock::GetRealTimeClock(), | 371 Clock::GetRealTimeClock(), |
371 GetCpuOveruseOptions(config.encoder_settings.full_overuse_time), | 372 GetCpuOveruseOptions(config.encoder_settings.full_overuse_time), |
372 this, | 373 this, |
373 config.post_encode_callback, | 374 config.post_encode_callback, |
374 &stats_proxy_), | 375 &stats_proxy_), |
375 vie_encoder_(num_cpu_cores, | 376 vie_encoder_(num_cpu_cores, |
376 config_.rtp.ssrcs, | |
377 module_process_thread_, | 377 module_process_thread_, |
378 &stats_proxy_, | 378 &stats_proxy_, |
379 config.pre_encode_callback, | 379 config.pre_encode_callback, |
380 &overuse_detector_, | 380 &overuse_detector_, |
381 congestion_controller_->pacer()), | 381 congestion_controller_->pacer()), |
382 video_sender_(vie_encoder_.video_sender()), | 382 video_sender_(vie_encoder_.video_sender()), |
383 bandwidth_observer_(congestion_controller_->GetBitrateController() | 383 bandwidth_observer_(congestion_controller_->GetBitrateController() |
384 ->CreateRtcpBandwidthObserver()), | 384 ->CreateRtcpBandwidthObserver()), |
385 rtp_rtcp_modules_(CreateRtpRtcpModules( | 385 rtp_rtcp_modules_(CreateRtpRtcpModules( |
386 config.send_transport, | 386 config.send_transport, |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
538 encoder_settings->video_codec.startBitrate = | 538 encoder_settings->video_codec.startBitrate = |
539 bitrate_allocator_->AddObserver( | 539 bitrate_allocator_->AddObserver( |
540 this, encoder_settings->video_codec.minBitrate * 1000, | 540 this, encoder_settings->video_codec.minBitrate * 1000, |
541 encoder_settings->video_codec.maxBitrate * 1000) / | 541 encoder_settings->video_codec.maxBitrate * 1000) / |
542 1000; | 542 1000; |
543 | 543 |
544 payload_router_.SetSendStreams(encoder_settings->streams); | 544 payload_router_.SetSendStreams(encoder_settings->streams); |
545 vie_encoder_.SetEncoder(encoder_settings->video_codec, | 545 vie_encoder_.SetEncoder(encoder_settings->video_codec, |
546 encoder_settings->min_transmit_bitrate_bps, | 546 encoder_settings->min_transmit_bitrate_bps, |
547 payload_router_.MaxPayloadLength(), this); | 547 payload_router_.MaxPayloadLength(), this); |
548 | |
549 // Clear stats for disabled layers. | |
550 for (size_t i = encoder_settings->streams.size(); | |
551 i < config_.rtp.ssrcs.size(); ++i) { | |
552 stats_proxy_.OnInactiveSsrc(config_.rtp.ssrcs[i]); | |
553 } | |
554 | |
548 if (config_.suspend_below_min_bitrate) { | 555 if (config_.suspend_below_min_bitrate) { |
549 video_sender_->SuspendBelowMinBitrate(); | 556 video_sender_->SuspendBelowMinBitrate(); |
550 bitrate_allocator_->EnforceMinBitrate(false); | 557 bitrate_allocator_->EnforceMinBitrate(false); |
551 } | 558 } |
552 // We might've gotten new settings while configuring the encoder settings, | 559 // We might've gotten new settings while configuring the encoder settings, |
553 // restart from the top to see if that's the case before trying to encode | 560 // restart from the top to see if that's the case before trying to encode |
554 // a frame (which might correspond to the last frame size). | 561 // a frame (which might correspond to the last frame size). |
555 encoder_wakeup_event_.Set(); | 562 encoder_wakeup_event_.Set(); |
556 continue; | 563 continue; |
557 } | 564 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
598 if (config_.overuse_callback) | 605 if (config_.overuse_callback) |
599 config_.overuse_callback->OnLoadUpdate(LoadObserver::kUnderuse); | 606 config_.overuse_callback->OnLoadUpdate(LoadObserver::kUnderuse); |
600 } | 607 } |
601 | 608 |
602 int32_t VideoSendStream::Encoded(const EncodedImage& encoded_image, | 609 int32_t VideoSendStream::Encoded(const EncodedImage& encoded_image, |
603 const CodecSpecificInfo* codec_specific_info, | 610 const CodecSpecificInfo* codec_specific_info, |
604 const RTPFragmentationHeader* fragmentation) { | 611 const RTPFragmentationHeader* fragmentation) { |
605 // |encoded_frame_proxy_| forwards frames to |config_.post_encode_callback|; | 612 // |encoded_frame_proxy_| forwards frames to |config_.post_encode_callback|; |
606 encoded_frame_proxy_.Encoded(encoded_image, codec_specific_info, | 613 encoded_frame_proxy_.Encoded(encoded_image, codec_specific_info, |
607 fragmentation); | 614 fragmentation); |
608 return payload_router_.Encoded(encoded_image, codec_specific_info, | 615 bool return_value = payload_router_.Encoded( |
pbos-webrtc
2016/05/02 01:06:46
eh, no, this should be int32_t, ignore comment bel
perkj_webrtc
2016/05/03 10:22:40
Done.
| |
609 fragmentation); | 616 encoded_image, codec_specific_info, fragmentation); |
pbos-webrtc
2016/05/02 01:06:11
== 0
| |
617 | |
618 if (kEnableFrameRecording) { | |
619 int layer = codec_specific_info->codecType == kVideoCodecVP8 | |
620 ? codec_specific_info->codecSpecific.VP8.simulcastIdx | |
621 : 0; | |
622 IvfFileWriter* file_writer; | |
623 { | |
624 if (file_writers_[layer] == nullptr) { | |
625 std::ostringstream oss; | |
626 oss << "send_bitstream_ssrc"; | |
627 for (uint32_t ssrc : config_.rtp.ssrcs) | |
628 oss << "_" << ssrc; | |
629 oss << "_layer" << layer << ".ivf"; | |
630 file_writers_[layer] = | |
631 IvfFileWriter::Open(oss.str(), codec_specific_info->codecType); | |
632 } | |
633 file_writer = file_writers_[layer].get(); | |
634 } | |
635 if (file_writer) { | |
636 bool ok = file_writer->WriteFrame(encoded_image); | |
637 RTC_DCHECK(ok); | |
638 } | |
639 } | |
640 | |
641 return return_value; | |
610 } | 642 } |
611 | 643 |
612 void VideoSendStream::ConfigureProtection() { | 644 void VideoSendStream::ConfigureProtection() { |
613 // Enable NACK, FEC or both. | 645 // Enable NACK, FEC or both. |
614 const bool enable_protection_nack = config_.rtp.nack.rtp_history_ms > 0; | 646 const bool enable_protection_nack = config_.rtp.nack.rtp_history_ms > 0; |
615 bool enable_protection_fec = config_.rtp.fec.red_payload_type != -1; | 647 bool enable_protection_fec = config_.rtp.fec.red_payload_type != -1; |
616 // Payload types without picture ID cannot determine that a stream is complete | 648 // Payload types without picture ID cannot determine that a stream is complete |
617 // without retransmitting FEC, so using FEC + NACK for H.264 (for instance) is | 649 // without retransmitting FEC, so using FEC + NACK for H.264 (for instance) is |
618 // a waste of bandwidth since FEC packets still have to be transmitted. Note | 650 // a waste of bandwidth since FEC packets still have to be transmitted. Note |
619 // that this is not the case with FLEXFEC. | 651 // that this is not the case with FLEXFEC. |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
767 &module_nack_rate); | 799 &module_nack_rate); |
768 *sent_video_rate_bps += module_video_rate; | 800 *sent_video_rate_bps += module_video_rate; |
769 *sent_nack_rate_bps += module_nack_rate; | 801 *sent_nack_rate_bps += module_nack_rate; |
770 *sent_fec_rate_bps += module_fec_rate; | 802 *sent_fec_rate_bps += module_fec_rate; |
771 } | 803 } |
772 return 0; | 804 return 0; |
773 } | 805 } |
774 | 806 |
775 } // namespace internal | 807 } // namespace internal |
776 } // namespace webrtc | 808 } // namespace webrtc |
OLD | NEW |