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 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 max_qp_(max_qp), | 294 max_qp_(max_qp), |
295 max_framerate_(max_framerate), | 295 max_framerate_(max_framerate), |
296 is_screencast_(is_screencast), | 296 is_screencast_(is_screencast), |
297 conference_mode_(conference_mode) {} | 297 conference_mode_(conference_mode) {} |
298 | 298 |
299 private: | 299 private: |
300 std::vector<webrtc::VideoStream> CreateEncoderStreams( | 300 std::vector<webrtc::VideoStream> CreateEncoderStreams( |
301 int width, | 301 int width, |
302 int height, | 302 int height, |
303 const webrtc::VideoEncoderConfig& encoder_config) override { | 303 const webrtc::VideoEncoderConfig& encoder_config) override { |
304 RTC_DCHECK(encoder_config.number_of_streams > 1 ? !is_screencast_ : true); | 304 if (is_screencast_ && |
305 if (encoder_config.number_of_streams > 1) { | 305 (!conference_mode_ || !cricket::UseSimulcastScreenshare())) { |
| 306 RTC_DCHECK_EQ(1, encoder_config.number_of_streams); |
| 307 } |
| 308 if (encoder_config.number_of_streams > 1 || |
| 309 (CodecNamesEq(codec_name_, kVp8CodecName) && is_screencast_)) { |
306 return GetSimulcastConfig(encoder_config.number_of_streams, width, height, | 310 return GetSimulcastConfig(encoder_config.number_of_streams, width, height, |
307 encoder_config.max_bitrate_bps, max_qp_, | 311 encoder_config.max_bitrate_bps, max_qp_, |
308 max_framerate_); | 312 max_framerate_, is_screencast_); |
309 } | 313 } |
310 | 314 |
311 // For unset max bitrates set default bitrate for non-simulcast. | 315 // For unset max bitrates set default bitrate for non-simulcast. |
312 int max_bitrate_bps = | 316 int max_bitrate_bps = |
313 (encoder_config.max_bitrate_bps > 0) | 317 (encoder_config.max_bitrate_bps > 0) |
314 ? encoder_config.max_bitrate_bps | 318 ? encoder_config.max_bitrate_bps |
315 : GetMaxDefaultVideoBitrateKbps(width, height) * 1000; | 319 : GetMaxDefaultVideoBitrateKbps(width, height) * 1000; |
316 | 320 |
317 webrtc::VideoStream stream; | 321 webrtc::VideoStream stream; |
318 stream.width = width; | 322 stream.width = width; |
319 stream.height = height; | 323 stream.height = height; |
320 stream.max_framerate = max_framerate_; | 324 stream.max_framerate = max_framerate_; |
321 stream.min_bitrate_bps = kMinVideoBitrateKbps * 1000; | 325 stream.min_bitrate_bps = kMinVideoBitrateKbps * 1000; |
322 stream.target_bitrate_bps = stream.max_bitrate_bps = max_bitrate_bps; | 326 stream.target_bitrate_bps = stream.max_bitrate_bps = max_bitrate_bps; |
323 stream.max_qp = max_qp_; | 327 stream.max_qp = max_qp_; |
324 | 328 |
325 // Conference mode screencast uses 2 temporal layers split at 100kbit. | |
326 if (conference_mode_ && is_screencast_) { | |
327 ScreenshareLayerConfig config = ScreenshareLayerConfig::GetDefault(); | |
328 // For screenshare in conference mode, tl0 and tl1 bitrates are | |
329 // piggybacked | |
330 // on the VideoCodec struct as target and max bitrates, respectively. | |
331 // See eg. webrtc::VP8EncoderImpl::SetRates(). | |
332 stream.target_bitrate_bps = config.tl0_bitrate_kbps * 1000; | |
333 stream.max_bitrate_bps = config.tl1_bitrate_kbps * 1000; | |
334 stream.temporal_layer_thresholds_bps.clear(); | |
335 stream.temporal_layer_thresholds_bps.push_back(config.tl0_bitrate_kbps * | |
336 1000); | |
337 } | |
338 | |
339 if (CodecNamesEq(codec_name_, kVp9CodecName) && !is_screencast_) { | 329 if (CodecNamesEq(codec_name_, kVp9CodecName) && !is_screencast_) { |
340 stream.temporal_layer_thresholds_bps.resize( | 330 stream.temporal_layer_thresholds_bps.resize( |
341 GetDefaultVp9TemporalLayers() - 1); | 331 GetDefaultVp9TemporalLayers() - 1); |
342 } | 332 } |
343 | 333 |
344 std::vector<webrtc::VideoStream> streams; | 334 std::vector<webrtc::VideoStream> streams; |
345 streams.push_back(stream); | 335 streams.push_back(stream); |
346 return streams; | 336 return streams; |
347 } | 337 } |
348 | 338 |
(...skipping 1192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1541 // TODO(deadbeef): Don't duplicate information between send_params, | 1531 // TODO(deadbeef): Don't duplicate information between send_params, |
1542 // rtp_extensions, options, etc. | 1532 // rtp_extensions, options, etc. |
1543 const VideoSendParameters& send_params) | 1533 const VideoSendParameters& send_params) |
1544 : worker_thread_(rtc::Thread::Current()), | 1534 : worker_thread_(rtc::Thread::Current()), |
1545 ssrcs_(sp.ssrcs), | 1535 ssrcs_(sp.ssrcs), |
1546 ssrc_groups_(sp.ssrc_groups), | 1536 ssrc_groups_(sp.ssrc_groups), |
1547 call_(call), | 1537 call_(call), |
1548 enable_cpu_overuse_detection_(enable_cpu_overuse_detection), | 1538 enable_cpu_overuse_detection_(enable_cpu_overuse_detection), |
1549 source_(nullptr), | 1539 source_(nullptr), |
1550 external_encoder_factory_(external_encoder_factory), | 1540 external_encoder_factory_(external_encoder_factory), |
| 1541 internal_encoder_factory_(new InternalEncoderFactory()), |
1551 stream_(nullptr), | 1542 stream_(nullptr), |
1552 encoder_sink_(nullptr), | 1543 encoder_sink_(nullptr), |
1553 parameters_(std::move(config), options, max_bitrate_bps, codec_settings), | 1544 parameters_(std::move(config), options, max_bitrate_bps, codec_settings), |
1554 rtp_parameters_(CreateRtpParametersWithOneEncoding()), | 1545 rtp_parameters_(CreateRtpParametersWithOneEncoding()), |
1555 allocated_encoder_(nullptr, cricket::VideoCodec(), false), | 1546 allocated_encoder_(nullptr, cricket::VideoCodec(), false), |
1556 sending_(false), | 1547 sending_(false), |
1557 last_frame_timestamp_us_(0) { | 1548 last_frame_timestamp_us_(0) { |
1558 parameters_.config.rtp.max_packet_size = kVideoMtu; | 1549 parameters_.config.rtp.max_packet_size = kVideoMtu; |
1559 parameters_.conference_mode = send_params.conference_mode; | 1550 parameters_.conference_mode = send_params.conference_mode; |
1560 | 1551 |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1728 // Try creating external encoder. | 1719 // Try creating external encoder. |
1729 if (external_encoder_factory_ != nullptr && | 1720 if (external_encoder_factory_ != nullptr && |
1730 FindMatchingCodec(external_encoder_factory_->supported_codecs(), codec)) { | 1721 FindMatchingCodec(external_encoder_factory_->supported_codecs(), codec)) { |
1731 webrtc::VideoEncoder* encoder = | 1722 webrtc::VideoEncoder* encoder = |
1732 external_encoder_factory_->CreateVideoEncoder(codec); | 1723 external_encoder_factory_->CreateVideoEncoder(codec); |
1733 if (encoder != nullptr) | 1724 if (encoder != nullptr) |
1734 return AllocatedEncoder(encoder, codec, true /* is_external */); | 1725 return AllocatedEncoder(encoder, codec, true /* is_external */); |
1735 } | 1726 } |
1736 | 1727 |
1737 // Try creating internal encoder. | 1728 // Try creating internal encoder. |
1738 InternalEncoderFactory internal_encoder_factory; | 1729 if (FindMatchingCodec(internal_encoder_factory_->supported_codecs(), codec)) { |
1739 if (FindMatchingCodec(internal_encoder_factory.supported_codecs(), codec)) { | 1730 if (parameters_.encoder_config.content_type == |
1740 return AllocatedEncoder(internal_encoder_factory.CreateVideoEncoder(codec), | 1731 webrtc::VideoEncoderConfig::ContentType::kScreen && |
1741 codec, false /* is_external */); | 1732 parameters_.conference_mode && UseSimulcastScreenshare()) { |
| 1733 // TODO(sprang): Remove this adapter once libvpx supports simulcast with |
| 1734 // same-resolution substreams. |
| 1735 WebRtcSimulcastEncoderFactory adapter_factory( |
| 1736 internal_encoder_factory_.get()); |
| 1737 return AllocatedEncoder(adapter_factory.CreateVideoEncoder(codec), codec, |
| 1738 false /* is_external */); |
| 1739 } |
| 1740 return AllocatedEncoder( |
| 1741 internal_encoder_factory_->CreateVideoEncoder(codec), codec, |
| 1742 false /* is_external */); |
1742 } | 1743 } |
1743 | 1744 |
1744 // This shouldn't happen, we should not be trying to create something we don't | 1745 // This shouldn't happen, we should not be trying to create something we don't |
1745 // support. | 1746 // support. |
1746 RTC_DCHECK(false); | 1747 RTC_DCHECK(false); |
1747 return AllocatedEncoder(NULL, cricket::VideoCodec(), false); | 1748 return AllocatedEncoder(NULL, cricket::VideoCodec(), false); |
1748 } | 1749 } |
1749 | 1750 |
1750 void WebRtcVideoChannel2::WebRtcVideoSendStream::DestroyVideoEncoder( | 1751 void WebRtcVideoChannel2::WebRtcVideoSendStream::DestroyVideoEncoder( |
1751 AllocatedEncoder* encoder) { | 1752 AllocatedEncoder* encoder) { |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1908 encoder_config.content_type = | 1909 encoder_config.content_type = |
1909 webrtc::VideoEncoderConfig::ContentType::kScreen; | 1910 webrtc::VideoEncoderConfig::ContentType::kScreen; |
1910 } else { | 1911 } else { |
1911 encoder_config.min_transmit_bitrate_bps = 0; | 1912 encoder_config.min_transmit_bitrate_bps = 0; |
1912 encoder_config.content_type = | 1913 encoder_config.content_type = |
1913 webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo; | 1914 webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo; |
1914 } | 1915 } |
1915 | 1916 |
1916 // By default, the stream count for the codec configuration should match the | 1917 // By default, the stream count for the codec configuration should match the |
1917 // number of negotiated ssrcs. But if the codec is blacklisted for simulcast | 1918 // number of negotiated ssrcs. But if the codec is blacklisted for simulcast |
1918 // or a screencast, only configure a single stream. | 1919 // or a screencast (and not in simulcast screenshare experiment), only |
| 1920 // configure a single stream. |
1919 encoder_config.number_of_streams = parameters_.config.rtp.ssrcs.size(); | 1921 encoder_config.number_of_streams = parameters_.config.rtp.ssrcs.size(); |
1920 if (IsCodecBlacklistedForSimulcast(codec.name) || is_screencast) { | 1922 if (IsCodecBlacklistedForSimulcast(codec.name) || |
| 1923 (is_screencast && !UseSimulcastScreenshare())) { |
1921 encoder_config.number_of_streams = 1; | 1924 encoder_config.number_of_streams = 1; |
1922 } | 1925 } |
1923 | 1926 |
1924 int stream_max_bitrate = | 1927 int stream_max_bitrate = |
1925 MinPositive(rtp_parameters_.encodings[0].max_bitrate_bps, | 1928 MinPositive(rtp_parameters_.encodings[0].max_bitrate_bps, |
1926 parameters_.max_bitrate_bps); | 1929 parameters_.max_bitrate_bps); |
1927 | 1930 |
1928 int codec_max_bitrate_kbps; | 1931 int codec_max_bitrate_kbps; |
1929 if (codec.GetParam(kCodecParamMaxBitrate, &codec_max_bitrate_kbps)) { | 1932 if (codec.GetParam(kCodecParamMaxBitrate, &codec_max_bitrate_kbps)) { |
1930 stream_max_bitrate = codec_max_bitrate_kbps * 1000; | 1933 stream_max_bitrate = codec_max_bitrate_kbps * 1000; |
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2587 rtx_mapping[video_codecs[i].codec.id] != | 2590 rtx_mapping[video_codecs[i].codec.id] != |
2588 ulpfec_config.red_payload_type) { | 2591 ulpfec_config.red_payload_type) { |
2589 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; | 2592 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; |
2590 } | 2593 } |
2591 } | 2594 } |
2592 | 2595 |
2593 return video_codecs; | 2596 return video_codecs; |
2594 } | 2597 } |
2595 | 2598 |
2596 } // namespace cricket | 2599 } // namespace cricket |
OLD | NEW |