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 static vpx_codec_alg_priv_t *get_alg_priv(vpx_codec_ctx_t *ctx) { |
| 24 return (vpx_codec_alg_priv_t *)ctx->priv; |
| 25 } |
| 26 |
23 vpx_codec_err_t vpx_codec_enc_init_ver(vpx_codec_ctx_t *ctx, | 27 vpx_codec_err_t vpx_codec_enc_init_ver(vpx_codec_ctx_t *ctx, |
24 vpx_codec_iface_t *iface, | 28 vpx_codec_iface_t *iface, |
25 vpx_codec_enc_cfg_t *cfg, | 29 const vpx_codec_enc_cfg_t *cfg, |
26 vpx_codec_flags_t flags, | 30 vpx_codec_flags_t flags, |
27 int ver) { | 31 int ver) { |
28 vpx_codec_err_t res; | 32 vpx_codec_err_t res; |
29 | 33 |
30 if (ver != VPX_ENCODER_ABI_VERSION) | 34 if (ver != VPX_ENCODER_ABI_VERSION) |
31 res = VPX_CODEC_ABI_MISMATCH; | 35 res = VPX_CODEC_ABI_MISMATCH; |
32 else if (!ctx || !iface || !cfg) | 36 else if (!ctx || !iface || !cfg) |
33 res = VPX_CODEC_INVALID_PARAM; | 37 res = VPX_CODEC_INVALID_PARAM; |
34 else if (iface->abi_version != VPX_CODEC_INTERNAL_ABI_VERSION) | 38 else if (iface->abi_version != VPX_CODEC_INTERNAL_ABI_VERSION) |
35 res = VPX_CODEC_ABI_MISMATCH; | 39 res = VPX_CODEC_ABI_MISMATCH; |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 res = VPX_CODEC_INCAPABLE; | 213 res = VPX_CODEC_INCAPABLE; |
210 else { | 214 else { |
211 unsigned int num_enc = ctx->priv->enc.total_encoders; | 215 unsigned int num_enc = ctx->priv->enc.total_encoders; |
212 | 216 |
213 /* Execute in a normalized floating point environment, if the platform | 217 /* Execute in a normalized floating point environment, if the platform |
214 * requires it. | 218 * requires it. |
215 */ | 219 */ |
216 FLOATING_POINT_INIT(); | 220 FLOATING_POINT_INIT(); |
217 | 221 |
218 if (num_enc == 1) | 222 if (num_enc == 1) |
219 res = ctx->iface->enc.encode(ctx->priv->alg_priv, img, pts, | 223 res = ctx->iface->enc.encode(get_alg_priv(ctx), img, pts, |
220 duration, flags, deadline); | 224 duration, flags, deadline); |
221 else { | 225 else { |
222 /* Multi-resolution encoding: | 226 /* Multi-resolution encoding: |
223 * Encode multi-levels in reverse order. For example, | 227 * Encode multi-levels in reverse order. For example, |
224 * if mr_total_resolutions = 3, first encode level 2, | 228 * if mr_total_resolutions = 3, first encode level 2, |
225 * then encode level 1, and finally encode level 0. | 229 * then encode level 1, and finally encode level 0. |
226 */ | 230 */ |
227 int i; | 231 int i; |
228 | 232 |
229 ctx += num_enc - 1; | 233 ctx += num_enc - 1; |
230 if (img) img += num_enc - 1; | 234 if (img) img += num_enc - 1; |
231 | 235 |
232 for (i = num_enc - 1; i >= 0; i--) { | 236 for (i = num_enc - 1; i >= 0; i--) { |
233 if ((res = ctx->iface->enc.encode(ctx->priv->alg_priv, img, pts, | 237 if ((res = ctx->iface->enc.encode(get_alg_priv(ctx), img, pts, |
234 duration, flags, deadline))) | 238 duration, flags, deadline))) |
235 break; | 239 break; |
236 | 240 |
237 ctx--; | 241 ctx--; |
238 if (img) img--; | 242 if (img) img--; |
239 } | 243 } |
240 ctx++; | 244 ctx++; |
241 } | 245 } |
242 | 246 |
243 FLOATING_POINT_RESTORE(); | 247 FLOATING_POINT_RESTORE(); |
244 } | 248 } |
245 | 249 |
246 return SAVE_STATUS(ctx, res); | 250 return SAVE_STATUS(ctx, res); |
247 } | 251 } |
248 | 252 |
249 | 253 |
250 const vpx_codec_cx_pkt_t *vpx_codec_get_cx_data(vpx_codec_ctx_t *ctx, | 254 const vpx_codec_cx_pkt_t *vpx_codec_get_cx_data(vpx_codec_ctx_t *ctx, |
251 vpx_codec_iter_t *iter) { | 255 vpx_codec_iter_t *iter) { |
252 const vpx_codec_cx_pkt_t *pkt = NULL; | 256 const vpx_codec_cx_pkt_t *pkt = NULL; |
253 | 257 |
254 if (ctx) { | 258 if (ctx) { |
255 if (!iter) | 259 if (!iter) |
256 ctx->err = VPX_CODEC_INVALID_PARAM; | 260 ctx->err = VPX_CODEC_INVALID_PARAM; |
257 else if (!ctx->iface || !ctx->priv) | 261 else if (!ctx->iface || !ctx->priv) |
258 ctx->err = VPX_CODEC_ERROR; | 262 ctx->err = VPX_CODEC_ERROR; |
259 else if (!(ctx->iface->caps & VPX_CODEC_CAP_ENCODER)) | 263 else if (!(ctx->iface->caps & VPX_CODEC_CAP_ENCODER)) |
260 ctx->err = VPX_CODEC_INCAPABLE; | 264 ctx->err = VPX_CODEC_INCAPABLE; |
261 else | 265 else |
262 pkt = ctx->iface->enc.get_cx_data(ctx->priv->alg_priv, iter); | 266 pkt = ctx->iface->enc.get_cx_data(get_alg_priv(ctx), iter); |
263 } | 267 } |
264 | 268 |
265 if (pkt && pkt->kind == VPX_CODEC_CX_FRAME_PKT) { | 269 if (pkt && pkt->kind == VPX_CODEC_CX_FRAME_PKT) { |
266 // If the application has specified a destination area for the | 270 // If the application has specified a destination area for the |
267 // compressed data, and the codec has not placed the data there, | 271 // compressed data, and the codec has not placed the data there, |
268 // and it fits, copy it. | 272 // and it fits, copy it. |
269 vpx_codec_priv_t *const priv = ctx->priv; | 273 vpx_codec_priv_t *const priv = ctx->priv; |
270 char *const dst_buf = (char *)priv->enc.cx_data_dst_buf.buf; | 274 char *const dst_buf = (char *)priv->enc.cx_data_dst_buf.buf; |
271 | 275 |
272 if (dst_buf && | 276 if (dst_buf && |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 vpx_image_t *img = NULL; | 324 vpx_image_t *img = NULL; |
321 | 325 |
322 if (ctx) { | 326 if (ctx) { |
323 if (!ctx->iface || !ctx->priv) | 327 if (!ctx->iface || !ctx->priv) |
324 ctx->err = VPX_CODEC_ERROR; | 328 ctx->err = VPX_CODEC_ERROR; |
325 else if (!(ctx->iface->caps & VPX_CODEC_CAP_ENCODER)) | 329 else if (!(ctx->iface->caps & VPX_CODEC_CAP_ENCODER)) |
326 ctx->err = VPX_CODEC_INCAPABLE; | 330 ctx->err = VPX_CODEC_INCAPABLE; |
327 else if (!ctx->iface->enc.get_preview) | 331 else if (!ctx->iface->enc.get_preview) |
328 ctx->err = VPX_CODEC_INCAPABLE; | 332 ctx->err = VPX_CODEC_INCAPABLE; |
329 else | 333 else |
330 img = ctx->iface->enc.get_preview(ctx->priv->alg_priv); | 334 img = ctx->iface->enc.get_preview(get_alg_priv(ctx)); |
331 } | 335 } |
332 | 336 |
333 return img; | 337 return img; |
334 } | 338 } |
335 | 339 |
336 | 340 |
337 vpx_fixed_buf_t *vpx_codec_get_global_headers(vpx_codec_ctx_t *ctx) { | 341 vpx_fixed_buf_t *vpx_codec_get_global_headers(vpx_codec_ctx_t *ctx) { |
338 vpx_fixed_buf_t *buf = NULL; | 342 vpx_fixed_buf_t *buf = NULL; |
339 | 343 |
340 if (ctx) { | 344 if (ctx) { |
341 if (!ctx->iface || !ctx->priv) | 345 if (!ctx->iface || !ctx->priv) |
342 ctx->err = VPX_CODEC_ERROR; | 346 ctx->err = VPX_CODEC_ERROR; |
343 else if (!(ctx->iface->caps & VPX_CODEC_CAP_ENCODER)) | 347 else if (!(ctx->iface->caps & VPX_CODEC_CAP_ENCODER)) |
344 ctx->err = VPX_CODEC_INCAPABLE; | 348 ctx->err = VPX_CODEC_INCAPABLE; |
345 else if (!ctx->iface->enc.get_glob_hdrs) | 349 else if (!ctx->iface->enc.get_glob_hdrs) |
346 ctx->err = VPX_CODEC_INCAPABLE; | 350 ctx->err = VPX_CODEC_INCAPABLE; |
347 else | 351 else |
348 buf = ctx->iface->enc.get_glob_hdrs(ctx->priv->alg_priv); | 352 buf = ctx->iface->enc.get_glob_hdrs(get_alg_priv(ctx)); |
349 } | 353 } |
350 | 354 |
351 return buf; | 355 return buf; |
352 } | 356 } |
353 | 357 |
354 | 358 |
355 vpx_codec_err_t vpx_codec_enc_config_set(vpx_codec_ctx_t *ctx, | 359 vpx_codec_err_t vpx_codec_enc_config_set(vpx_codec_ctx_t *ctx, |
356 const vpx_codec_enc_cfg_t *cfg) { | 360 const vpx_codec_enc_cfg_t *cfg) { |
357 vpx_codec_err_t res; | 361 vpx_codec_err_t res; |
358 | 362 |
359 if (!ctx || !ctx->iface || !ctx->priv || !cfg) | 363 if (!ctx || !ctx->iface || !ctx->priv || !cfg) |
360 res = VPX_CODEC_INVALID_PARAM; | 364 res = VPX_CODEC_INVALID_PARAM; |
361 else if (!(ctx->iface->caps & VPX_CODEC_CAP_ENCODER)) | 365 else if (!(ctx->iface->caps & VPX_CODEC_CAP_ENCODER)) |
362 res = VPX_CODEC_INCAPABLE; | 366 res = VPX_CODEC_INCAPABLE; |
363 else | 367 else |
364 res = ctx->iface->enc.cfg_set(ctx->priv->alg_priv, cfg); | 368 res = ctx->iface->enc.cfg_set(get_alg_priv(ctx), cfg); |
365 | 369 |
366 return SAVE_STATUS(ctx, res); | 370 return SAVE_STATUS(ctx, res); |
367 } | 371 } |
368 | 372 |
369 | 373 |
370 int vpx_codec_pkt_list_add(struct vpx_codec_pkt_list *list, | 374 int vpx_codec_pkt_list_add(struct vpx_codec_pkt_list *list, |
371 const struct vpx_codec_cx_pkt *pkt) { | 375 const struct vpx_codec_cx_pkt *pkt) { |
372 if (list->cnt < list->max) { | 376 if (list->cnt < list->max) { |
373 list->pkts[list->cnt++] = *pkt; | 377 list->pkts[list->cnt++] = *pkt; |
374 return 0; | 378 return 0; |
(...skipping 13 matching lines...) Expand all Loading... |
388 | 392 |
389 pkt = (const vpx_codec_cx_pkt_t *)*iter; | 393 pkt = (const vpx_codec_cx_pkt_t *)*iter; |
390 | 394 |
391 if ((size_t)(pkt - list->pkts) < list->cnt) | 395 if ((size_t)(pkt - list->pkts) < list->cnt) |
392 *iter = pkt + 1; | 396 *iter = pkt + 1; |
393 else | 397 else |
394 pkt = NULL; | 398 pkt = NULL; |
395 | 399 |
396 return pkt; | 400 return pkt; |
397 } | 401 } |
OLD | NEW |