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
3 // found in the LICENSE file.
5 #include "base/command_line.h"
6 #include "base/files/memory_mapped_file.h"
7 #include "base/logging.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "media/base/test_data_util.h"
10 #include "media/filters/h264_parser.h"
11 #include "testing/gtest/include/gtest/gtest.h"
15 TEST(H264ParserTest
, StreamFileParsing
) {
16 base::FilePath file_path
= GetTestDataFilePath("test-25fps.h264");
17 // Number of NALUs in the test stream to be parsed.
20 base::MemoryMappedFile stream
;
21 ASSERT_TRUE(stream
.Initialize(file_path
))
22 << "Couldn't open stream file: " << file_path
.MaybeAsASCII();
25 parser
.SetStream(stream
.data(), stream
.length());
27 // Parse until the end of stream/unsupported stream/error in stream is found.
28 int num_parsed_nalus
= 0;
30 media::H264SliceHeader shdr
;
31 media::H264SEIMessage sei_msg
;
33 H264Parser::Result res
= parser
.AdvanceToNextNALU(&nalu
);
34 if (res
== H264Parser::kEOStream
) {
35 DVLOG(1) << "Number of successfully parsed NALUs before EOS: "
37 ASSERT_EQ(num_nalus
, num_parsed_nalus
);
40 ASSERT_EQ(res
, H264Parser::kOk
);
45 switch (nalu
.nal_unit_type
) {
46 case H264NALU::kIDRSlice
:
47 case H264NALU::kNonIDRSlice
:
48 ASSERT_EQ(parser
.ParseSliceHeader(nalu
, &shdr
), H264Parser::kOk
);
52 ASSERT_EQ(parser
.ParseSPS(&id
), H264Parser::kOk
);
56 ASSERT_EQ(parser
.ParsePPS(&id
), H264Parser::kOk
);
59 case H264NALU::kSEIMessage
:
60 ASSERT_EQ(parser
.ParseSEI(&sei_msg
), H264Parser::kOk
);
64 // Skip unsupported NALU.
65 DVLOG(4) << "Skipping unsupported NALU";