1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DEC_INCLUDES 2 #define VPX_CODEC_DISABLE_COMPAT 1 3 #include "vpx/vpx_decoder.h" 4 #include "vpx/vp8dx.h" 5 #define interface (vpx_codec_vp8_dx()) 6 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DEC_INCLUDES 7 8 9 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DIE_CODEC 10 static void die_codec(vpx_codec_ctx_t *ctx, const char *s) { 11 const char *detail = vpx_codec_error_detail(ctx); 12 13 printf("%s: %s\n", s, vpx_codec_error(ctx)); 14 if(detail) 15 printf(" %s\n",detail); 16 exit(EXIT_FAILURE); 17 } 18 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DIE_CODEC 19 20 21 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ USAGE 22 if(argc!=3) 23 die("Usage: %s <infile> <outfile>\n", argv[0]); 24 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ USAGE 25 26 27 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DEC_INIT 28 /* Initialize codec */ 29 if(vpx_codec_dec_init(&codec, interface, NULL, flags)) 30 die_codec(&codec, "Failed to initialize decoder"); 31 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DEC_INIT 32 33 34 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DECODE 35 /* Decode the frame */ 36 if(vpx_codec_decode(&codec, frame, frame_sz, NULL, 0)) 37 die_codec(&codec, "Failed to decode frame"); 38 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DECODE 39 40 41 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ GET_FRAME 42 while((img = vpx_codec_get_frame(&codec, &iter))) { 43 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ GET_FRAME 44 45 46 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PROCESS_DX 47 for(plane=0; plane < 3; plane++) { 48 unsigned char *buf =img->planes[plane]; 49 50 for(y=0; y < (plane ? (img->d_h + 1) >> 1 : img->d_h); y++) { 51 (void) fwrite(buf, 1, (plane ? (img->d_w + 1) >> 1 : img->d_w), 52 outfile); 53 buf += img->stride[plane]; 54 } 55 } 56 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PROCESS_DX 57 58 59 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DESTROY 60 if(vpx_codec_destroy(&codec)) 61 die_codec(&codec, "Failed to destroy codec"); 62 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DESTROY 63