Updating XTBs based on .GRDs from branch master
[chromium-blink-merge.git] / media / filters / ivf_parser_unittest.cc
blob2d89dc2f745e04c0cfde122eab0b6c392d24b74c
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/files/memory_mapped_file.h"
6 #include "media/base/test_data_util.h"
7 #include "media/filters/ivf_parser.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 namespace media {
12 TEST(IvfParserTest, StreamFileParsing) {
13 base::FilePath file_path = GetTestDataFilePath("test-25fps.vp8");
15 base::MemoryMappedFile stream;
16 ASSERT_TRUE(stream.Initialize(file_path)) << "Couldn't open stream file: "
17 << file_path.MaybeAsASCII();
19 IvfParser parser;
20 IvfFileHeader file_header = {};
22 EXPECT_TRUE(parser.Initialize(stream.data(), stream.length(), &file_header));
24 // Check file header fields.
25 EXPECT_EQ(0, memcmp(file_header.signature, kIvfHeaderSignature,
26 sizeof(file_header.signature)));
27 EXPECT_EQ(0, file_header.version);
28 EXPECT_EQ(sizeof(IvfFileHeader), file_header.header_size);
29 EXPECT_EQ(0x30385056u, file_header.fourcc); // VP80
30 EXPECT_EQ(320u, file_header.width);
31 EXPECT_EQ(240u, file_header.height);
32 EXPECT_EQ(50u, file_header.timebase_denum);
33 EXPECT_EQ(2u, file_header.timebase_num);
34 EXPECT_EQ(250u, file_header.num_frames);
36 IvfFrameHeader frame_header;
37 size_t num_parsed_frames = 0;
38 const uint8_t* payload = nullptr;
39 while (parser.ParseNextFrame(&frame_header, &payload)) {
40 ++num_parsed_frames;
41 EXPECT_TRUE(payload != nullptr);
43 // Only check the first frame.
44 if (num_parsed_frames == 1u) {
45 EXPECT_EQ(14788u, frame_header.frame_size);
46 EXPECT_EQ(0u, frame_header.timestamp);
47 EXPECT_EQ(
48 static_cast<ptrdiff_t>(sizeof(file_header) + sizeof(frame_header)),
49 payload - stream.data());
53 EXPECT_EQ(file_header.num_frames, num_parsed_frames);
56 } // namespace media