OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | |
DaleCurtis
2014/11/21 23:51:14
no (c) in new copyrights.
sandersd (OOO until July 31)
2014/11/21 23:54:51
Done.
| |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/files/file_path.h" | |
6 #include "base/files/memory_mapped_file.h" | |
7 #include "media/base/test_data_util.h" | |
8 #include "media/filters/h264_parser.h" | |
9 #include "media/video/h264_poc.h" | |
10 #include "testing/gtest/include/gtest/gtest.h" | |
11 | |
12 namespace media { | |
13 | |
14 class H264POCTest: public testing::Test { | |
DaleCurtis
2014/11/21 23:51:14
Add space before :
sandersd (OOO until July 31)
2014/11/21 23:54:51
Done.
| |
15 public: | |
16 H264POCTest() : sps_(), slice_hdr_() { | |
17 // Default every frame to be a reference frame. | |
18 slice_hdr_.nal_ref_idc = 1; | |
19 } | |
20 | |
21 protected: | |
22 bool ComputePOC() { | |
23 return h264_poc_.ComputePicOrderCnt(&sps_, slice_hdr_, &poc_); | |
24 } | |
25 | |
26 // Also sets as a reference frame and unsets IDR, which is required for | |
27 // memory management control operations to be parsed. | |
28 void SetMMCO5() { | |
29 slice_hdr_.nal_ref_idc = 1; | |
30 slice_hdr_.idr_pic_flag = false; | |
31 slice_hdr_.adaptive_ref_pic_marking_mode_flag = true; | |
32 slice_hdr_.ref_pic_marking[0].memory_mgmnt_control_operation = 6; | |
33 slice_hdr_.ref_pic_marking[1].memory_mgmnt_control_operation = 5; | |
34 slice_hdr_.ref_pic_marking[2].memory_mgmnt_control_operation = 0; | |
35 } | |
36 | |
37 int32_t poc_; | |
38 | |
39 H264SPS sps_; | |
40 H264SliceHeader slice_hdr_; | |
41 H264POC h264_poc_; | |
42 | |
43 DISALLOW_COPY_AND_ASSIGN(H264POCTest); | |
44 }; | |
45 | |
46 TEST_F(H264POCTest, PicOrderCntType0) { | |
47 sps_.pic_order_cnt_type = 0; | |
48 sps_.log2_max_pic_order_cnt_lsb_minus4 = 0; // 16 | |
49 | |
50 // Initial IDR with POC 0. | |
51 slice_hdr_.idr_pic_flag = true; | |
52 ASSERT_TRUE(ComputePOC()); | |
53 ASSERT_EQ(0, poc_); | |
54 | |
55 // Ref frame with POC lsb 8. | |
56 slice_hdr_.idr_pic_flag = false; | |
57 slice_hdr_.pic_order_cnt_lsb = 8; | |
58 ASSERT_TRUE(ComputePOC()); | |
59 ASSERT_EQ(8, poc_); | |
60 | |
61 // Ref frame with POC lsb 0. This should be detected as wrapping, as the | |
62 // (negative) gap is at least half the maximum. | |
63 slice_hdr_.pic_order_cnt_lsb = 0; | |
64 ASSERT_TRUE(ComputePOC()); | |
65 ASSERT_EQ(16, poc_); | |
66 | |
67 // Ref frame with POC lsb 9. This should be detected as negative wrapping, | |
68 // as the (positive) gap is more than half the maximum. | |
69 slice_hdr_.pic_order_cnt_lsb = 9; | |
70 ASSERT_TRUE(ComputePOC()); | |
71 ASSERT_EQ(9, poc_); | |
72 } | |
73 | |
74 TEST_F(H264POCTest, PicOrderCntType0_WithMMCO5) { | |
75 sps_.pic_order_cnt_type = 0; | |
76 sps_.log2_max_pic_order_cnt_lsb_minus4 = 0; // 16 | |
77 | |
78 // Initial IDR with POC 0. | |
79 slice_hdr_.idr_pic_flag = true; | |
80 ASSERT_TRUE(ComputePOC()); | |
81 ASSERT_EQ(0, poc_); | |
82 | |
83 // Skip ahead. | |
84 slice_hdr_.idr_pic_flag = false; | |
85 slice_hdr_.pic_order_cnt_lsb = 8; | |
86 ASSERT_TRUE(ComputePOC()); | |
87 ASSERT_EQ(8, poc_); | |
88 | |
89 slice_hdr_.pic_order_cnt_lsb = 0; | |
90 ASSERT_TRUE(ComputePOC()); | |
91 ASSERT_EQ(16, poc_); | |
92 | |
93 slice_hdr_.pic_order_cnt_lsb = 8; | |
94 ASSERT_TRUE(ComputePOC()); | |
95 ASSERT_EQ(24, poc_); | |
96 | |
97 SetMMCO5(); | |
98 slice_hdr_.pic_order_cnt_lsb = 0; | |
99 ASSERT_TRUE(ComputePOC()); | |
100 ASSERT_EQ(32, poc_); | |
101 | |
102 // Due to the MMCO5 above, this is relative to 0, but also detected as | |
103 // positive wrapping. | |
104 slice_hdr_.pic_order_cnt_lsb = 8; | |
105 ASSERT_TRUE(ComputePOC()); | |
106 ASSERT_EQ(24, poc_); | |
107 } | |
108 | |
109 TEST_F(H264POCTest, PicOrderCntType1) { | |
110 sps_.pic_order_cnt_type = 1; | |
111 sps_.log2_max_frame_num_minus4 = 0; // 16 | |
112 sps_.num_ref_frames_in_pic_order_cnt_cycle = 2; | |
113 sps_.expected_delta_per_pic_order_cnt_cycle = 3; | |
114 sps_.offset_for_ref_frame[0] = 1; | |
115 sps_.offset_for_ref_frame[1] = 2; | |
116 | |
117 // Initial IDR with POC 0. | |
118 slice_hdr_.idr_pic_flag = true; | |
119 slice_hdr_.frame_num = 0; | |
120 ASSERT_TRUE(ComputePOC()); | |
121 ASSERT_EQ(0, poc_); | |
122 | |
123 // Ref frame. | |
124 slice_hdr_.idr_pic_flag = false; | |
125 slice_hdr_.frame_num = 1; | |
126 ASSERT_TRUE(ComputePOC()); | |
127 ASSERT_EQ(1, poc_); | |
128 | |
129 // Ref frame. | |
130 slice_hdr_.frame_num = 2; | |
131 ASSERT_TRUE(ComputePOC()); | |
132 ASSERT_EQ(3, poc_); | |
133 | |
134 // Ref frame. | |
135 slice_hdr_.frame_num = 3; | |
136 ASSERT_TRUE(ComputePOC()); | |
137 ASSERT_EQ(4, poc_); | |
138 | |
139 // Ref frame. | |
140 slice_hdr_.frame_num = 4; | |
141 ASSERT_TRUE(ComputePOC()); | |
142 ASSERT_EQ(6, poc_); | |
143 | |
144 // Ref frame, detected as wrapping (ie, this is frame 16). | |
145 slice_hdr_.frame_num = 0; | |
146 ASSERT_TRUE(ComputePOC()); | |
147 ASSERT_EQ(24, poc_); | |
148 } | |
149 | |
150 TEST_F(H264POCTest, PicOrderCntType1_WithMMCO5) { | |
151 sps_.pic_order_cnt_type = 1; | |
152 sps_.log2_max_frame_num_minus4 = 0; // 16 | |
153 sps_.num_ref_frames_in_pic_order_cnt_cycle = 2; | |
154 sps_.expected_delta_per_pic_order_cnt_cycle = 3; | |
155 sps_.offset_for_ref_frame[0] = 1; | |
156 sps_.offset_for_ref_frame[1] = 2; | |
157 | |
158 // Initial IDR with POC 0. | |
159 slice_hdr_.idr_pic_flag = true; | |
160 slice_hdr_.frame_num = 0; | |
161 ASSERT_TRUE(ComputePOC()); | |
162 ASSERT_EQ(0, poc_); | |
163 | |
164 // Ref frame. | |
165 slice_hdr_.idr_pic_flag = false; | |
166 slice_hdr_.frame_num = 1; | |
167 ASSERT_TRUE(ComputePOC()); | |
168 ASSERT_EQ(1, poc_); | |
169 | |
170 // Ref frame, detected as wrapping. | |
171 SetMMCO5(); | |
172 slice_hdr_.frame_num = 0; | |
173 ASSERT_TRUE(ComputePOC()); | |
174 ASSERT_EQ(24, poc_); | |
175 | |
176 // Ref frame, wrapping from before has been cleared. | |
177 slice_hdr_.frame_num = 1; | |
178 ASSERT_TRUE(ComputePOC()); | |
179 ASSERT_EQ(1, poc_); | |
180 } | |
181 | |
182 TEST_F(H264POCTest, PicOrderCntType2) { | |
183 sps_.pic_order_cnt_type = 2; | |
184 | |
185 // Initial IDR with POC 0. | |
186 slice_hdr_.idr_pic_flag = true; | |
187 slice_hdr_.frame_num = 0; | |
188 ASSERT_TRUE(ComputePOC()); | |
189 ASSERT_EQ(0, poc_); | |
190 | |
191 // Ref frame. | |
192 slice_hdr_.idr_pic_flag = false; | |
193 slice_hdr_.frame_num = 1; | |
194 ASSERT_TRUE(ComputePOC()); | |
195 ASSERT_EQ(2, poc_); | |
196 | |
197 // Ref frame. | |
198 slice_hdr_.frame_num = 2; | |
199 ASSERT_TRUE(ComputePOC()); | |
200 ASSERT_EQ(4, poc_); | |
201 | |
202 // Ref frame. | |
203 slice_hdr_.frame_num = 3; | |
204 ASSERT_TRUE(ComputePOC()); | |
205 ASSERT_EQ(6, poc_); | |
206 | |
207 // Ref frame. | |
208 slice_hdr_.frame_num = 4; | |
209 ASSERT_TRUE(ComputePOC()); | |
210 ASSERT_EQ(8, poc_); | |
211 | |
212 // Ref frame, detected as wrapping (ie, this is frame 16). | |
213 slice_hdr_.frame_num = 0; | |
214 ASSERT_TRUE(ComputePOC()); | |
215 ASSERT_EQ(32, poc_); | |
216 } | |
217 | |
218 TEST_F(H264POCTest, PicOrderCntType2_WithMMCO5) { | |
219 sps_.pic_order_cnt_type = 2; | |
220 | |
221 // Initial IDR with POC 0. | |
222 slice_hdr_.idr_pic_flag = true; | |
223 slice_hdr_.frame_num = 0; | |
224 ASSERT_TRUE(ComputePOC()); | |
225 ASSERT_EQ(0, poc_); | |
226 | |
227 // Ref frame. | |
228 slice_hdr_.idr_pic_flag = false; | |
229 slice_hdr_.frame_num = 1; | |
230 ASSERT_TRUE(ComputePOC()); | |
231 ASSERT_EQ(2, poc_); | |
232 | |
233 // Ref frame, detected as wrapping. | |
234 SetMMCO5(); | |
235 slice_hdr_.frame_num = 0; | |
236 ASSERT_TRUE(ComputePOC()); | |
237 ASSERT_EQ(32, poc_); | |
238 | |
239 // Ref frame, wrapping from before has been cleared. | |
240 slice_hdr_.frame_num = 1; | |
241 ASSERT_TRUE(ComputePOC()); | |
242 ASSERT_EQ(2, poc_); | |
243 } | |
244 | |
245 } // namespace media | |
OLD | NEW |