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