Coverage Report

Created: 2026-07-30 06:32

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libvpx/vpx/src/vpx_decoder.c
Line
Count
Source
1
/*
2
 *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3
 *
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
6
 *  tree. An additional intellectual property rights grant can be found
7
 *  in the file PATENTS.  All contributing project authors may
8
 *  be found in the AUTHORS file in the root of the source tree.
9
 */
10
11
/*!\file
12
 * \brief Provides the high level interface to wrap decoder algorithms.
13
 *
14
 */
15
#include <string.h>
16
#include "vpx/internal/vpx_codec_internal.h"
17
18
1.00M
#define SAVE_STATUS(ctx, var) (ctx ? (ctx->err = var) : var)
19
20
1.65M
static vpx_codec_alg_priv_t *get_alg_priv(vpx_codec_ctx_t *ctx) {
21
1.65M
  return (vpx_codec_alg_priv_t *)ctx->priv;
22
1.65M
}
23
24
vpx_codec_err_t vpx_codec_dec_init_ver(vpx_codec_ctx_t *ctx,
25
                                       vpx_codec_iface_t *iface,
26
                                       const vpx_codec_dec_cfg_t *cfg,
27
57.9k
                                       vpx_codec_flags_t flags, int ver) {
28
57.9k
  vpx_codec_err_t res;
29
30
57.9k
  if (ver != VPX_DECODER_ABI_VERSION)
31
0
    res = VPX_CODEC_ABI_MISMATCH;
32
57.9k
  else if (!ctx || !iface)
33
0
    res = VPX_CODEC_INVALID_PARAM;
34
57.9k
  else if (iface->abi_version != VPX_CODEC_INTERNAL_ABI_VERSION)
35
0
    res = VPX_CODEC_ABI_MISMATCH;
36
57.9k
  else if ((flags & VPX_CODEC_USE_POSTPROC) &&
37
19.3k
           !(iface->caps & VPX_CODEC_CAP_POSTPROC))
38
8.90k
    res = VPX_CODEC_INCAPABLE;
39
49.0k
  else if ((flags & VPX_CODEC_USE_ERROR_CONCEALMENT) &&
40
0
           !(iface->caps & VPX_CODEC_CAP_ERROR_CONCEALMENT))
41
0
    res = VPX_CODEC_INCAPABLE;
42
49.0k
  else if ((flags & VPX_CODEC_USE_INPUT_FRAGMENTS) &&
43
0
           !(iface->caps & VPX_CODEC_CAP_INPUT_FRAGMENTS))
44
0
    res = VPX_CODEC_INCAPABLE;
45
49.0k
  else if (!(iface->caps & VPX_CODEC_CAP_DECODER))
46
0
    res = VPX_CODEC_INCAPABLE;
47
49.0k
  else {
48
49.0k
    memset(ctx, 0, sizeof(*ctx));
49
49.0k
    ctx->iface = iface;
50
49.0k
    ctx->name = iface->name;
51
49.0k
    ctx->priv = NULL;
52
49.0k
    ctx->init_flags = flags;
53
49.0k
    ctx->config.dec = cfg;
54
55
49.0k
    res = ctx->iface->init(ctx, NULL);
56
49.0k
    if (res) {
57
0
      ctx->err_detail = ctx->priv ? ctx->priv->err_detail : NULL;
58
0
      vpx_codec_destroy(ctx);
59
0
    }
60
49.0k
  }
61
62
57.9k
  return SAVE_STATUS(ctx, res);
63
57.9k
}
64
65
vpx_codec_err_t vpx_codec_peek_stream_info(vpx_codec_iface_t *iface,
66
                                           const uint8_t *data,
67
                                           unsigned int data_sz,
68
945k
                                           vpx_codec_stream_info_t *si) {
69
945k
  vpx_codec_err_t res;
70
71
945k
  if (!iface || !data || !data_sz || !si ||
72
945k
      si->sz < sizeof(vpx_codec_stream_info_t))
73
0
    res = VPX_CODEC_INVALID_PARAM;
74
945k
  else {
75
    /* Set default/unknown values */
76
945k
    si->w = 0;
77
945k
    si->h = 0;
78
79
945k
    res = iface->dec.peek_si(data, data_sz, si);
80
945k
  }
81
82
945k
  return res;
83
945k
}
84
85
vpx_codec_err_t vpx_codec_get_stream_info(vpx_codec_ctx_t *ctx,
86
0
                                          vpx_codec_stream_info_t *si) {
87
0
  vpx_codec_err_t res;
88
89
0
  if (!ctx || !si || si->sz < sizeof(vpx_codec_stream_info_t))
90
0
    res = VPX_CODEC_INVALID_PARAM;
91
0
  else if (!ctx->iface || !ctx->priv)
92
0
    res = VPX_CODEC_ERROR;
93
0
  else {
94
    /* Set default/unknown values */
95
0
    si->w = 0;
96
0
    si->h = 0;
97
98
0
    res = ctx->iface->dec.get_si(get_alg_priv(ctx), si);
99
0
  }
100
101
0
  return SAVE_STATUS(ctx, res);
102
0
}
103
104
vpx_codec_err_t vpx_codec_decode(vpx_codec_ctx_t *ctx, const uint8_t *data,
105
                                 unsigned int data_sz, void *user_priv,
106
945k
                                 long deadline) {
107
945k
  vpx_codec_err_t res;
108
945k
  (void)deadline;
109
110
  /* Sanity checks */
111
  /* NULL data ptr allowed if data_sz is 0 too */
112
945k
  if (!ctx || (!data && data_sz) || (data && !data_sz))
113
403k
    res = VPX_CODEC_INVALID_PARAM;
114
541k
  else if (!ctx->iface || !ctx->priv)
115
0
    res = VPX_CODEC_ERROR;
116
541k
  else
117
541k
    res = ctx->iface->dec.decode(get_alg_priv(ctx), data, data_sz, user_priv);
118
119
945k
  return SAVE_STATUS(ctx, res);
120
945k
}
121
122
1.11M
vpx_image_t *vpx_codec_get_frame(vpx_codec_ctx_t *ctx, vpx_codec_iter_t *iter) {
123
1.11M
  vpx_image_t *img;
124
125
1.11M
  if (!ctx || !iter || !ctx->iface || !ctx->priv)
126
0
    img = NULL;
127
1.11M
  else
128
1.11M
    img = ctx->iface->dec.get_frame(get_alg_priv(ctx), iter);
129
130
1.11M
  return img;
131
1.11M
}
132
133
vpx_codec_err_t vpx_codec_register_put_frame_cb(vpx_codec_ctx_t *ctx,
134
                                                vpx_codec_put_frame_cb_fn_t cb,
135
0
                                                void *user_priv) {
136
0
  vpx_codec_err_t res;
137
138
0
  if (!ctx || !cb)
139
0
    res = VPX_CODEC_INVALID_PARAM;
140
0
  else if (!ctx->iface || !ctx->priv)
141
0
    res = VPX_CODEC_ERROR;
142
0
  else if (!(ctx->iface->caps & VPX_CODEC_CAP_PUT_FRAME))
143
0
    res = VPX_CODEC_INCAPABLE;
144
0
  else {
145
0
    ctx->priv->dec.put_frame_cb.u.put_frame = cb;
146
0
    ctx->priv->dec.put_frame_cb.user_priv = user_priv;
147
0
    res = VPX_CODEC_OK;
148
0
  }
149
150
0
  return SAVE_STATUS(ctx, res);
151
0
}
152
153
vpx_codec_err_t vpx_codec_register_put_slice_cb(vpx_codec_ctx_t *ctx,
154
                                                vpx_codec_put_slice_cb_fn_t cb,
155
0
                                                void *user_priv) {
156
0
  vpx_codec_err_t res;
157
158
0
  if (!ctx || !cb)
159
0
    res = VPX_CODEC_INVALID_PARAM;
160
0
  else if (!ctx->iface || !ctx->priv)
161
0
    res = VPX_CODEC_ERROR;
162
0
  else if (!(ctx->iface->caps & VPX_CODEC_CAP_PUT_SLICE))
163
0
    res = VPX_CODEC_INCAPABLE;
164
0
  else {
165
0
    ctx->priv->dec.put_slice_cb.u.put_slice = cb;
166
0
    ctx->priv->dec.put_slice_cb.user_priv = user_priv;
167
0
    res = VPX_CODEC_OK;
168
0
  }
169
170
0
  return SAVE_STATUS(ctx, res);
171
0
}
172
173
vpx_codec_err_t vpx_codec_set_frame_buffer_functions(
174
    vpx_codec_ctx_t *ctx, vpx_get_frame_buffer_cb_fn_t cb_get,
175
0
    vpx_release_frame_buffer_cb_fn_t cb_release, void *cb_priv) {
176
0
  vpx_codec_err_t res;
177
178
0
  if (!ctx || !cb_get || !cb_release) {
179
0
    res = VPX_CODEC_INVALID_PARAM;
180
0
  } else if (!ctx->iface || !ctx->priv) {
181
0
    res = VPX_CODEC_ERROR;
182
0
  } else if (!(ctx->iface->caps & VPX_CODEC_CAP_EXTERNAL_FRAME_BUFFER)) {
183
0
    res = VPX_CODEC_INCAPABLE;
184
0
  } else {
185
0
    res = ctx->iface->dec.set_fb_fn(get_alg_priv(ctx), cb_get, cb_release,
186
0
                                    cb_priv);
187
0
  }
188
189
0
  return SAVE_STATUS(ctx, res);
190
0
}