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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
205 } | 205 } |
206 if (inst->width < 1 || inst->height < 1) { | 206 if (inst->width < 1 || inst->height < 1) { |
207 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; | 207 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; |
208 } | 208 } |
209 if (number_of_cores < 1) { | 209 if (number_of_cores < 1) { |
210 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; | 210 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; |
211 } | 211 } |
212 if (inst->codecSpecific.VP9.numberOfTemporalLayers > 3) { | 212 if (inst->codecSpecific.VP9.numberOfTemporalLayers > 3) { |
213 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; | 213 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; |
214 } | 214 } |
215 // For now, only support one spatial layer. | 215 // libvpx currently supports only one or two spatial layers. |
216 if (inst->codecSpecific.VP9.numberOfSpatialLayers != 1) { | 216 if (inst->codecSpecific.VP9.numberOfSpatialLayers > 2) { |
217 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; | 217 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; |
218 } | 218 } |
219 int retVal = Release(); | 219 int retVal = Release(); |
220 if (retVal < 0) { | 220 if (retVal < 0) { |
221 return retVal; | 221 return retVal; |
222 } | 222 } |
223 if (encoder_ == NULL) { | 223 if (encoder_ == NULL) { |
224 encoder_ = new vpx_codec_ctx_t; | 224 encoder_ = new vpx_codec_ctx_t; |
225 } | 225 } |
226 if (config_ == NULL) { | 226 if (config_ == NULL) { |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
344 return 4; | 344 return 4; |
345 } else if (width * height >= 640 * 480 && number_of_cores > 2) { | 345 } else if (width * height >= 640 * 480 && number_of_cores > 2) { |
346 return 2; | 346 return 2; |
347 } else { | 347 } else { |
348 // 1 thread less than VGA. | 348 // 1 thread less than VGA. |
349 return 1; | 349 return 1; |
350 } | 350 } |
351 } | 351 } |
352 | 352 |
353 int VP9EncoderImpl::InitAndSetControlSettings(const VideoCodec* inst) { | 353 int VP9EncoderImpl::InitAndSetControlSettings(const VideoCodec* inst) { |
354 | |
355 config_->ss_number_layers = num_spatial_layers_; | 354 config_->ss_number_layers = num_spatial_layers_; |
356 | 355 |
357 if (num_spatial_layers_ > 1) { | 356 if (num_spatial_layers_ > 1) { |
mflodman
2015/08/27 07:27:48
I don't know the background for when to set min qp
ivica
2015/08/27 08:49:23
I don't know why was it set to 0 here. I removed t
| |
358 config_->rc_min_quantizer = 0; | 357 config_->rc_min_quantizer = 0; |
359 config_->rc_max_quantizer = 63; | 358 config_->rc_max_quantizer = 52; |
mflodman
2015/08/27 07:27:48
AFAICT this isn't needed, the max quantizer is alr
ivica
2015/08/27 08:49:23
I changed from 63 to 52, because 63 looks really b
| |
360 } | 359 } |
361 int scaling_factor_num = 256; | 360 int scaling_factor_num = 256; |
362 for (int i = num_spatial_layers_ - 1; i >= 0; --i) { | 361 for (int i = num_spatial_layers_ - 1; i >= 0; --i) { |
363 svc_internal_.svc_params.max_quantizers[i] = config_->rc_max_quantizer; | 362 svc_internal_.svc_params.max_quantizers[i] = config_->rc_max_quantizer; |
364 svc_internal_.svc_params.min_quantizers[i] = config_->rc_min_quantizer; | 363 svc_internal_.svc_params.min_quantizers[i] = config_->rc_min_quantizer; |
365 // 1:2 scaling in each dimension. | 364 // 1:2 scaling in each dimension. |
366 svc_internal_.svc_params.scaling_factor_num[i] = scaling_factor_num; | 365 svc_internal_.svc_params.scaling_factor_num[i] = scaling_factor_num; |
367 svc_internal_.svc_params.scaling_factor_den[i] = 256; | 366 svc_internal_.svc_params.scaling_factor_den[i] = 256; |
368 scaling_factor_num /= 2; | 367 scaling_factor_num /= 2; |
369 } | 368 } |
(...skipping 27 matching lines...) Expand all Loading... | |
397 // log2 unit: e.g., 0 = 1 tile column, 1 = 2 tile columns, 2 = 4 tile columns. | 396 // log2 unit: e.g., 0 = 1 tile column, 1 = 2 tile columns, 2 = 4 tile columns. |
398 // The number tile columns will be capped by the encoder based on image size | 397 // The number tile columns will be capped by the encoder based on image size |
399 // (minimum width of tile column is 256 pixels, maximum is 4096). | 398 // (minimum width of tile column is 256 pixels, maximum is 4096). |
400 vpx_codec_control(encoder_, VP9E_SET_TILE_COLUMNS, (config_->g_threads >> 1)); | 399 vpx_codec_control(encoder_, VP9E_SET_TILE_COLUMNS, (config_->g_threads >> 1)); |
401 #if !defined(WEBRTC_ARCH_ARM) && !defined(WEBRTC_ARCH_ARM64) | 400 #if !defined(WEBRTC_ARCH_ARM) && !defined(WEBRTC_ARCH_ARM64) |
402 // Note denoiser is still off by default until further testing/optimization, | 401 // Note denoiser is still off by default until further testing/optimization, |
403 // i.e., codecSpecific.VP9.denoisingOn == 0. | 402 // i.e., codecSpecific.VP9.denoisingOn == 0. |
404 vpx_codec_control(encoder_, VP9E_SET_NOISE_SENSITIVITY, | 403 vpx_codec_control(encoder_, VP9E_SET_NOISE_SENSITIVITY, |
405 inst->codecSpecific.VP9.denoisingOn ? 1 : 0); | 404 inst->codecSpecific.VP9.denoisingOn ? 1 : 0); |
406 #endif | 405 #endif |
406 if (codec_.mode == kScreensharing) { | |
407 vpx_codec_control(encoder_, VP9E_SET_TUNE_CONTENT, 1); | |
408 } | |
409 vpx_codec_control(encoder_, VP8E_SET_STATIC_THRESHOLD, 1); | |
407 inited_ = true; | 410 inited_ = true; |
408 return WEBRTC_VIDEO_CODEC_OK; | 411 return WEBRTC_VIDEO_CODEC_OK; |
409 } | 412 } |
410 | 413 |
411 uint32_t VP9EncoderImpl::MaxIntraTarget(uint32_t optimal_buffer_size) { | 414 uint32_t VP9EncoderImpl::MaxIntraTarget(uint32_t optimal_buffer_size) { |
412 // Set max to the optimal buffer level (normalized by target BR), | 415 // Set max to the optimal buffer level (normalized by target BR), |
413 // and scaled by a scale_par. | 416 // and scaled by a scale_par. |
414 // Max target size = scale_par * optimal_buffer_size * targetBR[Kbps]. | 417 // Max target size = scale_par * optimal_buffer_size * targetBR[Kbps]. |
415 // This value is presented in percentage of perFrameBw: | 418 // This value is presented in percentage of perFrameBw: |
416 // perFrameBw = targetBR[Kbps] * 1000 / framerate. | 419 // perFrameBw = targetBR[Kbps] * 1000 / framerate. |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
533 | 536 |
534 vp9_info->picture_id = picture_id_; | 537 vp9_info->picture_id = picture_id_; |
535 | 538 |
536 if (!vp9_info->flexible_mode) { | 539 if (!vp9_info->flexible_mode) { |
537 if (layer_id.temporal_layer_id == 0 && layer_id.spatial_layer_id == 0) { | 540 if (layer_id.temporal_layer_id == 0 && layer_id.spatial_layer_id == 0) { |
538 tl0_pic_idx_++; | 541 tl0_pic_idx_++; |
539 } | 542 } |
540 vp9_info->tl0_pic_idx = tl0_pic_idx_; | 543 vp9_info->tl0_pic_idx = tl0_pic_idx_; |
541 } | 544 } |
542 | 545 |
546 // Always populate this, so that packetizer can properly set the marker bit. | |
547 vp9_info->num_spatial_layers = num_spatial_layers_; | |
543 if (vp9_info->ss_data_available) { | 548 if (vp9_info->ss_data_available) { |
544 vp9_info->num_spatial_layers = num_spatial_layers_; | |
545 vp9_info->spatial_layer_resolution_present = true; | 549 vp9_info->spatial_layer_resolution_present = true; |
546 for (size_t i = 0; i < vp9_info->num_spatial_layers; ++i) { | 550 for (size_t i = 0; i < vp9_info->num_spatial_layers; ++i) { |
547 vp9_info->width[i] = codec_.width * | 551 vp9_info->width[i] = codec_.width * |
548 svc_internal_.svc_params.scaling_factor_num[i] / | 552 svc_internal_.svc_params.scaling_factor_num[i] / |
549 svc_internal_.svc_params.scaling_factor_den[i]; | 553 svc_internal_.svc_params.scaling_factor_den[i]; |
550 vp9_info->height[i] = codec_.height * | 554 vp9_info->height[i] = codec_.height * |
551 svc_internal_.svc_params.scaling_factor_num[i] / | 555 svc_internal_.svc_params.scaling_factor_num[i] / |
552 svc_internal_.svc_params.scaling_factor_den[i]; | 556 svc_internal_.svc_params.scaling_factor_den[i]; |
553 } | 557 } |
554 if (!vp9_info->flexible_mode) { | 558 if (!vp9_info->flexible_mode) { |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
775 decoder_ = NULL; | 779 decoder_ = NULL; |
776 } | 780 } |
777 // Releases buffers from the pool. Any buffers not in use are deleted. Buffers | 781 // Releases buffers from the pool. Any buffers not in use are deleted. Buffers |
778 // still referenced externally are deleted once fully released, not returning | 782 // still referenced externally are deleted once fully released, not returning |
779 // to the pool. | 783 // to the pool. |
780 frame_buffer_pool_.ClearPool(); | 784 frame_buffer_pool_.ClearPool(); |
781 inited_ = false; | 785 inited_ = false; |
782 return WEBRTC_VIDEO_CODEC_OK; | 786 return WEBRTC_VIDEO_CODEC_OK; |
783 } | 787 } |
784 } // namespace webrtc | 788 } // namespace webrtc |
OLD | NEW |