Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/command_line.h" | |
| 6 #include "base/files/memory_mapped_file.h" | 5 #include "base/files/memory_mapped_file.h" |
| 7 #include "base/logging.h" | 6 #include "base/logging.h" |
| 8 #include "base/strings/string_number_conversions.h" | |
| 9 #include "base/sys_byteorder.h" | |
| 10 #include "media/base/test_data_util.h" | 7 #include "media/base/test_data_util.h" |
| 8 #include "media/filters/ivf_parser.h" | |
| 11 #include "media/filters/vp8_parser.h" | 9 #include "media/filters/vp8_parser.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 11 |
| 14 namespace media { | 12 namespace media { |
| 15 | 13 |
| 16 TEST(Vp8ParserTest, StreamFileParsing) { | 14 TEST(Vp8ParserTest, StreamFileParsing) { |
| 17 base::FilePath file_path = GetTestDataFilePath("test-25fps.vp8"); | 15 base::FilePath file_path = GetTestDataFilePath("test-25fps.vp8"); |
| 18 // Number of frames in the test stream to be parsed. | 16 // Number of frames in the test stream to be parsed. |
| 19 const int num_frames = 250; | 17 const int num_frames = 250; |
| 20 | 18 |
| 21 base::MemoryMappedFile stream; | 19 base::MemoryMappedFile stream; |
| 22 ASSERT_TRUE(stream.Initialize(file_path)) | 20 ASSERT_TRUE(stream.Initialize(file_path)) |
| 23 << "Couldn't open stream file: " << file_path.MaybeAsASCII(); | 21 << "Couldn't open stream file: " << file_path.MaybeAsASCII(); |
| 24 | 22 |
| 25 Vp8Parser parser; | 23 IvfParser ivf_parser; |
| 24 IvfFileHeader ivf_file_header; | |
|
wuchengli
2015/07/30 06:26:13
memset to 0
kcwu
2015/07/30 11:52:52
Done.
| |
| 25 ASSERT_TRUE( | |
| 26 ivf_parser.Initialize(stream.data(), stream.length(), &ivf_file_header)); | |
| 27 ASSERT_EQ(ivf_file_header.fourcc, 0x30385056u); // VP80 | |
|
wuchengli
2015/07/30 06:26:13
Make 0x30385056 a constant and share it with video
kcwu
2015/07/30 11:52:52
Where do you suggest to put these fourcc values?
| |
| 28 | |
| 29 Vp8Parser vp8_parser; | |
| 30 IvfFrameHeader ivf_frame_header; | |
|
wuchengli
2015/07/30 06:26:13
memset to 0
kcwu
2015/07/30 11:52:52
Done.
| |
| 31 int num_parsed_frames = 0; | |
| 26 | 32 |
| 27 // Parse until the end of stream/unsupported stream/error in stream is found. | 33 // Parse until the end of stream/unsupported stream/error in stream is found. |
| 28 int num_parsed_frames = 0; | 34 while (ivf_parser.ParseNextFrame(&ivf_frame_header)) { |
| 29 const uint8_t* stream_ptr = stream.data(); | 35 Vp8FrameHeader fhdr; |
| 30 size_t bytes_left = stream.length(); | |
| 31 // Skip IVF file header. | |
| 32 const size_t kIvfStreamHeaderLen = 32; | |
| 33 CHECK_GE(bytes_left, kIvfStreamHeaderLen); | |
| 34 stream_ptr += kIvfStreamHeaderLen; | |
| 35 bytes_left -= kIvfStreamHeaderLen; | |
| 36 | 36 |
| 37 const size_t kIvfFrameHeaderLen = 12; | 37 ASSERT_TRUE(vp8_parser.ParseFrame(ivf_frame_header.data, |
| 38 while (bytes_left > kIvfFrameHeaderLen) { | 38 ivf_frame_header.data_size, &fhdr)); |
| 39 Vp8FrameHeader fhdr; | |
| 40 uint32_t frame_size = | |
| 41 base::ByteSwapToLE32(*reinterpret_cast<const uint32_t*>(stream_ptr)); | |
| 42 // Skip IVF frame header. | |
| 43 stream_ptr += kIvfFrameHeaderLen; | |
| 44 bytes_left -= kIvfFrameHeaderLen; | |
| 45 | 39 |
| 46 ASSERT_TRUE(parser.ParseFrame(stream_ptr, frame_size, &fhdr)); | |
| 47 | |
| 48 stream_ptr += frame_size; | |
| 49 bytes_left -= frame_size; | |
| 50 ++num_parsed_frames; | 40 ++num_parsed_frames; |
| 51 } | 41 } |
| 52 | 42 |
| 53 DVLOG(1) << "Number of successfully parsed frames before EOS: " | 43 DVLOG(1) << "Number of successfully parsed frames before EOS: " |
| 54 << num_parsed_frames; | 44 << num_parsed_frames; |
| 55 | 45 |
| 56 EXPECT_EQ(num_frames, num_parsed_frames); | 46 EXPECT_EQ(num_frames, num_parsed_frames); |
| 57 } | 47 } |
| 58 | 48 |
| 59 } // namespace media | 49 } // namespace media |
| OLD | NEW |