OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 976 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
987 | 987 |
988 rtc::CritScope stream_lock(&stream_crit_); | 988 rtc::CritScope stream_lock(&stream_crit_); |
989 | 989 |
990 if (!ValidateSendSsrcAvailability(sp)) | 990 if (!ValidateSendSsrcAvailability(sp)) |
991 return false; | 991 return false; |
992 | 992 |
993 for (uint32_t used_ssrc : sp.ssrcs) | 993 for (uint32_t used_ssrc : sp.ssrcs) |
994 send_ssrcs_.insert(used_ssrc); | 994 send_ssrcs_.insert(used_ssrc); |
995 | 995 |
996 webrtc::VideoSendStream::Config config(this); | 996 webrtc::VideoSendStream::Config config(this); |
997 config.overuse_callback = this; | |
998 | |
999 WebRtcVideoSendStream* stream = new WebRtcVideoSendStream( | 997 WebRtcVideoSendStream* stream = new WebRtcVideoSendStream( |
1000 call_, sp, config, external_encoder_factory_, options_, | 998 call_, sp, config, external_encoder_factory_, options_, |
1001 bitrate_config_.max_bitrate_bps, send_codec_, send_rtp_extensions_, | 999 signal_cpu_adaptation_, bitrate_config_.max_bitrate_bps, send_codec_, |
1002 send_params_); | 1000 send_rtp_extensions_, send_params_); |
1003 | |
1004 uint32_t ssrc = sp.first_ssrc(); | 1001 uint32_t ssrc = sp.first_ssrc(); |
1005 RTC_DCHECK(ssrc != 0); | 1002 RTC_DCHECK(ssrc != 0); |
1006 send_streams_[ssrc] = stream; | 1003 send_streams_[ssrc] = stream; |
1007 | 1004 |
1008 if (rtcp_receiver_report_ssrc_ == kDefaultRtcpReceiverReportSsrc) { | 1005 if (rtcp_receiver_report_ssrc_ == kDefaultRtcpReceiverReportSsrc) { |
1009 rtcp_receiver_report_ssrc_ = ssrc; | 1006 rtcp_receiver_report_ssrc_ = ssrc; |
1010 LOG(LS_INFO) << "SetLocalSsrc on all the receive streams because we added " | 1007 LOG(LS_INFO) << "SetLocalSsrc on all the receive streams because we added " |
1011 "a send stream."; | 1008 "a send stream."; |
1012 for (auto& kv : receive_streams_) | 1009 for (auto& kv : receive_streams_) |
1013 kv.second->SetLocalSsrc(ssrc); | 1010 kv.second->SetLocalSsrc(ssrc); |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1391 | 1388 |
1392 // Speculative change to increase the outbound socket buffer size. | 1389 // Speculative change to increase the outbound socket buffer size. |
1393 // In b/15152257, we are seeing a significant number of packets discarded | 1390 // In b/15152257, we are seeing a significant number of packets discarded |
1394 // due to lack of socket buffer space, although it's not yet clear what the | 1391 // due to lack of socket buffer space, although it's not yet clear what the |
1395 // ideal value should be. | 1392 // ideal value should be. |
1396 MediaChannel::SetOption(NetworkInterface::ST_RTP, | 1393 MediaChannel::SetOption(NetworkInterface::ST_RTP, |
1397 rtc::Socket::OPT_SNDBUF, | 1394 rtc::Socket::OPT_SNDBUF, |
1398 kVideoRtpBufferSize); | 1395 kVideoRtpBufferSize); |
1399 } | 1396 } |
1400 | 1397 |
1401 void WebRtcVideoChannel2::OnLoadUpdate(Load load) { | |
1402 // OnLoadUpdate can not take any locks that are held while creating streams | |
1403 // etc. Doing so establishes lock-order inversions between the webrtc process | |
1404 // thread on stream creation and locks such as stream_crit_ while calling out. | |
1405 rtc::CritScope stream_lock(&capturer_crit_); | |
1406 if (!signal_cpu_adaptation_) | |
1407 return; | |
1408 // Do not adapt resolution for screen content as this will likely result in | |
1409 // blurry and unreadable text. | |
1410 for (auto& kv : capturers_) { | |
1411 if (kv.second != nullptr | |
1412 && !kv.second->IsScreencast() | |
1413 && kv.second->video_adapter() != nullptr) { | |
1414 kv.second->video_adapter()->OnCpuResolutionRequest( | |
1415 load == kOveruse ? CoordinatedVideoAdapter::DOWNGRADE | |
1416 : CoordinatedVideoAdapter::UPGRADE); | |
1417 } | |
1418 } | |
1419 } | |
1420 | |
1421 bool WebRtcVideoChannel2::SendRtp(const uint8_t* data, | 1398 bool WebRtcVideoChannel2::SendRtp(const uint8_t* data, |
1422 size_t len, | 1399 size_t len, |
1423 const webrtc::PacketOptions& options) { | 1400 const webrtc::PacketOptions& options) { |
1424 rtc::Buffer packet(data, len, kMaxRtpPacketLen); | 1401 rtc::Buffer packet(data, len, kMaxRtpPacketLen); |
1425 rtc::PacketOptions rtc_options; | 1402 rtc::PacketOptions rtc_options; |
1426 rtc_options.packet_id = options.packet_id; | 1403 rtc_options.packet_id = options.packet_id; |
1427 return MediaChannel::SendPacket(&packet, rtc_options); | 1404 return MediaChannel::SendPacket(&packet, rtc_options); |
1428 } | 1405 } |
1429 | 1406 |
1430 bool WebRtcVideoChannel2::SendRtcp(const uint8_t* data, size_t len) { | 1407 bool WebRtcVideoChannel2::SendRtcp(const uint8_t* data, size_t len) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1475 new webrtc::VideoEncoderSoftwareFallbackWrapper(type, encoder); | 1452 new webrtc::VideoEncoderSoftwareFallbackWrapper(type, encoder); |
1476 } | 1453 } |
1477 } | 1454 } |
1478 | 1455 |
1479 WebRtcVideoChannel2::WebRtcVideoSendStream::WebRtcVideoSendStream( | 1456 WebRtcVideoChannel2::WebRtcVideoSendStream::WebRtcVideoSendStream( |
1480 webrtc::Call* call, | 1457 webrtc::Call* call, |
1481 const StreamParams& sp, | 1458 const StreamParams& sp, |
1482 const webrtc::VideoSendStream::Config& config, | 1459 const webrtc::VideoSendStream::Config& config, |
1483 WebRtcVideoEncoderFactory* external_encoder_factory, | 1460 WebRtcVideoEncoderFactory* external_encoder_factory, |
1484 const VideoOptions& options, | 1461 const VideoOptions& options, |
| 1462 bool enable_cpu_overuse_detection, |
1485 int max_bitrate_bps, | 1463 int max_bitrate_bps, |
1486 const rtc::Optional<VideoCodecSettings>& codec_settings, | 1464 const rtc::Optional<VideoCodecSettings>& codec_settings, |
1487 const std::vector<webrtc::RtpExtension>& rtp_extensions, | 1465 const std::vector<webrtc::RtpExtension>& rtp_extensions, |
1488 // TODO(deadbeef): Don't duplicate information between send_params, | 1466 // TODO(deadbeef): Don't duplicate information between send_params, |
1489 // rtp_extensions, options, etc. | 1467 // rtp_extensions, options, etc. |
1490 const VideoSendParameters& send_params) | 1468 const VideoSendParameters& send_params) |
1491 : ssrcs_(sp.ssrcs), | 1469 : ssrcs_(sp.ssrcs), |
1492 ssrc_groups_(sp.ssrc_groups), | 1470 ssrc_groups_(sp.ssrc_groups), |
1493 call_(call), | 1471 call_(call), |
| 1472 load_proxy_(this), |
1494 external_encoder_factory_(external_encoder_factory), | 1473 external_encoder_factory_(external_encoder_factory), |
1495 stream_(NULL), | 1474 stream_(NULL), |
1496 parameters_(config, options, max_bitrate_bps, codec_settings), | 1475 parameters_(config, options, max_bitrate_bps, codec_settings), |
1497 pending_encoder_reconfiguration_(false), | 1476 pending_encoder_reconfiguration_(false), |
1498 allocated_encoder_(NULL, webrtc::kVideoCodecUnknown, false), | 1477 allocated_encoder_(NULL, webrtc::kVideoCodecUnknown, false), |
1499 capturer_(NULL), | 1478 capturer_(NULL), |
1500 sending_(false), | 1479 sending_(false), |
1501 muted_(false), | 1480 muted_(false), |
1502 old_adapt_changes_(0), | 1481 old_adapt_changes_(0), |
1503 first_frame_timestamp_ms_(0), | 1482 first_frame_timestamp_ms_(0), |
1504 last_frame_timestamp_ms_(0) { | 1483 last_frame_timestamp_ms_(0) { |
1505 parameters_.config.rtp.max_packet_size = kVideoMtu; | 1484 parameters_.config.rtp.max_packet_size = kVideoMtu; |
1506 | 1485 |
1507 sp.GetPrimarySsrcs(¶meters_.config.rtp.ssrcs); | 1486 sp.GetPrimarySsrcs(¶meters_.config.rtp.ssrcs); |
1508 sp.GetFidSsrcs(parameters_.config.rtp.ssrcs, | 1487 sp.GetFidSsrcs(parameters_.config.rtp.ssrcs, |
1509 ¶meters_.config.rtp.rtx.ssrcs); | 1488 ¶meters_.config.rtp.rtx.ssrcs); |
1510 parameters_.config.rtp.c_name = sp.cname; | 1489 parameters_.config.rtp.c_name = sp.cname; |
1511 parameters_.config.rtp.extensions = rtp_extensions; | 1490 parameters_.config.rtp.extensions = rtp_extensions; |
1512 parameters_.config.rtp.rtcp_mode = send_params.rtcp.reduced_size | 1491 parameters_.config.rtp.rtcp_mode = send_params.rtcp.reduced_size |
1513 ? webrtc::RtcpMode::kReducedSize | 1492 ? webrtc::RtcpMode::kReducedSize |
1514 : webrtc::RtcpMode::kCompound; | 1493 : webrtc::RtcpMode::kCompound; |
| 1494 parameters_.config.overuse_callback = |
| 1495 enable_cpu_overuse_detection ? load_proxy_.proxy() : nullptr; |
1515 | 1496 |
1516 if (codec_settings) { | 1497 if (codec_settings) { |
1517 SetCodecAndOptions(*codec_settings, parameters_.options); | 1498 SetCodecAndOptions(*codec_settings, parameters_.options); |
1518 } | 1499 } |
1519 } | 1500 } |
1520 | 1501 |
1521 WebRtcVideoChannel2::WebRtcVideoSendStream::~WebRtcVideoSendStream() { | 1502 WebRtcVideoChannel2::WebRtcVideoSendStream::~WebRtcVideoSendStream() { |
1522 DisconnectCapturer(); | 1503 DisconnectCapturer(); |
1523 if (stream_ != NULL) { | 1504 if (stream_ != NULL) { |
1524 call_->DestroyVideoSendStream(stream_); | 1505 call_->DestroyVideoSendStream(stream_); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1628 muted_ = mute; | 1609 muted_ = mute; |
1629 } | 1610 } |
1630 | 1611 |
1631 bool WebRtcVideoChannel2::WebRtcVideoSendStream::DisconnectCapturer() { | 1612 bool WebRtcVideoChannel2::WebRtcVideoSendStream::DisconnectCapturer() { |
1632 cricket::VideoCapturer* capturer; | 1613 cricket::VideoCapturer* capturer; |
1633 { | 1614 { |
1634 rtc::CritScope cs(&lock_); | 1615 rtc::CritScope cs(&lock_); |
1635 if (capturer_ == NULL) | 1616 if (capturer_ == NULL) |
1636 return false; | 1617 return false; |
1637 | 1618 |
1638 if (capturer_->video_adapter() != nullptr) | |
1639 old_adapt_changes_ += capturer_->video_adapter()->adaptation_changes(); | |
1640 | |
1641 capturer = capturer_; | 1619 capturer = capturer_; |
1642 capturer_ = NULL; | 1620 capturer_ = NULL; |
1643 } | 1621 } |
1644 capturer->RemoveSink(this); | 1622 capturer->RemoveSink(this); |
1645 | 1623 |
1646 return true; | 1624 return true; |
1647 } | 1625 } |
1648 | 1626 |
1649 const std::vector<uint32_t>& | 1627 const std::vector<uint32_t>& |
1650 WebRtcVideoChannel2::WebRtcVideoSendStream::GetSsrcs() const { | 1628 WebRtcVideoChannel2::WebRtcVideoSendStream::GetSsrcs() const { |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1922 } | 1900 } |
1923 | 1901 |
1924 void WebRtcVideoChannel2::WebRtcVideoSendStream::Stop() { | 1902 void WebRtcVideoChannel2::WebRtcVideoSendStream::Stop() { |
1925 rtc::CritScope cs(&lock_); | 1903 rtc::CritScope cs(&lock_); |
1926 if (stream_ != NULL) { | 1904 if (stream_ != NULL) { |
1927 stream_->Stop(); | 1905 stream_->Stop(); |
1928 } | 1906 } |
1929 sending_ = false; | 1907 sending_ = false; |
1930 } | 1908 } |
1931 | 1909 |
| 1910 void WebRtcVideoChannel2::WebRtcVideoSendStream::OnLoadUpdate(Load load) { |
| 1911 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 1912 LOG(LS_INFO) << "OnLoadUpdate " << load; |
| 1913 if (!capturer_) |
| 1914 return; |
| 1915 sink_wants_.resolution_request.change = |
| 1916 load == kOveruse ? rtc::VideoSinkWants::ResolutionRequest::DOWN |
| 1917 : rtc::VideoSinkWants::ResolutionRequest::UP; |
| 1918 { |
| 1919 rtc::CritScope cs(&lock_); |
| 1920 // TODO(perkj): Resolution should be included as argument in OnLoadUpdate. |
| 1921 sink_wants_.resolution_request.from_height = last_dimensions_.height; |
| 1922 sink_wants_.resolution_request.from_width = last_dimensions_.width; |
| 1923 } |
| 1924 capturer_->AddOrUpdateSink(this, sink_wants_); |
| 1925 } |
| 1926 |
1932 VideoSenderInfo | 1927 VideoSenderInfo |
1933 WebRtcVideoChannel2::WebRtcVideoSendStream::GetVideoSenderInfo() { | 1928 WebRtcVideoChannel2::WebRtcVideoSendStream::GetVideoSenderInfo() { |
1934 VideoSenderInfo info; | 1929 VideoSenderInfo info; |
1935 webrtc::VideoSendStream::Stats stats; | 1930 webrtc::VideoSendStream::Stats stats; |
1936 { | 1931 { |
1937 rtc::CritScope cs(&lock_); | 1932 rtc::CritScope cs(&lock_); |
1938 for (uint32_t ssrc : parameters_.config.rtp.ssrcs) | 1933 for (uint32_t ssrc : parameters_.config.rtp.ssrcs) |
1939 info.add_ssrc(ssrc); | 1934 info.add_ssrc(ssrc); |
1940 | 1935 |
1941 if (parameters_.codec_settings) | 1936 if (parameters_.codec_settings) |
(...skipping 18 matching lines...) Expand all Loading... |
1960 | 1955 |
1961 if (capturer_ != NULL) { | 1956 if (capturer_ != NULL) { |
1962 if (!capturer_->IsMuted()) { | 1957 if (!capturer_->IsMuted()) { |
1963 VideoFormat last_captured_frame_format; | 1958 VideoFormat last_captured_frame_format; |
1964 capturer_->GetStats(&info.adapt_frame_drops, &info.effects_frame_drops, | 1959 capturer_->GetStats(&info.adapt_frame_drops, &info.effects_frame_drops, |
1965 &info.capturer_frame_time, | 1960 &info.capturer_frame_time, |
1966 &last_captured_frame_format); | 1961 &last_captured_frame_format); |
1967 info.input_frame_width = last_captured_frame_format.width; | 1962 info.input_frame_width = last_captured_frame_format.width; |
1968 info.input_frame_height = last_captured_frame_format.height; | 1963 info.input_frame_height = last_captured_frame_format.height; |
1969 } | 1964 } |
1970 if (capturer_->video_adapter() != nullptr) { | |
1971 info.adapt_changes += capturer_->video_adapter()->adaptation_changes(); | |
1972 info.adapt_reason = capturer_->video_adapter()->adapt_reason(); | |
1973 } | |
1974 } | 1965 } |
1975 } | 1966 } |
1976 | 1967 |
1977 // Get bandwidth limitation info from stream_->GetStats(). | 1968 // Get bandwidth limitation info from stream_->GetStats(). |
1978 // Input resolution (output from video_adapter) can be further scaled down or | 1969 // Input resolution (output from video_adapter) can be further scaled down or |
1979 // higher video layer(s) can be dropped due to bitrate constraints. | 1970 // higher video layer(s) can be dropped due to bitrate constraints. |
1980 // Note, adapt_changes only include changes from the video_adapter. | 1971 // Note, adapt_changes only include changes from the video_adapter. |
1981 if (stats.bw_limited_resolution) | 1972 if (stats.bw_limited_resolution) |
1982 info.adapt_reason |= CoordinatedVideoAdapter::ADAPTREASON_BANDWIDTH; | 1973 info.adapt_reason |= CoordinatedVideoAdapter::ADAPTREASON_BANDWIDTH; |
1983 | 1974 |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2483 rtx_mapping[video_codecs[i].codec.id] != | 2474 rtx_mapping[video_codecs[i].codec.id] != |
2484 fec_settings.red_payload_type) { | 2475 fec_settings.red_payload_type) { |
2485 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; | 2476 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; |
2486 } | 2477 } |
2487 } | 2478 } |
2488 | 2479 |
2489 return video_codecs; | 2480 return video_codecs; |
2490 } | 2481 } |
2491 | 2482 |
2492 } // namespace cricket | 2483 } // namespace cricket |
OLD | NEW |