Re-subimission of https://codereview.chromium.org/1041213003/
[chromium-blink-merge.git] / media / filters / vp8_parser_unittest.cc
blob39a2a801032e7d6cb2f459199b611321ae1effc2
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
3 // found in the LICENSE file.
5 #include "base/command_line.h"
6 #include "base/files/memory_mapped_file.h"
7 #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"
11 #include "media/filters/vp8_parser.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 namespace media {
16 TEST(Vp8ParserTest, StreamFileParsing) {
17 base::FilePath file_path = GetTestDataFilePath("test-25fps.vp8");
18 // Number of frames in the test stream to be parsed.
19 const int num_frames = 250;
21 base::MemoryMappedFile stream;
22 ASSERT_TRUE(stream.Initialize(file_path))
23 << "Couldn't open stream file: " << file_path.MaybeAsASCII();
25 Vp8Parser parser;
27 // Parse until the end of stream/unsupported stream/error in stream is found.
28 int num_parsed_frames = 0;
29 const uint8_t* stream_ptr = stream.data();
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;
37 const size_t kIvfFrameHeaderLen = 12;
38 while (bytes_left > kIvfFrameHeaderLen) {
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;
46 ASSERT_TRUE(parser.ParseFrame(stream_ptr, frame_size, &fhdr));
48 stream_ptr += frame_size;
49 bytes_left -= frame_size;
50 ++num_parsed_frames;
53 DVLOG(1) << "Number of successfully parsed frames before EOS: "
54 << num_parsed_frames;
56 EXPECT_EQ(num_frames, num_parsed_frames);
59 } // namespace media