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