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 | 11 |
12 /*!\file | 12 /*!\file |
13 * \brief Provides the high level interface to wrap encoder algorithms. | 13 * \brief Provides the high level interface to wrap encoder algorithms. |
14 * | 14 * |
15 */ | 15 */ |
16 #include <limits.h> | 16 #include <limits.h> |
17 #include <string.h> | 17 #include <string.h> |
18 #include "vpx/internal/vpx_codec_internal.h" | 18 #include "vpx/internal/vpx_codec_internal.h" |
19 #include "vpx_config.h" | 19 #include "vpx_config.h" |
20 | 20 |
21 #define SAVE_STATUS(ctx,var) (ctx?(ctx->err = var):var) | 21 #define SAVE_STATUS(ctx,var) (ctx?(ctx->err = var):var) |
22 | 22 |
23 vpx_codec_err_t vpx_codec_enc_init_ver(vpx_codec_ctx_t *ctx, | 23 vpx_codec_err_t vpx_codec_enc_init_ver(vpx_codec_ctx_t *ctx, |
24 vpx_codec_iface_t *iface, | 24 vpx_codec_iface_t *iface, |
25 vpx_codec_enc_cfg_t *cfg, | 25 vpx_codec_enc_cfg_t *cfg, |
26 vpx_codec_flags_t flags, | 26 vpx_codec_flags_t flags, |
27 int ver) | 27 int ver) { |
28 { | 28 vpx_codec_err_t res; |
29 vpx_codec_err_t res; | |
30 | 29 |
31 if (ver != VPX_ENCODER_ABI_VERSION) | 30 if (ver != VPX_ENCODER_ABI_VERSION) |
32 res = VPX_CODEC_ABI_MISMATCH; | 31 res = VPX_CODEC_ABI_MISMATCH; |
33 else if (!ctx || !iface || !cfg) | 32 else if (!ctx || !iface || !cfg) |
34 res = VPX_CODEC_INVALID_PARAM; | 33 res = VPX_CODEC_INVALID_PARAM; |
35 else if (iface->abi_version != VPX_CODEC_INTERNAL_ABI_VERSION) | 34 else if (iface->abi_version != VPX_CODEC_INTERNAL_ABI_VERSION) |
36 res = VPX_CODEC_ABI_MISMATCH; | 35 res = VPX_CODEC_ABI_MISMATCH; |
37 else if (!(iface->caps & VPX_CODEC_CAP_ENCODER)) | 36 else if (!(iface->caps & VPX_CODEC_CAP_ENCODER)) |
38 res = VPX_CODEC_INCAPABLE; | 37 res = VPX_CODEC_INCAPABLE; |
39 else if ((flags & VPX_CODEC_USE_XMA) && !(iface->caps & VPX_CODEC_CAP_XMA)) | 38 else if ((flags & VPX_CODEC_USE_XMA) && !(iface->caps & VPX_CODEC_CAP_XMA)) |
40 res = VPX_CODEC_INCAPABLE; | 39 res = VPX_CODEC_INCAPABLE; |
41 else if ((flags & VPX_CODEC_USE_PSNR) | 40 else if ((flags & VPX_CODEC_USE_PSNR) |
42 && !(iface->caps & VPX_CODEC_CAP_PSNR)) | 41 && !(iface->caps & VPX_CODEC_CAP_PSNR)) |
43 res = VPX_CODEC_INCAPABLE; | 42 res = VPX_CODEC_INCAPABLE; |
44 else if ((flags & VPX_CODEC_USE_OUTPUT_PARTITION) | 43 else if ((flags & VPX_CODEC_USE_OUTPUT_PARTITION) |
45 && !(iface->caps & VPX_CODEC_CAP_OUTPUT_PARTITION)) | 44 && !(iface->caps & VPX_CODEC_CAP_OUTPUT_PARTITION)) |
46 res = VPX_CODEC_INCAPABLE; | 45 res = VPX_CODEC_INCAPABLE; |
47 else | 46 else { |
48 { | 47 ctx->iface = iface; |
49 ctx->iface = iface; | 48 ctx->name = iface->name; |
50 ctx->name = iface->name; | 49 ctx->priv = NULL; |
51 ctx->priv = NULL; | 50 ctx->init_flags = flags; |
52 ctx->init_flags = flags; | 51 ctx->config.enc = cfg; |
53 ctx->config.enc = cfg; | 52 res = ctx->iface->init(ctx, NULL); |
54 res = ctx->iface->init(ctx, NULL); | |
55 | 53 |
56 if (res) | 54 if (res) { |
57 { | 55 ctx->err_detail = ctx->priv ? ctx->priv->err_detail : NULL; |
58 ctx->err_detail = ctx->priv ? ctx->priv->err_detail : NULL; | 56 vpx_codec_destroy(ctx); |
59 vpx_codec_destroy(ctx); | |
60 } | |
61 | |
62 if (ctx->priv) | |
63 ctx->priv->iface = ctx->iface; | |
64 } | 57 } |
65 | 58 |
66 return SAVE_STATUS(ctx, res); | 59 if (ctx->priv) |
| 60 ctx->priv->iface = ctx->iface; |
| 61 } |
| 62 |
| 63 return SAVE_STATUS(ctx, res); |
67 } | 64 } |
68 | 65 |
69 vpx_codec_err_t vpx_codec_enc_init_multi_ver(vpx_codec_ctx_t *ctx, | 66 vpx_codec_err_t vpx_codec_enc_init_multi_ver(vpx_codec_ctx_t *ctx, |
70 vpx_codec_iface_t *iface, | 67 vpx_codec_iface_t *iface, |
71 vpx_codec_enc_cfg_t *cfg, | 68 vpx_codec_enc_cfg_t *cfg, |
72 int num_enc, | 69 int num_enc, |
73 vpx_codec_flags_t flags, | 70 vpx_codec_flags_t flags, |
74 vpx_rational_t *dsf, | 71 vpx_rational_t *dsf, |
75 int ver) | 72 int ver) { |
76 { | 73 vpx_codec_err_t res = 0; |
77 vpx_codec_err_t res = 0; | |
78 | 74 |
79 if (ver != VPX_ENCODER_ABI_VERSION) | 75 if (ver != VPX_ENCODER_ABI_VERSION) |
80 res = VPX_CODEC_ABI_MISMATCH; | 76 res = VPX_CODEC_ABI_MISMATCH; |
81 else if (!ctx || !iface || !cfg || (num_enc > 16 || num_enc < 1)) | 77 else if (!ctx || !iface || !cfg || (num_enc > 16 || num_enc < 1)) |
82 res = VPX_CODEC_INVALID_PARAM; | 78 res = VPX_CODEC_INVALID_PARAM; |
83 else if (iface->abi_version != VPX_CODEC_INTERNAL_ABI_VERSION) | 79 else if (iface->abi_version != VPX_CODEC_INTERNAL_ABI_VERSION) |
84 res = VPX_CODEC_ABI_MISMATCH; | 80 res = VPX_CODEC_ABI_MISMATCH; |
85 else if (!(iface->caps & VPX_CODEC_CAP_ENCODER)) | 81 else if (!(iface->caps & VPX_CODEC_CAP_ENCODER)) |
86 res = VPX_CODEC_INCAPABLE; | 82 res = VPX_CODEC_INCAPABLE; |
87 else if ((flags & VPX_CODEC_USE_XMA) && !(iface->caps & VPX_CODEC_CAP_XMA)) | 83 else if ((flags & VPX_CODEC_USE_XMA) && !(iface->caps & VPX_CODEC_CAP_XMA)) |
88 res = VPX_CODEC_INCAPABLE; | 84 res = VPX_CODEC_INCAPABLE; |
89 else if ((flags & VPX_CODEC_USE_PSNR) | 85 else if ((flags & VPX_CODEC_USE_PSNR) |
90 && !(iface->caps & VPX_CODEC_CAP_PSNR)) | 86 && !(iface->caps & VPX_CODEC_CAP_PSNR)) |
91 res = VPX_CODEC_INCAPABLE; | 87 res = VPX_CODEC_INCAPABLE; |
92 else if ((flags & VPX_CODEC_USE_OUTPUT_PARTITION) | 88 else if ((flags & VPX_CODEC_USE_OUTPUT_PARTITION) |
93 && !(iface->caps & VPX_CODEC_CAP_OUTPUT_PARTITION)) | 89 && !(iface->caps & VPX_CODEC_CAP_OUTPUT_PARTITION)) |
94 res = VPX_CODEC_INCAPABLE; | 90 res = VPX_CODEC_INCAPABLE; |
95 else | 91 else { |
96 { | 92 int i; |
97 int i; | 93 void *mem_loc = NULL; |
98 void *mem_loc = NULL; | |
99 | 94 |
100 if(!(res = iface->enc.mr_get_mem_loc(cfg, &mem_loc))) | 95 if (!(res = iface->enc.mr_get_mem_loc(cfg, &mem_loc))) { |
101 { | 96 for (i = 0; i < num_enc; i++) { |
102 for (i = 0; i < num_enc; i++) | 97 vpx_codec_priv_enc_mr_cfg_t mr_cfg; |
103 { | |
104 vpx_codec_priv_enc_mr_cfg_t mr_cfg; | |
105 | 98 |
106 /* Validate down-sampling factor. */ | 99 /* Validate down-sampling factor. */ |
107 if(dsf->num < 1 || dsf->num > 4096 || dsf->den < 1 || | 100 if (dsf->num < 1 || dsf->num > 4096 || dsf->den < 1 || |
108 dsf->den > dsf->num) | 101 dsf->den > dsf->num) { |
109 { | 102 res = VPX_CODEC_INVALID_PARAM; |
110 res = VPX_CODEC_INVALID_PARAM; | 103 break; |
111 break; | 104 } |
112 } | |
113 | 105 |
114 mr_cfg.mr_low_res_mode_info = mem_loc; | 106 mr_cfg.mr_low_res_mode_info = mem_loc; |
115 mr_cfg.mr_total_resolutions = num_enc; | 107 mr_cfg.mr_total_resolutions = num_enc; |
116 mr_cfg.mr_encoder_id = num_enc-1-i; | 108 mr_cfg.mr_encoder_id = num_enc - 1 - i; |
117 mr_cfg.mr_down_sampling_factor.num = dsf->num; | 109 mr_cfg.mr_down_sampling_factor.num = dsf->num; |
118 mr_cfg.mr_down_sampling_factor.den = dsf->den; | 110 mr_cfg.mr_down_sampling_factor.den = dsf->den; |
119 | 111 |
120 /* Force Key-frame synchronization. Namely, encoder at higher | 112 /* Force Key-frame synchronization. Namely, encoder at higher |
121 * resolution always use the same frame_type chosen by the | 113 * resolution always use the same frame_type chosen by the |
122 * lowest-resolution encoder. | 114 * lowest-resolution encoder. |
123 */ | 115 */ |
124 if(mr_cfg.mr_encoder_id) | 116 if (mr_cfg.mr_encoder_id) |
125 cfg->kf_mode = VPX_KF_DISABLED; | 117 cfg->kf_mode = VPX_KF_DISABLED; |
126 | 118 |
127 ctx->iface = iface; | 119 ctx->iface = iface; |
128 ctx->name = iface->name; | 120 ctx->name = iface->name; |
129 ctx->priv = NULL; | 121 ctx->priv = NULL; |
130 ctx->init_flags = flags; | 122 ctx->init_flags = flags; |
131 ctx->config.enc = cfg; | 123 ctx->config.enc = cfg; |
132 res = ctx->iface->init(ctx, &mr_cfg); | 124 res = ctx->iface->init(ctx, &mr_cfg); |
133 | 125 |
134 if (res) | 126 if (res) { |
135 { | 127 const char *error_detail = |
136 const char *error_detail = | 128 ctx->priv ? ctx->priv->err_detail : NULL; |
137 ctx->priv ? ctx->priv->err_detail : NULL; | 129 /* Destroy current ctx */ |
138 /* Destroy current ctx */ | 130 ctx->err_detail = error_detail; |
139 ctx->err_detail = error_detail; | 131 vpx_codec_destroy(ctx); |
140 vpx_codec_destroy(ctx); | |
141 | 132 |
142 /* Destroy already allocated high-level ctx */ | 133 /* Destroy already allocated high-level ctx */ |
143 while (i) | 134 while (i) { |
144 { | 135 ctx--; |
145 ctx--; | 136 ctx->err_detail = error_detail; |
146 ctx->err_detail = error_detail; | 137 vpx_codec_destroy(ctx); |
147 vpx_codec_destroy(ctx); | 138 i--; |
148 i--; | 139 } |
149 } | 140 } |
150 } | |
151 | 141 |
152 if (ctx->priv) | 142 if (ctx->priv) |
153 ctx->priv->iface = ctx->iface; | 143 ctx->priv->iface = ctx->iface; |
154 | 144 |
155 if (res) | 145 if (res) |
156 break; | 146 break; |
157 | 147 |
158 ctx++; | 148 ctx++; |
159 cfg++; | 149 cfg++; |
160 dsf++; | 150 dsf++; |
161 } | 151 } |
162 } | |
163 } | 152 } |
| 153 } |
164 | 154 |
165 return SAVE_STATUS(ctx, res); | 155 return SAVE_STATUS(ctx, res); |
166 } | 156 } |
167 | 157 |
168 | 158 |
169 vpx_codec_err_t vpx_codec_enc_config_default(vpx_codec_iface_t *iface, | 159 vpx_codec_err_t vpx_codec_enc_config_default(vpx_codec_iface_t *iface, |
170 vpx_codec_enc_cfg_t *cfg, | 160 vpx_codec_enc_cfg_t *cfg, |
171 unsigned int usage) | 161 unsigned int usage) { |
172 { | 162 vpx_codec_err_t res; |
173 vpx_codec_err_t res; | 163 vpx_codec_enc_cfg_map_t *map; |
174 vpx_codec_enc_cfg_map_t *map; | |
175 | 164 |
176 if (!iface || !cfg || usage > INT_MAX) | 165 if (!iface || !cfg || usage > INT_MAX) |
177 res = VPX_CODEC_INVALID_PARAM; | 166 res = VPX_CODEC_INVALID_PARAM; |
178 else if (!(iface->caps & VPX_CODEC_CAP_ENCODER)) | 167 else if (!(iface->caps & VPX_CODEC_CAP_ENCODER)) |
179 res = VPX_CODEC_INCAPABLE; | 168 res = VPX_CODEC_INCAPABLE; |
180 else | 169 else { |
181 { | 170 res = VPX_CODEC_INVALID_PARAM; |
182 res = VPX_CODEC_INVALID_PARAM; | |
183 | 171 |
184 for (map = iface->enc.cfg_maps; map->usage >= 0; map++) | 172 for (map = iface->enc.cfg_maps; map->usage >= 0; map++) { |
185 { | 173 if (map->usage == (int)usage) { |
186 if (map->usage == (int)usage) | 174 *cfg = map->cfg; |
187 { | 175 cfg->g_usage = usage; |
188 *cfg = map->cfg; | 176 res = VPX_CODEC_OK; |
189 cfg->g_usage = usage; | 177 break; |
190 res = VPX_CODEC_OK; | 178 } |
191 break; | |
192 } | |
193 } | |
194 } | 179 } |
| 180 } |
195 | 181 |
196 return res; | 182 return res; |
197 } | 183 } |
198 | 184 |
199 | 185 |
200 #if ARCH_X86 || ARCH_X86_64 | 186 #if ARCH_X86 || ARCH_X86_64 |
201 /* On X86, disable the x87 unit's internal 80 bit precision for better | 187 /* On X86, disable the x87 unit's internal 80 bit precision for better |
202 * consistency with the SSE unit's 64 bit precision. | 188 * consistency with the SSE unit's 64 bit precision. |
203 */ | 189 */ |
204 #include "vpx_ports/x86.h" | 190 #include "vpx_ports/x86.h" |
205 #define FLOATING_POINT_INIT() do {\ | 191 #define FLOATING_POINT_INIT() do {\ |
206 unsigned short x87_orig_mode = x87_set_double_precision(); | 192 unsigned short x87_orig_mode = x87_set_double_precision(); |
207 #define FLOATING_POINT_RESTORE() \ | 193 #define FLOATING_POINT_RESTORE() \ |
208 x87_set_control_word(x87_orig_mode); }while(0) | 194 x87_set_control_word(x87_orig_mode); }while(0) |
209 | 195 |
210 | 196 |
211 #else | 197 #else |
212 static void FLOATING_POINT_INIT() {} | 198 static void FLOATING_POINT_INIT() {} |
213 static void FLOATING_POINT_RESTORE() {} | 199 static void FLOATING_POINT_RESTORE() {} |
214 #endif | 200 #endif |
215 | 201 |
216 | 202 |
217 vpx_codec_err_t vpx_codec_encode(vpx_codec_ctx_t *ctx, | 203 vpx_codec_err_t vpx_codec_encode(vpx_codec_ctx_t *ctx, |
218 const vpx_image_t *img, | 204 const vpx_image_t *img, |
219 vpx_codec_pts_t pts, | 205 vpx_codec_pts_t pts, |
220 unsigned long duration, | 206 unsigned long duration, |
221 vpx_enc_frame_flags_t flags, | 207 vpx_enc_frame_flags_t flags, |
222 unsigned long deadline) | 208 unsigned long deadline) { |
223 { | 209 vpx_codec_err_t res = 0; |
224 vpx_codec_err_t res = 0; | 210 |
225 | 211 if (!ctx || (img && !duration)) |
226 if (!ctx || (img && !duration)) | 212 res = VPX_CODEC_INVALID_PARAM; |
227 res = VPX_CODEC_INVALID_PARAM; | 213 else if (!ctx->iface || !ctx->priv) |
| 214 res = VPX_CODEC_ERROR; |
| 215 else if (!(ctx->iface->caps & VPX_CODEC_CAP_ENCODER)) |
| 216 res = VPX_CODEC_INCAPABLE; |
| 217 else { |
| 218 /* Execute in a normalized floating point environment, if the platform |
| 219 * requires it. |
| 220 */ |
| 221 unsigned int num_enc = ctx->priv->enc.total_encoders; |
| 222 |
| 223 FLOATING_POINT_INIT(); |
| 224 |
| 225 if (num_enc == 1) |
| 226 res = ctx->iface->enc.encode(ctx->priv->alg_priv, img, pts, |
| 227 duration, flags, deadline); |
| 228 else { |
| 229 /* Multi-resolution encoding: |
| 230 * Encode multi-levels in reverse order. For example, |
| 231 * if mr_total_resolutions = 3, first encode level 2, |
| 232 * then encode level 1, and finally encode level 0. |
| 233 */ |
| 234 int i; |
| 235 |
| 236 ctx += num_enc - 1; |
| 237 if (img) img += num_enc - 1; |
| 238 |
| 239 for (i = num_enc - 1; i >= 0; i--) { |
| 240 if ((res = ctx->iface->enc.encode(ctx->priv->alg_priv, img, pts, |
| 241 duration, flags, deadline))) |
| 242 break; |
| 243 |
| 244 ctx--; |
| 245 if (img) img--; |
| 246 } |
| 247 ctx++; |
| 248 } |
| 249 |
| 250 FLOATING_POINT_RESTORE(); |
| 251 } |
| 252 |
| 253 return SAVE_STATUS(ctx, res); |
| 254 } |
| 255 |
| 256 |
| 257 const vpx_codec_cx_pkt_t *vpx_codec_get_cx_data(vpx_codec_ctx_t *ctx, |
| 258 vpx_codec_iter_t *iter) { |
| 259 const vpx_codec_cx_pkt_t *pkt = NULL; |
| 260 |
| 261 if (ctx) { |
| 262 if (!iter) |
| 263 ctx->err = VPX_CODEC_INVALID_PARAM; |
228 else if (!ctx->iface || !ctx->priv) | 264 else if (!ctx->iface || !ctx->priv) |
229 res = VPX_CODEC_ERROR; | 265 ctx->err = VPX_CODEC_ERROR; |
230 else if (!(ctx->iface->caps & VPX_CODEC_CAP_ENCODER)) | 266 else if (!(ctx->iface->caps & VPX_CODEC_CAP_ENCODER)) |
231 res = VPX_CODEC_INCAPABLE; | 267 ctx->err = VPX_CODEC_INCAPABLE; |
232 else | 268 else |
233 { | 269 pkt = ctx->iface->enc.get_cx_data(ctx->priv->alg_priv, iter); |
234 /* Execute in a normalized floating point environment, if the platform | 270 } |
235 * requires it. | 271 |
236 */ | 272 if (pkt && pkt->kind == VPX_CODEC_CX_FRAME_PKT) { |
237 unsigned int num_enc =ctx->priv->enc.total_encoders; | 273 /* If the application has specified a destination area for the |
238 | 274 * compressed data, and the codec has not placed the data there, |
239 FLOATING_POINT_INIT(); | 275 * and it fits, copy it. |
240 | 276 */ |
241 if (num_enc == 1) | 277 char *dst_buf = ctx->priv->enc.cx_data_dst_buf.buf; |
242 res = ctx->iface->enc.encode(ctx->priv->alg_priv, img, pts, | 278 |
243 duration, flags, deadline); | 279 if (dst_buf |
244 else | 280 && pkt->data.raw.buf != dst_buf |
245 { | 281 && pkt->data.raw.sz |
246 /* Multi-resolution encoding: | 282 + ctx->priv->enc.cx_data_pad_before |
247 * Encode multi-levels in reverse order. For example, | 283 + ctx->priv->enc.cx_data_pad_after |
248 * if mr_total_resolutions = 3, first encode level 2, | 284 <= ctx->priv->enc.cx_data_dst_buf.sz) { |
249 * then encode level 1, and finally encode level 0. | 285 vpx_codec_cx_pkt_t *modified_pkt = &ctx->priv->enc.cx_data_pkt; |
250 */ | 286 |
251 int i; | 287 memcpy(dst_buf + ctx->priv->enc.cx_data_pad_before, |
252 | 288 pkt->data.raw.buf, pkt->data.raw.sz); |
253 ctx += num_enc - 1; | 289 *modified_pkt = *pkt; |
254 if (img) img += num_enc - 1; | 290 modified_pkt->data.raw.buf = dst_buf; |
255 | 291 modified_pkt->data.raw.sz += ctx->priv->enc.cx_data_pad_before |
256 for (i = num_enc-1; i >= 0; i--) | 292 + ctx->priv->enc.cx_data_pad_after; |
257 { | 293 pkt = modified_pkt; |
258 if ((res = ctx->iface->enc.encode(ctx->priv->alg_priv, img, pts, | |
259 duration, flags, deadline))) | |
260 break; | |
261 | |
262 ctx--; | |
263 if (img) img--; | |
264 } | |
265 ctx++; | |
266 } | |
267 | |
268 FLOATING_POINT_RESTORE(); | |
269 } | 294 } |
270 | 295 |
271 return SAVE_STATUS(ctx, res); | 296 if (dst_buf == pkt->data.raw.buf) { |
272 } | 297 ctx->priv->enc.cx_data_dst_buf.buf = dst_buf + pkt->data.raw.sz; |
273 | 298 ctx->priv->enc.cx_data_dst_buf.sz -= pkt->data.raw.sz; |
274 | |
275 const vpx_codec_cx_pkt_t *vpx_codec_get_cx_data(vpx_codec_ctx_t *ctx, | |
276 vpx_codec_iter_t *iter) | |
277 { | |
278 const vpx_codec_cx_pkt_t *pkt = NULL; | |
279 | |
280 if (ctx) | |
281 { | |
282 if (!iter) | |
283 ctx->err = VPX_CODEC_INVALID_PARAM; | |
284 else if (!ctx->iface || !ctx->priv) | |
285 ctx->err = VPX_CODEC_ERROR; | |
286 else if (!(ctx->iface->caps & VPX_CODEC_CAP_ENCODER)) | |
287 ctx->err = VPX_CODEC_INCAPABLE; | |
288 else | |
289 pkt = ctx->iface->enc.get_cx_data(ctx->priv->alg_priv, iter); | |
290 } | 299 } |
291 | 300 } |
292 if (pkt && pkt->kind == VPX_CODEC_CX_FRAME_PKT) | 301 |
293 { | 302 return pkt; |
294 /* If the application has specified a destination area for the | |
295 * compressed data, and the codec has not placed the data there, | |
296 * and it fits, copy it. | |
297 */ | |
298 char *dst_buf = ctx->priv->enc.cx_data_dst_buf.buf; | |
299 | |
300 if (dst_buf | |
301 && pkt->data.raw.buf != dst_buf | |
302 && pkt->data.raw.sz | |
303 + ctx->priv->enc.cx_data_pad_before | |
304 + ctx->priv->enc.cx_data_pad_after | |
305 <= ctx->priv->enc.cx_data_dst_buf.sz) | |
306 { | |
307 vpx_codec_cx_pkt_t *modified_pkt = &ctx->priv->enc.cx_data_pkt; | |
308 | |
309 memcpy(dst_buf + ctx->priv->enc.cx_data_pad_before, | |
310 pkt->data.raw.buf, pkt->data.raw.sz); | |
311 *modified_pkt = *pkt; | |
312 modified_pkt->data.raw.buf = dst_buf; | |
313 modified_pkt->data.raw.sz += ctx->priv->enc.cx_data_pad_before | |
314 + ctx->priv->enc.cx_data_pad_after; | |
315 pkt = modified_pkt; | |
316 } | |
317 | |
318 if (dst_buf == pkt->data.raw.buf) | |
319 { | |
320 ctx->priv->enc.cx_data_dst_buf.buf = dst_buf + pkt->data.raw.sz; | |
321 ctx->priv->enc.cx_data_dst_buf.sz -= pkt->data.raw.sz; | |
322 } | |
323 } | |
324 | |
325 return pkt; | |
326 } | 303 } |
327 | 304 |
328 | 305 |
329 vpx_codec_err_t vpx_codec_set_cx_data_buf(vpx_codec_ctx_t *ctx, | 306 vpx_codec_err_t vpx_codec_set_cx_data_buf(vpx_codec_ctx_t *ctx, |
330 const vpx_fixed_buf_t *buf, | 307 const vpx_fixed_buf_t *buf, |
331 unsigned int pad_before, | 308 unsigned int pad_before, |
332 unsigned int pad_after) | 309 unsigned int pad_after) { |
333 { | 310 if (!ctx || !ctx->priv) |
334 if (!ctx || !ctx->priv) | 311 return VPX_CODEC_INVALID_PARAM; |
335 return VPX_CODEC_INVALID_PARAM; | 312 |
336 | 313 if (buf) { |
337 if (buf) | 314 ctx->priv->enc.cx_data_dst_buf = *buf; |
338 { | 315 ctx->priv->enc.cx_data_pad_before = pad_before; |
339 ctx->priv->enc.cx_data_dst_buf = *buf; | 316 ctx->priv->enc.cx_data_pad_after = pad_after; |
340 ctx->priv->enc.cx_data_pad_before = pad_before; | 317 } else { |
341 ctx->priv->enc.cx_data_pad_after = pad_after; | 318 ctx->priv->enc.cx_data_dst_buf.buf = NULL; |
342 } | 319 ctx->priv->enc.cx_data_dst_buf.sz = 0; |
| 320 ctx->priv->enc.cx_data_pad_before = 0; |
| 321 ctx->priv->enc.cx_data_pad_after = 0; |
| 322 } |
| 323 |
| 324 return VPX_CODEC_OK; |
| 325 } |
| 326 |
| 327 |
| 328 const vpx_image_t *vpx_codec_get_preview_frame(vpx_codec_ctx_t *ctx) { |
| 329 vpx_image_t *img = NULL; |
| 330 |
| 331 if (ctx) { |
| 332 if (!ctx->iface || !ctx->priv) |
| 333 ctx->err = VPX_CODEC_ERROR; |
| 334 else if (!(ctx->iface->caps & VPX_CODEC_CAP_ENCODER)) |
| 335 ctx->err = VPX_CODEC_INCAPABLE; |
| 336 else if (!ctx->iface->enc.get_preview) |
| 337 ctx->err = VPX_CODEC_INCAPABLE; |
343 else | 338 else |
344 { | 339 img = ctx->iface->enc.get_preview(ctx->priv->alg_priv); |
345 ctx->priv->enc.cx_data_dst_buf.buf = NULL; | 340 } |
346 ctx->priv->enc.cx_data_dst_buf.sz = 0; | 341 |
347 ctx->priv->enc.cx_data_pad_before = 0; | 342 return img; |
348 ctx->priv->enc.cx_data_pad_after = 0; | 343 } |
349 } | 344 |
350 | 345 |
351 return VPX_CODEC_OK; | 346 vpx_fixed_buf_t *vpx_codec_get_global_headers(vpx_codec_ctx_t *ctx) { |
352 } | 347 vpx_fixed_buf_t *buf = NULL; |
353 | 348 |
354 | 349 if (ctx) { |
355 const vpx_image_t *vpx_codec_get_preview_frame(vpx_codec_ctx_t *ctx) | 350 if (!ctx->iface || !ctx->priv) |
356 { | 351 ctx->err = VPX_CODEC_ERROR; |
357 vpx_image_t *img = NULL; | 352 else if (!(ctx->iface->caps & VPX_CODEC_CAP_ENCODER)) |
358 | 353 ctx->err = VPX_CODEC_INCAPABLE; |
359 if (ctx) | 354 else if (!ctx->iface->enc.get_glob_hdrs) |
360 { | 355 ctx->err = VPX_CODEC_INCAPABLE; |
361 if (!ctx->iface || !ctx->priv) | 356 else |
362 ctx->err = VPX_CODEC_ERROR; | 357 buf = ctx->iface->enc.get_glob_hdrs(ctx->priv->alg_priv); |
363 else if (!(ctx->iface->caps & VPX_CODEC_CAP_ENCODER)) | 358 } |
364 ctx->err = VPX_CODEC_INCAPABLE; | 359 |
365 else if (!ctx->iface->enc.get_preview) | 360 return buf; |
366 ctx->err = VPX_CODEC_INCAPABLE; | |
367 else | |
368 img = ctx->iface->enc.get_preview(ctx->priv->alg_priv); | |
369 } | |
370 | |
371 return img; | |
372 } | |
373 | |
374 | |
375 vpx_fixed_buf_t *vpx_codec_get_global_headers(vpx_codec_ctx_t *ctx) | |
376 { | |
377 vpx_fixed_buf_t *buf = NULL; | |
378 | |
379 if (ctx) | |
380 { | |
381 if (!ctx->iface || !ctx->priv) | |
382 ctx->err = VPX_CODEC_ERROR; | |
383 else if (!(ctx->iface->caps & VPX_CODEC_CAP_ENCODER)) | |
384 ctx->err = VPX_CODEC_INCAPABLE; | |
385 else if (!ctx->iface->enc.get_glob_hdrs) | |
386 ctx->err = VPX_CODEC_INCAPABLE; | |
387 else | |
388 buf = ctx->iface->enc.get_glob_hdrs(ctx->priv->alg_priv); | |
389 } | |
390 | |
391 return buf; | |
392 } | 361 } |
393 | 362 |
394 | 363 |
395 vpx_codec_err_t vpx_codec_enc_config_set(vpx_codec_ctx_t *ctx, | 364 vpx_codec_err_t vpx_codec_enc_config_set(vpx_codec_ctx_t *ctx, |
396 const vpx_codec_enc_cfg_t *cfg) | 365 const vpx_codec_enc_cfg_t *cfg) { |
397 { | 366 vpx_codec_err_t res; |
398 vpx_codec_err_t res; | 367 |
399 | 368 if (!ctx || !ctx->iface || !ctx->priv || !cfg) |
400 if (!ctx || !ctx->iface || !ctx->priv || !cfg) | 369 res = VPX_CODEC_INVALID_PARAM; |
401 res = VPX_CODEC_INVALID_PARAM; | 370 else if (!(ctx->iface->caps & VPX_CODEC_CAP_ENCODER)) |
402 else if (!(ctx->iface->caps & VPX_CODEC_CAP_ENCODER)) | 371 res = VPX_CODEC_INCAPABLE; |
403 res = VPX_CODEC_INCAPABLE; | 372 else |
404 else | 373 res = ctx->iface->enc.cfg_set(ctx->priv->alg_priv, cfg); |
405 res = ctx->iface->enc.cfg_set(ctx->priv->alg_priv, cfg); | 374 |
406 | 375 return SAVE_STATUS(ctx, res); |
407 return SAVE_STATUS(ctx, res); | |
408 } | 376 } |
409 | 377 |
410 | 378 |
411 int vpx_codec_pkt_list_add(struct vpx_codec_pkt_list *list, | 379 int vpx_codec_pkt_list_add(struct vpx_codec_pkt_list *list, |
412 const struct vpx_codec_cx_pkt *pkt) | 380 const struct vpx_codec_cx_pkt *pkt) { |
413 { | 381 if (list->cnt < list->max) { |
414 if (list->cnt < list->max) | 382 list->pkts[list->cnt++] = *pkt; |
415 { | 383 return 0; |
416 list->pkts[list->cnt++] = *pkt; | 384 } |
417 return 0; | 385 |
418 } | 386 return 1; |
419 | |
420 return 1; | |
421 } | 387 } |
422 | 388 |
423 | 389 |
424 const vpx_codec_cx_pkt_t *vpx_codec_pkt_list_get(struct vpx_codec_pkt_list *list
, | 390 const vpx_codec_cx_pkt_t *vpx_codec_pkt_list_get(struct vpx_codec_pkt_list *list
, |
425 vpx_codec_iter_t *iter) | 391 vpx_codec_iter_t *ite
r) { |
426 { | 392 const vpx_codec_cx_pkt_t *pkt; |
427 const vpx_codec_cx_pkt_t *pkt; | 393 |
428 | 394 if (!(*iter)) { |
429 if (!(*iter)) | 395 *iter = list->pkts; |
430 { | 396 } |
431 *iter = list->pkts; | 397 |
432 } | 398 pkt = (const void *) * iter; |
433 | 399 |
434 pkt = (const void *) * iter; | 400 if ((size_t)(pkt - list->pkts) < list->cnt) |
435 | 401 *iter = pkt + 1; |
436 if ((size_t)(pkt - list->pkts) < list->cnt) | 402 else |
437 *iter = pkt + 1; | 403 pkt = NULL; |
438 else | 404 |
439 pkt = NULL; | 405 return pkt; |
440 | 406 } |
441 return pkt; | |
442 } | |
OLD | NEW |