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