PageRenderTime 10ms CodeModel.GetById 2ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 35/**#@+ @ignore */
 36require_once 'Zend/Media/Iso14496/Box.php';
 37/**#@-*/
 38
 39/**
 40 * A base class for objects that also contain a version number and flags field.
 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: FullBox.php 177 2010-03-09 13:13:34Z svollbehr $
 49 */
 50abstract class Zend_Media_Iso14496_FullBox extends Zend_Media_Iso14496_Box
 51{
 52    /** @var integer */
 53    protected $_version = 0;
 54
 55    /** @var integer */
 56    protected $_flags = 0;
 57
 58    /**
 59     * Constructs the class with given parameters and reads box related data
 60     * from the ISO Base Media file.
 61     *
 62     * @param Zend_Io_Reader $reader The reader object.
 63     */
 64    public function __construct($reader = null, &$options = array())
 65    {
 66        parent::__construct($reader, $options);
 67
 68        if ($reader === null) {
 69            return;
 70        }
 71
 72        $this->_version =
 73            (($field = $this->_reader->readUInt32BE()) >> 24) & 0xff;
 74        $this->_flags = $field & 0xffffff;
 75    }
 76
 77    /**
 78     * Returns the version of this format of the box.
 79     *
 80     * @return integer
 81     */
 82    public function getVersion() 
 83    {
 84        return $this->_version; 
 85    }
 86
 87    /**
 88     * Sets the version of this format of the box.
 89     *
 90     * @param integer $version The version.
 91     */
 92    public function setVersion($version) 
 93    {
 94        $this->_version = $version; 
 95    }
 96
 97    /**
 98     * Checks whether or not the flag is set. Returns <var>true</var> if the
 99     * flag is set, <var>false</var> otherwise.
100     *
101     * @param integer $flag The flag to query.
102     * @return boolean
103     */
104    public function hasFlag($flag) 
105    {
106        return ($this->_flags & $flag) == $flag; 
107    }
108
109    /**
110     * Returns the map of flags.
111     *
112     * @return integer
113     */
114    public function getFlags() 
115    {
116        return $this->_flags; 
117    }
118
119    /**
120     * Sets the map of flags.
121     *
122     * @param string $flags The map of flags.
123     */
124    public function setFlags($flags) 
125    {
126        $this->_flags = $flags; 
127    }
128
129    /**
130     * Returns the box heap size in bytes.
131     *
132     * @return integer
133     */
134    public function getHeapSize()
135    {
136        return parent::getHeapSize() + 4;
137    }
138
139    /**
140     * Writes the box data without the header.
141     *
142     * @param Zend_Io_Writer $writer The writer object.
143     * @return void
144     */
145    protected function _writeData($writer)
146    {
147        parent::_writeData($writer);
148        $writer->writeUInt32BE($this->_version << 24 | $this->_flags);
149    }
150}