PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/app/vendors/adapters/ffmpeg-php/php-reader/src/ID3/Object.php

https://github.com/mariuz/firetube
PHP | 150 lines | 42 code | 9 blank | 99 comment | 10 complexity | be3fd2064e7d83763023c8bcb70ab719 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /**
  3. * PHP Reader Library
  4. *
  5. * Copyright (c) 2008 The PHP Reader Project Workgroup. All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. *
  10. * - Redistributions of source code must retain the above copyright notice,
  11. * this list of conditions and the following disclaimer.
  12. * - Redistributions in binary form must reproduce the above copyright notice,
  13. * this list of conditions and the following disclaimer in the documentation
  14. * and/or other materials provided with the distribution.
  15. * - Neither the name of the project workgroup nor the names of its
  16. * contributors may be used to endorse or promote products derived from this
  17. * software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  20. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  23. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  24. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  25. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  26. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  27. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  28. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  29. * POSSIBILITY OF SUCH DAMAGE.
  30. *
  31. * @package php-reader
  32. * @subpackage ID3
  33. * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup
  34. * @license http://code.google.com/p/php-reader/wiki/License New BSD License
  35. * @version $Id: Object.php 75 2008-04-14 23:57:21Z svollbehr $
  36. */
  37. /**
  38. * The base class for all ID3v2 objects.
  39. *
  40. * @package php-reader
  41. * @subpackage ID3
  42. * @author Sven Vollbehr <svollbehr@gmail.com>
  43. * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup
  44. * @license http://code.google.com/p/php-reader/wiki/License New BSD License
  45. * @version $Rev: 75 $
  46. */
  47. abstract class ID3_Object
  48. {
  49. /**
  50. * The reader object.
  51. *
  52. * @var Reader
  53. */
  54. protected $_reader;
  55. /**
  56. * The options array.
  57. *
  58. * @var Array
  59. */
  60. protected $_options;
  61. /**
  62. * Constructs the class with given parameters and reads object related data
  63. * from the ID3v2 tag.
  64. *
  65. * @param Reader $reader The reader object.
  66. * @param Array $options The options array.
  67. */
  68. public function __construct($reader = null, &$options = array())
  69. {
  70. $this->_reader = $reader;
  71. $this->_options = $options;
  72. }
  73. /**
  74. * Returns the options array.
  75. *
  76. * @return Array
  77. */
  78. public function getOptions() { return $this->_options; }
  79. /**
  80. * Sets the options array. See {@link ID3v2} class for available options.
  81. *
  82. * @param Array $options The options array.
  83. */
  84. public function setOptions(&$options) { $this->_options = $options; }
  85. /**
  86. * Magic function so that $obj->value will work.
  87. *
  88. * @param string $name The field name.
  89. * @return mixed
  90. */
  91. public function __get($name)
  92. {
  93. if (method_exists($this, "get" . ucfirst($name)))
  94. return call_user_func(array($this, "get" . ucfirst($name)));
  95. else throw new Reader_Exception("Unknown field: " . $name);
  96. }
  97. /**
  98. * Magic function so that assignments with $obj->value will work.
  99. *
  100. * @param string $name The field name.
  101. * @param string $value The field value.
  102. * @return mixed
  103. */
  104. public function __set($name, $value)
  105. {
  106. if (method_exists($this, "set" . ucfirst($name)))
  107. call_user_func
  108. (array($this, "set" . ucfirst($name)), $value);
  109. else throw new Reader_Exception("Unknown field: " . $name);
  110. }
  111. /**
  112. * Encodes the given 32-bit integer to 28-bit synchsafe integer, where the
  113. * most significant bit of each byte is zero, making seven bits out of eight
  114. * available.
  115. *
  116. * @param integer $val The integer to encode.
  117. * @return integer
  118. */
  119. protected function encodeSynchsafe32($val)
  120. {
  121. if (!isset($this->_options["version"]) || $this->_options["version"] >= 4) {
  122. for ($i = 0, $mask = 0xffffff00; $i < 4; $i++, $mask <<= 8)
  123. $val = ($val << 1 & $mask) | ($val << 1 & ~$mask) >> 1;
  124. return $val & 0x7fffffff;
  125. }
  126. return $val;
  127. }
  128. /**
  129. * Decodes the given 28-bit synchsafe integer to regular 32-bit integer.
  130. *
  131. * @param integer $val The integer to decode
  132. * @return integer
  133. */
  134. protected function decodeSynchsafe32($val)
  135. {
  136. if (!isset($this->_options["version"]) || $this->_options["version"] >= 4)
  137. for ($i = 0, $mask = 0xff000000; $i < 3; $i++, $mask >>= 8)
  138. $val = ($val & $mask) >> 1 | ($val & ~$mask);
  139. return $val;
  140. }
  141. }