| 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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 // Copy the entire layer's data (including start codes). | 145 // Copy the entire layer's data (including start codes). |
| 146 memcpy(encoded_image->_buffer + encoded_image->_length, | 146 memcpy(encoded_image->_buffer + encoded_image->_length, |
| 147 layerInfo.pBsBuf, | 147 layerInfo.pBsBuf, |
| 148 layer_len); | 148 layer_len); |
| 149 encoded_image->_length += layer_len; | 149 encoded_image->_length += layer_len; |
| 150 } | 150 } |
| 151 } | 151 } |
| 152 | 152 |
| 153 H264EncoderImpl::H264EncoderImpl() | 153 H264EncoderImpl::H264EncoderImpl() |
| 154 : openh264_encoder_(nullptr), | 154 : openh264_encoder_(nullptr), |
| 155 width_(0), |
| 156 height_(0), |
| 157 max_frame_rate_(0.0f), |
| 158 target_bps_(0), |
| 159 max_bps_(0), |
| 160 mode_(kRealtimeVideo), |
| 161 frame_dropping_on_(false), |
| 162 key_frame_interval_(0), |
| 155 number_of_cores_(0), | 163 number_of_cores_(0), |
| 156 encoded_image_callback_(nullptr), | 164 encoded_image_callback_(nullptr), |
| 157 has_reported_init_(false), | 165 has_reported_init_(false), |
| 158 has_reported_error_(false) {} | 166 has_reported_error_(false) {} |
| 159 | 167 |
| 160 H264EncoderImpl::~H264EncoderImpl() { | 168 H264EncoderImpl::~H264EncoderImpl() { |
| 161 Release(); | 169 Release(); |
| 162 } | 170 } |
| 163 | 171 |
| 164 int32_t H264EncoderImpl::InitEncode(const VideoCodec* codec_settings, | 172 int32_t H264EncoderImpl::InitEncode(const VideoCodec* codec_settings, |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 encoded_image_buffer_.reset(); | 264 encoded_image_buffer_.reset(); |
| 257 return WEBRTC_VIDEO_CODEC_OK; | 265 return WEBRTC_VIDEO_CODEC_OK; |
| 258 } | 266 } |
| 259 | 267 |
| 260 int32_t H264EncoderImpl::RegisterEncodeCompleteCallback( | 268 int32_t H264EncoderImpl::RegisterEncodeCompleteCallback( |
| 261 EncodedImageCallback* callback) { | 269 EncodedImageCallback* callback) { |
| 262 encoded_image_callback_ = callback; | 270 encoded_image_callback_ = callback; |
| 263 return WEBRTC_VIDEO_CODEC_OK; | 271 return WEBRTC_VIDEO_CODEC_OK; |
| 264 } | 272 } |
| 265 | 273 |
| 266 int32_t H264EncoderImpl::SetRates(uint32_t bitrate, uint32_t framerate) { | 274 int32_t H264EncoderImpl::SetRateAllocation( |
| 267 if (bitrate <= 0 || framerate <= 0) { | 275 const BitrateAllocation& bitrate_allocation, |
| 276 uint32_t framerate) { |
| 277 if (bitrate_allocation.get_sum_bps() <= 0 || framerate <= 0) |
| 268 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; | 278 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; |
| 269 } | 279 |
| 270 target_bps_ = bitrate * 1000; | 280 target_bps_ = bitrate_allocation.get_sum_bps(); |
| 271 max_frame_rate_ = static_cast<float>(framerate); | 281 max_frame_rate_ = static_cast<float>(framerate); |
| 272 quality_scaler_.ReportFramerate(framerate); | 282 quality_scaler_.ReportFramerate(framerate); |
| 273 | 283 |
| 274 SBitrateInfo target_bitrate; | 284 SBitrateInfo target_bitrate; |
| 275 memset(&target_bitrate, 0, sizeof(SBitrateInfo)); | 285 memset(&target_bitrate, 0, sizeof(SBitrateInfo)); |
| 276 target_bitrate.iLayer = SPATIAL_LAYER_ALL, | 286 target_bitrate.iLayer = SPATIAL_LAYER_ALL, |
| 277 target_bitrate.iBitrate = target_bps_; | 287 target_bitrate.iBitrate = target_bps_; |
| 278 openh264_encoder_->SetOption(ENCODER_OPTION_BITRATE, | 288 openh264_encoder_->SetOption(ENCODER_OPTION_BITRATE, |
| 279 &target_bitrate); | 289 &target_bitrate); |
| 280 openh264_encoder_->SetOption(ENCODER_OPTION_FRAME_RATE, &max_frame_rate_); | 290 openh264_encoder_->SetOption(ENCODER_OPTION_FRAME_RATE, &max_frame_rate_); |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 | 496 |
| 487 int32_t H264EncoderImpl::SetPeriodicKeyFrames(bool enable) { | 497 int32_t H264EncoderImpl::SetPeriodicKeyFrames(bool enable) { |
| 488 return WEBRTC_VIDEO_CODEC_OK; | 498 return WEBRTC_VIDEO_CODEC_OK; |
| 489 } | 499 } |
| 490 | 500 |
| 491 void H264EncoderImpl::OnDroppedFrame() { | 501 void H264EncoderImpl::OnDroppedFrame() { |
| 492 quality_scaler_.ReportDroppedFrame(); | 502 quality_scaler_.ReportDroppedFrame(); |
| 493 } | 503 } |
| 494 | 504 |
| 495 } // namespace webrtc | 505 } // namespace webrtc |
| OLD | NEW |