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 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 if (width * height <= 320 * 240) { | 307 if (width * height <= 320 * 240) { |
308 return 600; | 308 return 600; |
309 } else if (width * height <= 640 * 480) { | 309 } else if (width * height <= 640 * 480) { |
310 return 1700; | 310 return 1700; |
311 } else if (width * height <= 960 * 540) { | 311 } else if (width * height <= 960 * 540) { |
312 return 2000; | 312 return 2000; |
313 } else { | 313 } else { |
314 return 2500; | 314 return 2500; |
315 } | 315 } |
316 } | 316 } |
| 317 |
317 } // namespace | 318 } // namespace |
318 | 319 |
319 // Constants defined in webrtc/media/engine/constants.h | 320 // Constants defined in webrtc/media/engine/constants.h |
320 // TODO(pbos): Move these to a separate constants.cc file. | 321 // TODO(pbos): Move these to a separate constants.cc file. |
321 const int kMinVideoBitrate = 30; | 322 const int kMinVideoBitrate = 30; |
322 const int kStartVideoBitrate = 300; | 323 const int kStartVideoBitrate = 300; |
323 | 324 |
324 const int kVideoMtu = 1200; | 325 const int kVideoMtu = 1200; |
325 const int kVideoRtpBufferSize = 65536; | 326 const int kVideoRtpBufferSize = 65536; |
326 | 327 |
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
993 | 994 |
994 rtc::CritScope stream_lock(&stream_crit_); | 995 rtc::CritScope stream_lock(&stream_crit_); |
995 | 996 |
996 if (!ValidateSendSsrcAvailability(sp)) | 997 if (!ValidateSendSsrcAvailability(sp)) |
997 return false; | 998 return false; |
998 | 999 |
999 for (uint32_t used_ssrc : sp.ssrcs) | 1000 for (uint32_t used_ssrc : sp.ssrcs) |
1000 send_ssrcs_.insert(used_ssrc); | 1001 send_ssrcs_.insert(used_ssrc); |
1001 | 1002 |
1002 webrtc::VideoSendStream::Config config(this); | 1003 webrtc::VideoSendStream::Config config(this); |
1003 config.overuse_callback = this; | 1004 WebRtcVideoSendStream* stream = new WebRtcVideoSendStream( |
1004 | 1005 call_, sp, config, external_encoder_factory_, signal_cpu_adaptation_, |
1005 WebRtcVideoSendStream* stream = | 1006 bitrate_config_.max_bitrate_bps, send_codec_, send_rtp_extensions_, |
1006 new WebRtcVideoSendStream(call_, sp, config, external_encoder_factory_, | 1007 send_params_); |
1007 bitrate_config_.max_bitrate_bps, send_codec_, | |
1008 send_rtp_extensions_, send_params_); | |
1009 | 1008 |
1010 uint32_t ssrc = sp.first_ssrc(); | 1009 uint32_t ssrc = sp.first_ssrc(); |
1011 RTC_DCHECK(ssrc != 0); | 1010 RTC_DCHECK(ssrc != 0); |
1012 send_streams_[ssrc] = stream; | 1011 send_streams_[ssrc] = stream; |
1013 | 1012 |
1014 if (rtcp_receiver_report_ssrc_ == kDefaultRtcpReceiverReportSsrc) { | 1013 if (rtcp_receiver_report_ssrc_ == kDefaultRtcpReceiverReportSsrc) { |
1015 rtcp_receiver_report_ssrc_ = ssrc; | 1014 rtcp_receiver_report_ssrc_ = ssrc; |
1016 LOG(LS_INFO) << "SetLocalSsrc on all the receive streams because we added " | 1015 LOG(LS_INFO) << "SetLocalSsrc on all the receive streams because we added " |
1017 "a send stream."; | 1016 "a send stream."; |
1018 for (auto& kv : receive_streams_) | 1017 for (auto& kv : receive_streams_) |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1276 rtc::CritScope stream_lock(&stream_crit_); | 1275 rtc::CritScope stream_lock(&stream_crit_); |
1277 const auto& kv = send_streams_.find(ssrc); | 1276 const auto& kv = send_streams_.find(ssrc); |
1278 if (kv == send_streams_.end()) { | 1277 if (kv == send_streams_.end()) { |
1279 LOG(LS_ERROR) << "No sending stream on ssrc " << ssrc; | 1278 LOG(LS_ERROR) << "No sending stream on ssrc " << ssrc; |
1280 return false; | 1279 return false; |
1281 } | 1280 } |
1282 if (!kv->second->SetCapturer(capturer)) { | 1281 if (!kv->second->SetCapturer(capturer)) { |
1283 return false; | 1282 return false; |
1284 } | 1283 } |
1285 } | 1284 } |
1286 { | |
1287 rtc::CritScope lock(&capturer_crit_); | |
1288 capturers_[ssrc] = capturer; | |
1289 } | |
1290 return true; | 1285 return true; |
1291 } | 1286 } |
1292 | 1287 |
1293 void WebRtcVideoChannel2::OnPacketReceived( | 1288 void WebRtcVideoChannel2::OnPacketReceived( |
1294 rtc::Buffer* packet, | 1289 rtc::Buffer* packet, |
1295 const rtc::PacketTime& packet_time) { | 1290 const rtc::PacketTime& packet_time) { |
1296 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp, | 1291 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp, |
1297 packet_time.not_before); | 1292 packet_time.not_before); |
1298 const webrtc::PacketReceiver::DeliveryStatus delivery_result = | 1293 const webrtc::PacketReceiver::DeliveryStatus delivery_result = |
1299 call_->Receiver()->DeliverPacket( | 1294 call_->Receiver()->DeliverPacket( |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1405 | 1400 |
1406 // Speculative change to increase the outbound socket buffer size. | 1401 // Speculative change to increase the outbound socket buffer size. |
1407 // In b/15152257, we are seeing a significant number of packets discarded | 1402 // In b/15152257, we are seeing a significant number of packets discarded |
1408 // due to lack of socket buffer space, although it's not yet clear what the | 1403 // due to lack of socket buffer space, although it's not yet clear what the |
1409 // ideal value should be. | 1404 // ideal value should be. |
1410 MediaChannel::SetOption(NetworkInterface::ST_RTP, | 1405 MediaChannel::SetOption(NetworkInterface::ST_RTP, |
1411 rtc::Socket::OPT_SNDBUF, | 1406 rtc::Socket::OPT_SNDBUF, |
1412 kVideoRtpBufferSize); | 1407 kVideoRtpBufferSize); |
1413 } | 1408 } |
1414 | 1409 |
1415 void WebRtcVideoChannel2::OnLoadUpdate(Load load) { | |
1416 // OnLoadUpdate can not take any locks that are held while creating streams | |
1417 // etc. Doing so establishes lock-order inversions between the webrtc process | |
1418 // thread on stream creation and locks such as stream_crit_ while calling out. | |
1419 rtc::CritScope stream_lock(&capturer_crit_); | |
1420 if (!signal_cpu_adaptation_) | |
1421 return; | |
1422 // Do not adapt resolution for screen content as this will likely result in | |
1423 // blurry and unreadable text. | |
1424 for (auto& kv : capturers_) { | |
1425 if (kv.second != nullptr | |
1426 && !kv.second->IsScreencast() | |
1427 && kv.second->video_adapter() != nullptr) { | |
1428 kv.second->video_adapter()->OnCpuResolutionRequest( | |
1429 load == kOveruse ? CoordinatedVideoAdapter::DOWNGRADE | |
1430 : CoordinatedVideoAdapter::UPGRADE); | |
1431 } | |
1432 } | |
1433 } | |
1434 | |
1435 bool WebRtcVideoChannel2::SendRtp(const uint8_t* data, | 1410 bool WebRtcVideoChannel2::SendRtp(const uint8_t* data, |
1436 size_t len, | 1411 size_t len, |
1437 const webrtc::PacketOptions& options) { | 1412 const webrtc::PacketOptions& options) { |
1438 rtc::Buffer packet(data, len, kMaxRtpPacketLen); | 1413 rtc::Buffer packet(data, len, kMaxRtpPacketLen); |
1439 rtc::PacketOptions rtc_options; | 1414 rtc::PacketOptions rtc_options; |
1440 rtc_options.packet_id = options.packet_id; | 1415 rtc_options.packet_id = options.packet_id; |
1441 return MediaChannel::SendPacket(&packet, rtc_options); | 1416 return MediaChannel::SendPacket(&packet, rtc_options); |
1442 } | 1417 } |
1443 | 1418 |
1444 bool WebRtcVideoChannel2::SendRtcp(const uint8_t* data, size_t len) { | 1419 bool WebRtcVideoChannel2::SendRtcp(const uint8_t* data, size_t len) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1488 this->encoder = | 1463 this->encoder = |
1489 new webrtc::VideoEncoderSoftwareFallbackWrapper(type, encoder); | 1464 new webrtc::VideoEncoderSoftwareFallbackWrapper(type, encoder); |
1490 } | 1465 } |
1491 } | 1466 } |
1492 | 1467 |
1493 WebRtcVideoChannel2::WebRtcVideoSendStream::WebRtcVideoSendStream( | 1468 WebRtcVideoChannel2::WebRtcVideoSendStream::WebRtcVideoSendStream( |
1494 webrtc::Call* call, | 1469 webrtc::Call* call, |
1495 const StreamParams& sp, | 1470 const StreamParams& sp, |
1496 const webrtc::VideoSendStream::Config& config, | 1471 const webrtc::VideoSendStream::Config& config, |
1497 WebRtcVideoEncoderFactory* external_encoder_factory, | 1472 WebRtcVideoEncoderFactory* external_encoder_factory, |
| 1473 bool enable_cpu_overuse_detection, |
1498 int max_bitrate_bps, | 1474 int max_bitrate_bps, |
1499 const rtc::Optional<VideoCodecSettings>& codec_settings, | 1475 const rtc::Optional<VideoCodecSettings>& codec_settings, |
1500 const std::vector<webrtc::RtpExtension>& rtp_extensions, | 1476 const std::vector<webrtc::RtpExtension>& rtp_extensions, |
1501 // TODO(deadbeef): Don't duplicate information between send_params, | 1477 // TODO(deadbeef): Don't duplicate information between send_params, |
1502 // rtp_extensions, options, etc. | 1478 // rtp_extensions, options, etc. |
1503 const VideoSendParameters& send_params) | 1479 const VideoSendParameters& send_params) |
1504 : ssrcs_(sp.ssrcs), | 1480 : worker_thread_(rtc::Thread::Current()), |
| 1481 ssrcs_(sp.ssrcs), |
1505 ssrc_groups_(sp.ssrc_groups), | 1482 ssrc_groups_(sp.ssrc_groups), |
1506 call_(call), | 1483 call_(call), |
| 1484 cpu_restricted_counter_(0), |
| 1485 number_of_cpu_adapt_changes_(0), |
| 1486 capturer_(nullptr), |
1507 external_encoder_factory_(external_encoder_factory), | 1487 external_encoder_factory_(external_encoder_factory), |
1508 stream_(NULL), | 1488 stream_(nullptr), |
1509 parameters_(config, send_params.options, max_bitrate_bps, codec_settings), | 1489 parameters_(config, send_params.options, max_bitrate_bps, codec_settings), |
1510 pending_encoder_reconfiguration_(false), | 1490 pending_encoder_reconfiguration_(false), |
1511 allocated_encoder_(NULL, webrtc::kVideoCodecUnknown, false), | 1491 allocated_encoder_(nullptr, webrtc::kVideoCodecUnknown, false), |
1512 capturer_(NULL), | 1492 capturer_is_screencast_(false), |
1513 sending_(false), | 1493 sending_(false), |
1514 muted_(false), | 1494 muted_(false), |
1515 old_adapt_changes_(0), | |
1516 first_frame_timestamp_ms_(0), | 1495 first_frame_timestamp_ms_(0), |
1517 last_frame_timestamp_ms_(0) { | 1496 last_frame_timestamp_ms_(0) { |
1518 parameters_.config.rtp.max_packet_size = kVideoMtu; | 1497 parameters_.config.rtp.max_packet_size = kVideoMtu; |
1519 parameters_.conference_mode = send_params.conference_mode; | 1498 parameters_.conference_mode = send_params.conference_mode; |
1520 | 1499 |
1521 sp.GetPrimarySsrcs(¶meters_.config.rtp.ssrcs); | 1500 sp.GetPrimarySsrcs(¶meters_.config.rtp.ssrcs); |
1522 sp.GetFidSsrcs(parameters_.config.rtp.ssrcs, | 1501 sp.GetFidSsrcs(parameters_.config.rtp.ssrcs, |
1523 ¶meters_.config.rtp.rtx.ssrcs); | 1502 ¶meters_.config.rtp.rtx.ssrcs); |
1524 parameters_.config.rtp.c_name = sp.cname; | 1503 parameters_.config.rtp.c_name = sp.cname; |
1525 parameters_.config.rtp.extensions = rtp_extensions; | 1504 parameters_.config.rtp.extensions = rtp_extensions; |
1526 parameters_.config.rtp.rtcp_mode = send_params.rtcp.reduced_size | 1505 parameters_.config.rtp.rtcp_mode = send_params.rtcp.reduced_size |
1527 ? webrtc::RtcpMode::kReducedSize | 1506 ? webrtc::RtcpMode::kReducedSize |
1528 : webrtc::RtcpMode::kCompound; | 1507 : webrtc::RtcpMode::kCompound; |
| 1508 parameters_.config.overuse_callback = |
| 1509 enable_cpu_overuse_detection ? this : nullptr; |
1529 | 1510 |
1530 if (codec_settings) { | 1511 if (codec_settings) { |
1531 SetCodecAndOptions(*codec_settings, parameters_.options); | 1512 SetCodecAndOptions(*codec_settings, parameters_.options); |
1532 } | 1513 } |
1533 } | 1514 } |
1534 | 1515 |
1535 WebRtcVideoChannel2::WebRtcVideoSendStream::~WebRtcVideoSendStream() { | 1516 WebRtcVideoChannel2::WebRtcVideoSendStream::~WebRtcVideoSendStream() { |
1536 DisconnectCapturer(); | 1517 DisconnectCapturer(); |
1537 if (stream_ != NULL) { | 1518 if (stream_ != NULL) { |
1538 call_->DestroyVideoSendStream(stream_); | 1519 call_->DestroyVideoSendStream(stream_); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1582 int64_t frame_delta_ms = frame.GetTimeStamp() / rtc::kNumNanosecsPerMillisec; | 1563 int64_t frame_delta_ms = frame.GetTimeStamp() / rtc::kNumNanosecsPerMillisec; |
1583 // frame->GetTimeStamp() is essentially a delta, align to webrtc time | 1564 // frame->GetTimeStamp() is essentially a delta, align to webrtc time |
1584 if (first_frame_timestamp_ms_ == 0) { | 1565 if (first_frame_timestamp_ms_ == 0) { |
1585 first_frame_timestamp_ms_ = rtc::Time() - frame_delta_ms; | 1566 first_frame_timestamp_ms_ = rtc::Time() - frame_delta_ms; |
1586 } | 1567 } |
1587 | 1568 |
1588 last_frame_timestamp_ms_ = first_frame_timestamp_ms_ + frame_delta_ms; | 1569 last_frame_timestamp_ms_ = first_frame_timestamp_ms_ + frame_delta_ms; |
1589 video_frame.set_render_time_ms(last_frame_timestamp_ms_); | 1570 video_frame.set_render_time_ms(last_frame_timestamp_ms_); |
1590 // Reconfigure codec if necessary. | 1571 // Reconfigure codec if necessary. |
1591 SetDimensions(video_frame.width(), video_frame.height(), | 1572 SetDimensions(video_frame.width(), video_frame.height(), |
1592 capturer_->IsScreencast()); | 1573 capturer_is_screencast_); |
1593 last_rotation_ = video_frame.rotation(); | 1574 last_rotation_ = video_frame.rotation(); |
1594 | 1575 |
1595 stream_->Input()->IncomingCapturedFrame(video_frame); | 1576 stream_->Input()->IncomingCapturedFrame(video_frame); |
1596 } | 1577 } |
1597 | 1578 |
1598 bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetCapturer( | 1579 bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetCapturer( |
1599 VideoCapturer* capturer) { | 1580 VideoCapturer* capturer) { |
1600 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::SetCapturer"); | 1581 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::SetCapturer"); |
| 1582 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
1601 if (!DisconnectCapturer() && capturer == NULL) { | 1583 if (!DisconnectCapturer() && capturer == NULL) { |
1602 return false; | 1584 return false; |
1603 } | 1585 } |
1604 | 1586 |
1605 { | 1587 { |
1606 rtc::CritScope cs(&lock_); | 1588 rtc::CritScope cs(&lock_); |
1607 | 1589 |
1608 // Reset timestamps to realign new incoming frames to a webrtc timestamp. A | 1590 // Reset timestamps to realign new incoming frames to a webrtc timestamp. A |
1609 // new capturer may have a different timestamp delta than the previous one. | 1591 // new capturer may have a different timestamp delta than the previous one. |
1610 first_frame_timestamp_ms_ = 0; | 1592 first_frame_timestamp_ms_ = 0; |
(...skipping 12 matching lines...) Expand all Loading... |
1623 // necessary to give this black frame a larger timestamp than the | 1605 // necessary to give this black frame a larger timestamp than the |
1624 // previous one. | 1606 // previous one. |
1625 last_frame_timestamp_ms_ += 1; | 1607 last_frame_timestamp_ms_ += 1; |
1626 black_frame.set_render_time_ms(last_frame_timestamp_ms_); | 1608 black_frame.set_render_time_ms(last_frame_timestamp_ms_); |
1627 stream_->Input()->IncomingCapturedFrame(black_frame); | 1609 stream_->Input()->IncomingCapturedFrame(black_frame); |
1628 } | 1610 } |
1629 | 1611 |
1630 capturer_ = NULL; | 1612 capturer_ = NULL; |
1631 return true; | 1613 return true; |
1632 } | 1614 } |
1633 | 1615 capturer_is_screencast_ = capturer->IsScreencast(); |
1634 capturer_ = capturer; | |
1635 capturer_->AddOrUpdateSink(this, sink_wants_); | |
1636 } | 1616 } |
| 1617 capturer_ = capturer; |
| 1618 capturer_->AddOrUpdateSink(this, sink_wants_); |
1637 return true; | 1619 return true; |
1638 } | 1620 } |
1639 | 1621 |
1640 void WebRtcVideoChannel2::WebRtcVideoSendStream::MuteStream(bool mute) { | 1622 void WebRtcVideoChannel2::WebRtcVideoSendStream::MuteStream(bool mute) { |
1641 rtc::CritScope cs(&lock_); | 1623 rtc::CritScope cs(&lock_); |
1642 muted_ = mute; | 1624 muted_ = mute; |
1643 } | 1625 } |
1644 | 1626 |
1645 bool WebRtcVideoChannel2::WebRtcVideoSendStream::DisconnectCapturer() { | 1627 bool WebRtcVideoChannel2::WebRtcVideoSendStream::DisconnectCapturer() { |
1646 cricket::VideoCapturer* capturer; | 1628 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
1647 { | 1629 if (capturer_ == NULL) { |
1648 rtc::CritScope cs(&lock_); | 1630 return false; |
1649 if (capturer_ == NULL) | 1631 } |
1650 return false; | |
1651 | 1632 |
1652 if (capturer_->video_adapter() != nullptr) | 1633 capturer_->RemoveSink(this); |
1653 old_adapt_changes_ += capturer_->video_adapter()->adaptation_changes(); | 1634 capturer_ = NULL; |
1654 | 1635 // Reset |cpu_restricted_counter_| if the capturer is changed. It is not |
1655 capturer = capturer_; | 1636 // possible to know if the video resolution is restricted by CPU usage after |
1656 capturer_ = NULL; | 1637 // the capturer is changed since the next capturer might be screen capture |
1657 } | 1638 // with another resolution and frame rate. |
1658 capturer->RemoveSink(this); | 1639 cpu_restricted_counter_ = 0; |
1659 | |
1660 return true; | 1640 return true; |
1661 } | 1641 } |
1662 | 1642 |
1663 const std::vector<uint32_t>& | 1643 const std::vector<uint32_t>& |
1664 WebRtcVideoChannel2::WebRtcVideoSendStream::GetSsrcs() const { | 1644 WebRtcVideoChannel2::WebRtcVideoSendStream::GetSsrcs() const { |
1665 return ssrcs_; | 1645 return ssrcs_; |
1666 } | 1646 } |
1667 | 1647 |
1668 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetOptions( | 1648 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetOptions( |
1669 const VideoOptions& options) { | 1649 const VideoOptions& options) { |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1815 params.options ? *params.options : parameters_.options); | 1795 params.options ? *params.options : parameters_.options); |
1816 return; | 1796 return; |
1817 } else if (params.options) { | 1797 } else if (params.options) { |
1818 // Reconfigure if codecs are already set. | 1798 // Reconfigure if codecs are already set. |
1819 if (parameters_.codec_settings) { | 1799 if (parameters_.codec_settings) { |
1820 SetCodecAndOptions(*parameters_.codec_settings, *params.options); | 1800 SetCodecAndOptions(*parameters_.codec_settings, *params.options); |
1821 return; | 1801 return; |
1822 } else { | 1802 } else { |
1823 parameters_.options = *params.options; | 1803 parameters_.options = *params.options; |
1824 } | 1804 } |
1825 } | 1805 } else if (params.conference_mode && parameters_.codec_settings) { |
1826 else if (params.conference_mode && parameters_.codec_settings) { | |
1827 SetCodecAndOptions(*parameters_.codec_settings, parameters_.options); | 1806 SetCodecAndOptions(*parameters_.codec_settings, parameters_.options); |
1828 return; | 1807 return; |
1829 } | 1808 } |
1830 if (recreate_stream) { | 1809 if (recreate_stream) { |
1831 LOG(LS_INFO) << "RecreateWebRtcStream (send) because of SetSendParameters"; | 1810 LOG(LS_INFO) << "RecreateWebRtcStream (send) because of SetSendParameters"; |
1832 RecreateWebRtcStream(); | 1811 RecreateWebRtcStream(); |
1833 } | 1812 } |
1834 } | 1813 } |
1835 | 1814 |
1836 webrtc::VideoEncoderConfig | 1815 webrtc::VideoEncoderConfig |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1943 } | 1922 } |
1944 | 1923 |
1945 void WebRtcVideoChannel2::WebRtcVideoSendStream::Stop() { | 1924 void WebRtcVideoChannel2::WebRtcVideoSendStream::Stop() { |
1946 rtc::CritScope cs(&lock_); | 1925 rtc::CritScope cs(&lock_); |
1947 if (stream_ != NULL) { | 1926 if (stream_ != NULL) { |
1948 stream_->Stop(); | 1927 stream_->Stop(); |
1949 } | 1928 } |
1950 sending_ = false; | 1929 sending_ = false; |
1951 } | 1930 } |
1952 | 1931 |
| 1932 void WebRtcVideoChannel2::WebRtcVideoSendStream::OnLoadUpdate(Load load) { |
| 1933 if (worker_thread_ != rtc::Thread::Current()) { |
| 1934 invoker_.AsyncInvoke<void>( |
| 1935 worker_thread_, |
| 1936 rtc::Bind(&WebRtcVideoChannel2::WebRtcVideoSendStream::OnLoadUpdate, |
| 1937 this, load)); |
| 1938 return; |
| 1939 } |
| 1940 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 1941 LOG(LS_INFO) << "OnLoadUpdate " << load; |
| 1942 if (!capturer_) { |
| 1943 return; |
| 1944 } |
| 1945 { |
| 1946 rtc::CritScope cs(&lock_); |
| 1947 // Do not adapt resolution for screen content as this will likely result in |
| 1948 // blurry and unreadable text. |
| 1949 if (capturer_is_screencast_) |
| 1950 return; |
| 1951 |
| 1952 rtc::Optional<int> max_pixel_count; |
| 1953 rtc::Optional<int> max_pixel_count_step_up; |
| 1954 if (load == kOveruse) { |
| 1955 max_pixel_count = rtc::Optional<int>( |
| 1956 (last_dimensions_.height * last_dimensions_.width) / 2); |
| 1957 // Increase |number_of_cpu_adapt_changes_| if |
| 1958 // sink_wants_.max_pixel_count will be changed since |
| 1959 // last time |capturer_->AddOrUpdateSink| was called. That is, this will |
| 1960 // result in a new request for the capturer to change resolution. |
| 1961 if (!sink_wants_.max_pixel_count || |
| 1962 *sink_wants_.max_pixel_count > *max_pixel_count) { |
| 1963 ++number_of_cpu_adapt_changes_; |
| 1964 ++cpu_restricted_counter_; |
| 1965 } |
| 1966 } else { |
| 1967 RTC_DCHECK(load == kUnderuse); |
| 1968 max_pixel_count_step_up = rtc::Optional<int>(last_dimensions_.height * |
| 1969 last_dimensions_.width); |
| 1970 // Increase |number_of_cpu_adapt_changes_| if |
| 1971 // sink_wants_.max_pixel_count_step_up will be changed since |
| 1972 // last time |capturer_->AddOrUpdateSink| was called. That is, this will |
| 1973 // result in a new request for the capturer to change resolution. |
| 1974 if (sink_wants_.max_pixel_count || |
| 1975 (sink_wants_.max_pixel_count_step_up && |
| 1976 *sink_wants_.max_pixel_count_step_up < *max_pixel_count_step_up)) { |
| 1977 ++number_of_cpu_adapt_changes_; |
| 1978 --cpu_restricted_counter_; |
| 1979 } |
| 1980 } |
| 1981 sink_wants_.max_pixel_count = max_pixel_count; |
| 1982 sink_wants_.max_pixel_count_step_up = max_pixel_count_step_up; |
| 1983 } |
| 1984 capturer_->AddOrUpdateSink(this, sink_wants_); |
| 1985 } |
| 1986 |
1953 VideoSenderInfo | 1987 VideoSenderInfo |
1954 WebRtcVideoChannel2::WebRtcVideoSendStream::GetVideoSenderInfo() { | 1988 WebRtcVideoChannel2::WebRtcVideoSendStream::GetVideoSenderInfo() { |
1955 VideoSenderInfo info; | 1989 VideoSenderInfo info; |
1956 webrtc::VideoSendStream::Stats stats; | 1990 webrtc::VideoSendStream::Stats stats; |
| 1991 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
1957 { | 1992 { |
1958 rtc::CritScope cs(&lock_); | 1993 rtc::CritScope cs(&lock_); |
1959 for (uint32_t ssrc : parameters_.config.rtp.ssrcs) | 1994 for (uint32_t ssrc : parameters_.config.rtp.ssrcs) |
1960 info.add_ssrc(ssrc); | 1995 info.add_ssrc(ssrc); |
1961 | 1996 |
1962 if (parameters_.codec_settings) | 1997 if (parameters_.codec_settings) |
1963 info.codec_name = parameters_.codec_settings->codec.name; | 1998 info.codec_name = parameters_.codec_settings->codec.name; |
1964 for (size_t i = 0; i < parameters_.encoder_config.streams.size(); ++i) { | 1999 for (size_t i = 0; i < parameters_.encoder_config.streams.size(); ++i) { |
1965 if (i == parameters_.encoder_config.streams.size() - 1) { | 2000 if (i == parameters_.encoder_config.streams.size() - 1) { |
1966 info.preferred_bitrate += | 2001 info.preferred_bitrate += |
1967 parameters_.encoder_config.streams[i].max_bitrate_bps; | 2002 parameters_.encoder_config.streams[i].max_bitrate_bps; |
1968 } else { | 2003 } else { |
1969 info.preferred_bitrate += | 2004 info.preferred_bitrate += |
1970 parameters_.encoder_config.streams[i].target_bitrate_bps; | 2005 parameters_.encoder_config.streams[i].target_bitrate_bps; |
1971 } | 2006 } |
1972 } | 2007 } |
1973 | 2008 |
1974 if (stream_ == NULL) | 2009 if (stream_ == NULL) |
1975 return info; | 2010 return info; |
1976 | 2011 |
1977 stats = stream_->GetStats(); | 2012 stats = stream_->GetStats(); |
| 2013 } |
| 2014 info.adapt_changes = number_of_cpu_adapt_changes_; |
| 2015 info.adapt_reason = cpu_restricted_counter_ <= 0 |
| 2016 ? CoordinatedVideoAdapter::ADAPTREASON_NONE |
| 2017 : CoordinatedVideoAdapter::ADAPTREASON_CPU; |
1978 | 2018 |
1979 info.adapt_changes = old_adapt_changes_; | 2019 if (capturer_) { |
1980 info.adapt_reason = CoordinatedVideoAdapter::ADAPTREASON_NONE; | 2020 if (!capturer_->IsMuted()) { |
1981 | 2021 VideoFormat last_captured_frame_format; |
1982 if (capturer_ != NULL) { | 2022 capturer_->GetStats(&info.adapt_frame_drops, &info.effects_frame_drops, |
1983 if (!capturer_->IsMuted()) { | 2023 &info.capturer_frame_time, |
1984 VideoFormat last_captured_frame_format; | 2024 &last_captured_frame_format); |
1985 capturer_->GetStats(&info.adapt_frame_drops, &info.effects_frame_drops, | 2025 info.input_frame_width = last_captured_frame_format.width; |
1986 &info.capturer_frame_time, | 2026 info.input_frame_height = last_captured_frame_format.height; |
1987 &last_captured_frame_format); | |
1988 info.input_frame_width = last_captured_frame_format.width; | |
1989 info.input_frame_height = last_captured_frame_format.height; | |
1990 } | |
1991 if (capturer_->video_adapter() != nullptr) { | |
1992 info.adapt_changes += capturer_->video_adapter()->adaptation_changes(); | |
1993 info.adapt_reason = capturer_->video_adapter()->adapt_reason(); | |
1994 } | |
1995 } | 2027 } |
1996 } | 2028 } |
1997 | 2029 |
1998 // Get bandwidth limitation info from stream_->GetStats(). | 2030 // Get bandwidth limitation info from stream_->GetStats(). |
1999 // Input resolution (output from video_adapter) can be further scaled down or | 2031 // Input resolution (output from video_adapter) can be further scaled down or |
2000 // higher video layer(s) can be dropped due to bitrate constraints. | 2032 // higher video layer(s) can be dropped due to bitrate constraints. |
2001 // Note, adapt_changes only include changes from the video_adapter. | 2033 // Note, adapt_changes only include changes from the video_adapter. |
2002 if (stats.bw_limited_resolution) | 2034 if (stats.bw_limited_resolution) |
2003 info.adapt_reason |= CoordinatedVideoAdapter::ADAPTREASON_BANDWIDTH; | 2035 info.adapt_reason |= CoordinatedVideoAdapter::ADAPTREASON_BANDWIDTH; |
2004 | 2036 |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2504 rtx_mapping[video_codecs[i].codec.id] != | 2536 rtx_mapping[video_codecs[i].codec.id] != |
2505 fec_settings.red_payload_type) { | 2537 fec_settings.red_payload_type) { |
2506 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; | 2538 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; |
2507 } | 2539 } |
2508 } | 2540 } |
2509 | 2541 |
2510 return video_codecs; | 2542 return video_codecs; |
2511 } | 2543 } |
2512 | 2544 |
2513 } // namespace cricket | 2545 } // namespace cricket |
OLD | NEW |