| Index: media/filters/h264_parser_unittest.cc
|
| diff --git a/media/filters/h264_parser_unittest.cc b/media/filters/h264_parser_unittest.cc
|
| index 1874666c3c2709bf670104fb1e2310cae5004b6a..9d69e2bfc0713921789e4344baed30c265cd7484 100644
|
| --- a/media/filters/h264_parser_unittest.cc
|
| +++ b/media/filters/h264_parser_unittest.cc
|
| @@ -2,16 +2,101 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| +#include <limits>
|
| +#include <memory>
|
| +
|
| #include "base/command_line.h"
|
| #include "base/files/memory_mapped_file.h"
|
| #include "base/logging.h"
|
| +#include "base/memory/ptr_util.h"
|
| +#include "base/optional.h"
|
| #include "base/strings/string_number_conversions.h"
|
| #include "media/base/test_data_util.h"
|
| #include "media/filters/h264_parser.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| +#include "ui/gfx/geometry/rect.h"
|
| +#include "ui/gfx/geometry/size.h"
|
|
|
| namespace media {
|
|
|
| +class H264SPSTest : public ::testing::Test {
|
| + public:
|
| + // An exact clone of an SPS from Big Buck Bunny 480p.
|
| + std::unique_ptr<H264SPS> MakeSPS_BBB480p() {
|
| + std::unique_ptr<H264SPS> sps = base::MakeUnique<H264SPS>();
|
| + sps->profile_idc = 100;
|
| + sps->level_idc = 30;
|
| + sps->chroma_format_idc = 1;
|
| + sps->log2_max_pic_order_cnt_lsb_minus4 = 2;
|
| + sps->max_num_ref_frames = 5;
|
| + sps->pic_width_in_mbs_minus1 = 52;
|
| + sps->pic_height_in_map_units_minus1 = 29;
|
| + sps->frame_mbs_only_flag = true;
|
| + sps->direct_8x8_inference_flag = true;
|
| + sps->vui_parameters_present_flag = true;
|
| + sps->timing_info_present_flag = true;
|
| + sps->num_units_in_tick = 1;
|
| + sps->time_scale = 48;
|
| + sps->fixed_frame_rate_flag = true;
|
| + sps->bitstream_restriction_flag = true;
|
| + // These next three fields are not part of our SPS struct yet.
|
| + // sps->motion_vectors_over_pic_boundaries_flag = true;
|
| + // sps->log2_max_mv_length_horizontal = 10;
|
| + // sps->log2_max_mv_length_vertical = 10;
|
| + sps->max_num_reorder_frames = 2;
|
| + sps->max_dec_frame_buffering = 5;
|
| +
|
| + // Computed field, matches |chroma_format_idc| in this case.
|
| + // TODO(sandersd): Extract that computation from the parsing step.
|
| + sps->chroma_array_type = 1;
|
| +
|
| + return sps;
|
| + }
|
| +};
|
| +
|
| +TEST_F(H264SPSTest, GetCodedSize) {
|
| + std::unique_ptr<H264SPS> sps = MakeSPS_BBB480p();
|
| + EXPECT_EQ(gfx::Size(848, 480), sps->GetCodedSize());
|
| +
|
| + // Overflow.
|
| + sps->pic_width_in_mbs_minus1 = std::numeric_limits<int>::max();
|
| + EXPECT_EQ(base::nullopt, sps->GetCodedSize());
|
| +}
|
| +
|
| +TEST_F(H264SPSTest, GetVisibleRect) {
|
| + std::unique_ptr<H264SPS> sps = MakeSPS_BBB480p();
|
| + EXPECT_EQ(gfx::Rect(0, 0, 848, 480), sps->GetVisibleRect());
|
| +
|
| + // Add some cropping.
|
| + sps->frame_cropping_flag = true;
|
| + sps->frame_crop_left_offset = 1;
|
| + sps->frame_crop_right_offset = 2;
|
| + sps->frame_crop_top_offset = 3;
|
| + sps->frame_crop_bottom_offset = 4;
|
| + EXPECT_EQ(gfx::Rect(2, 6, 848 - 6, 480 - 14), sps->GetVisibleRect());
|
| +
|
| + // Not quite invalid.
|
| + sps->frame_crop_left_offset = 422;
|
| + sps->frame_crop_right_offset = 1;
|
| + sps->frame_crop_top_offset = 0;
|
| + sps->frame_crop_bottom_offset = 0;
|
| + EXPECT_EQ(gfx::Rect(844, 0, 2, 480), sps->GetVisibleRect());
|
| +
|
| + // Invalid crop.
|
| + sps->frame_crop_left_offset = 423;
|
| + sps->frame_crop_right_offset = 1;
|
| + sps->frame_crop_top_offset = 0;
|
| + sps->frame_crop_bottom_offset = 0;
|
| + EXPECT_EQ(base::nullopt, sps->GetVisibleRect());
|
| +
|
| + // Overflow.
|
| + sps->frame_crop_left_offset = std::numeric_limits<int>::max() / 2 + 1;
|
| + sps->frame_crop_right_offset = 0;
|
| + sps->frame_crop_top_offset = 0;
|
| + sps->frame_crop_bottom_offset = 0;
|
| + EXPECT_EQ(base::nullopt, sps->GetVisibleRect());
|
| +}
|
| +
|
| TEST(H264ParserTest, StreamFileParsing) {
|
| base::FilePath file_path = GetTestDataFilePath("test-25fps.h264");
|
| // Number of NALUs in the test stream to be parsed.
|
|
|