Decoder loops refactoring
[aom.git] / examples / decoder_tmpl.c
blob8194f0ade368c298042d51e02c615d1b16b5be73
1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
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 */
13 @*INTRODUCTION
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <stdarg.h>
18 #include <string.h>
19 #define VPX_CODEC_DISABLE_COMPAT 1
20 #include "vpx/vpx_decoder.h"
21 #include "vpx/vp8dx.h"
22 #define interface (vpx_codec_vp8_dx())
23 @EXTRA_INCLUDES
26 #define IVF_FILE_HDR_SZ (32)
27 #define IVF_FRAME_HDR_SZ (12)
29 static unsigned int mem_get_le32(const unsigned char *mem) {
30 return (mem[3] << 24)|(mem[2] << 16)|(mem[1] << 8)|(mem[0]);
33 static void die(const char *fmt, ...) {
34 va_list ap;
36 va_start(ap, fmt);
37 vprintf(fmt, ap);
38 if(fmt[strlen(fmt)-1] != '\n')
39 printf("\n");
40 exit(EXIT_FAILURE);
43 @DIE_CODEC
45 @HELPERS
47 int main(int argc, char **argv) {
48 FILE *infile, *outfile;
49 vpx_codec_ctx_t codec;
50 int flags = 0, frame_cnt = 0;
51 unsigned char file_hdr[IVF_FILE_HDR_SZ];
52 unsigned char frame_hdr[IVF_FRAME_HDR_SZ];
53 unsigned char frame[256*1024];
54 vpx_codec_err_t res;
55 @@@@EXTRA_VARS
57 (void)res;
58 /* Open files */
59 @@@@USAGE
60 if(!(infile = fopen(argv[1], "rb")))
61 die("Failed to open %s for reading", argv[1]);
62 if(!(outfile = fopen(argv[2], "wb")))
63 die("Failed to open %s for writing", argv[2]);
65 /* Read file header */
66 if(!(fread(file_hdr, 1, IVF_FILE_HDR_SZ, infile) == IVF_FILE_HDR_SZ
67 && file_hdr[0]=='D' && file_hdr[1]=='K' && file_hdr[2]=='I'
68 && file_hdr[3]=='F'))
69 die("%s is not an IVF file.", argv[1]);
71 printf("Using %s\n",vpx_codec_iface_name(interface));
72 @@@@DEC_INIT
74 /* Read each frame */
75 while(fread(frame_hdr, 1, IVF_FRAME_HDR_SZ, infile) == IVF_FRAME_HDR_SZ) {
76 int frame_sz = mem_get_le32(frame_hdr);
77 vpx_codec_iter_t iter = NULL;
78 vpx_image_t *img;
81 frame_cnt++;
82 if(frame_sz > sizeof(frame))
83 die("Frame %d data too big for example code buffer", frame_sz);
84 if(fread(frame, 1, frame_sz, infile) != frame_sz)
85 die("Frame %d failed to read complete frame", frame_cnt);
87 @@@@@@@@PRE_DECODE
88 @@@@@@@@DECODE
90 /* Write decoded data to disk */
91 @@@@@@@@GET_FRAME
92 unsigned int plane, y;
94 @@@@@@@@@@@@PROCESS_DX
97 printf("Processed %d frames.\n",frame_cnt);
98 @@@@DESTROY
100 fclose(outfile);
101 fclose(infile);
102 return EXIT_SUCCESS;