/src/Zend/Media/Asf/Object/Header.php

http://php-reader.googlecode.com/ · PHP · 131 lines · 52 code · 8 blank · 71 comment · 0 complexity · d1e6901964bcd713a74612a96013d32e 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: Header.php 177 2010-03-09 13:13:34Z svollbehr $
  21. */
  22. /**#@+ @ignore */
  23. require_once 'Zend/Media/Asf/Object/Container.php';
  24. /**#@-*/
  25. /**
  26. * The role of the header object is to provide a well-known byte sequence at the
  27. * beginning of ASF files and to contain all the information that is needed to
  28. * properly interpret the information within the data object. The header object
  29. * can optionally contain metadata such as bibliographic information.
  30. *
  31. * Of the three top-level ASF objects, the header object is the only one that
  32. * contains other ASF objects. The header object may include a number of
  33. * standard objects including, but not limited to:
  34. *
  35. * o File Properties Object -- Contains global file attributes.
  36. * o Stream Properties Object -- Defines a digital media stream and its
  37. * characteristics.
  38. * o Header Extension Object -- Allows additional functionality to be added to
  39. * an ASF file while maintaining backward compatibility.
  40. * o Content Description Object -- Contains bibliographic information.
  41. * o Script Command Object -- Contains commands that can be executed on the
  42. * playback timeline.
  43. * o Marker Object -- Provides named jump points within a file.
  44. *
  45. * Note that objects in the header object may appear in any order. To be valid,
  46. * the header object must contain a
  47. * {@link Zend_Media_Asf_Object_FileProperties File Properties Object}, a
  48. * {@link Zend_Media_Asf_Object_HeaderExtension Header Extension Object}, and at
  49. * least one {@link Zend_Media_Asf_Object_StreamProperties Stream Properties
  50. * Object}.
  51. *
  52. * @category Zend
  53. * @package Zend_Media
  54. * @subpackage ASF
  55. * @author Sven Vollbehr <sven@vollbehr.eu>
  56. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  57. * @license http://framework.zend.com/license/new-bsd New BSD License
  58. * @version $Id: Header.php 177 2010-03-09 13:13:34Z svollbehr $
  59. */
  60. final class Zend_Media_Asf_Object_Header extends Zend_Media_Asf_Object_Container
  61. {
  62. /** @var integer */
  63. private $_reserved1;
  64. /** @var integer */
  65. private $_reserved2;
  66. /**
  67. * Constructs the class with given parameters and options.
  68. *
  69. * @param Zend_Io_Reader $reader The reader object.
  70. * @param Array $options The options array.
  71. */
  72. public function __construct($reader, &$options = array())
  73. {
  74. parent::__construct($reader, $options);
  75. $this->_reader->skip(4);
  76. $this->_reserved1 = $this->_reader->readInt8();
  77. $this->_reserved2 = $this->_reader->readInt8();
  78. $this->constructObjects
  79. (array
  80. (self::FILE_PROPERTIES => 'FileProperties',
  81. self::STREAM_PROPERTIES => 'StreamProperties',
  82. self::HEADER_EXTENSION => 'HeaderExtension',
  83. self::CODEC_LIST => 'CodecList',
  84. self::SCRIPT_COMMAND => 'ScriptCommand',
  85. self::MARKER => 'Marker',
  86. self::BITRATE_MUTUAL_EXCLUSION => 'BitrateMutualExclusion',
  87. self::ERROR_CORRECTION => 'ErrorCorrection',
  88. self::CONTENT_DESCRIPTION => 'ContentDescription',
  89. self::EXTENDED_CONTENT_DESCRIPTION =>
  90. 'ExtendedContentDescription',
  91. self::CONTENT_BRANDING => 'ContentBranding',
  92. self::STREAM_BITRATE_PROPERTIES => 'StreamBitrateProperties',
  93. self::CONTENT_ENCRYPTION => 'ContentEncryption',
  94. self::EXTENDED_CONTENT_ENCRYPTION =>
  95. 'ExtendedContentEncryption',
  96. self::DIGITAL_SIGNATURE => 'DigitalSignature',
  97. self::PADDING => 'Padding'));
  98. }
  99. /**
  100. * Writes the object data.
  101. *
  102. * @param Zend_Io_Writer $writer The writer object.
  103. * @return void
  104. */
  105. public function write($writer)
  106. {
  107. require_once 'Zend/Io/StringWriter.php';
  108. $objectsWriter = new Zend_Io_StringWriter();
  109. foreach ($this->getObjects() as $objects) {
  110. foreach ($objects as $object) {
  111. $object->write($objectsWriter);
  112. }
  113. }
  114. $this->setSize
  115. (24 /* for header */ + 6 + $objectsWriter->getSize());
  116. $writer->writeGuid($this->getIdentifier())
  117. ->writeInt64LE($this->getSize())
  118. ->writeUInt32LE($this->getObjectCount())
  119. ->writeInt8($this->_reserved1)
  120. ->writeInt8($this->_reserved2)
  121. ->write($objectsWriter->toString());
  122. }
  123. }