OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebM project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 #ifndef TEST_VIDEO_SOURCE_H_ | 10 #ifndef TEST_VIDEO_SOURCE_H_ |
11 #define TEST_VIDEO_SOURCE_H_ | 11 #define TEST_VIDEO_SOURCE_H_ |
12 | 12 |
| 13 #if defined(_WIN32) |
| 14 #include <windows.h> |
| 15 #endif |
13 #include <cstdio> | 16 #include <cstdio> |
14 #include <cstdlib> | 17 #include <cstdlib> |
15 #include <string> | 18 #include <string> |
16 #include "test/acm_random.h" | 19 #include "test/acm_random.h" |
17 #include "vpx/vpx_encoder.h" | 20 #include "vpx/vpx_encoder.h" |
18 | 21 |
19 namespace libvpx_test { | 22 namespace libvpx_test { |
20 | 23 |
21 // Helper macros to ensure LIBVPX_TEST_DATA_PATH is a quoted string. | 24 // Helper macros to ensure LIBVPX_TEST_DATA_PATH is a quoted string. |
22 // These are undefined right below GetDataPath | 25 // These are undefined right below GetDataPath |
(...skipping 25 matching lines...) Expand all Loading... |
48 static FILE *OpenTestDataFile(const std::string& file_name) { | 51 static FILE *OpenTestDataFile(const std::string& file_name) { |
49 const std::string path_to_source = GetDataPath() + "/" + file_name; | 52 const std::string path_to_source = GetDataPath() + "/" + file_name; |
50 return fopen(path_to_source.c_str(), "rb"); | 53 return fopen(path_to_source.c_str(), "rb"); |
51 } | 54 } |
52 | 55 |
53 static FILE *OpenTestOutFile(const std::string& file_name) { | 56 static FILE *OpenTestOutFile(const std::string& file_name) { |
54 const std::string path_to_source = GetDataPath() + "/" + file_name; | 57 const std::string path_to_source = GetDataPath() + "/" + file_name; |
55 return fopen(path_to_source.c_str(), "wb"); | 58 return fopen(path_to_source.c_str(), "wb"); |
56 } | 59 } |
57 | 60 |
58 static FILE *OpenTempOutFile() { | 61 static std::string GetTempOutFilename() { |
59 return tmpfile(); | 62 std::string basename; |
| 63 #if defined(_WIN32) |
| 64 char fname[MAX_PATH]; |
| 65 // Assume for now that the filename generated is unique per process |
| 66 const UINT ret = GetTempFileNameA( |
| 67 GetDataPath().c_str(), "lvx", 0, fname); |
| 68 if (ret != 0) { |
| 69 const char *slash = strrchr(fname, '\\'); |
| 70 if (slash == NULL) slash = strrchr(fname, '/'); |
| 71 if (slash == NULL) |
| 72 basename.assign(fname); |
| 73 else |
| 74 basename.assign(slash + 1); |
| 75 } else { |
| 76 basename.clear(); |
| 77 } |
| 78 #else |
| 79 char fname[256]; |
| 80 const std::string templ = GetDataPath() + "/libvpx_test_XXXXXX"; |
| 81 strncpy(fname, templ.c_str(), templ.size()); |
| 82 fname[templ.size()] = '\0'; |
| 83 const int fd = mkstemp(fname); |
| 84 if (fd != -1) { |
| 85 close(fd); |
| 86 basename.assign(strrchr(fname, '/') + 1); |
| 87 } else { |
| 88 basename.clear(); |
| 89 } |
| 90 #endif |
| 91 return basename; |
60 } | 92 } |
61 | 93 |
| 94 class TempOutFile { |
| 95 public: |
| 96 TempOutFile() { |
| 97 file_name_ = GetTempOutFilename(); |
| 98 file_ = OpenTestOutFile(file_name_); |
| 99 } |
| 100 ~TempOutFile() { |
| 101 CloseFile(); |
| 102 if (!file_name_.empty()) { |
| 103 const std::string path_to_source = GetDataPath() + "/" + file_name_; |
| 104 EXPECT_EQ(0, remove(path_to_source.c_str())); |
| 105 } |
| 106 } |
| 107 FILE *file() { |
| 108 return file_; |
| 109 } |
| 110 const std::string& file_name() { |
| 111 return file_name_; |
| 112 } |
| 113 void CloseFile() { |
| 114 if (file_) { |
| 115 fclose(file_); |
| 116 file_ = NULL; |
| 117 } |
| 118 } |
| 119 |
| 120 protected: |
| 121 FILE *file_; |
| 122 std::string file_name_; |
| 123 }; |
| 124 |
62 // Abstract base class for test video sources, which provide a stream of | 125 // Abstract base class for test video sources, which provide a stream of |
63 // vpx_image_t images with associated timestamps and duration. | 126 // vpx_image_t images with associated timestamps and duration. |
64 class VideoSource { | 127 class VideoSource { |
65 public: | 128 public: |
66 virtual ~VideoSource() {} | 129 virtual ~VideoSource() {} |
67 | 130 |
68 // Prepare the stream for reading, rewind/open as necessary. | 131 // Prepare the stream for reading, rewind/open as necessary. |
69 virtual void Begin() = 0; | 132 virtual void Begin() = 0; |
70 | 133 |
71 // Advance the cursor to the next frame | 134 // Advance the cursor to the next frame |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 | 183 |
121 virtual vpx_rational_t timebase() const { | 184 virtual vpx_rational_t timebase() const { |
122 const vpx_rational_t t = {1, 30}; | 185 const vpx_rational_t t = {1, 30}; |
123 return t; | 186 return t; |
124 } | 187 } |
125 | 188 |
126 virtual unsigned int frame() const { return frame_; } | 189 virtual unsigned int frame() const { return frame_; } |
127 | 190 |
128 virtual unsigned int limit() const { return limit_; } | 191 virtual unsigned int limit() const { return limit_; } |
129 | 192 |
| 193 void set_limit(unsigned int limit) { |
| 194 limit_ = limit; |
| 195 } |
| 196 |
130 void SetSize(unsigned int width, unsigned int height) { | 197 void SetSize(unsigned int width, unsigned int height) { |
131 if (width != width_ || height != height_) { | 198 if (width != width_ || height != height_) { |
132 vpx_img_free(img_); | 199 vpx_img_free(img_); |
133 raw_sz_ = ((width + 31)&~31) * height * 3 / 2; | 200 raw_sz_ = ((width + 31)&~31) * height * 3 / 2; |
134 img_ = vpx_img_alloc(NULL, VPX_IMG_FMT_I420, width, height, 32); | 201 img_ = vpx_img_alloc(NULL, VPX_IMG_FMT_I420, width, height, 32); |
135 width_ = width; | 202 width_ = width; |
136 height_ = height; | 203 height_ = height; |
137 } | 204 } |
138 } | 205 } |
139 | 206 |
140 protected: | 207 protected: |
141 virtual void FillFrame() { memset(img_->img_data, 0, raw_sz_); } | 208 virtual void FillFrame() { if (img_) memset(img_->img_data, 0, raw_sz_); } |
142 | 209 |
143 vpx_image_t *img_; | 210 vpx_image_t *img_; |
144 size_t raw_sz_; | 211 size_t raw_sz_; |
145 unsigned int limit_; | 212 unsigned int limit_; |
146 unsigned int frame_; | 213 unsigned int frame_; |
147 unsigned int width_; | 214 unsigned int width_; |
148 unsigned int height_; | 215 unsigned int height_; |
149 }; | 216 }; |
150 | 217 |
151 | 218 |
152 class RandomVideoSource : public DummyVideoSource { | 219 class RandomVideoSource : public DummyVideoSource { |
153 public: | 220 public: |
154 RandomVideoSource(int seed = ACMRandom::DeterministicSeed()) | 221 RandomVideoSource(int seed = ACMRandom::DeterministicSeed()) |
155 : rnd_(seed), | 222 : rnd_(seed), |
156 seed_(seed) { } | 223 seed_(seed) { } |
157 | 224 |
158 protected: | 225 protected: |
159 // Reset the RNG to get a matching stream for the second pass | 226 // Reset the RNG to get a matching stream for the second pass |
160 virtual void Begin() { | 227 virtual void Begin() { |
161 frame_ = 0; | 228 frame_ = 0; |
162 rnd_.Reset(seed_); | 229 rnd_.Reset(seed_); |
163 FillFrame(); | 230 FillFrame(); |
164 } | 231 } |
165 | 232 |
166 // 15 frames of noise, followed by 15 static frames. Reset to 0 rather | 233 // 15 frames of noise, followed by 15 static frames. Reset to 0 rather |
167 // than holding previous frames to encourage keyframes to be thrown. | 234 // than holding previous frames to encourage keyframes to be thrown. |
168 virtual void FillFrame() { | 235 virtual void FillFrame() { |
169 if (frame_ % 30 < 15) | 236 if (img_) { |
170 for (size_t i = 0; i < raw_sz_; ++i) | 237 if (frame_ % 30 < 15) |
171 img_->img_data[i] = rnd_.Rand8(); | 238 for (size_t i = 0; i < raw_sz_; ++i) |
172 else | 239 img_->img_data[i] = rnd_.Rand8(); |
173 memset(img_->img_data, 0, raw_sz_); | 240 else |
| 241 memset(img_->img_data, 0, raw_sz_); |
| 242 } |
174 } | 243 } |
175 | 244 |
176 ACMRandom rnd_; | 245 ACMRandom rnd_; |
177 int seed_; | 246 int seed_; |
178 }; | 247 }; |
179 | 248 |
180 // Abstract base class for test video sources, which provide a stream of | 249 // Abstract base class for test video sources, which provide a stream of |
181 // decompressed images to the decoder. | 250 // decompressed images to the decoder. |
182 class CompressedVideoSource { | 251 class CompressedVideoSource { |
183 public: | 252 public: |
(...skipping 10 matching lines...) Expand all Loading... |
194 virtual const uint8_t *cxdata() const = 0; | 263 virtual const uint8_t *cxdata() const = 0; |
195 | 264 |
196 virtual size_t frame_size() const = 0; | 265 virtual size_t frame_size() const = 0; |
197 | 266 |
198 virtual unsigned int frame_number() const = 0; | 267 virtual unsigned int frame_number() const = 0; |
199 }; | 268 }; |
200 | 269 |
201 } // namespace libvpx_test | 270 } // namespace libvpx_test |
202 | 271 |
203 #endif // TEST_VIDEO_SOURCE_H_ | 272 #endif // TEST_VIDEO_SOURCE_H_ |
OLD | NEW |