shithub: libvpx

Download patch

ref: 4aaf4841f2ddfee3860087dabebf7173dc4f0708
parent: b098c04290e04d03136b9cb6a87e913d7d3068e6
parent: 5260b39e5fd632858f98aed250427633307a64ad
author: Dmitry Kovalev <dkovalev@google.com>
date: Tue Jan 28 07:30:27 EST 2014

Merge "vpxdec: restoring old md5 behavior for y4m files."

--- a/vpxdec.c
+++ b/vpxdec.c
@@ -816,17 +816,34 @@
       }
 
       if (single_file) {
+        if (use_y4m) {
+          char buf[Y4M_BUFFER_SIZE] = {0};
+          size_t len = 0;
+          if (frame_out == 1) {
+            // Y4M file header
+            len = y4m_write_file_header(buf, sizeof(buf),
+                                        vpx_input_ctx.width,
+                                        vpx_input_ctx.height,
+                                        &vpx_input_ctx.framerate, img->fmt);
+            if (do_md5) {
+              MD5Update(&md5_ctx, (md5byte *)buf, len);
+            } else {
+              fputs(buf, outfile);
+            }
+          }
+
+          // Y4M frame header
+          len = y4m_write_frame_header(buf, sizeof(buf));
+          if (do_md5) {
+            MD5Update(&md5_ctx, (md5byte *)buf, len);
+          } else {
+            fputs(buf, outfile);
+          }
+        }
+
         if (do_md5) {
           update_image_md5(img, planes, &md5_ctx);
         } else {
-          if (use_y4m) {
-            if (frame_out == 1) {
-              y4m_write_file_header(outfile,
-                                    vpx_input_ctx.width, vpx_input_ctx.height,
-                                    &vpx_input_ctx.framerate, img->fmt);
-            }
-            y4m_write_frame_header(outfile);
-          }
           write_image_file(img, planes, outfile);
         }
       } else {
--- a/y4menc.c
+++ b/y4menc.c
@@ -10,21 +10,18 @@
 
 #include "./y4menc.h"
 
-void y4m_write_file_header(FILE *file, int width, int height,
-                           const struct VpxRational *framerate,
-                           vpx_img_fmt_t fmt) {
-  const char *color = fmt == VPX_IMG_FMT_444A ? "C444alpha\n" :
-                      fmt == VPX_IMG_FMT_I444 ? "C444\n" :
-                      fmt == VPX_IMG_FMT_I422 ? "C422\n" :
-                      "C420jpeg\n";
+int y4m_write_file_header(char *buf, size_t len, int width, int height,
+                          const struct VpxRational *framerate,
+                          vpx_img_fmt_t fmt) {
+  const char *const color = fmt == VPX_IMG_FMT_444A ? "C444alpha\n" :
+                            fmt == VPX_IMG_FMT_I444 ? "C444\n" :
+                            fmt == VPX_IMG_FMT_I422 ? "C422\n" :
+                            "C420jpeg\n";
 
-  // Note: We can't output an aspect ratio here because IVF doesn't
-  // store one, and neither does VP8.
-  // That will have to wait until these tools support WebM natively.*/
-  fprintf(file, "YUV4MPEG2 W%u H%u F%u:%u I%c %s", width, height,
-          framerate->numerator, framerate->denominator, 'p', color);
+  return snprintf(buf, len, "YUV4MPEG2 W%u H%u F%u:%u I%c %s", width, height,
+                  framerate->numerator, framerate->denominator, 'p', color);
 }
 
-void y4m_write_frame_header(FILE *file) {
-  fprintf(file, "FRAME\n");
+int y4m_write_frame_header(char *buf, size_t len) {
+  return snprintf(buf, len, "FRAME\n");
 }
--- a/y4menc.h
+++ b/y4menc.h
@@ -11,8 +11,6 @@
 #ifndef Y4MENC_H_
 #define Y4MENC_H_
 
-#include <stdio.h>
-
 #include "./tools_common.h"
 
 #include "vpx/vpx_decoder.h"
@@ -21,12 +19,12 @@
 extern "C" {
 #endif
 
-void y4m_write_file_header(FILE *file, int width, int height,
-                           const struct VpxRational *framerate,
-                           vpx_img_fmt_t fmt);
+#define Y4M_BUFFER_SIZE 128
 
-void y4m_write_frame_header(FILE *file);
-
+int y4m_write_file_header(char *buf, size_t len, int width, int height,
+                          const struct VpxRational *framerate,
+                          vpx_img_fmt_t fmt);
+int y4m_write_frame_header(char *buf, size_t len);
 
 #ifdef __cplusplus
 }  // extern "C"