OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
Ami GONE FROM CHROMIUM
2012/03/21 13:16:24
Not part of this CL?
| |
5 #include "h264_parser.h" | |
6 | |
7 #include "testing/gtest/include/gtest/gtest.h" | |
8 | |
9 #include <sys/types.h> | |
10 #include <sys/stat.h> | |
11 #include <fcntl.h> | |
12 #include <sys/mman.h> | |
13 #include <unistd.h> | |
14 | |
15 #include "base/logging.h" | |
16 #include "base/command_line.h" | |
17 #include "base/file_util.h" | |
18 | |
19 namespace { | |
20 | |
21 class H264ParserTest | |
22 : public testing::TestWithParam<const char *> { | |
23 protected: | |
24 H264ParserTest() {} | |
25 virtual ~H264ParserTest() {} | |
26 | |
27 private: | |
28 DISALLOW_COPY_AND_ASSIGN(H264ParserTest); | |
29 }; | |
30 | |
31 const FilePath::CharType* test_stream_filename; | |
32 | |
33 static uint8* OpenAndMapStream(const char *fn, int *fd, size_t *size) { | |
34 struct stat stat; | |
35 | |
36 *fd = open(fn, O_RDONLY); | |
37 if (!*fd) { | |
38 LOG(FATAL) << "Couldn't open test stream (" << fn << ")"; | |
39 return NULL; | |
40 } | |
41 | |
42 fstat(*fd, &stat); | |
43 | |
44 uint8 *ptr = (uint8*)mmap(NULL, stat.st_size, PROT_READ, MAP_SHARED, *fd, 0); | |
45 if (ptr == MAP_FAILED) { | |
46 LOG(FATAL) << "Couldn't map test stream (" << fn << ")"; | |
47 close(*fd); | |
48 return NULL; | |
49 } | |
50 | |
51 *size = stat.st_size; | |
52 | |
53 return ptr; | |
54 } | |
55 | |
56 void ParseStream(const char *fn) { | |
57 int fd; | |
58 size_t size; | |
59 uint8* ptr; | |
60 H264NALU nalu; | |
61 H264SliceHeader shdr; | |
62 H264SEIMessage sei_msg; | |
63 H264Parser::Result res; | |
64 int id; | |
65 | |
66 ptr = OpenAndMapStream(fn, &fd, &size); | |
67 ASSERT_TRUE(ptr != NULL); | |
68 ASSERT_TRUE(ptr != MAP_FAILED); | |
69 | |
70 H264Parser parser; | |
71 parser.SetStream(ptr, size); | |
72 | |
73 // parse until the end of stream/unsupported stream/error in stream is found | |
74 while (1) { | |
75 res = parser.ParseNextNalu(&nalu); | |
76 ASSERT_TRUE(res == H264Parser::kOk || res == H264Parser::kEOStream); | |
77 if (res == H264Parser::kEOStream) | |
78 return; | |
79 | |
80 switch (nalu.nal_unit_type) { | |
81 case kH264NaluIDRSlice: | |
82 case kH264NaluNonIDRSlice: | |
83 res = parser.ParseSliceHeader(&shdr, &nalu); | |
84 ASSERT_TRUE(res == H264Parser::kOk); | |
85 break; | |
86 | |
87 case kH264NaluSPS: | |
88 res = parser.ParseSPS(&id); | |
89 ASSERT_TRUE(res == H264Parser::kOk); | |
90 break; | |
91 | |
92 case kH264NaluPPS: | |
93 res = parser.ParsePPS(&id); | |
94 ASSERT_TRUE(res == H264Parser::kOk); | |
95 break; | |
96 | |
97 case kH264SEIMessage: | |
98 res = parser.ParseSEI(&sei_msg); | |
99 ASSERT_TRUE(res == H264Parser::kOk); | |
100 break; | |
101 | |
102 default: | |
103 // skip unsupported NALU | |
104 DVLOG(4) << "Skipping unsupported NALU"; | |
105 break; | |
106 } | |
107 } | |
108 } | |
109 | |
110 TEST_F(H264ParserTest, StreamFileParsing) { | |
111 ParseStream(test_stream_filename); | |
112 } | |
113 | |
114 } // namespace | |
115 | |
116 int main(int argc, char **argv) { | |
117 ::testing::InitGoogleTest(&argc, argv); | |
118 CommandLine::Init(argc, argv); | |
119 | |
120 CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | |
121 CHECK(cmd_line); | |
122 | |
123 CommandLine::SwitchMap switches = cmd_line->GetSwitches(); | |
124 for (CommandLine::SwitchMap::const_iterator it = switches.begin(); | |
125 it != switches.end(); ++it) { | |
126 if (it->first == "test_stream") { | |
127 test_stream_filename = it->second.c_str(); | |
128 continue; | |
129 } | |
130 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; | |
131 } | |
132 | |
133 return RUN_ALL_TESTS(); | |
134 return 0; | |
135 } | |
136 | |
OLD | NEW |