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