| 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/base/logging.h" |
| 15 #include "webrtc/common_video/include/video_bitrate_allocator.h" | 15 #include "webrtc/common_video/include/video_bitrate_allocator.h" |
| 16 #include "webrtc/common_types.h" | 16 #include "webrtc/common_types.h" |
| 17 #include "webrtc/modules/video_coding/codecs/vp8/screenshare_layers.h" | 17 #include "webrtc/modules/video_coding/codecs/vp8/screenshare_layers.h" |
| 18 #include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h" | 18 #include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h" |
| 19 #include "webrtc/modules/video_coding/utility/simulcast_rate_allocator.h" | 19 #include "webrtc/modules/video_coding/utility/simulcast_rate_allocator.h" |
| 20 #include "webrtc/modules/video_coding/utility/default_video_bitrate_allocator.h" | 20 #include "webrtc/modules/video_coding/utility/default_video_bitrate_allocator.h" |
| 21 #include "webrtc/system_wrappers/include/clock.h" | 21 #include "webrtc/system_wrappers/include/clock.h" |
| 22 | 22 |
| 23 namespace webrtc { | 23 namespace webrtc { |
| 24 namespace { |
| 25 bool TemporalLayersConfigured(const std::vector<VideoStream>& streams) { |
| 26 for (const VideoStream& stream : streams) { |
| 27 if (stream.temporal_layer_thresholds_bps.size() > 0) |
| 28 return true; |
| 29 } |
| 30 return false; |
| 31 } |
| 32 } // namespace |
| 24 | 33 |
| 25 bool VideoCodecInitializer::SetupCodec( | 34 bool VideoCodecInitializer::SetupCodec( |
| 26 const VideoEncoderConfig& config, | 35 const VideoEncoderConfig& config, |
| 27 const VideoSendStream::Config::EncoderSettings settings, | 36 const VideoSendStream::Config::EncoderSettings settings, |
| 28 const std::vector<VideoStream>& streams, | 37 const std::vector<VideoStream>& streams, |
| 29 bool nack_enabled, | 38 bool nack_enabled, |
| 30 VideoCodec* codec, | 39 VideoCodec* codec, |
| 31 std::unique_ptr<VideoBitrateAllocator>* bitrate_allocator) { | 40 std::unique_ptr<VideoBitrateAllocator>* bitrate_allocator) { |
| 32 *codec = | 41 *codec = |
| 33 VideoEncoderConfigToVideoCodec(config, streams, settings.payload_name, | 42 VideoEncoderConfigToVideoCodec(config, streams, settings.payload_name, |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 | 121 |
| 113 if (config.encoder_specific_settings) | 122 if (config.encoder_specific_settings) |
| 114 config.encoder_specific_settings->FillEncoderSpecificSettings(&video_codec); | 123 config.encoder_specific_settings->FillEncoderSpecificSettings(&video_codec); |
| 115 | 124 |
| 116 switch (video_codec.codecType) { | 125 switch (video_codec.codecType) { |
| 117 case kVideoCodecVP8: { | 126 case kVideoCodecVP8: { |
| 118 if (!config.encoder_specific_settings) | 127 if (!config.encoder_specific_settings) |
| 119 *video_codec.VP8() = VideoEncoder::GetDefaultVp8Settings(); | 128 *video_codec.VP8() = VideoEncoder::GetDefaultVp8Settings(); |
| 120 video_codec.VP8()->numberOfTemporalLayers = static_cast<unsigned char>( | 129 video_codec.VP8()->numberOfTemporalLayers = static_cast<unsigned char>( |
| 121 streams.back().temporal_layer_thresholds_bps.size() + 1); | 130 streams.back().temporal_layer_thresholds_bps.size() + 1); |
| 122 bool temporal_layers_configured = false; | 131 |
| 123 for (const VideoStream& stream : streams) { | 132 if (nack_enabled && !TemporalLayersConfigured(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"; | 133 LOG(LS_INFO) << "No temporal layers and nack enabled -> resilience off"; |
| 129 video_codec.VP8()->resilience = kResilienceOff; | 134 video_codec.VP8()->resilience = kResilienceOff; |
| 130 } | 135 } |
| 131 break; | 136 break; |
| 132 } | 137 } |
| 133 case kVideoCodecVP9: { | 138 case kVideoCodecVP9: { |
| 134 if (!config.encoder_specific_settings) | 139 if (!config.encoder_specific_settings) |
| 135 *video_codec.VP9() = VideoEncoder::GetDefaultVp9Settings(); | 140 *video_codec.VP9() = VideoEncoder::GetDefaultVp9Settings(); |
| 136 if (video_codec.mode == kScreensharing && | 141 if (video_codec.mode == kScreensharing && |
| 137 config.encoder_specific_settings) { | 142 config.encoder_specific_settings) { |
| 138 video_codec.VP9()->flexibleMode = true; | 143 video_codec.VP9()->flexibleMode = true; |
| 139 // For now VP9 screensharing use 1 temporal and 2 spatial layers. | 144 // For now VP9 screensharing use 1 temporal and 2 spatial layers. |
| 140 RTC_DCHECK_EQ(1, video_codec.VP9()->numberOfTemporalLayers); | 145 RTC_DCHECK_EQ(1, video_codec.VP9()->numberOfTemporalLayers); |
| 141 RTC_DCHECK_EQ(2, video_codec.VP9()->numberOfSpatialLayers); | 146 RTC_DCHECK_EQ(2, video_codec.VP9()->numberOfSpatialLayers); |
| 142 } | 147 } |
| 143 video_codec.VP9()->numberOfTemporalLayers = static_cast<unsigned char>( | 148 video_codec.VP9()->numberOfTemporalLayers = static_cast<unsigned char>( |
| 144 streams.back().temporal_layer_thresholds_bps.size() + 1); | 149 streams.back().temporal_layer_thresholds_bps.size() + 1); |
| 150 |
| 151 if (nack_enabled && !TemporalLayersConfigured(streams) && |
| 152 video_codec.VP9()->numberOfSpatialLayers == 1) { |
| 153 LOG(LS_INFO) << "No temporal or spatial layers and nack enabled -> " |
| 154 << "resilience off"; |
| 155 video_codec.VP9()->resilienceOn = false; |
| 156 } |
| 145 break; | 157 break; |
| 146 } | 158 } |
| 147 case kVideoCodecH264: { | 159 case kVideoCodecH264: { |
| 148 if (!config.encoder_specific_settings) | 160 if (!config.encoder_specific_settings) |
| 149 *video_codec.H264() = VideoEncoder::GetDefaultH264Settings(); | 161 *video_codec.H264() = VideoEncoder::GetDefaultH264Settings(); |
| 150 break; | 162 break; |
| 151 } | 163 } |
| 152 default: | 164 default: |
| 153 // TODO(pbos): Support encoder_settings codec-agnostically. | 165 // TODO(pbos): Support encoder_settings codec-agnostically. |
| 154 RTC_DCHECK(!config.encoder_specific_settings) | 166 RTC_DCHECK(!config.encoder_specific_settings) |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 } | 228 } |
| 217 if (video_codec.maxBitrate < kEncoderMinBitrateKbps) | 229 if (video_codec.maxBitrate < kEncoderMinBitrateKbps) |
| 218 video_codec.maxBitrate = kEncoderMinBitrateKbps; | 230 video_codec.maxBitrate = kEncoderMinBitrateKbps; |
| 219 | 231 |
| 220 RTC_DCHECK_GT(streams[0].max_framerate, 0); | 232 RTC_DCHECK_GT(streams[0].max_framerate, 0); |
| 221 video_codec.maxFramerate = streams[0].max_framerate; | 233 video_codec.maxFramerate = streams[0].max_framerate; |
| 222 return video_codec; | 234 return video_codec; |
| 223 } | 235 } |
| 224 | 236 |
| 225 } // namespace webrtc | 237 } // namespace webrtc |
| OLD | NEW |