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