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

Side by Side Diff: webrtc/modules/video_coding/codecs/h264/h264_encoder_impl.cc

Issue 2434073003: Extract bitrate allocation of spatial/temporal layers out of codec impl. (Closed)
Patch Set: Fixed sign mismatch 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
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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 // Copy the entire layer's data (including start codes). 142 // Copy the entire layer's data (including start codes).
143 memcpy(encoded_image->_buffer + encoded_image->_length, 143 memcpy(encoded_image->_buffer + encoded_image->_length,
144 layerInfo.pBsBuf, 144 layerInfo.pBsBuf,
145 layer_len); 145 layer_len);
146 encoded_image->_length += layer_len; 146 encoded_image->_length += layer_len;
147 } 147 }
148 } 148 }
149 149
150 H264EncoderImpl::H264EncoderImpl() 150 H264EncoderImpl::H264EncoderImpl()
151 : openh264_encoder_(nullptr), 151 : openh264_encoder_(nullptr),
152 number_of_cores_(0),
152 encoded_image_callback_(nullptr), 153 encoded_image_callback_(nullptr),
153 has_reported_init_(false), 154 has_reported_init_(false),
154 has_reported_error_(false) { 155 has_reported_error_(false) {}
155 }
156 156
157 H264EncoderImpl::~H264EncoderImpl() { 157 H264EncoderImpl::~H264EncoderImpl() {
158 Release(); 158 Release();
159 } 159 }
160 160
161 int32_t H264EncoderImpl::InitEncode(const VideoCodec* codec_settings, 161 int32_t H264EncoderImpl::InitEncode(const VideoCodec* codec_settings,
162 int32_t number_of_cores, 162 int32_t number_of_cores,
163 size_t /*max_payload_size*/) { 163 size_t /*max_payload_size*/) {
164 ReportInit(); 164 ReportInit();
165 if (!codec_settings || 165 if (!codec_settings ||
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 encoded_image_buffer_.reset(); 242 encoded_image_buffer_.reset();
243 return WEBRTC_VIDEO_CODEC_OK; 243 return WEBRTC_VIDEO_CODEC_OK;
244 } 244 }
245 245
246 int32_t H264EncoderImpl::RegisterEncodeCompleteCallback( 246 int32_t H264EncoderImpl::RegisterEncodeCompleteCallback(
247 EncodedImageCallback* callback) { 247 EncodedImageCallback* callback) {
248 encoded_image_callback_ = callback; 248 encoded_image_callback_ = callback;
249 return WEBRTC_VIDEO_CODEC_OK; 249 return WEBRTC_VIDEO_CODEC_OK;
250 } 250 }
251 251
252 int32_t H264EncoderImpl::SetRates(uint32_t bitrate, uint32_t framerate) { 252 int32_t H264EncoderImpl::SetRateAllocation(
253 if (bitrate <= 0 || framerate <= 0) { 253 const BitrateAllocation& bitrate_allocation,
254 uint32_t framerate) {
255 if (bitrate_allocation.get_sum_kbps() <= 0 || framerate <= 0) {
254 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; 256 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
255 } 257 }
256 codec_settings_.targetBitrate = bitrate; 258 codec_settings_.targetBitrate = bitrate_allocation.get_sum_kbps();
257 codec_settings_.maxFramerate = framerate; 259 codec_settings_.maxFramerate = framerate;
258 quality_scaler_.ReportFramerate(framerate); 260 quality_scaler_.ReportFramerate(framerate);
259 261
260 SBitrateInfo target_bitrate; 262 SBitrateInfo target_bitrate;
261 memset(&target_bitrate, 0, sizeof(SBitrateInfo)); 263 memset(&target_bitrate, 0, sizeof(SBitrateInfo));
262 target_bitrate.iLayer = SPATIAL_LAYER_ALL, 264 target_bitrate.iLayer = SPATIAL_LAYER_ALL,
263 target_bitrate.iBitrate = codec_settings_.targetBitrate * 1000; 265 target_bitrate.iBitrate = codec_settings_.targetBitrate * 1000;
264 openh264_encoder_->SetOption(ENCODER_OPTION_BITRATE, 266 openh264_encoder_->SetOption(ENCODER_OPTION_BITRATE,
265 &target_bitrate); 267 &target_bitrate);
266 float max_framerate = static_cast<float>(codec_settings_.maxFramerate); 268 float max_framerate = static_cast<float>(codec_settings_.maxFramerate);
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 471
470 int32_t H264EncoderImpl::SetPeriodicKeyFrames(bool enable) { 472 int32_t H264EncoderImpl::SetPeriodicKeyFrames(bool enable) {
471 return WEBRTC_VIDEO_CODEC_OK; 473 return WEBRTC_VIDEO_CODEC_OK;
472 } 474 }
473 475
474 void H264EncoderImpl::OnDroppedFrame() { 476 void H264EncoderImpl::OnDroppedFrame() {
475 quality_scaler_.ReportDroppedFrame(); 477 quality_scaler_.ReportDroppedFrame();
476 } 478 }
477 479
478 } // namespace webrtc 480 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698