ï»¿<?php
/**
 * MP4Info
 * 
 * @author 		Tommy Lacroix <lacroix.tommy@gmail.com>
 * @copyright   Copyright (c) 2006-2009 Tommy Lacroix
 * @license		LGPL version 3, http://www.gnu.org/licenses/lgpl.html
 * @package 	php-mp4info
 * @link 		$HeadURL$
 *
 * Version allégée par Jean-Yves Giraud (décembre 2013) pour récupérer uniquement largeur et hauteur d'une video MP4
 *
 */

// ---

/**
 * 8.9 Handler Reference Box (HDLR)
 * 
 * @author 		Tommy Lacroix <lacroix.tommy@gmail.com>
 * @version 	1.0.20090601	$Id$
 * @todo 		Factor this into a fullbox
 */
class MP4Info_Box_hdlr extends MP4Info_Box {
	
	/**
	 * Constructor
	 *
	 * @author 	Tommy Lacroix <lacroix.tommy@gmail.com>
	 * @param	int					$totalSize
	 * @param	int					$boxType
	 * @param	file|string			$data
	 * @param	MP4Info_Box			$parent
	 * @return 	MP4Info_Box_hdlr
	 * @access 	public
	 * @throws 	Exception
	 */	
	public function __construct($totalSize, $boxType, $data, $parent) {
		if (!self::isCompatible($boxType, $parent)) {
			throw new Exception('This box isn\'t "ftyp"');
		}

		// Call ancestor
		parent::__construct($totalSize,$boxType,'',$parent);
		
		// Get data
		$data = self::getDataFrom3rd($data,$totalSize);

		// Unpack
		$ar = unpack('Cversion/C3flags',$data);
		if ($ar['version'] == 0) {
			// 32 bit
			$ar2 = unpack('Nctime/Nmtime/NtimeScale/Nduration',substr($data,4));
			$len = 6*4;
		} else if ($ar['version'] == 1) {
			// 64 bit
			$ar2 = unpack('N2ctime/N2mtime/NtimeScale/N2duration',substr($data,4));
			$len = 9*4;
		} else {
			throw new Exception('Unhandled version: '.$ar['version']);
		}
		
		// Save		
		$this->handlerType = substr($data,$len,4);
	} // Constructor
	
	
	/**
	 * Check if block is compatible with class
	 *
	 * @author 	Tommy Lacroix <lacroix.tommy@gmail.com>
	 * @param 	int					$boxType
	 * @param 	MP4Info_Box			$parent
	 * @return 	bool
	 * @access 	public
	 * @static
	 */	
	static public function isCompatible($boxType, $parent) {
		return $boxType == 0x68646c72;
	} // isCompatible method
	
	
	/**
	 * Handler type getter
	 *
	 * @author 	Tommy Lacroix <lacroix.tommy@gmail.com>
	 * @return	int
	 * @access 	public
	 */
	public function getHandlerType() {
		return $this->handlerType;
	} // getHandlerType method

}	