mkvmuxer_tests: Actually test cue points in the cue point test.
Instead of blindly doing a file compare and hoping that we're not in a garbage in garbage out situation. Change-Id: Ie2f278e09ad67b3e8f40e602fcdd5c9ffb5e1b7d
This commit is contained in:
parent
93e9fb35f9
commit
cf1620444f
@ -478,6 +478,12 @@ TEST_F(MuxerTest, CuesBeforeClusters) {
|
||||
|
||||
EXPECT_TRUE(CompareFiles(GetTestFilePath("cues_before_clusters.webm"),
|
||||
cues_filename));
|
||||
MkvParser parser;
|
||||
ASSERT_TRUE(ParseMkvFileReleaseParser(cues_filename, &parser));
|
||||
int64_t cues_offset = 0;
|
||||
ASSERT_TRUE(HasCuePoints(parser.segment, &cues_offset));
|
||||
ASSERT_GT(cues_offset, 0);
|
||||
ASSERT_TRUE(ValidateCues(parser.segment, parser.reader));
|
||||
}
|
||||
|
||||
TEST_F(MuxerTest, MaxClusterSize) {
|
||||
@ -794,13 +800,12 @@ TEST_F(MuxerTest, Colour) {
|
||||
ASSERT_TRUE(video_track->SetColour(muxer_colour));
|
||||
ASSERT_NO_FATAL_FAILURE(AddDummyFrameAndFinalize(kVideoTrackNumber));
|
||||
|
||||
mkvparser::Segment* segment = nullptr;
|
||||
ASSERT_TRUE(ParseMkvFileReleaseSegment(filename_, &segment));
|
||||
std::unique_ptr<mkvparser::Segment> segment_ptr(segment);
|
||||
MkvParser parser;
|
||||
ASSERT_TRUE(ParseMkvFileReleaseParser(filename_, &parser));
|
||||
|
||||
const mkvparser::VideoTrack* const parser_track =
|
||||
static_cast<const mkvparser::VideoTrack*>(
|
||||
segment_ptr->GetTracks()->GetTrackByIndex(0));
|
||||
parser.segment->GetTracks()->GetTrackByIndex(0));
|
||||
const mkvparser::Colour* parser_colour = parser_track->GetColour();
|
||||
ASSERT_TRUE(parser_colour != nullptr);
|
||||
EXPECT_EQ(static_cast<long long>(muxer_colour.matrix_coefficients()),
|
||||
@ -865,13 +870,12 @@ TEST_F(MuxerTest, Projection) {
|
||||
ASSERT_TRUE(video_track->SetProjection(muxer_proj));
|
||||
ASSERT_NO_FATAL_FAILURE(AddDummyFrameAndFinalize(kVideoTrackNumber));
|
||||
|
||||
mkvparser::Segment* segment = nullptr;
|
||||
ASSERT_TRUE(ParseMkvFileReleaseSegment(filename_, &segment));
|
||||
std::unique_ptr<mkvparser::Segment> segment_ptr(segment);
|
||||
MkvParser parser;
|
||||
ASSERT_TRUE(ParseMkvFileReleaseParser(filename_, &parser));
|
||||
|
||||
const mkvparser::VideoTrack* const parser_track =
|
||||
static_cast<const mkvparser::VideoTrack*>(
|
||||
segment_ptr->GetTracks()->GetTrackByIndex(0));
|
||||
parser.segment->GetTracks()->GetTrackByIndex(0));
|
||||
|
||||
const mkvparser::Projection* const parser_proj =
|
||||
parser_track->GetProjection();
|
||||
|
@ -78,10 +78,11 @@ bool HasCuePoints(const mkvparser::Segment* segment,
|
||||
}
|
||||
}
|
||||
|
||||
if (offset == -1) {
|
||||
if (offset <= 0) {
|
||||
// No Cues found.
|
||||
return false;
|
||||
}
|
||||
|
||||
*cues_offset = offset;
|
||||
return true;
|
||||
}
|
||||
@ -143,10 +144,16 @@ bool ValidateCues(mkvparser::Segment* segment, mkvparser::IMkvReader* reader) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ParseMkvFileReleaseSegment(const std::string& webm_file,
|
||||
mkvparser::Segment** segment_out) {
|
||||
mkvparser::MkvReader reader;
|
||||
if (reader.Open(webm_file.c_str()) < 0) {
|
||||
MkvParser::~MkvParser() {
|
||||
delete segment;
|
||||
delete reader;
|
||||
}
|
||||
|
||||
bool ParseMkvFileReleaseParser(const std::string& webm_file,
|
||||
MkvParser* parser_out) {
|
||||
parser_out->reader = new (std::nothrow) mkvparser::MkvReader;
|
||||
mkvparser::MkvReader& reader = *parser_out->reader;
|
||||
if (!parser_out->reader || reader.Open(webm_file.c_str()) < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -192,14 +199,15 @@ bool ParseMkvFileReleaseSegment(const std::string& webm_file,
|
||||
cluster = segment->GetNext(cluster);
|
||||
}
|
||||
|
||||
*segment_out = segment.release();
|
||||
parser_out->segment = segment.release();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ParseMkvFile(const std::string& webm_file) {
|
||||
mkvparser::Segment* segment = nullptr;
|
||||
const bool result = ParseMkvFileReleaseSegment(webm_file, &segment);
|
||||
delete segment;
|
||||
MkvParser parser;
|
||||
const bool result = ParseMkvFileReleaseParser(webm_file, &parser);
|
||||
delete parser.segment;
|
||||
delete parser.reader;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,7 @@
|
||||
|
||||
namespace mkvparser {
|
||||
class IMkvReader;
|
||||
class MkvReader;
|
||||
class Segment;
|
||||
}
|
||||
|
||||
@ -57,6 +58,10 @@ std::string GetTestFilePath(const std::string& name);
|
||||
// files match exactly, false otherwise.
|
||||
bool CompareFiles(const std::string& file1, const std::string& file2);
|
||||
|
||||
// Returns true and sets |cues_offset| to the cues location within the MKV file
|
||||
// parsed by |segment| when the MKV file has cue points.
|
||||
bool HasCuePoints(const mkvparser::Segment* segment, std::int64_t* cues_offset);
|
||||
|
||||
// Validates cue points. Assumes caller has already called Load() on |segment|.
|
||||
// Returns true when:
|
||||
// All cue points point at clusters, OR
|
||||
@ -66,10 +71,17 @@ bool ValidateCues(mkvparser::Segment* segment, mkvparser::IMkvReader* reader);
|
||||
// Parses |webm_file| using mkvparser and returns true when file parses
|
||||
// successfully (all clusters and blocks can be successfully walked). Second
|
||||
// variant allows further interaction with the parsed file via transferring
|
||||
// ownership of the mkvparser Segment to the caller.
|
||||
// ownership of the mkvparser Segment and MkvReader to the caller via
|
||||
// |parser_out|.
|
||||
struct MkvParser {
|
||||
MkvParser() = default;
|
||||
~MkvParser();
|
||||
mkvparser::Segment* segment = nullptr;
|
||||
mkvparser::MkvReader* reader = nullptr;
|
||||
};
|
||||
bool ParseMkvFile(const std::string& webm_file);
|
||||
bool ParseMkvFileReleaseSegment(const std::string& webm_file,
|
||||
mkvparser::Segment** segment_out);
|
||||
bool ParseMkvFileReleaseParser(const std::string& webm_file,
|
||||
MkvParser* parser_out);
|
||||
|
||||
} // namespace test
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user