PageRenderTime 13ms CodeModel.GetById 8ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://php-reader.googlecode.com/
PHP | 169 lines | 56 code | 8 blank | 105 comment | 9 complexity | 68136538a265e072420dbc00d2e9406a 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: Elst.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>Edit List Box</i> contains an explicit timeline map. Each entry
 41 * defines part of the track time-line: by mapping part of the media time-line,
 42 * or by indicating empty time, or by defining a dwell, where a single
 43 * time-point in the media is held for a period.
 44 *
 45 * @category   Zend
 46 * @package    Zend_Media
 47 * @subpackage ISO14496
 48 * @author     Sven Vollbehr <sven@vollbehr.eu>
 49 * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) 
 50 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 51 * @version    $Id: Elst.php 177 2010-03-09 13:13:34Z svollbehr $
 52 */
 53final class Zend_Media_Iso14496_Box_Elst extends Zend_Media_Iso14496_FullBox
 54{
 55    /** @var Array */
 56    private $_entries = array();
 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     * @param Array          $options The options array.
 64     */
 65    public function __construct($reader, &$options = array())
 66    {
 67        parent::__construct($reader, $options);
 68
 69        $entryCount = $this->_reader->readUInt32BE();
 70        for ($i = 0; $i < $entryCount; $i++) {
 71            $entry = array();
 72            if ($this->getVersion() == 1) {
 73                $entry['segmentDuration'] = $this->_reader->readInt64BE();
 74                $entry['mediaTime'] = $this->_reader->readInt64BE();
 75            } else {
 76                $entry['segmentDuration'] = $this->_reader->readUInt32BE();
 77                $entry['mediaTime'] = $this->_reader->readInt32BE();
 78            }
 79            $entry['mediaRate'] =
 80                (float)($this->_reader->readInt16BE() . "." .
 81                    $this->_reader->readInt16BE());
 82            $this->_entries[] = $entry;
 83        }
 84    }
 85
 86    /**
 87     * Returns an array of entries. Each entry is an array containing the
 88     * following keys.
 89     *   o segmentDuration: specifies the duration of this edit segment in units
 90     *     of the timescale in the
 91     *     {@link Zend_Media_Iso14496_Box_Mvhd Movie Header Box}.
 92     *   o mediaTime: the starting time within the media of this edit segment
 93     *     (in media time scale units, in composition time). If this field is
 94     *     set to –1, it is an empty edit. The last edit in a track shall never
 95     *     be an empty edit. Any difference between the duration in the
 96     *     {@link Zend_Media_Iso14496_Box_MVHD Movie Header Box}, and the
 97     *     track's duration is expressed as an implicit empty edit at the end.
 98     *   o mediaRate: the relative rate at which to play the media corresponding
 99     *     to this edit segment. If this value is 0, then the edit is specifying
100     *     a dwell: the media at media-time is presented for the
101     *     segment-duration. Otherwise this field shall contain the value 1.
102     *
103     * @return Array
104     */
105    public function getEntries()
106    {
107        return $this->_entries;
108    }
109
110    /**
111     * Sets the array of entries. Each entry must be an array containing the
112     * following keys.
113     *   o segmentDuration: specifies the duration of this edit segment in units
114     *     of the timescale in the
115     *     {@link Zend_Media_Iso14496_Box_Mvhd Movie Header Box}.
116     *   o mediaTime: the starting time within the media of this edit segment
117     *     (in media time scale units, in composition time). If this field is
118     *     set to –1, it is an empty edit. The last edit in a track shall never
119     *     be an empty edit. Any difference between the duration in the
120     *     {@link Zend_Media_Iso14496_Box_MVHD Movie Header Box}, and the
121     *     track's duration is expressed as an implicit empty edit at the end.
122     *   o mediaRate: the relative rate at which to play the media corresponding
123     *     to this edit segment. If this value is 0, then the edit is specifying
124     *     a dwell: the media at media-time is presented for the
125     *     segment-duration. Otherwise this field shall contain the value 1.
126     *
127     * @param Array $entries The array of entries;
128     */
129    public function setEntries($entries)
130    {
131        $this->_entries = $entries;
132    }
133
134    /**
135     * Returns the box heap size in bytes.
136     *
137     * @return integer
138     */
139    public function getHeapSize()
140    {
141        return parent::getHeapSize() + 4 + count($this->_entries) *
142            ($this->getVersion() == 1 ? 20 : 12);
143    }
144
145    /**
146     * Writes the box data.
147     *
148     * @param Zend_Io_Writer $writer The writer object.
149     * @return void
150     */
151    protected function _writeData($writer)
152    {
153        parent::_writeData($writer);
154        $writer->writeUInt32BE($entryCount = count($this->_entries));
155        for ($i = 0; $i < $entryCount; $i++) {
156            if ($this->getVersion() == 1) {
157                $writer->writeInt64BE($this->_entries[$i]['segmentDuration'])
158                       ->writeInt64BE($this->_entries[$i]['mediaTime']);
159            } else {
160                $writer->writeUInt32BE($this->_entries[$i]['segmentDuration'])
161                       ->writeInt32BE($this->_entries[$i]['mediaTime']);
162            }
163            @list($mediaRateInteger, $mediaRateFraction) = explode
164                ('.', (float)$this->_entries[$i]['mediaRate']);
165            $writer->writeInt16BE($mediaRateInteger)
166                   ->writeInt16BE($mediaRateFraction);
167        }
168    }
169}