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/media/engine/videoencodersoftwarefallbackwrapper.h" | 11 #include "webrtc/media/engine/videoencodersoftwarefallbackwrapper.h" |
12 | 12 |
13 #include "webrtc/base/logging.h" | 13 #include "webrtc/base/logging.h" |
14 #include "webrtc/modules/video_coding/include/video_error_codes.h" | 14 #include "webrtc/modules/video_coding/include/video_error_codes.h" |
15 | 15 |
16 namespace webrtc { | 16 namespace webrtc { |
17 | 17 |
18 VideoEncoderSoftwareFallbackWrapper::VideoEncoderSoftwareFallbackWrapper( | 18 VideoEncoderSoftwareFallbackWrapper::VideoEncoderSoftwareFallbackWrapper( |
19 VideoCodecType codec_type, | 19 VideoCodecType codec_type, |
20 webrtc::VideoEncoder* encoder) | 20 webrtc::VideoEncoder* encoder) |
21 : rates_set_(false), | 21 : number_of_cores_(0), |
| 22 max_payload_size_(0), |
| 23 rates_set_(false), |
| 24 framerate_(0), |
22 channel_parameters_set_(false), | 25 channel_parameters_set_(false), |
| 26 packet_loss_(0), |
| 27 rtt_(0), |
23 encoder_type_(CodecToEncoderType(codec_type)), | 28 encoder_type_(CodecToEncoderType(codec_type)), |
24 encoder_(encoder), | 29 encoder_(encoder), |
25 callback_(nullptr) {} | 30 callback_(nullptr) {} |
26 | 31 |
27 bool VideoEncoderSoftwareFallbackWrapper::InitFallbackEncoder() { | 32 bool VideoEncoderSoftwareFallbackWrapper::InitFallbackEncoder() { |
28 if (!VideoEncoder::IsSupportedSoftware(encoder_type_)) { | 33 if (!VideoEncoder::IsSupportedSoftware(encoder_type_)) { |
29 LOG(LS_WARNING) | 34 LOG(LS_WARNING) |
30 << "Encoder requesting fallback to codec not supported in software."; | 35 << "Encoder requesting fallback to codec not supported in software."; |
31 return false; | 36 return false; |
32 } | 37 } |
33 fallback_encoder_.reset(VideoEncoder::Create(encoder_type_)); | 38 fallback_encoder_.reset(VideoEncoder::Create(encoder_type_)); |
34 if (fallback_encoder_->InitEncode(&codec_settings_, number_of_cores_, | 39 if (fallback_encoder_->InitEncode(&codec_settings_, number_of_cores_, |
35 max_payload_size_) != | 40 max_payload_size_) != |
36 WEBRTC_VIDEO_CODEC_OK) { | 41 WEBRTC_VIDEO_CODEC_OK) { |
37 LOG(LS_ERROR) << "Failed to initialize software-encoder fallback."; | 42 LOG(LS_ERROR) << "Failed to initialize software-encoder fallback."; |
38 fallback_encoder_->Release(); | 43 fallback_encoder_->Release(); |
39 fallback_encoder_.reset(); | 44 fallback_encoder_.reset(); |
40 return false; | 45 return false; |
41 } | 46 } |
42 // Replay callback, rates, and channel parameters. | 47 // Replay callback, rates, and channel parameters. |
43 if (callback_) | 48 if (callback_) |
44 fallback_encoder_->RegisterEncodeCompleteCallback(callback_); | 49 fallback_encoder_->RegisterEncodeCompleteCallback(callback_); |
45 if (rates_set_) | 50 if (rates_set_) |
46 fallback_encoder_->SetRates(bitrate_, framerate_); | 51 fallback_encoder_->SetRateAllocation(bitrate_allocation_, framerate_); |
47 if (channel_parameters_set_) | 52 if (channel_parameters_set_) |
48 fallback_encoder_->SetChannelParameters(packet_loss_, rtt_); | 53 fallback_encoder_->SetChannelParameters(packet_loss_, rtt_); |
49 | 54 |
50 fallback_implementation_name_ = | 55 fallback_implementation_name_ = |
51 std::string(fallback_encoder_->ImplementationName()) + | 56 std::string(fallback_encoder_->ImplementationName()) + |
52 " (fallback from: " + encoder_->ImplementationName() + ")"; | 57 " (fallback from: " + encoder_->ImplementationName() + ")"; |
53 // Since we're switching to the fallback encoder, Release the real encoder. It | 58 // Since we're switching to the fallback encoder, Release the real encoder. It |
54 // may be re-initialized via InitEncode later, and it will continue to get | 59 // may be re-initialized via InitEncode later, and it will continue to get |
55 // Set calls for rates and channel parameters in the meantime. | 60 // Set calls for rates and channel parameters in the meantime. |
56 encoder_->Release(); | 61 encoder_->Release(); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 int64_t rtt) { | 138 int64_t rtt) { |
134 channel_parameters_set_ = true; | 139 channel_parameters_set_ = true; |
135 packet_loss_ = packet_loss; | 140 packet_loss_ = packet_loss; |
136 rtt_ = rtt; | 141 rtt_ = rtt; |
137 int32_t ret = encoder_->SetChannelParameters(packet_loss, rtt); | 142 int32_t ret = encoder_->SetChannelParameters(packet_loss, rtt); |
138 if (fallback_encoder_) | 143 if (fallback_encoder_) |
139 return fallback_encoder_->SetChannelParameters(packet_loss, rtt); | 144 return fallback_encoder_->SetChannelParameters(packet_loss, rtt); |
140 return ret; | 145 return ret; |
141 } | 146 } |
142 | 147 |
143 int32_t VideoEncoderSoftwareFallbackWrapper::SetRates(uint32_t bitrate, | 148 int32_t VideoEncoderSoftwareFallbackWrapper::SetRateAllocation( |
144 uint32_t framerate) { | 149 const BitrateAllocation& bitrate_allocation, |
| 150 uint32_t framerate) { |
145 rates_set_ = true; | 151 rates_set_ = true; |
146 bitrate_ = bitrate; | 152 bitrate_allocation_ = bitrate_allocation; |
147 framerate_ = framerate; | 153 framerate_ = framerate; |
148 int32_t ret = encoder_->SetRates(bitrate, framerate); | 154 int32_t ret = encoder_->SetRateAllocation(bitrate_allocation_, framerate); |
149 if (fallback_encoder_) | 155 if (fallback_encoder_) |
150 return fallback_encoder_->SetRates(bitrate, framerate); | 156 return fallback_encoder_->SetRateAllocation(bitrate_allocation_, framerate); |
151 return ret; | 157 return ret; |
152 } | 158 } |
153 | 159 |
154 void VideoEncoderSoftwareFallbackWrapper::OnDroppedFrame() { | 160 void VideoEncoderSoftwareFallbackWrapper::OnDroppedFrame() { |
155 if (fallback_encoder_) | 161 if (fallback_encoder_) |
156 return fallback_encoder_->OnDroppedFrame(); | 162 return fallback_encoder_->OnDroppedFrame(); |
157 return encoder_->OnDroppedFrame(); | 163 return encoder_->OnDroppedFrame(); |
158 } | 164 } |
159 | 165 |
160 bool VideoEncoderSoftwareFallbackWrapper::SupportsNativeHandle() const { | 166 bool VideoEncoderSoftwareFallbackWrapper::SupportsNativeHandle() const { |
161 if (fallback_encoder_) | 167 if (fallback_encoder_) |
162 return fallback_encoder_->SupportsNativeHandle(); | 168 return fallback_encoder_->SupportsNativeHandle(); |
163 return encoder_->SupportsNativeHandle(); | 169 return encoder_->SupportsNativeHandle(); |
164 } | 170 } |
165 | 171 |
166 } // namespace webrtc | 172 } // namespace webrtc |
OLD | NEW |