| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 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 |
| 11 #include "webrtc/modules/video_coding/include/video_codec_initializer.h" | 11 #include "webrtc/modules/video_coding/include/video_codec_initializer.h" |
| 12 | 12 |
| 13 #include "webrtc/base/basictypes.h" | 13 #include "webrtc/base/basictypes.h" |
| 14 #include "webrtc/base/logging.h" |
| 14 #include "webrtc/common_video/include/video_bitrate_allocator.h" | 15 #include "webrtc/common_video/include/video_bitrate_allocator.h" |
| 15 #include "webrtc/common_types.h" | 16 #include "webrtc/common_types.h" |
| 16 #include "webrtc/modules/video_coding/codecs/vp8/screenshare_layers.h" | 17 #include "webrtc/modules/video_coding/codecs/vp8/screenshare_layers.h" |
| 17 #include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h" | 18 #include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h" |
| 18 #include "webrtc/modules/video_coding/utility/simulcast_rate_allocator.h" | 19 #include "webrtc/modules/video_coding/utility/simulcast_rate_allocator.h" |
| 19 #include "webrtc/modules/video_coding/utility/default_video_bitrate_allocator.h" | 20 #include "webrtc/modules/video_coding/utility/default_video_bitrate_allocator.h" |
| 20 #include "webrtc/system_wrappers/include/clock.h" | 21 #include "webrtc/system_wrappers/include/clock.h" |
| 21 | 22 |
| 22 namespace webrtc { | 23 namespace webrtc { |
| 23 | 24 |
| 24 bool VideoCodecInitializer::SetupCodec( | 25 bool VideoCodecInitializer::SetupCodec( |
| 25 const VideoEncoderConfig& config, | 26 const VideoEncoderConfig& config, |
| 26 const VideoSendStream::Config::EncoderSettings settings, | 27 const VideoSendStream::Config::EncoderSettings settings, |
| 27 const std::vector<VideoStream>& streams, | 28 const std::vector<VideoStream>& streams, |
| 29 bool nack_enabled, |
| 28 VideoCodec* codec, | 30 VideoCodec* codec, |
| 29 std::unique_ptr<VideoBitrateAllocator>* bitrate_allocator) { | 31 std::unique_ptr<VideoBitrateAllocator>* bitrate_allocator) { |
| 30 *codec = VideoEncoderConfigToVideoCodec( | 32 *codec = |
| 31 config, streams, settings.payload_name, settings.payload_type); | 33 VideoEncoderConfigToVideoCodec(config, streams, settings.payload_name, |
| 34 settings.payload_type, nack_enabled); |
| 32 | 35 |
| 33 std::unique_ptr<TemporalLayersFactory> tl_factory; | 36 std::unique_ptr<TemporalLayersFactory> tl_factory; |
| 34 switch (codec->codecType) { | 37 switch (codec->codecType) { |
| 35 case kVideoCodecVP8: { | 38 case kVideoCodecVP8: { |
| 36 if (!codec->VP8()->tl_factory) { | 39 if (!codec->VP8()->tl_factory) { |
| 37 if (codec->mode == kScreensharing && | 40 if (codec->mode == kScreensharing && |
| 38 codec->numberOfSimulcastStreams == 1 && | 41 codec->numberOfSimulcastStreams == 1 && |
| 39 codec->VP8()->numberOfTemporalLayers == 2) { | 42 codec->VP8()->numberOfTemporalLayers == 2) { |
| 40 // Conference mode temporal layering for screen content. | 43 // Conference mode temporal layering for screen content. |
| 41 tl_factory.reset(new ScreenshareTemporalLayersFactory()); | 44 tl_factory.reset(new ScreenshareTemporalLayersFactory()); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 } | 78 } |
| 76 | 79 |
| 77 return rate_allocator; | 80 return rate_allocator; |
| 78 } | 81 } |
| 79 | 82 |
| 80 // TODO(sprang): Split this up and separate the codec specific parts. | 83 // TODO(sprang): Split this up and separate the codec specific parts. |
| 81 VideoCodec VideoCodecInitializer::VideoEncoderConfigToVideoCodec( | 84 VideoCodec VideoCodecInitializer::VideoEncoderConfigToVideoCodec( |
| 82 const VideoEncoderConfig& config, | 85 const VideoEncoderConfig& config, |
| 83 const std::vector<VideoStream>& streams, | 86 const std::vector<VideoStream>& streams, |
| 84 const std::string& payload_name, | 87 const std::string& payload_name, |
| 85 int payload_type) { | 88 int payload_type, |
| 89 bool nack_enabled) { |
| 86 static const int kEncoderMinBitrateKbps = 30; | 90 static const int kEncoderMinBitrateKbps = 30; |
| 87 RTC_DCHECK(!streams.empty()); | 91 RTC_DCHECK(!streams.empty()); |
| 88 RTC_DCHECK_GE(config.min_transmit_bitrate_bps, 0); | 92 RTC_DCHECK_GE(config.min_transmit_bitrate_bps, 0); |
| 89 | 93 |
| 90 VideoCodec video_codec; | 94 VideoCodec video_codec; |
| 91 memset(&video_codec, 0, sizeof(video_codec)); | 95 memset(&video_codec, 0, sizeof(video_codec)); |
| 92 video_codec.codecType = PayloadNameToCodecType(payload_name) | 96 video_codec.codecType = PayloadNameToCodecType(payload_name) |
| 93 .value_or(VideoCodecType::kVideoCodecGeneric); | 97 .value_or(VideoCodecType::kVideoCodecGeneric); |
| 94 | 98 |
| 95 switch (config.content_type) { | 99 switch (config.content_type) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 108 | 112 |
| 109 if (config.encoder_specific_settings) | 113 if (config.encoder_specific_settings) |
| 110 config.encoder_specific_settings->FillEncoderSpecificSettings(&video_codec); | 114 config.encoder_specific_settings->FillEncoderSpecificSettings(&video_codec); |
| 111 | 115 |
| 112 switch (video_codec.codecType) { | 116 switch (video_codec.codecType) { |
| 113 case kVideoCodecVP8: { | 117 case kVideoCodecVP8: { |
| 114 if (!config.encoder_specific_settings) | 118 if (!config.encoder_specific_settings) |
| 115 *video_codec.VP8() = VideoEncoder::GetDefaultVp8Settings(); | 119 *video_codec.VP8() = VideoEncoder::GetDefaultVp8Settings(); |
| 116 video_codec.VP8()->numberOfTemporalLayers = static_cast<unsigned char>( | 120 video_codec.VP8()->numberOfTemporalLayers = static_cast<unsigned char>( |
| 117 streams.back().temporal_layer_thresholds_bps.size() + 1); | 121 streams.back().temporal_layer_thresholds_bps.size() + 1); |
| 122 bool temporal_layers_configured = false; |
| 123 for (const VideoStream& stream : streams) { |
| 124 if (stream.temporal_layer_thresholds_bps.size() > 0) |
| 125 temporal_layers_configured = true; |
| 126 } |
| 127 if (nack_enabled && !temporal_layers_configured) { |
| 128 LOG(LS_INFO) << "No temporal layers and nack enabled -> resilience off"; |
| 129 video_codec.VP8()->resilience = kResilienceOff; |
| 130 } |
| 118 break; | 131 break; |
| 119 } | 132 } |
| 120 case kVideoCodecVP9: { | 133 case kVideoCodecVP9: { |
| 121 if (!config.encoder_specific_settings) | 134 if (!config.encoder_specific_settings) |
| 122 *video_codec.VP9() = VideoEncoder::GetDefaultVp9Settings(); | 135 *video_codec.VP9() = VideoEncoder::GetDefaultVp9Settings(); |
| 123 if (video_codec.mode == kScreensharing && | 136 if (video_codec.mode == kScreensharing && |
| 124 config.encoder_specific_settings) { | 137 config.encoder_specific_settings) { |
| 125 video_codec.VP9()->flexibleMode = true; | 138 video_codec.VP9()->flexibleMode = true; |
| 126 // For now VP9 screensharing use 1 temporal and 2 spatial layers. | 139 // For now VP9 screensharing use 1 temporal and 2 spatial layers. |
| 127 RTC_DCHECK_EQ(1, video_codec.VP9()->numberOfTemporalLayers); | 140 RTC_DCHECK_EQ(1, video_codec.VP9()->numberOfTemporalLayers); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 } | 216 } |
| 204 if (video_codec.maxBitrate < kEncoderMinBitrateKbps) | 217 if (video_codec.maxBitrate < kEncoderMinBitrateKbps) |
| 205 video_codec.maxBitrate = kEncoderMinBitrateKbps; | 218 video_codec.maxBitrate = kEncoderMinBitrateKbps; |
| 206 | 219 |
| 207 RTC_DCHECK_GT(streams[0].max_framerate, 0); | 220 RTC_DCHECK_GT(streams[0].max_framerate, 0); |
| 208 video_codec.maxFramerate = streams[0].max_framerate; | 221 video_codec.maxFramerate = streams[0].max_framerate; |
| 209 return video_codec; | 222 return video_codec; |
| 210 } | 223 } |
| 211 | 224 |
| 212 } // namespace webrtc | 225 } // namespace webrtc |
| OLD | NEW |