ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
getid3_flac Class Reference

@tutorial http://flac.sourceforge.net/format.html More...

+ Inheritance diagram for getid3_flac:
+ Collaboration diagram for getid3_flac:

Public Member Functions

 getid3_flac (&$fd, &$ThisFileInfo)
 
 FLACparseMETAdata (&$fd, &$ThisFileInfo)
 
 FLACmetaBlockTypeLookup ($blocktype)
 
 FLACapplicationIDLookup ($applicationid)
 
 FLACparseSTREAMINFO ($METAdataBlockData, &$ThisFileInfo)
 
 FLACparseAPPLICATION ($METAdataBlockData, &$ThisFileInfo)
 
 FLACparseSEEKTABLE ($METAdataBlockData, &$ThisFileInfo)
 
 FLACparseCUESHEET ($METAdataBlockData, &$ThisFileInfo)
 
 Analyze ()
 
 parseMETAdata ()
 
 parsePICTURE ()
 Parse METADATA_BLOCK_PICTURE flac structure and extract attachment External usage: audio.ogg. More...
 
- Public Member Functions inherited from getid3_handler
 __construct (getID3 $getid3, $call_module=null)
 
 Analyze ()
 
 AnalyzeString ($string)
 
 setStringMode ($string)
 
 saveAttachment ($name, $offset, $length, $image_mime=null)
 

Static Public Member Functions

static metaBlockTypeLookup ($blocktype)
 
static applicationIDLookup ($applicationid)
 
static pictureTypeLookup ($type_id)
 

Data Fields

const syncword = 'fLaC'
 

Private Member Functions

 parseSTREAMINFO ($BlockData)
 
 parseAPPLICATION ($BlockData)
 
 parseSEEKTABLE ($BlockData)
 
 parseVORBIS_COMMENT ($BlockData)
 
 parseCUESHEET ($BlockData)
 

Additional Inherited Members

- Protected Member Functions inherited from getid3_handler
 ftell ()
 
 fread ($bytes)
 
 fseek ($bytes, $whence=SEEK_SET)
 
 feof ()
 
 isDependencyFor ($module)
 
 error ($text)
 
 warning ($text)
 
 notice ($text)
 
- Protected Attributes inherited from getid3_handler
 $getid3
 
 $data_string_flag = false
 
 $data_string = ''
 
 $data_string_position = 0
 
 $data_string_length = 0
 

Detailed Description

Member Function Documentation

◆ Analyze()

getid3_flac::Analyze ( )

Reimplemented from getid3_handler.

Definition at line 27 of file module.audio.flac.php.

27 {
28 $info = &$this->getid3->info;
29
30 $this->fseek($info['avdataoffset']);
31 $StreamMarker = $this->fread(4);
32 if ($StreamMarker != self::syncword) {
33 return $this->error('Expecting "'.getid3_lib::PrintHexBytes(self::syncword).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($StreamMarker).'"');
34 }
35 $info['fileformat'] = 'flac';
36 $info['audio']['dataformat'] = 'flac';
37 $info['audio']['bitrate_mode'] = 'vbr';
38 $info['audio']['lossless'] = true;
39
40 // parse flac container
41 return $this->parseMETAdata();
42 }
fseek($bytes, $whence=SEEK_SET)
Definition: getid3.php:1697
fread($bytes)
Definition: getid3.php:1685
error($text)
Definition: getid3.php:1738
PrintHexBytes($string, $hex=true, $spaces=true, $htmlsafe=true)
Definition: getid3.lib.php:17
$info
Definition: example_052.php:80

References $info, getid3_handler\error(), getid3_handler\fread(), getid3_handler\fseek(), parseMETAdata(), and getid3_lib\PrintHexBytes().

+ Here is the call graph for this function:

◆ applicationIDLookup()

static getid3_flac::applicationIDLookup (   $applicationid)
static

Definition at line 396 of file module.audio.flac.php.

396 {
397 // http://flac.sourceforge.net/id.html
398 static $lookup = array(
399 0x41544348 => 'FlacFile', // "ATCH"
400 0x42534F4C => 'beSolo', // "BSOL"
401 0x42554753 => 'Bugs Player', // "BUGS"
402 0x43756573 => 'GoldWave cue points (specification)', // "Cues"
403 0x46696361 => 'CUE Splitter', // "Fica"
404 0x46746F6C => 'flac-tools', // "Ftol"
405 0x4D4F5442 => 'MOTB MetaCzar', // "MOTB"
406 0x4D505345 => 'MP3 Stream Editor', // "MPSE"
407 0x4D754D4C => 'MusicML: Music Metadata Language', // "MuML"
408 0x52494646 => 'Sound Devices RIFF chunk storage', // "RIFF"
409 0x5346464C => 'Sound Font FLAC', // "SFFL"
410 0x534F4E59 => 'Sony Creative Software', // "SONY"
411 0x5351455A => 'flacsqueeze', // "SQEZ"
412 0x54745776 => 'TwistedWave', // "TtWv"
413 0x55495453 => 'UITS Embedding tools', // "UITS"
414 0x61696666 => 'FLAC AIFF chunk storage', // "aiff"
415 0x696D6167 => 'flac-image application for storing arbitrary files in APPLICATION metadata blocks', // "imag"
416 0x7065656D => 'Parseable Embedded Extensible Metadata (specification)', // "peem"
417 0x71667374 => 'QFLAC Studio', // "qfst"
418 0x72696666 => 'FLAC RIFF chunk storage', // "riff"
419 0x74756E65 => 'TagTuner', // "tune"
420 0x78626174 => 'XBAT', // "xbat"
421 0x786D6364 => 'xmcd', // "xmcd"
422 );
423 return (isset($lookup[$applicationid]) ? $lookup[$applicationid] : 'reserved');
424 }

Referenced by parseAPPLICATION().

+ Here is the caller graph for this function:

◆ FLACapplicationIDLookup()

getid3_flac::FLACapplicationIDLookup (   $applicationid)

Definition at line 170 of file module.audio.flac.php.

170 {
171 static $FLACapplicationIDLookup = array();
172 if (empty($FLACapplicationIDLookup)) {
173 // http://flac.sourceforge.net/id.html
174 $FLACapplicationIDLookup[0x46746F6C] = 'flac-tools'; // 'Ftol'
175 $FLACapplicationIDLookup[0x46746F6C] = 'Sound Font FLAC'; // 'SFFL'
176 }
177 return (isset($FLACapplicationIDLookup[$applicationid]) ? $FLACapplicationIDLookup[$applicationid] : 'reserved');
178 }

Referenced by FLACparseAPPLICATION().

+ Here is the caller graph for this function:

◆ FLACmetaBlockTypeLookup()

getid3_flac::FLACmetaBlockTypeLookup (   $blocktype)

Definition at line 157 of file module.audio.flac.php.

157 {
158 static $FLACmetaBlockTypeLookup = array();
159 if (empty($FLACmetaBlockTypeLookup)) {
160 $FLACmetaBlockTypeLookup[0] = 'STREAMINFO';
161 $FLACmetaBlockTypeLookup[1] = 'PADDING';
162 $FLACmetaBlockTypeLookup[2] = 'APPLICATION';
163 $FLACmetaBlockTypeLookup[3] = 'SEEKTABLE';
164 $FLACmetaBlockTypeLookup[4] = 'VORBIS_COMMENT';
165 $FLACmetaBlockTypeLookup[5] = 'CUESHEET';
166 }
167 return (isset($FLACmetaBlockTypeLookup[$blocktype]) ? $FLACmetaBlockTypeLookup[$blocktype] : 'reserved');
168 }

Referenced by FLACparseMETAdata().

+ Here is the caller graph for this function:

◆ FLACparseAPPLICATION()

getid3_flac::FLACparseAPPLICATION (   $METAdataBlockData,
$ThisFileInfo 
)

Definition at line 220 of file module.audio.flac.php.

220 {
221 $offset = 0;
222 $ApplicationID = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 4));
223 $offset += 4;
224 $ThisFileInfo['flac']['APPLICATION'][$ApplicationID]['name'] = getid3_flac::FLACapplicationIDLookup($ApplicationID);
225 $ThisFileInfo['flac']['APPLICATION'][$ApplicationID]['data'] = substr($METAdataBlockData, $offset);
226 $offset = $METAdataBlockLength;
227
228 return true;
229 }
FLACapplicationIDLookup($applicationid)
BigEndian2Int($byteword, $synchsafe=false, $signed=false)
Definition: getid3.lib.php:234

References getid3_lib\BigEndian2Int(), and FLACapplicationIDLookup().

Referenced by FLACparseMETAdata().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ FLACparseCUESHEET()

getid3_flac::FLACparseCUESHEET (   $METAdataBlockData,
$ThisFileInfo 
)

Definition at line 258 of file module.audio.flac.php.

258 {
259 $offset = 0;
260 $ThisFileInfo['flac']['CUESHEET']['media_catalog_number'] = trim(substr($METAdataBlockData, $offset, 128), "\0");
261 $offset += 128;
262 $ThisFileInfo['flac']['CUESHEET']['lead_in_samples'] = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 8));
263 $offset += 8;
264 $ThisFileInfo['flac']['CUESHEET']['flags']['is_cd'] = (bool) (getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 1)) & 0x80);
265 $offset += 1;
266
267 $offset += 258; // reserved
268
269 $ThisFileInfo['flac']['CUESHEET']['number_tracks'] = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 1));
270 $offset += 1;
271
272 for ($track = 0; $track < $ThisFileInfo['flac']['CUESHEET']['number_tracks']; $track++) {
273 $TrackSampleOffset = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 8));
274 $offset += 8;
275 $TrackNumber = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 1));
276 $offset += 1;
277
278 $ThisFileInfo['flac']['CUESHEET']['tracks'][$TrackNumber]['sample_offset'] = $TrackSampleOffset;
279
280 $ThisFileInfo['flac']['CUESHEET']['tracks'][$TrackNumber]['isrc'] = substr($METAdataBlockData, $offset, 12);
281 $offset += 12;
282
283 $TrackFlagsRaw = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 1));
284 $offset += 1;
285 $ThisFileInfo['flac']['CUESHEET']['tracks'][$TrackNumber]['flags']['is_audio'] = (bool) ($TrackFlagsRaw & 0x80);
286 $ThisFileInfo['flac']['CUESHEET']['tracks'][$TrackNumber]['flags']['pre_emphasis'] = (bool) ($TrackFlagsRaw & 0x40);
287
288 $offset += 13; // reserved
289
290 $ThisFileInfo['flac']['CUESHEET']['tracks'][$TrackNumber]['index_points'] = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 1));
291 $offset += 1;
292
293 for ($index = 0; $index < $ThisFileInfo['flac']['CUESHEET']['tracks'][$TrackNumber]['index_points']; $index++) {
294 $IndexSampleOffset = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 8));
295 $offset += 8;
296 $IndexNumber = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 1));
297 $offset += 1;
298
299 $offset += 3; // reserved
300
301 $ThisFileInfo['flac']['CUESHEET']['tracks'][$TrackNumber]['indexes'][$IndexNumber] = $IndexSampleOffset;
302 }
303 }
304 return true;
305 }

References getid3_lib\BigEndian2Int().

Referenced by FLACparseMETAdata().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ FLACparseMETAdata()

getid3_flac::FLACparseMETAdata ( $fd,
$ThisFileInfo 
)

Definition at line 40 of file module.audio.flac.php.

40 {
41
42 do {
43 $METAdataBlockOffset = ftell($fd);
44 $METAdataBlockHeader = fread($fd, 4);
45 $METAdataLastBlockFlag = (bool) (getid3_lib::BigEndian2Int(substr($METAdataBlockHeader, 0, 1)) & 0x80);
46 $METAdataBlockType = getid3_lib::BigEndian2Int(substr($METAdataBlockHeader, 0, 1)) & 0x7F;
47 $METAdataBlockLength = getid3_lib::BigEndian2Int(substr($METAdataBlockHeader, 1, 3));
48 $METAdataBlockTypeText = getid3_flac::FLACmetaBlockTypeLookup($METAdataBlockType);
49
50 if ($METAdataBlockLength < 0) {
51 $ThisFileInfo['error'][] = 'corrupt or invalid METADATA_BLOCK_HEADER.BLOCK_TYPE ('.$METAdataBlockType.') at offset '.$METAdataBlockOffset;
52 break;
53 }
54
55 $ThisFileInfo['flac'][$METAdataBlockTypeText]['raw'] = array();
56 $ThisFileInfo_flac_METAdataBlockTypeText_raw = &$ThisFileInfo['flac'][$METAdataBlockTypeText]['raw'];
57
58 $ThisFileInfo_flac_METAdataBlockTypeText_raw['offset'] = $METAdataBlockOffset;
59 $ThisFileInfo_flac_METAdataBlockTypeText_raw['last_meta_block'] = $METAdataLastBlockFlag;
60 $ThisFileInfo_flac_METAdataBlockTypeText_raw['block_type'] = $METAdataBlockType;
61 $ThisFileInfo_flac_METAdataBlockTypeText_raw['block_type_text'] = $METAdataBlockTypeText;
62 $ThisFileInfo_flac_METAdataBlockTypeText_raw['block_length'] = $METAdataBlockLength;
63 $ThisFileInfo_flac_METAdataBlockTypeText_raw['block_data'] = @fread($fd, $METAdataBlockLength);
64 $ThisFileInfo['avdataoffset'] = ftell($fd);
65
66 switch ($METAdataBlockTypeText) {
67
68 case 'STREAMINFO':
69 if (!getid3_flac::FLACparseSTREAMINFO($ThisFileInfo_flac_METAdataBlockTypeText_raw['block_data'], $ThisFileInfo)) {
70 return false;
71 }
72 break;
73
74 case 'PADDING':
75 // ignore
76 break;
77
78 case 'APPLICATION':
79 if (!getid3_flac::FLACparseAPPLICATION($ThisFileInfo_flac_METAdataBlockTypeText_raw['block_data'], $ThisFileInfo)) {
80 return false;
81 }
82 break;
83
84 case 'SEEKTABLE':
85 if (!getid3_flac::FLACparseSEEKTABLE($ThisFileInfo_flac_METAdataBlockTypeText_raw['block_data'], $ThisFileInfo)) {
86 return false;
87 }
88 break;
89
90 case 'VORBIS_COMMENT':
91 $OldOffset = ftell($fd);
92 fseek($fd, 0 - $METAdataBlockLength, SEEK_CUR);
94 fseek($fd, $OldOffset, SEEK_SET);
95 break;
96
97 case 'CUESHEET':
98 if (!getid3_flac::FLACparseCUESHEET($ThisFileInfo_flac_METAdataBlockTypeText_raw['block_data'], $ThisFileInfo)) {
99 return false;
100 }
101 break;
102
103 default:
104 $ThisFileInfo['warning'][] = 'Unhandled METADATA_BLOCK_HEADER.BLOCK_TYPE ('.$METAdataBlockType.') at offset '.$METAdataBlockOffset;
105 break;
106 }
107
108 } while ($METAdataLastBlockFlag === false);
109
110
111 if (isset($ThisFileInfo['flac']['STREAMINFO'])) {
112 $ThisFileInfo['flac']['compressed_audio_bytes'] = $ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset'];
113 $ThisFileInfo['flac']['uncompressed_audio_bytes'] = $ThisFileInfo['flac']['STREAMINFO']['samples_stream'] * $ThisFileInfo['flac']['STREAMINFO']['channels'] * ($ThisFileInfo['flac']['STREAMINFO']['bits_per_sample'] / 8);
114 if ($ThisFileInfo['flac']['uncompressed_audio_bytes'] == 0) {
115 $ThisFileInfo['error'][] = 'Corrupt FLAC file: uncompressed_audio_bytes == zero';
116 return false;
117 }
118 $ThisFileInfo['flac']['compression_ratio'] = $ThisFileInfo['flac']['compressed_audio_bytes'] / $ThisFileInfo['flac']['uncompressed_audio_bytes'];
119 }
120
121 // set md5_data_source - built into flac 0.5+
122 if (isset($ThisFileInfo['flac']['STREAMINFO']['audio_signature'])) {
123
124 if ($ThisFileInfo['flac']['STREAMINFO']['audio_signature'] === str_repeat("\x00", 16)) {
125
126 $ThisFileInfo['warning'][] = 'FLAC STREAMINFO.audio_signature is null (known issue with libOggFLAC)';
127
128 } else {
129
130 $ThisFileInfo['md5_data_source'] = '';
131 $md5 = $ThisFileInfo['flac']['STREAMINFO']['audio_signature'];
132 for ($i = 0; $i < strlen($md5); $i++) {
133 $ThisFileInfo['md5_data_source'] .= str_pad(dechex(ord($md5{$i})), 2, '00', STR_PAD_LEFT);
134 }
135 if (!preg_match('/^[0-9a-f]{32}$/', $ThisFileInfo['md5_data_source'])) {
136 unset($ThisFileInfo['md5_data_source']);
137 }
138
139 }
140
141 }
142
143 $ThisFileInfo['audio']['bits_per_sample'] = $ThisFileInfo['flac']['STREAMINFO']['bits_per_sample'];
144 if ($ThisFileInfo['audio']['bits_per_sample'] == 8) {
145 // special case
146 // must invert sign bit on all data bytes before MD5'ing to match FLAC's calculated value
147 // MD5sum calculates on unsigned bytes, but FLAC calculated MD5 on 8-bit audio data as signed
148 $ThisFileInfo['warning'][] = 'FLAC calculates MD5 data strangely on 8-bit audio, so the stored md5_data_source value will not match the decoded WAV file';
149 }
150 if (!empty($ThisFileInfo['ogg']['vendor'])) {
151 $ThisFileInfo['audio']['encoder'] = $ThisFileInfo['ogg']['vendor'];
152 }
153
154 return true;
155 }
FLACparseSTREAMINFO($METAdataBlockData, &$ThisFileInfo)
FLACparseCUESHEET($METAdataBlockData, &$ThisFileInfo)
FLACparseAPPLICATION($METAdataBlockData, &$ThisFileInfo)
FLACmetaBlockTypeLookup($blocktype)
FLACparseSEEKTABLE($METAdataBlockData, &$ThisFileInfo)
ParseVorbisCommentsFilepointer(&$fd, &$ThisFileInfo)

References getid3_lib\BigEndian2Int(), FLACmetaBlockTypeLookup(), FLACparseAPPLICATION(), FLACparseCUESHEET(), FLACparseSEEKTABLE(), FLACparseSTREAMINFO(), getid3_handler\fread(), getid3_handler\fseek(), getid3_handler\ftell(), and getid3_ogg\ParseVorbisCommentsFilepointer().

Referenced by getid3_flac(), and getid3_ogg\getid3_ogg().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ FLACparseSEEKTABLE()

getid3_flac::FLACparseSEEKTABLE (   $METAdataBlockData,
$ThisFileInfo 
)

Definition at line 232 of file module.audio.flac.php.

232 {
233 $offset = 0;
234 $METAdataBlockLength = strlen($METAdataBlockData);
235 $placeholderpattern = str_repeat("\xFF", 8);
236 while ($offset < $METAdataBlockLength) {
237 $SampleNumberString = substr($METAdataBlockData, $offset, 8);
238 $offset += 8;
239 if ($SampleNumberString == $placeholderpattern) {
240
241 // placeholder point
242 @$ThisFileInfo['flac']['SEEKTABLE']['placeholders']++;
243 $offset += 10;
244
245 } else {
246
247 $SampleNumber = getid3_lib::BigEndian2Int($SampleNumberString);
248 $ThisFileInfo['flac']['SEEKTABLE'][$SampleNumber]['offset'] = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 8));
249 $offset += 8;
250 $ThisFileInfo['flac']['SEEKTABLE'][$SampleNumber]['samples'] = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 2));
251 $offset += 2;
252
253 }
254 }
255 return true;
256 }

References getid3_lib\BigEndian2Int().

Referenced by FLACparseMETAdata().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ FLACparseSTREAMINFO()

getid3_flac::FLACparseSTREAMINFO (   $METAdataBlockData,
$ThisFileInfo 
)

Definition at line 180 of file module.audio.flac.php.

180 {
181 $offset = 0;
182 $ThisFileInfo['flac']['STREAMINFO']['min_block_size'] = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 2));
183 $offset += 2;
184 $ThisFileInfo['flac']['STREAMINFO']['max_block_size'] = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 2));
185 $offset += 2;
186 $ThisFileInfo['flac']['STREAMINFO']['min_frame_size'] = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 3));
187 $offset += 3;
188 $ThisFileInfo['flac']['STREAMINFO']['max_frame_size'] = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 3));
189 $offset += 3;
190
191 $SampleRateChannelsSampleBitsStreamSamples = getid3_lib::BigEndian2Bin(substr($METAdataBlockData, $offset, 8));
192 $ThisFileInfo['flac']['STREAMINFO']['sample_rate'] = getid3_lib::Bin2Dec(substr($SampleRateChannelsSampleBitsStreamSamples, 0, 20));
193 $ThisFileInfo['flac']['STREAMINFO']['channels'] = getid3_lib::Bin2Dec(substr($SampleRateChannelsSampleBitsStreamSamples, 20, 3)) + 1;
194 $ThisFileInfo['flac']['STREAMINFO']['bits_per_sample'] = getid3_lib::Bin2Dec(substr($SampleRateChannelsSampleBitsStreamSamples, 23, 5)) + 1;
195 $ThisFileInfo['flac']['STREAMINFO']['samples_stream'] = getid3_lib::Bin2Dec(substr($SampleRateChannelsSampleBitsStreamSamples, 28, 36));
196 $offset += 8;
197
198 $ThisFileInfo['flac']['STREAMINFO']['audio_signature'] = substr($METAdataBlockData, $offset, 16);
199 $offset += 16;
200
201 if (!empty($ThisFileInfo['flac']['STREAMINFO']['sample_rate'])) {
202
203 $ThisFileInfo['audio']['bitrate_mode'] = 'vbr';
204 $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['flac']['STREAMINFO']['sample_rate'];
205 $ThisFileInfo['audio']['channels'] = $ThisFileInfo['flac']['STREAMINFO']['channels'];
206 $ThisFileInfo['audio']['bits_per_sample'] = $ThisFileInfo['flac']['STREAMINFO']['bits_per_sample'];
207 $ThisFileInfo['playtime_seconds'] = $ThisFileInfo['flac']['STREAMINFO']['samples_stream'] / $ThisFileInfo['flac']['STREAMINFO']['sample_rate'];
208 $ThisFileInfo['audio']['bitrate'] = (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8) / $ThisFileInfo['playtime_seconds'];
209
210 } else {
211
212 $ThisFileInfo['error'][] = 'Corrupt METAdata block: STREAMINFO';
213 return false;
214
215 }
216 return true;
217 }
BigEndian2Bin($byteword)
Definition: getid3.lib.php:271
Bin2Dec($binstring, $signed=false)
Definition: getid3.lib.php:316

References getid3_lib\BigEndian2Bin(), getid3_lib\BigEndian2Int(), and getid3_lib\Bin2Dec().

Referenced by FLACparseMETAdata().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getid3_flac()

getid3_flac::getid3_flac ( $fd,
$ThisFileInfo 
)

Definition at line 22 of file module.audio.flac.php.

22 {
23 // http://flac.sourceforge.net/format.html
24
25 fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
26 $StreamMarker = fread($fd, 4);
27 if ($StreamMarker != 'fLaC') {
28 $ThisFileInfo['error'][] = 'Expecting "fLaC" at offset '.$ThisFileInfo['avdataoffset'].', found "'.$StreamMarker.'"';
29 return false;
30 }
31 $ThisFileInfo['fileformat'] = 'flac';
32 $ThisFileInfo['audio']['dataformat'] = 'flac';
33 $ThisFileInfo['audio']['bitrate_mode'] = 'vbr';
34 $ThisFileInfo['audio']['lossless'] = true;
35
36 return getid3_flac::FLACparseMETAdata($fd, $ThisFileInfo);
37 }
FLACparseMETAdata(&$fd, &$ThisFileInfo)

References FLACparseMETAdata(), getid3_handler\fread(), and getid3_handler\fseek().

+ Here is the call graph for this function:

◆ metaBlockTypeLookup()

static getid3_flac::metaBlockTypeLookup (   $blocktype)
static

Definition at line 383 of file module.audio.flac.php.

383 {
384 static $lookup = array(
385 0 => 'STREAMINFO',
386 1 => 'PADDING',
387 2 => 'APPLICATION',
388 3 => 'SEEKTABLE',
389 4 => 'VORBIS_COMMENT',
390 5 => 'CUESHEET',
391 6 => 'PICTURE',
392 );
393 return (isset($lookup[$blocktype]) ? $lookup[$blocktype] : 'reserved');
394 }

Referenced by parseMETAdata().

+ Here is the caller graph for this function:

◆ parseAPPLICATION()

getid3_flac::parseAPPLICATION (   $BlockData)
private

Definition at line 239 of file module.audio.flac.php.

239 {
240 $info = &$this->getid3->info;
241
242 $ApplicationID = getid3_lib::BigEndian2Int(substr($BlockData, 0, 4));
243 $info['flac']['APPLICATION'][$ApplicationID]['name'] = self::applicationIDLookup($ApplicationID);
244 $info['flac']['APPLICATION'][$ApplicationID]['data'] = substr($BlockData, 4);
245
246 return true;
247 }
static applicationIDLookup($applicationid)

References $info, applicationIDLookup(), and getid3_lib\BigEndian2Int().

Referenced by parseMETAdata().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseCUESHEET()

getid3_flac::parseCUESHEET (   $BlockData)
private

Definition at line 297 of file module.audio.flac.php.

297 {
298 $info = &$this->getid3->info;
299 $offset = 0;
300 $info['flac']['CUESHEET']['media_catalog_number'] = trim(substr($BlockData, $offset, 128), "\0");
301 $offset += 128;
302 $info['flac']['CUESHEET']['lead_in_samples'] = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 8));
303 $offset += 8;
304 $info['flac']['CUESHEET']['flags']['is_cd'] = (bool) (getid3_lib::BigEndian2Int(substr($BlockData, $offset, 1)) & 0x80);
305 $offset += 1;
306
307 $offset += 258; // reserved
308
309 $info['flac']['CUESHEET']['number_tracks'] = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 1));
310 $offset += 1;
311
312 for ($track = 0; $track < $info['flac']['CUESHEET']['number_tracks']; $track++) {
313 $TrackSampleOffset = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 8));
314 $offset += 8;
315 $TrackNumber = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 1));
316 $offset += 1;
317
318 $info['flac']['CUESHEET']['tracks'][$TrackNumber]['sample_offset'] = $TrackSampleOffset;
319
320 $info['flac']['CUESHEET']['tracks'][$TrackNumber]['isrc'] = substr($BlockData, $offset, 12);
321 $offset += 12;
322
323 $TrackFlagsRaw = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 1));
324 $offset += 1;
325 $info['flac']['CUESHEET']['tracks'][$TrackNumber]['flags']['is_audio'] = (bool) ($TrackFlagsRaw & 0x80);
326 $info['flac']['CUESHEET']['tracks'][$TrackNumber]['flags']['pre_emphasis'] = (bool) ($TrackFlagsRaw & 0x40);
327
328 $offset += 13; // reserved
329
330 $info['flac']['CUESHEET']['tracks'][$TrackNumber]['index_points'] = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 1));
331 $offset += 1;
332
333 for ($index = 0; $index < $info['flac']['CUESHEET']['tracks'][$TrackNumber]['index_points']; $index++) {
334 $IndexSampleOffset = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 8));
335 $offset += 8;
336 $IndexNumber = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 1));
337 $offset += 1;
338
339 $offset += 3; // reserved
340
341 $info['flac']['CUESHEET']['tracks'][$TrackNumber]['indexes'][$IndexNumber] = $IndexSampleOffset;
342 }
343 }
344
345 return true;
346 }

References $info, and getid3_lib\BigEndian2Int().

Referenced by parseMETAdata().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseMETAdata()

getid3_flac::parseMETAdata ( )

Definition at line 44 of file module.audio.flac.php.

44 {
45 $info = &$this->getid3->info;
46 do {
47 $BlockOffset = $this->ftell();
48 $BlockHeader = $this->fread(4);
49 $LBFBT = getid3_lib::BigEndian2Int(substr($BlockHeader, 0, 1));
50 $LastBlockFlag = (bool) ($LBFBT & 0x80);
51 $BlockType = ($LBFBT & 0x7F);
52 $BlockLength = getid3_lib::BigEndian2Int(substr($BlockHeader, 1, 3));
53 $BlockTypeText = self::metaBlockTypeLookup($BlockType);
54
55 if (($BlockOffset + 4 + $BlockLength) > $info['avdataend']) {
56 $this->error('METADATA_BLOCK_HEADER.BLOCK_TYPE ('.$BlockTypeText.') at offset '.$BlockOffset.' extends beyond end of file');
57 break;
58 }
59 if ($BlockLength < 1) {
60 $this->error('METADATA_BLOCK_HEADER.BLOCK_LENGTH ('.$BlockLength.') at offset '.$BlockOffset.' is invalid');
61 break;
62 }
63
64 $info['flac'][$BlockTypeText]['raw'] = array();
65 $BlockTypeText_raw = &$info['flac'][$BlockTypeText]['raw'];
66
67 $BlockTypeText_raw['offset'] = $BlockOffset;
68 $BlockTypeText_raw['last_meta_block'] = $LastBlockFlag;
69 $BlockTypeText_raw['block_type'] = $BlockType;
70 $BlockTypeText_raw['block_type_text'] = $BlockTypeText;
71 $BlockTypeText_raw['block_length'] = $BlockLength;
72 if ($BlockTypeText_raw['block_type'] != 0x06) { // do not read attachment data automatically
73 $BlockTypeText_raw['block_data'] = $this->fread($BlockLength);
74 }
75
76 switch ($BlockTypeText) {
77 case 'STREAMINFO': // 0x00
78 if (!$this->parseSTREAMINFO($BlockTypeText_raw['block_data'])) {
79 return false;
80 }
81 break;
82
83 case 'PADDING': // 0x01
84 unset($info['flac']['PADDING']); // ignore
85 break;
86
87 case 'APPLICATION': // 0x02
88 if (!$this->parseAPPLICATION($BlockTypeText_raw['block_data'])) {
89 return false;
90 }
91 break;
92
93 case 'SEEKTABLE': // 0x03
94 if (!$this->parseSEEKTABLE($BlockTypeText_raw['block_data'])) {
95 return false;
96 }
97 break;
98
99 case 'VORBIS_COMMENT': // 0x04
100 if (!$this->parseVORBIS_COMMENT($BlockTypeText_raw['block_data'])) {
101 return false;
102 }
103 break;
104
105 case 'CUESHEET': // 0x05
106 if (!$this->parseCUESHEET($BlockTypeText_raw['block_data'])) {
107 return false;
108 }
109 break;
110
111 case 'PICTURE': // 0x06
112 if (!$this->parsePICTURE()) {
113 return false;
114 }
115 break;
116
117 default:
118 $this->warning('Unhandled METADATA_BLOCK_HEADER.BLOCK_TYPE ('.$BlockType.') at offset '.$BlockOffset);
119 }
120
121 unset($info['flac'][$BlockTypeText]['raw']);
122 $info['avdataoffset'] = $this->ftell();
123 }
124 while ($LastBlockFlag === false);
125
126 // handle tags
127 if (!empty($info['flac']['VORBIS_COMMENT']['comments'])) {
128 $info['flac']['comments'] = $info['flac']['VORBIS_COMMENT']['comments'];
129 }
130 if (!empty($info['flac']['VORBIS_COMMENT']['vendor'])) {
131 $info['audio']['encoder'] = str_replace('reference ', '', $info['flac']['VORBIS_COMMENT']['vendor']);
132 }
133
134 // copy attachments to 'comments' array if nesesary
135 if (isset($info['flac']['PICTURE']) && ($this->getid3->option_save_attachments !== getID3::ATTACHMENTS_NONE)) {
136 foreach ($info['flac']['PICTURE'] as $entry) {
137 if (!empty($entry['data'])) {
138 if (!isset($info['flac']['comments']['picture'])) {
139 $info['flac']['comments']['picture'] = array();
140 }
141 $comments_picture_data = array();
142 foreach (array('data', 'image_mime', 'image_width', 'image_height', 'imagetype', 'picturetype', 'description', 'datalength') as $picture_key) {
143 if (isset($entry[$picture_key])) {
144 $comments_picture_data[$picture_key] = $entry[$picture_key];
145 }
146 }
147 $info['flac']['comments']['picture'][] = $comments_picture_data;
148 unset($comments_picture_data);
149 }
150 }
151 }
152
153 if (isset($info['flac']['STREAMINFO'])) {
154 if (!$this->isDependencyFor('matroska')) {
155 $info['flac']['compressed_audio_bytes'] = $info['avdataend'] - $info['avdataoffset'];
156 }
157 $info['flac']['uncompressed_audio_bytes'] = $info['flac']['STREAMINFO']['samples_stream'] * $info['flac']['STREAMINFO']['channels'] * ($info['flac']['STREAMINFO']['bits_per_sample'] / 8);
158 if ($info['flac']['uncompressed_audio_bytes'] == 0) {
159 return $this->error('Corrupt FLAC file: uncompressed_audio_bytes == zero');
160 }
161 if (!empty($info['flac']['compressed_audio_bytes'])) {
162 $info['flac']['compression_ratio'] = $info['flac']['compressed_audio_bytes'] / $info['flac']['uncompressed_audio_bytes'];
163 }
164 }
165
166 // set md5_data_source - built into flac 0.5+
167 if (isset($info['flac']['STREAMINFO']['audio_signature'])) {
168
169 if ($info['flac']['STREAMINFO']['audio_signature'] === str_repeat("\x00", 16)) {
170 $this->warning('FLAC STREAMINFO.audio_signature is null (known issue with libOggFLAC)');
171 }
172 else {
173 $info['md5_data_source'] = '';
174 $md5 = $info['flac']['STREAMINFO']['audio_signature'];
175 for ($i = 0; $i < strlen($md5); $i++) {
176 $info['md5_data_source'] .= str_pad(dechex(ord($md5[$i])), 2, '00', STR_PAD_LEFT);
177 }
178 if (!preg_match('/^[0-9a-f]{32}$/', $info['md5_data_source'])) {
179 unset($info['md5_data_source']);
180 }
181 }
182 }
183
184 if (isset($info['flac']['STREAMINFO']['bits_per_sample'])) {
185 $info['audio']['bits_per_sample'] = $info['flac']['STREAMINFO']['bits_per_sample'];
186 if ($info['audio']['bits_per_sample'] == 8) {
187 // special case
188 // must invert sign bit on all data bytes before MD5'ing to match FLAC's calculated value
189 // MD5sum calculates on unsigned bytes, but FLAC calculated MD5 on 8-bit audio data as signed
190 $this->warning('FLAC calculates MD5 data strangely on 8-bit audio, so the stored md5_data_source value will not match the decoded WAV file');
191 }
192 }
193
194 return true;
195 }
const ATTACHMENTS_NONE
Definition: getid3.php:115
parseAPPLICATION($BlockData)
parseSTREAMINFO($BlockData)
parseSEEKTABLE($BlockData)
static metaBlockTypeLookup($blocktype)
parseVORBIS_COMMENT($BlockData)
parseCUESHEET($BlockData)
parsePICTURE()
Parse METADATA_BLOCK_PICTURE flac structure and extract attachment External usage: audio....
isDependencyFor($module)
Definition: getid3.php:1734
warning($text)
Definition: getid3.php:1744

References $info, getID3\ATTACHMENTS_NONE, getid3_lib\BigEndian2Int(), getid3_handler\error(), getid3_handler\fread(), getid3_handler\ftell(), getid3_handler\isDependencyFor(), metaBlockTypeLookup(), parseAPPLICATION(), parseCUESHEET(), parsePICTURE(), parseSEEKTABLE(), parseSTREAMINFO(), parseVORBIS_COMMENT(), and getid3_handler\warning().

Referenced by Analyze().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parsePICTURE()

getid3_flac::parsePICTURE ( )

Parse METADATA_BLOCK_PICTURE flac structure and extract attachment External usage: audio.ogg.

Definition at line 352 of file module.audio.flac.php.

352 {
353 $info = &$this->getid3->info;
354
355 $picture['typeid'] = getid3_lib::BigEndian2Int($this->fread(4));
356 $picture['picturetype'] = self::pictureTypeLookup($picture['typeid']);
357 $picture['image_mime'] = $this->fread(getid3_lib::BigEndian2Int($this->fread(4)));
358 $descr_length = getid3_lib::BigEndian2Int($this->fread(4));
359 if ($descr_length) {
360 $picture['description'] = $this->fread($descr_length);
361 }
362 $picture['image_width'] = getid3_lib::BigEndian2Int($this->fread(4));
363 $picture['image_height'] = getid3_lib::BigEndian2Int($this->fread(4));
364 $picture['color_depth'] = getid3_lib::BigEndian2Int($this->fread(4));
365 $picture['colors_indexed'] = getid3_lib::BigEndian2Int($this->fread(4));
366 $picture['datalength'] = getid3_lib::BigEndian2Int($this->fread(4));
367
368 if ($picture['image_mime'] == '-->') {
369 $picture['data'] = $this->fread($picture['datalength']);
370 } else {
371 $picture['data'] = $this->saveAttachment(
372 str_replace('/', '_', $picture['picturetype']).'_'.$this->ftell(),
373 $this->ftell(),
374 $picture['datalength'],
375 $picture['image_mime']);
376 }
377
378 $info['flac']['PICTURE'][] = $picture;
379
380 return true;
381 }
static pictureTypeLookup($type_id)
saveAttachment($name, $offset, $length, $image_mime=null)
Definition: getid3.php:1752

References $info, getid3_lib\BigEndian2Int(), getid3_handler\fread(), getid3_handler\ftell(), pictureTypeLookup(), and getid3_handler\saveAttachment().

Referenced by parseMETAdata().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseSEEKTABLE()

getid3_flac::parseSEEKTABLE (   $BlockData)
private

Definition at line 249 of file module.audio.flac.php.

249 {
250 $info = &$this->getid3->info;
251
252 $offset = 0;
253 $BlockLength = strlen($BlockData);
254 $placeholderpattern = str_repeat("\xFF", 8);
255 while ($offset < $BlockLength) {
256 $SampleNumberString = substr($BlockData, $offset, 8);
257 $offset += 8;
258 if ($SampleNumberString == $placeholderpattern) {
259
260 // placeholder point
261 getid3_lib::safe_inc($info['flac']['SEEKTABLE']['placeholders'], 1);
262 $offset += 10;
263
264 } else {
265
266 $SampleNumber = getid3_lib::BigEndian2Int($SampleNumberString);
267 $info['flac']['SEEKTABLE'][$SampleNumber]['offset'] = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 8));
268 $offset += 8;
269 $info['flac']['SEEKTABLE'][$SampleNumber]['samples'] = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 2));
270 $offset += 2;
271
272 }
273 }
274
275 return true;
276 }
static safe_inc(&$variable, $increment=1)
Definition: getid3.lib.php:56

References $info, getid3_lib\BigEndian2Int(), and getid3_lib\safe_inc().

Referenced by parseMETAdata().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseSTREAMINFO()

getid3_flac::parseSTREAMINFO (   $BlockData)
private

Definition at line 197 of file module.audio.flac.php.

197 {
198 $info = &$this->getid3->info;
199
200 $info['flac']['STREAMINFO'] = array();
201 $streaminfo = &$info['flac']['STREAMINFO'];
202
203 $streaminfo['min_block_size'] = getid3_lib::BigEndian2Int(substr($BlockData, 0, 2));
204 $streaminfo['max_block_size'] = getid3_lib::BigEndian2Int(substr($BlockData, 2, 2));
205 $streaminfo['min_frame_size'] = getid3_lib::BigEndian2Int(substr($BlockData, 4, 3));
206 $streaminfo['max_frame_size'] = getid3_lib::BigEndian2Int(substr($BlockData, 7, 3));
207
208 $SRCSBSS = getid3_lib::BigEndian2Bin(substr($BlockData, 10, 8));
209 $streaminfo['sample_rate'] = getid3_lib::Bin2Dec(substr($SRCSBSS, 0, 20));
210 $streaminfo['channels'] = getid3_lib::Bin2Dec(substr($SRCSBSS, 20, 3)) + 1;
211 $streaminfo['bits_per_sample'] = getid3_lib::Bin2Dec(substr($SRCSBSS, 23, 5)) + 1;
212 $streaminfo['samples_stream'] = getid3_lib::Bin2Dec(substr($SRCSBSS, 28, 36));
213
214 $streaminfo['audio_signature'] = substr($BlockData, 18, 16);
215
216 if (!empty($streaminfo['sample_rate'])) {
217
218 $info['audio']['bitrate_mode'] = 'vbr';
219 $info['audio']['sample_rate'] = $streaminfo['sample_rate'];
220 $info['audio']['channels'] = $streaminfo['channels'];
221 $info['audio']['bits_per_sample'] = $streaminfo['bits_per_sample'];
222 $info['playtime_seconds'] = $streaminfo['samples_stream'] / $streaminfo['sample_rate'];
223 if ($info['playtime_seconds'] > 0) {
224 if (!$this->isDependencyFor('matroska')) {
225 $info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds'];
226 }
227 else {
228 $this->warning('Cannot determine audio bitrate because total stream size is unknown');
229 }
230 }
231
232 } else {
233 return $this->error('Corrupt METAdata block: STREAMINFO');
234 }
235
236 return true;
237 }

References $info, getid3_lib\BigEndian2Bin(), getid3_lib\BigEndian2Int(), getid3_lib\Bin2Dec(), getid3_handler\error(), getid3_handler\isDependencyFor(), and getid3_handler\warning().

Referenced by parseMETAdata().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseVORBIS_COMMENT()

getid3_flac::parseVORBIS_COMMENT (   $BlockData)
private

Definition at line 278 of file module.audio.flac.php.

278 {
279 $info = &$this->getid3->info;
280
281 $getid3_ogg = new getid3_ogg($this->getid3);
282 if ($this->isDependencyFor('matroska')) {
283 $getid3_ogg->setStringMode($this->data_string);
284 }
285 $getid3_ogg->ParseVorbisComments();
286 if (isset($info['ogg'])) {
287 unset($info['ogg']['comments_raw']);
288 $info['flac']['VORBIS_COMMENT'] = $info['ogg'];
289 unset($info['ogg']);
290 }
291
292 unset($getid3_ogg);
293
294 return true;
295 }

References $info, and getid3_handler\isDependencyFor().

Referenced by parseMETAdata().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pictureTypeLookup()

static getid3_flac::pictureTypeLookup (   $type_id)
static

Definition at line 426 of file module.audio.flac.php.

426 {
427 static $lookup = array (
428 0 => 'Other',
429 1 => '32x32 pixels \'file icon\' (PNG only)',
430 2 => 'Other file icon',
431 3 => 'Cover (front)',
432 4 => 'Cover (back)',
433 5 => 'Leaflet page',
434 6 => 'Media (e.g. label side of CD)',
435 7 => 'Lead artist/lead performer/soloist',
436 8 => 'Artist/performer',
437 9 => 'Conductor',
438 10 => 'Band/Orchestra',
439 11 => 'Composer',
440 12 => 'Lyricist/text writer',
441 13 => 'Recording Location',
442 14 => 'During recording',
443 15 => 'During performance',
444 16 => 'Movie/video screen capture',
445 17 => 'A bright coloured fish',
446 18 => 'Illustration',
447 19 => 'Band/artist logotype',
448 20 => 'Publisher/Studio logotype',
449 );
450 return (isset($lookup[$type_id]) ? $lookup[$type_id] : 'reserved');
451 }

Referenced by parsePICTURE().

+ Here is the caller graph for this function:

Field Documentation

◆ syncword

const getid3_flac::syncword = 'fLaC'

Definition at line 25 of file module.audio.flac.php.


The documentation for this class was generated from the following files: