1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the Metadata package. |
4
|
|
|
* |
5
|
|
|
* @author Daniel Schröder <[email protected]> |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace GravityMedia\Metadata\ID3v2\Metadata; |
9
|
|
|
|
10
|
|
|
use GravityMedia\Metadata\ID3v2\Filter\SynchsafeIntegerFilter; |
11
|
|
|
use GravityMedia\Metadata\ID3v2\Flag\ExtendedHeaderFlag; |
12
|
|
|
use GravityMedia\Metadata\ID3v2\Version; |
13
|
|
|
use GravityMedia\Stream\Stream; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* ID3v2 extended header metadata class. |
17
|
|
|
* |
18
|
|
|
* @package GravityMedia\Metadata\ID3v2\Metadata |
19
|
|
|
*/ |
20
|
|
|
class ExtendedHeaderMetadata |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var Stream |
24
|
|
|
*/ |
25
|
|
|
protected $stream; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var int |
29
|
|
|
*/ |
30
|
|
|
protected $version; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var SynchsafeIntegerFilter |
34
|
|
|
*/ |
35
|
|
|
protected $synchsafeIntegerFilter; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Create ID3v2 extended header metadata object. |
39
|
|
|
* |
40
|
|
|
* @param Stream $stream |
41
|
|
|
* @param int $version |
42
|
|
|
*/ |
43
|
|
|
public function __construct(Stream $stream, $version) |
44
|
|
|
{ |
45
|
|
|
$this->stream = $stream; |
46
|
|
|
$this->version = $version; |
47
|
|
|
$this->synchsafeIntegerFilter = new SynchsafeIntegerFilter(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Read ID3v2 extended header size. |
52
|
|
|
* |
53
|
|
|
* @return int |
54
|
|
|
*/ |
55
|
|
|
public function readSize() |
56
|
|
|
{ |
57
|
|
|
if (Version::VERSION_23 === $this->version) { |
58
|
|
|
return $this->stream->readUInt32(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
return $this->synchsafeIntegerFilter->decode($this->stream->readUInt32()); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Read ID3v2 extended header flags. |
66
|
|
|
* |
67
|
|
|
* @return array |
68
|
|
|
*/ |
69
|
|
|
public function readFlags() |
70
|
|
|
{ |
71
|
|
|
if (Version::VERSION_23 === $this->version) { |
72
|
|
|
$flags = $this->stream->readUInt16(); |
73
|
|
|
|
74
|
|
|
return [ |
75
|
|
|
ExtendedHeaderFlag::FLAG_CRC_DATA_PRESENT => (bool)($flags & 0x8000) |
76
|
|
|
]; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
$this->stream->seek(1, SEEK_CUR); |
80
|
|
|
|
81
|
|
|
$flags = $this->stream->readUInt8(); |
82
|
|
|
|
83
|
|
|
return [ |
84
|
|
|
ExtendedHeaderFlag::FLAG_TAG_IS_AN_UPDATE => (bool)($flags & 0x40), |
85
|
|
|
ExtendedHeaderFlag::FLAG_CRC_DATA_PRESENT => (bool)($flags & 0x20), |
86
|
|
|
ExtendedHeaderFlag::FLAG_TAG_RESTRICTIONS => (bool)($flags & 0x10) |
87
|
|
|
]; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Read ID3v2 extended header padding. |
92
|
|
|
* |
93
|
|
|
* @return int |
94
|
|
|
*/ |
95
|
|
|
public function readPadding() |
96
|
|
|
{ |
97
|
|
|
return $this->stream->readUInt32(); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Read ID3v2 extended header CRC-32 data. |
102
|
|
|
* |
103
|
|
|
* @return int |
104
|
|
|
*/ |
105
|
|
|
public function readCrc32() |
106
|
|
|
{ |
107
|
|
|
if (Version::VERSION_23 === $this->version) { |
108
|
|
|
return $this->stream->readUInt32(); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
$this->stream->seek(1, SEEK_CUR); |
112
|
|
|
|
113
|
|
|
return $this->stream->readUInt8() * 0x10000000 + |
114
|
|
|
$this->synchsafeIntegerFilter->decode($this->stream->readUInt32()); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Read ID3v2 extended header restrictions. |
119
|
|
|
* |
120
|
|
|
* @return int |
121
|
|
|
*/ |
122
|
|
|
public function readRestrictions() |
123
|
|
|
{ |
124
|
|
|
$this->stream->seek(1, SEEK_CUR); |
125
|
|
|
|
126
|
|
|
return $this->stream->readUInt8(); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|