File: quicktime.h

package info (click to toggle)
scummvm 2.9.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 450,268 kB
  • sloc: cpp: 4,297,604; asm: 28,322; python: 12,901; sh: 11,219; java: 8,477; xml: 7,843; perl: 2,633; ansic: 2,465; yacc: 1,670; javascript: 1,020; makefile: 933; lex: 578; awk: 275; objc: 82; sed: 11; php: 1
file content (83 lines) | stat: -rw-r--r-- 3,104 bytes parent folder | download | duplicates (2)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <cxxtest/TestSuite.h>
#include "common/util.h"
#include "common/formats/quicktime.h"

static const byte VALID_MOOV_DATA[] = { // a minimally 'correct' quicktime file.
	// size				'moov'					size				'mdat'
	0x0, 0x0, 0x0, 0x8, 0x6d, 0x6f, 0x6f, 0x76, 0x0, 0x0, 0x0, 0x8, 0x6d, 0x64, 0x61, 0x74
};

static const byte VALID_MHDR_DATA[] = { // a 'correct' quicktime file with a header
	// size	(incl mvhd)	'moov'
	0x0, 0x0, 0x0, 0x74, 0x6d, 0x6f, 0x6f, 0x76,
	//size (27*4)		'mvhd'					vers  3bytes flags
	0x0, 0x0, 0x0, 0x6c, 0x6d, 0x76, 0x68, 0x64, 0x00, 0xff, 0xff, 0xff,
	// creation				modification			timescale (60?)		length (999 * 60)+ 1
	0x65, 0x52, 0xef, 0x5b, 0x65, 0x52, 0xef, 0x5b, 0x0, 0x0, 0x0, 0x3c, 0x0, 0x0, 0xea, 0x25,
	// preferred scale, vol, 		[10 bytes reserved]
	0x0, 0x0, 0x0, 0x1, 0x0, 0x10, 0,0,0,0,0,0,0,0,0,0,
	// display matrix, mostly ignored by parser except xMod (0x8000) and yMod (0xa000)
	0x0, 0x0, 0x80, 0x0, 0,0,0,0,0,0,0,0,0,0,0,0, 0x0, 0x0, 0xa0, 0x0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	// 7 more 32-bit values
	0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
	// size				'mdat'
	0x0, 0x0, 0x0, 0x8, 0x6d, 0x64, 0x61, 0x74
};


class QuickTimeTestParser : public Common::QuickTimeParser {
public:
	uint32 getDuration() const { return _duration; }
	const Common::Rational &getScaleFactorX() const { return _scaleFactorX; }
	const Common::Rational &getScaleFactorY() const { return _scaleFactorY; }
	const Common::Array<Track *> &getTracks() const { return _tracks; }

	SampleDesc *readSampleDesc(Track *track, uint32 format, uint32 descSize) override {
		return nullptr;
	}
};

class QuicktimeParserTestSuite : public CxxTest::TestSuite {
public:
	void test_streamAtEOS() {
		QuickTimeTestParser parser;
		const byte data[] = "";
		Common::MemoryReadStream stream(data, sizeof(data));
		stream.readByte(); // read the null char
		bool result = parser.parseStream(&stream, DisposeAfterUse::NO);
		TS_ASSERT(!result);
	}

	void test_streamInvalid() {
		QuickTimeTestParser parser;
		const byte data[] = "not a moov";
		Common::MemoryReadStream stream(data, sizeof(data));
		bool result = parser.parseStream(&stream, DisposeAfterUse::NO);
		TS_ASSERT(!result);
	}

	void test_moov() {
		QuickTimeTestParser parser;
		Common::MemoryReadStream stream(VALID_MOOV_DATA, sizeof(VALID_MOOV_DATA));
		bool result = parser.parseStream(&stream, DisposeAfterUse::NO);
		TS_ASSERT(result);
	}

	void test_mhdr() {
		QuickTimeTestParser parser;
		Common::MemoryReadStream stream(VALID_MHDR_DATA, sizeof(VALID_MHDR_DATA));
		bool result = parser.parseStream(&stream, DisposeAfterUse::NO);
		TS_ASSERT(result);
		TS_ASSERT_EQUALS(parser.getDuration(), 999*60 + 1);
		TS_ASSERT_EQUALS(parser.getScaleFactorX(), Common::Rational(0x10000, 0x8000));
		TS_ASSERT_EQUALS(parser.getScaleFactorY(), Common::Rational(0x10000, 0xa000));
	}

	void test_mhdrEarlyEOF() {
		QuickTimeTestParser parser;
		Common::MemoryReadStream stream(VALID_MHDR_DATA, sizeof(VALID_MHDR_DATA) - 10);
		bool result = parser.parseStream(&stream, DisposeAfterUse::NO);
		TS_ASSERT(!result);
	}

};