OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 case kVideoCodecVP9: | 60 case kVideoCodecVP9: |
61 return VideoEncoder::kVp9; | 61 return VideoEncoder::kVp9; |
62 default: | 62 default: |
63 return VideoEncoder::kUnsupportedCodec; | 63 return VideoEncoder::kUnsupportedCodec; |
64 } | 64 } |
65 } | 65 } |
66 | 66 |
67 VideoEncoderSoftwareFallbackWrapper::VideoEncoderSoftwareFallbackWrapper( | 67 VideoEncoderSoftwareFallbackWrapper::VideoEncoderSoftwareFallbackWrapper( |
68 VideoCodecType codec_type, | 68 VideoCodecType codec_type, |
69 webrtc::VideoEncoder* encoder) | 69 webrtc::VideoEncoder* encoder) |
70 : number_of_cores_(0), | 70 : rates_set_(false), |
71 max_payload_size_(0), | |
72 rates_set_(false), | |
73 framerate_(0), | |
74 channel_parameters_set_(false), | 71 channel_parameters_set_(false), |
75 packet_loss_(0), | |
76 rtt_(0), | |
77 encoder_type_(CodecToEncoderType(codec_type)), | 72 encoder_type_(CodecToEncoderType(codec_type)), |
78 encoder_(encoder), | 73 encoder_(encoder), |
79 callback_(nullptr) {} | 74 callback_(nullptr) {} |
80 | 75 |
81 bool VideoEncoderSoftwareFallbackWrapper::InitFallbackEncoder() { | 76 bool VideoEncoderSoftwareFallbackWrapper::InitFallbackEncoder() { |
82 if (!VideoEncoder::IsSupportedSoftware(encoder_type_)) { | 77 if (!VideoEncoder::IsSupportedSoftware(encoder_type_)) { |
83 LOG(LS_WARNING) | 78 LOG(LS_WARNING) |
84 << "Encoder requesting fallback to codec not supported in software."; | 79 << "Encoder requesting fallback to codec not supported in software."; |
85 return false; | 80 return false; |
86 } | 81 } |
87 fallback_encoder_.reset(VideoEncoder::Create(encoder_type_)); | 82 fallback_encoder_.reset(VideoEncoder::Create(encoder_type_)); |
88 if (fallback_encoder_->InitEncode(&codec_settings_, number_of_cores_, | 83 if (fallback_encoder_->InitEncode(&codec_settings_, number_of_cores_, |
89 max_payload_size_) != | 84 max_payload_size_) != |
90 WEBRTC_VIDEO_CODEC_OK) { | 85 WEBRTC_VIDEO_CODEC_OK) { |
91 LOG(LS_ERROR) << "Failed to initialize software-encoder fallback."; | 86 LOG(LS_ERROR) << "Failed to initialize software-encoder fallback."; |
92 fallback_encoder_->Release(); | 87 fallback_encoder_->Release(); |
93 fallback_encoder_.reset(); | 88 fallback_encoder_.reset(); |
94 return false; | 89 return false; |
95 } | 90 } |
96 // Replay callback, rates, and channel parameters. | 91 // Replay callback, rates, and channel parameters. |
97 if (callback_) | 92 if (callback_) |
98 fallback_encoder_->RegisterEncodeCompleteCallback(callback_); | 93 fallback_encoder_->RegisterEncodeCompleteCallback(callback_); |
99 if (rates_set_) | 94 if (rates_set_) |
100 fallback_encoder_->SetRateAllocation(bitrate_allocation_, framerate_); | 95 fallback_encoder_->SetRates(bitrate_, framerate_); |
101 if (channel_parameters_set_) | 96 if (channel_parameters_set_) |
102 fallback_encoder_->SetChannelParameters(packet_loss_, rtt_); | 97 fallback_encoder_->SetChannelParameters(packet_loss_, rtt_); |
103 | 98 |
104 fallback_implementation_name_ = | 99 fallback_implementation_name_ = |
105 std::string(fallback_encoder_->ImplementationName()) + | 100 std::string(fallback_encoder_->ImplementationName()) + |
106 " (fallback from: " + encoder_->ImplementationName() + ")"; | 101 " (fallback from: " + encoder_->ImplementationName() + ")"; |
107 // Since we're switching to the fallback encoder, Release the real encoder. It | 102 // Since we're switching to the fallback encoder, Release the real encoder. It |
108 // may be re-initialized via InitEncode later, and it will continue to get | 103 // may be re-initialized via InitEncode later, and it will continue to get |
109 // Set calls for rates and channel parameters in the meantime. | 104 // Set calls for rates and channel parameters in the meantime. |
110 encoder_->Release(); | 105 encoder_->Release(); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 int64_t rtt) { | 182 int64_t rtt) { |
188 channel_parameters_set_ = true; | 183 channel_parameters_set_ = true; |
189 packet_loss_ = packet_loss; | 184 packet_loss_ = packet_loss; |
190 rtt_ = rtt; | 185 rtt_ = rtt; |
191 int32_t ret = encoder_->SetChannelParameters(packet_loss, rtt); | 186 int32_t ret = encoder_->SetChannelParameters(packet_loss, rtt); |
192 if (fallback_encoder_) | 187 if (fallback_encoder_) |
193 return fallback_encoder_->SetChannelParameters(packet_loss, rtt); | 188 return fallback_encoder_->SetChannelParameters(packet_loss, rtt); |
194 return ret; | 189 return ret; |
195 } | 190 } |
196 | 191 |
197 int32_t VideoEncoderSoftwareFallbackWrapper::SetRateAllocation( | 192 int32_t VideoEncoderSoftwareFallbackWrapper::SetRates(uint32_t bitrate, |
198 const BitrateAllocation& bitrate_allocation, | 193 uint32_t framerate) { |
199 uint32_t framerate) { | |
200 rates_set_ = true; | 194 rates_set_ = true; |
201 bitrate_allocation_ = bitrate_allocation; | 195 bitrate_ = bitrate; |
202 framerate_ = framerate; | 196 framerate_ = framerate; |
203 int32_t ret = encoder_->SetRateAllocation(bitrate_allocation_, framerate); | 197 int32_t ret = encoder_->SetRates(bitrate, framerate); |
204 if (fallback_encoder_) | 198 if (fallback_encoder_) |
205 return fallback_encoder_->SetRateAllocation(bitrate_allocation_, framerate); | 199 return fallback_encoder_->SetRates(bitrate, framerate); |
206 return ret; | 200 return ret; |
207 } | 201 } |
208 | 202 |
209 void VideoEncoderSoftwareFallbackWrapper::OnDroppedFrame() { | 203 void VideoEncoderSoftwareFallbackWrapper::OnDroppedFrame() { |
210 if (fallback_encoder_) | 204 if (fallback_encoder_) |
211 return fallback_encoder_->OnDroppedFrame(); | 205 return fallback_encoder_->OnDroppedFrame(); |
212 return encoder_->OnDroppedFrame(); | 206 return encoder_->OnDroppedFrame(); |
213 } | 207 } |
214 | 208 |
215 bool VideoEncoderSoftwareFallbackWrapper::SupportsNativeHandle() const { | 209 bool VideoEncoderSoftwareFallbackWrapper::SupportsNativeHandle() const { |
216 if (fallback_encoder_) | 210 if (fallback_encoder_) |
217 return fallback_encoder_->SupportsNativeHandle(); | 211 return fallback_encoder_->SupportsNativeHandle(); |
218 return encoder_->SupportsNativeHandle(); | 212 return encoder_->SupportsNativeHandle(); |
219 } | 213 } |
220 | 214 |
221 } // namespace webrtc | 215 } // namespace webrtc |
OLD | NEW |