diff --git a/webrtc/tools/frame_cutter/frame_cutter_lib.cc b/webrtc/tools/frame_cutter/frame_cutter_lib.cc index c387cd4bce..33597bf3cf 100644 --- a/webrtc/tools/frame_cutter/frame_cutter_lib.cc +++ b/webrtc/tools/frame_cutter/frame_cutter_lib.cc @@ -29,7 +29,7 @@ int FrameCutter(const string& in_path, int width, int height, return -10; } - FILE* in_fid = fopen(in_path.c_str() , "r"); + FILE* in_fid = fopen(in_path.c_str() , "rb"); if (!in_fid) { fprintf(stderr, "Could not read input file: %s.\n", in_path.c_str()); return -11; @@ -40,7 +40,7 @@ int FrameCutter(const string& in_path, int width, int height, webrtc::scoped_array temp_buffer(new uint8_t[frame_length]); - FILE* out_fid = fopen(out_path.c_str(), "w"); + FILE* out_fid = fopen(out_path.c_str(), "wb"); if (!out_fid) { fprintf(stderr, "Could not open output file: %s.\n", out_path.c_str()); diff --git a/webrtc/tools/frame_cutter/frame_cutter_unittest.cc b/webrtc/tools/frame_cutter/frame_cutter_unittest.cc index a58cc3b98a..ad2b588c04 100644 --- a/webrtc/tools/frame_cutter/frame_cutter_unittest.cc +++ b/webrtc/tools/frame_cutter/frame_cutter_unittest.cc @@ -44,9 +44,9 @@ TEST(FrameCutterUnittest, ValidInPath) { last_frame_to_cut, test_video); EXPECT_EQ(0, result); - FILE* ref_video_fid = fopen(ref_video.c_str(), "r"); + FILE* ref_video_fid = fopen(ref_video.c_str(), "rb"); ASSERT_TRUE(ref_video_fid != NULL); - FILE* test_video_fid = fopen(test_video.c_str(), "r"); + FILE* test_video_fid = fopen(test_video.c_str(), "rb"); ASSERT_TRUE(test_video_fid != NULL); const int frame_size =CalcBufferSize(kI420, width, height); @@ -55,30 +55,33 @@ TEST(FrameCutterUnittest, ValidInPath) { scoped_array test_buffer(new int[frame_size]); for (int i = 0; i < first_frame_to_cut; ++i) { - num_bytes_read = fread(ref_buffer.get(), frame_size, 1, ref_video_fid); + num_bytes_read = fread(ref_buffer.get(), 1, frame_size, ref_video_fid); EXPECT_EQ(frame_size, num_bytes_read); - num_bytes_read = fread(test_buffer.get(), frame_size, 1, test_video_fid); + num_bytes_read = fread(test_buffer.get(), 1, frame_size, test_video_fid); EXPECT_EQ(frame_size, num_bytes_read); EXPECT_EQ(0, memcmp(ref_buffer.get(), test_buffer.get(), frame_size)); } // Do not compare the frames that have been cut. for (int i = first_frame_to_cut; i <= last_frame_to_cut; ++i) { - num_bytes_read = fread(&ref_buffer, frame_size, 1, ref_video_fid); + num_bytes_read = fread(ref_buffer.get(), 1, frame_size, ref_video_fid); EXPECT_EQ(frame_size, num_bytes_read); } - while (!feof(test_video_fid)) { - num_bytes_read = fread(&ref_buffer, frame_size, 1, ref_video_fid); - EXPECT_EQ(frame_size, num_bytes_read); - num_bytes_read = fread(&test_buffer, frame_size, 1, test_video_fid); - EXPECT_EQ(frame_size, num_bytes_read); - EXPECT_EQ(0, memcmp(ref_buffer.get(), test_buffer.get(), frame_size)); + while (!feof(test_video_fid) && !feof(ref_video_fid)) { + num_bytes_read = fread(ref_buffer.get(), 1, frame_size, ref_video_fid); + if (!feof(ref_video_fid)) { + EXPECT_EQ(frame_size, num_bytes_read); + } + num_bytes_read = fread(test_buffer.get(), 1, frame_size, test_video_fid); + if (!feof(test_video_fid)) { + EXPECT_EQ(frame_size, num_bytes_read); + } + if (!feof(test_video_fid) && !feof(test_video_fid)) { + EXPECT_EQ(0, memcmp(ref_buffer.get(), test_buffer.get(), frame_size)); + } } - bool are_both_files_at_the_end = - (feof(test_video_fid) && feof(test_video_fid)); - EXPECT_TRUE(are_both_files_at_the_end); } TEST(FrameCutterUnittest, EmptySetToCut) {