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

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

Issue 2067103002: Avoid unnecessary HW video encoder reconfiguration (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: ReconfigureEncoderIfNecessary -> ReconfigureEncoder() Created 4 years, 6 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
« no previous file with comments | « webrtc/media/engine/webrtcvideoengine2.h ('k') | webrtc/video/video_send_stream.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 730 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 } 741 }
742 742
743 if (!send_codec_ || supported_codecs.front() != *send_codec_) { 743 if (!send_codec_ || supported_codecs.front() != *send_codec_) {
744 changed_params->codec = 744 changed_params->codec =
745 rtc::Optional<VideoCodecSettings>(supported_codecs.front()); 745 rtc::Optional<VideoCodecSettings>(supported_codecs.front());
746 } 746 }
747 747
748 // Handle RTP header extensions. 748 // Handle RTP header extensions.
749 std::vector<webrtc::RtpExtension> filtered_extensions = FilterRtpExtensions( 749 std::vector<webrtc::RtpExtension> filtered_extensions = FilterRtpExtensions(
750 params.extensions, webrtc::RtpExtension::IsSupportedForVideo, true); 750 params.extensions, webrtc::RtpExtension::IsSupportedForVideo, true);
751 if (send_rtp_extensions_ != filtered_extensions) { 751 if (!send_rtp_extensions_ || (*send_rtp_extensions_ != filtered_extensions)) {
752 changed_params->rtp_header_extensions = 752 changed_params->rtp_header_extensions =
753 rtc::Optional<std::vector<webrtc::RtpExtension>>(filtered_extensions); 753 rtc::Optional<std::vector<webrtc::RtpExtension>>(filtered_extensions);
754 } 754 }
755 755
756 // Handle max bitrate. 756 // Handle max bitrate.
757 if (params.max_bandwidth_bps != send_params_.max_bandwidth_bps && 757 if (params.max_bandwidth_bps != send_params_.max_bandwidth_bps &&
758 params.max_bandwidth_bps >= 0) { 758 params.max_bandwidth_bps >= 0) {
759 // 0 uncaps max bitrate (-1). 759 // 0 uncaps max bitrate (-1).
760 changed_params->max_bandwidth_bps = rtc::Optional<int>( 760 changed_params->max_bandwidth_bps = rtc::Optional<int>(
761 params.max_bandwidth_bps == 0 ? -1 : params.max_bandwidth_bps); 761 params.max_bandwidth_bps == 0 ? -1 : params.max_bandwidth_bps);
(...skipping 27 matching lines...) Expand all
789 return false; 789 return false;
790 } 790 }
791 791
792 if (changed_params.codec) { 792 if (changed_params.codec) {
793 const VideoCodecSettings& codec_settings = *changed_params.codec; 793 const VideoCodecSettings& codec_settings = *changed_params.codec;
794 send_codec_ = rtc::Optional<VideoCodecSettings>(codec_settings); 794 send_codec_ = rtc::Optional<VideoCodecSettings>(codec_settings);
795 LOG(LS_INFO) << "Using codec: " << codec_settings.codec.ToString(); 795 LOG(LS_INFO) << "Using codec: " << codec_settings.codec.ToString();
796 } 796 }
797 797
798 if (changed_params.rtp_header_extensions) { 798 if (changed_params.rtp_header_extensions) {
799 send_rtp_extensions_ = *changed_params.rtp_header_extensions; 799 send_rtp_extensions_ = changed_params.rtp_header_extensions;
800 } 800 }
801 801
802 if (changed_params.codec || changed_params.max_bandwidth_bps) { 802 if (changed_params.codec || changed_params.max_bandwidth_bps) {
803 if (send_codec_) { 803 if (send_codec_) {
804 // TODO(holmer): Changing the codec parameters shouldn't necessarily mean 804 // TODO(holmer): Changing the codec parameters shouldn't necessarily mean
805 // that we change the min/max of bandwidth estimation. Reevaluate this. 805 // that we change the min/max of bandwidth estimation. Reevaluate this.
806 bitrate_config_ = GetBitrateConfigForCodec(send_codec_->codec); 806 bitrate_config_ = GetBitrateConfigForCodec(send_codec_->codec);
807 if (!changed_params.codec) { 807 if (!changed_params.codec) {
808 // If the codec isn't changing, set the start bitrate to -1 which means 808 // If the codec isn't changing, set the start bitrate to -1 which means
809 // "unchanged" so that BWE isn't affected. 809 // "unchanged" so that BWE isn't affected.
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after
1513 1513
1514 WebRtcVideoChannel2::WebRtcVideoSendStream::WebRtcVideoSendStream( 1514 WebRtcVideoChannel2::WebRtcVideoSendStream::WebRtcVideoSendStream(
1515 webrtc::Call* call, 1515 webrtc::Call* call,
1516 const StreamParams& sp, 1516 const StreamParams& sp,
1517 const webrtc::VideoSendStream::Config& config, 1517 const webrtc::VideoSendStream::Config& config,
1518 const VideoOptions& options, 1518 const VideoOptions& options,
1519 WebRtcVideoEncoderFactory* external_encoder_factory, 1519 WebRtcVideoEncoderFactory* external_encoder_factory,
1520 bool enable_cpu_overuse_detection, 1520 bool enable_cpu_overuse_detection,
1521 int max_bitrate_bps, 1521 int max_bitrate_bps,
1522 const rtc::Optional<VideoCodecSettings>& codec_settings, 1522 const rtc::Optional<VideoCodecSettings>& codec_settings,
1523 const std::vector<webrtc::RtpExtension>& rtp_extensions, 1523 const rtc::Optional<std::vector<webrtc::RtpExtension>>& rtp_extensions,
1524 // TODO(deadbeef): Don't duplicate information between send_params, 1524 // TODO(deadbeef): Don't duplicate information between send_params,
1525 // rtp_extensions, options, etc. 1525 // rtp_extensions, options, etc.
1526 const VideoSendParameters& send_params) 1526 const VideoSendParameters& send_params)
1527 : worker_thread_(rtc::Thread::Current()), 1527 : worker_thread_(rtc::Thread::Current()),
1528 ssrcs_(sp.ssrcs), 1528 ssrcs_(sp.ssrcs),
1529 ssrc_groups_(sp.ssrc_groups), 1529 ssrc_groups_(sp.ssrc_groups),
1530 call_(call), 1530 call_(call),
1531 cpu_restricted_counter_(0), 1531 cpu_restricted_counter_(0),
1532 number_of_cpu_adapt_changes_(0), 1532 number_of_cpu_adapt_changes_(0),
1533 source_(nullptr), 1533 source_(nullptr),
1534 external_encoder_factory_(external_encoder_factory), 1534 external_encoder_factory_(external_encoder_factory),
1535 stream_(nullptr), 1535 stream_(nullptr),
1536 parameters_(config, options, max_bitrate_bps, codec_settings), 1536 parameters_(config, options, max_bitrate_bps, codec_settings),
1537 rtp_parameters_(CreateRtpParametersWithOneEncoding()), 1537 rtp_parameters_(CreateRtpParametersWithOneEncoding()),
1538 pending_encoder_reconfiguration_(false), 1538 pending_encoder_reconfiguration_(false),
1539 allocated_encoder_(nullptr, webrtc::kVideoCodecUnknown, false), 1539 allocated_encoder_(nullptr, webrtc::kVideoCodecUnknown, false),
1540 sending_(false), 1540 sending_(false),
1541 last_frame_timestamp_ms_(0) { 1541 last_frame_timestamp_ms_(0) {
1542 parameters_.config.rtp.max_packet_size = kVideoMtu; 1542 parameters_.config.rtp.max_packet_size = kVideoMtu;
1543 parameters_.conference_mode = send_params.conference_mode; 1543 parameters_.conference_mode = send_params.conference_mode;
1544 1544
1545 sp.GetPrimarySsrcs(&parameters_.config.rtp.ssrcs); 1545 sp.GetPrimarySsrcs(&parameters_.config.rtp.ssrcs);
1546 sp.GetFidSsrcs(parameters_.config.rtp.ssrcs, 1546 sp.GetFidSsrcs(parameters_.config.rtp.ssrcs,
1547 &parameters_.config.rtp.rtx.ssrcs); 1547 &parameters_.config.rtp.rtx.ssrcs);
1548 parameters_.config.rtp.c_name = sp.cname; 1548 parameters_.config.rtp.c_name = sp.cname;
1549 parameters_.config.rtp.extensions = rtp_extensions; 1549 if (rtp_extensions) {
1550 parameters_.config.rtp.extensions = *rtp_extensions;
1551 }
1550 parameters_.config.rtp.rtcp_mode = send_params.rtcp.reduced_size 1552 parameters_.config.rtp.rtcp_mode = send_params.rtcp.reduced_size
1551 ? webrtc::RtcpMode::kReducedSize 1553 ? webrtc::RtcpMode::kReducedSize
1552 : webrtc::RtcpMode::kCompound; 1554 : webrtc::RtcpMode::kCompound;
1553 parameters_.config.overuse_callback = 1555 parameters_.config.overuse_callback =
1554 enable_cpu_overuse_detection ? this : nullptr; 1556 enable_cpu_overuse_detection ? this : nullptr;
1555 1557
1556 sink_wants_.rotation_applied = !ContainsHeaderExtension( 1558 // Only request rotation at the source when we positively know that the remote
1557 rtp_extensions, webrtc::RtpExtension::kVideoRotationUri); 1559 // side doesn't support the rotation extension. This allows us to prepare the
1560 // encoder in the expectation that rotation is supported - which is the common
1561 // case.
1562 sink_wants_.rotation_applied =
1563 rtp_extensions &&
1564 !ContainsHeaderExtension(*rtp_extensions,
1565 webrtc::RtpExtension::kVideoRotationUri);
1558 1566
1559 if (codec_settings) { 1567 if (codec_settings) {
1560 SetCodec(*codec_settings); 1568 SetCodec(*codec_settings);
1561 } 1569 }
1562 } 1570 }
1563 1571
1564 WebRtcVideoChannel2::WebRtcVideoSendStream::~WebRtcVideoSendStream() { 1572 WebRtcVideoChannel2::WebRtcVideoSendStream::~WebRtcVideoSendStream() {
1565 DisconnectSource(); 1573 DisconnectSource();
1566 if (stream_ != NULL) { 1574 if (stream_ != NULL) {
1567 call_->DestroyVideoSendStream(stream_); 1575 call_->DestroyVideoSendStream(stream_);
(...skipping 18 matching lines...) Expand all
1586 frame.set_render_time_ms(render_time_ms_); 1594 frame.set_render_time_ms(render_time_ms_);
1587 return frame; 1595 return frame;
1588 } 1596 }
1589 1597
1590 void WebRtcVideoChannel2::WebRtcVideoSendStream::OnFrame( 1598 void WebRtcVideoChannel2::WebRtcVideoSendStream::OnFrame(
1591 const VideoFrame& frame) { 1599 const VideoFrame& frame) {
1592 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::OnFrame"); 1600 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::OnFrame");
1593 webrtc::VideoFrame video_frame(frame.video_frame_buffer(), 0, 0, 1601 webrtc::VideoFrame video_frame(frame.video_frame_buffer(), 0, 0,
1594 frame.rotation()); 1602 frame.rotation());
1595 rtc::CritScope cs(&lock_); 1603 rtc::CritScope cs(&lock_);
1604
1605 if (video_frame.width() != last_frame_info_.width ||
1606 video_frame.height() != last_frame_info_.height ||
1607 video_frame.rotation() != last_frame_info_.rotation ||
1608 video_frame.is_texture() != last_frame_info_.is_texture) {
1609 last_frame_info_.width = video_frame.width();
1610 last_frame_info_.height = video_frame.height();
1611 last_frame_info_.rotation = video_frame.rotation();
1612 last_frame_info_.is_texture = video_frame.is_texture();
1613 pending_encoder_reconfiguration_ = true;
1614
1615 LOG(LS_INFO) << "Video frame parameters changed: dimensions="
1616 << last_frame_info_.width << "x" << last_frame_info_.height
1617 << ", rotation=" << last_frame_info_.rotation
1618 << ", texture=" << last_frame_info_.is_texture;
1619 }
1620
1596 if (stream_ == NULL) { 1621 if (stream_ == NULL) {
1597 // Frame input before send codecs are configured, dropping frame. 1622 // Frame input before send codecs are configured, dropping frame.
1598 return; 1623 return;
1599 } 1624 }
1600 1625
1601 int64_t frame_delta_ms = frame.GetTimeStamp() / rtc::kNumNanosecsPerMillisec; 1626 int64_t frame_delta_ms = frame.GetTimeStamp() / rtc::kNumNanosecsPerMillisec;
1602 1627
1603 // frame->GetTimeStamp() is essentially a delta, align to webrtc time 1628 // frame->GetTimeStamp() is essentially a delta, align to webrtc time
1604 if (!first_frame_timestamp_ms_) { 1629 if (!first_frame_timestamp_ms_) {
1605 first_frame_timestamp_ms_ = 1630 first_frame_timestamp_ms_ =
1606 rtc::Optional<int64_t>(rtc::TimeMillis() - frame_delta_ms); 1631 rtc::Optional<int64_t>(rtc::TimeMillis() - frame_delta_ms);
1607 } 1632 }
1608 1633
1609 last_frame_timestamp_ms_ = *first_frame_timestamp_ms_ + frame_delta_ms; 1634 last_frame_timestamp_ms_ = *first_frame_timestamp_ms_ + frame_delta_ms;
1610 1635
1611 video_frame.set_render_time_ms(last_frame_timestamp_ms_); 1636 video_frame.set_render_time_ms(last_frame_timestamp_ms_);
1612 // Reconfigure codec if necessary. 1637
1613 SetDimensions(video_frame.width(), video_frame.height()); 1638 if (pending_encoder_reconfiguration_) {
1614 last_rotation_ = video_frame.rotation(); 1639 ReconfigureEncoder();
1640 pending_encoder_reconfiguration_ = false;
1641 }
1615 1642
1616 // Not sending, abort after reconfiguration. Reconfiguration should still 1643 // Not sending, abort after reconfiguration. Reconfiguration should still
1617 // occur to permit sending this input as quickly as possible once we start 1644 // occur to permit sending this input as quickly as possible once we start
1618 // sending (without having to reconfigure then). 1645 // sending (without having to reconfigure then).
1619 if (!sending_) { 1646 if (!sending_) {
1620 return; 1647 return;
1621 } 1648 }
1622 1649
1623 stream_->Input()->IncomingCapturedFrame(video_frame); 1650 stream_->Input()->IncomingCapturedFrame(video_frame);
1624 } 1651 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1657 first_frame_timestamp_ms_ = rtc::Optional<int64_t>(); 1684 first_frame_timestamp_ms_ = rtc::Optional<int64_t>();
1658 1685
1659 if (source == nullptr && stream_ != nullptr) { 1686 if (source == nullptr && stream_ != nullptr) {
1660 LOG(LS_VERBOSE) << "Disabling capturer, sending black frame."; 1687 LOG(LS_VERBOSE) << "Disabling capturer, sending black frame.";
1661 // Force this black frame not to be dropped due to timestamp order 1688 // Force this black frame not to be dropped due to timestamp order
1662 // check. As IncomingCapturedFrame will drop the frame if this frame's 1689 // check. As IncomingCapturedFrame will drop the frame if this frame's
1663 // timestamp is less than or equal to last frame's timestamp, it is 1690 // timestamp is less than or equal to last frame's timestamp, it is
1664 // necessary to give this black frame a larger timestamp than the 1691 // necessary to give this black frame a larger timestamp than the
1665 // previous one. 1692 // previous one.
1666 last_frame_timestamp_ms_ += 1; 1693 last_frame_timestamp_ms_ += 1;
1667 stream_->Input()->IncomingCapturedFrame( 1694 stream_->Input()->IncomingCapturedFrame(CreateBlackFrame(
1668 CreateBlackFrame(last_dimensions_.width, last_dimensions_.height, 1695 last_frame_info_.width, last_frame_info_.height,
1669 last_frame_timestamp_ms_, last_rotation_)); 1696 last_frame_timestamp_ms_, last_frame_info_.rotation));
1670 } 1697 }
1671 source_ = source; 1698 source_ = source;
1672 } 1699 }
1673 } 1700 }
1674 1701
1675 // |source_->AddOrUpdateSink| may not be called while holding |lock_| since 1702 // |source_->AddOrUpdateSink| may not be called while holding |lock_| since
1676 // that might cause a lock order inversion. 1703 // that might cause a lock order inversion.
1677 if (source_changing && source_) { 1704 if (source_changing && source_) {
1678 source_->AddOrUpdateSink(this, sink_wants_); 1705 source_->AddOrUpdateSink(this, sink_wants_);
1679 } 1706 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1751 void WebRtcVideoChannel2::WebRtcVideoSendStream::DestroyVideoEncoder( 1778 void WebRtcVideoChannel2::WebRtcVideoSendStream::DestroyVideoEncoder(
1752 AllocatedEncoder* encoder) { 1779 AllocatedEncoder* encoder) {
1753 if (encoder->external) { 1780 if (encoder->external) {
1754 external_encoder_factory_->DestroyVideoEncoder(encoder->external_encoder); 1781 external_encoder_factory_->DestroyVideoEncoder(encoder->external_encoder);
1755 } 1782 }
1756 delete encoder->encoder; 1783 delete encoder->encoder;
1757 } 1784 }
1758 1785
1759 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetCodec( 1786 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetCodec(
1760 const VideoCodecSettings& codec_settings) { 1787 const VideoCodecSettings& codec_settings) {
1761 parameters_.encoder_config = 1788 parameters_.encoder_config = CreateVideoEncoderConfig(codec_settings.codec);
1762 CreateVideoEncoderConfig(last_dimensions_, codec_settings.codec);
1763 RTC_DCHECK(!parameters_.encoder_config.streams.empty()); 1789 RTC_DCHECK(!parameters_.encoder_config.streams.empty());
1764 1790
1765 AllocatedEncoder new_encoder = CreateVideoEncoder(codec_settings.codec); 1791 AllocatedEncoder new_encoder = CreateVideoEncoder(codec_settings.codec);
1766 parameters_.config.encoder_settings.encoder = new_encoder.encoder; 1792 parameters_.config.encoder_settings.encoder = new_encoder.encoder;
1767 parameters_.config.encoder_settings.full_overuse_time = new_encoder.external; 1793 parameters_.config.encoder_settings.full_overuse_time = new_encoder.external;
1768 parameters_.config.encoder_settings.payload_name = codec_settings.codec.name; 1794 parameters_.config.encoder_settings.payload_name = codec_settings.codec.name;
1769 parameters_.config.encoder_settings.payload_type = codec_settings.codec.id; 1795 parameters_.config.encoder_settings.payload_type = codec_settings.codec.id;
1770 if (new_encoder.external) { 1796 if (new_encoder.external) {
1771 webrtc::VideoCodecType type = CodecTypeFromName(codec_settings.codec.name); 1797 webrtc::VideoCodecType type = CodecTypeFromName(codec_settings.codec.name);
1772 parameters_.config.encoder_settings.internal_source = 1798 parameters_.config.encoder_settings.internal_source =
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1891 stream_->Start(); 1917 stream_->Start();
1892 } else { 1918 } else {
1893 if (stream_ != nullptr) { 1919 if (stream_ != nullptr) {
1894 stream_->Stop(); 1920 stream_->Stop();
1895 } 1921 }
1896 } 1922 }
1897 } 1923 }
1898 1924
1899 webrtc::VideoEncoderConfig 1925 webrtc::VideoEncoderConfig
1900 WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoEncoderConfig( 1926 WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoEncoderConfig(
1901 const Dimensions& dimensions,
1902 const VideoCodec& codec) const { 1927 const VideoCodec& codec) const {
1903 webrtc::VideoEncoderConfig encoder_config; 1928 webrtc::VideoEncoderConfig encoder_config;
1904 bool is_screencast = parameters_.options.is_screencast.value_or(false); 1929 bool is_screencast = parameters_.options.is_screencast.value_or(false);
1905 if (is_screencast) { 1930 if (is_screencast) {
1906 encoder_config.min_transmit_bitrate_bps = 1931 encoder_config.min_transmit_bitrate_bps =
1907 1000 * parameters_.options.screencast_min_bitrate_kbps.value_or(0); 1932 1000 * parameters_.options.screencast_min_bitrate_kbps.value_or(0);
1908 encoder_config.content_type = 1933 encoder_config.content_type =
1909 webrtc::VideoEncoderConfig::ContentType::kScreen; 1934 webrtc::VideoEncoderConfig::ContentType::kScreen;
1910 } else { 1935 } else {
1911 encoder_config.min_transmit_bitrate_bps = 0; 1936 encoder_config.min_transmit_bitrate_bps = 0;
1912 encoder_config.content_type = 1937 encoder_config.content_type =
1913 webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo; 1938 webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo;
1914 } 1939 }
1915 1940
1916 // Restrict dimensions according to codec max. 1941 // Restrict dimensions according to codec max.
1917 int width = dimensions.width; 1942 int width = last_frame_info_.width;
1918 int height = dimensions.height; 1943 int height = last_frame_info_.height;
1919 if (!is_screencast) { 1944 if (!is_screencast) {
1920 if (codec.width < width) 1945 if (codec.width < width)
1921 width = codec.width; 1946 width = codec.width;
1922 if (codec.height < height) 1947 if (codec.height < height)
1923 height = codec.height; 1948 height = codec.height;
1924 } 1949 }
1925 1950
1926 VideoCodec clamped_codec = codec; 1951 VideoCodec clamped_codec = codec;
1927 clamped_codec.width = width; 1952 clamped_codec.width = width;
1928 clamped_codec.height = height; 1953 clamped_codec.height = height;
1929 1954
1930 // By default, the stream count for the codec configuration should match the 1955 // By default, the stream count for the codec configuration should match the
1931 // number of negotiated ssrcs. But if the codec is blacklisted for simulcast 1956 // number of negotiated ssrcs. But if the codec is blacklisted for simulcast
1932 // or a screencast, only configure a single stream. 1957 // or a screencast, only configure a single stream.
1933 size_t stream_count = parameters_.config.rtp.ssrcs.size(); 1958 size_t stream_count = parameters_.config.rtp.ssrcs.size();
1934 if (IsCodecBlacklistedForSimulcast(codec.name) || is_screencast) { 1959 if (IsCodecBlacklistedForSimulcast(codec.name) || is_screencast) {
1935 stream_count = 1; 1960 stream_count = 1;
1936 } 1961 }
1937 1962
1938 int stream_max_bitrate = 1963 int stream_max_bitrate =
1939 MinPositive(rtp_parameters_.encodings[0].max_bitrate_bps, 1964 MinPositive(rtp_parameters_.encodings[0].max_bitrate_bps,
1940 parameters_.max_bitrate_bps); 1965 parameters_.max_bitrate_bps);
1941 encoder_config.streams = CreateVideoStreams( 1966 encoder_config.streams = CreateVideoStreams(
1942 clamped_codec, parameters_.options, stream_max_bitrate, stream_count); 1967 clamped_codec, parameters_.options, stream_max_bitrate, stream_count);
1968 encoder_config.expect_encode_from_texture = last_frame_info_.is_texture;
1943 1969
1944 // Conference mode screencast uses 2 temporal layers split at 100kbit. 1970 // Conference mode screencast uses 2 temporal layers split at 100kbit.
1945 if (parameters_.conference_mode && is_screencast && 1971 if (parameters_.conference_mode && is_screencast &&
1946 encoder_config.streams.size() == 1) { 1972 encoder_config.streams.size() == 1) {
1947 ScreenshareLayerConfig config = ScreenshareLayerConfig::GetDefault(); 1973 ScreenshareLayerConfig config = ScreenshareLayerConfig::GetDefault();
1948 1974
1949 // For screenshare in conference mode, tl0 and tl1 bitrates are piggybacked 1975 // For screenshare in conference mode, tl0 and tl1 bitrates are piggybacked
1950 // on the VideoCodec struct as target and max bitrates, respectively. 1976 // on the VideoCodec struct as target and max bitrates, respectively.
1951 // See eg. webrtc::VP8EncoderImpl::SetRates(). 1977 // See eg. webrtc::VP8EncoderImpl::SetRates().
1952 encoder_config.streams[0].target_bitrate_bps = 1978 encoder_config.streams[0].target_bitrate_bps =
1953 config.tl0_bitrate_kbps * 1000; 1979 config.tl0_bitrate_kbps * 1000;
1954 encoder_config.streams[0].max_bitrate_bps = config.tl1_bitrate_kbps * 1000; 1980 encoder_config.streams[0].max_bitrate_bps = config.tl1_bitrate_kbps * 1000;
1955 encoder_config.streams[0].temporal_layer_thresholds_bps.clear(); 1981 encoder_config.streams[0].temporal_layer_thresholds_bps.clear();
1956 encoder_config.streams[0].temporal_layer_thresholds_bps.push_back( 1982 encoder_config.streams[0].temporal_layer_thresholds_bps.push_back(
1957 config.tl0_bitrate_kbps * 1000); 1983 config.tl0_bitrate_kbps * 1000);
1958 } 1984 }
1959 if (CodecNamesEq(codec.name, kVp9CodecName) && !is_screencast && 1985 if (CodecNamesEq(codec.name, kVp9CodecName) && !is_screencast &&
1960 encoder_config.streams.size() == 1) { 1986 encoder_config.streams.size() == 1) {
1961 encoder_config.streams[0].temporal_layer_thresholds_bps.resize( 1987 encoder_config.streams[0].temporal_layer_thresholds_bps.resize(
1962 GetDefaultVp9TemporalLayers() - 1); 1988 GetDefaultVp9TemporalLayers() - 1);
1963 } 1989 }
1964 return encoder_config; 1990 return encoder_config;
1965 } 1991 }
1966 1992
1967 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetDimensions( 1993 void WebRtcVideoChannel2::WebRtcVideoSendStream::ReconfigureEncoder() {
1968 int width,
1969 int height) {
1970 if (last_dimensions_.width == width && last_dimensions_.height == height &&
1971 !pending_encoder_reconfiguration_) {
1972 // Configured using the same parameters, do not reconfigure.
1973 return;
1974 }
1975
1976 last_dimensions_.width = width;
1977 last_dimensions_.height = height;
1978
1979 RTC_DCHECK(!parameters_.encoder_config.streams.empty()); 1994 RTC_DCHECK(!parameters_.encoder_config.streams.empty());
1980 1995
1981 RTC_CHECK(parameters_.codec_settings); 1996 RTC_CHECK(parameters_.codec_settings);
1982 VideoCodecSettings codec_settings = *parameters_.codec_settings; 1997 VideoCodecSettings codec_settings = *parameters_.codec_settings;
1983 1998
1984 webrtc::VideoEncoderConfig encoder_config = 1999 webrtc::VideoEncoderConfig encoder_config =
1985 CreateVideoEncoderConfig(last_dimensions_, codec_settings.codec); 2000 CreateVideoEncoderConfig(codec_settings.codec);
1986 2001
1987 encoder_config.encoder_specific_settings = ConfigureVideoEncoderSettings( 2002 encoder_config.encoder_specific_settings = ConfigureVideoEncoderSettings(
1988 codec_settings.codec); 2003 codec_settings.codec);
1989 2004
1990 stream_->ReconfigureVideoEncoder(encoder_config); 2005 stream_->ReconfigureVideoEncoder(encoder_config);
1991 2006
1992 encoder_config.encoder_specific_settings = NULL; 2007 encoder_config.encoder_specific_settings = NULL;
1993 pending_encoder_reconfiguration_ = false;
1994 2008
1995 parameters_.encoder_config = encoder_config; 2009 parameters_.encoder_config = encoder_config;
1996 } 2010 }
1997 2011
1998 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetSend(bool send) { 2012 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetSend(bool send) {
1999 rtc::CritScope cs(&lock_); 2013 rtc::CritScope cs(&lock_);
2000 sending_ = send; 2014 sending_ = send;
2001 UpdateSendState(); 2015 UpdateSendState();
2002 } 2016 }
2003 2017
(...skipping 24 matching lines...) Expand all
2028 rtc::Optional<int> max_pixel_count; 2042 rtc::Optional<int> max_pixel_count;
2029 rtc::Optional<int> max_pixel_count_step_up; 2043 rtc::Optional<int> max_pixel_count_step_up;
2030 if (load == kOveruse) { 2044 if (load == kOveruse) {
2031 if (cpu_restricted_counter_ >= kMaxCpuDowngrades) { 2045 if (cpu_restricted_counter_ >= kMaxCpuDowngrades) {
2032 return; 2046 return;
2033 } 2047 }
2034 // The input video frame size will have a resolution with less than or 2048 // The input video frame size will have a resolution with less than or
2035 // equal to |max_pixel_count| depending on how the source can scale the 2049 // equal to |max_pixel_count| depending on how the source can scale the
2036 // input frame size. 2050 // input frame size.
2037 max_pixel_count = rtc::Optional<int>( 2051 max_pixel_count = rtc::Optional<int>(
2038 (last_dimensions_.height * last_dimensions_.width * 3) / 5); 2052 (last_frame_info_.height * last_frame_info_.width * 3) / 5);
2039 // Increase |number_of_cpu_adapt_changes_| if 2053 // Increase |number_of_cpu_adapt_changes_| if
2040 // sink_wants_.max_pixel_count will be changed since 2054 // sink_wants_.max_pixel_count will be changed since
2041 // last time |source_->AddOrUpdateSink| was called. That is, this will 2055 // last time |source_->AddOrUpdateSink| was called. That is, this will
2042 // result in a new request for the source to change resolution. 2056 // result in a new request for the source to change resolution.
2043 if (!sink_wants_.max_pixel_count || 2057 if (!sink_wants_.max_pixel_count ||
2044 *sink_wants_.max_pixel_count > *max_pixel_count) { 2058 *sink_wants_.max_pixel_count > *max_pixel_count) {
2045 ++number_of_cpu_adapt_changes_; 2059 ++number_of_cpu_adapt_changes_;
2046 ++cpu_restricted_counter_; 2060 ++cpu_restricted_counter_;
2047 } 2061 }
2048 } else { 2062 } else {
2049 RTC_DCHECK(load == kUnderuse); 2063 RTC_DCHECK(load == kUnderuse);
2050 // The input video frame size will have a resolution with "one step up" 2064 // The input video frame size will have a resolution with "one step up"
2051 // pixels than |max_pixel_count_step_up| where "one step up" depends on 2065 // pixels than |max_pixel_count_step_up| where "one step up" depends on
2052 // how the source can scale the input frame size. 2066 // how the source can scale the input frame size.
2053 max_pixel_count_step_up = rtc::Optional<int>(last_dimensions_.height * 2067 max_pixel_count_step_up =
2054 last_dimensions_.width); 2068 rtc::Optional<int>(last_frame_info_.height * last_frame_info_.width);
2055 // Increase |number_of_cpu_adapt_changes_| if 2069 // Increase |number_of_cpu_adapt_changes_| if
2056 // sink_wants_.max_pixel_count_step_up will be changed since 2070 // sink_wants_.max_pixel_count_step_up will be changed since
2057 // last time |source_->AddOrUpdateSink| was called. That is, this will 2071 // last time |source_->AddOrUpdateSink| was called. That is, this will
2058 // result in a new request for the source to change resolution. 2072 // result in a new request for the source to change resolution.
2059 if (sink_wants_.max_pixel_count || 2073 if (sink_wants_.max_pixel_count ||
2060 (sink_wants_.max_pixel_count_step_up && 2074 (sink_wants_.max_pixel_count_step_up &&
2061 *sink_wants_.max_pixel_count_step_up < *max_pixel_count_step_up)) { 2075 *sink_wants_.max_pixel_count_step_up < *max_pixel_count_step_up)) {
2062 ++number_of_cpu_adapt_changes_; 2076 ++number_of_cpu_adapt_changes_;
2063 --cpu_restricted_counter_; 2077 --cpu_restricted_counter_;
2064 } 2078 }
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
2613 rtx_mapping[video_codecs[i].codec.id] != 2627 rtx_mapping[video_codecs[i].codec.id] !=
2614 fec_settings.red_payload_type) { 2628 fec_settings.red_payload_type) {
2615 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; 2629 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id];
2616 } 2630 }
2617 } 2631 }
2618 2632
2619 return video_codecs; 2633 return video_codecs;
2620 } 2634 }
2621 2635
2622 } // namespace cricket 2636 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/media/engine/webrtcvideoengine2.h ('k') | webrtc/video/video_send_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698