From 559220106a238626ed8818eac835b2a0b16ed388 Mon Sep 17 00:00:00 2001 From: svollbehr Date: Fri, 19 Feb 2010 21:17:47 +0000 Subject: [PATCH] Add ISO 14496 boxes git-svn-id: http://php-reader.googlecode.com/svn/branches/zend@162 51a70ab9-7547-0410-9469-37e369ee0574 --- src/Zend/Media/Iso14496/Box/Bxml.php | 118 +++++++++ src/Zend/Media/Iso14496/Box/Id32.php | 160 +++++++++++++ src/Zend/Media/Iso14496/Box/Ilst.php | 326 +++++++++++++++++++++++++ src/Zend/Media/Iso14496/Box/Infe.php | 233 ++++++++++++++++++ src/Zend/Media/Iso14496/Box/Mehd.php | 128 ++++++++++ src/Zend/Media/Iso14496/Box/Mfhd.php | 114 +++++++++ src/Zend/Media/Iso14496/Box/Mfro.php | 123 ++++++++++ src/Zend/Media/Iso14496/Box/Moov.php | 72 ++++++ src/Zend/Media/Iso14496/Box/Mvhd.php | 343 +++++++++++++++++++++++++++ src/Zend/Media/Iso14496/Box/Pdin.php | 143 +++++++++++ src/Zend/Media/Iso14496/Box/Pitm.php | 116 +++++++++ src/Zend/Media/Iso14496/Box/Trex.php | 214 +++++++++++++++++ src/Zend/Media/Iso14496/Box/Xml.php | 123 ++++++++++ 13 files changed, 2213 insertions(+) create mode 100644 src/Zend/Media/Iso14496/Box/Bxml.php create mode 100644 src/Zend/Media/Iso14496/Box/Id32.php create mode 100644 src/Zend/Media/Iso14496/Box/Ilst.php create mode 100644 src/Zend/Media/Iso14496/Box/Infe.php create mode 100644 src/Zend/Media/Iso14496/Box/Mehd.php create mode 100644 src/Zend/Media/Iso14496/Box/Mfhd.php create mode 100644 src/Zend/Media/Iso14496/Box/Mfro.php create mode 100644 src/Zend/Media/Iso14496/Box/Moov.php create mode 100644 src/Zend/Media/Iso14496/Box/Mvhd.php create mode 100644 src/Zend/Media/Iso14496/Box/Pdin.php create mode 100644 src/Zend/Media/Iso14496/Box/Pitm.php create mode 100644 src/Zend/Media/Iso14496/Box/Trex.php create mode 100644 src/Zend/Media/Iso14496/Box/Xml.php diff --git a/src/Zend/Media/Iso14496/Box/Bxml.php b/src/Zend/Media/Iso14496/Box/Bxml.php new file mode 100644 index 0000000..090a84b --- /dev/null +++ b/src/Zend/Media/Iso14496/Box/Bxml.php @@ -0,0 +1,118 @@ +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. + * + * @category Zend + * @package Zend_Media + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +final class Zend_Media_Iso14496_Box_Bxml extends Zend_Media_Iso14496_FullBox +{ + /** @var string */ + private $_xml; + + /** + * Constructs the class with given parameters and reads box related data + * from the ISO Base Media file. + * + * @param Zend_Io_Reader $reader The reader object. + * @param Array $options The options array. + */ + public function __construct($reader, &$options = array()) + { + parent::__construct($reader, $options); + + $this->_xml = $this->_reader->read + ($this->getOffset() + $this->getSize() - + $this->_reader->getOffset()); + } + + /** + * Returns the XML data. + * + * @return string + */ + public function getXml() + { + return $this->_xml; + } + + /** + * Sets the binary data. + * + * @param string $xml The XML data. + */ + public function setXml($xml) + { + $this->_xml = $xml; + } + + /** + * Returns the box heap size in bytes. + * + * @return integer + */ + public function getHeapSize() + { + return parent::getHeapSize() + strlen($this->_xml); + } + + /** + * Writes the box data. + * + * @param Zend_Io_Writer $writer The writer object. + * @return void + */ + protected function _writeData($writer) + { + parent::_writeData($writer); + $writer->write($this->_xml); + } +} diff --git a/src/Zend/Media/Iso14496/Box/Id32.php b/src/Zend/Media/Iso14496/Box/Id32.php new file mode 100644 index 0000000..63a7a01 --- /dev/null +++ b/src/Zend/Media/Iso14496/Box/Id32.php @@ -0,0 +1,160 @@ +ID3v2 Box resides under the + * {@link Zend_Media_Iso14496_Box_Meta Meta Box} and stores ID3 version 2 + * meta-data. There may be more than one Id3v2 Box present each with a different + * language code. + * + * @category Zend + * @package Zend_Media + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +final class Zend_Media_Iso14496_Box_Id32 extends Zend_Media_Iso14496_FullBox +{ + /** @var string */ + private $_language = 'und'; + + /** @var Zend_Media_Id3v2 */ + private $_tag; + + /** + * Constructs the class with given parameters and reads box related data + * from the ISO Base Media file. + * + * @param Zend_Io_Reader $reader The reader object. + * @param Array $options The options array. + */ + public function __construct($reader = null, &$options = array()) + { + parent::__construct($reader, $options); + + if ($reader === null) { + return; + } + + $this->_language = + chr(((($tmp = $this->_reader->readUInt16BE()) >> 10) & 0x1f) + + 0x60) . + chr((($tmp >> 5) & 0x1f) + 0x60) . chr(($tmp & 0x1f) + 0x60); + $this->_tag = new Zend_Media_Id3v2 + ($this->_reader, array('readonly' => true)); + } + + /** + * 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; + } + + /** + * Sets the three byte language code as specified in the + * {@link http://www.loc.gov/standards/iso639-2/ ISO 639-2} standard. + * + * @param string $language The language code. + */ + public function setLanguage($language) + { + $this->_language = $language; + } + + /** + * Returns the {@link Zend_Media_Id3v2 Id3v2} tag class instance. + * + * @return string + */ + public function getTag() + { + return $this->_tag; + } + + /** + * Sets the {@link Zend_Media_Id3v2 Id3v2} tag class instance using given + * language. + * + * @param Zend_Media_Id3v2 $tag The tag instance. + * @param string $language The language code. + */ + public function setTag($tag, $language = null) + { + $this->_tag = $tag; + if ($language !== null) { + $this->_language = $language; + } + } + + /** + * Returns the box heap size in bytes. + * + * @return integer + * @todo There has got to be a better way to do this + */ + public function getHeapSize() + { + $writer = new Zend_Io_StringWriter(); + $this->_tag->write($writer); + return parent::getHeapSize() + 2 + $writer->getSize(); + } + + /** + * Writes the box data. + * + * @param Zend_Io_Writer $writer The writer object. + * @return void + */ + protected function _writeData($writer) + { + parent::_writeData($writer); + $writer->writeUInt16BE + (((ord($this->_language[0]) - 0x60) << 10) | + ((ord($this->_language[1]) - 0x60) << 5) | + ord($this->_language[2]) - 0x60); + $this->_tag->write($writer); + } +} diff --git a/src/Zend/Media/Iso14496/Box/Ilst.php b/src/Zend/Media/Iso14496/Box/Ilst.php new file mode 100644 index 0000000..bc1e279 --- /dev/null +++ b/src/Zend/Media/Iso14496/Box/Ilst.php @@ -0,0 +1,326 @@ + + *
  • _nam -- Name of the track
  • + *
  • _ART -- Name of the artist
  • + *
  • aART -- Name of the album artist
  • + *
  • _alb -- Name of the album
  • + *
  • _grp -- Grouping
  • + *
  • _day -- Year of publication
  • + *
  • trkn -- Track number (number/total)
  • + *
  • disk -- Disk number (number/total)
  • + *
  • tmpo -- BPM tempo
  • + *
  • _wrt -- Name of the composer
  • + *
  • _cmt -- Comments
  • + *
  • _gen -- Genre as string
  • + *
  • gnre -- Genre as an ID3v1 code, added by one
  • + *
  • cpil -- Part of a compilation (0/1)
  • + *
  • tvsh -- Name of the (television) show
  • + *
  • sonm -- Sort name of the track
  • + *
  • soar -- Sort name of the artist
  • + *
  • soaa -- Sort name of the album artist
  • + *
  • soal -- Sort name of the album
  • + *
  • soco -- Sort name of the composer
  • + *
  • sosn -- Sort name of the show
  • + *
  • _lyr -- Lyrics
  • + *
  • covr -- Cover (or other) artwork binary data
  • + *
  • _too -- Information about the software
  • + * + * + * @category Zend + * @package Zend_Media + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + * @since iTunes/iPod specific + */ +final class Zend_Media_Iso14496_Box_Ilst extends Zend_Media_Iso14496_Box +{ + /** + * Constructs the class with given parameters and reads box related data + * from the ISO Base Media file. + * + * @param Zend_Io_Reader $reader The reader object. + * @param Array $options The options array. + */ + public function __construct($reader = null, &$options = array()) + { + parent::__construct($reader, $options); + $this->setContainer(true); + + if ($reader === null) { + return; + } + + $this->constructBoxes('Zend_Media_Iso14496_Box_Ilst_Container'); + } + + /** + * Override magic function so that $obj->value on a box will return the data + * box instead of the data container box. + * + * @param string $name The box or field name. + * @return mixed + */ + public function __get($name) + { + if (strlen($name) == 3) { + $name = "\xa9" . $name; + } + if ($name[0] == '_') { + $name = "\xa9" . substr($name, 1, 3); + } + if ($this->hasBox($name)) { + $boxes = $this->getBoxesByIdentifier($name); + return $boxes[0]->data; + } + if (method_exists($this, 'get' . ucfirst($name))) { + return call_user_func(array($this, 'get' . ucfirst($name))); + } + return $this->addBox + (new Zend_Media_Iso14496_Box_Ilst_Container($name))->data; + } +} + +/** + * Generic iTunes/iPod DATA Box container. + * + * @category Zend + * @package Zend_Media + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + * @since iTunes/iPod specific + * @ignore + */ +final class Zend_Media_Iso14496_Box_Ilst_Container + extends Zend_Media_Iso14496_Box +{ + /** + * Constructs the class with given parameters and reads box related data + * from the ISO Base Media file. + * + * @param Zend_Io_Reader $reader The reader object. + * @param Array $options The options array. + */ + public function __construct($reader = null, &$options = array()) + { + parent::__construct(is_string($reader) ? null : $reader, $options); + $this->setContainer(true); + + if (is_string($reader)) { + $this->setType($reader); + $this->addBox(new Zend_Media_Iso14496_Box_Data()); + } else { + $this->constructBoxes(); + } + } +} + +/**#@+ @ignore */ +require_once 'Zend/Media/Iso14496/FullBox.php'; +/**#@-*/ + +/** + * A box that contains data for iTunes/iPod specific boxes. + * + * @category Zend + * @package Zend_Media + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + * @since iTunes/iPod specific + */ +final class Zend_Media_Iso14496_Box_Data extends Zend_Media_Iso14496_FullBox +{ + /** @var mixed */ + private $_value; + + /** A flag to indicate that the data is an unsigned 8-bit integer. */ + const INTEGER = 0x0; + + /** + * A flag to indicate that the data is an unsigned 8-bit integer. Different + * value used in old versions of iTunes. + */ + const INTEGER_OLD_STYLE = 0x15; + + /** A flag to indicate that the data is a string. */ + const STRING = 0x1; + + /** A flag to indicate that the data is the contents of an JPEG image. */ + const JPEG = 0xd; + + /** A flag to indicate that the data is the contents of a PNG image. */ + const PNG = 0xe; + + /** + * Constructs the class with given parameters and reads box related data + * from the ISO Base Media file. + * + * @param Zend_Io_Reader $reader The reader object. + * @param Array $options The options array. + */ + public function __construct($reader = null, &$options = array()) + { + parent::__construct($reader, $options); + + if ($reader === null) { + return; + } + + $this->_reader->skip(4); + $data = $this->_reader->read + ($this->getOffset() + $this->getSize() - + $this->_reader->getOffset()); + switch ($this->getFlags()) { + case self::INTEGER: + // break intentionally omitted + case self::INTEGER_OLD_STYLE: + for ($i = 0; $i < strlen($data); $i++) { + $this->_value .= ord($data[$i]); + } + break; + case self::STRING: + // break intentionally omitted + default: + $this->_value = $data; + break; + } + } + + /** + * Returns the value this box contains. + * + * @return mixed + */ + public function getValue() + { + return $this->_value; + } + + /** + * Sets the value this box contains. + * + * @return mixed + */ + public function setValue($value, $type = null) + { + $this->_value = (string)$value; + if ($type === null && is_string($value)) { + $this->_flags = self::STRING; + } + if ($type === null && is_int($value)) { + $this->_flags = self::INTEGER; + } + if ($type !== null) { + $this->_flags = $type; + } + } + + /** + * Override magic function so that $obj->data will return the current box + * instead of an error. For other values the method will attempt to call a + * getter method. + * + * If there are no 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 ($name == 'data') { + return $this; + } + if (method_exists($this, 'get' . ucfirst($name))) { + return call_user_func(array($this, 'get' . ucfirst($name))); + } + require_once 'Zend/Media/Iso14496/Exception.php'; + throw new Zend_Media_Iso14496_Exception('Unknown box/field: ' . $name); + } + + /** + * Returns the box heap size in bytes. + * + * @return integer + */ + public function getHeapSize() + { + return parent::getHeapSize() + 4 + strlen($this->_value); + } + + /** + * Writes the box data. + * + * @param Zend_Io_Writer $writer The writer object. + * @return void + */ + protected function _writeData($writer) + { + parent::_writeData($writer); + $writer->write("\0\0\0\0"); + switch ($this->getFlags()) { + case self::INTEGER: + // break intentionally omitted + case self::INTEGER_OLD_STYLE: + for ($i = 0; $i < strlen($this->_value); $i++) { + $writer->writeInt8($this->_value[$i]); + } + break; + case self::STRING: + // break intentionally omitted + default: + $writer->write($this->_value); + break; + } + } +} diff --git a/src/Zend/Media/Iso14496/Box/Infe.php b/src/Zend/Media/Iso14496/Box/Infe.php new file mode 100644 index 0000000..f30b1e2 --- /dev/null +++ b/src/Zend/Media/Iso14496/Box/Infe.php @@ -0,0 +1,233 @@ +Item Information Entry Box contains the entry information. + * + * @category Zend + * @package Zend_Media + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +final class Zend_Media_Iso14496_Box_Infe extends Zend_Media_Iso14496_FullBox +{ + /** @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 Zend_Io_Reader $reader The reader object. + * @param Array $options The options array. + */ + public function __construct($reader, &$options = array()) + { + parent::__construct($reader, $options); + + $this->_itemId = $this->_reader->readUInt16BE(); + $this->_itemProtectionIndex = $this->_reader->readUInt16BE(); + list($this->_itemName, $this->_contentType, $this->_contentEncoding) = + preg_split + ("/\\x00/", $this->_reader->read + ($this->getOffset() + $this->getSize() - + $this->_reader->getOffset())); + } + + /** + * Returns the item identifier. The value is either 0 for the primary + * resource (e.g. the XML contained in an + * {@link Zend_Media_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; + } + + /** + * Sets the item identifier. The value must be either 0 for the primary + * resource (e.g. the XML contained in an + * {@link Zend_Media_Iso14496_Box_Xml XML Box}) or the ID of the item for + * which the following information is defined. + * + * @param integer $itemId The item identifier. + */ + public function setItemId($itemId) + { + $this->_itemId = $itemId; + } + + /** + * Returns the item protection index. The value is either 0 for an + * unprotected item, or the one-based index into the + * {@link Zend_Media_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; + } + + /** + * Sets the item protection index. The value must be either 0 for an + * unprotected item, or the one-based index into the + * {@link Zend_Media_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). + * + * @param integer $itemProtectionIndex The index. + */ + public function setItemProtectionIndex($itemProtectionIndex) + { + $this->_itemProtectionIndex = $itemProtectionIndex; + } + + /** + * Returns the symbolic name of the item. + * + * @return string + */ + public function getItemName() + { + return $this->_itemName; + } + + /** + * Sets the symbolic name of the item. + * + * @param string $itemName The item name. + */ + public function setItemName($itemName) + { + $this->_itemName = $itemName; + } + + /** + * Returns the MIME type for the item. + * + * @return string + */ + public function getContentType() + { + return $this->_contentType; + } + + /** + * Sets the MIME type for the item. + * + * @param string $contentType The content type. + */ + public function setContentType($contentType) + { + $this->_contentType = $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; + } + + /** + * Sets 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. + * + * @param string $contentEncoding The content encoding. + */ + public function setContentEncoding($contentEncoding) + { + $this->_contentEncoding = $contentEncoding; + } + + /** + * Returns the box heap size in bytes. + * + * @return integer + */ + public function getHeapSize() + { + return parent::getHeapSize() + 7 + strlen($this->_itemName) + + strlen($this->_contentType) + strlen($this->_contentEncoding); + } + + /** + * Writes the box data. + * + * @param Zend_Io_Writer $writer The writer object. + * @return void + */ + protected function _writeData($writer) + { + parent::_writeData($writer); + $writer->writeUInt16BE($this->_itemId) + ->writeUInt16BE($this->_itemProtectionIndex) + ->writeString8($this->_itemName, 1) + ->writeString8($this->_contentType, 1) + ->writeString8($this->_contentEncoding, 1); + } +} diff --git a/src/Zend/Media/Iso14496/Box/Mehd.php b/src/Zend/Media/Iso14496/Box/Mehd.php new file mode 100644 index 0000000..5f09558 --- /dev/null +++ b/src/Zend/Media/Iso14496/Box/Mehd.php @@ -0,0 +1,128 @@ +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. + * + * @category Zend + * @package Zend_Media + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +final class Zend_Media_Iso14496_Box_Mehd extends Zend_Media_Iso14496_FullBox +{ + /** @var integer */ + private $_fragmentDuration; + + /** + * Constructs the class with given parameters and reads box related data + * from the ISO Base Media file. + * + * @param Zend_Io_Reader $reader The reader object. + * @param Array $options The options array. + */ + public function __construct($reader, &$options = array()) + { + parent::__construct($reader, $options); + + 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 Zend_Media_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; + } + + /** + * Sets the length of the presentation of the whole movie including + * fragments (in the timescale indicated in the + * {@link Zend_Media_Iso14496_Box_Mvhd Movie Header Box}). The value of + * this field must correspond to the duration of the longest track, + * including movie fragments. + * + * @param integer $fragmentDuration The fragment duration. + */ + public function setFragmentDuration($fragmentDuration) + { + $this->_fragmentDuration = $fragmentDuration; + } + + /** + * Returns the box heap size in bytes. + * + * @return integer + */ + public function getHeapSize() + { + return parent::getHeapSize() + ($this->getVersion() == 1 ? 8 : 4); + } + + /** + * Writes the box data. + * + * @param Zend_Io_Writer $writer The writer object. + * @return void + */ + protected function _writeData($writer) + { + parent::_writeData($writer); + if ($this->getVersion() == 1) { + $writer->writeInt64BE($this->_fragmentDuration); + } else { + $writer->writeUInt32BE($this->_fragmentDuration); + } + } +} diff --git a/src/Zend/Media/Iso14496/Box/Mfhd.php b/src/Zend/Media/Iso14496/Box/Mfhd.php new file mode 100644 index 0000000..8fb82b5 --- /dev/null +++ b/src/Zend/Media/Iso14496/Box/Mfhd.php @@ -0,0 +1,114 @@ +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. + * + * @category Zend + * @package Zend_Media + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +final class Zend_Media_Iso14496_Box_Mfhd extends Zend_Media_Iso14496_FullBox +{ + /** @var integer */ + private $_sequenceNumber; + + /** + * Constructs the class with given parameters and reads box related data + * from the ISO Base Media file. + * + * @param Zend_Io_Reader $reader The reader object. + * @param Array $options The options array. + */ + public function __construct($reader, &$options = array()) + { + parent::__construct($reader, $options); + + $this->_sequenceNumber = $this->_reader->readUInt32BE(); + } + + /** + * Returns the ordinal number of this fragment, in increasing order. + * + * @return integer + */ + public function getSequenceNumber() + { + return $this->_sequenceNumber; + } + + /** + * Sets the ordinal number of this fragment, in increasing order. + * + * @param integer $sequenceNumber The sequence number. + */ + public function setSequenceNumber($sequenceNumber) + { + $this->_sequenceNumber = $sequenceNumber; + } + + /** + * Returns the box heap size in bytes. + * + * @return integer + */ + public function getHeapSize() + { + return parent::getHeapSize() + 4; + } + + /** + * Writes the box data. + * + * @param Zend_Io_Writer $writer The writer object. + * @return void + */ + protected function _writeData($writer) + { + parent::_writeData($writer); + $writer->writeUInt32BE($this->_sequenceNumber); + } +} diff --git a/src/Zend/Media/Iso14496/Box/Mfro.php b/src/Zend/Media/Iso14496/Box/Mfro.php new file mode 100644 index 0000000..40e0efd --- /dev/null +++ b/src/Zend/Media/Iso14496/Box/Mfro.php @@ -0,0 +1,123 @@ +Movie Fragment Random Access Offset Box provides a copy of the + * length field from the enclosing {@link Zend_Media_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. + * + * @category Zend + * @package Zend_Media + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +final class Zend_Media_Iso14496_Box_Mfro extends Zend_Media_Iso14496_FullBox +{ + /** @var integer */ + private $_parentSize; + + /** + * Constructs the class with given parameters and reads box related data + * from the ISO Base Media file. + * + * @param Zend_Io_Reader $reader The reader object. + * @param Array $options The options array. + */ + public function __construct($reader, &$options = array()) + { + parent::__construct($reader, $options); + + $this->_parentSize = $this->_reader->readUInt32BE(); + } + + /** + * Returns the number of bytes of the enclosing + * {@link Zend_Media_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 getParentSize() + { + return $this->_parentSize; + } + + /** + * Sets the number of bytes of the enclosing + * {@link Zend_Media_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. + * + * @param integer $parentSize The number of bytes. + */ + public function setParentSize($parentSize) + { + $this->_parentSize = $parentSize; + } + + /** + * Returns the box heap size in bytes. + * + * @return integer + */ + public function getHeapSize() + { + return parent::getHeapSize() + 4; + } + + /** + * Writes the box data. + * + * @param Zend_Io_Writer $writer The writer object. + * @return void + */ + protected function _writeData($writer) + { + parent::_writeData($writer); + $writer->writeUInt32BE($this->_parentSize); + } +} diff --git a/src/Zend/Media/Iso14496/Box/Moov.php b/src/Zend/Media/Iso14496/Box/Moov.php new file mode 100644 index 0000000..cc9ab80 --- /dev/null +++ b/src/Zend/Media/Iso14496/Box/Moov.php @@ -0,0 +1,72 @@ +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. + * + * @category Zend + * @package Zend_Media + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +final class Zend_Media_Iso14496_Box_Moov extends Zend_Media_Iso14496_Box +{ + /** + * Constructs the class with given parameters and reads box related data + * from the ISO Base Media file. + * + * @param Zend_Io_Reader $reader The reader object. + * @param Array $options The options array. + */ + public function __construct($reader = null, &$options = array()) + { + parent::__construct($reader, $options); + $this->setContainer(true); + + if ($reader === null) { + return; + } + + $this->constructBoxes(); + } +} diff --git a/src/Zend/Media/Iso14496/Box/Mvhd.php b/src/Zend/Media/Iso14496/Box/Mvhd.php new file mode 100644 index 0000000..8ed8d44 --- /dev/null +++ b/src/Zend/Media/Iso14496/Box/Mvhd.php @@ -0,0 +1,343 @@ +Movie Header Box defines overall information which is + * media-independent, and relevant to the entire presentation considered as a + * whole. + * + * @category Zend + * @package Zend_Media + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +final class Zend_Media_Iso14496_Box_Mvhd extends Zend_Media_Iso14496_FullBox +{ + /** @var integer */ + private $_creationTime; + + /** @var integer */ + private $_modificationTime; + + /** @var integer */ + private $_timescale; + + /** @var integer */ + private $_duration; + + /** @var integer */ + private $_rate = 1.0; + + /** @var integer */ + private $_volume = 1.0; + + /** @var Array */ + private $_matrix = array + (0x00010000, 0, 0, 0, 0x00010000, 0, 0, 0, 0x40000000); + + /** @var integer */ + private $_nextTrackId; + + /** + * Constructs the class with given parameters and reads box related data + * from the ISO Base Media file. + * + * @param Zend_Io_Reader $reader The reader object. + * @param Array $options The options array. + */ + public function __construct($reader, &$options = array()) + { + parent::__construct($reader, $options); + + 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) + + (float)("0." . ((string)($tmp & 0xffff))); + $this->_volume = + ((($tmp = $this->_reader->readUInt16BE()) >> 8) & 0xff) + + (float)("0." . ((string)($tmp & 0xff))); + $this->_reader->skip(10); + for ($i = 0; $i < 9; $i++) { + $this->_matrix[$i] = $this->_reader->readUInt32BE(); + } + $this->_reader->skip(24); + $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; + } + + /** + * Sets the creation time of the presentation in seconds since midnight, + * Jan. 1, 1904, in UTC time. + * + * @param integer $creationTime The creation time. + */ + public function setCreationTime($creationTime) + { + $this->_creationTime = $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; + } + + /** + * Sets the most recent time the presentation was modified in seconds since + * midnight, Jan. 1, 1904, in UTC time. + * + * @param integer $modificationTime The most recent time the presentation + * was modified. + */ + public function setModificationTime($modificationTime) + { + $this->_modificationTime = $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; + } + + /** + * Sets 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. + * + * @param integer $timescale The time-scale for the entire presentation. + */ + public function setTimescale($timescale) + { + $this->_timescale = $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; + } + + /** + * Sets the length of the presentation in the indicated timescale. This + * property must be derived from the presentation's tracks: the value of + * this field must correspond to the duration of the longest track in the + * presentation. + * + * @param integer $duration The length of the presentation. + */ + public function setDuration($duration) + { + $this->_duration = $duration; + } + + /** + * Returns the preferred rate to play the presentation. 1.0 is normal + * forward playback. + * + * @return integer + */ + public function getRate() + { + return $this->_rate; + } + + /** + * Sets the preferred rate to play the presentation. 1.0 is normal + * forward playback. + * + * @param integer $rate The preferred play rate. + */ + public function setRate($rate) + { + $this->_rate = $rate; + } + + /** + * Returns the preferred playback volume. 1.0 is full volume. + * + * @return integer + */ + public function getVolume() + { + return $this->_volume; + } + + /** + * Sets the preferred playback volume. 1.0 is full volume. + * + * @param integer $volume The playback volume. + */ + public function setVolume($volume) + { + $this->_volume = $volume; + } + + /** + * Returns the transformation matrix for the video; (u,v,w) are restricted + * here to (0,0,1), hex values (0,0,0x40000000). + * + * @return Array + */ + public function getMatrix() + { + return $this->_matrix; + } + + /** + * Sets the transformation matrix for the video; (u,v,w) are restricted + * here to (0,0,1), hex values (0,0,0x40000000). + * + * @param Array $matrix The transformation matrix array of 9 values + */ + public function setMatrix($matrix) + { + $this->_matrix = $matrix; + } + + /** + * 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; + } + + /** + * Sets 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 must be + * larger than the largest track-ID in use. + * + * @param integer $nextTrackId The next track ID. + */ + public function setNextTrackId($nextTrackId) + { + $this->_nextTrackId = $nextTrackId; + } + + /** + * Returns the box heap size in bytes. + * + * @return integer + */ + public function getHeapSize() + { + return parent::getHeapSize() + + ($this->getVersion() == 1 ? 28 : 16) + 80; + } + + /** + * Writes the box data. + * + * @param Zend_Io_Writer $writer The writer object. + * @return void + */ + protected function _writeData($writer) + { + parent::_writeData($writer); + if ($this->getVersion() == 1) { + $writer->writeInt64BE($this->_creationTime) + ->writeInt64BE($this->_modificationTime) + ->writeUInt32BE($this->_timescale) + ->writeInt64BE($this->_duration); + } else { + $writer->writeUInt32BE($this->_creationTime) + ->writeUInt32BE($this->_modificationTime) + ->writeUInt32BE($this->_timescale) + ->writeUInt32BE($this->_duration); + } + + @list(, $rateDecimals) = explode('.', (float)$this->_rate); + @list(, $volumeDecimals) = explode('.', (float)$this->_volume); + $writer->writeUInt32BE(floor($this->_rate) << 16 | $rateDecimals) + ->writeUInt16BE(floor($this->_volume) << 8 | $volumeDecimals) + ->write(str_pad('', 10, "\0")); + for ($i = 0; $i < 9; $i++) { + $writer->writeUInt32BE($this->_matrix[$i]); + } + $writer->write(str_pad('', 24, "\0")) + ->writeUInt32BE($this->_nextTrackId); + } +} diff --git a/src/Zend/Media/Iso14496/Box/Pdin.php b/src/Zend/Media/Iso14496/Box/Pdin.php new file mode 100644 index 0000000..78a4941 --- /dev/null +++ b/src/Zend/Media/Iso14496/Box/Pdin.php @@ -0,0 +1,143 @@ +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. + * + * @category Zend + * @package Zend_Media + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +final class Zend_Media_Iso14496_Box_Pdin extends Zend_Media_Iso14496_FullBox +{ + /** @var Array */ + private $_progressiveDownloadInfo = array(); + + /** + * Constructs the class with given parameters and reads box related data + * from the ISO Base Media file. + * + * @param Zend_Io_Reader $reader The reader object. + * @param Array $options The options array. + */ + public function __construct($reader, &$options = array()) + { + parent::__construct($reader, $options); + + while ($this->_reader->getOffset() < + $this->getOffset() + $this->getSize()) { + $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; + } + + /** + * Sets the progressive download information array. The array must consist + * 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. + * + * @param Array $progressiveDownloadInfo The array of values. + */ + public function setProgressiveDownloadInfo($progressiveDownloadInfo) + { + $this->_progressiveDownloadInfo = $progressiveDownloadInfo; + } + + /** + * Returns the box heap size in bytes. + * + * @return integer + */ + public function getHeapSize() + { + return parent::getHeapSize() + + count($this->_progressiveDownloadInfo) * 8; + } + + /** + * Writes the box data. + * + * @param Zend_Io_Writer $writer The writer object. + * @return void + */ + protected function _writeData($writer) + { + parent::_writeData($writer); + for ($i = 1; $i <= count($this->_timeToSampleTable); $i++) { + $writer->writeUInt32BE + ($this->_progressiveDownloadInfo[$i]['rate']) + ->writeUInt32BE + ($this->_progressiveDownloadInfo[$i]['initialDelay']); + } + } +} diff --git a/src/Zend/Media/Iso14496/Box/Pitm.php b/src/Zend/Media/Iso14496/Box/Pitm.php new file mode 100644 index 0000000..ccd9af5 --- /dev/null +++ b/src/Zend/Media/Iso14496/Box/Pitm.php @@ -0,0 +1,116 @@ +Primary Item + * Box must occur, or there must be a box within the meta-box (e.g. an + * {@link Zend_Media_Iso14496_Box_Xml XML Box}) containing the primary + * information in the format required by the identified handler. + * + * @category Zend + * @package Zend_Media + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +final class Zend_Media_Iso14496_Box_Pitm extends Zend_Media_Iso14496_FullBox +{ + /** @var string */ + private $_itemId; + + /** + * Constructs the class with given parameters and reads box related data + * from the ISO Base Media file. + * + * @param Zend_Io_Reader $reader The reader object. + * @param Array $options The options array. + */ + public function __construct($reader, &$options = array()) + { + parent::__construct($reader, $options); + + $this->_itemId = $this->_reader->readUInt16BE(); + } + + /** + * Returns the identifier of the primary item. + * + * @return integer + */ + public function getItemId() + { + return $this->_itemId; + } + + /** + * Sets the identifier of the primary item. + * + * @param integer $itemId The item identification. + */ + public function setItemId($itemId) + { + $this->_itemId = $itemId; + } + + /** + * Returns the box heap size in bytes. + * + * @return integer + */ + public function getHeapSize() + { + return parent::getHeapSize() + 2; + } + + /** + * Writes the box data. + * + * @param Zend_Io_Writer $writer The writer object. + * @return void + */ + protected function _writeData($writer) + { + parent::_writeData($writer); + $writer->writeUInt16BE($this->_itemId); + } +} diff --git a/src/Zend/Media/Iso14496/Box/Trex.php b/src/Zend/Media/Iso14496/Box/Trex.php new file mode 100644 index 0000000..51d4717 --- /dev/null +++ b/src/Zend/Media/Iso14496/Box/Trex.php @@ -0,0 +1,214 @@ +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 Zend_Media_Iso14496_Box_Traf Track Fragment Box}. + * + * @category Zend + * @package Zend_Media + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +final class Zend_Media_Iso14496_Box_Trex extends Zend_Media_Iso14496_FullBox +{ + /** @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 Zend_Io_Reader $reader The reader object. + * @param Array $options The options array. + * @todo The sample flags could be parsed further + */ + public function __construct($reader, &$options = array()) + { + parent::__construct($reader, $options); + + $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; + } + + /** + * Sets the default track identifier. + * + * @param integer $trackId The track identifier. + */ + public function setTrackId($trackId) + { + $this->_trackId = $trackId; + } + + /** + * Returns the default sample description index. + * + * @return integer + */ + public function getDefaultSampleDescriptionIndex() + { + return $this->_defaultSampleDescriptionIndex; + } + + /** + * Sets the default sample description index. + * + * @param integer $defaultSampleDescriptionIndex The description index. + */ + public function getDefaultSampleDescriptionIndex + ($defaultSampleDescriptionIndex) + { + $this->_defaultSampleDescriptionIndex = $defaultSampleDescriptionIndex; + } + + /** + * Returns the default sample duration. + * + * @return integer + */ + public function getDefaultSampleDuration() + { + return $this->_defaultSampleDuration; + } + + /** + * Sets the default sample duration. + * + * @param integer $defaultSampleDuration The sample duration. + */ + public function setDefaultSampleDuration($defaultSampleDuration) + { + $this->_defaultSampleDuration = $defaultSampleDuration; + } + + /** + * Returns the default sample size. + * + * @return integer + */ + public function getDefaultSampleSize() + { + return $this->_defaultSampleSize; + } + + /** + * Sets the default sample size. + * + * @param integer $defaultSampleSize The sample size. + */ + public function setDefaultSampleSize($defaultSampleSize) + { + $this->_defaultSampleSize = $defaultSampleSize; + } + + /** + * Returns the default sample flags. + * + * @return integer + */ + public function getDefaultSampleFlags() + { + return $this->_defaultSampleFlags; + } + + /** + * Sets the default sample flags. + * + * @param integer $defaultSampleFlags The sample flags. + */ + public function setDefaultSampleFlags() + { + $this->_defaultSampleFlags = $defaultSampleFlags; + } + + /** + * Returns the box heap size in bytes. + * + * @return integer + */ + public function getHeapSize() + { + return parent::getHeapSize() + 20; + } + + /** + * Writes the box data. + * + * @param Zend_Io_Writer $writer The writer object. + * @return void + */ + protected function _writeData($writer) + { + parent::_writeData($writer); + $writer->writeUInt32BE($this->_trackId) + ->writeUInt32BE($this->_defaultSampleDescriptionIndex) + ->writeUInt32BE($this->_defaultSampleDuration) + ->writeUInt32BE($this->_defaultSampleSize) + ->writeUInt32BE($this->_defaultSampleFlags); + } +} diff --git a/src/Zend/Media/Iso14496/Box/Xml.php b/src/Zend/Media/Iso14496/Box/Xml.php new file mode 100644 index 0000000..e8aaebb --- /dev/null +++ b/src/Zend/Media/Iso14496/Box/Xml.php @@ -0,0 +1,123 @@ +XML Box forms may be used. + * The {@link Zend_Media_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. + * + * @category Zend + * @package Zend_Media + * @subpackage ISO 14496 + * @author Sven Vollbehr + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +final class Zend_Media_Iso14496_Box_Xml extends Zend_Media_Iso14496_FullBox +{ + /** @var string */ + private $_xml; + + /** + * Constructs the class with given parameters and reads box related data + * from the ISO Base Media file. + * + * @param Zend_Io_Reader $reader The reader object. + * @param Array $options The options array. + */ + public function __construct($reader = null, &$options = array()) + { + parent::__construct($reader, $options); + + if ($reader === null) { + return; + } + + $this->_xml = $this->_reader->read + ($this->getOffset() + $this->getSize() - + $this->_reader->getOffset()); + } + + /** + * Returns the XML data. + * + * @return string + */ + public function getXml() + { + return $this->_xml; + } + + /** + * Sets the XML data. + * + * @param string $xml The XML data. + */ + public function setXml($xml) + { + $this->_xml = $xml; + } + + /** + * Returns the box heap size in bytes. + * + * @return integer + */ + public function getHeapSize() + { + return parent::getHeapSize() + strlen($this->_xml); + } + + /** + * Writes the box data. + * + * @param Zend_Io_Writer $writer The writer object. + * @return void + */ + protected function _writeData($writer) + { + parent::_writeData($writer); + $writer->write($this->_xml); + } +}