OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "testing/gtest/include/gtest/gtest.h" | |
6 | |
7 #include "base/command_line.h" | 5 #include "base/command_line.h" |
8 #include "base/files/memory_mapped_file.h" | 6 #include "base/files/memory_mapped_file.h" |
9 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/path_service.h" | |
10 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
11 #include "content/common/gpu/media/h264_parser.h" | 10 #include "media/base/test_data_util.h" |
11 #include "media/filters/h264_parser.h" | |
12 #include "testing/gtest/include/gtest/gtest.h" | |
12 | 13 |
13 using content::H264Parser; | 14 using media::H264Parser; |
scherkus (not reviewing)
2014/01/06 20:10:12
ditto
Pawel Osciak
2014/01/08 07:30:34
Done.
| |
14 using content::H264NALU; | 15 using media::H264NALU; |
15 | 16 |
16 const base::FilePath::CharType* test_stream_filename = | 17 const base::FilePath::CharType* test_stream_filename = |
17 FILE_PATH_LITERAL("content/common/gpu/testdata/test-25fps.h264"); | 18 FILE_PATH_LITERAL("content/common/gpu/testdata/test-25fps.h264"); |
18 // Number of NALUs in the stream to be parsed. | 19 // Number of NALUs in the stream to be parsed. |
19 int num_nalus = 759; | 20 int num_nalus = 759; |
20 | 21 |
21 TEST(H264ParserTest, StreamFileParsing) { | 22 TEST(H264ParserTest, StreamFileParsing) { |
22 base::FilePath fp(test_stream_filename); | 23 base::FilePath file_path; |
24 CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &file_path)); | |
25 | |
26 file_path = file_path.Append(test_stream_filename); | |
23 base::MemoryMappedFile stream; | 27 base::MemoryMappedFile stream; |
24 CHECK(stream.Initialize(fp)) << "Couldn't open stream file: " | 28 ASSERT_TRUE(stream.Initialize(file_path)) |
25 << test_stream_filename; | 29 << "Couldn't open stream file: " << file_path.MaybeAsASCII(); |
26 DVLOG(1) << "Parsing file: " << test_stream_filename; | 30 DVLOG(1) << "Parsing file: " << test_stream_filename; |
27 | 31 |
28 H264Parser parser; | 32 H264Parser parser; |
29 parser.SetStream(stream.data(), stream.length()); | 33 parser.SetStream(stream.data(), stream.length()); |
30 | 34 |
31 // Parse until the end of stream/unsupported stream/error in stream is found. | 35 // Parse until the end of stream/unsupported stream/error in stream is found. |
32 int num_parsed_nalus = 0; | 36 int num_parsed_nalus = 0; |
33 while (true) { | 37 while (true) { |
34 content::H264SliceHeader shdr; | 38 media::H264SliceHeader shdr; |
35 content::H264SEIMessage sei_msg; | 39 media::H264SEIMessage sei_msg; |
36 H264NALU nalu; | 40 H264NALU nalu; |
37 H264Parser::Result res = parser.AdvanceToNextNALU(&nalu); | 41 H264Parser::Result res = parser.AdvanceToNextNALU(&nalu); |
38 if (res == H264Parser::kEOStream) { | 42 if (res == H264Parser::kEOStream) { |
39 DVLOG(1) << "Number of successfully parsed NALUs before EOS: " | 43 DVLOG(1) << "Number of successfully parsed NALUs before EOS: " |
40 << num_parsed_nalus; | 44 << num_parsed_nalus; |
41 ASSERT_EQ(num_nalus, num_parsed_nalus); | 45 ASSERT_EQ(num_nalus, num_parsed_nalus); |
42 return; | 46 return; |
43 } | 47 } |
44 ASSERT_EQ(res, H264Parser::kOk); | 48 ASSERT_EQ(res, H264Parser::kOk); |
45 | 49 |
(...skipping 18 matching lines...) Expand all Loading... | |
64 ASSERT_EQ(parser.ParseSEI(&sei_msg), H264Parser::kOk); | 68 ASSERT_EQ(parser.ParseSEI(&sei_msg), H264Parser::kOk); |
65 break; | 69 break; |
66 | 70 |
67 default: | 71 default: |
68 // Skip unsupported NALU. | 72 // Skip unsupported NALU. |
69 DVLOG(4) << "Skipping unsupported NALU"; | 73 DVLOG(4) << "Skipping unsupported NALU"; |
70 break; | 74 break; |
71 } | 75 } |
72 } | 76 } |
73 } | 77 } |
74 | |
75 int main(int argc, char **argv) { | |
76 ::testing::InitGoogleTest(&argc, argv); | |
77 CommandLine::Init(argc, argv); | |
78 | |
79 const CommandLine::SwitchMap& switches = | |
80 CommandLine::ForCurrentProcess()->GetSwitches(); | |
81 for (CommandLine::SwitchMap::const_iterator it = switches.begin(); | |
82 it != switches.end(); ++it) { | |
83 if (it->first == "test_stream") { | |
84 test_stream_filename = it->second.c_str(); | |
85 } else if (it->first == "num_nalus") { | |
86 CHECK(base::StringToInt(it->second, &num_nalus)); | |
87 } else { | |
88 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; | |
89 } | |
90 } | |
91 | |
92 return RUN_ALL_TESTS(); | |
93 } | |
OLD | NEW |