Index: content/common/gpu/media/h264_parser_unittest.cc |
diff --git a/content/common/gpu/media/h264_parser_unittest.cc b/content/common/gpu/media/h264_parser_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..5f6ab63e0bd393c9e355cd2e6e75fe0bf773e4ee |
--- /dev/null |
+++ b/content/common/gpu/media/h264_parser_unittest.cc |
@@ -0,0 +1,136 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
Ami GONE FROM CHROMIUM
2012/03/21 13:16:24
Not part of this CL?
|
+#include "h264_parser.h" |
+ |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+#include <sys/types.h> |
+#include <sys/stat.h> |
+#include <fcntl.h> |
+#include <sys/mman.h> |
+#include <unistd.h> |
+ |
+#include "base/logging.h" |
+#include "base/command_line.h" |
+#include "base/file_util.h" |
+ |
+namespace { |
+ |
+class H264ParserTest |
+ : public testing::TestWithParam<const char *> { |
+ protected: |
+ H264ParserTest() {} |
+ virtual ~H264ParserTest() {} |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(H264ParserTest); |
+}; |
+ |
+const FilePath::CharType* test_stream_filename; |
+ |
+static uint8* OpenAndMapStream(const char *fn, int *fd, size_t *size) { |
+ struct stat stat; |
+ |
+ *fd = open(fn, O_RDONLY); |
+ if (!*fd) { |
+ LOG(FATAL) << "Couldn't open test stream (" << fn << ")"; |
+ return NULL; |
+ } |
+ |
+ fstat(*fd, &stat); |
+ |
+ uint8 *ptr = (uint8*)mmap(NULL, stat.st_size, PROT_READ, MAP_SHARED, *fd, 0); |
+ if (ptr == MAP_FAILED) { |
+ LOG(FATAL) << "Couldn't map test stream (" << fn << ")"; |
+ close(*fd); |
+ return NULL; |
+ } |
+ |
+ *size = stat.st_size; |
+ |
+ return ptr; |
+} |
+ |
+void ParseStream(const char *fn) { |
+ int fd; |
+ size_t size; |
+ uint8* ptr; |
+ H264NALU nalu; |
+ H264SliceHeader shdr; |
+ H264SEIMessage sei_msg; |
+ H264Parser::Result res; |
+ int id; |
+ |
+ ptr = OpenAndMapStream(fn, &fd, &size); |
+ ASSERT_TRUE(ptr != NULL); |
+ ASSERT_TRUE(ptr != MAP_FAILED); |
+ |
+ H264Parser parser; |
+ parser.SetStream(ptr, size); |
+ |
+ // parse until the end of stream/unsupported stream/error in stream is found |
+ while (1) { |
+ res = parser.ParseNextNalu(&nalu); |
+ ASSERT_TRUE(res == H264Parser::kOk || res == H264Parser::kEOStream); |
+ if (res == H264Parser::kEOStream) |
+ return; |
+ |
+ switch (nalu.nal_unit_type) { |
+ case kH264NaluIDRSlice: |
+ case kH264NaluNonIDRSlice: |
+ res = parser.ParseSliceHeader(&shdr, &nalu); |
+ ASSERT_TRUE(res == H264Parser::kOk); |
+ break; |
+ |
+ case kH264NaluSPS: |
+ res = parser.ParseSPS(&id); |
+ ASSERT_TRUE(res == H264Parser::kOk); |
+ break; |
+ |
+ case kH264NaluPPS: |
+ res = parser.ParsePPS(&id); |
+ ASSERT_TRUE(res == H264Parser::kOk); |
+ break; |
+ |
+ case kH264SEIMessage: |
+ res = parser.ParseSEI(&sei_msg); |
+ ASSERT_TRUE(res == H264Parser::kOk); |
+ break; |
+ |
+ default: |
+ // skip unsupported NALU |
+ DVLOG(4) << "Skipping unsupported NALU"; |
+ break; |
+ } |
+ } |
+} |
+ |
+TEST_F(H264ParserTest, StreamFileParsing) { |
+ ParseStream(test_stream_filename); |
+} |
+ |
+} // namespace |
+ |
+int main(int argc, char **argv) { |
+ ::testing::InitGoogleTest(&argc, argv); |
+ CommandLine::Init(argc, argv); |
+ |
+ CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
+ CHECK(cmd_line); |
+ |
+ CommandLine::SwitchMap switches = cmd_line->GetSwitches(); |
+ for (CommandLine::SwitchMap::const_iterator it = switches.begin(); |
+ it != switches.end(); ++it) { |
+ if (it->first == "test_stream") { |
+ test_stream_filename = it->second.c_str(); |
+ continue; |
+ } |
+ LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; |
+ } |
+ |
+ return RUN_ALL_TESTS(); |
+ return 0; |
+} |
+ |