John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1 | /* |
John Koleszar | c2140b8 | 2010-09-09 08:16:39 -0400 | [diff] [blame] | 2 | * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 3 | * |
John Koleszar | 94c52e4 | 2010-06-18 12:39:21 -0400 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license |
John Koleszar | 09202d8 | 2010-06-04 16:19:40 -0400 | [diff] [blame] | 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 |
John Koleszar | 94c52e4 | 2010-06-18 12:39:21 -0400 | [diff] [blame] | 7 | * in the file PATENTS. All contributing project authors may |
John Koleszar | 09202d8 | 2010-06-04 16:19:40 -0400 | [diff] [blame] | 8 | * be found in the AUTHORS file in the root of the source tree. |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | |
John Koleszar | b749234 | 2010-05-24 11:39:59 -0400 | [diff] [blame] | 12 | #include "vpx/vpx_codec.h" |
| 13 | #include "vpx/internal/vpx_codec_internal.h" |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 14 | #include "vpx_version.h" |
John Koleszar | 02321de | 2011-02-10 14:41:38 -0500 | [diff] [blame] | 15 | #include "vp8/encoder/onyx_int.h" |
John Koleszar | 2bf8fb5 | 2012-05-02 16:37:37 -0700 | [diff] [blame] | 16 | #include "vpx/vp8cx.h" |
John Koleszar | bb7dd5b | 2010-10-14 16:40:12 -0400 | [diff] [blame] | 17 | #include "vp8/encoder/firstpass.h" |
John Koleszar | 02321de | 2011-02-10 14:41:38 -0500 | [diff] [blame] | 18 | #include "vp8/common/onyx.h" |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 19 | #include <stdlib.h> |
| 20 | #include <string.h> |
| 21 | |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 22 | struct vp8_extracfg |
| 23 | { |
| 24 | struct vpx_codec_pkt_list *pkt_list; |
| 25 | vp8e_encoding_mode encoding_mode; /** best, good, realtime */ |
| 26 | int cpu_used; /** available cpu percentage in 1/16*/ |
| 27 | unsigned int enable_auto_alt_ref; /** if encoder decides to uses alternate reference frame */ |
| 28 | unsigned int noise_sensitivity; |
| 29 | unsigned int Sharpness; |
| 30 | unsigned int static_thresh; |
| 31 | unsigned int token_partitions; |
| 32 | unsigned int arnr_max_frames; /* alt_ref Noise Reduction Max Frame Count */ |
| 33 | unsigned int arnr_strength; /* alt_ref Noise Reduction Strength */ |
| 34 | unsigned int arnr_type; /* alt_ref filter type */ |
John Koleszar | b0da9b3 | 2010-12-17 09:43:39 -0500 | [diff] [blame] | 35 | vp8e_tuning tuning; |
Paul Wilkins | e0846c9 | 2011-01-07 18:29:37 +0000 | [diff] [blame] | 36 | unsigned int cq_level; /* constrained quality level */ |
John Koleszar | 1654ae9 | 2011-07-28 09:17:32 -0400 | [diff] [blame] | 37 | unsigned int rc_max_intra_bitrate_pct; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 38 | |
| 39 | }; |
| 40 | |
| 41 | struct extraconfig_map |
| 42 | { |
| 43 | int usage; |
| 44 | struct vp8_extracfg cfg; |
| 45 | }; |
| 46 | |
| 47 | static const struct extraconfig_map extracfg_map[] = |
| 48 | { |
| 49 | { |
| 50 | 0, |
| 51 | { |
| 52 | NULL, |
| 53 | #if !(CONFIG_REALTIME_ONLY) |
| 54 | VP8_BEST_QUALITY_ENCODING, /* Encoding Mode */ |
John Koleszar | 89c8b3d | 2010-06-14 10:22:55 -0400 | [diff] [blame] | 55 | 0, /* cpu_used */ |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 56 | #else |
| 57 | VP8_REAL_TIME_ENCODING, /* Encoding Mode */ |
John Koleszar | 89c8b3d | 2010-06-14 10:22:55 -0400 | [diff] [blame] | 58 | 4, /* cpu_used */ |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 59 | #endif |
| 60 | 0, /* enable_auto_alt_ref */ |
| 61 | 0, /* noise_sensitivity */ |
| 62 | 0, /* Sharpness */ |
John Koleszar | 89c8b3d | 2010-06-14 10:22:55 -0400 | [diff] [blame] | 63 | 0, /* static_thresh */ |
Attila Nagy | 52cf4dc | 2012-02-09 12:37:03 +0200 | [diff] [blame] | 64 | #if (CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING) |
| 65 | VP8_EIGHT_TOKENPARTITION, |
| 66 | #else |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 67 | VP8_ONE_TOKENPARTITION, /* token_partitions */ |
Attila Nagy | 52cf4dc | 2012-02-09 12:37:03 +0200 | [diff] [blame] | 68 | #endif |
Adrian Grange | 8ee7284 | 2010-09-30 10:06:09 +0100 | [diff] [blame] | 69 | 0, /* arnr_max_frames */ |
| 70 | 3, /* arnr_strength */ |
| 71 | 3, /* arnr_type*/ |
John Koleszar | b0da9b3 | 2010-12-17 09:43:39 -0500 | [diff] [blame] | 72 | 0, /* tuning*/ |
Paul Wilkins | e0846c9 | 2011-01-07 18:29:37 +0000 | [diff] [blame] | 73 | 10, /* cq_level */ |
John Koleszar | 1654ae9 | 2011-07-28 09:17:32 -0400 | [diff] [blame] | 74 | 0, /* rc_max_intra_bitrate_pct */ |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | }; |
| 78 | |
| 79 | struct vpx_codec_alg_priv |
| 80 | { |
| 81 | vpx_codec_priv_t base; |
| 82 | vpx_codec_enc_cfg_t cfg; |
| 83 | struct vp8_extracfg vp8_cfg; |
| 84 | VP8_CONFIG oxcf; |
John Koleszar | b0056c3 | 2011-12-20 16:54:54 -0800 | [diff] [blame] | 85 | struct VP8_COMP *cpi; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 86 | unsigned char *cx_data; |
| 87 | unsigned int cx_data_sz; |
| 88 | vpx_image_t preview_img; |
| 89 | unsigned int next_frame_flag; |
| 90 | vp8_postproc_cfg_t preview_ppcfg; |
John Koleszar | 0164a1c | 2012-05-21 14:30:56 -0700 | [diff] [blame] | 91 | /* pkt_list size depends on the maximum number of lagged frames allowed. */ |
| 92 | vpx_codec_pkt_list_decl(64) pkt_list; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 93 | unsigned int fixed_kf_cntr; |
| 94 | }; |
| 95 | |
| 96 | |
| 97 | static vpx_codec_err_t |
| 98 | update_error_state(vpx_codec_alg_priv_t *ctx, |
| 99 | const struct vpx_internal_error_info *error) |
| 100 | { |
| 101 | vpx_codec_err_t res; |
| 102 | |
| 103 | if ((res = error->error_code)) |
| 104 | ctx->base.err_detail = error->has_detail |
| 105 | ? error->detail |
| 106 | : NULL; |
| 107 | |
| 108 | return res; |
| 109 | } |
| 110 | |
| 111 | |
John Koleszar | 79e2b1f | 2010-11-17 09:08:47 -0500 | [diff] [blame] | 112 | #undef ERROR |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 113 | #define ERROR(str) do {\ |
| 114 | ctx->base.err_detail = str;\ |
| 115 | return VPX_CODEC_INVALID_PARAM;\ |
| 116 | } while(0) |
| 117 | |
| 118 | #define RANGE_CHECK(p,memb,lo,hi) do {\ |
Guillermo Ballester Valor | 5a72620 | 2010-06-11 14:33:49 -0400 | [diff] [blame] | 119 | if(!(((p)->memb == lo || (p)->memb > (lo)) && (p)->memb <= hi)) \ |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 120 | ERROR(#memb " out of range ["#lo".."#hi"]");\ |
| 121 | } while(0) |
| 122 | |
Guillermo Ballester Valor | 2369068 | 2010-06-11 14:33:49 -0400 | [diff] [blame] | 123 | #define RANGE_CHECK_HI(p,memb,hi) do {\ |
| 124 | if(!((p)->memb <= (hi))) \ |
| 125 | ERROR(#memb " out of range [.."#hi"]");\ |
| 126 | } while(0) |
| 127 | |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 128 | #define RANGE_CHECK_LO(p,memb,lo) do {\ |
| 129 | if(!((p)->memb >= (lo))) \ |
| 130 | ERROR(#memb " out of range ["#lo"..]");\ |
| 131 | } while(0) |
| 132 | |
| 133 | #define RANGE_CHECK_BOOL(p,memb) do {\ |
| 134 | if(!!((p)->memb) != (p)->memb) ERROR(#memb " expected boolean");\ |
| 135 | } while(0) |
| 136 | |
| 137 | static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx, |
| 138 | const vpx_codec_enc_cfg_t *cfg, |
James Berry | c1c47e8 | 2011-12-07 15:48:00 -0500 | [diff] [blame] | 139 | const struct vp8_extracfg *vp8_cfg, |
| 140 | int finalize) |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 141 | { |
Attila Nagy | 1aadced | 2011-04-12 15:01:22 +0300 | [diff] [blame] | 142 | RANGE_CHECK(cfg, g_w, 1, 16383); /* 14 bits available */ |
| 143 | RANGE_CHECK(cfg, g_h, 1, 16383); /* 14 bits available */ |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 144 | RANGE_CHECK(cfg, g_timebase.den, 1, 1000000000); |
| 145 | RANGE_CHECK(cfg, g_timebase.num, 1, cfg->g_timebase.den); |
Guillermo Ballester Valor | 2369068 | 2010-06-11 14:33:49 -0400 | [diff] [blame] | 146 | RANGE_CHECK_HI(cfg, g_profile, 3); |
Guillermo Ballester Valor | 2369068 | 2010-06-11 14:33:49 -0400 | [diff] [blame] | 147 | RANGE_CHECK_HI(cfg, rc_max_quantizer, 63); |
John Koleszar | 2d03f07 | 2011-01-28 11:56:18 -0500 | [diff] [blame] | 148 | RANGE_CHECK_HI(cfg, rc_min_quantizer, cfg->rc_max_quantizer); |
Guillermo Ballester Valor | 2369068 | 2010-06-11 14:33:49 -0400 | [diff] [blame] | 149 | RANGE_CHECK_HI(cfg, g_threads, 64); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 150 | #if !(CONFIG_REALTIME_ONLY) |
Guillermo Ballester Valor | 2369068 | 2010-06-11 14:33:49 -0400 | [diff] [blame] | 151 | RANGE_CHECK_HI(cfg, g_lag_in_frames, 25); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 152 | #else |
Guillermo Ballester Valor | 2369068 | 2010-06-11 14:33:49 -0400 | [diff] [blame] | 153 | RANGE_CHECK_HI(cfg, g_lag_in_frames, 0); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 154 | #endif |
Paul Wilkins | e0846c9 | 2011-01-07 18:29:37 +0000 | [diff] [blame] | 155 | RANGE_CHECK(cfg, rc_end_usage, VPX_VBR, VPX_CQ); |
John Koleszar | c99f9d7 | 2011-04-11 11:29:23 -0400 | [diff] [blame] | 156 | RANGE_CHECK_HI(cfg, rc_undershoot_pct, 1000); |
| 157 | RANGE_CHECK_HI(cfg, rc_overshoot_pct, 1000); |
Guillermo Ballester Valor | 2369068 | 2010-06-11 14:33:49 -0400 | [diff] [blame] | 158 | RANGE_CHECK_HI(cfg, rc_2pass_vbr_bias_pct, 100); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 159 | RANGE_CHECK(cfg, kf_mode, VPX_KF_DISABLED, VPX_KF_AUTO); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 160 | RANGE_CHECK_BOOL(cfg, rc_resize_allowed); |
Guillermo Ballester Valor | 2369068 | 2010-06-11 14:33:49 -0400 | [diff] [blame] | 161 | RANGE_CHECK_HI(cfg, rc_dropframe_thresh, 100); |
| 162 | RANGE_CHECK_HI(cfg, rc_resize_up_thresh, 100); |
| 163 | RANGE_CHECK_HI(cfg, rc_resize_down_thresh, 100); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 164 | #if !(CONFIG_REALTIME_ONLY) |
| 165 | RANGE_CHECK(cfg, g_pass, VPX_RC_ONE_PASS, VPX_RC_LAST_PASS); |
| 166 | #else |
| 167 | RANGE_CHECK(cfg, g_pass, VPX_RC_ONE_PASS, VPX_RC_ONE_PASS); |
| 168 | #endif |
| 169 | |
| 170 | /* VP8 does not support a lower bound on the keyframe interval in |
| 171 | * automatic keyframe placement mode. |
| 172 | */ |
| 173 | if (cfg->kf_mode != VPX_KF_DISABLED && cfg->kf_min_dist != cfg->kf_max_dist |
| 174 | && cfg->kf_min_dist > 0) |
| 175 | ERROR("kf_min_dist not supported in auto mode, use 0 " |
| 176 | "or kf_max_dist instead."); |
| 177 | |
| 178 | RANGE_CHECK_BOOL(vp8_cfg, enable_auto_alt_ref); |
Yunqing Wang | 4fd81a9 | 2011-04-11 15:55:04 -0400 | [diff] [blame] | 179 | RANGE_CHECK(vp8_cfg, cpu_used, -16, 16); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 180 | #if !(CONFIG_REALTIME_ONLY) |
| 181 | RANGE_CHECK(vp8_cfg, encoding_mode, VP8_BEST_QUALITY_ENCODING, VP8_REAL_TIME_ENCODING); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 182 | #else |
| 183 | RANGE_CHECK(vp8_cfg, encoding_mode, VP8_REAL_TIME_ENCODING, VP8_REAL_TIME_ENCODING); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 184 | #endif |
John Koleszar | c8f4c18 | 2012-05-08 11:23:42 -0700 | [diff] [blame] | 185 | |
| 186 | #if CONFIG_REALTIME_ONLY && !CONFIG_TEMPORAL_DENOISING |
| 187 | RANGE_CHECK(vp8_cfg, noise_sensitivity, 0, 0); |
| 188 | #else |
| 189 | RANGE_CHECK_HI(vp8_cfg, noise_sensitivity, 6); |
Stefan Holmer | 9c41143 | 2012-03-06 10:48:18 +0100 | [diff] [blame] | 190 | #endif |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 191 | |
| 192 | RANGE_CHECK(vp8_cfg, token_partitions, VP8_ONE_TOKENPARTITION, VP8_EIGHT_TOKENPARTITION); |
Guillermo Ballester Valor | 2369068 | 2010-06-11 14:33:49 -0400 | [diff] [blame] | 193 | RANGE_CHECK_HI(vp8_cfg, Sharpness, 7); |
Adrian Grange | 8ee7284 | 2010-09-30 10:06:09 +0100 | [diff] [blame] | 194 | RANGE_CHECK(vp8_cfg, arnr_max_frames, 0, 15); |
Frank Galligan | 1554272 | 2010-10-04 21:12:22 -0400 | [diff] [blame] | 195 | RANGE_CHECK_HI(vp8_cfg, arnr_strength, 6); |
Adrian Grange | 8ee7284 | 2010-09-30 10:06:09 +0100 | [diff] [blame] | 196 | RANGE_CHECK(vp8_cfg, arnr_type, 1, 3); |
Paul Wilkins | e0846c9 | 2011-01-07 18:29:37 +0000 | [diff] [blame] | 197 | RANGE_CHECK(vp8_cfg, cq_level, 0, 63); |
James Berry | c1c47e8 | 2011-12-07 15:48:00 -0500 | [diff] [blame] | 198 | if(finalize && cfg->rc_end_usage == VPX_CQ) |
| 199 | RANGE_CHECK(vp8_cfg, cq_level, |
| 200 | cfg->rc_min_quantizer, cfg->rc_max_quantizer); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 201 | |
Attila Nagy | cb791aa | 2011-01-10 11:14:10 +0200 | [diff] [blame] | 202 | #if !(CONFIG_REALTIME_ONLY) |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 203 | if (cfg->g_pass == VPX_RC_LAST_PASS) |
| 204 | { |
Adrian Grange | ed40ff9 | 2011-03-10 11:32:48 -0800 | [diff] [blame] | 205 | size_t packet_sz = sizeof(FIRSTPASS_STATS); |
John Koleszar | bb7dd5b | 2010-10-14 16:40:12 -0400 | [diff] [blame] | 206 | int n_packets = cfg->rc_twopass_stats_in.sz / packet_sz; |
| 207 | FIRSTPASS_STATS *stats; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 208 | |
| 209 | if (!cfg->rc_twopass_stats_in.buf) |
| 210 | ERROR("rc_twopass_stats_in.buf not set."); |
| 211 | |
John Koleszar | bb7dd5b | 2010-10-14 16:40:12 -0400 | [diff] [blame] | 212 | if (cfg->rc_twopass_stats_in.sz % packet_sz) |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 213 | ERROR("rc_twopass_stats_in.sz indicates truncated packet."); |
| 214 | |
John Koleszar | bb7dd5b | 2010-10-14 16:40:12 -0400 | [diff] [blame] | 215 | if (cfg->rc_twopass_stats_in.sz < 2 * packet_sz) |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 216 | ERROR("rc_twopass_stats_in requires at least two packets."); |
| 217 | |
John Koleszar | bb7dd5b | 2010-10-14 16:40:12 -0400 | [diff] [blame] | 218 | stats = (void*)((char *)cfg->rc_twopass_stats_in.buf |
| 219 | + (n_packets - 1) * packet_sz); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 220 | |
John Koleszar | bb7dd5b | 2010-10-14 16:40:12 -0400 | [diff] [blame] | 221 | if ((int)(stats->count + 0.5) != n_packets - 1) |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 222 | ERROR("rc_twopass_stats_in missing EOS stats packet"); |
| 223 | } |
Attila Nagy | cb791aa | 2011-01-10 11:14:10 +0200 | [diff] [blame] | 224 | #endif |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 225 | |
Adrian Grange | 217591f | 2011-10-06 15:49:11 -0700 | [diff] [blame] | 226 | RANGE_CHECK(cfg, ts_number_layers, 1, 5); |
| 227 | |
| 228 | if (cfg->ts_number_layers > 1) |
| 229 | { |
Scott Graham | 92963df | 2012-05-08 11:45:35 -0700 | [diff] [blame] | 230 | unsigned int i; |
Adrian Grange | 217591f | 2011-10-06 15:49:11 -0700 | [diff] [blame] | 231 | RANGE_CHECK_HI(cfg, ts_periodicity, 16); |
| 232 | |
| 233 | for (i=1; i<cfg->ts_number_layers; i++) |
| 234 | if (cfg->ts_target_bitrate[i] <= cfg->ts_target_bitrate[i-1]) |
| 235 | ERROR("ts_target_bitrate entries are not strictly increasing"); |
| 236 | |
| 237 | RANGE_CHECK(cfg, ts_rate_decimator[cfg->ts_number_layers-1], 1, 1); |
| 238 | for (i=cfg->ts_number_layers-2; i>0; i--) |
| 239 | if (cfg->ts_rate_decimator[i-1] != 2*cfg->ts_rate_decimator[i]) |
| 240 | ERROR("ts_rate_decimator factors are not powers of 2"); |
| 241 | |
| 242 | RANGE_CHECK_HI(cfg, ts_layer_id[i], cfg->ts_number_layers-1); |
| 243 | } |
| 244 | |
Attila Nagy | 52cf4dc | 2012-02-09 12:37:03 +0200 | [diff] [blame] | 245 | #if (CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING) |
| 246 | if(cfg->g_threads > (1 << vp8_cfg->token_partitions)) |
| 247 | ERROR("g_threads cannot be bigger than number of token partitions"); |
| 248 | #endif |
| 249 | |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 250 | return VPX_CODEC_OK; |
| 251 | } |
| 252 | |
| 253 | |
| 254 | static vpx_codec_err_t validate_img(vpx_codec_alg_priv_t *ctx, |
| 255 | const vpx_image_t *img) |
| 256 | { |
| 257 | switch (img->fmt) |
| 258 | { |
James Zern | 6cd4a10 | 2010-05-20 23:22:39 -0400 | [diff] [blame] | 259 | case VPX_IMG_FMT_YV12: |
| 260 | case VPX_IMG_FMT_I420: |
| 261 | case VPX_IMG_FMT_VPXI420: |
| 262 | case VPX_IMG_FMT_VPXYV12: |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 263 | break; |
| 264 | default: |
| 265 | ERROR("Invalid image format. Only YV12 and I420 images are supported"); |
| 266 | } |
| 267 | |
| 268 | if ((img->d_w != ctx->cfg.g_w) || (img->d_h != ctx->cfg.g_h)) |
| 269 | ERROR("Image size must match encoder init configuration size"); |
| 270 | |
| 271 | return VPX_CODEC_OK; |
| 272 | } |
| 273 | |
| 274 | |
| 275 | static vpx_codec_err_t set_vp8e_config(VP8_CONFIG *oxcf, |
| 276 | vpx_codec_enc_cfg_t cfg, |
Yunqing Wang | aa7335e | 2011-10-25 15:14:16 -0400 | [diff] [blame] | 277 | struct vp8_extracfg vp8_cfg, |
| 278 | vpx_codec_priv_enc_mr_cfg_t *mr_cfg) |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 279 | { |
| 280 | oxcf->multi_threaded = cfg.g_threads; |
| 281 | oxcf->Version = cfg.g_profile; |
| 282 | |
| 283 | oxcf->Width = cfg.g_w; |
| 284 | oxcf->Height = cfg.g_h; |
John Koleszar | bdd35c1 | 2011-11-11 10:47:20 -0800 | [diff] [blame] | 285 | oxcf->timebase = cfg.g_timebase; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 286 | |
Adrian Grange | 217591f | 2011-10-06 15:49:11 -0700 | [diff] [blame] | 287 | oxcf->error_resilient_mode = cfg.g_error_resilient; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 288 | |
| 289 | switch (cfg.g_pass) |
| 290 | { |
| 291 | case VPX_RC_ONE_PASS: |
| 292 | oxcf->Mode = MODE_BESTQUALITY; |
| 293 | break; |
| 294 | case VPX_RC_FIRST_PASS: |
| 295 | oxcf->Mode = MODE_FIRSTPASS; |
| 296 | break; |
| 297 | case VPX_RC_LAST_PASS: |
| 298 | oxcf->Mode = MODE_SECONDPASS_BEST; |
| 299 | break; |
| 300 | } |
| 301 | |
James Zern | 7b0b6a2 | 2012-06-13 11:59:12 -0700 | [diff] [blame^] | 302 | if (cfg.g_pass == VPX_RC_FIRST_PASS || cfg.g_pass == VPX_RC_ONE_PASS) |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 303 | { |
Adrian Grange | 217591f | 2011-10-06 15:49:11 -0700 | [diff] [blame] | 304 | oxcf->allow_lag = 0; |
| 305 | oxcf->lag_in_frames = 0; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 306 | } |
| 307 | else |
| 308 | { |
Adrian Grange | 217591f | 2011-10-06 15:49:11 -0700 | [diff] [blame] | 309 | oxcf->allow_lag = (cfg.g_lag_in_frames) > 0; |
| 310 | oxcf->lag_in_frames = cfg.g_lag_in_frames; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | oxcf->allow_df = (cfg.rc_dropframe_thresh > 0); |
| 314 | oxcf->drop_frames_water_mark = cfg.rc_dropframe_thresh; |
| 315 | |
| 316 | oxcf->allow_spatial_resampling = cfg.rc_resize_allowed; |
| 317 | oxcf->resample_up_water_mark = cfg.rc_resize_up_thresh; |
| 318 | oxcf->resample_down_water_mark = cfg.rc_resize_down_thresh; |
| 319 | |
| 320 | if (cfg.rc_end_usage == VPX_VBR) |
| 321 | { |
Adrian Grange | 217591f | 2011-10-06 15:49:11 -0700 | [diff] [blame] | 322 | oxcf->end_usage = USAGE_LOCAL_FILE_PLAYBACK; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 323 | } |
| 324 | else if (cfg.rc_end_usage == VPX_CBR) |
| 325 | { |
Adrian Grange | 217591f | 2011-10-06 15:49:11 -0700 | [diff] [blame] | 326 | oxcf->end_usage = USAGE_STREAM_FROM_SERVER; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 327 | } |
Paul Wilkins | e0846c9 | 2011-01-07 18:29:37 +0000 | [diff] [blame] | 328 | else if (cfg.rc_end_usage == VPX_CQ) |
| 329 | { |
Adrian Grange | 217591f | 2011-10-06 15:49:11 -0700 | [diff] [blame] | 330 | oxcf->end_usage = USAGE_CONSTRAINED_QUALITY; |
Paul Wilkins | e0846c9 | 2011-01-07 18:29:37 +0000 | [diff] [blame] | 331 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 332 | |
Adrian Grange | 217591f | 2011-10-06 15:49:11 -0700 | [diff] [blame] | 333 | oxcf->target_bandwidth = cfg.rc_target_bitrate; |
John Koleszar | 1654ae9 | 2011-07-28 09:17:32 -0400 | [diff] [blame] | 334 | oxcf->rc_max_intra_bitrate_pct = vp8_cfg.rc_max_intra_bitrate_pct; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 335 | |
Adrian Grange | 217591f | 2011-10-06 15:49:11 -0700 | [diff] [blame] | 336 | oxcf->best_allowed_q = cfg.rc_min_quantizer; |
| 337 | oxcf->worst_allowed_q = cfg.rc_max_quantizer; |
| 338 | oxcf->cq_level = vp8_cfg.cq_level; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 339 | oxcf->fixed_q = -1; |
| 340 | |
Adrian Grange | 217591f | 2011-10-06 15:49:11 -0700 | [diff] [blame] | 341 | oxcf->under_shoot_pct = cfg.rc_undershoot_pct; |
| 342 | oxcf->over_shoot_pct = cfg.rc_overshoot_pct; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 343 | |
Adrian Grange | e479379 | 2012-01-13 14:09:40 -0800 | [diff] [blame] | 344 | oxcf->maximum_buffer_size_in_ms = cfg.rc_buf_sz; |
| 345 | oxcf->starting_buffer_level_in_ms = cfg.rc_buf_initial_sz; |
| 346 | oxcf->optimal_buffer_level_in_ms = cfg.rc_buf_optimal_sz; |
| 347 | |
Adrian Grange | 217591f | 2011-10-06 15:49:11 -0700 | [diff] [blame] | 348 | oxcf->maximum_buffer_size = cfg.rc_buf_sz; |
| 349 | oxcf->starting_buffer_level = cfg.rc_buf_initial_sz; |
| 350 | oxcf->optimal_buffer_level = cfg.rc_buf_optimal_sz; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 351 | |
Adrian Grange | 217591f | 2011-10-06 15:49:11 -0700 | [diff] [blame] | 352 | oxcf->two_pass_vbrbias = cfg.rc_2pass_vbr_bias_pct; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 353 | oxcf->two_pass_vbrmin_section = cfg.rc_2pass_vbr_minsection_pct; |
| 354 | oxcf->two_pass_vbrmax_section = cfg.rc_2pass_vbr_maxsection_pct; |
| 355 | |
Adrian Grange | 217591f | 2011-10-06 15:49:11 -0700 | [diff] [blame] | 356 | oxcf->auto_key = cfg.kf_mode == VPX_KF_AUTO |
| 357 | && cfg.kf_min_dist != cfg.kf_max_dist; |
Adrian Grange | 217591f | 2011-10-06 15:49:11 -0700 | [diff] [blame] | 358 | oxcf->key_freq = cfg.kf_max_dist; |
| 359 | |
| 360 | oxcf->number_of_layers = cfg.ts_number_layers; |
| 361 | oxcf->periodicity = cfg.ts_periodicity; |
| 362 | |
| 363 | if (oxcf->number_of_layers > 1) |
| 364 | { |
| 365 | memcpy (oxcf->target_bitrate, cfg.ts_target_bitrate, |
| 366 | sizeof(cfg.ts_target_bitrate)); |
| 367 | memcpy (oxcf->rate_decimator, cfg.ts_rate_decimator, |
| 368 | sizeof(cfg.ts_rate_decimator)); |
| 369 | memcpy (oxcf->layer_id, cfg.ts_layer_id, sizeof(cfg.ts_layer_id)); |
| 370 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 371 | |
Yunqing Wang | aa7335e | 2011-10-25 15:14:16 -0400 | [diff] [blame] | 372 | #if CONFIG_MULTI_RES_ENCODING |
Yunqing Wang | c647ec4 | 2011-12-16 16:50:29 -0500 | [diff] [blame] | 373 | /* When mr_cfg is NULL, oxcf->mr_total_resolutions and oxcf->mr_encoder_id |
| 374 | * are both memset to 0, which ensures the correct logic under this |
| 375 | * situation. |
| 376 | */ |
Yunqing Wang | aa7335e | 2011-10-25 15:14:16 -0400 | [diff] [blame] | 377 | if(mr_cfg) |
| 378 | { |
| 379 | oxcf->mr_total_resolutions = mr_cfg->mr_total_resolutions; |
| 380 | oxcf->mr_encoder_id = mr_cfg->mr_encoder_id; |
| 381 | oxcf->mr_down_sampling_factor.num = mr_cfg->mr_down_sampling_factor.num; |
| 382 | oxcf->mr_down_sampling_factor.den = mr_cfg->mr_down_sampling_factor.den; |
| 383 | oxcf->mr_low_res_mode_info = mr_cfg->mr_low_res_mode_info; |
| 384 | } |
| 385 | #endif |
| 386 | |
Adrian Grange | 217591f | 2011-10-06 15:49:11 -0700 | [diff] [blame] | 387 | oxcf->cpu_used = vp8_cfg.cpu_used; |
| 388 | oxcf->encode_breakout = vp8_cfg.static_thresh; |
| 389 | oxcf->play_alternate = vp8_cfg.enable_auto_alt_ref; |
| 390 | oxcf->noise_sensitivity = vp8_cfg.noise_sensitivity; |
| 391 | oxcf->Sharpness = vp8_cfg.Sharpness; |
| 392 | oxcf->token_partitions = vp8_cfg.token_partitions; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 393 | |
Adrian Grange | 217591f | 2011-10-06 15:49:11 -0700 | [diff] [blame] | 394 | oxcf->two_pass_stats_in = cfg.rc_twopass_stats_in; |
| 395 | oxcf->output_pkt_list = vp8_cfg.pkt_list; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 396 | |
Adrian Grange | 217591f | 2011-10-06 15:49:11 -0700 | [diff] [blame] | 397 | oxcf->arnr_max_frames = vp8_cfg.arnr_max_frames; |
| 398 | oxcf->arnr_strength = vp8_cfg.arnr_strength; |
| 399 | oxcf->arnr_type = vp8_cfg.arnr_type; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 400 | |
Adrian Grange | 217591f | 2011-10-06 15:49:11 -0700 | [diff] [blame] | 401 | oxcf->tuning = vp8_cfg.tuning; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 402 | |
| 403 | /* |
| 404 | printf("Current VP8 Settings: \n"); |
| 405 | printf("target_bandwidth: %d\n", oxcf->target_bandwidth); |
| 406 | printf("noise_sensitivity: %d\n", oxcf->noise_sensitivity); |
| 407 | printf("Sharpness: %d\n", oxcf->Sharpness); |
| 408 | printf("cpu_used: %d\n", oxcf->cpu_used); |
| 409 | printf("Mode: %d\n", oxcf->Mode); |
| 410 | printf("delete_first_pass_file: %d\n", oxcf->delete_first_pass_file); |
| 411 | printf("auto_key: %d\n", oxcf->auto_key); |
| 412 | printf("key_freq: %d\n", oxcf->key_freq); |
| 413 | printf("end_usage: %d\n", oxcf->end_usage); |
| 414 | printf("under_shoot_pct: %d\n", oxcf->under_shoot_pct); |
John Koleszar | c99f9d7 | 2011-04-11 11:29:23 -0400 | [diff] [blame] | 415 | printf("over_shoot_pct: %d\n", oxcf->over_shoot_pct); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 416 | printf("starting_buffer_level: %d\n", oxcf->starting_buffer_level); |
| 417 | printf("optimal_buffer_level: %d\n", oxcf->optimal_buffer_level); |
| 418 | printf("maximum_buffer_size: %d\n", oxcf->maximum_buffer_size); |
| 419 | printf("fixed_q: %d\n", oxcf->fixed_q); |
| 420 | printf("worst_allowed_q: %d\n", oxcf->worst_allowed_q); |
| 421 | printf("best_allowed_q: %d\n", oxcf->best_allowed_q); |
| 422 | printf("allow_spatial_resampling: %d\n", oxcf->allow_spatial_resampling); |
| 423 | printf("resample_down_water_mark: %d\n", oxcf->resample_down_water_mark); |
| 424 | printf("resample_up_water_mark: %d\n", oxcf->resample_up_water_mark); |
| 425 | printf("allow_df: %d\n", oxcf->allow_df); |
| 426 | printf("drop_frames_water_mark: %d\n", oxcf->drop_frames_water_mark); |
| 427 | printf("two_pass_vbrbias: %d\n", oxcf->two_pass_vbrbias); |
| 428 | printf("two_pass_vbrmin_section: %d\n", oxcf->two_pass_vbrmin_section); |
| 429 | printf("two_pass_vbrmax_section: %d\n", oxcf->two_pass_vbrmax_section); |
| 430 | printf("allow_lag: %d\n", oxcf->allow_lag); |
| 431 | printf("lag_in_frames: %d\n", oxcf->lag_in_frames); |
| 432 | printf("play_alternate: %d\n", oxcf->play_alternate); |
| 433 | printf("Version: %d\n", oxcf->Version); |
| 434 | printf("multi_threaded: %d\n", oxcf->multi_threaded); |
| 435 | printf("encode_breakout: %d\n", oxcf->encode_breakout); |
| 436 | */ |
| 437 | return VPX_CODEC_OK; |
| 438 | } |
| 439 | |
| 440 | static vpx_codec_err_t vp8e_set_config(vpx_codec_alg_priv_t *ctx, |
| 441 | const vpx_codec_enc_cfg_t *cfg) |
| 442 | { |
| 443 | vpx_codec_err_t res; |
| 444 | |
John Koleszar | 51acb01 | 2012-02-07 17:07:49 -0800 | [diff] [blame] | 445 | if (((cfg->g_w != ctx->cfg.g_w) || (cfg->g_h != ctx->cfg.g_h)) |
John Koleszar | 410ae57 | 2012-05-23 12:07:53 -0700 | [diff] [blame] | 446 | && (cfg->g_lag_in_frames > 1 || cfg->g_pass != VPX_RC_ONE_PASS)) |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 447 | ERROR("Cannot change width or height after initialization"); |
| 448 | |
| 449 | /* Prevent increasing lag_in_frames. This check is stricter than it needs |
| 450 | * to be -- the limit is not increasing past the first lag_in_frames |
| 451 | * value, but we don't track the initial config, only the last successful |
| 452 | * config. |
| 453 | */ |
| 454 | if ((cfg->g_lag_in_frames > ctx->cfg.g_lag_in_frames)) |
| 455 | ERROR("Cannot increase lag_in_frames"); |
| 456 | |
James Berry | c1c47e8 | 2011-12-07 15:48:00 -0500 | [diff] [blame] | 457 | res = validate_config(ctx, cfg, &ctx->vp8_cfg, 0); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 458 | |
| 459 | if (!res) |
| 460 | { |
| 461 | ctx->cfg = *cfg; |
Yunqing Wang | aa7335e | 2011-10-25 15:14:16 -0400 | [diff] [blame] | 462 | set_vp8e_config(&ctx->oxcf, ctx->cfg, ctx->vp8_cfg, NULL); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 463 | vp8_change_config(ctx->cpi, &ctx->oxcf); |
| 464 | } |
| 465 | |
| 466 | return res; |
| 467 | } |
| 468 | |
| 469 | |
| 470 | int vp8_reverse_trans(int); |
| 471 | |
| 472 | |
| 473 | static vpx_codec_err_t get_param(vpx_codec_alg_priv_t *ctx, |
| 474 | int ctrl_id, |
| 475 | va_list args) |
| 476 | { |
| 477 | void *arg = va_arg(args, void *); |
| 478 | |
| 479 | #define MAP(id, var) case id: *(RECAST(id, arg)) = var; break |
| 480 | |
| 481 | if (!arg) |
| 482 | return VPX_CODEC_INVALID_PARAM; |
| 483 | |
| 484 | switch (ctrl_id) |
| 485 | { |
| 486 | MAP(VP8E_GET_LAST_QUANTIZER, vp8_get_quantizer(ctx->cpi)); |
| 487 | MAP(VP8E_GET_LAST_QUANTIZER_64, vp8_reverse_trans(vp8_get_quantizer(ctx->cpi))); |
| 488 | } |
| 489 | |
| 490 | return VPX_CODEC_OK; |
| 491 | #undef MAP |
| 492 | } |
| 493 | |
| 494 | |
| 495 | static vpx_codec_err_t set_param(vpx_codec_alg_priv_t *ctx, |
| 496 | int ctrl_id, |
| 497 | va_list args) |
| 498 | { |
| 499 | vpx_codec_err_t res = VPX_CODEC_OK; |
| 500 | struct vp8_extracfg xcfg = ctx->vp8_cfg; |
| 501 | |
| 502 | #define MAP(id, var) case id: var = CAST(id, args); break; |
| 503 | |
| 504 | switch (ctrl_id) |
| 505 | { |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 506 | MAP(VP8E_SET_CPUUSED, xcfg.cpu_used); |
| 507 | MAP(VP8E_SET_ENABLEAUTOALTREF, xcfg.enable_auto_alt_ref); |
| 508 | MAP(VP8E_SET_NOISE_SENSITIVITY, xcfg.noise_sensitivity); |
| 509 | MAP(VP8E_SET_SHARPNESS, xcfg.Sharpness); |
| 510 | MAP(VP8E_SET_STATIC_THRESHOLD, xcfg.static_thresh); |
| 511 | MAP(VP8E_SET_TOKEN_PARTITIONS, xcfg.token_partitions); |
| 512 | |
| 513 | MAP(VP8E_SET_ARNR_MAXFRAMES, xcfg.arnr_max_frames); |
| 514 | MAP(VP8E_SET_ARNR_STRENGTH , xcfg.arnr_strength); |
| 515 | MAP(VP8E_SET_ARNR_TYPE , xcfg.arnr_type); |
John Koleszar | b0da9b3 | 2010-12-17 09:43:39 -0500 | [diff] [blame] | 516 | MAP(VP8E_SET_TUNING, xcfg.tuning); |
Paul Wilkins | e0846c9 | 2011-01-07 18:29:37 +0000 | [diff] [blame] | 517 | MAP(VP8E_SET_CQ_LEVEL, xcfg.cq_level); |
John Koleszar | 1654ae9 | 2011-07-28 09:17:32 -0400 | [diff] [blame] | 518 | MAP(VP8E_SET_MAX_INTRA_BITRATE_PCT, xcfg.rc_max_intra_bitrate_pct); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 519 | |
| 520 | } |
| 521 | |
James Berry | c1c47e8 | 2011-12-07 15:48:00 -0500 | [diff] [blame] | 522 | res = validate_config(ctx, &ctx->cfg, &xcfg, 0); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 523 | |
| 524 | if (!res) |
| 525 | { |
| 526 | ctx->vp8_cfg = xcfg; |
Yunqing Wang | aa7335e | 2011-10-25 15:14:16 -0400 | [diff] [blame] | 527 | set_vp8e_config(&ctx->oxcf, ctx->cfg, ctx->vp8_cfg, NULL); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 528 | vp8_change_config(ctx->cpi, &ctx->oxcf); |
| 529 | } |
| 530 | |
| 531 | return res; |
| 532 | #undef MAP |
| 533 | } |
Yunqing Wang | aa7335e | 2011-10-25 15:14:16 -0400 | [diff] [blame] | 534 | |
| 535 | static vpx_codec_err_t vp8e_mr_alloc_mem(const vpx_codec_enc_cfg_t *cfg, |
| 536 | void **mem_loc) |
| 537 | { |
Yunqing Wang | ad479a9 | 2012-05-23 13:40:24 -0400 | [diff] [blame] | 538 | vpx_codec_err_t res = 0; |
| 539 | |
Yunqing Wang | aa7335e | 2011-10-25 15:14:16 -0400 | [diff] [blame] | 540 | #if CONFIG_MULTI_RES_ENCODING |
Yunqing Wang | 65dd157 | 2012-05-16 15:06:42 -0400 | [diff] [blame] | 541 | LOWER_RES_FRAME_INFO *shared_mem_loc; |
Yunqing Wang | aa7335e | 2011-10-25 15:14:16 -0400 | [diff] [blame] | 542 | int mb_rows = ((cfg->g_w + 15) >>4); |
| 543 | int mb_cols = ((cfg->g_h + 15) >>4); |
| 544 | |
Yunqing Wang | 65dd157 | 2012-05-16 15:06:42 -0400 | [diff] [blame] | 545 | shared_mem_loc = calloc(1, sizeof(LOWER_RES_FRAME_INFO)); |
| 546 | if(!shared_mem_loc) |
Yunqing Wang | aa7335e | 2011-10-25 15:14:16 -0400 | [diff] [blame] | 547 | { |
Yunqing Wang | ad479a9 | 2012-05-23 13:40:24 -0400 | [diff] [blame] | 548 | res = VPX_CODEC_MEM_ERROR; |
Yunqing Wang | 65dd157 | 2012-05-16 15:06:42 -0400 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | shared_mem_loc->mb_info = calloc(mb_rows*mb_cols, sizeof(LOWER_RES_MB_INFO)); |
| 552 | if(!(shared_mem_loc->mb_info)) |
| 553 | { |
Yunqing Wang | ad479a9 | 2012-05-23 13:40:24 -0400 | [diff] [blame] | 554 | res = VPX_CODEC_MEM_ERROR; |
Yunqing Wang | aa7335e | 2011-10-25 15:14:16 -0400 | [diff] [blame] | 555 | } |
| 556 | else |
Yunqing Wang | 65dd157 | 2012-05-16 15:06:42 -0400 | [diff] [blame] | 557 | { |
| 558 | *mem_loc = (void *)shared_mem_loc; |
Yunqing Wang | ad479a9 | 2012-05-23 13:40:24 -0400 | [diff] [blame] | 559 | res = VPX_CODEC_OK; |
Yunqing Wang | 65dd157 | 2012-05-16 15:06:42 -0400 | [diff] [blame] | 560 | } |
Yunqing Wang | aa7335e | 2011-10-25 15:14:16 -0400 | [diff] [blame] | 561 | #endif |
Yunqing Wang | ad479a9 | 2012-05-23 13:40:24 -0400 | [diff] [blame] | 562 | return res; |
Yunqing Wang | aa7335e | 2011-10-25 15:14:16 -0400 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | static vpx_codec_err_t vp8e_init(vpx_codec_ctx_t *ctx, |
| 566 | vpx_codec_priv_enc_mr_cfg_t *mr_cfg) |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 567 | { |
John Koleszar | 2bf8fb5 | 2012-05-02 16:37:37 -0700 | [diff] [blame] | 568 | vpx_codec_err_t res = VPX_CODEC_OK; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 569 | struct vpx_codec_alg_priv *priv; |
| 570 | vpx_codec_enc_cfg_t *cfg; |
| 571 | unsigned int i; |
| 572 | |
John Koleszar | b0056c3 | 2011-12-20 16:54:54 -0800 | [diff] [blame] | 573 | struct VP8_COMP *optr; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 574 | |
| 575 | if (!ctx->priv) |
| 576 | { |
| 577 | priv = calloc(1, sizeof(struct vpx_codec_alg_priv)); |
| 578 | |
Attila Nagy | e6db21e | 2011-02-22 15:02:05 +0200 | [diff] [blame] | 579 | if (!priv) |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 580 | { |
Attila Nagy | e6db21e | 2011-02-22 15:02:05 +0200 | [diff] [blame] | 581 | return VPX_CODEC_MEM_ERROR; |
| 582 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 583 | |
Attila Nagy | e6db21e | 2011-02-22 15:02:05 +0200 | [diff] [blame] | 584 | ctx->priv = &priv->base; |
| 585 | ctx->priv->sz = sizeof(*ctx->priv); |
| 586 | ctx->priv->iface = ctx->iface; |
| 587 | ctx->priv->alg_priv = priv; |
| 588 | ctx->priv->init_flags = ctx->init_flags; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 589 | |
Attila Nagy | e6db21e | 2011-02-22 15:02:05 +0200 | [diff] [blame] | 590 | if (ctx->config.enc) |
| 591 | { |
| 592 | /* Update the reference to the config structure to an |
| 593 | * internal copy. |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 594 | */ |
Attila Nagy | e6db21e | 2011-02-22 15:02:05 +0200 | [diff] [blame] | 595 | ctx->priv->alg_priv->cfg = *ctx->config.enc; |
| 596 | ctx->config.enc = &ctx->priv->alg_priv->cfg; |
| 597 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 598 | |
Attila Nagy | e6db21e | 2011-02-22 15:02:05 +0200 | [diff] [blame] | 599 | cfg = &ctx->priv->alg_priv->cfg; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 600 | |
Adrian Grange | 217591f | 2011-10-06 15:49:11 -0700 | [diff] [blame] | 601 | /* Select the extra vp8 configuration table based on the current |
Attila Nagy | e6db21e | 2011-02-22 15:02:05 +0200 | [diff] [blame] | 602 | * usage value. If the current usage value isn't found, use the |
| 603 | * values for usage case 0. |
| 604 | */ |
| 605 | for (i = 0; |
| 606 | extracfg_map[i].usage && extracfg_map[i].usage != cfg->g_usage; |
| 607 | i++); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 608 | |
Attila Nagy | e6db21e | 2011-02-22 15:02:05 +0200 | [diff] [blame] | 609 | priv->vp8_cfg = extracfg_map[i].cfg; |
| 610 | priv->vp8_cfg.pkt_list = &priv->pkt_list.head; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 611 | |
Attila Nagy | e6db21e | 2011-02-22 15:02:05 +0200 | [diff] [blame] | 612 | priv->cx_data_sz = priv->cfg.g_w * priv->cfg.g_h * 3 / 2 * 2; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 613 | |
James Berry | bac6c22 | 2011-10-24 11:50:27 -0400 | [diff] [blame] | 614 | if (priv->cx_data_sz < 32768) priv->cx_data_sz = 32768; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 615 | |
Attila Nagy | e6db21e | 2011-02-22 15:02:05 +0200 | [diff] [blame] | 616 | priv->cx_data = malloc(priv->cx_data_sz); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 617 | |
Attila Nagy | e6db21e | 2011-02-22 15:02:05 +0200 | [diff] [blame] | 618 | if (!priv->cx_data) |
| 619 | { |
| 620 | return VPX_CODEC_MEM_ERROR; |
| 621 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 622 | |
James Berry | c1c47e8 | 2011-12-07 15:48:00 -0500 | [diff] [blame] | 623 | res = validate_config(priv, &priv->cfg, &priv->vp8_cfg, 0); |
Attila Nagy | e6db21e | 2011-02-22 15:02:05 +0200 | [diff] [blame] | 624 | |
| 625 | if (!res) |
| 626 | { |
Yunqing Wang | aa7335e | 2011-10-25 15:14:16 -0400 | [diff] [blame] | 627 | if(mr_cfg) |
| 628 | ctx->priv->enc.total_encoders = mr_cfg->mr_total_resolutions; |
| 629 | else |
| 630 | ctx->priv->enc.total_encoders = 1; |
| 631 | |
Attila Nagy | e6db21e | 2011-02-22 15:02:05 +0200 | [diff] [blame] | 632 | set_vp8e_config(&ctx->priv->alg_priv->oxcf, |
| 633 | ctx->priv->alg_priv->cfg, |
Yunqing Wang | aa7335e | 2011-10-25 15:14:16 -0400 | [diff] [blame] | 634 | ctx->priv->alg_priv->vp8_cfg, |
| 635 | mr_cfg); |
| 636 | |
Attila Nagy | e6db21e | 2011-02-22 15:02:05 +0200 | [diff] [blame] | 637 | optr = vp8_create_compressor(&ctx->priv->alg_priv->oxcf); |
| 638 | |
| 639 | if (!optr) |
| 640 | res = VPX_CODEC_MEM_ERROR; |
| 641 | else |
| 642 | ctx->priv->alg_priv->cpi = optr; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 643 | } |
| 644 | } |
| 645 | |
| 646 | return res; |
| 647 | } |
| 648 | |
| 649 | static vpx_codec_err_t vp8e_destroy(vpx_codec_alg_priv_t *ctx) |
| 650 | { |
Yunqing Wang | aa7335e | 2011-10-25 15:14:16 -0400 | [diff] [blame] | 651 | #if CONFIG_MULTI_RES_ENCODING |
| 652 | /* Free multi-encoder shared memory */ |
| 653 | if (ctx->oxcf.mr_total_resolutions > 0 && (ctx->oxcf.mr_encoder_id == ctx->oxcf.mr_total_resolutions-1)) |
Yunqing Wang | 65dd157 | 2012-05-16 15:06:42 -0400 | [diff] [blame] | 654 | { |
| 655 | LOWER_RES_FRAME_INFO *shared_mem_loc = (LOWER_RES_FRAME_INFO *)ctx->oxcf.mr_low_res_mode_info; |
| 656 | free(shared_mem_loc->mb_info); |
Yunqing Wang | aa7335e | 2011-10-25 15:14:16 -0400 | [diff] [blame] | 657 | free(ctx->oxcf.mr_low_res_mode_info); |
Yunqing Wang | 65dd157 | 2012-05-16 15:06:42 -0400 | [diff] [blame] | 658 | } |
Yunqing Wang | aa7335e | 2011-10-25 15:14:16 -0400 | [diff] [blame] | 659 | #endif |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 660 | |
| 661 | free(ctx->cx_data); |
| 662 | vp8_remove_compressor(&ctx->cpi); |
| 663 | free(ctx); |
| 664 | return VPX_CODEC_OK; |
| 665 | } |
| 666 | |
| 667 | static vpx_codec_err_t image2yuvconfig(const vpx_image_t *img, |
| 668 | YV12_BUFFER_CONFIG *yv12) |
| 669 | { |
| 670 | vpx_codec_err_t res = VPX_CODEC_OK; |
John Koleszar | b6c7191 | 2010-05-24 21:45:05 -0400 | [diff] [blame] | 671 | yv12->y_buffer = img->planes[VPX_PLANE_Y]; |
| 672 | yv12->u_buffer = img->planes[VPX_PLANE_U]; |
| 673 | yv12->v_buffer = img->planes[VPX_PLANE_V]; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 674 | |
| 675 | yv12->y_width = img->d_w; |
| 676 | yv12->y_height = img->d_h; |
| 677 | yv12->uv_width = (1 + yv12->y_width) / 2; |
| 678 | yv12->uv_height = (1 + yv12->y_height) / 2; |
| 679 | |
John Koleszar | b6c7191 | 2010-05-24 21:45:05 -0400 | [diff] [blame] | 680 | yv12->y_stride = img->stride[VPX_PLANE_Y]; |
| 681 | yv12->uv_stride = img->stride[VPX_PLANE_U]; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 682 | |
John Koleszar | b6c7191 | 2010-05-24 21:45:05 -0400 | [diff] [blame] | 683 | yv12->border = (img->stride[VPX_PLANE_Y] - img->w) / 2; |
John Koleszar | 0164a1c | 2012-05-21 14:30:56 -0700 | [diff] [blame] | 684 | yv12->clrtype = (img->fmt == VPX_IMG_FMT_VPXI420 || img->fmt == VPX_IMG_FMT_VPXYV12); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 685 | return res; |
| 686 | } |
| 687 | |
| 688 | static void pick_quickcompress_mode(vpx_codec_alg_priv_t *ctx, |
| 689 | unsigned long duration, |
| 690 | unsigned long deadline) |
| 691 | { |
| 692 | unsigned int new_qc; |
| 693 | |
| 694 | #if !(CONFIG_REALTIME_ONLY) |
| 695 | /* Use best quality mode if no deadline is given. */ |
| 696 | new_qc = MODE_BESTQUALITY; |
| 697 | |
| 698 | if (deadline) |
| 699 | { |
| 700 | uint64_t duration_us; |
| 701 | |
| 702 | /* Convert duration parameter from stream timebase to microseconds */ |
| 703 | duration_us = (uint64_t)duration * 1000000 |
| 704 | * (uint64_t)ctx->cfg.g_timebase.num |
| 705 | / (uint64_t)ctx->cfg.g_timebase.den; |
| 706 | |
| 707 | /* If the deadline is more that the duration this frame is to be shown, |
| 708 | * use good quality mode. Otherwise use realtime mode. |
| 709 | */ |
| 710 | new_qc = (deadline > duration_us) ? MODE_GOODQUALITY : MODE_REALTIME; |
| 711 | } |
| 712 | |
| 713 | #else |
| 714 | new_qc = MODE_REALTIME; |
| 715 | #endif |
| 716 | |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 717 | if (ctx->cfg.g_pass == VPX_RC_FIRST_PASS) |
| 718 | new_qc = MODE_FIRSTPASS; |
| 719 | else if (ctx->cfg.g_pass == VPX_RC_LAST_PASS) |
| 720 | new_qc = (new_qc == MODE_BESTQUALITY) |
| 721 | ? MODE_SECONDPASS_BEST |
| 722 | : MODE_SECONDPASS; |
| 723 | |
| 724 | if (ctx->oxcf.Mode != new_qc) |
| 725 | { |
| 726 | ctx->oxcf.Mode = new_qc; |
| 727 | vp8_change_config(ctx->cpi, &ctx->oxcf); |
| 728 | } |
| 729 | } |
| 730 | |
| 731 | |
| 732 | static vpx_codec_err_t vp8e_encode(vpx_codec_alg_priv_t *ctx, |
| 733 | const vpx_image_t *img, |
| 734 | vpx_codec_pts_t pts, |
| 735 | unsigned long duration, |
| 736 | vpx_enc_frame_flags_t flags, |
| 737 | unsigned long deadline) |
| 738 | { |
| 739 | vpx_codec_err_t res = VPX_CODEC_OK; |
| 740 | |
John Koleszar | 25a36d6 | 2012-04-19 10:00:33 -0700 | [diff] [blame] | 741 | if (!ctx->cfg.rc_target_bitrate) |
| 742 | return res; |
| 743 | |
John Koleszar | 44d35f7 | 2012-05-11 10:51:05 -0700 | [diff] [blame] | 744 | if (!ctx->cfg.rc_target_bitrate) |
| 745 | return res; |
| 746 | |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 747 | if (img) |
| 748 | res = validate_img(ctx, img); |
| 749 | |
James Berry | c1c47e8 | 2011-12-07 15:48:00 -0500 | [diff] [blame] | 750 | if (!res) |
| 751 | res = validate_config(ctx, &ctx->cfg, &ctx->vp8_cfg, 1); |
| 752 | |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 753 | pick_quickcompress_mode(ctx, duration, deadline); |
| 754 | vpx_codec_pkt_list_init(&ctx->pkt_list); |
| 755 | |
| 756 | /* Handle Flags */ |
| 757 | if (((flags & VP8_EFLAG_NO_UPD_GF) && (flags & VP8_EFLAG_FORCE_GF)) |
| 758 | || ((flags & VP8_EFLAG_NO_UPD_ARF) && (flags & VP8_EFLAG_FORCE_ARF))) |
| 759 | { |
| 760 | ctx->base.err_detail = "Conflicting flags."; |
| 761 | return VPX_CODEC_INVALID_PARAM; |
| 762 | } |
| 763 | |
| 764 | if (flags & (VP8_EFLAG_NO_REF_LAST | VP8_EFLAG_NO_REF_GF |
| 765 | | VP8_EFLAG_NO_REF_ARF)) |
| 766 | { |
| 767 | int ref = 7; |
| 768 | |
| 769 | if (flags & VP8_EFLAG_NO_REF_LAST) |
Johann | 965d868 | 2012-05-23 16:08:37 -0700 | [diff] [blame] | 770 | ref ^= VP8_LAST_FRAME; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 771 | |
| 772 | if (flags & VP8_EFLAG_NO_REF_GF) |
Johann | 965d868 | 2012-05-23 16:08:37 -0700 | [diff] [blame] | 773 | ref ^= VP8_GOLD_FRAME; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 774 | |
| 775 | if (flags & VP8_EFLAG_NO_REF_ARF) |
Johann | 965d868 | 2012-05-23 16:08:37 -0700 | [diff] [blame] | 776 | ref ^= VP8_ALTR_FRAME; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 777 | |
| 778 | vp8_use_as_reference(ctx->cpi, ref); |
| 779 | } |
| 780 | |
| 781 | if (flags & (VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF |
| 782 | | VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_FORCE_GF |
| 783 | | VP8_EFLAG_FORCE_ARF)) |
| 784 | { |
| 785 | int upd = 7; |
| 786 | |
| 787 | if (flags & VP8_EFLAG_NO_UPD_LAST) |
Johann | 965d868 | 2012-05-23 16:08:37 -0700 | [diff] [blame] | 788 | upd ^= VP8_LAST_FRAME; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 789 | |
| 790 | if (flags & VP8_EFLAG_NO_UPD_GF) |
Johann | 965d868 | 2012-05-23 16:08:37 -0700 | [diff] [blame] | 791 | upd ^= VP8_GOLD_FRAME; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 792 | |
| 793 | if (flags & VP8_EFLAG_NO_UPD_ARF) |
Johann | 965d868 | 2012-05-23 16:08:37 -0700 | [diff] [blame] | 794 | upd ^= VP8_ALTR_FRAME; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 795 | |
| 796 | vp8_update_reference(ctx->cpi, upd); |
| 797 | } |
| 798 | |
| 799 | if (flags & VP8_EFLAG_NO_UPD_ENTROPY) |
| 800 | { |
| 801 | vp8_update_entropy(ctx->cpi, 0); |
| 802 | } |
| 803 | |
| 804 | /* Handle fixed keyframe intervals */ |
| 805 | if (ctx->cfg.kf_mode == VPX_KF_AUTO |
| 806 | && ctx->cfg.kf_min_dist == ctx->cfg.kf_max_dist) |
| 807 | { |
| 808 | if (++ctx->fixed_kf_cntr > ctx->cfg.kf_min_dist) |
| 809 | { |
| 810 | flags |= VPX_EFLAG_FORCE_KF; |
Andoni Morales Alastruey | 4814016 | 2011-02-07 18:04:02 +0100 | [diff] [blame] | 811 | ctx->fixed_kf_cntr = 1; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 812 | } |
| 813 | } |
| 814 | |
| 815 | /* Initialize the encoder instance on the first frame*/ |
| 816 | if (!res && ctx->cpi) |
| 817 | { |
| 818 | unsigned int lib_flags; |
| 819 | YV12_BUFFER_CONFIG sd; |
James Zern | b45065d | 2011-07-25 18:44:59 -0700 | [diff] [blame] | 820 | int64_t dst_time_stamp, dst_end_time_stamp; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 821 | unsigned long size, cx_data_sz; |
| 822 | unsigned char *cx_data; |
James Berry | bc71511 | 2011-10-12 11:18:50 -0400 | [diff] [blame] | 823 | unsigned char *cx_data_end; |
| 824 | int comp_data_state = 0; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 825 | |
| 826 | /* Set up internal flags */ |
| 827 | if (ctx->base.init_flags & VPX_CODEC_USE_PSNR) |
| 828 | ((VP8_COMP *)ctx->cpi)->b_calculate_psnr = 1; |
| 829 | |
Stefan Holmer | 7296b3f | 2011-06-13 16:42:27 +0200 | [diff] [blame] | 830 | if (ctx->base.init_flags & VPX_CODEC_USE_OUTPUT_PARTITION) |
| 831 | ((VP8_COMP *)ctx->cpi)->output_partition = 1; |
| 832 | |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 833 | /* Convert API flags to internal codec lib flags */ |
| 834 | lib_flags = (flags & VPX_EFLAG_FORCE_KF) ? FRAMEFLAGS_KEY : 0; |
| 835 | |
| 836 | /* vp8 use 10,000,000 ticks/second as time stamp */ |
| 837 | dst_time_stamp = pts * 10000000 * ctx->cfg.g_timebase.num / ctx->cfg.g_timebase.den; |
| 838 | dst_end_time_stamp = (pts + duration) * 10000000 * ctx->cfg.g_timebase.num / ctx->cfg.g_timebase.den; |
| 839 | |
| 840 | if (img != NULL) |
| 841 | { |
| 842 | res = image2yuvconfig(img, &sd); |
| 843 | |
| 844 | if (vp8_receive_raw_frame(ctx->cpi, ctx->next_frame_flag | lib_flags, |
| 845 | &sd, dst_time_stamp, dst_end_time_stamp)) |
| 846 | { |
| 847 | VP8_COMP *cpi = (VP8_COMP *)ctx->cpi; |
| 848 | res = update_error_state(ctx, &cpi->common.error); |
| 849 | } |
| 850 | |
| 851 | /* reset for next frame */ |
| 852 | ctx->next_frame_flag = 0; |
| 853 | } |
| 854 | |
| 855 | cx_data = ctx->cx_data; |
| 856 | cx_data_sz = ctx->cx_data_sz; |
James Berry | bc71511 | 2011-10-12 11:18:50 -0400 | [diff] [blame] | 857 | cx_data_end = ctx->cx_data + cx_data_sz; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 858 | lib_flags = 0; |
| 859 | |
James Berry | bc71511 | 2011-10-12 11:18:50 -0400 | [diff] [blame] | 860 | while (cx_data_sz >= ctx->cx_data_sz / 2) |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 861 | { |
James Berry | bc71511 | 2011-10-12 11:18:50 -0400 | [diff] [blame] | 862 | comp_data_state = vp8_get_compressed_data(ctx->cpi, |
| 863 | &lib_flags, |
| 864 | &size, |
| 865 | cx_data, |
| 866 | cx_data_end, |
| 867 | &dst_time_stamp, |
| 868 | &dst_end_time_stamp, |
| 869 | !img); |
| 870 | |
| 871 | if(comp_data_state == VPX_CODEC_CORRUPT_FRAME) |
| 872 | return VPX_CODEC_CORRUPT_FRAME; |
| 873 | else if(comp_data_state == -1) |
| 874 | break; |
| 875 | |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 876 | if (size) |
| 877 | { |
| 878 | vpx_codec_pts_t round, delta; |
| 879 | vpx_codec_cx_pkt_t pkt; |
| 880 | VP8_COMP *cpi = (VP8_COMP *)ctx->cpi; |
| 881 | |
| 882 | /* Add the frame packet to the list of returned packets. */ |
| 883 | round = 1000000 * ctx->cfg.g_timebase.num / 2 - 1; |
| 884 | delta = (dst_end_time_stamp - dst_time_stamp); |
| 885 | pkt.kind = VPX_CODEC_CX_FRAME_PKT; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 886 | pkt.data.frame.pts = |
| 887 | (dst_time_stamp * ctx->cfg.g_timebase.den + round) |
| 888 | / ctx->cfg.g_timebase.num / 10000000; |
| 889 | pkt.data.frame.duration = |
| 890 | (delta * ctx->cfg.g_timebase.den + round) |
| 891 | / ctx->cfg.g_timebase.num / 10000000; |
| 892 | pkt.data.frame.flags = lib_flags << 16; |
| 893 | |
| 894 | if (lib_flags & FRAMEFLAGS_KEY) |
| 895 | pkt.data.frame.flags |= VPX_FRAME_IS_KEY; |
| 896 | |
| 897 | if (!cpi->common.show_frame) |
| 898 | { |
| 899 | pkt.data.frame.flags |= VPX_FRAME_IS_INVISIBLE; |
| 900 | |
John Koleszar | 0164a1c | 2012-05-21 14:30:56 -0700 | [diff] [blame] | 901 | /* This timestamp should be as close as possible to the |
| 902 | * prior PTS so that if a decoder uses pts to schedule when |
| 903 | * to do this, we start right after last frame was decoded. |
| 904 | * Invisible frames have no duration. |
| 905 | */ |
Frank Galligan | 45e6494 | 2010-10-05 17:46:37 -0400 | [diff] [blame] | 906 | pkt.data.frame.pts = ((cpi->last_time_stamp_seen |
| 907 | * ctx->cfg.g_timebase.den + round) |
| 908 | / ctx->cfg.g_timebase.num / 10000000) + 1; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 909 | pkt.data.frame.duration = 0; |
| 910 | } |
| 911 | |
John Koleszar | 37de0b8 | 2011-07-07 10:38:23 -0400 | [diff] [blame] | 912 | if (cpi->droppable) |
| 913 | pkt.data.frame.flags |= VPX_FRAME_IS_DROPPABLE; |
| 914 | |
Stefan Holmer | 7296b3f | 2011-06-13 16:42:27 +0200 | [diff] [blame] | 915 | if (cpi->output_partition) |
| 916 | { |
| 917 | int i; |
| 918 | const int num_partitions = |
| 919 | (1 << cpi->common.multi_token_partition) + 1; |
Attila Nagy | 0afcc76 | 2011-07-20 14:09:42 +0300 | [diff] [blame] | 920 | |
| 921 | pkt.data.frame.flags |= VPX_FRAME_IS_FRAGMENT; |
| 922 | |
Stefan Holmer | 7296b3f | 2011-06-13 16:42:27 +0200 | [diff] [blame] | 923 | for (i = 0; i < num_partitions; ++i) |
| 924 | { |
Attila Nagy | 52cf4dc | 2012-02-09 12:37:03 +0200 | [diff] [blame] | 925 | #if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING |
| 926 | pkt.data.frame.buf = cpi->partition_d[i]; |
| 927 | #else |
Stefan Holmer | 7296b3f | 2011-06-13 16:42:27 +0200 | [diff] [blame] | 928 | pkt.data.frame.buf = cx_data; |
Attila Nagy | 52cf4dc | 2012-02-09 12:37:03 +0200 | [diff] [blame] | 929 | cx_data += cpi->partition_sz[i]; |
| 930 | cx_data_sz -= cpi->partition_sz[i]; |
| 931 | #endif |
Stefan Holmer | 7296b3f | 2011-06-13 16:42:27 +0200 | [diff] [blame] | 932 | pkt.data.frame.sz = cpi->partition_sz[i]; |
| 933 | pkt.data.frame.partition_id = i; |
| 934 | /* don't set the fragment bit for the last partition */ |
Attila Nagy | 0afcc76 | 2011-07-20 14:09:42 +0300 | [diff] [blame] | 935 | if (i == (num_partitions - 1)) |
| 936 | pkt.data.frame.flags &= ~VPX_FRAME_IS_FRAGMENT; |
Stefan Holmer | 7296b3f | 2011-06-13 16:42:27 +0200 | [diff] [blame] | 937 | vpx_codec_pkt_list_add(&ctx->pkt_list.head, &pkt); |
Stefan Holmer | 7296b3f | 2011-06-13 16:42:27 +0200 | [diff] [blame] | 938 | } |
Attila Nagy | 52cf4dc | 2012-02-09 12:37:03 +0200 | [diff] [blame] | 939 | #if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING |
| 940 | /* In lagged mode the encoder can buffer multiple frames. |
| 941 | * We don't want this in partitioned output because |
| 942 | * partitions are spread all over the output buffer. |
| 943 | * So, force an exit! |
| 944 | */ |
| 945 | cx_data_sz -= ctx->cx_data_sz / 2; |
| 946 | #endif |
Stefan Holmer | 7296b3f | 2011-06-13 16:42:27 +0200 | [diff] [blame] | 947 | } |
| 948 | else |
| 949 | { |
| 950 | pkt.data.frame.buf = cx_data; |
| 951 | pkt.data.frame.sz = size; |
| 952 | pkt.data.frame.partition_id = -1; |
| 953 | vpx_codec_pkt_list_add(&ctx->pkt_list.head, &pkt); |
| 954 | cx_data += size; |
| 955 | cx_data_sz -= size; |
| 956 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 957 | } |
| 958 | } |
| 959 | } |
| 960 | |
| 961 | return res; |
| 962 | } |
| 963 | |
| 964 | |
| 965 | static const vpx_codec_cx_pkt_t *vp8e_get_cxdata(vpx_codec_alg_priv_t *ctx, |
| 966 | vpx_codec_iter_t *iter) |
| 967 | { |
| 968 | return vpx_codec_pkt_list_get(&ctx->pkt_list.head, iter); |
| 969 | } |
| 970 | |
| 971 | static vpx_codec_err_t vp8e_set_reference(vpx_codec_alg_priv_t *ctx, |
| 972 | int ctr_id, |
| 973 | va_list args) |
| 974 | { |
| 975 | vpx_ref_frame_t *data = va_arg(args, vpx_ref_frame_t *); |
| 976 | |
| 977 | if (data) |
| 978 | { |
| 979 | vpx_ref_frame_t *frame = (vpx_ref_frame_t *)data; |
| 980 | YV12_BUFFER_CONFIG sd; |
| 981 | |
| 982 | image2yuvconfig(&frame->img, &sd); |
| 983 | vp8_set_reference(ctx->cpi, frame->frame_type, &sd); |
| 984 | return VPX_CODEC_OK; |
| 985 | } |
| 986 | else |
| 987 | return VPX_CODEC_INVALID_PARAM; |
| 988 | |
| 989 | } |
| 990 | |
| 991 | static vpx_codec_err_t vp8e_get_reference(vpx_codec_alg_priv_t *ctx, |
| 992 | int ctr_id, |
| 993 | va_list args) |
| 994 | { |
| 995 | |
| 996 | vpx_ref_frame_t *data = va_arg(args, vpx_ref_frame_t *); |
| 997 | |
| 998 | if (data) |
| 999 | { |
| 1000 | vpx_ref_frame_t *frame = (vpx_ref_frame_t *)data; |
| 1001 | YV12_BUFFER_CONFIG sd; |
| 1002 | |
| 1003 | image2yuvconfig(&frame->img, &sd); |
| 1004 | vp8_get_reference(ctx->cpi, frame->frame_type, &sd); |
| 1005 | return VPX_CODEC_OK; |
| 1006 | } |
| 1007 | else |
| 1008 | return VPX_CODEC_INVALID_PARAM; |
| 1009 | } |
| 1010 | |
| 1011 | static vpx_codec_err_t vp8e_set_previewpp(vpx_codec_alg_priv_t *ctx, |
| 1012 | int ctr_id, |
| 1013 | va_list args) |
| 1014 | { |
James Zern | 76640f8 | 2010-08-20 16:06:56 -0400 | [diff] [blame] | 1015 | #if CONFIG_POSTPROC |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1016 | vp8_postproc_cfg_t *data = va_arg(args, vp8_postproc_cfg_t *); |
James Zern | 76640f8 | 2010-08-20 16:06:56 -0400 | [diff] [blame] | 1017 | (void)ctr_id; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1018 | |
| 1019 | if (data) |
| 1020 | { |
| 1021 | ctx->preview_ppcfg = *((vp8_postproc_cfg_t *)data); |
| 1022 | return VPX_CODEC_OK; |
| 1023 | } |
| 1024 | else |
| 1025 | return VPX_CODEC_INVALID_PARAM; |
James Zern | 76640f8 | 2010-08-20 16:06:56 -0400 | [diff] [blame] | 1026 | #else |
| 1027 | (void)ctx; |
| 1028 | (void)ctr_id; |
| 1029 | (void)args; |
| 1030 | return VPX_CODEC_INCAPABLE; |
| 1031 | #endif |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | |
| 1035 | static vpx_image_t *vp8e_get_preview(vpx_codec_alg_priv_t *ctx) |
| 1036 | { |
| 1037 | |
| 1038 | YV12_BUFFER_CONFIG sd; |
Fritz Koenig | 647df00 | 2010-11-04 16:03:36 -0700 | [diff] [blame] | 1039 | vp8_ppflags_t flags = {0}; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1040 | |
Fritz Koenig | 647df00 | 2010-11-04 16:03:36 -0700 | [diff] [blame] | 1041 | if (ctx->preview_ppcfg.post_proc_flag) |
| 1042 | { |
| 1043 | flags.post_proc_flag = ctx->preview_ppcfg.post_proc_flag; |
| 1044 | flags.deblocking_level = ctx->preview_ppcfg.deblocking_level; |
| 1045 | flags.noise_level = ctx->preview_ppcfg.noise_level; |
| 1046 | } |
| 1047 | |
| 1048 | if (0 == vp8_get_preview_raw_frame(ctx->cpi, &sd, &flags)) |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1049 | { |
| 1050 | |
| 1051 | /* |
James Zern | 6cd4a10 | 2010-05-20 23:22:39 -0400 | [diff] [blame] | 1052 | vpx_img_wrap(&ctx->preview_img, VPX_IMG_FMT_YV12, |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1053 | sd.y_width + 2*VP8BORDERINPIXELS, |
| 1054 | sd.y_height + 2*VP8BORDERINPIXELS, |
| 1055 | 1, |
| 1056 | sd.buffer_alloc); |
| 1057 | vpx_img_set_rect(&ctx->preview_img, |
| 1058 | VP8BORDERINPIXELS, VP8BORDERINPIXELS, |
| 1059 | sd.y_width, sd.y_height); |
| 1060 | */ |
| 1061 | |
| 1062 | ctx->preview_img.bps = 12; |
John Koleszar | b6c7191 | 2010-05-24 21:45:05 -0400 | [diff] [blame] | 1063 | ctx->preview_img.planes[VPX_PLANE_Y] = sd.y_buffer; |
| 1064 | ctx->preview_img.planes[VPX_PLANE_U] = sd.u_buffer; |
| 1065 | ctx->preview_img.planes[VPX_PLANE_V] = sd.v_buffer; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1066 | |
| 1067 | if (sd.clrtype == REG_YUV) |
James Zern | 6cd4a10 | 2010-05-20 23:22:39 -0400 | [diff] [blame] | 1068 | ctx->preview_img.fmt = VPX_IMG_FMT_I420; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1069 | else |
James Zern | 6cd4a10 | 2010-05-20 23:22:39 -0400 | [diff] [blame] | 1070 | ctx->preview_img.fmt = VPX_IMG_FMT_VPXI420; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1071 | |
| 1072 | ctx->preview_img.x_chroma_shift = 1; |
| 1073 | ctx->preview_img.y_chroma_shift = 1; |
| 1074 | |
James Berry | ddacf1c | 2011-02-08 14:23:18 -0500 | [diff] [blame] | 1075 | ctx->preview_img.d_w = sd.y_width; |
| 1076 | ctx->preview_img.d_h = sd.y_height; |
John Koleszar | b6c7191 | 2010-05-24 21:45:05 -0400 | [diff] [blame] | 1077 | ctx->preview_img.stride[VPX_PLANE_Y] = sd.y_stride; |
| 1078 | ctx->preview_img.stride[VPX_PLANE_U] = sd.uv_stride; |
| 1079 | ctx->preview_img.stride[VPX_PLANE_V] = sd.uv_stride; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1080 | ctx->preview_img.w = sd.y_width; |
| 1081 | ctx->preview_img.h = sd.y_height; |
| 1082 | |
| 1083 | return &ctx->preview_img; |
| 1084 | } |
| 1085 | else |
| 1086 | return NULL; |
| 1087 | } |
| 1088 | |
| 1089 | static vpx_codec_err_t vp8e_update_entropy(vpx_codec_alg_priv_t *ctx, |
| 1090 | int ctr_id, |
| 1091 | va_list args) |
| 1092 | { |
| 1093 | int update = va_arg(args, int); |
| 1094 | vp8_update_entropy(ctx->cpi, update); |
| 1095 | return VPX_CODEC_OK; |
| 1096 | |
| 1097 | } |
| 1098 | |
| 1099 | static vpx_codec_err_t vp8e_update_reference(vpx_codec_alg_priv_t *ctx, |
| 1100 | int ctr_id, |
| 1101 | va_list args) |
| 1102 | { |
| 1103 | int update = va_arg(args, int); |
| 1104 | vp8_update_reference(ctx->cpi, update); |
| 1105 | return VPX_CODEC_OK; |
| 1106 | } |
| 1107 | |
| 1108 | static vpx_codec_err_t vp8e_use_reference(vpx_codec_alg_priv_t *ctx, |
| 1109 | int ctr_id, |
| 1110 | va_list args) |
| 1111 | { |
| 1112 | int reference_flag = va_arg(args, int); |
| 1113 | vp8_use_as_reference(ctx->cpi, reference_flag); |
| 1114 | return VPX_CODEC_OK; |
| 1115 | } |
| 1116 | |
| 1117 | static vpx_codec_err_t vp8e_set_roi_map(vpx_codec_alg_priv_t *ctx, |
| 1118 | int ctr_id, |
| 1119 | va_list args) |
| 1120 | { |
| 1121 | vpx_roi_map_t *data = va_arg(args, vpx_roi_map_t *); |
| 1122 | |
| 1123 | if (data) |
| 1124 | { |
| 1125 | vpx_roi_map_t *roi = (vpx_roi_map_t *)data; |
| 1126 | |
| 1127 | if (!vp8_set_roimap(ctx->cpi, roi->roi_map, roi->rows, roi->cols, roi->delta_q, roi->delta_lf, roi->static_threshold)) |
| 1128 | return VPX_CODEC_OK; |
| 1129 | else |
| 1130 | return VPX_CODEC_INVALID_PARAM; |
| 1131 | } |
| 1132 | else |
| 1133 | return VPX_CODEC_INVALID_PARAM; |
| 1134 | } |
| 1135 | |
| 1136 | |
| 1137 | static vpx_codec_err_t vp8e_set_activemap(vpx_codec_alg_priv_t *ctx, |
| 1138 | int ctr_id, |
| 1139 | va_list args) |
| 1140 | { |
| 1141 | vpx_active_map_t *data = va_arg(args, vpx_active_map_t *); |
| 1142 | |
| 1143 | if (data) |
| 1144 | { |
| 1145 | |
| 1146 | vpx_active_map_t *map = (vpx_active_map_t *)data; |
| 1147 | |
| 1148 | if (!vp8_set_active_map(ctx->cpi, map->active_map, map->rows, map->cols)) |
| 1149 | return VPX_CODEC_OK; |
| 1150 | else |
| 1151 | return VPX_CODEC_INVALID_PARAM; |
| 1152 | } |
| 1153 | else |
| 1154 | return VPX_CODEC_INVALID_PARAM; |
| 1155 | } |
| 1156 | |
| 1157 | static vpx_codec_err_t vp8e_set_scalemode(vpx_codec_alg_priv_t *ctx, |
| 1158 | int ctr_id, |
| 1159 | va_list args) |
| 1160 | { |
| 1161 | |
| 1162 | vpx_scaling_mode_t *data = va_arg(args, vpx_scaling_mode_t *); |
| 1163 | |
| 1164 | if (data) |
| 1165 | { |
| 1166 | int res; |
| 1167 | vpx_scaling_mode_t scalemode = *(vpx_scaling_mode_t *)data ; |
| 1168 | res = vp8_set_internal_size(ctx->cpi, scalemode.h_scaling_mode, scalemode.v_scaling_mode); |
| 1169 | |
| 1170 | if (!res) |
| 1171 | { |
| 1172 | /*force next frame a key frame to effect scaling mode */ |
| 1173 | ctx->next_frame_flag |= FRAMEFLAGS_KEY; |
| 1174 | return VPX_CODEC_OK; |
| 1175 | } |
| 1176 | else |
| 1177 | return VPX_CODEC_INVALID_PARAM; |
| 1178 | } |
| 1179 | else |
| 1180 | return VPX_CODEC_INVALID_PARAM; |
| 1181 | } |
| 1182 | |
| 1183 | |
| 1184 | static vpx_codec_ctrl_fn_map_t vp8e_ctf_maps[] = |
| 1185 | { |
| 1186 | {VP8_SET_REFERENCE, vp8e_set_reference}, |
| 1187 | {VP8_COPY_REFERENCE, vp8e_get_reference}, |
| 1188 | {VP8_SET_POSTPROC, vp8e_set_previewpp}, |
| 1189 | {VP8E_UPD_ENTROPY, vp8e_update_entropy}, |
| 1190 | {VP8E_UPD_REFERENCE, vp8e_update_reference}, |
| 1191 | {VP8E_USE_REFERENCE, vp8e_use_reference}, |
| 1192 | {VP8E_SET_ROI_MAP, vp8e_set_roi_map}, |
| 1193 | {VP8E_SET_ACTIVEMAP, vp8e_set_activemap}, |
| 1194 | {VP8E_SET_SCALEMODE, vp8e_set_scalemode}, |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1195 | {VP8E_SET_CPUUSED, set_param}, |
| 1196 | {VP8E_SET_NOISE_SENSITIVITY, set_param}, |
| 1197 | {VP8E_SET_ENABLEAUTOALTREF, set_param}, |
| 1198 | {VP8E_SET_SHARPNESS, set_param}, |
| 1199 | {VP8E_SET_STATIC_THRESHOLD, set_param}, |
| 1200 | {VP8E_SET_TOKEN_PARTITIONS, set_param}, |
| 1201 | {VP8E_GET_LAST_QUANTIZER, get_param}, |
| 1202 | {VP8E_GET_LAST_QUANTIZER_64, get_param}, |
| 1203 | {VP8E_SET_ARNR_MAXFRAMES, set_param}, |
| 1204 | {VP8E_SET_ARNR_STRENGTH , set_param}, |
| 1205 | {VP8E_SET_ARNR_TYPE , set_param}, |
John Koleszar | b0da9b3 | 2010-12-17 09:43:39 -0500 | [diff] [blame] | 1206 | {VP8E_SET_TUNING, set_param}, |
Paul Wilkins | e0846c9 | 2011-01-07 18:29:37 +0000 | [diff] [blame] | 1207 | {VP8E_SET_CQ_LEVEL, set_param}, |
John Koleszar | 1654ae9 | 2011-07-28 09:17:32 -0400 | [diff] [blame] | 1208 | {VP8E_SET_MAX_INTRA_BITRATE_PCT, set_param}, |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1209 | { -1, NULL}, |
| 1210 | }; |
| 1211 | |
| 1212 | static vpx_codec_enc_cfg_map_t vp8e_usage_cfg_map[] = |
| 1213 | { |
| 1214 | { |
| 1215 | 0, |
| 1216 | { |
| 1217 | 0, /* g_usage */ |
| 1218 | 0, /* g_threads */ |
| 1219 | 0, /* g_profile */ |
| 1220 | |
| 1221 | 320, /* g_width */ |
| 1222 | 240, /* g_height */ |
| 1223 | {1, 30}, /* g_timebase */ |
| 1224 | |
| 1225 | 0, /* g_error_resilient */ |
| 1226 | |
| 1227 | VPX_RC_ONE_PASS, /* g_pass */ |
| 1228 | |
| 1229 | 0, /* g_lag_in_frames */ |
| 1230 | |
John Koleszar | 2321621 | 2010-09-02 09:32:03 -0400 | [diff] [blame] | 1231 | 0, /* rc_dropframe_thresh */ |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1232 | 0, /* rc_resize_allowed */ |
| 1233 | 60, /* rc_resize_down_thresold */ |
| 1234 | 30, /* rc_resize_up_thresold */ |
| 1235 | |
| 1236 | VPX_VBR, /* rc_end_usage */ |
| 1237 | #if VPX_ENCODER_ABI_VERSION > (1 + VPX_CODEC_ABI_VERSION) |
| 1238 | {0}, /* rc_twopass_stats_in */ |
| 1239 | #endif |
| 1240 | 256, /* rc_target_bandwidth */ |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1241 | 4, /* rc_min_quantizer */ |
| 1242 | 63, /* rc_max_quantizer */ |
John Koleszar | c99f9d7 | 2011-04-11 11:29:23 -0400 | [diff] [blame] | 1243 | 100, /* rc_undershoot_pct */ |
| 1244 | 100, /* rc_overshoot_pct */ |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1245 | |
| 1246 | 6000, /* rc_max_buffer_size */ |
| 1247 | 4000, /* rc_buffer_initial_size; */ |
| 1248 | 5000, /* rc_buffer_optimal_size; */ |
| 1249 | |
| 1250 | 50, /* rc_two_pass_vbrbias */ |
| 1251 | 0, /* rc_two_pass_vbrmin_section */ |
| 1252 | 400, /* rc_two_pass_vbrmax_section */ |
| 1253 | |
| 1254 | /* keyframing settings (kf) */ |
| 1255 | VPX_KF_AUTO, /* g_kfmode*/ |
| 1256 | 0, /* kf_min_dist */ |
Ralph Giles | 2a0d7b1 | 2012-01-05 10:39:38 -0600 | [diff] [blame] | 1257 | 128, /* kf_max_dist */ |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1258 | |
| 1259 | #if VPX_ENCODER_ABI_VERSION == (1 + VPX_CODEC_ABI_VERSION) |
| 1260 | 1, /* g_delete_first_pass_file */ |
| 1261 | "vp8.fpf" /* first pass filename */ |
| 1262 | #endif |
Adrian Grange | 217591f | 2011-10-06 15:49:11 -0700 | [diff] [blame] | 1263 | |
| 1264 | 1, /* ts_number_layers */ |
| 1265 | {0}, /* ts_target_bitrate */ |
| 1266 | {0}, /* ts_rate_decimator */ |
| 1267 | 0, /* ts_periodicity */ |
| 1268 | {0}, /* ts_layer_id */ |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1269 | }}, |
| 1270 | { -1, {NOT_IMPLEMENTED}} |
| 1271 | }; |
| 1272 | |
| 1273 | |
| 1274 | #ifndef VERSION_STRING |
| 1275 | #define VERSION_STRING |
| 1276 | #endif |
John Koleszar | fa7a55b | 2010-09-21 10:35:52 -0400 | [diff] [blame] | 1277 | CODEC_INTERFACE(vpx_codec_vp8_cx) = |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1278 | { |
John Koleszar | 317a666 | 2010-06-10 12:08:01 -0400 | [diff] [blame] | 1279 | "WebM Project VP8 Encoder" VERSION_STRING, |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1280 | VPX_CODEC_INTERNAL_ABI_VERSION, |
Stefan Holmer | 7296b3f | 2011-06-13 16:42:27 +0200 | [diff] [blame] | 1281 | VPX_CODEC_CAP_ENCODER | VPX_CODEC_CAP_PSNR | |
| 1282 | VPX_CODEC_CAP_OUTPUT_PARTITION, |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1283 | /* vpx_codec_caps_t caps; */ |
| 1284 | vp8e_init, /* vpx_codec_init_fn_t init; */ |
| 1285 | vp8e_destroy, /* vpx_codec_destroy_fn_t destroy; */ |
| 1286 | vp8e_ctf_maps, /* vpx_codec_ctrl_fn_map_t *ctrl_maps; */ |
| 1287 | NOT_IMPLEMENTED, /* vpx_codec_get_mmap_fn_t get_mmap; */ |
| 1288 | NOT_IMPLEMENTED, /* vpx_codec_set_mmap_fn_t set_mmap; */ |
| 1289 | { |
| 1290 | NOT_IMPLEMENTED, /* vpx_codec_peek_si_fn_t peek_si; */ |
| 1291 | NOT_IMPLEMENTED, /* vpx_codec_get_si_fn_t get_si; */ |
| 1292 | NOT_IMPLEMENTED, /* vpx_codec_decode_fn_t decode; */ |
| 1293 | NOT_IMPLEMENTED, /* vpx_codec_frame_get_fn_t frame_get; */ |
| 1294 | }, |
| 1295 | { |
| 1296 | vp8e_usage_cfg_map, /* vpx_codec_enc_cfg_map_t peek_si; */ |
| 1297 | vp8e_encode, /* vpx_codec_encode_fn_t encode; */ |
| 1298 | vp8e_get_cxdata, /* vpx_codec_get_cx_data_fn_t frame_get; */ |
| 1299 | vp8e_set_config, |
| 1300 | NOT_IMPLEMENTED, |
| 1301 | vp8e_get_preview, |
Yunqing Wang | aa7335e | 2011-10-25 15:14:16 -0400 | [diff] [blame] | 1302 | vp8e_mr_alloc_mem, |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1303 | } /* encoder functions */ |
| 1304 | }; |