| // Copyright 2014 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #include "base/command_line.h" |
| #include "base/files/memory_mapped_file.h" |
| #include "base/logging.h" |
| #include "base/path_service.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" |
| |
| namespace media { |
| |
| TEST(H264ParserTest, StreamFileParsing) { |
| base::FilePath file_path = GetTestDataFilePath("test-25fps.h264"); |
| // Number of NALUs in the test stream to be parsed. |
| int num_nalus = 759; |
| |
| base::MemoryMappedFile stream; |
| ASSERT_TRUE(stream.Initialize(file_path)) |
| << "Couldn't open stream file: " << file_path.MaybeAsASCII(); |
| |
| H264Parser parser; |
| parser.SetStream(stream.data(), stream.length()); |
| |
| // Parse until the end of stream/unsupported stream/error in stream is found. |
| int num_parsed_nalus = 0; |
| while (true) { |
| media::H264SliceHeader shdr; |
| media::H264SEIMessage sei_msg; |
| H264NALU nalu; |
| H264Parser::Result res = parser.AdvanceToNextNALU(&nalu); |
| if (res == H264Parser::kEOStream) { |
| DVLOG(1) << "Number of successfully parsed NALUs before EOS: " |
| << num_parsed_nalus; |
| ASSERT_EQ(num_nalus, num_parsed_nalus); |
| return; |
| } |
| ASSERT_EQ(res, H264Parser::kOk); |
| |
| ++num_parsed_nalus; |
| |
| int id; |
| switch (nalu.nal_unit_type) { |
| case H264NALU::kIDRSlice: |
| case H264NALU::kNonIDRSlice: |
| ASSERT_EQ(parser.ParseSliceHeader(nalu, &shdr), H264Parser::kOk); |
| break; |
| |
| case H264NALU::kSPS: |
| ASSERT_EQ(parser.ParseSPS(&id), H264Parser::kOk); |
| break; |
| |
| case H264NALU::kPPS: |
| ASSERT_EQ(parser.ParsePPS(&id), H264Parser::kOk); |
| break; |
| |
| case H264NALU::kSEIMessage: |
| ASSERT_EQ(parser.ParseSEI(&sei_msg), H264Parser::kOk); |
| break; |
| |
| default: |
| // Skip unsupported NALU. |
| DVLOG(4) << "Skipping unsupported NALU"; |
| break; |
| } |
| } |
| } |
| |
| } // namespace media |