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

http://php-reader.googlecode.com/ · PHP · 123 lines · 34 code · 8 blank · 81 comment · 2 complexity · e949bb2a00376193d491e80876c5e0ce 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: Stss.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>Sync Sample Box</i> provides a compact marking of the random access
  39. * points within the stream. The table is arranged in strictly increasing order
  40. * of sample number. If the sync sample box is not present, every sample is a
  41. * random access point.
  42. *
  43. * @category Zend
  44. * @package Zend_Media
  45. * @subpackage ISO14496
  46. * @author Sven Vollbehr <sven@vollbehr.eu>
  47. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  48. * @license http://framework.zend.com/license/new-bsd New BSD License
  49. * @version $Id: Stss.php 177 2010-03-09 13:13:34Z svollbehr $
  50. */
  51. final class Zend_Media_Iso14496_Box_Stss extends Zend_Media_Iso14496_FullBox
  52. {
  53. /** @var Array */
  54. private $_syncSampleTable = array();
  55. /**
  56. * Constructs the class with given parameters and reads box related data
  57. * from the ISO Base Media file.
  58. *
  59. * @param Zend_Io_Reader $reader The reader object.
  60. * @param Array $options The options array.
  61. */
  62. public function __construct($reader, &$options = array())
  63. {
  64. parent::__construct($reader, $options);
  65. $entryCount = $this->_reader->readUInt32BE();
  66. for ($i = 1; $i <= $entryCount; $i++) {
  67. $this->_syncSampleTable[$i] = $this->_reader->readUInt32BE();
  68. }
  69. }
  70. /**
  71. * Returns an array of values. Each entry has the entry number as its index
  72. * and an integer that gives the numbers of the samples that are random
  73. * access points in the stream as its value.
  74. *
  75. * @return Array
  76. */
  77. public function getSyncSampleTable()
  78. {
  79. return $this->_syncSampleTable;
  80. }
  81. /**
  82. * Sets an array of values. Each entry has the entry number as its index
  83. * and an integer that gives the numbers of the samples that are random
  84. * access points in the stream as its value.
  85. *
  86. * @param Array $syncSampleTable The array of values.
  87. */
  88. public function setSyncSampleTable($syncSampleTable)
  89. {
  90. $this->_syncSampleTable = $syncSampleTable;
  91. }
  92. /**
  93. * Returns the box heap size in bytes.
  94. *
  95. * @return integer
  96. */
  97. public function getHeapSize()
  98. {
  99. return parent::getHeapSize() + 4 + count($this->_syncSampleTable) * 4;
  100. }
  101. /**
  102. * Writes the box data.
  103. *
  104. * @param Zend_Io_Writer $writer The writer object.
  105. * @return void
  106. */
  107. protected function _writeData($writer)
  108. {
  109. parent::_writeData($writer);
  110. $writer->writeUInt32BE($entryCount = count($this->_syncSampleTable));
  111. for ($i = 1; $i <= $entryCount; $i++) {
  112. $writer->writeUInt32BE($this->_syncSampleTable[$i]);
  113. }
  114. }
  115. }