Home | History | Annotate | Download | only in filters
      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.
      4 
      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"
     13 
     14 namespace media {
     15 
     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;
     20 
     21   base::MemoryMappedFile stream;
     22   ASSERT_TRUE(stream.Initialize(file_path))
     23       << "Couldn't open stream file: " << file_path.MaybeAsASCII();
     24 
     25   H264Parser parser;
     26   parser.SetStream(stream.data(), stream.length());
     27 
     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;
     40     }
     41     ASSERT_EQ(res, H264Parser::kOk);
     42 
     43     ++num_parsed_nalus;
     44 
     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;
     51 
     52       case H264NALU::kSPS:
     53         ASSERT_EQ(parser.ParseSPS(&id), H264Parser::kOk);
     54         break;
     55 
     56       case H264NALU::kPPS:
     57         ASSERT_EQ(parser.ParsePPS(&id), H264Parser::kOk);
     58         break;
     59 
     60       case H264NALU::kSEIMessage:
     61         ASSERT_EQ(parser.ParseSEI(&sei_msg), H264Parser::kOk);
     62         break;
     63 
     64       default:
     65         // Skip unsupported NALU.
     66         DVLOG(4) << "Skipping unsupported NALU";
     67         break;
     68     }
     69   }
     70 }
     71 
     72 }  // namespace media
     73