/extensions/MetavidWiki/skins/mv_embed/oggServer/PEAR/File_Ogg/File/Ogg/Bitstream.php

https://github.com/ChuguluGames/mediawiki-svn · PHP · 140 lines · 42 code · 9 blank · 89 comment · 5 complexity · 196bf11e1d4083a2135eebac99e185e3 MD5 · raw file

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------------+
  4. // | File_Ogg PEAR Package for Accessing Ogg Bitstreams |
  5. // | Copyright (c) 2005-2007 |
  6. // | David Grant <david@grant.org.uk> |
  7. // | Tim Starling <tstarling@wikimedia.org> |
  8. // +----------------------------------------------------------------------------+
  9. // | This library is free software; you can redistribute it and/or |
  10. // | modify it under the terms of the GNU Lesser General Public |
  11. // | License as published by the Free Software Foundation; either |
  12. // | version 2.1 of the License, or (at your option) any later version. |
  13. // | |
  14. // | This library is distributed in the hope that it will be useful, |
  15. // | but WITHOUT ANY WARRANTY; without even the implied warranty of |
  16. // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
  17. // | Lesser General Public License for more details. |
  18. // | |
  19. // | You should have received a copy of the GNU Lesser General Public |
  20. // | License along with this library; if not, write to the Free Software |
  21. // | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
  22. // +----------------------------------------------------------------------------+
  23. /**
  24. * @author David Grant <david@grant.org.uk>, Tim Starling <tstarling@wikimedia.org>
  25. * @category File
  26. * @copyright David Grant <david@grant.org.uk>, Tim Starling <tstarling@wikimedia.org>
  27. * @license http://www.gnu.org/copyleft/lesser.html GNU LGPL
  28. * @link http://pear.php.net/package/File_Ogg
  29. * @package File_Ogg
  30. * @version CVS: $Id: Bitstream.php,v 1.3 2005/11/08 19:36:18 djg Exp $
  31. */
  32. class File_Ogg_Bitstream
  33. {
  34. /**
  35. * The serial number of this logical stream.
  36. *
  37. * @var int
  38. * @access private
  39. */
  40. var $_streamSerial;
  41. /**
  42. * @access private
  43. */
  44. var $_streamList;
  45. /**
  46. * @access private
  47. */
  48. var $_filePointer;
  49. /**
  50. * The number of bits used in this stream.
  51. *
  52. * @var int
  53. * @access private
  54. */
  55. var $_streamSize;
  56. /**
  57. * The last granule position in the stream
  58. * @var int
  59. * @access private
  60. */
  61. var $_lastGranulePos;
  62. /**
  63. * Constructor for a generic logical stream.
  64. *
  65. * @param int $streamSerial Serial number of the logical stream.
  66. * @param array $streamData Data for the requested logical stream.
  67. * @param string $filePath Location of a file on the filesystem.
  68. * @param pointer $filePointer File pointer for the current physical stream.
  69. * @access private
  70. */
  71. function __construct($streamSerial, $streamData, $filePointer)
  72. {
  73. $this->_streamSerial = $streamSerial;
  74. $this->_streamList = $streamData;
  75. $this->_filePointer = $filePointer;
  76. $this->_lastGranulePos = 0;
  77. $this->_firstGranulePos = 0;
  78. // This gives an accuracy of approximately 99.7% to the streamsize of ogginfo.
  79. foreach ( $streamData as $packet ) {
  80. # Reject -1 as a granule pos, that means no segment finished in the packet
  81. if ( $packet['abs_granule_pos'] != 'ffffffffffffffff' ) {
  82. $this->_streamSize += $packet['data_length'];
  83. # Reject -1 as a granule pos, that means no segment finished in the packet
  84. if ( $packet['abs_granule_pos'] != 'ffffffffffffffff' ) {
  85. $currentPos = $packet['abs_granule_pos'];
  86. $this->_lastGranulePos = max($this->_lastGranulePos, $currentPos);
  87. //set the _firstGranulePos
  88. if( hexdec( $this->_firstGranulePos ) === 0){
  89. //print "on stream: $streamSerial set first gran:". $currentPos.": ". hexdec( $currentPos ) ."\n";
  90. $this->_firstGranulePos = $currentPos;
  91. }
  92. }
  93. }
  94. }
  95. $this->_group = $streamData[0]['group'];
  96. }
  97. /**
  98. * Gives the serial number of this stream.
  99. *
  100. * The stream serial number is of fairly academic importance, as it makes little
  101. * difference to the end user. The serial number is used by the Ogg physical
  102. * stream to distinguish between concurrent logical streams.
  103. *
  104. * @return int
  105. * @access public
  106. */
  107. function getSerial()
  108. {
  109. return ($this->_streamSerial);
  110. }
  111. /**
  112. * Gives the size (in bits) of this stream.
  113. *
  114. * This function returns the size of the Vorbis stream within the Ogg
  115. * physical stream.
  116. *
  117. * @return int
  118. * @access public
  119. */
  120. function getSize()
  121. {
  122. return ($this->_streamSize);
  123. }
  124. /**
  125. * Get the multiplexed group ID
  126. */
  127. function getGroup()
  128. {
  129. return $this->_group;
  130. }
  131. }