/src/Zend/Media/Iso14496/Box/Co64.php

http://php-reader.googlecode.com/ · PHP · 133 lines · 33 code · 8 blank · 92 comment · 2 complexity · 2d1f7ff288586af31f70972f8fd60243 MD5 · raw file

  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS'
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  19. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  20. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  21. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  22. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  23. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  24. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  25. * POSSIBILITY OF SUCH DAMAGE.
  26. *
  27. * @category Zend
  28. * @package Zend_Media
  29. * @subpackage ISO14496
  30. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. * @version $Id: Co64.php 177 2010-03-09 13:13:34Z svollbehr $
  33. */
  34. /**#@+ @ignore */
  35. require_once 'Zend/Media/Iso14496/FullBox.php';
  36. /**#@-*/
  37. /**
  38. * The <i>Chunk Offset Box</i> table gives the index of each chunk into the
  39. * containing file. There are two variants, permitting the use of 32-bit or
  40. * 64-bit offsets. The latter is useful when managing very large presentations.
  41. * At most one of these variants will occur in any single instance of a sample
  42. * table.
  43. *
  44. * Offsets are file offsets, not the offset into any box within the file (e.g.
  45. * {@link Zend_Media_Iso14496_Box_Mdat Media Data Box}). This permits referring
  46. * to media data in files without any box structure. It does also mean that care
  47. * must be taken when constructing a self-contained ISO file with its metadata
  48. * ({@link Zend_Media_Iso14496_Box_Moov Movie Box}) at the front, as the size of
  49. * the {@link Zend_Media_Iso14496_Box_Moov Movie Box} will affect the chunk
  50. * offsets to the media data.
  51. *
  52. * This box variant contains 64-bit offsets.
  53. *
  54. * @category Zend
  55. * @package Zend_Media
  56. * @subpackage ISO14496
  57. * @author Sven Vollbehr <sven@vollbehr.eu>
  58. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  59. * @license http://framework.zend.com/license/new-bsd New BSD License
  60. * @version $Id: Co64.php 177 2010-03-09 13:13:34Z svollbehr $
  61. */
  62. final class Zend_Media_Iso14496_Box_Co64 extends Zend_Media_Iso14496_FullBox
  63. {
  64. /** @var Array */
  65. private $_chunkOffsetTable = array();
  66. /**
  67. * Constructs the class with given parameters and reads box related data
  68. * from the ISO Base Media file.
  69. *
  70. * @param Zend_Io_Reader $reader The reader object.
  71. * @param Array $options The options array.
  72. */
  73. public function __construct($reader, &$options = array())
  74. {
  75. parent::__construct($reader, $options);
  76. $entryCount = $this->_reader->readUInt32BE();
  77. for ($i = 1; $i <= $entryCount; $i++) {
  78. $this->_chunkOffsetTable[$i] = $this->_reader->readInt64BE();
  79. }
  80. }
  81. /**
  82. * Returns an array of values. Each entry has the entry number as its index
  83. * and a 64 bit integer that gives the offset of the start of a chunk into
  84. * its containing media file as its value.
  85. *
  86. * @return Array
  87. */
  88. public function getChunkOffsetTable()
  89. {
  90. return $this->_chunkOffsetTable;
  91. }
  92. /**
  93. * Sets an array of chunk offsets. Each entry must have the entry number as
  94. * its index and a 64 bit integer that gives the offset of the start of a
  95. * chunk into its containing media file as its value.
  96. *
  97. * @param Array $chunkOffsetTable The chunk offset array.
  98. */
  99. public function setChunkOffsetTable($chunkOffsetTable)
  100. {
  101. $this->_chunkOffsetTable = $chunkOffsetTable;
  102. }
  103. /**
  104. * Returns the box heap size in bytes.
  105. *
  106. * @return integer
  107. */
  108. public function getHeapSize()
  109. {
  110. return parent::getHeapSize() + 4 + count($this->_chunkOffsetTable) * 8;
  111. }
  112. /**
  113. * Writes the box data.
  114. *
  115. * @param Zend_Io_Writer $writer The writer object.
  116. * @return void
  117. */
  118. protected function _writeData($writer)
  119. {
  120. $writer->writeUInt32BE($entryCount = count($this->_chunkOffsetTable));
  121. for ($i = 1; $i <= $entryCount; $i++) {
  122. $writer->writeInt64BE($this->_chunkOffsetTable[$i]);
  123. }
  124. }
  125. }