| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 config_->rc_undershoot_pct = 50; | 299 config_->rc_undershoot_pct = 50; |
| 300 config_->rc_overshoot_pct = 50; | 300 config_->rc_overshoot_pct = 50; |
| 301 config_->rc_buf_initial_sz = 500; | 301 config_->rc_buf_initial_sz = 500; |
| 302 config_->rc_buf_optimal_sz = 600; | 302 config_->rc_buf_optimal_sz = 600; |
| 303 config_->rc_buf_sz = 1000; | 303 config_->rc_buf_sz = 1000; |
| 304 // Set the maximum target size of any key-frame. | 304 // Set the maximum target size of any key-frame. |
| 305 rc_max_intra_target_ = MaxIntraTarget(config_->rc_buf_optimal_sz); | 305 rc_max_intra_target_ = MaxIntraTarget(config_->rc_buf_optimal_sz); |
| 306 if (inst->codecSpecific.VP9.keyFrameInterval > 0) { | 306 if (inst->codecSpecific.VP9.keyFrameInterval > 0) { |
| 307 config_->kf_mode = VPX_KF_AUTO; | 307 config_->kf_mode = VPX_KF_AUTO; |
| 308 config_->kf_max_dist = inst->codecSpecific.VP9.keyFrameInterval; | 308 config_->kf_max_dist = inst->codecSpecific.VP9.keyFrameInterval; |
| 309 // Needs to be set (in svc mode) to get correct periodic key frame interval |
| 310 // (will have no effect in non-svc). |
| 311 config_->kf_min_dist = config_->kf_max_dist; |
| 309 } else { | 312 } else { |
| 310 config_->kf_mode = VPX_KF_DISABLED; | 313 config_->kf_mode = VPX_KF_DISABLED; |
| 311 } | 314 } |
| 312 config_->rc_resize_allowed = inst->codecSpecific.VP9.automaticResizeOn ? | 315 config_->rc_resize_allowed = inst->codecSpecific.VP9.automaticResizeOn ? |
| 313 1 : 0; | 316 1 : 0; |
| 314 // Determine number of threads based on the image size and #cores. | 317 // Determine number of threads based on the image size and #cores. |
| 315 config_->g_threads = NumberOfThreads(config_->g_w, | 318 config_->g_threads = NumberOfThreads(config_->g_w, |
| 316 config_->g_h, | 319 config_->g_h, |
| 317 number_of_cores); | 320 number_of_cores); |
| 318 | 321 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 return 4; | 375 return 4; |
| 373 } else if (width * height >= 640 * 480 && number_of_cores > 2) { | 376 } else if (width * height >= 640 * 480 && number_of_cores > 2) { |
| 374 return 2; | 377 return 2; |
| 375 } else { | 378 } else { |
| 376 // 1 thread less than VGA. | 379 // 1 thread less than VGA. |
| 377 return 1; | 380 return 1; |
| 378 } | 381 } |
| 379 } | 382 } |
| 380 | 383 |
| 381 int VP9EncoderImpl::InitAndSetControlSettings(const VideoCodec* inst) { | 384 int VP9EncoderImpl::InitAndSetControlSettings(const VideoCodec* inst) { |
| 385 // Set QP-min/max per spatial and temporal layer. |
| 386 int tot_num_layers = num_spatial_layers_ * num_temporal_layers_; |
| 387 for (int i = 0; i < tot_num_layers; ++i) { |
| 388 svc_internal_.svc_params.max_quantizers[i] = config_->rc_max_quantizer; |
| 389 svc_internal_.svc_params.min_quantizers[i] = config_->rc_min_quantizer; |
| 390 } |
| 382 config_->ss_number_layers = num_spatial_layers_; | 391 config_->ss_number_layers = num_spatial_layers_; |
| 383 | |
| 384 if (ExplicitlyConfiguredSpatialLayers()) { | 392 if (ExplicitlyConfiguredSpatialLayers()) { |
| 385 for (int i = 0; i < num_spatial_layers_; ++i) { | 393 for (int i = 0; i < num_spatial_layers_; ++i) { |
| 386 const auto& layer = codec_.spatialLayers[i]; | 394 const auto& layer = codec_.spatialLayers[i]; |
| 387 svc_internal_.svc_params.max_quantizers[i] = config_->rc_max_quantizer; | |
| 388 svc_internal_.svc_params.min_quantizers[i] = config_->rc_min_quantizer; | |
| 389 svc_internal_.svc_params.scaling_factor_num[i] = layer.scaling_factor_num; | 395 svc_internal_.svc_params.scaling_factor_num[i] = layer.scaling_factor_num; |
| 390 svc_internal_.svc_params.scaling_factor_den[i] = layer.scaling_factor_den; | 396 svc_internal_.svc_params.scaling_factor_den[i] = layer.scaling_factor_den; |
| 391 } | 397 } |
| 392 } else { | 398 } else { |
| 393 int scaling_factor_num = 256; | 399 int scaling_factor_num = 256; |
| 394 for (int i = num_spatial_layers_ - 1; i >= 0; --i) { | 400 for (int i = num_spatial_layers_ - 1; i >= 0; --i) { |
| 395 svc_internal_.svc_params.max_quantizers[i] = config_->rc_max_quantizer; | |
| 396 svc_internal_.svc_params.min_quantizers[i] = config_->rc_min_quantizer; | |
| 397 // 1:2 scaling in each dimension. | 401 // 1:2 scaling in each dimension. |
| 398 svc_internal_.svc_params.scaling_factor_num[i] = scaling_factor_num; | 402 svc_internal_.svc_params.scaling_factor_num[i] = scaling_factor_num; |
| 399 svc_internal_.svc_params.scaling_factor_den[i] = 256; | 403 svc_internal_.svc_params.scaling_factor_den[i] = 256; |
| 400 if (codec_.mode != kScreensharing) | 404 if (codec_.mode != kScreensharing) |
| 401 scaling_factor_num /= 2; | 405 scaling_factor_num /= 2; |
| 402 } | 406 } |
| 403 } | 407 } |
| 404 | 408 |
| 405 if (!SetSvcRates()) { | 409 if (!SetSvcRates()) { |
| 406 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; | 410 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 | 541 |
| 538 return WEBRTC_VIDEO_CODEC_OK; | 542 return WEBRTC_VIDEO_CODEC_OK; |
| 539 } | 543 } |
| 540 | 544 |
| 541 void VP9EncoderImpl::PopulateCodecSpecific(CodecSpecificInfo* codec_specific, | 545 void VP9EncoderImpl::PopulateCodecSpecific(CodecSpecificInfo* codec_specific, |
| 542 const vpx_codec_cx_pkt& pkt, | 546 const vpx_codec_cx_pkt& pkt, |
| 543 uint32_t timestamp) { | 547 uint32_t timestamp) { |
| 544 assert(codec_specific != NULL); | 548 assert(codec_specific != NULL); |
| 545 codec_specific->codecType = kVideoCodecVP9; | 549 codec_specific->codecType = kVideoCodecVP9; |
| 546 CodecSpecificInfoVP9 *vp9_info = &(codec_specific->codecSpecific.VP9); | 550 CodecSpecificInfoVP9 *vp9_info = &(codec_specific->codecSpecific.VP9); |
| 547 // TODO(asapersson): Set correct values. | 551 // TODO(asapersson): Set correct value. |
| 548 vp9_info->inter_pic_predicted = | 552 vp9_info->inter_pic_predicted = |
| 549 (pkt.data.frame.flags & VPX_FRAME_IS_KEY) ? false : true; | 553 (pkt.data.frame.flags & VPX_FRAME_IS_KEY) ? false : true; |
| 550 vp9_info->flexible_mode = codec_.codecSpecific.VP9.flexibleMode; | 554 vp9_info->flexible_mode = codec_.codecSpecific.VP9.flexibleMode; |
| 551 vp9_info->ss_data_available = ((pkt.data.frame.flags & VPX_FRAME_IS_KEY) && | 555 vp9_info->ss_data_available = ((pkt.data.frame.flags & VPX_FRAME_IS_KEY) && |
| 552 !codec_.codecSpecific.VP9.flexibleMode) | 556 !codec_.codecSpecific.VP9.flexibleMode) |
| 553 ? true | 557 ? true |
| 554 : false; | 558 : false; |
| 555 | 559 |
| 556 vpx_svc_layer_id_t layer_id = {0}; | 560 vpx_svc_layer_id_t layer_id = {0}; |
| 557 vpx_codec_control(encoder_, VP9E_GET_SVC_LAYER_ID, &layer_id); | 561 vpx_codec_control(encoder_, VP9E_GET_SVC_LAYER_ID, &layer_id); |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 966 decoder_ = NULL; | 970 decoder_ = NULL; |
| 967 } | 971 } |
| 968 // Releases buffers from the pool. Any buffers not in use are deleted. Buffers | 972 // Releases buffers from the pool. Any buffers not in use are deleted. Buffers |
| 969 // still referenced externally are deleted once fully released, not returning | 973 // still referenced externally are deleted once fully released, not returning |
| 970 // to the pool. | 974 // to the pool. |
| 971 frame_buffer_pool_.ClearPool(); | 975 frame_buffer_pool_.ClearPool(); |
| 972 inited_ = false; | 976 inited_ = false; |
| 973 return WEBRTC_VIDEO_CODEC_OK; | 977 return WEBRTC_VIDEO_CODEC_OK; |
| 974 } | 978 } |
| 975 } // namespace webrtc | 979 } // namespace webrtc |
| OLD | NEW |