michael@0: /* michael@0: * Copyright (c) 2010 The WebM project authors. All Rights Reserved. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license michael@0: * that can be found in the LICENSE file in the root of the source michael@0: * tree. An additional intellectual property rights grant can be found michael@0: * in the file PATENTS. All contributing project authors may michael@0: * be found in the AUTHORS file in the root of the source tree. michael@0: */ michael@0: michael@0: #include michael@0: #include michael@0: michael@0: #include "vpx/vpx_codec.h" michael@0: #include "vpx/internal/vpx_codec_internal.h" michael@0: #include "./vpx_version.h" michael@0: #include "vp9/encoder/vp9_onyx_int.h" michael@0: #include "vpx/vp8cx.h" michael@0: #include "vp9/encoder/vp9_firstpass.h" michael@0: #include "vp9/common/vp9_onyx.h" michael@0: #include "vp9/vp9_iface_common.h" michael@0: michael@0: struct vp9_extracfg { michael@0: struct vpx_codec_pkt_list *pkt_list; michael@0: int cpu_used; /* available cpu percentage in 1/16 */ michael@0: unsigned int enable_auto_alt_ref; michael@0: unsigned int noise_sensitivity; michael@0: unsigned int Sharpness; michael@0: unsigned int static_thresh; michael@0: unsigned int tile_columns; michael@0: unsigned int tile_rows; michael@0: unsigned int arnr_max_frames; michael@0: unsigned int arnr_strength; michael@0: unsigned int arnr_type; michael@0: unsigned int experimental; michael@0: vp8e_tuning tuning; michael@0: unsigned int cq_level; /* constrained quality level */ michael@0: unsigned int rc_max_intra_bitrate_pct; michael@0: unsigned int lossless; michael@0: unsigned int frame_parallel_decoding_mode; michael@0: unsigned int aq_mode; michael@0: }; michael@0: michael@0: struct extraconfig_map { michael@0: int usage; michael@0: struct vp9_extracfg cfg; michael@0: }; michael@0: michael@0: static const struct extraconfig_map extracfg_map[] = { michael@0: { michael@0: 0, michael@0: { // NOLINT michael@0: NULL, michael@0: 0, /* cpu_used */ michael@0: 1, /* enable_auto_alt_ref */ michael@0: 0, /* noise_sensitivity */ michael@0: 0, /* Sharpness */ michael@0: 0, /* static_thresh */ michael@0: 0, /* tile_columns */ michael@0: 0, /* tile_rows */ michael@0: 7, /* arnr_max_frames */ michael@0: 5, /* arnr_strength */ michael@0: 3, /* arnr_type*/ michael@0: 0, /* experimental mode */ michael@0: 0, /* tuning*/ michael@0: 10, /* cq_level */ michael@0: 0, /* rc_max_intra_bitrate_pct */ michael@0: 0, /* lossless */ michael@0: 0, /* frame_parallel_decoding_mode */ michael@0: 0, /* aq_mode */ michael@0: } michael@0: } michael@0: }; michael@0: michael@0: struct vpx_codec_alg_priv { michael@0: vpx_codec_priv_t base; michael@0: vpx_codec_enc_cfg_t cfg; michael@0: struct vp9_extracfg vp8_cfg; michael@0: VP9_CONFIG oxcf; michael@0: VP9_PTR cpi; michael@0: unsigned char *cx_data; michael@0: unsigned int cx_data_sz; michael@0: unsigned char *pending_cx_data; michael@0: unsigned int pending_cx_data_sz; michael@0: int pending_frame_count; michael@0: uint32_t pending_frame_sizes[8]; michael@0: uint32_t pending_frame_magnitude; michael@0: vpx_image_t preview_img; michael@0: vp8_postproc_cfg_t preview_ppcfg; michael@0: vpx_codec_pkt_list_decl(64) pkt_list; michael@0: unsigned int fixed_kf_cntr; michael@0: }; michael@0: michael@0: static VP9_REFFRAME ref_frame_to_vp9_reframe(vpx_ref_frame_type_t frame) { michael@0: switch (frame) { michael@0: case VP8_LAST_FRAME: michael@0: return VP9_LAST_FLAG; michael@0: case VP8_GOLD_FRAME: michael@0: return VP9_GOLD_FLAG; michael@0: case VP8_ALTR_FRAME: michael@0: return VP9_ALT_FLAG; michael@0: } michael@0: assert(!"Invalid Reference Frame"); michael@0: return VP9_LAST_FLAG; michael@0: } michael@0: michael@0: static vpx_codec_err_t michael@0: update_error_state(vpx_codec_alg_priv_t *ctx, michael@0: const struct vpx_internal_error_info *error) { michael@0: vpx_codec_err_t res; michael@0: michael@0: if ((res = error->error_code)) michael@0: ctx->base.err_detail = error->has_detail michael@0: ? error->detail michael@0: : NULL; michael@0: michael@0: return res; michael@0: } michael@0: michael@0: michael@0: #undef ERROR michael@0: #define ERROR(str) do {\ michael@0: ctx->base.err_detail = str;\ michael@0: return VPX_CODEC_INVALID_PARAM;\ michael@0: } while (0) michael@0: michael@0: #define RANGE_CHECK(p, memb, lo, hi) do {\ michael@0: if (!(((p)->memb == lo || (p)->memb > (lo)) && (p)->memb <= hi)) \ michael@0: ERROR(#memb " out of range ["#lo".."#hi"]");\ michael@0: } while (0) michael@0: michael@0: #define RANGE_CHECK_HI(p, memb, hi) do {\ michael@0: if (!((p)->memb <= (hi))) \ michael@0: ERROR(#memb " out of range [.."#hi"]");\ michael@0: } while (0) michael@0: michael@0: #define RANGE_CHECK_LO(p, memb, lo) do {\ michael@0: if (!((p)->memb >= (lo))) \ michael@0: ERROR(#memb " out of range ["#lo"..]");\ michael@0: } while (0) michael@0: michael@0: #define RANGE_CHECK_BOOL(p, memb) do {\ michael@0: if (!!((p)->memb) != (p)->memb) ERROR(#memb " expected boolean");\ michael@0: } while (0) michael@0: michael@0: static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx, michael@0: const vpx_codec_enc_cfg_t *cfg, michael@0: const struct vp9_extracfg *vp8_cfg) { michael@0: RANGE_CHECK(cfg, g_w, 1, 65535); /* 16 bits available */ michael@0: RANGE_CHECK(cfg, g_h, 1, 65535); /* 16 bits available */ michael@0: RANGE_CHECK(cfg, g_timebase.den, 1, 1000000000); michael@0: RANGE_CHECK(cfg, g_timebase.num, 1, cfg->g_timebase.den); michael@0: RANGE_CHECK_HI(cfg, g_profile, 3); michael@0: michael@0: RANGE_CHECK_HI(cfg, rc_max_quantizer, 63); michael@0: RANGE_CHECK_HI(cfg, rc_min_quantizer, cfg->rc_max_quantizer); michael@0: RANGE_CHECK_BOOL(vp8_cfg, lossless); michael@0: if (vp8_cfg->lossless) { michael@0: RANGE_CHECK_HI(cfg, rc_max_quantizer, 0); michael@0: RANGE_CHECK_HI(cfg, rc_min_quantizer, 0); michael@0: } michael@0: RANGE_CHECK(vp8_cfg, aq_mode, 0, AQ_MODES_COUNT - 1); michael@0: michael@0: RANGE_CHECK_HI(cfg, g_threads, 64); michael@0: RANGE_CHECK_HI(cfg, g_lag_in_frames, MAX_LAG_BUFFERS); michael@0: RANGE_CHECK(cfg, rc_end_usage, VPX_VBR, VPX_Q); michael@0: RANGE_CHECK_HI(cfg, rc_undershoot_pct, 1000); michael@0: RANGE_CHECK_HI(cfg, rc_overshoot_pct, 1000); michael@0: RANGE_CHECK_HI(cfg, rc_2pass_vbr_bias_pct, 100); michael@0: RANGE_CHECK(cfg, kf_mode, VPX_KF_DISABLED, VPX_KF_AUTO); michael@0: // RANGE_CHECK_BOOL(cfg, g_delete_firstpassfile); michael@0: RANGE_CHECK_BOOL(cfg, rc_resize_allowed); michael@0: RANGE_CHECK_HI(cfg, rc_dropframe_thresh, 100); michael@0: RANGE_CHECK_HI(cfg, rc_resize_up_thresh, 100); michael@0: RANGE_CHECK_HI(cfg, rc_resize_down_thresh, 100); michael@0: RANGE_CHECK(cfg, g_pass, VPX_RC_ONE_PASS, VPX_RC_LAST_PASS); michael@0: michael@0: RANGE_CHECK(cfg, ss_number_layers, 1, michael@0: VPX_SS_MAX_LAYERS); /*Spatial layers max */ michael@0: /* VP8 does not support a lower bound on the keyframe interval in michael@0: * automatic keyframe placement mode. michael@0: */ michael@0: if (cfg->kf_mode != VPX_KF_DISABLED && cfg->kf_min_dist != cfg->kf_max_dist michael@0: && cfg->kf_min_dist > 0) michael@0: ERROR("kf_min_dist not supported in auto mode, use 0 " michael@0: "or kf_max_dist instead."); michael@0: michael@0: RANGE_CHECK_BOOL(vp8_cfg, enable_auto_alt_ref); michael@0: RANGE_CHECK(vp8_cfg, cpu_used, -16, 16); michael@0: michael@0: RANGE_CHECK_HI(vp8_cfg, noise_sensitivity, 6); michael@0: michael@0: RANGE_CHECK(vp8_cfg, tile_columns, 0, 6); michael@0: RANGE_CHECK(vp8_cfg, tile_rows, 0, 2); michael@0: RANGE_CHECK_HI(vp8_cfg, Sharpness, 7); michael@0: RANGE_CHECK(vp8_cfg, arnr_max_frames, 0, 15); michael@0: RANGE_CHECK_HI(vp8_cfg, arnr_strength, 6); michael@0: RANGE_CHECK(vp8_cfg, arnr_type, 1, 3); michael@0: RANGE_CHECK(vp8_cfg, cq_level, 0, 63); michael@0: michael@0: if (cfg->g_pass == VPX_RC_LAST_PASS) { michael@0: size_t packet_sz = sizeof(FIRSTPASS_STATS); michael@0: int n_packets = (int)(cfg->rc_twopass_stats_in.sz / packet_sz); michael@0: FIRSTPASS_STATS *stats; michael@0: michael@0: if (!cfg->rc_twopass_stats_in.buf) michael@0: ERROR("rc_twopass_stats_in.buf not set."); michael@0: michael@0: if (cfg->rc_twopass_stats_in.sz % packet_sz) michael@0: ERROR("rc_twopass_stats_in.sz indicates truncated packet."); michael@0: michael@0: if (cfg->rc_twopass_stats_in.sz < 2 * packet_sz) michael@0: ERROR("rc_twopass_stats_in requires at least two packets."); michael@0: michael@0: stats = (void *)((char *)cfg->rc_twopass_stats_in.buf michael@0: + (n_packets - 1) * packet_sz); michael@0: michael@0: if ((int)(stats->count + 0.5) != n_packets - 1) michael@0: ERROR("rc_twopass_stats_in missing EOS stats packet"); michael@0: } michael@0: michael@0: return VPX_CODEC_OK; michael@0: } michael@0: michael@0: michael@0: static vpx_codec_err_t validate_img(vpx_codec_alg_priv_t *ctx, michael@0: const vpx_image_t *img) { michael@0: switch (img->fmt) { michael@0: case VPX_IMG_FMT_YV12: michael@0: case VPX_IMG_FMT_I420: michael@0: case VPX_IMG_FMT_I422: michael@0: case VPX_IMG_FMT_I444: michael@0: break; michael@0: default: michael@0: ERROR("Invalid image format. Only YV12, I420, I422, I444 images are " michael@0: "supported."); michael@0: } michael@0: michael@0: if ((img->d_w != ctx->cfg.g_w) || (img->d_h != ctx->cfg.g_h)) michael@0: ERROR("Image size must match encoder init configuration size"); michael@0: michael@0: return VPX_CODEC_OK; michael@0: } michael@0: michael@0: michael@0: static vpx_codec_err_t set_vp9e_config(VP9_CONFIG *oxcf, michael@0: vpx_codec_enc_cfg_t cfg, michael@0: struct vp9_extracfg vp8_cfg) { michael@0: oxcf->version = cfg.g_profile | (vp8_cfg.experimental ? 0x4 : 0); michael@0: oxcf->width = cfg.g_w; michael@0: oxcf->height = cfg.g_h; michael@0: /* guess a frame rate if out of whack, use 30 */ michael@0: oxcf->framerate = (double)(cfg.g_timebase.den) michael@0: / (double)(cfg.g_timebase.num); michael@0: michael@0: if (oxcf->framerate > 180) { michael@0: oxcf->framerate = 30; michael@0: } michael@0: michael@0: switch (cfg.g_pass) { michael@0: case VPX_RC_ONE_PASS: michael@0: oxcf->Mode = MODE_GOODQUALITY; michael@0: break; michael@0: case VPX_RC_FIRST_PASS: michael@0: oxcf->Mode = MODE_FIRSTPASS; michael@0: break; michael@0: case VPX_RC_LAST_PASS: michael@0: oxcf->Mode = MODE_SECONDPASS_BEST; michael@0: break; michael@0: } michael@0: michael@0: if (cfg.g_pass == VPX_RC_FIRST_PASS) { michael@0: oxcf->allow_lag = 0; michael@0: oxcf->lag_in_frames = 0; michael@0: } else { michael@0: oxcf->allow_lag = (cfg.g_lag_in_frames) > 0; michael@0: oxcf->lag_in_frames = cfg.g_lag_in_frames; michael@0: } michael@0: michael@0: // VBR only supported for now. michael@0: // CBR code has been deprectated for experimental phase. michael@0: // CQ mode not yet tested michael@0: oxcf->end_usage = USAGE_LOCAL_FILE_PLAYBACK; michael@0: if (cfg.rc_end_usage == VPX_CQ) michael@0: oxcf->end_usage = USAGE_CONSTRAINED_QUALITY; michael@0: else if (cfg.rc_end_usage == VPX_Q) michael@0: oxcf->end_usage = USAGE_CONSTANT_QUALITY; michael@0: else if (cfg.rc_end_usage == VPX_CBR) michael@0: oxcf->end_usage = USAGE_STREAM_FROM_SERVER; michael@0: michael@0: oxcf->target_bandwidth = cfg.rc_target_bitrate; michael@0: oxcf->rc_max_intra_bitrate_pct = vp8_cfg.rc_max_intra_bitrate_pct; michael@0: michael@0: oxcf->best_allowed_q = cfg.rc_min_quantizer; michael@0: oxcf->worst_allowed_q = cfg.rc_max_quantizer; michael@0: oxcf->cq_level = vp8_cfg.cq_level; michael@0: oxcf->fixed_q = -1; michael@0: michael@0: oxcf->under_shoot_pct = cfg.rc_undershoot_pct; michael@0: oxcf->over_shoot_pct = cfg.rc_overshoot_pct; michael@0: michael@0: oxcf->maximum_buffer_size = cfg.rc_buf_sz; michael@0: oxcf->starting_buffer_level = cfg.rc_buf_initial_sz; michael@0: oxcf->optimal_buffer_level = cfg.rc_buf_optimal_sz; michael@0: michael@0: oxcf->two_pass_vbrbias = cfg.rc_2pass_vbr_bias_pct; michael@0: oxcf->two_pass_vbrmin_section = cfg.rc_2pass_vbr_minsection_pct; michael@0: oxcf->two_pass_vbrmax_section = cfg.rc_2pass_vbr_maxsection_pct; michael@0: michael@0: oxcf->auto_key = cfg.kf_mode == VPX_KF_AUTO michael@0: && cfg.kf_min_dist != cfg.kf_max_dist; michael@0: // oxcf->kf_min_dist = cfg.kf_min_dis; michael@0: oxcf->key_freq = cfg.kf_max_dist; michael@0: michael@0: // oxcf->delete_first_pass_file = cfg.g_delete_firstpassfile; michael@0: // strcpy(oxcf->first_pass_file, cfg.g_firstpass_file); michael@0: michael@0: oxcf->cpu_used = vp8_cfg.cpu_used; michael@0: oxcf->encode_breakout = vp8_cfg.static_thresh; michael@0: oxcf->play_alternate = vp8_cfg.enable_auto_alt_ref; michael@0: oxcf->noise_sensitivity = vp8_cfg.noise_sensitivity; michael@0: oxcf->Sharpness = vp8_cfg.Sharpness; michael@0: michael@0: oxcf->two_pass_stats_in = cfg.rc_twopass_stats_in; michael@0: oxcf->output_pkt_list = vp8_cfg.pkt_list; michael@0: michael@0: oxcf->arnr_max_frames = vp8_cfg.arnr_max_frames; michael@0: oxcf->arnr_strength = vp8_cfg.arnr_strength; michael@0: oxcf->arnr_type = vp8_cfg.arnr_type; michael@0: michael@0: oxcf->tuning = vp8_cfg.tuning; michael@0: michael@0: oxcf->tile_columns = vp8_cfg.tile_columns; michael@0: oxcf->tile_rows = vp8_cfg.tile_rows; michael@0: michael@0: oxcf->lossless = vp8_cfg.lossless; michael@0: michael@0: oxcf->error_resilient_mode = cfg.g_error_resilient; michael@0: oxcf->frame_parallel_decoding_mode = vp8_cfg.frame_parallel_decoding_mode; michael@0: michael@0: oxcf->aq_mode = vp8_cfg.aq_mode; michael@0: michael@0: oxcf->ss_number_layers = cfg.ss_number_layers; michael@0: /* michael@0: printf("Current VP9 Settings: \n"); michael@0: printf("target_bandwidth: %d\n", oxcf->target_bandwidth); michael@0: printf("noise_sensitivity: %d\n", oxcf->noise_sensitivity); michael@0: printf("Sharpness: %d\n", oxcf->Sharpness); michael@0: printf("cpu_used: %d\n", oxcf->cpu_used); michael@0: printf("Mode: %d\n", oxcf->Mode); michael@0: // printf("delete_first_pass_file: %d\n", oxcf->delete_first_pass_file); michael@0: printf("auto_key: %d\n", oxcf->auto_key); michael@0: printf("key_freq: %d\n", oxcf->key_freq); michael@0: printf("end_usage: %d\n", oxcf->end_usage); michael@0: printf("under_shoot_pct: %d\n", oxcf->under_shoot_pct); michael@0: printf("over_shoot_pct: %d\n", oxcf->over_shoot_pct); michael@0: printf("starting_buffer_level: %d\n", oxcf->starting_buffer_level); michael@0: printf("optimal_buffer_level: %d\n", oxcf->optimal_buffer_level); michael@0: printf("maximum_buffer_size: %d\n", oxcf->maximum_buffer_size); michael@0: printf("fixed_q: %d\n", oxcf->fixed_q); michael@0: printf("worst_allowed_q: %d\n", oxcf->worst_allowed_q); michael@0: printf("best_allowed_q: %d\n", oxcf->best_allowed_q); michael@0: printf("two_pass_vbrbias: %d\n", oxcf->two_pass_vbrbias); michael@0: printf("two_pass_vbrmin_section: %d\n", oxcf->two_pass_vbrmin_section); michael@0: printf("two_pass_vbrmax_section: %d\n", oxcf->two_pass_vbrmax_section); michael@0: printf("allow_lag: %d\n", oxcf->allow_lag); michael@0: printf("lag_in_frames: %d\n", oxcf->lag_in_frames); michael@0: printf("play_alternate: %d\n", oxcf->play_alternate); michael@0: printf("Version: %d\n", oxcf->Version); michael@0: printf("encode_breakout: %d\n", oxcf->encode_breakout); michael@0: printf("error resilient: %d\n", oxcf->error_resilient_mode); michael@0: printf("frame parallel detokenization: %d\n", michael@0: oxcf->frame_parallel_decoding_mode); michael@0: */ michael@0: return VPX_CODEC_OK; michael@0: } michael@0: michael@0: static vpx_codec_err_t vp9e_set_config(vpx_codec_alg_priv_t *ctx, michael@0: const vpx_codec_enc_cfg_t *cfg) { michael@0: vpx_codec_err_t res; michael@0: michael@0: if ((cfg->g_w != ctx->cfg.g_w) || (cfg->g_h != ctx->cfg.g_h)) michael@0: ERROR("Cannot change width or height after initialization"); michael@0: michael@0: /* Prevent increasing lag_in_frames. This check is stricter than it needs michael@0: * to be -- the limit is not increasing past the first lag_in_frames michael@0: * value, but we don't track the initial config, only the last successful michael@0: * config. michael@0: */ michael@0: if ((cfg->g_lag_in_frames > ctx->cfg.g_lag_in_frames)) michael@0: ERROR("Cannot increase lag_in_frames"); michael@0: michael@0: res = validate_config(ctx, cfg, &ctx->vp8_cfg); michael@0: michael@0: if (!res) { michael@0: ctx->cfg = *cfg; michael@0: set_vp9e_config(&ctx->oxcf, ctx->cfg, ctx->vp8_cfg); michael@0: vp9_change_config(ctx->cpi, &ctx->oxcf); michael@0: } michael@0: michael@0: return res; michael@0: } michael@0: michael@0: michael@0: int vp9_reverse_trans(int q); michael@0: michael@0: michael@0: static vpx_codec_err_t get_param(vpx_codec_alg_priv_t *ctx, michael@0: int ctrl_id, michael@0: va_list args) { michael@0: void *arg = va_arg(args, void *); michael@0: michael@0: #define MAP(id, var) case id: *(RECAST(id, arg)) = var; break michael@0: michael@0: if (!arg) michael@0: return VPX_CODEC_INVALID_PARAM; michael@0: michael@0: switch (ctrl_id) { michael@0: MAP(VP8E_GET_LAST_QUANTIZER, vp9_get_quantizer(ctx->cpi)); michael@0: MAP(VP8E_GET_LAST_QUANTIZER_64, michael@0: vp9_reverse_trans(vp9_get_quantizer(ctx->cpi))); michael@0: } michael@0: michael@0: return VPX_CODEC_OK; michael@0: #undef MAP michael@0: } michael@0: michael@0: michael@0: static vpx_codec_err_t set_param(vpx_codec_alg_priv_t *ctx, michael@0: int ctrl_id, michael@0: va_list args) { michael@0: vpx_codec_err_t res = VPX_CODEC_OK; michael@0: struct vp9_extracfg xcfg = ctx->vp8_cfg; michael@0: michael@0: #define MAP(id, var) case id: var = CAST(id, args); break; michael@0: michael@0: switch (ctrl_id) { michael@0: MAP(VP8E_SET_CPUUSED, xcfg.cpu_used); michael@0: MAP(VP8E_SET_ENABLEAUTOALTREF, xcfg.enable_auto_alt_ref); michael@0: MAP(VP8E_SET_NOISE_SENSITIVITY, xcfg.noise_sensitivity); michael@0: MAP(VP8E_SET_SHARPNESS, xcfg.Sharpness); michael@0: MAP(VP8E_SET_STATIC_THRESHOLD, xcfg.static_thresh); michael@0: MAP(VP9E_SET_TILE_COLUMNS, xcfg.tile_columns); michael@0: MAP(VP9E_SET_TILE_ROWS, xcfg.tile_rows); michael@0: MAP(VP8E_SET_ARNR_MAXFRAMES, xcfg.arnr_max_frames); michael@0: MAP(VP8E_SET_ARNR_STRENGTH, xcfg.arnr_strength); michael@0: MAP(VP8E_SET_ARNR_TYPE, xcfg.arnr_type); michael@0: MAP(VP8E_SET_TUNING, xcfg.tuning); michael@0: MAP(VP8E_SET_CQ_LEVEL, xcfg.cq_level); michael@0: MAP(VP8E_SET_MAX_INTRA_BITRATE_PCT, xcfg.rc_max_intra_bitrate_pct); michael@0: MAP(VP9E_SET_LOSSLESS, xcfg.lossless); michael@0: MAP(VP9E_SET_FRAME_PARALLEL_DECODING, xcfg.frame_parallel_decoding_mode); michael@0: MAP(VP9E_SET_AQ_MODE, xcfg.aq_mode); michael@0: } michael@0: michael@0: res = validate_config(ctx, &ctx->cfg, &xcfg); michael@0: michael@0: if (!res) { michael@0: ctx->vp8_cfg = xcfg; michael@0: set_vp9e_config(&ctx->oxcf, ctx->cfg, ctx->vp8_cfg); michael@0: vp9_change_config(ctx->cpi, &ctx->oxcf); michael@0: } michael@0: michael@0: return res; michael@0: #undef MAP michael@0: } michael@0: michael@0: michael@0: static vpx_codec_err_t vp9e_common_init(vpx_codec_ctx_t *ctx, michael@0: int experimental) { michael@0: vpx_codec_err_t res = VPX_CODEC_OK; michael@0: struct vpx_codec_alg_priv *priv; michael@0: vpx_codec_enc_cfg_t *cfg; michael@0: unsigned int i; michael@0: michael@0: VP9_PTR optr; michael@0: michael@0: if (!ctx->priv) { michael@0: priv = calloc(1, sizeof(struct vpx_codec_alg_priv)); michael@0: michael@0: if (!priv) { michael@0: return VPX_CODEC_MEM_ERROR; michael@0: } michael@0: michael@0: ctx->priv = &priv->base; michael@0: ctx->priv->sz = sizeof(*ctx->priv); michael@0: ctx->priv->iface = ctx->iface; michael@0: ctx->priv->alg_priv = priv; michael@0: ctx->priv->init_flags = ctx->init_flags; michael@0: ctx->priv->enc.total_encoders = 1; michael@0: michael@0: if (ctx->config.enc) { michael@0: /* Update the reference to the config structure to an michael@0: * internal copy. michael@0: */ michael@0: ctx->priv->alg_priv->cfg = *ctx->config.enc; michael@0: ctx->config.enc = &ctx->priv->alg_priv->cfg; michael@0: } michael@0: michael@0: cfg = &ctx->priv->alg_priv->cfg; michael@0: michael@0: /* Select the extra vp6 configuration table based on the current michael@0: * usage value. If the current usage value isn't found, use the michael@0: * values for usage case 0. michael@0: */ michael@0: for (i = 0; michael@0: extracfg_map[i].usage && extracfg_map[i].usage != cfg->g_usage; michael@0: i++) {} michael@0: michael@0: priv->vp8_cfg = extracfg_map[i].cfg; michael@0: priv->vp8_cfg.pkt_list = &priv->pkt_list.head; michael@0: priv->vp8_cfg.experimental = experimental; michael@0: michael@0: // TODO(agrange) Check the limits set on this buffer, or the check that is michael@0: // applied in vp9e_encode. michael@0: priv->cx_data_sz = priv->cfg.g_w * priv->cfg.g_h * 3 / 2 * 8; michael@0: // priv->cx_data_sz = priv->cfg.g_w * priv->cfg.g_h * 3 / 2 * 2; michael@0: michael@0: if (priv->cx_data_sz < 4096) priv->cx_data_sz = 4096; michael@0: michael@0: priv->cx_data = malloc(priv->cx_data_sz); michael@0: michael@0: if (!priv->cx_data) { michael@0: return VPX_CODEC_MEM_ERROR; michael@0: } michael@0: michael@0: vp9_initialize_enc(); michael@0: michael@0: res = validate_config(priv, &priv->cfg, &priv->vp8_cfg); michael@0: michael@0: if (!res) { michael@0: set_vp9e_config(&ctx->priv->alg_priv->oxcf, michael@0: ctx->priv->alg_priv->cfg, michael@0: ctx->priv->alg_priv->vp8_cfg); michael@0: optr = vp9_create_compressor(&ctx->priv->alg_priv->oxcf); michael@0: michael@0: if (!optr) michael@0: res = VPX_CODEC_MEM_ERROR; michael@0: else michael@0: ctx->priv->alg_priv->cpi = optr; michael@0: } michael@0: } michael@0: michael@0: return res; michael@0: } michael@0: michael@0: michael@0: static vpx_codec_err_t vp9e_init(vpx_codec_ctx_t *ctx, michael@0: vpx_codec_priv_enc_mr_cfg_t *data) { michael@0: return vp9e_common_init(ctx, 0); michael@0: } michael@0: michael@0: michael@0: #if CONFIG_EXPERIMENTAL michael@0: static vpx_codec_err_t vp9e_exp_init(vpx_codec_ctx_t *ctx, michael@0: vpx_codec_priv_enc_mr_cfg_t *data) { michael@0: return vp9e_common_init(ctx, 1); michael@0: } michael@0: #endif michael@0: michael@0: michael@0: static vpx_codec_err_t vp9e_destroy(vpx_codec_alg_priv_t *ctx) { michael@0: free(ctx->cx_data); michael@0: vp9_remove_compressor(&ctx->cpi); michael@0: free(ctx); michael@0: return VPX_CODEC_OK; michael@0: } michael@0: michael@0: static void pick_quickcompress_mode(vpx_codec_alg_priv_t *ctx, michael@0: unsigned long duration, michael@0: unsigned long deadline) { michael@0: unsigned int new_qc; michael@0: michael@0: /* Use best quality mode if no deadline is given. */ michael@0: if (deadline) michael@0: new_qc = MODE_GOODQUALITY; michael@0: else michael@0: new_qc = MODE_BESTQUALITY; michael@0: michael@0: if (ctx->cfg.g_pass == VPX_RC_FIRST_PASS) michael@0: new_qc = MODE_FIRSTPASS; michael@0: else if (ctx->cfg.g_pass == VPX_RC_LAST_PASS) michael@0: new_qc = (new_qc == MODE_BESTQUALITY) michael@0: ? MODE_SECONDPASS_BEST michael@0: : MODE_SECONDPASS; michael@0: michael@0: if (ctx->oxcf.Mode != new_qc) { michael@0: ctx->oxcf.Mode = new_qc; michael@0: vp9_change_config(ctx->cpi, &ctx->oxcf); michael@0: } michael@0: } michael@0: michael@0: michael@0: static int write_superframe_index(vpx_codec_alg_priv_t *ctx) { michael@0: uint8_t marker = 0xc0; michael@0: unsigned int mask; michael@0: int mag, index_sz; michael@0: michael@0: assert(ctx->pending_frame_count); michael@0: assert(ctx->pending_frame_count <= 8); michael@0: michael@0: /* Add the number of frames to the marker byte */ michael@0: marker |= ctx->pending_frame_count - 1; michael@0: michael@0: /* Choose the magnitude */ michael@0: for (mag = 0, mask = 0xff; mag < 4; mag++) { michael@0: if (ctx->pending_frame_magnitude < mask) michael@0: break; michael@0: mask <<= 8; michael@0: mask |= 0xff; michael@0: } michael@0: marker |= mag << 3; michael@0: michael@0: /* Write the index */ michael@0: index_sz = 2 + (mag + 1) * ctx->pending_frame_count; michael@0: if (ctx->pending_cx_data_sz + index_sz < ctx->cx_data_sz) { michael@0: uint8_t *x = ctx->pending_cx_data + ctx->pending_cx_data_sz; michael@0: int i, j; michael@0: michael@0: *x++ = marker; michael@0: for (i = 0; i < ctx->pending_frame_count; i++) { michael@0: int this_sz = ctx->pending_frame_sizes[i]; michael@0: michael@0: for (j = 0; j <= mag; j++) { michael@0: *x++ = this_sz & 0xff; michael@0: this_sz >>= 8; michael@0: } michael@0: } michael@0: *x++ = marker; michael@0: ctx->pending_cx_data_sz += index_sz; michael@0: } michael@0: return index_sz; michael@0: } michael@0: michael@0: static vpx_codec_err_t vp9e_encode(vpx_codec_alg_priv_t *ctx, michael@0: const vpx_image_t *img, michael@0: vpx_codec_pts_t pts, michael@0: unsigned long duration, michael@0: vpx_enc_frame_flags_t flags, michael@0: unsigned long deadline) { michael@0: vpx_codec_err_t res = VPX_CODEC_OK; michael@0: michael@0: if (img) michael@0: res = validate_img(ctx, img); michael@0: michael@0: pick_quickcompress_mode(ctx, duration, deadline); michael@0: vpx_codec_pkt_list_init(&ctx->pkt_list); michael@0: michael@0: /* Handle Flags */ michael@0: if (((flags & VP8_EFLAG_NO_UPD_GF) && (flags & VP8_EFLAG_FORCE_GF)) michael@0: || ((flags & VP8_EFLAG_NO_UPD_ARF) && (flags & VP8_EFLAG_FORCE_ARF))) { michael@0: ctx->base.err_detail = "Conflicting flags."; michael@0: return VPX_CODEC_INVALID_PARAM; michael@0: } michael@0: michael@0: if (flags & (VP8_EFLAG_NO_REF_LAST | VP8_EFLAG_NO_REF_GF michael@0: | VP8_EFLAG_NO_REF_ARF)) { michael@0: int ref = 7; michael@0: michael@0: if (flags & VP8_EFLAG_NO_REF_LAST) michael@0: ref ^= VP9_LAST_FLAG; michael@0: michael@0: if (flags & VP8_EFLAG_NO_REF_GF) michael@0: ref ^= VP9_GOLD_FLAG; michael@0: michael@0: if (flags & VP8_EFLAG_NO_REF_ARF) michael@0: ref ^= VP9_ALT_FLAG; michael@0: michael@0: vp9_use_as_reference(ctx->cpi, ref); michael@0: } michael@0: michael@0: if (flags & (VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF michael@0: | VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_FORCE_GF michael@0: | VP8_EFLAG_FORCE_ARF)) { michael@0: int upd = 7; michael@0: michael@0: if (flags & VP8_EFLAG_NO_UPD_LAST) michael@0: upd ^= VP9_LAST_FLAG; michael@0: michael@0: if (flags & VP8_EFLAG_NO_UPD_GF) michael@0: upd ^= VP9_GOLD_FLAG; michael@0: michael@0: if (flags & VP8_EFLAG_NO_UPD_ARF) michael@0: upd ^= VP9_ALT_FLAG; michael@0: michael@0: vp9_update_reference(ctx->cpi, upd); michael@0: } michael@0: michael@0: if (flags & VP8_EFLAG_NO_UPD_ENTROPY) { michael@0: vp9_update_entropy(ctx->cpi, 0); michael@0: } michael@0: michael@0: /* Handle fixed keyframe intervals */ michael@0: if (ctx->cfg.kf_mode == VPX_KF_AUTO michael@0: && ctx->cfg.kf_min_dist == ctx->cfg.kf_max_dist) { michael@0: if (++ctx->fixed_kf_cntr > ctx->cfg.kf_min_dist) { michael@0: flags |= VPX_EFLAG_FORCE_KF; michael@0: ctx->fixed_kf_cntr = 1; michael@0: } michael@0: } michael@0: michael@0: /* Initialize the encoder instance on the first frame*/ michael@0: if (!res && ctx->cpi) { michael@0: unsigned int lib_flags; michael@0: YV12_BUFFER_CONFIG sd; michael@0: int64_t dst_time_stamp, dst_end_time_stamp; michael@0: unsigned long size, cx_data_sz; michael@0: unsigned char *cx_data; michael@0: michael@0: /* Set up internal flags */ michael@0: if (ctx->base.init_flags & VPX_CODEC_USE_PSNR) michael@0: ((VP9_COMP *)ctx->cpi)->b_calculate_psnr = 1; michael@0: michael@0: // if (ctx->base.init_flags & VPX_CODEC_USE_OUTPUT_PARTITION) michael@0: // ((VP9_COMP *)ctx->cpi)->output_partition = 1; michael@0: michael@0: /* Convert API flags to internal codec lib flags */ michael@0: lib_flags = (flags & VPX_EFLAG_FORCE_KF) ? FRAMEFLAGS_KEY : 0; michael@0: michael@0: /* vp8 use 10,000,000 ticks/second as time stamp */ michael@0: dst_time_stamp = pts * 10000000 * ctx->cfg.g_timebase.num michael@0: / ctx->cfg.g_timebase.den; michael@0: dst_end_time_stamp = (pts + duration) * 10000000 * ctx->cfg.g_timebase.num / michael@0: ctx->cfg.g_timebase.den; michael@0: michael@0: if (img != NULL) { michael@0: res = image2yuvconfig(img, &sd); michael@0: michael@0: if (vp9_receive_raw_frame(ctx->cpi, lib_flags, michael@0: &sd, dst_time_stamp, dst_end_time_stamp)) { michael@0: VP9_COMP *cpi = (VP9_COMP *)ctx->cpi; michael@0: res = update_error_state(ctx, &cpi->common.error); michael@0: } michael@0: } michael@0: michael@0: cx_data = ctx->cx_data; michael@0: cx_data_sz = ctx->cx_data_sz; michael@0: lib_flags = 0; michael@0: michael@0: /* Any pending invisible frames? */ michael@0: if (ctx->pending_cx_data) { michael@0: memmove(cx_data, ctx->pending_cx_data, ctx->pending_cx_data_sz); michael@0: ctx->pending_cx_data = cx_data; michael@0: cx_data += ctx->pending_cx_data_sz; michael@0: cx_data_sz -= ctx->pending_cx_data_sz; michael@0: michael@0: /* TODO: this is a minimal check, the underlying codec doesn't respect michael@0: * the buffer size anyway. michael@0: */ michael@0: if (cx_data_sz < ctx->cx_data_sz / 2) { michael@0: ctx->base.err_detail = "Compressed data buffer too small"; michael@0: return VPX_CODEC_ERROR; michael@0: } michael@0: } michael@0: michael@0: while (cx_data_sz >= ctx->cx_data_sz / 2 && michael@0: -1 != vp9_get_compressed_data(ctx->cpi, &lib_flags, &size, michael@0: cx_data, &dst_time_stamp, michael@0: &dst_end_time_stamp, !img)) { michael@0: if (size) { michael@0: vpx_codec_pts_t round, delta; michael@0: vpx_codec_cx_pkt_t pkt; michael@0: VP9_COMP *cpi = (VP9_COMP *)ctx->cpi; michael@0: michael@0: /* Pack invisible frames with the next visible frame */ michael@0: if (!cpi->common.show_frame) { michael@0: if (!ctx->pending_cx_data) michael@0: ctx->pending_cx_data = cx_data; michael@0: ctx->pending_cx_data_sz += size; michael@0: ctx->pending_frame_sizes[ctx->pending_frame_count++] = size; michael@0: ctx->pending_frame_magnitude |= size; michael@0: cx_data += size; michael@0: cx_data_sz -= size; michael@0: continue; michael@0: } michael@0: michael@0: /* Add the frame packet to the list of returned packets. */ michael@0: round = (vpx_codec_pts_t)1000000 * ctx->cfg.g_timebase.num / 2 - 1; michael@0: delta = (dst_end_time_stamp - dst_time_stamp); michael@0: pkt.kind = VPX_CODEC_CX_FRAME_PKT; michael@0: pkt.data.frame.pts = michael@0: (dst_time_stamp * ctx->cfg.g_timebase.den + round) michael@0: / ctx->cfg.g_timebase.num / 10000000; michael@0: pkt.data.frame.duration = (unsigned long) michael@0: ((delta * ctx->cfg.g_timebase.den + round) michael@0: / ctx->cfg.g_timebase.num / 10000000); michael@0: pkt.data.frame.flags = lib_flags << 16; michael@0: michael@0: if (lib_flags & FRAMEFLAGS_KEY) michael@0: pkt.data.frame.flags |= VPX_FRAME_IS_KEY; michael@0: michael@0: if (!cpi->common.show_frame) { michael@0: pkt.data.frame.flags |= VPX_FRAME_IS_INVISIBLE; michael@0: michael@0: // This timestamp should be as close as possible to the michael@0: // prior PTS so that if a decoder uses pts to schedule when michael@0: // to do this, we start right after last frame was decoded. michael@0: // Invisible frames have no duration. michael@0: pkt.data.frame.pts = ((cpi->last_time_stamp_seen michael@0: * ctx->cfg.g_timebase.den + round) michael@0: / ctx->cfg.g_timebase.num / 10000000) + 1; michael@0: pkt.data.frame.duration = 0; michael@0: } michael@0: michael@0: if (cpi->droppable) michael@0: pkt.data.frame.flags |= VPX_FRAME_IS_DROPPABLE; michael@0: michael@0: /*if (cpi->output_partition) michael@0: { michael@0: int i; michael@0: const int num_partitions = 1; michael@0: michael@0: pkt.data.frame.flags |= VPX_FRAME_IS_FRAGMENT; michael@0: michael@0: for (i = 0; i < num_partitions; ++i) michael@0: { michael@0: pkt.data.frame.buf = cx_data; michael@0: pkt.data.frame.sz = cpi->partition_sz[i]; michael@0: pkt.data.frame.partition_id = i; michael@0: // don't set the fragment bit for the last partition michael@0: if (i == (num_partitions - 1)) michael@0: pkt.data.frame.flags &= ~VPX_FRAME_IS_FRAGMENT; michael@0: vpx_codec_pkt_list_add(&ctx->pkt_list.head, &pkt); michael@0: cx_data += cpi->partition_sz[i]; michael@0: cx_data_sz -= cpi->partition_sz[i]; michael@0: } michael@0: } michael@0: else*/ michael@0: { michael@0: if (ctx->pending_cx_data) { michael@0: ctx->pending_frame_sizes[ctx->pending_frame_count++] = size; michael@0: ctx->pending_frame_magnitude |= size; michael@0: ctx->pending_cx_data_sz += size; michael@0: size += write_superframe_index(ctx); michael@0: pkt.data.frame.buf = ctx->pending_cx_data; michael@0: pkt.data.frame.sz = ctx->pending_cx_data_sz; michael@0: ctx->pending_cx_data = NULL; michael@0: ctx->pending_cx_data_sz = 0; michael@0: ctx->pending_frame_count = 0; michael@0: ctx->pending_frame_magnitude = 0; michael@0: } else { michael@0: pkt.data.frame.buf = cx_data; michael@0: pkt.data.frame.sz = size; michael@0: } michael@0: pkt.data.frame.partition_id = -1; michael@0: vpx_codec_pkt_list_add(&ctx->pkt_list.head, &pkt); michael@0: cx_data += size; michael@0: cx_data_sz -= size; michael@0: } michael@0: } michael@0: } michael@0: } michael@0: michael@0: return res; michael@0: } michael@0: michael@0: michael@0: static const vpx_codec_cx_pkt_t *vp9e_get_cxdata(vpx_codec_alg_priv_t *ctx, michael@0: vpx_codec_iter_t *iter) { michael@0: return vpx_codec_pkt_list_get(&ctx->pkt_list.head, iter); michael@0: } michael@0: michael@0: static vpx_codec_err_t vp9e_set_reference(vpx_codec_alg_priv_t *ctx, michael@0: int ctr_id, michael@0: va_list args) { michael@0: vpx_ref_frame_t *data = va_arg(args, vpx_ref_frame_t *); michael@0: michael@0: if (data) { michael@0: vpx_ref_frame_t *frame = (vpx_ref_frame_t *)data; michael@0: YV12_BUFFER_CONFIG sd; michael@0: michael@0: image2yuvconfig(&frame->img, &sd); michael@0: vp9_set_reference_enc(ctx->cpi, ref_frame_to_vp9_reframe(frame->frame_type), michael@0: &sd); michael@0: return VPX_CODEC_OK; michael@0: } else { michael@0: return VPX_CODEC_INVALID_PARAM; michael@0: } michael@0: } michael@0: michael@0: static vpx_codec_err_t vp9e_copy_reference(vpx_codec_alg_priv_t *ctx, michael@0: int ctr_id, michael@0: va_list args) { michael@0: vpx_ref_frame_t *data = va_arg(args, vpx_ref_frame_t *); michael@0: michael@0: if (data) { michael@0: vpx_ref_frame_t *frame = (vpx_ref_frame_t *)data; michael@0: YV12_BUFFER_CONFIG sd; michael@0: michael@0: image2yuvconfig(&frame->img, &sd); michael@0: vp9_copy_reference_enc(ctx->cpi, michael@0: ref_frame_to_vp9_reframe(frame->frame_type), &sd); michael@0: return VPX_CODEC_OK; michael@0: } else { michael@0: return VPX_CODEC_INVALID_PARAM; michael@0: } michael@0: } michael@0: michael@0: static vpx_codec_err_t get_reference(vpx_codec_alg_priv_t *ctx, michael@0: int ctr_id, michael@0: va_list args) { michael@0: vp9_ref_frame_t *data = va_arg(args, vp9_ref_frame_t *); michael@0: michael@0: if (data) { michael@0: YV12_BUFFER_CONFIG* fb; michael@0: michael@0: vp9_get_reference_enc(ctx->cpi, data->idx, &fb); michael@0: yuvconfig2image(&data->img, fb, NULL); michael@0: return VPX_CODEC_OK; michael@0: } else { michael@0: return VPX_CODEC_INVALID_PARAM; michael@0: } michael@0: } michael@0: michael@0: static vpx_codec_err_t vp9e_set_previewpp(vpx_codec_alg_priv_t *ctx, michael@0: int ctr_id, michael@0: va_list args) { michael@0: #if CONFIG_VP9_POSTPROC michael@0: vp8_postproc_cfg_t *data = va_arg(args, vp8_postproc_cfg_t *); michael@0: (void)ctr_id; michael@0: michael@0: if (data) { michael@0: ctx->preview_ppcfg = *((vp8_postproc_cfg_t *)data); michael@0: return VPX_CODEC_OK; michael@0: } else { michael@0: return VPX_CODEC_INVALID_PARAM; michael@0: } michael@0: #else michael@0: (void)ctx; michael@0: (void)ctr_id; michael@0: (void)args; michael@0: return VPX_CODEC_INCAPABLE; michael@0: #endif michael@0: } michael@0: michael@0: michael@0: static vpx_image_t *vp9e_get_preview(vpx_codec_alg_priv_t *ctx) { michael@0: YV12_BUFFER_CONFIG sd; michael@0: vp9_ppflags_t flags = {0}; michael@0: michael@0: if (ctx->preview_ppcfg.post_proc_flag) { michael@0: flags.post_proc_flag = ctx->preview_ppcfg.post_proc_flag; michael@0: flags.deblocking_level = ctx->preview_ppcfg.deblocking_level; michael@0: flags.noise_level = ctx->preview_ppcfg.noise_level; michael@0: } michael@0: michael@0: if (0 == vp9_get_preview_raw_frame(ctx->cpi, &sd, &flags)) { michael@0: yuvconfig2image(&ctx->preview_img, &sd, NULL); michael@0: return &ctx->preview_img; michael@0: } else { michael@0: return NULL; michael@0: } michael@0: } michael@0: michael@0: static vpx_codec_err_t vp9e_update_entropy(vpx_codec_alg_priv_t *ctx, michael@0: int ctr_id, michael@0: va_list args) { michael@0: int update = va_arg(args, int); michael@0: vp9_update_entropy(ctx->cpi, update); michael@0: return VPX_CODEC_OK; michael@0: } michael@0: michael@0: static vpx_codec_err_t vp9e_update_reference(vpx_codec_alg_priv_t *ctx, michael@0: int ctr_id, michael@0: va_list args) { michael@0: int update = va_arg(args, int); michael@0: vp9_update_reference(ctx->cpi, update); michael@0: return VPX_CODEC_OK; michael@0: } michael@0: michael@0: static vpx_codec_err_t vp9e_use_reference(vpx_codec_alg_priv_t *ctx, michael@0: int ctr_id, michael@0: va_list args) { michael@0: int reference_flag = va_arg(args, int); michael@0: vp9_use_as_reference(ctx->cpi, reference_flag); michael@0: return VPX_CODEC_OK; michael@0: } michael@0: michael@0: static vpx_codec_err_t vp9e_set_roi_map(vpx_codec_alg_priv_t *ctx, michael@0: int ctr_id, michael@0: va_list args) { michael@0: // TODO(yaowu): Need to re-implement and test for VP9. michael@0: return VPX_CODEC_INVALID_PARAM; michael@0: } michael@0: michael@0: michael@0: static vpx_codec_err_t vp9e_set_activemap(vpx_codec_alg_priv_t *ctx, michael@0: int ctr_id, michael@0: va_list args) { michael@0: // TODO(yaowu): Need to re-implement and test for VP9. michael@0: return VPX_CODEC_INVALID_PARAM; michael@0: } michael@0: michael@0: static vpx_codec_err_t vp9e_set_scalemode(vpx_codec_alg_priv_t *ctx, michael@0: int ctr_id, michael@0: va_list args) { michael@0: vpx_scaling_mode_t *data = va_arg(args, vpx_scaling_mode_t *); michael@0: michael@0: if (data) { michael@0: int res; michael@0: vpx_scaling_mode_t scalemode = *(vpx_scaling_mode_t *)data; michael@0: res = vp9_set_internal_size(ctx->cpi, michael@0: (VPX_SCALING)scalemode.h_scaling_mode, michael@0: (VPX_SCALING)scalemode.v_scaling_mode); michael@0: michael@0: if (!res) { michael@0: return VPX_CODEC_OK; michael@0: } else { michael@0: return VPX_CODEC_INVALID_PARAM; michael@0: } michael@0: } else { michael@0: return VPX_CODEC_INVALID_PARAM; michael@0: } michael@0: } michael@0: michael@0: static vpx_codec_err_t vp9e_set_svc(vpx_codec_alg_priv_t *ctx, int ctr_id, michael@0: va_list args) { michael@0: int data = va_arg(args, int); michael@0: vp9_set_svc(ctx->cpi, data); michael@0: return VPX_CODEC_OK; michael@0: } michael@0: michael@0: static vpx_codec_err_t vp9e_set_svc_parameters(vpx_codec_alg_priv_t *ctx, michael@0: int ctr_id, va_list args) { michael@0: vpx_svc_parameters_t *data = va_arg(args, vpx_svc_parameters_t *); michael@0: VP9_COMP *cpi = (VP9_COMP *)ctx->cpi; michael@0: vpx_svc_parameters_t params; michael@0: michael@0: if (data == NULL) { michael@0: return VPX_CODEC_INVALID_PARAM; michael@0: } michael@0: michael@0: params = *(vpx_svc_parameters_t *)data; michael@0: michael@0: cpi->current_layer = params.layer; michael@0: cpi->lst_fb_idx = params.lst_fb_idx; michael@0: cpi->gld_fb_idx = params.gld_fb_idx; michael@0: cpi->alt_fb_idx = params.alt_fb_idx; michael@0: michael@0: if (vp9_set_size_literal(ctx->cpi, params.width, params.height) != 0) { michael@0: return VPX_CODEC_INVALID_PARAM; michael@0: } michael@0: michael@0: ctx->cfg.rc_max_quantizer = params.max_quantizer; michael@0: ctx->cfg.rc_min_quantizer = params.min_quantizer; michael@0: michael@0: set_vp9e_config(&ctx->oxcf, ctx->cfg, ctx->vp8_cfg); michael@0: vp9_change_config(ctx->cpi, &ctx->oxcf); michael@0: michael@0: return VPX_CODEC_OK; michael@0: } michael@0: michael@0: static vpx_codec_ctrl_fn_map_t vp9e_ctf_maps[] = { michael@0: {VP8_SET_REFERENCE, vp9e_set_reference}, michael@0: {VP8_COPY_REFERENCE, vp9e_copy_reference}, michael@0: {VP8_SET_POSTPROC, vp9e_set_previewpp}, michael@0: {VP8E_UPD_ENTROPY, vp9e_update_entropy}, michael@0: {VP8E_UPD_REFERENCE, vp9e_update_reference}, michael@0: {VP8E_USE_REFERENCE, vp9e_use_reference}, michael@0: {VP8E_SET_ROI_MAP, vp9e_set_roi_map}, michael@0: {VP8E_SET_ACTIVEMAP, vp9e_set_activemap}, michael@0: {VP8E_SET_SCALEMODE, vp9e_set_scalemode}, michael@0: {VP8E_SET_CPUUSED, set_param}, michael@0: {VP8E_SET_NOISE_SENSITIVITY, set_param}, michael@0: {VP8E_SET_ENABLEAUTOALTREF, set_param}, michael@0: {VP8E_SET_SHARPNESS, set_param}, michael@0: {VP8E_SET_STATIC_THRESHOLD, set_param}, michael@0: {VP9E_SET_TILE_COLUMNS, set_param}, michael@0: {VP9E_SET_TILE_ROWS, set_param}, michael@0: {VP8E_GET_LAST_QUANTIZER, get_param}, michael@0: {VP8E_GET_LAST_QUANTIZER_64, get_param}, michael@0: {VP8E_SET_ARNR_MAXFRAMES, set_param}, michael@0: {VP8E_SET_ARNR_STRENGTH, set_param}, michael@0: {VP8E_SET_ARNR_TYPE, set_param}, michael@0: {VP8E_SET_TUNING, set_param}, michael@0: {VP8E_SET_CQ_LEVEL, set_param}, michael@0: {VP8E_SET_MAX_INTRA_BITRATE_PCT, set_param}, michael@0: {VP9E_SET_LOSSLESS, set_param}, michael@0: {VP9E_SET_FRAME_PARALLEL_DECODING, set_param}, michael@0: {VP9E_SET_AQ_MODE, set_param}, michael@0: {VP9_GET_REFERENCE, get_reference}, michael@0: {VP9E_SET_SVC, vp9e_set_svc}, michael@0: {VP9E_SET_SVC_PARAMETERS, vp9e_set_svc_parameters}, michael@0: { -1, NULL}, michael@0: }; michael@0: michael@0: static vpx_codec_enc_cfg_map_t vp9e_usage_cfg_map[] = { michael@0: { michael@0: 0, michael@0: { // NOLINT michael@0: 0, /* g_usage */ michael@0: 0, /* g_threads */ michael@0: 0, /* g_profile */ michael@0: michael@0: 320, /* g_width */ michael@0: 240, /* g_height */ michael@0: {1, 30}, /* g_timebase */ michael@0: michael@0: 0, /* g_error_resilient */ michael@0: michael@0: VPX_RC_ONE_PASS, /* g_pass */ michael@0: michael@0: 25, /* g_lag_in_frames */ michael@0: michael@0: 0, /* rc_dropframe_thresh */ michael@0: 0, /* rc_resize_allowed */ michael@0: 60, /* rc_resize_down_thresold */ michael@0: 30, /* rc_resize_up_thresold */ michael@0: michael@0: VPX_VBR, /* rc_end_usage */ michael@0: #if VPX_ENCODER_ABI_VERSION > (1 + VPX_CODEC_ABI_VERSION) michael@0: {0}, /* rc_twopass_stats_in */ michael@0: #endif michael@0: 256, /* rc_target_bandwidth */ michael@0: 0, /* rc_min_quantizer */ michael@0: 63, /* rc_max_quantizer */ michael@0: 100, /* rc_undershoot_pct */ michael@0: 100, /* rc_overshoot_pct */ michael@0: michael@0: 6000, /* rc_max_buffer_size */ michael@0: 4000, /* rc_buffer_initial_size; */ michael@0: 5000, /* rc_buffer_optimal_size; */ michael@0: michael@0: 50, /* rc_two_pass_vbrbias */ michael@0: 0, /* rc_two_pass_vbrmin_section */ michael@0: 2000, /* rc_two_pass_vbrmax_section */ michael@0: michael@0: /* keyframing settings (kf) */ michael@0: VPX_KF_AUTO, /* g_kfmode*/ michael@0: 0, /* kf_min_dist */ michael@0: 9999, /* kf_max_dist */ michael@0: michael@0: VPX_SS_DEFAULT_LAYERS, /* ss_number_layers */ michael@0: michael@0: #if VPX_ENCODER_ABI_VERSION == (1 + VPX_CODEC_ABI_VERSION) michael@0: 1, /* g_delete_first_pass_file */ michael@0: "vp8.fpf" /* first pass filename */ michael@0: #endif michael@0: } michael@0: }, michael@0: { -1, {NOT_IMPLEMENTED}} michael@0: }; michael@0: michael@0: michael@0: #ifndef VERSION_STRING michael@0: #define VERSION_STRING michael@0: #endif michael@0: CODEC_INTERFACE(vpx_codec_vp9_cx) = { michael@0: "WebM Project VP9 Encoder" VERSION_STRING, michael@0: VPX_CODEC_INTERNAL_ABI_VERSION, michael@0: VPX_CODEC_CAP_ENCODER | VPX_CODEC_CAP_PSNR | michael@0: VPX_CODEC_CAP_OUTPUT_PARTITION, michael@0: /* vpx_codec_caps_t caps; */ michael@0: vp9e_init, /* vpx_codec_init_fn_t init; */ michael@0: vp9e_destroy, /* vpx_codec_destroy_fn_t destroy; */ michael@0: vp9e_ctf_maps, /* vpx_codec_ctrl_fn_map_t *ctrl_maps; */ michael@0: NOT_IMPLEMENTED, /* vpx_codec_get_mmap_fn_t get_mmap; */ michael@0: NOT_IMPLEMENTED, /* vpx_codec_set_mmap_fn_t set_mmap; */ michael@0: { // NOLINT michael@0: NOT_IMPLEMENTED, /* vpx_codec_peek_si_fn_t peek_si; */ michael@0: NOT_IMPLEMENTED, /* vpx_codec_get_si_fn_t get_si; */ michael@0: NOT_IMPLEMENTED, /* vpx_codec_decode_fn_t decode; */ michael@0: NOT_IMPLEMENTED, /* vpx_codec_frame_get_fn_t frame_get; */ michael@0: }, michael@0: { // NOLINT michael@0: vp9e_usage_cfg_map, /* vpx_codec_enc_cfg_map_t peek_si; */ michael@0: vp9e_encode, /* vpx_codec_encode_fn_t encode; */ michael@0: vp9e_get_cxdata, /* vpx_codec_get_cx_data_fn_t frame_get; */ michael@0: vp9e_set_config, michael@0: NOT_IMPLEMENTED, michael@0: vp9e_get_preview, michael@0: } /* encoder functions */ michael@0: }; michael@0: michael@0: michael@0: #if CONFIG_EXPERIMENTAL michael@0: michael@0: CODEC_INTERFACE(vpx_codec_vp9x_cx) = { michael@0: "VP8 Experimental Encoder" VERSION_STRING, michael@0: VPX_CODEC_INTERNAL_ABI_VERSION, michael@0: VPX_CODEC_CAP_ENCODER | VPX_CODEC_CAP_PSNR, michael@0: /* vpx_codec_caps_t caps; */ michael@0: vp9e_exp_init, /* vpx_codec_init_fn_t init; */ michael@0: vp9e_destroy, /* vpx_codec_destroy_fn_t destroy; */ michael@0: vp9e_ctf_maps, /* vpx_codec_ctrl_fn_map_t *ctrl_maps; */ michael@0: NOT_IMPLEMENTED, /* vpx_codec_get_mmap_fn_t get_mmap; */ michael@0: NOT_IMPLEMENTED, /* vpx_codec_set_mmap_fn_t set_mmap; */ michael@0: { // NOLINT michael@0: NOT_IMPLEMENTED, /* vpx_codec_peek_si_fn_t peek_si; */ michael@0: NOT_IMPLEMENTED, /* vpx_codec_get_si_fn_t get_si; */ michael@0: NOT_IMPLEMENTED, /* vpx_codec_decode_fn_t decode; */ michael@0: NOT_IMPLEMENTED, /* vpx_codec_frame_get_fn_t frame_get; */ michael@0: }, michael@0: { // NOLINT michael@0: vp9e_usage_cfg_map, /* vpx_codec_enc_cfg_map_t peek_si; */ michael@0: vp9e_encode, /* vpx_codec_encode_fn_t encode; */ michael@0: vp9e_get_cxdata, /* vpx_codec_get_cx_data_fn_t frame_get; */ michael@0: vp9e_set_config, michael@0: NOT_IMPLEMENTED, michael@0: vp9e_get_preview, michael@0: } /* encoder functions */ michael@0: }; michael@0: #endif