PageRenderTime 30ms CodeModel.GetById 17ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://php-reader.googlecode.com/
PHP | 133 lines | 33 code | 8 blank | 92 comment | 2 complexity | 2d1f7ff288586af31f70972f8fd60243 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: Co64.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>Chunk Offset Box</i> table gives the index of each chunk into the
 41 * containing file. There are two variants, permitting the use of 32-bit or
 42 * 64-bit offsets. The latter is useful when managing very large presentations.
 43 * At most one of these variants will occur in any single instance of a sample
 44 * table.
 45 *
 46 * Offsets are file offsets, not the offset into any box within the file (e.g.
 47 * {@link Zend_Media_Iso14496_Box_Mdat Media Data Box}). This permits referring
 48 * to media data in files without any box structure. It does also mean that care
 49 * must be taken when constructing a self-contained ISO file with its metadata
 50 * ({@link Zend_Media_Iso14496_Box_Moov Movie Box}) at the front, as the size of
 51 * the {@link Zend_Media_Iso14496_Box_Moov Movie Box} will affect the chunk
 52 * offsets to the media data.
 53 *
 54 * This box variant contains 64-bit offsets.
 55 *
 56 * @category   Zend
 57 * @package    Zend_Media
 58 * @subpackage ISO14496
 59 * @author     Sven Vollbehr <sven@vollbehr.eu>
 60 * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) 
 61 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 62 * @version    $Id: Co64.php 177 2010-03-09 13:13:34Z svollbehr $
 63 */
 64final class Zend_Media_Iso14496_Box_Co64 extends Zend_Media_Iso14496_FullBox
 65{
 66    /** @var Array */
 67    private $_chunkOffsetTable = array();
 68
 69    /**
 70     * Constructs the class with given parameters and reads box related data
 71     * from the ISO Base Media file.
 72     *
 73     * @param Zend_Io_Reader $reader  The reader object.
 74     * @param Array          $options The options array.
 75     */
 76    public function __construct($reader, &$options = array())
 77    {
 78        parent::__construct($reader, $options);
 79
 80        $entryCount = $this->_reader->readUInt32BE();
 81        for ($i = 1; $i <= $entryCount; $i++) {
 82            $this->_chunkOffsetTable[$i] = $this->_reader->readInt64BE();
 83        }
 84    }
 85
 86    /**
 87     * Returns an array of values. Each entry has the entry number as its index
 88     * and a 64 bit integer that gives the offset of the start of a chunk into
 89     * its containing media file as its value.
 90     *
 91     * @return Array
 92     */
 93    public function getChunkOffsetTable() 
 94    {
 95        return $this->_chunkOffsetTable; 
 96    }
 97
 98    /**
 99     * Sets an array of chunk offsets. Each entry must have the entry number as
100     * its index and a 64 bit integer that gives the offset of the start of a
101     * chunk into its containing media file as its value.
102     *
103     * @param Array $chunkOffsetTable The chunk offset array.
104     */
105    public function setChunkOffsetTable($chunkOffsetTable)
106    {
107        $this->_chunkOffsetTable = $chunkOffsetTable;
108    }
109
110    /**
111     * Returns the box heap size in bytes.
112     *
113     * @return integer
114     */
115    public function getHeapSize()
116    {
117        return parent::getHeapSize() + 4 + count($this->_chunkOffsetTable) * 8;
118    }
119
120    /**
121     * Writes the box data.
122     *
123     * @param Zend_Io_Writer $writer The writer object.
124     * @return void
125     */
126    protected function _writeData($writer)
127    {
128        $writer->writeUInt32BE($entryCount = count($this->_chunkOffsetTable));
129        for ($i = 1; $i <= $entryCount; $i++) {
130            $writer->writeInt64BE($this->_chunkOffsetTable[$i]);
131        }
132    }
133}