1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51

media / parsers / vp8_parser_unittest.cc [blame]

// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "media/parsers/vp8_parser.h"

#include <stddef.h>
#include <stdint.h>

#include "base/files/memory_mapped_file.h"
#include "base/logging.h"
#include "media/base/test_data_util.h"
#include "media/parsers/ivf_parser.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace media {

TEST(Vp8ParserTest, StreamFileParsing) {
  base::FilePath file_path = GetTestDataFilePath("test-25fps.vp8");
  base::MemoryMappedFile stream;
  ASSERT_TRUE(stream.Initialize(file_path))
      << "Couldn't open stream file: " << file_path.MaybeAsASCII();

  IvfParser ivf_parser;
  IvfFileHeader ivf_file_header = {};
  ASSERT_TRUE(
      ivf_parser.Initialize(stream.data(), stream.length(), &ivf_file_header));
  ASSERT_EQ(ivf_file_header.fourcc, 0x30385056u);  // VP80

  Vp8Parser vp8_parser;
  IvfFrameHeader ivf_frame_header = {};
  size_t num_parsed_frames = 0;

  // Parse until the end of stream/unsupported stream/error in stream is found.
  const uint8_t* payload = nullptr;
  while (ivf_parser.ParseNextFrame(&ivf_frame_header, &payload)) {
    Vp8FrameHeader fhdr;

    ASSERT_TRUE(
        vp8_parser.ParseFrame(payload, ivf_frame_header.frame_size, &fhdr));

    ++num_parsed_frames;
  }

  DVLOG(1) << "Number of successfully parsed frames before EOS: "
           << num_parsed_frames;

  EXPECT_EQ(ivf_file_header.num_frames, num_parsed_frames);
}

}  // namespace media