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