2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
4 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
13 * \brief Provides the high level interface to wrap decoder algorithms.
17 #include "aom/internal/aom_codec_internal.h"
19 #define SAVE_STATUS(ctx, var) (ctx ? (ctx->err = var) : var)
21 static aom_codec_alg_priv_t
*get_alg_priv(aom_codec_ctx_t
*ctx
) {
22 return (aom_codec_alg_priv_t
*)ctx
->priv
;
25 aom_codec_err_t
aom_codec_dec_init_ver(aom_codec_ctx_t
*ctx
,
26 aom_codec_iface_t
*iface
,
27 const aom_codec_dec_cfg_t
*cfg
,
28 aom_codec_flags_t flags
, int ver
) {
31 if (ver
!= AOM_DECODER_ABI_VERSION
)
32 res
= AOM_CODEC_ABI_MISMATCH
;
33 else if (!ctx
|| !iface
)
34 res
= AOM_CODEC_INVALID_PARAM
;
35 else if (iface
->abi_version
!= AOM_CODEC_INTERNAL_ABI_VERSION
)
36 res
= AOM_CODEC_ABI_MISMATCH
;
37 else if (!(iface
->caps
& AOM_CODEC_CAP_DECODER
))
38 res
= AOM_CODEC_INCAPABLE
;
40 memset(ctx
, 0, sizeof(*ctx
));
42 ctx
->name
= iface
->name
;
44 ctx
->init_flags
= flags
;
45 ctx
->config
.dec
= cfg
;
47 res
= ctx
->iface
->init(ctx
);
49 ctx
->err_detail
= ctx
->priv
? ctx
->priv
->err_detail
: NULL
;
50 aom_codec_destroy(ctx
);
54 return SAVE_STATUS(ctx
, res
);
57 aom_codec_err_t
aom_codec_peek_stream_info(aom_codec_iface_t
*iface
,
58 const uint8_t *data
, size_t data_sz
,
59 aom_codec_stream_info_t
*si
) {
62 if (!iface
|| !data
|| !data_sz
|| !si
) {
63 res
= AOM_CODEC_INVALID_PARAM
;
65 /* Set default/unknown values */
69 res
= iface
->dec
.peek_si(data
, data_sz
, si
);
75 aom_codec_err_t
aom_codec_get_stream_info(aom_codec_ctx_t
*ctx
,
76 aom_codec_stream_info_t
*si
) {
80 res
= AOM_CODEC_INVALID_PARAM
;
81 } else if (!ctx
->iface
|| !ctx
->priv
) {
82 res
= AOM_CODEC_ERROR
;
84 /* Set default/unknown values */
88 res
= ctx
->iface
->dec
.get_si(get_alg_priv(ctx
), si
);
91 return SAVE_STATUS(ctx
, res
);
94 aom_codec_err_t
aom_codec_decode(aom_codec_ctx_t
*ctx
, const uint8_t *data
,
95 size_t data_sz
, void *user_priv
) {
99 res
= AOM_CODEC_INVALID_PARAM
;
100 else if (!ctx
->iface
|| !ctx
->priv
)
101 res
= AOM_CODEC_ERROR
;
103 res
= ctx
->iface
->dec
.decode(get_alg_priv(ctx
), data
, data_sz
, user_priv
);
106 return SAVE_STATUS(ctx
, res
);
109 aom_image_t
*aom_codec_get_frame(aom_codec_ctx_t
*ctx
, aom_codec_iter_t
*iter
) {
112 if (!ctx
|| !iter
|| !ctx
->iface
|| !ctx
->priv
)
115 img
= ctx
->iface
->dec
.get_frame(get_alg_priv(ctx
), iter
);
120 aom_codec_err_t
aom_codec_set_frame_buffer_functions(
121 aom_codec_ctx_t
*ctx
, aom_get_frame_buffer_cb_fn_t cb_get
,
122 aom_release_frame_buffer_cb_fn_t cb_release
, void *cb_priv
) {
125 if (!ctx
|| !cb_get
|| !cb_release
) {
126 res
= AOM_CODEC_INVALID_PARAM
;
127 } else if (!ctx
->iface
|| !ctx
->priv
) {
128 res
= AOM_CODEC_ERROR
;
129 } else if (!(ctx
->iface
->caps
& AOM_CODEC_CAP_EXTERNAL_FRAME_BUFFER
)) {
130 res
= AOM_CODEC_INCAPABLE
;
132 res
= ctx
->iface
->dec
.set_fb_fn(get_alg_priv(ctx
), cb_get
, cb_release
,
136 return SAVE_STATUS(ctx
, res
);