shithub: libvpx

Download patch

ref: 21e93eb8140c832ce3bc5f6d40ba6eec507886ee
parent: c4f1fe4b221031f7739a13644b9053eb01f65332
author: angiebird <angiebird@google.com>
date: Tue Nov 12 13:34:03 EST 2019

Pass in infile_path to SimpleEncode()

Change-Id: If47867d4d59a59e252bfe7eb24c940f9e089d335

--- a/test/simple_encode_test.cc
+++ b/test/simple_encode_test.cc
@@ -4,18 +4,18 @@
 #include "vp9/simple_encode.h"
 
 namespace {
+const int w = 352;
+const int h = 288;
+const int frame_rate_num = 30;
+const int frame_rate_den = 1;
+const int target_bitrate = 1000;
+const int num_frames = 17;
+// TODO(angiebird): Figure out how to upload test video to our codebase
+const char infile_path[] = "bus_352x288_420_f20_b8.yuv";
 
 TEST(SimpleEncode, ComputeFirstPassStats) {
-  int w = 352;
-  int h = 288;
-  int frame_rate_num = 30;
-  int frame_rate_den = 1;
-  int target_bitrate = 200;
-  int num_frames = 17;
-  // TODO(angiebird): Figure out how to upload test video to our codebase
-  FILE *file = fopen("bus_352x288_420_f20_b8.yuv", "r");
   SimpleEncode simple_encode(w, h, frame_rate_num, frame_rate_den,
-                             target_bitrate, num_frames, file);
+                             target_bitrate, num_frames, infile_path);
   simple_encode.ComputeFirstPassStats();
   std::vector<std::vector<double>> frame_stats =
       simple_encode.ObserveFirstPassStats();
@@ -34,16 +34,8 @@
 }
 
 TEST(SimpleEncode, GetCodingFrameNum) {
-  int w = 352;
-  int h = 288;
-  int frame_rate_num = 30;
-  int frame_rate_den = 1;
-  int target_bitrate = 200;
-  int num_frames = 17;
-  // TODO(angiebird): Figure out how to upload test video to our codebase
-  FILE *file = fopen("bus_352x288_420_f20_b8.yuv", "r");
   SimpleEncode simple_encode(w, h, frame_rate_num, frame_rate_den,
-                             target_bitrate, num_frames, file);
+                             target_bitrate, num_frames, infile_path);
   simple_encode.ComputeFirstPassStats();
   int num_coding_frames = simple_encode.GetCodingFrameNum();
   EXPECT_EQ(num_coding_frames, 19);
@@ -50,16 +42,8 @@
 }
 
 TEST(SimpleEncode, EncodeFrame) {
-  int w = 352;
-  int h = 288;
-  int frame_rate_num = 30;
-  int frame_rate_den = 1;
-  int target_bitrate = 1000;
-  int num_frames = 17;
-  // TODO(angiebird): Figure out how to upload test video to our codebase
-  FILE *file = fopen("bus_352x288_420_f20_b8.yuv", "r");
   SimpleEncode simple_encode(w, h, frame_rate_num, frame_rate_den,
-                             target_bitrate, num_frames, file);
+                             target_bitrate, num_frames, infile_path);
   simple_encode.ComputeFirstPassStats();
   int num_coding_frames = simple_encode.GetCodingFrameNum();
   EXPECT_GE(num_coding_frames, num_frames);
@@ -94,16 +78,8 @@
 }
 
 TEST(SimpleEncode, EncodeFrameWithQuantizeIndex) {
-  int w = 352;
-  int h = 288;
-  int frame_rate_num = 30;
-  int frame_rate_den = 1;
-  int target_bitrate = 1000;
-  int num_frames = 17;
-  // TODO(angiebird): Figure out how to upload test video to our codebase
-  FILE *file = fopen("bus_352x288_420_f20_b8.yuv", "r");
   SimpleEncode simple_encode(w, h, frame_rate_num, frame_rate_den,
-                             target_bitrate, num_frames, file);
+                             target_bitrate, num_frames, infile_path);
   simple_encode.ComputeFirstPassStats();
   int num_coding_frames = simple_encode.GetCodingFrameNum();
   simple_encode.StartEncode();
--- a/vp9/simple_encode.cc
+++ b/vp9/simple_encode.cc
@@ -97,7 +97,8 @@
 
 SimpleEncode::SimpleEncode(int frame_width, int frame_height,
                            int frame_rate_num, int frame_rate_den,
-                           int target_bitrate, int num_frames, FILE *file)
+                           int target_bitrate, int num_frames,
+                           const char *infile_path)
     : pimpl{ std::unique_ptr<impl>(new impl()) } {
   this->frame_width = frame_width;
   this->frame_height = frame_height;
@@ -105,7 +106,8 @@
   this->frame_rate_den = frame_rate_den;
   this->target_bitrate = target_bitrate;
   this->num_frames = num_frames;
-  this->file = file;
+  // TODO(angirbid): Should we keep a file pointer here or keep the file_path?
+  this->file = fopen(infile_path, "r");
   pimpl->cpi = NULL;
   pimpl->img_fmt = VPX_IMG_FMT_I420;
 }
--- a/vp9/simple_encode.h
+++ b/vp9/simple_encode.h
@@ -23,7 +23,7 @@
  public:
   SimpleEncode(int frame_width, int frame_height, int frame_rate_num,
                int frame_rate_den, int target_bitrate, int num_frames,
-               FILE *file);
+               const char *infile_path);
   ~SimpleEncode();
   SimpleEncode(SimpleEncode &&) = delete;
   SimpleEncode &operator=(SimpleEncode &&) = delete;