2 * Copyright (c) 2010 The VP8 project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license and patent
5 * grant that can be found in the LICENSE file in the root of the source
6 * tree. All contributing project authors may be found in the AUTHORS
7 * file in the root of the source tree.
11 /* This is a simple program showing how to initialize the decoder in XMA mode */
16 #define VPX_CODEC_DISABLE_COMPAT 1
17 #include "vpx_config.h"
18 #include "vpx/vpx_decoder.h"
19 #include "vpx/vpx_integer.h"
20 #if CONFIG_VP8_DECODER
21 #include "vpx/vp8dx.h"
24 static char *exec_name
;
25 static int verbose
= 0;
30 const vpx_codec_iface_t
*iface
;
33 #if CONFIG_VP8_DECODER
34 {"vp8", &vpx_codec_vp8_dx_algo
},
38 static void usage_exit(void)
42 printf("Usage: %s <options>\n\n"
44 "\t--codec <name>\tCodec to use (default=%s)\n"
45 "\t-h <height>\tHeight of the simulated video frame, in pixels\n"
46 "\t-w <width> \tWidth of the simulated video frame, in pixels\n"
47 "\t-v \tVerbose mode (show individual segment sizes)\n"
48 "\t--help \tShow this message\n"
50 "Included decoders:\n"
55 for (i
= 0; i
< sizeof(ifaces
) / sizeof(ifaces
[0]); i
++)
56 printf(" %-6s - %s\n",
58 vpx_codec_iface_name(ifaces
[i
].iface
));
63 static void usage_error(const char *fmt
, ...)
72 void my_mem_dtor(vpx_codec_mmap_t
*mmap
)
75 printf("freeing segment %d\n", mmap
->id
);
80 int main(int argc
, char **argv
)
82 vpx_codec_ctx_t decoder
;
83 vpx_codec_iface_t
*iface
= ifaces
[0].iface
;
84 vpx_codec_iter_t iter
;
85 vpx_codec_dec_cfg_t cfg
;
86 vpx_codec_err_t res
= VPX_CODEC_OK
;
87 unsigned int alloc_sz
= 0;
94 for (i
= 1; i
< argc
; i
++)
96 if (!strcmp(argv
[i
], "--codec"))
104 for (j
= 0; j
< sizeof(ifaces
) / sizeof(ifaces
[0]); j
++)
105 if (!strcmp(ifaces
[j
].name
, argv
[i
]))
109 iface
= ifaces
[k
].iface
;
111 usage_error("Error: Unrecognized argument (%s) to --codec\n",
115 usage_error("Error: Option --codec requires argument.\n");
117 else if (!strcmp(argv
[i
], "-v"))
119 else if (!strcmp(argv
[i
], "-h"))
125 usage_error("Error: Option -h requires argument.\n");
126 else if (!strcmp(argv
[i
], "-w"))
132 usage_error("Error: Option -w requires argument.\n");
133 else if (!strcmp(argv
[i
], "--help"))
136 usage_error("Error: Unrecognized option %s\n\n", argv
[i
]);
140 printf("Using built-in defaults. For options, rerun with --help\n\n");
142 /* XMA mode is not supported on all decoders! */
143 if (!(vpx_codec_get_caps(iface
) & VPX_CODEC_CAP_XMA
))
145 printf("%s does not support XMA mode!\n", vpx_codec_iface_name(iface
));
149 /* The codec knows how much memory to allocate based on the size of the
150 * encoded frames. This data can be parsed from the bitstream with
151 * vpx_codec_peek_stream_info() if a bitstream is available. Otherwise,
152 * a fixed size can be used that will be the upper limit on the frame
153 * size the decoder can decode.
158 /* Initialize the decoder in XMA mode. */
159 if (vpx_codec_dec_init(&decoder
, iface
, &cfg
, VPX_CODEC_USE_XMA
))
161 printf("Failed to initialize decoder in XMA mode: %s\n", vpx_codec_error(&decoder
));
165 /* Iterate through the list of memory maps, allocating them with the
166 * requested alignment.
172 vpx_codec_mmap_t mmap
;
175 res
= vpx_codec_get_mem_map(&decoder
, &mmap
, &iter
);
176 align
= mmap
.align
? mmap
.align
- 1 : 0;
181 printf("Allocating segment %u, size %lu, align %u %s\n",
182 mmap
.id
, mmap
.sz
, mmap
.align
,
183 mmap
.flags
& VPX_CODEC_MEM_ZERO
? "(ZEROED)" : "");
185 if (mmap
.flags
& VPX_CODEC_MEM_ZERO
)
186 mmap
.priv
= calloc(1, mmap
.sz
+ align
);
188 mmap
.priv
= malloc(mmap
.sz
+ align
);
190 mmap
.base
= (void *)((((uintptr_t)mmap
.priv
) + align
) & ~(uintptr_t)align
);
191 mmap
.dtor
= my_mem_dtor
;
192 alloc_sz
+= mmap
.sz
+ align
;
194 if (vpx_codec_set_mem_map(&decoder
, &mmap
, 1))
196 printf("Failed to set mmap: %s\n", vpx_codec_error(&decoder
));
200 else if (res
!= VPX_CODEC_LIST_END
)
202 printf("Failed to get mmap: %s\n", vpx_codec_error(&decoder
));
206 while (res
!= VPX_CODEC_LIST_END
);
208 printf("%s\n %d bytes external memory required for %dx%d.\n",
209 decoder
.name
, alloc_sz
, cfg
.w
, cfg
.h
);
210 vpx_codec_destroy(&decoder
);