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 bool ParseNextFrame(struct Vp9FrameHeader
* frame_hdr
);
33 const Vp9Segmentation
& GetSegmentation() const {
34 return vp9_parser_
.GetSegmentation();
37 const Vp9LoopFilter
& GetLoopFilter() const {
38 return vp9_parser_
.GetLoopFilter();
41 IvfParser ivf_parser_
;
42 scoped_ptr
<base::MemoryMappedFile
> stream_
;
44 Vp9Parser vp9_parser_
;
47 bool Vp9ParserTest::ParseNextFrame(Vp9FrameHeader
* fhdr
) {
49 Vp9Parser::Result res
= vp9_parser_
.ParseNextFrame(fhdr
);
50 if (res
== Vp9Parser::kEOStream
) {
51 IvfFrameHeader ivf_frame_header
;
52 const uint8_t* ivf_payload
;
54 if (!ivf_parser_
.ParseNextFrame(&ivf_frame_header
, &ivf_payload
))
57 vp9_parser_
.SetStream(ivf_payload
, ivf_frame_header
.frame_size
);
61 return res
== Vp9Parser::kOk
;
65 TEST_F(Vp9ParserTest
, StreamFileParsing
) {
66 // Number of frames in the test stream to be parsed.
67 const int num_frames
= 250;
68 int num_parsed_frames
= 0;
70 while (num_parsed_frames
< num_frames
) {
72 if (!ParseNextFrame(&fhdr
))
78 DVLOG(1) << "Number of successfully parsed frames before EOS: "
81 EXPECT_EQ(num_frames
, num_parsed_frames
);
84 TEST_F(Vp9ParserTest
, VerifyFirstFrame
) {
87 ASSERT_TRUE(ParseNextFrame(&fhdr
));
89 EXPECT_EQ(0, fhdr
.profile
);
90 EXPECT_FALSE(fhdr
.show_existing_frame
);
91 EXPECT_EQ(Vp9FrameHeader::KEYFRAME
, fhdr
.frame_type
);
92 EXPECT_TRUE(fhdr
.show_frame
);
93 EXPECT_FALSE(fhdr
.error_resilient_mode
);
95 EXPECT_EQ(8, fhdr
.bit_depth
);
96 EXPECT_EQ(Vp9ColorSpace::UNKNOWN
, fhdr
.color_space
);
97 EXPECT_FALSE(fhdr
.yuv_range
);
98 EXPECT_EQ(1, fhdr
.subsampling_x
);
99 EXPECT_EQ(1, fhdr
.subsampling_y
);
101 EXPECT_EQ(320u, fhdr
.width
);
102 EXPECT_EQ(240u, fhdr
.height
);
103 EXPECT_EQ(320u, fhdr
.display_width
);
104 EXPECT_EQ(240u, fhdr
.display_height
);
106 EXPECT_TRUE(fhdr
.refresh_frame_context
);
107 EXPECT_TRUE(fhdr
.frame_parallel_decoding_mode
);
108 EXPECT_EQ(0, fhdr
.frame_context_idx
);
110 const Vp9LoopFilter
& lf
= GetLoopFilter();
111 EXPECT_EQ(9, lf
.filter_level
);
112 EXPECT_EQ(0, lf
.sharpness_level
);
113 EXPECT_TRUE(lf
.mode_ref_delta_enabled
);
114 EXPECT_TRUE(lf
.mode_ref_delta_update
);
115 EXPECT_TRUE(lf
.update_ref_deltas
[0]);
116 EXPECT_EQ(1, lf
.ref_deltas
[0]);
117 EXPECT_EQ(-1, lf
.ref_deltas
[2]);
118 EXPECT_EQ(-1, lf
.ref_deltas
[3]);
120 const Vp9QuantizationParams
& qp
= fhdr
.quant_params
;
121 EXPECT_EQ(65, qp
.base_qindex
);
122 EXPECT_FALSE(qp
.y_dc_delta
);
123 EXPECT_FALSE(qp
.uv_dc_delta
);
124 EXPECT_FALSE(qp
.uv_ac_delta
);
125 EXPECT_FALSE(qp
.IsLossless());
127 const Vp9Segmentation
& seg
= GetSegmentation();
128 EXPECT_FALSE(seg
.enabled
);
130 EXPECT_EQ(0, fhdr
.log2_tile_cols
);
131 EXPECT_EQ(0, fhdr
.log2_tile_rows
);
133 EXPECT_EQ(120u, fhdr
.first_partition_size
);
134 EXPECT_EQ(18u, fhdr
.uncompressed_header_size
);
137 TEST_F(Vp9ParserTest
, VerifyInterFrame
) {
140 // To verify the second frame.
141 for (int i
= 0; i
< 2; i
++)
142 ASSERT_TRUE(ParseNextFrame(&fhdr
));
144 EXPECT_EQ(Vp9FrameHeader::INTERFRAME
, fhdr
.frame_type
);
145 EXPECT_FALSE(fhdr
.show_frame
);
146 EXPECT_FALSE(fhdr
.intra_only
);
147 EXPECT_FALSE(fhdr
.reset_context
);
148 EXPECT_TRUE(fhdr
.RefreshFlag(2));
149 EXPECT_EQ(0, fhdr
.frame_refs
[0]);
150 EXPECT_EQ(1, fhdr
.frame_refs
[1]);
151 EXPECT_EQ(2, fhdr
.frame_refs
[2]);
152 EXPECT_TRUE(fhdr
.allow_high_precision_mv
);
153 EXPECT_EQ(Vp9InterpFilter::EIGHTTAP
, fhdr
.interp_filter
);
155 EXPECT_EQ(48u, fhdr
.first_partition_size
);
156 EXPECT_EQ(11u, fhdr
.uncompressed_header_size
);