1*103e46e4SHarish Mahendrakar // Copyright (c) 2016 The WebM project authors. All Rights Reserved. 2*103e46e4SHarish Mahendrakar // 3*103e46e4SHarish Mahendrakar // Use of this source code is governed by a BSD-style license 4*103e46e4SHarish Mahendrakar // that can be found in the LICENSE file in the root of the source 5*103e46e4SHarish Mahendrakar // tree. An additional intellectual property rights grant can be found 6*103e46e4SHarish Mahendrakar // in the file PATENTS. All contributing project authors may 7*103e46e4SHarish Mahendrakar // be found in the AUTHORS file in the root of the source tree. 8*103e46e4SHarish Mahendrakar #ifndef LIBWEBM_TESTING_TEST_UTIL_H_ 9*103e46e4SHarish Mahendrakar #define LIBWEBM_TESTING_TEST_UTIL_H_ 10*103e46e4SHarish Mahendrakar 11*103e46e4SHarish Mahendrakar #include <cstddef> 12*103e46e4SHarish Mahendrakar #include <cstdint> 13*103e46e4SHarish Mahendrakar #include <string> 14*103e46e4SHarish Mahendrakar 15*103e46e4SHarish Mahendrakar namespace mkvparser { 16*103e46e4SHarish Mahendrakar class IMkvReader; 17*103e46e4SHarish Mahendrakar class MkvReader; 18*103e46e4SHarish Mahendrakar class Segment; 19*103e46e4SHarish Mahendrakar } // namespace mkvparser 20*103e46e4SHarish Mahendrakar 21*103e46e4SHarish Mahendrakar namespace test { 22*103e46e4SHarish Mahendrakar 23*103e46e4SHarish Mahendrakar // constants for muxer and parser tests 24*103e46e4SHarish Mahendrakar const char kAppString[] = "mkvmuxer_unit_tests"; 25*103e46e4SHarish Mahendrakar const char kOpusCodecId[] = "A_OPUS"; 26*103e46e4SHarish Mahendrakar const char kVorbisCodecId[] = "A_VORBIS"; 27*103e46e4SHarish Mahendrakar const int kAudioTrackNumber = 2; 28*103e46e4SHarish Mahendrakar const int kBitDepth = 2; 29*103e46e4SHarish Mahendrakar const int kChannels = 2; 30*103e46e4SHarish Mahendrakar const double kDuration = 2.345; 31*103e46e4SHarish Mahendrakar const int kFrameLength = 10; 32*103e46e4SHarish Mahendrakar const int kHeight = 180; 33*103e46e4SHarish Mahendrakar const int kInvalidTrackNumber = 100; 34*103e46e4SHarish Mahendrakar const std::uint64_t kOpusCodecDelay = 6500000; 35*103e46e4SHarish Mahendrakar const std::size_t kOpusPrivateDataSizeMinimum = 19; 36*103e46e4SHarish Mahendrakar const std::uint64_t kOpusSeekPreroll = 80000000; 37*103e46e4SHarish Mahendrakar const char kMetadataCodecId[] = "D_WEBVTT/METADATA"; 38*103e46e4SHarish Mahendrakar const int kMetadataTrackNumber = 3; 39*103e46e4SHarish Mahendrakar const int kMetadataTrackType = 0x21; 40*103e46e4SHarish Mahendrakar const int kSampleRate = 30; 41*103e46e4SHarish Mahendrakar const int kTimeCodeScale = 1000; 42*103e46e4SHarish Mahendrakar const char kTrackName[] = "unit_test"; 43*103e46e4SHarish Mahendrakar const char kVP8CodecId[] = "V_VP8"; 44*103e46e4SHarish Mahendrakar const char kVP9CodecId[] = "V_VP9"; 45*103e46e4SHarish Mahendrakar const double kVideoFrameRate = 0.5; 46*103e46e4SHarish Mahendrakar const int kVideoTrackNumber = 1; 47*103e46e4SHarish Mahendrakar const int kWidth = 320; 48*103e46e4SHarish Mahendrakar 49*103e46e4SHarish Mahendrakar // Returns the path to the test data directory by reading and returning the 50*103e46e4SHarish Mahendrakar // contents the LIBWEBM_TESTDATA_DIR environment variable. 51*103e46e4SHarish Mahendrakar std::string GetTestDataDir(); 52*103e46e4SHarish Mahendrakar 53*103e46e4SHarish Mahendrakar // Returns the absolute path to the file of |name| in LIBWEBM_TESTDATA_DIR. 54*103e46e4SHarish Mahendrakar std::string GetTestFilePath(const std::string& name); 55*103e46e4SHarish Mahendrakar 56*103e46e4SHarish Mahendrakar // Byte-wise comparison of two files |file1| and |file2|. Returns true if the 57*103e46e4SHarish Mahendrakar // files match exactly, false otherwise. 58*103e46e4SHarish Mahendrakar bool CompareFiles(const std::string& file1, const std::string& file2); 59*103e46e4SHarish Mahendrakar 60*103e46e4SHarish Mahendrakar // Returns true and sets |cues_offset| to the cues location within the MKV file 61*103e46e4SHarish Mahendrakar // parsed by |segment| when the MKV file has cue points. 62*103e46e4SHarish Mahendrakar bool HasCuePoints(const mkvparser::Segment* segment, std::int64_t* cues_offset); 63*103e46e4SHarish Mahendrakar 64*103e46e4SHarish Mahendrakar // Validates cue points. Assumes caller has already called Load() on |segment|. 65*103e46e4SHarish Mahendrakar // Returns true when: 66*103e46e4SHarish Mahendrakar // All cue points point at clusters, OR 67*103e46e4SHarish Mahendrakar // Data parsed by |segment| has no cue points. 68*103e46e4SHarish Mahendrakar bool ValidateCues(mkvparser::Segment* segment, mkvparser::IMkvReader* reader); 69*103e46e4SHarish Mahendrakar 70*103e46e4SHarish Mahendrakar // Parses |webm_file| using mkvparser and returns true when file parses 71*103e46e4SHarish Mahendrakar // successfully (all clusters and blocks can be successfully walked). Second 72*103e46e4SHarish Mahendrakar // variant allows further interaction with the parsed file via transferring 73*103e46e4SHarish Mahendrakar // ownership of the mkvparser Segment and MkvReader to the caller via 74*103e46e4SHarish Mahendrakar // |parser_out|. 75*103e46e4SHarish Mahendrakar struct MkvParser { 76*103e46e4SHarish Mahendrakar MkvParser() = default; 77*103e46e4SHarish Mahendrakar ~MkvParser(); 78*103e46e4SHarish Mahendrakar mkvparser::Segment* segment = nullptr; 79*103e46e4SHarish Mahendrakar mkvparser::MkvReader* reader = nullptr; 80*103e46e4SHarish Mahendrakar }; 81*103e46e4SHarish Mahendrakar bool ParseMkvFile(const std::string& webm_file); 82*103e46e4SHarish Mahendrakar bool ParseMkvFileReleaseParser(const std::string& webm_file, 83*103e46e4SHarish Mahendrakar MkvParser* parser_out); 84*103e46e4SHarish Mahendrakar 85*103e46e4SHarish Mahendrakar } // namespace test 86*103e46e4SHarish Mahendrakar 87*103e46e4SHarish Mahendrakar #endif // LIBWEBM_TESTING_TEST_UTIL_H_ 88