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
12 /*!\file vpx_decoder.c
13 * \brief Provides the high level interface to wrap decoder algorithms.
14 *
15 */
16 #include <stdlib.h>
17 #include <string.h>
18 #include "vpx/vpx_decoder.h"
19 #include "vpx/internal/vpx_codec_internal.h"
20
21 #define SAVE_STATUS(ctx,var) (ctx?(ctx->err = var):var)
22
vpx_dec_iface_name(vpx_dec_iface_t * iface)23 const char *vpx_dec_iface_name(vpx_dec_iface_t *iface)
24 {
25 return vpx_codec_iface_name((vpx_codec_iface_t *)iface);
26 }
27
vpx_dec_err_to_string(vpx_dec_err_t err)28 const char *vpx_dec_err_to_string(vpx_dec_err_t err)
29 {
30 return vpx_codec_err_to_string(err);
31 }
32
vpx_dec_error(vpx_dec_ctx_t * ctx)33 const char *vpx_dec_error(vpx_dec_ctx_t *ctx)
34 {
35 return vpx_codec_error((vpx_codec_ctx_t *)ctx);
36 }
37
vpx_dec_error_detail(vpx_dec_ctx_t * ctx)38 const char *vpx_dec_error_detail(vpx_dec_ctx_t *ctx)
39 {
40 return vpx_codec_error_detail((vpx_codec_ctx_t *)ctx);
41 }
42
43
vpx_dec_init_ver(vpx_dec_ctx_t * ctx,vpx_dec_iface_t * iface,int ver)44 vpx_dec_err_t vpx_dec_init_ver(vpx_dec_ctx_t *ctx,
45 vpx_dec_iface_t *iface,
46 int ver)
47 {
48 return vpx_codec_dec_init_ver((vpx_codec_ctx_t *)ctx,
49 (vpx_codec_iface_t *)iface,
50 NULL,
51 0,
52 ver);
53 }
54
55
vpx_dec_destroy(vpx_dec_ctx_t * ctx)56 vpx_dec_err_t vpx_dec_destroy(vpx_dec_ctx_t *ctx)
57 {
58 return vpx_codec_destroy((vpx_codec_ctx_t *)ctx);
59 }
60
61
vpx_dec_get_caps(vpx_dec_iface_t * iface)62 vpx_dec_caps_t vpx_dec_get_caps(vpx_dec_iface_t *iface)
63 {
64 return vpx_codec_get_caps((vpx_codec_iface_t *)iface);
65 }
66
67
vpx_dec_peek_stream_info(vpx_dec_iface_t * iface,const uint8_t * data,unsigned int data_sz,vpx_dec_stream_info_t * si)68 vpx_dec_err_t vpx_dec_peek_stream_info(vpx_dec_iface_t *iface,
69 const uint8_t *data,
70 unsigned int data_sz,
71 vpx_dec_stream_info_t *si)
72 {
73 return vpx_codec_peek_stream_info((vpx_codec_iface_t *)iface, data, data_sz,
74 (vpx_codec_stream_info_t *)si);
75 }
76
77
vpx_dec_get_stream_info(vpx_dec_ctx_t * ctx,vpx_dec_stream_info_t * si)78 vpx_dec_err_t vpx_dec_get_stream_info(vpx_dec_ctx_t *ctx,
79 vpx_dec_stream_info_t *si)
80 {
81 return vpx_codec_get_stream_info((vpx_codec_ctx_t *)ctx,
82 (vpx_codec_stream_info_t *)si);
83 }
84
85
vpx_dec_control(vpx_dec_ctx_t * ctx,int ctrl_id,void * data)86 vpx_dec_err_t vpx_dec_control(vpx_dec_ctx_t *ctx,
87 int ctrl_id,
88 void *data)
89 {
90 return vpx_codec_control_((vpx_codec_ctx_t *)ctx, ctrl_id, data);
91 }
92
93
vpx_dec_decode(vpx_dec_ctx_t * ctx,uint8_t * data,unsigned int data_sz,void * user_priv,int rel_pts)94 vpx_dec_err_t vpx_dec_decode(vpx_dec_ctx_t *ctx,
95 uint8_t *data,
96 unsigned int data_sz,
97 void *user_priv,
98 int rel_pts)
99 {
100 (void)rel_pts;
101 return vpx_codec_decode((vpx_codec_ctx_t *)ctx, data, data_sz, user_priv,
102 0);
103 }
104
vpx_dec_get_frame(vpx_dec_ctx_t * ctx,vpx_dec_iter_t * iter)105 vpx_image_t *vpx_dec_get_frame(vpx_dec_ctx_t *ctx,
106 vpx_dec_iter_t *iter)
107 {
108 return vpx_codec_get_frame((vpx_codec_ctx_t *)ctx, iter);
109 }
110
111
vpx_dec_register_put_frame_cb(vpx_dec_ctx_t * ctx,vpx_dec_put_frame_cb_fn_t cb,void * user_priv)112 vpx_dec_err_t vpx_dec_register_put_frame_cb(vpx_dec_ctx_t *ctx,
113 vpx_dec_put_frame_cb_fn_t cb,
114 void *user_priv)
115 {
116 return vpx_codec_register_put_frame_cb((vpx_codec_ctx_t *)ctx, cb,
117 user_priv);
118 }
119
120
vpx_dec_register_put_slice_cb(vpx_dec_ctx_t * ctx,vpx_dec_put_slice_cb_fn_t cb,void * user_priv)121 vpx_dec_err_t vpx_dec_register_put_slice_cb(vpx_dec_ctx_t *ctx,
122 vpx_dec_put_slice_cb_fn_t cb,
123 void *user_priv)
124 {
125 return vpx_codec_register_put_slice_cb((vpx_codec_ctx_t *)ctx, cb,
126 user_priv);
127 }
128
129
vpx_dec_xma_init_ver(vpx_dec_ctx_t * ctx,vpx_dec_iface_t * iface,int ver)130 vpx_dec_err_t vpx_dec_xma_init_ver(vpx_dec_ctx_t *ctx,
131 vpx_dec_iface_t *iface,
132 int ver)
133 {
134 return vpx_codec_dec_init_ver((vpx_codec_ctx_t *)ctx,
135 (vpx_codec_iface_t *)iface,
136 NULL,
137 VPX_CODEC_USE_XMA,
138 ver);
139 }
140
vpx_dec_get_mem_map(vpx_dec_ctx_t * ctx_,vpx_dec_mmap_t * mmap,const vpx_dec_stream_info_t * si,vpx_dec_iter_t * iter)141 vpx_dec_err_t vpx_dec_get_mem_map(vpx_dec_ctx_t *ctx_,
142 vpx_dec_mmap_t *mmap,
143 const vpx_dec_stream_info_t *si,
144 vpx_dec_iter_t *iter)
145 {
146 vpx_codec_ctx_t *ctx = (vpx_codec_ctx_t *)ctx_;
147 vpx_dec_err_t res = VPX_DEC_OK;
148
149 if (!ctx || !mmap || !si || !iter || !ctx->iface)
150 res = VPX_DEC_INVALID_PARAM;
151 else if (!(ctx->iface->caps & VPX_DEC_CAP_XMA))
152 res = VPX_DEC_ERROR;
153 else
154 {
155 if (!ctx->config.dec)
156 {
157 ctx->config.dec = malloc(sizeof(vpx_codec_dec_cfg_t));
158 ctx->config.dec->w = si->w;
159 ctx->config.dec->h = si->h;
160 }
161
162 res = ctx->iface->get_mmap(ctx, mmap, iter);
163 }
164
165 return SAVE_STATUS(ctx, res);
166 }
167
168
vpx_dec_set_mem_map(vpx_dec_ctx_t * ctx_,vpx_dec_mmap_t * mmap,unsigned int num_maps)169 vpx_dec_err_t vpx_dec_set_mem_map(vpx_dec_ctx_t *ctx_,
170 vpx_dec_mmap_t *mmap,
171 unsigned int num_maps)
172 {
173 vpx_codec_ctx_t *ctx = (vpx_codec_ctx_t *)ctx_;
174 vpx_dec_err_t res = VPX_DEC_MEM_ERROR;
175
176 if (!ctx || !mmap || !ctx->iface)
177 res = VPX_DEC_INVALID_PARAM;
178 else if (!(ctx->iface->caps & VPX_DEC_CAP_XMA))
179 res = VPX_DEC_ERROR;
180 else
181 {
182 void *save = (ctx->priv) ? NULL : ctx->config.dec;
183 unsigned int i;
184
185 for (i = 0; i < num_maps; i++, mmap++)
186 {
187 if (!mmap->base)
188 break;
189
190 /* Everything look ok, set the mmap in the decoder */
191 res = ctx->iface->set_mmap(ctx, mmap);
192
193 if (res)
194 break;
195 }
196
197 if (save) free(save);
198 }
199
200 return SAVE_STATUS(ctx, res);
201 }
202