OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC 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 | 10 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 } | 62 } |
63 return true; | 63 return true; |
64 } | 64 } |
65 | 65 |
66 void VerifyIvfHeader(FileWrapper* file, | 66 void VerifyIvfHeader(FileWrapper* file, |
67 const uint8_t fourcc[4], | 67 const uint8_t fourcc[4], |
68 int width, | 68 int width, |
69 int height, | 69 int height, |
70 uint32_t num_frames, | 70 uint32_t num_frames, |
71 bool use_capture_tims_ms) { | 71 bool use_capture_tims_ms) { |
| 72 ASSERT_TRUE(file->is_open()); |
72 uint8_t data[kHeaderSize]; | 73 uint8_t data[kHeaderSize]; |
73 ASSERT_EQ(kHeaderSize, file->Read(data, kHeaderSize)); | 74 ASSERT_EQ(kHeaderSize, file->Read(data, kHeaderSize)); |
74 | 75 |
75 uint8_t dkif[4] = {'D', 'K', 'I', 'F'}; | 76 uint8_t dkif[4] = {'D', 'K', 'I', 'F'}; |
76 EXPECT_EQ(0, memcmp(dkif, data, 4)); | 77 EXPECT_EQ(0, memcmp(dkif, data, 4)); |
77 EXPECT_EQ(0u, ByteReader<uint16_t>::ReadLittleEndian(&data[4])); | 78 EXPECT_EQ(0u, ByteReader<uint16_t>::ReadLittleEndian(&data[4])); |
78 EXPECT_EQ(32u, ByteReader<uint16_t>::ReadLittleEndian(&data[6])); | 79 EXPECT_EQ(32u, ByteReader<uint16_t>::ReadLittleEndian(&data[6])); |
79 EXPECT_EQ(0, memcmp(fourcc, &data[8], 4)); | 80 EXPECT_EQ(0, memcmp(fourcc, &data[8], 4)); |
80 EXPECT_EQ(width, ByteReader<uint16_t>::ReadLittleEndian(&data[12])); | 81 EXPECT_EQ(width, ByteReader<uint16_t>::ReadLittleEndian(&data[12])); |
81 EXPECT_EQ(height, ByteReader<uint16_t>::ReadLittleEndian(&data[14])); | 82 EXPECT_EQ(height, ByteReader<uint16_t>::ReadLittleEndian(&data[14])); |
(...skipping 29 matching lines...) Expand all Loading... |
111 file_writer_ = IvfFileWriter::Open(file_name_, codec_type); | 112 file_writer_ = IvfFileWriter::Open(file_name_, codec_type); |
112 ASSERT_TRUE(file_writer_.get()); | 113 ASSERT_TRUE(file_writer_.get()); |
113 const int kWidth = 320; | 114 const int kWidth = 320; |
114 const int kHeight = 240; | 115 const int kHeight = 240; |
115 const int kNumFrames = 257; | 116 const int kNumFrames = 257; |
116 EXPECT_TRUE( | 117 EXPECT_TRUE( |
117 WriteDummyTestFrames(kWidth, kHeight, kNumFrames, use_capture_tims_ms)); | 118 WriteDummyTestFrames(kWidth, kHeight, kNumFrames, use_capture_tims_ms)); |
118 EXPECT_TRUE(file_writer_->Close()); | 119 EXPECT_TRUE(file_writer_->Close()); |
119 | 120 |
120 std::unique_ptr<FileWrapper> out_file(FileWrapper::Create()); | 121 std::unique_ptr<FileWrapper> out_file(FileWrapper::Create()); |
121 ASSERT_EQ(0, out_file->OpenFile(file_name_.c_str(), true)); | 122 ASSERT_TRUE(out_file->OpenFile(file_name_.c_str(), true)); |
122 VerifyIvfHeader(out_file.get(), fourcc, kWidth, kHeight, kNumFrames, | 123 VerifyIvfHeader(out_file.get(), fourcc, kWidth, kHeight, kNumFrames, |
123 use_capture_tims_ms); | 124 use_capture_tims_ms); |
124 VerifyDummyTestFrames(out_file.get(), kNumFrames); | 125 VerifyDummyTestFrames(out_file.get(), kNumFrames); |
125 | 126 |
126 out_file->Flush(); | 127 out_file->CloseFile(); |
127 EXPECT_EQ(0, out_file->CloseFile()); | |
128 | 128 |
129 bool file_removed = false; | 129 bool file_removed = false; |
130 for (int i = 0; i < kMaxFileRetries; ++i) { | 130 for (int i = 0; i < kMaxFileRetries; ++i) { |
131 file_removed = remove(file_name_.c_str()) == 0; | 131 file_removed = remove(file_name_.c_str()) == 0; |
132 if (file_removed) | 132 if (file_removed) |
133 break; | 133 break; |
134 | 134 |
135 // Couldn't remove file for some reason, wait a sec and try again. | 135 // Couldn't remove file for some reason, wait a sec and try again. |
136 rtc::Thread::SleepMs(1000); | 136 rtc::Thread::SleepMs(1000); |
137 } | 137 } |
138 EXPECT_TRUE(file_removed); | 138 EXPECT_TRUE(file_removed); |
139 } | 139 } |
140 | 140 |
141 // Check whether file exists or not, and if it does not meet expectation, | 141 // Check whether file exists or not, and if it does not meet expectation, |
142 // wait a bit and check again, up to kMaxFileRetries times. This is an ugly | 142 // wait a bit and check again, up to kMaxFileRetries times. This is an ugly |
143 // hack to avoid flakiness on certain operating systems where antivirus | 143 // hack to avoid flakiness on certain operating systems where antivirus |
144 // software may unexpectedly lock files and keep them from disappearing or | 144 // software may unexpectedly lock files and keep them from disappearing or |
145 // being reused. | 145 // being reused. |
146 bool FileExists(bool expected) { | 146 bool FileExists(bool expected) { |
147 bool file_exists = expected; | 147 bool file_exists = expected; |
148 std::unique_ptr<FileWrapper> file_wrapper; | 148 std::unique_ptr<FileWrapper> file_wrapper; |
149 int iterations = 0; | 149 int iterations = 0; |
150 do { | 150 do { |
151 if (file_wrapper.get() != nullptr) | 151 if (file_wrapper.get() != nullptr) |
152 rtc::Thread::SleepMs(1000); | 152 rtc::Thread::SleepMs(1000); |
153 file_wrapper.reset(FileWrapper::Create()); | 153 file_wrapper.reset(FileWrapper::Create()); |
154 file_exists = file_wrapper->OpenFile(file_name_.c_str(), true) == 0; | 154 file_exists = file_wrapper->OpenFile(file_name_.c_str(), true); |
155 file_wrapper->CloseFile(); | 155 file_wrapper->CloseFile(); |
156 } while (file_exists != expected && ++iterations < kMaxFileRetries); | 156 } while (file_exists != expected && ++iterations < kMaxFileRetries); |
157 return file_exists; | 157 return file_exists; |
158 } | 158 } |
159 | 159 |
160 std::string file_name_; | 160 std::string file_name_; |
161 std::unique_ptr<IvfFileWriter> file_writer_; | 161 std::unique_ptr<IvfFileWriter> file_writer_; |
162 }; | 162 }; |
163 | 163 |
164 TEST_F(IvfFileWriterTest, RemovesUnusedFile) { | 164 TEST_F(IvfFileWriterTest, RemovesUnusedFile) { |
(...skipping 29 matching lines...) Expand all Loading... |
194 const uint8_t fourcc[4] = {'H', '2', '6', '4'}; | 194 const uint8_t fourcc[4] = {'H', '2', '6', '4'}; |
195 RunBasicFileStructureTest(kVideoCodecH264, fourcc, false); | 195 RunBasicFileStructureTest(kVideoCodecH264, fourcc, false); |
196 } | 196 } |
197 | 197 |
198 TEST_F(IvfFileWriterTest, WritesBasicH264FileMsTimestamp) { | 198 TEST_F(IvfFileWriterTest, WritesBasicH264FileMsTimestamp) { |
199 const uint8_t fourcc[4] = {'H', '2', '6', '4'}; | 199 const uint8_t fourcc[4] = {'H', '2', '6', '4'}; |
200 RunBasicFileStructureTest(kVideoCodecH264, fourcc, true); | 200 RunBasicFileStructureTest(kVideoCodecH264, fourcc, true); |
201 } | 201 } |
202 | 202 |
203 } // namespace webrtc | 203 } // namespace webrtc |
OLD | NEW |