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 : thread_(rtc::Thread::Current()), |
pbos-webrtc
2016/02/26 14:26:18
worker_thread_ or main_thread_ maybe?
perkj_webrtc
2016/02/26 15:22:34
Done.
| |
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_(NULL), | |
pbos-webrtc
2016/02/26 14:26:18
nullptr
perkj_webrtc
2016/02/26 15:22:34
Done.
| |
1507 external_encoder_factory_(external_encoder_factory), | 1487 external_encoder_factory_(external_encoder_factory), |
1508 stream_(NULL), | 1488 stream_(NULL), |
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_(NULL, 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) | |
1650 return false; | |
1651 | 1631 |
1652 if (capturer_->video_adapter() != nullptr) | 1632 capturer_->RemoveSink(this); |
1653 old_adapt_changes_ += capturer_->video_adapter()->adaptation_changes(); | 1633 capturer_ = NULL; |
1654 | 1634 cpu_restricted_counter_ = 0; |
pbos-webrtc
2016/02/26 14:26:18
Comment on what this means.
perkj_webrtc
2016/02/26 15:22:34
Done.
| |
1655 capturer = capturer_; | |
1656 capturer_ = NULL; | |
1657 } | |
1658 capturer->RemoveSink(this); | |
1659 | 1635 |
1660 return true; | 1636 return true; |
1661 } | 1637 } |
1662 | 1638 |
1663 const std::vector<uint32_t>& | 1639 const std::vector<uint32_t>& |
1664 WebRtcVideoChannel2::WebRtcVideoSendStream::GetSsrcs() const { | 1640 WebRtcVideoChannel2::WebRtcVideoSendStream::GetSsrcs() const { |
1665 return ssrcs_; | 1641 return ssrcs_; |
1666 } | 1642 } |
1667 | 1643 |
1668 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetOptions( | 1644 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetOptions( |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1815 params.options ? *params.options : parameters_.options); | 1791 params.options ? *params.options : parameters_.options); |
1816 return; | 1792 return; |
1817 } else if (params.options) { | 1793 } else if (params.options) { |
1818 // Reconfigure if codecs are already set. | 1794 // Reconfigure if codecs are already set. |
1819 if (parameters_.codec_settings) { | 1795 if (parameters_.codec_settings) { |
1820 SetCodecAndOptions(*parameters_.codec_settings, *params.options); | 1796 SetCodecAndOptions(*parameters_.codec_settings, *params.options); |
1821 return; | 1797 return; |
1822 } else { | 1798 } else { |
1823 parameters_.options = *params.options; | 1799 parameters_.options = *params.options; |
1824 } | 1800 } |
1825 } | 1801 } else if (params.conference_mode && parameters_.codec_settings) { |
1826 else if (params.conference_mode && parameters_.codec_settings) { | |
1827 SetCodecAndOptions(*parameters_.codec_settings, parameters_.options); | 1802 SetCodecAndOptions(*parameters_.codec_settings, parameters_.options); |
1828 return; | 1803 return; |
1829 } | 1804 } |
1830 if (recreate_stream) { | 1805 if (recreate_stream) { |
1831 LOG(LS_INFO) << "RecreateWebRtcStream (send) because of SetSendParameters"; | 1806 LOG(LS_INFO) << "RecreateWebRtcStream (send) because of SetSendParameters"; |
1832 RecreateWebRtcStream(); | 1807 RecreateWebRtcStream(); |
1833 } | 1808 } |
1834 } | 1809 } |
1835 | 1810 |
1836 webrtc::VideoEncoderConfig | 1811 webrtc::VideoEncoderConfig |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1943 } | 1918 } |
1944 | 1919 |
1945 void WebRtcVideoChannel2::WebRtcVideoSendStream::Stop() { | 1920 void WebRtcVideoChannel2::WebRtcVideoSendStream::Stop() { |
1946 rtc::CritScope cs(&lock_); | 1921 rtc::CritScope cs(&lock_); |
1947 if (stream_ != NULL) { | 1922 if (stream_ != NULL) { |
1948 stream_->Stop(); | 1923 stream_->Stop(); |
1949 } | 1924 } |
1950 sending_ = false; | 1925 sending_ = false; |
1951 } | 1926 } |
1952 | 1927 |
1928 void WebRtcVideoChannel2::WebRtcVideoSendStream::OnLoadUpdate(Load load) { | |
1929 if (thread_ != rtc::Thread::Current()) { | |
1930 invoker_.AsyncInvoke<void>( | |
1931 thread_, | |
1932 rtc::Bind(&WebRtcVideoChannel2::WebRtcVideoSendStream::OnLoadUpdate, | |
1933 this, load)); | |
1934 return; | |
1935 } | |
1936 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
1937 LOG(LS_INFO) << "OnLoadUpdate " << load; | |
1938 { | |
1939 rtc::CritScope cs(&lock_); | |
1940 // Do not adapt resolution for screen content as this will likely result in | |
1941 // blurry and unreadable text. | |
1942 if (!capturer_ || capturer_is_screencast_) | |
pbos-webrtc
2016/02/26 14:26:18
abort on !capturer_ before taking the lock.
perkj_webrtc
2016/02/26 15:22:34
Done.
| |
1943 return; | |
1944 | |
1945 rtc::Optional<int> max_pixel_count; | |
1946 rtc::Optional<int> max_pixel_count_step_up; | |
1947 if (load == kOveruse) { | |
1948 { | |
pbos-webrtc
2016/02/26 14:26:18
remove {}s
perkj_webrtc
2016/02/26 15:22:34
Done.
| |
1949 max_pixel_count = rtc::Optional<int>( | |
1950 (last_dimensions_.height * last_dimensions_.width) / 2); | |
1951 } | |
1952 if (!sink_wants_.max_pixel_count || | |
pbos-webrtc
2016/02/26 14:26:18
Comment what this actually means.
perkj_webrtc
2016/02/26 15:22:34
Done.
| |
1953 *sink_wants_.max_pixel_count > *max_pixel_count) { | |
1954 ++number_of_cpu_adapt_changes_; | |
1955 ++cpu_restricted_counter_; | |
1956 } | |
1957 } else { | |
1958 RTC_DCHECK(load == kUnderuse); | |
1959 { | |
pbos-webrtc
2016/02/26 14:26:18
remove {}s
perkj_webrtc
2016/02/26 15:22:34
Done.
| |
1960 max_pixel_count_step_up = rtc::Optional<int>(last_dimensions_.height * | |
1961 last_dimensions_.width); | |
1962 } | |
1963 if (sink_wants_.max_pixel_count || | |
pbos-webrtc
2016/02/26 14:26:18
Same as above, comment please
perkj_webrtc
2016/02/26 15:22:34
Done.
| |
1964 (sink_wants_.max_pixel_count_step_up && | |
1965 *sink_wants_.max_pixel_count_step_up < *max_pixel_count_step_up)) { | |
1966 ++number_of_cpu_adapt_changes_; | |
1967 --cpu_restricted_counter_; | |
1968 } | |
1969 } | |
1970 sink_wants_.max_pixel_count = max_pixel_count; | |
1971 sink_wants_.max_pixel_count_step_up = max_pixel_count_step_up; | |
1972 } | |
1973 capturer_->AddOrUpdateSink(this, sink_wants_); | |
1974 } | |
1975 | |
1953 VideoSenderInfo | 1976 VideoSenderInfo |
1954 WebRtcVideoChannel2::WebRtcVideoSendStream::GetVideoSenderInfo() { | 1977 WebRtcVideoChannel2::WebRtcVideoSendStream::GetVideoSenderInfo() { |
1955 VideoSenderInfo info; | 1978 VideoSenderInfo info; |
1956 webrtc::VideoSendStream::Stats stats; | 1979 webrtc::VideoSendStream::Stats stats; |
1980 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
1957 { | 1981 { |
1958 rtc::CritScope cs(&lock_); | 1982 rtc::CritScope cs(&lock_); |
1959 for (uint32_t ssrc : parameters_.config.rtp.ssrcs) | 1983 for (uint32_t ssrc : parameters_.config.rtp.ssrcs) |
1960 info.add_ssrc(ssrc); | 1984 info.add_ssrc(ssrc); |
1961 | 1985 |
1962 if (parameters_.codec_settings) | 1986 if (parameters_.codec_settings) |
1963 info.codec_name = parameters_.codec_settings->codec.name; | 1987 info.codec_name = parameters_.codec_settings->codec.name; |
1964 for (size_t i = 0; i < parameters_.encoder_config.streams.size(); ++i) { | 1988 for (size_t i = 0; i < parameters_.encoder_config.streams.size(); ++i) { |
1965 if (i == parameters_.encoder_config.streams.size() - 1) { | 1989 if (i == parameters_.encoder_config.streams.size() - 1) { |
1966 info.preferred_bitrate += | 1990 info.preferred_bitrate += |
1967 parameters_.encoder_config.streams[i].max_bitrate_bps; | 1991 parameters_.encoder_config.streams[i].max_bitrate_bps; |
1968 } else { | 1992 } else { |
1969 info.preferred_bitrate += | 1993 info.preferred_bitrate += |
1970 parameters_.encoder_config.streams[i].target_bitrate_bps; | 1994 parameters_.encoder_config.streams[i].target_bitrate_bps; |
1971 } | 1995 } |
1972 } | 1996 } |
1973 | 1997 |
1974 if (stream_ == NULL) | 1998 if (stream_ == NULL) |
1975 return info; | 1999 return info; |
1976 | 2000 |
1977 stats = stream_->GetStats(); | 2001 stats = stream_->GetStats(); |
2002 } | |
2003 info.adapt_changes = number_of_cpu_adapt_changes_; | |
2004 info.adapt_reason = cpu_restricted_counter_ <= 0 | |
2005 ? CoordinatedVideoAdapter::ADAPTREASON_NONE | |
2006 : CoordinatedVideoAdapter::ADAPTREASON_CPU; | |
1978 | 2007 |
1979 info.adapt_changes = old_adapt_changes_; | 2008 if (capturer_ != NULL) { |
pbos-webrtc
2016/02/26 14:26:18
if (capturer_)
perkj_webrtc
2016/02/26 15:22:34
Done.
| |
1980 info.adapt_reason = CoordinatedVideoAdapter::ADAPTREASON_NONE; | 2009 if (!capturer_->IsMuted()) { |
1981 | 2010 VideoFormat last_captured_frame_format; |
1982 if (capturer_ != NULL) { | 2011 capturer_->GetStats(&info.adapt_frame_drops, &info.effects_frame_drops, |
1983 if (!capturer_->IsMuted()) { | 2012 &info.capturer_frame_time, |
1984 VideoFormat last_captured_frame_format; | 2013 &last_captured_frame_format); |
1985 capturer_->GetStats(&info.adapt_frame_drops, &info.effects_frame_drops, | 2014 info.input_frame_width = last_captured_frame_format.width; |
1986 &info.capturer_frame_time, | 2015 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 } | 2016 } |
1996 } | 2017 } |
1997 | 2018 |
1998 // Get bandwidth limitation info from stream_->GetStats(). | 2019 // Get bandwidth limitation info from stream_->GetStats(). |
1999 // Input resolution (output from video_adapter) can be further scaled down or | 2020 // Input resolution (output from video_adapter) can be further scaled down or |
2000 // higher video layer(s) can be dropped due to bitrate constraints. | 2021 // higher video layer(s) can be dropped due to bitrate constraints. |
2001 // Note, adapt_changes only include changes from the video_adapter. | 2022 // Note, adapt_changes only include changes from the video_adapter. |
2002 if (stats.bw_limited_resolution) | 2023 if (stats.bw_limited_resolution) |
2003 info.adapt_reason |= CoordinatedVideoAdapter::ADAPTREASON_BANDWIDTH; | 2024 info.adapt_reason |= CoordinatedVideoAdapter::ADAPTREASON_BANDWIDTH; |
2004 | 2025 |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2504 rtx_mapping[video_codecs[i].codec.id] != | 2525 rtx_mapping[video_codecs[i].codec.id] != |
2505 fec_settings.red_payload_type) { | 2526 fec_settings.red_payload_type) { |
2506 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; | 2527 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; |
2507 } | 2528 } |
2508 } | 2529 } |
2509 | 2530 |
2510 return video_codecs; | 2531 return video_codecs; |
2511 } | 2532 } |
2512 | 2533 |
2513 } // namespace cricket | 2534 } // namespace cricket |
OLD | NEW |