shithub: libvpx

Download patch

ref: 0f8787d6bea7e157f4418a34c3b829910dd4526e
parent: d39485a776bc94c897f4e9d6de8cb64f295c0e04
author: Dmitry Kovalev <dkovalev@google.com>
date: Wed Jan 15 09:38:27 EST 2014

Adding VP9 support to decode_to_md5 example.

This is still work in progress, there are many another planned updates
for all example files.

Change-Id: I2ba5dc6cd19a4bea9fbc6f1ee84cc2bd85925966

--- a/examples/decode_to_md5.c
+++ b/examples/decode_to_md5.c
@@ -37,12 +37,24 @@
 #include "./vpx_config.h"
 #include "vpx/vp8dx.h"
 #include "vpx/vpx_decoder.h"
-#define interface (vpx_codec_vp8_dx())
 #include "md5_utils.h"
 
+#define VP8_FOURCC 0x30385056
+#define VP9_FOURCC 0x30395056
+
 #define IVF_FILE_HDR_SZ  (32)
 #define IVF_FRAME_HDR_SZ (12)
 
+static vpx_codec_iface_t *get_codec_interface(unsigned int fourcc) {
+  switch (fourcc) {
+    case VP8_FOURCC:
+      return vpx_codec_vp8_dx();
+    case VP9_FOURCC:
+      return vpx_codec_vp9_dx();
+  }
+  return NULL;
+}
+
 static unsigned int mem_get_le32(const unsigned char *mem) {
   return (mem[3] << 24) | (mem[2] << 16) | (mem[1] << 8) | (mem[0]);
 }
@@ -52,7 +64,7 @@
 
   va_start(ap, fmt);
   vprintf(fmt, ap);
-  if(fmt[strlen(fmt)-1] != '\n')
+  if (fmt[strlen(fmt) - 1] != '\n')
     printf("\n");
   exit(EXIT_FAILURE);
 }
@@ -66,7 +78,7 @@
   exit(EXIT_FAILURE);
 }
 
-static void get_image_md5(const vpx_image_t *img, unsigned char md5_sum[16]) {
+static void get_image_md5(const vpx_image_t *img, unsigned char digest[16]) {
   int plane, y;
   MD5Context md5;
 
@@ -84,12 +96,20 @@
     }
   }
 
-  MD5Final(md5_sum, &md5);
+  MD5Final(digest, &md5);
 }
 
+static void print_md5(FILE *stream, unsigned char digest[16]) {
+  int i;
+
+  for (i = 0; i < 16; ++i)
+    fprintf(stream, "%02x", digest[i]);
+}
+
 int main(int argc, char **argv) {
   FILE *infile, *outfile;
   vpx_codec_ctx_t codec;
+  vpx_codec_iface_t *iface;
   int flags = 0, frame_cnt = 0;
   unsigned char file_hdr[IVF_FILE_HDR_SZ];
   unsigned char frame_hdr[IVF_FRAME_HDR_SZ];
@@ -109,9 +129,14 @@
      file_hdr[2] == 'I' && file_hdr[3] == 'F'))
     die("%s is not an IVF file.", argv[1]);
 
-  printf("Using %s\n",vpx_codec_iface_name(interface));
+  iface = get_codec_interface(mem_get_le32(file_hdr + 8));
+  if (!iface)
+    die("Unknown FOURCC code.");
 
-  if (vpx_codec_dec_init(&codec, interface, NULL, flags))
+
+  printf("Using %s\n", vpx_codec_iface_name(iface));
+
+  if (vpx_codec_dec_init(&codec, iface, NULL, flags))
     die_codec(&codec, "Failed to initialize decoder");
 
   while (fread(frame_hdr, 1, IVF_FRAME_HDR_SZ, infile) == IVF_FRAME_HDR_SZ) {
@@ -119,25 +144,22 @@
     vpx_codec_iter_t iter = NULL;
     vpx_image_t *img;
 
-    frame_cnt++;
     if (frame_size > sizeof(frame))
       die("Frame %d data too big for example code buffer", frame_size);
 
     if (fread(frame, 1, frame_size, infile) != frame_size)
-      die("Frame %d failed to read complete frame", frame_cnt);
+      die("Failed to read complete frame");
 
     if (vpx_codec_decode(&codec, frame, frame_size, NULL, 0))
       die_codec(&codec, "Failed to decode frame");
 
     while ((img = vpx_codec_get_frame(&codec, &iter)) != NULL) {
-      int i;
-      unsigned char md5_sum[16];
+      unsigned char digest[16];
 
-      get_image_md5(img, md5_sum);
-      for (i = 0; i < 16; ++i)
-        fprintf(outfile, "%02x", md5_sum[i]);
-      fprintf(outfile, "  img-%dx%d-%04d.i420\n", img->d_w, img->d_h,
-              frame_cnt);
+      get_image_md5(img, digest);
+      print_md5(outfile, digest);
+      fprintf(outfile, "  img-%dx%d-%04d.i420\n",
+              img->d_w, img->d_h, ++frame_cnt);
     }
   }