2024-09-16 12:10:19 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Media\QuickTime\Atoms;
|
|
|
|
|
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
use Leenooks\Traits\ObjectIssetFix;
|
|
|
|
|
|
|
|
use App\Media\QuickTime\Atom;
|
|
|
|
use App\Media\QuickTime\Atoms\moov\trak\tkhd;
|
|
|
|
|
|
|
|
abstract class SubAtom extends Atom
|
|
|
|
{
|
|
|
|
use ObjectIssetFix;
|
|
|
|
|
|
|
|
protected ?string $unused_data;
|
|
|
|
|
|
|
|
protected const atom_record = [
|
|
|
|
'version'=>['c',1],
|
|
|
|
'flags'=>['a3',3],
|
|
|
|
'count'=>['N',4],
|
|
|
|
];
|
|
|
|
|
|
|
|
public function __get(string $key): mixed
|
|
|
|
{
|
|
|
|
switch ($key) {
|
2024-09-18 08:16:31 +00:00
|
|
|
// Height is in the moov/trak/tkhd atom
|
2024-09-16 12:10:19 +00:00
|
|
|
case 'height':
|
2024-09-18 08:16:31 +00:00
|
|
|
// Width is in the moov/trak/tkhd atom
|
2024-09-16 12:10:19 +00:00
|
|
|
case 'width':
|
|
|
|
$atom = $this->find_atoms(tkhd::class,1);
|
|
|
|
|
|
|
|
return $atom->{$key};
|
|
|
|
|
|
|
|
default:
|
|
|
|
throw new \Exception('Unknown key: '.$key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unpack data into our cache
|
|
|
|
*
|
|
|
|
* @param string|null $data
|
|
|
|
* @return Collection
|
|
|
|
* @throws \Exception
|
|
|
|
*/
|
|
|
|
protected function cache(?string $data=NULL): Collection
|
|
|
|
{
|
|
|
|
$data = $data ?: $this->data();
|
|
|
|
|
|
|
|
if (! count($this->cache) && $this->size) {
|
|
|
|
$this->cache = collect(unpack($this->unpack(),$data));
|
|
|
|
|
|
|
|
if ($this->size > ($x=$this->unpack_size()))
|
|
|
|
$this->unused_data = substr($data,$x);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->cache;
|
|
|
|
}
|
|
|
|
}
|