diff --git a/src/ISO14496.php b/src/ISO14496.php index 068f4a0..c3f7cef 100644 --- a/src/ISO14496.php +++ b/src/ISO14496.php @@ -7,12 +7,12 @@ * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * - * - Redistributions of source code must retain the above copyright notice, + *
  • Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, + *
  • Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - * - Neither the name of the project workgroup nor the names of its + *
  • Neither the name of the project workgroup nor the names of its * contributors may be used to endorse or promote products derived from this * software without specific prior written permission. * @@ -57,6 +57,149 @@ require_once("ISO14496/Box.php"); * general. * * The ISO Base Media File Format is a base format for media file formats. + * + * + * An overall view of the normal encapsulation structure is provided in the + * following table. + * + * The table shows those boxes that may occur at the top-level in the left-most + * column; indentation is used to show possible containment. Thus, for example, + * a {@link ISO14496_Box_TKHD Track Header Box} is found in a + * {@link ISO14496_Box_TRAK Track Box}, which is found in a + * {@link ISO14496_Box_MOOV Movie Box}. Not all boxes need be used in all files; + * the mandatory boxes are marked with bold typeface. See the description of the + * individual boxes for a discussion of what must be assumed if the optional + * boxes are not present. + * + * User data objects shall be placed only in {@link ISO14496_Box_MOOV Movie} or + * {@link ISO14496_Box_TRAK Track Boxes}, and objects using an extended type may + * be placed in a wide variety of containers, not just the top level. + * + * + * + * There are two non-standard extensions to the ISO 14496 standard that add the + * ability to include file meta information. Both the boxes reside under + * moov.udta.meta. + * + * * * @package php-reader * @subpackage ISO 14496 diff --git a/src/ISO14496/Box.php b/src/ISO14496/Box.php index 3de1aaa..a2071ba 100644 --- a/src/ISO14496/Box.php +++ b/src/ISO14496/Box.php @@ -242,11 +242,25 @@ class ISO14496_Box * @param string $name The box or field name. * @return mixed */ - public function __get($name) { + 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); } + + /** + * Magic function so that isset($obj->value) will work. This method checks + * whether the box is a container and contains a box that matches the + * identifier. + * + * @param string $name The box name. + * @return boolean + */ + public function __isset($name) + { + return ($this->isContainer() && isset($this->_boxes[$name])); + } } diff --git a/src/ISO14496/Box/BXML.php b/src/ISO14496/Box/BXML.php index e0c7f82..fb8e821 100644 --- a/src/ISO14496/Box/BXML.php +++ b/src/ISO14496/Box/BXML.php @@ -65,7 +65,6 @@ final class ISO14496_Box_BXML extends ISO14496_Box_Full * the ISO Base Media file. * * @param Reader $reader The reader object. - * @todo The sample flags could be parsed further */ public function __construct($reader) { diff --git a/src/ISO14496/Box/CO64.php b/src/ISO14496/Box/CO64.php index ea62212..51f7b80 100644 --- a/src/ISO14496/Box/CO64.php +++ b/src/ISO14496/Box/CO64.php @@ -80,15 +80,13 @@ final class ISO14496_Box_CO64 extends ISO14496_Box_Full $entryCount = $this->_reader->readUInt32BE(); for ($i = 1; $i < $entryCount; $i++) - $this->_chunkOffsetTable[$i] = array - ("chunkOffset" => $this->_reader->readInt64BE()); + $this->_chunkOffsetTable[$i] = $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. + * Returns an array of values. Each entry has the entry number as its index + * and a 64 bit integer that gives the offset of the start of a chunk into + * its containing media file as its value. * * @return Array */ diff --git a/src/ISO14496/Box/ELST.php b/src/ISO14496/Box/ELST.php index 1e80958..bc81fde 100644 --- a/src/ISO14496/Box/ELST.php +++ b/src/ISO14496/Box/ELST.php @@ -92,7 +92,7 @@ final class ISO14496_Box_ELST extends ISO14496_Box_Full * 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 + * {@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 diff --git a/src/ISO14496/Box/HDLR.php b/src/ISO14496/Box/HDLR.php index f2e0e00..5112481 100644 --- a/src/ISO14496/Box/HDLR.php +++ b/src/ISO14496/Box/HDLR.php @@ -76,7 +76,7 @@ final class ISO14496_Box_HDLR extends ISO14496_Box_Full $this->_reader->skip(4); $this->_handlerType = $this->_reader->read(4); $this->_reader->skip(12); - $this->_name = $this->_reader->read + $this->_name = $this->_reader->readString8 ($this->_offset + $this->_size - $this->_reader->getOffset()); } diff --git a/src/ISO14496/Box/MINF.php b/src/ISO14496/Box/MINF.php index bac8d43..017e621 100644 --- a/src/ISO14496/Box/MINF.php +++ b/src/ISO14496/Box/MINF.php @@ -52,4 +52,16 @@ require_once("ISO14496/Box.php"); */ final class ISO14496_Box_MINF 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 index aa6a6e7..2ff90dc 100644 --- a/src/ISO14496/Box/MVHD.php +++ b/src/ISO14496/Box/MVHD.php @@ -131,7 +131,7 @@ final class ISO14496_Box_MVHD extends ISO14496_Box_Full /** * Returns the length of the presentation in the indicated timescale. This - * property is derived from the presentation’s tracks: the value of this field + * 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 diff --git a/src/ISO14496/Box/PITM.php b/src/ISO14496/Box/PITM.php index 8b913b8..b9fed10 100644 --- a/src/ISO14496/Box/PITM.php +++ b/src/ISO14496/Box/PITM.php @@ -65,7 +65,6 @@ final class ISO14496_Box_PITM extends ISO14496_Box_Full * the ISO Base Media file. * * @param Reader $reader The reader object. - * @todo The sample flags could be parsed further */ public function __construct($reader) { diff --git a/src/ISO14496/Box/STGP.php b/src/ISO14496/Box/SBGP.php similarity index 98% rename from src/ISO14496/Box/STGP.php rename to src/ISO14496/Box/SBGP.php index 8ad17d4..606dc28 100644 --- a/src/ISO14496/Box/STGP.php +++ b/src/ISO14496/Box/SBGP.php @@ -62,7 +62,7 @@ require_once("ISO14496/Box/Full.php"); * @license http://code.google.com/p/php-reader/wiki/License New BSD License * @version $Rev$ */ -final class ISO14496_Box_STGP extends ISO14496_Box_Full +final class ISO14496_Box_SBGP extends ISO14496_Box_Full { /** @var integer */ private $_groupingType; diff --git a/src/ISO14496/Box/STCO.php b/src/ISO14496/Box/STCO.php index 33a2fef..66c0d27 100644 --- a/src/ISO14496/Box/STCO.php +++ b/src/ISO14496/Box/STCO.php @@ -79,16 +79,14 @@ final class ISO14496_Box_STCO extends ISO14496_Box_Full parent::__construct($reader); $entryCount = $this->_reader->readUInt32BE(); - for ($i = 0; $i < $entryCount; $i++) - $this->_chunkOffsetTable[] = array - ("chunkOffset" => $this->_reader->readUInt32BE()); + for ($i = 1; $i < $entryCount; $i++) + $this->_chunkOffsetTable[$i] = $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. + * Returns an array of values. Each entry has the entry number as its index + * and a 32 bit integer that gives the offset of the start of a chunk into + * its containing media file as its value. * * @return Array */ diff --git a/src/ISO14496/Box/STSS.php b/src/ISO14496/Box/STSS.php index a726657..662e2b5 100644 --- a/src/ISO14496/Box/STSS.php +++ b/src/ISO14496/Box/STSS.php @@ -69,15 +69,13 @@ final class ISO14496_Box_STSS extends ISO14496_Box_Full $entryCount = $this->_reader->readUInt32BE(); for ($i = 1; $i < $entryCount; $i++) - $this->_syncSampleTable[$i] = array - ("sampleNumber" => $this->_reader->readUInt32BE()); + $this->_syncSampleTable[$i] = $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. + * Returns an array of values. Each entry has the entry number as its index + * and an integer that gives the numbers of the samples that are random access + * points in the stream as its value. * * @return Array */ diff --git a/src/ISO14496/Box/TKHD.php b/src/ISO14496/Box/TKHD.php index 602c1f1..c6a8750 100644 --- a/src/ISO14496/Box/TKHD.php +++ b/src/ISO14496/Box/TKHD.php @@ -146,7 +146,7 @@ final class ISO14496_Box_TKHD extends ISO14496_Box_Full /** * 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, + * 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. diff --git a/src/ISO14496/Box/XML.php b/src/ISO14496/Box/XML.php index 8df21d4..42d8617 100644 --- a/src/ISO14496/Box/XML.php +++ b/src/ISO14496/Box/XML.php @@ -66,7 +66,6 @@ final class ISO14496_Box_XML extends ISO14496_Box_Full * the ISO Base Media file. * * @param Reader $reader The reader object. - * @todo The sample flags could be parsed further */ public function __construct($reader) { diff --git a/src/Transform.php b/src/Transform.php index 66ff939..143a4e6 100644 --- a/src/Transform.php +++ b/src/Transform.php @@ -133,6 +133,62 @@ final class Transform return $int; } + /** + * Returns signed 32-bit integer as little-endian ordered binary data. + * + * @param integer $value The input value. + * @return string + */ + public static function toInt32LE($value) + { + if (self::fromInt32("\x00\x00\x00\x01") == 1) + return strrev(self::toInt32($value)); + else + return self::toInt32($value); + } + + /** + * Returns little-endian ordered binary data as signed 32-bit integer. + * + * @param string $value The binary data string. + * @return integer + */ + public static function fromInt32LE($value) + { + if (self::fromInt32("\x00\x00\x00\x01") == 1) + return self::fromInt32(strrev($value)); + else + return self::fromInt32($value); + } + + /** + * Returns signed 32-bit integer as big-endian ordered binary data. + * + * @param integer $value The input value. + * @return string + */ + public static function toInt32BE($value) + { + if (self::fromInt32("\x00\x00\x00\x01") == 1) + return self::toInt32($value); + else + return strrev(self::toInt32($value)); + } + + /** + * Returns big-endian ordered binary data as signed 32-bit integer. + * + * @param string $value The binary data string. + * @return integer + */ + public static function fromInt32BE($value) + { + if (self::fromInt32("\x00\x00\x00\x01") == 1) + return self::fromInt32($value); + else + return self::fromInt32(strrev($value)); + } + /** * Returns unsigned 32-bit integer as little-endian ordered binary data. * @@ -202,6 +258,62 @@ final class Transform return $int; } + /** + * Returns signed 16-bit integer as little-endian ordered binary data. + * + * @param integer $value The input value. + * @return string + */ + public static function toInt16LE($value) + { + if (self::fromInt16("\x00\x01") == 1) + return strrev(self::toInt16($value)); + else + return self::toInt16($value); + } + + /** + * Returns little-endian ordered binary data as signed 16-bit integer. + * + * @param string $value The binary data string. + * @return integer + */ + public static function fromInt16LE($value) + { + if (self::fromInt16("\x00\x01") == 1) + return self::fromInt16(strrev($value)); + else + return self::fromInt16($value); + } + + /** + * Returns signed 16-bit integer as big-endian ordered binary data. + * + * @param integer $value The input value. + * @return string + */ + public static function toInt16BE($value) + { + if (self::fromInt16("\x00\x01") == 1) + return self::toInt16($value); + else + return strrev(self::toInt16($value)); + } + + /** + * Returns big-endian ordered binary data as signed 16-bit integer. + * + * @param string $value The binary data string. + * @return integer + */ + public static function fromInt16BE($value) + { + if (self::fromInt16("\x00\x01") == 1) + return self::fromInt16($value); + else + return self::fromInt16(strrev($value)); + } + /** * Returns machine endian ordered binary data as unsigned 16-bit integer. * diff --git a/tests/TestTransform.php b/tests/TestTransform.php index 94740d3..aad9b70 100644 --- a/tests/TestTransform.php +++ b/tests/TestTransform.php @@ -70,6 +70,23 @@ final class TestTransform extends PHPUnit_Framework_TestCase { $this->assertEquals (0x7fffffff, Transform::fromInt32(Transform::toInt32(0x7fffffff))); + $this->assertEquals(-1, Transform::fromInt32(Transform::toInt32(-1))); + } + + function testInt32LE() + { + $this->assertEquals(1, Transform::fromInt32LE("\x01\x00\x00\x00")); + $this->assertEquals + (0x7fffffff, Transform::fromInt32LE(Transform::toInt32LE(0x7fffffff))); + $this->assertEquals(-1, Transform::fromInt32LE(Transform::toInt32LE(-1))); + } + + function testInt32BE() + { + $this->assertEquals(1, Transform::fromInt32BE("\x00\x00\x00\x01")); + $this->assertEquals + (0x7fffffff, Transform::fromInt32BE(Transform::toInt32BE(0x7fffffff))); + $this->assertEquals(-1, Transform::fromInt32BE(Transform::toInt32BE(-1))); } function testUInt32LE() @@ -92,6 +109,23 @@ final class TestTransform extends PHPUnit_Framework_TestCase { $this->assertEquals (0x7fff, Transform::fromInt16(Transform::toInt16(0x7fff))); + $this->assertEquals(-1, Transform::fromInt16(Transform::toInt16(-1))); + } + + function testInt16LE() + { + $this->assertEquals(1, Transform::fromInt16LE("\x01\x00")); + $this->assertEquals + (0x7fff, Transform::fromInt16LE(Transform::toInt16LE(0x7fff))); + $this->assertEquals(-1, Transform::fromInt16LE(Transform::toInt16LE(-1))); + } + + function testInt16BE() + { + $this->assertEquals(1, Transform::fromInt16BE("\x00\x01")); + $this->assertEquals + (0x7fff, Transform::fromInt16BE(Transform::toInt16BE(0x7fff))); + $this->assertEquals(-1, Transform::fromInt16BE(Transform::toInt16BE(-1))); } function testUInt16LE()