Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(829)

Side by Side Diff: media/filters/h264_parser_unittest.cc

Issue 2268183009: H264SPS: Centralize computation of coded size and visible rect. (Closed)
Patch Set: Make sure fuzzing code actually runs. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/filters/h264_parser_fuzzertest.cc ('k') | media/formats/mp2t/es_parser_h264.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <limits>
6 #include <memory>
7
5 #include "base/command_line.h" 8 #include "base/command_line.h"
6 #include "base/files/memory_mapped_file.h" 9 #include "base/files/memory_mapped_file.h"
7 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/ptr_util.h"
12 #include "base/optional.h"
8 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
9 #include "media/base/test_data_util.h" 14 #include "media/base/test_data_util.h"
10 #include "media/filters/h264_parser.h" 15 #include "media/filters/h264_parser.h"
11 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "ui/gfx/geometry/rect.h"
18 #include "ui/gfx/geometry/size.h"
12 19
13 namespace media { 20 namespace media {
14 21
22 class H264SPSTest : public ::testing::Test {
23 public:
24 // An exact clone of an SPS from Big Buck Bunny 480p.
25 std::unique_ptr<H264SPS> MakeSPS_BBB480p() {
26 std::unique_ptr<H264SPS> sps = base::MakeUnique<H264SPS>();
27 sps->profile_idc = 100;
28 sps->level_idc = 30;
29 sps->chroma_format_idc = 1;
30 sps->log2_max_pic_order_cnt_lsb_minus4 = 2;
31 sps->max_num_ref_frames = 5;
32 sps->pic_width_in_mbs_minus1 = 52;
33 sps->pic_height_in_map_units_minus1 = 29;
34 sps->frame_mbs_only_flag = true;
35 sps->direct_8x8_inference_flag = true;
36 sps->vui_parameters_present_flag = true;
37 sps->timing_info_present_flag = true;
38 sps->num_units_in_tick = 1;
39 sps->time_scale = 48;
40 sps->fixed_frame_rate_flag = true;
41 sps->bitstream_restriction_flag = true;
42 // These next three fields are not part of our SPS struct yet.
43 // sps->motion_vectors_over_pic_boundaries_flag = true;
44 // sps->log2_max_mv_length_horizontal = 10;
45 // sps->log2_max_mv_length_vertical = 10;
46 sps->max_num_reorder_frames = 2;
47 sps->max_dec_frame_buffering = 5;
48
49 // Computed field, matches |chroma_format_idc| in this case.
50 // TODO(sandersd): Extract that computation from the parsing step.
51 sps->chroma_array_type = 1;
52
53 return sps;
54 }
55 };
56
57 TEST_F(H264SPSTest, GetCodedSize) {
58 std::unique_ptr<H264SPS> sps = MakeSPS_BBB480p();
59 EXPECT_EQ(gfx::Size(848, 480), sps->GetCodedSize());
60
61 // Overflow.
62 sps->pic_width_in_mbs_minus1 = std::numeric_limits<int>::max();
63 EXPECT_EQ(base::nullopt, sps->GetCodedSize());
64 }
65
66 TEST_F(H264SPSTest, GetVisibleRect) {
67 std::unique_ptr<H264SPS> sps = MakeSPS_BBB480p();
68 EXPECT_EQ(gfx::Rect(0, 0, 848, 480), sps->GetVisibleRect());
69
70 // Add some cropping.
71 sps->frame_cropping_flag = true;
72 sps->frame_crop_left_offset = 1;
73 sps->frame_crop_right_offset = 2;
74 sps->frame_crop_top_offset = 3;
75 sps->frame_crop_bottom_offset = 4;
76 EXPECT_EQ(gfx::Rect(2, 6, 848 - 6, 480 - 14), sps->GetVisibleRect());
77
78 // Not quite invalid.
79 sps->frame_crop_left_offset = 422;
80 sps->frame_crop_right_offset = 1;
81 sps->frame_crop_top_offset = 0;
82 sps->frame_crop_bottom_offset = 0;
83 EXPECT_EQ(gfx::Rect(844, 0, 2, 480), sps->GetVisibleRect());
84
85 // Invalid crop.
86 sps->frame_crop_left_offset = 423;
87 sps->frame_crop_right_offset = 1;
88 sps->frame_crop_top_offset = 0;
89 sps->frame_crop_bottom_offset = 0;
90 EXPECT_EQ(base::nullopt, sps->GetVisibleRect());
91
92 // Overflow.
93 sps->frame_crop_left_offset = std::numeric_limits<int>::max() / 2 + 1;
94 sps->frame_crop_right_offset = 0;
95 sps->frame_crop_top_offset = 0;
96 sps->frame_crop_bottom_offset = 0;
97 EXPECT_EQ(base::nullopt, sps->GetVisibleRect());
98 }
99
15 TEST(H264ParserTest, StreamFileParsing) { 100 TEST(H264ParserTest, StreamFileParsing) {
16 base::FilePath file_path = GetTestDataFilePath("test-25fps.h264"); 101 base::FilePath file_path = GetTestDataFilePath("test-25fps.h264");
17 // Number of NALUs in the test stream to be parsed. 102 // Number of NALUs in the test stream to be parsed.
18 int num_nalus = 759; 103 int num_nalus = 759;
19 104
20 base::MemoryMappedFile stream; 105 base::MemoryMappedFile stream;
21 ASSERT_TRUE(stream.Initialize(file_path)) 106 ASSERT_TRUE(stream.Initialize(file_path))
22 << "Couldn't open stream file: " << file_path.MaybeAsASCII(); 107 << "Couldn't open stream file: " << file_path.MaybeAsASCII();
23 108
24 H264Parser parser; 109 H264Parser parser;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 147
63 default: 148 default:
64 // Skip unsupported NALU. 149 // Skip unsupported NALU.
65 DVLOG(4) << "Skipping unsupported NALU"; 150 DVLOG(4) << "Skipping unsupported NALU";
66 break; 151 break;
67 } 152 }
68 } 153 }
69 } 154 }
70 155
71 } // namespace media 156 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/h264_parser_fuzzertest.cc ('k') | media/formats/mp2t/es_parser_h264.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698