Coverage Report

Created: 2024-06-18 06:48

/src/aom/aom/src/aom_decoder.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
3
 *
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.
10
 */
11
12
/*!\file
13
 * \brief Provides the high level interface to wrap decoder algorithms.
14
 *
15
 */
16
#include <string.h>
17
#include "aom/internal/aom_codec_internal.h"
18
19
478k
#define SAVE_STATUS(ctx, var) (ctx ? (ctx->err = var) : var)
20
21
1.02M
static aom_codec_alg_priv_t *get_alg_priv(aom_codec_ctx_t *ctx) {
22
1.02M
  return (aom_codec_alg_priv_t *)ctx->priv;
23
1.02M
}
24
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
16.8k
                                       aom_codec_flags_t flags, int ver) {
29
16.8k
  aom_codec_err_t res;
30
31
16.8k
  if (ver != AOM_DECODER_ABI_VERSION)
32
0
    res = AOM_CODEC_ABI_MISMATCH;
33
16.8k
  else if (!ctx || !iface)
34
0
    res = AOM_CODEC_INVALID_PARAM;
35
16.8k
  else if (iface->abi_version != AOM_CODEC_INTERNAL_ABI_VERSION)
36
0
    res = AOM_CODEC_ABI_MISMATCH;
37
16.8k
  else if (!(iface->caps & AOM_CODEC_CAP_DECODER))
38
0
    res = AOM_CODEC_INCAPABLE;
39
16.8k
  else {
40
16.8k
    memset(ctx, 0, sizeof(*ctx));
41
16.8k
    ctx->iface = iface;
42
16.8k
    ctx->name = iface->name;
43
16.8k
    ctx->priv = NULL;
44
16.8k
    ctx->init_flags = flags;
45
16.8k
    ctx->config.dec = cfg;
46
47
16.8k
    res = ctx->iface->init(ctx);
48
16.8k
    if (res) {
49
0
      ctx->err_detail = ctx->priv ? ctx->priv->err_detail : NULL;
50
0
      aom_codec_destroy(ctx);
51
0
    }
52
16.8k
  }
53
54
16.8k
  return SAVE_STATUS(ctx, res);
55
16.8k
}
56
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
462k
                                           aom_codec_stream_info_t *si) {
60
462k
  aom_codec_err_t res;
61
62
462k
  if (!iface || !data || !data_sz || !si) {
63
0
    res = AOM_CODEC_INVALID_PARAM;
64
462k
  } else {
65
    /* Set default/unknown values */
66
462k
    si->w = 0;
67
462k
    si->h = 0;
68
69
462k
    res = iface->dec.peek_si(data, data_sz, si);
70
462k
  }
71
72
462k
  return res;
73
462k
}
74
75
aom_codec_err_t aom_codec_get_stream_info(aom_codec_ctx_t *ctx,
76
0
                                          aom_codec_stream_info_t *si) {
77
0
  aom_codec_err_t res;
78
79
0
  if (!ctx || !si) {
80
0
    res = AOM_CODEC_INVALID_PARAM;
81
0
  } else if (!ctx->iface || !ctx->priv) {
82
0
    res = AOM_CODEC_ERROR;
83
0
  } else {
84
    /* Set default/unknown values */
85
0
    si->w = 0;
86
0
    si->h = 0;
87
88
0
    res = ctx->iface->dec.get_si(get_alg_priv(ctx), si);
89
0
  }
90
91
0
  return SAVE_STATUS(ctx, res);
92
0
}
93
94
aom_codec_err_t aom_codec_decode(aom_codec_ctx_t *ctx, const uint8_t *data,
95
462k
                                 size_t data_sz, void *user_priv) {
96
462k
  aom_codec_err_t res;
97
98
462k
  if (!ctx)
99
0
    res = AOM_CODEC_INVALID_PARAM;
100
462k
  else if (!ctx->iface || !ctx->priv)
101
0
    res = AOM_CODEC_ERROR;
102
462k
  else {
103
462k
    res = ctx->iface->dec.decode(get_alg_priv(ctx), data, data_sz, user_priv);
104
462k
  }
105
106
462k
  return SAVE_STATUS(ctx, res);
107
462k
}
108
109
560k
aom_image_t *aom_codec_get_frame(aom_codec_ctx_t *ctx, aom_codec_iter_t *iter) {
110
560k
  aom_image_t *img;
111
112
560k
  if (!ctx || !iter || !ctx->iface || !ctx->priv)
113
0
    img = NULL;
114
560k
  else
115
560k
    img = ctx->iface->dec.get_frame(get_alg_priv(ctx), iter);
116
117
560k
  return img;
118
560k
}
119
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
0
    aom_release_frame_buffer_cb_fn_t cb_release, void *cb_priv) {
123
0
  aom_codec_err_t res;
124
125
0
  if (!ctx || !cb_get || !cb_release) {
126
0
    res = AOM_CODEC_INVALID_PARAM;
127
0
  } else if (!ctx->iface || !ctx->priv) {
128
0
    res = AOM_CODEC_ERROR;
129
0
  } else if (!(ctx->iface->caps & AOM_CODEC_CAP_EXTERNAL_FRAME_BUFFER)) {
130
0
    res = AOM_CODEC_INCAPABLE;
131
0
  } else {
132
0
    res = ctx->iface->dec.set_fb_fn(get_alg_priv(ctx), cb_get, cb_release,
133
0
                                    cb_priv);
134
0
  }
135
136
0
  return SAVE_STATUS(ctx, res);
137
0
}