| OLD | NEW | 
|---|
| (Empty) |  | 
|  | 1 /* | 
|  | 2  *  Copyright (c) 2012 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 #include <string> | 
|  | 12 #include "test/md5_helper.h" | 
|  | 13 #include "test/util.h" | 
|  | 14 #include "test/y4m_video_source.h" | 
|  | 15 #include "third_party/googletest/src/include/gtest/gtest.h" | 
|  | 16 #include "./vpx_config.h" | 
|  | 17 #include "./y4menc.h" | 
|  | 18 | 
|  | 19 namespace { | 
|  | 20 | 
|  | 21 using std::string; | 
|  | 22 | 
|  | 23 static const unsigned int kWidth  = 160; | 
|  | 24 static const unsigned int kHeight = 90; | 
|  | 25 static const unsigned int kFrames = 10; | 
|  | 26 | 
|  | 27 typedef struct { | 
|  | 28   const char *filename; | 
|  | 29   unsigned int bit_depth; | 
|  | 30   vpx_img_fmt format; | 
|  | 31   const char *md5raw; | 
|  | 32 } test_entry_type; | 
|  | 33 | 
|  | 34 const test_entry_type kY4mTestVectors[] = { | 
|  | 35   {"park_joy_90p_8_420.y4m", 8, VPX_IMG_FMT_I420, | 
|  | 36     "e5406275b9fc6bb3436c31d4a05c1cab"}, | 
|  | 37   {"park_joy_90p_8_422.y4m", 8, VPX_IMG_FMT_I422, | 
|  | 38     "284a47a47133b12884ec3a14e959a0b6"}, | 
|  | 39   {"park_joy_90p_8_444.y4m", 8, VPX_IMG_FMT_I444, | 
|  | 40     "90517ff33843d85de712fd4fe60dbed0"}, | 
|  | 41   {"park_joy_90p_10_420.y4m", 10, VPX_IMG_FMT_I42016, | 
|  | 42     "63f21f9f717d8b8631bd2288ee87137b"}, | 
|  | 43   {"park_joy_90p_10_422.y4m", 10, VPX_IMG_FMT_I42216, | 
|  | 44     "48ab51fb540aed07f7ff5af130c9b605"}, | 
|  | 45   {"park_joy_90p_10_444.y4m", 10, VPX_IMG_FMT_I44416, | 
|  | 46     "067bfd75aa85ff9bae91fa3e0edd1e3e"}, | 
|  | 47   {"park_joy_90p_12_420.y4m", 12, VPX_IMG_FMT_I42016, | 
|  | 48     "9e6d8f6508c6e55625f6b697bc461cef"}, | 
|  | 49   {"park_joy_90p_12_422.y4m", 12, VPX_IMG_FMT_I42216, | 
|  | 50     "b239c6b301c0b835485be349ca83a7e3"}, | 
|  | 51   {"park_joy_90p_12_444.y4m", 12, VPX_IMG_FMT_I44416, | 
|  | 52     "5a6481a550821dab6d0192f5c63845e9"}, | 
|  | 53 }; | 
|  | 54 | 
|  | 55 static void write_image_file(const vpx_image_t *img, FILE *file) { | 
|  | 56   int plane, y; | 
|  | 57   for (plane = 0; plane < 3; ++plane) { | 
|  | 58     const unsigned char *buf = img->planes[plane]; | 
|  | 59     const int stride = img->stride[plane]; | 
|  | 60     const int bytes_per_sample = (img->fmt & VPX_IMG_FMT_HIGH) ? 2 : 1; | 
|  | 61     const int h = (plane ? (img->d_h + img->y_chroma_shift) >> | 
|  | 62                    img->y_chroma_shift : img->d_h); | 
|  | 63     const int w = (plane ? (img->d_w + img->x_chroma_shift) >> | 
|  | 64                    img->x_chroma_shift : img->d_w); | 
|  | 65     for (y = 0; y < h; ++y) { | 
|  | 66       fwrite(buf, bytes_per_sample, w, file); | 
|  | 67       buf += stride; | 
|  | 68     } | 
|  | 69   } | 
|  | 70 } | 
|  | 71 | 
|  | 72 class Y4mVideoSourceTest | 
|  | 73     : public ::testing::TestWithParam<test_entry_type>, | 
|  | 74       public ::libvpx_test::Y4mVideoSource { | 
|  | 75  protected: | 
|  | 76   Y4mVideoSourceTest() : Y4mVideoSource("", 0, 0) {} | 
|  | 77 | 
|  | 78   virtual ~Y4mVideoSourceTest() { | 
|  | 79     CloseSource(); | 
|  | 80   } | 
|  | 81 | 
|  | 82   virtual void Init(const std::string &file_name, int limit) { | 
|  | 83     file_name_ = file_name; | 
|  | 84     start_ = 0; | 
|  | 85     limit_ = limit; | 
|  | 86     frame_ = 0; | 
|  | 87     Begin(); | 
|  | 88   } | 
|  | 89 | 
|  | 90   // Checks y4m header information | 
|  | 91   void HeaderChecks(unsigned int bit_depth, vpx_img_fmt_t fmt) { | 
|  | 92     ASSERT_TRUE(input_file_ != NULL); | 
|  | 93     ASSERT_EQ(y4m_.pic_w, (int)kWidth); | 
|  | 94     ASSERT_EQ(y4m_.pic_h, (int)kHeight); | 
|  | 95     ASSERT_EQ(img()->d_w, kWidth); | 
|  | 96     ASSERT_EQ(img()->d_h, kHeight); | 
|  | 97     ASSERT_EQ(y4m_.bit_depth, bit_depth); | 
|  | 98     ASSERT_EQ(y4m_.vpx_fmt, fmt); | 
|  | 99     if (fmt == VPX_IMG_FMT_I420 || fmt == VPX_IMG_FMT_I42016) { | 
|  | 100       ASSERT_EQ(y4m_.bps, (int)y4m_.bit_depth * 3 / 2); | 
|  | 101       ASSERT_EQ(img()->x_chroma_shift, 1U); | 
|  | 102       ASSERT_EQ(img()->y_chroma_shift, 1U); | 
|  | 103     } | 
|  | 104     if (fmt == VPX_IMG_FMT_I422 || fmt == VPX_IMG_FMT_I42216) { | 
|  | 105       ASSERT_EQ(y4m_.bps, (int)y4m_.bit_depth * 2); | 
|  | 106       ASSERT_EQ(img()->x_chroma_shift, 1U); | 
|  | 107       ASSERT_EQ(img()->y_chroma_shift, 0U); | 
|  | 108     } | 
|  | 109     if (fmt == VPX_IMG_FMT_I444 || fmt == VPX_IMG_FMT_I44416) { | 
|  | 110       ASSERT_EQ(y4m_.bps, (int)y4m_.bit_depth * 3); | 
|  | 111       ASSERT_EQ(img()->x_chroma_shift, 0U); | 
|  | 112       ASSERT_EQ(img()->y_chroma_shift, 0U); | 
|  | 113     } | 
|  | 114   } | 
|  | 115 | 
|  | 116   // Checks MD5 of the raw frame data | 
|  | 117   void Md5Check(const string &expected_md5) { | 
|  | 118     ASSERT_TRUE(input_file_ != NULL); | 
|  | 119     libvpx_test::MD5 md5; | 
|  | 120     for (unsigned int i = start_; i < limit_; i++) { | 
|  | 121       md5.Add(img()); | 
|  | 122       Next(); | 
|  | 123     } | 
|  | 124     ASSERT_EQ(string(md5.Get()), expected_md5); | 
|  | 125   } | 
|  | 126 }; | 
|  | 127 | 
|  | 128 TEST_P(Y4mVideoSourceTest, SourceTest) { | 
|  | 129   const test_entry_type t = GetParam(); | 
|  | 130   Init(t.filename, kFrames); | 
|  | 131   HeaderChecks(t.bit_depth, t.format); | 
|  | 132   Md5Check(t.md5raw); | 
|  | 133 } | 
|  | 134 | 
|  | 135 INSTANTIATE_TEST_CASE_P(C, Y4mVideoSourceTest, | 
|  | 136                         ::testing::ValuesIn(kY4mTestVectors)); | 
|  | 137 | 
|  | 138 class Y4mVideoWriteTest | 
|  | 139     : public Y4mVideoSourceTest { | 
|  | 140  protected: | 
|  | 141   Y4mVideoWriteTest() : Y4mVideoSourceTest() {} | 
|  | 142 | 
|  | 143   virtual void ReplaceInputFp(FILE *input_file) { | 
|  | 144     CloseSource(); | 
|  | 145     frame_ = 0; | 
|  | 146     input_file_ = input_file; | 
|  | 147     rewind(input_file_); | 
|  | 148     ReadSourceToStart(); | 
|  | 149   } | 
|  | 150 | 
|  | 151   // Writes out a y4m file and then reads it back | 
|  | 152   void WriteY4mAndReadBack() { | 
|  | 153     ASSERT_TRUE(input_file_ != NULL); | 
|  | 154     char buf[Y4M_BUFFER_SIZE] = {0}; | 
|  | 155     const struct VpxRational framerate = {y4m_.fps_n, y4m_.fps_d}; | 
|  | 156     FILE *out_file = libvpx_test::OpenTempOutFile(); | 
|  | 157     ASSERT_TRUE(out_file != NULL); | 
|  | 158     y4m_write_file_header(buf, sizeof(buf), | 
|  | 159                           kWidth, kHeight, | 
|  | 160                           &framerate, y4m_.vpx_fmt, | 
|  | 161                           y4m_.bit_depth); | 
|  | 162     fputs(buf, out_file); | 
|  | 163     for (unsigned int i = start_; i < limit_; i++) { | 
|  | 164       y4m_write_frame_header(buf, sizeof(buf)); | 
|  | 165       fputs(buf, out_file); | 
|  | 166       write_image_file(img(), out_file); | 
|  | 167       Next(); | 
|  | 168     } | 
|  | 169     ReplaceInputFp(out_file); | 
|  | 170   } | 
|  | 171 | 
|  | 172   virtual void Init(const std::string &file_name, int limit) { | 
|  | 173     Y4mVideoSourceTest::Init(file_name, limit); | 
|  | 174     WriteY4mAndReadBack(); | 
|  | 175   } | 
|  | 176 }; | 
|  | 177 | 
|  | 178 TEST_P(Y4mVideoWriteTest, WriteTest) { | 
|  | 179   const test_entry_type t = GetParam(); | 
|  | 180   Init(t.filename, kFrames); | 
|  | 181   HeaderChecks(t.bit_depth, t.format); | 
|  | 182   Md5Check(t.md5raw); | 
|  | 183 } | 
|  | 184 | 
|  | 185 INSTANTIATE_TEST_CASE_P(C, Y4mVideoWriteTest, | 
|  | 186                         ::testing::ValuesIn(kY4mTestVectors)); | 
|  | 187 }  // namespace | 
| OLD | NEW | 
|---|