From 42d91f7e33035061eab5f6fa880ec45309ab5b58 Mon Sep 17 00:00:00 2001 From: svollbehr Date: Wed, 23 Apr 2008 20:21:36 +0000 Subject: [PATCH] Add support for ISO base media file format git-svn-id: http://php-reader.googlecode.com/svn/trunk@85 51a70ab9-7547-0410-9469-37e369ee0574 --- src/ISO14496.php | 79 ++++++++++++ src/ISO14496/Box.php | 252 +++++++++++++++++++++++++++++++++++++ src/ISO14496/Box/BXML.php | 87 +++++++++++++ src/ISO14496/Box/CDSC.php | 80 ++++++++++++ src/ISO14496/Box/CO64.php | 99 +++++++++++++++ src/ISO14496/Box/CPRT.php | 96 ++++++++++++++ src/ISO14496/Box/CTTS.php | 95 ++++++++++++++ src/ISO14496/Box/DINF.php | 67 ++++++++++ src/ISO14496/Box/DREF.php | 88 +++++++++++++ src/ISO14496/Box/EDTS.php | 72 +++++++++++ src/ISO14496/Box/ELST.php | 108 ++++++++++++++++ src/ISO14496/Box/FREE.php | 57 +++++++++ src/ISO14496/Box/FRMA.php | 78 ++++++++++++ src/ISO14496/Box/FTYP.php | 142 +++++++++++++++++++++ src/ISO14496/Box/Full.php | 96 ++++++++++++++ src/ISO14496/Box/HDLR.php | 107 ++++++++++++++++ src/ISO14496/Box/HINT.php | 81 ++++++++++++ src/ISO14496/Box/HMHD.php | 110 ++++++++++++++++ src/ISO14496/Box/IINF.php | 73 +++++++++++ src/ISO14496/Box/ILOC.php | 134 ++++++++++++++++++++ src/ISO14496/Box/IMIF.php | 87 +++++++++++++ src/ISO14496/Box/INFE.php | 130 +++++++++++++++++++ src/ISO14496/Box/IPMC.php | 56 +++++++++ src/ISO14496/Box/IPRO.php | 68 ++++++++++ src/ISO14496/Box/MDAT.php | 66 ++++++++++ src/ISO14496/Box/MDHD.php | 136 ++++++++++++++++++++ src/ISO14496/Box/MDIA.php | 67 ++++++++++ src/ISO14496/Box/MEHD.php | 84 +++++++++++++ src/ISO14496/Box/META.php | 86 +++++++++++++ src/ISO14496/Box/MFHD.php | 80 ++++++++++++ src/ISO14496/Box/MFRA.php | 81 ++++++++++++ src/ISO14496/Box/MFRO.php | 85 +++++++++++++ src/ISO14496/Box/MINF.php | 55 ++++++++ src/ISO14496/Box/MOOF.php | 77 ++++++++++++ src/ISO14496/Box/MOOV.php | 68 ++++++++++ src/ISO14496/Box/MVEX.php | 70 +++++++++++ src/ISO14496/Box/MVHD.php | 166 ++++++++++++++++++++++++ src/ISO14496/Box/NMHD.php | 55 ++++++++ src/ISO14496/Box/PADB.php | 57 +++++++++ src/ISO14496/Box/PDIN.php | 97 ++++++++++++++ src/ISO14496/Box/PITM.php | 86 +++++++++++++ src/ISO14496/Box/SCHI.php | 70 +++++++++++ src/ISO14496/Box/SCHM.php | 103 +++++++++++++++ src/ISO14496/Box/SDTP.php | 127 +++++++++++++++++++ src/ISO14496/Box/SGPD.php | 64 ++++++++++ src/ISO14496/Box/SINF.php | 83 ++++++++++++ src/ISO14496/Box/SKIP.php | 69 ++++++++++ src/ISO14496/Box/SMHD.php | 66 ++++++++++ src/ISO14496/Box/STBL.php | 86 +++++++++++++ src/ISO14496/Box/STCO.php | 99 +++++++++++++++ src/ISO14496/Box/STDP.php | 84 +++++++++++++ src/ISO14496/Box/STGP.php | 128 +++++++++++++++++++ src/ISO14496/Box/STSC.php | 105 ++++++++++++++++ src/ISO14496/Box/STSD.php | 56 +++++++++ src/ISO14496/Box/STSH.php | 113 +++++++++++++++++ src/ISO14496/Box/STSS.php | 88 +++++++++++++ src/ISO14496/Box/STSZ.php | 106 ++++++++++++++++ src/ISO14496/Box/STTS.php | 106 ++++++++++++++++ src/ISO14496/Box/STZ2.php | 106 ++++++++++++++++ src/ISO14496/Box/SUBS.php | 138 ++++++++++++++++++++ src/ISO14496/Box/TFHD.php | 190 ++++++++++++++++++++++++++++ src/ISO14496/Box/TFRA.php | 142 +++++++++++++++++++++ src/ISO14496/Box/TKHD.php | 177 ++++++++++++++++++++++++++ src/ISO14496/Box/TRAF.php | 73 +++++++++++ src/ISO14496/Box/TRAK.php | 79 ++++++++++++ src/ISO14496/Box/TREF.php | 77 ++++++++++++ src/ISO14496/Box/TREX.php | 138 ++++++++++++++++++++ src/ISO14496/Box/TRUN.php | 149 ++++++++++++++++++++++ src/ISO14496/Box/UDTA.php | 71 +++++++++++ src/ISO14496/Box/URL.php | 83 ++++++++++++ src/ISO14496/Box/URN.php | 94 ++++++++++++++ src/ISO14496/Box/VMHD.php | 65 ++++++++++ src/ISO14496/Box/XML.php | 88 +++++++++++++ src/ISO14496/Exception.php | 51 ++++++++ 74 files changed, 7032 insertions(+) create mode 100644 src/ISO14496.php create mode 100644 src/ISO14496/Box.php create mode 100644 src/ISO14496/Box/BXML.php create mode 100644 src/ISO14496/Box/CDSC.php create mode 100644 src/ISO14496/Box/CO64.php create mode 100644 src/ISO14496/Box/CPRT.php create mode 100644 src/ISO14496/Box/CTTS.php create mode 100644 src/ISO14496/Box/DINF.php create mode 100644 src/ISO14496/Box/DREF.php create mode 100644 src/ISO14496/Box/EDTS.php create mode 100644 src/ISO14496/Box/ELST.php create mode 100644 src/ISO14496/Box/FREE.php create mode 100644 src/ISO14496/Box/FRMA.php create mode 100644 src/ISO14496/Box/FTYP.php create mode 100644 src/ISO14496/Box/Full.php create mode 100644 src/ISO14496/Box/HDLR.php create mode 100644 src/ISO14496/Box/HINT.php create mode 100644 src/ISO14496/Box/HMHD.php create mode 100644 src/ISO14496/Box/IINF.php create mode 100644 src/ISO14496/Box/ILOC.php create mode 100644 src/ISO14496/Box/IMIF.php create mode 100644 src/ISO14496/Box/INFE.php create mode 100644 src/ISO14496/Box/IPMC.php create mode 100644 src/ISO14496/Box/IPRO.php create mode 100644 src/ISO14496/Box/MDAT.php create mode 100644 src/ISO14496/Box/MDHD.php create mode 100644 src/ISO14496/Box/MDIA.php create mode 100644 src/ISO14496/Box/MEHD.php create mode 100644 src/ISO14496/Box/META.php create mode 100644 src/ISO14496/Box/MFHD.php create mode 100644 src/ISO14496/Box/MFRA.php create mode 100644 src/ISO14496/Box/MFRO.php create mode 100644 src/ISO14496/Box/MINF.php create mode 100644 src/ISO14496/Box/MOOF.php create mode 100644 src/ISO14496/Box/MOOV.php create mode 100644 src/ISO14496/Box/MVEX.php create mode 100644 src/ISO14496/Box/MVHD.php create mode 100644 src/ISO14496/Box/NMHD.php create mode 100644 src/ISO14496/Box/PADB.php create mode 100644 src/ISO14496/Box/PDIN.php create mode 100644 src/ISO14496/Box/PITM.php create mode 100644 src/ISO14496/Box/SCHI.php create mode 100644 src/ISO14496/Box/SCHM.php create mode 100644 src/ISO14496/Box/SDTP.php create mode 100644 src/ISO14496/Box/SGPD.php create mode 100644 src/ISO14496/Box/SINF.php create mode 100644 src/ISO14496/Box/SKIP.php create mode 100644 src/ISO14496/Box/SMHD.php create mode 100644 src/ISO14496/Box/STBL.php create mode 100644 src/ISO14496/Box/STCO.php create mode 100644 src/ISO14496/Box/STDP.php create mode 100644 src/ISO14496/Box/STGP.php create mode 100644 src/ISO14496/Box/STSC.php create mode 100644 src/ISO14496/Box/STSD.php create mode 100644 src/ISO14496/Box/STSH.php create mode 100644 src/ISO14496/Box/STSS.php create mode 100644 src/ISO14496/Box/STSZ.php create mode 100644 src/ISO14496/Box/STTS.php create mode 100644 src/ISO14496/Box/STZ2.php create mode 100644 src/ISO14496/Box/SUBS.php create mode 100644 src/ISO14496/Box/TFHD.php create mode 100644 src/ISO14496/Box/TFRA.php create mode 100644 src/ISO14496/Box/TKHD.php create mode 100644 src/ISO14496/Box/TRAF.php create mode 100644 src/ISO14496/Box/TRAK.php create mode 100644 src/ISO14496/Box/TREF.php create mode 100644 src/ISO14496/Box/TREX.php create mode 100644 src/ISO14496/Box/TRUN.php create mode 100644 src/ISO14496/Box/UDTA.php create mode 100644 src/ISO14496/Box/URL.php create mode 100644 src/ISO14496/Box/URN.php create mode 100644 src/ISO14496/Box/VMHD.php create mode 100644 src/ISO14496/Box/XML.php create mode 100644 src/ISO14496/Exception.php diff --git a/src/ISO14496.php b/src/ISO14496.php new file mode 100644 index 0000000..ec8e4a9 --- /dev/null +++ b/src/ISO14496.php @@ -0,0 +1,79 @@ + + * @copyright Copyright (c) 2008 PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +class ISO14496 extends ISO14496_Box +{ + public function __construct($filename) + { + $this->_reader = new Reader($filename); + $this->_offset = 0; + $this->_size = $this->_reader->getSize(); + $this->_type = "file"; + $this->_container = true; + $this->constructBoxes(); + } +} diff --git a/src/ISO14496/Box.php b/src/ISO14496/Box.php new file mode 100644 index 0000000..3de1aaa --- /dev/null +++ b/src/ISO14496/Box.php @@ -0,0 +1,252 @@ + + * @copyright Copyright (c) 2008 PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +class ISO14496_Box +{ + /** + * The reader object. + * + * @var Reader + */ + protected $_reader; + + /** + * The file offset to box start. + * + * @var integer + */ + protected $_offset; + + /** + * The object size in bytes, including the size and type header, fields, and + * all contained boxes. + * + * @var integer + */ + protected $_size; + + /** @var string */ + protected $_type; + + + /** @var boolean */ + protected $_container = false; + + /** + * An array of boxes the box contains. + * + * @var Array + */ + protected $_boxes = array(); + + + /** + * Constructs the class with given parameters. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + $this->_reader = $reader; + $this->_offset = $this->_reader->getOffset(); + $this->_size = $this->_reader->readUInt32BE(); + $this->_type = $this->_reader->read(4); + + if ($this->_size == 1) + $this->_size = $this->_reader->readInt64BE(); + if ($this->_size == 0) + $this->_size = $this->_reader->getSize() - $offset; + + if ($this->_type == "uuid") + $this->_type = $this->_reader->readGUID(); + } + + /** + * Returns the type of the ISO base media file object. + * + * @return string + */ + public function getType() { return $this->_type; } + + /** + * Returns a boolean value corresponding to whether the box is a container. + * + * @return boolean + */ + public function isContainer() { return $this->_container; } + + /** + * Returns a boolean value corresponding to whether the box is a container. + * + * @return boolean + */ + public function getContainer() { return $this->_container; } + + /** + * Sets whether the box is a container. + * + * @param boolean $container Whether the box is a container. + */ + protected function setContainer($container) + { + $this->_container = $container; + } + + /** + * Reads and constructs the boxes found within this box. + */ + protected function constructBoxes($defaultclassname = "ISO14496_Box") + { + while (true) { + $offset = $this->_reader->getOffset(); + if ($offset >= $this->_offset + $this->_size) + break; + $size = $this->_reader->readUInt32BE(); + $type = $this->_reader->read(4); + if ($size == 1) + $size = $this->_reader->readInt64BE(); + if ($size == 0) + $size = $this->_reader->getSize() - $offset; + $this->_reader->setOffset($offset); + + if (@fopen($filename = "ISO14496/Box/" . strtoupper($type) . ".php", + "r", true) !== false) + require_once($filename); + if (class_exists($classname = "ISO14496_Box_" . strtoupper($type))) + $box = new $classname($this->_reader); + else + $box = new $defaultclassname($this->_reader); + + if (!isset($this->_boxes[$type])) + $this->_boxes[$type] = array(); + $this->_boxes[$type][] = $box; + + $this->_reader->setOffset($offset + $size); + } + } + + /** + * Checks whether the box given as an argument is present in the file. Returns + * true if one or more boxes are present, false + * otherwise. + * + * @return boolean + * @throws ISO14496_Exception if called on a non-container box + */ + public function hasBox($identifier) + { + if (!$this->isContainer()) + throw new ISO14496_Exception("Box not a container"); + return isset($this->_boxes[$identifier]); + } + + /** + * Returns all the boxes the file contains as an associate array. The box + * identifiers work as keys having an array of boxes as associated value. + * + * @return Array + * @throws ISO14496_Exception if called on a non-container box + */ + public function getBoxes() + { + if (!$this->isContainer()) + throw new ISO14496_Exception("Box not a container"); + return $this->_boxes; + } + + /** + * Returns an array of boxes matching the given identifier or an empty array + * if no boxes matched the identifier. + * + * The identifier may contain wildcard characters "*" and "?". The asterisk + * matches against zero or more characters, and the question mark matches any + * single character. + * + * Please note that one may also use the shorthand $obj->identifier to access + * the first box with the identifier given. Wildcards cannot be used with + * the shorthand and they will not work with user defined uuid types. + * + * @return Array + * @throws ISO14496_Exception if called on a non-container box + */ + public function getBoxesByIdentifier($identifier) + { + if (!$this->isContainer()) + throw new ISO14496_Exception("Box not a container"); + $matches = array(); + $searchPattern = "/^" . + str_replace(array("*", "?"), array(".*", "."), $identifier) . "$/i"; + foreach ($this->_boxes as $identifier => $boxes) + if (preg_match($searchPattern, $identifier)) + foreach ($boxes as $box) + $boxes[] = $box; + return $boxes; + } + + /** + * Magic function so that $obj->value will work. If called on a container box, + * the method will first attempt to return the first contained box that + * matches the identifier, and if not found, invoke a getter method. + * + * If there are no boxes or getter methods with given name, the method + * will yield an exception. + * + * @param string $name The box or field name. + * @return mixed + */ + public function __get($name) { + if ($this->isContainer() && isset($this->_boxes[$name])) + return $this->_boxes[$name][0]; + if (method_exists($this, "get" . ucfirst($name))) + return call_user_func(array($this, "get" . ucfirst($name))); + throw new ISO14496_Exception("Unknown box/field: " . $name); + } +} diff --git a/src/ISO14496/Box/BXML.php b/src/ISO14496/Box/BXML.php new file mode 100644 index 0000000..e0c7f82 --- /dev/null +++ b/src/ISO14496/Box/BXML.php @@ -0,0 +1,87 @@ +XML Box forms may be used. + * The Binary XML Box may only be used when there is a single well-defined + * binarization of the XML for that defined format as identified by the handler. + * + * Within an XML box the data is in UTF-8 format unless the data starts with a + * byte-order-mark (BOM), which indicates that the data is in UTF-16 format. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_BXML extends ISO14496_Box_Full +{ + /** @var string */ + private $_data; + + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + * @todo The sample flags could be parsed further + */ + public function __construct($reader) + { + parent::__construct($reader); + + $this->_data = $this->_reader->read + ($this->_offset + $this->_size - $this->_reader->getOffset()); + } + + /** + * Returns the binary data. + * + * @return string + */ + public function getData() + { + return $this->_data; + } +} diff --git a/src/ISO14496/Box/CDSC.php b/src/ISO14496/Box/CDSC.php new file mode 100644 index 0000000..3369235 --- /dev/null +++ b/src/ISO14496/Box/CDSC.php @@ -0,0 +1,80 @@ + + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_CDSC extends ISO14496_Box +{ + /** @var Array */ + private $_trackId = array(); + + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + + while ($this->_reader->getOffset <= $this->_size) + $this->_trackId[] = $this->_reader->readUInt32BE(); + } + + /** + * Returns an array of integer references from the containing track to another + * track in the presentation. Track IDs are never re-used and cannot be equal + * to zero. + * + * @return integer + */ + public function getTrackId() { return $this->_trackId; } +} diff --git a/src/ISO14496/Box/CO64.php b/src/ISO14496/Box/CO64.php new file mode 100644 index 0000000..ea62212 --- /dev/null +++ b/src/ISO14496/Box/CO64.php @@ -0,0 +1,99 @@ +Chunk Offset Box table gives the index of each chunk into the + * containing file. There are two variants, permitting the use of 32-bit or + * 64-bit offsets. The latter is useful when managing very large presentations. + * At most one of these variants will occur in any single instance of a sample + * table. + * + * Offsets are file offsets, not the offset into any box within the file (e.g. + * {@link ISO14496_Box_MDAT Media Data Box}). This permits referring to media + * data in files without any box structure. It does also mean that care must be + * taken when constructing a self-contained ISO file with its metadata + * ({@link ISO14496_Box_MOOV Movie Box}) at the front, as the size of the + * {@link ISO14496_Box_MOOV Movie Box} will affect the chunk offsets to the + * media data. + * + * This box variant contains 64-bit offsets. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_CO64 extends ISO14496_Box_Full +{ + /** @var Array */ + private $_chunkOffsetTable = array(); + + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + + $entryCount = $this->_reader->readUInt32BE(); + for ($i = 1; $i < $entryCount; $i++) + $this->_chunkOffsetTable[$i] = array + ("chunkOffset" => $this->_reader->readInt64BE()); + } + + /** + * Returns an array of values. Each entry is an array containing the following + * keys. + * o chunkOffset -- a 64 bit integer that gives the offset of the start of a + * chunk into its containing media file. + * + * @return Array + */ + public function getChunkOffsetTable() + { + return $this->_chunkOffsetTable; + } +} diff --git a/src/ISO14496/Box/CPRT.php b/src/ISO14496/Box/CPRT.php new file mode 100644 index 0000000..b8c69f6 --- /dev/null +++ b/src/ISO14496/Box/CPRT.php @@ -0,0 +1,96 @@ +Copyright Box contains a copyright declaration which applies to + * the entire presentation, when contained within the {@link ISO14496_Box_MOOV + * Movie Box}, or, when contained in a track, to that entire track. There may be + * multiple copyright boxes using different language codes. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_CPRT extends ISO14496_Box_Full +{ + /** @var string */ + private $_language; + + /** @var string */ + private $_notice; + + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + * @todo Distinguish UTF-16? + */ + public function __construct($reader) + { + parent::__construct($reader); + + $this->_language = + chr(((($tmp = $this->_reader->readUInt16BE()) >> 10) & 0x1f) + 0x60) . + chr((($tmp >> 5) & 0x1f) + 0x60) . chr(($tmp & 0x1f) + 0x60); + $this->_notice = $this->_reader->read + ($this->_offset + $this->_size - $this->_reader->getOffset()); + } + + /** + * Returns the three byte language code to describe the language of the + * notice, according to {@link http://www.loc.gov/standards/iso639-2/ + * ISO 639-2/T}. + * + * @return string + */ + public function getLanguage() { return $this->_language; } + + /** + * Returns the copyright notice. + * + * @return string + */ + public function getNotice() { return $this->_notice; } +} diff --git a/src/ISO14496/Box/CTTS.php b/src/ISO14496/Box/CTTS.php new file mode 100644 index 0000000..b986a31 --- /dev/null +++ b/src/ISO14496/Box/CTTS.php @@ -0,0 +1,95 @@ +Composition Time to Sample Box provides the offset between + * decoding time and composition time. Since decoding time must be less than the + * composition time, the offsets are expressed as unsigned numbers such that + * CT(n) = DT(n) + CTTS(n) where CTTS(n) is the (uncompressed) table entry for + * sample n. + * + * The composition time to sample table is optional and must only be present if + * DT and CT differ for any samples. Hint tracks do not use this box. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_CTTS extends ISO14496_Box_Full +{ + /** @var Array */ + private $_compositionOffsetTable = array(); + + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + + $entryCount = $this->_reader->readUInt32BE(); + for ($i = 1; $i < $entryCount; $i++) + $this->_compositionOffsetTable[$i] = array + ("sampleCount" => $this->_reader->readUInt32BE(), + "sampleOffset" => $this->_reader->readUInt32BE()); + } + + /** + * Returns an array of values. Each entry is an array containing the following + * keys. + * o sampleCount -- an integer that counts the number of consecutive samples + * that have the given offset. + * o sampleOffset -- a non-negative integer that gives the offset between CT + * and DT, such that CT(n) = DT(n) + CTTS(n). + * + * @return Array + */ + public function getCompositionOffsetTable() + { + return $this->_compositionOffsetTable; + } +} diff --git a/src/ISO14496/Box/DINF.php b/src/ISO14496/Box/DINF.php new file mode 100644 index 0000000..da969b4 --- /dev/null +++ b/src/ISO14496/Box/DINF.php @@ -0,0 +1,67 @@ +Data Information Box contains objects that declare the location + * of the media information in a track. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_DINF extends ISO14496_Box +{ + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + $this->setContainer(true); + $this->constructBoxes(); + } +} diff --git a/src/ISO14496/Box/DREF.php b/src/ISO14496/Box/DREF.php new file mode 100644 index 0000000..9e59a2d --- /dev/null +++ b/src/ISO14496/Box/DREF.php @@ -0,0 +1,88 @@ +Data Reference Box contains a table of data references (normally + * URLs) that declare the location(s) of the media data used within the + * presentation. The data reference index in the sample description ties entries + * in this table to the samples in the track. A track may be split over several + * sources in this way. + * + * This box may either contain {@link ISO14496_Box_URN urn} or + * {@link ISO14496_Box_URL url} boxes. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_DREF extends ISO14496_Box_Full +{ + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + $this->setContainer(true); + $count = $this->_reader->readUInt32BE(); + for ($i = 0; $i < $count; $i++) { + $offset = $this->_reader->getOffset(); + $size = $this->_reader->readUInt32BE(); + $type = $this->_reader->read(4); + $this->_reader->setOffset($offset); + if ($type == "url ") { + require_once("ISO14496/Box/URL.php"); + $this->_boxes[] = new ISO14496_Box_URL($this->_reader); + } + if ($type == "urn ") { + require_once("ISO14496/Box/URN.php"); + $this->_boxes[] = new ISO14496_Box_URN($this->_reader); + } + $this->_reader->setOffset($offset + $size); + } + } +} diff --git a/src/ISO14496/Box/EDTS.php b/src/ISO14496/Box/EDTS.php new file mode 100644 index 0000000..322c992 --- /dev/null +++ b/src/ISO14496/Box/EDTS.php @@ -0,0 +1,72 @@ +Edit Box maps the presentation time-line to the media time-line as + * it is stored in the file. The Edit Box is a container for the edit lists. + * + * The Edit Box is optional. In the absence of this box, there is an implicit + * one-to-one mapping of these time-lines, and the presentation of a track + * starts at the beginning of the presentation. An empty edit is used to offset + * the start time of a track. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_EDTS extends ISO14496_Box +{ + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + $this->setContainer(true); + $this->constructBoxes(); + } +} diff --git a/src/ISO14496/Box/ELST.php b/src/ISO14496/Box/ELST.php new file mode 100644 index 0000000..1e80958 --- /dev/null +++ b/src/ISO14496/Box/ELST.php @@ -0,0 +1,108 @@ +Edit List Box contains an explicit timeline map. Each entry + * defines part of the track time-line: by mapping part of the media time-line, + * or by indicating empty time, or by defining a dwell, where a single + * time-point in the media is held for a period. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_ELST extends ISO14496_Box_Full +{ + /** @var Array */ + private $_entries = array(); + + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + + $entryCount = $this->_reader->readUInt32BE(); + for ($i = 1; $i <= $entryCount; $i++) { + $entry = array(); + if ($this->getVersion() == 1) { + $entry["segmentDuration"] = $this->_reader->readInt64BE(); + $entry["mediaTime"] = $this->_reader->readInt64BE(); + } else { + $entry["segmentDuration"] = $this->_reader->readUInt32BE(); + $entry["mediaTime"] = $this->_reader->readInt32BE(); + } + $entry["mediaRate"] = $this->_reader->readInt16BE() + + $this->_reader->readInt16BE() / 10; + $this->_entries[] = $entry; + } + } + + /** + * Returns an array of entries. Each entry is an array containing the + * following keys. + * o segmentDuration: specifies the duration of this edit segment in units + * of the timescale in the {@link ISO14496_Box_MVHD Movie Header Box}. + * o mediaTime: the starting time within the media of this edit segment (in + * media time scale units, in composition time). If this field is set to + * –1, it is an empty edit. The last edit in a track shall never be an + * empty edit. Any difference between the duration in the + * {@link ISO14496_Box_MVHD Movie Header Box}, and the track’s duration is + * expressed as an implicit empty edit at the end. + * o mediaRate: the relative rate at which to play the media corresponding + * to this edit segment. If this value is 0, then the edit is specifying + * a dwell: the media at media-time is presented for the segment-duration. + * Otherwise this field shall contain the value 1. + * + * @return Array + */ + public function getEntries() + { + return $this->_entries; + } +} diff --git a/src/ISO14496/Box/FREE.php b/src/ISO14496/Box/FREE.php new file mode 100644 index 0000000..dcf9607 --- /dev/null +++ b/src/ISO14496/Box/FREE.php @@ -0,0 +1,57 @@ +Free Space Box are irrelevant and may be ignored, or + * the object deleted, without affecting the presentation. (Care should be + * exercised when deleting the object, as this may invalidate the offsets used + * in the sample table, unless this object is after all the media data). + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_FREE extends ISO14496_Box +{ +} diff --git a/src/ISO14496/Box/FRMA.php b/src/ISO14496/Box/FRMA.php new file mode 100644 index 0000000..8d6d2cb --- /dev/null +++ b/src/ISO14496/Box/FRMA.php @@ -0,0 +1,78 @@ +Original Format Box contains the four-character-code of the + * original un-transformed sample description. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_FRMA extends ISO14496_Box +{ + /** @var string */ + private $_dataFormat; + + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + + $this->_dataFormat = $this->_reader->read(4); + } + + /** + * Returns the four-character-code of the original un-transformed sample entry + * (e.g. mp4v if the stream contains protected MPEG-4 visual material). + * + * @return string + */ + public function getDataFormat() { return $this->_dataFormat; } +} diff --git a/src/ISO14496/Box/FTYP.php b/src/ISO14496/Box/FTYP.php new file mode 100644 index 0000000..1e40ce3 --- /dev/null +++ b/src/ISO14496/Box/FTYP.php @@ -0,0 +1,142 @@ +File Type Box is placed as early as possible in the file (e.g. + * after any obligatory signature, but before any significant variable-size + * boxes such as a {@link ISO14496_Box_MOOV Movie Box}, {@link ISO14496_Box_MDAT + * Media Data Box}, or {@link ISO14496_Box_FREE Free Space}). It identifies + * which specification is the best use of the file, and a minor version + * of that specification; and also a set of others specifications to which the + * file complies. + * + * The minor version is informative only. It does not appear for + * compatible-brands, and must not be used to determine the conformance of a + * file to a standard. It may allow more precise identification of the major + * specification, for inspection, debugging, or improved decoding. + * + * The type isom (ISO Base Media file) is defined as identifying files + * that conform to the first version of the ISO Base Media File Format. More + * specific identifiers can be used to identify precise versions of + * specifications providing more detail. This brand is not be used as the major + * brand; this base file format should be derived into another specification to + * be used. There is therefore no defined normal file extension, or mime type + * assigned to this brand, nor definition of the minor version when isom + * is the major brand. + * + * Files would normally be externally identified (e.g. with a file extension or + * mime type) that identifies the best use (major brand), or the brand + * that the author believes will provide the greatest compatibility. + * + * The brand iso2 shall be used to indicate compatibility with the + * amended version of the ISO Base Media File Format; it may be used in addition + * to or instead of the isom brand and the same usage rules apply. If + * used without the brand isom identifying the first version of the + * specification, it indicates that support for some or all of the technology + * introduced by the amended version of the ISO Base Media File Format is + * required. + * + * The brand avc1 shall be used to indicate that the file is conformant + * with the AVC Extensions. If used without other brands, this implies + * that support for those extensions is required. The use of avc1 as a + * major-brand may be permitted by specifications; in that case, that + * specification defines the file extension and required behavior. + * + * If a Meta-box with an MPEG-7 handler type is used at the file level, then the + * brand mp71 is a member of the compatible-brands list in the file-type + * box. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_FTYP extends ISO14496_Box +{ + /** @var integer */ + private $_majorBrand; + + /** @var integer */ + private $_minorVersion; + + /** @var integer */ + private $_compatibleBrands = array(); + + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + + $this->_majorBrand = $this->_reader->readString8(4); + $this->_minorVersion = $this->_reader->readUInt32BE(); + while ($this->_reader->getOffset() < $this->_size) + if (($brand = $this->_reader->readString8(4)) != "") + $this->_compatibleBrands[] = $brand; + } + + /** + * Returns the major version brand. + * + * @return string + */ + public function getMajorBrand() { return $this->_majorBrand; } + + /** + * Returns the minor version number. + * + * @return integer + */ + public function getMinorVersion() { return $this->_minorVersion; } + + /** + * Returns the array of compatible version brands. + * + * @return Array + */ + public function getCompatibleBrands() { return $this->_compatibleBrands; } +} diff --git a/src/ISO14496/Box/Full.php b/src/ISO14496/Box/Full.php new file mode 100644 index 0000000..094cfff --- /dev/null +++ b/src/ISO14496/Box/Full.php @@ -0,0 +1,96 @@ + + * @copyright Copyright (c) 2008 PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +abstract class ISO14496_Box_Full extends ISO14496_Box +{ + /** @var integer */ + protected $_version; + + /** @var integer */ + protected $_flags; + + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + + $this->_version = (($field = $this->_reader->readUInt32BE()) >> 24) & 0xff; + $this->_flags = $field & 0xffffff; + } + + /** + * Returns the version of this format of the box. + * + * @return integer + */ + public function getVersion() { return $this->_version; } + + /** + * Checks whether or not the flag is set. Returns true if the flag + * is set, false otherwise. + * + * @param integer $flag The flag to query. + * @return boolean + */ + public function hasFlag($flag) { return ($this->_flags & $flag) == $flag; } + + /** + * Returns the map of flags. + * + * @return integer + */ + public function getFlags() { return $this->_flags; } +} diff --git a/src/ISO14496/Box/HDLR.php b/src/ISO14496/Box/HDLR.php new file mode 100644 index 0000000..f2e0e00 --- /dev/null +++ b/src/ISO14496/Box/HDLR.php @@ -0,0 +1,107 @@ +Handler Reference Box is within a {@link ISO14496_Box_MDIA Media + * Box} declares the process by which the media-data in the track is presented, + * and thus, the nature of the media in a track. For example, a video track + * would be handled by a video handler. + * + * This box when present within a {@link ISO14496_Box_META Meta Box}, declares + * the structure or format of the meta box contents. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_HDLR extends ISO14496_Box_Full +{ + /** @var string */ + private $_handlerType; + + /** @var string */ + private $_name; + + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + + $this->_reader->skip(4); + $this->_handlerType = $this->_reader->read(4); + $this->_reader->skip(12); + $this->_name = $this->_reader->read + ($this->_offset + $this->_size - $this->_reader->getOffset()); + } + + /** + * Returns the handler type. + * + * When present in a media box, the returned value contains one of the + * following values, or a value from a derived specification: + * o vide Video track + * o soun Audio track + * o hint Hint track + * + * When present in a meta box, the returned value contains an appropriate + * value to indicate the format of the meta box contents. + * + * @return integer + */ + public function getHandlerType() { return $this->_handlerType; } + + /** + * Returns the name string. The name is in UTF-8 characters and gives a + * human-readable name for the track type (for debugging and inspection + * purposes). + * + * @return integer + */ + public function getName() { return $this->_name; } +} diff --git a/src/ISO14496/Box/HINT.php b/src/ISO14496/Box/HINT.php new file mode 100644 index 0000000..365618a --- /dev/null +++ b/src/ISO14496/Box/HINT.php @@ -0,0 +1,81 @@ + + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_HINT extends ISO14496_Box +{ + /** @var Array */ + private $_trackId = array(); + + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + + while ($this->_reader->getOffset <= $this->_size) + $this->_trackId[] = $this->_reader->readUInt32BE(); + } + + /** + * Returns an array of integer references from the containing track to another + * track in the presentation. Track IDs are never re-used and cannot be equal + * to zero. + * + * @return integer + */ + public function getTrackId() { return $this->_trackId; } +} diff --git a/src/ISO14496/Box/HMHD.php b/src/ISO14496/Box/HMHD.php new file mode 100644 index 0000000..49ca254 --- /dev/null +++ b/src/ISO14496/Box/HMHD.php @@ -0,0 +1,110 @@ +Hint Media Header Box header contains general information, + * independent of the protocol, for hint tracks. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_HMHD extends ISO14496_Box_Full +{ + /** @var integer */ + private $_maxPDUSize; + + /** @var integer */ + private $_avgPDUSize; + + /** @var integer */ + private $_maxBitrate; + + /** @var integer */ + private $_avgBitrate; + + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + + $this->_maxPDUSize = $this->_reader->readUInt16BE(); + $this->_avgPDUSize = $this->_reader->readUInt16BE(); + $this->_maxBitrate = $this->_reader->readUInt32BE(); + $this->_avgBitrate = $this->_reader->readUInt32BE(); + } + + /** + * Returns the size in bytes of the largest PDU in this (hint) stream. + * + * @return integer + */ + public function getMaxPDUSize() { return $this->_maxPDUSize; } + + /** + * Returns the average size of a PDU over the entire presentation. + * + * @return integer + */ + public function getAvgPDUSize() { return $this->_avgPDUSize; } + + /** + * Returns the maximum rate in bits/second over any window of one second. + * + * @return integer + */ + public function getMaxBitrate() { return $this->_maxbitrate; } + + /** + * Returns the average rate in bits/second over the entire presentation. + * + * @return integer + */ + public function getAvgBitrate() { return $this->_maxbitrate; } +} diff --git a/src/ISO14496/Box/IINF.php b/src/ISO14496/Box/IINF.php new file mode 100644 index 0000000..1f96b4d --- /dev/null +++ b/src/ISO14496/Box/IINF.php @@ -0,0 +1,73 @@ +Item Information Box provides extra information about selected + * items, including symbolic (file) names. It may optionally occur, but + * if it does, it must be interpreted, as item protection or content encoding + * may have changed the format of the data in the item. If both content encoding + * and protection are indicated for an item, a reader should first un-protect + * the item, and then decode the item's content encoding. If more control is + * needed, an IPMP sequence code may be used. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_IINF extends ISO14496_Box +{ + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + $this->_reader->skip(2); + $this->setContainer(true); + $this->constructBoxes(); + } +} diff --git a/src/ISO14496/Box/ILOC.php b/src/ISO14496/Box/ILOC.php new file mode 100644 index 0000000..62d9dbe --- /dev/null +++ b/src/ISO14496/Box/ILOC.php @@ -0,0 +1,134 @@ +The Item Location Box provides a directory of resources in this or + * other files, by locating their containing file, their offset within that + * file, and their length. Placing this in binary format enables common handling + * of this data, even by systems which do not understand the particular metadata + * system (handler) used. For example, a system might integrate all the + * externally referenced metadata resources into one file, re-adjusting file + * offsets and file references accordingly. + * + * Items may be stored fragmented into extents, e.g. to enable interleaving. An + * extent is a contiguous subset of the bytes of the resource; the resource is + * formed by concatenating the extents. If only one extent is used then either + * or both of the offset and length may be implied: + * + * o If the offset is not identified (the field has a length of zero), then + * the beginning of the file (offset 0) is implied. + * o If the length is not specified, or specified as zero, then the entire + * file length is implied. References into the same file as this metadata, + * or items divided into more than one extent, should have an explicit + * offset and length, or use a MIME type requiring a different + * interpretation of the file, to avoid infinite recursion. + * + * The size of the item is the sum of the extentLengths. Note: extents may be + * interleaved with the chunks defined by the sample tables of tracks. + * + * The dataReferenceIndex may take the value 0, indicating a reference into the + * same file as this metadata, or an index into the dataReference table. + * + * Some referenced data may itself use offset/length techniques to address + * resources within it (e.g. an MP4 file might be included in this way). + * Normally such offsets are relative to the beginning of the containing file. + * The field base offset provides an additional offset for offset calculations + * within that contained data. For example, if an MP4 file is included within a + * file formatted to this specification, then normally data-offsets within that + * MP4 section are relative to the beginning of file; baseOffset adds to those + * offsets. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_ILOC extends ISO14496_Box +{ + /** @var Array */ + private $_items = array(); + + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + + $offsetSize = (($tmp = $this->_reader->readUInt32BE()) >> 28) & 0xf; + $lengthSize = ($tmp >> 24) & 0xf; + $baseOffsetSize = ($tmp >> 20) & 0xf; + $itemCount = $this->_reader->readUInt16BE(); + for ($i = 0; $i < $itemCount; $i++) { + $item = array(); + $item["itemId"] = $this->_reader->readUInt16BE(); + $item["dataReferenceIndex"] = $this->_reader->readUInt16BE(); + $item["baseOffset"] = + ($baseOffsetSize == 4 ? $this->_reader->readUInt32BE() : + ($baseOffsetSize == 8 ? $this->_reader->readInt64BE() : 0)); + $item["extents"] = array(); + for ($j = 0; $j < $extentCount; $j++) { + $extent = array(); + $extent["offset"] = + ($offsetSize == 4 ? $this->_reader->readUInt32BE() : + ($offsetSize == 8 ? $this->_reader->readInt64BE() : 0)); + $extent["length"] = + ($lengthSize == 4 ? $this->_reader->readUInt32BE() : + ($lengthSize == 8 ? $this->_reader->readInt64BE() : 0)); + $item["extents"][] = $extent; + } + $this->_items[] = $item; + } + } + + /** + * Returns the array of items. Each entry has the following keys set: itemId, + * dataReferenceIndex, baseOffset, and extents. + * + * @return Array + */ + public function getItems() { return $this->_items; } +} diff --git a/src/ISO14496/Box/IMIF.php b/src/ISO14496/Box/IMIF.php new file mode 100644 index 0000000..e42a32e --- /dev/null +++ b/src/ISO14496/Box/IMIF.php @@ -0,0 +1,87 @@ +IPMP Information Box contains IPMP Descriptors which document the + * protection applied to the stream. + * + * IPMP_Descriptor is defined in 14496-1. This is a part of the MPEG-4 object + * descriptors (OD) that describe how an object can be accessed and decoded. + * Here, in the ISO Base Media File Format, IPMP Descriptor can be carried + * directly in IPMP Information Box without the need for OD stream. + * + * The presence of IPMP Descriptor in this box indicates the associated media + * stream is protected by the IPMP Tool described in the IPMP Descriptor. + * + * Each IPMP_Descriptor has an IPMP_ToolID, which identifies the required IPMP + * tool for protection. An independent registration authority (RA) is used so + * any party can register its own IPMP Tool and identify this without + * collisions. + * + * The IPMP_Descriptor carries IPMP information for one or more IPMP Tool + * instances, it includes but not limited to IPMP Rights Data, IPMP Key Data, + * Tool Configuration Data, etc. + * + * More than one IPMP Descriptors can be carried in this box if this media + * stream is protected by more than one IPMP Tools. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_IMIF extends ISO14496_Box +{ + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + $this->setContainer(true); + $this->constructBoxes(); + } +} diff --git a/src/ISO14496/Box/INFE.php b/src/ISO14496/Box/INFE.php new file mode 100644 index 0000000..d48d6fa --- /dev/null +++ b/src/ISO14496/Box/INFE.php @@ -0,0 +1,130 @@ +Item Information Entry Box contains the entry information. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_INFE extends ISO14496_Box_Full +{ + /** @var integer */ + private $_itemId; + + /** @var integer */ + private $_itemProtectionIndex; + + /** @var string */ + private $_itemName; + + /** @var string */ + private $_contentType; + + /** @var string */ + private $_contentEncoding; + + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + + $this->_itemId = $this->_reader->readUInt16BE(); + $this->_itemProtectionIndex = $this->_reader->readUInt16BE(); + list($this->_itemName, $this->_contentType, $this->_contentEncoding) = + preg_split("/\\x00/", $this->_reader->read + ($this->_offset + $this->_size - $this->_reader->getOffset())); + } + + /** + * Returns the item identifier. The value is either 0 for the primary resource + * (e.g. the XML contained in an {@link ISO14496_Box_XML XML Box}) or the ID + * of the item for which the following information is defined. + * + * @return integer + */ + public function getItemId() { return $this->_itemId; } + + /** + * Returns the item protection index. The value is either 0 for an unprotected + * item, or the one-based index into the {@link ISO14496_Box_IPRO Item + * Protection Box} defining the protection applied to this item (the first box + * in the item protection box has the index 1). + * + * @return integer + */ + public function getItemProtectionIndex() + { + return $this->_itemProtectionIndex; + } + + /** + * Returns the symbolic name of the item. + * + * @return string + */ + public function getItemName() { return $this->_itemName; } + + /** + * Returns the MIME type for the item. + * + * @return string + */ + public function getContentType() { return $this->_contentType; } + + /** + * Returns the optional content encoding type as defined for Content-Encoding + * for HTTP /1.1. Some possible values are gzip, compress and + * deflate. An empty string indicates no content encoding. + * + * @return string + */ + public function getContentEncoding() { return $this->_contentEncoding; } +} diff --git a/src/ISO14496/Box/IPMC.php b/src/ISO14496/Box/IPMC.php new file mode 100644 index 0000000..1d86051 --- /dev/null +++ b/src/ISO14496/Box/IPMC.php @@ -0,0 +1,56 @@ +IPMP Control Box may contain IPMP descriptors which may be + * referenced by any stream in the file. + * + * @todo Data parsing + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_IPMC extends ISO14496_Box_Full +{ +} diff --git a/src/ISO14496/Box/IPRO.php b/src/ISO14496/Box/IPRO.php new file mode 100644 index 0000000..45c4fce --- /dev/null +++ b/src/ISO14496/Box/IPRO.php @@ -0,0 +1,68 @@ +Item Protection Box provides an array of item protection + * information, for use by the {@link ISO14496_Box_IINF Item Information Box}. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_IPRO extends ISO14496_Box +{ + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + $this->_reader->skip(2); + $this->setContainer(true); + $this->constructBoxes(); + } +} diff --git a/src/ISO14496/Box/MDAT.php b/src/ISO14496/Box/MDAT.php new file mode 100644 index 0000000..a9f66b7 --- /dev/null +++ b/src/ISO14496/Box/MDAT.php @@ -0,0 +1,66 @@ +Media Data Box contains the media data. In video tracks, this box + * would contain video frames. There may be any number of these boxes in the + * file (including zero, if all the media data is in other files). + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_MDAT extends ISO14496_Box +{ + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + } +} diff --git a/src/ISO14496/Box/MDHD.php b/src/ISO14496/Box/MDHD.php new file mode 100644 index 0000000..b3c32f3 --- /dev/null +++ b/src/ISO14496/Box/MDHD.php @@ -0,0 +1,136 @@ +Media Header Box declares overall information that is + * media-independent, and relevant to characteristics of the media in a track. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_MDHD extends ISO14496_Box_Full +{ + /** @var integer */ + private $_creationTime; + + /** @var integer */ + private $_modificationTime; + + /** @var integer */ + private $_timescale; + + /** @var integer */ + private $_duration; + + /** @var string */ + private $_language; + + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + + if ($this->getVersion() == 1) { + $this->_creationTime = $this->_reader->readInt64BE(); + $this->_modificationTime = $this->_reader->readInt64BE(); + $this->_timescale = $this->_reader->readUInt32BE(); + $this->_duration = $this->_reader->readInt64BE(); + } else { + $this->_creationTime = $this->_reader->readUInt32BE(); + $this->_modificationTime = $this->_reader->readUInt32BE(); + $this->_timescale = $this->_reader->readUInt32BE(); + $this->_duration = $this->_reader->readUInt32BE(); + } + $this->_language = + chr(((($tmp = $this->_reader->readUInt16BE()) >> 10) & 0x1f) + 0x60) . + chr((($tmp >> 5) & 0x1f) + 0x60) . chr(($tmp & 0x1f) + 0x60); + } + + /** + * Returns the creation time of the media in this track, in seconds since + * midnight, Jan. 1, 1904, in UTC time. + * + * @return integer + */ + public function getCreationTime() { return $this->_creationTime; } + + /** + * Returns the most recent time the media in this track was modified in + * seconds since midnight, Jan. 1, 1904, in UTC time. + * + * @return integer + */ + public function getModificationTime() { return $this->_modificationTime; } + + /** + * Returns the time-scale for this media. This is the number of time units + * that pass in one second. For example, a time coordinate system that + * measures time in sixtieths of a second has a time scale of 60. + * + * @return integer + */ + public function getTimescale() { return $this->_timescale; } + + /** + * Returns the duration of this media (in the scale of the timescale). + * + * @return integer + */ + public function getDuration() { return $this->_duration; } + + /** + * Returns the three byte language code to describe the language of this + * media, according to {@link http://www.loc.gov/standards/iso639-2/ + * ISO 639-2/T}. + * + * @return string + */ + public function getLanguage() { return $this->_language; } +} diff --git a/src/ISO14496/Box/MDIA.php b/src/ISO14496/Box/MDIA.php new file mode 100644 index 0000000..c06df11 --- /dev/null +++ b/src/ISO14496/Box/MDIA.php @@ -0,0 +1,67 @@ +Media Box contains all the objects that declare information about + * the media data within a track. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_MDIA extends ISO14496_Box +{ + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + $this->setContainer(true); + $this->constructBoxes(); + } +} diff --git a/src/ISO14496/Box/MEHD.php b/src/ISO14496/Box/MEHD.php new file mode 100644 index 0000000..3bdc5cd --- /dev/null +++ b/src/ISO14496/Box/MEHD.php @@ -0,0 +1,84 @@ +Movie Extends Header Box is optional, and provides the overall + * duration, including fragments, of a fragmented movie. If this box is not + * present, the overall duration must be computed by examining each fragment. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_MEHD extends ISO14496_Box_Full +{ + /** @var integer */ + private $_fragmentDuration; + + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + + if ($this->getVersion() == 1) + $this->_fragmentDuration = $this->_reader->readInt64BE(); + else + $this->_fragmentDuration = $this->_reader->readUInt32BE(); + } + + /** + * Returns the length of the presentation of the whole movie including + * fragments (in the timescale indicated in the {@link ISO14496_Box_MVHD + * Movie Header Box}). The value of this field corresponds to the duration of + * the longest track, including movie fragments. + * + * @return integer + */ + public function getFragmentDuration() { return $this->_fragmentDuration; } +} diff --git a/src/ISO14496/Box/META.php b/src/ISO14496/Box/META.php new file mode 100644 index 0000000..60ce1f0 --- /dev/null +++ b/src/ISO14496/Box/META.php @@ -0,0 +1,86 @@ +Meta Box contains descriptive or annotative metadata. The + * meta box is required to contain a {@link ISO14496_Box_HDLR hdlr} box + * indicating the structure or format of the meta box contents. That + * metadata is located either within a box within this box (e.g. an XML box), or + * is located by the item identified by a primary item box. + * + * All other contained boxes are specific to the format specified by the handler + * box. + * + * The other boxes defined here may be defined as optional or mandatory for a + * given format. If they are used, then they must take the form specified here. + * These optional boxes include a data-information box, which documents other + * files in which metadata values (e.g. pictures) are placed, and a item + * location box, which documents where in those files each item is located (e.g. + * in the common case of multiple pictures stored in the same file). At most one + * meta box may occur at each of the file level, movie level, or track level. + * + * If an {@link ISO14496_Box_IPRO Item Protection Box} occurs, then some or all + * of the meta-data, including possibly the primary resource, may have been + * protected and be un-readable unless the protection system is taken into + * account. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_META extends ISO14496_Box_Full +{ + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + $this->setContainer(true); + $this->constructBoxes(); + } +} diff --git a/src/ISO14496/Box/MFHD.php b/src/ISO14496/Box/MFHD.php new file mode 100644 index 0000000..42199d1 --- /dev/null +++ b/src/ISO14496/Box/MFHD.php @@ -0,0 +1,80 @@ +Movie Fragment Header Box contains a sequence number, as a safety + * check. The sequence number usually starts at 1 and must increase for each + * movie fragment in the file, in the order in which they occur. This allows + * readers to verify integrity of the sequence; it is an error to construct a + * file where the fragments are out of sequence. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_MFHD extends ISO14496_Box_Full +{ + /** @var integer */ + private $_sequenceNumber; + + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + + $this->_sequenceNumber = $this->_reader->readUInt32BE(); + } + + /** + * Returns the ordinal number of this fragment, in increasing order. + * + * @return integer + */ + public function getSequenceNumber() { return $this->_sequenceNumber; } +} diff --git a/src/ISO14496/Box/MFRA.php b/src/ISO14496/Box/MFRA.php new file mode 100644 index 0000000..1d09357 --- /dev/null +++ b/src/ISO14496/Box/MFRA.php @@ -0,0 +1,81 @@ +Movie Fragment Random Access Box provides a table which may assist + * readers in finding random access points in a file using movie fragments. It + * contains a track fragment random access box for each track for which + * information is provided (which may not be all tracks). It is usually placed + * at or near the end of the file; the last box within the Movie Fragment Random + * Access Box provides a copy of the length field from the Movie Fragment Random + * Access Box. Readers may attempt to find this box by examining the last 32 + * bits of the file, or scanning backwards from the end of the file for a Movie + * Fragment Random Access Offset Box and using the size information in it, to + * see if that locates the beginning of a Movie Fragment Random Access Box. + * + * This box provides only a hint as to where random access points are; the movie + * fragments themselves are definitive. It is recommended that readers take care + * in both locating and using this box as modifications to the file after it was + * created may render either the pointers, or the declaration of random access + * points, incorrect. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_MFRA extends ISO14496_Box +{ + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + $this->setContainer(true); + $this->constructBoxes(); + } +} diff --git a/src/ISO14496/Box/MFRO.php b/src/ISO14496/Box/MFRO.php new file mode 100644 index 0000000..d7ec28e --- /dev/null +++ b/src/ISO14496/Box/MFRO.php @@ -0,0 +1,85 @@ +Movie Fragment Random Access Offset Box provides a copy of the + * length field from the enclosing {@link ISO14496_Box_MFRA Movie Fragment + * Random Access Box}. It is placed last within that box, so that the size field + * is also last in the enclosing Movie Fragment Random Access Box. When the + * Movie Fragment Random Access Box is also last in the file this permits its + * easy location. The size field here must be correct. However, neither the + * presence of the Movie Fragment Random Access Box, nor its placement last in + * the file, are assured. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_MFRO extends ISO14496_Box_Full +{ + /** @var integer */ + private $_size; + + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + + $this->_size = $this->_reader->readUInt32BE(); + } + + /** + * Returns the number of bytes of the enclosing {@link ISO14496_Box_MFRA} box. + * This field is placed at the last of the enclosing box to assist readers + * scanning from the end of the file in finding the mfra box. + * + * @return integer + */ + public function getSize() { return $this->_size; } +} diff --git a/src/ISO14496/Box/MINF.php b/src/ISO14496/Box/MINF.php new file mode 100644 index 0000000..bac8d43 --- /dev/null +++ b/src/ISO14496/Box/MINF.php @@ -0,0 +1,55 @@ +Media Information Box contains all the objects that declare + * characteristic information of the media in the track. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_MINF extends ISO14496_Box +{ +} diff --git a/src/ISO14496/Box/MOOF.php b/src/ISO14496/Box/MOOF.php new file mode 100644 index 0000000..17cc950 --- /dev/null +++ b/src/ISO14496/Box/MOOF.php @@ -0,0 +1,77 @@ +Movie Fragment Box extend the presentation in time. They provide + * the information that would previously have been in the + * {@link ISO14496_Box_MOOV Movie Box}. The actual samples are in + * {@link ISO14496_Box_MDAT Media Data Boxes}, as usual, if they are in the same + * file. The data reference index is in the sample description, so it is + * possible to build incremental presentations where the media data is in files + * other than the file containing the Movie Box. + * + * The Movie Fragment Box is a top-level box, (i.e. a peer to the Movie Box and + * Media Data boxes). It contains a {@link ISO14496_Box_MFHD Movie Fragment + * Header Box}, and then one or more {@link ISO14496_Box_TRAF Track Fragment + * Boxes}. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_MOOF extends ISO14496_Box +{ + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + $this->setContainer(true); + $this->constructBoxes(); + } +} diff --git a/src/ISO14496/Box/MOOV.php b/src/ISO14496/Box/MOOV.php new file mode 100644 index 0000000..74308c7 --- /dev/null +++ b/src/ISO14496/Box/MOOV.php @@ -0,0 +1,68 @@ +Movie Box + * which occurs at the top-level of a file. Normally this box is close to the + * beginning or end of the file, though this is not required. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_MOOV extends ISO14496_Box +{ + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + $this->setContainer(true); + $this->constructBoxes(); + } +} diff --git a/src/ISO14496/Box/MVEX.php b/src/ISO14496/Box/MVEX.php new file mode 100644 index 0000000..9dcf7c7 --- /dev/null +++ b/src/ISO14496/Box/MVEX.php @@ -0,0 +1,70 @@ +Movie Extends Box warns readers that there might be + * {@link ISO14496_Box_MFRA Movie Fragment Boxes} in this file. To know of all + * samples in the tracks, these Movie Fragment Boxes must be found and scanned + * in order, and their information logically added to that found in the + * {@link ISO14496_Box_MOOV Movie Box}. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_MVEX extends ISO14496_Box +{ + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + $this->setContainer(true); + $this->constructBoxes(); + } +} diff --git a/src/ISO14496/Box/MVHD.php b/src/ISO14496/Box/MVHD.php new file mode 100644 index 0000000..aa6a6e7 --- /dev/null +++ b/src/ISO14496/Box/MVHD.php @@ -0,0 +1,166 @@ +Movie Header Box defines overall information which is + * media-independent, and relevant to the entire presentation considered as a + * whole. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_MVHD extends ISO14496_Box_Full +{ + /** @var integer */ + private $_creationTime; + + /** @var integer */ + private $_modificationTime; + + /** @var integer */ + private $_timescale; + + /** @var integer */ + private $_duration; + + /** @var integer */ + private $_rate; + + /** @var integer */ + private $_volume; + + /** @var integer */ + private $_nextTrackId; + + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + + if ($this->getVersion() == 1) { + $this->_creationTime = $this->_reader->readInt64BE(); + $this->_modificationTime = $this->_reader->readInt64BE(); + $this->_timescale = $this->_reader->readUInt32BE(); + $this->_duration = $this->_reader->readInt64BE(); + } else { + $this->_creationTime = $this->_reader->readUInt32BE(); + $this->_modificationTime = $this->_reader->readUInt32BE(); + $this->_timescale = $this->_reader->readUInt32BE(); + $this->_duration = $this->_reader->readUInt32BE(); + } + $this->_rate = + ((($tmp = $this->_reader->readUInt32BE()) >> 16) & 0xffff) + + ($tmp & 0xffff) / 10; + $this->_volume = ((($tmp = $this->_reader->readUInt16BE()) >> 8) & 0xff) + + ($tmp & 0xff) / 10; + $this->_reader->skip(70); + $this->_nextTrackId = $this->_reader->readUInt32BE(); + } + + /** + * Returns the creation time of the presentation. The value is in seconds + * since midnight, Jan. 1, 1904, in UTC time. + * + * @return integer + */ + public function getCreationTime() { return $this->_creationTime; } + + /** + * Returns the most recent time the presentation was modified. The value is in + * seconds since midnight, Jan. 1, 1904, in UTC time. + * + * @return integer + */ + public function getModificationTime() { return $this->_modificationTime; } + + /** + * Returns the time-scale for the entire presentation. This is the number of + * time units that pass in one second. For example, a time coordinate system + * that measures time in sixtieths of a second has a time scale of 60. + * + * @return integer + */ + public function getTimescale() { return $this->_timescale; } + + /** + * Returns the length of the presentation in the indicated timescale. This + * property is derived from the presentation’s tracks: the value of this field + * corresponds to the duration of the longest track in the presentation. + * + * @return integer + */ + public function getDuration() { return $this->_duration; } + + /** + * Returns the preferred rate to play the presentation. 1.0 is normal forward + * playback. + * + * @return integer + */ + public function getRate() { return $this->_rate; } + + /** + * Returns the preferred playback volume. 1.0 is full volume. + * + * @return integer + */ + public function getVolume() { return $this->_volume; } + + /** + * Returns a value to use for the track ID of the next track to be added to + * this presentation. Zero is not a valid track ID value. The value is larger + * than the largest track-ID in use. If this value is equal to or larger than + * 32-bit maxint, and a new media track is to be added, then a search must be + * made in the file for a unused track identifier. + * + * @return integer + */ + public function getNextTrackId() { return $this->_nextTrackId; } +} diff --git a/src/ISO14496/Box/NMHD.php b/src/ISO14496/Box/NMHD.php new file mode 100644 index 0000000..96ecf5b --- /dev/null +++ b/src/ISO14496/Box/NMHD.php @@ -0,0 +1,55 @@ +Null Media Header Box, + * as defined here. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_NMHD extends ISO14496_Box_Full +{ +} diff --git a/src/ISO14496/Box/PADB.php b/src/ISO14496/Box/PADB.php new file mode 100644 index 0000000..e1425ec --- /dev/null +++ b/src/ISO14496/Box/PADB.php @@ -0,0 +1,57 @@ +Padding Bits BoxIn some streams the media samples do not occupy + * all bits of the bytes given by the sample size, and are padded at the end to + * a byte boundary. In some cases, it is necessary to record externally the + * number of padding bits used. This table supplies that information. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_PADB extends ISO14496_Box_Full +{ +} diff --git a/src/ISO14496/Box/PDIN.php b/src/ISO14496/Box/PDIN.php new file mode 100644 index 0000000..0a3af25 --- /dev/null +++ b/src/ISO14496/Box/PDIN.php @@ -0,0 +1,97 @@ +Progressive Download Information Box aids the progressive download + * of an ISO file. The box contains pairs of numbers (to the end of the box) + * specifying combinations of effective file download bitrate in units of + * bytes/sec and a suggested initial playback delay in units of milliseconds. + * + * A receiving party can estimate the download rate it is experiencing, and from + * that obtain an upper estimate for a suitable initial delay by linear + * interpolation between pairs, or by extrapolation from the first or last + * entry. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_PDIN extends ISO14496_Box_Full +{ + /** @var Array */ + private $_progressiveDownloadInfo = array(); + + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + + while ($this->_reader->getOffset() < $this->_offset + $this->_size()) + $this->_progressiveDownloadInfo[] = array + ("rate" => $this->_reader->readUInt32BE(), + "initialDelay" => $this->_reader->readUInt32BE()); + } + + /** + * Returns the progressive download information array. The array consists of + * items having two keys. + * + * o rate -- the download rate expressed in bytes/second + * o initialDelay -- the suggested delay to use when playing the file, + * such that if download continues at the given rate, all data within the + * file will arrive in time for its use and playback should not need to + * stall. + * + * @return Array + */ + public function getProgressiveDownloadInfo() + { + return $this->_progressiveDownloadInfo; + } +} diff --git a/src/ISO14496/Box/PITM.php b/src/ISO14496/Box/PITM.php new file mode 100644 index 0000000..8b913b8 --- /dev/null +++ b/src/ISO14496/Box/PITM.php @@ -0,0 +1,86 @@ +Primary Item Box must + * occur, or there must be a box within the meta-box (e.g. an + * {@link ISO14496_Box_XML XML Box}) containing the primary information in the + * format required by the identified handler. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_PITM extends ISO14496_Box_Full +{ + /** @var string */ + private $_itemId; + + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + * @todo The sample flags could be parsed further + */ + public function __construct($reader) + { + parent::__construct($reader); + + $this->_itemId = $this->_reader->readUInt16BE(); + } + + /** + * Returns the identifier of the primary item. + * + * @return integer + */ + public function getItemId() + { + return $this->_itemId; + } +} diff --git a/src/ISO14496/Box/SCHI.php b/src/ISO14496/Box/SCHI.php new file mode 100644 index 0000000..19cba02 --- /dev/null +++ b/src/ISO14496/Box/SCHI.php @@ -0,0 +1,70 @@ +Scheme Information Box is a container Box that is only interpreted + * by the scheme being used. Any information the encryption system needs is + * stored here. The content of this box is a series of boxes whose type and + * format are defined by the scheme declared in the + * {@link ISO14496_Box_SCHM Scheme Type Box}. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_SCHI extends ISO14496_Box +{ + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + $this->setContainer(true); + $this->constructBoxes(); + } +} diff --git a/src/ISO14496/Box/SCHM.php b/src/ISO14496/Box/SCHM.php new file mode 100644 index 0000000..79934d2 --- /dev/null +++ b/src/ISO14496/Box/SCHM.php @@ -0,0 +1,103 @@ +Scheme Type Box identifies the protection scheme. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_SCHM extends ISO14496_Box_Full +{ + /** @var string */ + private $_schemeType; + + /** @var integer */ + private $_schemeVersion; + + /** @var string */ + private $_schemeUri; + + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + + $this->_schemeType = $this->_reader->read(4); + $this->_schemeVersion = $this->_reader->readUInt32BE(); + if ($this->hasFlag(1)) + $this->_schemeUri = preg_split + ("/\\x00/", $this->_reader->read + ($this->_offset + $this->_size - $this->_reader->getOffset())); + } + + /** + * Returns the code defining the protection scheme. + * + * @return string + */ + public function getSchemeType() { return $this->_schemeType; } + + /** + * Returns the version of the scheme used to create the content. + * + * @return integer + */ + public function getSchemeVersion() { return $this->_schemeVersion; } + + /** + * Returns the optional scheme address to allow for the option of directing + * the user to a web-page if they do not have the scheme installed on their + * system. It is an absolute URI. + * + * @return string + */ + public function getSchemeUri() { return $this->_schemeUri; } +} diff --git a/src/ISO14496/Box/SDTP.php b/src/ISO14496/Box/SDTP.php new file mode 100644 index 0000000..a16167d --- /dev/null +++ b/src/ISO14496/Box/SDTP.php @@ -0,0 +1,127 @@ +Independent and Disposable Samples Box optional table answers + * three questions about sample dependency: + * 1) does this sample depend on others (is it an I-picture)? + * 2) do no other samples depend on this one? + * 3) does this sample contain multiple (redundant) encodings of the data at + * this time-instant (possibly with different dependencies)? + * + * In the absence of this table: + * 1) the sync sample table answers the first question; in most video codecs, + * I-pictures are also sync points, + * 2) the dependency of other samples on this one is unknown. + * 3) the existence of redundant coding is unknown. + * + * When performing trick modes, such as fast-forward, it is possible to use the + * first piece of information to locate independently decodable samples. + * Similarly, when performing random access, it may be necessary to locate the + * previous sync point or random access recovery point, and roll-forward from + * the sync point or the pre-roll starting point of the random access recovery + * point to the desired point. While rolling forward, samples on which no others + * depend need not be retrieved or decoded. + * + * The value of sampleIsDependedOn is independent of the existence of redundant + * codings. However, a redundant coding may have different dependencies from the + * primary coding; if redundant codings are available, the value of + * sampleDependsOn documents only the primary coding. + * + * A sample dependency Box may also occur in the {@link ISO14496_Box_TRAF Track + * Fragment Box}. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_SDTP extends ISO14496_Box_Full +{ + /** @var Array */ + private $_sampleDependencyTypeTable = array(); + + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + + for ($i = 0; $this->_reader->getOffset() < + $this->_offset + $this->_size; $i++) + $this->_sampleDependencyTypeTable[$i] = array + ("sampleDependsOn" => (($tmp = $this->_reader->readInt8()) >> 4) & 0x3, + "sampleIsDependedOn" => ($tmp >> 2) & 0x3, + "sampleHasRedundancy" => $tmp & 0x3); + } + + /** + * Returns an array of values. Each entry is an array containing the following + * keys. + * o sampleDependsOn -- takes one of the following four values: + * 0: the dependency of this sample is unknown; + * 1: this sample does depend on others (not an I picture); + * 2: this sample does not depend on others (I picture); + * 3: reserved + * o sampleIsDependedOn -- takes one of the following four values: + * 0: the dependency of other samples on this sample is unknown; + * 1: other samples depend on this one (not disposable); + * 2: no other sample depends on this one (disposable); + * 3: reserved + * o sampleHasRedundancy -- takes one of the following four values: + * 0: it is unknown whether there is redundant coding in this sample; + * 1: there is redundant coding in this sample; + * 2: there is no redundant coding in this sample; + * 3: reserved + * + * @return Array + */ + public function getSampleDependencyTypeTable() + { + return $this->_sampleDependencyTypeTable; + } +} diff --git a/src/ISO14496/Box/SGPD.php b/src/ISO14496/Box/SGPD.php new file mode 100644 index 0000000..cf60fc4 --- /dev/null +++ b/src/ISO14496/Box/SGPD.php @@ -0,0 +1,64 @@ +Sample Group Description Box table gives information about the + * characteristics of sample groups. The descriptive information is any other + * information needed to define or characterize the sample group. + * + * There may be multiple instances of this box if there is more than one sample + * grouping for the samples in a track. Each instance of the Sample Group + * Description box has a type code that distinguishes different sample + * groupings. Within a track, there shall be at most one instance of this box + * with a particular grouping type. The associated Sample To Group shall + * indicate the same value for the grouping type. + * + * @todo Data parsing + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_SGPD extends ISO14496_Box_Full +{ +} diff --git a/src/ISO14496/Box/SINF.php b/src/ISO14496/Box/SINF.php new file mode 100644 index 0000000..947be52 --- /dev/null +++ b/src/ISO14496/Box/SINF.php @@ -0,0 +1,83 @@ +Protection Scheme Information Box contains all the information + * required both to understand the encryption transform applied and its + * parameters, and also to find other information such as the kind and location + * of the key management system. It also documents the original (unencrypted) + * format of the media. The Protection Scheme Info Box is a container Box. It is + * mandatory in a sample entry that uses a code indicating a protected stream. + * + * When used in a protected sample entry, this box must contain the original + * format box to document the original format. At least one of the following + * signaling methods must be used to identify the protection applied: + * + * a) MPEG-4 systems with IPMP: no other boxes, when IPMP descriptors in MPEG-4 + * systems streams are used; + * b) Standalone IPMP: an {@link ISO14496_Box_IMIF IPMP Info Box}, when IPMP + * descriptors outside MPEG-4 systems are used; + * c) Scheme signaling: a {@link ISO14496_Box_SCHM Scheme Type Box} and + * {@link ISO14496_Box_SCHI Scheme Information Box}, when these are used + * (either both must occur, or neither). + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_SINF extends ISO14496_Box +{ + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + $this->setContainer(true); + $this->constructBoxes(); + } +} diff --git a/src/ISO14496/Box/SKIP.php b/src/ISO14496/Box/SKIP.php new file mode 100644 index 0000000..be37347 --- /dev/null +++ b/src/ISO14496/Box/SKIP.php @@ -0,0 +1,69 @@ +Free Space Box are irrelevant and may be ignored, or + * the object deleted, without affecting the presentation. (Care should be + * exercised when deleting the object, as this may invalidate the offsets used + * in the sample table, unless this object is after all the media data). + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_SKIP extends ISO14496_Box +{ + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + $this->setContainer(true); + $this->constructBoxes(); + } +} diff --git a/src/ISO14496/Box/SMHD.php b/src/ISO14496/Box/SMHD.php new file mode 100644 index 0000000..d557513 --- /dev/null +++ b/src/ISO14496/Box/SMHD.php @@ -0,0 +1,66 @@ +Sound Media Header Box contains general presentation information, + * independent of the coding, for audio media. This header is used for all + * tracks containing audio. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_SMHD extends ISO14496_Box_Full +{ + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + } +} diff --git a/src/ISO14496/Box/STBL.php b/src/ISO14496/Box/STBL.php new file mode 100644 index 0000000..c63fca7 --- /dev/null +++ b/src/ISO14496/Box/STBL.php @@ -0,0 +1,86 @@ +Sample Table Box contains all the time and data indexing of the + * media samples in a track. Using the tables here, it is possible to locate + * samples in time, determine their type (e.g. I-frame or not), and determine + * their size, container, and offset into that container. + * + * If the track that contains the Sample Table Box references no data, then the + * Sample Table Box does not need to contain any sub-boxes (this is not a very + * useful media track). + * + * If the track that the Sample Table Box is contained in does reference data, + * then the following sub-boxes are required: {@link ISO14496_Box_STSD Sample + * Description}, {@link ISO14496_Box_STSZ Sample Size}, + * {@link ISO14496_Box_STSC Sample To Chunk}, and {@link ISO14496_Box_STCO Chunk + * Offset}. Further, the {@link ISO14496_Box_STSD Sample Description Box} shall + * contain at least one entry. A Sample Description Box is required because it + * contains the data reference index field which indicates which + * {@link ISO14496_Box_DREF Data Reference Box} to use to retrieve the media + * samples. Without the Sample Description, it is not possible to determine + * where the media samples are stored. The {@link ISO14496_Box_STSS Sync Sample + * Box} is optional. If the Sync Sample Box is not present, all samples are sync + * samples. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_STBL extends ISO14496_Box +{ + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + $this->setContainer(true); + $this->constructBoxes(); + } +} diff --git a/src/ISO14496/Box/STCO.php b/src/ISO14496/Box/STCO.php new file mode 100644 index 0000000..33a2fef --- /dev/null +++ b/src/ISO14496/Box/STCO.php @@ -0,0 +1,99 @@ +Chunk Offset Box table gives the index of each chunk into the + * containing file. There are two variants, permitting the use of 32-bit or + * 64-bit offsets. The latter is useful when managing very large presentations. + * At most one of these variants will occur in any single instance of a sample + * table. + * + * Offsets are file offsets, not the offset into any box within the file (e.g. + * {@link ISO14496_Box_MDAT Media Data Box}). This permits referring to media + * data in files without any box structure. It does also mean that care must be + * taken when constructing a self-contained ISO file with its metadata + * ({@link ISO14496_Box_MOOV Movie Box}) at the front, as the size of the + * {@link ISO14496_Box_MOOV Movie Box} will affect the chunk offsets to the + * media data. + * + * This box variant contains 32-bit offsets. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_STCO extends ISO14496_Box_Full +{ + /** @var Array */ + private $_chunkOffsetTable = array(); + + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + + $entryCount = $this->_reader->readUInt32BE(); + for ($i = 0; $i < $entryCount; $i++) + $this->_chunkOffsetTable[] = array + ("chunkOffset" => $this->_reader->readUInt32BE()); + } + + /** + * Returns an array of values. Each entry is an array containing the following + * keys. + * o chunkOffset -- a 32 bit integer that gives the offset of the start of a + * chunk into its containing media file. + * + * @return Array + */ + public function getChunkOffsetTable() + { + return $this->_chunkOffsetTable; + } +} diff --git a/src/ISO14496/Box/STDP.php b/src/ISO14496/Box/STDP.php new file mode 100644 index 0000000..b070924 --- /dev/null +++ b/src/ISO14496/Box/STDP.php @@ -0,0 +1,84 @@ +Degradation Priority Box contains the degradation priority of each + * sample. Specifications derived from this define the exact meaning and + * acceptable range of the priority field. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_STDP extends ISO14496_Box_Full +{ + /** @var Array */ + private $_values = array(); + + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + + while ($this->_reader->getOffset() < $this->_offset + $this->_size) + $this->_values[] = array("priority" => $this->_reader->readUInt16BE()); + } + + /** + * Returns an array of values. Each entry is an array containing the following + * keys. + * o priority: specifies the degradation priority for each sample segment. + * + * @return Array + */ + public function getValues() + { + return $this->_values; + } +} diff --git a/src/ISO14496/Box/STGP.php b/src/ISO14496/Box/STGP.php new file mode 100644 index 0000000..8ad17d4 --- /dev/null +++ b/src/ISO14496/Box/STGP.php @@ -0,0 +1,128 @@ +Sample To Group Box table can be used to find the group that a + * sample belongs to and the associated description of that sample group. The + * table is compactly coded with each entry giving the index of the first sample + * of a run of samples with the same sample group descriptor. The sample group + * description ID is an index that refers to a {@link ISO14496_Box_SGPD Sample + * Group Description Box}, which contains entries describing the characteristics + * of each sample group. + * + * There may be multiple instances of this box if there is more than one sample + * grouping for the samples in a track. Each instance of the Sample To Group Box + * has a type code that distinguishes different sample groupings. Within a + * track, there shall be at most one instance of this box with a particular + * grouping type. The associated Sample Group Description shall indicate the + * same value for the grouping type. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_STGP extends ISO14496_Box_Full +{ + /** @var integer */ + private $_groupingType; + + /** @var Array */ + private $_sampleToGroupTable = array(); + + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + + $groupingType = $this->_reader->readUInt32BE(); + $entryCount = $this->_reader->readUInt32BE(); + for ($i = 1; $i < $entryCount; $i++) + $this->_sampleToGroupTable[$i] = array + ("sampleCount" => $this->_reader->readUInt32BE(), + "groupDescriptionIndex" => $this->_reader->readUInt32BE()); + } + + /** + * Returns the grouping type that identifies the type (i.e. criterion used to + * form the sample groups) of the sample grouping and links it to its sample + * group description table with the same value for grouping type. At most one + * occurrence of this box with the same value for groupingType shall exist for + * a track. + * + * @return integer + */ + public function getGroupingType() + { + return $this->_groupingType; + } + + /** + * Returns an array of values. Each entry is an array containing the following + * keys. + * o sampleCount -- an integer that gives the number of consecutive samples + * with the same sample group descriptor. If the sum of the sample count + * in this box is less than the total sample count, then the reader should + * effectively extend it with an entry that associates the remaining + * samples with no group. It is an error for the total in this box to be + * greater than the sample_count documented elsewhere, and the reader + * behavior would then be undefined. + * o groupDescriptionIndex -- an integer that gives the index of the sample + * group entry which describes the samples in this group. The index ranges + * from 1 to the number of sample group entries in the + * {@link ISO14496_Box_SGPD Sample Group Description Box}, or takes the + * value 0 to indicate that this sample is a member of no group of this + * type. + * + * @return Array + */ + public function getSampleToGroupTable() + { + return $this->_sampleToGroupTable; + } +} diff --git a/src/ISO14496/Box/STSC.php b/src/ISO14496/Box/STSC.php new file mode 100644 index 0000000..e14a84a --- /dev/null +++ b/src/ISO14496/Box/STSC.php @@ -0,0 +1,105 @@ +Sample To Chunk Box table can be used to find the chunk that + * contains a sample, its position, and the associated sample description. + * + * The table is compactly coded. Each entry gives the index of the first chunk + * of a run of chunks with the same characteristics. By subtracting one entry + * here from the previous one, you can compute how many chunks are in this run. + * You can convert this to a sample count by multiplying by the appropriate + * samplesPerChunk. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_STSC extends ISO14496_Box_Full +{ + /** @var Array */ + private $_sampleToChunkTable = array(); + + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + + $entryCount = $this->_reader->readUInt32BE(); + for ($i = 1; $i < $entryCount; $i++) + $this->_sampleToChunkTable[$i] = array + ("firstChunk" => $this->_reader->readUInt32BE(), + "samplesPerChunk" => $this->_reader->readUInt32BE(), + "sampleDescriptionIndex" => $this->_reader->readUInt32BE()); + } + + /** + * Returns an array of values. Each entry is an array containing the following + * keys. + * o firstChunk -- an integer that gives the index of the first chunk in + * this run of chunks that share the same samplesPerChunk and + * sampleDescriptionIndex; the index of the first chunk in a track has the + * value 1 (the firstChunk field in the first record of this box has the + * value 1, identifying that the first sample maps to the first chunk). + * o samplesPerChunk is an integer that gives the number of samples in each + * of these chunks. + * o sampleDescriptionIndex is an integer that gives the index of the sample + * entry that describes the samples in this chunk. The index ranges from 1 + * to the number of sample entries in the {@link ISO14496_Box_STSD Sample + * Description Box}. + * + * @return Array + */ + public function getSampleToChunkTable() + { + return $this->_sampleToChunkTable; + } +} diff --git a/src/ISO14496/Box/STSD.php b/src/ISO14496/Box/STSD.php new file mode 100644 index 0000000..aa90e67 --- /dev/null +++ b/src/ISO14496/Box/STSD.php @@ -0,0 +1,56 @@ +Sample Description Box table gives detailed information about the + * coding type used, and any initialization information needed for that coding. + * + * @todo Data parsing + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_STSD extends ISO14496_Box_Full +{ +} diff --git a/src/ISO14496/Box/STSH.php b/src/ISO14496/Box/STSH.php new file mode 100644 index 0000000..1324e64 --- /dev/null +++ b/src/ISO14496/Box/STSH.php @@ -0,0 +1,113 @@ +Shadow Sync Sample Box table provides an optional set of sync + * samples that can be used when seeking or for similar purposes. In normal + * forward play they are ignored. + * + * Each entry in the Shadow Sync Table consists of a pair of sample numbers. The + * first entry (shadowedSampleNumber) indicates the number of the sample that a + * shadow sync will be defined for. This should always be a non-sync sample + * (e.g. a frame difference). The second sample number (syncSampleNumber) + * indicates the sample number of the sync sample (i.e. key frame) that can be + * used when there is a random access at, or before, the shadowedSampleNumber. + * + * The shadow sync samples are normally placed in an area of the track that is + * not presented during normal play (edited out by means of an edit list), + * though this is not a requirement. The shadow sync table can be ignored and + * the track will play (and seek) correctly if it is ignored (though perhaps not + * optimally). + * + * The Shadow Sync Sample replaces, not augments, the sample that it shadows + * (i.e. the next sample sent is shadowedSampleNumber+1). The shadow sync sample + * is treated as if it occurred at the time of the sample it shadows, having the + * duration of the sample it shadows. + * + * Hinting and transmission might become more complex if a shadow sample is used + * also as part of normal playback, or is used more than once as a shadow. In + * this case the hint track might need separate shadow syncs, all of which can + * get their media data from the one shadow sync in the media track, to allow + * for the different time-stamps etc. needed in their headers. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_STSH extends ISO14496_Box_Full +{ + /** @var Array */ + private $_shadowSyncSampleTable = array(); + + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + + $entryCount = $this->_reader->readUInt32BE(); + for ($i = 0; $i < $entryCount; $i++) + $this->_shadowSyncSampleTable[$i] = array + ("shadowedSampleNumber" => $this->_reader->readUInt32BE(), + "syncSampleNumber" => $this->_reader->readUInt32BE()); + } + + /** + * Returns an array of values. Each entry is an array containing the following + * keys. + * o shadowedSampleNumber - gives the number of a sample for which there is + * an alternative sync sample. + * o syncSampleNumber - gives the number of the alternative sync sample. + * + * @return Array + */ + public function getShadowSyncSampleTable() + { + return $this->_shadowSyncSampleTable; + } +} diff --git a/src/ISO14496/Box/STSS.php b/src/ISO14496/Box/STSS.php new file mode 100644 index 0000000..a726657 --- /dev/null +++ b/src/ISO14496/Box/STSS.php @@ -0,0 +1,88 @@ +Sync Sample Box provides a compact marking of the random access + * points within the stream. The table is arranged in strictly increasing order + * of sample number. If the sync sample box is not present, every sample is a + * random access point. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_STSS extends ISO14496_Box_Full +{ + /** @var Array */ + private $_syncSampleTable = array(); + + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + + $entryCount = $this->_reader->readUInt32BE(); + for ($i = 1; $i < $entryCount; $i++) + $this->_syncSampleTable[$i] = array + ("sampleNumber" => $this->_reader->readUInt32BE()); + } + + /** + * Returns an array of values. Each entry is an array containing the following + * keys. + * o sampleNumber -- gives the numbers of the samples that are random access + * points in the stream. + * + * @return Array + */ + public function getSyncSampleTable() + { + return $this->_syncSampleTable; + } +} diff --git a/src/ISO14496/Box/STSZ.php b/src/ISO14496/Box/STSZ.php new file mode 100644 index 0000000..b827ae2 --- /dev/null +++ b/src/ISO14496/Box/STSZ.php @@ -0,0 +1,106 @@ +Sample Size Box contains the sample count and a table giving the + * size in bytes of each sample. This allows the media data itself to be + * unframed. The total number of samples in the media is always indicated in the + * sample count. + * + * There are two variants of the sample size box. The first variant has a fixed + * size 32-bit field for representing the sample sizes; it permits defining a + * constant size for all samples in a track. The second variant permits smaller + * size fields, to save space when the sizes are varying but small. One of these + * boxes must be present; the first version is preferred for maximum + * compatibility. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_STSZ extends ISO14496_Box_Full +{ + /** @var integer */ + private $_sampleSize; + + /** @var Array */ + private $_sampleSizeTable = array(); + + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + + $this->_sampleSize = $this->_reader->readUInt32BE(); + $sampleCount = $this->_reader->readUInt32BE(); + if ($this->_sampleSize == 0) + for ($i = 1; $i < $sampleCount; $i++) + $this->_sampleSizeTable[$i] = $this->_reader->readUInt32BE(); + } + + /** + * Returns the default sample size. If all the samples are the same size, this + * field contains that size value. If this field is set to 0, then the samples + * have different sizes, and those sizes are stored in the sample size table. + * + * @return integer + */ + public function getSampleSize() { return $this->_sampleSize; } + + /** + * Returns an array of sample sizes specifying the size of a sample, indexed + * by its number. + * + * @return Array + */ + public function getSampleSizeTable() + { + return $this->_sampleSizeTable; + } +} diff --git a/src/ISO14496/Box/STTS.php b/src/ISO14496/Box/STTS.php new file mode 100644 index 0000000..7d08d8d --- /dev/null +++ b/src/ISO14496/Box/STTS.php @@ -0,0 +1,106 @@ +Decoding Time to Sample Box contains a compact version of a table + * that allows indexing from decoding time to sample number. Other tables give + * sample sizes and pointers, from the sample number. Each entry in the table + * gives the number of consecutive samples with the same time delta, and the + * delta of those samples. By adding the deltas a complete time-to-sample map + * may be built. + * + * The Decoding Time to Sample Box contains decode time delta's: DT(n+1) = DT(n) + * + STTS(n) where STTS(n) is the (uncompressed) table entry for sample n. + * + * The sample entries are ordered by decoding time stamps; therefore the deltas + * are all non-negative. + * + * The DT axis has a zero origin; DT(i) = SUM(for j=0 to i-1 of delta(j)), and + * the sum of all deltas gives the length of the media in the track (not mapped + * to the overall timescale, and not considering any edit list). + * + * The {@link ISO14496_Box_ELST Edit List Box} provides the initial CT value if + * it is non-empty (non-zero). + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_STTS extends ISO14496_Box_Full +{ + /** @var Array */ + private $_timeToSampleTable = array(); + + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + + $entryCount = $this->_reader->readUInt32BE(); + for ($i = 1; $i < $entryCount; $i++) + $this->_timeToSampleTable[$i] = array + ("sampleCount" => $this->_reader->readUInt32BE(), + "sampleDelta" => $this->_reader->readUInt32BE()); + } + + /** + * Returns an array of values. Each entry is an array containing the following + * keys. + * o sampleCount -- an integer that counts the number of consecutive samples + * that have the given duration. + * o sampleDelta -- an integer that gives the delta of these samples in the + * time-scale of the media. + * + * @return Array + */ + public function getTimeToSampleTable() + { + return $this->_timeToSampleTable; + } +} diff --git a/src/ISO14496/Box/STZ2.php b/src/ISO14496/Box/STZ2.php new file mode 100644 index 0000000..b7f44f6 --- /dev/null +++ b/src/ISO14496/Box/STZ2.php @@ -0,0 +1,106 @@ +Sample Size Box contains the sample count and a table giving the + * size in bytes of each sample. This allows the media data itself to be + * unframed. The total number of samples in the media is always indicated in the + * sample count. + * + * There are two variants of the sample size box. This variant permits smaller + * than 32-bit size fields, to save space when the sizes are varying but small. + * One of the boxes must be present; the {@link ISO14496_Box_STSZ another + * variant} is preferred for maximum compatibility. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_STZ2 extends ISO14496_Box_Full +{ + /** @var Array */ + private $_sampleSizeTable = array(); + + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + + $this->_reader->skip(3); + $fieldSize = $this->_reader->readInt8(); + $sampleCount = $this->_reader->readUInt32BE(); + for ($i = 1; $i < $sampleCount; $i++) { + switch ($fieldSize) { + case 4: + $this->_sampleSizeTable[$i] = + (($tmp = $this->_reader->readInt8()) >> 4) & 0xf; + if ($i + 1 < $sampleCount) + $this->_sampleSizeTable[$i++] = $tmp & 0xf; + break; + case 8: + $this->_sampleSizeTable[$i] = $this->_reader->readInt8(); + break; + case 16: + $this->_sampleSizeTable[$i] = $this->_reader->readUInt16BE(); + break; + } + } + } + + /** + * Returns an array of sample sizes specifying the size of a sample, indexed + * by its number. + * + * @return Array + */ + public function getSampleSizeTable() + { + return $this->_sampleSizeTable; + } +} diff --git a/src/ISO14496/Box/SUBS.php b/src/ISO14496/Box/SUBS.php new file mode 100644 index 0000000..bb53e61 --- /dev/null +++ b/src/ISO14496/Box/SUBS.php @@ -0,0 +1,138 @@ +Sub-Sample Information Box is designed to contain sub-sample + * information. + * + * A sub-sample is a contiguous range of bytes of a sample. The specific + * definition of a sub-sample shall be supplied for a given coding system (e.g. + * for ISO/IEC 14496-10, Advanced Video Coding). In the absence of such a + * specific definition, this box shall not be applied to samples using that + * coding system. + * + * If subsample_count is 0 for any entry, then those samples have no subsample + * information and no array follows. The table is sparsely coded; the table + * identifies which samples have sub-sample structure by recording the + * difference in sample-number between each entry. The first entry in the table + * records the sample number of the first sample having sub-sample information. + * + * Note: It is possible to combine subsamplePriority and discardable such that + * when subsamplePriority is smaller than a certain value, discardable is set to + * 1. However, since different systems may use different scales of priority + * values, to separate them is safe to have a clean solution for discardable + * sub-samples. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_SUBS extends ISO14496_Box_Full +{ + /** @var Array */ + private $_subSampleTable = array(); + + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + + $entryCount = $this->_reader->readUInt32BE(); + for ($i = 0; $i < $entryCount; $i++) { + $entry = array(); + $entry["sampleDelta"] = $this->_reader->readUInt32BE(); + $entry["subsamples"] = array(); + if (($subsampleCount = $this->_reader->readUInt16BE()) > 0) { + for ($j = 0; $j < $subsampleCount; $j++) { + $subsample = array(); + if ($this->getVersion() == 1) + $subsample["subsampleSize"] = $this->_reader->readUInt32BE(); + else + $subsample["subsampleSize"] = $this->_reader->readUInt16BE(); + $subsample["subsamplePriority"] = $this->_reader->readInt8(); + $subsample["discardable"] = $this->_reader->readInt8(); + $this->_reader->skip(4); + $entry["subsamples"][] = $subsample; + } + $this->_subSampleTable[] = $entry; + } + } + } + + /** + * Returns an array of values. Each entry is an array containing the following + * keys. + * o sampleDelta -- an integer that specifies the sample number of the + * sample having sub-sample structure. It is coded as the difference + * between the desired sample number, and the sample number indicated in + * the previous entry. If the current entry is the first entry, the value + * indicates the sample number of the first sample having sub-sample + * information, that is, the value is the difference between the sample + * number and zero (0). + * o subsamples -- an array of subsample arrays, each containing the + * following keys. + * o subsampleSize -- an integer that specifies the size, in bytes, of + * the current sub-sample. + * o subsamplePriority -- an integer specifying the degradation priority + * for each sub-sample. Higher values of subsamplePriority, indicate + * sub-samples which are important to, and have a greater impact on, + * the decoded quality. + * o discardable -- equal to 0 means that the sub-sample is required to + * decode the current sample, while equal to 1 means the sub-sample is + * not required to decode the current sample but may be used for + * enhancements, e.g., the sub-sample consists of supplemental + * enhancement information (SEI) messages. + * + * @return Array + */ + public function getSubSampleTable() + { + return $this->_subSampleTable; + } +} diff --git a/src/ISO14496/Box/TFHD.php b/src/ISO14496/Box/TFHD.php new file mode 100644 index 0000000..b9a93f6 --- /dev/null +++ b/src/ISO14496/Box/TFHD.php @@ -0,0 +1,190 @@ +Track Fragment Header Box to + * each track; and a track fragment can add zero or more contiguous runs of + * samples. The track fragment header sets up information and defaults used for + * those runs of samples. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_TFHD extends ISO14496_Box_Full +{ + /** @var integer */ + private $_trackId; + + /** @var integer */ + private $_defaultSampleDescriptionIndex; + + /** @var integer */ + private $_defaultSampleDuration; + + /** @var integer */ + private $_defaultSampleSize; + + /** @var integer */ + private $_defaultSampleFlags; + + /** + * Indicates indicates the presence of the baseDataOffset field. This provides + * an explicit anchor for the data offsets in each track run (see below). If + * not provided, the base-dataoffset for the first track in the movie fragment + * is the position of the first byte of the enclosing Movie Fragment Box, and + * for second and subsequent track fragments, the default is the end of the + * data defined by the preceding fragment. Fragments inheriting their offset + * in this way must all use the same data-reference (i.e., the data for these + * tracks must be in the same file). + */ + const BASE_DATA_OFFSET = 0x1; + + /** + * Indicates the presence of the sampleDescriptionIndex field, which + * over-rides, in this fragment, the default set up in the + * {@link ISO14496_Box_TREX Track Extends Box}. + */ + const SAMPLE_DESCRIPTION_INDEX = 0x2; + + /** Indicates the precense of the defaultSampleDuration field. */ + const DEFAULT_SAMPLE_DURATION = 0x8; + + /** Indicates the precense of the defaultSampleSize field. */ + const DEFAULT_SAMPLE_SIZE = 0x10; + + /** Indicates the precense of the defaultSampleFlags field. */ + const DEFAULT_SAMPLE_DURATION = 0x20; + + /** + * Indicates that the duration provided in either defaultSampleDuration, or by + * the defaultDuration in the {@link ISO14496_Box_TREX Track Extends Box}, is + * empty, i.e. that there are no samples for this time interval. + */ + const DURATION_IS_EMPTY = 0x10000; + + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + * @todo The sample flags could be parsed further + */ + public function __construct($reader) + { + parent::__construct($reader); + + $this->_trackId = $this->_reader->readUInt32BE(); + if ($this->hasFlag(self::BASE_DATA_OFFSET)) + $this->_baseDataOffset = $this->_reader->readInt64BE(); + if ($this->hasFlag(self::SAMPLE_DESCRIPTION_INDEX)) + $this->_sampleDescriptionIndex = $this->_reader->readUInt32BE(); + if ($this->hasFlag(self::DEFAULT_SAMPLE_DURATION)) + $this->_defaultSampleDuration = $this->_reader->readUInt32BE(); + if ($this->hasFlag(self::DEFAULT_SAMPLE_SIZE)) + $this->_defaultSampleSize = $this->_reader->readUInt32BE(); + if ($this->hasFlag(self::DEFAULT_SAMPLE_FLAGS)) + $this->_defaultSampleFlags = $this->_reader->readUInt32BE(); + } + + /** + * Returns the track identifier. + * + * @return integer + */ + public function getTrackId() + { + return $this->_trackId; + } + + /** + * Returns the base offset to use when calculating data offsets. + * + * @return integer + */ + public function getBaseDataOffset() + { + return $this->_baseDataOffset; + } + + /** + * Returns the sample description index. + * + * @return integer + */ + public function getSampleDescriptionIndex() + { + return $this->_defaultSampleDescriptionIndex; + } + + /** + * Returns the default sample duration. + * + * @return integer + */ + public function getDefaultSampleDuration() + { + return $this->_defaultSampleDuration; + } + + /** + * Returns the default sample size. + * + * @return integer + */ + public function getDefaultSampleSize() + { + return $this->_defaultSampleSize; + } + + /** + * Returns the default sample flags. + * + * @return integer + */ + public function getDefaultSampleFlags() + { + return $this->_defaultSampleFlags; + } +} diff --git a/src/ISO14496/Box/TFRA.php b/src/ISO14496/Box/TFRA.php new file mode 100644 index 0000000..70eb42a --- /dev/null +++ b/src/ISO14496/Box/TFRA.php @@ -0,0 +1,142 @@ +Track Fragment Random Access Box does not mean that + * all the samples are sync samples. Random access information in the + * {@link ISO14496_Box_TRUN Track Fragment Run Box}, + * {@link ISO14496_Box_TRAF Track Fragment Box} and + * {@link ISO14496_Box_TREX Track Fragment Box} shall be set appropriately + * regardless of the presence of this box. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_TFRA extends ISO14496_Box_Full +{ + /** @var integer */ + private $_trackId; + + /** @var Array */ + private $_degradationPriorityTable = array(); + + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + + $this->_trackId = $this->_reader->readUInt32BE(); + + $trafNumberSize = (($tmp = $this->_reader->readUInt32BE()) >> 4) & 0x3; + $trunNumberSize = ($tmp >> 2) & 0x3; + $sampleNumberSize = $tmp & 0x3; + $entryCount = $this->_reader->readUInt32BE(); + for ($i = 1; $i < $entryCount; $i++) { + $entry = array(); + if ($this->getVersion() == 1) { + $entry["time"] = $this->_reader->readInt64BE(); + $entry["moofOffset"] = $this->_reader->readInt64BE(); + } else { + $entry["time"] = $this->_reader->readUInt32BE(); + $entry["moofOffset"] = $this->_reader->readUInt32BE(); + } + $entry["trafNumber"] = + ($trafNumberSize == 4 ? $this->_reader->readUInt32BE() : + ($trafNumberSize == 8 ? $this->_reader->readInt64BE() : 0)); + $entry["trunNumber"] = + ($trunNumberSize == 4 ? $this->_reader->readUInt32BE() : + ($trunNumberSize == 8 ? $this->_reader->readInt64BE() : 0)); + $entry["sampleNumber"] = + ($sampleNumberSize == 4 ? $this->_reader->readUInt32BE() : + ($sampleNumberSize == 8 ? $this->_reader->readInt64BE() : 0)); + $this->_degradationPriorityTable[$i] = $entry; + } + } + + /** + * Returns the track identifier. + * + * @return integer + */ + public function getTrackId() { return $this->_trackId; } + + /** + * Returns an array of entries. Each entry is an array containing the + * following keys. + * o time -- a 32 or 64 bits integer that indicates the presentation time of + * the random access sample in units defined in the + * {@link ISO14496_Box_MDHD Media Header Box} of the associated track. + * o moofOffset -- a 32 or 64 bits integer that gives the offset of the + * {@link ISO14496_Box_MOOF Movie Fragment Box} used in this entry. Offset + * is the byte-offset between the beginning of the file and the beginning + * of the Movie Fragment Box. + * o trafNumber -- indicates the {@link ISO14496_Box_TRAF Track Fragment + * Box} number that contains the random accessible sample. The number + * ranges from 1 (the first traf is numbered 1) in each Track Fragment + * Box. + * o trunNumber -- indicates the {@link ISO14496_Box_TRUN Track Fragment Run + * Box} number that contains the random accessible sample. The number + * ranges from 1 in each Track Fragment Run Box. + * o sampleNumber -- indicates the sample number that contains the random + * accessible sample. The number ranges from 1 in each Track Fragment Run + * Box. + * + * @return Array + */ + public function getDegradationPriorityTable() + { + return $this->_degradationPriorityTable; + } +} diff --git a/src/ISO14496/Box/TKHD.php b/src/ISO14496/Box/TKHD.php new file mode 100644 index 0000000..602c1f1 --- /dev/null +++ b/src/ISO14496/Box/TKHD.php @@ -0,0 +1,177 @@ +Track Header Box specifies the characteristics of a single track. + * Exactly one Track Header Box is contained in a track. + * + * In the absence of an edit list, the presentation of a track starts at the + * beginning of the overall presentation. An empty edit is used to offset the + * start time of a track. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_TKHD extends ISO14496_Box_Full +{ + /** @var integer */ + private $_creationTime; + + /** @var integer */ + private $_modificationTime; + + /** @var integer */ + private $_trackId; + + /** @var integer */ + private $_duration; + + /** @var integer */ + private $_width; + + /** @var integer */ + private $_height; + + /** + * Indicates that the track is enabled. A disabled track is treated as if it + * were not present. + */ + const TRACK_ENABLED = 1; + + /** Indicates that the track is used in the presentation. */ + const TRACK_IN_MOVIE = 2; + + /** Indicates that the track is used when previewing the presentation. */ + const TRACK_IN_PREVIEW = 4; + + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + + if ($this->getVersion() == 1) { + $this->_creationTime = $this->_reader->readInt64BE(); + $this->_modificationTime = $this->_reader->readInt64BE(); + $this->_trackId = $this->_reader->readUInt32BE(); + $this->_reader->skip(4); + $this->_duration = $this->_reader->readInt64BE(); + } else { + $this->_creationTime = $this->_reader->readUInt32BE(); + $this->_modificationTime = $this->_reader->readUInt32BE(); + $this->_trackId = $this->_reader->readUInt32BE(); + $this->_reader->skip(4); + $this->_duration = $this->_reader->readUInt32BE(); + } + $this->_reader->skip(52); + $this->_width = + ((($tmp = $this->_reader->readUInt32BE()) >> 16) & 0xffff) + + ($tmp & 0xffff) / 10; + $this->_height = + ((($tmp = $this->_reader->readUInt32BE()) >> 16) & 0xffff) + + ($tmp & 0xffff) / 10; + } + + /** + * Returns the creation time of this track in seconds since midnight, Jan. 1, + * 1904, in UTC time. + * + * @return integer + */ + public function getCreationTime() { return $this->_creationTime; } + + /** + * Returns the most recent time the track was modified in seconds since + * midnight, Jan. 1, 1904, in UTC time. + * + * @return integer + */ + public function getModificationTime() { return $this->_modificationTime; } + + /** + * Returns a number that uniquely identifies this track over the entire + * life-time of this presentation. Track IDs are never re-used and cannot be + * zero. + * + * @return integer + */ + public function getTrackId() { return $this->_trackId; } + + /** + * Returns the duration of this track (in the timescale indicated in the + * {@link MVHD Movie Header Box}). The value of this field is equal to the sum + * of the durations of all of the track’s edits. If there is no edit list, + * then the duration is the sum of the sample durations, converted into the + * timescale in the {@link MVHD Movie Header Box}. If the duration of this + * track cannot be determined then duration is set to all 32-bit maxint. + * + * @return integer + */ + public function getDuration() { return $this->_duration; } + + /** + * Returns the track's visual presentation width. This needs not be the same + * as the pixel width of the images; all images in the sequence are scaled to + * this width, before any overall transformation of the track represented by + * the matrix. The pixel width of the images is the default value. + * + * @return integer + */ + public function getWidth() { return $this->_rate; } + + /** + * Returns the track's visual presentation height. This needs not be the same + * as the pixel height of the images; all images in the sequence are scaled to + * this height, before any overall transformation of the track represented by + * the matrix. The pixel height of the images is the default value. + * + * @return integer + */ + public function getHeight() { return $this->_volume; } +} diff --git a/src/ISO14496/Box/TRAF.php b/src/ISO14496/Box/TRAF.php new file mode 100644 index 0000000..dc1d6b3 --- /dev/null +++ b/src/ISO14496/Box/TRAF.php @@ -0,0 +1,73 @@ +Track Fragment Box there is a set of track fragments, zero + * or more per track. The track fragments in turn contain zero or more track + * runs, each of which document a contiguous run of samples for that track. + * + * Within these structures, many fields are optional and can be defaulted. It is + * possible to add empty time to a track using these structures, as well as + * adding samples. Empty inserts can be used in audio tracks doing silence + * suppression, for example. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_TRAF extends ISO14496_Box +{ + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + $this->setContainer(true); + $this->constructBoxes(); + } +} diff --git a/src/ISO14496/Box/TRAK.php b/src/ISO14496/Box/TRAK.php new file mode 100644 index 0000000..e3ce5d1 --- /dev/null +++ b/src/ISO14496/Box/TRAK.php @@ -0,0 +1,79 @@ +Track Box is a container box for a single track of a presentation. + * A presentation consists of one or more tracks. Each track is independent of + * the other tracks in the presentation and carries its own temporal and spatial + * information. Each track will contain its associated {@link ISO14496_Box_MDIA + * Media Box}. + * + * Tracks are used for two purposes: + * (a) to contain media data (media tracks) and + * (b) to contain packetization information for streaming protocols + * (hint tracks). + * There shall be at least one media track within an ISO file, and all the media + * tracks that contributed to the hint tracks shall remain in the file, even if + * the media data within them is not referenced by the hint tracks; after + * deleting all hint tracks, the entire un-hinted presentation shall remain. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_TRAK extends ISO14496_Box +{ + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + $this->setContainer(true); + $this->constructBoxes(); + } +} diff --git a/src/ISO14496/Box/TREF.php b/src/ISO14496/Box/TREF.php new file mode 100644 index 0000000..5cb654b --- /dev/null +++ b/src/ISO14496/Box/TREF.php @@ -0,0 +1,77 @@ +Track Reference Box provides a reference from the containing track + * to another track in the presentation. These references are typed. A {@link + * ISO14496_Box_HINT hint} reference links from the containing hint track to the + * media data that it hints. A content description reference {@link + * ISO14496_Box_CDSC cdsc} links a descriptive or metadata track to the content + * which it describes. + * + * Exactly one Track Reference Box can be contained within the {@link + * ISO14496_Box_TRAK Track Box}. + * + * If this box is not present, the track is not referencing any other track in + * any way. The reference array is sized to fill the reference type box. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_TREF extends ISO14496_Box +{ + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + $this->setContainer(true); + $this->constructBoxes(); + } +} diff --git a/src/ISO14496/Box/TREX.php b/src/ISO14496/Box/TREX.php new file mode 100644 index 0000000..9183fa8 --- /dev/null +++ b/src/ISO14496/Box/TREX.php @@ -0,0 +1,138 @@ +Track Extends Box sets up default values used by the movie + * fragments. By setting defaults in this way, space and complexity can be saved + * in each {@link ISO14496_Box_TRAF Track Fragment Box}. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_TREX extends ISO14496_Box_Full +{ + /** @var integer */ + private $_trackId; + + /** @var integer */ + private $_defaultSampleDescriptionIndex; + + /** @var integer */ + private $_defaultSampleDuration; + + /** @var integer */ + private $_defaultSampleSize; + + /** @var integer */ + private $_defaultSampleFlags; + + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + * @todo The sample flags could be parsed further + */ + public function __construct($reader) + { + parent::__construct($reader); + + $this->_trackId = $this->_reader->readUInt32BE(); + $this->_defaultSampleDescriptionIndex = $this->_reader->readUInt32BE(); + $this->_defaultSampleDuration = $this->_reader->readUInt32BE(); + $this->_defaultSampleSize = $this->_reader->readUInt32BE(); + $this->_defaultSampleFlags = $this->_reader->readUInt32BE(); + } + + /** + * Returns the default track identifier. + * + * @return integer + */ + public function getTrackId() + { + return $this->_trackId; + } + + /** + * Returns the default sample description index. + * + * @return integer + */ + public function getDefaultSampleDescriptionIndex() + { + return $this->_defaultSampleDescriptionIndex; + } + + /** + * Returns the default sample duration. + * + * @return integer + */ + public function getDefaultSampleDuration() + { + return $this->_defaultSampleDuration; + } + + /** + * Returns the default sample size. + * + * @return integer + */ + public function getDefaultSampleSize() + { + return $this->_defaultSampleSize; + } + + /** + * Returns the default sample flags. + * + * @return integer + */ + public function getDefaultSampleFlags() + { + return $this->_defaultSampleFlags; + } +} diff --git a/src/ISO14496/Box/TRUN.php b/src/ISO14496/Box/TRUN.php new file mode 100644 index 0000000..10500c2 --- /dev/null +++ b/src/ISO14496/Box/TRUN.php @@ -0,0 +1,149 @@ +Track Fragment Run Boxes. If the durationIsEmpty flag is set, + * there are no track runs. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_TRUN extends ISO14496_Box_Full +{ + /** @var integer */ + private $_dataOffset; + + /** @var Array */ + private $_samples = array(); + + /** Indicates the precense of the dataOffset field. */ + const DATA_OFFSET = 0x1; + + /** + * Indicates the precense of the firstSampleFlags field; this over-rides the + * default flags for the first sample only. This makes it possible to record + * a group of frames where the first is a key and the rest are difference + * frames, without supplying explicit flags for every sample. If this flag and + * field are used, sampleFlags field shall not be present. + */ + const FIRST_SAMPLE_FLAGS = 0x4; + + /** + * Indicates that each sample has its own duration, otherwise the default is + * used. + */ + const SAMPLE_DURATION = 0x100; + + /** + * Indicates that each sample has its own size, otherwise the default is used. + */ + const SAMPLE_SIZE = 0x200; + + /** + * Indicates that each sample has its own flags, otherwise the default is + * used. + */ + const SAMPLE_FLAGS = 0x400; + + /** + * Indicates that each sample has a composition time offset (e.g. as used for + * I/P/B video in MPEG). + */ + const SAMPLE_COMPOSITION_TIME_OFFSETS = 0x800; + + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + + $flags = $this->_flags; + $sampleCount = $this->_reader->readUInt32BE(); + + if ($this->hasFlag(self::DATA_OFFSET)) + $this->_dataOffset = $this->_reader->readInt32BE(); + if ($this->hasFlag(self::FIRST_SAMPLE_FLAGS)) + $this->_flags = $this->_reader->readUInt32BE(); + + for ($i = 0; $i < $sampleCount; $i++) { + $sample = array(); + if ($this->hasFlag(self::SAMPLE_DURATION)) + $sample["duration"] = $this->_reader->readUInt32BE(); + if ($this->hasFlag(self::SAMPLE_SIZE)) + $sample["size"] = $this->_reader->readUInt32BE(); + if ($this->hasFlag(self::SAMPLE_FLAGS)) + $sample["flags"] = $this->_reader->readUInt32BE(); + if ($this->hasFlag(self::SAMPLE_COMPOSITION_TIME_OFFSET)) + $sample["compositionTimeOffset"] = $this->_reader->readUInt32BE(); + $this->_samples[] = $sample; + $this->_flags = $flags; + } + } + + /** + * Returns the data offset. + * + * @return integer + */ + public function getDataOffset() + { + return $this->_trackId; + } + + /** + * Returns the array of samples. + * + * @return Array + */ + public function getSamples() + { + return $this->_samples; + } +} diff --git a/src/ISO14496/Box/UDTA.php b/src/ISO14496/Box/UDTA.php new file mode 100644 index 0000000..724d831 --- /dev/null +++ b/src/ISO14496/Box/UDTA.php @@ -0,0 +1,71 @@ +User Data Box contains objects that declare user information about + * the containing box and its data (presentation or track). + * + * The User Data Box is a container box for informative user-data. This user + * data is formatted as a set of boxes with more specific box types, which + * declare more precisely their content. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_UDTA extends ISO14496_Box +{ + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + $this->setContainer(true); + $this->constructBoxes(); + } +} diff --git a/src/ISO14496/Box/URL.php b/src/ISO14496/Box/URL.php new file mode 100644 index 0000000..f8b7809 --- /dev/null +++ b/src/ISO14496/Box/URL.php @@ -0,0 +1,83 @@ + + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_URL extends ISO14496_Box_Full +{ + /** @var string */ + private $_location; + + /** + * Indicates that the media data is in the same file as the Movie Box + * containing this data reference. + */ + const SELFCONTAINED = 1; + + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + + $this->_location = $this->_reader->read + ($this->_offset + $this->_size - $this->_reader->getOffset()); + } + + /** + * Returns the location. + * + * @return string + */ + public function getLocation() { return $this->_location; } +} diff --git a/src/ISO14496/Box/URN.php b/src/ISO14496/Box/URN.php new file mode 100644 index 0000000..ae4c9b8 --- /dev/null +++ b/src/ISO14496/Box/URN.php @@ -0,0 +1,94 @@ + + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_URN extends ISO14496_Box_Full +{ + /** @var string */ + private $_name; + + /** @var string */ + private $_location; + + /** + * Indicates that the media data is in the same file as the Movie Box + * containing this data reference. + */ + const SELFCONTAINED = 1; + + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + + list ($this->_name, $this->_location) = preg_split + ("/\\x00/", $this->_reader->read + ($this->_offset + $this->_size - $this->_reader->getOffset())); + } + + /** + * Returns the name. + * + * @return string + */ + public function getName() { return $this->_name; } + + /** + * Returns the location. + * + * @return string + */ + public function getLocation() { return $this->_location; } +} diff --git a/src/ISO14496/Box/VMHD.php b/src/ISO14496/Box/VMHD.php new file mode 100644 index 0000000..fbf0e9c --- /dev/null +++ b/src/ISO14496/Box/VMHD.php @@ -0,0 +1,65 @@ +Video Media Header Box contains general presentation information, + * independent of the coding, for video media. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_VMHD extends ISO14496_Box_Full +{ + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + } +} diff --git a/src/ISO14496/Box/XML.php b/src/ISO14496/Box/XML.php new file mode 100644 index 0000000..8df21d4 --- /dev/null +++ b/src/ISO14496/Box/XML.php @@ -0,0 +1,88 @@ +XML Box forms may be used. + * The {@link ISO14496_Box_BXML Binary XML Box} may only be used when there is a + * single well-defined binarization of the XML for that defined format as + * identified by the handler. + * + * Within an XML box the data is in UTF-8 format unless the data starts with a + * byte-order-mark (BOM), which indicates that the data is in UTF-16 format. + * + * @package php-reader + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +final class ISO14496_Box_XML extends ISO14496_Box_Full +{ + /** @var string */ + private $_xml; + + /** + * Constructs the class with given parameters and reads box related data from + * the ISO Base Media file. + * + * @param Reader $reader The reader object. + * @todo The sample flags could be parsed further + */ + public function __construct($reader) + { + parent::__construct($reader); + + $this->_xml = $this->_reader->read + ($this->_offset + $this->_size - $this->_reader->getOffset()); + } + + /** + * Returns the XML data. + * + * @return string + */ + public function getXml() + { + return $this->_xml; + } +} diff --git a/src/ISO14496/Exception.php b/src/ISO14496/Exception.php new file mode 100644 index 0000000..7e6970d --- /dev/null +++ b/src/ISO14496/Exception.php @@ -0,0 +1,51 @@ + + * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup + * @license http://code.google.com/p/php-reader/wiki/License New BSD License + * @version $Rev$ + */ +class ISO14496_Exception extends Exception +{ +}