OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include <stdlib.h> | 11 #include <stdlib.h> |
12 #include <string.h> | 12 #include <string.h> |
13 | 13 |
14 #include "vpx/vpx_codec.h" | 14 #include "vpx/vpx_codec.h" |
15 #include "vpx/internal/vpx_codec_internal.h" | 15 #include "vpx/internal/vpx_codec_internal.h" |
16 #include "./vpx_version.h" | 16 #include "./vpx_version.h" |
17 #include "vp9/encoder/vp9_onyx_int.h" | 17 #include "vp9/encoder/vp9_onyx_int.h" |
18 #include "vpx/vp8cx.h" | 18 #include "vpx/vp8cx.h" |
19 #include "vp9/encoder/vp9_firstpass.h" | 19 #include "vp9/encoder/vp9_firstpass.h" |
20 #include "vp9/common/vp9_onyx.h" | |
21 #include "vp9/vp9_iface_common.h" | 20 #include "vp9/vp9_iface_common.h" |
22 | 21 |
23 struct vp9_extracfg { | 22 struct vp9_extracfg { |
24 struct vpx_codec_pkt_list *pkt_list; | 23 struct vpx_codec_pkt_list *pkt_list; |
25 int cpu_used; /* available cpu percentage in 1/16 */ | 24 int cpu_used; // available cpu percentage in 1/16 |
26 unsigned int enable_auto_alt_ref; | 25 unsigned int enable_auto_alt_ref; |
27 unsigned int noise_sensitivity; | 26 unsigned int noise_sensitivity; |
28 unsigned int sharpness; | 27 unsigned int sharpness; |
29 unsigned int static_thresh; | 28 unsigned int static_thresh; |
30 unsigned int tile_columns; | 29 unsigned int tile_columns; |
31 unsigned int tile_rows; | 30 unsigned int tile_rows; |
32 unsigned int arnr_max_frames; | 31 unsigned int arnr_max_frames; |
33 unsigned int arnr_strength; | 32 unsigned int arnr_strength; |
34 unsigned int arnr_type; | 33 unsigned int arnr_type; |
35 vp8e_tuning tuning; | 34 vp8e_tuning tuning; |
36 unsigned int cq_level; /* constrained quality level */ | 35 unsigned int cq_level; // constrained quality level |
37 unsigned int rc_max_intra_bitrate_pct; | 36 unsigned int rc_max_intra_bitrate_pct; |
38 unsigned int lossless; | 37 unsigned int lossless; |
39 unsigned int frame_parallel_decoding_mode; | 38 unsigned int frame_parallel_decoding_mode; |
40 unsigned int aq_mode; | 39 AQ_MODE aq_mode; |
| 40 unsigned int frame_periodic_boost; |
| 41 BIT_DEPTH bit_depth; |
41 }; | 42 }; |
42 | 43 |
43 struct extraconfig_map { | 44 struct extraconfig_map { |
44 int usage; | 45 int usage; |
45 struct vp9_extracfg cfg; | 46 struct vp9_extracfg cfg; |
46 }; | 47 }; |
47 | 48 |
48 static const struct extraconfig_map extracfg_map[] = { | 49 static const struct extraconfig_map extracfg_map[] = { |
49 { | 50 { |
50 0, | 51 0, |
51 { // NOLINT | 52 { // NOLINT |
52 NULL, | 53 NULL, |
53 0, /* cpu_used */ | 54 0, // cpu_used |
54 1, /* enable_auto_alt_ref */ | 55 1, // enable_auto_alt_ref |
55 0, /* noise_sensitivity */ | 56 0, // noise_sensitivity |
56 0, /* sharpness */ | 57 0, // sharpness |
57 0, /* static_thresh */ | 58 0, // static_thresh |
58 0, /* tile_columns */ | 59 0, // tile_columns |
59 0, /* tile_rows */ | 60 0, // tile_rows |
60 7, /* arnr_max_frames */ | 61 7, // arnr_max_frames |
61 5, /* arnr_strength */ | 62 5, // arnr_strength |
62 3, /* arnr_type*/ | 63 3, // arnr_type |
63 0, /* tuning*/ | 64 VP8_TUNE_PSNR, // tuning |
64 10, /* cq_level */ | 65 10, // cq_level |
65 0, /* rc_max_intra_bitrate_pct */ | 66 0, // rc_max_intra_bitrate_pct |
66 0, /* lossless */ | 67 0, // lossless |
67 0, /* frame_parallel_decoding_mode */ | 68 0, // frame_parallel_decoding_mode |
68 0, /* aq_mode */ | 69 NO_AQ, // aq_mode |
| 70 0, // frame_periodic_delta_q |
| 71 BITS_8, // Bit depth |
69 } | 72 } |
70 } | 73 } |
71 }; | 74 }; |
72 | 75 |
73 struct vpx_codec_alg_priv { | 76 struct vpx_codec_alg_priv { |
74 vpx_codec_priv_t base; | 77 vpx_codec_priv_t base; |
75 vpx_codec_enc_cfg_t cfg; | 78 vpx_codec_enc_cfg_t cfg; |
76 struct vp9_extracfg vp8_cfg; | 79 struct vp9_extracfg extra_cfg; |
77 VP9_CONFIG oxcf; | 80 VP9_CONFIG oxcf; |
78 VP9_PTR cpi; | 81 VP9_COMP *cpi; |
79 unsigned char *cx_data; | 82 unsigned char *cx_data; |
80 size_t cx_data_sz; | 83 size_t cx_data_sz; |
81 unsigned char *pending_cx_data; | 84 unsigned char *pending_cx_data; |
82 size_t pending_cx_data_sz; | 85 size_t pending_cx_data_sz; |
83 int pending_frame_count; | 86 int pending_frame_count; |
84 size_t pending_frame_sizes[8]; | 87 size_t pending_frame_sizes[8]; |
85 size_t pending_frame_magnitude; | 88 size_t pending_frame_magnitude; |
86 vpx_image_t preview_img; | 89 vpx_image_t preview_img; |
87 vp8_postproc_cfg_t preview_ppcfg; | 90 vp8_postproc_cfg_t preview_ppcfg; |
88 vpx_codec_pkt_list_decl(64) pkt_list; | 91 vpx_codec_pkt_list_decl(64) pkt_list; |
89 unsigned int fixed_kf_cntr; | 92 unsigned int fixed_kf_cntr; |
90 }; | 93 }; |
91 | 94 |
92 static VP9_REFFRAME ref_frame_to_vp9_reframe(vpx_ref_frame_type_t frame) { | 95 static VP9_REFFRAME ref_frame_to_vp9_reframe(vpx_ref_frame_type_t frame) { |
93 switch (frame) { | 96 switch (frame) { |
94 case VP8_LAST_FRAME: | 97 case VP8_LAST_FRAME: |
95 return VP9_LAST_FLAG; | 98 return VP9_LAST_FLAG; |
96 case VP8_GOLD_FRAME: | 99 case VP8_GOLD_FRAME: |
97 return VP9_GOLD_FLAG; | 100 return VP9_GOLD_FLAG; |
98 case VP8_ALTR_FRAME: | 101 case VP8_ALTR_FRAME: |
99 return VP9_ALT_FLAG; | 102 return VP9_ALT_FLAG; |
100 } | 103 } |
101 assert(0 && "Invalid Reference Frame"); | 104 assert(0 && "Invalid Reference Frame"); |
102 return VP9_LAST_FLAG; | 105 return VP9_LAST_FLAG; |
103 } | 106 } |
104 | 107 |
105 static vpx_codec_err_t | 108 static vpx_codec_err_t update_error_state(vpx_codec_alg_priv_t *ctx, |
106 update_error_state(vpx_codec_alg_priv_t *ctx, | 109 const struct vpx_internal_error_info *error) { |
107 const struct vpx_internal_error_info *error) { | 110 const vpx_codec_err_t res = error->error_code; |
108 vpx_codec_err_t res; | |
109 | 111 |
110 if ((res = error->error_code)) | 112 if (res != VPX_CODEC_OK) |
111 ctx->base.err_detail = error->has_detail | 113 ctx->base.err_detail = error->has_detail ? error->detail : NULL; |
112 ? error->detail | |
113 : NULL; | |
114 | 114 |
115 return res; | 115 return res; |
116 } | 116 } |
117 | 117 |
118 | 118 |
119 #undef ERROR | 119 #undef ERROR |
120 #define ERROR(str) do {\ | 120 #define ERROR(str) do {\ |
121 ctx->base.err_detail = str;\ | 121 ctx->base.err_detail = str;\ |
122 return VPX_CODEC_INVALID_PARAM;\ | 122 return VPX_CODEC_INVALID_PARAM;\ |
123 } while (0) | 123 } while (0) |
(...skipping 10 matching lines...) Expand all Loading... |
134 | 134 |
135 #define RANGE_CHECK_LO(p, memb, lo) do {\ | 135 #define RANGE_CHECK_LO(p, memb, lo) do {\ |
136 if (!((p)->memb >= (lo))) \ | 136 if (!((p)->memb >= (lo))) \ |
137 ERROR(#memb " out of range ["#lo"..]");\ | 137 ERROR(#memb " out of range ["#lo"..]");\ |
138 } while (0) | 138 } while (0) |
139 | 139 |
140 #define RANGE_CHECK_BOOL(p, memb) do {\ | 140 #define RANGE_CHECK_BOOL(p, memb) do {\ |
141 if (!!((p)->memb) != (p)->memb) ERROR(#memb " expected boolean");\ | 141 if (!!((p)->memb) != (p)->memb) ERROR(#memb " expected boolean");\ |
142 } while (0) | 142 } while (0) |
143 | 143 |
144 static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx, | 144 static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx, |
145 const vpx_codec_enc_cfg_t *cfg, | 145 const vpx_codec_enc_cfg_t *cfg, |
146 const struct vp9_extracfg *vp8_cfg) { | 146 const struct vp9_extracfg *extra_cfg) { |
147 RANGE_CHECK(cfg, g_w, 1, 65535); /* 16 bits available */ | 147 RANGE_CHECK(cfg, g_w, 1, 65535); // 16 bits available |
148 RANGE_CHECK(cfg, g_h, 1, 65535); /* 16 bits available */ | 148 RANGE_CHECK(cfg, g_h, 1, 65535); // 16 bits available |
149 RANGE_CHECK(cfg, g_timebase.den, 1, 1000000000); | 149 RANGE_CHECK(cfg, g_timebase.den, 1, 1000000000); |
150 RANGE_CHECK(cfg, g_timebase.num, 1, cfg->g_timebase.den); | 150 RANGE_CHECK(cfg, g_timebase.num, 1, cfg->g_timebase.den); |
151 RANGE_CHECK_HI(cfg, g_profile, 3); | 151 RANGE_CHECK_HI(cfg, g_profile, 3); |
152 | 152 |
153 RANGE_CHECK_HI(cfg, rc_max_quantizer, 63); | 153 RANGE_CHECK_HI(cfg, rc_max_quantizer, 63); |
154 RANGE_CHECK_HI(cfg, rc_min_quantizer, cfg->rc_max_quantizer); | 154 RANGE_CHECK_HI(cfg, rc_min_quantizer, cfg->rc_max_quantizer); |
155 RANGE_CHECK_BOOL(vp8_cfg, lossless); | 155 RANGE_CHECK_BOOL(extra_cfg, lossless); |
156 if (vp8_cfg->lossless) { | 156 RANGE_CHECK(extra_cfg, aq_mode, 0, AQ_MODE_COUNT - 1); |
157 RANGE_CHECK_HI(cfg, rc_max_quantizer, 0); | 157 RANGE_CHECK(extra_cfg, frame_periodic_boost, 0, 1); |
158 RANGE_CHECK_HI(cfg, rc_min_quantizer, 0); | |
159 } | |
160 RANGE_CHECK(vp8_cfg, aq_mode, 0, AQ_MODES_COUNT - 1); | |
161 | |
162 RANGE_CHECK_HI(cfg, g_threads, 64); | 158 RANGE_CHECK_HI(cfg, g_threads, 64); |
163 RANGE_CHECK_HI(cfg, g_lag_in_frames, MAX_LAG_BUFFERS); | 159 RANGE_CHECK_HI(cfg, g_lag_in_frames, MAX_LAG_BUFFERS); |
164 RANGE_CHECK(cfg, rc_end_usage, VPX_VBR, VPX_Q); | 160 RANGE_CHECK(cfg, rc_end_usage, VPX_VBR, VPX_Q); |
165 RANGE_CHECK_HI(cfg, rc_undershoot_pct, 1000); | 161 RANGE_CHECK_HI(cfg, rc_undershoot_pct, 1000); |
166 RANGE_CHECK_HI(cfg, rc_overshoot_pct, 1000); | 162 RANGE_CHECK_HI(cfg, rc_overshoot_pct, 1000); |
167 RANGE_CHECK_HI(cfg, rc_2pass_vbr_bias_pct, 100); | 163 RANGE_CHECK_HI(cfg, rc_2pass_vbr_bias_pct, 100); |
168 RANGE_CHECK(cfg, kf_mode, VPX_KF_DISABLED, VPX_KF_AUTO); | 164 RANGE_CHECK(cfg, kf_mode, VPX_KF_DISABLED, VPX_KF_AUTO); |
169 // RANGE_CHECK_BOOL(cfg, g_delete_firstpassfile); | |
170 RANGE_CHECK_BOOL(cfg, rc_resize_allowed); | 165 RANGE_CHECK_BOOL(cfg, rc_resize_allowed); |
171 RANGE_CHECK_HI(cfg, rc_dropframe_thresh, 100); | 166 RANGE_CHECK_HI(cfg, rc_dropframe_thresh, 100); |
172 RANGE_CHECK_HI(cfg, rc_resize_up_thresh, 100); | 167 RANGE_CHECK_HI(cfg, rc_resize_up_thresh, 100); |
173 RANGE_CHECK_HI(cfg, rc_resize_down_thresh, 100); | 168 RANGE_CHECK_HI(cfg, rc_resize_down_thresh, 100); |
174 RANGE_CHECK(cfg, g_pass, VPX_RC_ONE_PASS, VPX_RC_LAST_PASS); | 169 RANGE_CHECK(cfg, g_pass, VPX_RC_ONE_PASS, VPX_RC_LAST_PASS); |
175 | 170 |
176 RANGE_CHECK(cfg, ss_number_layers, 1, | 171 RANGE_CHECK(cfg, ss_number_layers, 1, VPX_SS_MAX_LAYERS); |
177 VPX_SS_MAX_LAYERS); /*Spatial layers max */ | |
178 | |
179 RANGE_CHECK(cfg, ts_number_layers, 1, VPX_TS_MAX_LAYERS); | 172 RANGE_CHECK(cfg, ts_number_layers, 1, VPX_TS_MAX_LAYERS); |
180 if (cfg->ts_number_layers > 1) { | 173 if (cfg->ts_number_layers > 1) { |
181 unsigned int i; | 174 unsigned int i; |
182 for (i = 1; i < cfg->ts_number_layers; ++i) { | 175 for (i = 1; i < cfg->ts_number_layers; ++i) |
183 if (cfg->ts_target_bitrate[i] < cfg->ts_target_bitrate[i-1]) { | 176 if (cfg->ts_target_bitrate[i] < cfg->ts_target_bitrate[i - 1]) |
184 ERROR("ts_target_bitrate entries are not increasing"); | 177 ERROR("ts_target_bitrate entries are not increasing"); |
185 } | 178 |
186 } | 179 RANGE_CHECK(cfg, ts_rate_decimator[cfg->ts_number_layers - 1], 1, 1); |
187 RANGE_CHECK(cfg, ts_rate_decimator[cfg->ts_number_layers-1], 1, 1); | 180 for (i = cfg->ts_number_layers - 2; i > 0; --i) |
188 for (i = cfg->ts_number_layers-2; i > 0; --i) { | 181 if (cfg->ts_rate_decimator[i - 1] != 2 * cfg->ts_rate_decimator[i]) |
189 if (cfg->ts_rate_decimator[i-1] != 2*cfg->ts_rate_decimator[i]) { | |
190 ERROR("ts_rate_decimator factors are not powers of 2"); | 182 ERROR("ts_rate_decimator factors are not powers of 2"); |
191 } | |
192 } | |
193 } | 183 } |
194 | 184 |
195 /* VP8 does not support a lower bound on the keyframe interval in | 185 // VP8 does not support a lower bound on the keyframe interval in |
196 * automatic keyframe placement mode. | 186 // automatic keyframe placement mode. |
197 */ | 187 if (cfg->kf_mode != VPX_KF_DISABLED && |
198 if (cfg->kf_mode != VPX_KF_DISABLED && cfg->kf_min_dist != cfg->kf_max_dist | 188 cfg->kf_min_dist != cfg->kf_max_dist && |
199 && cfg->kf_min_dist > 0) | 189 cfg->kf_min_dist > 0) |
200 ERROR("kf_min_dist not supported in auto mode, use 0 " | 190 ERROR("kf_min_dist not supported in auto mode, use 0 " |
201 "or kf_max_dist instead."); | 191 "or kf_max_dist instead."); |
202 | 192 |
203 RANGE_CHECK_BOOL(vp8_cfg, enable_auto_alt_ref); | 193 RANGE_CHECK_BOOL(extra_cfg, enable_auto_alt_ref); |
204 RANGE_CHECK(vp8_cfg, cpu_used, -16, 16); | 194 RANGE_CHECK(extra_cfg, cpu_used, -16, 16); |
205 | 195 RANGE_CHECK_HI(extra_cfg, noise_sensitivity, 6); |
206 RANGE_CHECK_HI(vp8_cfg, noise_sensitivity, 6); | 196 RANGE_CHECK(extra_cfg, tile_columns, 0, 6); |
207 | 197 RANGE_CHECK(extra_cfg, tile_rows, 0, 2); |
208 RANGE_CHECK(vp8_cfg, tile_columns, 0, 6); | 198 RANGE_CHECK_HI(extra_cfg, sharpness, 7); |
209 RANGE_CHECK(vp8_cfg, tile_rows, 0, 2); | 199 RANGE_CHECK(extra_cfg, arnr_max_frames, 0, 15); |
210 RANGE_CHECK_HI(vp8_cfg, sharpness, 7); | 200 RANGE_CHECK_HI(extra_cfg, arnr_strength, 6); |
211 RANGE_CHECK(vp8_cfg, arnr_max_frames, 0, 15); | 201 RANGE_CHECK(extra_cfg, arnr_type, 1, 3); |
212 RANGE_CHECK_HI(vp8_cfg, arnr_strength, 6); | 202 RANGE_CHECK(extra_cfg, cq_level, 0, 63); |
213 RANGE_CHECK(vp8_cfg, arnr_type, 1, 3); | |
214 RANGE_CHECK(vp8_cfg, cq_level, 0, 63); | |
215 | 203 |
216 // TODO(yaowu): remove this when ssim tuning is implemented for vp9 | 204 // TODO(yaowu): remove this when ssim tuning is implemented for vp9 |
217 if (vp8_cfg->tuning == VP8_TUNE_SSIM) | 205 if (extra_cfg->tuning == VP8_TUNE_SSIM) |
218 ERROR("Option --tune=ssim is not currently supported in VP9."); | 206 ERROR("Option --tune=ssim is not currently supported in VP9."); |
219 | 207 |
220 if (cfg->g_pass == VPX_RC_LAST_PASS) { | 208 if (cfg->g_pass == VPX_RC_LAST_PASS) { |
221 size_t packet_sz = sizeof(FIRSTPASS_STATS); | 209 size_t packet_sz = sizeof(FIRSTPASS_STATS); |
222 int n_packets = (int)(cfg->rc_twopass_stats_in.sz / packet_sz); | 210 int n_packets = (int)(cfg->rc_twopass_stats_in.sz / packet_sz); |
223 FIRSTPASS_STATS *stats; | 211 const FIRSTPASS_STATS *stats; |
224 | 212 |
225 if (cfg->rc_twopass_stats_in.buf == NULL) | 213 if (cfg->rc_twopass_stats_in.buf == NULL) |
226 ERROR("rc_twopass_stats_in.buf not set."); | 214 ERROR("rc_twopass_stats_in.buf not set."); |
227 | 215 |
228 if (cfg->rc_twopass_stats_in.sz % packet_sz) | 216 if (cfg->rc_twopass_stats_in.sz % packet_sz) |
229 ERROR("rc_twopass_stats_in.sz indicates truncated packet."); | 217 ERROR("rc_twopass_stats_in.sz indicates truncated packet."); |
230 | 218 |
231 if (cfg->rc_twopass_stats_in.sz < 2 * packet_sz) | 219 if (cfg->ss_number_layers > 1) { |
232 ERROR("rc_twopass_stats_in requires at least two packets."); | 220 int i; |
| 221 unsigned int n_packets_per_layer[VPX_SS_MAX_LAYERS] = {0}; |
233 | 222 |
234 stats = (void *)((char *)cfg->rc_twopass_stats_in.buf | 223 stats = cfg->rc_twopass_stats_in.buf; |
235 + (n_packets - 1) * packet_sz); | 224 for (i = 0; i < n_packets; ++i) { |
| 225 const int layer_id = (int)stats[i].spatial_layer_id; |
| 226 if (layer_id >= 0 && layer_id < (int)cfg->ss_number_layers) { |
| 227 ++n_packets_per_layer[layer_id]; |
| 228 } |
| 229 } |
236 | 230 |
237 if ((int)(stats->count + 0.5) != n_packets - 1) | 231 for (i = 0; i < (int)cfg->ss_number_layers; ++i) { |
238 ERROR("rc_twopass_stats_in missing EOS stats packet"); | 232 unsigned int layer_id; |
| 233 if (n_packets_per_layer[i] < 2) { |
| 234 ERROR("rc_twopass_stats_in requires at least two packets for each " |
| 235 "layer."); |
| 236 } |
| 237 |
| 238 stats = (const FIRSTPASS_STATS *)cfg->rc_twopass_stats_in.buf + |
| 239 n_packets - cfg->ss_number_layers + i; |
| 240 layer_id = (int)stats->spatial_layer_id; |
| 241 |
| 242 if (layer_id >= cfg->ss_number_layers |
| 243 ||(int)(stats->count + 0.5) != n_packets_per_layer[layer_id] - 1) |
| 244 ERROR("rc_twopass_stats_in missing EOS stats packet"); |
| 245 } |
| 246 } else { |
| 247 if (cfg->rc_twopass_stats_in.sz < 2 * packet_sz) |
| 248 ERROR("rc_twopass_stats_in requires at least two packets."); |
| 249 |
| 250 stats = |
| 251 (const FIRSTPASS_STATS *)cfg->rc_twopass_stats_in.buf + n_packets - 1; |
| 252 |
| 253 if ((int)(stats->count + 0.5) != n_packets - 1) |
| 254 ERROR("rc_twopass_stats_in missing EOS stats packet"); |
| 255 } |
239 } | 256 } |
| 257 if (cfg->g_profile <= (unsigned int)PROFILE_1 && |
| 258 extra_cfg->bit_depth > BITS_8) |
| 259 ERROR("High bit-depth not supported in profile < 2"); |
| 260 if (cfg->g_profile > (unsigned int)PROFILE_1 && |
| 261 extra_cfg->bit_depth == BITS_8) |
| 262 ERROR("Bit-depth 8 not supported in profile > 1"); |
240 | 263 |
241 return VPX_CODEC_OK; | 264 return VPX_CODEC_OK; |
242 } | 265 } |
243 | 266 |
244 | 267 |
245 static vpx_codec_err_t validate_img(vpx_codec_alg_priv_t *ctx, | 268 static vpx_codec_err_t validate_img(vpx_codec_alg_priv_t *ctx, |
246 const vpx_image_t *img) { | 269 const vpx_image_t *img) { |
247 switch (img->fmt) { | 270 switch (img->fmt) { |
248 case VPX_IMG_FMT_YV12: | 271 case VPX_IMG_FMT_YV12: |
249 case VPX_IMG_FMT_I420: | 272 case VPX_IMG_FMT_I420: |
250 case VPX_IMG_FMT_I422: | 273 case VPX_IMG_FMT_I422: |
251 case VPX_IMG_FMT_I444: | 274 case VPX_IMG_FMT_I444: |
252 break; | 275 break; |
253 default: | 276 default: |
254 ERROR("Invalid image format. Only YV12, I420, I422, I444 images are " | 277 ERROR("Invalid image format. Only YV12, I420, I422, I444 images are " |
255 "supported."); | 278 "supported."); |
256 } | 279 } |
257 | 280 |
258 if ((img->d_w != ctx->cfg.g_w) || (img->d_h != ctx->cfg.g_h)) | 281 if (img->d_w != ctx->cfg.g_w || img->d_h != ctx->cfg.g_h) |
259 ERROR("Image size must match encoder init configuration size"); | 282 ERROR("Image size must match encoder init configuration size"); |
260 | 283 |
261 return VPX_CODEC_OK; | 284 return VPX_CODEC_OK; |
262 } | 285 } |
263 | 286 |
264 | 287 |
265 static vpx_codec_err_t set_vp9e_config(VP9_CONFIG *oxcf, | 288 static vpx_codec_err_t set_encoder_config( |
266 vpx_codec_enc_cfg_t cfg, | 289 VP9_CONFIG *oxcf, |
267 struct vp9_extracfg vp9_cfg) { | 290 const vpx_codec_enc_cfg_t *cfg, |
268 oxcf->version = cfg.g_profile; | 291 const struct vp9_extracfg *extra_cfg) { |
269 oxcf->width = cfg.g_w; | 292 oxcf->profile = cfg->g_profile; |
270 oxcf->height = cfg.g_h; | 293 oxcf->width = cfg->g_w; |
271 /* guess a frame rate if out of whack, use 30 */ | 294 oxcf->height = cfg->g_h; |
272 oxcf->framerate = (double)(cfg.g_timebase.den) | 295 oxcf->bit_depth = extra_cfg->bit_depth; |
273 / (double)(cfg.g_timebase.num); | 296 // guess a frame rate if out of whack, use 30 |
| 297 oxcf->framerate = (double)cfg->g_timebase.den / cfg->g_timebase.num; |
| 298 if (oxcf->framerate > 180) |
| 299 oxcf->framerate = 30; |
274 | 300 |
275 if (oxcf->framerate > 180) { | 301 switch (cfg->g_pass) { |
276 oxcf->framerate = 30; | |
277 } | |
278 | |
279 switch (cfg.g_pass) { | |
280 case VPX_RC_ONE_PASS: | 302 case VPX_RC_ONE_PASS: |
281 oxcf->mode = MODE_GOODQUALITY; | 303 oxcf->mode = MODE_GOODQUALITY; |
282 break; | 304 break; |
283 case VPX_RC_FIRST_PASS: | 305 case VPX_RC_FIRST_PASS: |
284 oxcf->mode = MODE_FIRSTPASS; | 306 oxcf->mode = MODE_FIRSTPASS; |
285 break; | 307 break; |
286 case VPX_RC_LAST_PASS: | 308 case VPX_RC_LAST_PASS: |
287 oxcf->mode = MODE_SECONDPASS_BEST; | 309 oxcf->mode = MODE_SECONDPASS_BEST; |
288 break; | 310 break; |
289 } | 311 } |
290 | 312 |
291 if (cfg.g_pass == VPX_RC_FIRST_PASS) { | 313 oxcf->lag_in_frames = cfg->g_pass == VPX_RC_FIRST_PASS ? 0 |
292 oxcf->lag_in_frames = 0; | 314 : cfg->g_lag_in_frames; |
293 } else { | |
294 oxcf->lag_in_frames = cfg.g_lag_in_frames; | |
295 } | |
296 | 315 |
297 oxcf->end_usage = USAGE_LOCAL_FILE_PLAYBACK; | 316 oxcf->end_usage = USAGE_LOCAL_FILE_PLAYBACK; |
298 if (cfg.rc_end_usage == VPX_CQ) | 317 if (cfg->rc_end_usage == VPX_CQ) |
299 oxcf->end_usage = USAGE_CONSTRAINED_QUALITY; | 318 oxcf->end_usage = USAGE_CONSTRAINED_QUALITY; |
300 else if (cfg.rc_end_usage == VPX_Q) | 319 else if (cfg->rc_end_usage == VPX_Q) |
301 oxcf->end_usage = USAGE_CONSTANT_QUALITY; | 320 oxcf->end_usage = USAGE_CONSTANT_QUALITY; |
302 else if (cfg.rc_end_usage == VPX_CBR) | 321 else if (cfg->rc_end_usage == VPX_CBR) |
303 oxcf->end_usage = USAGE_STREAM_FROM_SERVER; | 322 oxcf->end_usage = USAGE_STREAM_FROM_SERVER; |
304 | 323 |
305 oxcf->target_bandwidth = cfg.rc_target_bitrate; | 324 oxcf->target_bandwidth = cfg->rc_target_bitrate; |
306 oxcf->rc_max_intra_bitrate_pct = vp9_cfg.rc_max_intra_bitrate_pct; | 325 oxcf->rc_max_intra_bitrate_pct = extra_cfg->rc_max_intra_bitrate_pct; |
307 | 326 |
308 oxcf->best_allowed_q = cfg.rc_min_quantizer; | 327 oxcf->best_allowed_q = vp9_quantizer_to_qindex(cfg->rc_min_quantizer); |
309 oxcf->worst_allowed_q = cfg.rc_max_quantizer; | 328 oxcf->worst_allowed_q = vp9_quantizer_to_qindex(cfg->rc_max_quantizer); |
310 oxcf->cq_level = vp9_cfg.cq_level; | 329 oxcf->cq_level = vp9_quantizer_to_qindex(extra_cfg->cq_level); |
311 oxcf->fixed_q = -1; | 330 oxcf->fixed_q = -1; |
312 | 331 |
313 oxcf->under_shoot_pct = cfg.rc_undershoot_pct; | 332 oxcf->under_shoot_pct = cfg->rc_undershoot_pct; |
314 oxcf->over_shoot_pct = cfg.rc_overshoot_pct; | 333 oxcf->over_shoot_pct = cfg->rc_overshoot_pct; |
315 | 334 |
316 oxcf->maximum_buffer_size = cfg.rc_buf_sz; | 335 oxcf->maximum_buffer_size = cfg->rc_buf_sz; |
317 oxcf->starting_buffer_level = cfg.rc_buf_initial_sz; | 336 oxcf->starting_buffer_level = cfg->rc_buf_initial_sz; |
318 oxcf->optimal_buffer_level = cfg.rc_buf_optimal_sz; | 337 oxcf->optimal_buffer_level = cfg->rc_buf_optimal_sz; |
319 | 338 |
320 oxcf->drop_frames_water_mark = cfg.rc_dropframe_thresh; | 339 oxcf->drop_frames_water_mark = cfg->rc_dropframe_thresh; |
321 | 340 |
322 oxcf->two_pass_vbrbias = cfg.rc_2pass_vbr_bias_pct; | 341 oxcf->two_pass_vbrbias = cfg->rc_2pass_vbr_bias_pct; |
323 oxcf->two_pass_vbrmin_section = cfg.rc_2pass_vbr_minsection_pct; | 342 oxcf->two_pass_vbrmin_section = cfg->rc_2pass_vbr_minsection_pct; |
324 oxcf->two_pass_vbrmax_section = cfg.rc_2pass_vbr_maxsection_pct; | 343 oxcf->two_pass_vbrmax_section = cfg->rc_2pass_vbr_maxsection_pct; |
325 | 344 |
326 oxcf->auto_key = cfg.kf_mode == VPX_KF_AUTO | 345 oxcf->auto_key = cfg->kf_mode == VPX_KF_AUTO && |
327 && cfg.kf_min_dist != cfg.kf_max_dist; | 346 cfg->kf_min_dist != cfg->kf_max_dist; |
328 // oxcf->kf_min_dist = cfg.kf_min_dis; | |
329 oxcf->key_freq = cfg.kf_max_dist; | |
330 | 347 |
331 oxcf->cpu_used = vp9_cfg.cpu_used; | 348 oxcf->key_freq = cfg->kf_max_dist; |
332 oxcf->encode_breakout = vp9_cfg.static_thresh; | |
333 oxcf->play_alternate = vp9_cfg.enable_auto_alt_ref; | |
334 oxcf->noise_sensitivity = vp9_cfg.noise_sensitivity; | |
335 oxcf->sharpness = vp9_cfg.sharpness; | |
336 | 349 |
337 oxcf->two_pass_stats_in = cfg.rc_twopass_stats_in; | 350 oxcf->cpu_used = extra_cfg->cpu_used; |
338 oxcf->output_pkt_list = vp9_cfg.pkt_list; | 351 oxcf->encode_breakout = extra_cfg->static_thresh; |
| 352 oxcf->play_alternate = extra_cfg->enable_auto_alt_ref; |
| 353 oxcf->noise_sensitivity = extra_cfg->noise_sensitivity; |
| 354 oxcf->sharpness = extra_cfg->sharpness; |
339 | 355 |
340 oxcf->arnr_max_frames = vp9_cfg.arnr_max_frames; | 356 oxcf->two_pass_stats_in = cfg->rc_twopass_stats_in; |
341 oxcf->arnr_strength = vp9_cfg.arnr_strength; | 357 oxcf->output_pkt_list = extra_cfg->pkt_list; |
342 oxcf->arnr_type = vp9_cfg.arnr_type; | |
343 | 358 |
344 oxcf->tuning = vp9_cfg.tuning; | 359 oxcf->arnr_max_frames = extra_cfg->arnr_max_frames; |
| 360 oxcf->arnr_strength = extra_cfg->arnr_strength; |
| 361 oxcf->arnr_type = extra_cfg->arnr_type; |
345 | 362 |
346 oxcf->tile_columns = vp9_cfg.tile_columns; | 363 oxcf->tuning = extra_cfg->tuning; |
347 oxcf->tile_rows = vp9_cfg.tile_rows; | |
348 | 364 |
349 oxcf->lossless = vp9_cfg.lossless; | 365 oxcf->tile_columns = extra_cfg->tile_columns; |
| 366 oxcf->tile_rows = extra_cfg->tile_rows; |
350 | 367 |
351 oxcf->error_resilient_mode = cfg.g_error_resilient; | 368 oxcf->lossless = extra_cfg->lossless; |
352 oxcf->frame_parallel_decoding_mode = vp9_cfg.frame_parallel_decoding_mode; | |
353 | 369 |
354 oxcf->aq_mode = vp9_cfg.aq_mode; | 370 oxcf->error_resilient_mode = cfg->g_error_resilient; |
| 371 oxcf->frame_parallel_decoding_mode = extra_cfg->frame_parallel_decoding_mode; |
355 | 372 |
356 oxcf->ss_number_layers = cfg.ss_number_layers; | 373 oxcf->aq_mode = extra_cfg->aq_mode; |
| 374 |
| 375 oxcf->frame_periodic_boost = extra_cfg->frame_periodic_boost; |
| 376 |
| 377 oxcf->ss_number_layers = cfg->ss_number_layers; |
357 | 378 |
358 if (oxcf->ss_number_layers > 1) { | 379 if (oxcf->ss_number_layers > 1) { |
359 memcpy(oxcf->ss_target_bitrate, cfg.ss_target_bitrate, | 380 vp9_copy(oxcf->ss_target_bitrate, cfg->ss_target_bitrate); |
360 sizeof(cfg.ss_target_bitrate)); | |
361 } else if (oxcf->ss_number_layers == 1) { | 381 } else if (oxcf->ss_number_layers == 1) { |
362 oxcf->ss_target_bitrate[0] = (int)oxcf->target_bandwidth; | 382 oxcf->ss_target_bitrate[0] = (int)oxcf->target_bandwidth; |
363 } | 383 } |
364 | 384 |
365 oxcf->ts_number_layers = cfg.ts_number_layers; | 385 oxcf->ts_number_layers = cfg->ts_number_layers; |
366 | 386 |
367 if (oxcf->ts_number_layers > 1) { | 387 if (oxcf->ts_number_layers > 1) { |
368 memcpy(oxcf->ts_target_bitrate, cfg.ts_target_bitrate, | 388 vp9_copy(oxcf->ts_target_bitrate, cfg->ts_target_bitrate); |
369 sizeof(cfg.ts_target_bitrate)); | 389 vp9_copy(oxcf->ts_rate_decimator, cfg->ts_rate_decimator); |
370 memcpy(oxcf->ts_rate_decimator, cfg.ts_rate_decimator, | |
371 sizeof(cfg.ts_rate_decimator)); | |
372 } else if (oxcf->ts_number_layers == 1) { | 390 } else if (oxcf->ts_number_layers == 1) { |
373 oxcf->ts_target_bitrate[0] = (int)oxcf->target_bandwidth; | 391 oxcf->ts_target_bitrate[0] = (int)oxcf->target_bandwidth; |
374 oxcf->ts_rate_decimator[0] = 1; | 392 oxcf->ts_rate_decimator[0] = 1; |
375 } | 393 } |
376 | 394 |
377 /* | 395 /* |
378 printf("Current VP9 Settings: \n"); | 396 printf("Current VP9 Settings: \n"); |
379 printf("target_bandwidth: %d\n", oxcf->target_bandwidth); | 397 printf("target_bandwidth: %d\n", oxcf->target_bandwidth); |
380 printf("noise_sensitivity: %d\n", oxcf->noise_sensitivity); | 398 printf("noise_sensitivity: %d\n", oxcf->noise_sensitivity); |
381 printf("sharpness: %d\n", oxcf->sharpness); | 399 printf("sharpness: %d\n", oxcf->sharpness); |
(...skipping 17 matching lines...) Expand all Loading... |
399 printf("play_alternate: %d\n", oxcf->play_alternate); | 417 printf("play_alternate: %d\n", oxcf->play_alternate); |
400 printf("Version: %d\n", oxcf->Version); | 418 printf("Version: %d\n", oxcf->Version); |
401 printf("encode_breakout: %d\n", oxcf->encode_breakout); | 419 printf("encode_breakout: %d\n", oxcf->encode_breakout); |
402 printf("error resilient: %d\n", oxcf->error_resilient_mode); | 420 printf("error resilient: %d\n", oxcf->error_resilient_mode); |
403 printf("frame parallel detokenization: %d\n", | 421 printf("frame parallel detokenization: %d\n", |
404 oxcf->frame_parallel_decoding_mode); | 422 oxcf->frame_parallel_decoding_mode); |
405 */ | 423 */ |
406 return VPX_CODEC_OK; | 424 return VPX_CODEC_OK; |
407 } | 425 } |
408 | 426 |
409 static vpx_codec_err_t vp9e_set_config(vpx_codec_alg_priv_t *ctx, | 427 static vpx_codec_err_t encoder_set_config(vpx_codec_alg_priv_t *ctx, |
410 const vpx_codec_enc_cfg_t *cfg) { | 428 const vpx_codec_enc_cfg_t *cfg) { |
411 vpx_codec_err_t res; | 429 vpx_codec_err_t res; |
412 | 430 |
413 if ((cfg->g_w != ctx->cfg.g_w) || (cfg->g_h != ctx->cfg.g_h)) | 431 if (cfg->g_w != ctx->cfg.g_w || cfg->g_h != ctx->cfg.g_h) |
414 ERROR("Cannot change width or height after initialization"); | 432 ERROR("Cannot change width or height after initialization"); |
415 | 433 |
416 /* Prevent increasing lag_in_frames. This check is stricter than it needs | 434 // Prevent increasing lag_in_frames. This check is stricter than it needs |
417 * to be -- the limit is not increasing past the first lag_in_frames | 435 // to be -- the limit is not increasing past the first lag_in_frames |
418 * value, but we don't track the initial config, only the last successful | 436 // value, but we don't track the initial config, only the last successful |
419 * config. | 437 // config. |
420 */ | 438 if (cfg->g_lag_in_frames > ctx->cfg.g_lag_in_frames) |
421 if ((cfg->g_lag_in_frames > ctx->cfg.g_lag_in_frames)) | |
422 ERROR("Cannot increase lag_in_frames"); | 439 ERROR("Cannot increase lag_in_frames"); |
423 | 440 |
424 res = validate_config(ctx, cfg, &ctx->vp8_cfg); | 441 res = validate_config(ctx, cfg, &ctx->extra_cfg); |
425 | 442 |
426 if (res == VPX_CODEC_OK) { | 443 if (res == VPX_CODEC_OK) { |
427 ctx->cfg = *cfg; | 444 ctx->cfg = *cfg; |
428 set_vp9e_config(&ctx->oxcf, ctx->cfg, ctx->vp8_cfg); | 445 set_encoder_config(&ctx->oxcf, &ctx->cfg, &ctx->extra_cfg); |
429 vp9_change_config(ctx->cpi, &ctx->oxcf); | 446 vp9_change_config(ctx->cpi, &ctx->oxcf); |
430 } | 447 } |
431 | 448 |
432 return res; | 449 return res; |
433 } | 450 } |
434 | 451 |
435 | 452 static vpx_codec_err_t ctrl_get_param(vpx_codec_alg_priv_t *ctx, int ctrl_id, |
436 int vp9_reverse_trans(int q); | 453 va_list args) { |
437 | |
438 | |
439 static vpx_codec_err_t get_param(vpx_codec_alg_priv_t *ctx, | |
440 int ctrl_id, | |
441 va_list args) { | |
442 void *arg = va_arg(args, void *); | 454 void *arg = va_arg(args, void *); |
443 | 455 |
444 #define MAP(id, var) case id: *(RECAST(id, arg)) = var; break | 456 #define MAP(id, var) case id: *(RECAST(id, arg)) = var; break |
445 | 457 |
446 if (arg == NULL) return VPX_CODEC_INVALID_PARAM; | 458 if (arg == NULL) |
| 459 return VPX_CODEC_INVALID_PARAM; |
447 | 460 |
448 switch (ctrl_id) { | 461 switch (ctrl_id) { |
449 MAP(VP8E_GET_LAST_QUANTIZER, vp9_get_quantizer(ctx->cpi)); | 462 MAP(VP8E_GET_LAST_QUANTIZER, vp9_get_quantizer(ctx->cpi)); |
450 MAP(VP8E_GET_LAST_QUANTIZER_64, | 463 MAP(VP8E_GET_LAST_QUANTIZER_64, |
451 vp9_reverse_trans(vp9_get_quantizer(ctx->cpi))); | 464 vp9_qindex_to_quantizer(vp9_get_quantizer(ctx->cpi))); |
452 } | 465 } |
453 | 466 |
454 return VPX_CODEC_OK; | 467 return VPX_CODEC_OK; |
455 #undef MAP | 468 #undef MAP |
456 } | 469 } |
457 | 470 |
458 | 471 |
459 static vpx_codec_err_t set_param(vpx_codec_alg_priv_t *ctx, | 472 static vpx_codec_err_t ctrl_set_param(vpx_codec_alg_priv_t *ctx, int ctrl_id, |
460 int ctrl_id, | 473 va_list args) { |
461 va_list args) { | 474 vpx_codec_err_t res = VPX_CODEC_OK; |
462 vpx_codec_err_t res = VPX_CODEC_OK; | 475 struct vp9_extracfg extra_cfg = ctx->extra_cfg; |
463 struct vp9_extracfg xcfg = ctx->vp8_cfg; | |
464 | 476 |
465 #define MAP(id, var) case id: var = CAST(id, args); break; | 477 #define MAP(id, var) case id: var = CAST(id, args); break; |
466 | 478 |
467 switch (ctrl_id) { | 479 switch (ctrl_id) { |
468 MAP(VP8E_SET_CPUUSED, xcfg.cpu_used); | 480 MAP(VP8E_SET_CPUUSED, extra_cfg.cpu_used); |
469 MAP(VP8E_SET_ENABLEAUTOALTREF, xcfg.enable_auto_alt_ref); | 481 MAP(VP8E_SET_ENABLEAUTOALTREF, extra_cfg.enable_auto_alt_ref); |
470 MAP(VP8E_SET_NOISE_SENSITIVITY, xcfg.noise_sensitivity); | 482 MAP(VP8E_SET_NOISE_SENSITIVITY, extra_cfg.noise_sensitivity); |
471 MAP(VP8E_SET_SHARPNESS, xcfg.sharpness); | 483 MAP(VP8E_SET_SHARPNESS, extra_cfg.sharpness); |
472 MAP(VP8E_SET_STATIC_THRESHOLD, xcfg.static_thresh); | 484 MAP(VP8E_SET_STATIC_THRESHOLD, extra_cfg.static_thresh); |
473 MAP(VP9E_SET_TILE_COLUMNS, xcfg.tile_columns); | 485 MAP(VP9E_SET_TILE_COLUMNS, extra_cfg.tile_columns); |
474 MAP(VP9E_SET_TILE_ROWS, xcfg.tile_rows); | 486 MAP(VP9E_SET_TILE_ROWS, extra_cfg.tile_rows); |
475 MAP(VP8E_SET_ARNR_MAXFRAMES, xcfg.arnr_max_frames); | 487 MAP(VP8E_SET_ARNR_MAXFRAMES, extra_cfg.arnr_max_frames); |
476 MAP(VP8E_SET_ARNR_STRENGTH, xcfg.arnr_strength); | 488 MAP(VP8E_SET_ARNR_STRENGTH, extra_cfg.arnr_strength); |
477 MAP(VP8E_SET_ARNR_TYPE, xcfg.arnr_type); | 489 MAP(VP8E_SET_ARNR_TYPE, extra_cfg.arnr_type); |
478 MAP(VP8E_SET_TUNING, xcfg.tuning); | 490 MAP(VP8E_SET_TUNING, extra_cfg.tuning); |
479 MAP(VP8E_SET_CQ_LEVEL, xcfg.cq_level); | 491 MAP(VP8E_SET_CQ_LEVEL, extra_cfg.cq_level); |
480 MAP(VP8E_SET_MAX_INTRA_BITRATE_PCT, xcfg.rc_max_intra_bitrate_pct); | 492 MAP(VP8E_SET_MAX_INTRA_BITRATE_PCT, extra_cfg.rc_max_intra_bitrate_pct); |
481 MAP(VP9E_SET_LOSSLESS, xcfg.lossless); | 493 MAP(VP9E_SET_LOSSLESS, extra_cfg.lossless); |
482 MAP(VP9E_SET_FRAME_PARALLEL_DECODING, xcfg.frame_parallel_decoding_mode); | 494 MAP(VP9E_SET_FRAME_PARALLEL_DECODING, |
483 MAP(VP9E_SET_AQ_MODE, xcfg.aq_mode); | 495 extra_cfg.frame_parallel_decoding_mode); |
| 496 MAP(VP9E_SET_AQ_MODE, extra_cfg.aq_mode); |
| 497 MAP(VP9E_SET_FRAME_PERIODIC_BOOST, extra_cfg.frame_periodic_boost); |
484 } | 498 } |
485 | 499 |
486 res = validate_config(ctx, &ctx->cfg, &xcfg); | 500 res = validate_config(ctx, &ctx->cfg, &extra_cfg); |
487 | 501 |
488 if (res == VPX_CODEC_OK) { | 502 if (res == VPX_CODEC_OK) { |
489 ctx->vp8_cfg = xcfg; | 503 ctx->extra_cfg = extra_cfg; |
490 set_vp9e_config(&ctx->oxcf, ctx->cfg, ctx->vp8_cfg); | 504 set_encoder_config(&ctx->oxcf, &ctx->cfg, &ctx->extra_cfg); |
491 vp9_change_config(ctx->cpi, &ctx->oxcf); | 505 vp9_change_config(ctx->cpi, &ctx->oxcf); |
492 } | 506 } |
493 | 507 |
494 return res; | 508 return res; |
495 #undef MAP | 509 #undef MAP |
496 } | 510 } |
497 | 511 |
498 | 512 static vpx_codec_err_t encoder_common_init(vpx_codec_ctx_t *ctx) { |
499 static vpx_codec_err_t vp9e_common_init(vpx_codec_ctx_t *ctx) { | 513 vpx_codec_err_t res = VPX_CODEC_OK; |
500 vpx_codec_err_t res = VPX_CODEC_OK; | |
501 struct vpx_codec_alg_priv *priv; | |
502 vpx_codec_enc_cfg_t *cfg; | |
503 unsigned int i; | |
504 | |
505 VP9_PTR optr; | |
506 | 514 |
507 if (ctx->priv == NULL) { | 515 if (ctx->priv == NULL) { |
508 priv = calloc(1, sizeof(struct vpx_codec_alg_priv)); | 516 int i; |
| 517 vpx_codec_enc_cfg_t *cfg; |
| 518 struct vpx_codec_alg_priv *priv = calloc(1, sizeof(*priv)); |
509 | 519 |
510 if (priv == NULL) return VPX_CODEC_MEM_ERROR; | 520 if (priv == NULL) return VPX_CODEC_MEM_ERROR; |
511 | 521 |
512 ctx->priv = &priv->base; | 522 ctx->priv = &priv->base; |
513 ctx->priv->sz = sizeof(*ctx->priv); | 523 ctx->priv->sz = sizeof(*ctx->priv); |
514 ctx->priv->iface = ctx->iface; | 524 ctx->priv->iface = ctx->iface; |
515 ctx->priv->alg_priv = priv; | 525 ctx->priv->alg_priv = priv; |
516 ctx->priv->init_flags = ctx->init_flags; | 526 ctx->priv->init_flags = ctx->init_flags; |
517 ctx->priv->enc.total_encoders = 1; | 527 ctx->priv->enc.total_encoders = 1; |
518 | 528 |
519 if (ctx->config.enc) { | 529 if (ctx->config.enc) { |
520 /* Update the reference to the config structure to an | 530 // Update the reference to the config structure to an |
521 * internal copy. | 531 // internal copy. |
522 */ | |
523 ctx->priv->alg_priv->cfg = *ctx->config.enc; | 532 ctx->priv->alg_priv->cfg = *ctx->config.enc; |
524 ctx->config.enc = &ctx->priv->alg_priv->cfg; | 533 ctx->config.enc = &ctx->priv->alg_priv->cfg; |
525 } | 534 } |
526 | 535 |
527 cfg = &ctx->priv->alg_priv->cfg; | 536 cfg = &ctx->priv->alg_priv->cfg; |
528 | 537 |
529 /* Select the extra vp6 configuration table based on the current | 538 // Select the extra vp6 configuration table based on the current |
530 * usage value. If the current usage value isn't found, use the | 539 // usage value. If the current usage value isn't found, use the |
531 * values for usage case 0. | 540 // values for usage case 0. |
532 */ | |
533 for (i = 0; | 541 for (i = 0; |
534 extracfg_map[i].usage && extracfg_map[i].usage != cfg->g_usage; | 542 extracfg_map[i].usage && extracfg_map[i].usage != cfg->g_usage; |
535 i++) {} | 543 ++i) {} |
536 | 544 |
537 priv->vp8_cfg = extracfg_map[i].cfg; | 545 priv->extra_cfg = extracfg_map[i].cfg; |
538 priv->vp8_cfg.pkt_list = &priv->pkt_list.head; | 546 priv->extra_cfg.pkt_list = &priv->pkt_list.head; |
539 | 547 |
540 // Maximum buffer size approximated based on having multiple ARF. | 548 // Maximum buffer size approximated based on having multiple ARF. |
541 priv->cx_data_sz = priv->cfg.g_w * priv->cfg.g_h * 3 / 2 * 8; | 549 priv->cx_data_sz = priv->cfg.g_w * priv->cfg.g_h * 3 / 2 * 8; |
542 | 550 |
543 if (priv->cx_data_sz < 4096) priv->cx_data_sz = 4096; | 551 if (priv->cx_data_sz < 4096) priv->cx_data_sz = 4096; |
544 | 552 |
545 priv->cx_data = malloc(priv->cx_data_sz); | 553 priv->cx_data = (unsigned char *)malloc(priv->cx_data_sz); |
546 | 554 if (priv->cx_data == NULL) |
547 if (priv->cx_data == NULL) return VPX_CODEC_MEM_ERROR; | 555 return VPX_CODEC_MEM_ERROR; |
548 | 556 |
549 vp9_initialize_enc(); | 557 vp9_initialize_enc(); |
550 | 558 |
551 res = validate_config(priv, &priv->cfg, &priv->vp8_cfg); | 559 res = validate_config(priv, &priv->cfg, &priv->extra_cfg); |
552 | 560 |
553 if (res == VPX_CODEC_OK) { | 561 if (res == VPX_CODEC_OK) { |
554 set_vp9e_config(&ctx->priv->alg_priv->oxcf, | 562 VP9_COMP *cpi; |
555 ctx->priv->alg_priv->cfg, | 563 set_encoder_config(&ctx->priv->alg_priv->oxcf, |
556 ctx->priv->alg_priv->vp8_cfg); | 564 &ctx->priv->alg_priv->cfg, |
557 optr = vp9_create_compressor(&ctx->priv->alg_priv->oxcf); | 565 &ctx->priv->alg_priv->extra_cfg); |
558 | 566 cpi = vp9_create_compressor(&ctx->priv->alg_priv->oxcf); |
559 if (optr == NULL) | 567 if (cpi == NULL) |
560 res = VPX_CODEC_MEM_ERROR; | 568 res = VPX_CODEC_MEM_ERROR; |
561 else | 569 else |
562 ctx->priv->alg_priv->cpi = optr; | 570 ctx->priv->alg_priv->cpi = cpi; |
563 } | 571 } |
564 } | 572 } |
565 | 573 |
566 return res; | 574 return res; |
567 } | 575 } |
568 | 576 |
569 | 577 |
570 static vpx_codec_err_t vp9e_init(vpx_codec_ctx_t *ctx, | 578 static vpx_codec_err_t encoder_init(vpx_codec_ctx_t *ctx, |
571 vpx_codec_priv_enc_mr_cfg_t *data) { | 579 vpx_codec_priv_enc_mr_cfg_t *data) { |
572 return vp9e_common_init(ctx); | 580 return encoder_common_init(ctx); |
573 } | 581 } |
574 | 582 |
575 static vpx_codec_err_t vp9e_destroy(vpx_codec_alg_priv_t *ctx) { | 583 static vpx_codec_err_t encoder_destroy(vpx_codec_alg_priv_t *ctx) { |
576 free(ctx->cx_data); | 584 free(ctx->cx_data); |
577 vp9_remove_compressor(&ctx->cpi); | 585 vp9_remove_compressor(ctx->cpi); |
578 free(ctx); | 586 free(ctx); |
579 return VPX_CODEC_OK; | 587 return VPX_CODEC_OK; |
580 } | 588 } |
581 | 589 |
582 static void pick_quickcompress_mode(vpx_codec_alg_priv_t *ctx, | 590 static void pick_quickcompress_mode(vpx_codec_alg_priv_t *ctx, |
583 unsigned long duration, | 591 unsigned long duration, |
584 unsigned long deadline) { | 592 unsigned long deadline) { |
585 unsigned int new_qc; | 593 // Use best quality mode if no deadline is given. |
586 | 594 MODE new_qc = MODE_BESTQUALITY; |
587 /* Use best quality mode if no deadline is given. */ | |
588 new_qc = MODE_BESTQUALITY; | |
589 | 595 |
590 if (deadline) { | 596 if (deadline) { |
591 uint64_t duration_us; | 597 // Convert duration parameter from stream timebase to microseconds |
| 598 const uint64_t duration_us = (uint64_t)duration * 1000000 * |
| 599 (uint64_t)ctx->cfg.g_timebase.num / |
| 600 (uint64_t)ctx->cfg.g_timebase.den; |
592 | 601 |
593 /* Convert duration parameter from stream timebase to microseconds */ | 602 // If the deadline is more that the duration this frame is to be shown, |
594 duration_us = (uint64_t)duration * 1000000 | 603 // use good quality mode. Otherwise use realtime mode. |
595 * (uint64_t)ctx->cfg.g_timebase.num | 604 new_qc = (deadline > duration_us) ? MODE_GOODQUALITY : MODE_REALTIME; |
596 / (uint64_t)ctx->cfg.g_timebase.den; | |
597 | |
598 /* If the deadline is more that the duration this frame is to be shown, | |
599 * use good quality mode. Otherwise use realtime mode. | |
600 */ | |
601 new_qc = (deadline > duration_us) ? MODE_GOODQUALITY : MODE_REALTIME; | |
602 } | 605 } |
603 | 606 |
604 if (ctx->cfg.g_pass == VPX_RC_FIRST_PASS) | 607 if (ctx->cfg.g_pass == VPX_RC_FIRST_PASS) |
605 new_qc = MODE_FIRSTPASS; | 608 new_qc = MODE_FIRSTPASS; |
606 else if (ctx->cfg.g_pass == VPX_RC_LAST_PASS) | 609 else if (ctx->cfg.g_pass == VPX_RC_LAST_PASS) |
607 new_qc = (new_qc == MODE_BESTQUALITY) | 610 new_qc = (new_qc == MODE_BESTQUALITY) ? MODE_SECONDPASS_BEST |
608 ? MODE_SECONDPASS_BEST | 611 : MODE_SECONDPASS; |
609 : MODE_SECONDPASS; | |
610 | 612 |
611 if (ctx->oxcf.mode != new_qc) { | 613 if (ctx->oxcf.mode != new_qc) { |
612 ctx->oxcf.mode = new_qc; | 614 ctx->oxcf.mode = new_qc; |
613 vp9_change_config(ctx->cpi, &ctx->oxcf); | 615 vp9_change_config(ctx->cpi, &ctx->oxcf); |
614 } | 616 } |
615 } | 617 } |
616 | 618 |
617 | 619 |
618 static int write_superframe_index(vpx_codec_alg_priv_t *ctx) { | 620 static int write_superframe_index(vpx_codec_alg_priv_t *ctx) { |
619 uint8_t marker = 0xc0; | 621 uint8_t marker = 0xc0; |
620 unsigned int mask; | 622 unsigned int mask; |
621 int mag, index_sz; | 623 int mag, index_sz; |
622 | 624 |
623 assert(ctx->pending_frame_count); | 625 assert(ctx->pending_frame_count); |
624 assert(ctx->pending_frame_count <= 8); | 626 assert(ctx->pending_frame_count <= 8); |
625 | 627 |
626 /* Add the number of frames to the marker byte */ | 628 // Add the number of frames to the marker byte |
627 marker |= ctx->pending_frame_count - 1; | 629 marker |= ctx->pending_frame_count - 1; |
628 | 630 |
629 /* Choose the magnitude */ | 631 // Choose the magnitude |
630 for (mag = 0, mask = 0xff; mag < 4; mag++) { | 632 for (mag = 0, mask = 0xff; mag < 4; mag++) { |
631 if (ctx->pending_frame_magnitude < mask) | 633 if (ctx->pending_frame_magnitude < mask) |
632 break; | 634 break; |
633 mask <<= 8; | 635 mask <<= 8; |
634 mask |= 0xff; | 636 mask |= 0xff; |
635 } | 637 } |
636 marker |= mag << 3; | 638 marker |= mag << 3; |
637 | 639 |
638 /* Write the index */ | 640 // Write the index |
639 index_sz = 2 + (mag + 1) * ctx->pending_frame_count; | 641 index_sz = 2 + (mag + 1) * ctx->pending_frame_count; |
640 if (ctx->pending_cx_data_sz + index_sz < ctx->cx_data_sz) { | 642 if (ctx->pending_cx_data_sz + index_sz < ctx->cx_data_sz) { |
641 uint8_t *x = ctx->pending_cx_data + ctx->pending_cx_data_sz; | 643 uint8_t *x = ctx->pending_cx_data + ctx->pending_cx_data_sz; |
642 int i, j; | 644 int i, j; |
643 | 645 |
644 *x++ = marker; | 646 *x++ = marker; |
645 for (i = 0; i < ctx->pending_frame_count; i++) { | 647 for (i = 0; i < ctx->pending_frame_count; i++) { |
646 unsigned int this_sz = (unsigned int)ctx->pending_frame_sizes[i]; | 648 unsigned int this_sz = (unsigned int)ctx->pending_frame_sizes[i]; |
647 | 649 |
648 for (j = 0; j <= mag; j++) { | 650 for (j = 0; j <= mag; j++) { |
649 *x++ = this_sz & 0xff; | 651 *x++ = this_sz & 0xff; |
650 this_sz >>= 8; | 652 this_sz >>= 8; |
651 } | 653 } |
652 } | 654 } |
653 *x++ = marker; | 655 *x++ = marker; |
654 ctx->pending_cx_data_sz += index_sz; | 656 ctx->pending_cx_data_sz += index_sz; |
655 } | 657 } |
656 return index_sz; | 658 return index_sz; |
657 } | 659 } |
658 | 660 |
659 static vpx_codec_err_t vp9e_encode(vpx_codec_alg_priv_t *ctx, | 661 static vpx_codec_err_t encoder_encode(vpx_codec_alg_priv_t *ctx, |
660 const vpx_image_t *img, | 662 const vpx_image_t *img, |
661 vpx_codec_pts_t pts, | 663 vpx_codec_pts_t pts, |
662 unsigned long duration, | 664 unsigned long duration, |
663 vpx_enc_frame_flags_t flags, | 665 vpx_enc_frame_flags_t flags, |
664 unsigned long deadline) { | 666 unsigned long deadline) { |
665 vpx_codec_err_t res = VPX_CODEC_OK; | 667 vpx_codec_err_t res = VPX_CODEC_OK; |
666 | 668 |
667 if (img) | 669 if (img) |
668 res = validate_img(ctx, img); | 670 res = validate_img(ctx, img); |
669 | 671 |
670 pick_quickcompress_mode(ctx, duration, deadline); | 672 pick_quickcompress_mode(ctx, duration, deadline); |
671 vpx_codec_pkt_list_init(&ctx->pkt_list); | 673 vpx_codec_pkt_list_init(&ctx->pkt_list); |
672 | 674 |
673 /* Handle Flags */ | 675 // Handle Flags |
674 if (((flags & VP8_EFLAG_NO_UPD_GF) && (flags & VP8_EFLAG_FORCE_GF)) | 676 if (((flags & VP8_EFLAG_NO_UPD_GF) && (flags & VP8_EFLAG_FORCE_GF)) || |
675 || ((flags & VP8_EFLAG_NO_UPD_ARF) && (flags & VP8_EFLAG_FORCE_ARF))) { | 677 ((flags & VP8_EFLAG_NO_UPD_ARF) && (flags & VP8_EFLAG_FORCE_ARF))) { |
676 ctx->base.err_detail = "Conflicting flags."; | 678 ctx->base.err_detail = "Conflicting flags."; |
677 return VPX_CODEC_INVALID_PARAM; | 679 return VPX_CODEC_INVALID_PARAM; |
678 } | 680 } |
679 | 681 |
680 if (flags & (VP8_EFLAG_NO_REF_LAST | VP8_EFLAG_NO_REF_GF | 682 if (flags & (VP8_EFLAG_NO_REF_LAST | VP8_EFLAG_NO_REF_GF | |
681 | VP8_EFLAG_NO_REF_ARF)) { | 683 VP8_EFLAG_NO_REF_ARF)) { |
682 int ref = 7; | 684 int ref = 7; |
683 | 685 |
684 if (flags & VP8_EFLAG_NO_REF_LAST) | 686 if (flags & VP8_EFLAG_NO_REF_LAST) |
685 ref ^= VP9_LAST_FLAG; | 687 ref ^= VP9_LAST_FLAG; |
686 | 688 |
687 if (flags & VP8_EFLAG_NO_REF_GF) | 689 if (flags & VP8_EFLAG_NO_REF_GF) |
688 ref ^= VP9_GOLD_FLAG; | 690 ref ^= VP9_GOLD_FLAG; |
689 | 691 |
690 if (flags & VP8_EFLAG_NO_REF_ARF) | 692 if (flags & VP8_EFLAG_NO_REF_ARF) |
691 ref ^= VP9_ALT_FLAG; | 693 ref ^= VP9_ALT_FLAG; |
692 | 694 |
693 vp9_use_as_reference(ctx->cpi, ref); | 695 vp9_use_as_reference(ctx->cpi, ref); |
694 } | 696 } |
695 | 697 |
696 if (flags & (VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF | 698 if (flags & (VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF | |
697 | VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_FORCE_GF | 699 VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_FORCE_GF | |
698 | VP8_EFLAG_FORCE_ARF)) { | 700 VP8_EFLAG_FORCE_ARF)) { |
699 int upd = 7; | 701 int upd = 7; |
700 | 702 |
701 if (flags & VP8_EFLAG_NO_UPD_LAST) | 703 if (flags & VP8_EFLAG_NO_UPD_LAST) |
702 upd ^= VP9_LAST_FLAG; | 704 upd ^= VP9_LAST_FLAG; |
703 | 705 |
704 if (flags & VP8_EFLAG_NO_UPD_GF) | 706 if (flags & VP8_EFLAG_NO_UPD_GF) |
705 upd ^= VP9_GOLD_FLAG; | 707 upd ^= VP9_GOLD_FLAG; |
706 | 708 |
707 if (flags & VP8_EFLAG_NO_UPD_ARF) | 709 if (flags & VP8_EFLAG_NO_UPD_ARF) |
708 upd ^= VP9_ALT_FLAG; | 710 upd ^= VP9_ALT_FLAG; |
709 | 711 |
710 vp9_update_reference(ctx->cpi, upd); | 712 vp9_update_reference(ctx->cpi, upd); |
711 } | 713 } |
712 | 714 |
713 if (flags & VP8_EFLAG_NO_UPD_ENTROPY) { | 715 if (flags & VP8_EFLAG_NO_UPD_ENTROPY) { |
714 vp9_update_entropy(ctx->cpi, 0); | 716 vp9_update_entropy(ctx->cpi, 0); |
715 } | 717 } |
716 | 718 |
717 /* Handle fixed keyframe intervals */ | 719 // Handle fixed keyframe intervals |
718 if (ctx->cfg.kf_mode == VPX_KF_AUTO | 720 if (ctx->cfg.kf_mode == VPX_KF_AUTO && |
719 && ctx->cfg.kf_min_dist == ctx->cfg.kf_max_dist) { | 721 ctx->cfg.kf_min_dist == ctx->cfg.kf_max_dist) { |
720 if (++ctx->fixed_kf_cntr > ctx->cfg.kf_min_dist) { | 722 if (++ctx->fixed_kf_cntr > ctx->cfg.kf_min_dist) { |
721 flags |= VPX_EFLAG_FORCE_KF; | 723 flags |= VPX_EFLAG_FORCE_KF; |
722 ctx->fixed_kf_cntr = 1; | 724 ctx->fixed_kf_cntr = 1; |
723 } | 725 } |
724 } | 726 } |
725 | 727 |
726 /* Initialize the encoder instance on the first frame. */ | 728 // Initialize the encoder instance on the first frame. |
727 if (res == VPX_CODEC_OK && ctx->cpi != NULL) { | 729 if (res == VPX_CODEC_OK && ctx->cpi != NULL) { |
728 unsigned int lib_flags; | 730 unsigned int lib_flags; |
729 YV12_BUFFER_CONFIG sd; | 731 YV12_BUFFER_CONFIG sd; |
730 int64_t dst_time_stamp, dst_end_time_stamp; | 732 int64_t dst_time_stamp, dst_end_time_stamp; |
731 size_t size, cx_data_sz; | 733 size_t size, cx_data_sz; |
732 unsigned char *cx_data; | 734 unsigned char *cx_data; |
733 | 735 |
734 /* Set up internal flags */ | 736 // Set up internal flags |
735 if (ctx->base.init_flags & VPX_CODEC_USE_PSNR) | 737 if (ctx->base.init_flags & VPX_CODEC_USE_PSNR) |
736 ((VP9_COMP *)ctx->cpi)->b_calculate_psnr = 1; | 738 ((VP9_COMP *)ctx->cpi)->b_calculate_psnr = 1; |
737 | 739 |
738 /* Convert API flags to internal codec lib flags */ | 740 // Convert API flags to internal codec lib flags |
739 lib_flags = (flags & VPX_EFLAG_FORCE_KF) ? FRAMEFLAGS_KEY : 0; | 741 lib_flags = (flags & VPX_EFLAG_FORCE_KF) ? FRAMEFLAGS_KEY : 0; |
740 | 742 |
741 /* vp8 use 10,000,000 ticks/second as time stamp */ | 743 /* vp9 use 10,000,000 ticks/second as time stamp */ |
742 dst_time_stamp = pts * 10000000 * ctx->cfg.g_timebase.num | 744 dst_time_stamp = (pts * 10000000 * ctx->cfg.g_timebase.num) |
743 / ctx->cfg.g_timebase.den; | 745 / ctx->cfg.g_timebase.den; |
744 dst_end_time_stamp = (pts + duration) * 10000000 * ctx->cfg.g_timebase.num / | 746 dst_end_time_stamp = (pts + duration) * 10000000 * ctx->cfg.g_timebase.num / |
745 ctx->cfg.g_timebase.den; | 747 ctx->cfg.g_timebase.den; |
746 | 748 |
747 if (img != NULL) { | 749 if (img != NULL) { |
748 res = image2yuvconfig(img, &sd); | 750 res = image2yuvconfig(img, &sd); |
749 | 751 |
750 if (vp9_receive_raw_frame(ctx->cpi, lib_flags, | 752 if (vp9_receive_raw_frame(ctx->cpi, lib_flags, |
751 &sd, dst_time_stamp, dst_end_time_stamp)) { | 753 &sd, dst_time_stamp, dst_end_time_stamp)) { |
752 VP9_COMP *cpi = (VP9_COMP *)ctx->cpi; | 754 VP9_COMP *cpi = (VP9_COMP *)ctx->cpi; |
(...skipping 19 matching lines...) Expand all Loading... |
772 ctx->base.err_detail = "Compressed data buffer too small"; | 774 ctx->base.err_detail = "Compressed data buffer too small"; |
773 return VPX_CODEC_ERROR; | 775 return VPX_CODEC_ERROR; |
774 } | 776 } |
775 } | 777 } |
776 | 778 |
777 while (cx_data_sz >= ctx->cx_data_sz / 2 && | 779 while (cx_data_sz >= ctx->cx_data_sz / 2 && |
778 -1 != vp9_get_compressed_data(ctx->cpi, &lib_flags, &size, | 780 -1 != vp9_get_compressed_data(ctx->cpi, &lib_flags, &size, |
779 cx_data, &dst_time_stamp, | 781 cx_data, &dst_time_stamp, |
780 &dst_end_time_stamp, !img)) { | 782 &dst_end_time_stamp, !img)) { |
781 if (size) { | 783 if (size) { |
782 vpx_codec_pts_t round, delta; | 784 vpx_codec_pts_t round, delta; |
783 vpx_codec_cx_pkt_t pkt; | 785 vpx_codec_cx_pkt_t pkt; |
784 VP9_COMP *cpi = (VP9_COMP *)ctx->cpi; | 786 VP9_COMP *const cpi = (VP9_COMP *)ctx->cpi; |
785 | 787 |
786 /* Pack invisible frames with the next visible frame */ | 788 // Pack invisible frames with the next visible frame |
787 if (cpi->common.show_frame == 0) { | 789 if (cpi->common.show_frame == 0) { |
788 if (ctx->pending_cx_data == 0) | 790 if (ctx->pending_cx_data == 0) |
789 ctx->pending_cx_data = cx_data; | 791 ctx->pending_cx_data = cx_data; |
790 ctx->pending_cx_data_sz += size; | 792 ctx->pending_cx_data_sz += size; |
791 ctx->pending_frame_sizes[ctx->pending_frame_count++] = size; | 793 ctx->pending_frame_sizes[ctx->pending_frame_count++] = size; |
792 ctx->pending_frame_magnitude |= size; | 794 ctx->pending_frame_magnitude |= size; |
793 cx_data += size; | 795 cx_data += size; |
794 cx_data_sz -= size; | 796 cx_data_sz -= size; |
795 continue; | 797 continue; |
796 } | 798 } |
797 | 799 |
798 /* Add the frame packet to the list of returned packets. */ | 800 // Add the frame packet to the list of returned packets. |
799 round = (vpx_codec_pts_t)1000000 * ctx->cfg.g_timebase.num / 2 - 1; | 801 round = (vpx_codec_pts_t)1000000 * ctx->cfg.g_timebase.num / 2 - 1; |
800 delta = (dst_end_time_stamp - dst_time_stamp); | 802 delta = (dst_end_time_stamp - dst_time_stamp); |
801 pkt.kind = VPX_CODEC_CX_FRAME_PKT; | 803 pkt.kind = VPX_CODEC_CX_FRAME_PKT; |
802 pkt.data.frame.pts = | 804 pkt.data.frame.pts = |
803 (dst_time_stamp * ctx->cfg.g_timebase.den + round) | 805 (dst_time_stamp * ctx->cfg.g_timebase.den + round) |
804 / ctx->cfg.g_timebase.num / 10000000; | 806 / ctx->cfg.g_timebase.num / 10000000; |
805 pkt.data.frame.duration = (unsigned long) | 807 pkt.data.frame.duration = (unsigned long) |
806 ((delta * ctx->cfg.g_timebase.den + round) | 808 ((delta * ctx->cfg.g_timebase.den + round) |
807 / ctx->cfg.g_timebase.num / 10000000); | 809 / ctx->cfg.g_timebase.num / 10000000); |
808 pkt.data.frame.flags = lib_flags << 16; | 810 pkt.data.frame.flags = lib_flags << 16; |
(...skipping 10 matching lines...) Expand all Loading... |
819 // Invisible frames have no duration. | 821 // Invisible frames have no duration. |
820 pkt.data.frame.pts = ((cpi->last_time_stamp_seen | 822 pkt.data.frame.pts = ((cpi->last_time_stamp_seen |
821 * ctx->cfg.g_timebase.den + round) | 823 * ctx->cfg.g_timebase.den + round) |
822 / ctx->cfg.g_timebase.num / 10000000) + 1; | 824 / ctx->cfg.g_timebase.num / 10000000) + 1; |
823 pkt.data.frame.duration = 0; | 825 pkt.data.frame.duration = 0; |
824 } | 826 } |
825 | 827 |
826 if (cpi->droppable) | 828 if (cpi->droppable) |
827 pkt.data.frame.flags |= VPX_FRAME_IS_DROPPABLE; | 829 pkt.data.frame.flags |= VPX_FRAME_IS_DROPPABLE; |
828 | 830 |
829 /*if (cpi->output_partition) | 831 if (ctx->pending_cx_data) { |
830 { | 832 ctx->pending_frame_sizes[ctx->pending_frame_count++] = size; |
831 int i; | 833 ctx->pending_frame_magnitude |= size; |
832 const int num_partitions = 1; | 834 ctx->pending_cx_data_sz += size; |
833 | 835 size += write_superframe_index(ctx); |
834 pkt.data.frame.flags |= VPX_FRAME_IS_FRAGMENT; | 836 pkt.data.frame.buf = ctx->pending_cx_data; |
835 | 837 pkt.data.frame.sz = ctx->pending_cx_data_sz; |
836 for (i = 0; i < num_partitions; ++i) | 838 ctx->pending_cx_data = NULL; |
837 { | 839 ctx->pending_cx_data_sz = 0; |
838 pkt.data.frame.buf = cx_data; | 840 ctx->pending_frame_count = 0; |
839 pkt.data.frame.sz = cpi->partition_sz[i]; | 841 ctx->pending_frame_magnitude = 0; |
840 pkt.data.frame.partition_id = i; | 842 } else { |
841 // don't set the fragment bit for the last partition | 843 pkt.data.frame.buf = cx_data; |
842 if (i == (num_partitions - 1)) | 844 pkt.data.frame.sz = size; |
843 pkt.data.frame.flags &= ~VPX_FRAME_IS_FRAGMENT; | |
844 vpx_codec_pkt_list_add(&ctx->pkt_list.head, &pkt); | |
845 cx_data += cpi->partition_sz[i]; | |
846 cx_data_sz -= cpi->partition_sz[i]; | |
847 } | |
848 } | 845 } |
849 else*/ | 846 pkt.data.frame.partition_id = -1; |
850 { | 847 vpx_codec_pkt_list_add(&ctx->pkt_list.head, &pkt); |
851 if (ctx->pending_cx_data) { | 848 cx_data += size; |
852 ctx->pending_frame_sizes[ctx->pending_frame_count++] = size; | 849 cx_data_sz -= size; |
853 ctx->pending_frame_magnitude |= size; | |
854 ctx->pending_cx_data_sz += size; | |
855 size += write_superframe_index(ctx); | |
856 pkt.data.frame.buf = ctx->pending_cx_data; | |
857 pkt.data.frame.sz = ctx->pending_cx_data_sz; | |
858 ctx->pending_cx_data = NULL; | |
859 ctx->pending_cx_data_sz = 0; | |
860 ctx->pending_frame_count = 0; | |
861 ctx->pending_frame_magnitude = 0; | |
862 } else { | |
863 pkt.data.frame.buf = cx_data; | |
864 pkt.data.frame.sz = size; | |
865 } | |
866 pkt.data.frame.partition_id = -1; | |
867 vpx_codec_pkt_list_add(&ctx->pkt_list.head, &pkt); | |
868 cx_data += size; | |
869 cx_data_sz -= size; | |
870 } | |
871 } | 850 } |
872 } | 851 } |
873 } | 852 } |
874 | 853 |
875 return res; | 854 return res; |
876 } | 855 } |
877 | 856 |
878 | 857 |
879 static const vpx_codec_cx_pkt_t *vp9e_get_cxdata(vpx_codec_alg_priv_t *ctx, | 858 static const vpx_codec_cx_pkt_t *encoder_get_cxdata(vpx_codec_alg_priv_t *ctx, |
880 vpx_codec_iter_t *iter) { | 859 vpx_codec_iter_t *iter) { |
881 return vpx_codec_pkt_list_get(&ctx->pkt_list.head, iter); | 860 return vpx_codec_pkt_list_get(&ctx->pkt_list.head, iter); |
882 } | 861 } |
883 | 862 |
884 static vpx_codec_err_t vp9e_set_reference(vpx_codec_alg_priv_t *ctx, | 863 static vpx_codec_err_t ctrl_set_reference(vpx_codec_alg_priv_t *ctx, |
885 int ctr_id, | 864 int ctr_id, va_list args) { |
886 va_list args) { | 865 vpx_ref_frame_t *const frame = va_arg(args, vpx_ref_frame_t *); |
887 vpx_ref_frame_t *frame = va_arg(args, vpx_ref_frame_t *); | |
888 | 866 |
889 if (frame != NULL) { | 867 if (frame != NULL) { |
890 YV12_BUFFER_CONFIG sd; | 868 YV12_BUFFER_CONFIG sd; |
891 | 869 |
892 image2yuvconfig(&frame->img, &sd); | 870 image2yuvconfig(&frame->img, &sd); |
893 vp9_set_reference_enc(ctx->cpi, ref_frame_to_vp9_reframe(frame->frame_type), | 871 vp9_set_reference_enc(ctx->cpi, ref_frame_to_vp9_reframe(frame->frame_type), |
894 &sd); | 872 &sd); |
895 return VPX_CODEC_OK; | 873 return VPX_CODEC_OK; |
896 } else { | 874 } else { |
897 return VPX_CODEC_INVALID_PARAM; | 875 return VPX_CODEC_INVALID_PARAM; |
898 } | 876 } |
899 } | 877 } |
900 | 878 |
901 static vpx_codec_err_t vp9e_copy_reference(vpx_codec_alg_priv_t *ctx, | 879 static vpx_codec_err_t ctrl_copy_reference(vpx_codec_alg_priv_t *ctx, |
902 int ctr_id, | 880 int ctr_id, va_list args) { |
903 va_list args) { | 881 vpx_ref_frame_t *const frame = va_arg(args, vpx_ref_frame_t *); |
904 vpx_ref_frame_t *frame = va_arg(args, vpx_ref_frame_t *); | |
905 | 882 |
906 if (frame != NULL) { | 883 if (frame != NULL) { |
907 YV12_BUFFER_CONFIG sd; | 884 YV12_BUFFER_CONFIG sd; |
908 | 885 |
909 image2yuvconfig(&frame->img, &sd); | 886 image2yuvconfig(&frame->img, &sd); |
910 vp9_copy_reference_enc(ctx->cpi, | 887 vp9_copy_reference_enc(ctx->cpi, |
911 ref_frame_to_vp9_reframe(frame->frame_type), &sd); | 888 ref_frame_to_vp9_reframe(frame->frame_type), &sd); |
912 return VPX_CODEC_OK; | 889 return VPX_CODEC_OK; |
913 } else { | 890 } else { |
914 return VPX_CODEC_INVALID_PARAM; | 891 return VPX_CODEC_INVALID_PARAM; |
915 } | 892 } |
916 } | 893 } |
917 | 894 |
918 static vpx_codec_err_t get_reference(vpx_codec_alg_priv_t *ctx, | 895 static vpx_codec_err_t ctrl_get_reference(vpx_codec_alg_priv_t *ctx, |
919 int ctr_id, | 896 int ctr_id, va_list args) { |
920 va_list args) { | |
921 vp9_ref_frame_t *frame = va_arg(args, vp9_ref_frame_t *); | 897 vp9_ref_frame_t *frame = va_arg(args, vp9_ref_frame_t *); |
922 | 898 |
923 if (frame != NULL) { | 899 if (frame != NULL) { |
924 YV12_BUFFER_CONFIG* fb; | 900 YV12_BUFFER_CONFIG* fb; |
925 | 901 |
926 vp9_get_reference_enc(ctx->cpi, frame->idx, &fb); | 902 vp9_get_reference_enc(ctx->cpi, frame->idx, &fb); |
927 yuvconfig2image(&frame->img, fb, NULL); | 903 yuvconfig2image(&frame->img, fb, NULL); |
928 return VPX_CODEC_OK; | 904 return VPX_CODEC_OK; |
929 } else { | 905 } else { |
930 return VPX_CODEC_INVALID_PARAM; | 906 return VPX_CODEC_INVALID_PARAM; |
931 } | 907 } |
932 } | 908 } |
933 | 909 |
934 static vpx_codec_err_t vp9e_set_previewpp(vpx_codec_alg_priv_t *ctx, | 910 static vpx_codec_err_t ctrl_set_previewpp(vpx_codec_alg_priv_t *ctx, |
935 int ctr_id, | 911 int ctr_id, va_list args) { |
936 va_list args) { | |
937 #if CONFIG_VP9_POSTPROC | 912 #if CONFIG_VP9_POSTPROC |
938 vp8_postproc_cfg_t *config = va_arg(args, vp8_postproc_cfg_t *); | 913 vp8_postproc_cfg_t *config = va_arg(args, vp8_postproc_cfg_t *); |
939 (void)ctr_id; | 914 (void)ctr_id; |
940 | 915 |
941 if (config != NULL) { | 916 if (config != NULL) { |
942 ctx->preview_ppcfg = *config; | 917 ctx->preview_ppcfg = *config; |
943 return VPX_CODEC_OK; | 918 return VPX_CODEC_OK; |
944 } else { | 919 } else { |
945 return VPX_CODEC_INVALID_PARAM; | 920 return VPX_CODEC_INVALID_PARAM; |
946 } | 921 } |
947 #else | 922 #else |
948 (void)ctx; | 923 (void)ctx; |
949 (void)ctr_id; | 924 (void)ctr_id; |
950 (void)args; | 925 (void)args; |
951 return VPX_CODEC_INCAPABLE; | 926 return VPX_CODEC_INCAPABLE; |
952 #endif | 927 #endif |
953 } | 928 } |
954 | 929 |
955 | 930 |
956 static vpx_image_t *vp9e_get_preview(vpx_codec_alg_priv_t *ctx) { | 931 static vpx_image_t *encoder_get_preview(vpx_codec_alg_priv_t *ctx) { |
957 YV12_BUFFER_CONFIG sd; | 932 YV12_BUFFER_CONFIG sd; |
958 vp9_ppflags_t flags = {0}; | 933 vp9_ppflags_t flags = {0}; |
959 | 934 |
960 if (ctx->preview_ppcfg.post_proc_flag) { | 935 if (ctx->preview_ppcfg.post_proc_flag) { |
961 flags.post_proc_flag = ctx->preview_ppcfg.post_proc_flag; | 936 flags.post_proc_flag = ctx->preview_ppcfg.post_proc_flag; |
962 flags.deblocking_level = ctx->preview_ppcfg.deblocking_level; | 937 flags.deblocking_level = ctx->preview_ppcfg.deblocking_level; |
963 flags.noise_level = ctx->preview_ppcfg.noise_level; | 938 flags.noise_level = ctx->preview_ppcfg.noise_level; |
964 } | 939 } |
965 | 940 |
966 if (0 == vp9_get_preview_raw_frame(ctx->cpi, &sd, &flags)) { | 941 if (vp9_get_preview_raw_frame(ctx->cpi, &sd, &flags) == 0) { |
967 yuvconfig2image(&ctx->preview_img, &sd, NULL); | 942 yuvconfig2image(&ctx->preview_img, &sd, NULL); |
968 return &ctx->preview_img; | 943 return &ctx->preview_img; |
969 } else { | 944 } else { |
970 return NULL; | 945 return NULL; |
971 } | 946 } |
972 } | 947 } |
973 | 948 |
974 static vpx_codec_err_t vp9e_update_entropy(vpx_codec_alg_priv_t *ctx, | 949 static vpx_codec_err_t ctrl_update_entropy(vpx_codec_alg_priv_t *ctx, |
975 int ctr_id, | 950 int ctr_id, va_list args) { |
976 va_list args) { | 951 const int update = va_arg(args, int); |
977 int update = va_arg(args, int); | |
978 vp9_update_entropy(ctx->cpi, update); | 952 vp9_update_entropy(ctx->cpi, update); |
979 return VPX_CODEC_OK; | 953 return VPX_CODEC_OK; |
980 } | 954 } |
981 | 955 |
982 static vpx_codec_err_t vp9e_update_reference(vpx_codec_alg_priv_t *ctx, | 956 static vpx_codec_err_t ctrl_update_reference(vpx_codec_alg_priv_t *ctx, |
983 int ctr_id, | 957 int ctr_id, va_list args) { |
984 va_list args) { | 958 const int ref_frame_flags = va_arg(args, int); |
985 int update = va_arg(args, int); | 959 vp9_update_reference(ctx->cpi, ref_frame_flags); |
986 vp9_update_reference(ctx->cpi, update); | |
987 return VPX_CODEC_OK; | 960 return VPX_CODEC_OK; |
988 } | 961 } |
989 | 962 |
990 static vpx_codec_err_t vp9e_use_reference(vpx_codec_alg_priv_t *ctx, | 963 static vpx_codec_err_t ctrl_use_reference(vpx_codec_alg_priv_t *ctx, |
991 int ctr_id, | 964 int ctr_id, va_list args) { |
992 va_list args) { | 965 const int reference_flag = va_arg(args, int); |
993 int reference_flag = va_arg(args, int); | |
994 vp9_use_as_reference(ctx->cpi, reference_flag); | 966 vp9_use_as_reference(ctx->cpi, reference_flag); |
995 return VPX_CODEC_OK; | 967 return VPX_CODEC_OK; |
996 } | 968 } |
997 | 969 |
998 static vpx_codec_err_t vp9e_set_roi_map(vpx_codec_alg_priv_t *ctx, | 970 static vpx_codec_err_t ctrl_set_roi_map(vpx_codec_alg_priv_t *ctx, |
999 int ctr_id, | 971 int ctr_id, va_list args) { |
1000 va_list args) { | |
1001 // TODO(yaowu): Need to re-implement and test for VP9. | 972 // TODO(yaowu): Need to re-implement and test for VP9. |
1002 return VPX_CODEC_INVALID_PARAM; | 973 return VPX_CODEC_INVALID_PARAM; |
1003 } | 974 } |
1004 | 975 |
1005 | 976 |
1006 static vpx_codec_err_t vp9e_set_activemap(vpx_codec_alg_priv_t *ctx, | 977 static vpx_codec_err_t ctrl_set_active_map(vpx_codec_alg_priv_t *ctx, |
1007 int ctr_id, | 978 int ctr_id, va_list args) { |
1008 va_list args) { | 979 vpx_active_map_t *const map = va_arg(args, vpx_active_map_t *); |
1009 // TODO(yaowu): Need to re-implement and test for VP9. | 980 |
1010 return VPX_CODEC_INVALID_PARAM; | 981 if (map) { |
| 982 if (!vp9_set_active_map(ctx->cpi, map->active_map, map->rows, map->cols)) |
| 983 return VPX_CODEC_OK; |
| 984 else |
| 985 return VPX_CODEC_INVALID_PARAM; |
| 986 } else { |
| 987 return VPX_CODEC_INVALID_PARAM; |
| 988 } |
1011 } | 989 } |
1012 | 990 |
1013 static vpx_codec_err_t vp9e_set_scalemode(vpx_codec_alg_priv_t *ctx, | 991 static vpx_codec_err_t ctrl_set_scale_mode(vpx_codec_alg_priv_t *ctx, |
1014 int ctr_id, | 992 int ctr_id, va_list args) { |
1015 va_list args) { | 993 vpx_scaling_mode_t *const mode = va_arg(args, vpx_scaling_mode_t *); |
1016 vpx_scaling_mode_t *scalemode = va_arg(args, vpx_scaling_mode_t *); | |
1017 | 994 |
1018 if (scalemode != NULL) { | 995 if (mode) { |
1019 int res; | 996 const int res = vp9_set_internal_size(ctx->cpi, |
1020 res = vp9_set_internal_size(ctx->cpi, | 997 (VPX_SCALING)mode->h_scaling_mode, |
1021 (VPX_SCALING)scalemode->h_scaling_mode, | 998 (VPX_SCALING)mode->v_scaling_mode); |
1022 (VPX_SCALING)scalemode->v_scaling_mode); | |
1023 return (res == 0) ? VPX_CODEC_OK : VPX_CODEC_INVALID_PARAM; | 999 return (res == 0) ? VPX_CODEC_OK : VPX_CODEC_INVALID_PARAM; |
1024 } else { | 1000 } else { |
1025 return VPX_CODEC_INVALID_PARAM; | 1001 return VPX_CODEC_INVALID_PARAM; |
1026 } | 1002 } |
1027 } | 1003 } |
1028 | 1004 |
1029 static vpx_codec_err_t vp9e_set_svc(vpx_codec_alg_priv_t *ctx, int ctr_id, | 1005 static vpx_codec_err_t ctrl_set_svc(vpx_codec_alg_priv_t *ctx, int ctr_id, |
1030 va_list args) { | 1006 va_list args) { |
1031 int data = va_arg(args, int); | 1007 int data = va_arg(args, int); |
| 1008 const vpx_codec_enc_cfg_t *cfg = &ctx->cfg; |
1032 vp9_set_svc(ctx->cpi, data); | 1009 vp9_set_svc(ctx->cpi, data); |
1033 // CBR mode for SVC with both temporal and spatial layers not yet supported. | 1010 // CBR or two pass mode for SVC with both temporal and spatial layers |
| 1011 // not yet supported. |
1034 if (data == 1 && | 1012 if (data == 1 && |
1035 ctx->cfg.rc_end_usage == VPX_CBR && | 1013 (cfg->rc_end_usage == VPX_CBR || |
1036 ctx->cfg.ss_number_layers > 1 && | 1014 cfg->g_pass == VPX_RC_FIRST_PASS || |
1037 ctx->cfg.ts_number_layers > 1) { | 1015 cfg->g_pass == VPX_RC_LAST_PASS) && |
| 1016 cfg->ss_number_layers > 1 && |
| 1017 cfg->ts_number_layers > 1) { |
1038 return VPX_CODEC_INVALID_PARAM; | 1018 return VPX_CODEC_INVALID_PARAM; |
1039 } | 1019 } |
1040 return VPX_CODEC_OK; | 1020 return VPX_CODEC_OK; |
1041 } | 1021 } |
1042 | 1022 |
1043 static vpx_codec_err_t vp9e_set_svc_layer_id(vpx_codec_alg_priv_t *ctx, | 1023 static vpx_codec_err_t ctrl_set_svc_layer_id(vpx_codec_alg_priv_t *ctx, |
1044 int ctr_id, | 1024 int ctr_id, |
1045 va_list args) { | 1025 va_list args) { |
1046 vpx_svc_layer_id_t *data = va_arg(args, vpx_svc_layer_id_t *); | 1026 vpx_svc_layer_id_t *const data = va_arg(args, vpx_svc_layer_id_t *); |
1047 VP9_COMP *cpi = (VP9_COMP *)ctx->cpi; | 1027 VP9_COMP *const cpi = (VP9_COMP *)ctx->cpi; |
1048 cpi->svc.spatial_layer_id = data->spatial_layer_id; | 1028 SVC *const svc = &cpi->svc; |
1049 cpi->svc.temporal_layer_id = data->temporal_layer_id; | 1029 svc->spatial_layer_id = data->spatial_layer_id; |
| 1030 svc->temporal_layer_id = data->temporal_layer_id; |
1050 // Checks on valid layer_id input. | 1031 // Checks on valid layer_id input. |
1051 if (cpi->svc.temporal_layer_id < 0 || | 1032 if (svc->temporal_layer_id < 0 || |
1052 cpi->svc.temporal_layer_id >= (int)ctx->cfg.ts_number_layers) { | 1033 svc->temporal_layer_id >= (int)ctx->cfg.ts_number_layers) { |
1053 return VPX_CODEC_INVALID_PARAM; | 1034 return VPX_CODEC_INVALID_PARAM; |
1054 } | 1035 } |
1055 if (cpi->svc.spatial_layer_id < 0 || | 1036 if (svc->spatial_layer_id < 0 || |
1056 cpi->svc.spatial_layer_id >= (int)ctx->cfg.ss_number_layers) { | 1037 svc->spatial_layer_id >= (int)ctx->cfg.ss_number_layers) { |
1057 return VPX_CODEC_INVALID_PARAM; | 1038 return VPX_CODEC_INVALID_PARAM; |
1058 } | 1039 } |
1059 return VPX_CODEC_OK; | 1040 return VPX_CODEC_OK; |
1060 } | 1041 } |
1061 | 1042 |
1062 static vpx_codec_err_t vp9e_set_svc_parameters(vpx_codec_alg_priv_t *ctx, | 1043 static vpx_codec_err_t ctrl_set_svc_parameters(vpx_codec_alg_priv_t *ctx, |
1063 int ctr_id, va_list args) { | 1044 int ctr_id, va_list args) { |
1064 VP9_COMP *cpi = (VP9_COMP *)ctx->cpi; | 1045 VP9_COMP *const cpi = ctx->cpi; |
1065 vpx_svc_parameters_t *params = va_arg(args, vpx_svc_parameters_t *); | 1046 vpx_svc_parameters_t *const params = va_arg(args, vpx_svc_parameters_t *); |
1066 | 1047 |
1067 if (params == NULL) return VPX_CODEC_INVALID_PARAM; | 1048 if (params == NULL) |
| 1049 return VPX_CODEC_INVALID_PARAM; |
1068 | 1050 |
1069 cpi->svc.spatial_layer_id = params->spatial_layer; | 1051 cpi->svc.spatial_layer_id = params->spatial_layer; |
1070 cpi->svc.temporal_layer_id = params->temporal_layer; | 1052 cpi->svc.temporal_layer_id = params->temporal_layer; |
1071 | 1053 |
1072 cpi->lst_fb_idx = params->lst_fb_idx; | 1054 cpi->lst_fb_idx = params->lst_fb_idx; |
1073 cpi->gld_fb_idx = params->gld_fb_idx; | 1055 cpi->gld_fb_idx = params->gld_fb_idx; |
1074 cpi->alt_fb_idx = params->alt_fb_idx; | 1056 cpi->alt_fb_idx = params->alt_fb_idx; |
1075 | 1057 |
1076 if (vp9_set_size_literal(ctx->cpi, params->width, params->height) != 0) | 1058 if (vp9_set_size_literal(ctx->cpi, params->width, params->height) != 0) |
1077 return VPX_CODEC_INVALID_PARAM; | 1059 return VPX_CODEC_INVALID_PARAM; |
1078 | 1060 |
1079 ctx->cfg.rc_max_quantizer = params->max_quantizer; | 1061 ctx->cfg.rc_max_quantizer = params->max_quantizer; |
1080 ctx->cfg.rc_min_quantizer = params->min_quantizer; | 1062 ctx->cfg.rc_min_quantizer = params->min_quantizer; |
1081 | 1063 |
1082 set_vp9e_config(&ctx->oxcf, ctx->cfg, ctx->vp8_cfg); | 1064 set_encoder_config(&ctx->oxcf, &ctx->cfg, &ctx->extra_cfg); |
1083 vp9_change_config(ctx->cpi, &ctx->oxcf); | 1065 vp9_change_config(ctx->cpi, &ctx->oxcf); |
1084 | 1066 |
1085 return VPX_CODEC_OK; | 1067 return VPX_CODEC_OK; |
1086 } | 1068 } |
1087 | 1069 |
1088 static vpx_codec_ctrl_fn_map_t vp9e_ctf_maps[] = { | 1070 static vpx_codec_ctrl_fn_map_t encoder_ctrl_maps[] = { |
1089 {VP8_SET_REFERENCE, vp9e_set_reference}, | 1071 {VP8_COPY_REFERENCE, ctrl_copy_reference}, |
1090 {VP8_COPY_REFERENCE, vp9e_copy_reference}, | 1072 {VP8E_UPD_ENTROPY, ctrl_update_entropy}, |
1091 {VP8_SET_POSTPROC, vp9e_set_previewpp}, | 1073 {VP8E_UPD_REFERENCE, ctrl_update_reference}, |
1092 {VP8E_UPD_ENTROPY, vp9e_update_entropy}, | 1074 {VP8E_USE_REFERENCE, ctrl_use_reference}, |
1093 {VP8E_UPD_REFERENCE, vp9e_update_reference}, | 1075 |
1094 {VP8E_USE_REFERENCE, vp9e_use_reference}, | 1076 // Setters |
1095 {VP8E_SET_ROI_MAP, vp9e_set_roi_map}, | 1077 {VP8_SET_REFERENCE, ctrl_set_reference}, |
1096 {VP8E_SET_ACTIVEMAP, vp9e_set_activemap}, | 1078 {VP8_SET_POSTPROC, ctrl_set_previewpp}, |
1097 {VP8E_SET_SCALEMODE, vp9e_set_scalemode}, | 1079 {VP8E_SET_ROI_MAP, ctrl_set_roi_map}, |
1098 {VP8E_SET_CPUUSED, set_param}, | 1080 {VP8E_SET_ACTIVEMAP, ctrl_set_active_map}, |
1099 {VP8E_SET_NOISE_SENSITIVITY, set_param}, | 1081 {VP8E_SET_SCALEMODE, ctrl_set_scale_mode}, |
1100 {VP8E_SET_ENABLEAUTOALTREF, set_param}, | 1082 {VP8E_SET_CPUUSED, ctrl_set_param}, |
1101 {VP8E_SET_SHARPNESS, set_param}, | 1083 {VP8E_SET_NOISE_SENSITIVITY, ctrl_set_param}, |
1102 {VP8E_SET_STATIC_THRESHOLD, set_param}, | 1084 {VP8E_SET_ENABLEAUTOALTREF, ctrl_set_param}, |
1103 {VP9E_SET_TILE_COLUMNS, set_param}, | 1085 {VP8E_SET_SHARPNESS, ctrl_set_param}, |
1104 {VP9E_SET_TILE_ROWS, set_param}, | 1086 {VP8E_SET_STATIC_THRESHOLD, ctrl_set_param}, |
1105 {VP8E_GET_LAST_QUANTIZER, get_param}, | 1087 {VP9E_SET_TILE_COLUMNS, ctrl_set_param}, |
1106 {VP8E_GET_LAST_QUANTIZER_64, get_param}, | 1088 {VP9E_SET_TILE_ROWS, ctrl_set_param}, |
1107 {VP8E_SET_ARNR_MAXFRAMES, set_param}, | 1089 {VP8E_SET_ARNR_MAXFRAMES, ctrl_set_param}, |
1108 {VP8E_SET_ARNR_STRENGTH, set_param}, | 1090 {VP8E_SET_ARNR_STRENGTH, ctrl_set_param}, |
1109 {VP8E_SET_ARNR_TYPE, set_param}, | 1091 {VP8E_SET_ARNR_TYPE, ctrl_set_param}, |
1110 {VP8E_SET_TUNING, set_param}, | 1092 {VP8E_SET_TUNING, ctrl_set_param}, |
1111 {VP8E_SET_CQ_LEVEL, set_param}, | 1093 {VP8E_SET_CQ_LEVEL, ctrl_set_param}, |
1112 {VP8E_SET_MAX_INTRA_BITRATE_PCT, set_param}, | 1094 {VP8E_SET_MAX_INTRA_BITRATE_PCT, ctrl_set_param}, |
1113 {VP9E_SET_LOSSLESS, set_param}, | 1095 {VP9E_SET_LOSSLESS, ctrl_set_param}, |
1114 {VP9E_SET_FRAME_PARALLEL_DECODING, set_param}, | 1096 {VP9E_SET_FRAME_PARALLEL_DECODING, ctrl_set_param}, |
1115 {VP9E_SET_AQ_MODE, set_param}, | 1097 {VP9E_SET_AQ_MODE, ctrl_set_param}, |
1116 {VP9_GET_REFERENCE, get_reference}, | 1098 {VP9E_SET_FRAME_PERIODIC_BOOST, ctrl_set_param}, |
1117 {VP9E_SET_SVC, vp9e_set_svc}, | 1099 {VP9E_SET_SVC, ctrl_set_svc}, |
1118 {VP9E_SET_SVC_PARAMETERS, vp9e_set_svc_parameters}, | 1100 {VP9E_SET_SVC_PARAMETERS, ctrl_set_svc_parameters}, |
1119 {VP9E_SET_SVC_LAYER_ID, vp9e_set_svc_layer_id}, | 1101 {VP9E_SET_SVC_LAYER_ID, ctrl_set_svc_layer_id}, |
| 1102 |
| 1103 // Getters |
| 1104 {VP8E_GET_LAST_QUANTIZER, ctrl_get_param}, |
| 1105 {VP8E_GET_LAST_QUANTIZER_64, ctrl_get_param}, |
| 1106 {VP9_GET_REFERENCE, ctrl_get_reference}, |
| 1107 |
1120 { -1, NULL}, | 1108 { -1, NULL}, |
1121 }; | 1109 }; |
1122 | 1110 |
1123 static vpx_codec_enc_cfg_map_t vp9e_usage_cfg_map[] = { | 1111 static vpx_codec_enc_cfg_map_t encoder_usage_cfg_map[] = { |
1124 { | 1112 { |
1125 0, | 1113 0, |
1126 { // NOLINT | 1114 { // NOLINT |
1127 0, /* g_usage */ | 1115 0, // g_usage |
1128 0, /* g_threads */ | 1116 0, // g_threads |
1129 0, /* g_profile */ | 1117 0, // g_profile |
1130 | 1118 |
1131 320, /* g_width */ | 1119 320, // g_width |
1132 240, /* g_height */ | 1120 240, // g_height |
1133 {1, 30}, /* g_timebase */ | 1121 {1, 30}, // g_timebase |
1134 | 1122 |
1135 0, /* g_error_resilient */ | 1123 0, // g_error_resilient |
1136 | 1124 |
1137 VPX_RC_ONE_PASS, /* g_pass */ | 1125 VPX_RC_ONE_PASS, // g_pass |
1138 | 1126 |
1139 25, /* g_lag_in_frames */ | 1127 25, // g_lag_in_frames |
1140 | 1128 |
1141 0, /* rc_dropframe_thresh */ | 1129 0, // rc_dropframe_thresh |
1142 0, /* rc_resize_allowed */ | 1130 0, // rc_resize_allowed |
1143 60, /* rc_resize_down_thresold */ | 1131 60, // rc_resize_down_thresold |
1144 30, /* rc_resize_up_thresold */ | 1132 30, // rc_resize_up_thresold |
1145 | 1133 |
1146 VPX_VBR, /* rc_end_usage */ | 1134 VPX_VBR, // rc_end_usage |
1147 #if VPX_ENCODER_ABI_VERSION > (1 + VPX_CODEC_ABI_VERSION) | 1135 #if VPX_ENCODER_ABI_VERSION > (1 + VPX_CODEC_ABI_VERSION) |
1148 {0}, /* rc_twopass_stats_in */ | 1136 {0}, // rc_twopass_stats_in |
1149 #endif | 1137 #endif |
1150 256, /* rc_target_bandwidth */ | 1138 256, // rc_target_bandwidth |
1151 0, /* rc_min_quantizer */ | 1139 0, // rc_min_quantizer |
1152 63, /* rc_max_quantizer */ | 1140 63, // rc_max_quantizer |
1153 100, /* rc_undershoot_pct */ | 1141 100, // rc_undershoot_pct |
1154 100, /* rc_overshoot_pct */ | 1142 100, // rc_overshoot_pct |
1155 | 1143 |
1156 6000, /* rc_max_buffer_size */ | 1144 6000, // rc_max_buffer_size |
1157 4000, /* rc_buffer_initial_size; */ | 1145 4000, // rc_buffer_initial_size |
1158 5000, /* rc_buffer_optimal_size; */ | 1146 5000, // rc_buffer_optimal_size |
1159 | 1147 |
1160 50, /* rc_two_pass_vbrbias */ | 1148 50, // rc_two_pass_vbrbias |
1161 0, /* rc_two_pass_vbrmin_section */ | 1149 0, // rc_two_pass_vbrmin_section |
1162 2000, /* rc_two_pass_vbrmax_section */ | 1150 2000, // rc_two_pass_vbrmax_section |
1163 | 1151 |
1164 /* keyframing settings (kf) */ | 1152 // keyframing settings (kf) |
1165 VPX_KF_AUTO, /* g_kfmode*/ | 1153 VPX_KF_AUTO, // g_kfmode |
1166 0, /* kf_min_dist */ | 1154 0, // kf_min_dist |
1167 9999, /* kf_max_dist */ | 1155 9999, // kf_max_dist |
1168 | 1156 |
1169 VPX_SS_DEFAULT_LAYERS, /* ss_number_layers */ | 1157 VPX_SS_DEFAULT_LAYERS, // ss_number_layers |
1170 {0}, /* ss_target_bitrate */ | 1158 {0}, // ss_target_bitrate |
1171 1, /* ts_number_layers */ | 1159 1, // ts_number_layers |
1172 {0}, /* ts_target_bitrate */ | 1160 {0}, // ts_target_bitrate |
1173 {0}, /* ts_rate_decimator */ | 1161 {0}, // ts_rate_decimator |
1174 0, /* ts_periodicity */ | 1162 0, // ts_periodicity |
1175 {0}, /* ts_layer_id */ | 1163 {0}, // ts_layer_id |
1176 #if VPX_ENCODER_ABI_VERSION == (1 + VPX_CODEC_ABI_VERSION) | 1164 #if VPX_ENCODER_ABI_VERSION == (1 + VPX_CODEC_ABI_VERSION) |
1177 "vp8.fpf" /* first pass filename */ | 1165 "vp8.fpf" // first pass filename |
1178 #endif | 1166 #endif |
1179 } | 1167 } |
1180 }, | 1168 }, |
1181 { -1, {NOT_IMPLEMENTED}} | 1169 { -1, {NOT_IMPLEMENTED}} |
1182 }; | 1170 }; |
1183 | 1171 |
1184 | |
1185 #ifndef VERSION_STRING | 1172 #ifndef VERSION_STRING |
1186 #define VERSION_STRING | 1173 #define VERSION_STRING |
1187 #endif | 1174 #endif |
1188 CODEC_INTERFACE(vpx_codec_vp9_cx) = { | 1175 CODEC_INTERFACE(vpx_codec_vp9_cx) = { |
1189 "WebM Project VP9 Encoder" VERSION_STRING, | 1176 "WebM Project VP9 Encoder" VERSION_STRING, |
1190 VPX_CODEC_INTERNAL_ABI_VERSION, | 1177 VPX_CODEC_INTERNAL_ABI_VERSION, |
1191 VPX_CODEC_CAP_ENCODER | VPX_CODEC_CAP_PSNR | | 1178 VPX_CODEC_CAP_ENCODER | VPX_CODEC_CAP_PSNR, // vpx_codec_caps_t |
1192 VPX_CODEC_CAP_OUTPUT_PARTITION, | 1179 encoder_init, // vpx_codec_init_fn_t |
1193 /* vpx_codec_caps_t caps; */ | 1180 encoder_destroy, // vpx_codec_destroy_fn_t |
1194 vp9e_init, /* vpx_codec_init_fn_t init; */ | 1181 encoder_ctrl_maps, // vpx_codec_ctrl_fn_map_t |
1195 vp9e_destroy, /* vpx_codec_destroy_fn_t destroy; */ | 1182 NOT_IMPLEMENTED, // vpx_codec_get_mmap_fn_t |
1196 vp9e_ctf_maps, /* vpx_codec_ctrl_fn_map_t *ctrl_maps; */ | 1183 NOT_IMPLEMENTED, // vpx_codec_set_mmap_fn_t |
1197 NOT_IMPLEMENTED, /* vpx_codec_get_mmap_fn_t get_mmap; */ | |
1198 NOT_IMPLEMENTED, /* vpx_codec_set_mmap_fn_t set_mmap; */ | |
1199 { // NOLINT | 1184 { // NOLINT |
1200 NOT_IMPLEMENTED, /* vpx_codec_peek_si_fn_t peek_si; */ | 1185 NOT_IMPLEMENTED, // vpx_codec_peek_si_fn_t |
1201 NOT_IMPLEMENTED, /* vpx_codec_get_si_fn_t get_si; */ | 1186 NOT_IMPLEMENTED, // vpx_codec_get_si_fn_t |
1202 NOT_IMPLEMENTED, /* vpx_codec_decode_fn_t decode; */ | 1187 NOT_IMPLEMENTED, // vpx_codec_decode_fn_t |
1203 NOT_IMPLEMENTED, /* vpx_codec_frame_get_fn_t frame_get; */ | 1188 NOT_IMPLEMENTED, // vpx_codec_frame_get_fn_t |
1204 }, | 1189 }, |
1205 { // NOLINT | 1190 { // NOLINT |
1206 vp9e_usage_cfg_map, /* vpx_codec_enc_cfg_map_t peek_si; */ | 1191 encoder_usage_cfg_map, // vpx_codec_enc_cfg_map_t |
1207 vp9e_encode, /* vpx_codec_encode_fn_t encode; */ | 1192 encoder_encode, // vpx_codec_encode_fn_t |
1208 vp9e_get_cxdata, /* vpx_codec_get_cx_data_fn_t frame_get; */ | 1193 encoder_get_cxdata, // vpx_codec_get_cx_data_fn_t |
1209 vp9e_set_config, | 1194 encoder_set_config, // vpx_codec_enc_config_set_fn_t |
1210 NOT_IMPLEMENTED, | 1195 NOT_IMPLEMENTED, // vpx_codec_get_global_headers_fn_t |
1211 vp9e_get_preview, | 1196 encoder_get_preview, // vpx_codec_get_preview_frame_fn_t |
1212 } /* encoder functions */ | 1197 NOT_IMPLEMENTED , // vpx_codec_enc_mr_get_mem_loc_fn_t |
| 1198 } |
1213 }; | 1199 }; |
OLD | NEW |