| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebM 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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 RANGE_CHECK(cfg, g_pass, VPX_RC_ONE_PASS, VPX_RC_LAST_PASS); | 169 RANGE_CHECK(cfg, g_pass, VPX_RC_ONE_PASS, VPX_RC_LAST_PASS); |
| 170 | 170 |
| 171 if (cfg->rc_resize_allowed == 1) { | 171 if (cfg->rc_resize_allowed == 1) { |
| 172 RANGE_CHECK(cfg, rc_scaled_width, 0, cfg->g_w); | 172 RANGE_CHECK(cfg, rc_scaled_width, 0, cfg->g_w); |
| 173 RANGE_CHECK(cfg, rc_scaled_height, 0, cfg->g_h); | 173 RANGE_CHECK(cfg, rc_scaled_height, 0, cfg->g_h); |
| 174 } | 174 } |
| 175 | 175 |
| 176 RANGE_CHECK(cfg, ss_number_layers, 1, VPX_SS_MAX_LAYERS); | 176 RANGE_CHECK(cfg, ss_number_layers, 1, VPX_SS_MAX_LAYERS); |
| 177 RANGE_CHECK(cfg, ts_number_layers, 1, VPX_TS_MAX_LAYERS); | 177 RANGE_CHECK(cfg, ts_number_layers, 1, VPX_TS_MAX_LAYERS); |
| 178 | 178 |
| 179 if (cfg->ss_number_layers * cfg->ts_number_layers > VPX_MAX_LAYERS) |
| 180 ERROR("ss_number_layers * ts_number_layers is out of range"); |
| 179 if (cfg->ts_number_layers > 1) { | 181 if (cfg->ts_number_layers > 1) { |
| 180 unsigned int i; | 182 unsigned int sl, tl; |
| 181 for (i = 1; i < cfg->ts_number_layers; ++i) | 183 for (sl = 1; sl < cfg->ss_number_layers; ++sl) { |
| 182 if (cfg->ts_target_bitrate[i] < cfg->ts_target_bitrate[i - 1]) | 184 for (tl = 1; tl < cfg->ts_number_layers; ++tl) { |
| 185 const int layer = |
| 186 LAYER_IDS_TO_IDX(sl, tl, cfg->ts_number_layers); |
| 187 if (cfg->layer_target_bitrate[layer] < |
| 188 cfg->layer_target_bitrate[layer - 1]) |
| 183 ERROR("ts_target_bitrate entries are not increasing"); | 189 ERROR("ts_target_bitrate entries are not increasing"); |
| 190 } |
| 191 } |
| 184 | 192 |
| 185 RANGE_CHECK(cfg, ts_rate_decimator[cfg->ts_number_layers - 1], 1, 1); | 193 RANGE_CHECK(cfg, ts_rate_decimator[cfg->ts_number_layers - 1], 1, 1); |
| 186 for (i = cfg->ts_number_layers - 2; i > 0; --i) | 194 for (tl = cfg->ts_number_layers - 2; tl > 0; --tl) |
| 187 if (cfg->ts_rate_decimator[i - 1] != 2 * cfg->ts_rate_decimator[i]) | 195 if (cfg->ts_rate_decimator[tl - 1] != 2 * cfg->ts_rate_decimator[tl]) |
| 188 ERROR("ts_rate_decimator factors are not powers of 2"); | 196 ERROR("ts_rate_decimator factors are not powers of 2"); |
| 189 } | 197 } |
| 190 | 198 |
| 191 #if CONFIG_SPATIAL_SVC | 199 #if CONFIG_SPATIAL_SVC |
| 192 | 200 |
| 193 if ((cfg->ss_number_layers > 1 || cfg->ts_number_layers > 1) && | 201 if ((cfg->ss_number_layers > 1 || cfg->ts_number_layers > 1) && |
| 194 cfg->g_pass == VPX_RC_LAST_PASS) { | 202 cfg->g_pass == VPX_RC_LAST_PASS) { |
| 195 unsigned int i, alt_ref_sum = 0; | 203 unsigned int i, alt_ref_sum = 0; |
| 196 for (i = 0; i < cfg->ss_number_layers; ++i) { | 204 for (i = 0; i < cfg->ss_number_layers; ++i) { |
| 197 if (cfg->ss_enable_auto_alt_ref[i]) | 205 if (cfg->ss_enable_auto_alt_ref[i]) |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 default: assert(0 && "Invalid image format"); break; | 361 default: assert(0 && "Invalid image format"); break; |
| 354 } | 362 } |
| 355 return 0; | 363 return 0; |
| 356 } | 364 } |
| 357 | 365 |
| 358 static vpx_codec_err_t set_encoder_config( | 366 static vpx_codec_err_t set_encoder_config( |
| 359 VP9EncoderConfig *oxcf, | 367 VP9EncoderConfig *oxcf, |
| 360 const vpx_codec_enc_cfg_t *cfg, | 368 const vpx_codec_enc_cfg_t *cfg, |
| 361 const struct vp9_extracfg *extra_cfg) { | 369 const struct vp9_extracfg *extra_cfg) { |
| 362 const int is_vbr = cfg->rc_end_usage == VPX_VBR; | 370 const int is_vbr = cfg->rc_end_usage == VPX_VBR; |
| 371 int sl, tl; |
| 363 oxcf->profile = cfg->g_profile; | 372 oxcf->profile = cfg->g_profile; |
| 364 oxcf->max_threads = (int)cfg->g_threads; | 373 oxcf->max_threads = (int)cfg->g_threads; |
| 365 oxcf->width = cfg->g_w; | 374 oxcf->width = cfg->g_w; |
| 366 oxcf->height = cfg->g_h; | 375 oxcf->height = cfg->g_h; |
| 367 oxcf->bit_depth = cfg->g_bit_depth; | 376 oxcf->bit_depth = cfg->g_bit_depth; |
| 368 oxcf->input_bit_depth = cfg->g_input_bit_depth; | 377 oxcf->input_bit_depth = cfg->g_input_bit_depth; |
| 369 // guess a frame rate if out of whack, use 30 | 378 // guess a frame rate if out of whack, use 30 |
| 370 oxcf->init_framerate = (double)cfg->g_timebase.den / cfg->g_timebase.num; | 379 oxcf->init_framerate = (double)cfg->g_timebase.den / cfg->g_timebase.num; |
| 371 if (oxcf->init_framerate > 180) | 380 if (oxcf->init_framerate > 180) |
| 372 oxcf->init_framerate = 30; | 381 oxcf->init_framerate = 30; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 oxcf->tile_rows = extra_cfg->tile_rows; | 462 oxcf->tile_rows = extra_cfg->tile_rows; |
| 454 | 463 |
| 455 oxcf->error_resilient_mode = cfg->g_error_resilient; | 464 oxcf->error_resilient_mode = cfg->g_error_resilient; |
| 456 oxcf->frame_parallel_decoding_mode = extra_cfg->frame_parallel_decoding_mode; | 465 oxcf->frame_parallel_decoding_mode = extra_cfg->frame_parallel_decoding_mode; |
| 457 | 466 |
| 458 oxcf->aq_mode = extra_cfg->aq_mode; | 467 oxcf->aq_mode = extra_cfg->aq_mode; |
| 459 | 468 |
| 460 oxcf->frame_periodic_boost = extra_cfg->frame_periodic_boost; | 469 oxcf->frame_periodic_boost = extra_cfg->frame_periodic_boost; |
| 461 | 470 |
| 462 oxcf->ss_number_layers = cfg->ss_number_layers; | 471 oxcf->ss_number_layers = cfg->ss_number_layers; |
| 472 oxcf->ts_number_layers = cfg->ts_number_layers; |
| 473 oxcf->temporal_layering_mode = (enum vp9e_temporal_layering_mode) |
| 474 cfg->temporal_layering_mode; |
| 463 | 475 |
| 464 if (oxcf->ss_number_layers > 1) { | 476 for (sl = 0; sl < oxcf->ss_number_layers; ++sl) { |
| 465 int i; | |
| 466 for (i = 0; i < VPX_SS_MAX_LAYERS; ++i) { | |
| 467 oxcf->ss_target_bitrate[i] = 1000 * cfg->ss_target_bitrate[i]; | |
| 468 #if CONFIG_SPATIAL_SVC | 477 #if CONFIG_SPATIAL_SVC |
| 469 oxcf->ss_enable_auto_arf[i] = cfg->ss_enable_auto_alt_ref[i]; | 478 oxcf->ss_enable_auto_arf[sl] = cfg->ss_enable_auto_alt_ref[sl]; |
| 470 #endif | 479 #endif |
| 480 for (tl = 0; tl < oxcf->ts_number_layers; ++tl) { |
| 481 oxcf->layer_target_bitrate[sl * oxcf->ts_number_layers + tl] = |
| 482 1000 * cfg->layer_target_bitrate[sl * oxcf->ts_number_layers + tl]; |
| 471 } | 483 } |
| 472 } else if (oxcf->ss_number_layers == 1) { | 484 } |
| 485 if (oxcf->ss_number_layers == 1 && oxcf->pass != 0) { |
| 473 oxcf->ss_target_bitrate[0] = (int)oxcf->target_bandwidth; | 486 oxcf->ss_target_bitrate[0] = (int)oxcf->target_bandwidth; |
| 474 #if CONFIG_SPATIAL_SVC | 487 #if CONFIG_SPATIAL_SVC |
| 475 oxcf->ss_enable_auto_arf[0] = extra_cfg->enable_auto_alt_ref; | 488 oxcf->ss_enable_auto_arf[0] = extra_cfg->enable_auto_alt_ref; |
| 476 #endif | 489 #endif |
| 477 } | 490 } |
| 478 | |
| 479 oxcf->ts_number_layers = cfg->ts_number_layers; | |
| 480 | |
| 481 if (oxcf->ts_number_layers > 1) { | 491 if (oxcf->ts_number_layers > 1) { |
| 482 int i; | 492 for (tl = 0; tl < VPX_TS_MAX_LAYERS; ++tl) { |
| 483 for (i = 0; i < VPX_TS_MAX_LAYERS; ++i) { | 493 oxcf->ts_rate_decimator[tl] = cfg->ts_rate_decimator[tl] ? |
| 484 oxcf->ts_target_bitrate[i] = 1000 * cfg->ts_target_bitrate[i]; | 494 cfg->ts_rate_decimator[tl] : 1; |
| 485 oxcf->ts_rate_decimator[i] = cfg->ts_rate_decimator[i]; | |
| 486 } | 495 } |
| 487 } else if (oxcf->ts_number_layers == 1) { | 496 } else if (oxcf->ts_number_layers == 1) { |
| 488 oxcf->ts_target_bitrate[0] = (int)oxcf->target_bandwidth; | |
| 489 oxcf->ts_rate_decimator[0] = 1; | 497 oxcf->ts_rate_decimator[0] = 1; |
| 490 } | 498 } |
| 491 | |
| 492 /* | 499 /* |
| 493 printf("Current VP9 Settings: \n"); | 500 printf("Current VP9 Settings: \n"); |
| 494 printf("target_bandwidth: %d\n", oxcf->target_bandwidth); | 501 printf("target_bandwidth: %d\n", oxcf->target_bandwidth); |
| 495 printf("noise_sensitivity: %d\n", oxcf->noise_sensitivity); | 502 printf("noise_sensitivity: %d\n", oxcf->noise_sensitivity); |
| 496 printf("sharpness: %d\n", oxcf->sharpness); | 503 printf("sharpness: %d\n", oxcf->sharpness); |
| 497 printf("cpu_used: %d\n", oxcf->cpu_used); | 504 printf("cpu_used: %d\n", oxcf->cpu_used); |
| 498 printf("Mode: %d\n", oxcf->mode); | 505 printf("Mode: %d\n", oxcf->mode); |
| 499 printf("auto_key: %d\n", oxcf->auto_key); | 506 printf("auto_key: %d\n", oxcf->auto_key); |
| 500 printf("key_freq: %d\n", oxcf->key_freq); | 507 printf("key_freq: %d\n", oxcf->key_freq); |
| 501 printf("end_usage: %d\n", oxcf->end_usage); | 508 printf("end_usage: %d\n", oxcf->end_usage); |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 895 static int64_t ticks_to_timebase_units(const vpx_rational_t *timebase, | 902 static int64_t ticks_to_timebase_units(const vpx_rational_t *timebase, |
| 896 int64_t n) { | 903 int64_t n) { |
| 897 const int64_t round = TICKS_PER_SEC * timebase->num / 2 - 1; | 904 const int64_t round = TICKS_PER_SEC * timebase->num / 2 - 1; |
| 898 return (n * timebase->den + round) / timebase->num / TICKS_PER_SEC; | 905 return (n * timebase->den + round) / timebase->num / TICKS_PER_SEC; |
| 899 } | 906 } |
| 900 | 907 |
| 901 static vpx_codec_frame_flags_t get_frame_pkt_flags(const VP9_COMP *cpi, | 908 static vpx_codec_frame_flags_t get_frame_pkt_flags(const VP9_COMP *cpi, |
| 902 unsigned int lib_flags) { | 909 unsigned int lib_flags) { |
| 903 vpx_codec_frame_flags_t flags = lib_flags << 16; | 910 vpx_codec_frame_flags_t flags = lib_flags << 16; |
| 904 | 911 |
| 905 if (lib_flags & FRAMEFLAGS_KEY | 912 if (lib_flags & FRAMEFLAGS_KEY || |
| 906 #if CONFIG_SPATIAL_SVC | 913 (cpi->use_svc && |
| 907 || (is_two_pass_svc(cpi) && cpi->svc.layer_context[0].is_key_frame) | 914 cpi->svc.layer_context[cpi->svc.spatial_layer_id * |
| 908 #endif | 915 cpi->svc.number_temporal_layers + |
| 909 ) | 916 cpi->svc.temporal_layer_id].is_key_frame) |
| 917 ) |
| 910 flags |= VPX_FRAME_IS_KEY; | 918 flags |= VPX_FRAME_IS_KEY; |
| 911 | 919 |
| 912 if (cpi->droppable) | 920 if (cpi->droppable) |
| 913 flags |= VPX_FRAME_IS_DROPPABLE; | 921 flags |= VPX_FRAME_IS_DROPPABLE; |
| 914 | 922 |
| 915 return flags; | 923 return flags; |
| 916 } | 924 } |
| 917 | 925 |
| 918 static vpx_codec_err_t encoder_encode(vpx_codec_alg_priv_t *ctx, | 926 static vpx_codec_err_t encoder_encode(vpx_codec_alg_priv_t *ctx, |
| 919 const vpx_image_t *img, | 927 const vpx_image_t *img, |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1015 } | 1023 } |
| 1016 | 1024 |
| 1017 while (cx_data_sz >= ctx->cx_data_sz / 2 && | 1025 while (cx_data_sz >= ctx->cx_data_sz / 2 && |
| 1018 -1 != vp9_get_compressed_data(cpi, &lib_flags, &size, | 1026 -1 != vp9_get_compressed_data(cpi, &lib_flags, &size, |
| 1019 cx_data, &dst_time_stamp, | 1027 cx_data, &dst_time_stamp, |
| 1020 &dst_end_time_stamp, !img)) { | 1028 &dst_end_time_stamp, !img)) { |
| 1021 if (size) { | 1029 if (size) { |
| 1022 vpx_codec_cx_pkt_t pkt; | 1030 vpx_codec_cx_pkt_t pkt; |
| 1023 | 1031 |
| 1024 #if CONFIG_SPATIAL_SVC | 1032 #if CONFIG_SPATIAL_SVC |
| 1025 if (is_two_pass_svc(cpi)) | 1033 if (cpi->use_svc) |
| 1026 cpi->svc.layer_context[cpi->svc.spatial_layer_id].layer_size += size; | 1034 cpi->svc.layer_context[cpi->svc.spatial_layer_id * |
| 1035 cpi->svc.number_temporal_layers].layer_size += size; |
| 1027 #endif | 1036 #endif |
| 1028 | 1037 |
| 1029 // Pack invisible frames with the next visible frame | 1038 // Pack invisible frames with the next visible frame |
| 1030 if (!cpi->common.show_frame | 1039 if (!cpi->common.show_frame || |
| 1031 #if CONFIG_SPATIAL_SVC | 1040 (cpi->use_svc && |
| 1032 || (is_two_pass_svc(cpi) && | 1041 cpi->svc.spatial_layer_id < cpi->svc.number_spatial_layers - 1) |
| 1033 cpi->svc.spatial_layer_id < cpi->svc.number_spatial_layers - 1) | |
| 1034 #endif | |
| 1035 ) { | 1042 ) { |
| 1036 if (ctx->pending_cx_data == 0) | 1043 if (ctx->pending_cx_data == 0) |
| 1037 ctx->pending_cx_data = cx_data; | 1044 ctx->pending_cx_data = cx_data; |
| 1038 ctx->pending_cx_data_sz += size; | 1045 ctx->pending_cx_data_sz += size; |
| 1039 ctx->pending_frame_sizes[ctx->pending_frame_count++] = size; | 1046 ctx->pending_frame_sizes[ctx->pending_frame_count++] = size; |
| 1040 ctx->pending_frame_magnitude |= size; | 1047 ctx->pending_frame_magnitude |= size; |
| 1041 cx_data += size; | 1048 cx_data += size; |
| 1042 cx_data_sz -= size; | 1049 cx_data_sz -= size; |
| 1043 | 1050 |
| 1044 if (ctx->output_cx_pkt_cb.output_cx_pkt) { | 1051 if (ctx->output_cx_pkt_cb.output_cx_pkt) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1082 ctx->pending_cx_data_sz = 0; | 1089 ctx->pending_cx_data_sz = 0; |
| 1083 ctx->pending_frame_count = 0; | 1090 ctx->pending_frame_count = 0; |
| 1084 ctx->pending_frame_magnitude = 0; | 1091 ctx->pending_frame_magnitude = 0; |
| 1085 } else { | 1092 } else { |
| 1086 pkt.data.frame.buf = cx_data; | 1093 pkt.data.frame.buf = cx_data; |
| 1087 pkt.data.frame.sz = size; | 1094 pkt.data.frame.sz = size; |
| 1088 } | 1095 } |
| 1089 pkt.data.frame.partition_id = -1; | 1096 pkt.data.frame.partition_id = -1; |
| 1090 | 1097 |
| 1091 if(ctx->output_cx_pkt_cb.output_cx_pkt) | 1098 if(ctx->output_cx_pkt_cb.output_cx_pkt) |
| 1092 ctx->output_cx_pkt_cb.output_cx_pkt(&pkt, ctx->output_cx_pkt_cb.user_p
riv); | 1099 ctx->output_cx_pkt_cb.output_cx_pkt(&pkt, |
| 1100 ctx->output_cx_pkt_cb.user_priv); |
| 1093 else | 1101 else |
| 1094 vpx_codec_pkt_list_add(&ctx->pkt_list.head, &pkt); | 1102 vpx_codec_pkt_list_add(&ctx->pkt_list.head, &pkt); |
| 1095 | 1103 |
| 1096 cx_data += size; | 1104 cx_data += size; |
| 1097 cx_data_sz -= size; | 1105 cx_data_sz -= size; |
| 1106 #if VPX_ENCODER_ABI_VERSION > (5 + VPX_CODEC_ABI_VERSION) |
| 1098 #if CONFIG_SPATIAL_SVC | 1107 #if CONFIG_SPATIAL_SVC |
| 1099 if (is_two_pass_svc(cpi) && !ctx->output_cx_pkt_cb.output_cx_pkt) { | 1108 if (cpi->use_svc && !ctx->output_cx_pkt_cb.output_cx_pkt) { |
| 1100 vpx_codec_cx_pkt_t pkt_sizes, pkt_psnr; | 1109 vpx_codec_cx_pkt_t pkt_sizes, pkt_psnr; |
| 1101 int i; | 1110 int sl; |
| 1102 vp9_zero(pkt_sizes); | 1111 vp9_zero(pkt_sizes); |
| 1103 vp9_zero(pkt_psnr); | 1112 vp9_zero(pkt_psnr); |
| 1104 pkt_sizes.kind = VPX_CODEC_SPATIAL_SVC_LAYER_SIZES; | 1113 pkt_sizes.kind = VPX_CODEC_SPATIAL_SVC_LAYER_SIZES; |
| 1105 pkt_psnr.kind = VPX_CODEC_SPATIAL_SVC_LAYER_PSNR; | 1114 pkt_psnr.kind = VPX_CODEC_SPATIAL_SVC_LAYER_PSNR; |
| 1106 for (i = 0; i < cpi->svc.number_spatial_layers; ++i) { | 1115 for (sl = 0; sl < cpi->svc.number_spatial_layers; ++sl) { |
| 1107 LAYER_CONTEXT *lc = &cpi->svc.layer_context[i]; | 1116 LAYER_CONTEXT *lc = |
| 1108 pkt_sizes.data.layer_sizes[i] = lc->layer_size; | 1117 &cpi->svc.layer_context[sl * cpi->svc.number_temporal_layers]; |
| 1109 pkt_psnr.data.layer_psnr[i] = lc->psnr_pkt; | 1118 pkt_sizes.data.layer_sizes[sl] = lc->layer_size; |
| 1119 pkt_psnr.data.layer_psnr[sl] = lc->psnr_pkt; |
| 1110 lc->layer_size = 0; | 1120 lc->layer_size = 0; |
| 1111 } | 1121 } |
| 1112 | 1122 |
| 1113 vpx_codec_pkt_list_add(&ctx->pkt_list.head, &pkt_sizes); | 1123 vpx_codec_pkt_list_add(&ctx->pkt_list.head, &pkt_sizes); |
| 1114 | 1124 |
| 1115 vpx_codec_pkt_list_add(&ctx->pkt_list.head, &pkt_psnr); | 1125 vpx_codec_pkt_list_add(&ctx->pkt_list.head, &pkt_psnr); |
| 1116 } | 1126 } |
| 1117 #endif | 1127 #endif |
| 1128 #endif |
| 1129 if (is_one_pass_cbr_svc(cpi) && |
| 1130 (cpi->svc.spatial_layer_id == cpi->svc.number_spatial_layers - 1)) { |
| 1131 // Encoded all spatial layers; exit loop. |
| 1132 break; |
| 1133 } |
| 1118 } | 1134 } |
| 1119 } | 1135 } |
| 1120 } | 1136 } |
| 1121 | 1137 |
| 1122 return res; | 1138 return res; |
| 1123 } | 1139 } |
| 1124 | 1140 |
| 1125 static const vpx_codec_cx_pkt_t *encoder_get_cxdata(vpx_codec_alg_priv_t *ctx, | 1141 static const vpx_codec_cx_pkt_t *encoder_get_cxdata(vpx_codec_alg_priv_t *ctx, |
| 1126 vpx_codec_iter_t *iter) { | 1142 vpx_codec_iter_t *iter) { |
| 1127 return vpx_codec_pkt_list_get(&ctx->pkt_list.head, iter); | 1143 return vpx_codec_pkt_list_get(&ctx->pkt_list.head, iter); |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1285 (VPX_SCALING)mode->v_scaling_mode); | 1301 (VPX_SCALING)mode->v_scaling_mode); |
| 1286 return (res == 0) ? VPX_CODEC_OK : VPX_CODEC_INVALID_PARAM; | 1302 return (res == 0) ? VPX_CODEC_OK : VPX_CODEC_INVALID_PARAM; |
| 1287 } else { | 1303 } else { |
| 1288 return VPX_CODEC_INVALID_PARAM; | 1304 return VPX_CODEC_INVALID_PARAM; |
| 1289 } | 1305 } |
| 1290 } | 1306 } |
| 1291 | 1307 |
| 1292 static vpx_codec_err_t ctrl_set_svc(vpx_codec_alg_priv_t *ctx, va_list args) { | 1308 static vpx_codec_err_t ctrl_set_svc(vpx_codec_alg_priv_t *ctx, va_list args) { |
| 1293 int data = va_arg(args, int); | 1309 int data = va_arg(args, int); |
| 1294 const vpx_codec_enc_cfg_t *cfg = &ctx->cfg; | 1310 const vpx_codec_enc_cfg_t *cfg = &ctx->cfg; |
| 1311 // Both one-pass and two-pass RC are supported now. |
| 1312 // User setting this has to make sure of the following. |
| 1313 // In two-pass setting: either (but not both) |
| 1314 // cfg->ss_number_layers > 1, or cfg->ts_number_layers > 1 |
| 1315 // In one-pass setting: |
| 1316 // either or both cfg->ss_number_layers > 1, or cfg->ts_number_layers > 1 |
| 1295 | 1317 |
| 1296 vp9_set_svc(ctx->cpi, data); | 1318 vp9_set_svc(ctx->cpi, data); |
| 1297 // CBR or two pass mode for SVC with both temporal and spatial layers | 1319 |
| 1298 // not yet supported. | |
| 1299 if (data == 1 && | 1320 if (data == 1 && |
| 1300 (cfg->rc_end_usage == VPX_CBR || | 1321 (cfg->g_pass == VPX_RC_FIRST_PASS || |
| 1301 cfg->g_pass == VPX_RC_FIRST_PASS || | |
| 1302 cfg->g_pass == VPX_RC_LAST_PASS) && | 1322 cfg->g_pass == VPX_RC_LAST_PASS) && |
| 1303 cfg->ss_number_layers > 1 && | 1323 cfg->ss_number_layers > 1 && |
| 1304 cfg->ts_number_layers > 1) { | 1324 cfg->ts_number_layers > 1) { |
| 1305 return VPX_CODEC_INVALID_PARAM; | 1325 return VPX_CODEC_INVALID_PARAM; |
| 1306 } | 1326 } |
| 1307 return VPX_CODEC_OK; | 1327 return VPX_CODEC_OK; |
| 1308 } | 1328 } |
| 1309 | 1329 |
| 1310 static vpx_codec_err_t ctrl_set_svc_layer_id(vpx_codec_alg_priv_t *ctx, | 1330 static vpx_codec_err_t ctrl_set_svc_layer_id(vpx_codec_alg_priv_t *ctx, |
| 1311 va_list args) { | 1331 va_list args) { |
| 1312 vpx_svc_layer_id_t *const data = va_arg(args, vpx_svc_layer_id_t *); | 1332 vpx_svc_layer_id_t *const data = va_arg(args, vpx_svc_layer_id_t *); |
| 1313 VP9_COMP *const cpi = (VP9_COMP *)ctx->cpi; | 1333 VP9_COMP *const cpi = (VP9_COMP *)ctx->cpi; |
| 1314 SVC *const svc = &cpi->svc; | 1334 SVC *const svc = &cpi->svc; |
| 1315 | 1335 |
| 1316 #if VPX_ENCODER_ABI_VERSION > (4 + VPX_CODEC_ABI_VERSION) | |
| 1317 svc->spatial_layer_id = data->spatial_layer_id; | 1336 svc->spatial_layer_id = data->spatial_layer_id; |
| 1318 #endif | |
| 1319 svc->temporal_layer_id = data->temporal_layer_id; | 1337 svc->temporal_layer_id = data->temporal_layer_id; |
| 1320 // Checks on valid layer_id input. | 1338 // Checks on valid layer_id input. |
| 1321 if (svc->temporal_layer_id < 0 || | 1339 if (svc->temporal_layer_id < 0 || |
| 1322 svc->temporal_layer_id >= (int)ctx->cfg.ts_number_layers) { | 1340 svc->temporal_layer_id >= (int)ctx->cfg.ts_number_layers) { |
| 1323 return VPX_CODEC_INVALID_PARAM; | 1341 return VPX_CODEC_INVALID_PARAM; |
| 1324 } | 1342 } |
| 1325 if (svc->spatial_layer_id < 0 || | 1343 if (svc->spatial_layer_id < 0 || |
| 1326 svc->spatial_layer_id >= (int)ctx->cfg.ss_number_layers) { | 1344 svc->spatial_layer_id >= (int)ctx->cfg.ss_number_layers) { |
| 1327 return VPX_CODEC_INVALID_PARAM; | 1345 return VPX_CODEC_INVALID_PARAM; |
| 1328 } | 1346 } |
| 1329 return VPX_CODEC_OK; | 1347 return VPX_CODEC_OK; |
| 1330 } | 1348 } |
| 1331 | 1349 |
| 1332 static vpx_codec_err_t ctrl_get_svc_layer_id(vpx_codec_alg_priv_t *ctx, | 1350 static vpx_codec_err_t ctrl_get_svc_layer_id(vpx_codec_alg_priv_t *ctx, |
| 1333 va_list args) { | 1351 va_list args) { |
| 1334 vpx_svc_layer_id_t *data = va_arg(args, vpx_svc_layer_id_t *); | 1352 vpx_svc_layer_id_t *data = va_arg(args, vpx_svc_layer_id_t *); |
| 1335 VP9_COMP *const cpi = (VP9_COMP *)ctx->cpi; | 1353 VP9_COMP *const cpi = (VP9_COMP *)ctx->cpi; |
| 1336 SVC *const svc = &cpi->svc; | 1354 SVC *const svc = &cpi->svc; |
| 1337 | 1355 |
| 1338 #if VPX_ENCODER_ABI_VERSION > (4 + VPX_CODEC_ABI_VERSION) | |
| 1339 data->spatial_layer_id = svc->spatial_layer_id; | 1356 data->spatial_layer_id = svc->spatial_layer_id; |
| 1340 #endif | |
| 1341 data->temporal_layer_id = svc->temporal_layer_id; | 1357 data->temporal_layer_id = svc->temporal_layer_id; |
| 1342 | 1358 |
| 1343 return VPX_CODEC_OK; | 1359 return VPX_CODEC_OK; |
| 1344 } | 1360 } |
| 1345 | 1361 |
| 1346 static vpx_codec_err_t ctrl_set_svc_parameters(vpx_codec_alg_priv_t *ctx, | 1362 static vpx_codec_err_t ctrl_set_svc_parameters(vpx_codec_alg_priv_t *ctx, |
| 1347 va_list args) { | 1363 va_list args) { |
| 1348 VP9_COMP *const cpi = ctx->cpi; | 1364 VP9_COMP *const cpi = ctx->cpi; |
| 1349 vpx_svc_extra_cfg_t *const params = va_arg(args, vpx_svc_extra_cfg_t *); | 1365 vpx_svc_extra_cfg_t *const params = va_arg(args, vpx_svc_extra_cfg_t *); |
| 1350 int i; | 1366 int sl, tl; |
| 1351 | 1367 |
| 1352 for (i = 0; i < cpi->svc.number_spatial_layers; ++i) { | 1368 // Number of temporal layers and number of spatial layers have to be set |
| 1353 LAYER_CONTEXT *lc = &cpi->svc.layer_context[i]; | 1369 // properly before calling this control function. |
| 1354 | 1370 for (sl = 0; sl < cpi->svc.number_spatial_layers; ++sl) { |
| 1355 lc->max_q = params->max_quantizers[i]; | 1371 for (tl = 0; tl < cpi->svc.number_temporal_layers; ++tl) { |
| 1356 lc->min_q = params->min_quantizers[i]; | 1372 const int layer = |
| 1357 lc->scaling_factor_num = params->scaling_factor_num[i]; | 1373 LAYER_IDS_TO_IDX(sl, tl, cpi->svc.number_temporal_layers); |
| 1358 lc->scaling_factor_den = params->scaling_factor_den[i]; | 1374 LAYER_CONTEXT *lc = |
| 1375 &cpi->svc.layer_context[layer]; |
| 1376 lc->max_q = params->max_quantizers[sl]; |
| 1377 lc->min_q = params->min_quantizers[sl]; |
| 1378 lc->scaling_factor_num = params->scaling_factor_num[sl]; |
| 1379 lc->scaling_factor_den = params->scaling_factor_den[sl]; |
| 1380 } |
| 1359 } | 1381 } |
| 1360 | 1382 |
| 1361 return VPX_CODEC_OK; | 1383 return VPX_CODEC_OK; |
| 1362 } | 1384 } |
| 1363 | 1385 |
| 1364 static vpx_codec_err_t ctrl_register_cx_callback(vpx_codec_alg_priv_t *ctx, | 1386 static vpx_codec_err_t ctrl_register_cx_callback(vpx_codec_alg_priv_t *ctx, |
| 1365 va_list args) { | 1387 va_list args) { |
| 1366 vpx_codec_priv_output_cx_pkt_cb_pair_t *cbp = | 1388 vpx_codec_priv_output_cx_pkt_cb_pair_t *cbp = |
| 1367 (vpx_codec_priv_output_cx_pkt_cb_pair_t *)va_arg(args, void *); | 1389 (vpx_codec_priv_output_cx_pkt_cb_pair_t *)va_arg(args, void *); |
| 1368 ctx->output_cx_pkt_cb.output_cx_pkt = cbp->output_cx_pkt; | 1390 ctx->output_cx_pkt_cb.output_cx_pkt = cbp->output_cx_pkt; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1409 {VP8E_SET_TUNING, ctrl_set_tuning}, | 1431 {VP8E_SET_TUNING, ctrl_set_tuning}, |
| 1410 {VP8E_SET_CQ_LEVEL, ctrl_set_cq_level}, | 1432 {VP8E_SET_CQ_LEVEL, ctrl_set_cq_level}, |
| 1411 {VP8E_SET_MAX_INTRA_BITRATE_PCT, ctrl_set_rc_max_intra_bitrate_pct}, | 1433 {VP8E_SET_MAX_INTRA_BITRATE_PCT, ctrl_set_rc_max_intra_bitrate_pct}, |
| 1412 {VP9E_SET_MAX_INTER_BITRATE_PCT, ctrl_set_rc_max_inter_bitrate_pct}, | 1434 {VP9E_SET_MAX_INTER_BITRATE_PCT, ctrl_set_rc_max_inter_bitrate_pct}, |
| 1413 {VP9E_SET_GF_CBR_BOOST_PCT, ctrl_set_rc_gf_cbr_boost_pct}, | 1435 {VP9E_SET_GF_CBR_BOOST_PCT, ctrl_set_rc_gf_cbr_boost_pct}, |
| 1414 {VP9E_SET_LOSSLESS, ctrl_set_lossless}, | 1436 {VP9E_SET_LOSSLESS, ctrl_set_lossless}, |
| 1415 {VP9E_SET_FRAME_PARALLEL_DECODING, ctrl_set_frame_parallel_decoding_mode}, | 1437 {VP9E_SET_FRAME_PARALLEL_DECODING, ctrl_set_frame_parallel_decoding_mode}, |
| 1416 {VP9E_SET_AQ_MODE, ctrl_set_aq_mode}, | 1438 {VP9E_SET_AQ_MODE, ctrl_set_aq_mode}, |
| 1417 {VP9E_SET_FRAME_PERIODIC_BOOST, ctrl_set_frame_periodic_boost}, | 1439 {VP9E_SET_FRAME_PERIODIC_BOOST, ctrl_set_frame_periodic_boost}, |
| 1418 {VP9E_SET_SVC, ctrl_set_svc}, | 1440 {VP9E_SET_SVC, ctrl_set_svc}, |
| 1419 #if VPX_ENCODER_ABI_VERSION > (4 + VPX_CODEC_ABI_VERSION) | |
| 1420 {VP9E_SET_SVC_PARAMETERS, ctrl_set_svc_parameters}, | 1441 {VP9E_SET_SVC_PARAMETERS, ctrl_set_svc_parameters}, |
| 1421 {VP9E_REGISTER_CX_CALLBACK, ctrl_register_cx_callback}, | 1442 {VP9E_REGISTER_CX_CALLBACK, ctrl_register_cx_callback}, |
| 1422 #endif | |
| 1423 {VP9E_SET_SVC_LAYER_ID, ctrl_set_svc_layer_id}, | 1443 {VP9E_SET_SVC_LAYER_ID, ctrl_set_svc_layer_id}, |
| 1424 {VP9E_SET_TUNE_CONTENT, ctrl_set_tune_content}, | 1444 {VP9E_SET_TUNE_CONTENT, ctrl_set_tune_content}, |
| 1425 {VP9E_SET_COLOR_SPACE, ctrl_set_color_space}, | 1445 {VP9E_SET_COLOR_SPACE, ctrl_set_color_space}, |
| 1426 {VP9E_SET_NOISE_SENSITIVITY, ctrl_set_noise_sensitivity}, | 1446 {VP9E_SET_NOISE_SENSITIVITY, ctrl_set_noise_sensitivity}, |
| 1427 | 1447 |
| 1428 // Getters | 1448 // Getters |
| 1429 {VP8E_GET_LAST_QUANTIZER, ctrl_get_quantizer}, | 1449 {VP8E_GET_LAST_QUANTIZER, ctrl_get_quantizer}, |
| 1430 {VP8E_GET_LAST_QUANTIZER_64, ctrl_get_quantizer64}, | 1450 {VP8E_GET_LAST_QUANTIZER_64, ctrl_get_quantizer64}, |
| 1431 {VP9_GET_REFERENCE, ctrl_get_reference}, | 1451 {VP9_GET_REFERENCE, ctrl_get_reference}, |
| 1432 #if VPX_ENCODER_ABI_VERSION > (4 + VPX_CODEC_ABI_VERSION) | |
| 1433 {VP9E_GET_SVC_LAYER_ID, ctrl_get_svc_layer_id}, | 1452 {VP9E_GET_SVC_LAYER_ID, ctrl_get_svc_layer_id}, |
| 1434 #endif | |
| 1435 {VP9E_GET_ACTIVEMAP, ctrl_get_active_map}, | 1453 {VP9E_GET_ACTIVEMAP, ctrl_get_active_map}, |
| 1436 | 1454 |
| 1437 { -1, NULL}, | 1455 { -1, NULL}, |
| 1438 }; | 1456 }; |
| 1439 | 1457 |
| 1440 static vpx_codec_enc_cfg_map_t encoder_usage_cfg_map[] = { | 1458 static vpx_codec_enc_cfg_map_t encoder_usage_cfg_map[] = { |
| 1441 { | 1459 { |
| 1442 0, | 1460 0, |
| 1443 { // NOLINT | 1461 { // NOLINT |
| 1444 0, // g_usage | 1462 0, // g_usage |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1488 9999, // kf_max_dist | 1506 9999, // kf_max_dist |
| 1489 | 1507 |
| 1490 VPX_SS_DEFAULT_LAYERS, // ss_number_layers | 1508 VPX_SS_DEFAULT_LAYERS, // ss_number_layers |
| 1491 {0}, | 1509 {0}, |
| 1492 {0}, // ss_target_bitrate | 1510 {0}, // ss_target_bitrate |
| 1493 1, // ts_number_layers | 1511 1, // ts_number_layers |
| 1494 {0}, // ts_target_bitrate | 1512 {0}, // ts_target_bitrate |
| 1495 {0}, // ts_rate_decimator | 1513 {0}, // ts_rate_decimator |
| 1496 0, // ts_periodicity | 1514 0, // ts_periodicity |
| 1497 {0}, // ts_layer_id | 1515 {0}, // ts_layer_id |
| 1516 {0}, // layer_taget_bitrate |
| 1517 0 // temporal_layering_mode |
| 1498 } | 1518 } |
| 1499 }, | 1519 }, |
| 1500 }; | 1520 }; |
| 1501 | 1521 |
| 1502 #ifndef VERSION_STRING | 1522 #ifndef VERSION_STRING |
| 1503 #define VERSION_STRING | 1523 #define VERSION_STRING |
| 1504 #endif | 1524 #endif |
| 1505 CODEC_INTERFACE(vpx_codec_vp9_cx) = { | 1525 CODEC_INTERFACE(vpx_codec_vp9_cx) = { |
| 1506 "WebM Project VP9 Encoder" VERSION_STRING, | 1526 "WebM Project VP9 Encoder" VERSION_STRING, |
| 1507 VPX_CODEC_INTERNAL_ABI_VERSION, | 1527 VPX_CODEC_INTERNAL_ABI_VERSION, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1523 1, // 1 cfg map | 1543 1, // 1 cfg map |
| 1524 encoder_usage_cfg_map, // vpx_codec_enc_cfg_map_t | 1544 encoder_usage_cfg_map, // vpx_codec_enc_cfg_map_t |
| 1525 encoder_encode, // vpx_codec_encode_fn_t | 1545 encoder_encode, // vpx_codec_encode_fn_t |
| 1526 encoder_get_cxdata, // vpx_codec_get_cx_data_fn_t | 1546 encoder_get_cxdata, // vpx_codec_get_cx_data_fn_t |
| 1527 encoder_set_config, // vpx_codec_enc_config_set_fn_t | 1547 encoder_set_config, // vpx_codec_enc_config_set_fn_t |
| 1528 NULL, // vpx_codec_get_global_headers_fn_t | 1548 NULL, // vpx_codec_get_global_headers_fn_t |
| 1529 encoder_get_preview, // vpx_codec_get_preview_frame_fn_t | 1549 encoder_get_preview, // vpx_codec_get_preview_frame_fn_t |
| 1530 NULL // vpx_codec_enc_mr_get_mem_loc_fn_t | 1550 NULL // vpx_codec_enc_mr_get_mem_loc_fn_t |
| 1531 } | 1551 } |
| 1532 }; | 1552 }; |
| OLD | NEW |