2024-09-16 12:10:19 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Media\QuickTime\Atoms;
|
|
|
|
|
|
|
|
// Movie sample data—media samples such as video frames and groups of audio samples.
|
|
|
|
// Usually this data can be interpreted only by using the movie resource.
|
|
|
|
|
|
|
|
use Illuminate\Support\Arr;
|
|
|
|
|
|
|
|
use App\Media\QuickTime\Atom;
|
|
|
|
|
|
|
|
class mdat extends Atom
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Calculate the signature of the data
|
|
|
|
*
|
|
|
|
* @param string $alg
|
2024-09-28 14:26:22 +00:00
|
|
|
* @param mixed|null $hash If the hash was initialised already, this is it
|
|
|
|
* @param bool $next If the final hash is calculated by the calling method
|
|
|
|
* @return string|\HashContext
|
2024-09-16 12:10:19 +00:00
|
|
|
*/
|
2024-09-28 14:26:22 +00:00
|
|
|
public function signature(string $alg='sha1',mixed $hash=NULL,bool $next=FALSE): string|\HashContext
|
2024-09-16 12:10:19 +00:00
|
|
|
{
|
|
|
|
if (! Arr::has($this->cache,'signature')) {
|
|
|
|
if ($this->size) {
|
|
|
|
$this->fopen();
|
|
|
|
|
2024-09-28 14:26:22 +00:00
|
|
|
$hash = $hash ?: hash_init($alg);
|
|
|
|
while (! is_null($read=$this->fread(16384)))
|
|
|
|
hash_update($hash,$read);
|
2024-09-16 12:10:19 +00:00
|
|
|
|
|
|
|
$this->fclose();
|
|
|
|
|
2024-09-28 14:26:22 +00:00
|
|
|
if ($next)
|
|
|
|
return $hash;
|
|
|
|
else
|
|
|
|
$this->cache['signature'] = hash_final($hash);
|
2024-09-16 12:10:19 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
$this->cache['signature'] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->cache['signature'];
|
|
|
|
}
|
|
|
|
}
|