PageRenderTime 34ms CodeModel.GetById 15ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 1ms

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

http://php-reader.googlecode.com/
PHP | 217 lines | 71 code | 20 blank | 126 comment | 3 complexity | 01da1f8be21b2a751249eaf38b630048 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: BandwidthSharing.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>Bandwidth Sharing Object</i> indicates streams that share bandwidth in
 29 * such a way that the maximum bandwidth of the set of streams is less than the
 30 * sum of the maximum bandwidths of the individual streams. There should be one
 31 * instance of this object for each set of objects that share bandwidth. Whether
 32 * or not this object can be used meaningfully is content-dependent.
 33 *
 34 * @category   Zend
 35 * @package    Zend_Media
 36 * @subpackage ASF
 37 * @author     Sven Vollbehr <sven@vollbehr.eu>
 38 * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) 
 39 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 40 * @version    $Id: BandwidthSharing.php 177 2010-03-09 13:13:34Z svollbehr $
 41 */
 42final class Zend_Media_Asf_Object_BandwidthSharing extends Zend_Media_Asf_Object
 43{
 44    const SHARING_EXCLUSIVE = 'af6060aa-5197-11d2-b6af-00c04fd908e9';
 45    const SHARING_PARTIAL = 'af6060ab-5197-11d2-b6af-00c04fd908e9';
 46
 47    /** @var string */
 48    private $_sharingType;
 49
 50    /** @var integer */
 51    private $_dataBitrate;
 52
 53    /** @var integer */
 54    private $_bufferSize;
 55
 56    /** @var Array */
 57    private $_streamNumbers = array();
 58
 59    /**
 60     * Constructs the class with given parameters and reads object related data
 61     * from the ASF file.
 62     *
 63     * @param Zend_Io_Reader $reader  The reader object.
 64     * @param Array          $options The options array.
 65     */
 66    public function __construct($reader, &$options = array())
 67    {
 68        parent::__construct($reader = null, $options);
 69
 70        if ($reader === null) {
 71            return;
 72        }
 73
 74        $this->_sharingType = $this->_reader->readGuid();
 75        $this->_dataBitrate = $this->_reader->readUInt32LE();
 76        $this->_bufferSize  = $this->_reader->readUInt32LE();
 77        $streamNumbersCount = $this->_reader->readUInt16LE();
 78        for ($i = 0; $i < $streamNumbersCount; $i++) {
 79            $this->_streamNumbers[] = $this->_reader->readUInt16LE();
 80        }
 81    }
 82
 83    /**
 84     * Returns the type of sharing relationship for this object. Two types are
 85     * predefined: SHARING_PARTIAL, in which any number of the streams in the
 86     * relationship may be streaming data at any given time; and
 87     * SHARING_EXCLUSIVE, in which only one of the streams in the relationship
 88     * may be streaming data at any given time.
 89     *
 90     * @return string
 91     */
 92    public function getSharingType() 
 93    {
 94        return $this->_sharingType; 
 95    }
 96
 97    /**
 98     * Sets the type of sharing relationship for this object. Two types are
 99     * predefined: SHARING_PARTIAL, in which any number of the streams in the
100     * relationship may be streaming data at any given time; and
101     * SHARING_EXCLUSIVE, in which only one of the streams in the relationship
102     * may be streaming data at any given time.
103     *
104     * @return string
105     */
106    public function setSharingType($sharingType)
107    {
108        $this->_sharingType = $sharingType;
109    }
110
111    /**
112     * Returns the leak rate R, in bits per second, of a leaky bucket that
113     * contains the data portion of all of the streams, excluding all ASF Data
114     * Packet overhead, without overflowing. The size of the leaky bucket is
115     * specified by the value of the Buffer Size field. This value can be less
116     * than the sum of all of the data bit rates in the
117     * {@link Zend_Media_Asf_Object_ExtendedStreamProperties Extended Stream
118     * Properties} Objects for the streams contained in this bandwidth-sharing
119     * relationship.
120     *
121     * @return integer
122     */
123    public function getDataBitrate() 
124    {
125        return $this->_dataBitrate; 
126    }
127
128    /**
129     * Sets the leak rate R, in bits per second, of a leaky bucket that contains
130     * the data portion of all of the streams, excluding all ASF Data Packet
131     * overhead, without overflowing. The size of the leaky bucket is specified
132     * by the value of the Buffer Size field. This value can be less than the
133     * sum of all of the data bit rates in the
134     * {@link Zend_Media_Asf_Object_ExtendedStreamProperties Extended Stream
135     * Properties} Objects for the streams contained in this bandwidth-sharing
136     * relationship.
137     *
138     * @param integer $dataBitrate The data bitrate.
139     */
140    public function setDataBitrate($dataBitrate)
141    {
142        $this->_dataBitrate = $dataBitrate;
143    }
144
145    /**
146     * Specifies the size B, in bits, of the leaky bucket used in the Data
147     * Bitrate definition. This value can be less than the sum of all of the
148     * buffer sizes in the
149     * {@link Zend_Media_Asf_Object_ExtendedStreamProperties Extended Stream
150     * Properties} Objects for the streams contained in this bandwidth-sharing
151     * relationship.
152     *
153     * @return integer
154     */
155    public function getBufferSize() 
156    {
157        return $this->_bufferSize; 
158    }
159
160    /**
161     * Sets the size B, in bits, of the leaky bucket used in the Data Bitrate
162     * definition. This value can be less than the sum of all of the buffer
163     * sizes in the
164     * {@link Zend_Media_Asf_Object_ExtendedStreamProperties Extended Stream
165     * Properties} Objects for the streams contained in this bandwidth-sharing
166     * relationship.
167     *
168     * @param integer $bufferSize The buffer size.
169     */
170    public function setBufferSize($bufferSize)
171    {
172        $this->_bufferSize = $bufferSize;
173    }
174
175    /**
176     * Returns an array of stream numbers.
177     *
178     * @return Array
179     */
180    public function getStreamNumbers() 
181    {
182        return $this->_streamNumbers; 
183    }
184
185    /**
186     * Sets the array of stream numbers.
187     *
188     * @param Array $streamNumbers The array of stream numbers.
189     */
190    public function setStreamNumbers($streamNumbers)
191    {
192        $this->_streamNumbers = $streamNumbers;
193    }
194
195    /**
196     * Writes the object data.
197     *
198     * @param Zend_Io_Writer $writer The writer object.
199     * @return void
200     */
201    public function write($writer)
202    {
203        $streamNumbersCount = count($this->_streamNumber);
204
205        $this->setSize(24 /* for header */ + 28 + $streamNumbersCount * 2);
206
207        $writer->writeGuid($this->getIdentifier())
208               ->writeInt64LE($this->getSize())
209               ->writeGuid($this->_sharingType)
210               ->writeUInt32LE($this->_dataBitrate)
211               ->writeUInt32LE($this->_bufferSize)
212               ->writeUInt16LE($streamNumbersCount);
213        for ($i = 0; $i < $streamNumbersCount; $i++) {
214            $writer->writeUInt16LE($this->_streamNumbers[$i]);
215        }
216    }
217}