hunspell: Cleanup to fix the header include guards under google/ directory.
[chromium-blink-merge.git] / media / filters / h264_parser_unittest.cc
blob1874666c3c2709bf670104fb1e2310cae5004b6a
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"
13 namespace media {
15 TEST(H264ParserTest, StreamFileParsing) {
16 base::FilePath file_path = GetTestDataFilePath("test-25fps.h264");
17 // Number of NALUs in the test stream to be parsed.
18 int num_nalus = 759;
20 base::MemoryMappedFile stream;
21 ASSERT_TRUE(stream.Initialize(file_path))
22 << "Couldn't open stream file: " << file_path.MaybeAsASCII();
24 H264Parser parser;
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;
29 while (true) {
30 media::H264SliceHeader shdr;
31 media::H264SEIMessage sei_msg;
32 H264NALU nalu;
33 H264Parser::Result res = parser.AdvanceToNextNALU(&nalu);
34 if (res == H264Parser::kEOStream) {
35 DVLOG(1) << "Number of successfully parsed NALUs before EOS: "
36 << num_parsed_nalus;
37 ASSERT_EQ(num_nalus, num_parsed_nalus);
38 return;
40 ASSERT_EQ(res, H264Parser::kOk);
42 ++num_parsed_nalus;
44 int id;
45 switch (nalu.nal_unit_type) {
46 case H264NALU::kIDRSlice:
47 case H264NALU::kNonIDRSlice:
48 ASSERT_EQ(parser.ParseSliceHeader(nalu, &shdr), H264Parser::kOk);
49 break;
51 case H264NALU::kSPS:
52 ASSERT_EQ(parser.ParseSPS(&id), H264Parser::kOk);
53 break;
55 case H264NALU::kPPS:
56 ASSERT_EQ(parser.ParsePPS(&id), H264Parser::kOk);
57 break;
59 case H264NALU::kSEIMessage:
60 ASSERT_EQ(parser.ParseSEI(&sei_msg), H264Parser::kOk);
61 break;
63 default:
64 // Skip unsupported NALU.
65 DVLOG(4) << "Skipping unsupported NALU";
66 break;
71 } // namespace media