Add write support for ASF header objects
git-svn-id: http://php-reader.googlecode.com/svn/trunk@139 51a70ab9-7547-0410-9469-37e369ee0574
This commit is contained in:
@@ -2,7 +2,8 @@
|
||||
/**
|
||||
* PHP Reader Library
|
||||
*
|
||||
* Copyright (c) 2008 The PHP Reader Project Workgroup. All rights reserved.
|
||||
* Copyright (c) 2008-2009 The PHP Reader Project Workgroup. All rights
|
||||
* reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
@@ -30,7 +31,7 @@
|
||||
*
|
||||
* @package php-reader
|
||||
* @subpackage ASF
|
||||
* @copyright Copyright (c) 2008 The PHP Reader Project Workgroup
|
||||
* @copyright Copyright (c) 2008-2009 The PHP Reader Project Workgroup
|
||||
* @license http://code.google.com/p/php-reader/wiki/License New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
@@ -46,7 +47,7 @@ require_once("ASF/Object.php");
|
||||
* @package php-reader
|
||||
* @subpackage ASF
|
||||
* @author Sven Vollbehr <svollbehr@gmail.com>
|
||||
* @copyright Copyright (c) 2008 The PHP Reader Project Workgroup
|
||||
* @copyright Copyright (c) 2008-2009 The PHP Reader Project Workgroup
|
||||
* @license http://code.google.com/p/php-reader/wiki/License New BSD License
|
||||
* @version $Rev$
|
||||
*/
|
||||
@@ -56,6 +57,9 @@ final class ASF_Object_CodecList extends ASF_Object
|
||||
const AUDIO_CODEC = 0x2;
|
||||
const UNKNOWN_CODEC = 0xffff;
|
||||
|
||||
/** @var string */
|
||||
private $_reserved;
|
||||
|
||||
/** @var Array */
|
||||
private $_entries = array();
|
||||
|
||||
@@ -66,11 +70,14 @@ final class ASF_Object_CodecList extends ASF_Object
|
||||
* @param Reader $reader The reader object.
|
||||
* @param Array $options The options array.
|
||||
*/
|
||||
public function __construct($reader, &$options = array())
|
||||
public function __construct($reader = null, &$options = array())
|
||||
{
|
||||
parent::__construct($reader, $options);
|
||||
|
||||
$this->_reader->skip(16);
|
||||
if ($reader === null)
|
||||
return;
|
||||
|
||||
$this->_reserved = $this->_reader->readGUID();
|
||||
$codecEntriesCount = $this->_reader->readUInt32LE();
|
||||
for ($i = 0; $i < $codecEntriesCount; $i++) {
|
||||
$entry = array("type" => $this->_reader->readUInt16LE());
|
||||
@@ -90,9 +97,85 @@ final class ASF_Object_CodecList extends ASF_Object
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the array of codec entries.
|
||||
* Returns the array of codec entries. Each record consists of the following
|
||||
* keys.
|
||||
*
|
||||
* o type -- Specifies the type of the codec used. Use one of the following
|
||||
* values: VIDEO_CODEC, AUDIO_CODEC, or UNKNOWN_CODEC.
|
||||
*
|
||||
* o codecName -- Specifies the name of the codec used to create the
|
||||
* content.
|
||||
*
|
||||
* o codecDescription -- Specifies the description of the format used to
|
||||
* create the content.
|
||||
*
|
||||
* o codecInformation -- Specifies an opaque array of information bytes
|
||||
* about the codec used to create the content. The meaning of these bytes
|
||||
* is determined by the codec.
|
||||
*
|
||||
* @return Array
|
||||
*/
|
||||
public function getEntries() { return $this->_entries; }
|
||||
|
||||
/**
|
||||
* Sets the array of codec entries. Each record must consist of the following
|
||||
* keys.
|
||||
*
|
||||
* o codecName -- Specifies the name of the codec used to create the
|
||||
* content.
|
||||
*
|
||||
* o codecDescription -- Specifies the description of the format used to
|
||||
* create the content.
|
||||
*
|
||||
* o codecInformation -- Specifies an opaque array of information bytes
|
||||
* about the codec used to create the content. The meaning of these bytes
|
||||
* is determined by the codec.
|
||||
*
|
||||
* @param Array $entries The array of codec entries.
|
||||
*/
|
||||
public function setEntries($entries) { $this->_entries = $entries; }
|
||||
|
||||
/**
|
||||
* Returns the whether the object is required to be present, or whether
|
||||
* minimum cardinality is 1.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isMandatory() { return false; }
|
||||
|
||||
/**
|
||||
* Returns whether multiple instances of this object can be present, or
|
||||
* whether maximum cardinality is greater than 1.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isMultiple() { return false; }
|
||||
|
||||
/**
|
||||
* Returns the object data with headers.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
$data = Transform::toGUID($this->_reserved) .
|
||||
Transform::toUInt32LE($codecEntriesCount = count($this->_entries));
|
||||
for ($i = 0; $i < $codecEntriesCount; $i++) {
|
||||
$data .= Transform::toUInt16LE($this->_entries[$i]["type"]) .
|
||||
Transform::toUInt16LE(strlen($codecName = iconv
|
||||
($this->getOption("encoding"), "utf-16le",
|
||||
$this->_entries[$i]["codecName"]) . "\0\0") / 2) .
|
||||
Transform::toString16LE($codecName) .
|
||||
Transform::toUInt16LE(strlen($codecDescription = iconv
|
||||
($this->getOption("encoding"), "utf-16le",
|
||||
$this->_entries[$i]["codecDescription"]) . "\0\0") / 2) .
|
||||
Transform::toString16LE($codecDescription) .
|
||||
Transform::toUInt16LE(strlen($this->_entries[$i]["codecInformation"])) .
|
||||
$this->_entries[$i]["codecInformation"];
|
||||
}
|
||||
$this->setSize(24 /* for header */ + strlen($data));
|
||||
return
|
||||
Transform::toGUID($this->getIdentifier()) .
|
||||
Transform::toInt64LE($this->getSize()) . $data;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user