PageRenderTime 19ms CodeModel.GetById 10ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 1ms

/src/Zend/Media/Asf/Object/StreamBitrateProperties.php

http://php-reader.googlecode.com/
PHP | 134 lines | 46 code | 10 blank | 78 comment | 3 complexity | 93e8aaa7be242c0e4d84f7a00944fbca 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 * @category   Zend
 16 * @package    Zend_Media
 17 * @subpackage ASF
 18 * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) 
 19 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 20 * @version    $Id: StreamBitrateProperties.php 177 2010-03-09 13:13:34Z svollbehr $
 21 */
 22
 23/**#@+ @ignore */
 24require_once 'Zend/Media/Asf/Object.php';
 25/**#@-*/
 26
 27/**
 28 * The <i>Stream Bitrate Properties Object</i> defines the average bit rate of
 29 * each digital media stream.
 30 *
 31 * @category   Zend
 32 * @package    Zend_Media
 33 * @subpackage ASF
 34 * @author     Sven Vollbehr <sven@vollbehr.eu>
 35 * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) 
 36 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 37 * @version    $Id: StreamBitrateProperties.php 177 2010-03-09 13:13:34Z svollbehr $
 38 */
 39final class Zend_Media_Asf_Object_StreamBitrateProperties
 40    extends Zend_Media_Asf_Object
 41{
 42    /** @var Array */
 43    private $_bitrateRecords = array();
 44
 45    /**
 46     * Constructs the class with given parameters and reads object related data
 47     * from the ASF file.
 48     *
 49     * @param Zend_Io_Reader $reader  The reader object.
 50     * @param Array          $options The options array.
 51     */
 52    public function __construct($reader = null, &$options = array())
 53    {
 54        parent::__construct($reader, $options);
 55
 56        if ($reader === null) {
 57            return;
 58        }
 59
 60        $bitrateRecordsCount = $this->_reader->readUInt16LE();
 61        for ($i = 0; $i < $bitrateRecordsCount; $i++) {
 62            $this->_bitrateRecords[] = array
 63                ('streamNumber' =>
 64                     ($tmp = $this->_reader->readInt16LE()) & 0x1f,
 65                 'flags' => $tmp >> 5,
 66                 'averageBitrate' => $this->_reader->readUInt32LE());
 67        }
 68    }
 69
 70    /**
 71     * Returns an array of bitrate records. Each record consists of the
 72     * following keys.
 73     *
 74     *   o streamNumber -- Specifies the number of this stream described by this
 75     *     record. 0 is an invalid stream. Valid values are between 1 and 127.
 76     *
 77     *   o flags -- These bits are reserved and should be set to 0.
 78     *
 79     *   o averageBitrate -- Specifies the average bit rate of the stream in
 80     *     bits per second. This value should include an estimate of ASF packet
 81     *     and payload overhead associated with this stream.
 82     *
 83     * @return Array
 84     */
 85    public function getBitrateRecords() 
 86    {
 87        return $this->_bitrateRecords; 
 88    }
 89
 90    /**
 91     * Sets an array of bitrate records. Each record consists of the following
 92     * keys.
 93     *
 94     *   o streamNumber -- Specifies the number of this stream described by this
 95     *     record. 0 is an invalid stream. Valid values are between 1 and 127.
 96     *
 97     *   o flags -- These bits are reserved and should be set to 0.
 98     *
 99     *   o averageBitrate -- Specifies the average bit rate of the stream in bits
100     *     per second. This value should include an estimate of ASF packet and
101     *     payload overhead associated with this stream.
102     *
103     * @param Array $bitrateRecords The array of bitrate records.
104     */
105    public function setBitrateRecords($bitrateRecords)
106    {
107        $this->_bitrateRecords = $bitrateRecords;
108    }
109
110    /**
111     * Writes the object data.
112     *
113     * @param Zend_Io_Writer $writer The writer object.
114     * @return void
115     */
116    public function write($writer)
117    {
118        $bitrateRecordsCount = count($this->_bitrateRecords);
119
120        $this->setSize
121            (24 /* for header */ + 2 + $bitrateRecordsCount * 6);
122
123        $writer->writeGuid($this->getIdentifier())
124               ->writeInt64LE($this->getSize())
125               ->writeUInt16LE($bitrateRecordsCount);
126        for ($i = 0; $i < $bitrateRecordsCount; $i++) {
127            $writer->writeUInt16LE
128                        (($this->_bitrateRecords[$i]['flags'] << 5) |
129                         ($this->_bitrateRecords[$i]['streamNumber'] & 0x1f))
130                   ->writeUInt32LE
131                        ($this->_bitrateRecords[$i]['averageBitrate']);
132        }
133    }
134}