PageRenderTime 17ms CodeModel.GetById 11ms app.highlight 4ms RepoModel.GetById 0ms app.codeStats 1ms

/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
 35/**#@+ @ignore */
 36require_once 'Zend/Media/Iso14496/FullBox.php';
 37/**#@-*/
 38
 39/**
 40 * The <i>Scheme Type Box</i> identifies the protection scheme.
 41 *
 42 * @category   Zend
 43 * @package    Zend_Media
 44 * @subpackage ISO14496
 45 * @author     Sven Vollbehr <sven@vollbehr.eu>
 46 * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) 
 47 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 48 * @version    $Id: Schm.php 177 2010-03-09 13:13:34Z svollbehr $
 49 */
 50final class Zend_Media_Iso14496_Box_Schm extends Zend_Media_Iso14496_FullBox
 51{
 52    /** @var string */
 53    private $_schemeType;
 54
 55    /** @var integer */
 56    private $_schemeVersion;
 57
 58    /** @var string */
 59    private $_schemeUri;
 60
 61    /**
 62     * Constructs the class with given parameters and reads box related data
 63     * from the ISO Base Media file.
 64     *
 65     * @param Zend_Io_Reader $reader  The reader object.
 66     * @param Array          $options The options array.
 67     */
 68    public function __construct($reader, &$options = array())
 69    {
 70        parent::__construct($reader, $options);
 71
 72        $this->_schemeType = $this->_reader->read(4);
 73        $this->_schemeVersion = $this->_reader->readUInt32BE();
 74        if ($this->hasFlag(1)) {
 75            $this->_schemeUri = preg_split
 76                ("/\\x00/", $this->_reader->read
 77                 ($this->getOffset() + $this->getSize() -
 78                  $this->_reader->getOffset()));
 79        }
 80    }
 81
 82    /**
 83     * Returns the code defining the protection scheme.
 84     *
 85     * @return string
 86     */
 87    public function getSchemeType()
 88    {
 89        return $this->_schemeType;
 90    }
 91
 92    /**
 93     * Sets the code defining the protection scheme.
 94     *
 95     * @param string $schemeType The scheme type.
 96     */
 97    public function setSchemeType($schemeType)
 98    {
 99        $this->_schemeType = $schemeType;
100    }
101
102    /**
103     * Returns the version of the scheme used to create the content.
104     *
105     * @return integer
106     */
107    public function getSchemeVersion()
108    {
109        return $this->_schemeVersion;
110    }
111
112    /**
113     * Sets the version of the scheme used to create the content.
114     *
115     * @param integer $schemeVersion The scheme version.
116     */
117    public function setSchemeVersion($schemeVersion)
118    {
119        $this->_schemeVersion = $schemeVersion;
120    }
121
122    /**
123     * Returns 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     * @return string
128     */
129    public function getSchemeUri()
130    {
131        return $this->_schemeUri;
132    }
133
134    /**
135     * Sets the optional scheme address to allow for the option of directing
136     * the user to a web-page if they do not have the scheme installed on their
137     * system. It is an absolute URI.
138     *
139     * @param string $schemeUri The scheme URI.
140     */
141    public function setSchemeUri($schemeUri)
142    {
143        $this->_schemeUri = $schemeUri;
144        if ($schemeUri === null) {
145            $this->setFlags(0);
146        } else {
147            $this->setFlags(1);
148        }
149    }
150
151    /**
152     * Returns the box heap size in bytes.
153     *
154     * @return integer
155     */
156    public function getHeapSize()
157    {
158        return parent::getHeapSize() + 8 +
159            ($this->hasFlag(1) ? strlen($this->_schemeUri) + 1 : 0);
160    }
161
162    /**
163     * Writes the box data.
164     *
165     * @param Zend_Io_Writer $writer The writer object.
166     * @return void
167     */
168    protected function _writeData($writer)
169    {
170        parent::_writeData($writer);
171        $writer->write($this->_schemeType);
172        $writer->writeUInt32BE($this->_schemeVersion);
173        if ($this->hasFlag(1)) {
174            $writer->writeString8($this->_schemeUri, 1);
175        }
176    }
177}