46 lines
1.1 KiB
PHP
46 lines
1.1 KiB
PHP
<?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
|
|
* @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
|
|
*/
|
|
public function signature(string $alg='sha1',mixed $hash=NULL,bool $next=FALSE): string|\HashContext
|
|
{
|
|
if (! Arr::has($this->cache,'signature')) {
|
|
if ($this->size) {
|
|
$this->fopen();
|
|
|
|
$hash = $hash ?: hash_init($alg);
|
|
while (! is_null($read=$this->fread(16384)))
|
|
hash_update($hash,$read);
|
|
|
|
$this->fclose();
|
|
|
|
if ($next)
|
|
return $hash;
|
|
else
|
|
$this->cache['signature'] = hash_final($hash);
|
|
|
|
} else {
|
|
$this->cache['signature'] = NULL;
|
|
}
|
|
}
|
|
|
|
return $this->cache['signature'];
|
|
}
|
|
} |