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