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 "base/logging.h"
7 #include "media/base/test_data_util.h"
8 #include "media/filters/ivf_parser.h"
9 #include "media/filters/vp9_parser.h"
10 #include "testing/gtest/include/gtest/gtest.h"
14 class Vp9ParserTest
: public ::testing::Test
{
16 void SetUp() override
{
17 base::FilePath file_path
= GetTestDataFilePath("test-25fps.vp9");
19 stream_
.reset(new base::MemoryMappedFile());
20 ASSERT_TRUE(stream_
->Initialize(file_path
)) << "Couldn't open stream file: "
21 << file_path
.MaybeAsASCII();
23 IvfFileHeader ivf_file_header
;
24 ASSERT_TRUE(ivf_parser_
.Initialize(stream_
->data(), stream_
->length(),
26 ASSERT_EQ(ivf_file_header
.fourcc
, 0x30395056u
); // VP90
29 void TearDown() override
{ stream_
.reset(); }
31 IvfParser ivf_parser_
;
32 scoped_ptr
<base::MemoryMappedFile
> stream_
;
35 TEST_F(Vp9ParserTest
, StreamFileParsing
) {
36 // Number of frames in the test stream to be parsed.
37 const int num_frames
= 250;
40 IvfFrameHeader ivf_frame_header
;
41 int num_parsed_frames
= 0;
42 const uint8_t* ivf_payload
;
44 // Parse until the end of stream/unsupported stream/error in stream is found.
45 while (ivf_parser_
.ParseNextFrame(&ivf_frame_header
, &ivf_payload
)) {
49 vp9_parser
.ParseFrame(ivf_payload
, ivf_frame_header
.frame_size
, &fhdr
));
53 DVLOG(1) << "Number of successfully parsed frames before EOS: "
56 EXPECT_EQ(num_frames
, num_parsed_frames
);
59 TEST_F(Vp9ParserTest
, VerifyFirstFrame
) {
61 IvfFrameHeader ivf_frame_header
;
62 const uint8_t* ivf_payload
;
64 ASSERT_TRUE(ivf_parser_
.ParseNextFrame(&ivf_frame_header
, &ivf_payload
));
68 vp9_parser
.ParseFrame(ivf_payload
, ivf_frame_header
.frame_size
, &fhdr
));
70 EXPECT_EQ(0, fhdr
.profile
);
71 EXPECT_FALSE(fhdr
.show_existing_frame
);
72 EXPECT_EQ(Vp9FrameHeader::KEYFRAME
, fhdr
.frame_type
);
73 EXPECT_TRUE(fhdr
.show_frame
);
74 EXPECT_FALSE(fhdr
.error_resilient_mode
);
76 EXPECT_EQ(8, fhdr
.bit_depth
);
77 EXPECT_EQ(Vp9ColorSpace::UNKNOWN
, fhdr
.color_space
);
78 EXPECT_FALSE(fhdr
.yuv_range
);
79 EXPECT_EQ(1, fhdr
.subsampling_x
);
80 EXPECT_EQ(1, fhdr
.subsampling_y
);
82 EXPECT_EQ(320u, fhdr
.width
);
83 EXPECT_EQ(240u, fhdr
.height
);
84 EXPECT_EQ(320u, fhdr
.display_width
);
85 EXPECT_EQ(240u, fhdr
.display_height
);
87 EXPECT_TRUE(fhdr
.refresh_frame_context
);
88 EXPECT_TRUE(fhdr
.frame_parallel_decoding_mode
);
89 EXPECT_EQ(0, fhdr
.frame_context_idx
);
91 EXPECT_EQ(9, fhdr
.loop_filter
.filter_level
);
92 EXPECT_EQ(0, fhdr
.loop_filter
.sharpness_level
);
94 const Vp9LoopFilter
& lf
= fhdr
.loop_filter
;
95 EXPECT_TRUE(lf
.mode_ref_delta_enabled
);
96 EXPECT_TRUE(lf
.mode_ref_delta_update
);
97 EXPECT_TRUE(lf
.update_ref_deltas
[0]);
98 EXPECT_EQ(1, lf
.ref_deltas
[0]);
99 EXPECT_EQ(-1, lf
.ref_deltas
[2]);
100 EXPECT_EQ(-1, lf
.ref_deltas
[3]);
102 const Vp9QuantizationParams
& qp
= fhdr
.quant_params
;
103 EXPECT_EQ(65, qp
.base_qindex
);
104 EXPECT_FALSE(qp
.y_dc_delta
);
105 EXPECT_FALSE(qp
.uv_dc_delta
);
106 EXPECT_FALSE(qp
.uv_ac_delta
);
107 EXPECT_FALSE(qp
.IsLossless());
109 const Vp9Segmentation
& seg
= fhdr
.segment
;
110 EXPECT_FALSE(seg
.enabled
);
112 EXPECT_EQ(0, fhdr
.log2_tile_cols
);
113 EXPECT_EQ(0, fhdr
.log2_tile_rows
);
115 EXPECT_EQ(120u, fhdr
.first_partition_size
);
116 EXPECT_EQ(18u, fhdr
.uncompressed_header_size
);
119 TEST_F(Vp9ParserTest
, VerifyInterFrame
) {
120 Vp9Parser vp9_parser
;
123 // To verify the second frame.
124 for (int i
= 0; i
< 2; i
++) {
125 IvfFrameHeader ivf_frame_header
;
126 const uint8_t* ivf_payload
;
127 ASSERT_TRUE(ivf_parser_
.ParseNextFrame(&ivf_frame_header
, &ivf_payload
));
129 vp9_parser
.ParseFrame(ivf_payload
, ivf_frame_header
.frame_size
, &fhdr
));
132 EXPECT_EQ(Vp9FrameHeader::INTERFRAME
, fhdr
.frame_type
);
133 EXPECT_FALSE(fhdr
.show_frame
);
134 EXPECT_FALSE(fhdr
.intra_only
);
135 EXPECT_FALSE(fhdr
.reset_context
);
136 EXPECT_TRUE(fhdr
.refresh_flag
[5]);
137 EXPECT_EQ(0, fhdr
.frame_refs
[0]);
138 EXPECT_EQ(1, fhdr
.frame_refs
[1]);
139 EXPECT_EQ(2, fhdr
.frame_refs
[2]);
140 EXPECT_TRUE(fhdr
.allow_high_precision_mv
);
141 EXPECT_EQ(Vp9InterpFilter::EIGHTTAP
, fhdr
.interp_filter
);
143 EXPECT_EQ(48u, fhdr
.first_partition_size
);
144 EXPECT_EQ(11u, fhdr
.uncompressed_header_size
);