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

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

http://php-reader.googlecode.com/
PHP | 132 lines | 41 code | 10 blank | 81 comment | 3 complexity | 46a55afaae947d5929f744c988c6a07e 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: StreamPrioritization.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 Prioritization Object</i> indicates the author's intentions as
 29 * to which streams should or should not be dropped in response to varying
 30 * network congestion situations. There may be special cases where this
 31 * preferential order may be ignored (for example, the user hits the 'mute'
 32 * button). Generally it is expected that implementations will try to honor the
 33 * author's preference.
 34 *
 35 * The priority of each stream is indicated by how early in the list that
 36 * stream's stream number is listed (in other words, the list is ordered in
 37 * terms of decreasing priority).
 38 *
 39 * The Mandatory flag field shall be set if the author wants that stream kept
 40 * 'regardless'. If this flag is not set, then that indicates that the stream
 41 * should be dropped in response to network congestion situations. Non-mandatory
 42 * streams must never be assigned a higher priority than mandatory streams.
 43 *
 44 * @category   Zend
 45 * @package    Zend_Media
 46 * @subpackage ASF
 47 * @author     Sven Vollbehr <sven@vollbehr.eu>
 48 * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) 
 49 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 50 * @version    $Id: StreamPrioritization.php 177 2010-03-09 13:13:34Z svollbehr $
 51 */
 52final class Zend_Media_Asf_Object_StreamPrioritization
 53    extends Zend_Media_Asf_Object
 54{
 55    /** @var Array */
 56    private $_priorityRecords = array();
 57
 58    /**
 59     * Constructs the class with given parameters and reads object related data
 60     * from the ASF file.
 61     *
 62     * @param Zend_Io_Reader $reader  The reader object.
 63     * @param Array          $options The options array.
 64     */
 65    public function __construct($reader = null, &$options = array())
 66    {
 67        parent::__construct($reader, $options);
 68
 69        if ($reader === null) {
 70            return;
 71        }
 72
 73        $priorityRecordCount = $this->_reader->readUInt16LE();
 74        for ($i = 0; $i < $priorityRecordCount; $i++) {
 75            $this->_priorityRecords[] = array
 76                ('streamNumber' => $this->_reader->readUInt16LE(),
 77                 'flags'        => $this->_reader->readUInt16LE());
 78        }
 79    }
 80
 81    /**
 82     * Returns an array of records. Each record consists of the following keys.
 83     *
 84     *   o streamNumber -- Specifies the stream number. Valid values are between
 85     *     1 and 127.
 86     *
 87     *   o flags -- Specifies the flags. The mandatory flag is the bit 1 (LSB).
 88     *
 89     * @return Array
 90     */
 91    public function getPriorityRecords() 
 92    {
 93        return $this->_priorityRecords; 
 94    }
 95
 96    /**
 97     * Sets the array of records. Each record consists of the following keys.
 98     *
 99     *   o streamNumber -- Specifies the stream number. Valid values are between
100     *     1 and 127.
101     *
102     *   o flags -- Specifies the flags. The mandatory flag is the bit 1 (LSB).
103     *
104     * @param Array $priorityRecords The array of records.
105     */
106    public function setPriorityRecords($priorityRecords)
107    {
108        $this->_priorityRecords = $priorityRecords;
109    }
110
111    /**
112     * Writes the object data.
113     *
114     * @param Zend_Io_Writer $writer The writer object.
115     * @return void
116     */
117    public function write($writer)
118    {
119        $priorityRecordCount = count($this->_priorityRecords);
120
121        $this->setSize
122            (24 /* for header */ + 2 + $priorityRecordCount * 4);
123
124        $writer->writeGuid($this->getIdentifier())
125               ->writeInt64LE($this->getSize())
126               ->writeUInt16LE($priorityRecordCount);
127        for ($i = 0; $i < $priorityRecordCount; $i++) {
128            $writer->writeUInt16LE($this->_priorityRecords[$i]['streamNumber'])
129                   ->writeUInt16LE($this->_priorityRecords[$i]['flags']);
130        }
131    }
132}