Migrate away from the PrefMetricsService-based device ID in PrefHashCalculator.
[chromium-blink-merge.git] / media / filters / h264_parser_unittest.cc
bloba08cf26a15696b30a84c1527414c205d1bb71c86
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"
14 namespace media {
16 TEST(H264ParserTest, StreamFileParsing) {
17 base::FilePath file_path = GetTestDataFilePath("test-25fps.h264");
18 // Number of NALUs in the test stream to be parsed.
19 int num_nalus = 759;
21 base::MemoryMappedFile stream;
22 ASSERT_TRUE(stream.Initialize(file_path))
23 << "Couldn't open stream file: " << file_path.MaybeAsASCII();
25 H264Parser parser;
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;
30 while (true) {
31 media::H264SliceHeader shdr;
32 media::H264SEIMessage sei_msg;
33 H264NALU nalu;
34 H264Parser::Result res = parser.AdvanceToNextNALU(&nalu);
35 if (res == H264Parser::kEOStream) {
36 DVLOG(1) << "Number of successfully parsed NALUs before EOS: "
37 << num_parsed_nalus;
38 ASSERT_EQ(num_nalus, num_parsed_nalus);
39 return;
41 ASSERT_EQ(res, H264Parser::kOk);
43 ++num_parsed_nalus;
45 int id;
46 switch (nalu.nal_unit_type) {
47 case H264NALU::kIDRSlice:
48 case H264NALU::kNonIDRSlice:
49 ASSERT_EQ(parser.ParseSliceHeader(nalu, &shdr), H264Parser::kOk);
50 break;
52 case H264NALU::kSPS:
53 ASSERT_EQ(parser.ParseSPS(&id), H264Parser::kOk);
54 break;
56 case H264NALU::kPPS:
57 ASSERT_EQ(parser.ParsePPS(&id), H264Parser::kOk);
58 break;
60 case H264NALU::kSEIMessage:
61 ASSERT_EQ(parser.ParseSEI(&sei_msg), H264Parser::kOk);
62 break;
64 default:
65 // Skip unsupported NALU.
66 DVLOG(4) << "Skipping unsupported NALU";
67 break;
72 } // namespace media