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/path_service.h"
9 #include "base/strings/string_number_conversions.h"
10 #include "media/base/test_data_util.h"
11 #include "media/filters/h264_parser.h"
12 #include "testing/gtest/include/gtest/gtest.h"
16 TEST(H264ParserTest
, StreamFileParsing
) {
17 base::FilePath file_path
= GetTestDataFilePath("test-25fps.h264");
18 // Number of NALUs in the test stream to be parsed.
21 base::MemoryMappedFile stream
;
22 ASSERT_TRUE(stream
.Initialize(file_path
))
23 << "Couldn't open stream file: " << file_path
.MaybeAsASCII();
26 parser
.SetStream(stream
.data(), stream
.length());
28 // Parse until the end of stream/unsupported stream/error in stream is found.
29 int num_parsed_nalus
= 0;
31 media::H264SliceHeader shdr
;
32 media::H264SEIMessage sei_msg
;
34 H264Parser::Result res
= parser
.AdvanceToNextNALU(&nalu
);
35 if (res
== H264Parser::kEOStream
) {
36 DVLOG(1) << "Number of successfully parsed NALUs before EOS: "
38 ASSERT_EQ(num_nalus
, num_parsed_nalus
);
41 ASSERT_EQ(res
, H264Parser::kOk
);
46 switch (nalu
.nal_unit_type
) {
47 case H264NALU::kIDRSlice
:
48 case H264NALU::kNonIDRSlice
:
49 ASSERT_EQ(parser
.ParseSliceHeader(nalu
, &shdr
), H264Parser::kOk
);
53 ASSERT_EQ(parser
.ParseSPS(&id
), H264Parser::kOk
);
57 ASSERT_EQ(parser
.ParsePPS(&id
), H264Parser::kOk
);
60 case H264NALU::kSEIMessage
:
61 ASSERT_EQ(parser
.ParseSEI(&sei_msg
), H264Parser::kOk
);
65 // Skip unsupported NALU.
66 DVLOG(4) << "Skipping unsupported NALU";