/src/Zend/Media/Iso14496/FullBox.php

http://php-reader.googlecode.com/ · PHP · 150 lines · 46 code · 13 blank · 91 comment · 2 complexity · cb8bbceff4541970e27523a76b8c9a9e 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: FullBox.php 177 2010-03-09 13:13:34Z svollbehr $
  33. */
  34. /**#@+ @ignore */
  35. require_once 'Zend/Media/Iso14496/Box.php';
  36. /**#@-*/
  37. /**
  38. * A base class for objects that also contain a version number and flags field.
  39. *
  40. * @category Zend
  41. * @package Zend_Media
  42. * @subpackage ISO14496
  43. * @author Sven Vollbehr <sven@vollbehr.eu>
  44. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  45. * @license http://framework.zend.com/license/new-bsd New BSD License
  46. * @version $Id: FullBox.php 177 2010-03-09 13:13:34Z svollbehr $
  47. */
  48. abstract class Zend_Media_Iso14496_FullBox extends Zend_Media_Iso14496_Box
  49. {
  50. /** @var integer */
  51. protected $_version = 0;
  52. /** @var integer */
  53. protected $_flags = 0;
  54. /**
  55. * Constructs the class with given parameters and reads box related data
  56. * from the ISO Base Media file.
  57. *
  58. * @param Zend_Io_Reader $reader The reader object.
  59. */
  60. public function __construct($reader = null, &$options = array())
  61. {
  62. parent::__construct($reader, $options);
  63. if ($reader === null) {
  64. return;
  65. }
  66. $this->_version =
  67. (($field = $this->_reader->readUInt32BE()) >> 24) & 0xff;
  68. $this->_flags = $field & 0xffffff;
  69. }
  70. /**
  71. * Returns the version of this format of the box.
  72. *
  73. * @return integer
  74. */
  75. public function getVersion()
  76. {
  77. return $this->_version;
  78. }
  79. /**
  80. * Sets the version of this format of the box.
  81. *
  82. * @param integer $version The version.
  83. */
  84. public function setVersion($version)
  85. {
  86. $this->_version = $version;
  87. }
  88. /**
  89. * Checks whether or not the flag is set. Returns <var>true</var> if the
  90. * flag is set, <var>false</var> otherwise.
  91. *
  92. * @param integer $flag The flag to query.
  93. * @return boolean
  94. */
  95. public function hasFlag($flag)
  96. {
  97. return ($this->_flags & $flag) == $flag;
  98. }
  99. /**
  100. * Returns the map of flags.
  101. *
  102. * @return integer
  103. */
  104. public function getFlags()
  105. {
  106. return $this->_flags;
  107. }
  108. /**
  109. * Sets the map of flags.
  110. *
  111. * @param string $flags The map of flags.
  112. */
  113. public function setFlags($flags)
  114. {
  115. $this->_flags = $flags;
  116. }
  117. /**
  118. * Returns the box heap size in bytes.
  119. *
  120. * @return integer
  121. */
  122. public function getHeapSize()
  123. {
  124. return parent::getHeapSize() + 4;
  125. }
  126. /**
  127. * Writes the box data without the header.
  128. *
  129. * @param Zend_Io_Writer $writer The writer object.
  130. * @return void
  131. */
  132. protected function _writeData($writer)
  133. {
  134. parent::_writeData($writer);
  135. $writer->writeUInt32BE($this->_version << 24 | $this->_flags);
  136. }
  137. }