blob: 5fb74c45e1face167f843ff406e5944eef42482e [file] [log] [blame]
John Koleszar0ea50ce2010-05-18 11:58:33 -04001/*
John Koleszarc2140b82010-09-09 08:16:39 -04002 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
John Koleszar0ea50ce2010-05-18 11:58:33 -04003 *
John Koleszar94c52e42010-06-18 12:39:21 -04004 * Use of this source code is governed by a BSD-style license
John Koleszar09202d82010-06-04 16:19:40 -04005 * 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 Koleszar94c52e42010-06-18 12:39:21 -04007 * in the file PATENTS. All contributing project authors may
John Koleszar09202d82010-06-04 16:19:40 -04008 * be found in the AUTHORS file in the root of the source tree.
John Koleszar0ea50ce2010-05-18 11:58:33 -04009 */
10
11
John Koleszarb7492342010-05-24 11:39:59 -040012#include "vpx/vpx_codec.h"
13#include "vpx/internal/vpx_codec_internal.h"
John Koleszar0ea50ce2010-05-18 11:58:33 -040014#include "vpx_version.h"
John Koleszar02321de2011-02-10 14:41:38 -050015#include "vp8/encoder/onyx_int.h"
John Koleszar2bf8fb52012-05-02 16:37:37 -070016#include "vpx/vp8cx.h"
John Koleszarbb7dd5b2010-10-14 16:40:12 -040017#include "vp8/encoder/firstpass.h"
John Koleszar02321de2011-02-10 14:41:38 -050018#include "vp8/common/onyx.h"
John Koleszar0ea50ce2010-05-18 11:58:33 -040019#include <stdlib.h>
20#include <string.h>
21
John Koleszar0ea50ce2010-05-18 11:58:33 -040022struct 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 Koleszarb0da9b32010-12-17 09:43:39 -050035 vp8e_tuning tuning;
Paul Wilkinse0846c92011-01-07 18:29:37 +000036 unsigned int cq_level; /* constrained quality level */
John Koleszar1654ae92011-07-28 09:17:32 -040037 unsigned int rc_max_intra_bitrate_pct;
John Koleszar0ea50ce2010-05-18 11:58:33 -040038
39};
40
41struct extraconfig_map
42{
43 int usage;
44 struct vp8_extracfg cfg;
45};
46
47static 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 Koleszar89c8b3d2010-06-14 10:22:55 -040055 0, /* cpu_used */
John Koleszar0ea50ce2010-05-18 11:58:33 -040056#else
57 VP8_REAL_TIME_ENCODING, /* Encoding Mode */
John Koleszar89c8b3d2010-06-14 10:22:55 -040058 4, /* cpu_used */
John Koleszar0ea50ce2010-05-18 11:58:33 -040059#endif
60 0, /* enable_auto_alt_ref */
61 0, /* noise_sensitivity */
62 0, /* Sharpness */
John Koleszar89c8b3d2010-06-14 10:22:55 -040063 0, /* static_thresh */
Attila Nagy52cf4dc2012-02-09 12:37:03 +020064#if (CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING)
65 VP8_EIGHT_TOKENPARTITION,
66#else
John Koleszar0ea50ce2010-05-18 11:58:33 -040067 VP8_ONE_TOKENPARTITION, /* token_partitions */
Attila Nagy52cf4dc2012-02-09 12:37:03 +020068#endif
Adrian Grange8ee72842010-09-30 10:06:09 +010069 0, /* arnr_max_frames */
70 3, /* arnr_strength */
71 3, /* arnr_type*/
John Koleszarb0da9b32010-12-17 09:43:39 -050072 0, /* tuning*/
Paul Wilkinse0846c92011-01-07 18:29:37 +000073 10, /* cq_level */
John Koleszar1654ae92011-07-28 09:17:32 -040074 0, /* rc_max_intra_bitrate_pct */
John Koleszar0ea50ce2010-05-18 11:58:33 -040075 }
76 }
77};
78
79struct 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 Koleszarb0056c32011-12-20 16:54:54 -080085 struct VP8_COMP *cpi;
John Koleszar0ea50ce2010-05-18 11:58:33 -040086 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;
Yaowu Xu8caa5c22010-05-27 10:04:36 -070091 vpx_codec_pkt_list_decl(64) pkt_list; // changed to accomendate the maximum number of lagged frames allowed
John Koleszar0ea50ce2010-05-18 11:58:33 -040092 unsigned int fixed_kf_cntr;
93};
94
95
96static vpx_codec_err_t
97update_error_state(vpx_codec_alg_priv_t *ctx,
98 const struct vpx_internal_error_info *error)
99{
100 vpx_codec_err_t res;
101
102 if ((res = error->error_code))
103 ctx->base.err_detail = error->has_detail
104 ? error->detail
105 : NULL;
106
107 return res;
108}
109
110
John Koleszar79e2b1f2010-11-17 09:08:47 -0500111#undef ERROR
John Koleszar0ea50ce2010-05-18 11:58:33 -0400112#define ERROR(str) do {\
113 ctx->base.err_detail = str;\
114 return VPX_CODEC_INVALID_PARAM;\
115 } while(0)
116
117#define RANGE_CHECK(p,memb,lo,hi) do {\
Guillermo Ballester Valor5a726202010-06-11 14:33:49 -0400118 if(!(((p)->memb == lo || (p)->memb > (lo)) && (p)->memb <= hi)) \
John Koleszar0ea50ce2010-05-18 11:58:33 -0400119 ERROR(#memb " out of range ["#lo".."#hi"]");\
120 } while(0)
121
Guillermo Ballester Valor23690682010-06-11 14:33:49 -0400122#define RANGE_CHECK_HI(p,memb,hi) do {\
123 if(!((p)->memb <= (hi))) \
124 ERROR(#memb " out of range [.."#hi"]");\
125 } while(0)
126
John Koleszar0ea50ce2010-05-18 11:58:33 -0400127#define RANGE_CHECK_LO(p,memb,lo) do {\
128 if(!((p)->memb >= (lo))) \
129 ERROR(#memb " out of range ["#lo"..]");\
130 } while(0)
131
132#define RANGE_CHECK_BOOL(p,memb) do {\
133 if(!!((p)->memb) != (p)->memb) ERROR(#memb " expected boolean");\
134 } while(0)
135
136static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx,
137 const vpx_codec_enc_cfg_t *cfg,
James Berryc1c47e82011-12-07 15:48:00 -0500138 const struct vp8_extracfg *vp8_cfg,
139 int finalize)
John Koleszar0ea50ce2010-05-18 11:58:33 -0400140{
Attila Nagy1aadced2011-04-12 15:01:22 +0300141 RANGE_CHECK(cfg, g_w, 1, 16383); /* 14 bits available */
142 RANGE_CHECK(cfg, g_h, 1, 16383); /* 14 bits available */
John Koleszar0ea50ce2010-05-18 11:58:33 -0400143 RANGE_CHECK(cfg, g_timebase.den, 1, 1000000000);
144 RANGE_CHECK(cfg, g_timebase.num, 1, cfg->g_timebase.den);
Guillermo Ballester Valor23690682010-06-11 14:33:49 -0400145 RANGE_CHECK_HI(cfg, g_profile, 3);
Guillermo Ballester Valor23690682010-06-11 14:33:49 -0400146 RANGE_CHECK_HI(cfg, rc_max_quantizer, 63);
John Koleszar2d03f072011-01-28 11:56:18 -0500147 RANGE_CHECK_HI(cfg, rc_min_quantizer, cfg->rc_max_quantizer);
Guillermo Ballester Valor23690682010-06-11 14:33:49 -0400148 RANGE_CHECK_HI(cfg, g_threads, 64);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400149#if !(CONFIG_REALTIME_ONLY)
Guillermo Ballester Valor23690682010-06-11 14:33:49 -0400150 RANGE_CHECK_HI(cfg, g_lag_in_frames, 25);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400151#else
Guillermo Ballester Valor23690682010-06-11 14:33:49 -0400152 RANGE_CHECK_HI(cfg, g_lag_in_frames, 0);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400153#endif
Paul Wilkinse0846c92011-01-07 18:29:37 +0000154 RANGE_CHECK(cfg, rc_end_usage, VPX_VBR, VPX_CQ);
John Koleszarc99f9d72011-04-11 11:29:23 -0400155 RANGE_CHECK_HI(cfg, rc_undershoot_pct, 1000);
156 RANGE_CHECK_HI(cfg, rc_overshoot_pct, 1000);
Guillermo Ballester Valor23690682010-06-11 14:33:49 -0400157 RANGE_CHECK_HI(cfg, rc_2pass_vbr_bias_pct, 100);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400158 RANGE_CHECK(cfg, kf_mode, VPX_KF_DISABLED, VPX_KF_AUTO);
159 //RANGE_CHECK_BOOL(cfg, g_delete_firstpassfile);
160 RANGE_CHECK_BOOL(cfg, rc_resize_allowed);
Guillermo Ballester Valor23690682010-06-11 14:33:49 -0400161 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 Koleszar0ea50ce2010-05-18 11:58:33 -0400164#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 Wang4fd81a92011-04-11 15:55:04 -0400179 RANGE_CHECK(vp8_cfg, cpu_used, -16, 16);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400180#if !(CONFIG_REALTIME_ONLY)
181 RANGE_CHECK(vp8_cfg, encoding_mode, VP8_BEST_QUALITY_ENCODING, VP8_REAL_TIME_ENCODING);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400182#else
183 RANGE_CHECK(vp8_cfg, encoding_mode, VP8_REAL_TIME_ENCODING, VP8_REAL_TIME_ENCODING);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400184#endif
John Koleszarc8f4c182012-05-08 11:23:42 -0700185
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 Holmer9c411432012-03-06 10:48:18 +0100190#endif
John Koleszar0ea50ce2010-05-18 11:58:33 -0400191
192 RANGE_CHECK(vp8_cfg, token_partitions, VP8_ONE_TOKENPARTITION, VP8_EIGHT_TOKENPARTITION);
Guillermo Ballester Valor23690682010-06-11 14:33:49 -0400193 RANGE_CHECK_HI(vp8_cfg, Sharpness, 7);
Adrian Grange8ee72842010-09-30 10:06:09 +0100194 RANGE_CHECK(vp8_cfg, arnr_max_frames, 0, 15);
Frank Galligan15542722010-10-04 21:12:22 -0400195 RANGE_CHECK_HI(vp8_cfg, arnr_strength, 6);
Adrian Grange8ee72842010-09-30 10:06:09 +0100196 RANGE_CHECK(vp8_cfg, arnr_type, 1, 3);
Paul Wilkinse0846c92011-01-07 18:29:37 +0000197 RANGE_CHECK(vp8_cfg, cq_level, 0, 63);
James Berryc1c47e82011-12-07 15:48:00 -0500198 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 Koleszar0ea50ce2010-05-18 11:58:33 -0400201
Attila Nagycb791aa2011-01-10 11:14:10 +0200202#if !(CONFIG_REALTIME_ONLY)
John Koleszar0ea50ce2010-05-18 11:58:33 -0400203 if (cfg->g_pass == VPX_RC_LAST_PASS)
204 {
Adrian Grangeed40ff92011-03-10 11:32:48 -0800205 size_t packet_sz = sizeof(FIRSTPASS_STATS);
John Koleszarbb7dd5b2010-10-14 16:40:12 -0400206 int n_packets = cfg->rc_twopass_stats_in.sz / packet_sz;
207 FIRSTPASS_STATS *stats;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400208
209 if (!cfg->rc_twopass_stats_in.buf)
210 ERROR("rc_twopass_stats_in.buf not set.");
211
John Koleszarbb7dd5b2010-10-14 16:40:12 -0400212 if (cfg->rc_twopass_stats_in.sz % packet_sz)
John Koleszar0ea50ce2010-05-18 11:58:33 -0400213 ERROR("rc_twopass_stats_in.sz indicates truncated packet.");
214
John Koleszarbb7dd5b2010-10-14 16:40:12 -0400215 if (cfg->rc_twopass_stats_in.sz < 2 * packet_sz)
John Koleszar0ea50ce2010-05-18 11:58:33 -0400216 ERROR("rc_twopass_stats_in requires at least two packets.");
217
John Koleszarbb7dd5b2010-10-14 16:40:12 -0400218 stats = (void*)((char *)cfg->rc_twopass_stats_in.buf
219 + (n_packets - 1) * packet_sz);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400220
John Koleszarbb7dd5b2010-10-14 16:40:12 -0400221 if ((int)(stats->count + 0.5) != n_packets - 1)
John Koleszar0ea50ce2010-05-18 11:58:33 -0400222 ERROR("rc_twopass_stats_in missing EOS stats packet");
223 }
Attila Nagycb791aa2011-01-10 11:14:10 +0200224#endif
John Koleszar0ea50ce2010-05-18 11:58:33 -0400225
Adrian Grange217591f2011-10-06 15:49:11 -0700226 RANGE_CHECK(cfg, ts_number_layers, 1, 5);
227
228 if (cfg->ts_number_layers > 1)
229 {
230 int i;
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 Nagy52cf4dc2012-02-09 12:37:03 +0200245#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 Koleszar0ea50ce2010-05-18 11:58:33 -0400250 return VPX_CODEC_OK;
251}
252
253
254static 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 Zern6cd4a102010-05-20 23:22:39 -0400259 case VPX_IMG_FMT_YV12:
260 case VPX_IMG_FMT_I420:
261 case VPX_IMG_FMT_VPXI420:
262 case VPX_IMG_FMT_VPXYV12:
John Koleszar0ea50ce2010-05-18 11:58:33 -0400263 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
275static vpx_codec_err_t set_vp8e_config(VP8_CONFIG *oxcf,
276 vpx_codec_enc_cfg_t cfg,
Yunqing Wangaa7335e2011-10-25 15:14:16 -0400277 struct vp8_extracfg vp8_cfg,
278 vpx_codec_priv_enc_mr_cfg_t *mr_cfg)
John Koleszar0ea50ce2010-05-18 11:58:33 -0400279{
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 Koleszarbdd35c12011-11-11 10:47:20 -0800285 oxcf->timebase = cfg.g_timebase;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400286
Adrian Grange217591f2011-10-06 15:49:11 -0700287 oxcf->error_resilient_mode = cfg.g_error_resilient;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400288
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
302 if (cfg.g_pass == VPX_RC_FIRST_PASS)
303 {
Adrian Grange217591f2011-10-06 15:49:11 -0700304 oxcf->allow_lag = 0;
305 oxcf->lag_in_frames = 0;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400306 }
307 else
308 {
Adrian Grange217591f2011-10-06 15:49:11 -0700309 oxcf->allow_lag = (cfg.g_lag_in_frames) > 0;
310 oxcf->lag_in_frames = cfg.g_lag_in_frames;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400311 }
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 Grange217591f2011-10-06 15:49:11 -0700322 oxcf->end_usage = USAGE_LOCAL_FILE_PLAYBACK;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400323 }
324 else if (cfg.rc_end_usage == VPX_CBR)
325 {
Adrian Grange217591f2011-10-06 15:49:11 -0700326 oxcf->end_usage = USAGE_STREAM_FROM_SERVER;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400327 }
Paul Wilkinse0846c92011-01-07 18:29:37 +0000328 else if (cfg.rc_end_usage == VPX_CQ)
329 {
Adrian Grange217591f2011-10-06 15:49:11 -0700330 oxcf->end_usage = USAGE_CONSTRAINED_QUALITY;
Paul Wilkinse0846c92011-01-07 18:29:37 +0000331 }
John Koleszar0ea50ce2010-05-18 11:58:33 -0400332
Adrian Grange217591f2011-10-06 15:49:11 -0700333 oxcf->target_bandwidth = cfg.rc_target_bitrate;
John Koleszar1654ae92011-07-28 09:17:32 -0400334 oxcf->rc_max_intra_bitrate_pct = vp8_cfg.rc_max_intra_bitrate_pct;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400335
Adrian Grange217591f2011-10-06 15:49:11 -0700336 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 Koleszar0ea50ce2010-05-18 11:58:33 -0400339 oxcf->fixed_q = -1;
340
Adrian Grange217591f2011-10-06 15:49:11 -0700341 oxcf->under_shoot_pct = cfg.rc_undershoot_pct;
342 oxcf->over_shoot_pct = cfg.rc_overshoot_pct;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400343
Adrian Grangee4793792012-01-13 14:09:40 -0800344 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 Grange217591f2011-10-06 15:49:11 -0700348 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 Koleszar0ea50ce2010-05-18 11:58:33 -0400351
Adrian Grange217591f2011-10-06 15:49:11 -0700352 oxcf->two_pass_vbrbias = cfg.rc_2pass_vbr_bias_pct;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400353 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 Grange217591f2011-10-06 15:49:11 -0700356 oxcf->auto_key = cfg.kf_mode == VPX_KF_AUTO
357 && cfg.kf_min_dist != cfg.kf_max_dist;
358 //oxcf->kf_min_dist = cfg.kf_min_dis;
359 oxcf->key_freq = cfg.kf_max_dist;
360
361 oxcf->number_of_layers = cfg.ts_number_layers;
362 oxcf->periodicity = cfg.ts_periodicity;
363
364 if (oxcf->number_of_layers > 1)
365 {
366 memcpy (oxcf->target_bitrate, cfg.ts_target_bitrate,
367 sizeof(cfg.ts_target_bitrate));
368 memcpy (oxcf->rate_decimator, cfg.ts_rate_decimator,
369 sizeof(cfg.ts_rate_decimator));
370 memcpy (oxcf->layer_id, cfg.ts_layer_id, sizeof(cfg.ts_layer_id));
371 }
John Koleszar0ea50ce2010-05-18 11:58:33 -0400372
Yunqing Wangaa7335e2011-10-25 15:14:16 -0400373#if CONFIG_MULTI_RES_ENCODING
Yunqing Wangc647ec42011-12-16 16:50:29 -0500374 /* When mr_cfg is NULL, oxcf->mr_total_resolutions and oxcf->mr_encoder_id
375 * are both memset to 0, which ensures the correct logic under this
376 * situation.
377 */
Yunqing Wangaa7335e2011-10-25 15:14:16 -0400378 if(mr_cfg)
379 {
380 oxcf->mr_total_resolutions = mr_cfg->mr_total_resolutions;
381 oxcf->mr_encoder_id = mr_cfg->mr_encoder_id;
382 oxcf->mr_down_sampling_factor.num = mr_cfg->mr_down_sampling_factor.num;
383 oxcf->mr_down_sampling_factor.den = mr_cfg->mr_down_sampling_factor.den;
384 oxcf->mr_low_res_mode_info = mr_cfg->mr_low_res_mode_info;
385 }
386#endif
387
John Koleszar0ea50ce2010-05-18 11:58:33 -0400388 //oxcf->delete_first_pass_file = cfg.g_delete_firstpassfile;
389 //strcpy(oxcf->first_pass_file, cfg.g_firstpass_file);
390
Adrian Grange217591f2011-10-06 15:49:11 -0700391 oxcf->cpu_used = vp8_cfg.cpu_used;
392 oxcf->encode_breakout = vp8_cfg.static_thresh;
393 oxcf->play_alternate = vp8_cfg.enable_auto_alt_ref;
394 oxcf->noise_sensitivity = vp8_cfg.noise_sensitivity;
395 oxcf->Sharpness = vp8_cfg.Sharpness;
396 oxcf->token_partitions = vp8_cfg.token_partitions;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400397
Adrian Grange217591f2011-10-06 15:49:11 -0700398 oxcf->two_pass_stats_in = cfg.rc_twopass_stats_in;
399 oxcf->output_pkt_list = vp8_cfg.pkt_list;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400400
Adrian Grange217591f2011-10-06 15:49:11 -0700401 oxcf->arnr_max_frames = vp8_cfg.arnr_max_frames;
402 oxcf->arnr_strength = vp8_cfg.arnr_strength;
403 oxcf->arnr_type = vp8_cfg.arnr_type;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400404
Adrian Grange217591f2011-10-06 15:49:11 -0700405 oxcf->tuning = vp8_cfg.tuning;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400406
407 /*
408 printf("Current VP8 Settings: \n");
409 printf("target_bandwidth: %d\n", oxcf->target_bandwidth);
410 printf("noise_sensitivity: %d\n", oxcf->noise_sensitivity);
411 printf("Sharpness: %d\n", oxcf->Sharpness);
412 printf("cpu_used: %d\n", oxcf->cpu_used);
413 printf("Mode: %d\n", oxcf->Mode);
414 printf("delete_first_pass_file: %d\n", oxcf->delete_first_pass_file);
415 printf("auto_key: %d\n", oxcf->auto_key);
416 printf("key_freq: %d\n", oxcf->key_freq);
417 printf("end_usage: %d\n", oxcf->end_usage);
418 printf("under_shoot_pct: %d\n", oxcf->under_shoot_pct);
John Koleszarc99f9d72011-04-11 11:29:23 -0400419 printf("over_shoot_pct: %d\n", oxcf->over_shoot_pct);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400420 printf("starting_buffer_level: %d\n", oxcf->starting_buffer_level);
421 printf("optimal_buffer_level: %d\n", oxcf->optimal_buffer_level);
422 printf("maximum_buffer_size: %d\n", oxcf->maximum_buffer_size);
423 printf("fixed_q: %d\n", oxcf->fixed_q);
424 printf("worst_allowed_q: %d\n", oxcf->worst_allowed_q);
425 printf("best_allowed_q: %d\n", oxcf->best_allowed_q);
426 printf("allow_spatial_resampling: %d\n", oxcf->allow_spatial_resampling);
427 printf("resample_down_water_mark: %d\n", oxcf->resample_down_water_mark);
428 printf("resample_up_water_mark: %d\n", oxcf->resample_up_water_mark);
429 printf("allow_df: %d\n", oxcf->allow_df);
430 printf("drop_frames_water_mark: %d\n", oxcf->drop_frames_water_mark);
431 printf("two_pass_vbrbias: %d\n", oxcf->two_pass_vbrbias);
432 printf("two_pass_vbrmin_section: %d\n", oxcf->two_pass_vbrmin_section);
433 printf("two_pass_vbrmax_section: %d\n", oxcf->two_pass_vbrmax_section);
434 printf("allow_lag: %d\n", oxcf->allow_lag);
435 printf("lag_in_frames: %d\n", oxcf->lag_in_frames);
436 printf("play_alternate: %d\n", oxcf->play_alternate);
437 printf("Version: %d\n", oxcf->Version);
438 printf("multi_threaded: %d\n", oxcf->multi_threaded);
439 printf("encode_breakout: %d\n", oxcf->encode_breakout);
440 */
441 return VPX_CODEC_OK;
442}
443
444static vpx_codec_err_t vp8e_set_config(vpx_codec_alg_priv_t *ctx,
445 const vpx_codec_enc_cfg_t *cfg)
446{
447 vpx_codec_err_t res;
448
John Koleszar51acb012012-02-07 17:07:49 -0800449 if (((cfg->g_w != ctx->cfg.g_w) || (cfg->g_h != ctx->cfg.g_h))
450 && cfg->g_lag_in_frames > 1)
John Koleszar0ea50ce2010-05-18 11:58:33 -0400451 ERROR("Cannot change width or height after initialization");
452
453 /* Prevent increasing lag_in_frames. This check is stricter than it needs
454 * to be -- the limit is not increasing past the first lag_in_frames
455 * value, but we don't track the initial config, only the last successful
456 * config.
457 */
458 if ((cfg->g_lag_in_frames > ctx->cfg.g_lag_in_frames))
459 ERROR("Cannot increase lag_in_frames");
460
James Berryc1c47e82011-12-07 15:48:00 -0500461 res = validate_config(ctx, cfg, &ctx->vp8_cfg, 0);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400462
463 if (!res)
464 {
465 ctx->cfg = *cfg;
Yunqing Wangaa7335e2011-10-25 15:14:16 -0400466 set_vp8e_config(&ctx->oxcf, ctx->cfg, ctx->vp8_cfg, NULL);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400467 vp8_change_config(ctx->cpi, &ctx->oxcf);
468 }
469
470 return res;
471}
472
473
474int vp8_reverse_trans(int);
475
476
477static vpx_codec_err_t get_param(vpx_codec_alg_priv_t *ctx,
478 int ctrl_id,
479 va_list args)
480{
481 void *arg = va_arg(args, void *);
482
483#define MAP(id, var) case id: *(RECAST(id, arg)) = var; break
484
485 if (!arg)
486 return VPX_CODEC_INVALID_PARAM;
487
488 switch (ctrl_id)
489 {
490 MAP(VP8E_GET_LAST_QUANTIZER, vp8_get_quantizer(ctx->cpi));
491 MAP(VP8E_GET_LAST_QUANTIZER_64, vp8_reverse_trans(vp8_get_quantizer(ctx->cpi)));
492 }
493
494 return VPX_CODEC_OK;
495#undef MAP
496}
497
498
499static vpx_codec_err_t set_param(vpx_codec_alg_priv_t *ctx,
500 int ctrl_id,
501 va_list args)
502{
503 vpx_codec_err_t res = VPX_CODEC_OK;
504 struct vp8_extracfg xcfg = ctx->vp8_cfg;
505
506#define MAP(id, var) case id: var = CAST(id, args); break;
507
508 switch (ctrl_id)
509 {
John Koleszar0ea50ce2010-05-18 11:58:33 -0400510 MAP(VP8E_SET_CPUUSED, xcfg.cpu_used);
511 MAP(VP8E_SET_ENABLEAUTOALTREF, xcfg.enable_auto_alt_ref);
512 MAP(VP8E_SET_NOISE_SENSITIVITY, xcfg.noise_sensitivity);
513 MAP(VP8E_SET_SHARPNESS, xcfg.Sharpness);
514 MAP(VP8E_SET_STATIC_THRESHOLD, xcfg.static_thresh);
515 MAP(VP8E_SET_TOKEN_PARTITIONS, xcfg.token_partitions);
516
517 MAP(VP8E_SET_ARNR_MAXFRAMES, xcfg.arnr_max_frames);
518 MAP(VP8E_SET_ARNR_STRENGTH , xcfg.arnr_strength);
519 MAP(VP8E_SET_ARNR_TYPE , xcfg.arnr_type);
John Koleszarb0da9b32010-12-17 09:43:39 -0500520 MAP(VP8E_SET_TUNING, xcfg.tuning);
Paul Wilkinse0846c92011-01-07 18:29:37 +0000521 MAP(VP8E_SET_CQ_LEVEL, xcfg.cq_level);
John Koleszar1654ae92011-07-28 09:17:32 -0400522 MAP(VP8E_SET_MAX_INTRA_BITRATE_PCT, xcfg.rc_max_intra_bitrate_pct);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400523
524 }
525
James Berryc1c47e82011-12-07 15:48:00 -0500526 res = validate_config(ctx, &ctx->cfg, &xcfg, 0);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400527
528 if (!res)
529 {
530 ctx->vp8_cfg = xcfg;
Yunqing Wangaa7335e2011-10-25 15:14:16 -0400531 set_vp8e_config(&ctx->oxcf, ctx->cfg, ctx->vp8_cfg, NULL);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400532 vp8_change_config(ctx->cpi, &ctx->oxcf);
533 }
534
535 return res;
536#undef MAP
537}
Yunqing Wangaa7335e2011-10-25 15:14:16 -0400538
539static vpx_codec_err_t vp8e_mr_alloc_mem(const vpx_codec_enc_cfg_t *cfg,
540 void **mem_loc)
541{
542 vpx_codec_err_t res = 0;
543
544#if CONFIG_MULTI_RES_ENCODING
545 int mb_rows = ((cfg->g_w + 15) >>4);
546 int mb_cols = ((cfg->g_h + 15) >>4);
547
548 *mem_loc = calloc(mb_rows*mb_cols, sizeof(LOWER_RES_INFO));
549 if(!(*mem_loc))
550 {
551 free(*mem_loc);
552 res = VPX_CODEC_MEM_ERROR;
553 }
554 else
555 res = VPX_CODEC_OK;
556#endif
557
558 return res;
559}
560
561static vpx_codec_err_t vp8e_init(vpx_codec_ctx_t *ctx,
562 vpx_codec_priv_enc_mr_cfg_t *mr_cfg)
John Koleszar0ea50ce2010-05-18 11:58:33 -0400563{
John Koleszar2bf8fb52012-05-02 16:37:37 -0700564 vpx_codec_err_t res = VPX_CODEC_OK;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400565 struct vpx_codec_alg_priv *priv;
566 vpx_codec_enc_cfg_t *cfg;
567 unsigned int i;
568
John Koleszarb0056c32011-12-20 16:54:54 -0800569 struct VP8_COMP *optr;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400570
571 if (!ctx->priv)
572 {
573 priv = calloc(1, sizeof(struct vpx_codec_alg_priv));
574
Attila Nagye6db21e2011-02-22 15:02:05 +0200575 if (!priv)
John Koleszar0ea50ce2010-05-18 11:58:33 -0400576 {
Attila Nagye6db21e2011-02-22 15:02:05 +0200577 return VPX_CODEC_MEM_ERROR;
578 }
John Koleszar0ea50ce2010-05-18 11:58:33 -0400579
Attila Nagye6db21e2011-02-22 15:02:05 +0200580 ctx->priv = &priv->base;
581 ctx->priv->sz = sizeof(*ctx->priv);
582 ctx->priv->iface = ctx->iface;
583 ctx->priv->alg_priv = priv;
584 ctx->priv->init_flags = ctx->init_flags;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400585
Attila Nagye6db21e2011-02-22 15:02:05 +0200586 if (ctx->config.enc)
587 {
588 /* Update the reference to the config structure to an
589 * internal copy.
John Koleszar0ea50ce2010-05-18 11:58:33 -0400590 */
Attila Nagye6db21e2011-02-22 15:02:05 +0200591 ctx->priv->alg_priv->cfg = *ctx->config.enc;
592 ctx->config.enc = &ctx->priv->alg_priv->cfg;
593 }
John Koleszar0ea50ce2010-05-18 11:58:33 -0400594
Attila Nagye6db21e2011-02-22 15:02:05 +0200595 cfg = &ctx->priv->alg_priv->cfg;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400596
Adrian Grange217591f2011-10-06 15:49:11 -0700597 /* Select the extra vp8 configuration table based on the current
Attila Nagye6db21e2011-02-22 15:02:05 +0200598 * usage value. If the current usage value isn't found, use the
599 * values for usage case 0.
600 */
601 for (i = 0;
602 extracfg_map[i].usage && extracfg_map[i].usage != cfg->g_usage;
603 i++);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400604
Attila Nagye6db21e2011-02-22 15:02:05 +0200605 priv->vp8_cfg = extracfg_map[i].cfg;
606 priv->vp8_cfg.pkt_list = &priv->pkt_list.head;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400607
Attila Nagye6db21e2011-02-22 15:02:05 +0200608 priv->cx_data_sz = priv->cfg.g_w * priv->cfg.g_h * 3 / 2 * 2;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400609
James Berrybac6c222011-10-24 11:50:27 -0400610 if (priv->cx_data_sz < 32768) priv->cx_data_sz = 32768;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400611
Attila Nagye6db21e2011-02-22 15:02:05 +0200612 priv->cx_data = malloc(priv->cx_data_sz);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400613
Attila Nagye6db21e2011-02-22 15:02:05 +0200614 if (!priv->cx_data)
615 {
616 return VPX_CODEC_MEM_ERROR;
617 }
John Koleszar0ea50ce2010-05-18 11:58:33 -0400618
James Berryc1c47e82011-12-07 15:48:00 -0500619 res = validate_config(priv, &priv->cfg, &priv->vp8_cfg, 0);
Attila Nagye6db21e2011-02-22 15:02:05 +0200620
621 if (!res)
622 {
Yunqing Wangaa7335e2011-10-25 15:14:16 -0400623 if(mr_cfg)
624 ctx->priv->enc.total_encoders = mr_cfg->mr_total_resolutions;
625 else
626 ctx->priv->enc.total_encoders = 1;
627
Attila Nagye6db21e2011-02-22 15:02:05 +0200628 set_vp8e_config(&ctx->priv->alg_priv->oxcf,
629 ctx->priv->alg_priv->cfg,
Yunqing Wangaa7335e2011-10-25 15:14:16 -0400630 ctx->priv->alg_priv->vp8_cfg,
631 mr_cfg);
632
Attila Nagye6db21e2011-02-22 15:02:05 +0200633 optr = vp8_create_compressor(&ctx->priv->alg_priv->oxcf);
634
635 if (!optr)
636 res = VPX_CODEC_MEM_ERROR;
637 else
638 ctx->priv->alg_priv->cpi = optr;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400639 }
640 }
641
642 return res;
643}
644
645static vpx_codec_err_t vp8e_destroy(vpx_codec_alg_priv_t *ctx)
646{
Yunqing Wangaa7335e2011-10-25 15:14:16 -0400647#if CONFIG_MULTI_RES_ENCODING
648 /* Free multi-encoder shared memory */
649 if (ctx->oxcf.mr_total_resolutions > 0 && (ctx->oxcf.mr_encoder_id == ctx->oxcf.mr_total_resolutions-1))
650 free(ctx->oxcf.mr_low_res_mode_info);
651#endif
John Koleszar0ea50ce2010-05-18 11:58:33 -0400652
653 free(ctx->cx_data);
654 vp8_remove_compressor(&ctx->cpi);
655 free(ctx);
656 return VPX_CODEC_OK;
657}
658
659static vpx_codec_err_t image2yuvconfig(const vpx_image_t *img,
660 YV12_BUFFER_CONFIG *yv12)
661{
662 vpx_codec_err_t res = VPX_CODEC_OK;
John Koleszarb6c71912010-05-24 21:45:05 -0400663 yv12->y_buffer = img->planes[VPX_PLANE_Y];
664 yv12->u_buffer = img->planes[VPX_PLANE_U];
665 yv12->v_buffer = img->planes[VPX_PLANE_V];
John Koleszar0ea50ce2010-05-18 11:58:33 -0400666
667 yv12->y_width = img->d_w;
668 yv12->y_height = img->d_h;
669 yv12->uv_width = (1 + yv12->y_width) / 2;
670 yv12->uv_height = (1 + yv12->y_height) / 2;
671
John Koleszarb6c71912010-05-24 21:45:05 -0400672 yv12->y_stride = img->stride[VPX_PLANE_Y];
673 yv12->uv_stride = img->stride[VPX_PLANE_U];
John Koleszar0ea50ce2010-05-18 11:58:33 -0400674
John Koleszarb6c71912010-05-24 21:45:05 -0400675 yv12->border = (img->stride[VPX_PLANE_Y] - img->w) / 2;
James Zern6cd4a102010-05-20 23:22:39 -0400676 yv12->clrtype = (img->fmt == VPX_IMG_FMT_VPXI420 || img->fmt == VPX_IMG_FMT_VPXYV12); //REG_YUV = 0
John Koleszar0ea50ce2010-05-18 11:58:33 -0400677 return res;
678}
679
680static void pick_quickcompress_mode(vpx_codec_alg_priv_t *ctx,
681 unsigned long duration,
682 unsigned long deadline)
683{
684 unsigned int new_qc;
685
686#if !(CONFIG_REALTIME_ONLY)
687 /* Use best quality mode if no deadline is given. */
688 new_qc = MODE_BESTQUALITY;
689
690 if (deadline)
691 {
692 uint64_t duration_us;
693
694 /* Convert duration parameter from stream timebase to microseconds */
695 duration_us = (uint64_t)duration * 1000000
696 * (uint64_t)ctx->cfg.g_timebase.num
697 / (uint64_t)ctx->cfg.g_timebase.den;
698
699 /* If the deadline is more that the duration this frame is to be shown,
700 * use good quality mode. Otherwise use realtime mode.
701 */
702 new_qc = (deadline > duration_us) ? MODE_GOODQUALITY : MODE_REALTIME;
703 }
704
705#else
706 new_qc = MODE_REALTIME;
707#endif
708
John Koleszar0ea50ce2010-05-18 11:58:33 -0400709 if (ctx->cfg.g_pass == VPX_RC_FIRST_PASS)
710 new_qc = MODE_FIRSTPASS;
711 else if (ctx->cfg.g_pass == VPX_RC_LAST_PASS)
712 new_qc = (new_qc == MODE_BESTQUALITY)
713 ? MODE_SECONDPASS_BEST
714 : MODE_SECONDPASS;
715
716 if (ctx->oxcf.Mode != new_qc)
717 {
718 ctx->oxcf.Mode = new_qc;
719 vp8_change_config(ctx->cpi, &ctx->oxcf);
720 }
721}
722
723
724static vpx_codec_err_t vp8e_encode(vpx_codec_alg_priv_t *ctx,
725 const vpx_image_t *img,
726 vpx_codec_pts_t pts,
727 unsigned long duration,
728 vpx_enc_frame_flags_t flags,
729 unsigned long deadline)
730{
731 vpx_codec_err_t res = VPX_CODEC_OK;
732
John Koleszard72c5362012-04-19 10:00:33 -0700733 if (!ctx->cfg.rc_target_bitrate)
734 return res;
735
John Koleszar0ea50ce2010-05-18 11:58:33 -0400736 if (img)
737 res = validate_img(ctx, img);
738
James Berryc1c47e82011-12-07 15:48:00 -0500739 if (!res)
740 res = validate_config(ctx, &ctx->cfg, &ctx->vp8_cfg, 1);
741
John Koleszar0ea50ce2010-05-18 11:58:33 -0400742 pick_quickcompress_mode(ctx, duration, deadline);
743 vpx_codec_pkt_list_init(&ctx->pkt_list);
744
745 /* Handle Flags */
746 if (((flags & VP8_EFLAG_NO_UPD_GF) && (flags & VP8_EFLAG_FORCE_GF))
747 || ((flags & VP8_EFLAG_NO_UPD_ARF) && (flags & VP8_EFLAG_FORCE_ARF)))
748 {
749 ctx->base.err_detail = "Conflicting flags.";
750 return VPX_CODEC_INVALID_PARAM;
751 }
752
753 if (flags & (VP8_EFLAG_NO_REF_LAST | VP8_EFLAG_NO_REF_GF
754 | VP8_EFLAG_NO_REF_ARF))
755 {
756 int ref = 7;
757
758 if (flags & VP8_EFLAG_NO_REF_LAST)
759 ref ^= VP8_LAST_FLAG;
760
761 if (flags & VP8_EFLAG_NO_REF_GF)
762 ref ^= VP8_GOLD_FLAG;
763
764 if (flags & VP8_EFLAG_NO_REF_ARF)
765 ref ^= VP8_ALT_FLAG;
766
767 vp8_use_as_reference(ctx->cpi, ref);
768 }
769
770 if (flags & (VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF
771 | VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_FORCE_GF
772 | VP8_EFLAG_FORCE_ARF))
773 {
774 int upd = 7;
775
776 if (flags & VP8_EFLAG_NO_UPD_LAST)
777 upd ^= VP8_LAST_FLAG;
778
779 if (flags & VP8_EFLAG_NO_UPD_GF)
780 upd ^= VP8_GOLD_FLAG;
781
782 if (flags & VP8_EFLAG_NO_UPD_ARF)
783 upd ^= VP8_ALT_FLAG;
784
785 vp8_update_reference(ctx->cpi, upd);
786 }
787
788 if (flags & VP8_EFLAG_NO_UPD_ENTROPY)
789 {
790 vp8_update_entropy(ctx->cpi, 0);
791 }
792
793 /* Handle fixed keyframe intervals */
794 if (ctx->cfg.kf_mode == VPX_KF_AUTO
795 && ctx->cfg.kf_min_dist == ctx->cfg.kf_max_dist)
796 {
797 if (++ctx->fixed_kf_cntr > ctx->cfg.kf_min_dist)
798 {
799 flags |= VPX_EFLAG_FORCE_KF;
Andoni Morales Alastruey48140162011-02-07 18:04:02 +0100800 ctx->fixed_kf_cntr = 1;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400801 }
802 }
803
804 /* Initialize the encoder instance on the first frame*/
805 if (!res && ctx->cpi)
806 {
807 unsigned int lib_flags;
808 YV12_BUFFER_CONFIG sd;
James Zernb45065d2011-07-25 18:44:59 -0700809 int64_t dst_time_stamp, dst_end_time_stamp;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400810 unsigned long size, cx_data_sz;
811 unsigned char *cx_data;
James Berrybc715112011-10-12 11:18:50 -0400812 unsigned char *cx_data_end;
813 int comp_data_state = 0;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400814
815 /* Set up internal flags */
816 if (ctx->base.init_flags & VPX_CODEC_USE_PSNR)
817 ((VP8_COMP *)ctx->cpi)->b_calculate_psnr = 1;
818
Stefan Holmer7296b3f2011-06-13 16:42:27 +0200819 if (ctx->base.init_flags & VPX_CODEC_USE_OUTPUT_PARTITION)
820 ((VP8_COMP *)ctx->cpi)->output_partition = 1;
821
John Koleszar0ea50ce2010-05-18 11:58:33 -0400822 /* Convert API flags to internal codec lib flags */
823 lib_flags = (flags & VPX_EFLAG_FORCE_KF) ? FRAMEFLAGS_KEY : 0;
824
825 /* vp8 use 10,000,000 ticks/second as time stamp */
826 dst_time_stamp = pts * 10000000 * ctx->cfg.g_timebase.num / ctx->cfg.g_timebase.den;
827 dst_end_time_stamp = (pts + duration) * 10000000 * ctx->cfg.g_timebase.num / ctx->cfg.g_timebase.den;
828
829 if (img != NULL)
830 {
831 res = image2yuvconfig(img, &sd);
832
833 if (vp8_receive_raw_frame(ctx->cpi, ctx->next_frame_flag | lib_flags,
834 &sd, dst_time_stamp, dst_end_time_stamp))
835 {
836 VP8_COMP *cpi = (VP8_COMP *)ctx->cpi;
837 res = update_error_state(ctx, &cpi->common.error);
838 }
839
840 /* reset for next frame */
841 ctx->next_frame_flag = 0;
842 }
843
844 cx_data = ctx->cx_data;
845 cx_data_sz = ctx->cx_data_sz;
James Berrybc715112011-10-12 11:18:50 -0400846 cx_data_end = ctx->cx_data + cx_data_sz;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400847 lib_flags = 0;
848
James Berrybc715112011-10-12 11:18:50 -0400849 while (cx_data_sz >= ctx->cx_data_sz / 2)
John Koleszar0ea50ce2010-05-18 11:58:33 -0400850 {
James Berrybc715112011-10-12 11:18:50 -0400851 comp_data_state = vp8_get_compressed_data(ctx->cpi,
852 &lib_flags,
853 &size,
854 cx_data,
855 cx_data_end,
856 &dst_time_stamp,
857 &dst_end_time_stamp,
858 !img);
859
860 if(comp_data_state == VPX_CODEC_CORRUPT_FRAME)
861 return VPX_CODEC_CORRUPT_FRAME;
862 else if(comp_data_state == -1)
863 break;
864
John Koleszar0ea50ce2010-05-18 11:58:33 -0400865 if (size)
866 {
867 vpx_codec_pts_t round, delta;
868 vpx_codec_cx_pkt_t pkt;
869 VP8_COMP *cpi = (VP8_COMP *)ctx->cpi;
870
871 /* Add the frame packet to the list of returned packets. */
872 round = 1000000 * ctx->cfg.g_timebase.num / 2 - 1;
873 delta = (dst_end_time_stamp - dst_time_stamp);
874 pkt.kind = VPX_CODEC_CX_FRAME_PKT;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400875 pkt.data.frame.pts =
876 (dst_time_stamp * ctx->cfg.g_timebase.den + round)
877 / ctx->cfg.g_timebase.num / 10000000;
878 pkt.data.frame.duration =
879 (delta * ctx->cfg.g_timebase.den + round)
880 / ctx->cfg.g_timebase.num / 10000000;
881 pkt.data.frame.flags = lib_flags << 16;
882
883 if (lib_flags & FRAMEFLAGS_KEY)
884 pkt.data.frame.flags |= VPX_FRAME_IS_KEY;
885
886 if (!cpi->common.show_frame)
887 {
888 pkt.data.frame.flags |= VPX_FRAME_IS_INVISIBLE;
889
Frank Galligan45e64942010-10-05 17:46:37 -0400890 // This timestamp should be as close as possible to the
891 // prior PTS so that if a decoder uses pts to schedule when
892 // to do this, we start right after last frame was decoded.
893 // Invisible frames have no duration.
894 pkt.data.frame.pts = ((cpi->last_time_stamp_seen
895 * ctx->cfg.g_timebase.den + round)
896 / ctx->cfg.g_timebase.num / 10000000) + 1;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400897 pkt.data.frame.duration = 0;
898 }
899
John Koleszar37de0b82011-07-07 10:38:23 -0400900 if (cpi->droppable)
901 pkt.data.frame.flags |= VPX_FRAME_IS_DROPPABLE;
902
Stefan Holmer7296b3f2011-06-13 16:42:27 +0200903 if (cpi->output_partition)
904 {
905 int i;
906 const int num_partitions =
907 (1 << cpi->common.multi_token_partition) + 1;
Attila Nagy0afcc762011-07-20 14:09:42 +0300908
909 pkt.data.frame.flags |= VPX_FRAME_IS_FRAGMENT;
910
Stefan Holmer7296b3f2011-06-13 16:42:27 +0200911 for (i = 0; i < num_partitions; ++i)
912 {
Attila Nagy52cf4dc2012-02-09 12:37:03 +0200913#if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING
914 pkt.data.frame.buf = cpi->partition_d[i];
915#else
Stefan Holmer7296b3f2011-06-13 16:42:27 +0200916 pkt.data.frame.buf = cx_data;
Attila Nagy52cf4dc2012-02-09 12:37:03 +0200917 cx_data += cpi->partition_sz[i];
918 cx_data_sz -= cpi->partition_sz[i];
919#endif
Stefan Holmer7296b3f2011-06-13 16:42:27 +0200920 pkt.data.frame.sz = cpi->partition_sz[i];
921 pkt.data.frame.partition_id = i;
922 /* don't set the fragment bit for the last partition */
Attila Nagy0afcc762011-07-20 14:09:42 +0300923 if (i == (num_partitions - 1))
924 pkt.data.frame.flags &= ~VPX_FRAME_IS_FRAGMENT;
Stefan Holmer7296b3f2011-06-13 16:42:27 +0200925 vpx_codec_pkt_list_add(&ctx->pkt_list.head, &pkt);
Stefan Holmer7296b3f2011-06-13 16:42:27 +0200926 }
Attila Nagy52cf4dc2012-02-09 12:37:03 +0200927#if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING
928 /* In lagged mode the encoder can buffer multiple frames.
929 * We don't want this in partitioned output because
930 * partitions are spread all over the output buffer.
931 * So, force an exit!
932 */
933 cx_data_sz -= ctx->cx_data_sz / 2;
934#endif
Stefan Holmer7296b3f2011-06-13 16:42:27 +0200935 }
936 else
937 {
938 pkt.data.frame.buf = cx_data;
939 pkt.data.frame.sz = size;
940 pkt.data.frame.partition_id = -1;
941 vpx_codec_pkt_list_add(&ctx->pkt_list.head, &pkt);
942 cx_data += size;
943 cx_data_sz -= size;
944 }
John Koleszar0ea50ce2010-05-18 11:58:33 -0400945
946 //printf("timestamp: %lld, duration: %d\n", pkt->data.frame.pts, pkt->data.frame.duration);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400947 }
948 }
949 }
950
951 return res;
952}
953
954
955static const vpx_codec_cx_pkt_t *vp8e_get_cxdata(vpx_codec_alg_priv_t *ctx,
956 vpx_codec_iter_t *iter)
957{
958 return vpx_codec_pkt_list_get(&ctx->pkt_list.head, iter);
959}
960
961static vpx_codec_err_t vp8e_set_reference(vpx_codec_alg_priv_t *ctx,
962 int ctr_id,
963 va_list args)
964{
965 vpx_ref_frame_t *data = va_arg(args, vpx_ref_frame_t *);
966
967 if (data)
968 {
969 vpx_ref_frame_t *frame = (vpx_ref_frame_t *)data;
970 YV12_BUFFER_CONFIG sd;
971
972 image2yuvconfig(&frame->img, &sd);
973 vp8_set_reference(ctx->cpi, frame->frame_type, &sd);
974 return VPX_CODEC_OK;
975 }
976 else
977 return VPX_CODEC_INVALID_PARAM;
978
979}
980
981static vpx_codec_err_t vp8e_get_reference(vpx_codec_alg_priv_t *ctx,
982 int ctr_id,
983 va_list args)
984{
985
986 vpx_ref_frame_t *data = va_arg(args, vpx_ref_frame_t *);
987
988 if (data)
989 {
990 vpx_ref_frame_t *frame = (vpx_ref_frame_t *)data;
991 YV12_BUFFER_CONFIG sd;
992
993 image2yuvconfig(&frame->img, &sd);
994 vp8_get_reference(ctx->cpi, frame->frame_type, &sd);
995 return VPX_CODEC_OK;
996 }
997 else
998 return VPX_CODEC_INVALID_PARAM;
999}
1000
1001static vpx_codec_err_t vp8e_set_previewpp(vpx_codec_alg_priv_t *ctx,
1002 int ctr_id,
1003 va_list args)
1004{
James Zern76640f82010-08-20 16:06:56 -04001005#if CONFIG_POSTPROC
John Koleszar0ea50ce2010-05-18 11:58:33 -04001006 vp8_postproc_cfg_t *data = va_arg(args, vp8_postproc_cfg_t *);
James Zern76640f82010-08-20 16:06:56 -04001007 (void)ctr_id;
John Koleszar0ea50ce2010-05-18 11:58:33 -04001008
1009 if (data)
1010 {
1011 ctx->preview_ppcfg = *((vp8_postproc_cfg_t *)data);
1012 return VPX_CODEC_OK;
1013 }
1014 else
1015 return VPX_CODEC_INVALID_PARAM;
James Zern76640f82010-08-20 16:06:56 -04001016#else
1017 (void)ctx;
1018 (void)ctr_id;
1019 (void)args;
1020 return VPX_CODEC_INCAPABLE;
1021#endif
John Koleszar0ea50ce2010-05-18 11:58:33 -04001022}
1023
1024
1025static vpx_image_t *vp8e_get_preview(vpx_codec_alg_priv_t *ctx)
1026{
1027
1028 YV12_BUFFER_CONFIG sd;
Fritz Koenig647df002010-11-04 16:03:36 -07001029 vp8_ppflags_t flags = {0};
John Koleszar0ea50ce2010-05-18 11:58:33 -04001030
Fritz Koenig647df002010-11-04 16:03:36 -07001031 if (ctx->preview_ppcfg.post_proc_flag)
1032 {
1033 flags.post_proc_flag = ctx->preview_ppcfg.post_proc_flag;
1034 flags.deblocking_level = ctx->preview_ppcfg.deblocking_level;
1035 flags.noise_level = ctx->preview_ppcfg.noise_level;
1036 }
1037
1038 if (0 == vp8_get_preview_raw_frame(ctx->cpi, &sd, &flags))
John Koleszar0ea50ce2010-05-18 11:58:33 -04001039 {
1040
1041 /*
James Zern6cd4a102010-05-20 23:22:39 -04001042 vpx_img_wrap(&ctx->preview_img, VPX_IMG_FMT_YV12,
John Koleszar0ea50ce2010-05-18 11:58:33 -04001043 sd.y_width + 2*VP8BORDERINPIXELS,
1044 sd.y_height + 2*VP8BORDERINPIXELS,
1045 1,
1046 sd.buffer_alloc);
1047 vpx_img_set_rect(&ctx->preview_img,
1048 VP8BORDERINPIXELS, VP8BORDERINPIXELS,
1049 sd.y_width, sd.y_height);
1050 */
1051
1052 ctx->preview_img.bps = 12;
John Koleszarb6c71912010-05-24 21:45:05 -04001053 ctx->preview_img.planes[VPX_PLANE_Y] = sd.y_buffer;
1054 ctx->preview_img.planes[VPX_PLANE_U] = sd.u_buffer;
1055 ctx->preview_img.planes[VPX_PLANE_V] = sd.v_buffer;
John Koleszar0ea50ce2010-05-18 11:58:33 -04001056
1057 if (sd.clrtype == REG_YUV)
James Zern6cd4a102010-05-20 23:22:39 -04001058 ctx->preview_img.fmt = VPX_IMG_FMT_I420;
John Koleszar0ea50ce2010-05-18 11:58:33 -04001059 else
James Zern6cd4a102010-05-20 23:22:39 -04001060 ctx->preview_img.fmt = VPX_IMG_FMT_VPXI420;
John Koleszar0ea50ce2010-05-18 11:58:33 -04001061
1062 ctx->preview_img.x_chroma_shift = 1;
1063 ctx->preview_img.y_chroma_shift = 1;
1064
James Berryddacf1c2011-02-08 14:23:18 -05001065 ctx->preview_img.d_w = sd.y_width;
1066 ctx->preview_img.d_h = sd.y_height;
John Koleszarb6c71912010-05-24 21:45:05 -04001067 ctx->preview_img.stride[VPX_PLANE_Y] = sd.y_stride;
1068 ctx->preview_img.stride[VPX_PLANE_U] = sd.uv_stride;
1069 ctx->preview_img.stride[VPX_PLANE_V] = sd.uv_stride;
John Koleszar0ea50ce2010-05-18 11:58:33 -04001070 ctx->preview_img.w = sd.y_width;
1071 ctx->preview_img.h = sd.y_height;
1072
1073 return &ctx->preview_img;
1074 }
1075 else
1076 return NULL;
1077}
1078
1079static vpx_codec_err_t vp8e_update_entropy(vpx_codec_alg_priv_t *ctx,
1080 int ctr_id,
1081 va_list args)
1082{
1083 int update = va_arg(args, int);
1084 vp8_update_entropy(ctx->cpi, update);
1085 return VPX_CODEC_OK;
1086
1087}
1088
1089static vpx_codec_err_t vp8e_update_reference(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_reference(ctx->cpi, update);
1095 return VPX_CODEC_OK;
1096}
1097
1098static vpx_codec_err_t vp8e_use_reference(vpx_codec_alg_priv_t *ctx,
1099 int ctr_id,
1100 va_list args)
1101{
1102 int reference_flag = va_arg(args, int);
1103 vp8_use_as_reference(ctx->cpi, reference_flag);
1104 return VPX_CODEC_OK;
1105}
1106
1107static vpx_codec_err_t vp8e_set_roi_map(vpx_codec_alg_priv_t *ctx,
1108 int ctr_id,
1109 va_list args)
1110{
1111 vpx_roi_map_t *data = va_arg(args, vpx_roi_map_t *);
1112
1113 if (data)
1114 {
1115 vpx_roi_map_t *roi = (vpx_roi_map_t *)data;
1116
1117 if (!vp8_set_roimap(ctx->cpi, roi->roi_map, roi->rows, roi->cols, roi->delta_q, roi->delta_lf, roi->static_threshold))
1118 return VPX_CODEC_OK;
1119 else
1120 return VPX_CODEC_INVALID_PARAM;
1121 }
1122 else
1123 return VPX_CODEC_INVALID_PARAM;
1124}
1125
1126
1127static vpx_codec_err_t vp8e_set_activemap(vpx_codec_alg_priv_t *ctx,
1128 int ctr_id,
1129 va_list args)
1130{
1131 vpx_active_map_t *data = va_arg(args, vpx_active_map_t *);
1132
1133 if (data)
1134 {
1135
1136 vpx_active_map_t *map = (vpx_active_map_t *)data;
1137
1138 if (!vp8_set_active_map(ctx->cpi, map->active_map, map->rows, map->cols))
1139 return VPX_CODEC_OK;
1140 else
1141 return VPX_CODEC_INVALID_PARAM;
1142 }
1143 else
1144 return VPX_CODEC_INVALID_PARAM;
1145}
1146
1147static vpx_codec_err_t vp8e_set_scalemode(vpx_codec_alg_priv_t *ctx,
1148 int ctr_id,
1149 va_list args)
1150{
1151
1152 vpx_scaling_mode_t *data = va_arg(args, vpx_scaling_mode_t *);
1153
1154 if (data)
1155 {
1156 int res;
1157 vpx_scaling_mode_t scalemode = *(vpx_scaling_mode_t *)data ;
1158 res = vp8_set_internal_size(ctx->cpi, scalemode.h_scaling_mode, scalemode.v_scaling_mode);
1159
1160 if (!res)
1161 {
1162 /*force next frame a key frame to effect scaling mode */
1163 ctx->next_frame_flag |= FRAMEFLAGS_KEY;
1164 return VPX_CODEC_OK;
1165 }
1166 else
1167 return VPX_CODEC_INVALID_PARAM;
1168 }
1169 else
1170 return VPX_CODEC_INVALID_PARAM;
1171}
1172
1173
1174static vpx_codec_ctrl_fn_map_t vp8e_ctf_maps[] =
1175{
1176 {VP8_SET_REFERENCE, vp8e_set_reference},
1177 {VP8_COPY_REFERENCE, vp8e_get_reference},
1178 {VP8_SET_POSTPROC, vp8e_set_previewpp},
1179 {VP8E_UPD_ENTROPY, vp8e_update_entropy},
1180 {VP8E_UPD_REFERENCE, vp8e_update_reference},
1181 {VP8E_USE_REFERENCE, vp8e_use_reference},
1182 {VP8E_SET_ROI_MAP, vp8e_set_roi_map},
1183 {VP8E_SET_ACTIVEMAP, vp8e_set_activemap},
1184 {VP8E_SET_SCALEMODE, vp8e_set_scalemode},
John Koleszar0ea50ce2010-05-18 11:58:33 -04001185 {VP8E_SET_CPUUSED, set_param},
1186 {VP8E_SET_NOISE_SENSITIVITY, set_param},
1187 {VP8E_SET_ENABLEAUTOALTREF, set_param},
1188 {VP8E_SET_SHARPNESS, set_param},
1189 {VP8E_SET_STATIC_THRESHOLD, set_param},
1190 {VP8E_SET_TOKEN_PARTITIONS, set_param},
1191 {VP8E_GET_LAST_QUANTIZER, get_param},
1192 {VP8E_GET_LAST_QUANTIZER_64, get_param},
1193 {VP8E_SET_ARNR_MAXFRAMES, set_param},
1194 {VP8E_SET_ARNR_STRENGTH , set_param},
1195 {VP8E_SET_ARNR_TYPE , set_param},
John Koleszarb0da9b32010-12-17 09:43:39 -05001196 {VP8E_SET_TUNING, set_param},
Paul Wilkinse0846c92011-01-07 18:29:37 +00001197 {VP8E_SET_CQ_LEVEL, set_param},
John Koleszar1654ae92011-07-28 09:17:32 -04001198 {VP8E_SET_MAX_INTRA_BITRATE_PCT, set_param},
John Koleszar0ea50ce2010-05-18 11:58:33 -04001199 { -1, NULL},
1200};
1201
1202static vpx_codec_enc_cfg_map_t vp8e_usage_cfg_map[] =
1203{
1204 {
1205 0,
1206 {
1207 0, /* g_usage */
1208 0, /* g_threads */
1209 0, /* g_profile */
1210
1211 320, /* g_width */
1212 240, /* g_height */
1213 {1, 30}, /* g_timebase */
1214
1215 0, /* g_error_resilient */
1216
1217 VPX_RC_ONE_PASS, /* g_pass */
1218
1219 0, /* g_lag_in_frames */
1220
John Koleszar23216212010-09-02 09:32:03 -04001221 0, /* rc_dropframe_thresh */
John Koleszar0ea50ce2010-05-18 11:58:33 -04001222 0, /* rc_resize_allowed */
1223 60, /* rc_resize_down_thresold */
1224 30, /* rc_resize_up_thresold */
1225
1226 VPX_VBR, /* rc_end_usage */
1227#if VPX_ENCODER_ABI_VERSION > (1 + VPX_CODEC_ABI_VERSION)
1228 {0}, /* rc_twopass_stats_in */
1229#endif
1230 256, /* rc_target_bandwidth */
John Koleszar0ea50ce2010-05-18 11:58:33 -04001231 4, /* rc_min_quantizer */
1232 63, /* rc_max_quantizer */
John Koleszarc99f9d72011-04-11 11:29:23 -04001233 100, /* rc_undershoot_pct */
1234 100, /* rc_overshoot_pct */
John Koleszar0ea50ce2010-05-18 11:58:33 -04001235
1236 6000, /* rc_max_buffer_size */
1237 4000, /* rc_buffer_initial_size; */
1238 5000, /* rc_buffer_optimal_size; */
1239
1240 50, /* rc_two_pass_vbrbias */
1241 0, /* rc_two_pass_vbrmin_section */
1242 400, /* rc_two_pass_vbrmax_section */
1243
1244 /* keyframing settings (kf) */
1245 VPX_KF_AUTO, /* g_kfmode*/
1246 0, /* kf_min_dist */
Ralph Giles2a0d7b12012-01-05 10:39:38 -06001247 128, /* kf_max_dist */
John Koleszar0ea50ce2010-05-18 11:58:33 -04001248
1249#if VPX_ENCODER_ABI_VERSION == (1 + VPX_CODEC_ABI_VERSION)
1250 1, /* g_delete_first_pass_file */
1251 "vp8.fpf" /* first pass filename */
1252#endif
Adrian Grange217591f2011-10-06 15:49:11 -07001253
1254 1, /* ts_number_layers */
1255 {0}, /* ts_target_bitrate */
1256 {0}, /* ts_rate_decimator */
1257 0, /* ts_periodicity */
1258 {0}, /* ts_layer_id */
John Koleszar0ea50ce2010-05-18 11:58:33 -04001259 }},
1260 { -1, {NOT_IMPLEMENTED}}
1261};
1262
1263
1264#ifndef VERSION_STRING
1265#define VERSION_STRING
1266#endif
John Koleszarfa7a55b2010-09-21 10:35:52 -04001267CODEC_INTERFACE(vpx_codec_vp8_cx) =
John Koleszar0ea50ce2010-05-18 11:58:33 -04001268{
John Koleszar317a6662010-06-10 12:08:01 -04001269 "WebM Project VP8 Encoder" VERSION_STRING,
John Koleszar0ea50ce2010-05-18 11:58:33 -04001270 VPX_CODEC_INTERNAL_ABI_VERSION,
Stefan Holmer7296b3f2011-06-13 16:42:27 +02001271 VPX_CODEC_CAP_ENCODER | VPX_CODEC_CAP_PSNR |
1272 VPX_CODEC_CAP_OUTPUT_PARTITION,
John Koleszar0ea50ce2010-05-18 11:58:33 -04001273 /* vpx_codec_caps_t caps; */
1274 vp8e_init, /* vpx_codec_init_fn_t init; */
1275 vp8e_destroy, /* vpx_codec_destroy_fn_t destroy; */
1276 vp8e_ctf_maps, /* vpx_codec_ctrl_fn_map_t *ctrl_maps; */
1277 NOT_IMPLEMENTED, /* vpx_codec_get_mmap_fn_t get_mmap; */
1278 NOT_IMPLEMENTED, /* vpx_codec_set_mmap_fn_t set_mmap; */
1279 {
1280 NOT_IMPLEMENTED, /* vpx_codec_peek_si_fn_t peek_si; */
1281 NOT_IMPLEMENTED, /* vpx_codec_get_si_fn_t get_si; */
1282 NOT_IMPLEMENTED, /* vpx_codec_decode_fn_t decode; */
1283 NOT_IMPLEMENTED, /* vpx_codec_frame_get_fn_t frame_get; */
1284 },
1285 {
1286 vp8e_usage_cfg_map, /* vpx_codec_enc_cfg_map_t peek_si; */
1287 vp8e_encode, /* vpx_codec_encode_fn_t encode; */
1288 vp8e_get_cxdata, /* vpx_codec_get_cx_data_fn_t frame_get; */
1289 vp8e_set_config,
1290 NOT_IMPLEMENTED,
1291 vp8e_get_preview,
Yunqing Wangaa7335e2011-10-25 15:14:16 -04001292 vp8e_mr_alloc_mem,
John Koleszar0ea50ce2010-05-18 11:58:33 -04001293 } /* encoder functions */
1294};