Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(658)

Side by Side Diff: webrtc/video/video_encoder.cc

Issue 2488833004: Reland of Issue 2434073003: Extract bitrate allocation ... (Closed)
Patch Set: Rebase Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/video/end_to_end_tests.cc ('k') | webrtc/video/video_encoder_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 : rates_set_(false), 70 : number_of_cores_(0),
71 max_payload_size_(0),
72 rates_set_(false),
73 framerate_(0),
71 channel_parameters_set_(false), 74 channel_parameters_set_(false),
75 packet_loss_(0),
76 rtt_(0),
72 encoder_type_(CodecToEncoderType(codec_type)), 77 encoder_type_(CodecToEncoderType(codec_type)),
73 encoder_(encoder), 78 encoder_(encoder),
74 callback_(nullptr) {} 79 callback_(nullptr) {}
75 80
76 bool VideoEncoderSoftwareFallbackWrapper::InitFallbackEncoder() { 81 bool VideoEncoderSoftwareFallbackWrapper::InitFallbackEncoder() {
77 if (!VideoEncoder::IsSupportedSoftware(encoder_type_)) { 82 if (!VideoEncoder::IsSupportedSoftware(encoder_type_)) {
78 LOG(LS_WARNING) 83 LOG(LS_WARNING)
79 << "Encoder requesting fallback to codec not supported in software."; 84 << "Encoder requesting fallback to codec not supported in software.";
80 return false; 85 return false;
81 } 86 }
82 fallback_encoder_.reset(VideoEncoder::Create(encoder_type_)); 87 fallback_encoder_.reset(VideoEncoder::Create(encoder_type_));
83 if (fallback_encoder_->InitEncode(&codec_settings_, number_of_cores_, 88 if (fallback_encoder_->InitEncode(&codec_settings_, number_of_cores_,
84 max_payload_size_) != 89 max_payload_size_) !=
85 WEBRTC_VIDEO_CODEC_OK) { 90 WEBRTC_VIDEO_CODEC_OK) {
86 LOG(LS_ERROR) << "Failed to initialize software-encoder fallback."; 91 LOG(LS_ERROR) << "Failed to initialize software-encoder fallback.";
87 fallback_encoder_->Release(); 92 fallback_encoder_->Release();
88 fallback_encoder_.reset(); 93 fallback_encoder_.reset();
89 return false; 94 return false;
90 } 95 }
91 // Replay callback, rates, and channel parameters. 96 // Replay callback, rates, and channel parameters.
92 if (callback_) 97 if (callback_)
93 fallback_encoder_->RegisterEncodeCompleteCallback(callback_); 98 fallback_encoder_->RegisterEncodeCompleteCallback(callback_);
94 if (rates_set_) 99 if (rates_set_)
95 fallback_encoder_->SetRates(bitrate_, framerate_); 100 fallback_encoder_->SetRateAllocation(bitrate_allocation_, framerate_);
96 if (channel_parameters_set_) 101 if (channel_parameters_set_)
97 fallback_encoder_->SetChannelParameters(packet_loss_, rtt_); 102 fallback_encoder_->SetChannelParameters(packet_loss_, rtt_);
98 103
99 fallback_implementation_name_ = 104 fallback_implementation_name_ =
100 std::string(fallback_encoder_->ImplementationName()) + 105 std::string(fallback_encoder_->ImplementationName()) +
101 " (fallback from: " + encoder_->ImplementationName() + ")"; 106 " (fallback from: " + encoder_->ImplementationName() + ")";
102 // Since we're switching to the fallback encoder, Release the real encoder. It 107 // Since we're switching to the fallback encoder, Release the real encoder. It
103 // may be re-initialized via InitEncode later, and it will continue to get 108 // may be re-initialized via InitEncode later, and it will continue to get
104 // Set calls for rates and channel parameters in the meantime. 109 // Set calls for rates and channel parameters in the meantime.
105 encoder_->Release(); 110 encoder_->Release();
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 int64_t rtt) { 187 int64_t rtt) {
183 channel_parameters_set_ = true; 188 channel_parameters_set_ = true;
184 packet_loss_ = packet_loss; 189 packet_loss_ = packet_loss;
185 rtt_ = rtt; 190 rtt_ = rtt;
186 int32_t ret = encoder_->SetChannelParameters(packet_loss, rtt); 191 int32_t ret = encoder_->SetChannelParameters(packet_loss, rtt);
187 if (fallback_encoder_) 192 if (fallback_encoder_)
188 return fallback_encoder_->SetChannelParameters(packet_loss, rtt); 193 return fallback_encoder_->SetChannelParameters(packet_loss, rtt);
189 return ret; 194 return ret;
190 } 195 }
191 196
192 int32_t VideoEncoderSoftwareFallbackWrapper::SetRates(uint32_t bitrate, 197 int32_t VideoEncoderSoftwareFallbackWrapper::SetRateAllocation(
193 uint32_t framerate) { 198 const BitrateAllocation& bitrate_allocation,
199 uint32_t framerate) {
194 rates_set_ = true; 200 rates_set_ = true;
195 bitrate_ = bitrate; 201 bitrate_allocation_ = bitrate_allocation;
196 framerate_ = framerate; 202 framerate_ = framerate;
197 int32_t ret = encoder_->SetRates(bitrate, framerate); 203 int32_t ret = encoder_->SetRateAllocation(bitrate_allocation_, framerate);
198 if (fallback_encoder_) 204 if (fallback_encoder_)
199 return fallback_encoder_->SetRates(bitrate, framerate); 205 return fallback_encoder_->SetRateAllocation(bitrate_allocation_, framerate);
200 return ret; 206 return ret;
201 } 207 }
202 208
203 void VideoEncoderSoftwareFallbackWrapper::OnDroppedFrame() { 209 void VideoEncoderSoftwareFallbackWrapper::OnDroppedFrame() {
204 if (fallback_encoder_) 210 if (fallback_encoder_)
205 return fallback_encoder_->OnDroppedFrame(); 211 return fallback_encoder_->OnDroppedFrame();
206 return encoder_->OnDroppedFrame(); 212 return encoder_->OnDroppedFrame();
207 } 213 }
208 214
209 bool VideoEncoderSoftwareFallbackWrapper::SupportsNativeHandle() const { 215 bool VideoEncoderSoftwareFallbackWrapper::SupportsNativeHandle() const {
210 if (fallback_encoder_) 216 if (fallback_encoder_)
211 return fallback_encoder_->SupportsNativeHandle(); 217 return fallback_encoder_->SupportsNativeHandle();
212 return encoder_->SupportsNativeHandle(); 218 return encoder_->SupportsNativeHandle();
213 } 219 }
214 220
215 } // namespace webrtc 221 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/end_to_end_tests.cc ('k') | webrtc/video/video_encoder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698