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 |
11 #include "webrtc/media/engine/webrtcvideoengine2.h" | 11 #include "webrtc/media/engine/webrtcvideoengine2.h" |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
14 #include <set> | 14 #include <set> |
15 #include <string> | 15 #include <string> |
16 | 16 |
17 #include "webrtc/base/asyncinvoker.h" | |
17 #include "webrtc/base/buffer.h" | 18 #include "webrtc/base/buffer.h" |
18 #include "webrtc/base/logging.h" | 19 #include "webrtc/base/logging.h" |
19 #include "webrtc/base/stringutils.h" | 20 #include "webrtc/base/stringutils.h" |
20 #include "webrtc/base/timeutils.h" | 21 #include "webrtc/base/timeutils.h" |
21 #include "webrtc/base/trace_event.h" | 22 #include "webrtc/base/trace_event.h" |
22 #include "webrtc/call.h" | 23 #include "webrtc/call.h" |
23 #include "webrtc/media/base/videocapturer.h" | 24 #include "webrtc/media/base/videocapturer.h" |
24 #include "webrtc/media/base/videorenderer.h" | 25 #include "webrtc/media/base/videorenderer.h" |
25 #include "webrtc/media/engine/constants.h" | 26 #include "webrtc/media/engine/constants.h" |
26 #include "webrtc/media/engine/simulcast.h" | 27 #include "webrtc/media/engine/simulcast.h" |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
307 if (width * height <= 320 * 240) { | 308 if (width * height <= 320 * 240) { |
308 return 600; | 309 return 600; |
309 } else if (width * height <= 640 * 480) { | 310 } else if (width * height <= 640 * 480) { |
310 return 1700; | 311 return 1700; |
311 } else if (width * height <= 960 * 540) { | 312 } else if (width * height <= 960 * 540) { |
312 return 2000; | 313 return 2000; |
313 } else { | 314 } else { |
314 return 2500; | 315 return 2500; |
315 } | 316 } |
316 } | 317 } |
318 | |
317 } // namespace | 319 } // namespace |
318 | 320 |
319 // Constants defined in webrtc/media/engine/constants.h | 321 // Constants defined in webrtc/media/engine/constants.h |
320 // TODO(pbos): Move these to a separate constants.cc file. | 322 // TODO(pbos): Move these to a separate constants.cc file. |
321 const int kMinVideoBitrate = 30; | 323 const int kMinVideoBitrate = 30; |
322 const int kStartVideoBitrate = 300; | 324 const int kStartVideoBitrate = 300; |
323 | 325 |
324 const int kVideoMtu = 1200; | 326 const int kVideoMtu = 1200; |
325 const int kVideoRtpBufferSize = 65536; | 327 const int kVideoRtpBufferSize = 65536; |
326 | 328 |
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
993 | 995 |
994 rtc::CritScope stream_lock(&stream_crit_); | 996 rtc::CritScope stream_lock(&stream_crit_); |
995 | 997 |
996 if (!ValidateSendSsrcAvailability(sp)) | 998 if (!ValidateSendSsrcAvailability(sp)) |
997 return false; | 999 return false; |
998 | 1000 |
999 for (uint32_t used_ssrc : sp.ssrcs) | 1001 for (uint32_t used_ssrc : sp.ssrcs) |
1000 send_ssrcs_.insert(used_ssrc); | 1002 send_ssrcs_.insert(used_ssrc); |
1001 | 1003 |
1002 webrtc::VideoSendStream::Config config(this); | 1004 webrtc::VideoSendStream::Config config(this); |
1003 config.overuse_callback = this; | 1005 WebRtcVideoSendStream* stream = new WebRtcVideoSendStream( |
1004 | 1006 call_, sp, config, external_encoder_factory_, signal_cpu_adaptation_, |
1005 WebRtcVideoSendStream* stream = | 1007 bitrate_config_.max_bitrate_bps, send_codec_, send_rtp_extensions_, |
1006 new WebRtcVideoSendStream(call_, sp, config, external_encoder_factory_, | 1008 send_params_); |
1007 bitrate_config_.max_bitrate_bps, send_codec_, | |
1008 send_rtp_extensions_, send_params_); | |
1009 | 1009 |
1010 uint32_t ssrc = sp.first_ssrc(); | 1010 uint32_t ssrc = sp.first_ssrc(); |
1011 RTC_DCHECK(ssrc != 0); | 1011 RTC_DCHECK(ssrc != 0); |
1012 send_streams_[ssrc] = stream; | 1012 send_streams_[ssrc] = stream; |
1013 | 1013 |
1014 if (rtcp_receiver_report_ssrc_ == kDefaultRtcpReceiverReportSsrc) { | 1014 if (rtcp_receiver_report_ssrc_ == kDefaultRtcpReceiverReportSsrc) { |
1015 rtcp_receiver_report_ssrc_ = ssrc; | 1015 rtcp_receiver_report_ssrc_ = ssrc; |
1016 LOG(LS_INFO) << "SetLocalSsrc on all the receive streams because we added " | 1016 LOG(LS_INFO) << "SetLocalSsrc on all the receive streams because we added " |
1017 "a send stream."; | 1017 "a send stream."; |
1018 for (auto& kv : receive_streams_) | 1018 for (auto& kv : receive_streams_) |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1405 | 1405 |
1406 // Speculative change to increase the outbound socket buffer size. | 1406 // Speculative change to increase the outbound socket buffer size. |
1407 // In b/15152257, we are seeing a significant number of packets discarded | 1407 // 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 | 1408 // due to lack of socket buffer space, although it's not yet clear what the |
1409 // ideal value should be. | 1409 // ideal value should be. |
1410 MediaChannel::SetOption(NetworkInterface::ST_RTP, | 1410 MediaChannel::SetOption(NetworkInterface::ST_RTP, |
1411 rtc::Socket::OPT_SNDBUF, | 1411 rtc::Socket::OPT_SNDBUF, |
1412 kVideoRtpBufferSize); | 1412 kVideoRtpBufferSize); |
1413 } | 1413 } |
1414 | 1414 |
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, | 1415 bool WebRtcVideoChannel2::SendRtp(const uint8_t* data, |
1436 size_t len, | 1416 size_t len, |
1437 const webrtc::PacketOptions& options) { | 1417 const webrtc::PacketOptions& options) { |
1438 rtc::Buffer packet(data, len, kMaxRtpPacketLen); | 1418 rtc::Buffer packet(data, len, kMaxRtpPacketLen); |
1439 rtc::PacketOptions rtc_options; | 1419 rtc::PacketOptions rtc_options; |
1440 rtc_options.packet_id = options.packet_id; | 1420 rtc_options.packet_id = options.packet_id; |
1441 return MediaChannel::SendPacket(&packet, rtc_options); | 1421 return MediaChannel::SendPacket(&packet, rtc_options); |
1442 } | 1422 } |
1443 | 1423 |
1444 bool WebRtcVideoChannel2::SendRtcp(const uint8_t* data, size_t len) { | 1424 bool WebRtcVideoChannel2::SendRtcp(const uint8_t* data, size_t len) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1483 external_encoder(nullptr), | 1463 external_encoder(nullptr), |
1484 type(type), | 1464 type(type), |
1485 external(external) { | 1465 external(external) { |
1486 if (external) { | 1466 if (external) { |
1487 external_encoder = encoder; | 1467 external_encoder = encoder; |
1488 this->encoder = | 1468 this->encoder = |
1489 new webrtc::VideoEncoderSoftwareFallbackWrapper(type, encoder); | 1469 new webrtc::VideoEncoderSoftwareFallbackWrapper(type, encoder); |
1490 } | 1470 } |
1491 } | 1471 } |
1492 | 1472 |
1473 // Proxy class used for marshalling calls to webrtc::LoadObserver::OnLoadUpdate | |
1474 // from a media engine thread to the worker thread. | |
1475 // This proxy is necessary to make sure VideoSourceInterface::AddOrUpdateSink is | |
1476 // called from only one thread and also because |lock_| should not be held | |
1477 // in a media engine thread since that may cause a deadlock is |stream_| is | |
1478 // destroyed. | |
pthatcher1
2016/02/25 20:20:05
Could we just implement WebRtcVideoChannel2::WebRt
perkj_webrtc
2016/02/26 14:08:25
// Invokes function objects (aka functors) asynchr
| |
1479 class WebRtcVideoChannel2::WebRtcVideoSendStream::LoadObserverProxy { | |
1480 public: | |
1481 explicit LoadObserverProxy(webrtc::LoadObserver* observer) { | |
1482 helper_ = new rtc::RefCountedObject<Helper>(observer); | |
1483 } | |
1484 ~LoadObserverProxy() { helper_->Detach(); } | |
1485 | |
1486 webrtc::LoadObserver* proxy() { return helper_; } | |
1487 | |
1488 private: | |
1489 class Helper : public webrtc::LoadObserver, public rtc::RefCountInterface { | |
1490 public: | |
1491 explicit Helper(webrtc::LoadObserver* observer) | |
1492 : thread_(rtc::Thread::Current()), observer_(observer) {} | |
1493 void Detach() { | |
1494 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
1495 observer_ = nullptr; | |
1496 } | |
1497 void OnLoadUpdate(webrtc::LoadObserver::Load load) override { | |
1498 if (rtc::Thread::Current() == thread_) { | |
1499 observer_->OnLoadUpdate(load); | |
1500 return; | |
1501 } | |
1502 invoker_.AsyncInvoke<void>( | |
1503 thread_, rtc::Bind(&Helper::OnLoadUpdateOnCorrectThread, this, load)); | |
1504 } | |
1505 void OnLoadUpdateOnCorrectThread(webrtc::LoadObserver::Load load) { | |
1506 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
1507 if (observer_) { | |
1508 observer_->OnLoadUpdate(load); | |
1509 } | |
1510 } | |
1511 | |
1512 private: | |
1513 rtc::ThreadChecker thread_checker_; | |
1514 rtc::AsyncInvoker invoker_; | |
1515 rtc::Thread* thread_; | |
1516 webrtc::LoadObserver* observer_; | |
1517 }; | |
1518 | |
1519 rtc::scoped_refptr<Helper> helper_; | |
1520 }; | |
1521 | |
1493 WebRtcVideoChannel2::WebRtcVideoSendStream::WebRtcVideoSendStream( | 1522 WebRtcVideoChannel2::WebRtcVideoSendStream::WebRtcVideoSendStream( |
1494 webrtc::Call* call, | 1523 webrtc::Call* call, |
1495 const StreamParams& sp, | 1524 const StreamParams& sp, |
1496 const webrtc::VideoSendStream::Config& config, | 1525 const webrtc::VideoSendStream::Config& config, |
1497 WebRtcVideoEncoderFactory* external_encoder_factory, | 1526 WebRtcVideoEncoderFactory* external_encoder_factory, |
1527 bool enable_cpu_overuse_detection, | |
1498 int max_bitrate_bps, | 1528 int max_bitrate_bps, |
1499 const rtc::Optional<VideoCodecSettings>& codec_settings, | 1529 const rtc::Optional<VideoCodecSettings>& codec_settings, |
1500 const std::vector<webrtc::RtpExtension>& rtp_extensions, | 1530 const std::vector<webrtc::RtpExtension>& rtp_extensions, |
1501 // TODO(deadbeef): Don't duplicate information between send_params, | 1531 // TODO(deadbeef): Don't duplicate information between send_params, |
1502 // rtp_extensions, options, etc. | 1532 // rtp_extensions, options, etc. |
1503 const VideoSendParameters& send_params) | 1533 const VideoSendParameters& send_params) |
1504 : ssrcs_(sp.ssrcs), | 1534 : ssrcs_(sp.ssrcs), |
1505 ssrc_groups_(sp.ssrc_groups), | 1535 ssrc_groups_(sp.ssrc_groups), |
1506 call_(call), | 1536 call_(call), |
1537 cpu_downgrade_counter_(0), | |
1538 number_of_cpu_adapt_changes_(0), | |
1539 load_proxy_(new LoadObserverProxy(this)), | |
1540 capturer_(NULL), | |
1507 external_encoder_factory_(external_encoder_factory), | 1541 external_encoder_factory_(external_encoder_factory), |
1508 stream_(NULL), | 1542 stream_(NULL), |
1509 parameters_(config, send_params.options, max_bitrate_bps, codec_settings), | 1543 parameters_(config, send_params.options, max_bitrate_bps, codec_settings), |
1510 pending_encoder_reconfiguration_(false), | 1544 pending_encoder_reconfiguration_(false), |
1511 allocated_encoder_(NULL, webrtc::kVideoCodecUnknown, false), | 1545 allocated_encoder_(NULL, webrtc::kVideoCodecUnknown, false), |
1512 capturer_(NULL), | 1546 capturer_is_screencast_(false), |
1513 sending_(false), | 1547 sending_(false), |
1514 muted_(false), | 1548 muted_(false), |
1515 old_adapt_changes_(0), | |
1516 first_frame_timestamp_ms_(0), | 1549 first_frame_timestamp_ms_(0), |
1517 last_frame_timestamp_ms_(0) { | 1550 last_frame_timestamp_ms_(0) { |
1518 parameters_.config.rtp.max_packet_size = kVideoMtu; | 1551 parameters_.config.rtp.max_packet_size = kVideoMtu; |
1519 parameters_.conference_mode = send_params.conference_mode; | 1552 parameters_.conference_mode = send_params.conference_mode; |
1520 | 1553 |
1521 sp.GetPrimarySsrcs(¶meters_.config.rtp.ssrcs); | 1554 sp.GetPrimarySsrcs(¶meters_.config.rtp.ssrcs); |
1522 sp.GetFidSsrcs(parameters_.config.rtp.ssrcs, | 1555 sp.GetFidSsrcs(parameters_.config.rtp.ssrcs, |
1523 ¶meters_.config.rtp.rtx.ssrcs); | 1556 ¶meters_.config.rtp.rtx.ssrcs); |
1524 parameters_.config.rtp.c_name = sp.cname; | 1557 parameters_.config.rtp.c_name = sp.cname; |
1525 parameters_.config.rtp.extensions = rtp_extensions; | 1558 parameters_.config.rtp.extensions = rtp_extensions; |
1526 parameters_.config.rtp.rtcp_mode = send_params.rtcp.reduced_size | 1559 parameters_.config.rtp.rtcp_mode = send_params.rtcp.reduced_size |
1527 ? webrtc::RtcpMode::kReducedSize | 1560 ? webrtc::RtcpMode::kReducedSize |
1528 : webrtc::RtcpMode::kCompound; | 1561 : webrtc::RtcpMode::kCompound; |
1562 parameters_.config.overuse_callback = | |
1563 enable_cpu_overuse_detection ? load_proxy_->proxy() : nullptr; | |
1529 | 1564 |
1530 if (codec_settings) { | 1565 if (codec_settings) { |
1531 SetCodecAndOptions(*codec_settings, parameters_.options); | 1566 SetCodecAndOptions(*codec_settings, parameters_.options); |
1532 } | 1567 } |
1533 } | 1568 } |
1534 | 1569 |
1535 WebRtcVideoChannel2::WebRtcVideoSendStream::~WebRtcVideoSendStream() { | 1570 WebRtcVideoChannel2::WebRtcVideoSendStream::~WebRtcVideoSendStream() { |
1536 DisconnectCapturer(); | 1571 DisconnectCapturer(); |
1537 if (stream_ != NULL) { | 1572 if (stream_ != NULL) { |
1538 call_->DestroyVideoSendStream(stream_); | 1573 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; | 1617 int64_t frame_delta_ms = frame.GetTimeStamp() / rtc::kNumNanosecsPerMillisec; |
1583 // frame->GetTimeStamp() is essentially a delta, align to webrtc time | 1618 // frame->GetTimeStamp() is essentially a delta, align to webrtc time |
1584 if (first_frame_timestamp_ms_ == 0) { | 1619 if (first_frame_timestamp_ms_ == 0) { |
1585 first_frame_timestamp_ms_ = rtc::Time() - frame_delta_ms; | 1620 first_frame_timestamp_ms_ = rtc::Time() - frame_delta_ms; |
1586 } | 1621 } |
1587 | 1622 |
1588 last_frame_timestamp_ms_ = first_frame_timestamp_ms_ + frame_delta_ms; | 1623 last_frame_timestamp_ms_ = first_frame_timestamp_ms_ + frame_delta_ms; |
1589 video_frame.set_render_time_ms(last_frame_timestamp_ms_); | 1624 video_frame.set_render_time_ms(last_frame_timestamp_ms_); |
1590 // Reconfigure codec if necessary. | 1625 // Reconfigure codec if necessary. |
1591 SetDimensions(video_frame.width(), video_frame.height(), | 1626 SetDimensions(video_frame.width(), video_frame.height(), |
1592 capturer_->IsScreencast()); | 1627 capturer_is_screencast_); |
1593 last_rotation_ = video_frame.rotation(); | 1628 last_rotation_ = video_frame.rotation(); |
1594 | 1629 |
1595 stream_->Input()->IncomingCapturedFrame(video_frame); | 1630 stream_->Input()->IncomingCapturedFrame(video_frame); |
1596 } | 1631 } |
1597 | 1632 |
1598 bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetCapturer( | 1633 bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetCapturer( |
1599 VideoCapturer* capturer) { | 1634 VideoCapturer* capturer) { |
1600 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::SetCapturer"); | 1635 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::SetCapturer"); |
1636 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
1601 if (!DisconnectCapturer() && capturer == NULL) { | 1637 if (!DisconnectCapturer() && capturer == NULL) { |
1602 return false; | 1638 return false; |
1603 } | 1639 } |
1604 | 1640 |
1605 { | 1641 { |
1606 rtc::CritScope cs(&lock_); | 1642 rtc::CritScope cs(&lock_); |
1607 | 1643 |
1608 // Reset timestamps to realign new incoming frames to a webrtc timestamp. A | 1644 // 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. | 1645 // new capturer may have a different timestamp delta than the previous one. |
1610 first_frame_timestamp_ms_ = 0; | 1646 first_frame_timestamp_ms_ = 0; |
(...skipping 12 matching lines...) Expand all Loading... | |
1623 // necessary to give this black frame a larger timestamp than the | 1659 // necessary to give this black frame a larger timestamp than the |
1624 // previous one. | 1660 // previous one. |
1625 last_frame_timestamp_ms_ += 1; | 1661 last_frame_timestamp_ms_ += 1; |
1626 black_frame.set_render_time_ms(last_frame_timestamp_ms_); | 1662 black_frame.set_render_time_ms(last_frame_timestamp_ms_); |
1627 stream_->Input()->IncomingCapturedFrame(black_frame); | 1663 stream_->Input()->IncomingCapturedFrame(black_frame); |
1628 } | 1664 } |
1629 | 1665 |
1630 capturer_ = NULL; | 1666 capturer_ = NULL; |
1631 return true; | 1667 return true; |
1632 } | 1668 } |
1633 | 1669 capturer_is_screencast_ = capturer->IsScreencast(); |
1634 capturer_ = capturer; | |
1635 capturer_->AddOrUpdateSink(this, sink_wants_); | |
1636 } | 1670 } |
1671 capturer_ = capturer; | |
1672 capturer_->AddOrUpdateSink(this, sink_wants_); | |
1637 return true; | 1673 return true; |
1638 } | 1674 } |
1639 | 1675 |
1640 void WebRtcVideoChannel2::WebRtcVideoSendStream::MuteStream(bool mute) { | 1676 void WebRtcVideoChannel2::WebRtcVideoSendStream::MuteStream(bool mute) { |
1641 rtc::CritScope cs(&lock_); | 1677 rtc::CritScope cs(&lock_); |
1642 muted_ = mute; | 1678 muted_ = mute; |
1643 } | 1679 } |
1644 | 1680 |
1645 bool WebRtcVideoChannel2::WebRtcVideoSendStream::DisconnectCapturer() { | 1681 bool WebRtcVideoChannel2::WebRtcVideoSendStream::DisconnectCapturer() { |
1646 cricket::VideoCapturer* capturer; | 1682 cricket::VideoCapturer* capturer; |
1647 { | 1683 { |
1648 rtc::CritScope cs(&lock_); | 1684 rtc::CritScope cs(&lock_); |
1649 if (capturer_ == NULL) | 1685 if (capturer_ == NULL) |
1650 return false; | 1686 return false; |
1651 | 1687 |
1652 if (capturer_->video_adapter() != nullptr) | |
1653 old_adapt_changes_ += capturer_->video_adapter()->adaptation_changes(); | |
1654 | |
1655 capturer = capturer_; | 1688 capturer = capturer_; |
1656 capturer_ = NULL; | 1689 capturer_ = NULL; |
1657 } | 1690 } |
1658 capturer->RemoveSink(this); | 1691 capturer->RemoveSink(this); |
1659 | 1692 |
1660 return true; | 1693 return true; |
1661 } | 1694 } |
1662 | 1695 |
1663 const std::vector<uint32_t>& | 1696 const std::vector<uint32_t>& |
1664 WebRtcVideoChannel2::WebRtcVideoSendStream::GetSsrcs() const { | 1697 WebRtcVideoChannel2::WebRtcVideoSendStream::GetSsrcs() const { |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1815 params.options ? *params.options : parameters_.options); | 1848 params.options ? *params.options : parameters_.options); |
1816 return; | 1849 return; |
1817 } else if (params.options) { | 1850 } else if (params.options) { |
1818 // Reconfigure if codecs are already set. | 1851 // Reconfigure if codecs are already set. |
1819 if (parameters_.codec_settings) { | 1852 if (parameters_.codec_settings) { |
1820 SetCodecAndOptions(*parameters_.codec_settings, *params.options); | 1853 SetCodecAndOptions(*parameters_.codec_settings, *params.options); |
1821 return; | 1854 return; |
1822 } else { | 1855 } else { |
1823 parameters_.options = *params.options; | 1856 parameters_.options = *params.options; |
1824 } | 1857 } |
1825 } | 1858 } else if (params.conference_mode && parameters_.codec_settings) { |
1826 else if (params.conference_mode && parameters_.codec_settings) { | |
1827 SetCodecAndOptions(*parameters_.codec_settings, parameters_.options); | 1859 SetCodecAndOptions(*parameters_.codec_settings, parameters_.options); |
1828 return; | 1860 return; |
1829 } | 1861 } |
1830 if (recreate_stream) { | 1862 if (recreate_stream) { |
1831 LOG(LS_INFO) << "RecreateWebRtcStream (send) because of SetSendParameters"; | 1863 LOG(LS_INFO) << "RecreateWebRtcStream (send) because of SetSendParameters"; |
1832 RecreateWebRtcStream(); | 1864 RecreateWebRtcStream(); |
1833 } | 1865 } |
1834 } | 1866 } |
1835 | 1867 |
1836 webrtc::VideoEncoderConfig | 1868 webrtc::VideoEncoderConfig |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1943 } | 1975 } |
1944 | 1976 |
1945 void WebRtcVideoChannel2::WebRtcVideoSendStream::Stop() { | 1977 void WebRtcVideoChannel2::WebRtcVideoSendStream::Stop() { |
1946 rtc::CritScope cs(&lock_); | 1978 rtc::CritScope cs(&lock_); |
1947 if (stream_ != NULL) { | 1979 if (stream_ != NULL) { |
1948 stream_->Stop(); | 1980 stream_->Stop(); |
1949 } | 1981 } |
1950 sending_ = false; | 1982 sending_ = false; |
1951 } | 1983 } |
1952 | 1984 |
1985 void WebRtcVideoChannel2::WebRtcVideoSendStream::OnLoadUpdate(Load load) { | |
1986 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
1987 LOG(LS_INFO) << "OnLoadUpdate " << load; | |
1988 if (!capturer_) { | |
1989 return; | |
1990 } | |
1991 | |
1992 rtc::Optional<int> max_pixel_count; | |
1993 rtc::Optional<int> max_pixel_count_step_up; | |
1994 if (load == kOveruse) { | |
1995 { | |
1996 rtc::CritScope cs(&lock_); | |
1997 max_pixel_count = rtc::Optional<int>( | |
1998 (last_dimensions_.height * last_dimensions_.width) / 2); | |
1999 } | |
2000 if (!sink_wants_.max_pixel_count || | |
2001 *sink_wants_.max_pixel_count != *max_pixel_count) { | |
2002 ++number_of_cpu_adapt_changes_; | |
pthatcher1
2016/02/25 20:20:05
If we track cpu_downgrades_ and cpu_upgrades_, wou
perkj_webrtc
2016/02/26 14:08:25
hum- I think the easiest is to move back the logic
| |
2003 ++cpu_downgrade_counter_; | |
2004 } | |
2005 } else { | |
2006 RTC_DCHECK(load == kUnderuse); | |
2007 if (cpu_downgrade_counter_ > 0) { | |
2008 --cpu_downgrade_counter_; | |
2009 } | |
2010 { | |
2011 rtc::CritScope cs(&lock_); | |
2012 max_pixel_count_step_up = | |
2013 rtc::Optional<int>(last_dimensions_.height * last_dimensions_.width); | |
2014 } | |
2015 if (sink_wants_.max_pixel_count || | |
2016 (sink_wants_.max_pixel_count_step_up && | |
2017 *sink_wants_.max_pixel_count_step_up != *max_pixel_count_step_up)) { | |
2018 ++number_of_cpu_adapt_changes_; | |
2019 } | |
2020 } | |
2021 sink_wants_.max_pixel_count = max_pixel_count; | |
2022 sink_wants_.max_pixel_count_step_up = max_pixel_count_step_up; | |
2023 capturer_->AddOrUpdateSink(this, sink_wants_); | |
2024 } | |
2025 | |
1953 VideoSenderInfo | 2026 VideoSenderInfo |
1954 WebRtcVideoChannel2::WebRtcVideoSendStream::GetVideoSenderInfo() { | 2027 WebRtcVideoChannel2::WebRtcVideoSendStream::GetVideoSenderInfo() { |
1955 VideoSenderInfo info; | 2028 VideoSenderInfo info; |
1956 webrtc::VideoSendStream::Stats stats; | 2029 webrtc::VideoSendStream::Stats stats; |
2030 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
1957 { | 2031 { |
1958 rtc::CritScope cs(&lock_); | 2032 rtc::CritScope cs(&lock_); |
1959 for (uint32_t ssrc : parameters_.config.rtp.ssrcs) | 2033 for (uint32_t ssrc : parameters_.config.rtp.ssrcs) |
1960 info.add_ssrc(ssrc); | 2034 info.add_ssrc(ssrc); |
1961 | 2035 |
1962 if (parameters_.codec_settings) | 2036 if (parameters_.codec_settings) |
1963 info.codec_name = parameters_.codec_settings->codec.name; | 2037 info.codec_name = parameters_.codec_settings->codec.name; |
1964 for (size_t i = 0; i < parameters_.encoder_config.streams.size(); ++i) { | 2038 for (size_t i = 0; i < parameters_.encoder_config.streams.size(); ++i) { |
1965 if (i == parameters_.encoder_config.streams.size() - 1) { | 2039 if (i == parameters_.encoder_config.streams.size() - 1) { |
1966 info.preferred_bitrate += | 2040 info.preferred_bitrate += |
1967 parameters_.encoder_config.streams[i].max_bitrate_bps; | 2041 parameters_.encoder_config.streams[i].max_bitrate_bps; |
1968 } else { | 2042 } else { |
1969 info.preferred_bitrate += | 2043 info.preferred_bitrate += |
1970 parameters_.encoder_config.streams[i].target_bitrate_bps; | 2044 parameters_.encoder_config.streams[i].target_bitrate_bps; |
1971 } | 2045 } |
1972 } | 2046 } |
1973 | 2047 |
1974 if (stream_ == NULL) | 2048 if (stream_ == NULL) |
1975 return info; | 2049 return info; |
1976 | 2050 |
1977 stats = stream_->GetStats(); | 2051 stats = stream_->GetStats(); |
2052 } | |
2053 info.adapt_changes = number_of_cpu_adapt_changes_; | |
2054 info.adapt_reason = cpu_downgrade_counter_ == 0 | |
2055 ? CoordinatedVideoAdapter::ADAPTREASON_NONE | |
2056 : CoordinatedVideoAdapter::ADAPTREASON_CPU; | |
1978 | 2057 |
1979 info.adapt_changes = old_adapt_changes_; | 2058 if (capturer_ != NULL) { |
1980 info.adapt_reason = CoordinatedVideoAdapter::ADAPTREASON_NONE; | 2059 if (!capturer_->IsMuted()) { |
1981 | 2060 VideoFormat last_captured_frame_format; |
1982 if (capturer_ != NULL) { | 2061 capturer_->GetStats(&info.adapt_frame_drops, &info.effects_frame_drops, |
1983 if (!capturer_->IsMuted()) { | 2062 &info.capturer_frame_time, |
1984 VideoFormat last_captured_frame_format; | 2063 &last_captured_frame_format); |
1985 capturer_->GetStats(&info.adapt_frame_drops, &info.effects_frame_drops, | 2064 info.input_frame_width = last_captured_frame_format.width; |
1986 &info.capturer_frame_time, | 2065 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 } | 2066 } |
1996 } | 2067 } |
1997 | 2068 |
1998 // Get bandwidth limitation info from stream_->GetStats(). | 2069 // Get bandwidth limitation info from stream_->GetStats(). |
1999 // Input resolution (output from video_adapter) can be further scaled down or | 2070 // Input resolution (output from video_adapter) can be further scaled down or |
2000 // higher video layer(s) can be dropped due to bitrate constraints. | 2071 // higher video layer(s) can be dropped due to bitrate constraints. |
2001 // Note, adapt_changes only include changes from the video_adapter. | 2072 // Note, adapt_changes only include changes from the video_adapter. |
2002 if (stats.bw_limited_resolution) | 2073 if (stats.bw_limited_resolution) |
2003 info.adapt_reason |= CoordinatedVideoAdapter::ADAPTREASON_BANDWIDTH; | 2074 info.adapt_reason |= CoordinatedVideoAdapter::ADAPTREASON_BANDWIDTH; |
2004 | 2075 |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2504 rtx_mapping[video_codecs[i].codec.id] != | 2575 rtx_mapping[video_codecs[i].codec.id] != |
2505 fec_settings.red_payload_type) { | 2576 fec_settings.red_payload_type) { |
2506 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; | 2577 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; |
2507 } | 2578 } |
2508 } | 2579 } |
2509 | 2580 |
2510 return video_codecs; | 2581 return video_codecs; |
2511 } | 2582 } |
2512 | 2583 |
2513 } // namespace cricket | 2584 } // namespace cricket |
OLD | NEW |