Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: webrtc/media/engine/webrtcvideoengine2.cc

Issue 1695263002: Move direct use of VideoCapturer::VideoAdapter to VideoSinkWants. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 975 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 return false; 986 return false;
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 // |config| must be initialized before WebRtcVideoSendStream since
997 // WebRtcVideoSendStream creates a copy and later change the configuration.
perkj_webrtc 2016/02/15 12:28:00 remove comments.
perkj_webrtc 2016/02/16 11:18:59 Done.
998
996 webrtc::VideoSendStream::Config config(this); 999 webrtc::VideoSendStream::Config config(this);
997 config.overuse_callback = this;
998
999 WebRtcVideoSendStream* stream = new WebRtcVideoSendStream( 1000 WebRtcVideoSendStream* stream = new WebRtcVideoSendStream(
1000 call_, sp, config, external_encoder_factory_, options_, 1001 call_, sp, config,external_encoder_factory_, options_,
1001 bitrate_config_.max_bitrate_bps, send_codec_, send_rtp_extensions_, 1002 signal_cpu_adaptation_, bitrate_config_.max_bitrate_bps, send_codec_,
1002 send_params_); 1003 send_rtp_extensions_, send_params_);
1003
1004 uint32_t ssrc = sp.first_ssrc(); 1004 uint32_t ssrc = sp.first_ssrc();
1005 RTC_DCHECK(ssrc != 0); 1005 RTC_DCHECK(ssrc != 0);
1006 send_streams_[ssrc] = stream; 1006 send_streams_[ssrc] = stream;
1007 1007
1008 if (rtcp_receiver_report_ssrc_ == kDefaultRtcpReceiverReportSsrc) { 1008 if (rtcp_receiver_report_ssrc_ == kDefaultRtcpReceiverReportSsrc) {
1009 rtcp_receiver_report_ssrc_ = ssrc; 1009 rtcp_receiver_report_ssrc_ = ssrc;
1010 LOG(LS_INFO) << "SetLocalSsrc on all the receive streams because we added " 1010 LOG(LS_INFO) << "SetLocalSsrc on all the receive streams because we added "
1011 "a send stream."; 1011 "a send stream.";
1012 for (auto& kv : receive_streams_) 1012 for (auto& kv : receive_streams_)
1013 kv.second->SetLocalSsrc(ssrc); 1013 kv.second->SetLocalSsrc(ssrc);
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
1391 1391
1392 // Speculative change to increase the outbound socket buffer size. 1392 // Speculative change to increase the outbound socket buffer size.
1393 // In b/15152257, we are seeing a significant number of packets discarded 1393 // 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 1394 // due to lack of socket buffer space, although it's not yet clear what the
1395 // ideal value should be. 1395 // ideal value should be.
1396 MediaChannel::SetOption(NetworkInterface::ST_RTP, 1396 MediaChannel::SetOption(NetworkInterface::ST_RTP,
1397 rtc::Socket::OPT_SNDBUF, 1397 rtc::Socket::OPT_SNDBUF,
1398 kVideoRtpBufferSize); 1398 kVideoRtpBufferSize);
1399 } 1399 }
1400 1400
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, 1401 bool WebRtcVideoChannel2::SendRtp(const uint8_t* data,
1422 size_t len, 1402 size_t len,
1423 const webrtc::PacketOptions& options) { 1403 const webrtc::PacketOptions& options) {
1424 rtc::Buffer packet(data, len, kMaxRtpPacketLen); 1404 rtc::Buffer packet(data, len, kMaxRtpPacketLen);
1425 rtc::PacketOptions rtc_options; 1405 rtc::PacketOptions rtc_options;
1426 rtc_options.packet_id = options.packet_id; 1406 rtc_options.packet_id = options.packet_id;
1427 return MediaChannel::SendPacket(&packet, rtc_options); 1407 return MediaChannel::SendPacket(&packet, rtc_options);
1428 } 1408 }
1429 1409
1430 bool WebRtcVideoChannel2::SendRtcp(const uint8_t* data, size_t len) { 1410 bool WebRtcVideoChannel2::SendRtcp(const uint8_t* data, size_t len) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1475 new webrtc::VideoEncoderSoftwareFallbackWrapper(type, encoder); 1455 new webrtc::VideoEncoderSoftwareFallbackWrapper(type, encoder);
1476 } 1456 }
1477 } 1457 }
1478 1458
1479 WebRtcVideoChannel2::WebRtcVideoSendStream::WebRtcVideoSendStream( 1459 WebRtcVideoChannel2::WebRtcVideoSendStream::WebRtcVideoSendStream(
1480 webrtc::Call* call, 1460 webrtc::Call* call,
1481 const StreamParams& sp, 1461 const StreamParams& sp,
1482 const webrtc::VideoSendStream::Config& config, 1462 const webrtc::VideoSendStream::Config& config,
1483 WebRtcVideoEncoderFactory* external_encoder_factory, 1463 WebRtcVideoEncoderFactory* external_encoder_factory,
1484 const VideoOptions& options, 1464 const VideoOptions& options,
1465 bool enable_cpu_overuse_detection,
1485 int max_bitrate_bps, 1466 int max_bitrate_bps,
1486 const rtc::Optional<VideoCodecSettings>& codec_settings, 1467 const rtc::Optional<VideoCodecSettings>& codec_settings,
1487 const std::vector<webrtc::RtpExtension>& rtp_extensions, 1468 const std::vector<webrtc::RtpExtension>& rtp_extensions,
1488 // TODO(deadbeef): Don't duplicate information between send_params, 1469 // TODO(deadbeef): Don't duplicate information between send_params,
1489 // rtp_extensions, options, etc. 1470 // rtp_extensions, options, etc.
1490 const VideoSendParameters& send_params) 1471 const VideoSendParameters& send_params)
1491 : ssrcs_(sp.ssrcs), 1472 : ssrcs_(sp.ssrcs),
1492 ssrc_groups_(sp.ssrc_groups), 1473 ssrc_groups_(sp.ssrc_groups),
1493 call_(call), 1474 call_(call),
1494 external_encoder_factory_(external_encoder_factory), 1475 external_encoder_factory_(external_encoder_factory),
(...skipping 10 matching lines...) Expand all
1505 parameters_.config.rtp.max_packet_size = kVideoMtu; 1486 parameters_.config.rtp.max_packet_size = kVideoMtu;
1506 1487
1507 sp.GetPrimarySsrcs(&parameters_.config.rtp.ssrcs); 1488 sp.GetPrimarySsrcs(&parameters_.config.rtp.ssrcs);
1508 sp.GetFidSsrcs(parameters_.config.rtp.ssrcs, 1489 sp.GetFidSsrcs(parameters_.config.rtp.ssrcs,
1509 &parameters_.config.rtp.rtx.ssrcs); 1490 &parameters_.config.rtp.rtx.ssrcs);
1510 parameters_.config.rtp.c_name = sp.cname; 1491 parameters_.config.rtp.c_name = sp.cname;
1511 parameters_.config.rtp.extensions = rtp_extensions; 1492 parameters_.config.rtp.extensions = rtp_extensions;
1512 parameters_.config.rtp.rtcp_mode = send_params.rtcp.reduced_size 1493 parameters_.config.rtp.rtcp_mode = send_params.rtcp.reduced_size
1513 ? webrtc::RtcpMode::kReducedSize 1494 ? webrtc::RtcpMode::kReducedSize
1514 : webrtc::RtcpMode::kCompound; 1495 : webrtc::RtcpMode::kCompound;
1496 parameters_.config.overuse_callback = enable_cpu_overuse_detection ?
1497 this : nullptr;
1515 1498
1516 if (codec_settings) { 1499 if (codec_settings) {
1517 SetCodecAndOptions(*codec_settings, parameters_.options); 1500 SetCodecAndOptions(*codec_settings, parameters_.options);
1518 } 1501 }
1519 } 1502 }
1520 1503
1521 WebRtcVideoChannel2::WebRtcVideoSendStream::~WebRtcVideoSendStream() { 1504 WebRtcVideoChannel2::WebRtcVideoSendStream::~WebRtcVideoSendStream() {
1522 DisconnectCapturer(); 1505 DisconnectCapturer();
1523 if (stream_ != NULL) { 1506 if (stream_ != NULL) {
1524 call_->DestroyVideoSendStream(stream_); 1507 call_->DestroyVideoSendStream(stream_);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1628 muted_ = mute; 1611 muted_ = mute;
1629 } 1612 }
1630 1613
1631 bool WebRtcVideoChannel2::WebRtcVideoSendStream::DisconnectCapturer() { 1614 bool WebRtcVideoChannel2::WebRtcVideoSendStream::DisconnectCapturer() {
1632 cricket::VideoCapturer* capturer; 1615 cricket::VideoCapturer* capturer;
1633 { 1616 {
1634 rtc::CritScope cs(&lock_); 1617 rtc::CritScope cs(&lock_);
1635 if (capturer_ == NULL) 1618 if (capturer_ == NULL)
1636 return false; 1619 return false;
1637 1620
1638 if (capturer_->video_adapter() != nullptr)
1639 old_adapt_changes_ += capturer_->video_adapter()->adaptation_changes();
1640
1641 capturer = capturer_; 1621 capturer = capturer_;
1642 capturer_ = NULL; 1622 capturer_ = NULL;
1643 } 1623 }
1644 capturer->RemoveSink(this); 1624 capturer->RemoveSink(this);
1645 1625
1646 return true; 1626 return true;
1647 } 1627 }
1648 1628
1649 const std::vector<uint32_t>& 1629 const std::vector<uint32_t>&
1650 WebRtcVideoChannel2::WebRtcVideoSendStream::GetSsrcs() const { 1630 WebRtcVideoChannel2::WebRtcVideoSendStream::GetSsrcs() const {
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
1922 } 1902 }
1923 1903
1924 void WebRtcVideoChannel2::WebRtcVideoSendStream::Stop() { 1904 void WebRtcVideoChannel2::WebRtcVideoSendStream::Stop() {
1925 rtc::CritScope cs(&lock_); 1905 rtc::CritScope cs(&lock_);
1926 if (stream_ != NULL) { 1906 if (stream_ != NULL) {
1927 stream_->Stop(); 1907 stream_->Stop();
1928 } 1908 }
1929 sending_ = false; 1909 sending_ = false;
1930 } 1910 }
1931 1911
1912 void WebRtcVideoChannel2::WebRtcVideoSendStream::OnLoadUpdate(Load load) {
1913 rtc::CritScope cs(&lock_);
1914 if (!capturer_)
1915 return;
1916 rtc::VideoSinkWants wants = sink_wants_;
1917 wants.resolution = load == kOveruse ? rtc::VideoSinkWants::Resolution::DOWN :
1918 rtc::VideoSinkWants::Resolution::UP;
1919 capturer_->AddOrUpdateSink(this, wants);
perkj_webrtc 2016/02/15 12:28:00 This will actually currently not work since OnLoad
1920 }
perkj_webrtc 2016/02/15 12:28:00 Also- Would it make more sense to store an absolut
nisse-webrtc 2016/02/17 08:19:46 I think so. (Or a scale factor, also with the logi
perkj_webrtc 2016/02/17 17:16:29 Moved logic from CoordinatedVideoAdapter to here.
1921
1932 VideoSenderInfo 1922 VideoSenderInfo
1933 WebRtcVideoChannel2::WebRtcVideoSendStream::GetVideoSenderInfo() { 1923 WebRtcVideoChannel2::WebRtcVideoSendStream::GetVideoSenderInfo() {
1934 VideoSenderInfo info; 1924 VideoSenderInfo info;
1935 webrtc::VideoSendStream::Stats stats; 1925 webrtc::VideoSendStream::Stats stats;
1936 { 1926 {
1937 rtc::CritScope cs(&lock_); 1927 rtc::CritScope cs(&lock_);
1938 for (uint32_t ssrc : parameters_.config.rtp.ssrcs) 1928 for (uint32_t ssrc : parameters_.config.rtp.ssrcs)
1939 info.add_ssrc(ssrc); 1929 info.add_ssrc(ssrc);
1940 1930
1941 if (parameters_.codec_settings) 1931 if (parameters_.codec_settings)
(...skipping 18 matching lines...) Expand all
1960 1950
1961 if (capturer_ != NULL) { 1951 if (capturer_ != NULL) {
1962 if (!capturer_->IsMuted()) { 1952 if (!capturer_->IsMuted()) {
1963 VideoFormat last_captured_frame_format; 1953 VideoFormat last_captured_frame_format;
1964 capturer_->GetStats(&info.adapt_frame_drops, &info.effects_frame_drops, 1954 capturer_->GetStats(&info.adapt_frame_drops, &info.effects_frame_drops,
1965 &info.capturer_frame_time, 1955 &info.capturer_frame_time,
1966 &last_captured_frame_format); 1956 &last_captured_frame_format);
1967 info.input_frame_width = last_captured_frame_format.width; 1957 info.input_frame_width = last_captured_frame_format.width;
1968 info.input_frame_height = last_captured_frame_format.height; 1958 info.input_frame_height = last_captured_frame_format.height;
1969 } 1959 }
1970 if (capturer_->video_adapter() != nullptr) {
1971 info.adapt_changes += capturer_->video_adapter()->adaptation_changes();
perkj_webrtc 2016/02/15 12:28:00 where do we want this type of stats to take place?
perkj_webrtc 2016/02/16 11:18:59 Now added a proxy. See comments in asyncproxy.h
1972 info.adapt_reason = capturer_->video_adapter()->adapt_reason();
1973 }
1974 } 1960 }
1975 } 1961 }
1976 1962
1977 // Get bandwidth limitation info from stream_->GetStats(). 1963 // Get bandwidth limitation info from stream_->GetStats().
1978 // Input resolution (output from video_adapter) can be further scaled down or 1964 // Input resolution (output from video_adapter) can be further scaled down or
1979 // higher video layer(s) can be dropped due to bitrate constraints. 1965 // higher video layer(s) can be dropped due to bitrate constraints.
1980 // Note, adapt_changes only include changes from the video_adapter. 1966 // Note, adapt_changes only include changes from the video_adapter.
1981 if (stats.bw_limited_resolution) 1967 if (stats.bw_limited_resolution)
1982 info.adapt_reason |= CoordinatedVideoAdapter::ADAPTREASON_BANDWIDTH; 1968 info.adapt_reason |= CoordinatedVideoAdapter::ADAPTREASON_BANDWIDTH;
1983 1969
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
2483 rtx_mapping[video_codecs[i].codec.id] != 2469 rtx_mapping[video_codecs[i].codec.id] !=
2484 fec_settings.red_payload_type) { 2470 fec_settings.red_payload_type) {
2485 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; 2471 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id];
2486 } 2472 }
2487 } 2473 }
2488 2474
2489 return video_codecs; 2475 return video_codecs;
2490 } 2476 }
2491 2477
2492 } // namespace cricket 2478 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698