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_ && |
| 310 conference_mode_)) { |
306 return GetSimulcastConfig(encoder_config.number_of_streams, width, height, | 311 return GetSimulcastConfig(encoder_config.number_of_streams, width, height, |
307 encoder_config.max_bitrate_bps, max_qp_, | 312 encoder_config.max_bitrate_bps, max_qp_, |
308 max_framerate_); | 313 max_framerate_, is_screencast_); |
309 } | 314 } |
310 | 315 |
311 // For unset max bitrates set default bitrate for non-simulcast. | 316 // For unset max bitrates set default bitrate for non-simulcast. |
312 int max_bitrate_bps = | 317 int max_bitrate_bps = |
313 (encoder_config.max_bitrate_bps > 0) | 318 (encoder_config.max_bitrate_bps > 0) |
314 ? encoder_config.max_bitrate_bps | 319 ? encoder_config.max_bitrate_bps |
315 : GetMaxDefaultVideoBitrateKbps(width, height) * 1000; | 320 : GetMaxDefaultVideoBitrateKbps(width, height) * 1000; |
316 | 321 |
317 webrtc::VideoStream stream; | 322 webrtc::VideoStream stream; |
318 stream.width = width; | 323 stream.width = width; |
319 stream.height = height; | 324 stream.height = height; |
320 stream.max_framerate = max_framerate_; | 325 stream.max_framerate = max_framerate_; |
321 stream.min_bitrate_bps = kMinVideoBitrateKbps * 1000; | 326 stream.min_bitrate_bps = kMinVideoBitrateKbps * 1000; |
322 stream.target_bitrate_bps = stream.max_bitrate_bps = max_bitrate_bps; | 327 stream.target_bitrate_bps = stream.max_bitrate_bps = max_bitrate_bps; |
323 stream.max_qp = max_qp_; | 328 stream.max_qp = max_qp_; |
324 | 329 |
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_) { | 330 if (CodecNamesEq(codec_name_, kVp9CodecName) && !is_screencast_) { |
340 stream.temporal_layer_thresholds_bps.resize( | 331 stream.temporal_layer_thresholds_bps.resize( |
341 GetDefaultVp9TemporalLayers() - 1); | 332 GetDefaultVp9TemporalLayers() - 1); |
342 } | 333 } |
343 | 334 |
344 std::vector<webrtc::VideoStream> streams; | 335 std::vector<webrtc::VideoStream> streams; |
345 streams.push_back(stream); | 336 streams.push_back(stream); |
346 return streams; | 337 return streams; |
347 } | 338 } |
348 | 339 |
(...skipping 1195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1544 // TODO(deadbeef): Don't duplicate information between send_params, | 1535 // TODO(deadbeef): Don't duplicate information between send_params, |
1545 // rtp_extensions, options, etc. | 1536 // rtp_extensions, options, etc. |
1546 const VideoSendParameters& send_params) | 1537 const VideoSendParameters& send_params) |
1547 : worker_thread_(rtc::Thread::Current()), | 1538 : worker_thread_(rtc::Thread::Current()), |
1548 ssrcs_(sp.ssrcs), | 1539 ssrcs_(sp.ssrcs), |
1549 ssrc_groups_(sp.ssrc_groups), | 1540 ssrc_groups_(sp.ssrc_groups), |
1550 call_(call), | 1541 call_(call), |
1551 enable_cpu_overuse_detection_(enable_cpu_overuse_detection), | 1542 enable_cpu_overuse_detection_(enable_cpu_overuse_detection), |
1552 source_(nullptr), | 1543 source_(nullptr), |
1553 external_encoder_factory_(external_encoder_factory), | 1544 external_encoder_factory_(external_encoder_factory), |
| 1545 internal_encoder_factory_(new InternalEncoderFactory()), |
1554 stream_(nullptr), | 1546 stream_(nullptr), |
1555 encoder_sink_(nullptr), | 1547 encoder_sink_(nullptr), |
1556 parameters_(std::move(config), options, max_bitrate_bps, codec_settings), | 1548 parameters_(std::move(config), options, max_bitrate_bps, codec_settings), |
1557 rtp_parameters_(CreateRtpParametersWithOneEncoding()), | 1549 rtp_parameters_(CreateRtpParametersWithOneEncoding()), |
1558 allocated_encoder_(nullptr, cricket::VideoCodec(), false), | 1550 allocated_encoder_(nullptr, cricket::VideoCodec(), false), |
1559 sending_(false) { | 1551 sending_(false) { |
1560 parameters_.config.rtp.max_packet_size = kVideoMtu; | 1552 parameters_.config.rtp.max_packet_size = kVideoMtu; |
1561 parameters_.conference_mode = send_params.conference_mode; | 1553 parameters_.conference_mode = send_params.conference_mode; |
1562 | 1554 |
1563 sp.GetPrimarySsrcs(¶meters_.config.rtp.ssrcs); | 1555 sp.GetPrimarySsrcs(¶meters_.config.rtp.ssrcs); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1671 // Try creating external encoder. | 1663 // Try creating external encoder. |
1672 if (external_encoder_factory_ != nullptr && | 1664 if (external_encoder_factory_ != nullptr && |
1673 FindMatchingCodec(external_encoder_factory_->supported_codecs(), codec)) { | 1665 FindMatchingCodec(external_encoder_factory_->supported_codecs(), codec)) { |
1674 webrtc::VideoEncoder* encoder = | 1666 webrtc::VideoEncoder* encoder = |
1675 external_encoder_factory_->CreateVideoEncoder(codec); | 1667 external_encoder_factory_->CreateVideoEncoder(codec); |
1676 if (encoder != nullptr) | 1668 if (encoder != nullptr) |
1677 return AllocatedEncoder(encoder, codec, true /* is_external */); | 1669 return AllocatedEncoder(encoder, codec, true /* is_external */); |
1678 } | 1670 } |
1679 | 1671 |
1680 // Try creating internal encoder. | 1672 // Try creating internal encoder. |
1681 InternalEncoderFactory internal_encoder_factory; | 1673 if (FindMatchingCodec(internal_encoder_factory_->supported_codecs(), codec)) { |
1682 if (FindMatchingCodec(internal_encoder_factory.supported_codecs(), codec)) { | 1674 if (parameters_.encoder_config.content_type == |
1683 return AllocatedEncoder(internal_encoder_factory.CreateVideoEncoder(codec), | 1675 webrtc::VideoEncoderConfig::ContentType::kScreen && |
1684 codec, false /* is_external */); | 1676 parameters_.conference_mode && UseSimulcastScreenshare()) { |
| 1677 // TODO(sprang): Remove this adapter once libvpx supports simulcast with |
| 1678 // same-resolution substreams. |
| 1679 WebRtcSimulcastEncoderFactory adapter_factory( |
| 1680 internal_encoder_factory_.get()); |
| 1681 return AllocatedEncoder(adapter_factory.CreateVideoEncoder(codec), codec, |
| 1682 false /* is_external */); |
| 1683 } |
| 1684 return AllocatedEncoder( |
| 1685 internal_encoder_factory_->CreateVideoEncoder(codec), codec, |
| 1686 false /* is_external */); |
1685 } | 1687 } |
1686 | 1688 |
1687 // This shouldn't happen, we should not be trying to create something we don't | 1689 // This shouldn't happen, we should not be trying to create something we don't |
1688 // support. | 1690 // support. |
1689 RTC_NOTREACHED(); | 1691 RTC_NOTREACHED(); |
1690 return AllocatedEncoder(NULL, cricket::VideoCodec(), false); | 1692 return AllocatedEncoder(NULL, cricket::VideoCodec(), false); |
1691 } | 1693 } |
1692 | 1694 |
1693 void WebRtcVideoChannel2::WebRtcVideoSendStream::DestroyVideoEncoder( | 1695 void WebRtcVideoChannel2::WebRtcVideoSendStream::DestroyVideoEncoder( |
1694 AllocatedEncoder* encoder) { | 1696 AllocatedEncoder* encoder) { |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1851 encoder_config.content_type = | 1853 encoder_config.content_type = |
1852 webrtc::VideoEncoderConfig::ContentType::kScreen; | 1854 webrtc::VideoEncoderConfig::ContentType::kScreen; |
1853 } else { | 1855 } else { |
1854 encoder_config.min_transmit_bitrate_bps = 0; | 1856 encoder_config.min_transmit_bitrate_bps = 0; |
1855 encoder_config.content_type = | 1857 encoder_config.content_type = |
1856 webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo; | 1858 webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo; |
1857 } | 1859 } |
1858 | 1860 |
1859 // By default, the stream count for the codec configuration should match the | 1861 // By default, the stream count for the codec configuration should match the |
1860 // number of negotiated ssrcs. But if the codec is blacklisted for simulcast | 1862 // number of negotiated ssrcs. But if the codec is blacklisted for simulcast |
1861 // or a screencast, only configure a single stream. | 1863 // or a screencast (and not in simulcast screenshare experiment), only |
| 1864 // configure a single stream. |
1862 encoder_config.number_of_streams = parameters_.config.rtp.ssrcs.size(); | 1865 encoder_config.number_of_streams = parameters_.config.rtp.ssrcs.size(); |
1863 if (IsCodecBlacklistedForSimulcast(codec.name) || is_screencast) { | 1866 if (IsCodecBlacklistedForSimulcast(codec.name) || |
| 1867 (is_screencast && !UseSimulcastScreenshare())) { |
1864 encoder_config.number_of_streams = 1; | 1868 encoder_config.number_of_streams = 1; |
1865 } | 1869 } |
1866 | 1870 |
1867 int stream_max_bitrate = | 1871 int stream_max_bitrate = |
1868 MinPositive(rtp_parameters_.encodings[0].max_bitrate_bps, | 1872 MinPositive(rtp_parameters_.encodings[0].max_bitrate_bps, |
1869 parameters_.max_bitrate_bps); | 1873 parameters_.max_bitrate_bps); |
1870 | 1874 |
1871 int codec_max_bitrate_kbps; | 1875 int codec_max_bitrate_kbps; |
1872 if (codec.GetParam(kCodecParamMaxBitrate, &codec_max_bitrate_kbps)) { | 1876 if (codec.GetParam(kCodecParamMaxBitrate, &codec_max_bitrate_kbps)) { |
1873 stream_max_bitrate = codec_max_bitrate_kbps * 1000; | 1877 stream_max_bitrate = codec_max_bitrate_kbps * 1000; |
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2516 rtx_mapping[video_codecs[i].codec.id] != | 2520 rtx_mapping[video_codecs[i].codec.id] != |
2517 ulpfec_config.red_payload_type) { | 2521 ulpfec_config.red_payload_type) { |
2518 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; | 2522 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; |
2519 } | 2523 } |
2520 } | 2524 } |
2521 | 2525 |
2522 return video_codecs; | 2526 return video_codecs; |
2523 } | 2527 } |
2524 | 2528 |
2525 } // namespace cricket | 2529 } // namespace cricket |
OLD | NEW |