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

http://php-reader.googlecode.com/ · PHP · 177 lines · 63 code · 14 blank · 100 comment · 4 complexity · 8f5544a8e951479fc0ff055512157305 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: Schm.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>Scheme Type Box</i> identifies the protection scheme.
  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: Schm.php 177 2010-03-09 13:13:34Z svollbehr $
  47. */
  48. final class Zend_Media_Iso14496_Box_Schm extends Zend_Media_Iso14496_FullBox
  49. {
  50. /** @var string */
  51. private $_schemeType;
  52. /** @var integer */
  53. private $_schemeVersion;
  54. /** @var string */
  55. private $_schemeUri;
  56. /**
  57. * Constructs the class with given parameters and reads box related data
  58. * from the ISO Base Media file.
  59. *
  60. * @param Zend_Io_Reader $reader The reader object.
  61. * @param Array $options The options array.
  62. */
  63. public function __construct($reader, &$options = array())
  64. {
  65. parent::__construct($reader, $options);
  66. $this->_schemeType = $this->_reader->read(4);
  67. $this->_schemeVersion = $this->_reader->readUInt32BE();
  68. if ($this->hasFlag(1)) {
  69. $this->_schemeUri = preg_split
  70. ("/\\x00/", $this->_reader->read
  71. ($this->getOffset() + $this->getSize() -
  72. $this->_reader->getOffset()));
  73. }
  74. }
  75. /**
  76. * Returns the code defining the protection scheme.
  77. *
  78. * @return string
  79. */
  80. public function getSchemeType()
  81. {
  82. return $this->_schemeType;
  83. }
  84. /**
  85. * Sets the code defining the protection scheme.
  86. *
  87. * @param string $schemeType The scheme type.
  88. */
  89. public function setSchemeType($schemeType)
  90. {
  91. $this->_schemeType = $schemeType;
  92. }
  93. /**
  94. * Returns the version of the scheme used to create the content.
  95. *
  96. * @return integer
  97. */
  98. public function getSchemeVersion()
  99. {
  100. return $this->_schemeVersion;
  101. }
  102. /**
  103. * Sets the version of the scheme used to create the content.
  104. *
  105. * @param integer $schemeVersion The scheme version.
  106. */
  107. public function setSchemeVersion($schemeVersion)
  108. {
  109. $this->_schemeVersion = $schemeVersion;
  110. }
  111. /**
  112. * Returns the optional scheme address to allow for the option of directing
  113. * the user to a web-page if they do not have the scheme installed on their
  114. * system. It is an absolute URI.
  115. *
  116. * @return string
  117. */
  118. public function getSchemeUri()
  119. {
  120. return $this->_schemeUri;
  121. }
  122. /**
  123. * Sets the optional scheme address to allow for the option of directing
  124. * the user to a web-page if they do not have the scheme installed on their
  125. * system. It is an absolute URI.
  126. *
  127. * @param string $schemeUri The scheme URI.
  128. */
  129. public function setSchemeUri($schemeUri)
  130. {
  131. $this->_schemeUri = $schemeUri;
  132. if ($schemeUri === null) {
  133. $this->setFlags(0);
  134. } else {
  135. $this->setFlags(1);
  136. }
  137. }
  138. /**
  139. * Returns the box heap size in bytes.
  140. *
  141. * @return integer
  142. */
  143. public function getHeapSize()
  144. {
  145. return parent::getHeapSize() + 8 +
  146. ($this->hasFlag(1) ? strlen($this->_schemeUri) + 1 : 0);
  147. }
  148. /**
  149. * Writes the box data.
  150. *
  151. * @param Zend_Io_Writer $writer The writer object.
  152. * @return void
  153. */
  154. protected function _writeData($writer)
  155. {
  156. parent::_writeData($writer);
  157. $writer->write($this->_schemeType);
  158. $writer->writeUInt32BE($this->_schemeVersion);
  159. if ($this->hasFlag(1)) {
  160. $writer->writeString8($this->_schemeUri, 1);
  161. }
  162. }
  163. }