PageRenderTime 21ms CodeModel.GetById 12ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

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