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_ |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 | 46 |
47 // Undefining stringification macros because they are not used elsewhere | 47 // Undefining stringification macros because they are not used elsewhere |
48 #undef TO_STRING | 48 #undef TO_STRING |
49 #undef STRINGIFY | 49 #undef STRINGIFY |
50 | 50 |
51 static FILE *OpenTestDataFile(const std::string& file_name) { | 51 static FILE *OpenTestDataFile(const std::string& file_name) { |
52 const std::string path_to_source = GetDataPath() + "/" + file_name; | 52 const std::string path_to_source = GetDataPath() + "/" + file_name; |
53 return fopen(path_to_source.c_str(), "rb"); | 53 return fopen(path_to_source.c_str(), "rb"); |
54 } | 54 } |
55 | 55 |
56 static FILE *OpenTestOutFile(const std::string& file_name) { | 56 static FILE *GetTempOutFile(std::string *file_name) { |
57 const std::string path_to_source = GetDataPath() + "/" + file_name; | 57 file_name->clear(); |
58 return fopen(path_to_source.c_str(), "wb"); | |
59 } | |
60 | |
61 static std::string GetTempOutFilename() { | |
62 std::string basename; | |
63 #if defined(_WIN32) | 58 #if defined(_WIN32) |
64 char fname[MAX_PATH]; | 59 char fname[MAX_PATH]; |
65 // Assume for now that the filename generated is unique per process | 60 char tmppath[MAX_PATH]; |
66 const UINT ret = GetTempFileNameA( | 61 if (GetTempPathA(MAX_PATH, tmppath)) { |
67 GetDataPath().c_str(), "lvx", 0, fname); | 62 // Assume for now that the filename generated is unique per process |
68 if (ret != 0) { | 63 if (GetTempFileNameA(tmppath, "lvx", 0, fname)) { |
69 const char *slash = strrchr(fname, '\\'); | 64 file_name->assign(fname); |
70 if (slash == NULL) slash = strrchr(fname, '/'); | 65 return fopen(fname, "wb+"); |
71 if (slash == NULL) | 66 } |
72 basename.assign(fname); | |
73 else | |
74 basename.assign(slash + 1); | |
75 } else { | |
76 basename.clear(); | |
77 } | 67 } |
| 68 return NULL; |
78 #else | 69 #else |
79 char fname[256]; | 70 return tmpfile(); |
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 | 71 #endif |
91 return basename; | |
92 } | 72 } |
93 | 73 |
94 class TempOutFile { | 74 class TempOutFile { |
95 public: | 75 public: |
96 TempOutFile() { | 76 TempOutFile() { |
97 file_name_ = GetTempOutFilename(); | 77 file_ = GetTempOutFile(&file_name_); |
98 file_ = OpenTestOutFile(file_name_); | |
99 } | 78 } |
100 ~TempOutFile() { | 79 ~TempOutFile() { |
101 CloseFile(); | 80 CloseFile(); |
102 if (!file_name_.empty()) { | 81 if (!file_name_.empty()) { |
103 const std::string path_to_source = GetDataPath() + "/" + file_name_; | 82 EXPECT_EQ(0, remove(file_name_.c_str())); |
104 EXPECT_EQ(0, remove(path_to_source.c_str())); | |
105 } | 83 } |
106 } | 84 } |
107 FILE *file() { | 85 FILE *file() { |
108 return file_; | 86 return file_; |
109 } | 87 } |
110 const std::string& file_name() { | 88 const std::string& file_name() { |
111 return file_name_; | 89 return file_name_; |
112 } | 90 } |
| 91 |
| 92 protected: |
113 void CloseFile() { | 93 void CloseFile() { |
114 if (file_) { | 94 if (file_) { |
115 fclose(file_); | 95 fclose(file_); |
116 file_ = NULL; | 96 file_ = NULL; |
117 } | 97 } |
118 } | 98 } |
119 | |
120 protected: | |
121 FILE *file_; | 99 FILE *file_; |
122 std::string file_name_; | 100 std::string file_name_; |
123 }; | 101 }; |
124 | 102 |
125 // Abstract base class for test video sources, which provide a stream of | 103 // Abstract base class for test video sources, which provide a stream of |
126 // vpx_image_t images with associated timestamps and duration. | 104 // vpx_image_t images with associated timestamps and duration. |
127 class VideoSource { | 105 class VideoSource { |
128 public: | 106 public: |
129 virtual ~VideoSource() {} | 107 virtual ~VideoSource() {} |
130 | 108 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 virtual const uint8_t *cxdata() const = 0; | 241 virtual const uint8_t *cxdata() const = 0; |
264 | 242 |
265 virtual size_t frame_size() const = 0; | 243 virtual size_t frame_size() const = 0; |
266 | 244 |
267 virtual unsigned int frame_number() const = 0; | 245 virtual unsigned int frame_number() const = 0; |
268 }; | 246 }; |
269 | 247 |
270 } // namespace libvpx_test | 248 } // namespace libvpx_test |
271 | 249 |
272 #endif // TEST_VIDEO_SOURCE_H_ | 250 #endif // TEST_VIDEO_SOURCE_H_ |
OLD | NEW |