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
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 :
23 0 : const char *vpx_dec_iface_name(vpx_dec_iface_t *iface)
24 : {
25 0 : return vpx_codec_iface_name((vpx_codec_iface_t *)iface);
26 : }
27 :
28 0 : const char *vpx_dec_err_to_string(vpx_dec_err_t err)
29 : {
30 0 : return vpx_codec_err_to_string(err);
31 : }
32 :
33 0 : const char *vpx_dec_error(vpx_dec_ctx_t *ctx)
34 : {
35 0 : return vpx_codec_error((vpx_codec_ctx_t *)ctx);
36 : }
37 :
38 0 : const char *vpx_dec_error_detail(vpx_dec_ctx_t *ctx)
39 : {
40 0 : return vpx_codec_error_detail((vpx_codec_ctx_t *)ctx);
41 : }
42 :
43 :
44 0 : vpx_dec_err_t vpx_dec_init_ver(vpx_dec_ctx_t *ctx,
45 : vpx_dec_iface_t *iface,
46 : int ver)
47 : {
48 0 : 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 :
56 0 : vpx_dec_err_t vpx_dec_destroy(vpx_dec_ctx_t *ctx)
57 : {
58 0 : return vpx_codec_destroy((vpx_codec_ctx_t *)ctx);
59 : }
60 :
61 :
62 0 : vpx_dec_caps_t vpx_dec_get_caps(vpx_dec_iface_t *iface)
63 : {
64 0 : return vpx_codec_get_caps((vpx_codec_iface_t *)iface);
65 : }
66 :
67 :
68 0 : 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 0 : return vpx_codec_peek_stream_info((vpx_codec_iface_t *)iface, data, data_sz,
74 : (vpx_codec_stream_info_t *)si);
75 : }
76 :
77 :
78 0 : vpx_dec_err_t vpx_dec_get_stream_info(vpx_dec_ctx_t *ctx,
79 : vpx_dec_stream_info_t *si)
80 : {
81 0 : return vpx_codec_get_stream_info((vpx_codec_ctx_t *)ctx,
82 : (vpx_codec_stream_info_t *)si);
83 : }
84 :
85 :
86 0 : vpx_dec_err_t vpx_dec_control(vpx_dec_ctx_t *ctx,
87 : int ctrl_id,
88 : void *data)
89 : {
90 0 : return vpx_codec_control_((vpx_codec_ctx_t *)ctx, ctrl_id, data);
91 : }
92 :
93 :
94 0 : 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 0 : return vpx_codec_decode((vpx_codec_ctx_t *)ctx, data, data_sz, user_priv,
102 : 0);
103 : }
104 :
105 0 : vpx_image_t *vpx_dec_get_frame(vpx_dec_ctx_t *ctx,
106 : vpx_dec_iter_t *iter)
107 : {
108 0 : return vpx_codec_get_frame((vpx_codec_ctx_t *)ctx, iter);
109 : }
110 :
111 :
112 0 : 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 0 : return vpx_codec_register_put_frame_cb((vpx_codec_ctx_t *)ctx, cb,
117 : user_priv);
118 : }
119 :
120 :
121 0 : 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 0 : return vpx_codec_register_put_slice_cb((vpx_codec_ctx_t *)ctx, cb,
126 : user_priv);
127 : }
128 :
129 :
130 0 : 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 0 : 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 :
141 0 : 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 0 : vpx_codec_ctx_t *ctx = (vpx_codec_ctx_t *)ctx_;
147 0 : vpx_dec_err_t res = VPX_DEC_OK;
148 :
149 0 : if (!ctx || !mmap || !si || !iter || !ctx->iface)
150 0 : res = VPX_DEC_INVALID_PARAM;
151 0 : else if (!(ctx->iface->caps & VPX_DEC_CAP_XMA))
152 0 : res = VPX_DEC_ERROR;
153 : else
154 : {
155 0 : if (!ctx->config.dec)
156 : {
157 0 : ctx->config.dec = malloc(sizeof(vpx_codec_dec_cfg_t));
158 0 : ctx->config.dec->w = si->w;
159 0 : ctx->config.dec->h = si->h;
160 : }
161 :
162 0 : res = ctx->iface->get_mmap(ctx, mmap, iter);
163 : }
164 :
165 0 : return SAVE_STATUS(ctx, res);
166 : }
167 :
168 :
169 0 : 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 0 : vpx_codec_ctx_t *ctx = (vpx_codec_ctx_t *)ctx_;
174 0 : vpx_dec_err_t res = VPX_DEC_MEM_ERROR;
175 :
176 0 : if (!ctx || !mmap || !ctx->iface)
177 0 : res = VPX_DEC_INVALID_PARAM;
178 0 : else if (!(ctx->iface->caps & VPX_DEC_CAP_XMA))
179 0 : res = VPX_DEC_ERROR;
180 : else
181 : {
182 0 : void *save = (ctx->priv) ? NULL : ctx->config.dec;
183 : unsigned int i;
184 :
185 0 : for (i = 0; i < num_maps; i++, mmap++)
186 : {
187 0 : if (!mmap->base)
188 0 : break;
189 :
190 : /* Everything look ok, set the mmap in the decoder */
191 0 : res = ctx->iface->set_mmap(ctx, mmap);
192 :
193 0 : if (res)
194 0 : break;
195 : }
196 :
197 0 : if (save) free(save);
198 : }
199 :
200 0 : return SAVE_STATUS(ctx, res);
201 : }
|