webm/common/vp9_header_parser_tests.cc
Tom Finegan 9828e39874 mkvmuxer: Set default doc type version to 4.
mkvmuxer can write matroska v4 elements in all modes, but does
not always confirm that the doc type is high enough for all
elements written. The main culprits are Colour and its
children. Avoid problems by using 4 as the default version.
This avoids problems in all cases but those where users who
know what they are doing have written the EBML header manually.

Update the test files because the new default causes the file
compare abuse in the muxer tests to fail.

Update expected doc type version in the parsing tests.

BUG=webm:1201

Change-Id: I4c69000af4c1d5efe66315c17f3953344ef04993
2016-08-11 14:20:53 -07:00

145 lines
4.5 KiB
C++

// Copyright (c) 2016 The WebM project authors. All Rights Reserved.
//
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file in the root of the source
// tree. An additional intellectual property rights grant can be found
// in the file PATENTS. All contributing project authors may
// be found in the AUTHORS file in the root of the source tree.
#include "common/vp9_header_parser.h"
#include <string>
#include "gtest/gtest.h"
#include "common/hdr_util.h"
#include "mkvparser/mkvparser.h"
#include "mkvparser/mkvreader.h"
#include "testing/test_util.h"
namespace {
class Vp9HeaderParserTests : public ::testing::Test {
public:
Vp9HeaderParserTests() : is_reader_open_(false), segment_(NULL) {}
~Vp9HeaderParserTests() override {
CloseReader();
if (segment_ != NULL) {
delete segment_;
segment_ = NULL;
}
}
void CloseReader() {
if (is_reader_open_) {
reader_.Close();
}
is_reader_open_ = false;
}
void CreateAndLoadSegment(const std::string& filename,
int expected_doc_type_ver) {
filename_ = test::GetTestFilePath(filename);
ASSERT_EQ(0, reader_.Open(filename_.c_str()));
is_reader_open_ = true;
pos_ = 0;
mkvparser::EBMLHeader ebml_header;
ebml_header.Parse(&reader_, pos_);
ASSERT_EQ(1, ebml_header.m_version);
ASSERT_EQ(1, ebml_header.m_readVersion);
ASSERT_STREQ("webm", ebml_header.m_docType);
ASSERT_EQ(expected_doc_type_ver, ebml_header.m_docTypeVersion);
ASSERT_EQ(2, ebml_header.m_docTypeReadVersion);
ASSERT_EQ(0, mkvparser::Segment::CreateInstance(&reader_, pos_, segment_));
ASSERT_FALSE(HasFailure());
ASSERT_GE(0, segment_->Load());
}
void CreateAndLoadSegment(const std::string& filename) {
CreateAndLoadSegment(filename, 4);
}
void ProcessTheFrames() {
unsigned char* data = NULL;
size_t data_len = 0;
const mkvparser::Tracks* const parser_tracks = segment_->GetTracks();
ASSERT_TRUE(parser_tracks != NULL);
const mkvparser::Cluster* cluster = segment_->GetFirst();
ASSERT_TRUE(cluster != NULL);
while ((cluster != NULL) && !cluster->EOS()) {
const mkvparser::BlockEntry* block_entry;
long status = cluster->GetFirst(block_entry); // NOLINT
ASSERT_EQ(0, status);
while ((block_entry != NULL) && !block_entry->EOS()) {
const mkvparser::Block* const block = block_entry->GetBlock();
ASSERT_TRUE(block != NULL);
const long long trackNum = block->GetTrackNumber(); // NOLINT
const mkvparser::Track* const parser_track =
parser_tracks->GetTrackByNumber(
static_cast<unsigned long>(trackNum)); // NOLINT
ASSERT_TRUE(parser_track != NULL);
const long long track_type = parser_track->GetType(); // NOLINT
if (track_type == mkvparser::Track::kVideo) {
const int frame_count = block->GetFrameCount();
for (int i = 0; i < frame_count; ++i) {
const mkvparser::Block::Frame& frame = block->GetFrame(i);
if (static_cast<size_t>(frame.len) > data_len) {
delete[] data;
data = new unsigned char[frame.len];
ASSERT_TRUE(data != NULL);
data_len = static_cast<size_t>(frame.len);
}
ASSERT_FALSE(frame.Read(&reader_, data));
parser_.SetFrame(data, data_len);
parser_.ParseUncompressedHeader();
}
}
status = cluster->GetNext(block_entry, block_entry);
ASSERT_EQ(0, status);
}
cluster = segment_->GetNext(cluster);
}
delete[] data;
}
protected:
mkvparser::MkvReader reader_;
bool is_reader_open_;
mkvparser::Segment* segment_;
std::string filename_;
long long pos_; // NOLINT
vp9_parser::Vp9HeaderParser parser_;
};
TEST_F(Vp9HeaderParserTests, VideoOnlyFile) {
CreateAndLoadSegment("test_stereo_left_right.webm");
ProcessTheFrames();
EXPECT_EQ(256, parser_.width());
EXPECT_EQ(144, parser_.height());
EXPECT_EQ(1, parser_.column_tiles());
EXPECT_EQ(0, parser_.frame_parallel_mode());
}
TEST_F(Vp9HeaderParserTests, Muxed) {
CreateAndLoadSegment("bbb_480p_vp9_opus_1second.webm", 4);
ProcessTheFrames();
EXPECT_EQ(854, parser_.width());
EXPECT_EQ(480, parser_.height());
EXPECT_EQ(2, parser_.column_tiles());
EXPECT_EQ(1, parser_.frame_parallel_mode());
}
} // namespace
int main(int argc, char* argv[]) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}