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 1192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1541 // TODO(deadbeef): Don't duplicate information between send_params, | 1532 // TODO(deadbeef): Don't duplicate information between send_params, |
1542 // rtp_extensions, options, etc. | 1533 // rtp_extensions, options, etc. |
1543 const VideoSendParameters& send_params) | 1534 const VideoSendParameters& send_params) |
1544 : worker_thread_(rtc::Thread::Current()), | 1535 : worker_thread_(rtc::Thread::Current()), |
1545 ssrcs_(sp.ssrcs), | 1536 ssrcs_(sp.ssrcs), |
1546 ssrc_groups_(sp.ssrc_groups), | 1537 ssrc_groups_(sp.ssrc_groups), |
1547 call_(call), | 1538 call_(call), |
1548 enable_cpu_overuse_detection_(enable_cpu_overuse_detection), | 1539 enable_cpu_overuse_detection_(enable_cpu_overuse_detection), |
1549 source_(nullptr), | 1540 source_(nullptr), |
1550 external_encoder_factory_(external_encoder_factory), | 1541 external_encoder_factory_(external_encoder_factory), |
1542 internal_encoder_factory_(new InternalEncoderFactory()), | |
1551 stream_(nullptr), | 1543 stream_(nullptr), |
1552 encoder_sink_(nullptr), | 1544 encoder_sink_(nullptr), |
1553 parameters_(std::move(config), options, max_bitrate_bps, codec_settings), | 1545 parameters_(std::move(config), options, max_bitrate_bps, codec_settings), |
1554 rtp_parameters_(CreateRtpParametersWithOneEncoding()), | 1546 rtp_parameters_(CreateRtpParametersWithOneEncoding()), |
1555 allocated_encoder_(nullptr, cricket::VideoCodec(), false), | 1547 allocated_encoder_(nullptr, cricket::VideoCodec(), false), |
1556 sending_(false), | 1548 sending_(false), |
1557 last_frame_timestamp_us_(0) { | 1549 last_frame_timestamp_us_(0) { |
1558 parameters_.config.rtp.max_packet_size = kVideoMtu; | 1550 parameters_.config.rtp.max_packet_size = kVideoMtu; |
1559 parameters_.conference_mode = send_params.conference_mode; | 1551 parameters_.conference_mode = send_params.conference_mode; |
1560 | 1552 |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1728 // Try creating external encoder. | 1720 // Try creating external encoder. |
1729 if (external_encoder_factory_ != nullptr && | 1721 if (external_encoder_factory_ != nullptr && |
1730 FindMatchingCodec(external_encoder_factory_->supported_codecs(), codec)) { | 1722 FindMatchingCodec(external_encoder_factory_->supported_codecs(), codec)) { |
1731 webrtc::VideoEncoder* encoder = | 1723 webrtc::VideoEncoder* encoder = |
1732 external_encoder_factory_->CreateVideoEncoder(codec); | 1724 external_encoder_factory_->CreateVideoEncoder(codec); |
1733 if (encoder != nullptr) | 1725 if (encoder != nullptr) |
1734 return AllocatedEncoder(encoder, codec, true /* is_external */); | 1726 return AllocatedEncoder(encoder, codec, true /* is_external */); |
1735 } | 1727 } |
1736 | 1728 |
1737 // Try creating internal encoder. | 1729 // Try creating internal encoder. |
1738 InternalEncoderFactory internal_encoder_factory; | 1730 if (FindMatchingCodec(internal_encoder_factory_->supported_codecs(), codec)) { |
perkj_webrtc
2017/01/17 13:09:03
internal_encoder_factory_ does not seem to be used
sprang_webrtc
2017/01/17 13:23:27
It's the SimulcastEncoderAdapter that uses this re
| |
1739 if (FindMatchingCodec(internal_encoder_factory.supported_codecs(), codec)) { | 1731 if (parameters_.encoder_config.content_type == |
1740 return AllocatedEncoder(internal_encoder_factory.CreateVideoEncoder(codec), | 1732 webrtc::VideoEncoderConfig::ContentType::kScreen && |
1741 codec, false /* is_external */); | 1733 parameters_.conference_mode && UseSimulcastScreenshare()) { |
1734 // TODO(sprang): Remove this adapter once libvpx supports simulcast with | |
1735 // same-resolution substreams. | |
1736 WebRtcSimulcastEncoderFactory adapter_factory( | |
1737 internal_encoder_factory_.get()); | |
1738 return AllocatedEncoder(adapter_factory.CreateVideoEncoder(codec), codec, | |
1739 false /* is_external */); | |
1740 } | |
1741 return AllocatedEncoder( | |
1742 internal_encoder_factory_->CreateVideoEncoder(codec), codec, | |
1743 false /* is_external */); | |
1742 } | 1744 } |
1743 | 1745 |
1744 // This shouldn't happen, we should not be trying to create something we don't | 1746 // This shouldn't happen, we should not be trying to create something we don't |
1745 // support. | 1747 // support. |
1746 RTC_DCHECK(false); | 1748 RTC_DCHECK(false); |
1747 return AllocatedEncoder(NULL, cricket::VideoCodec(), false); | 1749 return AllocatedEncoder(NULL, cricket::VideoCodec(), false); |
1748 } | 1750 } |
1749 | 1751 |
1750 void WebRtcVideoChannel2::WebRtcVideoSendStream::DestroyVideoEncoder( | 1752 void WebRtcVideoChannel2::WebRtcVideoSendStream::DestroyVideoEncoder( |
1751 AllocatedEncoder* encoder) { | 1753 AllocatedEncoder* encoder) { |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1908 encoder_config.content_type = | 1910 encoder_config.content_type = |
1909 webrtc::VideoEncoderConfig::ContentType::kScreen; | 1911 webrtc::VideoEncoderConfig::ContentType::kScreen; |
1910 } else { | 1912 } else { |
1911 encoder_config.min_transmit_bitrate_bps = 0; | 1913 encoder_config.min_transmit_bitrate_bps = 0; |
1912 encoder_config.content_type = | 1914 encoder_config.content_type = |
1913 webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo; | 1915 webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo; |
1914 } | 1916 } |
1915 | 1917 |
1916 // By default, the stream count for the codec configuration should match the | 1918 // 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 | 1919 // number of negotiated ssrcs. But if the codec is blacklisted for simulcast |
1918 // or a screencast, only configure a single stream. | 1920 // or a screencast (and not in simulcast screenshare experiment), only |
1921 // configure a single stream. | |
1919 encoder_config.number_of_streams = parameters_.config.rtp.ssrcs.size(); | 1922 encoder_config.number_of_streams = parameters_.config.rtp.ssrcs.size(); |
1920 if (IsCodecBlacklistedForSimulcast(codec.name) || is_screencast) { | 1923 if (IsCodecBlacklistedForSimulcast(codec.name) || |
1924 (is_screencast && !UseSimulcastScreenshare())) { | |
1921 encoder_config.number_of_streams = 1; | 1925 encoder_config.number_of_streams = 1; |
1922 } | 1926 } |
1923 | 1927 |
1924 int stream_max_bitrate = | 1928 int stream_max_bitrate = |
1925 MinPositive(rtp_parameters_.encodings[0].max_bitrate_bps, | 1929 MinPositive(rtp_parameters_.encodings[0].max_bitrate_bps, |
1926 parameters_.max_bitrate_bps); | 1930 parameters_.max_bitrate_bps); |
1927 | 1931 |
1928 int codec_max_bitrate_kbps; | 1932 int codec_max_bitrate_kbps; |
1929 if (codec.GetParam(kCodecParamMaxBitrate, &codec_max_bitrate_kbps)) { | 1933 if (codec.GetParam(kCodecParamMaxBitrate, &codec_max_bitrate_kbps)) { |
1930 stream_max_bitrate = codec_max_bitrate_kbps * 1000; | 1934 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] != | 2591 rtx_mapping[video_codecs[i].codec.id] != |
2588 ulpfec_config.red_payload_type) { | 2592 ulpfec_config.red_payload_type) { |
2589 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; | 2593 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; |
2590 } | 2594 } |
2591 } | 2595 } |
2592 | 2596 |
2593 return video_codecs; | 2597 return video_codecs; |
2594 } | 2598 } |
2595 | 2599 |
2596 } // namespace cricket | 2600 } // namespace cricket |
OLD | NEW |