OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 |
11 #include <stdio.h> | 11 #include <stdio.h> |
12 #include <stdlib.h> | 12 #include <stdlib.h> |
13 | 13 |
14 #include <fstream> | 14 #include <fstream> |
| 15 #include <memory> |
15 | 16 |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "webrtc/base/scoped_ptr.h" | |
18 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 18 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
19 #include "webrtc/test/testsupport/fileutils.h" | 19 #include "webrtc/test/testsupport/fileutils.h" |
20 #include "webrtc/tools/frame_editing/frame_editing_lib.h" | 20 #include "webrtc/tools/frame_editing/frame_editing_lib.h" |
21 | 21 |
22 namespace webrtc { | 22 namespace webrtc { |
23 namespace test { | 23 namespace test { |
24 | 24 |
25 const int kWidth = 352; | 25 const int kWidth = 352; |
26 const int kHeight = 288; | 26 const int kHeight = 288; |
27 const size_t kFrameSize = CalcBufferSize(kI420, kWidth, kHeight); | 27 const size_t kFrameSize = CalcBufferSize(kI420, kWidth, kHeight); |
(...skipping 21 matching lines...) Expand all Loading... |
49 num_frames_read_ = 0; | 49 num_frames_read_ = 0; |
50 } | 50 } |
51 virtual void TearDown() { | 51 virtual void TearDown() { |
52 fclose(original_fid_); | 52 fclose(original_fid_); |
53 fclose(edited_fid_); | 53 fclose(edited_fid_); |
54 remove(test_video_.c_str()); | 54 remove(test_video_.c_str()); |
55 } | 55 } |
56 // Compares the frames in both streams to the end of one of the streams. | 56 // Compares the frames in both streams to the end of one of the streams. |
57 void CompareToTheEnd(FILE* test_video_fid, | 57 void CompareToTheEnd(FILE* test_video_fid, |
58 FILE* ref_video_fid, | 58 FILE* ref_video_fid, |
59 rtc::scoped_ptr<int[]>* ref_buffer, | 59 std::unique_ptr<int[]>* ref_buffer, |
60 rtc::scoped_ptr<int[]>* test_buffer) { | 60 std::unique_ptr<int[]>* test_buffer) { |
61 while (!feof(test_video_fid) && !feof(ref_video_fid)) { | 61 while (!feof(test_video_fid) && !feof(ref_video_fid)) { |
62 num_bytes_read_ = fread(ref_buffer->get(), 1, kFrameSize, ref_video_fid); | 62 num_bytes_read_ = fread(ref_buffer->get(), 1, kFrameSize, ref_video_fid); |
63 if (!feof(ref_video_fid)) { | 63 if (!feof(ref_video_fid)) { |
64 EXPECT_EQ(kFrameSize, num_bytes_read_); | 64 EXPECT_EQ(kFrameSize, num_bytes_read_); |
65 } | 65 } |
66 num_bytes_read_ = fread(test_buffer->get(), 1, kFrameSize, | 66 num_bytes_read_ = fread(test_buffer->get(), 1, kFrameSize, |
67 test_video_fid); | 67 test_video_fid); |
68 if (!feof(test_video_fid)) { | 68 if (!feof(test_video_fid)) { |
69 EXPECT_EQ(kFrameSize, num_bytes_read_); | 69 EXPECT_EQ(kFrameSize, num_bytes_read_); |
70 } | 70 } |
71 if (!feof(test_video_fid) && !feof(test_video_fid)) { | 71 if (!feof(test_video_fid) && !feof(test_video_fid)) { |
72 EXPECT_EQ(0, memcmp(ref_buffer->get(), test_buffer->get(), | 72 EXPECT_EQ(0, memcmp(ref_buffer->get(), test_buffer->get(), |
73 kFrameSize)); | 73 kFrameSize)); |
74 } | 74 } |
75 } | 75 } |
76 // There should not be anything left in either stream. | 76 // There should not be anything left in either stream. |
77 EXPECT_EQ(!feof(test_video_fid), !feof(ref_video_fid)); | 77 EXPECT_EQ(!feof(test_video_fid), !feof(ref_video_fid)); |
78 } | 78 } |
79 std::string reference_video_; | 79 std::string reference_video_; |
80 std::string test_video_; | 80 std::string test_video_; |
81 FILE* original_fid_; | 81 FILE* original_fid_; |
82 FILE* edited_fid_; | 82 FILE* edited_fid_; |
83 size_t num_bytes_read_; | 83 size_t num_bytes_read_; |
84 rtc::scoped_ptr<int[]> original_buffer_; | 84 std::unique_ptr<int[]> original_buffer_; |
85 rtc::scoped_ptr<int[]> edited_buffer_; | 85 std::unique_ptr<int[]> edited_buffer_; |
86 int num_frames_read_; | 86 int num_frames_read_; |
87 }; | 87 }; |
88 | 88 |
89 TEST_F(FrameEditingTest, ValidInPath) { | 89 TEST_F(FrameEditingTest, ValidInPath) { |
90 const int kFirstFrameToProcess = 160; | 90 const int kFirstFrameToProcess = 160; |
91 const int kInterval = -1; | 91 const int kInterval = -1; |
92 const int kLastFrameToProcess = 240; | 92 const int kLastFrameToProcess = 240; |
93 | 93 |
94 int result = EditFrames(reference_video_, kWidth, kHeight, | 94 int result = EditFrames(reference_video_, kWidth, kHeight, |
95 kFirstFrameToProcess, kInterval, kLastFrameToProcess, | 95 kFirstFrameToProcess, kInterval, kLastFrameToProcess, |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 EXPECT_EQ(kFrameSize, num_bytes_read_); | 207 EXPECT_EQ(kFrameSize, num_bytes_read_); |
208 EXPECT_EQ(0, memcmp(original_buffer_.get(), edited_buffer_.get(), | 208 EXPECT_EQ(0, memcmp(original_buffer_.get(), edited_buffer_.get(), |
209 kFrameSize)); | 209 kFrameSize)); |
210 } | 210 } |
211 } | 211 } |
212 CompareToTheEnd(edited_fid_, original_fid_, &original_buffer_, | 212 CompareToTheEnd(edited_fid_, original_fid_, &original_buffer_, |
213 &edited_buffer_); | 213 &edited_buffer_); |
214 } | 214 } |
215 } // namespace test | 215 } // namespace test |
216 } // namespace webrtc | 216 } // namespace webrtc |
OLD | NEW |