diff --git a/ext/handle_video/main.php b/ext/handle_video/main.php
new file mode 100644
index 00000000..9d34d436
--- /dev/null
+++ b/ext/handle_video/main.php
@@ -0,0 +1,82 @@
+
+ * License: GPLv2
+ * Description: Handle FLV, MP4, OGV and WEBM video files.
+ * Documentation:
+ * Based heavily on "Handle MP3" by Shish.
+ * FLV: Flash player
+ * MP4: HTML5 with Flash fallback
+ * OGV, WEBM: HTML5
+ * MP4's flash fallback is forced with a bit of Javascript as some browsers won't fallback if they can't play H.264.
+ * In the future, it may be necessary to change the user agent checks to reflect the current state of H.264 support.
+ * Made possible by:
+ * getID3() - Gets media information with PHP (no bulky FFMPEG API required).
+ * Jaris FLV Player - GPLv3 flash multimedia player.
+ */
+
+class VideoFileHandler extends DataHandlerExtension {
+ protected function create_thumb($hash) {
+ copy("ext/handle_video/thumb.jpg", warehouse_path("thumbs", $hash));
+ }
+
+ protected function supported_ext($ext) {
+ $exts = array("flv", "mp4", "m4v", "ogv", "webm");
+ return in_array(strtolower($ext), $exts);
+ }
+
+ protected function create_image_from_data($filename, $metadata) {
+ global $config;
+
+ $image = new Image();
+
+ require_once('lib/getid3/getid3/getid3.php');
+ $getID3 = new getID3;
+ $ThisFileInfo = $getID3->analyze($filename);
+
+ if (isset($ThisFileInfo['video']['resolution_x']) && isset($ThisFileInfo['video']['resolution_y'])) {
+ $image->width = $ThisFileInfo['video']['resolution_x'];
+ $image->height = $ThisFileInfo['video']['resolution_y'];
+ } else {
+ $image->width = 0;
+ $image->height = 0;
+ }
+
+ switch ($ThisFileInfo['mime_type']) {
+ case "video/webm":
+ $image->ext = "webm";
+ break;
+ case "video/quicktime":
+ $image->ext = "mp4";
+ break;
+ case "application/ogg":
+ $image->ext = "ogv";
+ break;
+ case "video/x-flv":
+ $image->ext = "flv";
+ break;
+ }
+
+ $image->filesize = $metadata['size'];
+ $image->hash = $metadata['hash'];
+ $image->filename = $metadata['filename'];
+ $image->tag_array = Tag::explode($metadata['tags']);
+ $image->source = $metadata['source'];
+
+ return $image;
+ }
+
+ protected function check_contents($file) {
+ if (file_exists($file)) {
+ require_once('lib/getid3/getid3/getid3.php');
+ $getID3 = new getID3;
+ $ThisFileInfo = $getID3->analyze($file);
+ if (isset($ThisFileInfo['mime_type']) && ($ThisFileInfo['mime_type'] == "video/webm" || $ThisFileInfo['mime_type'] == "video/quicktime" || $ThisFileInfo['mime_type'] == "application/ogg" || $ThisFileInfo['mime_type'] == 'video/x-flv')) {
+ return TRUE;
+ }
+ }
+ return FALSE;
+ }
+}
+?>
diff --git a/ext/handle_video/theme.php b/ext/handle_video/theme.php
new file mode 100644
index 00000000..c58dd6e5
--- /dev/null
+++ b/ext/handle_video/theme.php
@@ -0,0 +1,37 @@
+get_image_link();
+ $ext = strtolower($image->get_ext());
+
+ if ($ext == "mp4") {
+ $html = "Video not playing? Click here to download the file.
+";
+ } elseif ($ext == "flv") {
+ $html = "Video not playing? Click here to download the file. ";
+ } elseif ($ext == "ogv") {
+ $html = "Video not playing? Click here to download the file. ";
+ } elseif ($ext == "webm") {
+ $html = "Video not playing? Click here to download the file. ";
+ }
+ $page->add_block(new Block("Video", $html, "main", 10));
+ }
+}
+?>
diff --git a/ext/handle_video/thumb.jpg b/ext/handle_video/thumb.jpg
new file mode 100644
index 00000000..d52ac9c4
Binary files /dev/null and b/ext/handle_video/thumb.jpg differ
diff --git a/lib/Jaris/Jaris FLV Player.hxproj b/lib/Jaris/Jaris FLV Player.hxproj
new file mode 100644
index 00000000..f71a96a8
--- /dev/null
+++ b/lib/Jaris/Jaris FLV Player.hxproj
@@ -0,0 +1,55 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/lib/Jaris/bin/JarisFLVPlayer.swf b/lib/Jaris/bin/JarisFLVPlayer.swf
new file mode 100644
index 00000000..467f2eb0
Binary files /dev/null and b/lib/Jaris/bin/JarisFLVPlayer.swf differ
diff --git a/lib/Jaris/bin/expressInstall.swf b/lib/Jaris/bin/expressInstall.swf
new file mode 100644
index 00000000..86958bf3
Binary files /dev/null and b/lib/Jaris/bin/expressInstall.swf differ
diff --git a/lib/Jaris/bin/index.html b/lib/Jaris/bin/index.html
new file mode 100644
index 00000000..0b4dedef
--- /dev/null
+++ b/lib/Jaris/bin/index.html
@@ -0,0 +1,126 @@
+
+
+
+ Jaris FLV Player
+
+
+
+
+
+
+
+
+
+
+
+
+
Video Example
+
+
Jaris FLV Player
+
Alternative content
+
+
+
+
+
+
Video Example with New Controls
+
+
Jaris FLV Player
+
Alternative content
+
+
+
+
+
+
Audio Example
+
+
Jaris FLV Player
+
Alternative content
+
+
+
+
+
diff --git a/lib/Jaris/bin/jarisflvplayer.js b/lib/Jaris/bin/jarisflvplayer.js
new file mode 100644
index 00000000..08ae0a02
--- /dev/null
+++ b/lib/Jaris/bin/jarisflvplayer.js
@@ -0,0 +1,98 @@
+/**
+ * @author Jefferson Gonzalez
+ * @copyright 2010 Jefferson Gonzalez
+ *
+ * @license
+ * This file is part of Jaris FLV Player.
+ *
+ * Jaris FLV Player is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License or GNU LESSER GENERAL
+ * PUBLIC LICENSE as published by the Free Software Foundation, either version
+ * 3 of the License, or (at your option) any later version.
+ *
+ * Jaris FLV Player is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License and
+ * GNU LESSER GENERAL PUBLIC LICENSE along with Jaris FLV Player. If not,
+ * see .
+ */
+
+/**
+ *Interface for the JarisFLVPlayer JavaScript API implemented
+ *by Sascha from http://projekktor.com/
+ *@param id The id of the flash object
+*/
+function JarisFLVPlayer(id){
+
+ this.playerId = id; //Stores the id of the player
+ this.player = document.getElementById(id); //Object that points to the player
+}
+
+//Event constants
+JarisFLVPlayer.event = {
+ MOUSE_HIDE: "onMouseHide",
+ MOUSE_SHOW: "onMouseShow",
+ MEDIA_INITIALIZED: "onDataInitialized",
+ BUFFERING: "onBuffering",
+ NOT_BUFFERING: "onNotBuffering",
+ RESIZE: "onResize",
+ PLAY_PAUSE: "onPlayPause",
+ PLAYBACK_FINISHED: "onPlaybackFinished",
+ CONNECTION_FAILED: "onConnectionFailed",
+ ASPECT_RATIO: "onAspectRatio",
+ VOLUME_UP: "onVolumeUp",
+ VOLUME_DOWN: "onVolumeDown",
+ VOLUME_CHANGE: "onVolumeChange",
+ MUTE: "onMute",
+ TIME: "onTimeUpdate",
+ PROGRESS: "onProgress",
+ SEEK: "onSeek",
+ ON_ALL: "on*"
+};
+
+JarisFLVPlayer.prototype.isBuffering = function(){
+ return this.player.api_get("isBuffering");
+}
+
+JarisFLVPlayer.prototype.isPlaying = function(){
+ return this.player.api_get("isPlaying");
+}
+
+JarisFLVPlayer.prototype.getCurrentTime = function(){
+ return this.player.api_get("time");
+}
+
+JarisFLVPlayer.prototype.getBytesLoaded = function(){
+ return this.player.api_get("loaded");
+}
+
+JarisFLVPlayer.prototype.getVolume = function(){
+ return this.player.api_get("volume");
+}
+
+JarisFLVPlayer.prototype.addListener = function(event, listener){
+ this.player.api_addlistener(event, listener);
+}
+
+JarisFLVPlayer.prototype.removeListener = function(event){
+ this.player.api_removelistener(event);
+}
+
+JarisFLVPlayer.prototype.play = function(){
+ this.player.api_play();
+}
+
+JarisFLVPlayer.prototype.pause = function(){
+ this.player.api_pause();
+}
+
+JarisFLVPlayer.prototype.seek = function(seconds){
+ this.player.api_seek(seconds);
+}
+
+JarisFLVPlayer.prototype.volume = function(value){
+ this.player.api_volume(value);
+}
diff --git a/lib/Jaris/bin/js/swfobject.js b/lib/Jaris/bin/js/swfobject.js
new file mode 100644
index 00000000..8eafe9dd
--- /dev/null
+++ b/lib/Jaris/bin/js/swfobject.js
@@ -0,0 +1,4 @@
+/* SWFObject v2.2
+ is released under the MIT License
+*/
+var swfobject=function(){var D="undefined",r="object",S="Shockwave Flash",W="ShockwaveFlash.ShockwaveFlash",q="application/x-shockwave-flash",R="SWFObjectExprInst",x="onreadystatechange",O=window,j=document,t=navigator,T=false,U=[h],o=[],N=[],I=[],l,Q,E,B,J=false,a=false,n,G,m=true,M=function(){var aa=typeof j.getElementById!=D&&typeof j.getElementsByTagName!=D&&typeof j.createElement!=D,ah=t.userAgent.toLowerCase(),Y=t.platform.toLowerCase(),ae=Y?/win/.test(Y):/win/.test(ah),ac=Y?/mac/.test(Y):/mac/.test(ah),af=/webkit/.test(ah)?parseFloat(ah.replace(/^.*webkit\/(\d+(\.\d+)?).*$/,"$1")):false,X=!+"\v1",ag=[0,0,0],ab=null;if(typeof t.plugins!=D&&typeof t.plugins[S]==r){ab=t.plugins[S].description;if(ab&&!(typeof t.mimeTypes!=D&&t.mimeTypes[q]&&!t.mimeTypes[q].enabledPlugin)){T=true;X=false;ab=ab.replace(/^.*\s+(\S+\s+\S+$)/,"$1");ag[0]=parseInt(ab.replace(/^(.*)\..*$/,"$1"),10);ag[1]=parseInt(ab.replace(/^.*\.(.*)\s.*$/,"$1"),10);ag[2]=/[a-zA-Z]/.test(ab)?parseInt(ab.replace(/^.*[a-zA-Z]+(.*)$/,"$1"),10):0}}else{if(typeof O.ActiveXObject!=D){try{var ad=new ActiveXObject(W);if(ad){ab=ad.GetVariable("$version");if(ab){X=true;ab=ab.split(" ")[1].split(",");ag=[parseInt(ab[0],10),parseInt(ab[1],10),parseInt(ab[2],10)]}}}catch(Z){}}}return{w3:aa,pv:ag,wk:af,ie:X,win:ae,mac:ac}}(),k=function(){if(!M.w3){return}if((typeof j.readyState!=D&&j.readyState=="complete")||(typeof j.readyState==D&&(j.getElementsByTagName("body")[0]||j.body))){f()}if(!J){if(typeof j.addEventListener!=D){j.addEventListener("DOMContentLoaded",f,false)}if(M.ie&&M.win){j.attachEvent(x,function(){if(j.readyState=="complete"){j.detachEvent(x,arguments.callee);f()}});if(O==top){(function(){if(J){return}try{j.documentElement.doScroll("left")}catch(X){setTimeout(arguments.callee,0);return}f()})()}}if(M.wk){(function(){if(J){return}if(!/loaded|complete/.test(j.readyState)){setTimeout(arguments.callee,0);return}f()})()}s(f)}}();function f(){if(J){return}try{var Z=j.getElementsByTagName("body")[0].appendChild(C("span"));Z.parentNode.removeChild(Z)}catch(aa){return}J=true;var X=U.length;for(var Y=0;Y0){for(var af=0;af0){var ae=c(Y);if(ae){if(F(o[af].swfVersion)&&!(M.wk&&M.wk<312)){w(Y,true);if(ab){aa.success=true;aa.ref=z(Y);ab(aa)}}else{if(o[af].expressInstall&&A()){var ai={};ai.data=o[af].expressInstall;ai.width=ae.getAttribute("width")||"0";ai.height=ae.getAttribute("height")||"0";if(ae.getAttribute("class")){ai.styleclass=ae.getAttribute("class")}if(ae.getAttribute("align")){ai.align=ae.getAttribute("align")}var ah={};var X=ae.getElementsByTagName("param");var ac=X.length;for(var ad=0;ad'}}aa.outerHTML='";N[N.length]=ai.id;X=c(ai.id)}else{var Z=C(r);Z.setAttribute("type",q);for(var ac in ai){if(ai[ac]!=Object.prototype[ac]){if(ac.toLowerCase()=="styleclass"){Z.setAttribute("class",ai[ac])}else{if(ac.toLowerCase()!="classid"){Z.setAttribute(ac,ai[ac])}}}}for(var ab in ag){if(ag[ab]!=Object.prototype[ab]&&ab.toLowerCase()!="movie"){e(Z,ab,ag[ab])}}aa.parentNode.replaceChild(Z,aa);X=Z}}return X}function e(Z,X,Y){var aa=C("param");aa.setAttribute("name",X);aa.setAttribute("value",Y);Z.appendChild(aa)}function y(Y){var X=c(Y);if(X&&X.nodeName=="OBJECT"){if(M.ie&&M.win){X.style.display="none";(function(){if(X.readyState==4){b(Y)}else{setTimeout(arguments.callee,10)}})()}else{X.parentNode.removeChild(X)}}}function b(Z){var Y=c(Z);if(Y){for(var X in Y){if(typeof Y[X]=="function"){Y[X]=null}}Y.parentNode.removeChild(Y)}}function c(Z){var X=null;try{X=j.getElementById(Z)}catch(Y){}return X}function C(X){return j.createElement(X)}function i(Z,X,Y){Z.attachEvent(X,Y);I[I.length]=[Z,X,Y]}function F(Z){var Y=M.pv,X=Z.split(".");X[0]=parseInt(X[0],10);X[1]=parseInt(X[1],10)||0;X[2]=parseInt(X[2],10)||0;return(Y[0]>X[0]||(Y[0]==X[0]&&Y[1]>X[1])||(Y[0]==X[0]&&Y[1]==X[1]&&Y[2]>=X[2]))?true:false}function v(ac,Y,ad,ab){if(M.ie&&M.mac){return}var aa=j.getElementsByTagName("head")[0];if(!aa){return}var X=(ad&&typeof ad=="string")?ad:"screen";if(ab){n=null;G=null}if(!n||G!=X){var Z=C("style");Z.setAttribute("type","text/css");Z.setAttribute("media",X);n=aa.appendChild(Z);if(M.ie&&M.win&&typeof j.styleSheets!=D&&j.styleSheets.length>0){n=j.styleSheets[j.styleSheets.length-1]}G=X}if(M.ie&&M.win){if(n&&typeof n.addRule==r){n.addRule(ac,Y)}}else{if(n&&typeof j.createTextNode!=D){n.appendChild(j.createTextNode(ac+" {"+Y+"}"))}}}function w(Z,X){if(!m){return}var Y=X?"visible":"hidden";if(J&&c(Z)){c(Z).style.visibility=Y}else{v("#"+Z,"visibility:"+Y)}}function L(Y){var Z=/[\\\"<>\.;]/;var X=Z.exec(Y)!=null;return X&&typeof encodeURIComponent!=D?encodeURIComponent(Y):Y}var d=function(){if(M.ie&&M.win){window.attachEvent("onunload",function(){var ac=I.length;for(var ab=0;ab
+
+
+
+
+
+
+
+
+
+
+
+--------------------------------------End-Code---------------------------------------
+
+==================
+Flash Variables
+==================
+
+Here is the list of variables that you can pass to the player.
+
+ * source:
+ This is the actual path of the media that is going to be played.
+
+ * type:
+ The type of file to play, allowable values are: audio, video.
+
+ * streamtype:
+ The stream type of the file, allowable values are: file, http, rmtp, youtube.
+
+ * server:
+ Used in coordination with rtmp stream servers
+
+ * duration:
+ Total times in seconds for input media or formatted string in the format hh:mm:ss
+
+ * poster:
+ Screenshot of the video that is displayed before playing in png, jpg or gif format.
+
+ * autostart:
+ A true or false value that indicates to the player if it should auto play the video on load.
+
+ * logo:
+ The path to the image of your logo.
+
+ * logoposition:
+ The position of the logo in the player, permitted values are: top left, top right, bottom left and bottom right
+
+ * logoalpha:
+ The transparency percent. values permitted 0 to 100, while more higher the vale less transparency is applied.
+
+ * logowidth:
+ The width in pixels of the logo.
+
+ * logolink:
+ A link to a webpage when the logo is clicked.
+
+ * hardwarescaling:
+ Enable or disable hardware scaling on fullscreen mode, values: false or true
+
+ * logoalpha:
+ The transparency percent. values permitted 1 to 100
+
+ * controls:
+ To disable the displaying of controls, values: false to hide otherwise defaults to show
+
+ * controltype
+ Choose which controls to displa. 0 = old controls, 1 = new controls
+
+ * controlsize
+ Changes the height of the new controllers, the default value is 40
+
+ * seekcolor
+ Change the seekbar color (new controls only)
+
+ * darkcolor:
+ The darker color of player controls in html hexadecimal format
+
+ * brightcolor:
+ The bright color of player controls in html hexadecimal format
+
+ * controlcolor:
+ The face color of controls in html hexadecimal format
+
+ * hovercolor:
+ On mouse hover color for controls in html hexadecimal format
+
+ * aspectratio:
+ To override original aspect ratio on first time player load. Allowable values: 1:1, 3:2, 4:3, 5:4, 14:9, 14:10, 16:9, 16:10
+
+ * jsapi:
+ Expose events to javascript functions and enable controlling the player from the outside. Set to any value to enable.
+
+ * loop:
+ As the variable says this keeps looping the video. Set to any value to enable.
+
+ * buffertime
+ To change the default 10 seconds buffer time for local/pseudo streaming
+
+==================
+Keyboard Shortcuts
+==================
+
+Here is the list of keyboard shortcuts to control Jaris Player.
+
+ * SPACE
+ Play or pause video.
+
+ * TAB
+ Switch between different aspect ratios.
+
+ * UP
+ Raise volume
+
+ * DOWN
+ Lower volume
+
+ * LEFT
+ Rewind
+
+ * RIGHT
+ Forward
+
+ * M
+ Mute or unmute volume.
+
+ * F
+ Swtich to fullscreen mode.
+
+ * X
+ Stops and close current stream
\ No newline at end of file
diff --git a/lib/Jaris/license.txt b/lib/Jaris/license.txt
new file mode 100644
index 00000000..f55f0f68
--- /dev/null
+++ b/lib/Jaris/license.txt
@@ -0,0 +1,789 @@
+ GNU GENERAL PUBLIC LICENSE
+
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc.
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users. We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors. You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+ To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. You must make sure that they, too, receive
+or can get the source code. And you must show them these terms so they
+know their rights.
+
+ Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+ For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+ Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so. This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software. The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products. If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary. To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Use with the GNU Affero General Public License.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc.
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+ This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+ 0. Additional Definitions.
+
+ As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+ "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+ An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+ A "Combined Work" is a work produced by combining or linking an
+Application with the Library. The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+ The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+ The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+ 1. Exception to Section 3 of the GNU GPL.
+
+ You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+ 2. Conveying Modified Versions.
+
+ If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+ a) under this License, provided that you make a good faith effort to
+ ensure that, in the event an Application does not supply the
+ function or data, the facility still operates, and performs
+ whatever part of its purpose remains meaningful, or
+
+ b) under the GNU GPL, with none of the additional permissions of
+ this License applicable to that copy.
+
+ 3. Object Code Incorporating Material from Library Header Files.
+
+ The object code form of an Application may incorporate material from
+a header file that is part of the Library. You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+ a) Give prominent notice with each copy of the object code that the
+ Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the object code with a copy of the GNU GPL and this license
+ document.
+
+ 4. Combined Works.
+
+ You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+ a) Give prominent notice with each copy of the Combined Work that
+ the Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
+ document.
+
+ c) For a Combined Work that displays copyright notices during
+ execution, include the copyright notice for the Library among
+ these notices, as well as a reference directing the user to the
+ copies of the GNU GPL and this license document.
+
+ d) Do one of the following:
+
+ 0) Convey the Minimal Corresponding Source under the terms of this
+ License, and the Corresponding Application Code in a form
+ suitable for, and under terms that permit, the user to
+ recombine or relink the Application with a modified version of
+ the Linked Version to produce a modified Combined Work, in the
+ manner specified by section 6 of the GNU GPL for conveying
+ Corresponding Source.
+
+ 1) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (a) uses at run time
+ a copy of the Library already present on the user's computer
+ system, and (b) will operate properly with a modified version
+ of the Library that is interface-compatible with the Linked
+ Version.
+
+ e) Provide Installation Information, but only if you would otherwise
+ be required to provide such information under section 6 of the
+ GNU GPL, and only to the extent that such information is
+ necessary to install and execute a modified version of the
+ Combined Work produced by recombining or relinking the
+ Application with a modified version of the Linked Version. (If
+ you use option 4d0, the Installation Information must accompany
+ the Minimal Corresponding Source and Corresponding Application
+ Code. If you use option 4d1, you must provide the Installation
+ Information in the manner specified by section 6 of the GNU GPL
+ for conveying Corresponding Source.)
+
+ 5. Combined Libraries.
+
+ You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+ a) Accompany the combined library with a copy of the same work based
+ on the Library, uncombined with any other library facilities,
+ conveyed under the terms of this License.
+
+ b) Give prominent notice with the combined library that part of it
+ is a work based on the Library, and explaining where to find the
+ accompanying uncombined form of the same work.
+
+ 6. Revised Versions of the GNU Lesser General Public License.
+
+ The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+ If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
diff --git a/lib/Jaris/readme.txt b/lib/Jaris/readme.txt
new file mode 100644
index 00000000..bd797e32
--- /dev/null
+++ b/lib/Jaris/readme.txt
@@ -0,0 +1,52 @@
+==================
+Jaris FLV Player
+==================
+A flash flv player made using haxe and flash develop that can be embedded into any website
+for free or commercial use.
+
+Web Page: http://jaris.sourceforge.net/
+Project Page: https://sourceforge.net/projects/jaris/
+
+==================
+Be Free!
+==================
+
+Searching for an flv player that could be used freely in all aspects and open source was
+a hard job. So I just decided to work on a basic player that had the most important
+features found in others players.
+
+Thats the story of how Jaris was born.
+
+==================
+Features
+==================
+
+
+ * Aspect ratio switcher
+ * Fullscreen support
+ * Http pseudostreaming support
+ * Poster image
+ * Volume control
+ * Seek control
+ * Display time
+ * Use your own logo
+ * Add a link to your logo
+ * Change position of logo
+ * Hide controls on fullscreen
+ * Custom control colors
+ * Hardware scaling
+ * Keyboard shortcuts
+ * Mp3 support
+
+
+==================
+License
+==================
+
+Jaris is licensed under GPL and LGPL, meaning that you could use it commercially.
+What we ask for is that any improvements made to the player should be taken back to jaris flv website
+so that any one could enjoy the new improvements or features also. In this way everyone could
+help to maintain an up to date tool that adapts to todays multimedia demands.
+Using sourceforge.net you could send a patch http://sourceforge.net/projects/jaris/.
+
+Enjoy a totally free player ;-)
\ No newline at end of file
diff --git a/lib/Jaris/src/jaris/Main.hx b/lib/Jaris/src/jaris/Main.hx
new file mode 100644
index 00000000..525ab87e
--- /dev/null
+++ b/lib/Jaris/src/jaris/Main.hx
@@ -0,0 +1,204 @@
+/**
+ * @author Jefferson González
+ * @copyright 2010 Jefferson González
+ *
+ * @license
+ * This file is part of Jaris FLV Player.
+ *
+ * Jaris FLV Player is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License or GNU LESSER GENERAL
+ * PUBLIC LICENSE as published by the Free Software Foundation, either version
+ * 3 of the License, or (at your option) any later version.
+ *
+ * Jaris FLV Player is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License and
+ * GNU LESSER GENERAL PUBLIC LICENSE along with Jaris FLV Player. If not,
+ * see .
+ */
+
+
+package jaris;
+
+import flash.display.MovieClip;
+import flash.display.Stage;
+import flash.display.StageAlign;
+import flash.display.StageScaleMode;
+import flash.Lib;
+import flash.system.Capabilities;
+import jaris.display.Logo;
+import jaris.display.Menu;
+import jaris.display.Poster;
+import jaris.player.controls.Controls;
+import jaris.player.newcontrols.NewControls;
+import jaris.player.JsApi;
+import jaris.player.InputType;
+import jaris.player.Player;
+import jaris.player.StreamType;
+import jaris.player.AspectRatio;
+import jaris.player.UserSettings;
+import jaris.player.Loop;
+
+/**
+ * Main jaris player starting point
+ */
+class Main
+{
+ static var stage:Stage;
+ static var movieClip:MovieClip;
+
+ static function main():Void
+ {
+ //Initialize stage and main movie clip
+ stage = Lib.current.stage;
+ movieClip = Lib.current;
+
+ stage.scaleMode = StageScaleMode.NO_SCALE;
+ stage.align = StageAlign.TOP_LEFT;
+
+ //Retrieve user settings
+ var userSettings:UserSettings = new UserSettings();
+
+ //Reads flash vars
+ var parameters:Dynamic = flash.Lib.current.loaderInfo.parameters;
+
+ //Initialize and draw player object
+ var player:Player = new Player();
+ if (Capabilities.playerType == "PlugIn" || Capabilities.playerType == "ActiveX")
+ {
+ var autoStart:Bool = parameters.autostart == "true" || parameters.autostart == "" || parameters.autostart == null? true: false;
+ var type:String = parameters.type != "" && parameters.type != null? parameters.type : InputType.VIDEO;
+ var streamType:String = parameters.streamtype != "" && parameters.streamtype != null? parameters.streamtype : StreamType.FILE;
+ var server:String = parameters.server != "" && parameters.server != null? parameters.server : "";
+ var aspectRatio:String = parameters.aspectratio != "" && parameters.aspectratio != null? parameters.aspectratio : "";
+ var bufferTime:Float = parameters.buffertime != "" && parameters.buffertime != null? Std.parseFloat(parameters.buffertime) : 0;
+
+ if (aspectRatio != "" && !userSettings.isSet("aspectratio"))
+ {
+ switch(aspectRatio)
+ {
+ case "1:1":
+ player.setAspectRatio(AspectRatio._1_1);
+ case "3:2":
+ player.setAspectRatio(AspectRatio._3_2);
+ case "4:3":
+ player.setAspectRatio(AspectRatio._4_3);
+ case "5:4":
+ player.setAspectRatio(AspectRatio._5_4);
+ case "14:9":
+ player.setAspectRatio(AspectRatio._14_9);
+ case "14:10":
+ player.setAspectRatio(AspectRatio._14_10);
+ case "16:9":
+ player.setAspectRatio(AspectRatio._16_9);
+ case "16:10":
+ player.setAspectRatio(AspectRatio._16_10);
+ }
+ }
+ else if(userSettings.isSet("aspectratio"))
+ {
+ player.setAspectRatio(userSettings.getAspectRatio());
+ }
+
+ player.setType(type);
+ player.setStreamType(streamType);
+ player.setServer(server);
+ player.setVolume(userSettings.getVolume());
+ player.setBufferTime(bufferTime);
+
+ if (autoStart)
+ {
+ player.load(parameters.source, type, streamType, server);
+ }
+ else
+ {
+ player.setSource(parameters.source);
+ }
+
+ player.setHardwareScaling(parameters.hardwarescaling=="true"?true:false);
+ }
+ else
+ {
+ //For development purposes
+ if(userSettings.isSet("aspectratio"))
+ {
+ player.setAspectRatio(userSettings.getAspectRatio());
+ }
+
+ player.setVolume(userSettings.getVolume());
+
+ player.load("http://jaris.sourceforge.net/files/jaris-intro.flv", InputType.VIDEO, StreamType.FILE);
+ //player.load("http://jaris.sourceforge.net/files/audio.mp3", InputType.AUDIO, StreamType.FILE);
+ }
+
+ //Draw preview image
+ if (parameters.poster != null)
+ {
+ var poster:String = parameters.poster;
+ var posterImage = new Poster(poster);
+ posterImage.setPlayer(player);
+ movieClip.addChild(posterImage);
+ }
+
+ //Modify Context Menu
+ var menu:Menu = new Menu(player);
+
+ //Draw logo
+ if (parameters.logo!=null)
+ {
+ var logoSource:String = parameters.logo != null ? parameters.logo : "logo.png";
+ var logoPosition:String = parameters.logoposition != null ? parameters.logoposition : "top left";
+ var logoAlpha:Float = parameters.logoalpha != null ? Std.parseFloat(parameters.logoalpha) / 100 : 0.3;
+ var logoWidth:Float = parameters.logowidth != null ? Std.parseFloat(parameters.logowidth) : 130;
+ var logoLink:String = parameters.logolink != null ? parameters.logolink : "http://jaris.sourceforge.net";
+
+ var logo:Logo = new Logo(logoSource, logoPosition, logoAlpha, logoWidth);
+ logo.setLink(logoLink);
+ movieClip.addChild(logo);
+ }
+
+ //Draw Controls
+ if (parameters.controls != "false")
+ {
+ var duration:String = parameters.duration != "" && parameters.duration != null? parameters.duration : "0";
+ var controlType:Int = parameters.controltype != "" && parameters.controltype != null? Std.parseInt(parameters.controltype) : 0;
+ var controlSize:Int = parameters.controlsize != "" && parameters.controlsize != null? Std.parseInt(parameters.controlsize) : 0;
+
+ var controlColors:Array = ["", "", "", "", ""];
+ controlColors[0] = parameters.darkcolor != null ? parameters.darkcolor : "";
+ controlColors[1] = parameters.brightcolor != null ? parameters.brightcolor : "";
+ controlColors[2] = parameters.controlcolor != null ? parameters.controlcolor : "";
+ controlColors[3] = parameters.hovercolor != null ? parameters.hovercolor : "";
+ controlColors[4] = parameters.seekcolor != null ? parameters.seekcolor : "";
+
+ if (controlType == 1) {
+ var controls:NewControls = new NewControls(player);
+ controls.setDurationLabel(duration);
+ controls.setControlColors(controlColors);
+ controls.setControlSize(controlSize);
+ movieClip.addChild(controls);
+ } else {
+ var controls:Controls = new Controls(player);
+ controls.setDurationLabel(duration);
+ controls.setControlColors(controlColors);
+ movieClip.addChild(controls);
+ }
+ }
+
+ //Loop the video
+ if (parameters.loop != null)
+ {
+ var loop:Loop = new Loop(player);
+ }
+
+ //Expose events to javascript functions and enable controlling the player from the outside
+ if (parameters.jsapi != null)
+ {
+ var jsAPI:JsApi = new JsApi(player);
+ movieClip.addChild(jsAPI);
+ }
+ }
+}
\ No newline at end of file
diff --git a/lib/Jaris/src/jaris/Version.hx b/lib/Jaris/src/jaris/Version.hx
new file mode 100644
index 00000000..b3b852da
--- /dev/null
+++ b/lib/Jaris/src/jaris/Version.hx
@@ -0,0 +1,35 @@
+/**
+ * @author Jefferson González
+ * @copyright 2010 Jefferson González
+ *
+ * @license
+ * This file is part of Jaris FLV Player.
+ *
+ * Jaris FLV Player is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License or GNU LESSER GENERAL
+ * PUBLIC LICENSE as published by the Free Software Foundation, either version
+ * 3 of the License, or (at your option) any later version.
+ *
+ * Jaris FLV Player is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License and
+ * GNU LESSER GENERAL PUBLIC LICENSE along with Jaris FLV Player. If not,
+ * see .
+ */
+
+package jaris;
+
+/**
+ * Actual jaris flv player version and date
+ */
+class Version
+{
+ public static var NUMBER:String = "2.0.15";
+ public static var STATUS:String = "beta";
+ public static var DATE:String = "27";
+ public static var MONTH:String = "08";
+ public static var YEAR:String = "2011";
+}
\ No newline at end of file
diff --git a/lib/Jaris/src/jaris/animation/Animation.hx b/lib/Jaris/src/jaris/animation/Animation.hx
new file mode 100644
index 00000000..91cf60bd
--- /dev/null
+++ b/lib/Jaris/src/jaris/animation/Animation.hx
@@ -0,0 +1,77 @@
+/**
+ * @author Jefferson González
+ * @copyright 2010 Jefferson González
+ *
+ * @license
+ * This file is part of Jaris FLV Player.
+ *
+ * Jaris FLV Player is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License or GNU LESSER GENERAL
+ * PUBLIC LICENSE as published by the Free Software Foundation, either version
+ * 3 of the License, or (at your option) any later version.
+ *
+ * Jaris FLV Player is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License and
+ * GNU LESSER GENERAL PUBLIC LICENSE along with Jaris FLV Player. If not,
+ * see .
+ */
+
+package jaris.animation;
+
+/**
+ * Gives quick access usage to jaris animations
+ */
+class Animation
+{
+
+ /**
+ * Quick access to fade in effect
+ * @param object the object to animate
+ * @param seconds the duration of the animation
+ */
+ public static function fadeIn(object:Dynamic, seconds:Float):Void
+ {
+ var animation:AnimationsBase = new AnimationsBase();
+ animation.fadeIn(object, seconds);
+ }
+
+ /**
+ * Quick access to fade out effect
+ * @param object the object to animate
+ * @param seconds the duration of the animation
+ */
+ public static function fadeOut(object:Dynamic, seconds:Float):Void
+ {
+ var animation:AnimationsBase = new AnimationsBase();
+ animation.fadeOut(object, seconds);
+ }
+
+ /**
+ * Quick access to slide in effect
+ * @param object the object to animate
+ * @param position could be top, left, bottom or right
+ * @param seconds the duration of the animation
+ */
+ public static function slideIn(object:Dynamic, position:String, seconds:Float):Void
+ {
+ var animation:AnimationsBase = new AnimationsBase();
+ animation.slideIn(object, position, seconds);
+ }
+
+ /**
+ * Quick access to slide out effect
+ * @param object the object to animate
+ * @param position could be top, left, bottom or right
+ * @param seconds the duration of the animation
+ */
+ public static function slideOut(object:Dynamic, position:String, seconds:Float):Void
+ {
+ var animation:AnimationsBase = new AnimationsBase();
+ animation.slideOut(object, position, seconds);
+ }
+
+}
\ No newline at end of file
diff --git a/lib/Jaris/src/jaris/animation/AnimationsBase.hx b/lib/Jaris/src/jaris/animation/AnimationsBase.hx
new file mode 100644
index 00000000..8f0aebc5
--- /dev/null
+++ b/lib/Jaris/src/jaris/animation/AnimationsBase.hx
@@ -0,0 +1,306 @@
+/**
+ * @author Jefferson González
+ * @copyright 2010 Jefferson González
+ *
+ * @license
+ * This file is part of Jaris FLV Player.
+ *
+ * Jaris FLV Player is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License or GNU LESSER GENERAL
+ * PUBLIC LICENSE as published by the Free Software Foundation, either version
+ * 3 of the License, or (at your option) any later version.
+ *
+ * Jaris FLV Player is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License and
+ * GNU LESSER GENERAL PUBLIC LICENSE along with Jaris FLV Player. If not,
+ * see .
+ */
+
+package jaris.animation;
+
+import flash.display.MovieClip;
+import flash.display.Stage;
+import flash.events.TimerEvent;
+import flash.Lib;
+import flash.utils.Timer;
+
+/**
+ * Jaris main animations
+ */
+class AnimationsBase
+{
+ private var _fadeInTimer:Timer;
+ private var _fadeOutTimer:Timer;
+
+ private var _slideInTimer:Timer;
+ private var _slideInOrigX:Float;
+ private var _slideInOrigY:Float;
+ private var _slideInPosition:String;
+ private var _slideInIncrements:Float;
+
+ private var _slideOutTimer:Timer;
+ private var _slideOutOrigX:Float;
+ private var _slideOutOrigY:Float;
+ private var _slideOutPosition:String;
+ private var _slideOutIncrements:Float;
+
+ private var _stage:Stage;
+ private var _movieClip:MovieClip;
+
+
+ private var _currentObject:Dynamic;
+
+ public function new()
+ {
+ _stage = Lib.current.stage;
+ _movieClip = Lib.current;
+ }
+
+ /**
+ * Moves an object until is shown
+ * @param event
+ */
+ private function slideInTimer(event:TimerEvent):Void
+ {
+ var last:Bool = false;
+ switch(_slideInPosition)
+ {
+ case "top":
+ if (_currentObject.y >= _slideInOrigY) { last = true; }
+ _currentObject.y += _slideInIncrements;
+
+ case "left":
+ if (_currentObject.x >= _slideInOrigX) { last = true; }
+ _currentObject.x += _slideInIncrements;
+
+ case "bottom":
+ if (_currentObject.y <= _slideInOrigY) { last = true; }
+ _currentObject.y -= _slideInIncrements;
+
+ case "right":
+ if (_currentObject.x <= _slideInOrigX) { last = true; }
+ _currentObject.x -= _slideInIncrements;
+ }
+
+ if (last)
+ {
+ _currentObject.x = _slideInOrigX;
+ _currentObject.y = _slideInOrigY;
+ _slideInTimer.stop();
+ }
+ }
+
+ /**
+ * Moves an object until is hidden
+ * @param event
+ */
+ private function slideOutTimer(event:TimerEvent):Void
+ {
+ if (((_currentObject.x + _currentObject.width) < 0) || (_currentObject.y + _currentObject.height < 0))
+ {
+ _currentObject.visible = false;
+ _currentObject.x = _slideOutOrigX;
+ _currentObject.y = _slideOutOrigY;
+
+ _slideOutTimer.stop();
+ }
+ else if (((_currentObject.x) > _stage.stageWidth) || (_currentObject.y > _stage.stageHeight))
+ {
+ _currentObject.visible = false;
+ _currentObject.x = _slideOutOrigX;
+ _currentObject.y = _slideOutOrigY;
+
+ _slideOutTimer.stop();
+ }
+ else
+ {
+ switch(_slideOutPosition)
+ {
+ case "top":
+ _currentObject.y -= _slideOutIncrements;
+
+ case "left":
+ _currentObject.x -= _slideOutIncrements;
+
+ case "bottom":
+ _currentObject.y += _slideOutIncrements;
+
+ case "right":
+ _currentObject.x += _slideOutIncrements;
+ }
+ }
+ }
+
+ /**
+ * Lower object transparency until not visible
+ * @param event
+ */
+ private function fadeOutTimer(event:TimerEvent):Void
+ {
+ if (_currentObject.alpha > 0)
+ {
+ _currentObject.alpha -= 1 / 10;
+ }
+ else
+ {
+ _currentObject.visible = false;
+ _fadeOutTimer.stop();
+ }
+ }
+
+ /**
+ * Highers object transparency until visible
+ * @param event
+ */
+ private function fadeInTimer(event:TimerEvent):Void
+ {
+ if (_currentObject.alpha < 1)
+ {
+ _currentObject.alpha += 1 / 10;
+ }
+ else
+ {
+ _fadeInTimer.stop();
+ }
+ }
+
+ /**
+ * Effect that moves an object into stage
+ * @param object the element to move
+ * @param slidePosition could be top, left bottom or right
+ * @param speed the time in seconds for duration of the animation
+ */
+ public function slideIn(object:Dynamic, slidePosition:String, speed:Float=1000):Void
+ {
+ if (object.visible)
+ {
+ object.visible = false;
+ }
+
+ _slideInOrigX = object.x;
+ _slideInOrigY = object.y;
+ _slideInPosition = slidePosition;
+
+ var increments:Float = 0;
+
+ switch(slidePosition)
+ {
+ case "top":
+ object.y = 0 - object.height;
+ increments = object.height + _slideInOrigY;
+
+ case "left":
+ object.x = 0 - object.width;
+ increments = object.width + _slideInOrigX;
+
+ case "bottom":
+ object.y = _stage.stageHeight;
+ increments = _stage.stageHeight - _slideInOrigY;
+
+ case "right":
+ object.x = _stage.stageWidth;
+ increments = _stage.stageWidth - _slideInOrigX;
+ }
+
+ _slideInIncrements = increments / (speed / 100);
+
+ _currentObject = object;
+ _currentObject.visible = true;
+ _currentObject.alpha = 1;
+
+ _slideInTimer = new Timer(speed / 100);
+ _slideInTimer.addEventListener(TimerEvent.TIMER, slideInTimer);
+ _slideInTimer.start();
+ }
+
+ /**
+ * Effect that moves an object out of stage
+ * @param object the element to move
+ * @param slidePosition could be top, left bottom or right
+ * @param speed the time in seconds for duration of the animation
+ */
+ public function slideOut(object:Dynamic, slidePosition:String, speed:Float=1000):Void
+ {
+ if (!object.visible)
+ {
+ object.visible = true;
+ }
+
+ _slideOutOrigX = object.x;
+ _slideOutOrigY = object.y;
+ _slideOutPosition = slidePosition;
+
+ var increments:Float = 0;
+
+ switch(slidePosition)
+ {
+ case "top":
+ increments = object.height + _slideOutOrigY;
+
+ case "left":
+ increments = object.width + _slideOutOrigX;
+
+ case "bottom":
+ increments = _stage.stageHeight - _slideOutOrigY;
+
+ case "right":
+ increments = _stage.stageWidth - _slideOutOrigX;
+ }
+
+ _slideOutIncrements = increments / (speed / 100);
+
+ _currentObject = object;
+ _currentObject.visible = true;
+ _currentObject.alpha = 1;
+
+ _slideOutTimer = new Timer(speed / 100);
+ _slideOutTimer.addEventListener(TimerEvent.TIMER, slideOutTimer);
+ _slideOutTimer.start();
+ }
+
+ /**
+ * Effect that dissapears an object from stage
+ * @param object the element to dissapear
+ * @param speed the time in seconds for the duration of the animation
+ */
+ public function fadeOut(object:Dynamic, speed:Float=500):Void
+ {
+ if (!object.visible)
+ {
+ object.visible = true;
+ }
+
+ object.alpha = 1;
+ _currentObject = object;
+
+ _fadeOutTimer = new Timer(speed / 10);
+ _fadeOutTimer.addEventListener(TimerEvent.TIMER, fadeOutTimer);
+ _fadeOutTimer.start();
+ }
+
+ /**
+ * Effect that shows a hidden object an in stage
+ * @param object the element to show
+ * @param speed the time in seconds for the duration of the animation
+ */
+ public function fadeIn(object:Dynamic, speed:Float=500):Void
+ {
+ if (object.visible)
+ {
+ object.visible = false;
+ }
+
+ object.alpha = 0;
+ _currentObject = object;
+ _currentObject.visible = true;
+
+ _fadeInTimer = new Timer(speed / 10);
+ _fadeInTimer.addEventListener(TimerEvent.TIMER, fadeInTimer);
+ _fadeInTimer.start();
+ }
+
+}
\ No newline at end of file
diff --git a/lib/Jaris/src/jaris/display/Loader.hx b/lib/Jaris/src/jaris/display/Loader.hx
new file mode 100644
index 00000000..3a309b4d
--- /dev/null
+++ b/lib/Jaris/src/jaris/display/Loader.hx
@@ -0,0 +1,181 @@
+/**
+ * @author Jefferson González
+ * @copyright 2010 Jefferson González
+ *
+ * @license
+ * This file is part of Jaris FLV Player.
+ *
+ * Jaris FLV Player is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License or GNU LESSER GENERAL
+ * PUBLIC LICENSE as published by the Free Software Foundation, either version
+ * 3 of the License, or (at your option) any later version.
+ *
+ * Jaris FLV Player is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License and
+ * GNU LESSER GENERAL PUBLIC LICENSE along with Jaris FLV Player. If not,
+ * see .
+ */
+
+package jaris.display;
+
+import flash.display.MovieClip;
+import flash.display.Sprite;
+import flash.display.Stage;
+import flash.events.Event;
+import flash.Lib;
+
+/**
+ * Draws a loading bar
+ */
+class Loader extends Sprite
+{
+ private var _stage:Stage;
+ private var _movieClip:MovieClip;
+ private var _background:Sprite;
+ private var _loaderTrack:Sprite;
+ private var _loaderThumb:Sprite;
+ private var _visible:Bool;
+ private var _brightColor:UInt;
+ private var _controlColor:UInt;
+ private var _forward:Bool;
+
+ public function new()
+ {
+ super();
+
+ _stage = Lib.current.stage;
+ _movieClip = Lib.current;
+
+ _background = new Sprite();
+ addChild(_background);
+
+ _loaderTrack = new Sprite();
+ addChild(_loaderTrack);
+
+ _loaderThumb = new Sprite();
+ addChild(_loaderThumb);
+
+ _brightColor = 0x4c4c4c;
+ _controlColor = 0xFFFFFF;
+
+ _forward = true;
+ _visible = true;
+
+ addEventListener(Event.ENTER_FRAME, onEnterFrame);
+ _stage.addEventListener(Event.RESIZE, onResize);
+
+ drawLoader();
+ }
+
+ /**
+ * Animation of a thumb moving on the track
+ * @param event
+ */
+ private function onEnterFrame(event:Event):Void
+ {
+ if (_visible)
+ {
+ if (_forward)
+ {
+ if ((_loaderThumb.x + _loaderThumb.width) >= (_loaderTrack.x + _loaderTrack.width))
+ {
+ _forward = false;
+ }
+ else
+ {
+ _loaderThumb.x += 10;
+ }
+ }
+ else
+ {
+ if (_loaderThumb.x <= _loaderTrack.x)
+ {
+ _forward = true;
+ }
+ else
+ {
+ _loaderThumb.x -= 10;
+ }
+ }
+ }
+ }
+
+ /**
+ * Redraws the loader to match new stage size
+ * @param event
+ */
+ private function onResize(event:Event):Void
+ {
+ drawLoader();
+ }
+
+ /**
+ * Draw loader graphics
+ */
+ private function drawLoader():Void
+ {
+ //Clear graphics
+ _background.graphics.clear();
+ _loaderTrack.graphics.clear();
+ _loaderThumb.graphics.clear();
+
+ //Draw background
+ var backgroundWidth:Float = (65 / 100) * _stage.stageWidth;
+ var backgroundHeight:Float = 30;
+ _background.x = (_stage.stageWidth / 2) - (backgroundWidth / 2);
+ _background.y = (_stage.stageHeight / 2) - (backgroundHeight / 2);
+ _background.graphics.lineStyle();
+ _background.graphics.beginFill(_brightColor, 0.5);
+ _background.graphics.drawRoundRect(0, 0, backgroundWidth, backgroundHeight, 6, 6);
+ _background.graphics.endFill();
+
+ //Draw track
+ var trackWidth:Float = (50 / 100) * _stage.stageWidth;
+ var trackHeight:Float = 15;
+ _loaderTrack.x = (_stage.stageWidth / 2) - (trackWidth / 2);
+ _loaderTrack.y = (_stage.stageHeight / 2) - (trackHeight / 2);
+ _loaderTrack.graphics.lineStyle(2, _controlColor);
+ _loaderTrack.graphics.drawRect(0, 0, trackWidth, trackHeight);
+
+ //Draw thumb
+ _loaderThumb.x = _loaderTrack.x;
+ _loaderThumb.y = _loaderTrack.y;
+ _loaderThumb.graphics.lineStyle();
+ _loaderThumb.graphics.beginFill(_controlColor, 1);
+ _loaderThumb.graphics.drawRect(0, 0, trackHeight, trackHeight);
+ }
+
+ /**
+ * Stops drawing the loader
+ */
+ public function hide():Void
+ {
+ this.visible = false;
+ _visible = false;
+ }
+
+ /**
+ * Starts drawing the loader
+ */
+ public function show():Void
+ {
+ this.visible = true;
+ _visible = true;
+ }
+
+ /**
+ * Set loader colors
+ * @param colors
+ */
+ public function setColors(colors:Array):Void
+ {
+ _brightColor = colors[0].length > 0? Std.parseInt("0x" + colors[0]) : 0x4c4c4c;
+ _controlColor = colors[1].length > 0? Std.parseInt("0x" + colors[1]) : 0xFFFFFF;
+
+ drawLoader();
+ }
+}
\ No newline at end of file
diff --git a/lib/Jaris/src/jaris/display/Logo.hx b/lib/Jaris/src/jaris/display/Logo.hx
new file mode 100644
index 00000000..48e66c54
--- /dev/null
+++ b/lib/Jaris/src/jaris/display/Logo.hx
@@ -0,0 +1,185 @@
+/**
+ * @author Jefferson González
+ * @copyright 2010 Jefferson González
+ *
+ * @license
+ * This file is part of Jaris FLV Player.
+ *
+ * Jaris FLV Player is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License or GNU LESSER GENERAL
+ * PUBLIC LICENSE as published by the Free Software Foundation, either version
+ * 3 of the License, or (at your option) any later version.
+ *
+ * Jaris FLV Player is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License and
+ * GNU LESSER GENERAL PUBLIC LICENSE along with Jaris FLV Player. If not,
+ * see .
+ */
+
+package jaris.display;
+
+import flash.display.Loader;
+import flash.display.MovieClip;
+import flash.display.Sprite;
+import flash.display.Stage;
+import flash.events.Event;
+import flash.events.IOErrorEvent;
+import flash.events.MouseEvent;
+import flash.Lib;
+import flash.net.URLRequest;
+
+/**
+ * To display an image in jpg, png or gif format as logo
+ */
+class Logo extends Sprite
+{
+ private var _stage:Stage;
+ private var _movieClip:MovieClip;
+ private var _loader:Loader;
+ private var _position:String;
+ private var _alpha:Float;
+ private var _source:String;
+ private var _width:Float;
+ private var _link:String;
+ private var _loading:Bool;
+
+ public function new(source:String, position:String, alpha:Float, width:Float=0.0)
+ {
+ super();
+
+ _stage = Lib.current.stage;
+ _movieClip = Lib.current;
+ _loader = new Loader();
+ _position = position;
+ _alpha = alpha;
+ _source = source;
+ _width = width;
+ _loading = true;
+
+ this.tabEnabled = false;
+
+ _loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderComplete);
+ _loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onNotLoaded);
+ _loader.load(new URLRequest(source));
+ }
+
+ /**
+ * Triggers when the logo image could not be loaded
+ * @param event
+ */
+ private function onNotLoaded(event:IOErrorEvent):Void
+ {
+ //Image not loaded
+ }
+
+ /**
+ * Triggers when the logo image finished loading.
+ * @param event
+ */
+ private function onLoaderComplete(event:Event):Void
+ {
+ addChild(_loader);
+
+ setWidth(_width);
+ setPosition(_position);
+ setAlpha(_alpha);
+ _loading = false;
+
+ _stage.addEventListener(Event.RESIZE, onStageResize);
+ }
+
+ /**
+ * Recalculate logo position on stage resize
+ * @param event
+ */
+ private function onStageResize(event:Event):Void
+ {
+ setPosition(_position);
+ }
+
+ /**
+ * Opens the an url when the logo is clicked
+ * @param event
+ */
+ private function onLogoClick(event:MouseEvent):Void
+ {
+ Lib.getURL(new URLRequest(_link), "_blank");
+ }
+
+ /**
+ * Position where logo will be showing
+ * @param position values could be top left, top right, bottom left, bottom right
+ */
+ public function setPosition(position:String):Void
+ {
+ switch(position)
+ {
+ case "top left":
+ this.x = 25;
+ this.y = 25;
+
+ case "top right":
+ this.x = _stage.stageWidth - this._width - 25;
+ this.y = 25;
+
+ case "bottom left":
+ this.x = 25;
+ this.y = _stage.stageHeight - this.height - 25;
+
+ case "bottom right":
+ this.x = _stage.stageWidth - this.width - 25;
+ this.y = _stage.stageHeight - this.height - 25;
+
+ default:
+ this.x = 25;
+ this.y = 25;
+ }
+ }
+
+ /**
+ * To set logo transparency
+ * @param alpha
+ */
+ public function setAlpha(alpha:Float):Void
+ {
+ this.alpha = alpha;
+ }
+
+ /**
+ * Sets logo width and recalculates height keeping aspect ratio
+ * @param width
+ */
+ public function setWidth(width:Float):Void
+ {
+ if (width > 0)
+ {
+ this.height = (this.height / this.width) * width;
+ this.width = width;
+ }
+ }
+
+ /**
+ * Link that opens when clicked the logo image is clicked
+ * @param link
+ */
+ public function setLink(link:String):Void
+ {
+ _link = link;
+ this.buttonMode = true;
+ this.useHandCursor = true;
+ this.addEventListener(MouseEvent.CLICK, onLogoClick);
+ }
+
+ /**
+ * To check if the logo stills loading
+ * @return true if loading false otherwise
+ */
+ public function isLoading():Bool
+ {
+ return _loading;
+ }
+}
\ No newline at end of file
diff --git a/lib/Jaris/src/jaris/display/Menu.hx b/lib/Jaris/src/jaris/display/Menu.hx
new file mode 100644
index 00000000..39d0a849
--- /dev/null
+++ b/lib/Jaris/src/jaris/display/Menu.hx
@@ -0,0 +1,246 @@
+/**
+ * @author Jefferson González
+ * @copyright 2010 Jefferson González
+ *
+ * @license
+ * This file is part of Jaris FLV Player.
+ *
+ * Jaris FLV Player is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License or GNU LESSER GENERAL
+ * PUBLIC LICENSE as published by the Free Software Foundation, either version
+ * 3 of the License, or (at your option) any later version.
+ *
+ * Jaris FLV Player is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License and
+ * GNU LESSER GENERAL PUBLIC LICENSE along with Jaris FLV Player. If not,
+ * see .
+ */
+
+package jaris.display;
+import flash.display.MovieClip;
+import flash.events.ContextMenuEvent;
+import flash.Lib;
+import flash.net.URLRequest;
+import flash.ui.ContextMenu;
+import flash.ui.ContextMenuItem;
+import jaris.player.Player;
+import jaris.player.AspectRatio;
+import jaris.Version;
+
+/**
+ * Modify original context menu
+ */
+class Menu
+{
+ private var _movieClip:MovieClip;
+ public static var _player:Player;
+
+ private var _contextMenu:ContextMenu;
+ private var _jarisVersionMenuItem:ContextMenuItem;
+ private var _playMenuItem:ContextMenuItem;
+ private var _fullscreenMenuItem:ContextMenuItem;
+ private var _aspectRatioMenuItem:ContextMenuItem;
+ private var _muteMenuItem:ContextMenuItem;
+ private var _volumeUpMenuItem:ContextMenuItem;
+ private var _volumeDownMenuItem:ContextMenuItem;
+ private var _qualityContextMenu:ContextMenuItem;
+
+ public function new(player:Player)
+ {
+ _movieClip = Lib.current;
+ _player = player;
+
+ //Initialize context menu replacement
+ _contextMenu = new ContextMenu();
+ _contextMenu.hideBuiltInItems();
+
+ _contextMenu.addEventListener(ContextMenuEvent.MENU_SELECT, onMenuOpen);
+
+ //Initialize each menu item
+ _jarisVersionMenuItem = new ContextMenuItem("Jaris Player v" + Version.NUMBER + " " + Version.STATUS, true, true, true);
+ _jarisVersionMenuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, onJarisVersion);
+
+ _playMenuItem = new ContextMenuItem("Play (SPACE)", true, true, true);
+ _playMenuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, onPlay);
+
+ _fullscreenMenuItem = new ContextMenuItem("Fullscreen View (F)");
+ _fullscreenMenuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, onFullscreen);
+
+ _aspectRatioMenuItem = new ContextMenuItem("Aspect Ratio (original) (TAB)");
+ _aspectRatioMenuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, onAspectRatio);
+
+ _muteMenuItem = new ContextMenuItem("Mute (M)");
+ _muteMenuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, onMute);
+
+ _volumeUpMenuItem = new ContextMenuItem("Volume + (arrow UP)");
+ _volumeUpMenuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, onVolumeUp);
+
+ _volumeDownMenuItem = new ContextMenuItem("Volume - (arrow DOWN)");
+ _volumeDownMenuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, onVolumeDown);
+
+ _qualityContextMenu = new ContextMenuItem("Lower Quality", true, true, true);
+ _qualityContextMenu.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, onQuality);
+
+ //add all context menu items to context menu object
+ _contextMenu.customItems.push(_jarisVersionMenuItem);
+ _contextMenu.customItems.push(_playMenuItem);
+ _contextMenu.customItems.push(_fullscreenMenuItem);
+ _contextMenu.customItems.push(_aspectRatioMenuItem);
+ _contextMenu.customItems.push(_muteMenuItem);
+ _contextMenu.customItems.push(_volumeUpMenuItem);
+ _contextMenu.customItems.push(_volumeDownMenuItem);
+ _contextMenu.customItems.push(_qualityContextMenu);
+
+ //override default context menu
+ _movieClip.contextMenu = _contextMenu;
+ }
+
+ /**
+ * Update context menu item captions depending on player status before showing them
+ * @param event
+ */
+ private function onMenuOpen(event:ContextMenuEvent):Void
+ {
+ if (_player.isPlaying())
+ {
+ _playMenuItem.caption = "Pause (SPACE)";
+ }
+ else
+ {
+ _playMenuItem.caption = "Play (SPACE)";
+ }
+
+ if (_player.isFullscreen())
+ {
+ _fullscreenMenuItem.caption = "Normal View";
+ }
+ else
+ {
+ _fullscreenMenuItem.caption = "Fullscreen View (F)";
+ }
+
+ if (_player.getMute())
+ {
+ _muteMenuItem.caption = _player.isFullscreen()?"Unmute":"Unmute (M)";
+ }
+ else
+ {
+ _muteMenuItem.caption = _player.isFullscreen()?"Mute":"Mute (M)";
+ }
+
+ switch(_player.getAspectRatioString())
+ {
+ case "original":
+ _aspectRatioMenuItem.caption = "Aspect Ratio (1:1) (TAB)";
+
+ case "1:1":
+ _aspectRatioMenuItem.caption = "Aspect Ratio (3:2) (TAB)";
+
+ case "3:2":
+ _aspectRatioMenuItem.caption = "Aspect Ratio (4:3) (TAB)";
+
+ case "4:3":
+ _aspectRatioMenuItem.caption = "Aspect Ratio (5:4) (TAB)";
+
+ case "5:4":
+ _aspectRatioMenuItem.caption = "Aspect Ratio (14:9) (TAB)";
+
+ case "14:9":
+ _aspectRatioMenuItem.caption = "Aspect Ratio (14:10) (TAB)";
+
+ case "14:10":
+ _aspectRatioMenuItem.caption = "Aspect Ratio (16:9) (TAB)";
+
+ case "16:9":
+ _aspectRatioMenuItem.caption = "Aspect Ratio (16:10) (TAB)";
+
+ case "16:10":
+ _aspectRatioMenuItem.caption = "Aspect Ratio (original) (TAB)";
+ }
+
+ if (_player.getQuality())
+ {
+ _qualityContextMenu.caption = "Lower Quality";
+ }
+ else
+ {
+ _qualityContextMenu.caption = "Higher Quality";
+ }
+ }
+
+ /**
+ * Open jaris player website
+ * @param event
+ */
+ private function onJarisVersion(event:ContextMenuEvent)
+ {
+ Lib.getURL(new URLRequest("http://jaris.sourceforge.net"), "_blank");
+ }
+
+ /**
+ * Toggles playback
+ * @param event
+ */
+ private function onPlay(event:ContextMenuEvent)
+ {
+ _player.togglePlay();
+ }
+
+ /**
+ * Toggles fullscreen
+ * @param event
+ */
+ private function onFullscreen(event:ContextMenuEvent)
+ {
+ _player.toggleFullscreen();
+ }
+
+ /**
+ * Toggles aspect ratio
+ * @param event
+ */
+ private function onAspectRatio(event:ContextMenuEvent)
+ {
+ _player.toggleAspectRatio();
+ }
+
+ /**
+ * Toggles mute
+ * @param event
+ */
+ private function onMute(event:ContextMenuEvent)
+ {
+ _player.toggleMute();
+ }
+
+ /**
+ * Raise volume
+ * @param event
+ */
+ private function onVolumeUp(event:ContextMenuEvent)
+ {
+ _player.volumeUp();
+ }
+
+ /**
+ * Lower volume
+ * @param event
+ */
+ private function onVolumeDown(event:ContextMenuEvent)
+ {
+ _player.volumeDown();
+ }
+
+ /**
+ * Toggle video quality
+ * @param event
+ */
+ private function onQuality(event:ContextMenuEvent)
+ {
+ _player.toggleQuality();
+ }
+}
\ No newline at end of file
diff --git a/lib/Jaris/src/jaris/display/Poster.hx b/lib/Jaris/src/jaris/display/Poster.hx
new file mode 100644
index 00000000..4c237468
--- /dev/null
+++ b/lib/Jaris/src/jaris/display/Poster.hx
@@ -0,0 +1,170 @@
+/**
+ * @author Jefferson González
+ * @copyright 2010 Jefferson González
+ *
+ * @license
+ * This file is part of Jaris FLV Player.
+ *
+ * Jaris FLV Player is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License or GNU LESSER GENERAL
+ * PUBLIC LICENSE as published by the Free Software Foundation, either version
+ * 3 of the License, or (at your option) any later version.
+ *
+ * Jaris FLV Player is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License and
+ * GNU LESSER GENERAL PUBLIC LICENSE along with Jaris FLV Player. If not,
+ * see .
+ */
+
+package jaris.display;
+
+import flash.display.DisplayObject;
+import flash.display.Loader;
+import flash.display.MovieClip;
+import flash.display.Sprite;
+import flash.display.Stage;
+import flash.events.Event;
+import flash.events.IOErrorEvent;
+import flash.Lib;
+import flash.net.URLRequest;
+import jaris.events.PlayerEvents;
+import jaris.player.InputType;
+import jaris.player.Player;
+
+/**
+ * To display an png, jpg or gif as preview of video content
+ */
+class Poster extends Sprite
+{
+
+ private var _stage:Stage;
+ private var _movieClip:MovieClip;
+ private var _loader:Loader;
+ private var _source:String;
+ private var _width:Float;
+ private var _height:Float;
+ private var _loading:Bool;
+ private var _loaderStatus:jaris.display.Loader;
+ private var _player:Player;
+
+ public function new(source:String)
+ {
+ super();
+
+ _stage = Lib.current.stage;
+ _movieClip = Lib.current;
+ _loader = new Loader();
+ _source = source;
+ _loading = true;
+
+ //Reads flash vars
+ var parameters:Dynamic = flash.Lib.current.loaderInfo.parameters;
+
+ //Draw Loader status
+ var loaderColors:Array = ["", "", "", ""];
+ loaderColors[0] = parameters.brightcolor != null ? parameters.brightcolor : "";
+ loaderColors[1] = parameters.controlcolor != null ? parameters.controlcolor : "";
+
+ _loaderStatus = new jaris.display.Loader();
+ _loaderStatus.show();
+ _loaderStatus.setColors(loaderColors);
+ addChild(_loaderStatus);
+
+ _loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderComplete);
+ _loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onNotLoaded);
+ _loader.load(new URLRequest(source));
+ }
+
+ /**
+ * Triggers when the poster image could not be loaded
+ * @param event
+ */
+ private function onNotLoaded(event:IOErrorEvent):Void
+ {
+ _loaderStatus.hide();
+ removeChild(_loaderStatus);
+ }
+
+ /**
+ * Triggers when the poster image finalized loading
+ * @param event
+ */
+ private function onLoaderComplete(event:Event):Void
+ {
+ _loaderStatus.hide();
+ removeChild(_loaderStatus);
+
+ addChild(_loader);
+
+ _width = this.width;
+ _height = this.height;
+ _loading = false;
+
+ _stage.addEventListener(Event.RESIZE, onStageResize);
+
+ resizeImage();
+ }
+
+ /**
+ * Triggers when the stage is resized to resize the poster image
+ * @param event
+ */
+ private function onStageResize(event:Event):Void
+ {
+ resizeImage();
+ }
+
+ private function onPlayerMediaInitialized(event:PlayerEvents)
+ {
+ if (_player.getType() == InputType.VIDEO)
+ {
+ this.visible = false;
+ }
+ }
+
+ private function onPlayerPlay(event:PlayerEvents)
+ {
+ if (_player.getType() == InputType.VIDEO)
+ {
+ this.visible = false;
+ }
+ }
+
+ private function onPlayBackFinished(event:PlayerEvents)
+ {
+ this.visible = true;
+ }
+
+ /**
+ * Resizes the poster image to take all the stage
+ */
+ private function resizeImage():Void
+ {
+ this.height = _stage.stageHeight;
+ this.width = ((_width / _height) * this.height);
+
+ this.x = (_stage.stageWidth / 2) - (this.width / 2);
+ }
+
+ /**
+ * To check if the poster image stills loading
+ * @return true if stills loading false if loaded
+ */
+ public function isLoading():Bool
+ {
+ return _loading;
+ }
+
+ public function setPlayer(player:Player):Void
+ {
+ _player = player;
+ _player.addEventListener(PlayerEvents.MEDIA_INITIALIZED, onPlayerMediaInitialized);
+ _player.addEventListener(PlayerEvents.PLAYBACK_FINISHED, onPlayBackFinished);
+ _player.addEventListener(PlayerEvents.PLAY_PAUSE, onPlayerPlay);
+ }
+
+}
\ No newline at end of file
diff --git a/lib/Jaris/src/jaris/events/PlayerEvents.hx b/lib/Jaris/src/jaris/events/PlayerEvents.hx
new file mode 100644
index 00000000..a2d1edf3
--- /dev/null
+++ b/lib/Jaris/src/jaris/events/PlayerEvents.hx
@@ -0,0 +1,84 @@
+/**
+ * @author Jefferson González
+ * @copyright 2010 Jefferson González
+ *
+ * @license
+ * This file is part of Jaris FLV Player.
+ *
+ * Jaris FLV Player is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License or GNU LESSER GENERAL
+ * PUBLIC LICENSE as published by the Free Software Foundation, either version
+ * 3 of the License, or (at your option) any later version.
+ *
+ * Jaris FLV Player is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License and
+ * GNU LESSER GENERAL PUBLIC LICENSE along with Jaris FLV Player. If not,
+ * see .
+ */
+
+package jaris.events;
+
+import flash.events.Event;
+import flash.media.ID3Info;
+import flash.media.Sound;
+import flash.net.NetStream;
+
+/**
+ * Implements the player events
+ */
+class PlayerEvents extends Event
+{
+ public static var ASPECT_RATIO = "onAspectRatio";
+ public static var MOUSE_SHOW = "onMouseShow";
+ public static var MOUSE_HIDE = "onMouseHide";
+ public static var FULLSCREEN = "onFullscreen";
+ public static var VOLUME_UP = "onVolumeUp";
+ public static var VOLUME_DOWN = "onVolumeDown";
+ public static var VOLUME_CHANGE= "onVolumeChange"; //Nuevo
+ public static var MUTE = "onMute";
+ public static var FORWARD = "onForward";
+ public static var REWIND = "onRewind";
+ public static var PLAY_PAUSE = "onPlayPause";
+ public static var SEEK = "onSeek";
+ public static var TIME = "onTimeUpdate";
+ public static var PROGRESS = "onProgress";
+ public static var BUFFERING = "onBuffering";
+ public static var NOT_BUFFERING = "onNotBuffering";
+ public static var CONNECTION_FAILED = "onConnectionFailed";
+ public static var CONNECTION_SUCCESS = "onConnectionSuccess";
+ public static var MEDIA_INITIALIZED = "onDataInitialized";
+ public static var PLAYBACK_FINISHED = "onPlaybackFinished";
+ public static var STOP_CLOSE = "onStopAndClose";
+ public static var RESIZE = "onResize";
+
+ public var name:String;
+ public var aspectRatio:Float;
+ public var duration:Float;
+ public var fullscreen:Bool;
+ public var mute:Bool;
+ public var volume:Float;
+ public var width:Float;
+ public var height:Float;
+ public var stream:NetStream;
+ public var sound:Sound;
+ public var time:Float;
+ public var id3Info:ID3Info;
+
+ public function new(type:String, bubbles:Bool=false, cancelable:Bool=false)
+ {
+ super(type, bubbles, cancelable);
+
+ fullscreen = false;
+ mute = false;
+ volume = 1.0;
+ duration = 0;
+ width = 0;
+ height = 0;
+ time = 0;
+ name = type;
+ }
+}
\ No newline at end of file
diff --git a/lib/Jaris/src/jaris/player/AspectRatio.hx b/lib/Jaris/src/jaris/player/AspectRatio.hx
new file mode 100644
index 00000000..3b4648ba
--- /dev/null
+++ b/lib/Jaris/src/jaris/player/AspectRatio.hx
@@ -0,0 +1,49 @@
+/**
+ * @author Jefferson González
+ * @copyright 2010 Jefferson González
+ *
+ * @license
+ * This file is part of Jaris FLV Player.
+ *
+ * Jaris FLV Player is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License or GNU LESSER GENERAL
+ * PUBLIC LICENSE as published by the Free Software Foundation, either version
+ * 3 of the License, or (at your option) any later version.
+ *
+ * Jaris FLV Player is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License and
+ * GNU LESSER GENERAL PUBLIC LICENSE along with Jaris FLV Player. If not,
+ * see .
+ */
+
+package jaris.player;
+
+/**
+ * Stores the player used aspect ratio constants
+ */
+class AspectRatio
+{
+ public static var _1_1:Float = 1 / 1;
+ public static var _3_2:Float = 3 / 2;
+ public static var _4_3:Float = 4 / 3;
+ public static var _5_4:Float = 5 / 4;
+ public static var _14_9:Float = 14 / 9;
+ public static var _14_10:Float = 14 / 10;
+ public static var _16_9:Float = 16 / 9;
+ public static var _16_10:Float = 16 / 10;
+
+ /**
+ * Calculates the ratio for a given width and height
+ * @param width
+ * @param height
+ * @return aspect ratio
+ */
+ public static function getAspectRatio(width:Float, height:Float):Float
+ {
+ return width / height;
+ }
+}
\ No newline at end of file
diff --git a/lib/Jaris/src/jaris/player/InputType.hx b/lib/Jaris/src/jaris/player/InputType.hx
new file mode 100644
index 00000000..e22e502e
--- /dev/null
+++ b/lib/Jaris/src/jaris/player/InputType.hx
@@ -0,0 +1,32 @@
+/**
+ * @author Jefferson González
+ * @copyright 2010 Jefferson González
+ *
+ * @license
+ * This file is part of Jaris FLV Player.
+ *
+ * Jaris FLV Player is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License or GNU LESSER GENERAL
+ * PUBLIC LICENSE as published by the Free Software Foundation, either version
+ * 3 of the License, or (at your option) any later version.
+ *
+ * Jaris FLV Player is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License and
+ * GNU LESSER GENERAL PUBLIC LICENSE along with Jaris FLV Player. If not,
+ * see .
+ */
+
+package jaris.player;
+
+/**
+ * Stores the identifiers for loaded media type
+ */
+class InputType
+{
+ public static var AUDIO = "audio";
+ public static var VIDEO = "video";
+}
\ No newline at end of file
diff --git a/lib/Jaris/src/jaris/player/JsApi.hx b/lib/Jaris/src/jaris/player/JsApi.hx
new file mode 100644
index 00000000..59f72571
--- /dev/null
+++ b/lib/Jaris/src/jaris/player/JsApi.hx
@@ -0,0 +1,232 @@
+/**
+ * @author Sascha Kluger
+ * @copyright 2010 Jefferson González, Sascha Kluger
+ *
+ * @license
+ * This file is part of Jaris FLV Player.
+ *
+ * Jaris FLV Player is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License or GNU LESSER GENERAL
+ * PUBLIC LICENSE as published by the Free Software Foundation, either version
+ * 3 of the License, or (at your option) any later version.
+ *
+ * Jaris FLV Player is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License and
+ * GNU LESSER GENERAL PUBLIC LICENSE along with Jaris FLV Player. If not,
+ * see .
+ */
+
+package jaris.player;
+
+//{Libraries
+import flash.system.Capabilities;
+import flash.system.Security;
+import flash.external.ExternalInterface;
+import flash.display.GradientType;
+import flash.events.Event;
+import flash.events.TimerEvent;
+import flash.geom.Matrix;
+import flash.Lib;
+import flash.events.MouseEvent;
+import flash.display.MovieClip;
+import flash.net.NetStream;
+import flash.geom.Rectangle;
+import flash.net.ObjectEncoding;
+import flash.text.AntiAliasType;
+import flash.text.TextField;
+import flash.text.TextFieldAutoSize;
+import flash.text.TextFormat;
+import flash.utils.Timer;
+import jaris.animation.Animation;
+import jaris.display.Loader;
+import jaris.events.PlayerEvents;
+import jaris.player.controls.AspectRatioIcon;
+import jaris.player.controls.FullscreenIcon;
+import jaris.player.controls.PauseIcon;
+import jaris.player.controls.PlayIcon;
+import jaris.player.controls.VolumeIcon;
+import jaris.player.Player;
+import flash.display.Sprite;
+import flash.display.Stage;
+import jaris.utils.Utils;
+//}
+
+/**
+ * Default controls for jaris player
+ */
+class JsApi extends MovieClip {
+
+ //{Member Variables
+ private var _stage:Stage;
+ private var _movieClip:MovieClip;
+ private var _player:Player;
+ private var _isBuffering:Bool;
+ private var _percentLoaded:Float;
+ private var _externalListeners:Hash;
+
+ //}
+
+
+ //{Constructor
+ public function new(player:Player)
+ {
+ super();
+ _externalListeners = new Hash();
+
+ Security.allowDomain("*");
+
+ //{Main variables
+ // _stage = Lib.current.stage;
+ // _movieClip = Lib.current;
+ _player = player;
+
+ _player.addEventListener(PlayerEvents.MOUSE_HIDE, onPlayerEvent);
+ _player.addEventListener(PlayerEvents.MOUSE_SHOW, onPlayerEvent);
+ _player.addEventListener(PlayerEvents.MEDIA_INITIALIZED, onPlayerEvent);
+ _player.addEventListener(PlayerEvents.BUFFERING, onPlayerEvent);
+ _player.addEventListener(PlayerEvents.NOT_BUFFERING, onPlayerEvent);
+ _player.addEventListener(PlayerEvents.RESIZE, onPlayerEvent);
+ _player.addEventListener(PlayerEvents.PLAY_PAUSE, onPlayerEvent);
+ _player.addEventListener(PlayerEvents.PLAYBACK_FINISHED, onPlayerEvent);
+ _player.addEventListener(PlayerEvents.CONNECTION_FAILED, onPlayerEvent);
+ _player.addEventListener(PlayerEvents.ASPECT_RATIO, onPlayerEvent);
+ _player.addEventListener(PlayerEvents.VOLUME_UP, onPlayerEvent);
+ _player.addEventListener(PlayerEvents.VOLUME_DOWN, onPlayerEvent);
+ _player.addEventListener(PlayerEvents.VOLUME_CHANGE, onPlayerEvent);
+ _player.addEventListener(PlayerEvents.MUTE, onPlayerEvent);
+ _player.addEventListener(PlayerEvents.TIME, onPlayerEvent);
+ _player.addEventListener(PlayerEvents.PROGRESS, onPlayerEvent);
+ _player.addEventListener(PlayerEvents.SEEK, onPlayerEvent);
+
+ ExternalInterface.addCallback("api_get", getAttribute);
+ ExternalInterface.addCallback("api_addlistener", addJsListener);
+ ExternalInterface.addCallback("api_removelistener", removeJsListener);
+ ExternalInterface.addCallback("api_play", setPlay);
+ ExternalInterface.addCallback("api_pause", setPause);
+ ExternalInterface.addCallback("api_seek", setSeek);
+ ExternalInterface.addCallback("api_volume", setVolume);
+
+
+ }
+
+ public function getAttribute(attribute:String):Float {
+
+ switch (attribute) {
+ case 'isBuffering':
+ return (_isBuffering) ? 1 : 0;
+
+ case 'isPlaying':
+ return (_player.isPlaying()) ? 1 : 0;
+
+ case 'time':
+ return Math.round(_player.getCurrentTime() * 10) / 10;
+
+ case 'loaded':
+ return _player.getBytesLoaded();
+
+ case 'volume':
+ return (_player.getMute()==true) ? 0 : _player.getVolume();
+ }
+
+ return 0;
+
+
+ }
+
+ public function addJsListener(attribute:String, parameter:String):Void {
+ _externalListeners.set(attribute.toLowerCase(), parameter);
+ }
+
+ public function removeJsListener(attribute:String):Void {
+ if (attribute == '*')
+ {
+ _externalListeners = new Hash();
+ return;
+ }
+ _externalListeners.remove(attribute.toLowerCase());
+ }
+
+ public function onPlayerEvent(event:PlayerEvents):Void
+ {
+ var jsFunction = '';
+ var data = {
+ duration: event.duration,
+ fullscreen: event.fullscreen,
+ mute: event.mute,
+ volume: event.volume,
+ position: event.time,
+ type: event.name,
+ loaded: _player.getBytesLoaded(),
+ total: _player.getBytesTotal()
+ };
+
+ if (_externalListeners.exists(event.name.toLowerCase()))
+ {
+ ExternalInterface.call(_externalListeners.get(event.name.toLowerCase()), data);
+ }
+
+ if (_externalListeners.exists('on*'))
+ {
+ ExternalInterface.call(_externalListeners.get('on*'), data);
+ }
+
+ }
+
+
+ /**
+ * Toggles pause or play
+ */
+ private function setPlay():Void
+ {
+ if (_player.isPlaying()!=true) {
+ _player.togglePlay();
+ }
+ }
+
+ /**
+ * Toggles play or pause
+ */
+ private function setPause():Void
+ {
+ if (_player.isPlaying()==true) {
+ _player.togglePlay();
+ }
+ }
+
+ /**
+ * Set Seek
+ */
+ private function setSeek(pos:Float):Void
+ {
+ _player.seek(pos);
+ }
+
+ /**
+ * Set Volume
+ */
+ private function setVolume(vol:Float):Void
+ {
+ if (vol <= 0 && _player.getMute()!=true) {
+ _player.toggleMute();
+ _player.setVolume(0);
+ return;
+ }
+
+ if (_player.getMute() == true) {
+ _player.toggleMute();
+ }
+
+ if (vol >= 1) {
+ _player.setVolume(1);
+ return;
+ }
+
+ _player.setVolume(vol);
+ }
+
+
+}
\ No newline at end of file
diff --git a/lib/Jaris/src/jaris/player/Loop.hx b/lib/Jaris/src/jaris/player/Loop.hx
new file mode 100644
index 00000000..acd6dbd5
--- /dev/null
+++ b/lib/Jaris/src/jaris/player/Loop.hx
@@ -0,0 +1,50 @@
+/**
+ * @author Jefferson González
+ * @copyright 2010 Jefferson González
+ *
+ * @license
+ * This file is part of Jaris FLV Player.
+ *
+ * Jaris FLV Player is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License or GNU LESSER GENERAL
+ * PUBLIC LICENSE as published by the Free Software Foundation, either version
+ * 3 of the License, or (at your option) any later version.
+ *
+ * Jaris FLV Player is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License and
+ * GNU LESSER GENERAL PUBLIC LICENSE along with Jaris FLV Player. If not,
+ * see .
+ */
+
+package jaris.player;
+
+//{Libraries
+import jaris.events.PlayerEvents;
+//}
+
+/**
+ * Implements a loop mechanism on the player
+ */
+class Loop
+{
+ private var _player:Player;
+
+ public function new(player:Player)
+ {
+ _player = player;
+ _player.addEventListener(PlayerEvents.PLAYBACK_FINISHED, onPlayerStop);
+ }
+
+ /**
+ * Everytime the player stops, the playback is restarted
+ * @param event
+ */
+ private function onPlayerStop(event:PlayerEvents):Void
+ {
+ _player.togglePlay();
+ }
+}
\ No newline at end of file
diff --git a/lib/Jaris/src/jaris/player/Player.hx b/lib/Jaris/src/jaris/player/Player.hx
new file mode 100644
index 00000000..144dd8df
--- /dev/null
+++ b/lib/Jaris/src/jaris/player/Player.hx
@@ -0,0 +1,1788 @@
+/**
+ * @author Jefferson González
+ * @copyright 2010 Jefferson González
+ *
+ * @license
+ * This file is part of Jaris FLV Player.
+ *
+ * Jaris FLV Player is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License or GNU LESSER GENERAL
+ * PUBLIC LICENSE as published by the Free Software Foundation, either version
+ * 3 of the License, or (at your option) any later version.
+ *
+ * Jaris FLV Player is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License and
+ * GNU LESSER GENERAL PUBLIC LICENSE along with Jaris FLV Player. If not,
+ * see .
+ */
+
+package jaris.player;
+
+import flash.display.Loader;
+import flash.display.MovieClip;
+import flash.display.Sprite;
+import flash.display.Stage;
+import flash.display.StageDisplayState;
+import flash.events.AsyncErrorEvent;
+import flash.events.Event;
+import flash.events.EventDispatcher;
+import flash.events.FullScreenEvent;
+import flash.events.IOErrorEvent;
+import flash.events.KeyboardEvent;
+import flash.events.MouseEvent;
+import flash.events.NetStatusEvent;
+import flash.events.ProgressEvent;
+import flash.events.TimerEvent;
+import flash.geom.Rectangle;
+import flash.Lib;
+import flash.media.ID3Info;
+import flash.media.Sound;
+import flash.media.SoundChannel;
+import flash.media.SoundTransform;
+import flash.media.Video;
+import flash.net.NetConnection;
+import flash.net.NetStream;
+import flash.net.URLRequest;
+import flash.system.Capabilities;
+import flash.system.Security;
+import flash.ui.Keyboard;
+import flash.ui.Mouse;
+import flash.utils.Timer;
+import jaris.events.PlayerEvents;
+import jaris.utils.Utils;
+import jaris.player.AspectRatio;
+import jaris.player.UserSettings;
+
+/**
+ * Jaris main video player
+ */
+class Player extends EventDispatcher
+{
+ //{Member variables
+ private var _stage:Stage;
+ private var _movieClip:MovieClip;
+ private var _connection:NetConnection;
+ private var _stream:NetStream;
+ private var _fullscreen:Bool;
+ private var _soundMuted:Bool;
+ private var _volume:Float;
+ private var _bufferTime:Float;
+ private var _mouseVisible:Bool;
+ private var _mediaLoaded:Bool;
+ private var _hideMouseTimer:Timer;
+ private var _checkAudioTimer:Timer;
+ private var _mediaSource:String;
+ private var _type:String;
+ private var _streamType:String;
+ private var _server:String; //For future use on rtmp
+ private var _sound:Sound;
+ private var _soundChannel:SoundChannel;
+ private var _id3Info:ID3Info;
+ private var _video:Video;
+ private var _videoWidth:Float;
+ private var _videoHeight:Float;
+ private var _videoMask:Sprite;
+ private var _videoQualityHigh:Bool;
+ private var _mediaDuration:Float;
+ private var _lastTime:Float;
+ private var _lastProgress:Float;
+ private var _isPlaying:Bool;
+ private var _aspectRatio:Float;
+ private var _currentAspectRatio:String;
+ private var _originalAspectRatio:Float;
+ private var _mediaEndReached:Bool;
+ private var _seekPoints:Array;
+ private var _downloadCompleted:Bool;
+ private var _startTime:Float;
+ private var _firstLoad:Bool;
+ private var _stopped:Bool;
+ private var _useHardWareScaling:Bool;
+ private var _youtubeLoader:Loader;
+ private var _userSettings:UserSettings;
+ //}
+
+
+ //{Constructor
+ public function new()
+ {
+ super();
+
+ //{Main Variables Init
+ _stage = Lib.current.stage;
+ _movieClip = Lib.current;
+ _mouseVisible = true;
+ _soundMuted = false;
+ _volume = 1.0;
+ _bufferTime = 10;
+ _fullscreen = false;
+ _mediaLoaded = false;
+ _hideMouseTimer = new Timer(1500);
+ _checkAudioTimer = new Timer(100);
+ _seekPoints = new Array();
+ _downloadCompleted = false;
+ _startTime = 0;
+ _firstLoad = true;
+ _stopped = false;
+ _videoQualityHigh = false;
+ _isPlaying = false;
+ _streamType = StreamType.FILE;
+ _type = InputType.VIDEO;
+ _server = "";
+ _currentAspectRatio = "original";
+ _aspectRatio = 0;
+ _lastTime = 0;
+ _lastProgress = 0;
+ _userSettings = new UserSettings();
+ //}
+
+ //{Initialize sound object
+ _sound = new Sound();
+ _sound.addEventListener(Event.COMPLETE, onSoundComplete);
+ _sound.addEventListener(Event.ID3, onSoundID3);
+ _sound.addEventListener(IOErrorEvent.IO_ERROR, onSoundIOError);
+ _sound.addEventListener(ProgressEvent.PROGRESS, onSoundProgress);
+
+ //}
+
+ //{Initialize video and connection objects
+ _connection = new NetConnection();
+ _connection.client = this;
+ _connection.connect(null);
+ _stream = new NetStream(_connection);
+
+ _video = new Video(_stage.stageWidth, _stage.stageHeight);
+
+ _movieClip.addChild(_video);
+ //}
+
+ //Video mask so that custom menu items work
+ _videoMask = new Sprite();
+ _movieClip.addChild(_videoMask);
+
+ //Set initial rendering to high quality
+ toggleQuality();
+
+ //{Initialize system event listeners
+ _movieClip.addEventListener(Event.ENTER_FRAME, onEnterFrame);
+ _stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
+ _stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
+ _stage.addEventListener(FullScreenEvent.FULL_SCREEN, onFullScreen);
+ _stage.addEventListener(Event.RESIZE, onResize);
+ _hideMouseTimer.addEventListener(TimerEvent.TIMER, hideMouseTimer);
+ _checkAudioTimer.addEventListener(TimerEvent.TIMER, checkAudioTimer);
+ _connection.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
+ _connection.addEventListener(AsyncErrorEvent.ASYNC_ERROR, onAsyncError);
+ //}
+ }
+ //}
+
+
+ //{Timers
+ /**
+ * Timer that hides the mouse pointer when it is idle and dispatch the PlayerEvents.MOUSE_HIDE
+ * @param event
+ */
+ private function hideMouseTimer(event:TimerEvent):Void
+ {
+ if (_fullscreen)
+ {
+ if (_mouseVisible)
+ {
+ _mouseVisible = false;
+ }
+ else
+ {
+ Mouse.hide();
+ callEvents(PlayerEvents.MOUSE_HIDE);
+ _hideMouseTimer.stop();
+ }
+ }
+ }
+
+ /**
+ * To check if the sound finished playing
+ * @param event
+ */
+ private function checkAudioTimer(event:TimerEvent):Void
+ {
+ if (_soundChannel.position + 100 >= _sound.length)
+ {
+ _isPlaying = false;
+ _mediaEndReached = true;
+ callEvents(PlayerEvents.PLAYBACK_FINISHED);
+
+ _checkAudioTimer.stop();
+ }
+ }
+ //}
+
+
+ //{Events
+ /**
+ * Callback after bandwidth calculation for rtmp streams
+ */
+ private function onBWDone():Void
+ {
+ //Need to study this more
+ }
+
+ /**
+ * Triggers error event on rtmp connections
+ * @param event
+ */
+ private function onAsyncError(event:AsyncErrorEvent):Void
+ {
+ //TODO: Should trigger event for controls to display error message
+ trace(event.error);
+ }
+
+ /**
+ * Checks if connection failed or succeed
+ * @param event
+ */
+ private function onNetStatus(event:NetStatusEvent):Void
+ {
+ switch (event.info.code)
+ {
+ case "NetConnection.Connect.Success":
+ if (_streamType == StreamType.RTMP)
+ {
+ _stream = new NetStream(_connection);
+ _stream.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
+ _stream.bufferTime = 10;
+ _stream.play(Utils.rtmpSourceParser(_mediaSource), true);
+ _stream.client = this;
+ if(_type == InputType.VIDEO) {_video.attachNetStream(_stream); }
+ }
+ callEvents(PlayerEvents.CONNECTION_SUCCESS);
+
+ case "NetStream.Play.StreamNotFound":
+ trace("Stream not found: " + _mediaSource); //Replace with a dispatch for error event
+ callEvents(PlayerEvents.CONNECTION_FAILED);
+
+ case "NetStream.Play.Stop":
+ if (_streamType != StreamType.RTMP)
+ {
+ if (_isPlaying) { _stream.togglePause(); }
+ _isPlaying = false;
+ _mediaEndReached = true;
+ callEvents(PlayerEvents.PLAYBACK_FINISHED);
+ }
+
+ case "NetStream.Play.Start":
+ _isPlaying = true;
+ _mediaEndReached = false;
+ if (_stream.bytesLoaded != _stream.bytesTotal || _streamType == StreamType.RTMP)
+ {
+ callEvents(PlayerEvents.BUFFERING);
+ }
+
+ case "NetStream.Seek.Notify":
+ _mediaEndReached = false;
+ if (_streamType == StreamType.RTMP)
+ {
+ _isPlaying = true;
+ callEvents(PlayerEvents.PLAY_PAUSE);
+ callEvents(PlayerEvents.BUFFERING);
+ }
+
+ case "NetStream.Buffer.Empty":
+ if (_stream.bytesLoaded != _stream.bytesTotal)
+ {
+ callEvents(PlayerEvents.BUFFERING);
+ }
+
+ case "NetStream.Buffer.Full":
+ callEvents(PlayerEvents.NOT_BUFFERING);
+
+ case "NetStream.Buffer.Flush":
+ if (_stream.bytesLoaded == _stream.bytesTotal)
+ {
+ _downloadCompleted = true;
+ }
+ }
+ }
+
+ /**
+ * Proccess keyboard shortcuts
+ * @param event
+ */
+ private function onKeyDown(event:KeyboardEvent):Void
+ {
+ var F_KEY:UInt = 70;
+ var M_KEY:UInt = 77;
+ var X_KEY:UInt = 88;
+
+ switch(event.keyCode)
+ {
+ case Keyboard.TAB:
+ toggleAspectRatio();
+
+ case F_KEY:
+ toggleFullscreen();
+
+ case M_KEY:
+ toggleMute();
+
+ case Keyboard.UP:
+ volumeUp();
+
+ case Keyboard.DOWN:
+ volumeDown();
+
+ case Keyboard.RIGHT:
+ forward();
+
+ case Keyboard.LEFT:
+ rewind();
+
+ case Keyboard.SPACE:
+ togglePlay();
+
+ case X_KEY:
+ stopAndClose();
+ }
+ }
+
+ /**
+ * IF player is full screen shows the mouse when gets hide
+ * @param event
+ */
+ private function onMouseMove(event:MouseEvent):Void
+ {
+ if (_fullscreen && !_mouseVisible)
+ {
+ if (!_hideMouseTimer.running)
+ {
+ _hideMouseTimer.start();
+ }
+
+ _mouseVisible = true;
+ Mouse.show();
+
+ callEvents(PlayerEvents.MOUSE_SHOW);
+ }
+ }
+
+ /**
+ * Resize video player
+ * @param event
+ */
+ private function onResize(event:Event):Void
+ {
+ resizeAndCenterPlayer();
+ }
+
+ /**
+ * Dispath a full screen event to listeners as redraw player an takes care of some other aspects
+ * @param event
+ */
+ private function onFullScreen(event:FullScreenEvent):Void
+ {
+ _fullscreen = event.fullScreen;
+
+ if (!event.fullScreen)
+ {
+ Mouse.show();
+ callEvents(PlayerEvents.MOUSE_SHOW);
+ _mouseVisible = true;
+ }
+ else
+ {
+ _mouseVisible = true;
+ _hideMouseTimer.start();
+ }
+
+ resizeAndCenterPlayer();
+
+ callEvents(PlayerEvents.FULLSCREEN);
+ }
+
+ /**
+ * Sits for any cue points available
+ * @param data
+ * @note Planned future implementation
+ */
+ private function onCuePoint(data:Dynamic):Void
+ {
+
+ }
+
+ /**
+ * After a video is loaded this callback gets the video information at start and stores it on variables
+ * @param data
+ */
+ private function onMetaData(data:Dynamic):Void
+ {
+ if (_firstLoad)
+ {
+ _isPlaying = true;
+
+ _firstLoad = false;
+ if (data.width)
+ {
+ _videoWidth = data.width;
+ _videoHeight = data.height;
+ }
+ else
+ {
+ _videoWidth = _video.width;
+ _videoHeight = _video.height;
+ }
+
+ //Store seekpoints times
+ if (data.hasOwnProperty("seekpoints")) //MP4
+ {
+ for (position in Reflect.fields(data.seekpoints))
+ {
+ _seekPoints.push(Reflect.field(data.seekpoints, position).time);
+ }
+ }
+ else if (data.hasOwnProperty("keyframes")) //FLV
+ {
+ for (position in Reflect.fields(data.keyframes.times))
+ {
+ _seekPoints.push(Reflect.field(data.keyframes.times, position));
+ }
+ }
+
+ _mediaLoaded = true;
+ _mediaDuration = data.duration;
+ _originalAspectRatio = AspectRatio.getAspectRatio(_videoWidth, _videoHeight);
+
+ if (_aspectRatio <= 0)
+ {
+ _aspectRatio = _originalAspectRatio;
+ }
+
+ callEvents(PlayerEvents.MEDIA_INITIALIZED);
+
+ resizeAndCenterPlayer();
+
+ //Retrieve the volume that user selected last time
+ setVolume(_userSettings.getVolume());
+ }
+ }
+
+ /**
+ * Dummy function invoked for pseudostream servers
+ * @param data
+ */
+ private function onLastSecond(data:Dynamic):Void
+ {
+ trace("last second pseudostream");
+ }
+
+ /**
+ * Broadcast Timeupdate and Duration
+ */
+ private function onEnterFrame(event:Event):Void
+ {
+ if (getDuration() > 0 && _lastTime != getCurrentTime())
+ {
+ _lastTime = getCurrentTime();
+ callEvents(PlayerEvents.TIME);
+ }
+
+ if (getBytesLoaded() > 0 && _lastProgress < getBytesLoaded())
+ {
+ _lastProgress = getBytesLoaded();
+ callEvents(PlayerEvents.PROGRESS);
+ }
+
+ }
+
+
+ /**
+ * Triggers when playbacks end on rtmp streaming server
+ */
+ private function onPlayStatus(info:Dynamic):Void
+ {
+ _isPlaying = false;
+ _mediaEndReached = true;
+ callEvents(PlayerEvents.PLAYBACK_FINISHED);
+ }
+
+ /**
+ * When sound finished downloading
+ * @param event
+ */
+ private function onSoundComplete(event:Event)
+ {
+ _mediaDuration = _sound.length / 1000;
+ _downloadCompleted = true;
+
+ callEvents(PlayerEvents.MEDIA_INITIALIZED);
+ }
+
+ /**
+ * Mimic stream onMetaData
+ * @param event
+ */
+ private function onSoundID3(event:Event)
+ {
+ if (_firstLoad)
+ {
+ _soundChannel = _sound.play();
+ _checkAudioTimer.start();
+
+ _isPlaying = true;
+
+ _firstLoad = false;
+
+ _mediaLoaded = true;
+ _mediaDuration = ((_sound.bytesTotal / _sound.bytesLoaded) * _sound.length) / 1000;
+ _aspectRatio = AspectRatio.getAspectRatio(_videoWidth, _videoHeight);
+ _originalAspectRatio = _aspectRatio;
+ _id3Info = _sound.id3;
+
+ callEvents(PlayerEvents.CONNECTION_SUCCESS);
+ callEvents(PlayerEvents.MEDIA_INITIALIZED);
+
+ resizeAndCenterPlayer();
+
+ //Retrieve the volume that user selected last time
+ setVolume(_userSettings.getVolume());
+ }
+ }
+
+ /**
+ * Dispatch connection failed event on error
+ * @param event
+ */
+ private function onSoundIOError(event:IOErrorEvent)
+ {
+ callEvents(PlayerEvents.CONNECTION_FAILED);
+ }
+
+ /**
+ * Monitor sound download progress
+ * @param event
+ */
+ private function onSoundProgress(event:ProgressEvent)
+ {
+ if (_sound.isBuffering)
+ {
+ callEvents(PlayerEvents.BUFFERING);
+ }
+ else
+ {
+ callEvents(PlayerEvents.NOT_BUFFERING);
+ }
+
+ _mediaDuration = ((_sound.bytesTotal / _sound.bytesLoaded) * _sound.length) / 1000;
+ callEvents(PlayerEvents.MEDIA_INITIALIZED);
+ }
+
+ /**
+ * Initializes the youtube loader object
+ * @param event
+ */
+ private function onYouTubeLoaderInit(event:Event):Void
+ {
+ _youtubeLoader.content.addEventListener("onReady", onYoutubeReady);
+ _youtubeLoader.content.addEventListener("onError", onYoutubeError);
+ _youtubeLoader.content.addEventListener("onStateChange", onYoutubeStateChange);
+ _youtubeLoader.content.addEventListener("onPlaybackQualityChange", onYoutubePlaybackQualityChange);
+
+ }
+
+ /**
+ * This event is fired when the player is loaded and initialized, meaning it is ready to receive API calls.
+ */
+ private function onYoutubeReady(event:Event):Void
+ {
+ _movieClip.addChild(_youtubeLoader.content);
+ _movieClip.setChildIndex(_youtubeLoader.content, 0);
+ Reflect.field(_youtubeLoader.content, "setSize")(_stage.stageWidth, _stage.stageHeight);
+ Reflect.field(_youtubeLoader.content, "loadVideoByUrl")(Utils.youtubeSourceParse(_mediaSource));
+ callEvents(PlayerEvents.BUFFERING);
+ }
+
+ /**
+ * This event is fired whenever the player's state changes. Possible values are unstarted (-1), ended (0),
+ * playing (1), paused (2), buffering (3), video cued (5). When the SWF is first loaded it will broadcast
+ * an unstarted (-1) event. When the video is cued and ready to play it will broadcast a video cued event (5).
+ * @param event
+ */
+ private function onYoutubeStateChange(event:Event):Void
+ {
+ var status:UInt = Std.parseInt(Reflect.field(event, "data"));
+
+ switch(status)
+ {
+ case -1:
+ callEvents(PlayerEvents.BUFFERING);
+
+ case 0:
+ _isPlaying = false;
+ _mediaEndReached = true;
+ callEvents(PlayerEvents.PLAYBACK_FINISHED);
+
+ case 1:
+ if (_firstLoad)
+ {
+ _isPlaying = true;
+
+ _videoWidth = _stage.stageWidth;
+ _videoHeight = _stage.stageHeight;
+
+ _firstLoad = false;
+
+ _mediaLoaded = true;
+ _mediaDuration = Reflect.field(_youtubeLoader.content, "getDuration")();
+ _aspectRatio = AspectRatio.getAspectRatio(_videoWidth, _videoHeight);
+ _originalAspectRatio = _aspectRatio;
+
+ callEvents(PlayerEvents.CONNECTION_SUCCESS);
+ callEvents(PlayerEvents.MEDIA_INITIALIZED);
+
+ resizeAndCenterPlayer();
+
+ //Retrieve the volume that user selected last time
+ setVolume(_userSettings.getVolume());
+ }
+ callEvents(PlayerEvents.NOT_BUFFERING);
+
+ case 2:
+ callEvents(PlayerEvents.NOT_BUFFERING);
+
+ case 3:
+ callEvents(PlayerEvents.BUFFERING);
+
+ case 5:
+ callEvents(PlayerEvents.NOT_BUFFERING);
+ }
+ }
+
+ /**
+ * This event is fired whenever the video playback quality changes. For example, if you call the
+ * setPlaybackQuality(suggestedQuality) function, this event will fire if the playback quality actually
+ * changes. Your code should respond to the event and should not assume that the quality will automatically
+ * change when the setPlaybackQuality(suggestedQuality) function is called. Similarly, your code should not
+ * assume that playback quality will only change as a result of an explicit call to setPlaybackQuality or any
+ * other function that allows you to set a suggested playback quality.
+ *
+ * The value that the event broadcasts is the new playback quality. Possible values are "small", "medium",
+ * "large" and "hd720".
+ * @param event
+ */
+ private function onYoutubePlaybackQualityChange(event:Event):Void
+ {
+ //trace(Reflect.field(event, "data"));
+ }
+
+ /**
+ * This event is fired when an error in the player occurs. The possible error codes are 100, 101,
+ * and 150. The 100 error code is broadcast when the video requested is not found. This occurs when
+ * a video has been removed (for any reason), or it has been marked as private. The 101 error code is
+ * broadcast when the video requested does not allow playback in the embedded players. The error code
+ * 150 is the same as 101, it's just 101 in disguise!
+ * @param event
+ */
+ private function onYoutubeError(event:Event):Void
+ {
+ trace(Reflect.field(event, "data"));
+ }
+ //}
+
+
+ //{Private Methods
+ /**
+ * Function used each time is needed to dispatch an event
+ * @param type
+ */
+ private function callEvents(type:String):Void
+ {
+ var playerEvent:PlayerEvents = new PlayerEvents(type, true);
+
+ playerEvent.aspectRatio = getAspectRatio();
+ playerEvent.duration = getDuration();
+ playerEvent.fullscreen = isFullscreen();
+ playerEvent.mute = getMute();
+ playerEvent.volume = getVolume();
+ playerEvent.width = _video.width;
+ playerEvent.height = _video.height;
+ playerEvent.stream = getNetStream();
+ playerEvent.sound = getSound();
+ playerEvent.time = getCurrentTime();
+ playerEvent.id3Info = getId3Info();
+
+ dispatchEvent(playerEvent);
+ }
+
+ /**
+ * Reposition and resizes the video player to fit on screen
+ */
+ private function resizeAndCenterPlayer():Void
+ {
+ if (_streamType != StreamType.YOUTUBE)
+ {
+ _video.height = _stage.stageHeight;
+ _video.width = _video.height * _aspectRatio;
+
+ _video.x = (_stage.stageWidth / 2) - (_video.width / 2);
+ _video.y = 0;
+
+ if (_video.width > _stage.stageWidth && _aspectRatio == _originalAspectRatio)
+ {
+ var aspectRatio:Float = _videoHeight / _videoWidth;
+ _video.width = _stage.stageWidth;
+ _video.height = aspectRatio * _video.width;
+ _video.x = 0;
+ _video.y = (_stage.stageHeight / 2) - (_video.height / 2);
+ }
+
+ _videoMask.graphics.clear();
+ _videoMask.graphics.lineStyle();
+ _videoMask.graphics.beginFill(0x000000, 0);
+ _videoMask.graphics.drawRect(_video.x, _video.y, _video.width, _video.height);
+ _videoMask.graphics.endFill();
+ }
+ else
+ {
+ Reflect.field(_youtubeLoader.content, "setSize")(_stage.stageWidth, _stage.stageHeight);
+
+ _videoMask.graphics.clear();
+ _videoMask.graphics.lineStyle();
+ _videoMask.graphics.beginFill(0x000000, 0);
+ _videoMask.graphics.drawRect(0, 0, _stage.stageWidth, _stage.stageHeight);
+ _videoMask.graphics.endFill();
+ }
+
+ callEvents(PlayerEvents.RESIZE);
+ }
+
+ /**
+ * Check the best seek point available if the seekpoints array is available
+ * @param time time in seconds
+ * @return best seek point in seconds or given one if no seekpoints array is available
+ */
+ private function getBestSeekPoint(time:Float):Float
+ {
+ if (_seekPoints.length > 0)
+ {
+ var timeOne:String="0";
+ var timeTwo:String="0";
+
+ for(prop in Reflect.fields(_seekPoints))
+ {
+ if(Reflect.field(_seekPoints,prop) < time)
+ {
+ timeOne = prop;
+ }
+ else
+ {
+ timeTwo = prop;
+ break;
+ }
+ }
+
+ if(time - _seekPoints[Std.parseInt(timeOne)] < _seekPoints[Std.parseInt(timeTwo)] - time)
+ {
+ return _seekPoints[Std.parseInt(timeOne)];
+ }
+ else
+ {
+ return _seekPoints[Std.parseInt(timeTwo)];
+ }
+ }
+
+ return time;
+ }
+
+ /**
+ * Checks if the given seek time is already buffered
+ * @param time time in seconds
+ * @return true if can seek false if not in buffer
+ */
+ private function canSeek(time:Float):Bool
+ {
+ if (_type == InputType.VIDEO)
+ {
+ time = getBestSeekPoint(time);
+ }
+
+ var cacheTotal = Math.floor((getDuration() - _startTime) * (getBytesLoaded() / getBytesTotal())) - 1;
+
+ if(time >= _startTime && time < _startTime + cacheTotal)
+ {
+ return true;
+ }
+
+ return false;
+ }
+ //}
+
+
+ //{Public methods
+ /**
+ * Loads a video and starts playing it
+ * @param video video url to load
+ */
+ public function load(source:String, type:String="video", streamType:String="file", server:String=""):Void
+ {
+ stopAndClose();
+
+ _type = type;
+ _streamType = streamType;
+ _mediaSource = source;
+ _stopped = false;
+ _mediaLoaded = false;
+ _firstLoad = true;
+ _startTime = 0;
+ _downloadCompleted = false;
+ _seekPoints = new Array();
+ _server = server;
+
+ callEvents(PlayerEvents.BUFFERING);
+
+ if (_streamType == StreamType.YOUTUBE)
+ {
+ Security.allowDomain("*");
+ Security.allowDomain("www.youtube.com");
+ Security.allowDomain("youtube.com");
+ Security.allowDomain("s.ytimg.com");
+ Security.allowDomain("i.ytimg.com");
+
+ _youtubeLoader = new Loader();
+ _youtubeLoader.contentLoaderInfo.addEventListener(Event.INIT, onYouTubeLoaderInit);
+ _youtubeLoader.load(new URLRequest("http://www.youtube.com/apiplayer?version=3"));
+ }
+ else if (_type == InputType.VIDEO && (_streamType == StreamType.FILE || _streamType == StreamType.PSEUDOSTREAM))
+ {
+ _connection.connect(null);
+ _stream = new NetStream(_connection);
+ _stream.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
+ _stream.bufferTime = _bufferTime;
+ _stream.play(source);
+ _stream.client = this;
+ _video.attachNetStream(_stream);
+ }
+ else if (_type == InputType.VIDEO && _streamType == StreamType.RTMP)
+ {
+ _connection.connect(_server);
+ }
+ else if (_type == InputType.AUDIO && _streamType == StreamType.RTMP)
+ {
+ _connection.connect(_server);
+ }
+ else if(_type == InputType.AUDIO && _streamType == StreamType.FILE)
+ {
+ _sound.load(new URLRequest(source));
+ }
+ }
+
+ /**
+ * Closes the connection and makes player available for another video
+ */
+ public function stopAndClose():Void
+ {
+ if (_mediaLoaded)
+ {
+ _mediaLoaded = false;
+ _isPlaying = false;
+ _stopped = true;
+ _startTime = 0;
+
+ if (_streamType == StreamType.YOUTUBE)
+ {
+ Reflect.field(_youtubeLoader.content, "destroy")();
+ }
+ else if (_type == InputType.VIDEO)
+ {
+ _stream.close();
+ }
+ else
+ {
+ _soundChannel.stop();
+ _sound.close();
+ }
+ }
+
+ callEvents(PlayerEvents.STOP_CLOSE);
+ }
+
+ /**
+ * Seeks 8 seconds forward from the current position.
+ * @return current play time after forward
+ */
+ public function forward():Float
+ {
+ var seekTime = (getCurrentTime() + 8) + _startTime;
+
+ if (getDuration() > seekTime)
+ {
+ seekTime = seek(seekTime);
+ }
+
+ return seekTime;
+ }
+
+ /**
+ * Seeks 8 seconds back from the current position.
+ * @return current play time after rewind
+ */
+ public function rewind():Float
+ {
+ var seekTime = (getCurrentTime() - 8) + _startTime;
+
+ if (seekTime >= _startTime)
+ {
+ seekTime = seek(seekTime);
+ }
+
+ return seekTime;
+ }
+
+ /**
+ * Seeks video player to a given time in seconds
+ * @param seekTime time in seconds to seek
+ * @return current play time after seeking
+ */
+ public function seek(seekTime:Float):Float
+ {
+ if (_startTime <= 1 && _downloadCompleted)
+ {
+ if (_type == InputType.VIDEO || _streamType == StreamType.RTMP)
+ {
+ _stream.seek(seekTime);
+ }
+ else if (_type == InputType.AUDIO)
+ {
+ _soundChannel.stop();
+ _soundChannel = _sound.play(seekTime * 1000);
+ if (!_isPlaying)
+ {
+ _soundChannel.stop();
+ }
+
+ setVolume(_userSettings.getVolume());
+ }
+ }
+ else if(_seekPoints.length > 0 && _streamType == StreamType.PSEUDOSTREAM)
+ {
+ seekTime = getBestSeekPoint(seekTime);
+
+ if (canSeek(seekTime))
+ {
+ _stream.seek(seekTime - _startTime);
+ }
+ else if(seekTime != _startTime)
+ {
+ _startTime = seekTime;
+
+ var url:String;
+ if (_mediaSource.indexOf("?") != -1)
+ {
+ url = _mediaSource + "&start=" + seekTime;
+ }
+ else
+ {
+ url = _mediaSource + "?start=" + seekTime;
+ }
+ _stream.play(url);
+ }
+ }
+ else if (_streamType == StreamType.YOUTUBE)
+ {
+ if (!canSeek(seekTime))
+ {
+ _startTime = seekTime;
+ Reflect.field(_youtubeLoader.content, "seekTo")(seekTime);
+ }
+ else
+ {
+ Reflect.field(_youtubeLoader.content, "seekTo")(seekTime);
+ }
+
+ }
+ else if (_streamType == StreamType.RTMP)
+ {
+ // seekTime = getBestSeekPoint(seekTime); //Not Needed?
+ _stream.seek(seekTime);
+ }
+ else if(canSeek(seekTime))
+ {
+ if (_type == InputType.VIDEO || _streamType == StreamType.RTMP)
+ {
+ _stream.seek(seekTime);
+ }
+ else if (_type == InputType.AUDIO)
+ {
+ _soundChannel.stop();
+ _soundChannel = _sound.play(seekTime * 1000);
+ if (!_isPlaying)
+ {
+ _soundChannel.stop();
+ }
+
+ setVolume(_userSettings.getVolume());
+ }
+ }
+ callEvents(PlayerEvents.SEEK);
+ return seekTime;
+ }
+
+ /**
+ * To check wheter the media is playing
+ * @return true if is playing false otherwise
+ */
+ public function isPlaying():Bool
+ {
+ return _isPlaying;
+ }
+
+ /**
+ * Cycle betewen aspect ratios
+ * @return new aspect ratio in use
+ */
+ public function toggleAspectRatio():Float
+ {
+ switch(_currentAspectRatio)
+ {
+ case "original":
+ _aspectRatio = AspectRatio._1_1;
+ _currentAspectRatio = "1:1";
+
+ case "1:1":
+ _aspectRatio = AspectRatio._3_2;
+ _currentAspectRatio = "3:2";
+
+ case "3:2":
+ _aspectRatio = AspectRatio._4_3;
+ _currentAspectRatio = "4:3";
+
+ case "4:3":
+ _aspectRatio = AspectRatio._5_4;
+ _currentAspectRatio = "5:4";
+
+ case "5:4":
+ _aspectRatio = AspectRatio._14_9;
+ _currentAspectRatio = "14:9";
+
+ case "14:9":
+ _aspectRatio = AspectRatio._14_10;
+ _currentAspectRatio = "14:10";
+
+ case "14:10":
+ _aspectRatio = AspectRatio._16_9;
+ _currentAspectRatio = "16:9";
+
+ case "16:9":
+ _aspectRatio = AspectRatio._16_10;
+ _currentAspectRatio = "16:10";
+
+ case "16:10":
+ _aspectRatio = _originalAspectRatio;
+ _currentAspectRatio = "original";
+
+ default:
+ _aspectRatio = _originalAspectRatio;
+ _currentAspectRatio = "original";
+ }
+
+ resizeAndCenterPlayer();
+
+ callEvents(PlayerEvents.ASPECT_RATIO);
+
+ //Store aspect ratio into user settings
+ if (_aspectRatio == _originalAspectRatio)
+ {
+ _userSettings.setAspectRatio(0.0);
+ }
+ else
+ {
+ _userSettings.setAspectRatio(_aspectRatio);
+ }
+
+ return _aspectRatio;
+ }
+
+ /**
+ * Swithces between play and pause
+ */
+ public function togglePlay():Bool
+ {
+ if (_mediaLoaded)
+ {
+ if (_mediaEndReached)
+ {
+ _mediaEndReached = false;
+
+ if (_streamType == StreamType.YOUTUBE)
+ {
+ Reflect.field(_youtubeLoader.content, "seekTo")(0);
+ Reflect.field(_youtubeLoader.content, "playVideo")();
+ }
+ else if (_type == InputType.VIDEO || _streamType == StreamType.RTMP)
+ {
+ _stream.seek(0);
+ _stream.togglePause();
+ }
+ else if (_type == InputType.AUDIO)
+ {
+ _checkAudioTimer.start();
+ _soundChannel = _sound.play();
+ setVolume(_userSettings.getVolume());
+ }
+ }
+ else if (_mediaLoaded)
+ {
+ if (_streamType == StreamType.YOUTUBE)
+ {
+ if (_isPlaying)
+ {
+ Reflect.field(_youtubeLoader.content, "pauseVideo")();
+ }
+ else
+ {
+ Reflect.field(_youtubeLoader.content, "playVideo")();
+ }
+ }
+ else if (_type == InputType.VIDEO || _streamType == StreamType.RTMP)
+ {
+ _stream.togglePause();
+ }
+ else if (_type == InputType.AUDIO)
+ {
+ if (_isPlaying)
+ {
+ _soundChannel.stop();
+ }
+ else
+ {
+ //If end of audio reached start from beggining
+ if (_soundChannel.position + 100 >= _sound.length)
+ {
+ _soundChannel = _sound.play();
+ }
+ else
+ {
+ _soundChannel = _sound.play(_soundChannel.position);
+ }
+
+ setVolume(_userSettings.getVolume());
+ }
+ }
+ }
+ else if (_stopped)
+ {
+ load(_mediaSource, _type, _streamType, _server);
+ }
+
+ _isPlaying = !_isPlaying;
+ callEvents(PlayerEvents.PLAY_PAUSE);
+ return _isPlaying;
+ }
+ else if(_mediaSource != "")
+ {
+ load(_mediaSource, _type, _streamType, _server);
+ callEvents(PlayerEvents.BUFFERING);
+ return true;
+ }
+ callEvents(PlayerEvents.PLAY_PAUSE);
+ return false;
+ }
+
+ /**
+ * Switches on or off fullscreen
+ * @return true if fullscreen otherwise false
+ */
+ public function toggleFullscreen():Bool
+ {
+ if (_fullscreen)
+ {
+ _stage.displayState = StageDisplayState.NORMAL;
+ _stage.focus = _stage;
+ return false;
+ }
+ else
+ {
+ if (_useHardWareScaling)
+ {
+ //Match full screen aspec ratio to desktop
+ var aspectRatio = Capabilities.screenResolutionY / Capabilities.screenResolutionX;
+ _stage.fullScreenSourceRect = new Rectangle(0, 0, _videoWidth, _videoWidth * aspectRatio);
+ }
+ else
+ {
+ //Use desktop resolution
+ _stage.fullScreenSourceRect = new Rectangle(0, 0, Capabilities.screenResolutionX ,Capabilities.screenResolutionY);
+ }
+
+ _stage.displayState = StageDisplayState.FULL_SCREEN;
+ _stage.focus = _stage;
+ return true;
+ }
+ }
+
+ /**
+ * Toggles betewen high and low quality image rendering
+ * @return true if quality high false otherwise
+ */
+ public function toggleQuality():Bool
+ {
+ if (_videoQualityHigh)
+ {
+ _video.smoothing = false;
+ _video.deblocking = 1;
+ }
+ else
+ {
+ _video.smoothing = true;
+ _video.deblocking = 5;
+ }
+
+ _videoQualityHigh = _videoQualityHigh?false:true;
+
+ return _videoQualityHigh;
+ }
+
+ /**
+ * Mutes or unmutes the sound
+ * @return true if muted false if unmuted
+ */
+ public function toggleMute():Bool
+ {
+ var soundTransform:SoundTransform = new SoundTransform();
+ var isMute:Bool;
+
+ //unmute sound
+ if (_soundMuted)
+ {
+ _soundMuted = false;
+
+ if (_volume > 0)
+ {
+ soundTransform.volume = _volume;
+ }
+ else
+ {
+ _volume = 1.0;
+ soundTransform.volume = _volume;
+ }
+
+ isMute = false;
+ }
+
+ //mute sound
+ else
+ {
+ _soundMuted = true;
+ _volume = _stream.soundTransform.volume;
+ soundTransform.volume = 0;
+ _stream.soundTransform = soundTransform;
+
+ isMute = true;
+ }
+
+ if (_streamType == StreamType.YOUTUBE)
+ {
+ Reflect.field(_youtubeLoader.content, "setVolume")(soundTransform.volume * 100);
+ }
+ else if (_type == InputType.VIDEO || _streamType == StreamType.RTMP)
+ {
+ _stream.soundTransform = soundTransform;
+ }
+ else if (_type == InputType.AUDIO)
+ {
+ _soundChannel.soundTransform = soundTransform;
+ setVolume(_userSettings.getVolume());
+ }
+
+ callEvents(PlayerEvents.MUTE);
+ return isMute;
+ }
+
+ /**
+ * Check if player is running on fullscreen mode
+ * @return true if fullscreen false if not
+ */
+ public function isFullscreen():Bool
+ {
+ return _stage.displayState == StageDisplayState.FULL_SCREEN;
+ }
+
+ /**
+ * Raises the volume
+ * @return volume value after raising
+ */
+ public function volumeUp():Float
+ {
+ var soundTransform:SoundTransform = new SoundTransform();
+
+ if (_soundMuted)
+ {
+ _soundMuted = false;
+ }
+
+ //raise volume if not already at max
+ if (_volume < 1)
+ {
+ if (_streamType == StreamType.YOUTUBE)
+ {
+ _volume = (Reflect.field(_youtubeLoader.content, "getVolume")() + 10) / 100;
+ Reflect.field(_youtubeLoader.content, "setVolume")(_volume * 100);
+ }
+ else if (_type == InputType.VIDEO || _streamType == StreamType.RTMP)
+ {
+ _volume = _stream.soundTransform.volume + (10/100);
+ soundTransform.volume = _volume;
+ _stream.soundTransform = soundTransform;
+ }
+ else if (_type == InputType.AUDIO)
+ {
+ _volume = _soundChannel.soundTransform.volume + (10/100);
+ soundTransform.volume = _volume;
+ _soundChannel.soundTransform = soundTransform;
+ }
+ }
+
+ //reset volume to 1.0 if already reached max
+ if (_volume >= 1)
+ {
+ _volume = 1.0;
+ }
+
+ //Store volume into user settings
+ _userSettings.setVolume(_volume);
+
+ callEvents(PlayerEvents.VOLUME_UP);
+ return _volume;
+ }
+
+ /**
+ * Lower the volume
+ * @return volume value after lowering
+ */
+ public function volumeDown():Float
+ {
+ var soundTransform:SoundTransform = new SoundTransform();
+
+ //lower sound
+ if(!_soundMuted)
+ {
+ if (_streamType == StreamType.YOUTUBE)
+ {
+ _volume = (Reflect.field(_youtubeLoader.content, "getVolume")() - 10) / 100;
+ Reflect.field(_youtubeLoader.content, "setVolume")(_volume * 100);
+ }
+ else if (_type == InputType.VIDEO || _streamType == StreamType.RTMP)
+ {
+ _volume = _stream.soundTransform.volume - (10/100);
+ soundTransform.volume = _volume;
+ _stream.soundTransform = soundTransform;
+ }
+ else if (_type == InputType.AUDIO)
+ {
+ _volume = _soundChannel.soundTransform.volume - (10/100);
+ soundTransform.volume = _volume;
+ _soundChannel.soundTransform = soundTransform;
+ }
+
+ //if volume reached min is muted
+ if (_volume <= 0)
+ {
+ _soundMuted = true;
+ _volume = 0;
+ }
+ }
+
+ //Store volume into user settings
+ _userSettings.setVolume(_volume);
+
+ callEvents(PlayerEvents.VOLUME_DOWN);
+ return _volume;
+ }
+ //}
+
+
+ //{Setters
+ /**
+ * Set input type
+ * @param type Allowable values are audio, video
+ */
+ public function setType(type:String):Void
+ {
+ _type = type;
+ }
+
+ /**
+ * Set streaming type
+ * @param streamType Allowable values are file, http, rmtp
+ */
+ public function setStreamType(streamType:String):Void
+ {
+ _streamType = streamType;
+ }
+
+ /**
+ * Sets the server url for rtmp streams
+ * @param server
+ */
+ public function setServer(server:String):Void
+ {
+ _server = server;
+ }
+
+ /**
+ * To set the video source in case we dont want to start downloading at first so when use tooglePlay the
+ * media is loaded automatically
+ * @param source
+ */
+ public function setSource(source):Void
+ {
+ _mediaSource = source;
+ }
+
+ /**
+ * Changes the current volume
+ * @param volume
+ */
+ public function setVolume(volume:Float):Void
+ {
+ var soundTransform:SoundTransform = new SoundTransform();
+
+ if (volume > _volume) {
+ callEvents(PlayerEvents.VOLUME_UP);
+ }
+
+ if (volume < _volume) {
+ callEvents(PlayerEvents.VOLUME_DOWN);
+ }
+
+ if (volume > 0)
+ {
+ _soundMuted = false;
+ _volume = volume;
+ }
+ else
+ {
+ _soundMuted = true;
+ _volume = 1.0;
+ }
+
+ soundTransform.volume = volume;
+
+ if (!_firstLoad) //To prevent errors if objects aren't initialized
+ {
+ if (_streamType == StreamType.YOUTUBE)
+ {
+ Reflect.field(_youtubeLoader.content, "setVolume")(soundTransform.volume * 100);
+ }
+ else if (_type == InputType.VIDEO || _streamType == StreamType.RTMP)
+ {
+ _stream.soundTransform = soundTransform;
+ }
+ else if (_type == InputType.AUDIO)
+ {
+ _soundChannel.soundTransform = soundTransform;
+ }
+ }
+
+ //Store volume into user settings
+ _userSettings.setVolume(_volume);
+
+ callEvents(PlayerEvents.VOLUME_CHANGE);
+ }
+
+ /**
+ * Changes the buffer time for local and pseudo streaming
+ * @param time in seconds
+ */
+ public function setBufferTime(time:Float):Void
+ {
+ if (time > 0)
+ {
+ _bufferTime = time;
+ }
+ }
+
+ /**
+ * Changes the aspec ratio of current playing media and resizes video player
+ * @param aspectRatio new aspect ratio value
+ */
+ public function setAspectRatio(aspectRatio:Float):Void
+ {
+ _aspectRatio = aspectRatio;
+
+ switch(_aspectRatio)
+ {
+ case 0.0:
+ _currentAspectRatio = "original";
+
+ case AspectRatio._1_1:
+ _currentAspectRatio = "1:1";
+
+ case AspectRatio._3_2:
+ _currentAspectRatio = "3:2";
+
+ case AspectRatio._4_3:
+ _currentAspectRatio = "4:3";
+
+ case AspectRatio._5_4:
+ _currentAspectRatio = "5:4";
+
+ case AspectRatio._14_9:
+ _currentAspectRatio = "14:9";
+
+ case AspectRatio._14_10:
+ _currentAspectRatio = "14:10";
+
+ case AspectRatio._16_9:
+ _currentAspectRatio = "16:9";
+
+ case AspectRatio._16_10:
+ _currentAspectRatio = "16:10";
+ }
+
+ resizeAndCenterPlayer();
+
+ //Store aspect ratio into user settings
+ _userSettings.setAspectRatio(_aspectRatio);
+ }
+
+ /**
+ * Enable or disable hardware scaling
+ * @param value true to enable false to disable
+ */
+ public function setHardwareScaling(value:Bool):Void
+ {
+ _useHardWareScaling = value;
+ }
+ //}
+
+
+ //{Getters
+ /**
+ * Gets the volume amount 0.0 to 1.0
+ * @return
+ */
+ public function getVolume():Float
+ {
+ return _volume;
+ }
+
+ /**
+ * The current aspect ratio of the loaded Player
+ * @return
+ */
+ public function getAspectRatio():Float
+ {
+ return _aspectRatio;
+ }
+
+ /**
+ * The current aspect ratio of the loaded Player in string format
+ * @return
+ */
+ public function getAspectRatioString():String
+ {
+ return _currentAspectRatio;
+ }
+
+ /**
+ * Original aspect ratio of the video
+ * @return original aspect ratio
+ */
+ public function getOriginalAspectRatio():Float
+ {
+ return _originalAspectRatio;
+ }
+
+ /**
+ * Total duration time of the loaded media
+ * @return time in seconds
+ */
+ public function getDuration():Float
+ {
+ return _mediaDuration;
+ }
+
+ /**
+ * The time in seconds where the player started downloading
+ * @return time in seconds
+ */
+ public function getStartTime():Float
+ {
+ return _startTime;
+ }
+
+ /**
+ * The stream associated with the player
+ * @return netstream object
+ */
+ public function getNetStream():NetStream
+ {
+ return _stream;
+ }
+
+ /**
+ * Video object associated to the player
+ * @return video object for further manipulation
+ */
+ public function getVideo():Video
+ {
+ return _video;
+ }
+
+ /**
+ * Sound object associated to the player
+ * @return sound object for further manipulation
+ */
+ public function getSound():Sound
+ {
+ return _sound;
+ }
+
+ /**
+ * The id3 info of sound object
+ * @return
+ */
+ public function getId3Info():ID3Info
+ {
+ return _id3Info;
+ }
+
+ /**
+ * The current sound state
+ * @return true if mute otherwise false
+ */
+ public function getMute():Bool
+ {
+ return _soundMuted;
+ }
+
+ /**
+ * The amount of total bytes
+ * @return amount of bytes
+ */
+ public function getBytesTotal():Float
+ {
+ var bytesTotal:Float = 0;
+
+ if (_streamType == StreamType.YOUTUBE)
+ {
+ if(_youtubeLoader != null && _mediaLoaded)
+ bytesTotal = Reflect.field(_youtubeLoader.content, "getVideoBytesTotal")();
+ }
+ else if (_type == InputType.VIDEO || _streamType == StreamType.RTMP)
+ {
+ bytesTotal = _stream.bytesTotal;
+ }
+ else if (_type == InputType.AUDIO)
+ {
+ bytesTotal = _sound.bytesTotal;
+ }
+
+ return bytesTotal;
+ }
+
+ /**
+ * The amount of bytes loaded
+ * @return amount of bytes
+ */
+ public function getBytesLoaded():Float
+ {
+ var bytesLoaded:Float = 0;
+
+ if (_streamType == StreamType.YOUTUBE)
+ {
+ if(_youtubeLoader != null && _mediaLoaded)
+ bytesLoaded = Reflect.field(_youtubeLoader.content, "getVideoBytesLoaded")();
+ }
+ else if (_type == InputType.VIDEO || _streamType == StreamType.RTMP)
+ {
+ bytesLoaded = _stream.bytesLoaded;
+ }
+ else if (_type == InputType.AUDIO)
+ {
+ bytesLoaded = _sound.bytesLoaded;
+ }
+
+ return bytesLoaded;
+ }
+
+ /**
+ * Current playing file type
+ * @return audio or video
+ */
+ public function getType():String
+ {
+ return _type;
+ }
+
+ /**
+ * The stream method for the current playing media
+ * @return
+ */
+ public function getStreamType():String
+ {
+ return _streamType;
+ }
+
+ /**
+ * The server url for current rtmp stream
+ * @return
+ */
+ public function getServer():String
+ {
+ return _server;
+ }
+
+ /**
+ * To check current quality mode
+ * @return true if high quality false if low
+ */
+ public function getQuality():Bool
+ {
+ return _videoQualityHigh;
+ }
+
+ /**
+ * The current playing time
+ * @return current playing time in seconds
+ */
+ public function getCurrentTime():Float
+ {
+ var time:Float = 0;
+ if (_streamType == StreamType.YOUTUBE)
+ {
+ if(_youtubeLoader != null)
+ {
+ time = Reflect.field(_youtubeLoader.content, "getCurrentTime")();
+ }
+ else
+ {
+ time = 0;
+ }
+ }
+ else if (_streamType == StreamType.PSEUDOSTREAM)
+ {
+ time = getStartTime() + _stream.time;
+ }
+ else if (_type == InputType.VIDEO || _streamType == StreamType.RTMP)
+ {
+ time = _stream.time;
+ }
+ else if (_type == InputType.AUDIO)
+ {
+ if(_soundChannel != null)
+ {
+ time = _soundChannel.position / 1000;
+ }
+ else
+ {
+ time = 0;
+ }
+ }
+
+ return time;
+ }
+ //}
+}
\ No newline at end of file
diff --git a/lib/Jaris/src/jaris/player/StreamType.hx b/lib/Jaris/src/jaris/player/StreamType.hx
new file mode 100644
index 00000000..d3b11024
--- /dev/null
+++ b/lib/Jaris/src/jaris/player/StreamType.hx
@@ -0,0 +1,34 @@
+/**
+ * @author Jefferson González
+ * @copyright 2010 Jefferson González
+ *
+ * @license
+ * This file is part of Jaris FLV Player.
+ *
+ * Jaris FLV Player is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License or GNU LESSER GENERAL
+ * PUBLIC LICENSE as published by the Free Software Foundation, either version
+ * 3 of the License, or (at your option) any later version.
+ *
+ * Jaris FLV Player is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License and
+ * GNU LESSER GENERAL PUBLIC LICENSE along with Jaris FLV Player. If not,
+ * see .
+ */
+
+package jaris.player;
+
+/**
+ * Some constants for the stream types
+ */
+class StreamType
+{
+ public static var FILE:String = "file";
+ public static var PSEUDOSTREAM:String = "http";
+ public static var RTMP:String = "rtmp";
+ public static var YOUTUBE = "youtube";
+}
\ No newline at end of file
diff --git a/lib/Jaris/src/jaris/player/UserSettings.hx b/lib/Jaris/src/jaris/player/UserSettings.hx
new file mode 100644
index 00000000..cb3688cc
--- /dev/null
+++ b/lib/Jaris/src/jaris/player/UserSettings.hx
@@ -0,0 +1,112 @@
+/**
+ * @author Jefferson González
+ * @copyright 2010 Jefferson González
+ *
+ * @license
+ * This file is part of Jaris FLV Player.
+ *
+ * Jaris FLV Player is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License or GNU LESSER GENERAL
+ * PUBLIC LICENSE as published by the Free Software Foundation, either version
+ * 3 of the License, or (at your option) any later version.
+ *
+ * Jaris FLV Player is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License and
+ * GNU LESSER GENERAL PUBLIC LICENSE along with Jaris FLV Player. If not,
+ * see .
+ */
+
+package jaris.player;
+
+import flash.net.SharedObject;
+
+
+/**
+ * To store and retrieve user settings so the player can load them next time it loads.
+ * In this way player can remember user selected aspect ratio and volume.
+ */
+class UserSettings
+{
+ private var _settings:SharedObject;
+
+ public function new()
+ {
+ _settings = SharedObject.getLocal("JarisPlayerUserSettings");
+ }
+
+ //{Methods
+ /**
+ * Deletes all user settings
+ */
+ public function deleteSettings():Void
+ {
+ _settings.clear();
+ }
+
+ /**
+ * Checks if a user setting is available
+ * @param field The name of the setting
+ * @return true if is set false otherwise
+ */
+ public function isSet(field:String):Bool
+ {
+ return Reflect.hasField(_settings.data, field);
+ }
+ //}
+
+ //{Properties Setters
+ /**
+ * Stores the volume value
+ * @param level
+ */
+ public function setVolume(level:Float):Void
+ {
+ _settings.data.volume = level;
+ _settings.flush();
+ }
+
+ /**
+ * Stores the aspect ratio value
+ * @param aspect
+ */
+ public function setAspectRatio(aspectratio:Float):Void
+ {
+ _settings.data.aspectratio = aspectratio;
+ _settings.flush();
+ }
+ //}
+
+ //{Properties Getters
+ /**
+ * The last user selected volume value
+ * @return Last user selected volume value or default if not set.
+ */
+ public function getVolume():Float
+ {
+ if (!isSet("volume"))
+ {
+ return 1.0; //The maximum volume value
+ }
+
+ return _settings.data.volume;
+ }
+
+ /**
+ * The last user selected aspect ratio value
+ * @return Last user selected aspect ratio value or default if not set.
+ */
+ public function getAspectRatio():Float
+ {
+ if (!isSet("aspectratio"))
+ {
+ return 0.0; //Equivalent to original
+ }
+
+ return _settings.data.aspectratio;
+ }
+ //}
+}
\ No newline at end of file
diff --git a/lib/Jaris/src/jaris/player/controls/AspectRatioIcon.hx b/lib/Jaris/src/jaris/player/controls/AspectRatioIcon.hx
new file mode 100644
index 00000000..d05d5fa2
--- /dev/null
+++ b/lib/Jaris/src/jaris/player/controls/AspectRatioIcon.hx
@@ -0,0 +1,119 @@
+/**
+ * @author Jefferson González
+ * @copyright 2010 Jefferson González
+ *
+ * @license
+ * This file is part of Jaris FLV Player.
+ *
+ * Jaris FLV Player is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License or GNU LESSER GENERAL
+ * PUBLIC LICENSE as published by the Free Software Foundation, either version
+ * 3 of the License, or (at your option) any later version.
+ *
+ * Jaris FLV Player is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License and
+ * GNU LESSER GENERAL PUBLIC LICENSE along with Jaris FLV Player. If not,
+ * see .
+ */
+
+package jaris.player.controls;
+import flash.display.Sprite;
+import flash.events.MouseEvent;
+
+class AspectRatioIcon extends Sprite
+{
+ private var _width:Float;
+ private var _height:Float;
+ private var _normalColor:UInt;
+ private var _hoverColor:UInt;
+
+ public function new(x:Float, y:Float, width:Float, height:Float, normalColor:UInt, hoverColor:UInt)
+ {
+ super();
+
+ this.x = x;
+ this.y = y;
+ this.buttonMode = true;
+ this.useHandCursor = true;
+ this.tabEnabled = false;
+
+ _width = width;
+ _height = height;
+ _normalColor = normalColor;
+ _hoverColor = hoverColor;
+
+ addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
+ addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
+
+ draw(_normalColor);
+ }
+
+ private function onMouseOver(event:MouseEvent):Void
+ {
+ draw(_hoverColor);
+ }
+
+ private function onMouseOut(event:MouseEvent):Void
+ {
+ draw(_normalColor);
+ }
+
+ //{Private Methods
+ private function draw(color:UInt):Void
+ {
+ graphics.clear();
+
+ graphics.lineStyle(2, color);
+ graphics.drawRect(0, 0, _width, _height);
+
+ var innerWidth:Float = (60 / 100) * width;
+ var innerHeight:Float = (60 / 100) * height;
+ var innerX:Float = (width / 2) - (innerWidth / 2) - 1;
+ var innerY:Float = (height / 2) - (innerHeight / 2) - 1;
+
+ graphics.lineStyle();
+ graphics.beginFill(color, 1);
+ graphics.drawRect(innerX, innerY, innerWidth, innerHeight);
+ graphics.endFill();
+
+ graphics.lineStyle();
+ graphics.beginFill(0, 0);
+ graphics.drawRect(0, 0, width, height);
+ graphics.endFill();
+ }
+ //}
+
+ //{Setters
+ public function setNormalColor(color:UInt):Void
+ {
+ _normalColor = color;
+ draw(_normalColor);
+ }
+
+ public function setHoverColor(color:UInt):Void
+ {
+ _hoverColor = color;
+ draw(_hoverColor);
+ }
+
+ public function setPosition(x:Float, y:Float):Void
+ {
+ this.x = x;
+ this.y = y;
+
+ draw(_normalColor);
+ }
+
+ public function setSize(width:Float, height:Float):Void
+ {
+ _width = width;
+ _height = height;
+
+ draw(_normalColor);
+ }
+ //}
+}
\ No newline at end of file
diff --git a/lib/Jaris/src/jaris/player/controls/Controls.hx b/lib/Jaris/src/jaris/player/controls/Controls.hx
new file mode 100644
index 00000000..4311fcaa
--- /dev/null
+++ b/lib/Jaris/src/jaris/player/controls/Controls.hx
@@ -0,0 +1,912 @@
+/**
+ * @author Jefferson González
+ * @copyright 2010 Jefferson González
+ *
+ * @license
+ * This file is part of Jaris FLV Player.
+ *
+ * Jaris FLV Player is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License or GNU LESSER GENERAL
+ * PUBLIC LICENSE as published by the Free Software Foundation, either version
+ * 3 of the License, or (at your option) any later version.
+ *
+ * Jaris FLV Player is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License and
+ * GNU LESSER GENERAL PUBLIC LICENSE along with Jaris FLV Player. If not,
+ * see .
+ */
+
+package jaris.player.controls;
+
+//{Libraries
+import flash.display.GradientType;
+import flash.events.Event;
+import flash.events.TimerEvent;
+import flash.geom.Matrix;
+import flash.Lib;
+import flash.events.MouseEvent;
+import flash.display.MovieClip;
+import flash.net.NetStream;
+import flash.geom.Rectangle;
+import flash.text.AntiAliasType;
+import flash.text.TextField;
+import flash.text.TextFieldAutoSize;
+import flash.text.TextFormat;
+import flash.utils.Timer;
+import jaris.animation.Animation;
+import jaris.display.Loader;
+import jaris.events.PlayerEvents;
+import jaris.player.controls.AspectRatioIcon;
+import jaris.player.controls.FullscreenIcon;
+import jaris.player.controls.PauseIcon;
+import jaris.player.controls.PlayIcon;
+import jaris.player.controls.VolumeIcon;
+import jaris.player.Player;
+import flash.display.Sprite;
+import flash.display.Stage;
+import jaris.utils.Utils;
+//}
+
+/**
+ * Default controls for jaris player
+ */
+class Controls extends MovieClip {
+
+ //{Member Variables
+ private var _thumb:Sprite;
+ private var _track:Sprite;
+ private var _trackDownloaded:Sprite;
+ private var _scrubbing:Bool;
+ private var _stage:Stage;
+ private var _movieClip:MovieClip;
+ private var _player:Player;
+ private var _darkColor:UInt;
+ private var _brightColor:UInt;
+ private var _controlColor:UInt;
+ private var _hoverColor:UInt;
+ private var _hideControlsTimer:Timer;
+ private var _hideAspectRatioLabelTimer:Timer;
+ private var _currentPlayTimeLabel:TextField;
+ private var _totalPlayTimeLabel:TextField;
+ private var _seekPlayTimeLabel:TextField;
+ private var _percentLoaded:Float;
+ private var _controlsVisible:Bool;
+ private var _seekBar:Sprite;
+ private var _controlsBar:Sprite;
+ private var _playControl:PlayIcon;
+ private var _pauseControl:PauseIcon;
+ private var _aspectRatioControl:AspectRatioIcon;
+ private var _fullscreenControl:FullscreenIcon;
+ private var _volumeIcon:VolumeIcon;
+ private var _volumeTrack:Sprite;
+ private var _volumeSlider:Sprite;
+ private var _loader:Loader;
+ private var _aspectRatioLabelContainer:Sprite;
+ private var _aspectRatioLabel:TextField;
+ private var _textFormat:TextFormat;
+ //}
+
+
+ //{Constructor
+ public function new(player:Player)
+ {
+ super();
+
+ //{Main variables
+ _stage = Lib.current.stage;
+ _movieClip = Lib.current;
+ _player = player;
+ _darkColor = 0x000000;
+ _brightColor = 0x4c4c4c;
+ _controlColor = 0xFFFFFF;
+ _hoverColor = 0x67A8C1;
+ _percentLoaded = 0.0;
+ _hideControlsTimer = new Timer(500);
+ _hideAspectRatioLabelTimer = new Timer(500);
+ _controlsVisible = false;
+
+ _textFormat = new TextFormat();
+ _textFormat.font = "arial";
+ _textFormat.color = _controlColor;
+ _textFormat.size = 14;
+ //}
+
+ //{Seeking Controls initialization
+ _seekBar = new Sprite();
+ addChild(_seekBar);
+
+ _trackDownloaded = new Sprite( );
+ _trackDownloaded.tabEnabled = false;
+ _seekBar.addChild(_trackDownloaded);
+
+ _track = new Sprite( );
+ _track.tabEnabled = false;
+ _track.buttonMode = true;
+ _track.useHandCursor = true;
+ _seekBar.addChild(_track);
+
+
+ _thumb = new Sprite( );
+ _thumb.buttonMode = true;
+ _thumb.useHandCursor = true;
+ _thumb.tabEnabled = false;
+ _seekBar.addChild(_thumb);
+
+ _currentPlayTimeLabel = new TextField();
+ _currentPlayTimeLabel.autoSize = TextFieldAutoSize.LEFT;
+ _currentPlayTimeLabel.text = "00:00:00";
+ _currentPlayTimeLabel.tabEnabled = false;
+ _currentPlayTimeLabel.setTextFormat(_textFormat);
+ _seekBar.addChild(_currentPlayTimeLabel);
+
+ _totalPlayTimeLabel = new TextField();
+ _totalPlayTimeLabel.autoSize = TextFieldAutoSize.LEFT;
+ _totalPlayTimeLabel.text = "00:00:00";
+ _totalPlayTimeLabel.tabEnabled = false;
+ _totalPlayTimeLabel.setTextFormat(_textFormat);
+ _seekBar.addChild(_totalPlayTimeLabel);
+
+ _seekPlayTimeLabel = new TextField();
+ _seekPlayTimeLabel.visible = false;
+ _seekPlayTimeLabel.autoSize = TextFieldAutoSize.LEFT;
+ _seekPlayTimeLabel.text = "00:00:00";
+ _seekPlayTimeLabel.tabEnabled = false;
+ _seekPlayTimeLabel.setTextFormat(_textFormat);
+ addChild(_seekPlayTimeLabel);
+ //}
+
+ //{Playing controls initialization
+ _controlsBar = new Sprite();
+ _controlsBar.visible = true;
+ addChild(_controlsBar);
+
+ _playControl = new PlayIcon(0, 0, 0, 0, _controlColor, _hoverColor);
+ _controlsBar.addChild(_playControl);
+
+ _pauseControl = new PauseIcon(0, 0, 0, 0, _controlColor, _hoverColor);
+ _pauseControl.visible = false;
+ _controlsBar.addChild(_pauseControl);
+
+ _aspectRatioControl = new AspectRatioIcon(0, 0, 0, 0, _controlColor, _hoverColor);
+ _controlsBar.addChild(_aspectRatioControl);
+
+ _fullscreenControl = new FullscreenIcon(0, 0, 0, 0, _controlColor, _hoverColor);
+ _controlsBar.addChild(_fullscreenControl);
+
+ _volumeIcon = new VolumeIcon(0, 0, 0, 0, _controlColor, _hoverColor);
+ _controlsBar.addChild(_volumeIcon);
+
+ _volumeSlider = new Sprite();
+ _controlsBar.addChild(_volumeSlider);
+
+ _volumeTrack = new Sprite();
+ _volumeTrack.buttonMode = true;
+ _volumeTrack.useHandCursor = true;
+ _volumeTrack.tabEnabled = false;
+ _controlsBar.addChild(_volumeTrack);
+ //}
+
+ //{Aspect ratio label
+ _aspectRatioLabelContainer = new Sprite();
+ addChild(_aspectRatioLabelContainer);
+
+ _aspectRatioLabel = new TextField();
+ _aspectRatioLabel.autoSize = TextFieldAutoSize.CENTER;
+ _aspectRatioLabel.text = "original";
+ _aspectRatioLabel.tabEnabled = false;
+ _aspectRatioLabelContainer.addChild(_aspectRatioLabel);
+ //}
+
+ redrawControls();
+
+ //{Loader bar
+ _loader = new Loader();
+ _loader.hide();
+
+ var loaderColors:Array = ["", "", "", ""];
+ loaderColors[0] = Std.string(_brightColor);
+ loaderColors[1] = Std.string(_controlColor);
+
+ _loader.setColors(loaderColors);
+
+ addChild(_loader);
+ //}
+
+ //{event Listeners
+ _movieClip.addEventListener(Event.ENTER_FRAME, onEnterFrame);
+ _thumb.addEventListener(MouseEvent.MOUSE_DOWN, onThumbMouseDown);
+ _thumb.addEventListener(MouseEvent.MOUSE_UP, onThumbMouseUp);
+ _thumb.addEventListener(MouseEvent.MOUSE_OVER, onThumbHover);
+ _thumb.addEventListener(MouseEvent.MOUSE_OUT, onThumbMouseOut);
+ _thumb.addEventListener(MouseEvent.MOUSE_MOVE, onTrackMouseMove);
+ _thumb.addEventListener(MouseEvent.MOUSE_OUT, onTrackMouseOut);
+ _track.addEventListener(MouseEvent.CLICK, onTrackClick);
+ _track.addEventListener(MouseEvent.MOUSE_MOVE, onTrackMouseMove);
+ _track.addEventListener(MouseEvent.MOUSE_OUT, onTrackMouseOut);
+ _playControl.addEventListener(MouseEvent.CLICK, onPlayClick);
+ _pauseControl.addEventListener(MouseEvent.CLICK, onPauseClick);
+ _aspectRatioControl.addEventListener(MouseEvent.CLICK, onAspectRatioClick);
+ _fullscreenControl.addEventListener(MouseEvent.CLICK, onFullscreenClick);
+ _volumeIcon.addEventListener(MouseEvent.CLICK, onVolumeIconClick);
+ _volumeTrack.addEventListener(MouseEvent.CLICK, onVolumeTrackClick);
+
+ _player.addEventListener(PlayerEvents.MOUSE_HIDE, onPlayerMouseHide);
+ _player.addEventListener(PlayerEvents.MOUSE_SHOW, onPlayerMouseShow);
+ _player.addEventListener(PlayerEvents.MEDIA_INITIALIZED, onPlayerMediaInitialized);
+ _player.addEventListener(PlayerEvents.BUFFERING, onPlayerBuffering);
+ _player.addEventListener(PlayerEvents.NOT_BUFFERING, onPlayerNotBuffering);
+ _player.addEventListener(PlayerEvents.RESIZE, onPlayerResize);
+ _player.addEventListener(PlayerEvents.PLAY_PAUSE, onPlayerPlayPause);
+ _player.addEventListener(PlayerEvents.PLAYBACK_FINISHED, onPlayerPlaybackFinished);
+ _player.addEventListener(PlayerEvents.CONNECTION_FAILED, onPlayerStreamNotFound);
+ _player.addEventListener(PlayerEvents.ASPECT_RATIO, onPlayerAspectRatio);
+
+ _stage.addEventListener(MouseEvent.MOUSE_UP, onThumbMouseUp);
+ _stage.addEventListener(MouseEvent.MOUSE_OUT, onThumbMouseUp);
+ _stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
+ _stage.addEventListener(Event.RESIZE, onStageResize);
+
+ _hideControlsTimer.addEventListener(TimerEvent.TIMER, hideControlsTimer);
+ _hideAspectRatioLabelTimer.addEventListener(TimerEvent.TIMER, hideAspectRatioLabelTimer);
+
+ _hideControlsTimer.start();
+ //}
+ }
+ //}
+
+
+ //{Timers
+ /**
+ * Hides the playing controls when not moving mouse.
+ * @param event The timer event associated
+ */
+ private function hideControlsTimer(event:TimerEvent):Void
+ {
+ if (_player.isPlaying())
+ {
+ if (_controlsVisible)
+ {
+ if (_stage.mouseX < _controlsBar.x ||
+ _stage.mouseX >= _stage.stageWidth - 1 ||
+ _stage.mouseY >= _stage.stageHeight - 1 ||
+ _stage.mouseY <= 1
+ )
+ {
+ _controlsVisible = false;
+ }
+ }
+ else
+ {
+ hideControls();
+ _hideControlsTimer.stop();
+ }
+ }
+ }
+
+ /**
+ * Hides aspect ratio label
+ * @param event
+ */
+ private function hideAspectRatioLabelTimer(event:TimerEvent):Void
+ {
+ //wait till fade in effect finish
+ if (_aspectRatioLabelContainer.alpha >= 1)
+ {
+ Animation.fadeOut(_aspectRatioLabelContainer, 300);
+ _hideAspectRatioLabelTimer.stop();
+ }
+ }
+ //}
+
+
+ //{Events
+ /**
+ * Keeps syncronized various elements of the controls like the thumb and download track bar
+ * @param event
+ */
+ private function onEnterFrame(event:Event):Void
+ {
+ if(_player.getDuration() > 0) {
+ if (_scrubbing)
+ {
+ _player.seek(((_thumb.x - _track.x) / _track.width) * _player.getDuration());
+ }
+ else
+ {
+ _currentPlayTimeLabel.text = Utils.formatTime(_player.getCurrentTime());
+ _currentPlayTimeLabel.setTextFormat(_textFormat);
+ _thumb.x = _player.getCurrentTime() / _player.getDuration() * (_track.width-_thumb.width) + _track.x;
+ }
+ }
+
+ _volumeSlider.height = _volumeTrack.height * (_player.getVolume() / 1.0);
+ _volumeSlider.y = (_volumeTrack.y + _volumeTrack.height) - _volumeSlider.height;
+
+ drawDownloadProgress();
+ }
+
+ /**
+ * Show playing controls on mouse movement.
+ * @param event
+ */
+ private function onMouseMove(event:MouseEvent):Void
+ {
+ if (_stage.mouseX >= _controlsBar.x)
+ {
+ if (!_hideControlsTimer.running)
+ {
+ _hideControlsTimer.start();
+ }
+
+ _controlsVisible = true;
+ showControls();
+ }
+ }
+
+ /**
+ * Function fired by a stage resize eventthat redraws the player controls
+ * @param event
+ */
+ private function onStageResize(event:Event):Void
+ {
+ redrawControls();
+ }
+
+ /**
+ * Toggles pause or play
+ * @param event
+ */
+ private function onPlayClick(event:MouseEvent):Void
+ {
+ _player.togglePlay();
+ _playControl.visible = !_player.isPlaying();
+ _pauseControl.visible = _player.isPlaying();
+ }
+
+ /**
+ * Toggles pause or play
+ * @param event
+ */
+ private function onPauseClick(event:MouseEvent):Void
+ {
+ _player.togglePlay();
+ _playControl.visible = !_player.isPlaying();
+ _pauseControl.visible = _player.isPlaying();
+ }
+
+ /**
+ * Toggles betewen aspect ratios
+ * @param event
+ */
+ private function onAspectRatioClick(event:MouseEvent):Void
+ {
+ _player.toggleAspectRatio();
+ }
+
+ /**
+ * Toggles between window and fullscreen mode
+ * @param event
+ */
+ private function onFullscreenClick(event:MouseEvent):Void
+ {
+ _player.toggleFullscreen();
+ }
+
+ /**
+ * Toggles between mute and unmute
+ * @param event
+ */
+ private function onVolumeIconClick(event: MouseEvent):Void
+ {
+ _player.toggleMute();
+ }
+
+ /**
+ * Detect user click on volume track control and change volume according
+ * @param event
+ */
+ private function onVolumeTrackClick(event:MouseEvent):Void
+ {
+ var percent:Float = _volumeTrack.height - _volumeTrack.mouseY;
+ var volume:Float = 1.0 * (percent / _volumeTrack.height);
+
+ _player.setVolume(volume);
+ }
+
+ /**
+ * Display not found message
+ * @param event
+ */
+ private function onPlayerStreamNotFound(event:PlayerEvents):Void
+ {
+ //todo: to work on this
+ }
+
+ /**
+ * Shows the loader bar when buffering
+ * @param event
+ */
+ private function onPlayerBuffering(event:PlayerEvents):Void
+ {
+ _loader.show();
+ }
+
+ /**
+ * Hides loader bar when not buffering
+ * @param event
+ */
+ private function onPlayerNotBuffering(event:PlayerEvents):Void
+ {
+ _loader.hide();
+ }
+
+ /**
+ * Show the selected aspect ratio
+ * @param event
+ */
+ private function onPlayerAspectRatio(event:PlayerEvents):Void
+ {
+ _hideAspectRatioLabelTimer.stop();
+ _aspectRatioLabel.text = _player.getAspectRatioString();
+ drawAspectRatioLabel();
+
+ while (_aspectRatioLabelContainer.visible)
+ {
+ //wait till fade out finishes
+ }
+
+ Animation.fadeIn(_aspectRatioLabelContainer, 300);
+
+ _hideAspectRatioLabelTimer.start();
+ }
+
+ /**
+ * Monitors playbeack when finishes tu update controls
+ * @param event
+ */
+ private function onPlayerPlaybackFinished(event:PlayerEvents):Void
+ {
+ _playControl.visible = !_player.isPlaying();
+ _pauseControl.visible = _player.isPlaying();
+ showControls();
+ }
+
+ /**
+ * Monitors keyboard play pause actions to update icons
+ * @param event
+ */
+ private function onPlayerPlayPause(event:PlayerEvents):Void
+ {
+ _playControl.visible = !_player.isPlaying();
+ _pauseControl.visible = _player.isPlaying();
+ }
+
+ /**
+ * Resizes the video player on windowed mode substracting the seekbar height
+ * @param event
+ */
+ private function onPlayerResize(event:PlayerEvents):Void
+ {
+ if (!_player.isFullscreen())
+ {
+ if (_player.getVideo().y + _player.getVideo().height >= _stage.stageHeight)
+ {
+ _player.getVideo().height = _stage.stageHeight - _seekBar.height;
+ _player.getVideo().width = _player.getVideo().height * _player.getAspectRatio();
+
+ _player.getVideo().x = (_stage.stageWidth / 2) - (_player.getVideo().width / 2);
+ }
+ }
+ }
+
+ /**
+ * Updates media total time duration.
+ * @param event
+ */
+ private function onPlayerMediaInitialized(event:PlayerEvents):Void
+ {
+ _totalPlayTimeLabel.text = Utils.formatTime(event.duration);
+ _totalPlayTimeLabel.setTextFormat(_textFormat);
+
+ _playControl.visible = !_player.isPlaying();
+ _pauseControl.visible = _player.isPlaying();
+ }
+
+ /**
+ * Hides seekbar if on fullscreen.
+ * @param event
+ */
+ private function onPlayerMouseHide(event:PlayerEvents):Void
+ {
+ if (_seekBar.visible && _player.isFullscreen())
+ {
+ Animation.slideOut(_seekBar, "bottom", 1000);
+ }
+ }
+
+ /**
+ * Shows seekbar
+ * @param event
+ */
+ private function onPlayerMouseShow(event:PlayerEvents):Void
+ {
+ //Only use slidein effect on fullscreen since switching to windowed mode on
+ //hardware scaling causes a bug by a slow response on stage height changes
+ if (_player.isFullscreen() && !_seekBar.visible)
+ {
+ Animation.slideIn(_seekBar, "bottom",1000);
+ }
+ else
+ {
+ _seekBar.visible = true;
+ }
+ }
+
+ /**
+ * Translates a user click in to time and seeks to it
+ * @param event
+ */
+ private function onTrackClick(event:MouseEvent):Void
+ {
+ var clickPosition:Float = _track.mouseX;
+ _player.seek(_player.getDuration() * (clickPosition / _track.width));
+ }
+
+ /**
+ * Shows a small tooltip showing the time calculated by mouse position
+ * @param event
+ */
+ private function onTrackMouseMove(event:MouseEvent):Void
+ {
+ var clickPosition:Float = _track.mouseX;
+ _seekPlayTimeLabel.text = Utils.formatTime(_player.getDuration() * (clickPosition / _track.width));
+ _seekPlayTimeLabel.setTextFormat(_textFormat);
+
+ _seekPlayTimeLabel.y = _stage.stageHeight - _seekBar.height - _seekPlayTimeLabel.height - 1;
+ _seekPlayTimeLabel.x = clickPosition + (_seekPlayTimeLabel.width / 2);
+
+ _seekPlayTimeLabel.backgroundColor = _brightColor;
+ _seekPlayTimeLabel.background = true;
+ _seekPlayTimeLabel.textColor = _controlColor;
+ _seekPlayTimeLabel.borderColor = _darkColor;
+ _seekPlayTimeLabel.border = true;
+
+ if (!_seekPlayTimeLabel.visible)
+ {
+ Animation.fadeIn(_seekPlayTimeLabel, 300);
+ }
+ }
+
+ /**
+ * Hides the tooltip that shows the time calculated by mouse position
+ * @param event
+ */
+ private function onTrackMouseOut(event:MouseEvent):Void
+ {
+ Animation.fadeOut(_seekPlayTimeLabel, 300);
+ }
+
+ /**
+ * Enables dragging of thumb for seeking media
+ * @param event
+ */
+ private function onThumbMouseDown(event:MouseEvent):Void
+ {
+ _scrubbing = true;
+ var rectangle:Rectangle = new Rectangle(_track.x, _track.y, _track.width-_thumb.width, 0);
+ _thumb.startDrag(false, rectangle);
+ }
+
+ /**
+ * Changes thumb seek control to hover color
+ * @param event
+ */
+ private function onThumbHover(event:MouseEvent):Void
+ {
+ _thumb.graphics.lineStyle();
+ _thumb.graphics.beginFill(_hoverColor);
+ _thumb.graphics.drawRect(0, (_seekBar.height/2)-(10/2), 10, 10);
+ _thumb.graphics.endFill();
+ }
+
+ /**
+ * Changes thumb seek control to control color
+ * @param event
+ */
+ private function onThumbMouseOut(event:MouseEvent):Void
+ {
+ _thumb.graphics.lineStyle();
+ _thumb.graphics.beginFill(_controlColor);
+ _thumb.graphics.drawRect(0, (_seekBar.height/2)-(10/2), 10, 10);
+ _thumb.graphics.endFill();
+ }
+
+ /**
+ * Disables dragging of thumb
+ * @param event
+ */
+ private function onThumbMouseUp(event:MouseEvent):Void
+ {
+ _scrubbing = false;
+ _thumb.stopDrag( );
+ }
+ //}
+
+
+ //{Drawing functions
+ /**
+ * Clears all current graphics a draw new ones
+ */
+ private function redrawControls():Void
+ {
+ drawSeekControls();
+ drawPlayingControls();
+ drawAspectRatioLabel();
+ }
+
+ /**
+ * Draws the download progress track bar
+ */
+ private function drawDownloadProgress():Void
+ {
+ if (_player.getBytesTotal() > 0)
+ {
+ var bytesLoaded:Float = _player.getBytesLoaded();
+ var bytesTotal:Float = _player.getBytesTotal();
+
+ _percentLoaded = bytesLoaded / bytesTotal;
+ }
+
+ var position:Float = _player.getStartTime() / _player.getDuration();
+ //var startPosition:Float = (position * _track.width) + _track.x; //Old way
+ var startPosition:Float = (position > 0?(position * _track.width):0) + _track.x;
+
+ _trackDownloaded.graphics.clear();
+ _trackDownloaded.graphics.lineStyle();
+ _trackDownloaded.x = startPosition;
+ _trackDownloaded.graphics.beginFill(_brightColor, 0xFFFFFF);
+ _trackDownloaded.graphics.drawRect(0, (_seekBar.height / 2) - (10 / 2), ((_track.width + _track.x) - _trackDownloaded.x) * _percentLoaded, 10);
+ _trackDownloaded.graphics.endFill();
+ }
+
+ /**
+ * Draws all seekbar controls
+ */
+ private function drawSeekControls()
+ {
+ //Reset sprites for redraw
+ _seekBar.graphics.clear();
+ _track.graphics.clear();
+ _thumb.graphics.clear();
+
+ //Draw seek bar
+ var _seekBarWidth:UInt = _stage.stageWidth;
+ var _seekBarHeight:UInt = 25;
+ _seekBar.x = 0;
+ _seekBar.y = _stage.stageHeight - _seekBarHeight;
+ var matrix:Matrix = new Matrix( );
+ matrix.createGradientBox(_seekBarWidth, _seekBarHeight, Utils.degreesToRadians(90), 0, 0);
+ var colors:Array = [_brightColor, _darkColor];
+ var alphas:Array = [1, 1];
+ var ratios:Array = [0, 255];
+ _seekBar.graphics.lineStyle();
+ _seekBar.graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix);
+ _seekBar.graphics.drawRect(0, 0, _seekBarWidth, _seekBarHeight);
+ _seekBar.graphics.endFill();
+
+ _textFormat.color = _controlColor;
+
+ //Draw current play time label
+ _currentPlayTimeLabel.y = _seekBarHeight - (_seekBarHeight / 2) - (_currentPlayTimeLabel.height / 2);
+ _currentPlayTimeLabel.antiAliasType = AntiAliasType.ADVANCED;
+ _currentPlayTimeLabel.setTextFormat(_textFormat);
+
+ //Draw total play time label
+ _totalPlayTimeLabel.x = _seekBarWidth - _totalPlayTimeLabel.width;
+ _totalPlayTimeLabel.y = _seekBarHeight - (_seekBarHeight / 2) - (_totalPlayTimeLabel.height / 2);
+ _totalPlayTimeLabel.antiAliasType = AntiAliasType.ADVANCED;
+ _totalPlayTimeLabel.setTextFormat(_textFormat);
+
+ //Draw download progress
+ drawDownloadProgress();
+
+ //Draw track place holder for drag
+ _track.x = _currentPlayTimeLabel.width;
+ _track.graphics.lineStyle(1, _controlColor);
+ _track.graphics.beginFill(_darkColor, 0);
+ _track.graphics.drawRect(0, (_seekBarHeight / 2) - (10 / 2), _seekBarWidth - _currentPlayTimeLabel.width - _totalPlayTimeLabel.width, 10);
+ _track.graphics.endFill();
+
+ //Draw thumb
+ _thumb.x = _currentPlayTimeLabel.width;
+ _thumb.graphics.lineStyle();
+ _thumb.graphics.beginFill(_controlColor);
+ _thumb.graphics.drawRect(0, (_seekBarHeight/2)-(10/2), 10, 10);
+ _thumb.graphics.endFill();
+ }
+
+ /**
+ * Draws control bar player controls
+ */
+ private function drawPlayingControls():Void
+ {
+ //Reset sprites for redraw
+ _controlsBar.graphics.clear();
+ _volumeTrack.graphics.clear();
+ _volumeSlider.graphics.clear();
+
+ //Draw controls bar
+ var barMargin = _stage.stageHeight < 330 ? 5 : 25;
+ var barHeight = _stage.stageHeight - _seekBar.height - (barMargin * 2);
+ var barWidth = _stage.stageHeight < 330 ? 45 : 60;
+ _controlsBar.x = (_stage.stageWidth - barWidth) + 20;
+ _controlsBar.y = barMargin;
+
+ var matrix:Matrix = new Matrix( );
+ matrix.createGradientBox(barWidth, barHeight, Utils.degreesToRadians(0), 0, barHeight);
+ var colors:Array = [_brightColor, _darkColor];
+ var alphas:Array = [0.75, 0.75];
+ var ratios:Array = [0, 255];
+ _controlsBar.graphics.lineStyle();
+ _controlsBar.graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix);
+ _controlsBar.graphics.drawRoundRect(0, 0, barWidth, barHeight, 20, 20);
+ _controlsBar.graphics.endFill();
+
+ var topMargin:Float = _stage.stageHeight < 330 ? 5 : 10;
+ var barCenter:Float = (barWidth - 20) / 2;
+ var buttonSize:Float = ((80 / 100) * (barWidth - 20));
+ var buttonX:Float = buttonSize / 2;
+
+ //Draw playbutton
+ _playControl.setNormalColor(_controlColor);
+ _playControl.setHoverColor(_hoverColor);
+ _playControl.setPosition(barCenter - buttonX, topMargin);
+ _playControl.setSize(buttonSize, buttonSize);
+
+ //Draw pausebutton
+ _pauseControl.setNormalColor(_controlColor);
+ _pauseControl.setHoverColor(_hoverColor);
+ _pauseControl.setPosition(_playControl.x, topMargin);
+ _pauseControl.setSize(buttonSize, buttonSize);
+
+ //Draw aspec ratio button
+ _aspectRatioControl.setNormalColor(_controlColor);
+ _aspectRatioControl.setHoverColor(_hoverColor);
+ _aspectRatioControl.setPosition(_playControl.x, (_playControl.y + buttonSize) + topMargin);
+ _aspectRatioControl.setSize(buttonSize, buttonSize);
+
+ //Draw fullscreen button
+ _fullscreenControl.setNormalColor(_controlColor);
+ _fullscreenControl.setHoverColor(_hoverColor);
+ _fullscreenControl.setPosition(_playControl.x, (_aspectRatioControl.y + _aspectRatioControl.height) + topMargin);
+ _fullscreenControl.setSize(buttonSize, buttonSize);
+
+ //Draw volume icon
+ _volumeIcon.setNormalColor(_controlColor);
+ _volumeIcon.setHoverColor(_hoverColor);
+ _volumeIcon.setPosition(_playControl.x, barHeight - _playControl.height - topMargin);
+ _volumeIcon.setSize(buttonSize, buttonSize);
+
+ //Draw volume track
+ _volumeTrack.x = _playControl.x;
+ _volumeTrack.y = (_fullscreenControl.y + _fullscreenControl.height) + topMargin;
+ _volumeTrack.graphics.lineStyle(1, _controlColor);
+ _volumeTrack.graphics.beginFill(0x000000, 0);
+ _volumeTrack.graphics.drawRect(0, 0, _playControl.width / 2, _volumeIcon.y - (_fullscreenControl.y + _fullscreenControl.height) - (topMargin*2));
+ _volumeTrack.graphics.endFill();
+ _volumeTrack.x = barCenter - (_volumeTrack.width / 2);
+
+ //Draw volume slider
+ _volumeSlider.x = _volumeTrack.x;
+ _volumeSlider.y = _volumeTrack.y;
+ _volumeSlider.graphics.lineStyle();
+ _volumeSlider.graphics.beginFill(_controlColor, 1);
+ _volumeSlider.graphics.drawRect(0, 0, _volumeTrack.width, _volumeTrack.height);
+ _volumeSlider.graphics.endFill();
+
+ }
+
+ private function drawAspectRatioLabel():Void
+ {
+ _aspectRatioLabelContainer.graphics.clear();
+ _aspectRatioLabelContainer.visible = false;
+
+ //Update aspect ratio label
+ var textFormat:TextFormat = new TextFormat();
+ textFormat.font = "arial";
+ textFormat.bold = true;
+ textFormat.size = 40;
+ textFormat.color = _controlColor;
+
+ _aspectRatioLabel.setTextFormat(textFormat);
+ _aspectRatioLabel.x = (_stage.stageWidth / 2) - (_aspectRatioLabel.width / 2);
+ _aspectRatioLabel.y = (_stage.stageHeight / 2) - (_aspectRatioLabel.height / 2);
+
+ //Draw aspect ratio label container
+ _aspectRatioLabelContainer.x = _aspectRatioLabel.x - 10;
+ _aspectRatioLabelContainer.y = _aspectRatioLabel.y - 10;
+ _aspectRatioLabelContainer.graphics.lineStyle(3, _controlColor);
+ _aspectRatioLabelContainer.graphics.beginFill(_brightColor, 1);
+ _aspectRatioLabelContainer.graphics.drawRoundRect(0, 0, _aspectRatioLabel.width + 20, _aspectRatioLabel.height + 20, 15, 15);
+ _aspectRatioLabelContainer.graphics.endFill();
+
+ _aspectRatioLabel.x = 10;
+ _aspectRatioLabel.y = 10;
+ }
+ //}
+
+
+ //{Private Methods
+ /**
+ * Hide the play controls bar
+ */
+ private function hideControls():Void
+ {
+ if(_controlsBar.visible)
+ {
+ drawPlayingControls();
+ Animation.slideOut(_controlsBar, "right", 800);
+ }
+ }
+
+ /**
+ * Shows play controls bar
+ */
+ private function showControls():Void
+ {
+ if(!_controlsBar.visible)
+ {
+ drawPlayingControls();
+ Animation.slideIn(_controlsBar, "right", 800);
+ }
+ }
+ //}
+
+
+ //{Setters
+ /**
+ * Sets the player colors and redraw them
+ * @param colors Array of colors in the following order: darkColor, brightColor, controlColor, hoverColor
+ */
+ public function setControlColors(colors:Array):Void
+ {
+ _darkColor = colors[0].length > 0? Std.parseInt("0x" + colors[0]) : 0x000000;
+ _brightColor = colors[1].length > 0? Std.parseInt("0x" + colors[1]) : 0x4c4c4c;
+ _controlColor = colors[2].length > 0? Std.parseInt("0x" + colors[2]) : 0xFFFFFF;
+ _hoverColor = colors[3].length > 0? Std.parseInt("0x" + colors[3]) : 0x67A8C1;
+
+ var loaderColors:Array = ["", ""];
+ loaderColors[0] = colors[1];
+ loaderColors[1] = colors[2];
+ _loader.setColors(loaderColors);
+
+ redrawControls();
+ }
+
+ /**
+ * To set the duration label when autostart parameter is false
+ * @param duration in seconds or formatted string in format hh:mm:ss
+ */
+ public function setDurationLabel(duration:String):Void
+ {
+ //Person passed time already formatted
+ if (duration.indexOf(":") != -1)
+ {
+ _totalPlayTimeLabel.text = duration;
+ }
+
+ //Time passed in seconds
+ else
+ {
+ _totalPlayTimeLabel.text = Std.string(Utils.formatTime(Std.parseFloat(duration)));
+ }
+
+ _totalPlayTimeLabel.setTextFormat(_textFormat);
+ }
+ //}
+
+}
\ No newline at end of file
diff --git a/lib/Jaris/src/jaris/player/controls/FullscreenIcon.hx b/lib/Jaris/src/jaris/player/controls/FullscreenIcon.hx
new file mode 100644
index 00000000..95da6e51
--- /dev/null
+++ b/lib/Jaris/src/jaris/player/controls/FullscreenIcon.hx
@@ -0,0 +1,114 @@
+/**
+ * @author Jefferson González
+ * @copyright 2010 Jefferson González
+ *
+ * @license
+ * This file is part of Jaris FLV Player.
+ *
+ * Jaris FLV Player is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License or GNU LESSER GENERAL
+ * PUBLIC LICENSE as published by the Free Software Foundation, either version
+ * 3 of the License, or (at your option) any later version.
+ *
+ * Jaris FLV Player is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License and
+ * GNU LESSER GENERAL PUBLIC LICENSE along with Jaris FLV Player. If not,
+ * see .
+ */
+
+package jaris.player.controls;
+import flash.display.Sprite;
+import flash.events.MouseEvent;
+
+class FullscreenIcon extends Sprite
+{
+ private var _width:Float;
+ private var _height:Float;
+ private var _normalColor:UInt;
+ private var _hoverColor:UInt;
+
+ public function new(x:Float, y:Float, width:Float, height:Float, normalColor:UInt, hoverColor:UInt)
+ {
+ super();
+
+ this.x = x;
+ this.y = y;
+ this.buttonMode = true;
+ this.useHandCursor = true;
+ this.tabEnabled = false;
+
+ _width = width;
+ _height = height;
+ _normalColor = normalColor;
+ _hoverColor = hoverColor;
+
+ addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
+ addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
+
+ draw(_normalColor);
+ }
+
+ private function onMouseOver(event:MouseEvent):Void
+ {
+ draw(_hoverColor);
+ }
+
+ private function onMouseOut(event:MouseEvent):Void
+ {
+ draw(_normalColor);
+ }
+
+ //{Private Methods
+ private function draw(color:UInt):Void
+ {
+ graphics.clear();
+
+ graphics.lineStyle(2, color);
+ graphics.beginFill(0x000000, 0);
+ graphics.drawRoundRect(0, 0, _width, _height, 6, 6);
+ graphics.endFill();
+
+ graphics.lineStyle();
+ graphics.beginFill(color, 1);
+ graphics.drawRoundRect(3, 3, 4, 4, 2, 2);
+ graphics.drawRoundRect(width - 9, 3, 4, 4, 2, 2);
+ graphics.drawRoundRect(3, height - 9, 4, 4, 2, 2);
+ graphics.drawRoundRect(width - 9, height - 9, 4, 4, 2, 2);
+ graphics.endFill();
+ }
+ //}
+
+ //{Setters
+ public function setNormalColor(color:UInt):Void
+ {
+ _normalColor = color;
+ draw(_normalColor);
+ }
+
+ public function setHoverColor(color:UInt):Void
+ {
+ _hoverColor = color;
+ draw(_hoverColor);
+ }
+
+ public function setPosition(x:Float, y:Float):Void
+ {
+ this.x = x;
+ this.y = y;
+
+ draw(_normalColor);
+ }
+
+ public function setSize(width:Float, height:Float):Void
+ {
+ _width = width;
+ _height = height;
+
+ draw(_normalColor);
+ }
+ //}
+}
\ No newline at end of file
diff --git a/lib/Jaris/src/jaris/player/controls/PauseIcon.hx b/lib/Jaris/src/jaris/player/controls/PauseIcon.hx
new file mode 100644
index 00000000..c16a113e
--- /dev/null
+++ b/lib/Jaris/src/jaris/player/controls/PauseIcon.hx
@@ -0,0 +1,112 @@
+/**
+ * @author Jefferson González
+ * @copyright 2010 Jefferson González
+ *
+ * @license
+ * This file is part of Jaris FLV Player.
+ *
+ * Jaris FLV Player is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License or GNU LESSER GENERAL
+ * PUBLIC LICENSE as published by the Free Software Foundation, either version
+ * 3 of the License, or (at your option) any later version.
+ *
+ * Jaris FLV Player is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License and
+ * GNU LESSER GENERAL PUBLIC LICENSE along with Jaris FLV Player. If not,
+ * see .
+ */
+
+package jaris.player.controls;
+import flash.display.Sprite;
+import flash.events.MouseEvent;
+
+class PauseIcon extends Sprite
+{
+ private var _width:Float;
+ private var _height:Float;
+ private var _normalColor:UInt;
+ private var _hoverColor:UInt;
+
+ public function new(x:Float, y:Float, width:Float, height:Float, normalColor:UInt, hoverColor:UInt)
+ {
+ super();
+
+ this.x = x;
+ this.y = y;
+ this.buttonMode = true;
+ this.useHandCursor = true;
+ this.tabEnabled = false;
+
+ _width = width;
+ _height = height;
+ _normalColor = normalColor;
+ _hoverColor = hoverColor;
+
+ addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
+ addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
+
+ draw(_normalColor);
+ }
+
+ private function onMouseOver(event:MouseEvent):Void
+ {
+ draw(_hoverColor);
+ }
+
+ private function onMouseOut(event:MouseEvent):Void
+ {
+ draw(_normalColor);
+ }
+
+ //{Private Methods
+ private function draw(color:UInt):Void
+ {
+ graphics.clear();
+
+ graphics.lineStyle();
+ graphics.beginFill(color);
+ graphics.drawRoundRect(0, 0, (33 / 100) * _width, _height, 6, 6);
+ graphics.drawRoundRect(_width - ((33 / 100) * _width), 0, (33 / 100) * _width, _height, 6, 6);
+ graphics.endFill();
+
+ graphics.lineStyle();
+ graphics.beginFill(color, 0);
+ graphics.drawRect(0, 0, _width, _height);
+ graphics.endFill();
+ }
+ //}
+
+ //{Setters
+ public function setNormalColor(color:UInt):Void
+ {
+ _normalColor = color;
+ draw(_normalColor);
+ }
+
+ public function setHoverColor(color:UInt):Void
+ {
+ _hoverColor = color;
+ draw(_hoverColor);
+ }
+
+ public function setPosition(x:Float, y:Float):Void
+ {
+ this.x = x;
+ this.y = y;
+
+ draw(_normalColor);
+ }
+
+ public function setSize(width:Float, height:Float):Void
+ {
+ _width = width;
+ _height = height;
+
+ draw(_normalColor);
+ }
+ //}
+}
\ No newline at end of file
diff --git a/lib/Jaris/src/jaris/player/controls/PlayIcon.hx b/lib/Jaris/src/jaris/player/controls/PlayIcon.hx
new file mode 100644
index 00000000..0d506d98
--- /dev/null
+++ b/lib/Jaris/src/jaris/player/controls/PlayIcon.hx
@@ -0,0 +1,107 @@
+/**
+ * @author Jefferson González
+ * @copyright 2010 Jefferson González
+ *
+ * @license
+ * This file is part of Jaris FLV Player.
+ *
+ * Jaris FLV Player is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License or GNU LESSER GENERAL
+ * PUBLIC LICENSE as published by the Free Software Foundation, either version
+ * 3 of the License, or (at your option) any later version.
+ *
+ * Jaris FLV Player is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License and
+ * GNU LESSER GENERAL PUBLIC LICENSE along with Jaris FLV Player. If not,
+ * see .
+ */
+
+package jaris.player.controls;
+import flash.display.Sprite;
+import flash.events.MouseEvent;
+
+class PlayIcon extends Sprite
+{
+ private var _width:Float;
+ private var _height:Float;
+ private var _normalColor:UInt;
+ private var _hoverColor:UInt;
+
+ public function new(x:Float, y:Float, width:Float, height:Float, normalColor:UInt, hoverColor:UInt)
+ {
+ super();
+
+ this.x = x;
+ this.y = y;
+ this.buttonMode = true;
+ this.useHandCursor = true;
+ this.tabEnabled = false;
+
+ _width = width;
+ _height = height;
+ _normalColor = normalColor;
+ _hoverColor = hoverColor;
+
+ addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
+ addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
+
+ draw(_normalColor);
+ }
+
+ private function onMouseOver(event:MouseEvent):Void
+ {
+ draw(_hoverColor);
+ }
+
+ private function onMouseOut(event:MouseEvent):Void
+ {
+ draw(_normalColor);
+ }
+
+ //{Private Methods
+ private function draw(color:UInt):Void
+ {
+ graphics.clear();
+ graphics.lineStyle();
+ graphics.beginFill(color);
+ graphics.lineTo(0, _height);
+ graphics.lineTo(_width, _height / 2);
+ graphics.lineTo(0, 0);
+ graphics.endFill();
+ }
+ //}
+
+ //{Setters
+ public function setNormalColor(color:UInt):Void
+ {
+ _normalColor = color;
+ draw(_normalColor);
+ }
+
+ public function setHoverColor(color:UInt):Void
+ {
+ _hoverColor = color;
+ draw(_hoverColor);
+ }
+
+ public function setPosition(x:Float, y:Float):Void
+ {
+ this.x = x;
+ this.y = y;
+
+ draw(_normalColor);
+ }
+
+ public function setSize(width:Float, height:Float):Void
+ {
+ _width = width;
+ _height = height;
+
+ draw(_normalColor);
+ }
+ //}
+}
\ No newline at end of file
diff --git a/lib/Jaris/src/jaris/player/controls/VolumeIcon.hx b/lib/Jaris/src/jaris/player/controls/VolumeIcon.hx
new file mode 100644
index 00000000..e2eed7d9
--- /dev/null
+++ b/lib/Jaris/src/jaris/player/controls/VolumeIcon.hx
@@ -0,0 +1,110 @@
+/**
+ * @author Jefferson González
+ * @copyright 2010 Jefferson González
+ *
+ * @license
+ * This file is part of Jaris FLV Player.
+ *
+ * Jaris FLV Player is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License or GNU LESSER GENERAL
+ * PUBLIC LICENSE as published by the Free Software Foundation, either version
+ * 3 of the License, or (at your option) any later version.
+ *
+ * Jaris FLV Player is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License and
+ * GNU LESSER GENERAL PUBLIC LICENSE along with Jaris FLV Player. If not,
+ * see .
+ */
+
+package jaris.player.controls;
+import flash.display.Sprite;
+import flash.events.MouseEvent;
+
+class VolumeIcon extends Sprite
+{
+ private var _width:Float;
+ private var _height:Float;
+ private var _normalColor:UInt;
+ private var _hoverColor:UInt;
+
+ public function new(x:Float, y:Float, width:Float, height:Float, normalColor:UInt, hoverColor:UInt)
+ {
+ super();
+
+ this.x = x;
+ this.y = y;
+ this.buttonMode = true;
+ this.useHandCursor = true;
+ this.tabEnabled = false;
+
+ _width = width;
+ _height = height;
+ _normalColor = normalColor;
+ _hoverColor = hoverColor;
+
+ addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
+ addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
+
+ draw(_normalColor);
+ }
+
+ private function onMouseOver(event:MouseEvent):Void
+ {
+ draw(_hoverColor);
+ }
+
+ private function onMouseOut(event:MouseEvent):Void
+ {
+ draw(_normalColor);
+ }
+
+ //{Private Methods
+ private function draw(color:UInt):Void
+ {
+ graphics.clear();
+
+ graphics.lineStyle();
+ graphics.beginFill(color, 1);
+ graphics.drawRect(0, ((50 / 100) * _height) / 2, _width / 2, ((50 / 100) * _height));
+ graphics.moveTo(_width / 2, ((50 / 100) * _height)/2);
+ graphics.lineTo(_width, 0);
+ graphics.lineTo(_width, _height);
+ graphics.lineTo(_width / 2, ((50 / 100) * _height) + (((50 / 100) * _height) / 2));
+ graphics.endFill();
+ }
+ //}
+
+ //{Setters
+ public function setNormalColor(color:UInt):Void
+ {
+ _normalColor = color;
+ draw(_normalColor);
+ }
+
+ public function setHoverColor(color:UInt):Void
+ {
+ _hoverColor = color;
+ draw(_hoverColor);
+ }
+
+ public function setPosition(x:Float, y:Float):Void
+ {
+ this.x = x;
+ this.y = y;
+
+ draw(_normalColor);
+ }
+
+ public function setSize(width:Float, height:Float):Void
+ {
+ _width = width;
+ _height = height;
+
+ draw(_normalColor);
+ }
+ //}
+}
\ No newline at end of file
diff --git a/lib/Jaris/src/jaris/player/newcontrols/AspectRatioIcon.hx b/lib/Jaris/src/jaris/player/newcontrols/AspectRatioIcon.hx
new file mode 100644
index 00000000..10f91f43
--- /dev/null
+++ b/lib/Jaris/src/jaris/player/newcontrols/AspectRatioIcon.hx
@@ -0,0 +1,130 @@
+/**
+ * @author Jefferson González
+ * @copyright 2010 Jefferson González
+ *
+ * @license
+ * This file is part of Jaris FLV Player.
+ *
+ * Jaris FLV Player is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License or GNU LESSER GENERAL
+ * PUBLIC LICENSE as published by the Free Software Foundation, either version
+ * 3 of the License, or (at your option) any later version.
+ *
+ * Jaris FLV Player is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License and
+ * GNU LESSER GENERAL PUBLIC LICENSE along with Jaris FLV Player. If not,
+ * see .
+ */
+
+package jaris.player.newcontrols;
+import flash.display.Sprite;
+import flash.events.MouseEvent;
+import flash.geom.Matrix;
+import jaris.utils.Utils;
+import flash.display.GradientType;
+
+class AspectRatioIcon extends Sprite
+{
+ private var _width:Float;
+ private var _height:Float;
+ private var _normalColor:UInt;
+ private var _hoverColor:UInt;
+
+ public function new(x:Float, y:Float, width:Float, height:Float, normalColor:UInt, hoverColor:UInt)
+ {
+ super();
+
+ this.x = x;
+ this.y = y;
+ this.buttonMode = true;
+ this.useHandCursor = true;
+ this.tabEnabled = false;
+
+ _width = width;
+ _height = height;
+ _normalColor = normalColor;
+ _hoverColor = hoverColor;
+
+ addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
+ addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
+
+ draw(_normalColor);
+ }
+
+ private function onMouseOver(event:MouseEvent):Void
+ {
+ draw(_hoverColor);
+ }
+
+ private function onMouseOut(event:MouseEvent):Void
+ {
+ draw(_normalColor);
+ }
+
+ //{Private Methods
+ private function draw(color:UInt):Void
+ {
+ graphics.clear();
+
+ graphics.lineStyle(0, color, 0.0);
+ graphics.beginFill(color, 0);
+ graphics.drawRect(0, 0, _width, _height);
+ graphics.endFill();
+
+ var matrix:Matrix = new Matrix( );
+ matrix.createGradientBox(_width, _height, Utils.degreesToRadians(-90), _width, 0);
+ var colors:Array = [color, color];
+ var alphas:Array = [0.75, 1];
+ var ratios:Array = [0, 255];
+
+ var innerWidth:Float = (70 / 100) * width;
+ var innerHeight:Float = (40 / 100) * height;
+ var innerX:Float = (width / 2) - (innerWidth / 2) + 1 ;
+ var innerY:Float = (height / 2) - (innerHeight / 2) + 1;
+
+ graphics.lineStyle();
+ graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix);
+ //graphics.beginFill(color, 1);
+ graphics.drawRect(0, 0, 1, _height+1);
+ graphics.drawRect(0, 0, _width+1, 1);
+ graphics.drawRect(_width+1, 0, 1, _height+1);
+ graphics.drawRect(0, _height+1, _width+1, 1);
+ graphics.drawRect(innerX, innerY, innerWidth, innerHeight);
+ graphics.endFill();
+ }
+ //}
+
+ //{Setters
+ public function setNormalColor(color:UInt):Void
+ {
+ _normalColor = color;
+ draw(_normalColor);
+ }
+
+ public function setHoverColor(color:UInt):Void
+ {
+ _hoverColor = color;
+ draw(_hoverColor);
+ }
+
+ public function setPosition(x:Float, y:Float):Void
+ {
+ this.x = x;
+ this.y = y;
+
+ draw(_normalColor);
+ }
+
+ public function setSize(width:Float, height:Float):Void
+ {
+ _width = width;
+ _height = height;
+
+ draw(_normalColor);
+ }
+ //}
+}
\ No newline at end of file
diff --git a/lib/Jaris/src/jaris/player/newcontrols/FullscreenIcon.hx b/lib/Jaris/src/jaris/player/newcontrols/FullscreenIcon.hx
new file mode 100644
index 00000000..1749b02d
--- /dev/null
+++ b/lib/Jaris/src/jaris/player/newcontrols/FullscreenIcon.hx
@@ -0,0 +1,130 @@
+/**
+ * @author Jefferson González
+ * @copyright 2010 Jefferson González
+ *
+ * @license
+ * This file is part of Jaris FLV Player.
+ *
+ * Jaris FLV Player is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License or GNU LESSER GENERAL
+ * PUBLIC LICENSE as published by the Free Software Foundation, either version
+ * 3 of the License, or (at your option) any later version.
+ *
+ * Jaris FLV Player is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License and
+ * GNU LESSER GENERAL PUBLIC LICENSE along with Jaris FLV Player. If not,
+ * see .
+ */
+
+package jaris.player.newcontrols;
+import flash.display.Sprite;
+import flash.events.MouseEvent;
+import flash.geom.Matrix;
+import jaris.utils.Utils;
+import flash.display.GradientType;
+
+class FullscreenIcon extends Sprite
+{
+ private var _width:Float;
+ private var _height:Float;
+ private var _normalColor:UInt;
+ private var _hoverColor:UInt;
+
+ public function new(x:Float, y:Float, width:Float, height:Float, normalColor:UInt, hoverColor:UInt)
+ {
+ super();
+
+ this.x = x;
+ this.y = y;
+ this.buttonMode = true;
+ this.useHandCursor = true;
+ this.tabEnabled = false;
+
+ _width = width;
+ _height = height;
+ _normalColor = normalColor;
+ _hoverColor = hoverColor;
+
+ addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
+ addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
+
+ draw(_normalColor);
+ }
+
+ private function onMouseOver(event:MouseEvent):Void
+ {
+ draw(_hoverColor);
+ }
+
+ private function onMouseOut(event:MouseEvent):Void
+ {
+ draw(_normalColor);
+ }
+
+ //{Private Methods
+ private function draw(color:UInt):Void
+ {
+ graphics.clear();
+
+ graphics.lineStyle(0, color, 0.0);
+ graphics.beginFill(color, 0);
+ graphics.drawRect(0, 0, _width, _height);
+ graphics.endFill();
+
+ var arrowWidth = Std.int(_width / 2 * 0.8);
+
+ var matrix:Matrix = new Matrix( );
+ matrix.createGradientBox(_width, _height, Utils.degreesToRadians(-90), _width, 0);
+ var colors:Array = [color, color];
+ var alphas:Array = [0.75, 1];
+ var ratios:Array = [0, 255];
+
+ graphics.lineStyle(0, color, 0, true);
+ graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix);
+ //graphics.beginFill(color, 0);
+ graphics.drawRect(0, 0, arrowWidth, 2);
+ graphics.drawRect(0, 2, 2, arrowWidth-2);
+ graphics.drawRect(_width-arrowWidth+1, 0, arrowWidth, 2);
+ graphics.drawRect(_width-1, 2, 2, arrowWidth-2);
+ graphics.drawRect(0, _height-arrowWidth+2, 2, arrowWidth);
+ graphics.drawRect(2, _height, arrowWidth-2, 2);
+ graphics.drawRect(_width-1, _height-arrowWidth+2, 2, arrowWidth-2);
+ graphics.drawRect(_width-arrowWidth+1, _height, arrowWidth, 2);
+ graphics.endFill();
+ }
+ //}
+
+ //{Setters
+ public function setNormalColor(color:UInt):Void
+ {
+ _normalColor = color;
+ draw(_normalColor);
+ }
+
+ public function setHoverColor(color:UInt):Void
+ {
+ _hoverColor = color;
+ draw(_hoverColor);
+ }
+
+ public function setPosition(x:Float, y:Float):Void
+ {
+ this.x = x;
+ this.y = y;
+
+ draw(_normalColor);
+ }
+
+ public function setSize(width:Float, height:Float):Void
+ {
+ _width = width;
+ _height = height;
+
+ draw(_normalColor);
+ }
+ //}
+}
\ No newline at end of file
diff --git a/lib/Jaris/src/jaris/player/newcontrols/Loader.hx b/lib/Jaris/src/jaris/player/newcontrols/Loader.hx
new file mode 100644
index 00000000..18fb2ac1
--- /dev/null
+++ b/lib/Jaris/src/jaris/player/newcontrols/Loader.hx
@@ -0,0 +1,195 @@
+/**
+ * @author Jefferson González
+ * @copyright 2010 Jefferson González
+ *
+ * @license
+ * This file is part of Jaris FLV Player.
+ *
+ * Jaris FLV Player is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License or GNU LESSER GENERAL
+ * PUBLIC LICENSE as published by the Free Software Foundation, either version
+ * 3 of the License, or (at your option) any later version.
+ *
+ * Jaris FLV Player is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License and
+ * GNU LESSER GENERAL PUBLIC LICENSE along with Jaris FLV Player. If not,
+ * see .
+ */
+
+package jaris.player.newcontrols;
+
+import flash.display.MovieClip;
+import flash.display.Sprite;
+import flash.display.Stage;
+import flash.events.Event;
+import flash.Lib;
+import flash.geom.Matrix;
+import jaris.utils.Utils;
+import flash.display.GradientType;
+
+/**
+ * Draws a loading bar
+ */
+class Loader extends Sprite
+{
+ private var _stage:Stage;
+ private var _movieClip:MovieClip;
+ private var _background:Sprite;
+ private var _loaderTrack:Sprite;
+ private var _loaderThumb:Sprite;
+ private var _visible:Bool;
+ private var _darkColor:UInt;
+ private var _controlColor:UInt;
+ private var _seekColor:UInt;
+ private var _forward:Bool;
+
+ public function new()
+ {
+ super();
+
+ _stage = Lib.current.stage;
+ _movieClip = Lib.current;
+
+ _background = new Sprite();
+ addChild(_background);
+
+ _loaderTrack = new Sprite();
+ addChild(_loaderTrack);
+
+ _loaderThumb = new Sprite();
+ addChild(_loaderThumb);
+
+ _darkColor = 0x000000;
+ _controlColor = 0xFFFFFF;
+ _seekColor = 0x747474;
+
+ _forward = true;
+ _visible = true;
+
+ addEventListener(Event.ENTER_FRAME, onEnterFrame);
+ _stage.addEventListener(Event.RESIZE, onResize);
+
+ drawLoader();
+ }
+
+ /**
+ * Animation of a thumb moving on the track
+ * @param event
+ */
+ private function onEnterFrame(event:Event):Void
+ {
+ if (_visible)
+ {
+ if (_forward)
+ {
+ if ((_loaderThumb.x + _loaderThumb.width) >= (_loaderTrack.x + _loaderTrack.width))
+ {
+ _forward = false;
+ }
+ else
+ {
+ _loaderThumb.x += 10;
+ }
+ }
+ else
+ {
+ if (_loaderThumb.x <= _loaderTrack.x)
+ {
+ _forward = true;
+ }
+ else
+ {
+ _loaderThumb.x -= 10;
+ }
+ }
+ }
+ }
+
+ /**
+ * Redraws the loader to match new stage size
+ * @param event
+ */
+ private function onResize(event:Event):Void
+ {
+ drawLoader();
+ }
+
+ /**
+ * Draw loader graphics
+ */
+ private function drawLoader():Void
+ {
+ //Clear graphics
+ _background.graphics.clear();
+ _loaderTrack.graphics.clear();
+ _loaderThumb.graphics.clear();
+
+ //Draw background
+ var backgroundWidth:Float = (65 / 100) * _stage.stageWidth;
+ var backgroundHeight:Float = 30;
+ _background.x = (_stage.stageWidth / 2) - (backgroundWidth / 2);
+ _background.y = (_stage.stageHeight / 2) - (backgroundHeight / 2);
+ _background.graphics.lineStyle();
+ _background.graphics.beginFill(_darkColor, 0.75);
+ _background.graphics.drawRoundRect(0, 0, backgroundWidth, backgroundHeight, 6, 6);
+ _background.graphics.endFill();
+
+ //Draw track
+ var trackWidth:Float = (50 / 100) * _stage.stageWidth;
+ var trackHeight:Float = 11;
+ _loaderTrack.x = (_stage.stageWidth / 2) - (trackWidth / 2);
+ _loaderTrack.y = (_stage.stageHeight / 2) - (trackHeight / 2);
+ _loaderTrack.graphics.lineStyle();
+ _loaderTrack.graphics.beginFill(_seekColor, 0.3);
+ _loaderTrack.graphics.drawRoundRect(0, trackHeight/2/2, trackWidth, trackHeight/2, 5, 5);
+
+ //Draw thumb
+ var matrix:Matrix = new Matrix( );
+ matrix.createGradientBox(trackHeight*3, trackHeight, Utils.degreesToRadians(-90), trackHeight*3, 0);
+ var colors:Array = [_controlColor, _controlColor];
+ var alphas:Array = [0.75, 1];
+ var ratios:Array = [0, 255];
+
+ _loaderThumb.x = _loaderTrack.x;
+ _loaderThumb.y = _loaderTrack.y;
+ _loaderThumb.graphics.lineStyle();
+ _loaderThumb.graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix);
+ //_loaderThumb.graphics.beginFill(_controlColor, 1);
+ _loaderThumb.graphics.drawRoundRect(0, 0, trackHeight*3, trackHeight, 10, 10);
+ }
+
+ /**
+ * Stops drawing the loader
+ */
+ public function hide():Void
+ {
+ this.visible = false;
+ _visible = false;
+ }
+
+ /**
+ * Starts drawing the loader
+ */
+ public function show():Void
+ {
+ this.visible = true;
+ _visible = true;
+ }
+
+ /**
+ * Set loader colors
+ * @param colors
+ */
+ public function setColors(colors:Array):Void
+ {
+ _darkColor = colors[0].length > 0? Std.parseInt("0x" + colors[0]) : 0x000000;
+ _controlColor = colors[1].length > 0? Std.parseInt("0x" + colors[1]) : 0xFFFFFF;
+ _seekColor = colors[2].length > 0? Std.parseInt("0x" + colors[2]) : 0x747474;
+
+ drawLoader();
+ }
+}
\ No newline at end of file
diff --git a/lib/Jaris/src/jaris/player/newcontrols/NewControls.hx b/lib/Jaris/src/jaris/player/newcontrols/NewControls.hx
new file mode 100644
index 00000000..e3493bc6
--- /dev/null
+++ b/lib/Jaris/src/jaris/player/newcontrols/NewControls.hx
@@ -0,0 +1,945 @@
+/**
+ * @author Jefferson González
+ * @copyright 2010 Jefferson González
+ *
+ * @license
+ * This file is part of Jaris FLV Player.
+ *
+ * Jaris FLV Player is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License or GNU LESSER GENERAL
+ * PUBLIC LICENSE as published by the Free Software Foundation, either version
+ * 3 of the License, or (at your option) any later version.
+ *
+ * Jaris FLV Player is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License and
+ * GNU LESSER GENERAL PUBLIC LICENSE along with Jaris FLV Player. If not,
+ * see .
+ */
+
+package jaris.player.newcontrols;
+
+//{Libraries
+import flash.display.GradientType;
+import flash.events.Event;
+import flash.events.TimerEvent;
+import flash.geom.Matrix;
+import flash.Lib;
+import flash.events.MouseEvent;
+import flash.display.MovieClip;
+import flash.net.NetStream;
+import flash.geom.Rectangle;
+import flash.text.AntiAliasType;
+import flash.text.TextField;
+import flash.text.TextFieldAutoSize;
+import flash.text.TextFormat;
+import flash.utils.Timer;
+import jaris.animation.Animation;
+import jaris.events.PlayerEvents;
+import jaris.player.newcontrols.Loader;
+import jaris.player.newcontrols.AspectRatioIcon;
+import jaris.player.newcontrols.FullscreenIcon;
+import jaris.player.newcontrols.PauseIcon;
+import jaris.player.newcontrols.PlayIcon;
+import jaris.player.newcontrols.VolumeIcon;
+import jaris.player.Player;
+import flash.display.Sprite;
+import flash.display.Stage;
+import jaris.utils.Utils;
+//}
+
+/**
+ * Default controls for jaris player
+ */
+class NewControls extends MovieClip {
+
+ //{Member Variables
+ private var _thumb:Sprite;
+ private var _track:Sprite;
+ private var _trackDownloaded:Sprite;
+ private var _scrubbing:Bool;
+ private var _stage:Stage;
+ private var _movieClip:MovieClip;
+ private var _player:Player;
+ private var _darkColor:UInt;
+ private var _brightColor:UInt;
+ private var _seekColor:UInt;
+ private var _controlColor:UInt;
+ private var _controlSize:Int;
+ private var _hoverColor:UInt;
+ private var _hideControlsTimer:Timer;
+ private var _hideAspectRatioLabelTimer:Timer;
+ private var _currentPlayTimeLabel:TextField;
+ private var _totalPlayTimeLabel:TextField;
+ private var _seekPlayTimeLabel:TextField;
+ private var _percentLoaded:Float;
+ private var _controlsVisible:Bool;
+ private var _seekBar:Sprite;
+ private var _controlsBar:Sprite;
+ private var _playControl:PlayIcon;
+ private var _pauseControl:PauseIcon;
+ private var _aspectRatioControl:AspectRatioIcon;
+ private var _fullscreenControl:FullscreenIcon;
+ private var _volumeIcon:VolumeIcon;
+ private var _volumeTrack:Sprite;
+ private var _volumeSlider:Sprite;
+ private var _loader:Loader;
+ private var _aspectRatioLabelContainer:Sprite;
+ private var _aspectRatioLabel:TextField;
+ private var _textFormat:TextFormat;
+ //}
+
+
+ //{Constructor
+ public function new(player:Player)
+ {
+ super();
+
+ //{Main variables
+ _stage = Lib.current.stage;
+ _movieClip = Lib.current;
+ _player = player;
+ _darkColor = 0x000000;
+ _brightColor = 0x4c4c4c;
+ _controlColor = 0xFFFFFF;
+ _hoverColor = 0x67A8C1;
+ _seekColor = 0x7c7c7c;
+ _controlSize = 40;
+ _percentLoaded = 0.0;
+ _hideControlsTimer = new Timer(500);
+ _hideAspectRatioLabelTimer = new Timer(500);
+ _controlsVisible = false;
+
+ _textFormat = new TextFormat();
+ _textFormat.font = "arial";
+ _textFormat.color = _controlColor;
+ _textFormat.size = 14;
+ //}
+
+ //{Playing controls initialization
+ _controlsBar = new Sprite();
+ _controlsBar.visible = true;
+ addChild(_controlsBar);
+
+ _playControl = new PlayIcon(0, 0, 0, 0, _controlColor, _hoverColor);
+ _controlsBar.addChild(_playControl);
+
+ _pauseControl = new PauseIcon(0, 0, 0, 0, _controlColor, _hoverColor);
+ _pauseControl.visible = false;
+ _controlsBar.addChild(_pauseControl);
+
+ _aspectRatioControl = new AspectRatioIcon(0, 0, 0, 0, _controlColor, _hoverColor);
+ _controlsBar.addChild(_aspectRatioControl);
+
+ _fullscreenControl = new FullscreenIcon(0, 0, 0, 0, _controlColor, _hoverColor);
+ _controlsBar.addChild(_fullscreenControl);
+
+ _volumeIcon = new VolumeIcon(0, 0, 0, 0, _controlColor, _hoverColor);
+ _controlsBar.addChild(_volumeIcon);
+
+ _volumeSlider = new Sprite();
+ _volumeSlider.visible = false;
+ _controlsBar.addChild(_volumeSlider);
+
+ _volumeTrack = new Sprite();
+ _volumeTrack.visible = false;
+ _volumeTrack.buttonMode = true;
+ _volumeTrack.useHandCursor = true;
+ _volumeTrack.tabEnabled = false;
+ _controlsBar.addChild(_volumeTrack);
+ //}
+
+ //{Seeking Controls initialization
+ _seekBar = new Sprite();
+ _controlsBar.addChild(_seekBar);
+
+ _trackDownloaded = new Sprite( );
+ _trackDownloaded.tabEnabled = false;
+ _seekBar.addChild(_trackDownloaded);
+
+ _track = new Sprite( );
+ _track.tabEnabled = false;
+ _track.buttonMode = true;
+ _track.useHandCursor = true;
+ _seekBar.addChild(_track);
+
+ _thumb = new Sprite( );
+ _thumb.buttonMode = true;
+ _thumb.useHandCursor = true;
+ _thumb.tabEnabled = false;
+ _seekBar.addChild(_thumb);
+
+ _currentPlayTimeLabel = new TextField();
+ _currentPlayTimeLabel.autoSize = TextFieldAutoSize.LEFT;
+ _currentPlayTimeLabel.text = "00:00:00";
+ _currentPlayTimeLabel.tabEnabled = false;
+ _currentPlayTimeLabel.setTextFormat(_textFormat);
+ _seekBar.addChild(_currentPlayTimeLabel);
+
+ _totalPlayTimeLabel = new TextField();
+ _totalPlayTimeLabel.autoSize = TextFieldAutoSize.LEFT;
+ _totalPlayTimeLabel.text = "00:00:00";
+ _totalPlayTimeLabel.tabEnabled = false;
+ _totalPlayTimeLabel.setTextFormat(_textFormat);
+ _seekBar.addChild(_totalPlayTimeLabel);
+
+ _seekPlayTimeLabel = new TextField();
+ _seekPlayTimeLabel.visible = false;
+ _seekPlayTimeLabel.autoSize = TextFieldAutoSize.LEFT;
+ _seekPlayTimeLabel.text = "00:00:00";
+ _seekPlayTimeLabel.tabEnabled = false;
+ _seekPlayTimeLabel.setTextFormat(_textFormat);
+ addChild(_seekPlayTimeLabel);
+ //}
+
+ //{Aspect ratio label
+ _aspectRatioLabelContainer = new Sprite();
+ addChild(_aspectRatioLabelContainer);
+
+ _aspectRatioLabel = new TextField();
+ _aspectRatioLabel.autoSize = TextFieldAutoSize.CENTER;
+ _aspectRatioLabel.text = "original";
+ _aspectRatioLabel.tabEnabled = false;
+ _aspectRatioLabelContainer.addChild(_aspectRatioLabel);
+ //}
+
+ redrawControls();
+
+ //{Loader bar
+ _loader = new Loader();
+ _loader.hide();
+
+ var loaderColors:Array = ["", "", "", ""];
+ loaderColors[0] = Std.string(_darkColor);
+ loaderColors[1] = Std.string(_controlColor);
+ loaderColors[2] = Std.string(_seekColor);
+
+ _loader.setColors(loaderColors);
+
+ addChild(_loader);
+ //}
+
+ //{event Listeners
+ _movieClip.addEventListener(Event.ENTER_FRAME, onEnterFrame);
+ _thumb.addEventListener(MouseEvent.MOUSE_DOWN, onThumbMouseDown);
+ _thumb.addEventListener(MouseEvent.MOUSE_UP, onThumbMouseUp);
+ _thumb.addEventListener(MouseEvent.MOUSE_OVER, onThumbHover);
+ _thumb.addEventListener(MouseEvent.MOUSE_OUT, onThumbMouseOut);
+ _thumb.addEventListener(MouseEvent.MOUSE_MOVE, onTrackMouseMove);
+ _thumb.addEventListener(MouseEvent.MOUSE_OUT, onTrackMouseOut);
+ _track.addEventListener(MouseEvent.CLICK, onTrackClick);
+ _track.addEventListener(MouseEvent.MOUSE_MOVE, onTrackMouseMove);
+ _track.addEventListener(MouseEvent.MOUSE_OUT, onTrackMouseOut);
+ _playControl.addEventListener(MouseEvent.CLICK, onPlayClick);
+ _pauseControl.addEventListener(MouseEvent.CLICK, onPauseClick);
+ _aspectRatioControl.addEventListener(MouseEvent.CLICK, onAspectRatioClick);
+ _fullscreenControl.addEventListener(MouseEvent.CLICK, onFullscreenClick);
+ _volumeIcon.addEventListener(MouseEvent.CLICK, onVolumeIconClick);
+ _volumeTrack.addEventListener(MouseEvent.CLICK, onVolumeTrackClick);
+
+ _player.addEventListener(PlayerEvents.MOUSE_HIDE, onPlayerMouseHide);
+ _player.addEventListener(PlayerEvents.MOUSE_SHOW, onPlayerMouseShow);
+ _player.addEventListener(PlayerEvents.MEDIA_INITIALIZED, onPlayerMediaInitialized);
+ _player.addEventListener(PlayerEvents.BUFFERING, onPlayerBuffering);
+ _player.addEventListener(PlayerEvents.NOT_BUFFERING, onPlayerNotBuffering);
+ _player.addEventListener(PlayerEvents.RESIZE, onPlayerResize);
+ _player.addEventListener(PlayerEvents.PLAY_PAUSE, onPlayerPlayPause);
+ _player.addEventListener(PlayerEvents.PLAYBACK_FINISHED, onPlayerPlaybackFinished);
+ _player.addEventListener(PlayerEvents.CONNECTION_FAILED, onPlayerStreamNotFound);
+ _player.addEventListener(PlayerEvents.ASPECT_RATIO, onPlayerAspectRatio);
+
+ _stage.addEventListener(MouseEvent.MOUSE_UP, onThumbMouseUp);
+ _stage.addEventListener(MouseEvent.MOUSE_OUT, onThumbMouseUp);
+ _stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
+ _stage.addEventListener(Event.RESIZE, onStageResize);
+
+ _hideControlsTimer.addEventListener(TimerEvent.TIMER, hideControlsTimer);
+ _hideAspectRatioLabelTimer.addEventListener(TimerEvent.TIMER, hideAspectRatioLabelTimer);
+
+ _hideControlsTimer.start();
+ //}
+ }
+ //}
+
+
+ //{Timers
+ /**
+ * Hides the playing controls when not moving mouse.
+ * @param event The timer event associated
+ */
+ private function hideControlsTimer(event:TimerEvent):Void
+ {
+ if (_player.isPlaying())
+ {
+ if (_controlsVisible)
+ {
+ if (_stage.mouseX < _controlsBar.x ||
+ _stage.mouseX >= _stage.stageWidth - 1 ||
+ _stage.mouseY >= _stage.stageHeight - 1 ||
+ _stage.mouseY <= 1
+ )
+ {
+ _controlsVisible = false;
+ }
+ }
+ else
+ {
+ hideControls();
+ _hideControlsTimer.stop();
+ }
+ }
+ }
+
+ /**
+ * Hides aspect ratio label
+ * @param event
+ */
+ private function hideAspectRatioLabelTimer(event:TimerEvent):Void
+ {
+ //wait till fade in effect finish
+ if (_aspectRatioLabelContainer.alpha >= 1)
+ {
+ Animation.fadeOut(_aspectRatioLabelContainer, 300);
+ _hideAspectRatioLabelTimer.stop();
+ }
+ }
+ //}
+
+
+ //{Events
+ /**
+ * Keeps syncronized various elements of the controls like the thumb and download track bar
+ * @param event
+ */
+ private function onEnterFrame(event:Event):Void
+ {
+ if(_player.getDuration() > 0) {
+ if (_scrubbing)
+ {
+ _player.seek(((_thumb.x - _track.x) / _track.width) * _player.getDuration());
+ }
+ else
+ {
+ _currentPlayTimeLabel.text = Utils.formatTime(_player.getCurrentTime());
+ _currentPlayTimeLabel.setTextFormat(_textFormat);
+ _thumb.x = _player.getCurrentTime() / _player.getDuration() * (_track.width-_thumb.width) + _track.x;
+ }
+ }
+
+ _volumeSlider.height = _volumeTrack.height * (_player.getVolume() / 1.0);
+ _volumeSlider.y = (_volumeTrack.y + _volumeTrack.height) - _volumeSlider.height;
+
+ drawDownloadProgress();
+ }
+
+ /**
+ * Show playing controls on mouse movement.
+ * @param event
+ */
+ private function onMouseMove(event:MouseEvent):Void
+ {
+ if (_stage.mouseX >= _controlsBar.x)
+ {
+ if (!_hideControlsTimer.running)
+ {
+ _hideControlsTimer.start();
+ }
+
+ _controlsVisible = true;
+ showControls();
+ }
+ }
+
+ /**
+ * Function fired by a stage resize eventthat redraws the player controls
+ * @param event
+ */
+ private function onStageResize(event:Event):Void
+ {
+ redrawControls();
+ }
+
+ /**
+ * Toggles pause or play
+ * @param event
+ */
+ private function onPlayClick(event:MouseEvent):Void
+ {
+ _player.togglePlay();
+ _playControl.visible = !_player.isPlaying();
+ _pauseControl.visible = _player.isPlaying();
+ }
+
+ /**
+ * Toggles pause or play
+ * @param event
+ */
+ private function onPauseClick(event:MouseEvent):Void
+ {
+ _player.togglePlay();
+ _playControl.visible = !_player.isPlaying();
+ _pauseControl.visible = _player.isPlaying();
+ }
+
+ /**
+ * Toggles betewen aspect ratios
+ * @param event
+ */
+ private function onAspectRatioClick(event:MouseEvent):Void
+ {
+ _player.toggleAspectRatio();
+ }
+
+ /**
+ * Toggles between window and fullscreen mode
+ * @param event
+ */
+ private function onFullscreenClick(event:MouseEvent):Void
+ {
+ _player.toggleFullscreen();
+ }
+
+ /**
+ * Toggles between mute and unmute
+ * @param event
+ */
+ private function onVolumeIconClick(event: MouseEvent):Void
+ {
+ if (_volumeSlider.visible) {
+ _volumeSlider.visible = false;
+ _volumeTrack.visible = false;
+ } else {
+ _volumeSlider.visible = true;
+ _volumeTrack.visible = true;
+ }
+ }
+
+ /**
+ * Detect user click on volume track control and change volume according
+ * @param event
+ */
+ private function onVolumeTrackClick(event:MouseEvent):Void
+ {
+ var percent:Float = _volumeTrack.height - _volumeTrack.mouseY;
+ var volume:Float = 1.0 * (percent / _volumeTrack.height);
+
+ _player.setVolume(volume);
+ }
+
+ /**
+ * Display not found message
+ * @param event
+ */
+ private function onPlayerStreamNotFound(event:PlayerEvents):Void
+ {
+ //todo: to work on this
+ }
+
+ /**
+ * Shows the loader bar when buffering
+ * @param event
+ */
+ private function onPlayerBuffering(event:PlayerEvents):Void
+ {
+ _loader.show();
+ }
+
+ /**
+ * Hides loader bar when not buffering
+ * @param event
+ */
+ private function onPlayerNotBuffering(event:PlayerEvents):Void
+ {
+ _loader.hide();
+ }
+
+ /**
+ * Show the selected aspect ratio
+ * @param event
+ */
+ private function onPlayerAspectRatio(event:PlayerEvents):Void
+ {
+ _hideAspectRatioLabelTimer.stop();
+ _aspectRatioLabel.text = _player.getAspectRatioString();
+ drawAspectRatioLabel();
+
+ while (_aspectRatioLabelContainer.visible)
+ {
+ //wait till fade out finishes
+ }
+
+ Animation.fadeIn(_aspectRatioLabelContainer, 1);
+
+ _hideAspectRatioLabelTimer.start();
+ }
+
+ /**
+ * Monitors playbeack when finishes tu update controls
+ * @param event
+ */
+ private function onPlayerPlaybackFinished(event:PlayerEvents):Void
+ {
+ _playControl.visible = !_player.isPlaying();
+ _pauseControl.visible = _player.isPlaying();
+ showControls();
+ }
+
+ /**
+ * Monitors keyboard play pause actions to update icons
+ * @param event
+ */
+ private function onPlayerPlayPause(event:PlayerEvents):Void
+ {
+ _playControl.visible = !_player.isPlaying();
+ _pauseControl.visible = _player.isPlaying();
+ }
+
+ /**
+ * Resizes the video player on windowed mode substracting the seekbar height
+ * @param event
+ */
+ private function onPlayerResize(event:PlayerEvents):Void
+ {
+ }
+
+ /**
+ * Updates media total time duration.
+ * @param event
+ */
+ private function onPlayerMediaInitialized(event:PlayerEvents):Void
+ {
+ _totalPlayTimeLabel.text = Utils.formatTime(event.duration);
+ _totalPlayTimeLabel.setTextFormat(_textFormat);
+
+ _playControl.visible = !_player.isPlaying();
+ _pauseControl.visible = _player.isPlaying();
+ }
+
+ /**
+ * Hides seekbar if on fullscreen.
+ * @param event
+ */
+ private function onPlayerMouseHide(event:PlayerEvents):Void
+ {
+ if (_controlsBar.visible && _player.isFullscreen())
+ {
+ hideControls();
+ }
+ }
+
+ /**
+ * Shows seekbar
+ * @param event
+ */
+ private function onPlayerMouseShow(event:PlayerEvents):Void
+ {
+ //Only use slidein effect on fullscreen since switching to windowed mode on
+ //hardware scaling causes a bug by a slow response on stage height changes
+ if (_player.isFullscreen() && !_controlsBar.visible)
+ {
+ _controlsBar.visible = true;
+ }
+ else if (!_controlsBar.visible)
+ {
+ _controlsBar.visible = true;
+ }
+ }
+
+ /**
+ * Translates a user click in to time and seeks to it
+ * @param event
+ */
+ private function onTrackClick(event:MouseEvent):Void
+ {
+ var clickPosition:Float = _track.mouseX;
+ _player.seek(_player.getDuration() * (clickPosition / _track.width));
+ }
+
+ /**
+ * Shows a small tooltip showing the time calculated by mouse position
+ * @param event
+ */
+ private function onTrackMouseMove(event:MouseEvent):Void
+ {
+ var clickPosition:Float = _track.mouseX;
+ _seekPlayTimeLabel.text = Utils.formatTime(_player.getDuration() * (clickPosition / _track.width));
+ _seekPlayTimeLabel.setTextFormat(_textFormat);
+
+ _seekPlayTimeLabel.y = _stage.stageHeight - _seekBar.height - _seekPlayTimeLabel.height - 1;
+ _seekPlayTimeLabel.x = clickPosition + (_seekPlayTimeLabel.width / 2) + (_playControl.width + 10) * 2;
+ _seekPlayTimeLabel.backgroundColor = _darkColor;
+ _seekPlayTimeLabel.background = true;
+ _seekPlayTimeLabel.textColor = _controlColor;
+ _seekPlayTimeLabel.borderColor = _darkColor;
+ _seekPlayTimeLabel.border = true;
+
+ if (!_seekPlayTimeLabel.visible)
+ {
+ _seekPlayTimeLabel.visible = true;
+ }
+ }
+
+ /**
+ * Hides the tooltip that shows the time calculated by mouse position
+ * @param event
+ */
+ private function onTrackMouseOut(event:MouseEvent):Void
+ {
+ _seekPlayTimeLabel.visible = false;
+ }
+
+ /**
+ * Enables dragging of thumb for seeking media
+ * @param event
+ */
+ private function onThumbMouseDown(event:MouseEvent):Void
+ {
+ _scrubbing = true;
+ var rectangle:Rectangle = new Rectangle(_track.x, _track.y, _track.width-_thumb.width, 0);
+ _thumb.startDrag(false, rectangle);
+ }
+
+ /**
+ * Changes thumb seek control to hover color
+ * @param event
+ */
+ private function onThumbHover(event:MouseEvent):Void
+ {
+ _thumb.graphics.lineStyle();
+ _thumb.graphics.beginFill(_hoverColor);
+ _thumb.graphics.drawRoundRect(0, (_seekBar.height/2)-(11/2), 11, 11, 10, 10);
+ _thumb.graphics.endFill();
+ }
+
+ /**
+ * Changes thumb seek control to control color
+ * @param event
+ */
+ private function onThumbMouseOut(event:MouseEvent):Void
+ {
+ var matrix:Matrix = new Matrix( );
+ matrix.createGradientBox(11, 11, Utils.degreesToRadians(-90), 11, 0);
+ var colors:Array = [_controlColor, _controlColor];
+ var alphas:Array = [0.75, 1];
+ var ratios:Array = [0, 255];
+
+ _thumb.graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix);
+ _thumb.graphics.drawRoundRect(0, (_seekBar.height / 2) - (11 / 2), 11, 11, 10, 10);
+ _thumb.graphics.endFill();
+ }
+
+ /**
+ * Disables dragging of thumb
+ * @param event
+ */
+ private function onThumbMouseUp(event:MouseEvent):Void
+ {
+ _scrubbing = false;
+ _thumb.stopDrag( );
+ }
+ //}
+
+
+ //{Drawing functions
+ /**
+ * Clears all current graphics a draw new ones
+ */
+ private function redrawControls():Void
+ {
+ drawControls();
+ drawAspectRatioLabel();
+ }
+
+ /**
+ * Draws the download progress track bar
+ */
+ private function drawDownloadProgress():Void
+ {
+ if (_player.getBytesTotal() > 0)
+ {
+ var bytesLoaded:Float = _player.getBytesLoaded();
+ var bytesTotal:Float = _player.getBytesTotal();
+
+ _percentLoaded = bytesLoaded / bytesTotal;
+ }
+
+ var position:Float = _player.getStartTime() / _player.getDuration();
+ var startPosition:Float = (position > 0?(position * _track.width):0) + _track.x;
+
+ _trackDownloaded.graphics.clear();
+ _trackDownloaded.graphics.lineStyle();
+ _trackDownloaded.x = startPosition;
+ _trackDownloaded.graphics.beginFill(_seekColor, 0.5);
+ _trackDownloaded.graphics.drawRoundRect(0, (_seekBar.height / 2) - (5 / 2), ((_track.width + _track.x) - _trackDownloaded.x) * _percentLoaded, 5, 3, 3);
+ _trackDownloaded.graphics.endFill();
+ }
+
+ /**
+ * Draws NEW control bar player/seek controls
+ */
+ private function drawControls():Void
+ {
+ //Reset sprites for redraw
+ _controlsBar.graphics.clear();
+ _volumeTrack.graphics.clear();
+ _volumeSlider.graphics.clear();
+ _volumeSlider.visible = false;
+ _volumeTrack.visible = false;
+
+ //Reset sprites for redraw
+ _seekBar.graphics.clear();
+ _track.graphics.clear();
+ _thumb.graphics.clear();
+
+ //Draw controls bar
+ var barMargin = 10;
+ var barWidth = _stage.stageWidth;
+ var barHeight = _controlSize;
+ var barCenter = barWidth / 2;
+ var buttonSize = Std.int(((80 / 100) * (barHeight - (barMargin*2))));
+
+ _controlsBar.x = 0;
+ _controlsBar.y = (_stage.stageHeight - barHeight);
+
+ var matrix:Matrix = new Matrix( );
+ matrix.createGradientBox(barWidth, barHeight, Utils.degreesToRadians(-90), barWidth, 0);
+ var colors:Array = [_brightColor, _darkColor];
+ var alphas:Array = [1.0, 1];
+ var ratios:Array = [0, 255];
+ _controlsBar.graphics.lineStyle();
+ _controlsBar.graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix);
+ _controlsBar.graphics.drawRect(0, 2, barWidth, barHeight-2);
+ _controlsBar.graphics.endFill();
+ _controlsBar.graphics.beginFill(_darkColor, 1);
+ _controlsBar.graphics.drawRect(0, 0, barWidth, 1);
+ _controlsBar.graphics.endFill();
+ _controlsBar.graphics.beginFill(_brightColor, 1);
+ _controlsBar.graphics.drawRect(0, 1, barWidth, 1);
+ _controlsBar.graphics.endFill();
+
+ //Draw seek bar
+ var _seekBarWidth = barWidth - (buttonSize+barMargin)*3 - (_playControl.x + _playControl.width + barMargin) - barMargin;
+ var _seekBarHeight = barHeight;
+ _seekBar.x = _playControl.x + _playControl.width + barMargin;
+ _seekBar.y = 0;
+ _seekBar.graphics.lineStyle();
+ _seekBar.graphics.beginFill(_darkColor, 0);
+ _seekBar.graphics.drawRect(0, 0, _seekBarWidth, _seekBarHeight);
+ _seekBar.graphics.endFill();
+
+ //Draw playbutton
+ _playControl.setNormalColor(_controlColor);
+ _playControl.setHoverColor(_hoverColor);
+ _playControl.setPosition(barMargin, barMargin);
+ _playControl.setSize(buttonSize+5, buttonSize+5);
+
+ //Draw pausebutton
+ _pauseControl.setNormalColor(_controlColor);
+ _pauseControl.setHoverColor(_hoverColor);
+ _pauseControl.setPosition(_playControl.x, _playControl.y);
+ _pauseControl.setSize(buttonSize+5, buttonSize+5);
+
+ //Draw current play time label
+ _textFormat.color = _seekColor;
+ _currentPlayTimeLabel.x = 0;
+ _currentPlayTimeLabel.y = _seekBarHeight - (_seekBarHeight / 2) - (_currentPlayTimeLabel.height / 2);
+ _currentPlayTimeLabel.antiAliasType = AntiAliasType.ADVANCED;
+ _currentPlayTimeLabel.setTextFormat(_textFormat);
+
+ //Draw total play time label
+ _totalPlayTimeLabel.x = _seekBarWidth - _totalPlayTimeLabel.width;
+ _totalPlayTimeLabel.y = _seekBarHeight - (_seekBarHeight / 2) - (_totalPlayTimeLabel.height / 2);
+ _totalPlayTimeLabel.antiAliasType = AntiAliasType.ADVANCED;
+ _totalPlayTimeLabel.setTextFormat(_textFormat);
+
+ //Draw download progress
+ drawDownloadProgress();
+
+ //Draw track place holder for drag
+ _track.x = _currentPlayTimeLabel.x + _currentPlayTimeLabel.width + barMargin;
+ _track.graphics.lineStyle();
+ _track.graphics.beginFill(_seekColor, 0);
+ _track.graphics.drawRect(0, (_seekBarHeight / 2) - ((buttonSize+barMargin) / 2), _totalPlayTimeLabel.x - _totalPlayTimeLabel.width - barMargin - barMargin, buttonSize + barMargin);
+ _track.graphics.endFill();
+
+ _track.graphics.lineStyle();
+ _track.graphics.beginFill(_seekColor, 0.3);
+ _track.graphics.drawRoundRect(0, (_seekBarHeight / 2) - (5 / 2), _totalPlayTimeLabel.x - _totalPlayTimeLabel.width - barMargin - barMargin, 5, 3, 3);
+ _track.graphics.endFill();
+
+ //Draw thumb
+ var matrix:Matrix = new Matrix( );
+ matrix.createGradientBox(11, 11, Utils.degreesToRadians(-90), 11, 0);
+ var colors:Array = [_controlColor, _controlColor];
+ var alphas:Array = [0.75, 1];
+ var ratios:Array = [0, 255];
+
+ _thumb.x = _currentPlayTimeLabel.width + _currentPlayTimeLabel.x + barMargin;
+ _thumb.graphics.lineStyle();
+ _thumb.graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix);
+ //_thumb.graphics.beginFill(_controlColor);
+ _thumb.graphics.drawRoundRect(0, (_seekBarHeight/2)-(11/2), 11, 11, 10, 10);
+ _thumb.graphics.endFill();
+
+ //Draw volume icon
+ _volumeIcon.setNormalColor(_controlColor);
+ _volumeIcon.setHoverColor(_hoverColor);
+ _volumeIcon.setPosition(_seekBar.x + _seekBar.width + barMargin, _playControl.y+1);
+ _volumeIcon.setSize(buttonSize, buttonSize);
+
+ //Draw aspec ratio button
+ _aspectRatioControl.setNormalColor(_controlColor);
+ _aspectRatioControl.setHoverColor(_hoverColor);
+ _aspectRatioControl.setPosition(_volumeIcon.x + _volumeIcon.width + barMargin, _playControl.y+1);
+ _aspectRatioControl.setSize(buttonSize, buttonSize);
+
+ //Draw fullscreen button
+ _fullscreenControl.setNormalColor(_controlColor);
+ _fullscreenControl.setHoverColor(_hoverColor);
+ _fullscreenControl.setPosition(_aspectRatioControl.x + _aspectRatioControl.width + barMargin, _playControl.y+1);
+ _fullscreenControl.setSize(buttonSize, buttonSize);
+
+ //Draw volume track
+ _volumeTrack.x = _controlsBar.width-(buttonSize+barMargin)*3;
+ _volumeTrack.y = -_controlsBar.height-2;
+ _volumeTrack.graphics.lineStyle(1, _controlColor);
+ _volumeTrack.graphics.beginFill(0x000000, 0);
+ _volumeTrack.graphics.drawRect(0, 0, buttonSize, _controlsBar.height);
+ _volumeTrack.graphics.endFill();
+
+ //Draw volume slider
+ var matrix:Matrix = new Matrix( );
+ matrix.createGradientBox(_volumeTrack.width, _volumeTrack.height, Utils.degreesToRadians(-90), _volumeTrack.width, 0);
+ var colors:Array = [_hoverColor, _hoverColor];
+ var alphas:Array = [0.75, 1];
+ var ratios:Array = [0, 255];
+
+ _volumeSlider.x = _volumeTrack.x;
+ _volumeSlider.y = _volumeTrack.y;
+ _volumeSlider.graphics.lineStyle();
+ _volumeSlider.graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix);
+ //_volumeSlider.graphics.beginFill(_hoverColor, 1);
+ _volumeSlider.graphics.drawRect(0, 0, _volumeTrack.width, _volumeTrack.height);
+ _volumeSlider.graphics.endFill();
+
+ }
+
+ private function drawAspectRatioLabel():Void
+ {
+ _aspectRatioLabelContainer.graphics.clear();
+ _aspectRatioLabelContainer.visible = false;
+
+ //Update aspect ratio label
+ var textFormat:TextFormat = new TextFormat();
+ textFormat.font = "arial";
+ textFormat.bold = true;
+ textFormat.size = 40;
+ textFormat.color = _controlColor;
+
+ _aspectRatioLabel.setTextFormat(textFormat);
+ _aspectRatioLabel.x = (_stage.stageWidth / 2) - (_aspectRatioLabel.width / 2);
+ _aspectRatioLabel.y = (_stage.stageHeight / 2) - (_aspectRatioLabel.height / 2);
+
+ //Draw aspect ratio label container
+ _aspectRatioLabelContainer.x = _aspectRatioLabel.x - 10;
+ _aspectRatioLabelContainer.y = _aspectRatioLabel.y - 10;
+ _aspectRatioLabelContainer.graphics.lineStyle(0, _darkColor);
+ _aspectRatioLabelContainer.graphics.beginFill(_darkColor, 1);
+ _aspectRatioLabelContainer.graphics.drawRoundRect(0, 0, _aspectRatioLabel.width + 20, _aspectRatioLabel.height + 20, 15, 15);
+ _aspectRatioLabelContainer.graphics.endFill();
+
+ _aspectRatioLabel.x = 10;
+ _aspectRatioLabel.y = 10;
+ }
+ //}
+
+
+ //{Private Methods
+ /**
+ * Hide the play controls bar
+ */
+ private function hideControls():Void
+ {
+ if(_controlsBar.visible)
+ {
+ drawControls();
+ Animation.slideOut(_controlsBar, "bottom", 800);
+ }
+ }
+
+ /**
+ * Shows play controls bar
+ */
+ private function showControls():Void
+ {
+ if(!_controlsBar.visible)
+ {
+ drawControls();
+ _controlsBar.visible = true;
+ }
+ }
+ //}
+
+
+ //{Setters
+ /**
+ * Sets the player colors and redraw them
+ * @param colors Array of colors in the following order: darkColor, brightColor, controlColor, hoverColor
+ */
+ public function setControlColors(colors:Array):Void
+ {
+ _darkColor = colors[0].length > 0? Std.parseInt("0x" + colors[0]) : 0x000000;
+ _brightColor = colors[1].length > 0? Std.parseInt("0x" + colors[1]) : 0x4c4c4c;
+ _controlColor = colors[2].length > 0? Std.parseInt("0x" + colors[2]) : 0xFFFFFF;
+ _hoverColor = colors[3].length > 0? Std.parseInt("0x" + colors[3]) : 0x67A8C1;
+ _seekColor = colors[4].length > 0? Std.parseInt("0x" + colors[4]) : 0x7c7c7c;
+
+
+ var loaderColors:Array = ["", ""];
+ loaderColors[0] = colors[0];
+ loaderColors[1] = colors[2];
+ loaderColors[2] = colors[4];
+ _loader.setColors(loaderColors);
+
+ redrawControls();
+ }
+
+ /**
+ * Sets the player controls size (height)
+ * @param size int: for e.g. 50
+ */
+ public function setControlSize(size:Int):Void
+ {
+ if (size == 0)
+ return;
+
+ _controlSize = size;
+ redrawControls();
+ }
+
+ /**
+ * To set the duration label when autostart parameter is false
+ * @param duration in seconds or formatted string in format hh:mm:ss
+ */
+ public function setDurationLabel(duration:String):Void
+ {
+ //Person passed time already formatted
+ if (duration.indexOf(":") != -1)
+ {
+ _totalPlayTimeLabel.text = duration;
+ }
+
+ //Time passed in seconds
+ else
+ {
+ _totalPlayTimeLabel.text = Std.string(Utils.formatTime(Std.parseFloat(duration)));
+ }
+
+ _totalPlayTimeLabel.setTextFormat(_textFormat);
+ }
+ //}
+
+}
\ No newline at end of file
diff --git a/lib/Jaris/src/jaris/player/newcontrols/PauseIcon.hx b/lib/Jaris/src/jaris/player/newcontrols/PauseIcon.hx
new file mode 100644
index 00000000..c0b8343b
--- /dev/null
+++ b/lib/Jaris/src/jaris/player/newcontrols/PauseIcon.hx
@@ -0,0 +1,127 @@
+/**
+ * @author Jefferson González
+ * @copyright 2010 Jefferson González
+ *
+ * @license
+ * This file is part of Jaris FLV Player.
+ *
+ * Jaris FLV Player is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License or GNU LESSER GENERAL
+ * PUBLIC LICENSE as published by the Free Software Foundation, either version
+ * 3 of the License, or (at your option) any later version.
+ *
+ * Jaris FLV Player is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License and
+ * GNU LESSER GENERAL PUBLIC LICENSE along with Jaris FLV Player. If not,
+ * see .
+ */
+
+package jaris.player.newcontrols;
+import flash.display.Sprite;
+import flash.events.MouseEvent;
+import flash.geom.Matrix;
+import jaris.utils.Utils;
+import flash.display.GradientType;
+
+class PauseIcon extends Sprite
+{
+ private var _width:Float;
+ private var _height:Float;
+ private var _normalColor:UInt;
+ private var _hoverColor:UInt;
+
+ public function new(x:Float, y:Float, width:Float, height:Float, normalColor:UInt, hoverColor:UInt)
+ {
+ super();
+
+ this.x = x;
+ this.y = y;
+ this.buttonMode = true;
+ this.useHandCursor = true;
+ this.tabEnabled = false;
+
+ _width = width;
+ _height = height;
+ _normalColor = normalColor;
+ _hoverColor = hoverColor;
+
+ addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
+ addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
+
+ draw(_normalColor);
+ }
+
+ private function onMouseOver(event:MouseEvent):Void
+ {
+ draw(_hoverColor);
+ }
+
+ private function onMouseOut(event:MouseEvent):Void
+ {
+ draw(_normalColor);
+ }
+
+ //{Private Methods
+ private function draw(color:UInt):Void
+ {
+ graphics.clear();
+
+ graphics.lineStyle(0, color, 0.0);
+ graphics.beginFill(color, 0);
+ graphics.drawRect(0, 0, _width, _height);
+ graphics.endFill();
+
+ var matrix:Matrix = new Matrix( );
+ matrix.createGradientBox(_width, _height, Utils.degreesToRadians(-90), _width, 0);
+ var colors:Array = [color, color];
+ var alphas:Array = [0.75, 1];
+ var ratios:Array = [0, 255];
+
+ graphics.lineStyle();
+ graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix);
+ //graphics.beginFill(color);
+ graphics.drawRoundRect(0, 0, (33 / 100) * _width, _height, 6, 6);
+ graphics.drawRoundRect(_width - ((33 / 100) * _width), 0, (33 / 100) * _width, _height, 6, 6);
+ graphics.endFill();
+
+ graphics.lineStyle();
+ graphics.beginFill(color, 0);
+ graphics.drawRect(0, 0, _width, _height);
+ graphics.endFill();
+ }
+ //}
+
+ //{Setters
+ public function setNormalColor(color:UInt):Void
+ {
+ _normalColor = color;
+ draw(_normalColor);
+ }
+
+ public function setHoverColor(color:UInt):Void
+ {
+ _hoverColor = color;
+ draw(_hoverColor);
+ }
+
+ public function setPosition(x:Float, y:Float):Void
+ {
+ this.x = x;
+ this.y = y;
+
+ draw(_normalColor);
+ }
+
+ public function setSize(width:Float, height:Float):Void
+ {
+ _width = width;
+ _height = height;
+
+ draw(_normalColor);
+ }
+ //}
+}
\ No newline at end of file
diff --git a/lib/Jaris/src/jaris/player/newcontrols/PlayIcon.hx b/lib/Jaris/src/jaris/player/newcontrols/PlayIcon.hx
new file mode 100644
index 00000000..9059215e
--- /dev/null
+++ b/lib/Jaris/src/jaris/player/newcontrols/PlayIcon.hx
@@ -0,0 +1,122 @@
+/**
+ * @author Jefferson González
+ * @copyright 2010 Jefferson González
+ *
+ * @license
+ * This file is part of Jaris FLV Player.
+ *
+ * Jaris FLV Player is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License or GNU LESSER GENERAL
+ * PUBLIC LICENSE as published by the Free Software Foundation, either version
+ * 3 of the License, or (at your option) any later version.
+ *
+ * Jaris FLV Player is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License and
+ * GNU LESSER GENERAL PUBLIC LICENSE along with Jaris FLV Player. If not,
+ * see .
+ */
+
+package jaris.player.newcontrols;
+import flash.display.Sprite;
+import flash.events.MouseEvent;
+import flash.geom.Matrix;
+import jaris.utils.Utils;
+import flash.display.GradientType;
+
+class PlayIcon extends Sprite
+{
+ private var _width:Float;
+ private var _height:Float;
+ private var _normalColor:UInt;
+ private var _hoverColor:UInt;
+
+ public function new(x:Float, y:Float, width:Float, height:Float, normalColor:UInt, hoverColor:UInt)
+ {
+ super();
+
+ this.x = x;
+ this.y = y;
+ this.buttonMode = true;
+ this.useHandCursor = true;
+ this.tabEnabled = false;
+
+ _width = width;
+ _height = height;
+ _normalColor = normalColor;
+ _hoverColor = hoverColor;
+
+ addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
+ addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
+
+ draw(_normalColor);
+ }
+
+ private function onMouseOver(event:MouseEvent):Void
+ {
+ draw(_hoverColor);
+ }
+
+ private function onMouseOut(event:MouseEvent):Void
+ {
+ draw(_normalColor);
+ }
+
+ //{Private Methods
+ private function draw(color:UInt):Void
+ {
+ graphics.clear();
+ graphics.lineStyle(0, color, 0.0);
+ graphics.beginFill(color, 0);
+ graphics.drawRect(0, 0, _width, _height);
+ graphics.endFill();
+
+ var matrix:Matrix = new Matrix( );
+ matrix.createGradientBox(_width, _height, Utils.degreesToRadians(-90), _width, 0);
+ var colors:Array = [color, color];
+ var alphas:Array = [0.75, 1];
+ var ratios:Array = [0, 255];
+
+ graphics.lineStyle();
+ graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix);
+ //graphics.beginFill(color);
+ graphics.lineTo(0, _height);
+ graphics.lineTo(_width, _height / 2);
+ graphics.lineTo(0, 0);
+ graphics.endFill();
+ }
+ //}
+
+ //{Setters
+ public function setNormalColor(color:UInt):Void
+ {
+ _normalColor = color;
+ draw(_normalColor);
+ }
+
+ public function setHoverColor(color:UInt):Void
+ {
+ _hoverColor = color;
+ draw(_hoverColor);
+ }
+
+ public function setPosition(x:Float, y:Float):Void
+ {
+ this.x = x;
+ this.y = y;
+
+ draw(_normalColor);
+ }
+
+ public function setSize(width:Float, height:Float):Void
+ {
+ _width = width;
+ _height = height;
+
+ draw(_normalColor);
+ }
+ //}
+}
\ No newline at end of file
diff --git a/lib/Jaris/src/jaris/player/newcontrols/VolumeIcon.hx b/lib/Jaris/src/jaris/player/newcontrols/VolumeIcon.hx
new file mode 100644
index 00000000..c263ecfa
--- /dev/null
+++ b/lib/Jaris/src/jaris/player/newcontrols/VolumeIcon.hx
@@ -0,0 +1,125 @@
+/**
+ * @author Jefferson González
+ * @copyright 2010 Jefferson González
+ *
+ * @license
+ * This file is part of Jaris FLV Player.
+ *
+ * Jaris FLV Player is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License or GNU LESSER GENERAL
+ * PUBLIC LICENSE as published by the Free Software Foundation, either version
+ * 3 of the License, or (at your option) any later version.
+ *
+ * Jaris FLV Player is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License and
+ * GNU LESSER GENERAL PUBLIC LICENSE along with Jaris FLV Player. If not,
+ * see .
+ */
+
+package jaris.player.newcontrols;
+import flash.display.Sprite;
+import flash.events.MouseEvent;
+import flash.geom.Matrix;
+import jaris.utils.Utils;
+import flash.display.GradientType;
+
+class VolumeIcon extends Sprite
+{
+ private var _width:Float;
+ private var _height:Float;
+ private var _normalColor:UInt;
+ private var _hoverColor:UInt;
+
+ public function new(x:Float, y:Float, width:Float, height:Float, normalColor:UInt, hoverColor:UInt)
+ {
+ super();
+
+ this.x = x;
+ this.y = y;
+ this.buttonMode = true;
+ this.useHandCursor = true;
+ this.tabEnabled = false;
+
+ _width = width;
+ _height = height;
+ _normalColor = normalColor;
+ _hoverColor = hoverColor;
+
+ addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
+ addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
+
+ draw(_normalColor);
+ }
+
+ private function onMouseOver(event:MouseEvent):Void
+ {
+ draw(_hoverColor);
+ }
+
+ private function onMouseOut(event:MouseEvent):Void
+ {
+ draw(_normalColor);
+ }
+
+ //{Private Methods
+ private function draw(color:UInt):Void
+ {
+ graphics.clear();
+
+ graphics.lineStyle(0, color, 0.0);
+ graphics.beginFill(color, 0);
+ graphics.drawRect(0, 0, _width, _height);
+ graphics.endFill();
+
+ var matrix:Matrix = new Matrix( );
+ matrix.createGradientBox(_width, _height, Utils.degreesToRadians(-90), _width, 0);
+ var colors:Array = [color, color];
+ var alphas:Array = [0.75, 1];
+ var ratios:Array = [0, 255];
+
+ graphics.lineStyle();
+ graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix);
+ //graphics.beginFill(color, 1);
+ graphics.drawRect(0, ((50 / 100) * _height) / 2+1, _width / 2-1, ((50 / 100) * _height));
+ graphics.moveTo(_width / 2 -1, ((50 / 100) * _height)/2+1);
+ graphics.lineTo(_width, 0);
+ graphics.lineTo(_width, _height+2);
+ graphics.lineTo(_width / 2 -1, ((50 / 100) * _height) + (((50 / 100) * _height) / 2)+1);
+ graphics.endFill();
+ }
+ //}
+
+ //{Setters
+ public function setNormalColor(color:UInt):Void
+ {
+ _normalColor = color;
+ draw(_normalColor);
+ }
+
+ public function setHoverColor(color:UInt):Void
+ {
+ _hoverColor = color;
+ draw(_hoverColor);
+ }
+
+ public function setPosition(x:Float, y:Float):Void
+ {
+ this.x = x;
+ this.y = y;
+
+ draw(_normalColor);
+ }
+
+ public function setSize(width:Float, height:Float):Void
+ {
+ _width = width;
+ _height = height;
+
+ draw(_normalColor);
+ }
+ //}
+}
\ No newline at end of file
diff --git a/lib/Jaris/src/jaris/utils/Utils.hx b/lib/Jaris/src/jaris/utils/Utils.hx
new file mode 100644
index 00000000..be279307
--- /dev/null
+++ b/lib/Jaris/src/jaris/utils/Utils.hx
@@ -0,0 +1,161 @@
+/**
+ * @author Jefferson González
+ * @copyright 2010 Jefferson González
+ *
+ * @license
+ * This file is part of Jaris FLV Player.
+ *
+ * Jaris FLV Player is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License or GNU LESSER GENERAL
+ * PUBLIC LICENSE as published by the Free Software Foundation, either version
+ * 3 of the License, or (at your option) any later version.
+ *
+ * Jaris FLV Player is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License and
+ * GNU LESSER GENERAL PUBLIC LICENSE along with Jaris FLV Player. If not,
+ * see .
+ */
+
+package jaris.utils;
+
+/**
+ * Some utility functions
+ */
+class Utils
+{
+
+ /**
+ * Converts degrees to radians for easy rotation where applicable
+ * @param value A radian value to convert
+ * @return conversion of degree to radian
+ */
+ public static function degreesToRadians(value:Float):Float
+ {
+ return (Math.PI / 180) * value;
+ }
+
+ /**
+ * Converts a float value representing seconds to a readale string
+ * @param time A given time in seconds
+ * @return A string in the format 00:00:00
+ */
+ public static function formatTime(time:Float):String
+ {
+ var seconds:String = "";
+ var minutes:String = "";
+ var hours:String = "";
+ var timeString:String = "";
+
+ if (((time / 60) / 60) >= 1)
+ {
+ if (Math.floor((time / 60)) / 60 < 10)
+ {
+ hours = "0" + Math.floor((time / 60) / 60) + ":";
+ }
+ else
+ {
+ hours = Math.floor((time / 60) / 60) + ":";
+ }
+
+ if (Math.floor((time / 60) % 60) < 10)
+ {
+ minutes = "0" + Math.floor((time / 60) % 60) + ":";
+ }
+ else
+ {
+ minutes = Math.floor((time / 60) % 60) + ":";
+ }
+
+ if (Math.floor(time % 60) < 10)
+ {
+ seconds = "0" + Math.floor(time % 60);
+ }
+ else
+ {
+ seconds = Std.string(Math.floor(time % 60));
+ }
+ }
+ else if((time / 60) >= 1)
+ {
+ hours = "00:";
+
+ if (Math.floor(time / 60) < 10)
+ {
+ minutes = "0" + Math.floor(time / 60) + ":";
+ }
+ else
+ {
+ minutes = Math.floor(time / 60) + ":";
+ }
+
+ if (Math.floor(time % 60) < 10)
+ {
+ seconds = "0" + Math.floor(time % 60);
+ }
+ else
+ {
+ seconds = Std.string(Math.floor(time % 60));
+ }
+ }
+ else
+ {
+ hours = "00:";
+
+ minutes = "00:";
+
+ if (Math.floor(time) < 10)
+ {
+ seconds = "0" + Math.floor(time);
+ }
+ else
+ {
+ seconds = Std.string(Math.floor(time));
+ }
+ }
+
+ timeString += hours + minutes + seconds;
+
+ return timeString;
+ }
+
+ /**
+ * Converts a given rtmp source to a valid format for NetStream
+ * @param source
+ * @return
+ */
+ public static function rtmpSourceParser(source:String):String
+ {
+ if (source.indexOf(".flv") != -1)
+ {
+ return source.split(".flv").join("");
+ }
+ else if (source.indexOf(".mp3") != -1)
+ {
+ return "mp3:" + source.split(".mp3").join("");
+ }
+ else if (source.indexOf(".mp4") != -1)
+ {
+ return "mp4:" + source;
+ }
+ else if (source.indexOf(".f4v") != -1)
+ {
+ return "mp4:" + source;
+ }
+
+ return source;
+ }
+
+ /**
+ * Changes a youtube url to the format youtube.com/v/video_id
+ * @param source
+ * @return
+ */
+ public static function youtubeSourceParse(source:String):String
+ {
+ return source.split("watch?v=").join("v/");
+ }
+}
\ No newline at end of file
diff --git a/lib/getid3/getid3/extension.cache.dbm.php b/lib/getid3/getid3/extension.cache.dbm.php
new file mode 100644
index 00000000..9a88c22b
--- /dev/null
+++ b/lib/getid3/getid3/extension.cache.dbm.php
@@ -0,0 +1,211 @@
+ //
+// available at http://getid3.sourceforge.net //
+// or http://www.getid3.org //
+/////////////////////////////////////////////////////////////////
+// //
+// extension.cache.dbm.php - part of getID3() //
+// Please see readme.txt for more information //
+// ///
+/////////////////////////////////////////////////////////////////
+// //
+// This extension written by Allan Hansen //
+// ///
+/////////////////////////////////////////////////////////////////
+
+
+/**
+* This is a caching extension for getID3(). It works the exact same
+* way as the getID3 class, but return cached information very fast
+*
+* Example:
+*
+* Normal getID3 usage (example):
+*
+* require_once 'getid3/getid3.php';
+* $getID3 = new getID3;
+* $getID3->encoding = 'UTF-8';
+* $info1 = $getID3->analyze('file1.flac');
+* $info2 = $getID3->analyze('file2.wv');
+*
+* getID3_cached usage:
+*
+* require_once 'getid3/getid3.php';
+* require_once 'getid3/getid3/extension.cache.dbm.php';
+* $getID3 = new getID3_cached('db3', '/tmp/getid3_cache.dbm',
+* '/tmp/getid3_cache.lock');
+* $getID3->encoding = 'UTF-8';
+* $info1 = $getID3->analyze('file1.flac');
+* $info2 = $getID3->analyze('file2.wv');
+*
+*
+* Supported Cache Types
+*
+* SQL Databases: (use extension.cache.mysql)
+*
+* cache_type cache_options
+* -------------------------------------------------------------------
+* mysql host, database, username, password
+*
+*
+* DBM-Style Databases: (this extension)
+*
+* cache_type cache_options
+* -------------------------------------------------------------------
+* gdbm dbm_filename, lock_filename
+* ndbm dbm_filename, lock_filename
+* db2 dbm_filename, lock_filename
+* db3 dbm_filename, lock_filename
+* db4 dbm_filename, lock_filename (PHP5 required)
+*
+* PHP must have write access to both dbm_filename and lock_filename.
+*
+*
+* Recommended Cache Types
+*
+* Infrequent updates, many reads any DBM
+* Frequent updates mysql
+*/
+
+
+class getID3_cached_dbm extends getID3
+{
+
+ // public: constructor - see top of this file for cache type and cache_options
+ function getID3_cached_dbm($cache_type, $dbm_filename, $lock_filename) {
+
+ // Check for dba extension
+ if (!extension_loaded('dba')) {
+ throw new Exception('PHP is not compiled with dba support, required to use DBM style cache.');
+ }
+
+ // Check for specific dba driver
+ if (!function_exists('dba_handlers') || !in_array($cache_type, dba_handlers())) {
+ throw new Exception('PHP is not compiled --with '.$cache_type.' support, required to use DBM style cache.');
+ }
+
+ // Create lock file if needed
+ if (!file_exists($lock_filename)) {
+ if (!touch($lock_filename)) {
+ throw new Exception('failed to create lock file: '.$lock_filename);
+ }
+ }
+
+ // Open lock file for writing
+ if (!is_writeable($lock_filename)) {
+ throw new Exception('lock file: '.$lock_filename.' is not writable');
+ }
+ $this->lock = fopen($lock_filename, 'w');
+
+ // Acquire exclusive write lock to lock file
+ flock($this->lock, LOCK_EX);
+
+ // Create dbm-file if needed
+ if (!file_exists($dbm_filename)) {
+ if (!touch($dbm_filename)) {
+ throw new Exception('failed to create dbm file: '.$dbm_filename);
+ }
+ }
+
+ // Try to open dbm file for writing
+ $this->dba = dba_open($dbm_filename, 'w', $cache_type);
+ if (!$this->dba) {
+
+ // Failed - create new dbm file
+ $this->dba = dba_open($dbm_filename, 'n', $cache_type);
+
+ if (!$this->dba) {
+ throw new Exception('failed to create dbm file: '.$dbm_filename);
+ }
+
+ // Insert getID3 version number
+ dba_insert(getID3::VERSION, getID3::VERSION, $this->dba);
+ }
+
+ // Init misc values
+ $this->cache_type = $cache_type;
+ $this->dbm_filename = $dbm_filename;
+
+ // Register destructor
+ register_shutdown_function(array($this, '__destruct'));
+
+ // Check version number and clear cache if changed
+ if (dba_fetch(getID3::VERSION, $this->dba) != getID3::VERSION) {
+ $this->clear_cache();
+ }
+
+ parent::getID3();
+ }
+
+
+
+ // public: destuctor
+ function __destruct() {
+
+ // Close dbm file
+ dba_close($this->dba);
+
+ // Release exclusive lock
+ flock($this->lock, LOCK_UN);
+
+ // Close lock file
+ fclose($this->lock);
+ }
+
+
+
+ // public: clear cache
+ function clear_cache() {
+
+ // Close dbm file
+ dba_close($this->dba);
+
+ // Create new dbm file
+ $this->dba = dba_open($this->dbm_filename, 'n', $this->cache_type);
+
+ if (!$this->dba) {
+ throw new Exception('failed to clear cache/recreate dbm file: '.$this->dbm_filename);
+ }
+
+ // Insert getID3 version number
+ dba_insert(getID3::VERSION, getID3::VERSION, $this->dba);
+
+ // Re-register shutdown function
+ register_shutdown_function(array($this, '__destruct'));
+ }
+
+
+
+ // public: analyze file
+ function analyze($filename) {
+
+ if (file_exists($filename)) {
+
+ // Calc key filename::mod_time::size - should be unique
+ $key = $filename.'::'.filemtime($filename).'::'.filesize($filename);
+
+ // Loopup key
+ $result = dba_fetch($key, $this->dba);
+
+ // Hit
+ if ($result !== false) {
+ return unserialize($result);
+ }
+ }
+
+ // Miss
+ $result = parent::analyze($filename);
+
+ // Save result
+ if (file_exists($filename)) {
+ dba_insert($key, serialize($result), $this->dba);
+ }
+
+ return $result;
+ }
+
+}
+
+
+?>
\ No newline at end of file
diff --git a/lib/getid3/getid3/extension.cache.mysql.php b/lib/getid3/getid3/extension.cache.mysql.php
new file mode 100644
index 00000000..1e1f91fa
--- /dev/null
+++ b/lib/getid3/getid3/extension.cache.mysql.php
@@ -0,0 +1,173 @@
+ //
+// available at http://getid3.sourceforge.net //
+// or http://www.getid3.org //
+/////////////////////////////////////////////////////////////////
+// //
+// extension.cache.mysql.php - part of getID3() //
+// Please see readme.txt for more information //
+// ///
+/////////////////////////////////////////////////////////////////
+// //
+// This extension written by Allan Hansen //
+// Table name mod by Carlo Capocasa //
+// ///
+/////////////////////////////////////////////////////////////////
+
+
+/**
+* This is a caching extension for getID3(). It works the exact same
+* way as the getID3 class, but return cached information very fast
+*
+* Example: (see also demo.cache.mysql.php in /demo/)
+*
+* Normal getID3 usage (example):
+*
+* require_once 'getid3/getid3.php';
+* $getID3 = new getID3;
+* $getID3->encoding = 'UTF-8';
+* $info1 = $getID3->analyze('file1.flac');
+* $info2 = $getID3->analyze('file2.wv');
+*
+* getID3_cached usage:
+*
+* require_once 'getid3/getid3.php';
+* require_once 'getid3/getid3/extension.cache.mysql.php';
+* // 5th parameter (tablename) is optional, default is 'getid3_cache'
+* $getID3 = new getID3_cached_mysql('localhost', 'database', 'username', 'password', 'tablename');
+* $getID3->encoding = 'UTF-8';
+* $info1 = $getID3->analyze('file1.flac');
+* $info2 = $getID3->analyze('file2.wv');
+*
+*
+* Supported Cache Types (this extension)
+*
+* SQL Databases:
+*
+* cache_type cache_options
+* -------------------------------------------------------------------
+* mysql host, database, username, password
+*
+*
+* DBM-Style Databases: (use extension.cache.dbm)
+*
+* cache_type cache_options
+* -------------------------------------------------------------------
+* gdbm dbm_filename, lock_filename
+* ndbm dbm_filename, lock_filename
+* db2 dbm_filename, lock_filename
+* db3 dbm_filename, lock_filename
+* db4 dbm_filename, lock_filename (PHP5 required)
+*
+* PHP must have write access to both dbm_filename and lock_filename.
+*
+*
+* Recommended Cache Types
+*
+* Infrequent updates, many reads any DBM
+* Frequent updates mysql
+*/
+
+
+class getID3_cached_mysql extends getID3
+{
+
+ // private vars
+ var $cursor;
+ var $connection;
+
+
+ // public: constructor - see top of this file for cache type and cache_options
+ function getID3_cached_mysql($host, $database, $username, $password, $table='getid3_cache') {
+
+ // Check for mysql support
+ if (!function_exists('mysql_pconnect')) {
+ throw new Exception('PHP not compiled with mysql support.');
+ }
+
+ // Connect to database
+ $this->connection = mysql_pconnect($host, $username, $password);
+ if (!$this->connection) {
+ throw new Exception('mysql_pconnect() failed - check permissions and spelling.');
+ }
+
+ // Select database
+ if (!mysql_select_db($database, $this->connection)) {
+ throw new Exception('Cannot use database '.$database);
+ }
+
+ // Set table
+ $this->table = $table;
+
+ // Create cache table if not exists
+ $this->create_table();
+
+ // Check version number and clear cache if changed
+ $version = '';
+ if ($this->cursor = mysql_query("SELECT `value` FROM `".mysql_real_escape_string($this->table)."` WHERE (`filename` = '".mysql_real_escape_string(getID3::VERSION)."') AND (`filesize` = '-1') AND (`filetime` = '-1') AND (`analyzetime` = '-1')", $this->connection)) {
+ list($version) = mysql_fetch_array($this->cursor);
+ }
+ if ($version != getID3::VERSION) {
+ $this->clear_cache();
+ }
+
+ parent::getID3();
+ }
+
+
+
+ // public: clear cache
+ function clear_cache() {
+
+ $this->cursor = mysql_query("DELETE FROM `".mysql_real_escape_string($this->table)."`", $this->connection);
+ $this->cursor = mysql_query("INSERT INTO `".mysql_real_escape_string($this->table)."` VALUES ('".getID3::VERSION."', -1, -1, -1, '".getID3::VERSION."')", $this->connection);
+ }
+
+
+
+ // public: analyze file
+ function analyze($filename) {
+
+ if (file_exists($filename)) {
+
+ // Short-hands
+ $filetime = filemtime($filename);
+ $filesize = filesize($filename);
+
+ // Lookup file
+ $this->cursor = mysql_query("SELECT `value` FROM `".mysql_real_escape_string($this->table)."` WHERE (`filename` = '".mysql_real_escape_string($filename)."') AND (`filesize` = '".mysql_real_escape_string($filesize)."') AND (`filetime` = '".mysql_real_escape_string($filetime)."')", $this->connection);
+ if (mysql_num_rows($this->cursor) > 0) {
+ // Hit
+ list($result) = mysql_fetch_array($this->cursor);
+ return unserialize(base64_decode($result));
+ }
+ }
+
+ // Miss
+ $analysis = parent::analyze($filename);
+
+ // Save result
+ if (file_exists($filename)) {
+ $this->cursor = mysql_query("INSERT INTO `".mysql_real_escape_string($this->table)."` (`filename`, `filesize`, `filetime`, `analyzetime`, `value`) VALUES ('".mysql_real_escape_string($filename)."', '".mysql_real_escape_string($filesize)."', '".mysql_real_escape_string($filetime)."', '".mysql_real_escape_string(time())."', '".mysql_real_escape_string(base64_encode(serialize($analysis)))."')", $this->connection);
+ }
+ return $analysis;
+ }
+
+
+
+ // private: (re)create sql table
+ function create_table($drop=false) {
+
+ $this->cursor = mysql_query("CREATE TABLE IF NOT EXISTS `".mysql_real_escape_string($this->table)."` (
+ `filename` VARCHAR(255) NOT NULL DEFAULT '',
+ `filesize` INT(11) NOT NULL DEFAULT '0',
+ `filetime` INT(11) NOT NULL DEFAULT '0',
+ `analyzetime` INT(11) NOT NULL DEFAULT '0',
+ `value` TEXT NOT NULL,
+ PRIMARY KEY (`filename`,`filesize`,`filetime`)) TYPE=MyISAM", $this->connection);
+ echo mysql_error($this->connection);
+ }
+}
+
+?>
\ No newline at end of file
diff --git a/lib/getid3/getid3/getid3.lib.php b/lib/getid3/getid3/getid3.lib.php
new file mode 100644
index 00000000..723e2e24
--- /dev/null
+++ b/lib/getid3/getid3/getid3.lib.php
@@ -0,0 +1,1317 @@
+ //
+// available at http://getid3.sourceforge.net //
+// or http://www.getid3.org //
+/////////////////////////////////////////////////////////////////
+// //
+// getid3.lib.php - part of getID3() //
+// See readme.txt for more details //
+// ///
+/////////////////////////////////////////////////////////////////
+
+
+class getid3_lib
+{
+
+ static function PrintHexBytes($string, $hex=true, $spaces=true, $htmlencoding='UTF-8') {
+ $returnstring = '';
+ for ($i = 0; $i < strlen($string); $i++) {
+ if ($hex) {
+ $returnstring .= str_pad(dechex(ord($string{$i})), 2, '0', STR_PAD_LEFT);
+ } else {
+ $returnstring .= ' '.(preg_match("#[\x20-\x7E]#", $string{$i}) ? $string{$i} : '¤');
+ }
+ if ($spaces) {
+ $returnstring .= ' ';
+ }
+ }
+ if (!empty($htmlencoding)) {
+ if ($htmlencoding === true) {
+ $htmlencoding = 'UTF-8'; // prior to getID3 v1.9.0 the function's 4th parameter was boolean
+ }
+ $returnstring = htmlentities($returnstring, ENT_QUOTES, $htmlencoding);
+ }
+ return $returnstring;
+ }
+
+ static function trunc($floatnumber) {
+ // truncates a floating-point number at the decimal point
+ // returns int (if possible, otherwise float)
+ if ($floatnumber >= 1) {
+ $truncatednumber = floor($floatnumber);
+ } elseif ($floatnumber <= -1) {
+ $truncatednumber = ceil($floatnumber);
+ } else {
+ $truncatednumber = 0;
+ }
+ if (getid3_lib::intValueSupported($truncatednumber)) {
+ $truncatednumber = (int) $truncatednumber;
+ }
+ return $truncatednumber;
+ }
+
+
+ static function safe_inc(&$variable, $increment=1) {
+ if (isset($variable)) {
+ $variable += $increment;
+ } else {
+ $variable = $increment;
+ }
+ return true;
+ }
+
+ static function CastAsInt($floatnum) {
+ // convert to float if not already
+ $floatnum = (float) $floatnum;
+
+ // convert a float to type int, only if possible
+ if (getid3_lib::trunc($floatnum) == $floatnum) {
+ // it's not floating point
+ if (getid3_lib::intValueSupported($floatnum)) {
+ // it's within int range
+ $floatnum = (int) $floatnum;
+ }
+ }
+ return $floatnum;
+ }
+
+ public static function intValueSupported($num) {
+ // check if integers are 64-bit
+ static $hasINT64 = null;
+ if ($hasINT64 === null) { // 10x faster than is_null()
+ $hasINT64 = is_int(pow(2, 31)); // 32-bit int are limited to (2^31)-1
+ if (!$hasINT64 && !defined('PHP_INT_MIN')) {
+ define('PHP_INT_MIN', ~PHP_INT_MAX);
+ }
+ }
+ // if integers are 64-bit - no other check required
+ if ($hasINT64 || (($num <= PHP_INT_MAX) && ($num >= PHP_INT_MIN))) {
+ return true;
+ }
+ return false;
+ }
+
+ static function DecimalizeFraction($fraction) {
+ list($numerator, $denominator) = explode('/', $fraction);
+ return $numerator / ($denominator ? $denominator : 1);
+ }
+
+
+ static function DecimalBinary2Float($binarynumerator) {
+ $numerator = getid3_lib::Bin2Dec($binarynumerator);
+ $denominator = getid3_lib::Bin2Dec('1'.str_repeat('0', strlen($binarynumerator)));
+ return ($numerator / $denominator);
+ }
+
+
+ static function NormalizeBinaryPoint($binarypointnumber, $maxbits=52) {
+ // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/binary.html
+ if (strpos($binarypointnumber, '.') === false) {
+ $binarypointnumber = '0.'.$binarypointnumber;
+ } elseif ($binarypointnumber{0} == '.') {
+ $binarypointnumber = '0'.$binarypointnumber;
+ }
+ $exponent = 0;
+ while (($binarypointnumber{0} != '1') || (substr($binarypointnumber, 1, 1) != '.')) {
+ if (substr($binarypointnumber, 1, 1) == '.') {
+ $exponent--;
+ $binarypointnumber = substr($binarypointnumber, 2, 1).'.'.substr($binarypointnumber, 3);
+ } else {
+ $pointpos = strpos($binarypointnumber, '.');
+ $exponent += ($pointpos - 1);
+ $binarypointnumber = str_replace('.', '', $binarypointnumber);
+ $binarypointnumber = $binarypointnumber{0}.'.'.substr($binarypointnumber, 1);
+ }
+ }
+ $binarypointnumber = str_pad(substr($binarypointnumber, 0, $maxbits + 2), $maxbits + 2, '0', STR_PAD_RIGHT);
+ return array('normalized'=>$binarypointnumber, 'exponent'=>(int) $exponent);
+ }
+
+
+ static function Float2BinaryDecimal($floatvalue) {
+ // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/binary.html
+ $maxbits = 128; // to how many bits of precision should the calculations be taken?
+ $intpart = getid3_lib::trunc($floatvalue);
+ $floatpart = abs($floatvalue - $intpart);
+ $pointbitstring = '';
+ while (($floatpart != 0) && (strlen($pointbitstring) < $maxbits)) {
+ $floatpart *= 2;
+ $pointbitstring .= (string) getid3_lib::trunc($floatpart);
+ $floatpart -= getid3_lib::trunc($floatpart);
+ }
+ $binarypointnumber = decbin($intpart).'.'.$pointbitstring;
+ return $binarypointnumber;
+ }
+
+
+ static function Float2String($floatvalue, $bits) {
+ // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee-expl.html
+ switch ($bits) {
+ case 32:
+ $exponentbits = 8;
+ $fractionbits = 23;
+ break;
+
+ case 64:
+ $exponentbits = 11;
+ $fractionbits = 52;
+ break;
+
+ default:
+ return false;
+ break;
+ }
+ if ($floatvalue >= 0) {
+ $signbit = '0';
+ } else {
+ $signbit = '1';
+ }
+ $normalizedbinary = getid3_lib::NormalizeBinaryPoint(getid3_lib::Float2BinaryDecimal($floatvalue), $fractionbits);
+ $biasedexponent = pow(2, $exponentbits - 1) - 1 + $normalizedbinary['exponent']; // (127 or 1023) +/- exponent
+ $exponentbitstring = str_pad(decbin($biasedexponent), $exponentbits, '0', STR_PAD_LEFT);
+ $fractionbitstring = str_pad(substr($normalizedbinary['normalized'], 2), $fractionbits, '0', STR_PAD_RIGHT);
+
+ return getid3_lib::BigEndian2String(getid3_lib::Bin2Dec($signbit.$exponentbitstring.$fractionbitstring), $bits % 8, false);
+ }
+
+
+ static function LittleEndian2Float($byteword) {
+ return getid3_lib::BigEndian2Float(strrev($byteword));
+ }
+
+
+ static function BigEndian2Float($byteword) {
+ // ANSI/IEEE Standard 754-1985, Standard for Binary Floating Point Arithmetic
+ // http://www.psc.edu/general/software/packages/ieee/ieee.html
+ // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee.html
+
+ $bitword = getid3_lib::BigEndian2Bin($byteword);
+ if (!$bitword) {
+ return 0;
+ }
+ $signbit = $bitword{0};
+
+ switch (strlen($byteword) * 8) {
+ case 32:
+ $exponentbits = 8;
+ $fractionbits = 23;
+ break;
+
+ case 64:
+ $exponentbits = 11;
+ $fractionbits = 52;
+ break;
+
+ case 80:
+ // 80-bit Apple SANE format
+ // http://www.mactech.com/articles/mactech/Vol.06/06.01/SANENormalized/
+ $exponentstring = substr($bitword, 1, 15);
+ $isnormalized = intval($bitword{16});
+ $fractionstring = substr($bitword, 17, 63);
+ $exponent = pow(2, getid3_lib::Bin2Dec($exponentstring) - 16383);
+ $fraction = $isnormalized + getid3_lib::DecimalBinary2Float($fractionstring);
+ $floatvalue = $exponent * $fraction;
+ if ($signbit == '1') {
+ $floatvalue *= -1;
+ }
+ return $floatvalue;
+ break;
+
+ default:
+ return false;
+ break;
+ }
+ $exponentstring = substr($bitword, 1, $exponentbits);
+ $fractionstring = substr($bitword, $exponentbits + 1, $fractionbits);
+ $exponent = getid3_lib::Bin2Dec($exponentstring);
+ $fraction = getid3_lib::Bin2Dec($fractionstring);
+
+ if (($exponent == (pow(2, $exponentbits) - 1)) && ($fraction != 0)) {
+ // Not a Number
+ $floatvalue = false;
+ } elseif (($exponent == (pow(2, $exponentbits) - 1)) && ($fraction == 0)) {
+ if ($signbit == '1') {
+ $floatvalue = '-infinity';
+ } else {
+ $floatvalue = '+infinity';
+ }
+ } elseif (($exponent == 0) && ($fraction == 0)) {
+ if ($signbit == '1') {
+ $floatvalue = -0;
+ } else {
+ $floatvalue = 0;
+ }
+ $floatvalue = ($signbit ? 0 : -0);
+ } elseif (($exponent == 0) && ($fraction != 0)) {
+ // These are 'unnormalized' values
+ $floatvalue = pow(2, (-1 * (pow(2, $exponentbits - 1) - 2))) * getid3_lib::DecimalBinary2Float($fractionstring);
+ if ($signbit == '1') {
+ $floatvalue *= -1;
+ }
+ } elseif ($exponent != 0) {
+ $floatvalue = pow(2, ($exponent - (pow(2, $exponentbits - 1) - 1))) * (1 + getid3_lib::DecimalBinary2Float($fractionstring));
+ if ($signbit == '1') {
+ $floatvalue *= -1;
+ }
+ }
+ return (float) $floatvalue;
+ }
+
+
+ static function BigEndian2Int($byteword, $synchsafe=false, $signed=false) {
+ $intvalue = 0;
+ $bytewordlen = strlen($byteword);
+ if ($bytewordlen == 0) {
+ return false;
+ }
+ for ($i = 0; $i < $bytewordlen; $i++) {
+ if ($synchsafe) { // disregard MSB, effectively 7-bit bytes
+ //$intvalue = $intvalue | (ord($byteword{$i}) & 0x7F) << (($bytewordlen - 1 - $i) * 7); // faster, but runs into problems past 2^31 on 32-bit systems
+ $intvalue += (ord($byteword{$i}) & 0x7F) * pow(2, ($bytewordlen - 1 - $i) * 7);
+ } else {
+ $intvalue += ord($byteword{$i}) * pow(256, ($bytewordlen - 1 - $i));
+ }
+ }
+ if ($signed && !$synchsafe) {
+ // synchsafe ints are not allowed to be signed
+ if ($bytewordlen <= PHP_INT_SIZE) {
+ $signMaskBit = 0x80 << (8 * ($bytewordlen - 1));
+ if ($intvalue & $signMaskBit) {
+ $intvalue = 0 - ($intvalue & ($signMaskBit - 1));
+ }
+ } else {
+ throw new Exception('ERROR: Cannot have signed integers larger than '.(8 * PHP_INT_SIZE).'-bits ('.strlen($byteword).') in getid3_lib::BigEndian2Int()');
+ break;
+ }
+ }
+ return getid3_lib::CastAsInt($intvalue);
+ }
+
+
+ static function LittleEndian2Int($byteword, $signed=false) {
+ return getid3_lib::BigEndian2Int(strrev($byteword), false, $signed);
+ }
+
+
+ static function BigEndian2Bin($byteword) {
+ $binvalue = '';
+ $bytewordlen = strlen($byteword);
+ for ($i = 0; $i < $bytewordlen; $i++) {
+ $binvalue .= str_pad(decbin(ord($byteword{$i})), 8, '0', STR_PAD_LEFT);
+ }
+ return $binvalue;
+ }
+
+
+ static function BigEndian2String($number, $minbytes=1, $synchsafe=false, $signed=false) {
+ if ($number < 0) {
+ throw new Exception('ERROR: getid3_lib::BigEndian2String() does not support negative numbers');
+ }
+ $maskbyte = (($synchsafe || $signed) ? 0x7F : 0xFF);
+ $intstring = '';
+ if ($signed) {
+ if ($minbytes > PHP_INT_SIZE) {
+ throw new Exception('ERROR: Cannot have signed integers larger than '.(8 * PHP_INT_SIZE).'-bits in getid3_lib::BigEndian2String()');
+ }
+ $number = $number & (0x80 << (8 * ($minbytes - 1)));
+ }
+ while ($number != 0) {
+ $quotient = ($number / ($maskbyte + 1));
+ $intstring = chr(ceil(($quotient - floor($quotient)) * $maskbyte)).$intstring;
+ $number = floor($quotient);
+ }
+ return str_pad($intstring, $minbytes, "\x00", STR_PAD_LEFT);
+ }
+
+
+ static function Dec2Bin($number) {
+ while ($number >= 256) {
+ $bytes[] = (($number / 256) - (floor($number / 256))) * 256;
+ $number = floor($number / 256);
+ }
+ $bytes[] = $number;
+ $binstring = '';
+ for ($i = 0; $i < count($bytes); $i++) {
+ $binstring = (($i == count($bytes) - 1) ? decbin($bytes[$i]) : str_pad(decbin($bytes[$i]), 8, '0', STR_PAD_LEFT)).$binstring;
+ }
+ return $binstring;
+ }
+
+
+ static function Bin2Dec($binstring, $signed=false) {
+ $signmult = 1;
+ if ($signed) {
+ if ($binstring{0} == '1') {
+ $signmult = -1;
+ }
+ $binstring = substr($binstring, 1);
+ }
+ $decvalue = 0;
+ for ($i = 0; $i < strlen($binstring); $i++) {
+ $decvalue += ((int) substr($binstring, strlen($binstring) - $i - 1, 1)) * pow(2, $i);
+ }
+ return getid3_lib::CastAsInt($decvalue * $signmult);
+ }
+
+
+ static function Bin2String($binstring) {
+ // return 'hi' for input of '0110100001101001'
+ $string = '';
+ $binstringreversed = strrev($binstring);
+ for ($i = 0; $i < strlen($binstringreversed); $i += 8) {
+ $string = chr(getid3_lib::Bin2Dec(strrev(substr($binstringreversed, $i, 8)))).$string;
+ }
+ return $string;
+ }
+
+
+ static function LittleEndian2String($number, $minbytes=1, $synchsafe=false) {
+ $intstring = '';
+ while ($number > 0) {
+ if ($synchsafe) {
+ $intstring = $intstring.chr($number & 127);
+ $number >>= 7;
+ } else {
+ $intstring = $intstring.chr($number & 255);
+ $number >>= 8;
+ }
+ }
+ return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
+ }
+
+
+ static function array_merge_clobber($array1, $array2) {
+ // written by kcØhireability*com
+ // taken from http://www.php.net/manual/en/function.array-merge-recursive.php
+ if (!is_array($array1) || !is_array($array2)) {
+ return false;
+ }
+ $newarray = $array1;
+ foreach ($array2 as $key => $val) {
+ if (is_array($val) && isset($newarray[$key]) && is_array($newarray[$key])) {
+ $newarray[$key] = getid3_lib::array_merge_clobber($newarray[$key], $val);
+ } else {
+ $newarray[$key] = $val;
+ }
+ }
+ return $newarray;
+ }
+
+
+ static function array_merge_noclobber($array1, $array2) {
+ if (!is_array($array1) || !is_array($array2)) {
+ return false;
+ }
+ $newarray = $array1;
+ foreach ($array2 as $key => $val) {
+ if (is_array($val) && isset($newarray[$key]) && is_array($newarray[$key])) {
+ $newarray[$key] = getid3_lib::array_merge_noclobber($newarray[$key], $val);
+ } elseif (!isset($newarray[$key])) {
+ $newarray[$key] = $val;
+ }
+ }
+ return $newarray;
+ }
+
+
+ static function ksort_recursive(&$theArray) {
+ ksort($theArray);
+ foreach ($theArray as $key => $value) {
+ if (is_array($value)) {
+ self::ksort_recursive($theArray[$key]);
+ }
+ }
+ return true;
+ }
+
+ static function fileextension($filename, $numextensions=1) {
+ if (strstr($filename, '.')) {
+ $reversedfilename = strrev($filename);
+ $offset = 0;
+ for ($i = 0; $i < $numextensions; $i++) {
+ $offset = strpos($reversedfilename, '.', $offset + 1);
+ if ($offset === false) {
+ return '';
+ }
+ }
+ return strrev(substr($reversedfilename, 0, $offset));
+ }
+ return '';
+ }
+
+
+ static function PlaytimeString($seconds) {
+ $sign = (($seconds < 0) ? '-' : '');
+ $seconds = abs($seconds);
+ $H = floor( $seconds / 3600);
+ $M = floor(($seconds - (3600 * $H) ) / 60);
+ $S = round( $seconds - (3600 * $H) - (60 * $M) );
+ return $sign.($H ? $H.':' : '').($H ? str_pad($M, 2, '0', STR_PAD_LEFT) : intval($M)).':'.str_pad($S, 2, 0, STR_PAD_LEFT);
+ }
+
+
+ static function DateMac2Unix($macdate) {
+ // Macintosh timestamp: seconds since 00:00h January 1, 1904
+ // UNIX timestamp: seconds since 00:00h January 1, 1970
+ return getid3_lib::CastAsInt($macdate - 2082844800);
+ }
+
+
+ static function FixedPoint8_8($rawdata) {
+ return getid3_lib::BigEndian2Int(substr($rawdata, 0, 1)) + (float) (getid3_lib::BigEndian2Int(substr($rawdata, 1, 1)) / pow(2, 8));
+ }
+
+
+ static function FixedPoint16_16($rawdata) {
+ return getid3_lib::BigEndian2Int(substr($rawdata, 0, 2)) + (float) (getid3_lib::BigEndian2Int(substr($rawdata, 2, 2)) / pow(2, 16));
+ }
+
+
+ static function FixedPoint2_30($rawdata) {
+ $binarystring = getid3_lib::BigEndian2Bin($rawdata);
+ return getid3_lib::Bin2Dec(substr($binarystring, 0, 2)) + (float) (getid3_lib::Bin2Dec(substr($binarystring, 2, 30)) / pow(2, 30));
+ }
+
+
+ static function CreateDeepArray($ArrayPath, $Separator, $Value) {
+ // assigns $Value to a nested array path:
+ // $foo = getid3_lib::CreateDeepArray('/path/to/my', '/', 'file.txt')
+ // is the same as:
+ // $foo = array('path'=>array('to'=>'array('my'=>array('file.txt'))));
+ // or
+ // $foo['path']['to']['my'] = 'file.txt';
+ while ($ArrayPath && ($ArrayPath{0} == $Separator)) {
+ $ArrayPath = substr($ArrayPath, 1);
+ }
+ if (($pos = strpos($ArrayPath, $Separator)) !== false) {
+ $ReturnedArray[substr($ArrayPath, 0, $pos)] = getid3_lib::CreateDeepArray(substr($ArrayPath, $pos + 1), $Separator, $Value);
+ } else {
+ $ReturnedArray[$ArrayPath] = $Value;
+ }
+ return $ReturnedArray;
+ }
+
+ static function array_max($arraydata, $returnkey=false) {
+ $maxvalue = false;
+ $maxkey = false;
+ foreach ($arraydata as $key => $value) {
+ if (!is_array($value)) {
+ if ($value > $maxvalue) {
+ $maxvalue = $value;
+ $maxkey = $key;
+ }
+ }
+ }
+ return ($returnkey ? $maxkey : $maxvalue);
+ }
+
+ static function array_min($arraydata, $returnkey=false) {
+ $minvalue = false;
+ $minkey = false;
+ foreach ($arraydata as $key => $value) {
+ if (!is_array($value)) {
+ if ($value > $minvalue) {
+ $minvalue = $value;
+ $minkey = $key;
+ }
+ }
+ }
+ return ($returnkey ? $minkey : $minvalue);
+ }
+
+ static function XML2array($XMLstring) {
+ if (function_exists('simplexml_load_string')) {
+ if (function_exists('get_object_vars')) {
+ $XMLobject = simplexml_load_string($XMLstring);
+ return self::SimpleXMLelement2array($XMLobject);
+ }
+ }
+ return false;
+ }
+
+ static function SimpleXMLelement2array($XMLobject) {
+ if (!is_object($XMLobject) && !is_array($XMLobject)) {
+ return $XMLobject;
+ }
+ $XMLarray = (is_object($XMLobject) ? get_object_vars($XMLobject) : $XMLobject);
+ foreach ($XMLarray as $key => $value) {
+ $XMLarray[$key] = self::SimpleXMLelement2array($value);
+ }
+ return $XMLarray;
+ }
+
+
+ // Allan Hansen
+ // getid3_lib::md5_data() - returns md5sum for a file from startuing position to absolute end position
+ static function hash_data($file, $offset, $end, $algorithm) {
+ static $tempdir = '';
+ if (!getid3_lib::intValueSupported($end)) {
+ return false;
+ }
+ switch ($algorithm) {
+ case 'md5':
+ $hash_function = 'md5_file';
+ $unix_call = 'md5sum';
+ $windows_call = 'md5sum.exe';
+ $hash_length = 32;
+ break;
+
+ case 'sha1':
+ $hash_function = 'sha1_file';
+ $unix_call = 'sha1sum';
+ $windows_call = 'sha1sum.exe';
+ $hash_length = 40;
+ break;
+
+ default:
+ throw new Exception('Invalid algorithm ('.$algorithm.') in getid3_lib::hash_data()');
+ break;
+ }
+ $size = $end - $offset;
+ while (true) {
+ if (GETID3_OS_ISWINDOWS) {
+
+ // It seems that sha1sum.exe for Windows only works on physical files, does not accept piped data
+ // Fall back to create-temp-file method:
+ if ($algorithm == 'sha1') {
+ break;
+ }
+
+ $RequiredFiles = array('cygwin1.dll', 'head.exe', 'tail.exe', $windows_call);
+ foreach ($RequiredFiles as $required_file) {
+ if (!is_readable(GETID3_HELPERAPPSDIR.$required_file)) {
+ // helper apps not available - fall back to old method
+ break;
+ }
+ }
+ $commandline = GETID3_HELPERAPPSDIR.'head.exe -c '.$end.' "'.escapeshellarg(str_replace('/', DIRECTORY_SEPARATOR, $file)).'" | ';
+ $commandline .= GETID3_HELPERAPPSDIR.'tail.exe -c '.$size.' | ';
+ $commandline .= GETID3_HELPERAPPSDIR.$windows_call;
+
+ } else {
+
+ $commandline = 'head -c'.$end.' '.escapeshellarg($file).' | ';
+ $commandline .= 'tail -c'.$size.' | ';
+ $commandline .= $unix_call;
+
+ }
+ if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) {
+ //throw new Exception('PHP running in Safe Mode - backtick operator not available, using slower non-system-call '.$algorithm.' algorithm');
+ break;
+ }
+ return substr(`$commandline`, 0, $hash_length);
+ }
+
+ if (empty($tempdir)) {
+ // yes this is ugly, feel free to suggest a better way
+ require_once(dirname(__FILE__).'/getid3.php');
+ $getid3_temp = new getID3();
+ $tempdir = $getid3_temp->tempdir;
+ unset($getid3_temp);
+ }
+ // try to create a temporary file in the system temp directory - invalid dirname should force to system temp dir
+ if (($data_filename = tempnam($tempdir, 'gI3')) === false) {
+ // can't find anywhere to create a temp file, just fail
+ return false;
+ }
+
+ // Init
+ $result = false;
+
+ // copy parts of file
+ try {
+ getid3_lib::CopyFileParts($file, $data_filename, $offset, $end - $offset);
+ $result = $hash_function($data_filename);
+ } catch (Exception $e) {
+ throw new Exception('getid3_lib::CopyFileParts() failed in getid_lib::hash_data(): '.$e->getMessage());
+ }
+ unlink($data_filename);
+ return $result;
+ }
+
+ static function CopyFileParts($filename_source, $filename_dest, $offset, $length) {
+ if (!getid3_lib::intValueSupported($offset + $length)) {
+ throw new Exception('cannot copy file portion, it extends beyond the '.round(PHP_INT_MAX / 1073741824).'GB limit');
+ }
+ if (is_readable($filename_source) && is_file($filename_source) && ($fp_src = fopen($filename_source, 'rb'))) {
+ if (($fp_dest = fopen($filename_dest, 'wb'))) {
+ if (fseek($fp_src, $offset, SEEK_SET) == 0) {
+ $byteslefttowrite = $length;
+ while (($byteslefttowrite > 0) && ($buffer = fread($fp_src, min($byteslefttowrite, getID3::FREAD_BUFFER_SIZE)))) {
+ $byteswritten = fwrite($fp_dest, $buffer, $byteslefttowrite);
+ $byteslefttowrite -= $byteswritten;
+ }
+ return true;
+ } else {
+ throw new Exception('failed to seek to offset '.$offset.' in '.$filename_source);
+ }
+ fclose($fp_dest);
+ } else {
+ throw new Exception('failed to create file for writing '.$filename_dest);
+ }
+ fclose($fp_src);
+ } else {
+ throw new Exception('failed to open file for reading '.$filename_source);
+ }
+ return false;
+ }
+
+ static function iconv_fallback_int_utf8($charval) {
+ if ($charval < 128) {
+ // 0bbbbbbb
+ $newcharstring = chr($charval);
+ } elseif ($charval < 2048) {
+ // 110bbbbb 10bbbbbb
+ $newcharstring = chr(($charval >> 6) | 0xC0);
+ $newcharstring .= chr(($charval & 0x3F) | 0x80);
+ } elseif ($charval < 65536) {
+ // 1110bbbb 10bbbbbb 10bbbbbb
+ $newcharstring = chr(($charval >> 12) | 0xE0);
+ $newcharstring .= chr(($charval >> 6) | 0xC0);
+ $newcharstring .= chr(($charval & 0x3F) | 0x80);
+ } else {
+ // 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb
+ $newcharstring = chr(($charval >> 18) | 0xF0);
+ $newcharstring .= chr(($charval >> 12) | 0xC0);
+ $newcharstring .= chr(($charval >> 6) | 0xC0);
+ $newcharstring .= chr(($charval & 0x3F) | 0x80);
+ }
+ return $newcharstring;
+ }
+
+ // ISO-8859-1 => UTF-8
+ static function iconv_fallback_iso88591_utf8($string, $bom=false) {
+ if (function_exists('utf8_encode')) {
+ return utf8_encode($string);
+ }
+ // utf8_encode() unavailable, use getID3()'s iconv_fallback() conversions (possibly PHP is compiled without XML support)
+ $newcharstring = '';
+ if ($bom) {
+ $newcharstring .= "\xEF\xBB\xBF";
+ }
+ for ($i = 0; $i < strlen($string); $i++) {
+ $charval = ord($string{$i});
+ $newcharstring .= getid3_lib::iconv_fallback_int_utf8($charval);
+ }
+ return $newcharstring;
+ }
+
+ // ISO-8859-1 => UTF-16BE
+ static function iconv_fallback_iso88591_utf16be($string, $bom=false) {
+ $newcharstring = '';
+ if ($bom) {
+ $newcharstring .= "\xFE\xFF";
+ }
+ for ($i = 0; $i < strlen($string); $i++) {
+ $newcharstring .= "\x00".$string{$i};
+ }
+ return $newcharstring;
+ }
+
+ // ISO-8859-1 => UTF-16LE
+ static function iconv_fallback_iso88591_utf16le($string, $bom=false) {
+ $newcharstring = '';
+ if ($bom) {
+ $newcharstring .= "\xFF\xFE";
+ }
+ for ($i = 0; $i < strlen($string); $i++) {
+ $newcharstring .= $string{$i}."\x00";
+ }
+ return $newcharstring;
+ }
+
+ // ISO-8859-1 => UTF-16LE (BOM)
+ static function iconv_fallback_iso88591_utf16($string) {
+ return getid3_lib::iconv_fallback_iso88591_utf16le($string, true);
+ }
+
+ // UTF-8 => ISO-8859-1
+ static function iconv_fallback_utf8_iso88591($string) {
+ if (function_exists('utf8_decode')) {
+ return utf8_decode($string);
+ }
+ // utf8_decode() unavailable, use getID3()'s iconv_fallback() conversions (possibly PHP is compiled without XML support)
+ $newcharstring = '';
+ $offset = 0;
+ $stringlength = strlen($string);
+ while ($offset < $stringlength) {
+ if ((ord($string{$offset}) | 0x07) == 0xF7) {
+ // 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb
+ $charval = ((ord($string{($offset + 0)}) & 0x07) << 18) &
+ ((ord($string{($offset + 1)}) & 0x3F) << 12) &
+ ((ord($string{($offset + 2)}) & 0x3F) << 6) &
+ (ord($string{($offset + 3)}) & 0x3F);
+ $offset += 4;
+ } elseif ((ord($string{$offset}) | 0x0F) == 0xEF) {
+ // 1110bbbb 10bbbbbb 10bbbbbb
+ $charval = ((ord($string{($offset + 0)}) & 0x0F) << 12) &
+ ((ord($string{($offset + 1)}) & 0x3F) << 6) &
+ (ord($string{($offset + 2)}) & 0x3F);
+ $offset += 3;
+ } elseif ((ord($string{$offset}) | 0x1F) == 0xDF) {
+ // 110bbbbb 10bbbbbb
+ $charval = ((ord($string{($offset + 0)}) & 0x1F) << 6) &
+ (ord($string{($offset + 1)}) & 0x3F);
+ $offset += 2;
+ } elseif ((ord($string{$offset}) | 0x7F) == 0x7F) {
+ // 0bbbbbbb
+ $charval = ord($string{$offset});
+ $offset += 1;
+ } else {
+ // error? throw some kind of warning here?
+ $charval = false;
+ $offset += 1;
+ }
+ if ($charval !== false) {
+ $newcharstring .= (($charval < 256) ? chr($charval) : '?');
+ }
+ }
+ return $newcharstring;
+ }
+
+ // UTF-8 => UTF-16BE
+ static function iconv_fallback_utf8_utf16be($string, $bom=false) {
+ $newcharstring = '';
+ if ($bom) {
+ $newcharstring .= "\xFE\xFF";
+ }
+ $offset = 0;
+ $stringlength = strlen($string);
+ while ($offset < $stringlength) {
+ if ((ord($string{$offset}) | 0x07) == 0xF7) {
+ // 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb
+ $charval = ((ord($string{($offset + 0)}) & 0x07) << 18) &
+ ((ord($string{($offset + 1)}) & 0x3F) << 12) &
+ ((ord($string{($offset + 2)}) & 0x3F) << 6) &
+ (ord($string{($offset + 3)}) & 0x3F);
+ $offset += 4;
+ } elseif ((ord($string{$offset}) | 0x0F) == 0xEF) {
+ // 1110bbbb 10bbbbbb 10bbbbbb
+ $charval = ((ord($string{($offset + 0)}) & 0x0F) << 12) &
+ ((ord($string{($offset + 1)}) & 0x3F) << 6) &
+ (ord($string{($offset + 2)}) & 0x3F);
+ $offset += 3;
+ } elseif ((ord($string{$offset}) | 0x1F) == 0xDF) {
+ // 110bbbbb 10bbbbbb
+ $charval = ((ord($string{($offset + 0)}) & 0x1F) << 6) &
+ (ord($string{($offset + 1)}) & 0x3F);
+ $offset += 2;
+ } elseif ((ord($string{$offset}) | 0x7F) == 0x7F) {
+ // 0bbbbbbb
+ $charval = ord($string{$offset});
+ $offset += 1;
+ } else {
+ // error? throw some kind of warning here?
+ $charval = false;
+ $offset += 1;
+ }
+ if ($charval !== false) {
+ $newcharstring .= (($charval < 65536) ? getid3_lib::BigEndian2String($charval, 2) : "\x00".'?');
+ }
+ }
+ return $newcharstring;
+ }
+
+ // UTF-8 => UTF-16LE
+ static function iconv_fallback_utf8_utf16le($string, $bom=false) {
+ $newcharstring = '';
+ if ($bom) {
+ $newcharstring .= "\xFF\xFE";
+ }
+ $offset = 0;
+ $stringlength = strlen($string);
+ while ($offset < $stringlength) {
+ if ((ord($string{$offset}) | 0x07) == 0xF7) {
+ // 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb
+ $charval = ((ord($string{($offset + 0)}) & 0x07) << 18) &
+ ((ord($string{($offset + 1)}) & 0x3F) << 12) &
+ ((ord($string{($offset + 2)}) & 0x3F) << 6) &
+ (ord($string{($offset + 3)}) & 0x3F);
+ $offset += 4;
+ } elseif ((ord($string{$offset}) | 0x0F) == 0xEF) {
+ // 1110bbbb 10bbbbbb 10bbbbbb
+ $charval = ((ord($string{($offset + 0)}) & 0x0F) << 12) &
+ ((ord($string{($offset + 1)}) & 0x3F) << 6) &
+ (ord($string{($offset + 2)}) & 0x3F);
+ $offset += 3;
+ } elseif ((ord($string{$offset}) | 0x1F) == 0xDF) {
+ // 110bbbbb 10bbbbbb
+ $charval = ((ord($string{($offset + 0)}) & 0x1F) << 6) &
+ (ord($string{($offset + 1)}) & 0x3F);
+ $offset += 2;
+ } elseif ((ord($string{$offset}) | 0x7F) == 0x7F) {
+ // 0bbbbbbb
+ $charval = ord($string{$offset});
+ $offset += 1;
+ } else {
+ // error? maybe throw some warning here?
+ $charval = false;
+ $offset += 1;
+ }
+ if ($charval !== false) {
+ $newcharstring .= (($charval < 65536) ? getid3_lib::LittleEndian2String($charval, 2) : '?'."\x00");
+ }
+ }
+ return $newcharstring;
+ }
+
+ // UTF-8 => UTF-16LE (BOM)
+ static function iconv_fallback_utf8_utf16($string) {
+ return getid3_lib::iconv_fallback_utf8_utf16le($string, true);
+ }
+
+ // UTF-16BE => UTF-8
+ static function iconv_fallback_utf16be_utf8($string) {
+ if (substr($string, 0, 2) == "\xFE\xFF") {
+ // strip BOM
+ $string = substr($string, 2);
+ }
+ $newcharstring = '';
+ for ($i = 0; $i < strlen($string); $i += 2) {
+ $charval = getid3_lib::BigEndian2Int(substr($string, $i, 2));
+ $newcharstring .= getid3_lib::iconv_fallback_int_utf8($charval);
+ }
+ return $newcharstring;
+ }
+
+ // UTF-16LE => UTF-8
+ static function iconv_fallback_utf16le_utf8($string) {
+ if (substr($string, 0, 2) == "\xFF\xFE") {
+ // strip BOM
+ $string = substr($string, 2);
+ }
+ $newcharstring = '';
+ for ($i = 0; $i < strlen($string); $i += 2) {
+ $charval = getid3_lib::LittleEndian2Int(substr($string, $i, 2));
+ $newcharstring .= getid3_lib::iconv_fallback_int_utf8($charval);
+ }
+ return $newcharstring;
+ }
+
+ // UTF-16BE => ISO-8859-1
+ static function iconv_fallback_utf16be_iso88591($string) {
+ if (substr($string, 0, 2) == "\xFE\xFF") {
+ // strip BOM
+ $string = substr($string, 2);
+ }
+ $newcharstring = '';
+ for ($i = 0; $i < strlen($string); $i += 2) {
+ $charval = getid3_lib::BigEndian2Int(substr($string, $i, 2));
+ $newcharstring .= (($charval < 256) ? chr($charval) : '?');
+ }
+ return $newcharstring;
+ }
+
+ // UTF-16LE => ISO-8859-1
+ static function iconv_fallback_utf16le_iso88591($string) {
+ if (substr($string, 0, 2) == "\xFF\xFE") {
+ // strip BOM
+ $string = substr($string, 2);
+ }
+ $newcharstring = '';
+ for ($i = 0; $i < strlen($string); $i += 2) {
+ $charval = getid3_lib::LittleEndian2Int(substr($string, $i, 2));
+ $newcharstring .= (($charval < 256) ? chr($charval) : '?');
+ }
+ return $newcharstring;
+ }
+
+ // UTF-16 (BOM) => ISO-8859-1
+ static function iconv_fallback_utf16_iso88591($string) {
+ $bom = substr($string, 0, 2);
+ if ($bom == "\xFE\xFF") {
+ return getid3_lib::iconv_fallback_utf16be_iso88591(substr($string, 2));
+ } elseif ($bom == "\xFF\xFE") {
+ return getid3_lib::iconv_fallback_utf16le_iso88591(substr($string, 2));
+ }
+ return $string;
+ }
+
+ // UTF-16 (BOM) => UTF-8
+ static function iconv_fallback_utf16_utf8($string) {
+ $bom = substr($string, 0, 2);
+ if ($bom == "\xFE\xFF") {
+ return getid3_lib::iconv_fallback_utf16be_utf8(substr($string, 2));
+ } elseif ($bom == "\xFF\xFE") {
+ return getid3_lib::iconv_fallback_utf16le_utf8(substr($string, 2));
+ }
+ return $string;
+ }
+
+ static function iconv_fallback($in_charset, $out_charset, $string) {
+
+ if ($in_charset == $out_charset) {
+ return $string;
+ }
+
+ // iconv() availble
+ if (function_exists('iconv')) {
+ if ($converted_string = @iconv($in_charset, $out_charset.'//TRANSLIT', $string)) {
+ switch ($out_charset) {
+ case 'ISO-8859-1':
+ $converted_string = rtrim($converted_string, "\x00");
+ break;
+ }
+ return $converted_string;
+ }
+
+ // iconv() may sometimes fail with "illegal character in input string" error message
+ // and return an empty string, but returning the unconverted string is more useful
+ return $string;
+ }
+
+
+ // iconv() not available
+ static $ConversionFunctionList = array();
+ if (empty($ConversionFunctionList)) {
+ $ConversionFunctionList['ISO-8859-1']['UTF-8'] = 'iconv_fallback_iso88591_utf8';
+ $ConversionFunctionList['ISO-8859-1']['UTF-16'] = 'iconv_fallback_iso88591_utf16';
+ $ConversionFunctionList['ISO-8859-1']['UTF-16BE'] = 'iconv_fallback_iso88591_utf16be';
+ $ConversionFunctionList['ISO-8859-1']['UTF-16LE'] = 'iconv_fallback_iso88591_utf16le';
+ $ConversionFunctionList['UTF-8']['ISO-8859-1'] = 'iconv_fallback_utf8_iso88591';
+ $ConversionFunctionList['UTF-8']['UTF-16'] = 'iconv_fallback_utf8_utf16';
+ $ConversionFunctionList['UTF-8']['UTF-16BE'] = 'iconv_fallback_utf8_utf16be';
+ $ConversionFunctionList['UTF-8']['UTF-16LE'] = 'iconv_fallback_utf8_utf16le';
+ $ConversionFunctionList['UTF-16']['ISO-8859-1'] = 'iconv_fallback_utf16_iso88591';
+ $ConversionFunctionList['UTF-16']['UTF-8'] = 'iconv_fallback_utf16_utf8';
+ $ConversionFunctionList['UTF-16LE']['ISO-8859-1'] = 'iconv_fallback_utf16le_iso88591';
+ $ConversionFunctionList['UTF-16LE']['UTF-8'] = 'iconv_fallback_utf16le_utf8';
+ $ConversionFunctionList['UTF-16BE']['ISO-8859-1'] = 'iconv_fallback_utf16be_iso88591';
+ $ConversionFunctionList['UTF-16BE']['UTF-8'] = 'iconv_fallback_utf16be_utf8';
+ }
+ if (isset($ConversionFunctionList[strtoupper($in_charset)][strtoupper($out_charset)])) {
+ $ConversionFunction = $ConversionFunctionList[strtoupper($in_charset)][strtoupper($out_charset)];
+ return getid3_lib::$ConversionFunction($string);
+ }
+ throw new Exception('PHP does not have iconv() support - cannot convert from '.$in_charset.' to '.$out_charset);
+ }
+
+
+ static function MultiByteCharString2HTML($string, $charset='ISO-8859-1') {
+ $string = (string) $string; // in case trying to pass a numeric (float, int) string, would otherwise return an empty string
+ $HTMLstring = '';
+
+ switch ($charset) {
+ case '1251':
+ case '1252':
+ case '866':
+ case '932':
+ case '936':
+ case '950':
+ case 'BIG5':
+ case 'BIG5-HKSCS':
+ case 'cp1251':
+ case 'cp1252':
+ case 'cp866':
+ case 'EUC-JP':
+ case 'EUCJP':
+ case 'GB2312':
+ case 'ibm866':
+ case 'ISO-8859-1':
+ case 'ISO-8859-15':
+ case 'ISO8859-1':
+ case 'ISO8859-15':
+ case 'KOI8-R':
+ case 'koi8-ru':
+ case 'koi8r':
+ case 'Shift_JIS':
+ case 'SJIS':
+ case 'win-1251':
+ case 'Windows-1251':
+ case 'Windows-1252':
+ $HTMLstring = htmlentities($string, ENT_COMPAT, $charset);
+ break;
+
+ case 'UTF-8':
+ $strlen = strlen($string);
+ for ($i = 0; $i < $strlen; $i++) {
+ $char_ord_val = ord($string{$i});
+ $charval = 0;
+ if ($char_ord_val < 0x80) {
+ $charval = $char_ord_val;
+ } elseif ((($char_ord_val & 0xF0) >> 4) == 0x0F && $i+3 < $strlen) {
+ $charval = (($char_ord_val & 0x07) << 18);
+ $charval += ((ord($string{++$i}) & 0x3F) << 12);
+ $charval += ((ord($string{++$i}) & 0x3F) << 6);
+ $charval += (ord($string{++$i}) & 0x3F);
+ } elseif ((($char_ord_val & 0xE0) >> 5) == 0x07 && $i+2 < $strlen) {
+ $charval = (($char_ord_val & 0x0F) << 12);
+ $charval += ((ord($string{++$i}) & 0x3F) << 6);
+ $charval += (ord($string{++$i}) & 0x3F);
+ } elseif ((($char_ord_val & 0xC0) >> 6) == 0x03 && $i+1 < $strlen) {
+ $charval = (($char_ord_val & 0x1F) << 6);
+ $charval += (ord($string{++$i}) & 0x3F);
+ }
+ if (($charval >= 32) && ($charval <= 127)) {
+ $HTMLstring .= htmlentities(chr($charval));
+ } else {
+ $HTMLstring .= ''.$charval.';';
+ }
+ }
+ break;
+
+ case 'UTF-16LE':
+ for ($i = 0; $i < strlen($string); $i += 2) {
+ $charval = getid3_lib::LittleEndian2Int(substr($string, $i, 2));
+ if (($charval >= 32) && ($charval <= 127)) {
+ $HTMLstring .= chr($charval);
+ } else {
+ $HTMLstring .= ''.$charval.';';
+ }
+ }
+ break;
+
+ case 'UTF-16BE':
+ for ($i = 0; $i < strlen($string); $i += 2) {
+ $charval = getid3_lib::BigEndian2Int(substr($string, $i, 2));
+ if (($charval >= 32) && ($charval <= 127)) {
+ $HTMLstring .= chr($charval);
+ } else {
+ $HTMLstring .= ''.$charval.';';
+ }
+ }
+ break;
+
+ default:
+ $HTMLstring = 'ERROR: Character set "'.$charset.'" not supported in MultiByteCharString2HTML()';
+ break;
+ }
+ return $HTMLstring;
+ }
+
+
+
+ static function RGADnameLookup($namecode) {
+ static $RGADname = array();
+ if (empty($RGADname)) {
+ $RGADname[0] = 'not set';
+ $RGADname[1] = 'Track Gain Adjustment';
+ $RGADname[2] = 'Album Gain Adjustment';
+ }
+
+ return (isset($RGADname[$namecode]) ? $RGADname[$namecode] : '');
+ }
+
+
+ static function RGADoriginatorLookup($originatorcode) {
+ static $RGADoriginator = array();
+ if (empty($RGADoriginator)) {
+ $RGADoriginator[0] = 'unspecified';
+ $RGADoriginator[1] = 'pre-set by artist/producer/mastering engineer';
+ $RGADoriginator[2] = 'set by user';
+ $RGADoriginator[3] = 'determined automatically';
+ }
+
+ return (isset($RGADoriginator[$originatorcode]) ? $RGADoriginator[$originatorcode] : '');
+ }
+
+
+ static function RGADadjustmentLookup($rawadjustment, $signbit) {
+ $adjustment = $rawadjustment / 10;
+ if ($signbit == 1) {
+ $adjustment *= -1;
+ }
+ return (float) $adjustment;
+ }
+
+
+ static function RGADgainString($namecode, $originatorcode, $replaygain) {
+ if ($replaygain < 0) {
+ $signbit = '1';
+ } else {
+ $signbit = '0';
+ }
+ $storedreplaygain = intval(round($replaygain * 10));
+ $gainstring = str_pad(decbin($namecode), 3, '0', STR_PAD_LEFT);
+ $gainstring .= str_pad(decbin($originatorcode), 3, '0', STR_PAD_LEFT);
+ $gainstring .= $signbit;
+ $gainstring .= str_pad(decbin($storedreplaygain), 9, '0', STR_PAD_LEFT);
+
+ return $gainstring;
+ }
+
+ static function RGADamplitude2dB($amplitude) {
+ return 20 * log10($amplitude);
+ }
+
+
+ static function GetDataImageSize($imgData, &$imageinfo) {
+ static $tempdir = '';
+ if (empty($tempdir)) {
+ // yes this is ugly, feel free to suggest a better way
+ require_once(dirname(__FILE__).'/getid3.php');
+ $getid3_temp = new getID3();
+ $tempdir = $getid3_temp->tempdir;
+ unset($getid3_temp);
+ }
+ $GetDataImageSize = false;
+ if ($tempfilename = tempnam($tempdir, 'gI3')) {
+ if (is_writable($tempfilename) && is_file($tempfilename) && ($tmp = fopen($tempfilename, 'wb'))) {
+ fwrite($tmp, $imgData);
+ fclose($tmp);
+ $GetDataImageSize = @GetImageSize($tempfilename, $imageinfo);
+ }
+ unlink($tempfilename);
+ }
+ return $GetDataImageSize;
+ }
+
+ static function ImageTypesLookup($imagetypeid) {
+ static $ImageTypesLookup = array();
+ if (empty($ImageTypesLookup)) {
+ $ImageTypesLookup[1] = 'gif';
+ $ImageTypesLookup[2] = 'jpeg';
+ $ImageTypesLookup[3] = 'png';
+ $ImageTypesLookup[4] = 'swf';
+ $ImageTypesLookup[5] = 'psd';
+ $ImageTypesLookup[6] = 'bmp';
+ $ImageTypesLookup[7] = 'tiff (little-endian)';
+ $ImageTypesLookup[8] = 'tiff (big-endian)';
+ $ImageTypesLookup[9] = 'jpc';
+ $ImageTypesLookup[10] = 'jp2';
+ $ImageTypesLookup[11] = 'jpx';
+ $ImageTypesLookup[12] = 'jb2';
+ $ImageTypesLookup[13] = 'swc';
+ $ImageTypesLookup[14] = 'iff';
+ }
+ return (isset($ImageTypesLookup[$imagetypeid]) ? $ImageTypesLookup[$imagetypeid] : '');
+ }
+
+ static function CopyTagsToComments(&$ThisFileInfo) {
+
+ // Copy all entries from ['tags'] into common ['comments']
+ if (!empty($ThisFileInfo['tags'])) {
+ foreach ($ThisFileInfo['tags'] as $tagtype => $tagarray) {
+ foreach ($tagarray as $tagname => $tagdata) {
+ foreach ($tagdata as $key => $value) {
+ if (!empty($value)) {
+ if (empty($ThisFileInfo['comments'][$tagname])) {
+
+ // fall through and append value
+
+ } elseif ($tagtype == 'id3v1') {
+
+ $newvaluelength = strlen(trim($value));
+ foreach ($ThisFileInfo['comments'][$tagname] as $existingkey => $existingvalue) {
+ $oldvaluelength = strlen(trim($existingvalue));
+ if (($newvaluelength <= $oldvaluelength) && (substr($existingvalue, 0, $newvaluelength) == trim($value))) {
+ // new value is identical but shorter-than (or equal-length to) one already in comments - skip
+ break 2;
+ }
+ }
+
+ } elseif (!is_array($value)) {
+
+ $newvaluelength = strlen(trim($value));
+ foreach ($ThisFileInfo['comments'][$tagname] as $existingkey => $existingvalue) {
+ $oldvaluelength = strlen(trim($existingvalue));
+ if (($newvaluelength > $oldvaluelength) && (substr(trim($value), 0, strlen($existingvalue)) == $existingvalue)) {
+ $ThisFileInfo['comments'][$tagname][$existingkey] = trim($value);
+ break 2;
+ }
+ }
+
+ }
+ if (is_array($value) || empty($ThisFileInfo['comments'][$tagname]) || !in_array(trim($value), $ThisFileInfo['comments'][$tagname])) {
+ $value = (is_string($value) ? trim($value) : $value);
+ $ThisFileInfo['comments'][$tagname][] = $value;
+ }
+ }
+ }
+ }
+ }
+
+ // Copy to ['comments_html']
+ foreach ($ThisFileInfo['comments'] as $field => $values) {
+ if ($field == 'picture') {
+ // pictures can take up a lot of space, and we don't need multiple copies of them
+ // let there be a single copy in [comments][picture], and not elsewhere
+ continue;
+ }
+ foreach ($values as $index => $value) {
+ if (is_array($value)) {
+ $ThisFileInfo['comments_html'][$field][$index] = $value;
+ } else {
+ $ThisFileInfo['comments_html'][$field][$index] = str_replace('', '', getid3_lib::MultiByteCharString2HTML($value, $ThisFileInfo['encoding']));
+ }
+ }
+ }
+ }
+ return true;
+ }
+
+
+ static function EmbeddedLookup($key, $begin, $end, $file, $name) {
+
+ // Cached
+ static $cache;
+ if (isset($cache[$file][$name])) {
+ return (isset($cache[$file][$name][$key]) ? $cache[$file][$name][$key] : '');
+ }
+
+ // Init
+ $keylength = strlen($key);
+ $line_count = $end - $begin - 7;
+
+ // Open php file
+ $fp = fopen($file, 'r');
+
+ // Discard $begin lines
+ for ($i = 0; $i < ($begin + 3); $i++) {
+ fgets($fp, 1024);
+ }
+
+ // Loop thru line
+ while (0 < $line_count--) {
+
+ // Read line
+ $line = ltrim(fgets($fp, 1024), "\t ");
+
+ // METHOD A: only cache the matching key - less memory but slower on next lookup of not-previously-looked-up key
+ //$keycheck = substr($line, 0, $keylength);
+ //if ($key == $keycheck) {
+ // $cache[$file][$name][$keycheck] = substr($line, $keylength + 1);
+ // break;
+ //}
+
+ // METHOD B: cache all keys in this lookup - more memory but faster on next lookup of not-previously-looked-up key
+ //$cache[$file][$name][substr($line, 0, $keylength)] = trim(substr($line, $keylength + 1));
+ $explodedLine = explode("\t", $line, 2);
+ $ThisKey = (isset($explodedLine[0]) ? $explodedLine[0] : '');
+ $ThisValue = (isset($explodedLine[1]) ? $explodedLine[1] : '');
+ $cache[$file][$name][$ThisKey] = trim($ThisValue);
+ }
+
+ // Close and return
+ fclose($fp);
+ return (isset($cache[$file][$name][$key]) ? $cache[$file][$name][$key] : '');
+ }
+
+ static function IncludeDependency($filename, $sourcefile, $DieOnFailure=false) {
+ global $GETID3_ERRORARRAY;
+
+ if (file_exists($filename)) {
+ if (include_once($filename)) {
+ return true;
+ } else {
+ $diemessage = basename($sourcefile).' depends on '.$filename.', which has errors';
+ }
+ } else {
+ $diemessage = basename($sourcefile).' depends on '.$filename.', which is missing';
+ }
+ if ($DieOnFailure) {
+ throw new Exception($diemessage);
+ } else {
+ $GETID3_ERRORARRAY[] = $diemessage;
+ }
+ return false;
+ }
+
+ public static function trimNullByte($string) {
+ return trim($string, "\x00");
+ }
+
+}
+
+?>
\ No newline at end of file
diff --git a/lib/getid3/getid3/getid3.php b/lib/getid3/getid3/getid3.php
new file mode 100644
index 00000000..e8a3f7e2
--- /dev/null
+++ b/lib/getid3/getid3/getid3.php
@@ -0,0 +1,1744 @@
+ //
+// available at http://getid3.sourceforge.net //
+// or http://www.getid3.org //
+/////////////////////////////////////////////////////////////////
+// //
+// Please see readme.txt for more information //
+// ///
+/////////////////////////////////////////////////////////////////
+
+// attempt to define temp dir as something flexible but reliable
+$temp_dir = ini_get('upload_tmp_dir');
+if ($temp_dir && (!is_dir($temp_dir) || !is_readable($temp_dir))) {
+ $temp_dir = '';
+}
+if (!$temp_dir && function_exists('sys_get_temp_dir')) {
+ // PHP v5.2.1+
+ // sys_get_temp_dir() may give inaccessible temp dir, e.g. with open_basedir on virtual hosts
+ $temp_dir = sys_get_temp_dir();
+}
+$temp_dir = realpath($temp_dir);
+$open_basedir = ini_get('open_basedir');
+if ($open_basedir) {
+ // e.g. "/var/www/vhosts/getid3.org/httpdocs/:/tmp/"
+ $temp_dir = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $temp_dir);
+ $open_basedir = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $open_basedir);
+ if (substr($temp_dir, -1, 1) != DIRECTORY_SEPARATOR) {
+ $temp_dir .= DIRECTORY_SEPARATOR;
+ }
+ $found_valid_tempdir = false;
+ $open_basedirs = explode(':', $open_basedir);
+ foreach ($open_basedirs as $basedir) {
+ if (substr($basedir, -1, 1) != DIRECTORY_SEPARATOR) {
+ $basedir .= DIRECTORY_SEPARATOR;
+ }
+ if (preg_match('#^'.preg_quote($basedir).'#', $temp_dir)) {
+ $found_valid_tempdir = true;
+ break;
+ }
+ }
+ if (!$found_valid_tempdir) {
+ $temp_dir = '';
+ }
+ unset($open_basedirs, $found_valid_tempdir, $basedir);
+}
+if (!$temp_dir) {
+ $temp_dir = '*'; // invalid directory name should force tempnam() to use system default temp dir
+}
+// $temp_dir = '/something/else/'; // feel free to override temp dir here if it works better for your system
+define('GETID3_TEMP_DIR', $temp_dir);
+unset($open_basedir, $temp_dir);
+
+
+// define a constant rather than looking up every time it is needed
+if (!defined('GETID3_OS_ISWINDOWS')) {
+ if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
+ define('GETID3_OS_ISWINDOWS', true);
+ } else {
+ define('GETID3_OS_ISWINDOWS', false);
+ }
+}
+
+// Get base path of getID3() - ONCE
+if (!defined('GETID3_INCLUDEPATH')) {
+ foreach (get_included_files() as $key => $val) {
+ if (basename($val) == 'getid3.php') {
+ define('GETID3_INCLUDEPATH', dirname($val).DIRECTORY_SEPARATOR);
+ break;
+ }
+ }
+}
+
+// End: Defines
+
+
+class getID3
+{
+ // public: Settings
+ public $encoding = 'UTF-8'; // CASE SENSITIVE! - i.e. (must be supported by iconv()). Examples: ISO-8859-1 UTF-8 UTF-16 UTF-16BE
+ public $encoding_id3v1 = 'ISO-8859-1'; // Should always be 'ISO-8859-1', but some tags may be written in other encodings such as 'EUC-CN' or 'CP1252'
+
+ // public: Optional tag checks - disable for speed.
+ public $option_tag_id3v1 = true; // Read and process ID3v1 tags
+ public $option_tag_id3v2 = true; // Read and process ID3v2 tags
+ public $option_tag_lyrics3 = true; // Read and process Lyrics3 tags
+ public $option_tag_apetag = true; // Read and process APE tags
+ public $option_tags_process = true; // Copy tags to root key 'tags' and encode to $this->encoding
+ public $option_tags_html = true; // Copy tags to root key 'tags_html' properly translated from various encodings to HTML entities
+
+ // public: Optional tag/comment calucations
+ public $option_extra_info = true; // Calculate additional info such as bitrate, channelmode etc
+
+ // public: Optional handling of embedded attachments (e.g. images)
+ public $option_save_attachments = true; // defaults to true (ATTACHMENTS_INLINE) for backward compatibility
+
+ // public: Optional calculations
+ public $option_md5_data = false; // Get MD5 sum of data part - slow
+ public $option_md5_data_source = false; // Use MD5 of source file if availble - only FLAC and OptimFROG
+ public $option_sha1_data = false; // Get SHA1 sum of data part - slow
+ public $option_max_2gb_check = null; // Check whether file is larger than 2GB and thus not supported by 32-bit PHP (null: auto-detect based on PHP_INT_MAX)
+
+ // public: Read buffer size in bytes
+ public $option_fread_buffer_size = 32768;
+
+ // Public variables
+ public $filename; // Filename of file being analysed.
+ public $fp; // Filepointer to file being analysed.
+ public $info; // Result array.
+
+ // Protected variables
+ protected $startup_error = '';
+ protected $startup_warning = '';
+ protected $memory_limit = 0;
+
+ const VERSION = '1.9.3-20111213';
+ const FREAD_BUFFER_SIZE = 32768;
+ var $tempdir = GETID3_TEMP_DIR;
+
+ const ATTACHMENTS_NONE = false;
+ const ATTACHMENTS_INLINE = true;
+
+ // public: constructor
+ public function __construct() {
+
+ // Check for PHP version
+ $required_php_version = '5.0.5';
+ if (version_compare(PHP_VERSION, $required_php_version, '<')) {
+ $this->startup_error .= 'getID3() requires PHP v'.$required_php_version.' or higher - you are running v'.PHP_VERSION;
+ return false;
+ }
+
+ // Check memory
+ $this->memory_limit = ini_get('memory_limit');
+ if (preg_match('#([0-9]+)M#i', $this->memory_limit, $matches)) {
+ // could be stored as "16M" rather than 16777216 for example
+ $this->memory_limit = $matches[1] * 1048576;
+ } elseif (preg_match('#([0-9]+)G#i', $this->memory_limit, $matches)) { // The 'G' modifier is available since PHP 5.1.0
+ // could be stored as "2G" rather than 2147483648 for example
+ $this->memory_limit = $matches[1] * 1073741824;
+ }
+ if ($this->memory_limit <= 0) {
+ // memory limits probably disabled
+ } elseif ($this->memory_limit <= 4194304) {
+ $this->startup_error .= 'PHP has less than 4MB available memory and will very likely run out. Increase memory_limit in php.ini';
+ } elseif ($this->memory_limit <= 12582912) {
+ $this->startup_warning .= 'PHP has less than 12MB available memory and might run out if all modules are loaded. Increase memory_limit in php.ini';
+ }
+
+ // Check safe_mode off
+ if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) {
+ $this->warning('WARNING: Safe mode is on, shorten support disabled, md5data/sha1data for ogg vorbis disabled, ogg vorbos/flac tag writing disabled.');
+ }
+
+ if (intval(ini_get('mbstring.func_overload')) > 0) {
+ $this->warning('WARNING: php.ini contains "mbstring.func_overload = '.ini_get('mbstring.func_overload').'", this may break things.');
+ }
+
+ // Check for magic_quotes_runtime
+ if (function_exists('get_magic_quotes_runtime')) {
+ if (get_magic_quotes_runtime()) {
+ return $this->startup_error('magic_quotes_runtime must be disabled before running getID3(). Surround getid3 block by set_magic_quotes_runtime(0) and set_magic_quotes_runtime(1).');
+ }
+ }
+
+ // Check for magic_quotes_gpc
+ if (function_exists('magic_quotes_gpc')) {
+ if (get_magic_quotes_gpc()) {
+ return $this->startup_error('magic_quotes_gpc must be disabled before running getID3(). Surround getid3 block by set_magic_quotes_gpc(0) and set_magic_quotes_gpc(1).');
+ }
+ }
+
+ // Load support library
+ if (!include_once(GETID3_INCLUDEPATH.'getid3.lib.php')) {
+ $this->startup_error .= 'getid3.lib.php is missing or corrupt';
+ }
+
+ if ($this->option_max_2gb_check === null) {
+ $this->option_max_2gb_check = (PHP_INT_MAX <= 2147483647);
+ }
+
+
+ // Needed for Windows only:
+ // Define locations of helper applications for Shorten, VorbisComment, MetaFLAC
+ // as well as other helper functions such as head, tail, md5sum, etc
+ // This path cannot contain spaces, but the below code will attempt to get the
+ // 8.3-equivalent path automatically
+ // IMPORTANT: This path must include the trailing slash
+ if (GETID3_OS_ISWINDOWS && !defined('GETID3_HELPERAPPSDIR')) {
+
+ $helperappsdir = GETID3_INCLUDEPATH.'..'.DIRECTORY_SEPARATOR.'helperapps'; // must not have any space in this path
+
+ if (!is_dir($helperappsdir)) {
+ $this->startup_warning .= '"'.$helperappsdir.'" cannot be defined as GETID3_HELPERAPPSDIR because it does not exist';
+ } elseif (strpos(realpath($helperappsdir), ' ') !== false) {
+ $DirPieces = explode(DIRECTORY_SEPARATOR, realpath($helperappsdir));
+ $path_so_far = array();
+ foreach ($DirPieces as $key => $value) {
+ if (strpos($value, ' ') !== false) {
+ if (!empty($path_so_far)) {
+ $commandline = 'dir /x '.escapeshellarg(implode(DIRECTORY_SEPARATOR, $path_so_far));
+ $dir_listing = `$commandline`;
+ $lines = explode("\n", $dir_listing);
+ foreach ($lines as $line) {
+ $line = trim($line);
+ if (preg_match('#^([0-9/]{10}) +([0-9:]{4,5}( [AP]M)?) +(|[0-9,]+) +([^ ]{0,11}) +(.+)$#', $line, $matches)) {
+ list($dummy, $date, $time, $ampm, $filesize, $shortname, $filename) = $matches;
+ if ((strtoupper($filesize) == '') && (strtolower($filename) == strtolower($value))) {
+ $value = $shortname;
+ }
+ }
+ }
+ } else {
+ $this->startup_warning .= 'GETID3_HELPERAPPSDIR must not have any spaces in it - use 8dot3 naming convention if neccesary. You can run "dir /x" from the commandline to see the correct 8.3-style names.';
+ }
+ }
+ $path_so_far[] = $value;
+ }
+ $helperappsdir = implode(DIRECTORY_SEPARATOR, $path_so_far);
+ }
+ define('GETID3_HELPERAPPSDIR', $helperappsdir.DIRECTORY_SEPARATOR);
+ }
+
+ return true;
+ }
+
+ public function version() {
+ return self::VERSION;
+ }
+
+ public function fread_buffer_size() {
+ return $this->option_fread_buffer_size;
+ }
+
+
+ // public: setOption
+ function setOption($optArray) {
+ if (!is_array($optArray) || empty($optArray)) {
+ return false;
+ }
+ foreach ($optArray as $opt => $val) {
+ if (isset($this->$opt) === false) {
+ continue;
+ }
+ $this->$opt = $val;
+ }
+ return true;
+ }
+
+
+ public function openfile($filename) {
+ try {
+ if (!empty($this->startup_error)) {
+ throw new getid3_exception($this->startup_error);
+ }
+ if (!empty($this->startup_warning)) {
+ $this->warning($this->startup_warning);
+ }
+
+ // init result array and set parameters
+ $this->filename = $filename;
+ $this->info = array();
+ $this->info['GETID3_VERSION'] = $this->version();
+ $this->info['php_memory_limit'] = $this->memory_limit;
+
+ // remote files not supported
+ if (preg_match('/^(ht|f)tp:\/\//', $filename)) {
+ throw new getid3_exception('Remote files are not supported - please copy the file locally first');
+ }
+
+ $filename = str_replace('/', DIRECTORY_SEPARATOR, $filename);
+ $filename = preg_replace('#(.+)'.preg_quote(DIRECTORY_SEPARATOR).'{2,}#U', '\1'.DIRECTORY_SEPARATOR, $filename);
+
+ // open local file
+ if (is_readable($filename) && is_file($filename) && ($this->fp = fopen($filename, 'rb'))) {
+ // great
+ } else {
+ throw new getid3_exception('Could not open "'.$filename.'" (does not exist, or is not a file)');
+ }
+
+ $this->info['filesize'] = filesize($filename);
+ // set redundant parameters - might be needed in some include file
+ $this->info['filename'] = basename($filename);
+ $this->info['filepath'] = str_replace('\\', '/', realpath(dirname($filename)));
+ $this->info['filenamepath'] = $this->info['filepath'].'/'.$this->info['filename'];
+
+
+ // option_max_2gb_check
+ if ($this->option_max_2gb_check) {
+ // PHP (32-bit all, and 64-bit Windows) doesn't support integers larger than 2^31 (~2GB)
+ // filesize() simply returns (filesize % (pow(2, 32)), no matter the actual filesize
+ // ftell() returns 0 if seeking to the end is beyond the range of unsigned integer
+ $fseek = fseek($this->fp, 0, SEEK_END);
+ if (($fseek < 0) || (($this->info['filesize'] != 0) && (ftell($this->fp) == 0)) ||
+ ($this->info['filesize'] < 0) ||
+ (ftell($this->fp) < 0)) {
+ $real_filesize = false;
+ if (GETID3_OS_ISWINDOWS) {
+ $commandline = 'dir /-C "'.str_replace('/', DIRECTORY_SEPARATOR, $filename).'"';
+ $dir_output = `$commandline`;
+ if (preg_match('#1 File\(s\)[ ]+([0-9]+) bytes#i', $dir_output, $matches)) {
+ $real_filesize = (float) $matches[1];
+ }
+ } else {
+ $commandline = 'ls -o -g -G --time-style=long-iso '.escapeshellarg($filename);
+ $dir_output = `$commandline`;
+ if (preg_match('#([0-9]+) ([0-9]{4}-[0-9]{2}\-[0-9]{2} [0-9]{2}:[0-9]{2}) '.str_replace('#', '\\#', preg_quote($filename)).'$#', $dir_output, $matches)) {
+ $real_filesize = (float) $matches[1];
+ }
+ }
+ if ($real_filesize === false) {
+ unset($this->info['filesize']);
+ fclose($this->fp);
+ throw new getid3_exception('Unable to determine actual filesize. File is most likely larger than '.round(PHP_INT_MAX / 1073741824).'GB and is not supported by PHP.');
+ } elseif (getid3_lib::intValueSupported($real_filesize)) {
+ unset($this->info['filesize']);
+ fclose($this->fp);
+ throw new getid3_exception('PHP seems to think the file is larger than '.round(PHP_INT_MAX / 1073741824).'GB, but filesystem reports it as '.number_format($real_filesize, 3).'GB, please report to info@getid3.org');
+ }
+ $this->info['filesize'] = $real_filesize;
+ $this->error('File is larger than '.round(PHP_INT_MAX / 1073741824).'GB (filesystem reports it as '.number_format($real_filesize, 3).'GB) and is not properly supported by PHP.');
+ }
+ }
+
+ // set more parameters
+ $this->info['avdataoffset'] = 0;
+ $this->info['avdataend'] = $this->info['filesize'];
+ $this->info['fileformat'] = ''; // filled in later
+ $this->info['audio']['dataformat'] = ''; // filled in later, unset if not used
+ $this->info['video']['dataformat'] = ''; // filled in later, unset if not used
+ $this->info['tags'] = array(); // filled in later, unset if not used
+ $this->info['error'] = array(); // filled in later, unset if not used
+ $this->info['warning'] = array(); // filled in later, unset if not used
+ $this->info['comments'] = array(); // filled in later, unset if not used
+ $this->info['encoding'] = $this->encoding; // required by id3v2 and iso modules - can be unset at the end if desired
+
+ return true;
+
+ } catch (Exception $e) {
+ $this->error($e->getMessage());
+ }
+ return false;
+ }
+
+ // public: analyze file
+ function analyze($filename) {
+ try {
+ if (!$this->openfile($filename)) {
+ return $this->info;
+ }
+
+ // Handle tags
+ foreach (array('id3v2'=>'id3v2', 'id3v1'=>'id3v1', 'apetag'=>'ape', 'lyrics3'=>'lyrics3') as $tag_name => $tag_key) {
+ $option_tag = 'option_tag_'.$tag_name;
+ if ($this->$option_tag) {
+ $this->include_module('tag.'.$tag_name);
+ try {
+ $tag_class = 'getid3_'.$tag_name;
+ $tag = new $tag_class($this);
+ $tag->Analyze();
+ }
+ catch (getid3_exception $e) {
+ throw $e;
+ }
+ }
+ }
+ if (isset($this->info['id3v2']['tag_offset_start'])) {
+ $this->info['avdataoffset'] = max($this->info['avdataoffset'], $this->info['id3v2']['tag_offset_end']);
+ }
+ foreach (array('id3v1'=>'id3v1', 'apetag'=>'ape', 'lyrics3'=>'lyrics3') as $tag_name => $tag_key) {
+ if (isset($this->info[$tag_key]['tag_offset_start'])) {
+ $this->info['avdataend'] = min($this->info['avdataend'], $this->info[$tag_key]['tag_offset_start']);
+ }
+ }
+
+ // ID3v2 detection (NOT parsing), even if ($this->option_tag_id3v2 == false) done to make fileformat easier
+ if (!$this->option_tag_id3v2) {
+ fseek($this->fp, 0, SEEK_SET);
+ $header = fread($this->fp, 10);
+ if ((substr($header, 0, 3) == 'ID3') && (strlen($header) == 10)) {
+ $this->info['id3v2']['header'] = true;
+ $this->info['id3v2']['majorversion'] = ord($header{3});
+ $this->info['id3v2']['minorversion'] = ord($header{4});
+ $this->info['avdataoffset'] += getid3_lib::BigEndian2Int(substr($header, 6, 4), 1) + 10; // length of ID3v2 tag in 10-byte header doesn't include 10-byte header length
+ }
+ }
+
+ // read 32 kb file data
+ fseek($this->fp, $this->info['avdataoffset'], SEEK_SET);
+ $formattest = fread($this->fp, 32774);
+
+ // determine format
+ $determined_format = $this->GetFileFormat($formattest, $filename);
+
+ // unable to determine file format
+ if (!$determined_format) {
+ fclose($this->fp);
+ return $this->error('unable to determine file format');
+ }
+
+ // check for illegal ID3 tags
+ if (isset($determined_format['fail_id3']) && (in_array('id3v1', $this->info['tags']) || in_array('id3v2', $this->info['tags']))) {
+ if ($determined_format['fail_id3'] === 'ERROR') {
+ fclose($this->fp);
+ return $this->error('ID3 tags not allowed on this file type.');
+ } elseif ($determined_format['fail_id3'] === 'WARNING') {
+ $this->warning('ID3 tags not allowed on this file type.');
+ }
+ }
+
+ // check for illegal APE tags
+ if (isset($determined_format['fail_ape']) && in_array('ape', $this->info['tags'])) {
+ if ($determined_format['fail_ape'] === 'ERROR') {
+ fclose($this->fp);
+ return $this->error('APE tags not allowed on this file type.');
+ } elseif ($determined_format['fail_ape'] === 'WARNING') {
+ $this->warning('APE tags not allowed on this file type.');
+ }
+ }
+
+ // set mime type
+ $this->info['mime_type'] = $determined_format['mime_type'];
+
+ // supported format signature pattern detected, but module deleted
+ if (!file_exists(GETID3_INCLUDEPATH.$determined_format['include'])) {
+ fclose($this->fp);
+ return $this->error('Format not supported, module "'.$determined_format['include'].'" was removed.');
+ }
+
+ // module requires iconv support
+ // Check encoding/iconv support
+ if (!empty($determined_format['iconv_req']) && !function_exists('iconv') && !in_array($this->encoding, array('ISO-8859-1', 'UTF-8', 'UTF-16LE', 'UTF-16BE', 'UTF-16'))) {
+ $errormessage = 'iconv() support is required for this module ('.$determined_format['include'].') for encodings other than ISO-8859-1, UTF-8, UTF-16LE, UTF16-BE, UTF-16. ';
+ if (GETID3_OS_ISWINDOWS) {
+ $errormessage .= 'PHP does not have iconv() support. Please enable php_iconv.dll in php.ini, and copy iconv.dll from c:/php/dlls to c:/windows/system32';
+ } else {
+ $errormessage .= 'PHP is not compiled with iconv() support. Please recompile with the --with-iconv switch';
+ }
+ return $this->error($errormessage);
+ }
+
+ // include module
+ include_once(GETID3_INCLUDEPATH.$determined_format['include']);
+
+ // instantiate module class
+ $class_name = 'getid3_'.$determined_format['module'];
+ if (!class_exists($class_name)) {
+ return $this->error('Format not supported, module "'.$determined_format['include'].'" is corrupt.');
+ }
+ //if (isset($determined_format['option'])) {
+ // //$class = new $class_name($this->fp, $this->info, $determined_format['option']);
+ //} else {
+ //$class = new $class_name($this->fp, $this->info);
+ $class = new $class_name($this);
+ //}
+
+ if (!empty($determined_format['set_inline_attachments'])) {
+ $class->inline_attachments = $this->option_save_attachments;
+ }
+ $class->Analyze();
+
+ unset($class);
+
+ // close file
+ fclose($this->fp);
+
+ // process all tags - copy to 'tags' and convert charsets
+ if ($this->option_tags_process) {
+ $this->HandleAllTags();
+ }
+
+ // perform more calculations
+ if ($this->option_extra_info) {
+ $this->ChannelsBitratePlaytimeCalculations();
+ $this->CalculateCompressionRatioVideo();
+ $this->CalculateCompressionRatioAudio();
+ $this->CalculateReplayGain();
+ $this->ProcessAudioStreams();
+ }
+
+ // get the MD5 sum of the audio/video portion of the file - without ID3/APE/Lyrics3/etc header/footer tags
+ if ($this->option_md5_data) {
+ // do not cald md5_data if md5_data_source is present - set by flac only - future MPC/SV8 too
+ if (!$this->option_md5_data_source || empty($this->info['md5_data_source'])) {
+ $this->getHashdata('md5');
+ }
+ }
+
+ // get the SHA1 sum of the audio/video portion of the file - without ID3/APE/Lyrics3/etc header/footer tags
+ if ($this->option_sha1_data) {
+ $this->getHashdata('sha1');
+ }
+
+ // remove undesired keys
+ $this->CleanUp();
+
+ } catch (Exception $e) {
+ $this->error('Caught exception: '.$e->getMessage());
+ }
+
+ // return info array
+ return $this->info;
+ }
+
+
+ // private: error handling
+ function error($message) {
+ $this->CleanUp();
+ if (!isset($this->info['error'])) {
+ $this->info['error'] = array();
+ }
+ $this->info['error'][] = $message;
+ return $this->info;
+ }
+
+
+ // private: warning handling
+ function warning($message) {
+ $this->info['warning'][] = $message;
+ return true;
+ }
+
+
+ // private: CleanUp
+ function CleanUp() {
+
+ // remove possible empty keys
+ $AVpossibleEmptyKeys = array('dataformat', 'bits_per_sample', 'encoder_options', 'streams', 'bitrate');
+ foreach ($AVpossibleEmptyKeys as $dummy => $key) {
+ if (empty($this->info['audio'][$key]) && isset($this->info['audio'][$key])) {
+ unset($this->info['audio'][$key]);
+ }
+ if (empty($this->info['video'][$key]) && isset($this->info['video'][$key])) {
+ unset($this->info['video'][$key]);
+ }
+ }
+
+ // remove empty root keys
+ if (!empty($this->info)) {
+ foreach ($this->info as $key => $value) {
+ if (empty($this->info[$key]) && ($this->info[$key] !== 0) && ($this->info[$key] !== '0')) {
+ unset($this->info[$key]);
+ }
+ }
+ }
+
+ // remove meaningless entries from unknown-format files
+ if (empty($this->info['fileformat'])) {
+ if (isset($this->info['avdataoffset'])) {
+ unset($this->info['avdataoffset']);
+ }
+ if (isset($this->info['avdataend'])) {
+ unset($this->info['avdataend']);
+ }
+ }
+
+ // remove possible duplicated identical entries
+ if (!empty($this->info['error'])) {
+ $this->info['error'] = array_values(array_unique($this->info['error']));
+ }
+ if (!empty($this->info['warning'])) {
+ $this->info['warning'] = array_values(array_unique($this->info['warning']));
+ }
+
+ // remove "global variable" type keys
+ unset($this->info['php_memory_limit']);
+
+ return true;
+ }
+
+
+ // return array containing information about all supported formats
+ function GetFileFormatArray() {
+ static $format_info = array();
+ if (empty($format_info)) {
+ $format_info = array(
+
+ // Audio formats
+
+ // AC-3 - audio - Dolby AC-3 / Dolby Digital
+ 'ac3' => array(
+ 'pattern' => '^\x0B\x77',
+ 'group' => 'audio',
+ 'module' => 'ac3',
+ 'mime_type' => 'audio/ac3',
+ ),
+
+ // AAC - audio - Advanced Audio Coding (AAC) - ADIF format
+ 'adif' => array(
+ 'pattern' => '^ADIF',
+ 'group' => 'audio',
+ 'module' => 'aac',
+ 'mime_type' => 'application/octet-stream',
+ 'fail_ape' => 'WARNING',
+ ),
+
+
+ // AA - audio - Audible Audiobook
+ 'adts' => array(
+ 'pattern' => '^.{4}\x57\x90\x75\x36',
+ 'group' => 'audio',
+ 'module' => 'aa',
+ 'mime_type' => 'audio/audible ',
+ ),
+
+ // AAC - audio - Advanced Audio Coding (AAC) - ADTS format (very similar to MP3)
+ 'adts' => array(
+ 'pattern' => '^\xFF[\xF0-\xF1\xF8-\xF9]',
+ 'group' => 'audio',
+ 'module' => 'aac',
+ 'mime_type' => 'application/octet-stream',
+ 'fail_ape' => 'WARNING',
+ ),
+
+
+ // AU - audio - NeXT/Sun AUdio (AU)
+ 'au' => array(
+ 'pattern' => '^\.snd',
+ 'group' => 'audio',
+ 'module' => 'au',
+ 'mime_type' => 'audio/basic',
+ ),
+
+ // AVR - audio - Audio Visual Research
+ 'avr' => array(
+ 'pattern' => '^2BIT',
+ 'group' => 'audio',
+ 'module' => 'avr',
+ 'mime_type' => 'application/octet-stream',
+ ),
+
+ // BONK - audio - Bonk v0.9+
+ 'bonk' => array(
+ 'pattern' => '^\x00(BONK|INFO|META| ID3)',
+ 'group' => 'audio',
+ 'module' => 'bonk',
+ 'mime_type' => 'audio/xmms-bonk',
+ ),
+
+ // DSS - audio - Digital Speech Standard
+ 'dss' => array(
+ 'pattern' => '^[\x02-\x03]dss',
+ 'group' => 'audio',
+ 'module' => 'dss',
+ 'mime_type' => 'application/octet-stream',
+ ),
+
+ // DTS - audio - Dolby Theatre System
+ 'dts' => array(
+ 'pattern' => '^\x7F\xFE\x80\x01',
+ 'group' => 'audio',
+ 'module' => 'dts',
+ 'mime_type' => 'audio/dts',
+ ),
+
+ // FLAC - audio - Free Lossless Audio Codec
+ 'flac' => array(
+ 'pattern' => '^fLaC',
+ 'group' => 'audio',
+ 'module' => 'flac',
+ 'mime_type' => 'audio/x-flac',
+ 'set_inline_attachments' => true,
+ ),
+
+ // LA - audio - Lossless Audio (LA)
+ 'la' => array(
+ 'pattern' => '^LA0[2-4]',
+ 'group' => 'audio',
+ 'module' => 'la',
+ 'mime_type' => 'application/octet-stream',
+ ),
+
+ // LPAC - audio - Lossless Predictive Audio Compression (LPAC)
+ 'lpac' => array(
+ 'pattern' => '^LPAC',
+ 'group' => 'audio',
+ 'module' => 'lpac',
+ 'mime_type' => 'application/octet-stream',
+ ),
+
+ // MIDI - audio - MIDI (Musical Instrument Digital Interface)
+ 'midi' => array(
+ 'pattern' => '^MThd',
+ 'group' => 'audio',
+ 'module' => 'midi',
+ 'mime_type' => 'audio/midi',
+ ),
+
+ // MAC - audio - Monkey's Audio Compressor
+ 'mac' => array(
+ 'pattern' => '^MAC ',
+ 'group' => 'audio',
+ 'module' => 'monkey',
+ 'mime_type' => 'application/octet-stream',
+ ),
+
+// has been known to produce false matches in random files (e.g. JPEGs), leave out until more precise matching available
+// // MOD - audio - MODule (assorted sub-formats)
+// 'mod' => array(
+// 'pattern' => '^.{1080}(M\\.K\\.|M!K!|FLT4|FLT8|[5-9]CHN|[1-3][0-9]CH)',
+// 'group' => 'audio',
+// 'module' => 'mod',
+// 'option' => 'mod',
+// 'mime_type' => 'audio/mod',
+// ),
+
+ // MOD - audio - MODule (Impulse Tracker)
+ 'it' => array(
+ 'pattern' => '^IMPM',
+ 'group' => 'audio',
+ 'module' => 'mod',
+ //'option' => 'it',
+ 'mime_type' => 'audio/it',
+ ),
+
+ // MOD - audio - MODule (eXtended Module, various sub-formats)
+ 'xm' => array(
+ 'pattern' => '^Extended Module',
+ 'group' => 'audio',
+ 'module' => 'mod',
+ //'option' => 'xm',
+ 'mime_type' => 'audio/xm',
+ ),
+
+ // MOD - audio - MODule (ScreamTracker)
+ 's3m' => array(
+ 'pattern' => '^.{44}SCRM',
+ 'group' => 'audio',
+ 'module' => 'mod',
+ //'option' => 's3m',
+ 'mime_type' => 'audio/s3m',
+ ),
+
+ // MPC - audio - Musepack / MPEGplus
+ 'mpc' => array(
+ 'pattern' => '^(MPCK|MP\+|[\x00\x01\x10\x11\x40\x41\x50\x51\x80\x81\x90\x91\xC0\xC1\xD0\xD1][\x20-37][\x00\x20\x40\x60\x80\xA0\xC0\xE0])',
+ 'group' => 'audio',
+ 'module' => 'mpc',
+ 'mime_type' => 'audio/x-musepack',
+ ),
+
+ // MP3 - audio - MPEG-audio Layer 3 (very similar to AAC-ADTS)
+ 'mp3' => array(
+ 'pattern' => '^\xFF[\xE2-\xE7\xF2-\xF7\xFA-\xFF][\x00-\x0B\x10-\x1B\x20-\x2B\x30-\x3B\x40-\x4B\x50-\x5B\x60-\x6B\x70-\x7B\x80-\x8B\x90-\x9B\xA0-\xAB\xB0-\xBB\xC0-\xCB\xD0-\xDB\xE0-\xEB\xF0-\xFB]',
+ 'group' => 'audio',
+ 'module' => 'mp3',
+ 'mime_type' => 'audio/mpeg',
+ ),
+
+ // OFR - audio - OptimFROG
+ 'ofr' => array(
+ 'pattern' => '^(\*RIFF|OFR)',
+ 'group' => 'audio',
+ 'module' => 'optimfrog',
+ 'mime_type' => 'application/octet-stream',
+ ),
+
+ // RKAU - audio - RKive AUdio compressor
+ 'rkau' => array(
+ 'pattern' => '^RKA',
+ 'group' => 'audio',
+ 'module' => 'rkau',
+ 'mime_type' => 'application/octet-stream',
+ ),
+
+ // SHN - audio - Shorten
+ 'shn' => array(
+ 'pattern' => '^ajkg',
+ 'group' => 'audio',
+ 'module' => 'shorten',
+ 'mime_type' => 'audio/xmms-shn',
+ 'fail_id3' => 'ERROR',
+ 'fail_ape' => 'ERROR',
+ ),
+
+ // TTA - audio - TTA Lossless Audio Compressor (http://tta.corecodec.org)
+ 'tta' => array(
+ 'pattern' => '^TTA', // could also be '^TTA(\x01|\x02|\x03|2|1)'
+ 'group' => 'audio',
+ 'module' => 'tta',
+ 'mime_type' => 'application/octet-stream',
+ ),
+
+ // VOC - audio - Creative Voice (VOC)
+ 'voc' => array(
+ 'pattern' => '^Creative Voice File',
+ 'group' => 'audio',
+ 'module' => 'voc',
+ 'mime_type' => 'audio/voc',
+ ),
+
+ // VQF - audio - transform-domain weighted interleave Vector Quantization Format (VQF)
+ 'vqf' => array(
+ 'pattern' => '^TWIN',
+ 'group' => 'audio',
+ 'module' => 'vqf',
+ 'mime_type' => 'application/octet-stream',
+ ),
+
+ // WV - audio - WavPack (v4.0+)
+ 'wv' => array(
+ 'pattern' => '^wvpk',
+ 'group' => 'audio',
+ 'module' => 'wavpack',
+ 'mime_type' => 'application/octet-stream',
+ ),
+
+
+ // Audio-Video formats
+
+ // ASF - audio/video - Advanced Streaming Format, Windows Media Video, Windows Media Audio
+ 'asf' => array(
+ 'pattern' => '^\x30\x26\xB2\x75\x8E\x66\xCF\x11\xA6\xD9\x00\xAA\x00\x62\xCE\x6C',
+ 'group' => 'audio-video',
+ 'module' => 'asf',
+ 'mime_type' => 'video/x-ms-asf',
+ 'iconv_req' => false,
+ ),
+
+ // BINK - audio/video - Bink / Smacker
+ 'bink' => array(
+ 'pattern' => '^(BIK|SMK)',
+ 'group' => 'audio-video',
+ 'module' => 'bink',
+ 'mime_type' => 'application/octet-stream',
+ ),
+
+ // FLV - audio/video - FLash Video
+ 'flv' => array(
+ 'pattern' => '^FLV\x01',
+ 'group' => 'audio-video',
+ 'module' => 'flv',
+ 'mime_type' => 'video/x-flv',
+ ),
+
+ // MKAV - audio/video - Mastroka
+ 'matroska' => array(
+ 'pattern' => '^\x1A\x45\xDF\xA3',
+ 'group' => 'audio-video',
+ 'module' => 'matroska',
+ 'mime_type' => 'video/x-matroska', // may also be audio/x-matroska
+ 'set_inline_attachments' => true,
+ ),
+
+ // MPEG - audio/video - MPEG (Moving Pictures Experts Group)
+ 'mpeg' => array(
+ 'pattern' => '^\x00\x00\x01(\xBA|\xB3)',
+ 'group' => 'audio-video',
+ 'module' => 'mpeg',
+ 'mime_type' => 'video/mpeg',
+ ),
+
+ // NSV - audio/video - Nullsoft Streaming Video (NSV)
+ 'nsv' => array(
+ 'pattern' => '^NSV[sf]',
+ 'group' => 'audio-video',
+ 'module' => 'nsv',
+ 'mime_type' => 'application/octet-stream',
+ ),
+
+ // Ogg - audio/video - Ogg (Ogg-Vorbis, Ogg-FLAC, Speex, Ogg-Theora(*), Ogg-Tarkin(*))
+ 'ogg' => array(
+ 'pattern' => '^OggS',
+ 'group' => 'audio',
+ 'module' => 'ogg',
+ 'mime_type' => 'application/ogg',
+ 'fail_id3' => 'WARNING',
+ 'fail_ape' => 'WARNING',
+ 'set_inline_attachments' => true,
+ ),
+
+ // QT - audio/video - Quicktime
+ 'quicktime' => array(
+ 'pattern' => '^.{4}(cmov|free|ftyp|mdat|moov|pnot|skip|wide)',
+ 'group' => 'audio-video',
+ 'module' => 'quicktime',
+ 'mime_type' => 'video/quicktime',
+ ),
+
+ // RIFF - audio/video - Resource Interchange File Format (RIFF) / WAV / AVI / CD-audio / SDSS = renamed variant used by SmartSound QuickTracks (www.smartsound.com) / FORM = Audio Interchange File Format (AIFF)
+ 'riff' => array(
+ 'pattern' => '^(RIFF|SDSS|FORM)',
+ 'group' => 'audio-video',
+ 'module' => 'riff',
+ 'mime_type' => 'audio/x-wave',
+ 'fail_ape' => 'WARNING',
+ ),
+
+ // Real - audio/video - RealAudio, RealVideo
+ 'real' => array(
+ 'pattern' => '^(\\.RMF|\\.ra)',
+ 'group' => 'audio-video',
+ 'module' => 'real',
+ 'mime_type' => 'audio/x-realaudio',
+ ),
+
+ // SWF - audio/video - ShockWave Flash
+ 'swf' => array(
+ 'pattern' => '^(F|C)WS',
+ 'group' => 'audio-video',
+ 'module' => 'swf',
+ 'mime_type' => 'application/x-shockwave-flash',
+ ),
+
+
+ // Still-Image formats
+
+ // BMP - still image - Bitmap (Windows, OS/2; uncompressed, RLE8, RLE4)
+ 'bmp' => array(
+ 'pattern' => '^BM',
+ 'group' => 'graphic',
+ 'module' => 'bmp',
+ 'mime_type' => 'image/bmp',
+ 'fail_id3' => 'ERROR',
+ 'fail_ape' => 'ERROR',
+ ),
+
+ // GIF - still image - Graphics Interchange Format
+ 'gif' => array(
+ 'pattern' => '^GIF',
+ 'group' => 'graphic',
+ 'module' => 'gif',
+ 'mime_type' => 'image/gif',
+ 'fail_id3' => 'ERROR',
+ 'fail_ape' => 'ERROR',
+ ),
+
+ // JPEG - still image - Joint Photographic Experts Group (JPEG)
+ 'jpg' => array(
+ 'pattern' => '^\xFF\xD8\xFF',
+ 'group' => 'graphic',
+ 'module' => 'jpg',
+ 'mime_type' => 'image/jpeg',
+ 'fail_id3' => 'ERROR',
+ 'fail_ape' => 'ERROR',
+ ),
+
+ // PCD - still image - Kodak Photo CD
+ 'pcd' => array(
+ 'pattern' => '^.{2048}PCD_IPI\x00',
+ 'group' => 'graphic',
+ 'module' => 'pcd',
+ 'mime_type' => 'image/x-photo-cd',
+ 'fail_id3' => 'ERROR',
+ 'fail_ape' => 'ERROR',
+ ),
+
+
+ // PNG - still image - Portable Network Graphics (PNG)
+ 'png' => array(
+ 'pattern' => '^\x89\x50\x4E\x47\x0D\x0A\x1A\x0A',
+ 'group' => 'graphic',
+ 'module' => 'png',
+ 'mime_type' => 'image/png',
+ 'fail_id3' => 'ERROR',
+ 'fail_ape' => 'ERROR',
+ ),
+
+
+ // SVG - still image - Scalable Vector Graphics (SVG)
+ 'svg' => array(
+ 'pattern' => '( 'graphic',
+ 'module' => 'svg',
+ 'mime_type' => 'image/svg+xml',
+ 'fail_id3' => 'ERROR',
+ 'fail_ape' => 'ERROR',
+ ),
+
+
+ // TIFF - still image - Tagged Information File Format (TIFF)
+ 'tiff' => array(
+ 'pattern' => '^(II\x2A\x00|MM\x00\x2A)',
+ 'group' => 'graphic',
+ 'module' => 'tiff',
+ 'mime_type' => 'image/tiff',
+ 'fail_id3' => 'ERROR',
+ 'fail_ape' => 'ERROR',
+ ),
+
+
+ // EFAX - still image - eFax (TIFF derivative)
+ 'bmp' => array(
+ 'pattern' => '^\xDC\xFE',
+ 'group' => 'graphic',
+ 'module' => 'efax',
+ 'mime_type' => 'image/efax',
+ 'fail_id3' => 'ERROR',
+ 'fail_ape' => 'ERROR',
+ ),
+
+
+ // Data formats
+
+ // ISO - data - International Standards Organization (ISO) CD-ROM Image
+ 'iso' => array(
+ 'pattern' => '^.{32769}CD001',
+ 'group' => 'misc',
+ 'module' => 'iso',
+ 'mime_type' => 'application/octet-stream',
+ 'fail_id3' => 'ERROR',
+ 'fail_ape' => 'ERROR',
+ 'iconv_req' => false,
+ ),
+
+ // RAR - data - RAR compressed data
+ 'rar' => array(
+ 'pattern' => '^Rar\!',
+ 'group' => 'archive',
+ 'module' => 'rar',
+ 'mime_type' => 'application/octet-stream',
+ 'fail_id3' => 'ERROR',
+ 'fail_ape' => 'ERROR',
+ ),
+
+ // SZIP - audio/data - SZIP compressed data
+ 'szip' => array(
+ 'pattern' => '^SZ\x0A\x04',
+ 'group' => 'archive',
+ 'module' => 'szip',
+ 'mime_type' => 'application/octet-stream',
+ 'fail_id3' => 'ERROR',
+ 'fail_ape' => 'ERROR',
+ ),
+
+ // TAR - data - TAR compressed data
+ 'tar' => array(
+ 'pattern' => '^.{100}[0-9\x20]{7}\x00[0-9\x20]{7}\x00[0-9\x20]{7}\x00[0-9\x20\x00]{12}[0-9\x20\x00]{12}',
+ 'group' => 'archive',
+ 'module' => 'tar',
+ 'mime_type' => 'application/x-tar',
+ 'fail_id3' => 'ERROR',
+ 'fail_ape' => 'ERROR',
+ ),
+
+ // GZIP - data - GZIP compressed data
+ 'gz' => array(
+ 'pattern' => '^\x1F\x8B\x08',
+ 'group' => 'archive',
+ 'module' => 'gzip',
+ 'mime_type' => 'application/x-gzip',
+ 'fail_id3' => 'ERROR',
+ 'fail_ape' => 'ERROR',
+ ),
+
+ // ZIP - data - ZIP compressed data
+ 'zip' => array(
+ 'pattern' => '^PK\x03\x04',
+ 'group' => 'archive',
+ 'module' => 'zip',
+ 'mime_type' => 'application/zip',
+ 'fail_id3' => 'ERROR',
+ 'fail_ape' => 'ERROR',
+ ),
+
+
+ // Misc other formats
+
+ // PAR2 - data - Parity Volume Set Specification 2.0
+ 'par2' => array (
+ 'pattern' => '^PAR2\x00PKT',
+ 'group' => 'misc',
+ 'module' => 'par2',
+ 'mime_type' => 'application/octet-stream',
+ 'fail_id3' => 'ERROR',
+ 'fail_ape' => 'ERROR',
+ ),
+
+ // PDF - data - Portable Document Format
+ 'pdf' => array(
+ 'pattern' => '^\x25PDF',
+ 'group' => 'misc',
+ 'module' => 'pdf',
+ 'mime_type' => 'application/pdf',
+ 'fail_id3' => 'ERROR',
+ 'fail_ape' => 'ERROR',
+ ),
+
+ // MSOFFICE - data - ZIP compressed data
+ 'msoffice' => array(
+ 'pattern' => '^\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1', // D0CF11E == DOCFILE == Microsoft Office Document
+ 'group' => 'misc',
+ 'module' => 'msoffice',
+ 'mime_type' => 'application/octet-stream',
+ 'fail_id3' => 'ERROR',
+ 'fail_ape' => 'ERROR',
+ ),
+
+ // CUE - data - CUEsheet (index to single-file disc images)
+ 'cue' => array(
+ 'pattern' => '', // empty pattern means cannot be automatically detected, will fall through all other formats and match based on filename and very basic file contents
+ 'group' => 'misc',
+ 'module' => 'cue',
+ 'mime_type' => 'application/octet-stream',
+ ),
+
+ );
+ }
+
+ return $format_info;
+ }
+
+
+
+ function GetFileFormat(&$filedata, $filename='') {
+ // this function will determine the format of a file based on usually
+ // the first 2-4 bytes of the file (8 bytes for PNG, 16 bytes for JPG,
+ // and in the case of ISO CD image, 6 bytes offset 32kb from the start
+ // of the file).
+
+ // Identify file format - loop through $format_info and detect with reg expr
+ foreach ($this->GetFileFormatArray() as $format_name => $info) {
+ // The /s switch on preg_match() forces preg_match() NOT to treat
+ // newline (0x0A) characters as special chars but do a binary match
+ if (!empty($info['pattern']) && preg_match('#'.$info['pattern'].'#s', $filedata)) {
+ $info['include'] = 'module.'.$info['group'].'.'.$info['module'].'.php';
+ return $info;
+ }
+ }
+
+
+ if (preg_match('#\.mp[123a]$#i', $filename)) {
+ // Too many mp3 encoders on the market put gabage in front of mpeg files
+ // use assume format on these if format detection failed
+ $GetFileFormatArray = $this->GetFileFormatArray();
+ $info = $GetFileFormatArray['mp3'];
+ $info['include'] = 'module.'.$info['group'].'.'.$info['module'].'.php';
+ return $info;
+ } elseif (preg_match('/\.cue$/i', $filename) && preg_match('#FILE "[^"]+" (BINARY|MOTOROLA|AIFF|WAVE|MP3)#', $filedata)) {
+ // there's not really a useful consistent "magic" at the beginning of .cue files to identify them
+ // so until I think of something better, just go by filename if all other format checks fail
+ // and verify there's at least one instance of "TRACK xx AUDIO" in the file
+ $GetFileFormatArray = $this->GetFileFormatArray();
+ $info = $GetFileFormatArray['cue'];
+ $info['include'] = 'module.'.$info['group'].'.'.$info['module'].'.php';
+ return $info;
+ }
+
+ return false;
+ }
+
+
+ // converts array to $encoding charset from $this->encoding
+ function CharConvert(&$array, $encoding) {
+
+ // identical encoding - end here
+ if ($encoding == $this->encoding) {
+ return;
+ }
+
+ // loop thru array
+ foreach ($array as $key => $value) {
+
+ // go recursive
+ if (is_array($value)) {
+ $this->CharConvert($array[$key], $encoding);
+ }
+
+ // convert string
+ elseif (is_string($value)) {
+ $array[$key] = trim(getid3_lib::iconv_fallback($encoding, $this->encoding, $value));
+ }
+ }
+ }
+
+
+ function HandleAllTags() {
+
+ // key name => array (tag name, character encoding)
+ static $tags;
+ if (empty($tags)) {
+ $tags = array(
+ 'asf' => array('asf' , 'UTF-16LE'),
+ 'midi' => array('midi' , 'ISO-8859-1'),
+ 'nsv' => array('nsv' , 'ISO-8859-1'),
+ 'ogg' => array('vorbiscomment' , 'UTF-8'),
+ 'png' => array('png' , 'UTF-8'),
+ 'tiff' => array('tiff' , 'ISO-8859-1'),
+ 'quicktime' => array('quicktime' , 'UTF-8'),
+ 'real' => array('real' , 'ISO-8859-1'),
+ 'vqf' => array('vqf' , 'ISO-8859-1'),
+ 'zip' => array('zip' , 'ISO-8859-1'),
+ 'riff' => array('riff' , 'ISO-8859-1'),
+ 'lyrics3' => array('lyrics3' , 'ISO-8859-1'),
+ 'id3v1' => array('id3v1' , $this->encoding_id3v1),
+ 'id3v2' => array('id3v2' , 'UTF-8'), // not according to the specs (every frame can have a different encoding), but getID3() force-converts all encodings to UTF-8
+ 'ape' => array('ape' , 'UTF-8'),
+ 'cue' => array('cue' , 'ISO-8859-1'),
+ 'matroska' => array('matroska' , 'UTF-8'),
+ );
+ }
+
+ // loop through comments array
+ foreach ($tags as $comment_name => $tagname_encoding_array) {
+ list($tag_name, $encoding) = $tagname_encoding_array;
+
+ // fill in default encoding type if not already present
+ if (isset($this->info[$comment_name]) && !isset($this->info[$comment_name]['encoding'])) {
+ $this->info[$comment_name]['encoding'] = $encoding;
+ }
+
+ // copy comments if key name set
+ if (!empty($this->info[$comment_name]['comments'])) {
+
+ foreach ($this->info[$comment_name]['comments'] as $tag_key => $valuearray) {
+ foreach ($valuearray as $key => $value) {
+ if (is_string($value)) {
+ $value = trim($value, " \r\n\t"); // do not trim nulls from $value!! Unicode characters will get mangled if trailing nulls are removed!
+ }
+ if ($value) {
+ $this->info['tags'][trim($tag_name)][trim($tag_key)][] = $value;
+ }
+ }
+ }
+
+ if (!isset($this->info['tags'][$tag_name])) {
+ // comments are set but contain nothing but empty strings, so skip
+ continue;
+ }
+
+ if ($this->option_tags_html) {
+ foreach ($this->info['tags'][$tag_name] as $tag_key => $valuearray) {
+ foreach ($valuearray as $key => $value) {
+ if (is_string($value)) {
+ //$this->info['tags_html'][$tag_name][$tag_key][$key] = getid3_lib::MultiByteCharString2HTML($value, $encoding);
+ $this->info['tags_html'][$tag_name][$tag_key][$key] = str_replace('', '', trim(getid3_lib::MultiByteCharString2HTML($value, $encoding)));
+ } else {
+ $this->info['tags_html'][$tag_name][$tag_key][$key] = $value;
+ }
+ }
+ }
+ }
+
+ $this->CharConvert($this->info['tags'][$tag_name], $encoding); // only copy gets converted!
+ }
+
+ }
+
+ // pictures can take up a lot of space, and we don't need multiple copies of them
+ // let there be a single copy in [comments][picture], and not elsewhere
+ if (!empty($this->info['tags'])) {
+ $unset_keys = array('tags', 'tags_html');
+ foreach ($this->info['tags'] as $tagtype => $tagarray) {
+ foreach ($tagarray as $tagname => $tagdata) {
+ if ($tagname == 'picture') {
+ foreach ($tagdata as $key => $tagarray) {
+ $this->info['comments']['picture'][] = $tagarray;
+ if (isset($tagarray['data']) && isset($tagarray['image_mime'])) {
+ if (isset($this->info['tags'][$tagtype][$tagname][$key])) {
+ unset($this->info['tags'][$tagtype][$tagname][$key]);
+ }
+ if (isset($this->info['tags_html'][$tagtype][$tagname][$key])) {
+ unset($this->info['tags_html'][$tagtype][$tagname][$key]);
+ }
+ }
+ }
+ }
+ }
+ foreach ($unset_keys as $unset_key) {
+ // remove possible empty keys from (e.g. [tags][id3v2][picture])
+ if (empty($this->info[$unset_key][$tagtype]['picture'])) {
+ unset($this->info[$unset_key][$tagtype]['picture']);
+ }
+ if (empty($this->info[$unset_key][$tagtype])) {
+ unset($this->info[$unset_key][$tagtype]);
+ }
+ if (empty($this->info[$unset_key])) {
+ unset($this->info[$unset_key]);
+ }
+ }
+ // remove duplicate copy of picture data from (e.g. [id3v2][comments][picture])
+ if (isset($this->info[$tagtype]['comments']['picture'])) {
+ unset($this->info[$tagtype]['comments']['picture']);
+ }
+ if (empty($this->info[$tagtype]['comments'])) {
+ unset($this->info[$tagtype]['comments']);
+ }
+ if (empty($this->info[$tagtype])) {
+ unset($this->info[$tagtype]);
+ }
+ }
+ }
+ return true;
+ }
+
+
+ function getHashdata($algorithm) {
+ switch ($algorithm) {
+ case 'md5':
+ case 'sha1':
+ break;
+
+ default:
+ return $this->error('bad algorithm "'.$algorithm.'" in getHashdata()');
+ break;
+ }
+
+ if (!empty($this->info['fileformat']) && !empty($this->info['dataformat']) && ($this->info['fileformat'] == 'ogg') && ($this->info['audio']['dataformat'] == 'vorbis')) {
+
+ // We cannot get an identical md5_data value for Ogg files where the comments
+ // span more than 1 Ogg page (compared to the same audio data with smaller
+ // comments) using the normal getID3() method of MD5'ing the data between the
+ // end of the comments and the end of the file (minus any trailing tags),
+ // because the page sequence numbers of the pages that the audio data is on
+ // do not match. Under normal circumstances, where comments are smaller than
+ // the nominal 4-8kB page size, then this is not a problem, but if there are
+ // very large comments, the only way around it is to strip off the comment
+ // tags with vorbiscomment and MD5 that file.
+ // This procedure must be applied to ALL Ogg files, not just the ones with
+ // comments larger than 1 page, because the below method simply MD5's the
+ // whole file with the comments stripped, not just the portion after the
+ // comments block (which is the standard getID3() method.
+
+ // The above-mentioned problem of comments spanning multiple pages and changing
+ // page sequence numbers likely happens for OggSpeex and OggFLAC as well, but
+ // currently vorbiscomment only works on OggVorbis files.
+
+ if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) {
+
+ $this->warning('Failed making system call to vorbiscomment.exe - '.$algorithm.'_data is incorrect - error returned: PHP running in Safe Mode (backtick operator not available)');
+ $this->info[$algorithm.'_data'] = false;
+
+ } else {
+
+ // Prevent user from aborting script
+ $old_abort = ignore_user_abort(true);
+
+ // Create empty file
+ $empty = tempnam(GETID3_TEMP_DIR, 'getID3');
+ touch($empty);
+
+ // Use vorbiscomment to make temp file without comments
+ $temp = tempnam(GETID3_TEMP_DIR, 'getID3');
+ $file = $this->info['filenamepath'];
+
+ if (GETID3_OS_ISWINDOWS) {
+
+ if (file_exists(GETID3_HELPERAPPSDIR.'vorbiscomment.exe')) {
+
+ $commandline = '"'.GETID3_HELPERAPPSDIR.'vorbiscomment.exe" -w -c "'.$empty.'" "'.$file.'" "'.$temp.'"';
+ $VorbisCommentError = `$commandline`;
+
+ } else {
+
+ $VorbisCommentError = 'vorbiscomment.exe not found in '.GETID3_HELPERAPPSDIR;
+
+ }
+
+ } else {
+
+ $commandline = 'vorbiscomment -w -c "'.$empty.'" "'.$file.'" "'.$temp.'" 2>&1';
+ $commandline = 'vorbiscomment -w -c '.escapeshellarg($empty).' '.escapeshellarg($file).' '.escapeshellarg($temp).' 2>&1';
+ $VorbisCommentError = `$commandline`;
+
+ }
+
+ if (!empty($VorbisCommentError)) {
+
+ $this->info['warning'][] = 'Failed making system call to vorbiscomment(.exe) - '.$algorithm.'_data will be incorrect. If vorbiscomment is unavailable, please download from http://www.vorbis.com/download.psp and put in the getID3() directory. Error returned: '.$VorbisCommentError;
+ $this->info[$algorithm.'_data'] = false;
+
+ } else {
+
+ // Get hash of newly created file
+ switch ($algorithm) {
+ case 'md5':
+ $this->info[$algorithm.'_data'] = md5_file($temp);
+ break;
+
+ case 'sha1':
+ $this->info[$algorithm.'_data'] = sha1_file($temp);
+ break;
+ }
+ }
+
+ // Clean up
+ unlink($empty);
+ unlink($temp);
+
+ // Reset abort setting
+ ignore_user_abort($old_abort);
+
+ }
+
+ } else {
+
+ if (!empty($this->info['avdataoffset']) || (isset($this->info['avdataend']) && ($this->info['avdataend'] < $this->info['filesize']))) {
+
+ // get hash from part of file
+ $this->info[$algorithm.'_data'] = getid3_lib::hash_data($this->info['filenamepath'], $this->info['avdataoffset'], $this->info['avdataend'], $algorithm);
+
+ } else {
+
+ // get hash from whole file
+ switch ($algorithm) {
+ case 'md5':
+ $this->info[$algorithm.'_data'] = md5_file($this->info['filenamepath']);
+ break;
+
+ case 'sha1':
+ $this->info[$algorithm.'_data'] = sha1_file($this->info['filenamepath']);
+ break;
+ }
+ }
+
+ }
+ return true;
+ }
+
+
+ function ChannelsBitratePlaytimeCalculations() {
+
+ // set channelmode on audio
+ if (!empty($this->info['audio']['channelmode']) || !isset($this->info['audio']['channels'])) {
+ // ignore
+ } elseif ($this->info['audio']['channels'] == 1) {
+ $this->info['audio']['channelmode'] = 'mono';
+ } elseif ($this->info['audio']['channels'] == 2) {
+ $this->info['audio']['channelmode'] = 'stereo';
+ }
+
+ // Calculate combined bitrate - audio + video
+ $CombinedBitrate = 0;
+ $CombinedBitrate += (isset($this->info['audio']['bitrate']) ? $this->info['audio']['bitrate'] : 0);
+ $CombinedBitrate += (isset($this->info['video']['bitrate']) ? $this->info['video']['bitrate'] : 0);
+ if (($CombinedBitrate > 0) && empty($this->info['bitrate'])) {
+ $this->info['bitrate'] = $CombinedBitrate;
+ }
+ //if ((isset($this->info['video']) && !isset($this->info['video']['bitrate'])) || (isset($this->info['audio']) && !isset($this->info['audio']['bitrate']))) {
+ // // for example, VBR MPEG video files cannot determine video bitrate:
+ // // should not set overall bitrate and playtime from audio bitrate only
+ // unset($this->info['bitrate']);
+ //}
+
+ // video bitrate undetermined, but calculable
+ if (isset($this->info['video']['dataformat']) && $this->info['video']['dataformat'] && (!isset($this->info['video']['bitrate']) || ($this->info['video']['bitrate'] == 0))) {
+ // if video bitrate not set
+ if (isset($this->info['audio']['bitrate']) && ($this->info['audio']['bitrate'] > 0) && ($this->info['audio']['bitrate'] == $this->info['bitrate'])) {
+ // AND if audio bitrate is set to same as overall bitrate
+ if (isset($this->info['playtime_seconds']) && ($this->info['playtime_seconds'] > 0)) {
+ // AND if playtime is set
+ if (isset($this->info['avdataend']) && isset($this->info['avdataoffset'])) {
+ // AND if AV data offset start/end is known
+ // THEN we can calculate the video bitrate
+ $this->info['bitrate'] = round((($this->info['avdataend'] - $this->info['avdataoffset']) * 8) / $this->info['playtime_seconds']);
+ $this->info['video']['bitrate'] = $this->info['bitrate'] - $this->info['audio']['bitrate'];
+ }
+ }
+ }
+ }
+
+ if ((!isset($this->info['playtime_seconds']) || ($this->info['playtime_seconds'] <= 0)) && !empty($this->info['bitrate'])) {
+ $this->info['playtime_seconds'] = (($this->info['avdataend'] - $this->info['avdataoffset']) * 8) / $this->info['bitrate'];
+ }
+
+ if (!isset($this->info['bitrate']) && !empty($this->info['playtime_seconds'])) {
+ $this->info['bitrate'] = (($this->info['avdataend'] - $this->info['avdataoffset']) * 8) / $this->info['playtime_seconds'];
+ }
+ if (isset($this->info['bitrate']) && empty($this->info['audio']['bitrate']) && empty($this->info['video']['bitrate'])) {
+ if (isset($this->info['audio']['dataformat']) && empty($this->info['video']['resolution_x'])) {
+ // audio only
+ $this->info['audio']['bitrate'] = $this->info['bitrate'];
+ } elseif (isset($this->info['video']['resolution_x']) && empty($this->info['audio']['dataformat'])) {
+ // video only
+ $this->info['video']['bitrate'] = $this->info['bitrate'];
+ }
+ }
+
+ // Set playtime string
+ if (!empty($this->info['playtime_seconds']) && empty($this->info['playtime_string'])) {
+ $this->info['playtime_string'] = getid3_lib::PlaytimeString($this->info['playtime_seconds']);
+ }
+ }
+
+
+ function CalculateCompressionRatioVideo() {
+ if (empty($this->info['video'])) {
+ return false;
+ }
+ if (empty($this->info['video']['resolution_x']) || empty($this->info['video']['resolution_y'])) {
+ return false;
+ }
+ if (empty($this->info['video']['bits_per_sample'])) {
+ return false;
+ }
+
+ switch ($this->info['video']['dataformat']) {
+ case 'bmp':
+ case 'gif':
+ case 'jpeg':
+ case 'jpg':
+ case 'png':
+ case 'tiff':
+ $FrameRate = 1;
+ $PlaytimeSeconds = 1;
+ $BitrateCompressed = $this->info['filesize'] * 8;
+ break;
+
+ default:
+ if (!empty($this->info['video']['frame_rate'])) {
+ $FrameRate = $this->info['video']['frame_rate'];
+ } else {
+ return false;
+ }
+ if (!empty($this->info['playtime_seconds'])) {
+ $PlaytimeSeconds = $this->info['playtime_seconds'];
+ } else {
+ return false;
+ }
+ if (!empty($this->info['video']['bitrate'])) {
+ $BitrateCompressed = $this->info['video']['bitrate'];
+ } else {
+ return false;
+ }
+ break;
+ }
+ $BitrateUncompressed = $this->info['video']['resolution_x'] * $this->info['video']['resolution_y'] * $this->info['video']['bits_per_sample'] * $FrameRate;
+
+ $this->info['video']['compression_ratio'] = $BitrateCompressed / $BitrateUncompressed;
+ return true;
+ }
+
+
+ function CalculateCompressionRatioAudio() {
+ if (empty($this->info['audio']['bitrate']) || empty($this->info['audio']['channels']) || empty($this->info['audio']['sample_rate'])) {
+ return false;
+ }
+ $this->info['audio']['compression_ratio'] = $this->info['audio']['bitrate'] / ($this->info['audio']['channels'] * $this->info['audio']['sample_rate'] * (!empty($this->info['audio']['bits_per_sample']) ? $this->info['audio']['bits_per_sample'] : 16));
+
+ if (!empty($this->info['audio']['streams'])) {
+ foreach ($this->info['audio']['streams'] as $streamnumber => $streamdata) {
+ if (!empty($streamdata['bitrate']) && !empty($streamdata['channels']) && !empty($streamdata['sample_rate'])) {
+ $this->info['audio']['streams'][$streamnumber]['compression_ratio'] = $streamdata['bitrate'] / ($streamdata['channels'] * $streamdata['sample_rate'] * (!empty($streamdata['bits_per_sample']) ? $streamdata['bits_per_sample'] : 16));
+ }
+ }
+ }
+ return true;
+ }
+
+
+ function CalculateReplayGain() {
+ if (isset($this->info['replay_gain'])) {
+ if (!isset($this->info['replay_gain']['reference_volume'])) {
+ $this->info['replay_gain']['reference_volume'] = (double) 89.0;
+ }
+ if (isset($this->info['replay_gain']['track']['adjustment'])) {
+ $this->info['replay_gain']['track']['volume'] = $this->info['replay_gain']['reference_volume'] - $this->info['replay_gain']['track']['adjustment'];
+ }
+ if (isset($this->info['replay_gain']['album']['adjustment'])) {
+ $this->info['replay_gain']['album']['volume'] = $this->info['replay_gain']['reference_volume'] - $this->info['replay_gain']['album']['adjustment'];
+ }
+
+ if (isset($this->info['replay_gain']['track']['peak'])) {
+ $this->info['replay_gain']['track']['max_noclip_gain'] = 0 - getid3_lib::RGADamplitude2dB($this->info['replay_gain']['track']['peak']);
+ }
+ if (isset($this->info['replay_gain']['album']['peak'])) {
+ $this->info['replay_gain']['album']['max_noclip_gain'] = 0 - getid3_lib::RGADamplitude2dB($this->info['replay_gain']['album']['peak']);
+ }
+ }
+ return true;
+ }
+
+ function ProcessAudioStreams() {
+ if (!empty($this->info['audio']['bitrate']) || !empty($this->info['audio']['channels']) || !empty($this->info['audio']['sample_rate'])) {
+ if (!isset($this->info['audio']['streams'])) {
+ foreach ($this->info['audio'] as $key => $value) {
+ if ($key != 'streams') {
+ $this->info['audio']['streams'][0][$key] = $value;
+ }
+ }
+ }
+ }
+ return true;
+ }
+
+ function getid3_tempnam() {
+ return tempnam($this->tempdir, 'gI3');
+ }
+
+
+ public function saveAttachment(&$ThisFileInfoIndex, $filename, $offset, $length) {
+ try {
+ if (!getid3_lib::intValueSupported($offset + $length)) {
+ throw new Exception('cannot extract attachment, it extends beyond the '.round(PHP_INT_MAX / 1073741824).'GB limit');
+ }
+
+ // do not extract at all
+ if ($this->option_save_attachments === getID3::ATTACHMENTS_NONE) {
+
+ unset($ThisFileInfoIndex); // do not set any
+
+ // extract to return array
+ } elseif ($this->option_save_attachments === getID3::ATTACHMENTS_INLINE) {
+
+ // get whole data in one pass, till it is anyway stored in memory
+ $ThisFileInfoIndex = file_get_contents($this->info['filenamepath'], false, null, $offset, $length);
+ if (($ThisFileInfoIndex === false) || (strlen($ThisFileInfoIndex) != $length)) { // verify
+ throw new Exception('failed to read attachment data');
+ }
+
+ // assume directory path is given
+ } else {
+
+ $dir = rtrim(str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $this->option_save_attachments), DIRECTORY_SEPARATOR);
+ // check supplied directory
+ if (!is_dir($dir) || !is_writable($dir)) {
+ throw new Exception('getID3::saveAttachment() -- supplied path ('.$dir.') does not exist, or is not writable');
+ }
+
+ // set up destination path
+ $dest = $dir.DIRECTORY_SEPARATOR.$filename;
+
+ // optimize speed if read buffer size is configured to be large enough
+ // here stream_copy_to_stream() may also be used. need to do speed-compare tests
+ if ($length <= $this->fread_buffer_size()) {
+ $data = file_get_contents($this->info['filenamepath'], false, null, $offset, $length);
+ if (($data === false) || (strlen($data) != $length)) { // verify
+ throw new Exception('failed to read attachment data');
+ }
+ if (!file_put_contents($dest, $data)) {
+ throw new Exception('failed to create file '.$dest);
+ }
+ } else {
+ // optimization not available - copy data in loop
+ // here stream_copy_to_stream() shouldn't be used because it's internal read buffer may be larger than ours!
+ getid3_lib::CopyFileParts($this->info['filenamepath'], $dest, $offset, $length);
+ }
+ $ThisFileInfoIndex = $dest;
+ }
+
+ } catch (Exception $e) {
+
+ unset($ThisFileInfoIndex); // do not set any is case of error
+ $this->warning('Failed to extract attachment '.$filename.': '.$e->getMessage());
+ return false;
+
+ }
+ return true;
+ }
+
+
+ public function include_module($name) {
+ //if (!file_exists($this->include_path.'module.'.$name.'.php')) {
+ if (!file_exists(GETID3_INCLUDEPATH.'module.'.$name.'.php')) {
+ throw new getid3_exception('Required module.'.$name.'.php is missing.');
+ }
+ include_once(GETID3_INCLUDEPATH.'module.'.$name.'.php');
+ return true;
+ }
+
+}
+
+
+abstract class getid3_handler
+{
+ protected $getid3; // pointer
+
+ protected $data_string_flag = false; // analyzing filepointer or string
+ protected $data_string; // string to analyze
+ protected $data_string_position = 0; // seek position in string
+
+
+ public function __construct(getID3 $getid3) {
+ $this->getid3 = $getid3;
+ }
+
+
+ // Analyze from file pointer
+ abstract public function Analyze();
+
+
+ // Analyze from string instead
+ public function AnalyzeString(&$string) {
+ // Enter string mode
+ $this->data_string_flag = true;
+ $this->data_string = $string;
+
+ // Save info
+ $saved_avdataoffset = $this->getid3->info['avdataoffset'];
+ $saved_avdataend = $this->getid3->info['avdataend'];
+ $saved_filesize = $this->getid3->info['filesize'];
+
+ // Reset some info
+ $this->getid3->info['avdataoffset'] = 0;
+ $this->getid3->info['avdataend'] = $this->getid3->info['filesize'] = strlen($string);
+
+ // Analyze
+ $this->Analyze();
+
+ // Restore some info
+ $this->getid3->info['avdataoffset'] = $saved_avdataoffset;
+ $this->getid3->info['avdataend'] = $saved_avdataend;
+ $this->getid3->info['filesize'] = $saved_filesize;
+
+ // Exit string mode
+ $this->data_string_flag = false;
+ }
+
+
+ protected function ftell() {
+ if ($this->data_string_flag) {
+ return $this->data_string_position;
+ }
+ return ftell($this->getid3->fp);
+ }
+
+
+ protected function fread($bytes) {
+ if ($this->data_string_flag) {
+ $this->data_string_position += $bytes;
+ return substr($this->data_string, $this->data_string_position - $bytes, $bytes);
+ }
+ return fread($this->getid3->fp, $bytes);
+ }
+
+
+ protected function fseek($bytes, $whence = SEEK_SET) {
+ if ($this->data_string_flag) {
+ switch ($whence) {
+ case SEEK_SET:
+ $this->data_string_position = $bytes;
+ return;
+
+ case SEEK_CUR:
+ $this->data_string_position += $bytes;
+ return;
+
+ case SEEK_END:
+ $this->data_string_position = strlen($this->data_string) + $bytes;
+ return;
+ }
+ }
+ return fseek($this->getid3->fp, $bytes, $whence);
+ }
+
+}
+
+
+class getid3_exception extends Exception
+{
+ public $message;
+}
+
+?>
\ No newline at end of file
diff --git a/lib/getid3/getid3/module.archive.gzip.php b/lib/getid3/getid3/module.archive.gzip.php
new file mode 100644
index 00000000..c30052ed
--- /dev/null
+++ b/lib/getid3/getid3/module.archive.gzip.php
@@ -0,0 +1,280 @@
+ //
+// available at http://getid3.sourceforge.net //
+// or http://www.getid3.org //
+/////////////////////////////////////////////////////////////////
+// See readme.txt for more details //
+/////////////////////////////////////////////////////////////////
+// //
+// module.archive.gzip.php //
+// module for analyzing GZIP files //
+// dependencies: NONE //
+// ///
+/////////////////////////////////////////////////////////////////
+// //
+// Module originally written by //
+// Mike Mozolin //
+// //
+/////////////////////////////////////////////////////////////////
+
+
+class getid3_gzip extends getid3_handler {
+
+ // public: Optional file list - disable for speed.
+ var $option_gzip_parse_contents = false; // decode gzipped files, if possible, and parse recursively (.tar.gz for example)
+
+ function Analyze() {
+ $info = &$this->getid3->info;
+
+ $info['fileformat'] = 'gzip';
+
+ $start_length = 10;
+ $unpack_header = 'a1id1/a1id2/a1cmethod/a1flags/a4mtime/a1xflags/a1os';
+ //+---+---+---+---+---+---+---+---+---+---+
+ //|ID1|ID2|CM |FLG| MTIME |XFL|OS |
+ //+---+---+---+---+---+---+---+---+---+---+
+
+ if ($info['filesize'] > $info['php_memory_limit']) {
+ $info['error'][] = 'File is too large ('.number_format($info['filesize']).' bytes) to read into memory (limit: '.number_format($info['php_memory_limit'] / 1048576).'MB)';
+ return false;
+ }
+ fseek($this->getid3->fp, 0);
+ $buffer = fread($this->getid3->fp, $info['filesize']);
+
+ $arr_members = explode("\x1F\x8B\x08", $buffer);
+ while (true) {
+ $is_wrong_members = false;
+ $num_members = intval(count($arr_members));
+ for ($i = 0; $i < $num_members; $i++) {
+ if (strlen($arr_members[$i]) == 0) {
+ continue;
+ }
+ $buf = "\x1F\x8B\x08".$arr_members[$i];
+
+ $attr = unpack($unpack_header, substr($buf, 0, $start_length));
+ if (!$this->get_os_type(ord($attr['os']))) {
+ // Merge member with previous if wrong OS type
+ $arr_members[$i - 1] .= $buf;
+ $arr_members[$i] = '';
+ $is_wrong_members = true;
+ continue;
+ }
+ }
+ if (!$is_wrong_members) {
+ break;
+ }
+ }
+
+ $info['gzip']['files'] = array();
+
+ $fpointer = 0;
+ $idx = 0;
+ for ($i = 0; $i < $num_members; $i++) {
+ if (strlen($arr_members[$i]) == 0) {
+ continue;
+ }
+ $thisInfo = &$info['gzip']['member_header'][++$idx];
+
+ $buff = "\x1F\x8B\x08".$arr_members[$i];
+
+ $attr = unpack($unpack_header, substr($buff, 0, $start_length));
+ $thisInfo['filemtime'] = getid3_lib::LittleEndian2Int($attr['mtime']);
+ $thisInfo['raw']['id1'] = ord($attr['cmethod']);
+ $thisInfo['raw']['id2'] = ord($attr['cmethod']);
+ $thisInfo['raw']['cmethod'] = ord($attr['cmethod']);
+ $thisInfo['raw']['os'] = ord($attr['os']);
+ $thisInfo['raw']['xflags'] = ord($attr['xflags']);
+ $thisInfo['raw']['flags'] = ord($attr['flags']);
+
+ $thisInfo['flags']['crc16'] = (bool) ($thisInfo['raw']['flags'] & 0x02);
+ $thisInfo['flags']['extra'] = (bool) ($thisInfo['raw']['flags'] & 0x04);
+ $thisInfo['flags']['filename'] = (bool) ($thisInfo['raw']['flags'] & 0x08);
+ $thisInfo['flags']['comment'] = (bool) ($thisInfo['raw']['flags'] & 0x10);
+
+ $thisInfo['compression'] = $this->get_xflag_type($thisInfo['raw']['xflags']);
+
+ $thisInfo['os'] = $this->get_os_type($thisInfo['raw']['os']);
+ if (!$thisInfo['os']) {
+ $info['error'][] = 'Read error on gzip file';
+ return false;
+ }
+
+ $fpointer = 10;
+ $arr_xsubfield = array();
+ // bit 2 - FLG.FEXTRA
+ //+---+---+=================================+
+ //| XLEN |...XLEN bytes of "extra field"...|
+ //+---+---+=================================+
+ if ($thisInfo['flags']['extra']) {
+ $w_xlen = substr($buff, $fpointer, 2);
+ $xlen = getid3_lib::LittleEndian2Int($w_xlen);
+ $fpointer += 2;
+
+ $thisInfo['raw']['xfield'] = substr($buff, $fpointer, $xlen);
+ // Extra SubFields
+ //+---+---+---+---+==================================+
+ //|SI1|SI2| LEN |... LEN bytes of subfield data ...|
+ //+---+---+---+---+==================================+
+ $idx = 0;
+ while (true) {
+ if ($idx >= $xlen) {
+ break;
+ }
+ $si1 = ord(substr($buff, $fpointer + $idx++, 1));
+ $si2 = ord(substr($buff, $fpointer + $idx++, 1));
+ if (($si1 == 0x41) && ($si2 == 0x70)) {
+ $w_xsublen = substr($buff, $fpointer + $idx, 2);
+ $xsublen = getid3_lib::LittleEndian2Int($w_xsublen);
+ $idx += 2;
+ $arr_xsubfield[] = substr($buff, $fpointer + $idx, $xsublen);
+ $idx += $xsublen;
+ } else {
+ break;
+ }
+ }
+ $fpointer += $xlen;
+ }
+ // bit 3 - FLG.FNAME
+ //+=========================================+
+ //|...original file name, zero-terminated...|
+ //+=========================================+
+ // GZIP files may have only one file, with no filename, so assume original filename is current filename without .gz
+ $thisInfo['filename'] = preg_replace('#\.gz$#i', '', $info['filename']);
+ if ($thisInfo['flags']['filename']) {
+ while (true) {
+ if (ord($buff[$fpointer]) == 0) {
+ $fpointer++;
+ break;
+ }
+ $thisInfo['filename'] .= $buff[$fpointer];
+ $fpointer++;
+ }
+ }
+ // bit 4 - FLG.FCOMMENT
+ //+===================================+
+ //|...file comment, zero-terminated...|
+ //+===================================+
+ if ($thisInfo['flags']['comment']) {
+ while (true) {
+ if (ord($buff[$fpointer]) == 0) {
+ $fpointer++;
+ break;
+ }
+ $thisInfo['comment'] .= $buff[$fpointer];
+ $fpointer++;
+ }
+ }
+ // bit 1 - FLG.FHCRC
+ //+---+---+
+ //| CRC16 |
+ //+---+---+
+ if ($thisInfo['flags']['crc16']) {
+ $w_crc = substr($buff, $fpointer, 2);
+ $thisInfo['crc16'] = getid3_lib::LittleEndian2Int($w_crc);
+ $fpointer += 2;
+ }
+ // bit 0 - FLG.FTEXT
+ //if ($thisInfo['raw']['flags'] & 0x01) {
+ // Ignored...
+ //}
+ // bits 5, 6, 7 - reserved
+
+ $thisInfo['crc32'] = getid3_lib::LittleEndian2Int(substr($buff, strlen($buff) - 8, 4));
+ $thisInfo['filesize'] = getid3_lib::LittleEndian2Int(substr($buff, strlen($buff) - 4));
+
+ $info['gzip']['files'] = getid3_lib::array_merge_clobber($info['gzip']['files'], getid3_lib::CreateDeepArray($thisInfo['filename'], '/', $thisInfo['filesize']));
+
+ if ($this->option_gzip_parse_contents) {
+ // Try to inflate GZip
+ $csize = 0;
+ $inflated = '';
+ $chkcrc32 = '';
+ if (function_exists('gzinflate')) {
+ $cdata = substr($buff, $fpointer);
+ $cdata = substr($cdata, 0, strlen($cdata) - 8);
+ $csize = strlen($cdata);
+ $inflated = gzinflate($cdata);
+
+ // Calculate CRC32 for inflated content
+ $thisInfo['crc32_valid'] = (bool) (sprintf('%u', crc32($inflated)) == $thisInfo['crc32']);
+
+ // determine format
+ $formattest = substr($inflated, 0, 32774);
+ $getid3_temp = new getID3();
+ $determined_format = $getid3_temp->GetFileFormat($formattest);
+ unset($getid3_temp);
+
+ // file format is determined
+ $determined_format['module'] = (isset($determined_format['module']) ? $determined_format['module'] : '');
+ switch ($determined_format['module']) {
+ case 'tar':
+ // view TAR-file info
+ if (file_exists(GETID3_INCLUDEPATH.$determined_format['include']) && include_once(GETID3_INCLUDEPATH.$determined_format['include'])) {
+ if (($temp_tar_filename = tempnam(GETID3_TEMP_DIR, 'getID3')) === false) {
+ // can't find anywhere to create a temp file, abort
+ $info['error'][] = 'Unable to create temp file to parse TAR inside GZIP file';
+ break;
+ }
+ if ($fp_temp_tar = fopen($temp_tar_filename, 'w+b')) {
+ fwrite($fp_temp_tar, $inflated);
+ fclose($fp_temp_tar);
+ $getid3_temp = new getID3();
+ $getid3_temp->openfile($temp_tar_filename);
+ $getid3_tar = new getid3_tar($getid3_temp);
+ $getid3_tar->Analyze();
+ $info['gzip']['member_header'][$idx]['tar'] = $getid3_temp->info['tar'];
+ unset($getid3_temp, $getid3_tar);
+ unlink($temp_tar_filename);
+ } else {
+ $info['error'][] = 'Unable to fopen() temp file to parse TAR inside GZIP file';
+ break;
+ }
+ }
+ break;
+
+ case '':
+ default:
+ // unknown or unhandled format
+ break;
+ }
+ }
+ }
+ }
+ return true;
+ }
+
+ // Converts the OS type
+ function get_os_type($key) {
+ static $os_type = array(
+ '0' => 'FAT filesystem (MS-DOS, OS/2, NT/Win32)',
+ '1' => 'Amiga',
+ '2' => 'VMS (or OpenVMS)',
+ '3' => 'Unix',
+ '4' => 'VM/CMS',
+ '5' => 'Atari TOS',
+ '6' => 'HPFS filesystem (OS/2, NT)',
+ '7' => 'Macintosh',
+ '8' => 'Z-System',
+ '9' => 'CP/M',
+ '10' => 'TOPS-20',
+ '11' => 'NTFS filesystem (NT)',
+ '12' => 'QDOS',
+ '13' => 'Acorn RISCOS',
+ '255' => 'unknown'
+ );
+ return (isset($os_type[$key]) ? $os_type[$key] : '');
+ }
+
+ // Converts the eXtra FLags
+ function get_xflag_type($key) {
+ static $xflag_type = array(
+ '0' => 'unknown',
+ '2' => 'maximum compression',
+ '4' => 'fastest algorithm'
+ );
+ return (isset($xflag_type[$key]) ? $xflag_type[$key] : '');
+ }
+}
+
+?>
diff --git a/lib/getid3/getid3/module.archive.rar.php b/lib/getid3/getid3/module.archive.rar.php
new file mode 100644
index 00000000..4f5d46f8
--- /dev/null
+++ b/lib/getid3/getid3/module.archive.rar.php
@@ -0,0 +1,53 @@
+ //
+// available at http://getid3.sourceforge.net //
+// or http://www.getid3.org //
+/////////////////////////////////////////////////////////////////
+// See readme.txt for more details //
+/////////////////////////////////////////////////////////////////
+// //
+// module.archive.rar.php //
+// module for analyzing RAR files //
+// dependencies: NONE //
+// ///
+/////////////////////////////////////////////////////////////////
+
+
+class getid3_rar extends getid3_handler
+{
+
+ var $option_use_rar_extension = false;
+
+ function Analyze() {
+ $info = &$this->getid3->info;
+
+ $info['fileformat'] = 'rar';
+
+ if ($this->option_use_rar_extension === true) {
+ if (function_exists('rar_open')) {
+ if ($rp = rar_open($info['filenamepath'])) {
+ $info['rar']['files'] = array();
+ $entries = rar_list($rp);
+ foreach ($entries as $entry) {
+ $info['rar']['files'] = getid3_lib::array_merge_clobber($info['rar']['files'], getid3_lib::CreateDeepArray($entry->getName(), '/', $entry->getUnpackedSize()));
+ }
+ rar_close($rp);
+ return true;
+ } else {
+ $info['error'][] = 'failed to rar_open('.$info['filename'].')';
+ }
+ } else {
+ $info['error'][] = 'RAR support does not appear to be available in this PHP installation';
+ }
+ } else {
+ $info['error'][] = 'PHP-RAR processing has been disabled (set $getid3_rar->option_use_rar_extension=true to enable)';
+ }
+ return false;
+
+ }
+
+}
+
+
+?>
\ No newline at end of file
diff --git a/lib/getid3/getid3/module.archive.szip.php b/lib/getid3/getid3/module.archive.szip.php
new file mode 100644
index 00000000..3be62532
--- /dev/null
+++ b/lib/getid3/getid3/module.archive.szip.php
@@ -0,0 +1,96 @@
+ //
+// available at http://getid3.sourceforge.net //
+// or http://www.getid3.org //
+/////////////////////////////////////////////////////////////////
+// See readme.txt for more details //
+/////////////////////////////////////////////////////////////////
+// //
+// module.archive.szip.php //
+// module for analyzing SZIP compressed files //
+// dependencies: NONE //
+// ///
+/////////////////////////////////////////////////////////////////
+
+
+class getid3_szip extends getid3_handler
+{
+
+ function Analyze() {
+ $info = &$this->getid3->info;
+
+ fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
+ $SZIPHeader = fread($this->getid3->fp, 6);
+ if (substr($SZIPHeader, 0, 4) != "SZ\x0A\x04") {
+ $info['error'][] = 'Expecting "53 5A 0A 04" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($SZIPHeader, 0, 4)).'"';
+ return false;
+ }
+ $info['fileformat'] = 'szip';
+ $info['szip']['major_version'] = getid3_lib::BigEndian2Int(substr($SZIPHeader, 4, 1));
+ $info['szip']['minor_version'] = getid3_lib::BigEndian2Int(substr($SZIPHeader, 5, 1));
+
+ while (!feof($this->getid3->fp)) {
+ $NextBlockID = fread($this->getid3->fp, 2);
+ switch ($NextBlockID) {
+ case 'SZ':
+ // Note that szip files can be concatenated, this has the same effect as
+ // concatenating the files. this also means that global header blocks
+ // might be present between directory/data blocks.
+ fseek($this->getid3->fp, 4, SEEK_CUR);
+ break;
+
+ case 'BH':
+ $BHheaderbytes = getid3_lib::BigEndian2Int(fread($this->getid3->fp, 3));
+ $BHheaderdata = fread($this->getid3->fp, $BHheaderbytes);
+ $BHheaderoffset = 0;
+ while (strpos($BHheaderdata, "\x00", $BHheaderoffset) > 0) {
+ //filename as \0 terminated string (empty string indicates end)
+ //owner as \0 terminated string (empty is same as last file)
+ //group as \0 terminated string (empty is same as last file)
+ //3 byte filelength in this block
+ //2 byte access flags
+ //4 byte creation time (like in unix)
+ //4 byte modification time (like in unix)
+ //4 byte access time (like in unix)
+
+ $BHdataArray['filename'] = substr($BHheaderdata, $BHheaderoffset, strcspn($BHheaderdata, "\x00"));
+ $BHheaderoffset += (strlen($BHdataArray['filename']) + 1);
+
+ $BHdataArray['owner'] = substr($BHheaderdata, $BHheaderoffset, strcspn($BHheaderdata, "\x00"));
+ $BHheaderoffset += (strlen($BHdataArray['owner']) + 1);
+
+ $BHdataArray['group'] = substr($BHheaderdata, $BHheaderoffset, strcspn($BHheaderdata, "\x00"));
+ $BHheaderoffset += (strlen($BHdataArray['group']) + 1);
+
+ $BHdataArray['filelength'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 3));
+ $BHheaderoffset += 3;
+
+ $BHdataArray['access_flags'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 2));
+ $BHheaderoffset += 2;
+
+ $BHdataArray['creation_time'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 4));
+ $BHheaderoffset += 4;
+
+ $BHdataArray['modification_time'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 4));
+ $BHheaderoffset += 4;
+
+ $BHdataArray['access_time'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 4));
+ $BHheaderoffset += 4;
+
+ $info['szip']['BH'][] = $BHdataArray;
+ }
+ break;
+
+ default:
+ break 2;
+ }
+ }
+
+ return true;
+
+ }
+
+}
+
+?>
\ No newline at end of file
diff --git a/lib/getid3/getid3/module.archive.tar.php b/lib/getid3/getid3/module.archive.tar.php
new file mode 100644
index 00000000..94d32039
--- /dev/null
+++ b/lib/getid3/getid3/module.archive.tar.php
@@ -0,0 +1,178 @@
+ //
+// available at http://getid3.sourceforge.net //
+// or http://www.getid3.org //
+/////////////////////////////////////////////////////////////////
+// See readme.txt for more details //
+/////////////////////////////////////////////////////////////////
+// //
+// module.archive.tar.php //
+// module for analyzing TAR files //
+// dependencies: NONE //
+// ///
+/////////////////////////////////////////////////////////////////
+// //
+// Module originally written by //
+// Mike Mozolin //
+// //
+/////////////////////////////////////////////////////////////////
+
+
+class getid3_tar extends getid3_handler
+{
+
+ function Analyze() {
+ $info = &$this->getid3->info;
+
+ $info['fileformat'] = 'tar';
+ $info['tar']['files'] = array();
+
+ $unpack_header = 'a100fname/a8mode/a8uid/a8gid/a12size/a12mtime/a8chksum/a1typflag/a100lnkname/a6magic/a2ver/a32uname/a32gname/a8devmaj/a8devmin/a155prefix';
+ $null_512k = str_repeat("\x00", 512); // end-of-file marker
+
+ fseek($this->getid3->fp, 0);
+ while (!feof($this->getid3->fp)) {
+ $buffer = fread($this->getid3->fp, 512);
+ if (strlen($buffer) < 512) {
+ break;
+ }
+
+ // check the block
+ $checksum = 0;
+ for ($i = 0; $i < 148; $i++) {
+ $checksum += ord($buffer{$i});
+ }
+ for ($i = 148; $i < 156; $i++) {
+ $checksum += ord(' ');
+ }
+ for ($i = 156; $i < 512; $i++) {
+ $checksum += ord($buffer{$i});
+ }
+ $attr = unpack($unpack_header, $buffer);
+ $name = (isset($attr['fname'] ) ? trim($attr['fname'] ) : '');
+ $mode = octdec(isset($attr['mode'] ) ? trim($attr['mode'] ) : '');
+ $uid = octdec(isset($attr['uid'] ) ? trim($attr['uid'] ) : '');
+ $gid = octdec(isset($attr['gid'] ) ? trim($attr['gid'] ) : '');
+ $size = octdec(isset($attr['size'] ) ? trim($attr['size'] ) : '');
+ $mtime = octdec(isset($attr['mtime'] ) ? trim($attr['mtime'] ) : '');
+ $chksum = octdec(isset($attr['chksum'] ) ? trim($attr['chksum'] ) : '');
+ $typflag = (isset($attr['typflag']) ? trim($attr['typflag']) : '');
+ $lnkname = (isset($attr['lnkname']) ? trim($attr['lnkname']) : '');
+ $magic = (isset($attr['magic'] ) ? trim($attr['magic'] ) : '');
+ $ver = (isset($attr['ver'] ) ? trim($attr['ver'] ) : '');
+ $uname = (isset($attr['uname'] ) ? trim($attr['uname'] ) : '');
+ $gname = (isset($attr['gname'] ) ? trim($attr['gname'] ) : '');
+ $devmaj = octdec(isset($attr['devmaj'] ) ? trim($attr['devmaj'] ) : '');
+ $devmin = octdec(isset($attr['devmin'] ) ? trim($attr['devmin'] ) : '');
+ $prefix = (isset($attr['prefix'] ) ? trim($attr['prefix'] ) : '');
+ if (($checksum == 256) && ($chksum == 0)) {
+ // EOF Found
+ break;
+ }
+ if ($prefix) {
+ $name = $prefix.'/'.$name;
+ }
+ if ((preg_match('#/$#', $name)) && !$name) {
+ $typeflag = 5;
+ }
+ if ($buffer == $null_512k) {
+ // it's the end of the tar-file...
+ break;
+ }
+
+ // Read to the next chunk
+ fseek($this->getid3->fp, $size, SEEK_CUR);
+
+ $diff = $size % 512;
+ if ($diff != 0) {
+ // Padding, throw away
+ fseek($this->getid3->fp, (512 - $diff), SEEK_CUR);
+ }
+ // Protect against tar-files with garbage at the end
+ if ($name == '') {
+ break;
+ }
+ $info['tar']['file_details'][$name] = array (
+ 'name' => $name,
+ 'mode_raw' => $mode,
+ 'mode' => getid3_tar::display_perms($mode),
+ 'uid' => $uid,
+ 'gid' => $gid,
+ 'size' => $size,
+ 'mtime' => $mtime,
+ 'chksum' => $chksum,
+ 'typeflag' => getid3_tar::get_flag_type($typflag),
+ 'linkname' => $lnkname,
+ 'magic' => $magic,
+ 'version' => $ver,
+ 'uname' => $uname,
+ 'gname' => $gname,
+ 'devmajor' => $devmaj,
+ 'devminor' => $devmin
+ );
+ $info['tar']['files'] = getid3_lib::array_merge_clobber($info['tar']['files'], getid3_lib::CreateDeepArray($info['tar']['file_details'][$name]['name'], '/', $size));
+ }
+ return true;
+ }
+
+ // Parses the file mode to file permissions
+ function display_perms($mode) {
+ // Determine Type
+ if ($mode & 0x1000) $type='p'; // FIFO pipe
+ elseif ($mode & 0x2000) $type='c'; // Character special
+ elseif ($mode & 0x4000) $type='d'; // Directory
+ elseif ($mode & 0x6000) $type='b'; // Block special
+ elseif ($mode & 0x8000) $type='-'; // Regular
+ elseif ($mode & 0xA000) $type='l'; // Symbolic Link
+ elseif ($mode & 0xC000) $type='s'; // Socket
+ else $type='u'; // UNKNOWN
+
+ // Determine permissions
+ $owner['read'] = (($mode & 00400) ? 'r' : '-');
+ $owner['write'] = (($mode & 00200) ? 'w' : '-');
+ $owner['execute'] = (($mode & 00100) ? 'x' : '-');
+ $group['read'] = (($mode & 00040) ? 'r' : '-');
+ $group['write'] = (($mode & 00020) ? 'w' : '-');
+ $group['execute'] = (($mode & 00010) ? 'x' : '-');
+ $world['read'] = (($mode & 00004) ? 'r' : '-');
+ $world['write'] = (($mode & 00002) ? 'w' : '-');
+ $world['execute'] = (($mode & 00001) ? 'x' : '-');
+
+ // Adjust for SUID, SGID and sticky bit
+ if ($mode & 0x800) $owner['execute'] = ($owner['execute'] == 'x') ? 's' : 'S';
+ if ($mode & 0x400) $group['execute'] = ($group['execute'] == 'x') ? 's' : 'S';
+ if ($mode & 0x200) $world['execute'] = ($world['execute'] == 'x') ? 't' : 'T';
+
+ $s = sprintf('%1s', $type);
+ $s .= sprintf('%1s%1s%1s', $owner['read'], $owner['write'], $owner['execute']);
+ $s .= sprintf('%1s%1s%1s', $group['read'], $group['write'], $group['execute']);
+ $s .= sprintf('%1s%1s%1s'."\n", $world['read'], $world['write'], $world['execute']);
+ return $s;
+ }
+
+ // Converts the file type
+ function get_flag_type($typflag) {
+ static $flag_types = array(
+ '0' => 'LF_NORMAL',
+ '1' => 'LF_LINK',
+ '2' => 'LF_SYNLINK',
+ '3' => 'LF_CHR',
+ '4' => 'LF_BLK',
+ '5' => 'LF_DIR',
+ '6' => 'LF_FIFO',
+ '7' => 'LF_CONFIG',
+ 'D' => 'LF_DUMPDIR',
+ 'K' => 'LF_LONGLINK',
+ 'L' => 'LF_LONGNAME',
+ 'M' => 'LF_MULTIVOL',
+ 'N' => 'LF_NAMES',
+ 'S' => 'LF_SPARSE',
+ 'V' => 'LF_VOLHDR'
+ );
+ return (isset($flag_types[$typflag]) ? $flag_types[$typflag] : '');
+ }
+
+}
+
+?>
\ No newline at end of file
diff --git a/lib/getid3/getid3/module.archive.zip.php b/lib/getid3/getid3/module.archive.zip.php
new file mode 100644
index 00000000..7db8fd23
--- /dev/null
+++ b/lib/getid3/getid3/module.archive.zip.php
@@ -0,0 +1,424 @@
+ //
+// available at http://getid3.sourceforge.net //
+// or http://www.getid3.org //
+/////////////////////////////////////////////////////////////////
+// See readme.txt for more details //
+/////////////////////////////////////////////////////////////////
+// //
+// module.archive.zip.php //
+// module for analyzing pkZip files //
+// dependencies: NONE //
+// ///
+/////////////////////////////////////////////////////////////////
+
+
+class getid3_zip extends getid3_handler
+{
+
+ function Analyze() {
+ $info = &$this->getid3->info;
+
+ $info['fileformat'] = 'zip';
+ $info['zip']['encoding'] = 'ISO-8859-1';
+ $info['zip']['files'] = array();
+
+ $info['zip']['compressed_size'] = 0;
+ $info['zip']['uncompressed_size'] = 0;
+ $info['zip']['entries_count'] = 0;
+
+ if (!getid3_lib::intValueSupported($info['filesize'])) {
+ $info['error'][] = 'File is larger than '.round(PHP_INT_MAX / 1073741824).'GB, not supported by PHP';
+ return false;
+ } else {
+ $EOCDsearchData = '';
+ $EOCDsearchCounter = 0;
+ while ($EOCDsearchCounter++ < 512) {
+
+ fseek($this->getid3->fp, -128 * $EOCDsearchCounter, SEEK_END);
+ $EOCDsearchData = fread($this->getid3->fp, 128).$EOCDsearchData;
+
+ if (strstr($EOCDsearchData, 'PK'."\x05\x06")) {
+
+ $EOCDposition = strpos($EOCDsearchData, 'PK'."\x05\x06");
+ fseek($this->getid3->fp, (-128 * $EOCDsearchCounter) + $EOCDposition, SEEK_END);
+ $info['zip']['end_central_directory'] = $this->ZIPparseEndOfCentralDirectory();
+
+ fseek($this->getid3->fp, $info['zip']['end_central_directory']['directory_offset'], SEEK_SET);
+ $info['zip']['entries_count'] = 0;
+ while ($centraldirectoryentry = $this->ZIPparseCentralDirectory($this->getid3->fp)) {
+ $info['zip']['central_directory'][] = $centraldirectoryentry;
+ $info['zip']['entries_count']++;
+ $info['zip']['compressed_size'] += $centraldirectoryentry['compressed_size'];
+ $info['zip']['uncompressed_size'] += $centraldirectoryentry['uncompressed_size'];
+
+ if ($centraldirectoryentry['uncompressed_size'] > 0) {
+ $info['zip']['files'] = getid3_lib::array_merge_clobber($info['zip']['files'], getid3_lib::CreateDeepArray($centraldirectoryentry['filename'], '/', $centraldirectoryentry['uncompressed_size']));
+ }
+ }
+
+ if ($info['zip']['entries_count'] == 0) {
+ $info['error'][] = 'No Central Directory entries found (truncated file?)';
+ return false;
+ }
+
+ if (!empty($info['zip']['end_central_directory']['comment'])) {
+ $info['zip']['comments']['comment'][] = $info['zip']['end_central_directory']['comment'];
+ }
+
+ if (isset($info['zip']['central_directory'][0]['compression_method'])) {
+ $info['zip']['compression_method'] = $info['zip']['central_directory'][0]['compression_method'];
+ }
+ if (isset($info['zip']['central_directory'][0]['flags']['compression_speed'])) {
+ $info['zip']['compression_speed'] = $info['zip']['central_directory'][0]['flags']['compression_speed'];
+ }
+ if (isset($info['zip']['compression_method']) && ($info['zip']['compression_method'] == 'store') && !isset($info['zip']['compression_speed'])) {
+ $info['zip']['compression_speed'] = 'store';
+ }
+
+ return true;
+
+ }
+ }
+ }
+
+ if ($this->getZIPentriesFilepointer()) {
+
+ // central directory couldn't be found and/or parsed
+ // scan through actual file data entries, recover as much as possible from probable trucated file
+ if ($info['zip']['compressed_size'] > ($info['filesize'] - 46 - 22)) {
+ $info['error'][] = 'Warning: Truncated file! - Total compressed file sizes ('.$info['zip']['compressed_size'].' bytes) is greater than filesize minus Central Directory and End Of Central Directory structures ('.($info['filesize'] - 46 - 22).' bytes)';
+ }
+ $info['error'][] = 'Cannot find End Of Central Directory - returned list of files in [zip][entries] array may not be complete';
+ foreach ($info['zip']['entries'] as $key => $valuearray) {
+ $info['zip']['files'][$valuearray['filename']] = $valuearray['uncompressed_size'];
+ }
+ return true;
+
+ } else {
+
+ unset($info['zip']);
+ $info['fileformat'] = '';
+ $info['error'][] = 'Cannot find End Of Central Directory (truncated file?)';
+ return false;
+
+ }
+ }
+
+
+ function getZIPHeaderFilepointerTopDown() {
+ $info = &$this->getid3->info;
+
+ $info['fileformat'] = 'zip';
+
+ $info['zip']['compressed_size'] = 0;
+ $info['zip']['uncompressed_size'] = 0;
+ $info['zip']['entries_count'] = 0;
+
+ rewind($this->getid3->fp);
+ while ($fileentry = $this->ZIPparseLocalFileHeader()) {
+ $info['zip']['entries'][] = $fileentry;
+ $info['zip']['entries_count']++;
+ }
+ if ($info['zip']['entries_count'] == 0) {
+ $info['error'][] = 'No Local File Header entries found';
+ return false;
+ }
+
+ $info['zip']['entries_count'] = 0;
+ while ($centraldirectoryentry = $this->ZIPparseCentralDirectory($this->getid3->fp)) {
+ $info['zip']['central_directory'][] = $centraldirectoryentry;
+ $info['zip']['entries_count']++;
+ $info['zip']['compressed_size'] += $centraldirectoryentry['compressed_size'];
+ $info['zip']['uncompressed_size'] += $centraldirectoryentry['uncompressed_size'];
+ }
+ if ($info['zip']['entries_count'] == 0) {
+ $info['error'][] = 'No Central Directory entries found (truncated file?)';
+ return false;
+ }
+
+ if ($EOCD = $this->ZIPparseEndOfCentralDirectory()) {
+ $info['zip']['end_central_directory'] = $EOCD;
+ } else {
+ $info['error'][] = 'No End Of Central Directory entry found (truncated file?)';
+ return false;
+ }
+
+ if (!empty($info['zip']['end_central_directory']['comment'])) {
+ $info['zip']['comments']['comment'][] = $info['zip']['end_central_directory']['comment'];
+ }
+
+ return true;
+ }
+
+
+ function getZIPentriesFilepointer() {
+ $info = &$this->getid3->info;
+
+ $info['zip']['compressed_size'] = 0;
+ $info['zip']['uncompressed_size'] = 0;
+ $info['zip']['entries_count'] = 0;
+
+ rewind($this->getid3->fp);
+ while ($fileentry = $this->ZIPparseLocalFileHeader()) {
+ $info['zip']['entries'][] = $fileentry;
+ $info['zip']['entries_count']++;
+ $info['zip']['compressed_size'] += $fileentry['compressed_size'];
+ $info['zip']['uncompressed_size'] += $fileentry['uncompressed_size'];
+ }
+ if ($info['zip']['entries_count'] == 0) {
+ $info['error'][] = 'No Local File Header entries found';
+ return false;
+ }
+
+ return true;
+ }
+
+
+ function ZIPparseLocalFileHeader() {
+ $LocalFileHeader['offset'] = ftell($this->getid3->fp);
+
+ $ZIPlocalFileHeader = fread($this->getid3->fp, 30);
+
+ $LocalFileHeader['raw']['signature'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 0, 4));
+ if ($LocalFileHeader['raw']['signature'] != 0x04034B50) {
+ // invalid Local File Header Signature
+ fseek($this->getid3->fp, $LocalFileHeader['offset'], SEEK_SET); // seek back to where filepointer originally was so it can be handled properly
+ return false;
+ }
+ $LocalFileHeader['raw']['extract_version'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 4, 2));
+ $LocalFileHeader['raw']['general_flags'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 6, 2));
+ $LocalFileHeader['raw']['compression_method'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 8, 2));
+ $LocalFileHeader['raw']['last_mod_file_time'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 10, 2));
+ $LocalFileHeader['raw']['last_mod_file_date'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 12, 2));
+ $LocalFileHeader['raw']['crc_32'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 14, 4));
+ $LocalFileHeader['raw']['compressed_size'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 18, 4));
+ $LocalFileHeader['raw']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 22, 4));
+ $LocalFileHeader['raw']['filename_length'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 26, 2));
+ $LocalFileHeader['raw']['extra_field_length'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 28, 2));
+
+ $LocalFileHeader['extract_version'] = sprintf('%1.1f', $LocalFileHeader['raw']['extract_version'] / 10);
+ $LocalFileHeader['host_os'] = $this->ZIPversionOSLookup(($LocalFileHeader['raw']['extract_version'] & 0xFF00) >> 8);
+ $LocalFileHeader['compression_method'] = $this->ZIPcompressionMethodLookup($LocalFileHeader['raw']['compression_method']);
+ $LocalFileHeader['compressed_size'] = $LocalFileHeader['raw']['compressed_size'];
+ $LocalFileHeader['uncompressed_size'] = $LocalFileHeader['raw']['uncompressed_size'];
+ $LocalFileHeader['flags'] = $this->ZIPparseGeneralPurposeFlags($LocalFileHeader['raw']['general_flags'], $LocalFileHeader['raw']['compression_method']);
+ $LocalFileHeader['last_modified_timestamp'] = $this->DOStime2UNIXtime($LocalFileHeader['raw']['last_mod_file_date'], $LocalFileHeader['raw']['last_mod_file_time']);
+
+ $FilenameExtrafieldLength = $LocalFileHeader['raw']['filename_length'] + $LocalFileHeader['raw']['extra_field_length'];
+ if ($FilenameExtrafieldLength > 0) {
+ $ZIPlocalFileHeader .= fread($this->getid3->fp, $FilenameExtrafieldLength);
+
+ if ($LocalFileHeader['raw']['filename_length'] > 0) {
+ $LocalFileHeader['filename'] = substr($ZIPlocalFileHeader, 30, $LocalFileHeader['raw']['filename_length']);
+ }
+ if ($LocalFileHeader['raw']['extra_field_length'] > 0) {
+ $LocalFileHeader['raw']['extra_field_data'] = substr($ZIPlocalFileHeader, 30 + $LocalFileHeader['raw']['filename_length'], $LocalFileHeader['raw']['extra_field_length']);
+ }
+ }
+
+ $LocalFileHeader['data_offset'] = ftell($this->getid3->fp);
+ //$LocalFileHeader['compressed_data'] = fread($this->getid3->fp, $LocalFileHeader['raw']['compressed_size']);
+ fseek($this->getid3->fp, $LocalFileHeader['raw']['compressed_size'], SEEK_CUR);
+
+ if ($LocalFileHeader['flags']['data_descriptor_used']) {
+ $DataDescriptor = fread($this->getid3->fp, 12);
+ $LocalFileHeader['data_descriptor']['crc_32'] = getid3_lib::LittleEndian2Int(substr($DataDescriptor, 0, 4));
+ $LocalFileHeader['data_descriptor']['compressed_size'] = getid3_lib::LittleEndian2Int(substr($DataDescriptor, 4, 4));
+ $LocalFileHeader['data_descriptor']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($DataDescriptor, 8, 4));
+ }
+
+ return $LocalFileHeader;
+ }
+
+
+ function ZIPparseCentralDirectory() {
+ $CentralDirectory['offset'] = ftell($this->getid3->fp);
+
+ $ZIPcentralDirectory = fread($this->getid3->fp, 46);
+
+ $CentralDirectory['raw']['signature'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 0, 4));
+ if ($CentralDirectory['raw']['signature'] != 0x02014B50) {
+ // invalid Central Directory Signature
+ fseek($this->getid3->fp, $CentralDirectory['offset'], SEEK_SET); // seek back to where filepointer originally was so it can be handled properly
+ return false;
+ }
+ $CentralDirectory['raw']['create_version'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 4, 2));
+ $CentralDirectory['raw']['extract_version'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 6, 2));
+ $CentralDirectory['raw']['general_flags'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 8, 2));
+ $CentralDirectory['raw']['compression_method'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 10, 2));
+ $CentralDirectory['raw']['last_mod_file_time'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 12, 2));
+ $CentralDirectory['raw']['last_mod_file_date'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 14, 2));
+ $CentralDirectory['raw']['crc_32'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 16, 4));
+ $CentralDirectory['raw']['compressed_size'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 20, 4));
+ $CentralDirectory['raw']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 24, 4));
+ $CentralDirectory['raw']['filename_length'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 28, 2));
+ $CentralDirectory['raw']['extra_field_length'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 30, 2));
+ $CentralDirectory['raw']['file_comment_length'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 32, 2));
+ $CentralDirectory['raw']['disk_number_start'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 34, 2));
+ $CentralDirectory['raw']['internal_file_attrib'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 36, 2));
+ $CentralDirectory['raw']['external_file_attrib'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 38, 4));
+ $CentralDirectory['raw']['local_header_offset'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 42, 4));
+
+ $CentralDirectory['entry_offset'] = $CentralDirectory['raw']['local_header_offset'];
+ $CentralDirectory['create_version'] = sprintf('%1.1f', $CentralDirectory['raw']['create_version'] / 10);
+ $CentralDirectory['extract_version'] = sprintf('%1.1f', $CentralDirectory['raw']['extract_version'] / 10);
+ $CentralDirectory['host_os'] = $this->ZIPversionOSLookup(($CentralDirectory['raw']['extract_version'] & 0xFF00) >> 8);
+ $CentralDirectory['compression_method'] = $this->ZIPcompressionMethodLookup($CentralDirectory['raw']['compression_method']);
+ $CentralDirectory['compressed_size'] = $CentralDirectory['raw']['compressed_size'];
+ $CentralDirectory['uncompressed_size'] = $CentralDirectory['raw']['uncompressed_size'];
+ $CentralDirectory['flags'] = $this->ZIPparseGeneralPurposeFlags($CentralDirectory['raw']['general_flags'], $CentralDirectory['raw']['compression_method']);
+ $CentralDirectory['last_modified_timestamp'] = $this->DOStime2UNIXtime($CentralDirectory['raw']['last_mod_file_date'], $CentralDirectory['raw']['last_mod_file_time']);
+
+ $FilenameExtrafieldCommentLength = $CentralDirectory['raw']['filename_length'] + $CentralDirectory['raw']['extra_field_length'] + $CentralDirectory['raw']['file_comment_length'];
+ if ($FilenameExtrafieldCommentLength > 0) {
+ $FilenameExtrafieldComment = fread($this->getid3->fp, $FilenameExtrafieldCommentLength);
+
+ if ($CentralDirectory['raw']['filename_length'] > 0) {
+ $CentralDirectory['filename'] = substr($FilenameExtrafieldComment, 0, $CentralDirectory['raw']['filename_length']);
+ }
+ if ($CentralDirectory['raw']['extra_field_length'] > 0) {
+ $CentralDirectory['raw']['extra_field_data'] = substr($FilenameExtrafieldComment, $CentralDirectory['raw']['filename_length'], $CentralDirectory['raw']['extra_field_length']);
+ }
+ if ($CentralDirectory['raw']['file_comment_length'] > 0) {
+ $CentralDirectory['file_comment'] = substr($FilenameExtrafieldComment, $CentralDirectory['raw']['filename_length'] + $CentralDirectory['raw']['extra_field_length'], $CentralDirectory['raw']['file_comment_length']);
+ }
+ }
+
+ return $CentralDirectory;
+ }
+
+ function ZIPparseEndOfCentralDirectory() {
+ $EndOfCentralDirectory['offset'] = ftell($this->getid3->fp);
+
+ $ZIPendOfCentralDirectory = fread($this->getid3->fp, 22);
+
+ $EndOfCentralDirectory['signature'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 0, 4));
+ if ($EndOfCentralDirectory['signature'] != 0x06054B50) {
+ // invalid End Of Central Directory Signature
+ fseek($this->getid3->fp, $EndOfCentralDirectory['offset'], SEEK_SET); // seek back to where filepointer originally was so it can be handled properly
+ return false;
+ }
+ $EndOfCentralDirectory['disk_number_current'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 4, 2));
+ $EndOfCentralDirectory['disk_number_start_directory'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 6, 2));
+ $EndOfCentralDirectory['directory_entries_this_disk'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 8, 2));
+ $EndOfCentralDirectory['directory_entries_total'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 10, 2));
+ $EndOfCentralDirectory['directory_size'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 12, 4));
+ $EndOfCentralDirectory['directory_offset'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 16, 4));
+ $EndOfCentralDirectory['comment_length'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 20, 2));
+
+ if ($EndOfCentralDirectory['comment_length'] > 0) {
+ $EndOfCentralDirectory['comment'] = fread($this->getid3->fp, $EndOfCentralDirectory['comment_length']);
+ }
+
+ return $EndOfCentralDirectory;
+ }
+
+
+ static function ZIPparseGeneralPurposeFlags($flagbytes, $compressionmethod) {
+ $ParsedFlags['encrypted'] = (bool) ($flagbytes & 0x0001);
+
+ switch ($compressionmethod) {
+ case 6:
+ $ParsedFlags['dictionary_size'] = (($flagbytes & 0x0002) ? 8192 : 4096);
+ $ParsedFlags['shannon_fano_trees'] = (($flagbytes & 0x0004) ? 3 : 2);
+ break;
+
+ case 8:
+ case 9:
+ switch (($flagbytes & 0x0006) >> 1) {
+ case 0:
+ $ParsedFlags['compression_speed'] = 'normal';
+ break;
+ case 1:
+ $ParsedFlags['compression_speed'] = 'maximum';
+ break;
+ case 2:
+ $ParsedFlags['compression_speed'] = 'fast';
+ break;
+ case 3:
+ $ParsedFlags['compression_speed'] = 'superfast';
+ break;
+ }
+ break;
+ }
+ $ParsedFlags['data_descriptor_used'] = (bool) ($flagbytes & 0x0008);
+
+ return $ParsedFlags;
+ }
+
+
+ static function ZIPversionOSLookup($index) {
+ static $ZIPversionOSLookup = array(
+ 0 => 'MS-DOS and OS/2 (FAT / VFAT / FAT32 file systems)',
+ 1 => 'Amiga',
+ 2 => 'OpenVMS',
+ 3 => 'Unix',
+ 4 => 'VM/CMS',
+ 5 => 'Atari ST',
+ 6 => 'OS/2 H.P.F.S.',
+ 7 => 'Macintosh',
+ 8 => 'Z-System',
+ 9 => 'CP/M',
+ 10 => 'Windows NTFS',
+ 11 => 'MVS',
+ 12 => 'VSE',
+ 13 => 'Acorn Risc',
+ 14 => 'VFAT',
+ 15 => 'Alternate MVS',
+ 16 => 'BeOS',
+ 17 => 'Tandem'
+ );
+
+ return (isset($ZIPversionOSLookup[$index]) ? $ZIPversionOSLookup[$index] : '[unknown]');
+ }
+
+ static function ZIPcompressionMethodLookup($index) {
+ static $ZIPcompressionMethodLookup = array(
+ 0 => 'store',
+ 1 => 'shrink',
+ 2 => 'reduce-1',
+ 3 => 'reduce-2',
+ 4 => 'reduce-3',
+ 5 => 'reduce-4',
+ 6 => 'implode',
+ 7 => 'tokenize',
+ 8 => 'deflate',
+ 9 => 'deflate64',
+ 10 => 'PKWARE Date Compression Library Imploding'
+ );
+
+ return (isset($ZIPcompressionMethodLookup[$index]) ? $ZIPcompressionMethodLookup[$index] : '[unknown]');
+ }
+
+ static function DOStime2UNIXtime($DOSdate, $DOStime) {
+ // wFatDate
+ // Specifies the MS-DOS date. The date is a packed 16-bit value with the following format:
+ // Bits Contents
+ // 0-4 Day of the month (1-31)
+ // 5-8 Month (1 = January, 2 = February, and so on)
+ // 9-15 Year offset from 1980 (add 1980 to get actual year)
+
+ $UNIXday = ($DOSdate & 0x001F);
+ $UNIXmonth = (($DOSdate & 0x01E0) >> 5);
+ $UNIXyear = (($DOSdate & 0xFE00) >> 9) + 1980;
+
+ // wFatTime
+ // Specifies the MS-DOS time. The time is a packed 16-bit value with the following format:
+ // Bits Contents
+ // 0-4 Second divided by 2
+ // 5-10 Minute (0-59)
+ // 11-15 Hour (0-23 on a 24-hour clock)
+
+ $UNIXsecond = ($DOStime & 0x001F) * 2;
+ $UNIXminute = (($DOStime & 0x07E0) >> 5);
+ $UNIXhour = (($DOStime & 0xF800) >> 11);
+
+ return gmmktime($UNIXhour, $UNIXminute, $UNIXsecond, $UNIXmonth, $UNIXday, $UNIXyear);
+ }
+
+}
+
+
+?>
\ No newline at end of file
diff --git a/lib/getid3/getid3/module.audio-video.asf.php b/lib/getid3/getid3/module.audio-video.asf.php
new file mode 100644
index 00000000..0bb095f5
--- /dev/null
+++ b/lib/getid3/getid3/module.audio-video.asf.php
@@ -0,0 +1,2021 @@
+ //
+// available at http://getid3.sourceforge.net //
+// or http://www.getid3.org //
+/////////////////////////////////////////////////////////////////
+// See readme.txt for more details //
+/////////////////////////////////////////////////////////////////
+// //
+// module.audio-video.asf.php //
+// module for analyzing ASF, WMA and WMV files //
+// dependencies: module.audio-video.riff.php //
+// ///
+/////////////////////////////////////////////////////////////////
+
+getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true);
+
+class getid3_asf extends getid3_handler
+{
+
+ function __construct(getID3 $getid3) {
+ parent::__construct($getid3); // extends getid3_handler::__construct()
+
+ // initialize all GUID constants
+ $GUIDarray = $this->KnownGUIDs();
+ foreach ($GUIDarray as $GUIDname => $hexstringvalue) {
+ if (!defined($GUIDname)) {
+ define($GUIDname, $this->GUIDtoBytestring($hexstringvalue));
+ }
+ }
+ }
+
+ function Analyze() {
+ $info = &$this->getid3->info;
+
+ // Shortcuts
+ $thisfile_audio = &$info['audio'];
+ $thisfile_video = &$info['video'];
+ $info['asf'] = array();
+ $thisfile_asf = &$info['asf'];
+ $thisfile_asf['comments'] = array();
+ $thisfile_asf_comments = &$thisfile_asf['comments'];
+ $thisfile_asf['header_object'] = array();
+ $thisfile_asf_headerobject = &$thisfile_asf['header_object'];
+
+
+ // ASF structure:
+ // * Header Object [required]
+ // * File Properties Object [required] (global file attributes)
+ // * Stream Properties Object [required] (defines media stream & characteristics)
+ // * Header Extension Object [required] (additional functionality)
+ // * Content Description Object (bibliographic information)
+ // * Script Command Object (commands for during playback)
+ // * Marker Object (named jumped points within the file)
+ // * Data Object [required]
+ // * Data Packets
+ // * Index Object
+
+ // Header Object: (mandatory, one only)
+ // Field Name Field Type Size (bits)
+ // Object ID GUID 128 // GUID for header object - GETID3_ASF_Header_Object
+ // Object Size QWORD 64 // size of header object, including 30 bytes of Header Object header
+ // Number of Header Objects DWORD 32 // number of objects in header object
+ // Reserved1 BYTE 8 // hardcoded: 0x01
+ // Reserved2 BYTE 8 // hardcoded: 0x02
+
+ $info['fileformat'] = 'asf';
+
+ fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
+ $HeaderObjectData = fread($this->getid3->fp, 30);
+
+ $thisfile_asf_headerobject['objectid'] = substr($HeaderObjectData, 0, 16);
+ $thisfile_asf_headerobject['objectid_guid'] = $this->BytestringToGUID($thisfile_asf_headerobject['objectid']);
+ if ($thisfile_asf_headerobject['objectid'] != GETID3_ASF_Header_Object) {
+ $info['warning'][] = 'ASF header GUID {'.$this->BytestringToGUID($thisfile_asf_headerobject['objectid']).'} does not match expected "GETID3_ASF_Header_Object" GUID {'.$this->BytestringToGUID(GETID3_ASF_Header_Object).'}';
+ unset($info['fileformat']);
+ unset($info['asf']);
+ return false;
+ break;
+ }
+ $thisfile_asf_headerobject['objectsize'] = getid3_lib::LittleEndian2Int(substr($HeaderObjectData, 16, 8));
+ $thisfile_asf_headerobject['headerobjects'] = getid3_lib::LittleEndian2Int(substr($HeaderObjectData, 24, 4));
+ $thisfile_asf_headerobject['reserved1'] = getid3_lib::LittleEndian2Int(substr($HeaderObjectData, 28, 1));
+ $thisfile_asf_headerobject['reserved2'] = getid3_lib::LittleEndian2Int(substr($HeaderObjectData, 29, 1));
+
+ $NextObjectOffset = ftell($this->getid3->fp);
+ $ASFHeaderData = fread($this->getid3->fp, $thisfile_asf_headerobject['objectsize'] - 30);
+ $offset = 0;
+
+ for ($HeaderObjectsCounter = 0; $HeaderObjectsCounter < $thisfile_asf_headerobject['headerobjects']; $HeaderObjectsCounter++) {
+ $NextObjectGUID = substr($ASFHeaderData, $offset, 16);
+ $offset += 16;
+ $NextObjectGUIDtext = $this->BytestringToGUID($NextObjectGUID);
+ $NextObjectSize = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
+ $offset += 8;
+ switch ($NextObjectGUID) {
+
+ case GETID3_ASF_File_Properties_Object:
+ // File Properties Object: (mandatory, one only)
+ // Field Name Field Type Size (bits)
+ // Object ID GUID 128 // GUID for file properties object - GETID3_ASF_File_Properties_Object
+ // Object Size QWORD 64 // size of file properties object, including 104 bytes of File Properties Object header
+ // File ID GUID 128 // unique ID - identical to File ID in Data Object
+ // File Size QWORD 64 // entire file in bytes. Invalid if Broadcast Flag == 1
+ // Creation Date QWORD 64 // date & time of file creation. Maybe invalid if Broadcast Flag == 1
+ // Data Packets Count QWORD 64 // number of data packets in Data Object. Invalid if Broadcast Flag == 1
+ // Play Duration QWORD 64 // playtime, in 100-nanosecond units. Invalid if Broadcast Flag == 1
+ // Send Duration QWORD 64 // time needed to send file, in 100-nanosecond units. Players can ignore this value. Invalid if Broadcast Flag == 1
+ // Preroll QWORD 64 // time to buffer data before starting to play file, in 1-millisecond units. If <> 0, PlayDuration and PresentationTime have been offset by this amount
+ // Flags DWORD 32 //
+ // * Broadcast Flag bits 1 (0x01) // file is currently being written, some header values are invalid
+ // * Seekable Flag bits 1 (0x02) // is file seekable
+ // * Reserved bits 30 (0xFFFFFFFC) // reserved - set to zero
+ // Minimum Data Packet Size DWORD 32 // in bytes. should be same as Maximum Data Packet Size. Invalid if Broadcast Flag == 1
+ // Maximum Data Packet Size DWORD 32 // in bytes. should be same as Minimum Data Packet Size. Invalid if Broadcast Flag == 1
+ // Maximum Bitrate DWORD 32 // maximum instantaneous bitrate in bits per second for entire file, including all data streams and ASF overhead
+
+ // shortcut
+ $thisfile_asf['file_properties_object'] = array();
+ $thisfile_asf_filepropertiesobject = &$thisfile_asf['file_properties_object'];
+
+ $thisfile_asf_filepropertiesobject['offset'] = $NextObjectOffset + $offset;
+ $thisfile_asf_filepropertiesobject['objectid'] = $NextObjectGUID;
+ $thisfile_asf_filepropertiesobject['objectid_guid'] = $NextObjectGUIDtext;
+ $thisfile_asf_filepropertiesobject['objectsize'] = $NextObjectSize;
+ $thisfile_asf_filepropertiesobject['fileid'] = substr($ASFHeaderData, $offset, 16);
+ $offset += 16;
+ $thisfile_asf_filepropertiesobject['fileid_guid'] = $this->BytestringToGUID($thisfile_asf_filepropertiesobject['fileid']);
+ $thisfile_asf_filepropertiesobject['filesize'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
+ $offset += 8;
+ $thisfile_asf_filepropertiesobject['creation_date'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
+ $thisfile_asf_filepropertiesobject['creation_date_unix'] = $this->FILETIMEtoUNIXtime($thisfile_asf_filepropertiesobject['creation_date']);
+ $offset += 8;
+ $thisfile_asf_filepropertiesobject['data_packets'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
+ $offset += 8;
+ $thisfile_asf_filepropertiesobject['play_duration'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
+ $offset += 8;
+ $thisfile_asf_filepropertiesobject['send_duration'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
+ $offset += 8;
+ $thisfile_asf_filepropertiesobject['preroll'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
+ $offset += 8;
+ $thisfile_asf_filepropertiesobject['flags_raw'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
+ $offset += 4;
+ $thisfile_asf_filepropertiesobject['flags']['broadcast'] = (bool) ($thisfile_asf_filepropertiesobject['flags_raw'] & 0x0001);
+ $thisfile_asf_filepropertiesobject['flags']['seekable'] = (bool) ($thisfile_asf_filepropertiesobject['flags_raw'] & 0x0002);
+
+ $thisfile_asf_filepropertiesobject['min_packet_size'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
+ $offset += 4;
+ $thisfile_asf_filepropertiesobject['max_packet_size'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
+ $offset += 4;
+ $thisfile_asf_filepropertiesobject['max_bitrate'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
+ $offset += 4;
+
+ if ($thisfile_asf_filepropertiesobject['flags']['broadcast']) {
+
+ // broadcast flag is set, some values invalid
+ unset($thisfile_asf_filepropertiesobject['filesize']);
+ unset($thisfile_asf_filepropertiesobject['data_packets']);
+ unset($thisfile_asf_filepropertiesobject['play_duration']);
+ unset($thisfile_asf_filepropertiesobject['send_duration']);
+ unset($thisfile_asf_filepropertiesobject['min_packet_size']);
+ unset($thisfile_asf_filepropertiesobject['max_packet_size']);
+
+ } else {
+
+ // broadcast flag NOT set, perform calculations
+ $info['playtime_seconds'] = ($thisfile_asf_filepropertiesobject['play_duration'] / 10000000) - ($thisfile_asf_filepropertiesobject['preroll'] / 1000);
+
+ //$info['bitrate'] = $thisfile_asf_filepropertiesobject['max_bitrate'];
+ $info['bitrate'] = ((isset($thisfile_asf_filepropertiesobject['filesize']) ? $thisfile_asf_filepropertiesobject['filesize'] : $info['filesize']) * 8) / $info['playtime_seconds'];
+ }
+ break;
+
+ case GETID3_ASF_Stream_Properties_Object:
+ // Stream Properties Object: (mandatory, one per media stream)
+ // Field Name Field Type Size (bits)
+ // Object ID GUID 128 // GUID for stream properties object - GETID3_ASF_Stream_Properties_Object
+ // Object Size QWORD 64 // size of stream properties object, including 78 bytes of Stream Properties Object header
+ // Stream Type GUID 128 // GETID3_ASF_Audio_Media, GETID3_ASF_Video_Media or GETID3_ASF_Command_Media
+ // Error Correction Type GUID 128 // GETID3_ASF_Audio_Spread for audio-only streams, GETID3_ASF_No_Error_Correction for other stream types
+ // Time Offset QWORD 64 // 100-nanosecond units. typically zero. added to all timestamps of samples in the stream
+ // Type-Specific Data Length DWORD 32 // number of bytes for Type-Specific Data field
+ // Error Correction Data Length DWORD 32 // number of bytes for Error Correction Data field
+ // Flags WORD 16 //
+ // * Stream Number bits 7 (0x007F) // number of this stream. 1 <= valid <= 127
+ // * Reserved bits 8 (0x7F80) // reserved - set to zero
+ // * Encrypted Content Flag bits 1 (0x8000) // stream contents encrypted if set
+ // Reserved DWORD 32 // reserved - set to zero
+ // Type-Specific Data BYTESTREAM variable // type-specific format data, depending on value of Stream Type
+ // Error Correction Data BYTESTREAM variable // error-correction-specific format data, depending on value of Error Correct Type
+
+ // There is one GETID3_ASF_Stream_Properties_Object for each stream (audio, video) but the
+ // stream number isn't known until halfway through decoding the structure, hence it
+ // it is decoded to a temporary variable and then stuck in the appropriate index later
+
+ $StreamPropertiesObjectData['offset'] = $NextObjectOffset + $offset;
+ $StreamPropertiesObjectData['objectid'] = $NextObjectGUID;
+ $StreamPropertiesObjectData['objectid_guid'] = $NextObjectGUIDtext;
+ $StreamPropertiesObjectData['objectsize'] = $NextObjectSize;
+ $StreamPropertiesObjectData['stream_type'] = substr($ASFHeaderData, $offset, 16);
+ $offset += 16;
+ $StreamPropertiesObjectData['stream_type_guid'] = $this->BytestringToGUID($StreamPropertiesObjectData['stream_type']);
+ $StreamPropertiesObjectData['error_correct_type'] = substr($ASFHeaderData, $offset, 16);
+ $offset += 16;
+ $StreamPropertiesObjectData['error_correct_guid'] = $this->BytestringToGUID($StreamPropertiesObjectData['error_correct_type']);
+ $StreamPropertiesObjectData['time_offset'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
+ $offset += 8;
+ $StreamPropertiesObjectData['type_data_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
+ $offset += 4;
+ $StreamPropertiesObjectData['error_data_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
+ $offset += 4;
+ $StreamPropertiesObjectData['flags_raw'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ $StreamPropertiesObjectStreamNumber = $StreamPropertiesObjectData['flags_raw'] & 0x007F;
+ $StreamPropertiesObjectData['flags']['encrypted'] = (bool) ($StreamPropertiesObjectData['flags_raw'] & 0x8000);
+
+ $offset += 4; // reserved - DWORD
+ $StreamPropertiesObjectData['type_specific_data'] = substr($ASFHeaderData, $offset, $StreamPropertiesObjectData['type_data_length']);
+ $offset += $StreamPropertiesObjectData['type_data_length'];
+ $StreamPropertiesObjectData['error_correct_data'] = substr($ASFHeaderData, $offset, $StreamPropertiesObjectData['error_data_length']);
+ $offset += $StreamPropertiesObjectData['error_data_length'];
+
+ switch ($StreamPropertiesObjectData['stream_type']) {
+
+ case GETID3_ASF_Audio_Media:
+ $thisfile_audio['dataformat'] = (!empty($thisfile_audio['dataformat']) ? $thisfile_audio['dataformat'] : 'asf');
+ $thisfile_audio['bitrate_mode'] = (!empty($thisfile_audio['bitrate_mode']) ? $thisfile_audio['bitrate_mode'] : 'cbr');
+
+ $audiodata = getid3_riff::RIFFparseWAVEFORMATex(substr($StreamPropertiesObjectData['type_specific_data'], 0, 16));
+ unset($audiodata['raw']);
+ $thisfile_audio = getid3_lib::array_merge_noclobber($audiodata, $thisfile_audio);
+ break;
+
+ case GETID3_ASF_Video_Media:
+ $thisfile_video['dataformat'] = (!empty($thisfile_video['dataformat']) ? $thisfile_video['dataformat'] : 'asf');
+ $thisfile_video['bitrate_mode'] = (!empty($thisfile_video['bitrate_mode']) ? $thisfile_video['bitrate_mode'] : 'cbr');
+ break;
+
+ case GETID3_ASF_Command_Media:
+ default:
+ // do nothing
+ break;
+
+ }
+
+ $thisfile_asf['stream_properties_object'][$StreamPropertiesObjectStreamNumber] = $StreamPropertiesObjectData;
+ unset($StreamPropertiesObjectData); // clear for next stream, if any
+ break;
+
+ case GETID3_ASF_Header_Extension_Object:
+ // Header Extension Object: (mandatory, one only)
+ // Field Name Field Type Size (bits)
+ // Object ID GUID 128 // GUID for Header Extension object - GETID3_ASF_Header_Extension_Object
+ // Object Size QWORD 64 // size of Header Extension object, including 46 bytes of Header Extension Object header
+ // Reserved Field 1 GUID 128 // hardcoded: GETID3_ASF_Reserved_1
+ // Reserved Field 2 WORD 16 // hardcoded: 0x00000006
+ // Header Extension Data Size DWORD 32 // in bytes. valid: 0, or > 24. equals object size minus 46
+ // Header Extension Data BYTESTREAM variable // array of zero or more extended header objects
+
+ // shortcut
+ $thisfile_asf['header_extension_object'] = array();
+ $thisfile_asf_headerextensionobject = &$thisfile_asf['header_extension_object'];
+
+ $thisfile_asf_headerextensionobject['offset'] = $NextObjectOffset + $offset;
+ $thisfile_asf_headerextensionobject['objectid'] = $NextObjectGUID;
+ $thisfile_asf_headerextensionobject['objectid_guid'] = $NextObjectGUIDtext;
+ $thisfile_asf_headerextensionobject['objectsize'] = $NextObjectSize;
+ $thisfile_asf_headerextensionobject['reserved_1'] = substr($ASFHeaderData, $offset, 16);
+ $offset += 16;
+ $thisfile_asf_headerextensionobject['reserved_1_guid'] = $this->BytestringToGUID($thisfile_asf_headerextensionobject['reserved_1']);
+ if ($thisfile_asf_headerextensionobject['reserved_1'] != GETID3_ASF_Reserved_1) {
+ $info['warning'][] = 'header_extension_object.reserved_1 GUID ('.$this->BytestringToGUID($thisfile_asf_headerextensionobject['reserved_1']).') does not match expected "GETID3_ASF_Reserved_1" GUID ('.$this->BytestringToGUID(GETID3_ASF_Reserved_1).')';
+ //return false;
+ break;
+ }
+ $thisfile_asf_headerextensionobject['reserved_2'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ if ($thisfile_asf_headerextensionobject['reserved_2'] != 6) {
+ $info['warning'][] = 'header_extension_object.reserved_2 ('.getid3_lib::PrintHexBytes($thisfile_asf_headerextensionobject['reserved_2']).') does not match expected value of "6"';
+ //return false;
+ break;
+ }
+ $thisfile_asf_headerextensionobject['extension_data_size'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
+ $offset += 4;
+ $thisfile_asf_headerextensionobject['extension_data'] = substr($ASFHeaderData, $offset, $thisfile_asf_headerextensionobject['extension_data_size']);
+ $unhandled_sections = 0;
+ $thisfile_asf_headerextensionobject['extension_data_parsed'] = $this->ASF_HeaderExtensionObjectDataParse($thisfile_asf_headerextensionobject['extension_data'], $unhandled_sections);
+ if ($unhandled_sections === 0) {
+ unset($thisfile_asf_headerextensionobject['extension_data']);
+ }
+ $offset += $thisfile_asf_headerextensionobject['extension_data_size'];
+ break;
+
+ case GETID3_ASF_Codec_List_Object:
+ // Codec List Object: (optional, one only)
+ // Field Name Field Type Size (bits)
+ // Object ID GUID 128 // GUID for Codec List object - GETID3_ASF_Codec_List_Object
+ // Object Size QWORD 64 // size of Codec List object, including 44 bytes of Codec List Object header
+ // Reserved GUID 128 // hardcoded: 86D15241-311D-11D0-A3A4-00A0C90348F6
+ // Codec Entries Count DWORD 32 // number of entries in Codec Entries array
+ // Codec Entries array of: variable //
+ // * Type WORD 16 // 0x0001 = Video Codec, 0x0002 = Audio Codec, 0xFFFF = Unknown Codec
+ // * Codec Name Length WORD 16 // number of Unicode characters stored in the Codec Name field
+ // * Codec Name WCHAR variable // array of Unicode characters - name of codec used to create the content
+ // * Codec Description Length WORD 16 // number of Unicode characters stored in the Codec Description field
+ // * Codec Description WCHAR variable // array of Unicode characters - description of format used to create the content
+ // * Codec Information Length WORD 16 // number of Unicode characters stored in the Codec Information field
+ // * Codec Information BYTESTREAM variable // opaque array of information bytes about the codec used to create the content
+
+ // shortcut
+ $thisfile_asf['codec_list_object'] = array();
+ $thisfile_asf_codeclistobject = &$thisfile_asf['codec_list_object'];
+
+ $thisfile_asf_codeclistobject['offset'] = $NextObjectOffset + $offset;
+ $thisfile_asf_codeclistobject['objectid'] = $NextObjectGUID;
+ $thisfile_asf_codeclistobject['objectid_guid'] = $NextObjectGUIDtext;
+ $thisfile_asf_codeclistobject['objectsize'] = $NextObjectSize;
+ $thisfile_asf_codeclistobject['reserved'] = substr($ASFHeaderData, $offset, 16);
+ $offset += 16;
+ $thisfile_asf_codeclistobject['reserved_guid'] = $this->BytestringToGUID($thisfile_asf_codeclistobject['reserved']);
+ if ($thisfile_asf_codeclistobject['reserved'] != $this->GUIDtoBytestring('86D15241-311D-11D0-A3A4-00A0C90348F6')) {
+ $info['warning'][] = 'codec_list_object.reserved GUID {'.$this->BytestringToGUID($thisfile_asf_codeclistobject['reserved']).'} does not match expected "GETID3_ASF_Reserved_1" GUID {86D15241-311D-11D0-A3A4-00A0C90348F6}';
+ //return false;
+ break;
+ }
+ $thisfile_asf_codeclistobject['codec_entries_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
+ $offset += 4;
+ for ($CodecEntryCounter = 0; $CodecEntryCounter < $thisfile_asf_codeclistobject['codec_entries_count']; $CodecEntryCounter++) {
+ // shortcut
+ $thisfile_asf_codeclistobject['codec_entries'][$CodecEntryCounter] = array();
+ $thisfile_asf_codeclistobject_codecentries_current = &$thisfile_asf_codeclistobject['codec_entries'][$CodecEntryCounter];
+
+ $thisfile_asf_codeclistobject_codecentries_current['type_raw'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ $thisfile_asf_codeclistobject_codecentries_current['type'] = $this->ASFCodecListObjectTypeLookup($thisfile_asf_codeclistobject_codecentries_current['type_raw']);
+
+ $CodecNameLength = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)) * 2; // 2 bytes per character
+ $offset += 2;
+ $thisfile_asf_codeclistobject_codecentries_current['name'] = substr($ASFHeaderData, $offset, $CodecNameLength);
+ $offset += $CodecNameLength;
+
+ $CodecDescriptionLength = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)) * 2; // 2 bytes per character
+ $offset += 2;
+ $thisfile_asf_codeclistobject_codecentries_current['description'] = substr($ASFHeaderData, $offset, $CodecDescriptionLength);
+ $offset += $CodecDescriptionLength;
+
+ $CodecInformationLength = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ $thisfile_asf_codeclistobject_codecentries_current['information'] = substr($ASFHeaderData, $offset, $CodecInformationLength);
+ $offset += $CodecInformationLength;
+
+ if ($thisfile_asf_codeclistobject_codecentries_current['type_raw'] == 2) { // audio codec
+
+ if (strpos($thisfile_asf_codeclistobject_codecentries_current['description'], ',') === false) {
+ $info['warning'][] = '[asf][codec_list_object][codec_entries]['.$CodecEntryCounter.'][description] expected to contain comma-seperated list of parameters: "'.$thisfile_asf_codeclistobject_codecentries_current['description'].'"';
+ } else {
+
+ list($AudioCodecBitrate, $AudioCodecFrequency, $AudioCodecChannels) = explode(',', $this->TrimConvert($thisfile_asf_codeclistobject_codecentries_current['description']));
+ $thisfile_audio['codec'] = $this->TrimConvert($thisfile_asf_codeclistobject_codecentries_current['name']);
+
+ if (!isset($thisfile_audio['bitrate']) && strstr($AudioCodecBitrate, 'kbps')) {
+ $thisfile_audio['bitrate'] = (int) (trim(str_replace('kbps', '', $AudioCodecBitrate)) * 1000);
+ }
+ //if (!isset($thisfile_video['bitrate']) && isset($thisfile_audio['bitrate']) && isset($thisfile_asf['file_properties_object']['max_bitrate']) && ($thisfile_asf_codeclistobject['codec_entries_count'] > 1)) {
+ if (empty($thisfile_video['bitrate']) && !empty($thisfile_audio['bitrate']) && !empty($info['bitrate'])) {
+ //$thisfile_video['bitrate'] = $thisfile_asf['file_properties_object']['max_bitrate'] - $thisfile_audio['bitrate'];
+ $thisfile_video['bitrate'] = $info['bitrate'] - $thisfile_audio['bitrate'];
+ }
+
+ $AudioCodecFrequency = (int) trim(str_replace('kHz', '', $AudioCodecFrequency));
+ switch ($AudioCodecFrequency) {
+ case 8:
+ case 8000:
+ $thisfile_audio['sample_rate'] = 8000;
+ break;
+
+ case 11:
+ case 11025:
+ $thisfile_audio['sample_rate'] = 11025;
+ break;
+
+ case 12:
+ case 12000:
+ $thisfile_audio['sample_rate'] = 12000;
+ break;
+
+ case 16:
+ case 16000:
+ $thisfile_audio['sample_rate'] = 16000;
+ break;
+
+ case 22:
+ case 22050:
+ $thisfile_audio['sample_rate'] = 22050;
+ break;
+
+ case 24:
+ case 24000:
+ $thisfile_audio['sample_rate'] = 24000;
+ break;
+
+ case 32:
+ case 32000:
+ $thisfile_audio['sample_rate'] = 32000;
+ break;
+
+ case 44:
+ case 441000:
+ $thisfile_audio['sample_rate'] = 44100;
+ break;
+
+ case 48:
+ case 48000:
+ $thisfile_audio['sample_rate'] = 48000;
+ break;
+
+ default:
+ $info['warning'][] = 'unknown frequency: "'.$AudioCodecFrequency.'" ('.$this->TrimConvert($thisfile_asf_codeclistobject_codecentries_current['description']).')';
+ break;
+ }
+
+ if (!isset($thisfile_audio['channels'])) {
+ if (strstr($AudioCodecChannels, 'stereo')) {
+ $thisfile_audio['channels'] = 2;
+ } elseif (strstr($AudioCodecChannels, 'mono')) {
+ $thisfile_audio['channels'] = 1;
+ }
+ }
+
+ }
+ }
+ }
+ break;
+
+ case GETID3_ASF_Script_Command_Object:
+ // Script Command Object: (optional, one only)
+ // Field Name Field Type Size (bits)
+ // Object ID GUID 128 // GUID for Script Command object - GETID3_ASF_Script_Command_Object
+ // Object Size QWORD 64 // size of Script Command object, including 44 bytes of Script Command Object header
+ // Reserved GUID 128 // hardcoded: 4B1ACBE3-100B-11D0-A39B-00A0C90348F6
+ // Commands Count WORD 16 // number of Commands structures in the Script Commands Objects
+ // Command Types Count WORD 16 // number of Command Types structures in the Script Commands Objects
+ // Command Types array of: variable //
+ // * Command Type Name Length WORD 16 // number of Unicode characters for Command Type Name
+ // * Command Type Name WCHAR variable // array of Unicode characters - name of a type of command
+ // Commands array of: variable //
+ // * Presentation Time DWORD 32 // presentation time of that command, in milliseconds
+ // * Type Index WORD 16 // type of this command, as a zero-based index into the array of Command Types of this object
+ // * Command Name Length WORD 16 // number of Unicode characters for Command Name
+ // * Command Name WCHAR variable // array of Unicode characters - name of this command
+
+ // shortcut
+ $thisfile_asf['script_command_object'] = array();
+ $thisfile_asf_scriptcommandobject = &$thisfile_asf['script_command_object'];
+
+ $thisfile_asf_scriptcommandobject['offset'] = $NextObjectOffset + $offset;
+ $thisfile_asf_scriptcommandobject['objectid'] = $NextObjectGUID;
+ $thisfile_asf_scriptcommandobject['objectid_guid'] = $NextObjectGUIDtext;
+ $thisfile_asf_scriptcommandobject['objectsize'] = $NextObjectSize;
+ $thisfile_asf_scriptcommandobject['reserved'] = substr($ASFHeaderData, $offset, 16);
+ $offset += 16;
+ $thisfile_asf_scriptcommandobject['reserved_guid'] = $this->BytestringToGUID($thisfile_asf_scriptcommandobject['reserved']);
+ if ($thisfile_asf_scriptcommandobject['reserved'] != $this->GUIDtoBytestring('4B1ACBE3-100B-11D0-A39B-00A0C90348F6')) {
+ $info['warning'][] = 'script_command_object.reserved GUID {'.$this->BytestringToGUID($thisfile_asf_scriptcommandobject['reserved']).'} does not match expected "GETID3_ASF_Reserved_1" GUID {4B1ACBE3-100B-11D0-A39B-00A0C90348F6}';
+ //return false;
+ break;
+ }
+ $thisfile_asf_scriptcommandobject['commands_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ $thisfile_asf_scriptcommandobject['command_types_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ for ($CommandTypesCounter = 0; $CommandTypesCounter < $thisfile_asf_scriptcommandobject['command_types_count']; $CommandTypesCounter++) {
+ $CommandTypeNameLength = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)) * 2; // 2 bytes per character
+ $offset += 2;
+ $thisfile_asf_scriptcommandobject['command_types'][$CommandTypesCounter]['name'] = substr($ASFHeaderData, $offset, $CommandTypeNameLength);
+ $offset += $CommandTypeNameLength;
+ }
+ for ($CommandsCounter = 0; $CommandsCounter < $thisfile_asf_scriptcommandobject['commands_count']; $CommandsCounter++) {
+ $thisfile_asf_scriptcommandobject['commands'][$CommandsCounter]['presentation_time'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
+ $offset += 4;
+ $thisfile_asf_scriptcommandobject['commands'][$CommandsCounter]['type_index'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+
+ $CommandTypeNameLength = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)) * 2; // 2 bytes per character
+ $offset += 2;
+ $thisfile_asf_scriptcommandobject['commands'][$CommandsCounter]['name'] = substr($ASFHeaderData, $offset, $CommandTypeNameLength);
+ $offset += $CommandTypeNameLength;
+ }
+ break;
+
+ case GETID3_ASF_Marker_Object:
+ // Marker Object: (optional, one only)
+ // Field Name Field Type Size (bits)
+ // Object ID GUID 128 // GUID for Marker object - GETID3_ASF_Marker_Object
+ // Object Size QWORD 64 // size of Marker object, including 48 bytes of Marker Object header
+ // Reserved GUID 128 // hardcoded: 4CFEDB20-75F6-11CF-9C0F-00A0C90349CB
+ // Markers Count DWORD 32 // number of Marker structures in Marker Object
+ // Reserved WORD 16 // hardcoded: 0x0000
+ // Name Length WORD 16 // number of bytes in the Name field
+ // Name WCHAR variable // name of the Marker Object
+ // Markers array of: variable //
+ // * Offset QWORD 64 // byte offset into Data Object
+ // * Presentation Time QWORD 64 // in 100-nanosecond units
+ // * Entry Length WORD 16 // length in bytes of (Send Time + Flags + Marker Description Length + Marker Description + Padding)
+ // * Send Time DWORD 32 // in milliseconds
+ // * Flags DWORD 32 // hardcoded: 0x00000000
+ // * Marker Description Length DWORD 32 // number of bytes in Marker Description field
+ // * Marker Description WCHAR variable // array of Unicode characters - description of marker entry
+ // * Padding BYTESTREAM variable // optional padding bytes
+
+ // shortcut
+ $thisfile_asf['marker_object'] = array();
+ $thisfile_asf_markerobject = &$thisfile_asf['marker_object'];
+
+ $thisfile_asf_markerobject['offset'] = $NextObjectOffset + $offset;
+ $thisfile_asf_markerobject['objectid'] = $NextObjectGUID;
+ $thisfile_asf_markerobject['objectid_guid'] = $NextObjectGUIDtext;
+ $thisfile_asf_markerobject['objectsize'] = $NextObjectSize;
+ $thisfile_asf_markerobject['reserved'] = substr($ASFHeaderData, $offset, 16);
+ $offset += 16;
+ $thisfile_asf_markerobject['reserved_guid'] = $this->BytestringToGUID($thisfile_asf_markerobject['reserved']);
+ if ($thisfile_asf_markerobject['reserved'] != $this->GUIDtoBytestring('4CFEDB20-75F6-11CF-9C0F-00A0C90349CB')) {
+ $info['warning'][] = 'marker_object.reserved GUID {'.$this->BytestringToGUID($thisfile_asf_markerobject['reserved_1']).'} does not match expected "GETID3_ASF_Reserved_1" GUID {4CFEDB20-75F6-11CF-9C0F-00A0C90349CB}';
+ break;
+ }
+ $thisfile_asf_markerobject['markers_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
+ $offset += 4;
+ $thisfile_asf_markerobject['reserved_2'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ if ($thisfile_asf_markerobject['reserved_2'] != 0) {
+ $info['warning'][] = 'marker_object.reserved_2 ('.getid3_lib::PrintHexBytes($thisfile_asf_markerobject['reserved_2']).') does not match expected value of "0"';
+ break;
+ }
+ $thisfile_asf_markerobject['name_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ $thisfile_asf_markerobject['name'] = substr($ASFHeaderData, $offset, $thisfile_asf_markerobject['name_length']);
+ $offset += $thisfile_asf_markerobject['name_length'];
+ for ($MarkersCounter = 0; $MarkersCounter < $thisfile_asf_markerobject['markers_count']; $MarkersCounter++) {
+ $thisfile_asf_markerobject['markers'][$MarkersCounter]['offset'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
+ $offset += 8;
+ $thisfile_asf_markerobject['markers'][$MarkersCounter]['presentation_time'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
+ $offset += 8;
+ $thisfile_asf_markerobject['markers'][$MarkersCounter]['entry_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ $thisfile_asf_markerobject['markers'][$MarkersCounter]['send_time'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
+ $offset += 4;
+ $thisfile_asf_markerobject['markers'][$MarkersCounter]['flags'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
+ $offset += 4;
+ $thisfile_asf_markerobject['markers'][$MarkersCounter]['marker_description_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
+ $offset += 4;
+ $thisfile_asf_markerobject['markers'][$MarkersCounter]['marker_description'] = substr($ASFHeaderData, $offset, $thisfile_asf_markerobject['markers'][$MarkersCounter]['marker_description_length']);
+ $offset += $thisfile_asf_markerobject['markers'][$MarkersCounter]['marker_description_length'];
+ $PaddingLength = $thisfile_asf_markerobject['markers'][$MarkersCounter]['entry_length'] - 4 - 4 - 4 - $thisfile_asf_markerobject['markers'][$MarkersCounter]['marker_description_length'];
+ if ($PaddingLength > 0) {
+ $thisfile_asf_markerobject['markers'][$MarkersCounter]['padding'] = substr($ASFHeaderData, $offset, $PaddingLength);
+ $offset += $PaddingLength;
+ }
+ }
+ break;
+
+ case GETID3_ASF_Bitrate_Mutual_Exclusion_Object:
+ // Bitrate Mutual Exclusion Object: (optional)
+ // Field Name Field Type Size (bits)
+ // Object ID GUID 128 // GUID for Bitrate Mutual Exclusion object - GETID3_ASF_Bitrate_Mutual_Exclusion_Object
+ // Object Size QWORD 64 // size of Bitrate Mutual Exclusion object, including 42 bytes of Bitrate Mutual Exclusion Object header
+ // Exlusion Type GUID 128 // nature of mutual exclusion relationship. one of: (GETID3_ASF_Mutex_Bitrate, GETID3_ASF_Mutex_Unknown)
+ // Stream Numbers Count WORD 16 // number of video streams
+ // Stream Numbers WORD variable // array of mutually exclusive video stream numbers. 1 <= valid <= 127
+
+ // shortcut
+ $thisfile_asf['bitrate_mutual_exclusion_object'] = array();
+ $thisfile_asf_bitratemutualexclusionobject = &$thisfile_asf['bitrate_mutual_exclusion_object'];
+
+ $thisfile_asf_bitratemutualexclusionobject['offset'] = $NextObjectOffset + $offset;
+ $thisfile_asf_bitratemutualexclusionobject['objectid'] = $NextObjectGUID;
+ $thisfile_asf_bitratemutualexclusionobject['objectid_guid'] = $NextObjectGUIDtext;
+ $thisfile_asf_bitratemutualexclusionobject['objectsize'] = $NextObjectSize;
+ $thisfile_asf_bitratemutualexclusionobject['reserved'] = substr($ASFHeaderData, $offset, 16);
+ $thisfile_asf_bitratemutualexclusionobject['reserved_guid'] = $this->BytestringToGUID($thisfile_asf_bitratemutualexclusionobject['reserved']);
+ $offset += 16;
+ if (($thisfile_asf_bitratemutualexclusionobject['reserved'] != GETID3_ASF_Mutex_Bitrate) && ($thisfile_asf_bitratemutualexclusionobject['reserved'] != GETID3_ASF_Mutex_Unknown)) {
+ $info['warning'][] = 'bitrate_mutual_exclusion_object.reserved GUID {'.$this->BytestringToGUID($thisfile_asf_bitratemutualexclusionobject['reserved']).'} does not match expected "GETID3_ASF_Mutex_Bitrate" GUID {'.$this->BytestringToGUID(GETID3_ASF_Mutex_Bitrate).'} or "GETID3_ASF_Mutex_Unknown" GUID {'.$this->BytestringToGUID(GETID3_ASF_Mutex_Unknown).'}';
+ //return false;
+ break;
+ }
+ $thisfile_asf_bitratemutualexclusionobject['stream_numbers_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ for ($StreamNumberCounter = 0; $StreamNumberCounter < $thisfile_asf_bitratemutualexclusionobject['stream_numbers_count']; $StreamNumberCounter++) {
+ $thisfile_asf_bitratemutualexclusionobject['stream_numbers'][$StreamNumberCounter] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ }
+ break;
+
+ case GETID3_ASF_Error_Correction_Object:
+ // Error Correction Object: (optional, one only)
+ // Field Name Field Type Size (bits)
+ // Object ID GUID 128 // GUID for Error Correction object - GETID3_ASF_Error_Correction_Object
+ // Object Size QWORD 64 // size of Error Correction object, including 44 bytes of Error Correction Object header
+ // Error Correction Type GUID 128 // type of error correction. one of: (GETID3_ASF_No_Error_Correction, GETID3_ASF_Audio_Spread)
+ // Error Correction Data Length DWORD 32 // number of bytes in Error Correction Data field
+ // Error Correction Data BYTESTREAM variable // structure depends on value of Error Correction Type field
+
+ // shortcut
+ $thisfile_asf['error_correction_object'] = array();
+ $thisfile_asf_errorcorrectionobject = &$thisfile_asf['error_correction_object'];
+
+ $thisfile_asf_errorcorrectionobject['offset'] = $NextObjectOffset + $offset;
+ $thisfile_asf_errorcorrectionobject['objectid'] = $NextObjectGUID;
+ $thisfile_asf_errorcorrectionobject['objectid_guid'] = $NextObjectGUIDtext;
+ $thisfile_asf_errorcorrectionobject['objectsize'] = $NextObjectSize;
+ $thisfile_asf_errorcorrectionobject['error_correction_type'] = substr($ASFHeaderData, $offset, 16);
+ $offset += 16;
+ $thisfile_asf_errorcorrectionobject['error_correction_guid'] = $this->BytestringToGUID($thisfile_asf_errorcorrectionobject['error_correction_type']);
+ $thisfile_asf_errorcorrectionobject['error_correction_data_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
+ $offset += 4;
+ switch ($thisfile_asf_errorcorrectionobject['error_correction_type']) {
+ case GETID3_ASF_No_Error_Correction:
+ // should be no data, but just in case there is, skip to the end of the field
+ $offset += $thisfile_asf_errorcorrectionobject['error_correction_data_length'];
+ break;
+
+ case GETID3_ASF_Audio_Spread:
+ // Field Name Field Type Size (bits)
+ // Span BYTE 8 // number of packets over which audio will be spread.
+ // Virtual Packet Length WORD 16 // size of largest audio payload found in audio stream
+ // Virtual Chunk Length WORD 16 // size of largest audio payload found in audio stream
+ // Silence Data Length WORD 16 // number of bytes in Silence Data field
+ // Silence Data BYTESTREAM variable // hardcoded: 0x00 * (Silence Data Length) bytes
+
+ $thisfile_asf_errorcorrectionobject['span'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 1));
+ $offset += 1;
+ $thisfile_asf_errorcorrectionobject['virtual_packet_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ $thisfile_asf_errorcorrectionobject['virtual_chunk_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ $thisfile_asf_errorcorrectionobject['silence_data_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ $thisfile_asf_errorcorrectionobject['silence_data'] = substr($ASFHeaderData, $offset, $thisfile_asf_errorcorrectionobject['silence_data_length']);
+ $offset += $thisfile_asf_errorcorrectionobject['silence_data_length'];
+ break;
+
+ default:
+ $info['warning'][] = 'error_correction_object.error_correction_type GUID {'.$this->BytestringToGUID($thisfile_asf_errorcorrectionobject['reserved']).'} does not match expected "GETID3_ASF_No_Error_Correction" GUID {'.$this->BytestringToGUID(GETID3_ASF_No_Error_Correction).'} or "GETID3_ASF_Audio_Spread" GUID {'.$this->BytestringToGUID(GETID3_ASF_Audio_Spread).'}';
+ //return false;
+ break;
+ }
+
+ break;
+
+ case GETID3_ASF_Content_Description_Object:
+ // Content Description Object: (optional, one only)
+ // Field Name Field Type Size (bits)
+ // Object ID GUID 128 // GUID for Content Description object - GETID3_ASF_Content_Description_Object
+ // Object Size QWORD 64 // size of Content Description object, including 34 bytes of Content Description Object header
+ // Title Length WORD 16 // number of bytes in Title field
+ // Author Length WORD 16 // number of bytes in Author field
+ // Copyright Length WORD 16 // number of bytes in Copyright field
+ // Description Length WORD 16 // number of bytes in Description field
+ // Rating Length WORD 16 // number of bytes in Rating field
+ // Title WCHAR 16 // array of Unicode characters - Title
+ // Author WCHAR 16 // array of Unicode characters - Author
+ // Copyright WCHAR 16 // array of Unicode characters - Copyright
+ // Description WCHAR 16 // array of Unicode characters - Description
+ // Rating WCHAR 16 // array of Unicode characters - Rating
+
+ // shortcut
+ $thisfile_asf['content_description_object'] = array();
+ $thisfile_asf_contentdescriptionobject = &$thisfile_asf['content_description_object'];
+
+ $thisfile_asf_contentdescriptionobject['offset'] = $NextObjectOffset + $offset;
+ $thisfile_asf_contentdescriptionobject['objectid'] = $NextObjectGUID;
+ $thisfile_asf_contentdescriptionobject['objectid_guid'] = $NextObjectGUIDtext;
+ $thisfile_asf_contentdescriptionobject['objectsize'] = $NextObjectSize;
+ $thisfile_asf_contentdescriptionobject['title_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ $thisfile_asf_contentdescriptionobject['author_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ $thisfile_asf_contentdescriptionobject['copyright_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ $thisfile_asf_contentdescriptionobject['description_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ $thisfile_asf_contentdescriptionobject['rating_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ $thisfile_asf_contentdescriptionobject['title'] = substr($ASFHeaderData, $offset, $thisfile_asf_contentdescriptionobject['title_length']);
+ $offset += $thisfile_asf_contentdescriptionobject['title_length'];
+ $thisfile_asf_contentdescriptionobject['author'] = substr($ASFHeaderData, $offset, $thisfile_asf_contentdescriptionobject['author_length']);
+ $offset += $thisfile_asf_contentdescriptionobject['author_length'];
+ $thisfile_asf_contentdescriptionobject['copyright'] = substr($ASFHeaderData, $offset, $thisfile_asf_contentdescriptionobject['copyright_length']);
+ $offset += $thisfile_asf_contentdescriptionobject['copyright_length'];
+ $thisfile_asf_contentdescriptionobject['description'] = substr($ASFHeaderData, $offset, $thisfile_asf_contentdescriptionobject['description_length']);
+ $offset += $thisfile_asf_contentdescriptionobject['description_length'];
+ $thisfile_asf_contentdescriptionobject['rating'] = substr($ASFHeaderData, $offset, $thisfile_asf_contentdescriptionobject['rating_length']);
+ $offset += $thisfile_asf_contentdescriptionobject['rating_length'];
+
+ $ASFcommentKeysToCopy = array('title'=>'title', 'author'=>'artist', 'copyright'=>'copyright', 'description'=>'comment', 'rating'=>'rating');
+ foreach ($ASFcommentKeysToCopy as $keytocopyfrom => $keytocopyto) {
+ if (!empty($thisfile_asf_contentdescriptionobject[$keytocopyfrom])) {
+ $thisfile_asf_comments[$keytocopyto][] = $this->TrimTerm($thisfile_asf_contentdescriptionobject[$keytocopyfrom]);
+ }
+ }
+ break;
+
+ case GETID3_ASF_Extended_Content_Description_Object:
+ // Extended Content Description Object: (optional, one only)
+ // Field Name Field Type Size (bits)
+ // Object ID GUID 128 // GUID for Extended Content Description object - GETID3_ASF_Extended_Content_Description_Object
+ // Object Size QWORD 64 // size of ExtendedContent Description object, including 26 bytes of Extended Content Description Object header
+ // Content Descriptors Count WORD 16 // number of entries in Content Descriptors list
+ // Content Descriptors array of: variable //
+ // * Descriptor Name Length WORD 16 // size in bytes of Descriptor Name field
+ // * Descriptor Name WCHAR variable // array of Unicode characters - Descriptor Name
+ // * Descriptor Value Data Type WORD 16 // Lookup array:
+ // 0x0000 = Unicode String (variable length)
+ // 0x0001 = BYTE array (variable length)
+ // 0x0002 = BOOL (DWORD, 32 bits)
+ // 0x0003 = DWORD (DWORD, 32 bits)
+ // 0x0004 = QWORD (QWORD, 64 bits)
+ // 0x0005 = WORD (WORD, 16 bits)
+ // * Descriptor Value Length WORD 16 // number of bytes stored in Descriptor Value field
+ // * Descriptor Value variable variable // value for Content Descriptor
+
+ // shortcut
+ $thisfile_asf['extended_content_description_object'] = array();
+ $thisfile_asf_extendedcontentdescriptionobject = &$thisfile_asf['extended_content_description_object'];
+
+ $thisfile_asf_extendedcontentdescriptionobject['offset'] = $NextObjectOffset + $offset;
+ $thisfile_asf_extendedcontentdescriptionobject['objectid'] = $NextObjectGUID;
+ $thisfile_asf_extendedcontentdescriptionobject['objectid_guid'] = $NextObjectGUIDtext;
+ $thisfile_asf_extendedcontentdescriptionobject['objectsize'] = $NextObjectSize;
+ $thisfile_asf_extendedcontentdescriptionobject['content_descriptors_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ for ($ExtendedContentDescriptorsCounter = 0; $ExtendedContentDescriptorsCounter < $thisfile_asf_extendedcontentdescriptionobject['content_descriptors_count']; $ExtendedContentDescriptorsCounter++) {
+ // shortcut
+ $thisfile_asf_extendedcontentdescriptionobject['content_descriptors'][$ExtendedContentDescriptorsCounter] = array();
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current = &$thisfile_asf_extendedcontentdescriptionobject['content_descriptors'][$ExtendedContentDescriptorsCounter];
+
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['base_offset'] = $offset + 30;
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name'] = substr($ASFHeaderData, $offset, $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name_length']);
+ $offset += $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name_length'];
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_type'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'] = substr($ASFHeaderData, $offset, $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_length']);
+ $offset += $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_length'];
+ switch ($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_type']) {
+ case 0x0000: // Unicode string
+ break;
+
+ case 0x0001: // BYTE array
+ // do nothing
+ break;
+
+ case 0x0002: // BOOL
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'] = (bool) getid3_lib::LittleEndian2Int($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']);
+ break;
+
+ case 0x0003: // DWORD
+ case 0x0004: // QWORD
+ case 0x0005: // WORD
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'] = getid3_lib::LittleEndian2Int($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']);
+ break;
+
+ default:
+ $info['warning'][] = 'extended_content_description.content_descriptors.'.$ExtendedContentDescriptorsCounter.'.value_type is invalid ('.$thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_type'].')';
+ //return false;
+ break;
+ }
+ switch ($this->TrimConvert(strtolower($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name']))) {
+
+ case 'wm/albumartist':
+ case 'artist':
+ // Note: not 'artist', that comes from 'author' tag
+ $thisfile_asf_comments['albumartist'] = array($this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']));
+ break;
+
+ case 'wm/albumtitle':
+ case 'album':
+ $thisfile_asf_comments['album'] = array($this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']));
+ break;
+
+ case 'wm/genre':
+ case 'genre':
+ $thisfile_asf_comments['genre'] = array($this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']));
+ break;
+
+ case 'wm/partofset':
+ $thisfile_asf_comments['partofset'] = array($this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']));
+ break;
+
+ case 'wm/tracknumber':
+ case 'tracknumber':
+ // be careful casting to int: casting unicode strings to int gives unexpected results (stops parsing at first non-numeric character)
+ $thisfile_asf_comments['track'] = array($this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']));
+ foreach ($thisfile_asf_comments['track'] as $key => $value) {
+ if (preg_match('/^[0-9\x00]+$/', $value)) {
+ $thisfile_asf_comments['track'][$key] = intval(str_replace("\x00", '', $value));
+ }
+ }
+ break;
+
+ case 'wm/track':
+ if (empty($thisfile_asf_comments['track'])) {
+ $thisfile_asf_comments['track'] = array(1 + $this->TrimConvert($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']));
+ }
+ break;
+
+ case 'wm/year':
+ case 'year':
+ case 'date':
+ $thisfile_asf_comments['year'] = array( $this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']));
+ break;
+
+ case 'wm/lyrics':
+ case 'lyrics':
+ $thisfile_asf_comments['lyrics'] = array($this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']));
+ break;
+
+ case 'isvbr':
+ if ($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']) {
+ $thisfile_audio['bitrate_mode'] = 'vbr';
+ $thisfile_video['bitrate_mode'] = 'vbr';
+ }
+ break;
+
+ case 'id3':
+ // id3v2 module might not be loaded
+ if (class_exists('getid3_id3v2')) {
+ $tempfile = tempnam(GETID3_TEMP_DIR, 'getID3');
+ $tempfilehandle = fopen($tempfile, 'wb');
+ $tempThisfileInfo = array('encoding'=>$info['encoding']);
+ fwrite($tempfilehandle, $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']);
+ fclose($tempfilehandle);
+
+ $getid3_temp = new getID3();
+ $getid3_temp->openfile($tempfile);
+ $getid3_id3v2 = new getid3_id3v2($getid3_temp);
+ $getid3_id3v2->Analyze();
+ $info['id3v2'] = $getid3_temp->info['id3v2'];
+ unset($getid3_temp, $getid3_id3v2);
+
+ unlink($tempfile);
+ }
+ break;
+
+ case 'wm/encodingtime':
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['encoding_time_unix'] = $this->FILETIMEtoUNIXtime($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']);
+ $thisfile_asf_comments['encoding_time_unix'] = array($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['encoding_time_unix']);
+ break;
+
+ case 'wm/picture':
+ $WMpicture = $this->ASF_WMpicture($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']);
+ foreach ($WMpicture as $key => $value) {
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current[$key] = $value;
+ }
+ unset($WMpicture);
+/*
+ $wm_picture_offset = 0;
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_type_id'] = getid3_lib::LittleEndian2Int(substr($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'], $wm_picture_offset, 1));
+ $wm_picture_offset += 1;
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_type'] = $this->WMpictureTypeLookup($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_type_id']);
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_size'] = getid3_lib::LittleEndian2Int(substr($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'], $wm_picture_offset, 4));
+ $wm_picture_offset += 4;
+
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_mime'] = '';
+ do {
+ $next_byte_pair = substr($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'], $wm_picture_offset, 2);
+ $wm_picture_offset += 2;
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_mime'] .= $next_byte_pair;
+ } while ($next_byte_pair !== "\x00\x00");
+
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_description'] = '';
+ do {
+ $next_byte_pair = substr($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'], $wm_picture_offset, 2);
+ $wm_picture_offset += 2;
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_description'] .= $next_byte_pair;
+ } while ($next_byte_pair !== "\x00\x00");
+
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['dataoffset'] = $wm_picture_offset;
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['data'] = substr($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'], $wm_picture_offset);
+ unset($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']);
+
+ $imageinfo = array();
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_mime'] = '';
+ $imagechunkcheck = getid3_lib::GetDataImageSize($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['data'], $imageinfo);
+ unset($imageinfo);
+ if (!empty($imagechunkcheck)) {
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_mime'] = image_type_to_mime_type($imagechunkcheck[2]);
+ }
+ if (!isset($thisfile_asf_comments['picture'])) {
+ $thisfile_asf_comments['picture'] = array();
+ }
+ $thisfile_asf_comments['picture'][] = array('data'=>$thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['data'], 'image_mime'=>$thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_mime']);
+*/
+ break;
+
+ default:
+ switch ($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_type']) {
+ case 0: // Unicode string
+ if (substr($this->TrimConvert($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name']), 0, 3) == 'WM/') {
+ $thisfile_asf_comments[str_replace('wm/', '', strtolower($this->TrimConvert($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name'])))] = array($this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']));
+ }
+ break;
+
+ case 1:
+ break;
+ }
+ break;
+ }
+
+ }
+ break;
+
+ case GETID3_ASF_Stream_Bitrate_Properties_Object:
+ // Stream Bitrate Properties Object: (optional, one only)
+ // Field Name Field Type Size (bits)
+ // Object ID GUID 128 // GUID for Stream Bitrate Properties object - GETID3_ASF_Stream_Bitrate_Properties_Object
+ // Object Size QWORD 64 // size of Extended Content Description object, including 26 bytes of Stream Bitrate Properties Object header
+ // Bitrate Records Count WORD 16 // number of records in Bitrate Records
+ // Bitrate Records array of: variable //
+ // * Flags WORD 16 //
+ // * * Stream Number bits 7 (0x007F) // number of this stream
+ // * * Reserved bits 9 (0xFF80) // hardcoded: 0
+ // * Average Bitrate DWORD 32 // in bits per second
+
+ // shortcut
+ $thisfile_asf['stream_bitrate_properties_object'] = array();
+ $thisfile_asf_streambitratepropertiesobject = &$thisfile_asf['stream_bitrate_properties_object'];
+
+ $thisfile_asf_streambitratepropertiesobject['offset'] = $NextObjectOffset + $offset;
+ $thisfile_asf_streambitratepropertiesobject['objectid'] = $NextObjectGUID;
+ $thisfile_asf_streambitratepropertiesobject['objectid_guid'] = $NextObjectGUIDtext;
+ $thisfile_asf_streambitratepropertiesobject['objectsize'] = $NextObjectSize;
+ $thisfile_asf_streambitratepropertiesobject['bitrate_records_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ for ($BitrateRecordsCounter = 0; $BitrateRecordsCounter < $thisfile_asf_streambitratepropertiesobject['bitrate_records_count']; $BitrateRecordsCounter++) {
+ $thisfile_asf_streambitratepropertiesobject['bitrate_records'][$BitrateRecordsCounter]['flags_raw'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ $thisfile_asf_streambitratepropertiesobject['bitrate_records'][$BitrateRecordsCounter]['flags']['stream_number'] = $thisfile_asf_streambitratepropertiesobject['bitrate_records'][$BitrateRecordsCounter]['flags_raw'] & 0x007F;
+ $thisfile_asf_streambitratepropertiesobject['bitrate_records'][$BitrateRecordsCounter]['bitrate'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
+ $offset += 4;
+ }
+ break;
+
+ case GETID3_ASF_Padding_Object:
+ // Padding Object: (optional)
+ // Field Name Field Type Size (bits)
+ // Object ID GUID 128 // GUID for Padding object - GETID3_ASF_Padding_Object
+ // Object Size QWORD 64 // size of Padding object, including 24 bytes of ASF Padding Object header
+ // Padding Data BYTESTREAM variable // ignore
+
+ // shortcut
+ $thisfile_asf['padding_object'] = array();
+ $thisfile_asf_paddingobject = &$thisfile_asf['padding_object'];
+
+ $thisfile_asf_paddingobject['offset'] = $NextObjectOffset + $offset;
+ $thisfile_asf_paddingobject['objectid'] = $NextObjectGUID;
+ $thisfile_asf_paddingobject['objectid_guid'] = $NextObjectGUIDtext;
+ $thisfile_asf_paddingobject['objectsize'] = $NextObjectSize;
+ $thisfile_asf_paddingobject['padding_length'] = $thisfile_asf_paddingobject['objectsize'] - 16 - 8;
+ $thisfile_asf_paddingobject['padding'] = substr($ASFHeaderData, $offset, $thisfile_asf_paddingobject['padding_length']);
+ $offset += ($NextObjectSize - 16 - 8);
+ break;
+
+ case GETID3_ASF_Extended_Content_Encryption_Object:
+ case GETID3_ASF_Content_Encryption_Object:
+ // WMA DRM - just ignore
+ $offset += ($NextObjectSize - 16 - 8);
+ break;
+
+ default:
+ // Implementations shall ignore any standard or non-standard object that they do not know how to handle.
+ if ($this->GUIDname($NextObjectGUIDtext)) {
+ $info['warning'][] = 'unhandled GUID "'.$this->GUIDname($NextObjectGUIDtext).'" {'.$NextObjectGUIDtext.'} in ASF header at offset '.($offset - 16 - 8);
+ } else {
+ $info['warning'][] = 'unknown GUID {'.$NextObjectGUIDtext.'} in ASF header at offset '.($offset - 16 - 8);
+ }
+ $offset += ($NextObjectSize - 16 - 8);
+ break;
+ }
+ }
+ if (isset($thisfile_asf_streambitrateproperties['bitrate_records_count'])) {
+ $ASFbitrateAudio = 0;
+ $ASFbitrateVideo = 0;
+ for ($BitrateRecordsCounter = 0; $BitrateRecordsCounter < $thisfile_asf_streambitrateproperties['bitrate_records_count']; $BitrateRecordsCounter++) {
+ if (isset($thisfile_asf_codeclistobject['codec_entries'][$BitrateRecordsCounter])) {
+ switch ($thisfile_asf_codeclistobject['codec_entries'][$BitrateRecordsCounter]['type_raw']) {
+ case 1:
+ $ASFbitrateVideo += $thisfile_asf_streambitrateproperties['bitrate_records'][$BitrateRecordsCounter]['bitrate'];
+ break;
+
+ case 2:
+ $ASFbitrateAudio += $thisfile_asf_streambitrateproperties['bitrate_records'][$BitrateRecordsCounter]['bitrate'];
+ break;
+
+ default:
+ // do nothing
+ break;
+ }
+ }
+ }
+ if ($ASFbitrateAudio > 0) {
+ $thisfile_audio['bitrate'] = $ASFbitrateAudio;
+ }
+ if ($ASFbitrateVideo > 0) {
+ $thisfile_video['bitrate'] = $ASFbitrateVideo;
+ }
+ }
+ if (isset($thisfile_asf['stream_properties_object']) && is_array($thisfile_asf['stream_properties_object'])) {
+
+ $thisfile_audio['bitrate'] = 0;
+ $thisfile_video['bitrate'] = 0;
+
+ foreach ($thisfile_asf['stream_properties_object'] as $streamnumber => $streamdata) {
+
+ switch ($streamdata['stream_type']) {
+ case GETID3_ASF_Audio_Media:
+ // Field Name Field Type Size (bits)
+ // Codec ID / Format Tag WORD 16 // unique ID of audio codec - defined as wFormatTag field of WAVEFORMATEX structure
+ // Number of Channels WORD 16 // number of channels of audio - defined as nChannels field of WAVEFORMATEX structure
+ // Samples Per Second DWORD 32 // in Hertz - defined as nSamplesPerSec field of WAVEFORMATEX structure
+ // Average number of Bytes/sec DWORD 32 // bytes/sec of audio stream - defined as nAvgBytesPerSec field of WAVEFORMATEX structure
+ // Block Alignment WORD 16 // block size in bytes of audio codec - defined as nBlockAlign field of WAVEFORMATEX structure
+ // Bits per sample WORD 16 // bits per sample of mono data. set to zero for variable bitrate codecs. defined as wBitsPerSample field of WAVEFORMATEX structure
+ // Codec Specific Data Size WORD 16 // size in bytes of Codec Specific Data buffer - defined as cbSize field of WAVEFORMATEX structure
+ // Codec Specific Data BYTESTREAM variable // array of codec-specific data bytes
+
+ // shortcut
+ $thisfile_asf['audio_media'][$streamnumber] = array();
+ $thisfile_asf_audiomedia_currentstream = &$thisfile_asf['audio_media'][$streamnumber];
+
+ $audiomediaoffset = 0;
+
+ $thisfile_asf_audiomedia_currentstream = getid3_riff::RIFFparseWAVEFORMATex(substr($streamdata['type_specific_data'], $audiomediaoffset, 16));
+ $audiomediaoffset += 16;
+
+ $thisfile_audio['lossless'] = false;
+ switch ($thisfile_asf_audiomedia_currentstream['raw']['wFormatTag']) {
+ case 0x0001: // PCM
+ case 0x0163: // WMA9 Lossless
+ $thisfile_audio['lossless'] = true;
+ break;
+ }
+
+ if (!empty($thisfile_asf['stream_bitrate_properties_object']['bitrate_records'])) {
+ foreach ($thisfile_asf['stream_bitrate_properties_object']['bitrate_records'] as $dummy => $dataarray) {
+ if (isset($dataarray['flags']['stream_number']) && ($dataarray['flags']['stream_number'] == $streamnumber)) {
+ $thisfile_asf_audiomedia_currentstream['bitrate'] = $dataarray['bitrate'];
+ $thisfile_audio['bitrate'] += $dataarray['bitrate'];
+ break;
+ }
+ }
+ } else {
+ if (!empty($thisfile_asf_audiomedia_currentstream['bytes_sec'])) {
+ $thisfile_audio['bitrate'] += $thisfile_asf_audiomedia_currentstream['bytes_sec'] * 8;
+ } elseif (!empty($thisfile_asf_audiomedia_currentstream['bitrate'])) {
+ $thisfile_audio['bitrate'] += $thisfile_asf_audiomedia_currentstream['bitrate'];
+ }
+ }
+ $thisfile_audio['streams'][$streamnumber] = $thisfile_asf_audiomedia_currentstream;
+ $thisfile_audio['streams'][$streamnumber]['wformattag'] = $thisfile_asf_audiomedia_currentstream['raw']['wFormatTag'];
+ $thisfile_audio['streams'][$streamnumber]['lossless'] = $thisfile_audio['lossless'];
+ $thisfile_audio['streams'][$streamnumber]['bitrate'] = $thisfile_audio['bitrate'];
+ $thisfile_audio['streams'][$streamnumber]['dataformat'] = 'wma';
+ unset($thisfile_audio['streams'][$streamnumber]['raw']);
+
+ $thisfile_asf_audiomedia_currentstream['codec_data_size'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $audiomediaoffset, 2));
+ $audiomediaoffset += 2;
+ $thisfile_asf_audiomedia_currentstream['codec_data'] = substr($streamdata['type_specific_data'], $audiomediaoffset, $thisfile_asf_audiomedia_currentstream['codec_data_size']);
+ $audiomediaoffset += $thisfile_asf_audiomedia_currentstream['codec_data_size'];
+
+ break;
+
+ case GETID3_ASF_Video_Media:
+ // Field Name Field Type Size (bits)
+ // Encoded Image Width DWORD 32 // width of image in pixels
+ // Encoded Image Height DWORD 32 // height of image in pixels
+ // Reserved Flags BYTE 8 // hardcoded: 0x02
+ // Format Data Size WORD 16 // size of Format Data field in bytes
+ // Format Data array of: variable //
+ // * Format Data Size DWORD 32 // number of bytes in Format Data field, in bytes - defined as biSize field of BITMAPINFOHEADER structure
+ // * Image Width LONG 32 // width of encoded image in pixels - defined as biWidth field of BITMAPINFOHEADER structure
+ // * Image Height LONG 32 // height of encoded image in pixels - defined as biHeight field of BITMAPINFOHEADER structure
+ // * Reserved WORD 16 // hardcoded: 0x0001 - defined as biPlanes field of BITMAPINFOHEADER structure
+ // * Bits Per Pixel Count WORD 16 // bits per pixel - defined as biBitCount field of BITMAPINFOHEADER structure
+ // * Compression ID FOURCC 32 // fourcc of video codec - defined as biCompression field of BITMAPINFOHEADER structure
+ // * Image Size DWORD 32 // image size in bytes - defined as biSizeImage field of BITMAPINFOHEADER structure
+ // * Horizontal Pixels / Meter DWORD 32 // horizontal resolution of target device in pixels per meter - defined as biXPelsPerMeter field of BITMAPINFOHEADER structure
+ // * Vertical Pixels / Meter DWORD 32 // vertical resolution of target device in pixels per meter - defined as biYPelsPerMeter field of BITMAPINFOHEADER structure
+ // * Colors Used Count DWORD 32 // number of color indexes in the color table that are actually used - defined as biClrUsed field of BITMAPINFOHEADER structure
+ // * Important Colors Count DWORD 32 // number of color index required for displaying bitmap. if zero, all colors are required. defined as biClrImportant field of BITMAPINFOHEADER structure
+ // * Codec Specific Data BYTESTREAM variable // array of codec-specific data bytes
+
+ // shortcut
+ $thisfile_asf['video_media'][$streamnumber] = array();
+ $thisfile_asf_videomedia_currentstream = &$thisfile_asf['video_media'][$streamnumber];
+
+ $videomediaoffset = 0;
+ $thisfile_asf_videomedia_currentstream['image_width'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
+ $videomediaoffset += 4;
+ $thisfile_asf_videomedia_currentstream['image_height'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
+ $videomediaoffset += 4;
+ $thisfile_asf_videomedia_currentstream['flags'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 1));
+ $videomediaoffset += 1;
+ $thisfile_asf_videomedia_currentstream['format_data_size'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 2));
+ $videomediaoffset += 2;
+ $thisfile_asf_videomedia_currentstream['format_data']['format_data_size'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
+ $videomediaoffset += 4;
+ $thisfile_asf_videomedia_currentstream['format_data']['image_width'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
+ $videomediaoffset += 4;
+ $thisfile_asf_videomedia_currentstream['format_data']['image_height'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
+ $videomediaoffset += 4;
+ $thisfile_asf_videomedia_currentstream['format_data']['reserved'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 2));
+ $videomediaoffset += 2;
+ $thisfile_asf_videomedia_currentstream['format_data']['bits_per_pixel'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 2));
+ $videomediaoffset += 2;
+ $thisfile_asf_videomedia_currentstream['format_data']['codec_fourcc'] = substr($streamdata['type_specific_data'], $videomediaoffset, 4);
+ $videomediaoffset += 4;
+ $thisfile_asf_videomedia_currentstream['format_data']['image_size'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
+ $videomediaoffset += 4;
+ $thisfile_asf_videomedia_currentstream['format_data']['horizontal_pels'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
+ $videomediaoffset += 4;
+ $thisfile_asf_videomedia_currentstream['format_data']['vertical_pels'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
+ $videomediaoffset += 4;
+ $thisfile_asf_videomedia_currentstream['format_data']['colors_used'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
+ $videomediaoffset += 4;
+ $thisfile_asf_videomedia_currentstream['format_data']['colors_important'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
+ $videomediaoffset += 4;
+ $thisfile_asf_videomedia_currentstream['format_data']['codec_data'] = substr($streamdata['type_specific_data'], $videomediaoffset);
+
+ if (!empty($thisfile_asf['stream_bitrate_properties_object']['bitrate_records'])) {
+ foreach ($thisfile_asf['stream_bitrate_properties_object']['bitrate_records'] as $dummy => $dataarray) {
+ if (isset($dataarray['flags']['stream_number']) && ($dataarray['flags']['stream_number'] == $streamnumber)) {
+ $thisfile_asf_videomedia_currentstream['bitrate'] = $dataarray['bitrate'];
+ $thisfile_video['streams'][$streamnumber]['bitrate'] = $dataarray['bitrate'];
+ $thisfile_video['bitrate'] += $dataarray['bitrate'];
+ break;
+ }
+ }
+ }
+
+ $thisfile_asf_videomedia_currentstream['format_data']['codec'] = getid3_riff::RIFFfourccLookup($thisfile_asf_videomedia_currentstream['format_data']['codec_fourcc']);
+
+ $thisfile_video['streams'][$streamnumber]['fourcc'] = $thisfile_asf_videomedia_currentstream['format_data']['codec_fourcc'];
+ $thisfile_video['streams'][$streamnumber]['codec'] = $thisfile_asf_videomedia_currentstream['format_data']['codec'];
+ $thisfile_video['streams'][$streamnumber]['resolution_x'] = $thisfile_asf_videomedia_currentstream['image_width'];
+ $thisfile_video['streams'][$streamnumber]['resolution_y'] = $thisfile_asf_videomedia_currentstream['image_height'];
+ $thisfile_video['streams'][$streamnumber]['bits_per_sample'] = $thisfile_asf_videomedia_currentstream['format_data']['bits_per_pixel'];
+ break;
+
+ default:
+ break;
+ }
+ }
+ }
+
+ while (ftell($this->getid3->fp) < $info['avdataend']) {
+ $NextObjectDataHeader = fread($this->getid3->fp, 24);
+ $offset = 0;
+ $NextObjectGUID = substr($NextObjectDataHeader, 0, 16);
+ $offset += 16;
+ $NextObjectGUIDtext = $this->BytestringToGUID($NextObjectGUID);
+ $NextObjectSize = getid3_lib::LittleEndian2Int(substr($NextObjectDataHeader, $offset, 8));
+ $offset += 8;
+
+ switch ($NextObjectGUID) {
+ case GETID3_ASF_Data_Object:
+ // Data Object: (mandatory, one only)
+ // Field Name Field Type Size (bits)
+ // Object ID GUID 128 // GUID for Data object - GETID3_ASF_Data_Object
+ // Object Size QWORD 64 // size of Data object, including 50 bytes of Data Object header. may be 0 if FilePropertiesObject.BroadcastFlag == 1
+ // File ID GUID 128 // unique identifier. identical to File ID field in Header Object
+ // Total Data Packets QWORD 64 // number of Data Packet entries in Data Object. invalid if FilePropertiesObject.BroadcastFlag == 1
+ // Reserved WORD 16 // hardcoded: 0x0101
+
+ // shortcut
+ $thisfile_asf['data_object'] = array();
+ $thisfile_asf_dataobject = &$thisfile_asf['data_object'];
+
+ $DataObjectData = $NextObjectDataHeader.fread($this->getid3->fp, 50 - 24);
+ $offset = 24;
+
+ $thisfile_asf_dataobject['objectid'] = $NextObjectGUID;
+ $thisfile_asf_dataobject['objectid_guid'] = $NextObjectGUIDtext;
+ $thisfile_asf_dataobject['objectsize'] = $NextObjectSize;
+
+ $thisfile_asf_dataobject['fileid'] = substr($DataObjectData, $offset, 16);
+ $offset += 16;
+ $thisfile_asf_dataobject['fileid_guid'] = $this->BytestringToGUID($thisfile_asf_dataobject['fileid']);
+ $thisfile_asf_dataobject['total_data_packets'] = getid3_lib::LittleEndian2Int(substr($DataObjectData, $offset, 8));
+ $offset += 8;
+ $thisfile_asf_dataobject['reserved'] = getid3_lib::LittleEndian2Int(substr($DataObjectData, $offset, 2));
+ $offset += 2;
+ if ($thisfile_asf_dataobject['reserved'] != 0x0101) {
+ $info['warning'][] = 'data_object.reserved ('.getid3_lib::PrintHexBytes($thisfile_asf_dataobject['reserved']).') does not match expected value of "0x0101"';
+ //return false;
+ break;
+ }
+
+ // Data Packets array of: variable //
+ // * Error Correction Flags BYTE 8 //
+ // * * Error Correction Data Length bits 4 // if Error Correction Length Type == 00, size of Error Correction Data in bytes, else hardcoded: 0000
+ // * * Opaque Data Present bits 1 //
+ // * * Error Correction Length Type bits 2 // number of bits for size of the error correction data. hardcoded: 00
+ // * * Error Correction Present bits 1 // If set, use Opaque Data Packet structure, else use Payload structure
+ // * Error Correction Data
+
+ $info['avdataoffset'] = ftell($this->getid3->fp);
+ fseek($this->getid3->fp, ($thisfile_asf_dataobject['objectsize'] - 50), SEEK_CUR); // skip actual audio/video data
+ $info['avdataend'] = ftell($this->getid3->fp);
+ break;
+
+ case GETID3_ASF_Simple_Index_Object:
+ // Simple Index Object: (optional, recommended, one per video stream)
+ // Field Name Field Type Size (bits)
+ // Object ID GUID 128 // GUID for Simple Index object - GETID3_ASF_Data_Object
+ // Object Size QWORD 64 // size of Simple Index object, including 56 bytes of Simple Index Object header
+ // File ID GUID 128 // unique identifier. may be zero or identical to File ID field in Data Object and Header Object
+ // Index Entry Time Interval QWORD 64 // interval between index entries in 100-nanosecond units
+ // Maximum Packet Count DWORD 32 // maximum packet count for all index entries
+ // Index Entries Count DWORD 32 // number of Index Entries structures
+ // Index Entries array of: variable //
+ // * Packet Number DWORD 32 // number of the Data Packet associated with this index entry
+ // * Packet Count WORD 16 // number of Data Packets to sent at this index entry
+
+ // shortcut
+ $thisfile_asf['simple_index_object'] = array();
+ $thisfile_asf_simpleindexobject = &$thisfile_asf['simple_index_object'];
+
+ $SimpleIndexObjectData = $NextObjectDataHeader.fread($this->getid3->fp, 56 - 24);
+ $offset = 24;
+
+ $thisfile_asf_simpleindexobject['objectid'] = $NextObjectGUID;
+ $thisfile_asf_simpleindexobject['objectid_guid'] = $NextObjectGUIDtext;
+ $thisfile_asf_simpleindexobject['objectsize'] = $NextObjectSize;
+
+ $thisfile_asf_simpleindexobject['fileid'] = substr($SimpleIndexObjectData, $offset, 16);
+ $offset += 16;
+ $thisfile_asf_simpleindexobject['fileid_guid'] = $this->BytestringToGUID($thisfile_asf_simpleindexobject['fileid']);
+ $thisfile_asf_simpleindexobject['index_entry_time_interval'] = getid3_lib::LittleEndian2Int(substr($SimpleIndexObjectData, $offset, 8));
+ $offset += 8;
+ $thisfile_asf_simpleindexobject['maximum_packet_count'] = getid3_lib::LittleEndian2Int(substr($SimpleIndexObjectData, $offset, 4));
+ $offset += 4;
+ $thisfile_asf_simpleindexobject['index_entries_count'] = getid3_lib::LittleEndian2Int(substr($SimpleIndexObjectData, $offset, 4));
+ $offset += 4;
+
+ $IndexEntriesData = $SimpleIndexObjectData.fread($this->getid3->fp, 6 * $thisfile_asf_simpleindexobject['index_entries_count']);
+ for ($IndexEntriesCounter = 0; $IndexEntriesCounter < $thisfile_asf_simpleindexobject['index_entries_count']; $IndexEntriesCounter++) {
+ $thisfile_asf_simpleindexobject['index_entries'][$IndexEntriesCounter]['packet_number'] = getid3_lib::LittleEndian2Int(substr($IndexEntriesData, $offset, 4));
+ $offset += 4;
+ $thisfile_asf_simpleindexobject['index_entries'][$IndexEntriesCounter]['packet_count'] = getid3_lib::LittleEndian2Int(substr($IndexEntriesData, $offset, 4));
+ $offset += 2;
+ }
+
+ break;
+
+ case GETID3_ASF_Index_Object:
+ // 6.2 ASF top-level Index Object (optional but recommended when appropriate, 0 or 1)
+ // Field Name Field Type Size (bits)
+ // Object ID GUID 128 // GUID for the Index Object - GETID3_ASF_Index_Object
+ // Object Size QWORD 64 // Specifies the size, in bytes, of the Index Object, including at least 34 bytes of Index Object header
+ // Index Entry Time Interval DWORD 32 // Specifies the time interval between each index entry in ms.
+ // Index Specifiers Count WORD 16 // Specifies the number of Index Specifiers structures in this Index Object.
+ // Index Blocks Count DWORD 32 // Specifies the number of Index Blocks structures in this Index Object.
+
+ // Index Entry Time Interval DWORD 32 // Specifies the time interval between index entries in milliseconds. This value cannot be 0.
+ // Index Specifiers Count WORD 16 // Specifies the number of entries in the Index Specifiers list. Valid values are 1 and greater.
+ // Index Specifiers array of: varies //
+ // * Stream Number WORD 16 // Specifies the stream number that the Index Specifiers refer to. Valid values are between 1 and 127.
+ // * Index Type WORD 16 // Specifies Index Type values as follows:
+ // 1 = Nearest Past Data Packet - indexes point to the data packet whose presentation time is closest to the index entry time.
+ // 2 = Nearest Past Media Object - indexes point to the closest data packet containing an entire object or first fragment of an object.
+ // 3 = Nearest Past Cleanpoint. - indexes point to the closest data packet containing an entire object (or first fragment of an object) that has the Cleanpoint Flag set.
+ // Nearest Past Cleanpoint is the most common type of index.
+ // Index Entry Count DWORD 32 // Specifies the number of Index Entries in the block.
+ // * Block Positions QWORD varies // Specifies a list of byte offsets of the beginnings of the blocks relative to the beginning of the first Data Packet (i.e., the beginning of the Data Object + 50 bytes). The number of entries in this list is specified by the value of the Index Specifiers Count field. The order of those byte offsets is tied to the order in which Index Specifiers are listed.
+ // * Index Entries array of: varies //
+ // * * Offsets DWORD varies // An offset value of 0xffffffff indicates an invalid offset value
+
+ // shortcut
+ $thisfile_asf['asf_index_object'] = array();
+ $thisfile_asf_asfindexobject = &$thisfile_asf['asf_index_object'];
+
+ $ASFIndexObjectData = $NextObjectDataHeader.fread($this->getid3->fp, 34 - 24);
+ $offset = 24;
+
+ $thisfile_asf_asfindexobject['objectid'] = $NextObjectGUID;
+ $thisfile_asf_asfindexobject['objectid_guid'] = $NextObjectGUIDtext;
+ $thisfile_asf_asfindexobject['objectsize'] = $NextObjectSize;
+
+ $thisfile_asf_asfindexobject['entry_time_interval'] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 4));
+ $offset += 4;
+ $thisfile_asf_asfindexobject['index_specifiers_count'] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 2));
+ $offset += 2;
+ $thisfile_asf_asfindexobject['index_blocks_count'] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 4));
+ $offset += 4;
+
+ $ASFIndexObjectData .= fread($this->getid3->fp, 4 * $thisfile_asf_asfindexobject['index_specifiers_count']);
+ for ($IndexSpecifiersCounter = 0; $IndexSpecifiersCounter < $thisfile_asf_asfindexobject['index_specifiers_count']; $IndexSpecifiersCounter++) {
+ $IndexSpecifierStreamNumber = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 2));
+ $offset += 2;
+ $thisfile_asf_asfindexobject['index_specifiers'][$IndexSpecifiersCounter]['stream_number'] = $IndexSpecifierStreamNumber;
+ $thisfile_asf_asfindexobject['index_specifiers'][$IndexSpecifiersCounter]['index_type'] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 2));
+ $offset += 2;
+ $thisfile_asf_asfindexobject['index_specifiers'][$IndexSpecifiersCounter]['index_type_text'] = $this->ASFIndexObjectIndexTypeLookup($thisfile_asf_asfindexobject['index_specifiers'][$IndexSpecifiersCounter]['index_type']);
+ }
+
+ $ASFIndexObjectData .= fread($this->getid3->fp, 4);
+ $thisfile_asf_asfindexobject['index_entry_count'] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 4));
+ $offset += 4;
+
+ $ASFIndexObjectData .= fread($this->getid3->fp, 8 * $thisfile_asf_asfindexobject['index_specifiers_count']);
+ for ($IndexSpecifiersCounter = 0; $IndexSpecifiersCounter < $thisfile_asf_asfindexobject['index_specifiers_count']; $IndexSpecifiersCounter++) {
+ $thisfile_asf_asfindexobject['block_positions'][$IndexSpecifiersCounter] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 8));
+ $offset += 8;
+ }
+
+ $ASFIndexObjectData .= fread($this->getid3->fp, 4 * $thisfile_asf_asfindexobject['index_specifiers_count'] * $thisfile_asf_asfindexobject['index_entry_count']);
+ for ($IndexEntryCounter = 0; $IndexEntryCounter < $thisfile_asf_asfindexobject['index_entry_count']; $IndexEntryCounter++) {
+ for ($IndexSpecifiersCounter = 0; $IndexSpecifiersCounter < $thisfile_asf_asfindexobject['index_specifiers_count']; $IndexSpecifiersCounter++) {
+ $thisfile_asf_asfindexobject['offsets'][$IndexSpecifiersCounter][$IndexEntryCounter] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 4));
+ $offset += 4;
+ }
+ }
+ break;
+
+
+ default:
+ // Implementations shall ignore any standard or non-standard object that they do not know how to handle.
+ if ($this->GUIDname($NextObjectGUIDtext)) {
+ $info['warning'][] = 'unhandled GUID "'.$this->GUIDname($NextObjectGUIDtext).'" {'.$NextObjectGUIDtext.'} in ASF body at offset '.($offset - 16 - 8);
+ } else {
+ $info['warning'][] = 'unknown GUID {'.$NextObjectGUIDtext.'} in ASF body at offset '.(ftell($this->getid3->fp) - 16 - 8);
+ }
+ fseek($this->getid3->fp, ($NextObjectSize - 16 - 8), SEEK_CUR);
+ break;
+ }
+ }
+
+ if (isset($thisfile_asf_codeclistobject['codec_entries']) && is_array($thisfile_asf_codeclistobject['codec_entries'])) {
+ foreach ($thisfile_asf_codeclistobject['codec_entries'] as $streamnumber => $streamdata) {
+ switch ($streamdata['information']) {
+ case 'WMV1':
+ case 'WMV2':
+ case 'WMV3':
+ case 'MSS1':
+ case 'MSS2':
+ case 'WMVA':
+ case 'WVC1':
+ case 'WMVP':
+ case 'WVP2':
+ $thisfile_video['dataformat'] = 'wmv';
+ $info['mime_type'] = 'video/x-ms-wmv';
+ break;
+
+ case 'MP42':
+ case 'MP43':
+ case 'MP4S':
+ case 'mp4s':
+ $thisfile_video['dataformat'] = 'asf';
+ $info['mime_type'] = 'video/x-ms-asf';
+ break;
+
+ default:
+ switch ($streamdata['type_raw']) {
+ case 1:
+ if (strstr($this->TrimConvert($streamdata['name']), 'Windows Media')) {
+ $thisfile_video['dataformat'] = 'wmv';
+ if ($info['mime_type'] == 'video/x-ms-asf') {
+ $info['mime_type'] = 'video/x-ms-wmv';
+ }
+ }
+ break;
+
+ case 2:
+ if (strstr($this->TrimConvert($streamdata['name']), 'Windows Media')) {
+ $thisfile_audio['dataformat'] = 'wma';
+ if ($info['mime_type'] == 'video/x-ms-asf') {
+ $info['mime_type'] = 'audio/x-ms-wma';
+ }
+ }
+ break;
+
+ }
+ break;
+ }
+ }
+ }
+
+ switch (isset($thisfile_audio['codec']) ? $thisfile_audio['codec'] : '') {
+ case 'MPEG Layer-3':
+ $thisfile_audio['dataformat'] = 'mp3';
+ break;
+
+ default:
+ break;
+ }
+
+ if (isset($thisfile_asf_codeclistobject['codec_entries'])) {
+ foreach ($thisfile_asf_codeclistobject['codec_entries'] as $streamnumber => $streamdata) {
+ switch ($streamdata['type_raw']) {
+
+ case 1: // video
+ $thisfile_video['encoder'] = $this->TrimConvert($thisfile_asf_codeclistobject['codec_entries'][$streamnumber]['name']);
+ break;
+
+ case 2: // audio
+ $thisfile_audio['encoder'] = $this->TrimConvert($thisfile_asf_codeclistobject['codec_entries'][$streamnumber]['name']);
+
+ // AH 2003-10-01
+ $thisfile_audio['encoder_options'] = $this->TrimConvert($thisfile_asf_codeclistobject['codec_entries'][0]['description']);
+
+ $thisfile_audio['codec'] = $thisfile_audio['encoder'];
+ break;
+
+ default:
+ $info['warning'][] = 'Unknown streamtype: [codec_list_object][codec_entries]['.$streamnumber.'][type_raw] == '.$streamdata['type_raw'];
+ break;
+
+ }
+ }
+ }
+
+ if (isset($info['audio'])) {
+ $thisfile_audio['lossless'] = (isset($thisfile_audio['lossless']) ? $thisfile_audio['lossless'] : false);
+ $thisfile_audio['dataformat'] = (!empty($thisfile_audio['dataformat']) ? $thisfile_audio['dataformat'] : 'asf');
+ }
+ if (!empty($thisfile_video['dataformat'])) {
+ $thisfile_video['lossless'] = (isset($thisfile_audio['lossless']) ? $thisfile_audio['lossless'] : false);
+ $thisfile_video['pixel_aspect_ratio'] = (isset($thisfile_audio['pixel_aspect_ratio']) ? $thisfile_audio['pixel_aspect_ratio'] : (float) 1);
+ $thisfile_video['dataformat'] = (!empty($thisfile_video['dataformat']) ? $thisfile_video['dataformat'] : 'asf');
+ }
+ if (!empty($thisfile_video['streams'])) {
+ $thisfile_video['streams']['resolution_x'] = 0;
+ $thisfile_video['streams']['resolution_y'] = 0;
+ foreach ($thisfile_video['streams'] as $key => $valuearray) {
+ if (($valuearray['resolution_x'] > $thisfile_video['streams']['resolution_x']) || ($valuearray['resolution_y'] > $thisfile_video['streams']['resolution_y'])) {
+ $thisfile_video['resolution_x'] = $valuearray['resolution_x'];
+ $thisfile_video['resolution_y'] = $valuearray['resolution_y'];
+ }
+ }
+ }
+ $info['bitrate'] = (isset($thisfile_audio['bitrate']) ? $thisfile_audio['bitrate'] : 0) + (isset($thisfile_video['bitrate']) ? $thisfile_video['bitrate'] : 0);
+
+ if ((!isset($info['playtime_seconds']) || ($info['playtime_seconds'] <= 0)) && ($info['bitrate'] > 0)) {
+ $info['playtime_seconds'] = ($info['filesize'] - $info['avdataoffset']) / ($info['bitrate'] / 8);
+ }
+
+ return true;
+ }
+
+ static function ASFCodecListObjectTypeLookup($CodecListType) {
+ static $ASFCodecListObjectTypeLookup = array();
+ if (empty($ASFCodecListObjectTypeLookup)) {
+ $ASFCodecListObjectTypeLookup[0x0001] = 'Video Codec';
+ $ASFCodecListObjectTypeLookup[0x0002] = 'Audio Codec';
+ $ASFCodecListObjectTypeLookup[0xFFFF] = 'Unknown Codec';
+ }
+
+ return (isset($ASFCodecListObjectTypeLookup[$CodecListType]) ? $ASFCodecListObjectTypeLookup[$CodecListType] : 'Invalid Codec Type');
+ }
+
+ static function KnownGUIDs() {
+ static $GUIDarray = array(
+ 'GETID3_ASF_Extended_Stream_Properties_Object' => '14E6A5CB-C672-4332-8399-A96952065B5A',
+ 'GETID3_ASF_Padding_Object' => '1806D474-CADF-4509-A4BA-9AABCB96AAE8',
+ 'GETID3_ASF_Payload_Ext_Syst_Pixel_Aspect_Ratio' => '1B1EE554-F9EA-4BC8-821A-376B74E4C4B8',
+ 'GETID3_ASF_Script_Command_Object' => '1EFB1A30-0B62-11D0-A39B-00A0C90348F6',
+ 'GETID3_ASF_No_Error_Correction' => '20FB5700-5B55-11CF-A8FD-00805F5C442B',
+ 'GETID3_ASF_Content_Branding_Object' => '2211B3FA-BD23-11D2-B4B7-00A0C955FC6E',
+ 'GETID3_ASF_Content_Encryption_Object' => '2211B3FB-BD23-11D2-B4B7-00A0C955FC6E',
+ 'GETID3_ASF_Digital_Signature_Object' => '2211B3FC-BD23-11D2-B4B7-00A0C955FC6E',
+ 'GETID3_ASF_Extended_Content_Encryption_Object' => '298AE614-2622-4C17-B935-DAE07EE9289C',
+ 'GETID3_ASF_Simple_Index_Object' => '33000890-E5B1-11CF-89F4-00A0C90349CB',
+ 'GETID3_ASF_Degradable_JPEG_Media' => '35907DE0-E415-11CF-A917-00805F5C442B',
+ 'GETID3_ASF_Payload_Extension_System_Timecode' => '399595EC-8667-4E2D-8FDB-98814CE76C1E',
+ 'GETID3_ASF_Binary_Media' => '3AFB65E2-47EF-40F2-AC2C-70A90D71D343',
+ 'GETID3_ASF_Timecode_Index_Object' => '3CB73FD0-0C4A-4803-953D-EDF7B6228F0C',
+ 'GETID3_ASF_Metadata_Library_Object' => '44231C94-9498-49D1-A141-1D134E457054',
+ 'GETID3_ASF_Reserved_3' => '4B1ACBE3-100B-11D0-A39B-00A0C90348F6',
+ 'GETID3_ASF_Reserved_4' => '4CFEDB20-75F6-11CF-9C0F-00A0C90349CB',
+ 'GETID3_ASF_Command_Media' => '59DACFC0-59E6-11D0-A3AC-00A0C90348F6',
+ 'GETID3_ASF_Header_Extension_Object' => '5FBF03B5-A92E-11CF-8EE3-00C00C205365',
+ 'GETID3_ASF_Media_Object_Index_Parameters_Obj' => '6B203BAD-3F11-4E84-ACA8-D7613DE2CFA7',
+ 'GETID3_ASF_Header_Object' => '75B22630-668E-11CF-A6D9-00AA0062CE6C',
+ 'GETID3_ASF_Content_Description_Object' => '75B22633-668E-11CF-A6D9-00AA0062CE6C',
+ 'GETID3_ASF_Error_Correction_Object' => '75B22635-668E-11CF-A6D9-00AA0062CE6C',
+ 'GETID3_ASF_Data_Object' => '75B22636-668E-11CF-A6D9-00AA0062CE6C',
+ 'GETID3_ASF_Web_Stream_Media_Subtype' => '776257D4-C627-41CB-8F81-7AC7FF1C40CC',
+ 'GETID3_ASF_Stream_Bitrate_Properties_Object' => '7BF875CE-468D-11D1-8D82-006097C9A2B2',
+ 'GETID3_ASF_Language_List_Object' => '7C4346A9-EFE0-4BFC-B229-393EDE415C85',
+ 'GETID3_ASF_Codec_List_Object' => '86D15240-311D-11D0-A3A4-00A0C90348F6',
+ 'GETID3_ASF_Reserved_2' => '86D15241-311D-11D0-A3A4-00A0C90348F6',
+ 'GETID3_ASF_File_Properties_Object' => '8CABDCA1-A947-11CF-8EE4-00C00C205365',
+ 'GETID3_ASF_File_Transfer_Media' => '91BD222C-F21C-497A-8B6D-5AA86BFC0185',
+ 'GETID3_ASF_Old_RTP_Extension_Data' => '96800C63-4C94-11D1-837B-0080C7A37F95',
+ 'GETID3_ASF_Advanced_Mutual_Exclusion_Object' => 'A08649CF-4775-4670-8A16-6E35357566CD',
+ 'GETID3_ASF_Bandwidth_Sharing_Object' => 'A69609E6-517B-11D2-B6AF-00C04FD908E9',
+ 'GETID3_ASF_Reserved_1' => 'ABD3D211-A9BA-11cf-8EE6-00C00C205365',
+ 'GETID3_ASF_Bandwidth_Sharing_Exclusive' => 'AF6060AA-5197-11D2-B6AF-00C04FD908E9',
+ 'GETID3_ASF_Bandwidth_Sharing_Partial' => 'AF6060AB-5197-11D2-B6AF-00C04FD908E9',
+ 'GETID3_ASF_JFIF_Media' => 'B61BE100-5B4E-11CF-A8FD-00805F5C442B',
+ 'GETID3_ASF_Stream_Properties_Object' => 'B7DC0791-A9B7-11CF-8EE6-00C00C205365',
+ 'GETID3_ASF_Video_Media' => 'BC19EFC0-5B4D-11CF-A8FD-00805F5C442B',
+ 'GETID3_ASF_Audio_Spread' => 'BFC3CD50-618F-11CF-8BB2-00AA00B4E220',
+ 'GETID3_ASF_Metadata_Object' => 'C5F8CBEA-5BAF-4877-8467-AA8C44FA4CCA',
+ 'GETID3_ASF_Payload_Ext_Syst_Sample_Duration' => 'C6BD9450-867F-4907-83A3-C77921B733AD',
+ 'GETID3_ASF_Group_Mutual_Exclusion_Object' => 'D1465A40-5A79-4338-B71B-E36B8FD6C249',
+ 'GETID3_ASF_Extended_Content_Description_Object' => 'D2D0A440-E307-11D2-97F0-00A0C95EA850',
+ 'GETID3_ASF_Stream_Prioritization_Object' => 'D4FED15B-88D3-454F-81F0-ED5C45999E24',
+ 'GETID3_ASF_Payload_Ext_System_Content_Type' => 'D590DC20-07BC-436C-9CF7-F3BBFBF1A4DC',
+ 'GETID3_ASF_Old_File_Properties_Object' => 'D6E229D0-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_ASF_Header_Object' => 'D6E229D1-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_ASF_Data_Object' => 'D6E229D2-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Index_Object' => 'D6E229D3-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_Stream_Properties_Object' => 'D6E229D4-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_Content_Description_Object' => 'D6E229D5-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_Script_Command_Object' => 'D6E229D6-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_Marker_Object' => 'D6E229D7-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_Component_Download_Object' => 'D6E229D8-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_Stream_Group_Object' => 'D6E229D9-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_Scalable_Object' => 'D6E229DA-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_Prioritization_Object' => 'D6E229DB-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Bitrate_Mutual_Exclusion_Object' => 'D6E229DC-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_Inter_Media_Dependency_Object' => 'D6E229DD-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_Rating_Object' => 'D6E229DE-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Index_Parameters_Object' => 'D6E229DF-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_Color_Table_Object' => 'D6E229E0-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_Language_List_Object' => 'D6E229E1-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_Audio_Media' => 'D6E229E2-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_Video_Media' => 'D6E229E3-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_Image_Media' => 'D6E229E4-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_Timecode_Media' => 'D6E229E5-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_Text_Media' => 'D6E229E6-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_MIDI_Media' => 'D6E229E7-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_Command_Media' => 'D6E229E8-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_No_Error_Concealment' => 'D6E229EA-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_Scrambled_Audio' => 'D6E229EB-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_No_Color_Table' => 'D6E229EC-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_SMPTE_Time' => 'D6E229ED-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_ASCII_Text' => 'D6E229EE-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_Unicode_Text' => 'D6E229EF-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_HTML_Text' => 'D6E229F0-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_URL_Command' => 'D6E229F1-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_Filename_Command' => 'D6E229F2-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_ACM_Codec' => 'D6E229F3-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_VCM_Codec' => 'D6E229F4-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_QuickTime_Codec' => 'D6E229F5-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_DirectShow_Transform_Filter' => 'D6E229F6-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_DirectShow_Rendering_Filter' => 'D6E229F7-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_No_Enhancement' => 'D6E229F8-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_Unknown_Enhancement_Type' => 'D6E229F9-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_Temporal_Enhancement' => 'D6E229FA-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_Spatial_Enhancement' => 'D6E229FB-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_Quality_Enhancement' => 'D6E229FC-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_Number_of_Channels_Enhancement' => 'D6E229FD-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_Frequency_Response_Enhancement' => 'D6E229FE-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_Media_Object' => 'D6E229FF-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Mutex_Language' => 'D6E22A00-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Mutex_Bitrate' => 'D6E22A01-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Mutex_Unknown' => 'D6E22A02-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_ASF_Placeholder_Object' => 'D6E22A0E-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Old_Data_Unit_Extension_Object' => 'D6E22A0F-35DA-11D1-9034-00A0C90349BE',
+ 'GETID3_ASF_Web_Stream_Format' => 'DA1E6B13-8359-4050-B398-388E965BF00C',
+ 'GETID3_ASF_Payload_Ext_System_File_Name' => 'E165EC0E-19ED-45D7-B4A7-25CBD1E28E9B',
+ 'GETID3_ASF_Marker_Object' => 'F487CD01-A951-11CF-8EE6-00C00C205365',
+ 'GETID3_ASF_Timecode_Index_Parameters_Object' => 'F55E496D-9797-4B5D-8C8B-604DFE9BFB24',
+ 'GETID3_ASF_Audio_Media' => 'F8699E40-5B4D-11CF-A8FD-00805F5C442B',
+ 'GETID3_ASF_Media_Object_Index_Object' => 'FEB103F8-12AD-4C64-840F-2A1D2F7AD48C',
+ 'GETID3_ASF_Alt_Extended_Content_Encryption_Obj' => 'FF889EF1-ADEE-40DA-9E71-98704BB928CE',
+ 'GETID3_ASF_Index_Placeholder_Object' => 'D9AADE20-7C17-4F9C-BC28-8555DD98E2A2', // http://cpan.uwinnipeg.ca/htdocs/Audio-WMA/Audio/WMA.pm.html
+ 'GETID3_ASF_Compatibility_Object' => '26F18B5D-4584-47EC-9F5F-0E651F0452C9', // http://cpan.uwinnipeg.ca/htdocs/Audio-WMA/Audio/WMA.pm.html
+ );
+ return $GUIDarray;
+ }
+
+ static function GUIDname($GUIDstring) {
+ static $GUIDarray = array();
+ if (empty($GUIDarray)) {
+ $GUIDarray = getid3_asf::KnownGUIDs();
+ }
+ return array_search($GUIDstring, $GUIDarray);
+ }
+
+ static function ASFIndexObjectIndexTypeLookup($id) {
+ static $ASFIndexObjectIndexTypeLookup = array();
+ if (empty($ASFIndexObjectIndexTypeLookup)) {
+ $ASFIndexObjectIndexTypeLookup[1] = 'Nearest Past Data Packet';
+ $ASFIndexObjectIndexTypeLookup[2] = 'Nearest Past Media Object';
+ $ASFIndexObjectIndexTypeLookup[3] = 'Nearest Past Cleanpoint';
+ }
+ return (isset($ASFIndexObjectIndexTypeLookup[$id]) ? $ASFIndexObjectIndexTypeLookup[$id] : 'invalid');
+ }
+
+ static function GUIDtoBytestring($GUIDstring) {
+ // Microsoft defines these 16-byte (128-bit) GUIDs in the strangest way:
+ // first 4 bytes are in little-endian order
+ // next 2 bytes are appended in little-endian order
+ // next 2 bytes are appended in little-endian order
+ // next 2 bytes are appended in big-endian order
+ // next 6 bytes are appended in big-endian order
+
+ // AaBbCcDd-EeFf-GgHh-IiJj-KkLlMmNnOoPp is stored as this 16-byte string:
+ // $Dd $Cc $Bb $Aa $Ff $Ee $Hh $Gg $Ii $Jj $Kk $Ll $Mm $Nn $Oo $Pp
+
+ $hexbytecharstring = chr(hexdec(substr($GUIDstring, 6, 2)));
+ $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 4, 2)));
+ $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 2, 2)));
+ $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 0, 2)));
+
+ $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 11, 2)));
+ $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 9, 2)));
+
+ $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 16, 2)));
+ $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 14, 2)));
+
+ $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 19, 2)));
+ $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 21, 2)));
+
+ $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 24, 2)));
+ $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 26, 2)));
+ $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 28, 2)));
+ $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 30, 2)));
+ $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 32, 2)));
+ $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 34, 2)));
+
+ return $hexbytecharstring;
+ }
+
+ static function BytestringToGUID($Bytestring) {
+ $GUIDstring = str_pad(dechex(ord($Bytestring{3})), 2, '0', STR_PAD_LEFT);
+ $GUIDstring .= str_pad(dechex(ord($Bytestring{2})), 2, '0', STR_PAD_LEFT);
+ $GUIDstring .= str_pad(dechex(ord($Bytestring{1})), 2, '0', STR_PAD_LEFT);
+ $GUIDstring .= str_pad(dechex(ord($Bytestring{0})), 2, '0', STR_PAD_LEFT);
+ $GUIDstring .= '-';
+ $GUIDstring .= str_pad(dechex(ord($Bytestring{5})), 2, '0', STR_PAD_LEFT);
+ $GUIDstring .= str_pad(dechex(ord($Bytestring{4})), 2, '0', STR_PAD_LEFT);
+ $GUIDstring .= '-';
+ $GUIDstring .= str_pad(dechex(ord($Bytestring{7})), 2, '0', STR_PAD_LEFT);
+ $GUIDstring .= str_pad(dechex(ord($Bytestring{6})), 2, '0', STR_PAD_LEFT);
+ $GUIDstring .= '-';
+ $GUIDstring .= str_pad(dechex(ord($Bytestring{8})), 2, '0', STR_PAD_LEFT);
+ $GUIDstring .= str_pad(dechex(ord($Bytestring{9})), 2, '0', STR_PAD_LEFT);
+ $GUIDstring .= '-';
+ $GUIDstring .= str_pad(dechex(ord($Bytestring{10})), 2, '0', STR_PAD_LEFT);
+ $GUIDstring .= str_pad(dechex(ord($Bytestring{11})), 2, '0', STR_PAD_LEFT);
+ $GUIDstring .= str_pad(dechex(ord($Bytestring{12})), 2, '0', STR_PAD_LEFT);
+ $GUIDstring .= str_pad(dechex(ord($Bytestring{13})), 2, '0', STR_PAD_LEFT);
+ $GUIDstring .= str_pad(dechex(ord($Bytestring{14})), 2, '0', STR_PAD_LEFT);
+ $GUIDstring .= str_pad(dechex(ord($Bytestring{15})), 2, '0', STR_PAD_LEFT);
+
+ return strtoupper($GUIDstring);
+ }
+
+ static function FILETIMEtoUNIXtime($FILETIME, $round=true) {
+ // FILETIME is a 64-bit unsigned integer representing
+ // the number of 100-nanosecond intervals since January 1, 1601
+ // UNIX timestamp is number of seconds since January 1, 1970
+ // 116444736000000000 = 10000000 * 60 * 60 * 24 * 365 * 369 + 89 leap days
+ if ($round) {
+ return intval(round(($FILETIME - 116444736000000000) / 10000000));
+ }
+ return ($FILETIME - 116444736000000000) / 10000000;
+ }
+
+ static function WMpictureTypeLookup($WMpictureType) {
+ static $WMpictureTypeLookup = array();
+ if (empty($WMpictureTypeLookup)) {
+ $WMpictureTypeLookup[0x03] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Front Cover');
+ $WMpictureTypeLookup[0x04] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Back Cover');
+ $WMpictureTypeLookup[0x00] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'User Defined');
+ $WMpictureTypeLookup[0x05] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Leaflet Page');
+ $WMpictureTypeLookup[0x06] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Media Label');
+ $WMpictureTypeLookup[0x07] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Lead Artist');
+ $WMpictureTypeLookup[0x08] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Artist');
+ $WMpictureTypeLookup[0x09] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Conductor');
+ $WMpictureTypeLookup[0x0A] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Band');
+ $WMpictureTypeLookup[0x0B] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Composer');
+ $WMpictureTypeLookup[0x0C] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Lyricist');
+ $WMpictureTypeLookup[0x0D] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Recording Location');
+ $WMpictureTypeLookup[0x0E] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'During Recording');
+ $WMpictureTypeLookup[0x0F] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'During Performance');
+ $WMpictureTypeLookup[0x10] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Video Screen Capture');
+ $WMpictureTypeLookup[0x12] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Illustration');
+ $WMpictureTypeLookup[0x13] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Band Logotype');
+ $WMpictureTypeLookup[0x14] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Publisher Logotype');
+ }
+ return (isset($WMpictureTypeLookup[$WMpictureType]) ? $WMpictureTypeLookup[$WMpictureType] : '');
+ }
+
+ function ASF_HeaderExtensionObjectDataParse(&$asf_header_extension_object_data, &$unhandled_sections) {
+ // http://msdn.microsoft.com/en-us/library/bb643323.aspx
+
+ $offset = 0;
+ $objectOffset = 0;
+ $HeaderExtensionObjectParsed = array();
+ while ($objectOffset < strlen($asf_header_extension_object_data)) {
+ $offset = $objectOffset;
+ $thisObject = array();
+
+ $thisObject['guid'] = substr($asf_header_extension_object_data, $offset, 16);
+ $offset += 16;
+ $thisObject['guid_text'] = $this->BytestringToGUID($thisObject['guid']);
+ $thisObject['guid_name'] = $this->GUIDname($thisObject['guid_text']);
+
+ $thisObject['size'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 8));
+ $offset += 8;
+ if ($thisObject['size'] <= 0) {
+ break;
+ }
+
+ switch ($thisObject['guid']) {
+ case GETID3_ASF_Extended_Stream_Properties_Object:
+ $thisObject['start_time'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 8));
+ $offset += 8;
+ $thisObject['start_time_unix'] = $this->FILETIMEtoUNIXtime($thisObject['start_time']);
+
+ $thisObject['end_time'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 8));
+ $offset += 8;
+ $thisObject['end_time_unix'] = $this->FILETIMEtoUNIXtime($thisObject['end_time']);
+
+ $thisObject['data_bitrate'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4));
+ $offset += 4;
+
+ $thisObject['buffer_size'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4));
+ $offset += 4;
+
+ $thisObject['initial_buffer_fullness'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4));
+ $offset += 4;
+
+ $thisObject['alternate_data_bitrate'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4));
+ $offset += 4;
+
+ $thisObject['alternate_buffer_size'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4));
+ $offset += 4;
+
+ $thisObject['alternate_initial_buffer_fullness'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4));
+ $offset += 4;
+
+ $thisObject['maximum_object_size'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4));
+ $offset += 4;
+
+ $thisObject['flags_raw'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4));
+ $offset += 4;
+ $thisObject['flags']['reliable'] = (bool) $thisObject['flags_raw'] & 0x00000001;
+ $thisObject['flags']['seekable'] = (bool) $thisObject['flags_raw'] & 0x00000002;
+ $thisObject['flags']['no_cleanpoints'] = (bool) $thisObject['flags_raw'] & 0x00000004;
+ $thisObject['flags']['resend_live_cleanpoints'] = (bool) $thisObject['flags_raw'] & 0x00000008;
+
+ $thisObject['stream_number'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2));
+ $offset += 2;
+
+ $thisObject['stream_language_id_index'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2));
+ $offset += 2;
+
+ $thisObject['average_time_per_frame'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4));
+ $offset += 4;
+
+ $thisObject['stream_name_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2));
+ $offset += 2;
+
+ $thisObject['payload_extension_system_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2));
+ $offset += 2;
+
+ for ($i = 0; $i < $thisObject['stream_name_count']; $i++) {
+ $streamName = array();
+
+ $streamName['language_id_index'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2));
+ $offset += 2;
+
+ $streamName['stream_name_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2));
+ $offset += 2;
+
+ $streamName['stream_name'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, $streamName['stream_name_length']));
+ $offset += $streamName['stream_name_length'];
+
+ $thisObject['stream_names'][$i] = $streamName;
+ }
+
+ for ($i = 0; $i < $thisObject['payload_extension_system_count']; $i++) {
+ $payloadExtensionSystem = array();
+
+ $payloadExtensionSystem['extension_system_id'] = substr($asf_header_extension_object_data, $offset, 16);
+ $offset += 16;
+ $payloadExtensionSystem['extension_system_id_text'] = $this->BytestringToGUID($payloadExtensionSystem['extension_system_id']);
+
+ $payloadExtensionSystem['extension_system_size'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2));
+ $offset += 2;
+ if ($payloadExtensionSystem['extension_system_size'] <= 0) {
+ break 2;
+ }
+
+ $payloadExtensionSystem['extension_system_info_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4));
+ $offset += 4;
+
+ $payloadExtensionSystem['extension_system_info_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, $payloadExtensionSystem['extension_system_info_length']));
+ $offset += $payloadExtensionSystem['extension_system_info_length'];
+
+ $thisObject['payload_extension_systems'][$i] = $payloadExtensionSystem;
+ }
+
+ break;
+
+ case GETID3_ASF_Padding_Object:
+ // padding, skip it
+ break;
+
+ case GETID3_ASF_Metadata_Object:
+ $thisObject['description_record_counts'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2));
+ $offset += 2;
+
+ for ($i = 0; $i < $thisObject['description_record_counts']; $i++) {
+ $descriptionRecord = array();
+
+ $descriptionRecord['reserved_1'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); // must be zero
+ $offset += 2;
+
+ $descriptionRecord['stream_number'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2));
+ $offset += 2;
+
+ $descriptionRecord['name_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2));
+ $offset += 2;
+
+ $descriptionRecord['data_type'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2));
+ $offset += 2;
+ $descriptionRecord['data_type_text'] = $this->ASFmetadataLibraryObjectDataTypeLookup($descriptionRecord['data_type']);
+
+ $descriptionRecord['data_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4));
+ $offset += 4;
+
+ $descriptionRecord['name'] = substr($asf_header_extension_object_data, $offset, $descriptionRecord['name_length']);
+ $offset += $descriptionRecord['name_length'];
+
+ $descriptionRecord['data'] = substr($asf_header_extension_object_data, $offset, $descriptionRecord['data_length']);
+ $offset += $descriptionRecord['data_length'];
+ switch ($descriptionRecord['data_type']) {
+ case 0x0000: // Unicode string
+ break;
+
+ case 0x0001: // BYTE array
+ // do nothing
+ break;
+
+ case 0x0002: // BOOL
+ $descriptionRecord['data'] = (bool) getid3_lib::LittleEndian2Int($descriptionRecord['data']);
+ break;
+
+ case 0x0003: // DWORD
+ case 0x0004: // QWORD
+ case 0x0005: // WORD
+ $descriptionRecord['data'] = getid3_lib::LittleEndian2Int($descriptionRecord['data']);
+ break;
+
+ case 0x0006: // GUID
+ $descriptionRecord['data_text'] = $this->BytestringToGUID($descriptionRecord['data']);
+ break;
+ }
+
+ $thisObject['description_record'][$i] = $descriptionRecord;
+ }
+ break;
+
+ case GETID3_ASF_Language_List_Object:
+ $thisObject['language_id_record_counts'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2));
+ $offset += 2;
+
+ for ($i = 0; $i < $thisObject['language_id_record_counts']; $i++) {
+ $languageIDrecord = array();
+
+ $languageIDrecord['language_id_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 1));
+ $offset += 1;
+
+ $languageIDrecord['language_id'] = substr($asf_header_extension_object_data, $offset, $languageIDrecord['language_id_length']);
+ $offset += $languageIDrecord['language_id_length'];
+
+ $thisObject['language_id_record'][$i] = $languageIDrecord;
+ }
+ break;
+
+ case GETID3_ASF_Metadata_Library_Object:
+ $thisObject['description_records_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2));
+ $offset += 2;
+
+ for ($i = 0; $i < $thisObject['description_records_count']; $i++) {
+ $descriptionRecord = array();
+
+ $descriptionRecord['language_list_index'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2));
+ $offset += 2;
+
+ $descriptionRecord['stream_number'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2));
+ $offset += 2;
+
+ $descriptionRecord['name_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2));
+ $offset += 2;
+
+ $descriptionRecord['data_type'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2));
+ $offset += 2;
+ $descriptionRecord['data_type_text'] = $this->ASFmetadataLibraryObjectDataTypeLookup($descriptionRecord['data_type']);
+
+ $descriptionRecord['data_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4));
+ $offset += 4;
+
+ $descriptionRecord['name'] = substr($asf_header_extension_object_data, $offset, $descriptionRecord['name_length']);
+ $offset += $descriptionRecord['name_length'];
+
+ $descriptionRecord['data'] = substr($asf_header_extension_object_data, $offset, $descriptionRecord['data_length']);
+ $offset += $descriptionRecord['data_length'];
+
+ if (preg_match('#^WM/Picture$#', str_replace("\x00", '', trim($descriptionRecord['name'])))) {
+ $WMpicture = $this->ASF_WMpicture($descriptionRecord['data']);
+ foreach ($WMpicture as $key => $value) {
+ $descriptionRecord['data'] = $WMpicture;
+ }
+ unset($WMpicture);
+ }
+
+ $thisObject['description_record'][$i] = $descriptionRecord;
+ }
+ break;
+
+ default:
+ $unhandled_sections++;
+ if ($this->GUIDname($thisObject['guid_text'])) {
+ $this->getid3->info['warning'][] = 'unhandled Header Extension Object GUID "'.$this->GUIDname($thisObject['guid_text']).'" {'.$thisObject['guid_text'].'} at offset '.($offset - 16 - 8);
+ } else {
+ $this->getid3->info['warning'][] = 'unknown Header Extension Object GUID {'.$thisObject['guid_text'].'} in at offset '.($offset - 16 - 8);
+ }
+ break;
+ }
+ $HeaderExtensionObjectParsed[] = $thisObject;
+
+ $objectOffset += $thisObject['size'];
+ }
+ return $HeaderExtensionObjectParsed;
+ }
+
+
+ static function ASFmetadataLibraryObjectDataTypeLookup($id) {
+ static $ASFmetadataLibraryObjectDataTypeLookup = array(
+ 0x0000 => 'Unicode string', // The data consists of a sequence of Unicode characters
+ 0x0001 => 'BYTE array', // The type of the data is implementation-specific
+ 0x0002 => 'BOOL', // The data is 2 bytes long and should be interpreted as a 16-bit unsigned integer. Only 0x0000 or 0x0001 are permitted values
+ 0x0003 => 'DWORD', // The data is 4 bytes long and should be interpreted as a 32-bit unsigned integer
+ 0x0004 => 'QWORD', // The data is 8 bytes long and should be interpreted as a 64-bit unsigned integer
+ 0x0005 => 'WORD', // The data is 2 bytes long and should be interpreted as a 16-bit unsigned integer
+ 0x0006 => 'GUID', // The data is 16 bytes long and should be interpreted as a 128-bit GUID
+ );
+ return (isset($ASFmetadataLibraryObjectDataTypeLookup[$id]) ? $ASFmetadataLibraryObjectDataTypeLookup[$id] : 'invalid');
+ }
+
+ function ASF_WMpicture(&$data) {
+ //typedef struct _WMPicture{
+ // LPWSTR pwszMIMEType;
+ // BYTE bPictureType;
+ // LPWSTR pwszDescription;
+ // DWORD dwDataLen;
+ // BYTE* pbData;
+ //} WM_PICTURE;
+
+ $WMpicture = array();
+
+ $offset = 0;
+ $WMpicture['image_type_id'] = getid3_lib::LittleEndian2Int(substr($data, $offset, 1));
+ $offset += 1;
+ $WMpicture['image_type'] = $this->WMpictureTypeLookup($WMpicture['image_type_id']);
+ $WMpicture['image_size'] = getid3_lib::LittleEndian2Int(substr($data, $offset, 4));
+ $offset += 4;
+
+ $WMpicture['image_mime'] = '';
+ do {
+ $next_byte_pair = substr($data, $offset, 2);
+ $offset += 2;
+ $WMpicture['image_mime'] .= $next_byte_pair;
+ } while ($next_byte_pair !== "\x00\x00");
+
+ $WMpicture['image_description'] = '';
+ do {
+ $next_byte_pair = substr($data, $offset, 2);
+ $offset += 2;
+ $WMpicture['image_description'] .= $next_byte_pair;
+ } while ($next_byte_pair !== "\x00\x00");
+
+ $WMpicture['dataoffset'] = $offset;
+ $WMpicture['data'] = substr($data, $offset);
+
+ $imageinfo = array();
+ $WMpicture['image_mime'] = '';
+ $imagechunkcheck = getid3_lib::GetDataImageSize($WMpicture['data'], $imageinfo);
+ unset($imageinfo);
+ if (!empty($imagechunkcheck)) {
+ $WMpicture['image_mime'] = image_type_to_mime_type($imagechunkcheck[2]);
+ }
+ if (!isset($this->getid3->info['asf']['comments']['picture'])) {
+ $this->getid3->info['asf']['comments']['picture'] = array();
+ }
+ $this->getid3->info['asf']['comments']['picture'][] = array('data'=>$WMpicture['data'], 'image_mime'=>$WMpicture['image_mime']);
+
+ return $WMpicture;
+ }
+
+
+ // Remove terminator 00 00 and convert UTF-16LE to Latin-1
+ static function TrimConvert($string) {
+ return trim(getid3_lib::iconv_fallback('UTF-16LE', 'ISO-8859-1', getid3_asf::TrimTerm($string)), ' ');
+ }
+
+
+ // Remove terminator 00 00
+ static function TrimTerm($string) {
+ // remove terminator, only if present (it should be, but...)
+ if (substr($string, -2) === "\x00\x00") {
+ $string = substr($string, 0, -2);
+ }
+ return $string;
+ }
+
+}
+
+?>
\ No newline at end of file
diff --git a/lib/getid3/getid3/module.audio-video.bink.php b/lib/getid3/getid3/module.audio-video.bink.php
new file mode 100644
index 00000000..0a321396
--- /dev/null
+++ b/lib/getid3/getid3/module.audio-video.bink.php
@@ -0,0 +1,73 @@
+ //
+// available at http://getid3.sourceforge.net //
+// or http://www.getid3.org //
+/////////////////////////////////////////////////////////////////
+// See readme.txt for more details //
+/////////////////////////////////////////////////////////////////
+// //
+// module.audio.bink.php //
+// module for analyzing Bink or Smacker audio-video files //
+// dependencies: NONE //
+// ///
+/////////////////////////////////////////////////////////////////
+
+
+class getid3_bink extends getid3_handler
+{
+
+ function Analyze() {
+ $info = &$this->getid3->info;
+
+$info['error'][] = 'Bink / Smacker files not properly processed by this version of getID3() ['.$this->getid3->version().']';
+
+ fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
+ $fileTypeID = fread($this->getid3->fp, 3);
+ switch ($fileTypeID) {
+ case 'BIK':
+ return $this->ParseBink();
+ break;
+
+ case 'SMK':
+ return $this->ParseSmacker();
+ break;
+
+ default:
+ $info['error'][] = 'Expecting "BIK" or "SMK" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($fileTypeID).'"';
+ return false;
+ break;
+ }
+
+ return true;
+
+ }
+
+ function ParseBink() {
+ $info = &$this->getid3->info;
+ $info['fileformat'] = 'bink';
+ $info['video']['dataformat'] = 'bink';
+
+ $fileData = 'BIK'.fread($this->getid3->fp, 13);
+
+ $info['bink']['data_size'] = getid3_lib::LittleEndian2Int(substr($fileData, 4, 4));
+ $info['bink']['frame_count'] = getid3_lib::LittleEndian2Int(substr($fileData, 8, 2));
+
+ if (($info['avdataend'] - $info['avdataoffset']) != ($info['bink']['data_size'] + 8)) {
+ $info['error'][] = 'Probably truncated file: expecting '.$info['bink']['data_size'].' bytes, found '.($info['avdataend'] - $info['avdataoffset']);
+ }
+
+ return true;
+ }
+
+ function ParseSmacker() {
+ $info = &$this->getid3->info;
+ $info['fileformat'] = 'smacker';
+ $info['video']['dataformat'] = 'smacker';
+
+ return true;
+ }
+
+}
+
+?>
\ No newline at end of file
diff --git a/lib/getid3/getid3/module.audio-video.flv.php b/lib/getid3/getid3/module.audio-video.flv.php
new file mode 100644
index 00000000..ba3cd908
--- /dev/null
+++ b/lib/getid3/getid3/module.audio-video.flv.php
@@ -0,0 +1,731 @@
+ //
+// available at http://getid3.sourceforge.net //
+// or http://www.getid3.org //
+// //
+// FLV module by Seth Kaufman //
+// //
+// * version 0.1 (26 June 2005) //
+// //
+// //
+// * version 0.1.1 (15 July 2005) //
+// minor modifications by James Heinrich //
+// //
+// * version 0.2 (22 February 2006) //
+// Support for On2 VP6 codec and meta information //
+// by Steve Webster //
+// //
+// * version 0.3 (15 June 2006) //
+// Modified to not read entire file into memory //
+// by James Heinrich //
+// //
+// * version 0.4 (07 December 2007) //
+// Bugfixes for incorrectly parsed FLV dimensions //
+// and incorrect parsing of onMetaTag //
+// by Evgeny Moysevich //
+// //
+// * version 0.5 (21 May 2009) //
+// Fixed parsing of audio tags and added additional codec //
+// details. The duration is now read from onMetaTag (if //
+// exists), rather than parsing whole file //
+// by Nigel Barnes //
+// //
+// * version 0.6 (24 May 2009) //
+// Better parsing of files with h264 video //
+// by Evgeny Moysevich //
+// //
+// * version 0.6.1 (30 May 2011) //
+// prevent infinite loops in expGolombUe() //
+// //
+/////////////////////////////////////////////////////////////////
+// //
+// module.audio-video.flv.php //
+// module for analyzing Shockwave Flash Video files //
+// dependencies: NONE //
+// ///
+/////////////////////////////////////////////////////////////////
+
+define('GETID3_FLV_TAG_AUDIO', 8);
+define('GETID3_FLV_TAG_VIDEO', 9);
+define('GETID3_FLV_TAG_META', 18);
+
+define('GETID3_FLV_VIDEO_H263', 2);
+define('GETID3_FLV_VIDEO_SCREEN', 3);
+define('GETID3_FLV_VIDEO_VP6FLV', 4);
+define('GETID3_FLV_VIDEO_VP6FLV_ALPHA', 5);
+define('GETID3_FLV_VIDEO_SCREENV2', 6);
+define('GETID3_FLV_VIDEO_H264', 7);
+
+define('H264_AVC_SEQUENCE_HEADER', 0);
+define('H264_PROFILE_BASELINE', 66);
+define('H264_PROFILE_MAIN', 77);
+define('H264_PROFILE_EXTENDED', 88);
+define('H264_PROFILE_HIGH', 100);
+define('H264_PROFILE_HIGH10', 110);
+define('H264_PROFILE_HIGH422', 122);
+define('H264_PROFILE_HIGH444', 144);
+define('H264_PROFILE_HIGH444_PREDICTIVE', 244);
+
+class getid3_flv extends getid3_handler
+{
+ var $max_frames = 100000; // break out of the loop if too many frames have been scanned; only scan this many if meta frame does not contain useful duration
+
+ function Analyze() {
+ $info = &$this->getid3->info;
+
+ fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
+
+ $FLVdataLength = $info['avdataend'] - $info['avdataoffset'];
+ $FLVheader = fread($this->getid3->fp, 5);
+
+ $info['fileformat'] = 'flv';
+ $info['flv']['header']['signature'] = substr($FLVheader, 0, 3);
+ $info['flv']['header']['version'] = getid3_lib::BigEndian2Int(substr($FLVheader, 3, 1));
+ $TypeFlags = getid3_lib::BigEndian2Int(substr($FLVheader, 4, 1));
+
+ $magic = 'FLV';
+ if ($info['flv']['header']['signature'] != $magic) {
+ $info['error'][] = 'Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($info['flv']['header']['signature']).'"';
+ unset($info['flv']);
+ unset($info['fileformat']);
+ return false;
+ }
+
+ $info['flv']['header']['hasAudio'] = (bool) ($TypeFlags & 0x04);
+ $info['flv']['header']['hasVideo'] = (bool) ($TypeFlags & 0x01);
+
+ $FrameSizeDataLength = getid3_lib::BigEndian2Int(fread($this->getid3->fp, 4));
+ $FLVheaderFrameLength = 9;
+ if ($FrameSizeDataLength > $FLVheaderFrameLength) {
+ fseek($this->getid3->fp, $FrameSizeDataLength - $FLVheaderFrameLength, SEEK_CUR);
+ }
+ $Duration = 0;
+ $found_video = false;
+ $found_audio = false;
+ $found_meta = false;
+ $found_valid_meta_playtime = false;
+ $tagParseCount = 0;
+ $info['flv']['framecount'] = array('total'=>0, 'audio'=>0, 'video'=>0);
+ $flv_framecount = &$info['flv']['framecount'];
+ while (((ftell($this->getid3->fp) + 16) < $info['avdataend']) && (($tagParseCount++ <= $this->max_frames) || !$found_valid_meta_playtime)) {
+ $ThisTagHeader = fread($this->getid3->fp, 16);
+
+ $PreviousTagLength = getid3_lib::BigEndian2Int(substr($ThisTagHeader, 0, 4));
+ $TagType = getid3_lib::BigEndian2Int(substr($ThisTagHeader, 4, 1));
+ $DataLength = getid3_lib::BigEndian2Int(substr($ThisTagHeader, 5, 3));
+ $Timestamp = getid3_lib::BigEndian2Int(substr($ThisTagHeader, 8, 3));
+ $LastHeaderByte = getid3_lib::BigEndian2Int(substr($ThisTagHeader, 15, 1));
+ $NextOffset = ftell($this->getid3->fp) - 1 + $DataLength;
+ if ($Timestamp > $Duration) {
+ $Duration = $Timestamp;
+ }
+
+ $flv_framecount['total']++;
+ switch ($TagType) {
+ case GETID3_FLV_TAG_AUDIO:
+ $flv_framecount['audio']++;
+ if (!$found_audio) {
+ $found_audio = true;
+ $info['flv']['audio']['audioFormat'] = ($LastHeaderByte >> 4) & 0x0F;
+ $info['flv']['audio']['audioRate'] = ($LastHeaderByte >> 2) & 0x03;
+ $info['flv']['audio']['audioSampleSize'] = ($LastHeaderByte >> 1) & 0x01;
+ $info['flv']['audio']['audioType'] = $LastHeaderByte & 0x01;
+ }
+ break;
+
+ case GETID3_FLV_TAG_VIDEO:
+ $flv_framecount['video']++;
+ if (!$found_video) {
+ $found_video = true;
+ $info['flv']['video']['videoCodec'] = $LastHeaderByte & 0x07;
+
+ $FLVvideoHeader = fread($this->getid3->fp, 11);
+
+ if ($info['flv']['video']['videoCodec'] == GETID3_FLV_VIDEO_H264) {
+ // this code block contributed by: moysevichØgmail*com
+
+ $AVCPacketType = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 0, 1));
+ if ($AVCPacketType == H264_AVC_SEQUENCE_HEADER) {
+ // read AVCDecoderConfigurationRecord
+ $configurationVersion = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 4, 1));
+ $AVCProfileIndication = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 5, 1));
+ $profile_compatibility = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 6, 1));
+ $lengthSizeMinusOne = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 7, 1));
+ $numOfSequenceParameterSets = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 8, 1));
+
+ if (($numOfSequenceParameterSets & 0x1F) != 0) {
+ // there is at least one SequenceParameterSet
+ // read size of the first SequenceParameterSet
+ //$spsSize = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 9, 2));
+ $spsSize = getid3_lib::LittleEndian2Int(substr($FLVvideoHeader, 9, 2));
+ // read the first SequenceParameterSet
+ $sps = fread($this->getid3->fp, $spsSize);
+ if (strlen($sps) == $spsSize) { // make sure that whole SequenceParameterSet was red
+ $spsReader = new AVCSequenceParameterSetReader($sps);
+ $spsReader->readData();
+ $info['video']['resolution_x'] = $spsReader->getWidth();
+ $info['video']['resolution_y'] = $spsReader->getHeight();
+ }
+ }
+ }
+ // end: moysevichØgmail*com
+
+ } elseif ($info['flv']['video']['videoCodec'] == GETID3_FLV_VIDEO_H263) {
+
+ $PictureSizeType = (getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 3, 2))) >> 7;
+ $PictureSizeType = $PictureSizeType & 0x0007;
+ $info['flv']['header']['videoSizeType'] = $PictureSizeType;
+ switch ($PictureSizeType) {
+ case 0:
+ //$PictureSizeEnc = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 5, 2));
+ //$PictureSizeEnc <<= 1;
+ //$info['video']['resolution_x'] = ($PictureSizeEnc & 0xFF00) >> 8;
+ //$PictureSizeEnc = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 6, 2));
+ //$PictureSizeEnc <<= 1;
+ //$info['video']['resolution_y'] = ($PictureSizeEnc & 0xFF00) >> 8;
+
+ $PictureSizeEnc['x'] = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 4, 2));
+ $PictureSizeEnc['y'] = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 5, 2));
+ $PictureSizeEnc['x'] >>= 7;
+ $PictureSizeEnc['y'] >>= 7;
+ $info['video']['resolution_x'] = $PictureSizeEnc['x'] & 0xFF;
+ $info['video']['resolution_y'] = $PictureSizeEnc['y'] & 0xFF;
+ break;
+
+ case 1:
+ $PictureSizeEnc['x'] = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 4, 3));
+ $PictureSizeEnc['y'] = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 6, 3));
+ $PictureSizeEnc['x'] >>= 7;
+ $PictureSizeEnc['y'] >>= 7;
+ $info['video']['resolution_x'] = $PictureSizeEnc['x'] & 0xFFFF;
+ $info['video']['resolution_y'] = $PictureSizeEnc['y'] & 0xFFFF;
+ break;
+
+ case 2:
+ $info['video']['resolution_x'] = 352;
+ $info['video']['resolution_y'] = 288;
+ break;
+
+ case 3:
+ $info['video']['resolution_x'] = 176;
+ $info['video']['resolution_y'] = 144;
+ break;
+
+ case 4:
+ $info['video']['resolution_x'] = 128;
+ $info['video']['resolution_y'] = 96;
+ break;
+
+ case 5:
+ $info['video']['resolution_x'] = 320;
+ $info['video']['resolution_y'] = 240;
+ break;
+
+ case 6:
+ $info['video']['resolution_x'] = 160;
+ $info['video']['resolution_y'] = 120;
+ break;
+
+ default:
+ $info['video']['resolution_x'] = 0;
+ $info['video']['resolution_y'] = 0;
+ break;
+
+ }
+ }
+ $info['video']['pixel_aspect_ratio'] = $info['video']['resolution_x'] / $info['video']['resolution_y'];
+ }
+ break;
+
+ // Meta tag
+ case GETID3_FLV_TAG_META:
+ if (!$found_meta) {
+ $found_meta = true;
+ fseek($this->getid3->fp, -1, SEEK_CUR);
+ $datachunk = fread($this->getid3->fp, $DataLength);
+ $AMFstream = new AMFStream($datachunk);
+ $reader = new AMFReader($AMFstream);
+ $eventName = $reader->readData();
+ $info['flv']['meta'][$eventName] = $reader->readData();
+ unset($reader);
+
+ $copykeys = array('framerate'=>'frame_rate', 'width'=>'resolution_x', 'height'=>'resolution_y', 'audiodatarate'=>'bitrate', 'videodatarate'=>'bitrate');
+ foreach ($copykeys as $sourcekey => $destkey) {
+ if (isset($info['flv']['meta']['onMetaData'][$sourcekey])) {
+ switch ($sourcekey) {
+ case 'width':
+ case 'height':
+ $info['video'][$destkey] = intval(round($info['flv']['meta']['onMetaData'][$sourcekey]));
+ break;
+ case 'audiodatarate':
+ $info['audio'][$destkey] = getid3_lib::CastAsInt(round($info['flv']['meta']['onMetaData'][$sourcekey] * 1000));
+ break;
+ case 'videodatarate':
+ case 'frame_rate':
+ default:
+ $info['video'][$destkey] = $info['flv']['meta']['onMetaData'][$sourcekey];
+ break;
+ }
+ }
+ }
+ if (!empty($info['flv']['meta']['onMetaData']['duration'])) {
+ $found_valid_meta_playtime = true;
+ }
+ }
+ break;
+
+ default:
+ // noop
+ break;
+ }
+ fseek($this->getid3->fp, $NextOffset, SEEK_SET);
+ }
+
+ $info['playtime_seconds'] = $Duration / 1000;
+ if ($info['playtime_seconds'] > 0) {
+ $info['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds'];
+ }
+
+ if ($info['flv']['header']['hasAudio']) {
+ $info['audio']['codec'] = $this->FLVaudioFormat($info['flv']['audio']['audioFormat']);
+ $info['audio']['sample_rate'] = $this->FLVaudioRate($info['flv']['audio']['audioRate']);
+ $info['audio']['bits_per_sample'] = $this->FLVaudioBitDepth($info['flv']['audio']['audioSampleSize']);
+
+ $info['audio']['channels'] = $info['flv']['audio']['audioType'] + 1; // 0=mono,1=stereo
+ $info['audio']['lossless'] = ($info['flv']['audio']['audioFormat'] ? false : true); // 0=uncompressed
+ $info['audio']['dataformat'] = 'flv';
+ }
+ if (!empty($info['flv']['header']['hasVideo'])) {
+ $info['video']['codec'] = $this->FLVvideoCodec($info['flv']['video']['videoCodec']);
+ $info['video']['dataformat'] = 'flv';
+ $info['video']['lossless'] = false;
+ }
+
+ // Set information from meta
+ if (!empty($info['flv']['meta']['onMetaData']['duration'])) {
+ $info['playtime_seconds'] = $info['flv']['meta']['onMetaData']['duration'];
+ $info['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds'];
+ }
+ if (isset($info['flv']['meta']['onMetaData']['audiocodecid'])) {
+ $info['audio']['codec'] = $this->FLVaudioFormat($info['flv']['meta']['onMetaData']['audiocodecid']);
+ }
+ if (isset($info['flv']['meta']['onMetaData']['videocodecid'])) {
+ $info['video']['codec'] = $this->FLVvideoCodec($info['flv']['meta']['onMetaData']['videocodecid']);
+ }
+ return true;
+ }
+
+
+ function FLVaudioFormat($id) {
+ $FLVaudioFormat = array(
+ 0 => 'Linear PCM, platform endian',
+ 1 => 'ADPCM',
+ 2 => 'mp3',
+ 3 => 'Linear PCM, little endian',
+ 4 => 'Nellymoser 16kHz mono',
+ 5 => 'Nellymoser 8kHz mono',
+ 6 => 'Nellymoser',
+ 7 => 'G.711A-law logarithmic PCM',
+ 8 => 'G.711 mu-law logarithmic PCM',
+ 9 => 'reserved',
+ 10 => 'AAC',
+ 11 => false, // unknown?
+ 12 => false, // unknown?
+ 13 => false, // unknown?
+ 14 => 'mp3 8kHz',
+ 15 => 'Device-specific sound',
+ );
+ return (isset($FLVaudioFormat[$id]) ? $FLVaudioFormat[$id] : false);
+ }
+
+ function FLVaudioRate($id) {
+ $FLVaudioRate = array(
+ 0 => 5500,
+ 1 => 11025,
+ 2 => 22050,
+ 3 => 44100,
+ );
+ return (isset($FLVaudioRate[$id]) ? $FLVaudioRate[$id] : false);
+ }
+
+ function FLVaudioBitDepth($id) {
+ $FLVaudioBitDepth = array(
+ 0 => 8,
+ 1 => 16,
+ );
+ return (isset($FLVaudioBitDepth[$id]) ? $FLVaudioBitDepth[$id] : false);
+ }
+
+ function FLVvideoCodec($id) {
+ $FLVvideoCodec = array(
+ GETID3_FLV_VIDEO_H263 => 'Sorenson H.263',
+ GETID3_FLV_VIDEO_SCREEN => 'Screen video',
+ GETID3_FLV_VIDEO_VP6FLV => 'On2 VP6',
+ GETID3_FLV_VIDEO_VP6FLV_ALPHA => 'On2 VP6 with alpha channel',
+ GETID3_FLV_VIDEO_SCREENV2 => 'Screen video v2',
+ GETID3_FLV_VIDEO_H264 => 'Sorenson H.264',
+ );
+ return (isset($FLVvideoCodec[$id]) ? $FLVvideoCodec[$id] : false);
+ }
+}
+
+class AMFStream {
+ var $bytes;
+ var $pos;
+
+ function AMFStream(&$bytes) {
+ $this->bytes =& $bytes;
+ $this->pos = 0;
+ }
+
+ function readByte() {
+ return getid3_lib::BigEndian2Int(substr($this->bytes, $this->pos++, 1));
+ }
+
+ function readInt() {
+ return ($this->readByte() << 8) + $this->readByte();
+ }
+
+ function readLong() {
+ return ($this->readByte() << 24) + ($this->readByte() << 16) + ($this->readByte() << 8) + $this->readByte();
+ }
+
+ function readDouble() {
+ return getid3_lib::BigEndian2Float($this->read(8));
+ }
+
+ function readUTF() {
+ $length = $this->readInt();
+ return $this->read($length);
+ }
+
+ function readLongUTF() {
+ $length = $this->readLong();
+ return $this->read($length);
+ }
+
+ function read($length) {
+ $val = substr($this->bytes, $this->pos, $length);
+ $this->pos += $length;
+ return $val;
+ }
+
+ function peekByte() {
+ $pos = $this->pos;
+ $val = $this->readByte();
+ $this->pos = $pos;
+ return $val;
+ }
+
+ function peekInt() {
+ $pos = $this->pos;
+ $val = $this->readInt();
+ $this->pos = $pos;
+ return $val;
+ }
+
+ function peekLong() {
+ $pos = $this->pos;
+ $val = $this->readLong();
+ $this->pos = $pos;
+ return $val;
+ }
+
+ function peekDouble() {
+ $pos = $this->pos;
+ $val = $this->readDouble();
+ $this->pos = $pos;
+ return $val;
+ }
+
+ function peekUTF() {
+ $pos = $this->pos;
+ $val = $this->readUTF();
+ $this->pos = $pos;
+ return $val;
+ }
+
+ function peekLongUTF() {
+ $pos = $this->pos;
+ $val = $this->readLongUTF();
+ $this->pos = $pos;
+ return $val;
+ }
+}
+
+class AMFReader {
+ var $stream;
+
+ function AMFReader(&$stream) {
+ $this->stream =& $stream;
+ }
+
+ function readData() {
+ $value = null;
+
+ $type = $this->stream->readByte();
+ switch ($type) {
+
+ // Double
+ case 0:
+ $value = $this->readDouble();
+ break;
+
+ // Boolean
+ case 1:
+ $value = $this->readBoolean();
+ break;
+
+ // String
+ case 2:
+ $value = $this->readString();
+ break;
+
+ // Object
+ case 3:
+ $value = $this->readObject();
+ break;
+
+ // null
+ case 6:
+ return null;
+ break;
+
+ // Mixed array
+ case 8:
+ $value = $this->readMixedArray();
+ break;
+
+ // Array
+ case 10:
+ $value = $this->readArray();
+ break;
+
+ // Date
+ case 11:
+ $value = $this->readDate();
+ break;
+
+ // Long string
+ case 13:
+ $value = $this->readLongString();
+ break;
+
+ // XML (handled as string)
+ case 15:
+ $value = $this->readXML();
+ break;
+
+ // Typed object (handled as object)
+ case 16:
+ $value = $this->readTypedObject();
+ break;
+
+ // Long string
+ default:
+ $value = '(unknown or unsupported data type)';
+ break;
+ }
+
+ return $value;
+ }
+
+ function readDouble() {
+ return $this->stream->readDouble();
+ }
+
+ function readBoolean() {
+ return $this->stream->readByte() == 1;
+ }
+
+ function readString() {
+ return $this->stream->readUTF();
+ }
+
+ function readObject() {
+ // Get highest numerical index - ignored
+// $highestIndex = $this->stream->readLong();
+
+ $data = array();
+
+ while ($key = $this->stream->readUTF()) {
+ $data[$key] = $this->readData();
+ }
+ // Mixed array record ends with empty string (0x00 0x00) and 0x09
+ if (($key == '') && ($this->stream->peekByte() == 0x09)) {
+ // Consume byte
+ $this->stream->readByte();
+ }
+ return $data;
+ }
+
+ function readMixedArray() {
+ // Get highest numerical index - ignored
+ $highestIndex = $this->stream->readLong();
+
+ $data = array();
+
+ while ($key = $this->stream->readUTF()) {
+ if (is_numeric($key)) {
+ $key = (float) $key;
+ }
+ $data[$key] = $this->readData();
+ }
+ // Mixed array record ends with empty string (0x00 0x00) and 0x09
+ if (($key == '') && ($this->stream->peekByte() == 0x09)) {
+ // Consume byte
+ $this->stream->readByte();
+ }
+
+ return $data;
+ }
+
+ function readArray() {
+ $length = $this->stream->readLong();
+ $data = array();
+
+ for ($i = 0; $i < $length; $i++) {
+ $data[] = $this->readData();
+ }
+ return $data;
+ }
+
+ function readDate() {
+ $timestamp = $this->stream->readDouble();
+ $timezone = $this->stream->readInt();
+ return $timestamp;
+ }
+
+ function readLongString() {
+ return $this->stream->readLongUTF();
+ }
+
+ function readXML() {
+ return $this->stream->readLongUTF();
+ }
+
+ function readTypedObject() {
+ $className = $this->stream->readUTF();
+ return $this->readObject();
+ }
+}
+
+class AVCSequenceParameterSetReader {
+ var $sps;
+ var $start = 0;
+ var $currentBytes = 0;
+ var $currentBits = 0;
+ var $width;
+ var $height;
+
+ function AVCSequenceParameterSetReader($sps) {
+ $this->sps = $sps;
+ }
+
+ function readData() {
+ $this->skipBits(8);
+ $this->skipBits(8);
+ $profile = $this->getBits(8); // read profile
+ $this->skipBits(16);
+ $this->expGolombUe(); // read sps id
+ if (in_array($profile, array(H264_PROFILE_HIGH, H264_PROFILE_HIGH10, H264_PROFILE_HIGH422, H264_PROFILE_HIGH444, H264_PROFILE_HIGH444_PREDICTIVE))) {
+ if ($this->expGolombUe() == 3) {
+ $this->skipBits(1);
+ }
+ $this->expGolombUe();
+ $this->expGolombUe();
+ $this->skipBits(1);
+ if ($this->getBit()) {
+ for ($i = 0; $i < 8; $i++) {
+ if ($this->getBit()) {
+ $size = $i < 6 ? 16 : 64;
+ $lastScale = 8;
+ $nextScale = 8;
+ for ($j = 0; $j < $size; $j++) {
+ if ($nextScale != 0) {
+ $deltaScale = $this->expGolombUe();
+ $nextScale = ($lastScale + $deltaScale + 256) % 256;
+ }
+ if ($nextScale != 0) {
+ $lastScale = $nextScale;
+ }
+ }
+ }
+ }
+ }
+ }
+ $this->expGolombUe();
+ $pocType = $this->expGolombUe();
+ if ($pocType == 0) {
+ $this->expGolombUe();
+ } elseif ($pocType == 1) {
+ $this->skipBits(1);
+ $this->expGolombSe();
+ $this->expGolombSe();
+ $pocCycleLength = $this->expGolombUe();
+ for ($i = 0; $i < $pocCycleLength; $i++) {
+ $this->expGolombSe();
+ }
+ }
+ $this->expGolombUe();
+ $this->skipBits(1);
+ $this->width = ($this->expGolombUe() + 1) * 16;
+ $heightMap = $this->expGolombUe() + 1;
+ $this->height = (2 - $this->getBit()) * $heightMap * 16;
+ }
+
+ function skipBits($bits) {
+ $newBits = $this->currentBits + $bits;
+ $this->currentBytes += (int)floor($newBits / 8);
+ $this->currentBits = $newBits % 8;
+ }
+
+ function getBit() {
+ $result = (getid3_lib::BigEndian2Int(substr($this->sps, $this->currentBytes, 1)) >> (7 - $this->currentBits)) & 0x01;
+ $this->skipBits(1);
+ return $result;
+ }
+
+ function getBits($bits) {
+ $result = 0;
+ for ($i = 0; $i < $bits; $i++) {
+ $result = ($result << 1) + $this->getBit();
+ }
+ return $result;
+ }
+
+ function expGolombUe() {
+ $significantBits = 0;
+ $bit = $this->getBit();
+ while ($bit == 0) {
+ $significantBits++;
+ $bit = $this->getBit();
+
+ if ($significantBits > 31) {
+ // something is broken, this is an emergency escape to prevent infinite loops
+ return 0;
+ }
+ }
+ return (1 << $significantBits) + $this->getBits($significantBits) - 1;
+ }
+
+ function expGolombSe() {
+ $result = $this->expGolombUe();
+ if (($result & 0x01) == 0) {
+ return -($result >> 1);
+ } else {
+ return ($result + 1) >> 1;
+ }
+ }
+
+ function getWidth() {
+ return $this->width;
+ }
+
+ function getHeight() {
+ return $this->height;
+ }
+}
+
+?>
\ No newline at end of file
diff --git a/lib/getid3/getid3/module.audio-video.matroska.php b/lib/getid3/getid3/module.audio-video.matroska.php
new file mode 100644
index 00000000..b7ab6679
--- /dev/null
+++ b/lib/getid3/getid3/module.audio-video.matroska.php
@@ -0,0 +1,1706 @@
+ //
+// available at http://getid3.sourceforge.net //
+// or http://www.getid3.org //
+/////////////////////////////////////////////////////////////////
+// See readme.txt for more details //
+/////////////////////////////////////////////////////////////////
+// //
+// module.audio-video.matriska.php //
+// module for analyzing Matroska containers //
+// dependencies: NONE //
+// ///
+/////////////////////////////////////////////////////////////////
+
+
+// from: http://www.matroska.org/technical/specs/index.html
+define('EBML_ID_CHAPTERS', 0x0043A770); // [10][43][A7][70] -- A system to define basic menus and partition data. For more detailed information, look at the Chapters Explanation.
+define('EBML_ID_SEEKHEAD', 0x014D9B74); // [11][4D][9B][74] -- Contains the position of other level 1 elements.
+define('EBML_ID_TAGS', 0x0254C367); // [12][54][C3][67] -- Element containing elements specific to Tracks/Chapters. A list of valid tags can be found .
+define('EBML_ID_INFO', 0x0549A966); // [15][49][A9][66] -- Contains miscellaneous general information and statistics on the file.
+define('EBML_ID_TRACKS', 0x0654AE6B); // [16][54][AE][6B] -- A top-level block of information with many tracks described.
+define('EBML_ID_SEGMENT', 0x08538067); // [18][53][80][67] -- This element contains all other top-level (level 1) elements. Typically a Matroska file is composed of 1 segment.
+define('EBML_ID_ATTACHMENTS', 0x0941A469); // [19][41][A4][69] -- Contain attached files.
+define('EBML_ID_EBML', 0x0A45DFA3); // [1A][45][DF][A3] -- Set the EBML characteristics of the data to follow. Each EBML document has to start with this.
+define('EBML_ID_CUES', 0x0C53BB6B); // [1C][53][BB][6B] -- A top-level element to speed seeking access. All entries are local to the segment.
+define('EBML_ID_CLUSTER', 0x0F43B675); // [1F][43][B6][75] -- The lower level element containing the (monolithic) Block structure.
+define('EBML_ID_LANGUAGE', 0x02B59C); // [22][B5][9C] -- Specifies the language of the track in the Matroska languages form.
+define('EBML_ID_TRACKTIMECODESCALE', 0x03314F); // [23][31][4F] -- The scale to apply on this track to work at normal speed in relation with other tracks (mostly used to adjust video speed when the audio length differs).
+define('EBML_ID_DEFAULTDURATION', 0x03E383); // [23][E3][83] -- Number of nanoseconds (i.e. not scaled) per frame.
+define('EBML_ID_CODECNAME', 0x058688); // [25][86][88] -- A human-readable string specifying the codec.
+define('EBML_ID_CODECDOWNLOADURL', 0x06B240); // [26][B2][40] -- A URL to download about the codec used.
+define('EBML_ID_TIMECODESCALE', 0x0AD7B1); // [2A][D7][B1] -- Timecode scale in nanoseconds (1.000.000 means all timecodes in the segment are expressed in milliseconds).
+define('EBML_ID_COLOURSPACE', 0x0EB524); // [2E][B5][24] -- Same value as in AVI (32 bits).
+define('EBML_ID_GAMMAVALUE', 0x0FB523); // [2F][B5][23] -- Gamma Value.
+define('EBML_ID_CODECSETTINGS', 0x1A9697); // [3A][96][97] -- A string describing the encoding setting used.
+define('EBML_ID_CODECINFOURL', 0x1B4040); // [3B][40][40] -- A URL to find information about the codec used.
+define('EBML_ID_PREVFILENAME', 0x1C83AB); // [3C][83][AB] -- An escaped filename corresponding to the previous segment.
+define('EBML_ID_PREVUID', 0x1CB923); // [3C][B9][23] -- A unique ID to identify the previous chained segment (128 bits).
+define('EBML_ID_NEXTFILENAME', 0x1E83BB); // [3E][83][BB] -- An escaped filename corresponding to the next segment.
+define('EBML_ID_NEXTUID', 0x1EB923); // [3E][B9][23] -- A unique ID to identify the next chained segment (128 bits).
+define('EBML_ID_CONTENTCOMPALGO', 0x0254); // [42][54] -- The compression algorithm used. Algorithms that have been specified so far are:
+define('EBML_ID_CONTENTCOMPSETTINGS', 0x0255); // [42][55] -- Settings that might be needed by the decompressor. For Header Stripping (ContentCompAlgo=3), the bytes that were removed from the beggining of each frames of the track.
+define('EBML_ID_DOCTYPE', 0x0282); // [42][82] -- A string that describes the type of document that follows this EBML header ('matroska' in our case).
+define('EBML_ID_DOCTYPEREADVERSION', 0x0285); // [42][85] -- The minimum DocType version an interpreter has to support to read this file.
+define('EBML_ID_EBMLVERSION', 0x0286); // [42][86] -- The version of EBML parser used to create the file.
+define('EBML_ID_DOCTYPEVERSION', 0x0287); // [42][87] -- The version of DocType interpreter used to create the file.
+define('EBML_ID_EBMLMAXIDLENGTH', 0x02F2); // [42][F2] -- The maximum length of the IDs you'll find in this file (4 or less in Matroska).
+define('EBML_ID_EBMLMAXSIZELENGTH', 0x02F3); // [42][F3] -- The maximum length of the sizes you'll find in this file (8 or less in Matroska). This does not override the element size indicated at the beginning of an element. Elements that have an indicated size which is larger than what is allowed by EBMLMaxSizeLength shall be considered invalid.
+define('EBML_ID_EBMLREADVERSION', 0x02F7); // [42][F7] -- The minimum EBML version a parser has to support to read this file.
+define('EBML_ID_CHAPLANGUAGE', 0x037C); // [43][7C] -- The languages corresponding to the string, in the bibliographic ISO-639-2 form.
+define('EBML_ID_CHAPCOUNTRY', 0x037E); // [43][7E] -- The countries corresponding to the string, same 2 octets as in Internet domains.
+define('EBML_ID_SEGMENTFAMILY', 0x0444); // [44][44] -- A randomly generated unique ID that all segments related to each other must use (128 bits).
+define('EBML_ID_DATEUTC', 0x0461); // [44][61] -- Date of the origin of timecode (value 0), i.e. production date.
+define('EBML_ID_TAGLANGUAGE', 0x047A); // [44][7A] -- Specifies the language of the tag specified, in the Matroska languages form.
+define('EBML_ID_TAGDEFAULT', 0x0484); // [44][84] -- Indication to know if this is the default/original language to use for the given tag.
+define('EBML_ID_TAGBINARY', 0x0485); // [44][85] -- The values of the Tag if it is binary. Note that this cannot be used in the same SimpleTag as TagString.
+define('EBML_ID_TAGSTRING', 0x0487); // [44][87] -- The value of the Tag.
+define('EBML_ID_DURATION', 0x0489); // [44][89] -- Duration of the segment (based on TimecodeScale).
+define('EBML_ID_CHAPPROCESSPRIVATE', 0x050D); // [45][0D] -- Some optional data attached to the ChapProcessCodecID information. For ChapProcessCodecID = 1, it is the "DVD level" equivalent.
+define('EBML_ID_CHAPTERFLAGENABLED', 0x0598); // [45][98] -- Specify wether the chapter is enabled. It can be enabled/disabled by a Control Track. When disabled, the movie should skip all the content between the TimeStart and TimeEnd of this chapter.
+define('EBML_ID_TAGNAME', 0x05A3); // [45][A3] -- The name of the Tag that is going to be stored.
+define('EBML_ID_EDITIONENTRY', 0x05B9); // [45][B9] -- Contains all information about a segment edition.
+define('EBML_ID_EDITIONUID', 0x05BC); // [45][BC] -- A unique ID to identify the edition. It's useful for tagging an edition.
+define('EBML_ID_EDITIONFLAGHIDDEN', 0x05BD); // [45][BD] -- If an edition is hidden (1), it should not be available to the user interface (but still to Control Tracks).
+define('EBML_ID_EDITIONFLAGDEFAULT', 0x05DB); // [45][DB] -- If a flag is set (1) the edition should be used as the default one.
+define('EBML_ID_EDITIONFLAGORDERED', 0x05DD); // [45][DD] -- Specify if the chapters can be defined multiple times and the order to play them is enforced.
+define('EBML_ID_FILEDATA', 0x065C); // [46][5C] -- The data of the file.
+define('EBML_ID_FILEMIMETYPE', 0x0660); // [46][60] -- MIME type of the file.
+define('EBML_ID_FILENAME', 0x066E); // [46][6E] -- Filename of the attached file.
+define('EBML_ID_FILEREFERRAL', 0x0675); // [46][75] -- A binary value that a track/codec can refer to when the attachment is needed.
+define('EBML_ID_FILEDESCRIPTION', 0x067E); // [46][7E] -- A human-friendly name for the attached file.
+define('EBML_ID_FILEUID', 0x06AE); // [46][AE] -- Unique ID representing the file, as random as possible.
+define('EBML_ID_CONTENTENCALGO', 0x07E1); // [47][E1] -- The encryption algorithm used. The value '0' means that the contents have not been encrypted but only signed. Predefined values:
+define('EBML_ID_CONTENTENCKEYID', 0x07E2); // [47][E2] -- For public key algorithms this is the ID of the public key the the data was encrypted with.
+define('EBML_ID_CONTENTSIGNATURE', 0x07E3); // [47][E3] -- A cryptographic signature of the contents.
+define('EBML_ID_CONTENTSIGKEYID', 0x07E4); // [47][E4] -- This is the ID of the private key the data was signed with.
+define('EBML_ID_CONTENTSIGALGO', 0x07E5); // [47][E5] -- The algorithm used for the signature. A value of '0' means that the contents have not been signed but only encrypted. Predefined values:
+define('EBML_ID_CONTENTSIGHASHALGO', 0x07E6); // [47][E6] -- The hash algorithm used for the signature. A value of '0' means that the contents have not been signed but only encrypted. Predefined values:
+define('EBML_ID_MUXINGAPP', 0x0D80); // [4D][80] -- Muxing application or library ("libmatroska-0.4.3").
+define('EBML_ID_SEEK', 0x0DBB); // [4D][BB] -- Contains a single seek entry to an EBML element.
+define('EBML_ID_CONTENTENCODINGORDER', 0x1031); // [50][31] -- Tells when this modification was used during encoding/muxing starting with 0 and counting upwards. The decoder/demuxer has to start with the highest order number it finds and work its way down. This value has to be unique over all ContentEncodingOrder elements in the segment.
+define('EBML_ID_CONTENTENCODINGSCOPE', 0x1032); // [50][32] -- A bit field that describes which elements have been modified in this way. Values (big endian) can be OR'ed. Possible values:
+define('EBML_ID_CONTENTENCODINGTYPE', 0x1033); // [50][33] -- A value describing what kind of transformation has been done. Possible values:
+define('EBML_ID_CONTENTCOMPRESSION', 0x1034); // [50][34] -- Settings describing the compression used. Must be present if the value of ContentEncodingType is 0 and absent otherwise. Each block must be decompressable even if no previous block is available in order not to prevent seeking.
+define('EBML_ID_CONTENTENCRYPTION', 0x1035); // [50][35] -- Settings describing the encryption used. Must be present if the value of ContentEncodingType is 1 and absent otherwise.
+define('EBML_ID_CUEREFNUMBER', 0x135F); // [53][5F] -- Number of the referenced Block of Track X in the specified Cluster.
+define('EBML_ID_NAME', 0x136E); // [53][6E] -- A human-readable track name.
+define('EBML_ID_CUEBLOCKNUMBER', 0x1378); // [53][78] -- Number of the Block in the specified Cluster.
+define('EBML_ID_TRACKOFFSET', 0x137F); // [53][7F] -- A value to add to the Block's Timecode. This can be used to adjust the playback offset of a track.
+define('EBML_ID_SEEKID', 0x13AB); // [53][AB] -- The binary ID corresponding to the element name.
+define('EBML_ID_SEEKPOSITION', 0x13AC); // [53][AC] -- The position of the element in the segment in octets (0 = first level 1 element).
+define('EBML_ID_STEREOMODE', 0x13B8); // [53][B8] -- Stereo-3D video mode on 2 bits (0: mono, 1: right eye, 2: left eye, 3: both eyes).
+define('EBML_ID_PIXELCROPBOTTOM', 0x14AA); // [54][AA] -- The number of video pixels to remove at the bottom of the image (for HDTV content).
+define('EBML_ID_DISPLAYWIDTH', 0x14B0); // [54][B0] -- Width of the video frames to display.
+define('EBML_ID_DISPLAYUNIT', 0x14B2); // [54][B2] -- Type of the unit for DisplayWidth/Height (0: pixels, 1: centimeters, 2: inches).
+define('EBML_ID_ASPECTRATIOTYPE', 0x14B3); // [54][B3] -- Specify the possible modifications to the aspect ratio (0: free resizing, 1: keep aspect ratio, 2: fixed).
+define('EBML_ID_DISPLAYHEIGHT', 0x14BA); // [54][BA] -- Height of the video frames to display.
+define('EBML_ID_PIXELCROPTOP', 0x14BB); // [54][BB] -- The number of video pixels to remove at the top of the image.
+define('EBML_ID_PIXELCROPLEFT', 0x14CC); // [54][CC] -- The number of video pixels to remove on the left of the image.
+define('EBML_ID_PIXELCROPRIGHT', 0x14DD); // [54][DD] -- The number of video pixels to remove on the right of the image.
+define('EBML_ID_FLAGFORCED', 0x15AA); // [55][AA] -- Set if that track MUST be used during playback. There can be many forced track for a kind (audio, video or subs), the player should select the one which language matches the user preference or the default + forced track. Overlay MAY happen between a forced and non-forced track of the same kind.
+define('EBML_ID_MAXBLOCKADDITIONID', 0x15EE); // [55][EE] -- The maximum value of BlockAddID. A value 0 means there is no BlockAdditions for this track.
+define('EBML_ID_WRITINGAPP', 0x1741); // [57][41] -- Writing application ("mkvmerge-0.3.3").
+define('EBML_ID_CLUSTERSILENTTRACKS', 0x1854); // [58][54] -- The list of tracks that are not used in that part of the stream. It is useful when using overlay tracks on seeking. Then you should decide what track to use.
+define('EBML_ID_CLUSTERSILENTTRACKNUMBER', 0x18D7); // [58][D7] -- One of the track number that are not used from now on in the stream. It could change later if not specified as silent in a further Cluster.
+define('EBML_ID_ATTACHEDFILE', 0x21A7); // [61][A7] -- An attached file.
+define('EBML_ID_CONTENTENCODING', 0x2240); // [62][40] -- Settings for one content encoding like compression or encryption.
+define('EBML_ID_BITDEPTH', 0x2264); // [62][64] -- Bits per sample, mostly used for PCM.
+define('EBML_ID_CODECPRIVATE', 0x23A2); // [63][A2] -- Private data only known to the codec.
+define('EBML_ID_TARGETS', 0x23C0); // [63][C0] -- Contain all UIDs where the specified meta data apply. It is void to describe everything in the segment.
+define('EBML_ID_CHAPTERPHYSICALEQUIV', 0x23C3); // [63][C3] -- Specify the physical equivalent of this ChapterAtom like "DVD" (60) or "SIDE" (50), see complete list of values.
+define('EBML_ID_TAGCHAPTERUID', 0x23C4); // [63][C4] -- A unique ID to identify the Chapter(s) the tags belong to. If the value is 0 at this level, the tags apply to all chapters in the Segment.
+define('EBML_ID_TAGTRACKUID', 0x23C5); // [63][C5] -- A unique ID to identify the Track(s) the tags belong to. If the value is 0 at this level, the tags apply to all tracks in the Segment.
+define('EBML_ID_TAGATTACHMENTUID', 0x23C6); // [63][C6] -- A unique ID to identify the Attachment(s) the tags belong to. If the value is 0 at this level, the tags apply to all the attachments in the Segment.
+define('EBML_ID_TAGEDITIONUID', 0x23C9); // [63][C9] -- A unique ID to identify the EditionEntry(s) the tags belong to. If the value is 0 at this level, the tags apply to all editions in the Segment.
+define('EBML_ID_TARGETTYPE', 0x23CA); // [63][CA] -- An informational string that can be used to display the logical level of the target like "ALBUM", "TRACK", "MOVIE", "CHAPTER", etc (see TargetType).
+define('EBML_ID_TRACKTRANSLATE', 0x2624); // [66][24] -- The track identification for the given Chapter Codec.
+define('EBML_ID_TRACKTRANSLATETRACKID', 0x26A5); // [66][A5] -- The binary value used to represent this track in the chapter codec data. The format depends on the ChapProcessCodecID used.
+define('EBML_ID_TRACKTRANSLATECODEC', 0x26BF); // [66][BF] -- The chapter codec using this ID (0: Matroska Script, 1: DVD-menu).
+define('EBML_ID_TRACKTRANSLATEEDITIONUID', 0x26FC); // [66][FC] -- Specify an edition UID on which this translation applies. When not specified, it means for all editions found in the segment.
+define('EBML_ID_SIMPLETAG', 0x27C8); // [67][C8] -- Contains general information about the target.
+define('EBML_ID_TARGETTYPEVALUE', 0x28CA); // [68][CA] -- A number to indicate the logical level of the target (see TargetType).
+define('EBML_ID_CHAPPROCESSCOMMAND', 0x2911); // [69][11] -- Contains all the commands associated to the Atom.
+define('EBML_ID_CHAPPROCESSTIME', 0x2922); // [69][22] -- Defines when the process command should be handled (0: during the whole chapter, 1: before starting playback, 2: after playback of the chapter).
+define('EBML_ID_CHAPTERTRANSLATE', 0x2924); // [69][24] -- A tuple of corresponding ID used by chapter codecs to represent this segment.
+define('EBML_ID_CHAPPROCESSDATA', 0x2933); // [69][33] -- Contains the command information. The data should be interpreted depending on the ChapProcessCodecID value. For ChapProcessCodecID = 1, the data correspond to the binary DVD cell pre/post commands.
+define('EBML_ID_CHAPPROCESS', 0x2944); // [69][44] -- Contains all the commands associated to the Atom.
+define('EBML_ID_CHAPPROCESSCODECID', 0x2955); // [69][55] -- Contains the type of the codec used for the processing. A value of 0 means native Matroska processing (to be defined), a value of 1 means the DVD command set is used. More codec IDs can be added later.
+define('EBML_ID_CHAPTERTRANSLATEID', 0x29A5); // [69][A5] -- The binary value used to represent this segment in the chapter codec data. The format depends on the ChapProcessCodecID used.
+define('EBML_ID_CHAPTERTRANSLATECODEC', 0x29BF); // [69][BF] -- The chapter codec using this ID (0: Matroska Script, 1: DVD-menu).
+define('EBML_ID_CHAPTERTRANSLATEEDITIONUID', 0x29FC); // [69][FC] -- Specify an edition UID on which this correspondance applies. When not specified, it means for all editions found in the segment.
+define('EBML_ID_CONTENTENCODINGS', 0x2D80); // [6D][80] -- Settings for several content encoding mechanisms like compression or encryption.
+define('EBML_ID_MINCACHE', 0x2DE7); // [6D][E7] -- The minimum number of frames a player should be able to cache during playback. If set to 0, the reference pseudo-cache system is not used.
+define('EBML_ID_MAXCACHE', 0x2DF8); // [6D][F8] -- The maximum cache size required to store referenced frames in and the current frame. 0 means no cache is needed.
+define('EBML_ID_CHAPTERSEGMENTUID', 0x2E67); // [6E][67] -- A segment to play in place of this chapter. Edition ChapterSegmentEditionUID should be used for this segment, otherwise no edition is used.
+define('EBML_ID_CHAPTERSEGMENTEDITIONUID', 0x2EBC); // [6E][BC] -- The edition to play from the segment linked in ChapterSegmentUID.
+define('EBML_ID_TRACKOVERLAY', 0x2FAB); // [6F][AB] -- Specify that this track is an overlay track for the Track specified (in the u-integer). That means when this track has a gap (see SilentTracks) the overlay track should be used instead. The order of multiple TrackOverlay matters, the first one is the one that should be used. If not found it should be the second, etc.
+define('EBML_ID_TAG', 0x3373); // [73][73] -- Element containing elements specific to Tracks/Chapters.
+define('EBML_ID_SEGMENTFILENAME', 0x3384); // [73][84] -- A filename corresponding to this segment.
+define('EBML_ID_SEGMENTUID', 0x33A4); // [73][A4] -- A randomly generated unique ID to identify the current segment between many others (128 bits).
+define('EBML_ID_CHAPTERUID', 0x33C4); // [73][C4] -- A unique ID to identify the Chapter.
+define('EBML_ID_TRACKUID', 0x33C5); // [73][C5] -- A unique ID to identify the Track. This should be kept the same when making a direct stream copy of the Track to another file.
+define('EBML_ID_ATTACHMENTLINK', 0x3446); // [74][46] -- The UID of an attachment that is used by this codec.
+define('EBML_ID_CLUSTERBLOCKADDITIONS', 0x35A1); // [75][A1] -- Contain additional blocks to complete the main one. An EBML parser that has no knowledge of the Block structure could still see and use/skip these data.
+define('EBML_ID_CHANNELPOSITIONS', 0x347B); // [7D][7B] -- Table of horizontal angles for each successive channel, see appendix.
+define('EBML_ID_OUTPUTSAMPLINGFREQUENCY', 0x38B5); // [78][B5] -- Real output sampling frequency in Hz (used for SBR techniques).
+define('EBML_ID_TITLE', 0x3BA9); // [7B][A9] -- General name of the segment.
+define('EBML_ID_CHAPTERDISPLAY', 0x00); // [80] -- Contains all possible strings to use for the chapter display.
+define('EBML_ID_TRACKTYPE', 0x03); // [83] -- A set of track types coded on 8 bits (1: video, 2: audio, 3: complex, 0x10: logo, 0x11: subtitle, 0x12: buttons, 0x20: control).
+define('EBML_ID_CHAPSTRING', 0x05); // [85] -- Contains the string to use as the chapter atom.
+define('EBML_ID_CODECID', 0x06); // [86] -- An ID corresponding to the codec, see the codec page for more info.
+define('EBML_ID_FLAGDEFAULT', 0x08); // [88] -- Set if that track (audio, video or subs) SHOULD be used if no language found matches the user preference.
+define('EBML_ID_CHAPTERTRACKNUMBER', 0x09); // [89] -- UID of the Track to apply this chapter too. In the absense of a control track, choosing this chapter will select the listed Tracks and deselect unlisted tracks. Absense of this element indicates that the Chapter should be applied to any currently used Tracks.
+define('EBML_ID_CLUSTERSLICES', 0x0E); // [8E] -- Contains slices description.
+define('EBML_ID_CHAPTERTRACK', 0x0F); // [8F] -- List of tracks on which the chapter applies. If this element is not present, all tracks apply
+define('EBML_ID_CHAPTERTIMESTART', 0x11); // [91] -- Timecode of the start of Chapter (not scaled).
+define('EBML_ID_CHAPTERTIMEEND', 0x12); // [92] -- Timecode of the end of Chapter (timecode excluded, not scaled).
+define('EBML_ID_CUEREFTIME', 0x16); // [96] -- Timecode of the referenced Block.
+define('EBML_ID_CUEREFCLUSTER', 0x17); // [97] -- Position of the Cluster containing the referenced Block.
+define('EBML_ID_CHAPTERFLAGHIDDEN', 0x18); // [98] -- If a chapter is hidden (1), it should not be available to the user interface (but still to Control Tracks).
+define('EBML_ID_FLAGINTERLACED', 0x1A); // [9A] -- Set if the video is interlaced.
+define('EBML_ID_CLUSTERBLOCKDURATION', 0x1B); // [9B] -- The duration of the Block (based on TimecodeScale). This element is mandatory when DefaultDuration is set for the track. When not written and with no DefaultDuration, the value is assumed to be the difference between the timecode of this Block and the timecode of the next Block in "display" order (not coding order). This element can be useful at the end of a Track (as there is not other Block available), or when there is a break in a track like for subtitle tracks.
+define('EBML_ID_FLAGLACING', 0x1C); // [9C] -- Set if the track may contain blocks using lacing.
+define('EBML_ID_CHANNELS', 0x1F); // [9F] -- Numbers of channels in the track.
+define('EBML_ID_CLUSTERBLOCKGROUP', 0x20); // [A0] -- Basic container of information containing a single Block or BlockVirtual, and information specific to that Block/VirtualBlock.
+define('EBML_ID_CLUSTERBLOCK', 0x21); // [A1] -- Block containing the actual data to be rendered and a timecode relative to the Cluster Timecode.
+define('EBML_ID_CLUSTERBLOCKVIRTUAL', 0x22); // [A2] -- A Block with no data. It must be stored in the stream at the place the real Block should be in display order.
+define('EBML_ID_CLUSTERSIMPLEBLOCK', 0x23); // [A3] -- Similar to Block but without all the extra information, mostly used to reduced overhead when no extra feature is needed.
+define('EBML_ID_CLUSTERCODECSTATE', 0x24); // [A4] -- The new codec state to use. Data interpretation is private to the codec. This information should always be referenced by a seek entry.
+define('EBML_ID_CLUSTERBLOCKADDITIONAL', 0x25); // [A5] -- Interpreted by the codec as it wishes (using the BlockAddID).
+define('EBML_ID_CLUSTERBLOCKMORE', 0x26); // [A6] -- Contain the BlockAdditional and some parameters.
+define('EBML_ID_CLUSTERPOSITION', 0x27); // [A7] -- Position of the Cluster in the segment (0 in live broadcast streams). It might help to resynchronise offset on damaged streams.
+define('EBML_ID_CODECDECODEALL', 0x2A); // [AA] -- The codec can decode potentially damaged data.
+define('EBML_ID_CLUSTERPREVSIZE', 0x2B); // [AB] -- Size of the previous Cluster, in octets. Can be useful for backward playing.
+define('EBML_ID_TRACKENTRY', 0x2E); // [AE] -- Describes a track with all elements.
+define('EBML_ID_CLUSTERENCRYPTEDBLOCK', 0x2F); // [AF] -- Similar to SimpleBlock but the data inside the Block are Transformed (encrypt and/or signed).
+define('EBML_ID_PIXELWIDTH', 0x30); // [B0] -- Width of the encoded video frames in pixels.
+define('EBML_ID_CUETIME', 0x33); // [B3] -- Absolute timecode according to the segment time base.
+define('EBML_ID_SAMPLINGFREQUENCY', 0x35); // [B5] -- Sampling frequency in Hz.
+define('EBML_ID_CHAPTERATOM', 0x36); // [B6] -- Contains the atom information to use as the chapter atom (apply to all tracks).
+define('EBML_ID_CUETRACKPOSITIONS', 0x37); // [B7] -- Contain positions for different tracks corresponding to the timecode.
+define('EBML_ID_FLAGENABLED', 0x39); // [B9] -- Set if the track is used.
+define('EBML_ID_PIXELHEIGHT', 0x3A); // [BA] -- Height of the encoded video frames in pixels.
+define('EBML_ID_CUEPOINT', 0x3B); // [BB] -- Contains all information relative to a seek point in the segment.
+define('EBML_ID_CRC32', 0x3F); // [BF] -- The CRC is computed on all the data of the Master element it's in, regardless of its position. It's recommended to put the CRC value at the beggining of the Master element for easier reading. All level 1 elements should include a CRC-32.
+define('EBML_ID_CLUSTERBLOCKADDITIONID', 0x4B); // [CB] -- The ID of the BlockAdditional element (0 is the main Block).
+define('EBML_ID_CLUSTERLACENUMBER', 0x4C); // [CC] -- The reverse number of the frame in the lace (0 is the last frame, 1 is the next to last, etc). While there are a few files in the wild with this element, it is no longer in use and has been deprecated. Being able to interpret this element is not required for playback.
+define('EBML_ID_CLUSTERFRAMENUMBER', 0x4D); // [CD] -- The number of the frame to generate from this lace with this delay (allow you to generate many frames from the same Block/Frame).
+define('EBML_ID_CLUSTERDELAY', 0x4E); // [CE] -- The (scaled) delay to apply to the element.
+define('EBML_ID_CLUSTERDURATION', 0x4F); // [CF] -- The (scaled) duration to apply to the element.
+define('EBML_ID_TRACKNUMBER', 0x57); // [D7] -- The track number as used in the Block Header (using more than 127 tracks is not encouraged, though the design allows an unlimited number).
+define('EBML_ID_CUEREFERENCE', 0x5B); // [DB] -- The Clusters containing the required referenced Blocks.
+define('EBML_ID_VIDEO', 0x60); // [E0] -- Video settings.
+define('EBML_ID_AUDIO', 0x61); // [E1] -- Audio settings.
+define('EBML_ID_CLUSTERTIMESLICE', 0x68); // [E8] -- Contains extra time information about the data contained in the Block. While there are a few files in the wild with this element, it is no longer in use and has been deprecated. Being able to interpret this element is not required for playback.
+define('EBML_ID_CUECODECSTATE', 0x6A); // [EA] -- The position of the Codec State corresponding to this Cue element. 0 means that the data is taken from the initial Track Entry.
+define('EBML_ID_CUEREFCODECSTATE', 0x6B); // [EB] -- The position of the Codec State corresponding to this referenced element. 0 means that the data is taken from the initial Track Entry.
+define('EBML_ID_VOID', 0x6C); // [EC] -- Used to void damaged data, to avoid unexpected behaviors when using damaged data. The content is discarded. Also used to reserve space in a sub-element for later use.
+define('EBML_ID_CLUSTERTIMECODE', 0x67); // [E7] -- Absolute timecode of the cluster (based on TimecodeScale).
+define('EBML_ID_CLUSTERBLOCKADDID', 0x6E); // [EE] -- An ID to identify the BlockAdditional level.
+define('EBML_ID_CUECLUSTERPOSITION', 0x71); // [F1] -- The position of the Cluster containing the required Block.
+define('EBML_ID_CUETRACK', 0x77); // [F7] -- The track for which a position is given.
+define('EBML_ID_CLUSTERREFERENCEPRIORITY', 0x7A); // [FA] -- This frame is referenced and has the specified cache priority. In cache only a frame of the same or higher priority can replace this frame. A value of 0 means the frame is not referenced.
+define('EBML_ID_CLUSTERREFERENCEBLOCK', 0x7B); // [FB] -- Timecode of another frame used as a reference (ie: B or P frame). The timecode is relative to the block it's attached to.
+define('EBML_ID_CLUSTERREFERENCEVIRTUAL', 0x7D); // [FD] -- Relative position of the data that should be in position of the virtual block.
+
+
+class getid3_matroska extends getid3_handler
+{
+ // public options
+ public static $hide_clusters = true; // if true, do not return information about CLUSTER chunks, since there's a lot of them and they're not usually useful [default: TRUE]
+ public static $parse_whole_file = false; // true to parse the whole file, not only header [default: FALSE]
+
+ // private parser settings/placeholders
+ private $EBMLbuffer = '';
+ private $EBMLbuffer_offset = 0;
+ private $EBMLbuffer_length = 0;
+ private $current_offset = 0;
+ private $unuseful_elements = array(EBML_ID_CRC32, EBML_ID_VOID);
+
+ public function Analyze()
+ {
+ $info = &$this->getid3->info;
+
+ // parse container
+ try {
+ $this->parseEBML($info);
+ }
+ catch (Exception $e) {
+ $info['error'][] = 'EBML parser: '.$e->getMessage();
+ }
+
+ // calculate playtime
+ if (isset($info['matroska']['info']) && is_array($info['matroska']['info'])) {
+ foreach ($info['matroska']['info'] as $key => $infoarray) {
+ if (isset($infoarray['Duration'])) {
+ // TimecodeScale is how many nanoseconds each Duration unit is
+ $info['playtime_seconds'] = $infoarray['Duration'] * ((isset($infoarray['TimecodeScale']) ? $infoarray['TimecodeScale'] : 1000000) / 1000000000);
+ break;
+ }
+ }
+ }
+
+ // extract tags
+ if (isset($info['matroska']['tags']) && is_array($info['matroska']['tags'])) {
+ foreach ($info['matroska']['tags'] as $key => $infoarray) {
+ $this->ExtractCommentsSimpleTag($infoarray);
+ }
+ }
+
+ // process tracks
+ if (isset($info['matroska']['tracks']['tracks']) && is_array($info['matroska']['tracks']['tracks'])) {
+ foreach ($info['matroska']['tracks']['tracks'] as $key => $trackarray) {
+
+ $track_info = array();
+ $track_info['dataformat'] = self::MatroskaCodecIDtoCommonName($trackarray['CodecID']);
+ $track_info['default'] = (isset($trackarray['FlagDefault']) ? $trackarray['FlagDefault'] : true);
+ if (isset($trackarray['Name'])) { $track_info['name'] = $trackarray['Name']; }
+
+ switch ($trackarray['TrackType']) {
+
+ case 1: // Video
+ $track_info['resolution_x'] = $trackarray['PixelWidth'];
+ $track_info['resolution_y'] = $trackarray['PixelHeight'];
+ if (isset($trackarray['DisplayWidth'])) { $track_info['display_x'] = $trackarray['DisplayWidth']; }
+ if (isset($trackarray['DisplayHeight'])) { $track_info['display_y'] = $trackarray['DisplayHeight']; }
+ if (isset($trackarray['DefaultDuration'])) { $track_info['frame_rate'] = round(1000000000 / $trackarray['DefaultDuration'], 3); }
+ //if (isset($trackarray['CodecName'])) { $track_info['codec'] = $trackarray['CodecName']; }
+
+ switch ($trackarray['CodecID']) {
+ case 'V_MS/VFW/FOURCC':
+ if (!getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, false)) {
+ $this->getid3->warning('Unable to parse codec private data ['.basename(__FILE__).':'.__LINE__.'] because cannot include "module.audio-video.riff.php"');
+ break;
+ }
+ $parsed = getid3_riff::ParseBITMAPINFOHEADER($trackarray['CodecPrivate']);
+ $track_info['codec'] = getid3_riff::RIFFfourccLookup($parsed['fourcc']);
+ $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $parsed;
+ break;
+ }
+
+ $info['video']['streams'][] = $track_info;
+ break;
+
+ case 2: // Audio
+ $track_info['sample_rate'] = (isset($trackarray['SamplingFrequency']) ? $trackarray['SamplingFrequency'] : 8000.0);
+ $track_info['channels'] = (isset($trackarray['Channels']) ? $trackarray['Channels'] : 1);
+ $track_info['language'] = (isset($trackarray['Language']) ? $trackarray['Language'] : 'eng');
+ if (isset($trackarray['BitDepth'])) { $track_info['bits_per_sample'] = $trackarray['BitDepth']; }
+ //if (isset($trackarray['CodecName'])) { $track_info['codec'] = $trackarray['CodecName']; }
+
+ switch ($trackarray['CodecID']) {
+ case 'A_PCM/INT/LIT':
+ case 'A_PCM/INT/BIG':
+ $track_info['bitrate'] = $trackarray['SamplingFrequency'] * $trackarray['Channels'] * $trackarray['BitDepth'];
+ break;
+
+ case 'A_AC3':
+ case 'A_DTS':
+ case 'A_MPEG/L3':
+ //case 'A_FLAC':
+ if (!getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.'.$track_info['dataformat'].'.php', __FILE__, false)) {
+ $this->getid3->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because cannot include "module.audio.'.$track_info['dataformat'].'.php"');
+ break;
+ }
+
+ if (!isset($info['matroska']['track_data_offsets'][$trackarray['TrackNumber']])) {
+ $this->getid3->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because $info[matroska][track_data_offsets]['.$trackarray['TrackNumber'].'] not set');
+ break;
+ }
+
+ // create temp instance
+ $getid3_temp = new getID3();
+ $getid3_temp->openfile($this->getid3->filename);
+ $getid3_temp->info['avdataoffset'] = $info['matroska']['track_data_offsets'][$trackarray['TrackNumber']]['offset'];
+ if ($track_info['dataformat'] == 'mp3' || $track_info['dataformat'] == 'flac') {
+ $getid3_temp->info['avdataend'] = $info['matroska']['track_data_offsets'][$trackarray['TrackNumber']]['offset'] + $info['matroska']['track_data_offsets'][$trackarray['TrackNumber']]['length'];
+ }
+
+ // analyze
+ $class = 'getid3_'.$track_info['dataformat'];
+ $header_data_key = $track_info['dataformat'] == 'mp3' ? 'mpeg' : $track_info['dataformat'];
+ $getid3_audio = new $class($getid3_temp);
+ if ($track_info['dataformat'] == 'mp3') {
+ $getid3_audio->allow_bruteforce = true;
+ }
+ if ($track_info['dataformat'] == 'flac') {
+ $getid3_audio->AnalyzeString($trackarray['CodecPrivate']);
+ }
+ else {
+ $getid3_audio->Analyze();
+ }
+ if (!empty($getid3_temp->info[$header_data_key])) {
+ unset($getid3_temp->info[$header_data_key]['GETID3_VERSION']);
+ $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $getid3_temp->info[$header_data_key];
+ if (isset($getid3_temp->info['audio']) && is_array($getid3_temp->info['audio'])) {
+ foreach ($getid3_temp->info['audio'] as $key => $value) {
+ $track_info[$key] = $value;
+ }
+ }
+ }
+ else {
+ $this->getid3->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because '.$class.'::Analyze() failed at offset '.$getid3_temp->info['avdataoffset']);
+ }
+
+ // copy errors and warnings
+ if (!empty($getid3_temp->info['error'])) {
+ foreach ($getid3_temp->info['error'] as $newerror) {
+ $this->getid3->warning($class.'() says: ['.$newerror.']');
+ }
+ }
+ if (!empty($getid3_temp->info['warning'])) {
+ foreach ($getid3_temp->info['warning'] as $newerror) {
+ if ($track_info['dataformat'] == 'mp3' && preg_match('/^Probable truncated file: expecting \d+ bytes of audio data, only found \d+ \(short by \d+ bytes\)$/', $newerror)) {
+ // LAME/Xing header is probably set, but audio data is chunked into Matroska file and near-impossible to verify if audio stream is complete, so ignore useless warning
+ continue;
+ }
+ $this->getid3->warning($class.'() says: ['.$newerror.']');
+ }
+ }
+ unset($getid3_temp, $getid3_audio);
+ break;
+
+ case 'A_AAC':
+ case 'A_AAC/MPEG2/LC':
+ case 'A_AAC/MPEG4/LC':
+ case 'A_AAC/MPEG4/LC/SBR':
+ $this->getid3->warning($trackarray['CodecID'].' audio data contains no header, audio/video bitrates can\'t be calculated');
+ break;
+
+ case 'A_VORBIS':
+ if (!isset($trackarray['CodecPrivate'])) {
+ $this->getid3->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because CodecPrivate data not set');
+ break;
+ }
+ $vorbis_offset = strpos($trackarray['CodecPrivate'], 'vorbis', 1);
+ if ($vorbis_offset === false) {
+ $this->getid3->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because CodecPrivate data does not contain "vorbis" keyword');
+ break;
+ }
+ $vorbis_offset -= 1;
+
+ if (!getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.ogg.php', __FILE__, false)) {
+ $this->getid3->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because cannot include "module.audio.ogg.php"');
+ }
+
+ // create temp instance
+ $getid3_temp = new getID3();
+ $getid3_temp->openfile($this->getid3->filename);
+
+ // analyze
+ $getid3_ogg = new getid3_ogg($getid3_temp);
+ $oggpageinfo['page_seqno'] = 0;
+ $getid3_ogg->ParseVorbisPageHeader($trackarray['CodecPrivate'], $vorbis_offset, $oggpageinfo);
+ if (!empty($getid3_temp->info['ogg'])) {
+ $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $getid3_temp->info['ogg'];
+ if (isset($getid3_temp->info['audio']) && is_array($getid3_temp->info['audio'])) {
+ foreach ($getid3_temp->info['audio'] as $key => $value) {
+ $track_info[$key] = $value;
+ }
+ }
+ }
+
+ // copy errors and warnings
+ if (!empty($getid3_temp->info['error'])) {
+ foreach ($getid3_temp->info['error'] as $newerror) {
+ $this->getid3->warning('getid3_ogg() says: ['.$newerror.']');
+ }
+ }
+ if (!empty($getid3_temp->info['warning'])) {
+ foreach ($getid3_temp->info['warning'] as $newerror) {
+ $this->getid3->warning('getid3_ogg() says: ['.$newerror.']');
+ }
+ }
+
+ if (!empty($getid3_temp->info['ogg']['bitrate_nominal'])) {
+ $track_info['bitrate'] = $getid3_temp->info['ogg']['bitrate_nominal'];
+ }
+ unset($getid3_temp, $getid3_ogg, $oggpageinfo, $vorbis_offset);
+ break;
+
+ case 'A_MS/ACM':
+ if (!getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, false)) {
+ $this->getid3->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because cannot include "module.audio-video.riff.php"');
+ break;
+ }
+
+ $parsed = getid3_riff::RIFFparseWAVEFORMATex($trackarray['CodecPrivate']);
+ foreach ($parsed as $key => $value) {
+ if ($key != 'raw') {
+ $track_info[$key] = $value;
+ }
+ }
+ $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $parsed;
+ break;
+
+ default:
+ $this->getid3->warning('Unhandled audio type "'.(isset($trackarray['CodecID']) ? $trackarray['CodecID'] : '').'"');
+ }
+
+ $info['audio']['streams'][] = $track_info;
+ break;
+ }
+ }
+
+ if (!empty($info['video']['streams'])) {
+ $info['video'] = self::getDefaultStreamInfo($info['video']['streams']);
+ }
+ if (!empty($info['audio']['streams'])) {
+ $info['audio'] = self::getDefaultStreamInfo($info['audio']['streams']);
+ }
+ }
+
+ // determine mime type
+ if (!empty($info['video']['streams'])) {
+ $info['mime_type'] = ($info['matroska']['doctype'] == 'webm' ? 'video/webm' : 'video/x-matroska');
+ } elseif (!empty($info['audio']['streams'])) {
+ $info['mime_type'] = ($info['matroska']['doctype'] == 'webm' ? 'audio/webm' : 'audio/x-matroska');
+ } elseif (isset($info['mime_type'])) {
+ unset($info['mime_type']);
+ }
+
+ return true;
+ }
+
+
+///////////////////////////////////////
+
+ private function parseEBML(&$info)
+ {
+ // http://www.matroska.org/technical/specs/index.html#EBMLBasics
+ $this->current_offset = $info['avdataoffset'];
+
+ while ($this->getEBMLelement($top_element, $info['avdataend'])) {
+ switch ($top_element['id']) {
+
+ case EBML_ID_EBML:
+ $info['fileformat'] = 'matroska';
+ $info['matroska']['header']['offset'] = $top_element['offset'];
+ $info['matroska']['header']['length'] = $top_element['length'];
+
+ while ($this->getEBMLelement($element_data, $top_element['end'], true)) {
+ switch ($element_data['id']) {
+
+ case EBML_ID_EBMLVERSION:
+ case EBML_ID_EBMLREADVERSION:
+ case EBML_ID_EBMLMAXIDLENGTH:
+ case EBML_ID_EBMLMAXSIZELENGTH:
+ case EBML_ID_DOCTYPEVERSION:
+ case EBML_ID_DOCTYPEREADVERSION:
+ $element_data['data'] = getid3_lib::BigEndian2Int($element_data['data']);
+ break;
+
+ case EBML_ID_DOCTYPE:
+ $element_data['data'] = getid3_lib::trimNullByte($element_data['data']);
+ $info['matroska']['doctype'] = $element_data['data'];
+ break;
+
+ case EBML_ID_CRC32: // not useful, ignore
+ $this->current_offset = $element_data['end'];
+ unset($element_data);
+ break;
+
+ default:
+ $this->unhandledElement('header', __LINE__, $element_data);
+ }
+ if (!empty($element_data)) {
+ unset($element_data['offset'], $element_data['end']);
+ $info['matroska']['header']['elements'][] = $element_data;
+ }
+ }
+ break;
+
+ case EBML_ID_SEGMENT:
+ $info['matroska']['segment'][0]['offset'] = $top_element['offset'];
+ $info['matroska']['segment'][0]['length'] = $top_element['length'];
+
+ while ($this->getEBMLelement($element_data, $top_element['end'])) {
+ if ($element_data['id'] != EBML_ID_CLUSTER || !self::$hide_clusters) { // collect clusters only if required
+ $info['matroska']['segments'][] = $element_data;
+ }
+ switch ($element_data['id']) {
+
+ case EBML_ID_SEEKHEAD: // Contains the position of other level 1 elements.
+
+ while ($this->getEBMLelement($seek_entry, $element_data['end'])) {
+ switch ($seek_entry['id']) {
+
+ case EBML_ID_SEEK: // Contains a single seek entry to an EBML element
+ while ($this->getEBMLelement($sub_seek_entry, $seek_entry['end'], true)) {
+
+ switch ($sub_seek_entry['id']) {
+
+ case EBML_ID_SEEKID:
+ $seek_entry['target_id'] = self::EBML2Int($sub_seek_entry['data']);
+ $seek_entry['target_name'] = self::EBMLidName($seek_entry['target_id']);
+ break;
+
+ case EBML_ID_SEEKPOSITION:
+ $seek_entry['target_offset'] = $element_data['offset'] + getid3_lib::BigEndian2Int($sub_seek_entry['data']);
+ break;
+
+ default:
+ $this->unhandledElement('seekhead.seek', __LINE__, $sub_seek_entry); }
+ }
+
+ if ($seek_entry['target_id'] != EBML_ID_CLUSTER || !self::$hide_clusters) { // collect clusters only if required
+ $info['matroska']['seek'][] = $seek_entry;
+ }
+ break;
+
+ default:
+ $this->unhandledElement('seekhead', __LINE__, $seek_entry);
+ }
+ }
+ break;
+
+ case EBML_ID_TRACKS: // A top-level block of information with many tracks described.
+ $info['matroska']['tracks'] = $element_data;
+
+ while ($this->getEBMLelement($track_entry, $element_data['end'])) {
+ switch ($track_entry['id']) {
+
+ case EBML_ID_TRACKENTRY: //subelements: Describes a track with all elements.
+
+ while ($this->getEBMLelement($subelement, $track_entry['end'], array(EBML_ID_VIDEO, EBML_ID_AUDIO, EBML_ID_CONTENTENCODINGS))) {
+ switch ($subelement['id']) {
+
+ case EBML_ID_TRACKNUMBER:
+ case EBML_ID_TRACKUID:
+ case EBML_ID_TRACKTYPE:
+ case EBML_ID_MINCACHE:
+ case EBML_ID_MAXCACHE:
+ case EBML_ID_MAXBLOCKADDITIONID:
+ case EBML_ID_DEFAULTDURATION: // nanoseconds per frame
+ $track_entry[$subelement['id_name']] = getid3_lib::BigEndian2Int($subelement['data']);
+ break;
+
+ case EBML_ID_TRACKTIMECODESCALE:
+ $track_entry[$subelement['id_name']] = getid3_lib::BigEndian2Float($subelement['data']);
+ break;
+
+ case EBML_ID_CODECID:
+ case EBML_ID_LANGUAGE:
+ case EBML_ID_NAME:
+ case EBML_ID_CODECNAME:
+ $track_entry[$subelement['id_name']] = getid3_lib::trimNullByte($subelement['data']);
+ break;
+
+ case EBML_ID_CODECPRIVATE:
+ $track_entry[$subelement['id_name']] = $subelement['data'];
+ break;
+
+ case EBML_ID_FLAGENABLED:
+ case EBML_ID_FLAGDEFAULT:
+ case EBML_ID_FLAGFORCED:
+ case EBML_ID_FLAGLACING:
+ case EBML_ID_CODECDECODEALL:
+ $track_entry[$subelement['id_name']] = (bool) getid3_lib::BigEndian2Int($subelement['data']);
+ break;
+
+ case EBML_ID_VIDEO:
+
+ while ($this->getEBMLelement($sub_subelement, $subelement['end'], true)) {
+ switch ($sub_subelement['id']) {
+
+ case EBML_ID_PIXELWIDTH:
+ case EBML_ID_PIXELHEIGHT:
+ case EBML_ID_STEREOMODE:
+ case EBML_ID_PIXELCROPBOTTOM:
+ case EBML_ID_PIXELCROPTOP:
+ case EBML_ID_PIXELCROPLEFT:
+ case EBML_ID_PIXELCROPRIGHT:
+ case EBML_ID_DISPLAYWIDTH:
+ case EBML_ID_DISPLAYHEIGHT:
+ case EBML_ID_DISPLAYUNIT:
+ case EBML_ID_ASPECTRATIOTYPE:
+ $track_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']);
+ break;
+
+ case EBML_ID_FLAGINTERLACED:
+ $track_entry[$sub_subelement['id_name']] = (bool)getid3_lib::BigEndian2Int($sub_subelement['data']);
+ break;
+
+ case EBML_ID_GAMMAVALUE:
+ $track_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Float($sub_subelement['data']);
+ break;
+
+ case EBML_ID_COLOURSPACE:
+ $track_entry[$sub_subelement['id_name']] = getid3_lib::trimNullByte($sub_subelement['data']);
+ break;
+
+ default:
+ $this->unhandledElement('track.video', __LINE__, $sub_subelement);
+ }
+ }
+ break;
+
+ case EBML_ID_AUDIO:
+
+ while ($this->getEBMLelement($sub_subelement, $subelement['end'], true)) {
+ switch ($sub_subelement['id']) {
+
+ case EBML_ID_CHANNELS:
+ case EBML_ID_BITDEPTH:
+ $track_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']);
+ break;
+
+ case EBML_ID_SAMPLINGFREQUENCY:
+ case EBML_ID_OUTPUTSAMPLINGFREQUENCY:
+ $track_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Float($sub_subelement['data']);
+ break;
+
+ case EBML_ID_CHANNELPOSITIONS:
+ $track_entry[$sub_subelement['id_name']] = getid3_lib::trimNullByte($sub_subelement['data']);
+ break;
+
+ default:
+ $this->unhandledElement('track.audio', __LINE__, $sub_subelement);
+ }
+ }
+ break;
+
+ case EBML_ID_CONTENTENCODINGS:
+
+ while ($this->getEBMLelement($sub_subelement, $subelement['end'])) {
+ switch ($sub_subelement['id']) {
+
+ case EBML_ID_CONTENTENCODING:
+
+ while ($this->getEBMLelement($sub_sub_subelement, $sub_subelement['end'], array(EBML_ID_CONTENTCOMPRESSION, EBML_ID_CONTENTENCRYPTION))) {
+ switch ($sub_sub_subelement['id']) {
+
+ case EBML_ID_CONTENTENCODINGORDER:
+ case EBML_ID_CONTENTENCODINGSCOPE:
+ case EBML_ID_CONTENTENCODINGTYPE:
+ $track_entry[$sub_subelement['id_name']][$sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_subelement['data']);
+ break;
+
+ case EBML_ID_CONTENTCOMPRESSION:
+
+ while ($this->getEBMLelement($sub_sub_sub_subelement, $sub_sub_subelement['end'], true)) {
+ switch ($sub_sub_sub_subelement['id']) {
+
+ case EBML_ID_CONTENTCOMPALGO:
+ $track_entry[$sub_subelement['id_name']][$sub_sub_subelement['id_name']][$sub_sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_sub_subelement['data']);
+ break;
+
+ case EBML_ID_CONTENTCOMPSETTINGS:
+ $track_entry[$sub_subelement['id_name']][$sub_sub_subelement['id_name']][$sub_sub_sub_subelement['id_name']] = $sub_sub_sub_subelement['data'];
+ break;
+
+ default:
+ $this->unhandledElement('track.contentencodings.contentencoding.contentcompression', __LINE__, $sub_sub_sub_subelement);
+ }
+ }
+ break;
+
+ case EBML_ID_CONTENTENCRYPTION:
+
+ while ($this->getEBMLelement($sub_sub_sub_subelement, $sub_sub_subelement['end'], true)) {
+ switch ($sub_sub_sub_subelement['id']) {
+
+ case EBML_ID_CONTENTENCALGO:
+ case EBML_ID_CONTENTSIGALGO:
+ case EBML_ID_CONTENTSIGHASHALGO:
+ $track_entry[$sub_subelement['id_name']][$sub_sub_subelement['id_name']][$sub_sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_sub_subelement['data']);
+ break;
+
+ case EBML_ID_CONTENTENCKEYID:
+ case EBML_ID_CONTENTSIGNATURE:
+ case EBML_ID_CONTENTSIGKEYID:
+ $track_entry[$sub_subelement['id_name']][$sub_sub_subelement['id_name']][$sub_sub_sub_subelement['id_name']] = $sub_sub_sub_subelement['data'];
+ break;
+
+ default:
+ $this->unhandledElement('track.contentencodings.contentencoding.contentcompression', __LINE__, $sub_sub_sub_subelement);
+ }
+ }
+ break;
+
+ default:
+ $this->unhandledElement('track.contentencodings.contentencoding', __LINE__, $sub_sub_subelement);
+ }
+ }
+ break;
+
+ default:
+ $this->unhandledElement('track.contentencodings', __LINE__, $sub_subelement);
+ }
+ }
+ break;
+
+ default:
+ $this->unhandledElement('track', __LINE__, $subelement);
+ }
+ }
+
+ $info['matroska']['tracks']['tracks'][] = $track_entry;
+ break;
+
+ default:
+ $this->unhandledElement('tracks', __LINE__, $track_entry);
+ }
+ }
+ break;
+
+ case EBML_ID_INFO: // Contains miscellaneous general information and statistics on the file.
+ $info_entry = array();
+
+ while ($this->getEBMLelement($subelement, $element_data['end'], true)) {
+ switch ($subelement['id']) {
+
+ case EBML_ID_CHAPTERTRANSLATEEDITIONUID:
+ case EBML_ID_CHAPTERTRANSLATECODEC:
+ case EBML_ID_TIMECODESCALE:
+ $info_entry[$subelement['id_name']] = getid3_lib::BigEndian2Int($subelement['data']);
+ break;
+
+ case EBML_ID_DURATION:
+ $info_entry[$subelement['id_name']] = getid3_lib::BigEndian2Float($subelement['data']);
+ break;
+
+ case EBML_ID_DATEUTC:
+ $info_entry[$subelement['id_name']] = getid3_lib::BigEndian2Int($subelement['data']);
+ $info_entry[$subelement['id_name'].'_unix'] = self::EBMLdate2unix($info_entry[$subelement['id_name']]);
+ break;
+
+ case EBML_ID_SEGMENTUID:
+ case EBML_ID_PREVUID:
+ case EBML_ID_NEXTUID:
+ case EBML_ID_SEGMENTFAMILY:
+ case EBML_ID_CHAPTERTRANSLATEID:
+ $info_entry[$subelement['id_name']] = getid3_lib::trimNullByte($subelement['data']);
+ break;
+
+ case EBML_ID_SEGMENTFILENAME:
+ case EBML_ID_PREVFILENAME:
+ case EBML_ID_NEXTFILENAME:
+ case EBML_ID_TITLE:
+ case EBML_ID_MUXINGAPP:
+ case EBML_ID_WRITINGAPP:
+ $info_entry[$subelement['id_name']] = getid3_lib::trimNullByte($subelement['data']);
+ $info['matroska']['comments'][strtolower($subelement['id_name'])][] = $info_entry[$subelement['id_name']];
+ break;
+
+ default:
+ $this->unhandledElement('info', __LINE__, $subelement);
+ }
+ }
+ $info['matroska']['info'][] = $info_entry;
+ break;
+
+ case EBML_ID_CUES: // A top-level element to speed seeking access. All entries are local to the segment. Should be mandatory for non "live" streams.
+ if (self::$hide_clusters) { // do not parse cues if hide clusters is "ON" till they point to clusters anyway
+ $this->current_offset = $element_data['end'];
+ break;
+ }
+ $cues_entry = array();
+
+ while ($this->getEBMLelement($subelement, $element_data['end'])) {
+ switch ($subelement['id']) {
+
+ case EBML_ID_CUEPOINT:
+ $cuepoint_entry = array();
+
+ while ($this->getEBMLelement($sub_subelement, $subelement['end'], array(EBML_ID_CUETRACKPOSITIONS))) {
+ switch ($sub_subelement['id']) {
+
+ case EBML_ID_CUETRACKPOSITIONS:
+ $cuetrackpositions_entry = array();
+
+ while ($this->getEBMLelement($sub_sub_subelement, $sub_subelement['end'], true)) {
+ switch ($sub_sub_subelement['id']) {
+
+ case EBML_ID_CUETRACK:
+ case EBML_ID_CUECLUSTERPOSITION:
+ case EBML_ID_CUEBLOCKNUMBER:
+ case EBML_ID_CUECODECSTATE:
+ $cuetrackpositions_entry[$sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_subelement['data']);
+ break;
+
+ default:
+ $this->unhandledElement('cues.cuepoint.cuetrackpositions', __LINE__, $sub_sub_subelement);
+ }
+ }
+ $cuepoint_entry[$sub_subelement['id_name']][] = $cuetrackpositions_entry;
+ break;
+
+ case EBML_ID_CUETIME:
+ $cuepoint_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']);
+ break;
+
+ default:
+ $this->unhandledElement('cues.cuepoint', __LINE__, $sub_subelement);
+ }
+ }
+ $cues_entry[] = $cuepoint_entry;
+ break;
+
+ default:
+ $this->unhandledElement('cues', __LINE__, $subelement);
+ }
+ }
+ $info['matroska']['cues'] = $cues_entry;
+ break;
+
+ case EBML_ID_TAGS: // Element containing elements specific to Tracks/Chapters.
+ $tags_entry = array();
+
+ while ($this->getEBMLelement($subelement, $element_data['end'], false)) {
+ switch ($subelement['id']) {
+
+ case EBML_ID_TAG:
+ $tag_entry = array();
+
+ while ($this->getEBMLelement($sub_subelement, $subelement['end'], false)) {
+ switch ($sub_subelement['id']) {
+
+ case EBML_ID_TARGETS:
+ $targets_entry = array();
+
+ while ($this->getEBMLelement($sub_sub_subelement, $sub_subelement['end'], true)) {
+ switch ($sub_sub_subelement['id']) {
+
+ case EBML_ID_TARGETTYPEVALUE:
+ $targets_entry[$sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_subelement['data']);
+ $targets_entry[strtolower($sub_sub_subelement['id_name']).'_long'] = self::MatroskaTargetTypeValue($targets_entry[$sub_sub_subelement['id_name']]);
+ break;
+
+ case EBML_ID_TARGETTYPE:
+ $targets_entry[$sub_sub_subelement['id_name']] = $sub_sub_subelement['data'];
+ break;
+
+ case EBML_ID_TAGTRACKUID:
+ case EBML_ID_TAGEDITIONUID:
+ case EBML_ID_TAGCHAPTERUID:
+ case EBML_ID_TAGATTACHMENTUID:
+ $targets_entry[$sub_sub_subelement['id_name']][] = getid3_lib::BigEndian2Int($sub_sub_subelement['data']);
+ break;
+
+ default:
+ $this->unhandledElement('tags.tag.targets', __LINE__, $sub_sub_subelement);
+ }
+ }
+ $tag_entry[$sub_subelement['id_name']] = $targets_entry;
+ break;
+
+ case EBML_ID_SIMPLETAG:
+ $tag_entry[$sub_subelement['id_name']][] = $this->HandleEMBLSimpleTag($sub_subelement['end']);
+ break;
+
+ default:
+ $this->unhandledElement('tags.tag', __LINE__, $sub_subelement);
+ }
+ }
+ $tags_entry[] = $tag_entry;
+ break;
+
+ default:
+ $this->unhandledElement('tags', __LINE__, $subelement);
+ }
+ }
+ $info['matroska']['tags'] = $tags_entry;
+ break;
+
+ case EBML_ID_ATTACHMENTS: // Contain attached files.
+
+ while ($this->getEBMLelement($subelement, $element_data['end'])) {
+ switch ($subelement['id']) {
+
+ case EBML_ID_ATTACHEDFILE:
+ $attachedfile_entry = array();
+
+ while ($this->getEBMLelement($sub_subelement, $subelement['end'], array(EBML_ID_FILEDATA))) {
+ switch ($sub_subelement['id']) {
+
+ case EBML_ID_FILEDESCRIPTION:
+ case EBML_ID_FILENAME:
+ case EBML_ID_FILEMIMETYPE:
+ $attachedfile_entry[$sub_subelement['id_name']] = $sub_subelement['data'];
+ break;
+
+ case EBML_ID_FILEDATA:
+ $attachedfile_entry['data_offset'] = $this->current_offset;
+ $attachedfile_entry['data_length'] = $sub_subelement['length'];
+
+ $this->getid3->saveAttachment(
+ $attachedfile_entry[$sub_subelement['id_name']],
+ $attachedfile_entry['FileName'],
+ $attachedfile_entry['data_offset'],
+ $attachedfile_entry['data_length']);
+
+ if (@$attachedfile_entry[$sub_subelement['id_name']] && is_file($attachedfile_entry[$sub_subelement['id_name']])) {
+ $attachedfile_entry[$sub_subelement['id_name'].'_filename'] = $attachedfile_entry[$sub_subelement['id_name']];
+ unset($attachedfile_entry[$sub_subelement['id_name']]);
+ }
+
+ $this->current_offset = $sub_subelement['end'];
+ break;
+
+ case EBML_ID_FILEUID:
+ $attachedfile_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']);
+ break;
+
+ default:
+ $this->unhandledElement('attachments.attachedfile', __LINE__, $sub_subelement);
+ }
+ }
+ if (!empty($attachedfile_entry['FileData']) && !empty($attachedfile_entry['FileMimeType']) && preg_match('#^image/#i', $attachedfile_entry['FileMimeType'])) {
+ if ($this->getid3->option_save_attachments === getID3::ATTACHMENTS_INLINE) {
+ $attachedfile_entry['data'] = $attachedfile_entry['FileData'];
+ $attachedfile_entry['image_mime'] = $attachedfile_entry['FileMimeType'];
+ $info['matroska']['comments']['picture'][] = array('data' => $attachedfile_entry['data'], 'image_mime' => $attachedfile_entry['image_mime'], 'filename' => (!empty($attachedfile_entry['FileName']) ? $attachedfile_entry['FileName'] : ''));
+ unset($attachedfile_entry['FileData'], $attachedfile_entry['FileMimeType']);
+ }
+ }
+ if (!empty($attachedfile_entry['image_mime']) && preg_match('#^image/#i', $attachedfile_entry['image_mime'])) {
+ // don't add a second copy of attached images, which are grouped under the standard location [comments][picture]
+ } else {
+ $info['matroska']['attachments'][] = $attachedfile_entry;
+ }
+ break;
+
+ default:
+ $this->unhandledElement('attachments', __LINE__, $subelement);
+ }
+ }
+ break;
+
+ case EBML_ID_CHAPTERS:
+
+ while ($this->getEBMLelement($subelement, $element_data['end'])) {
+ switch ($subelement['id']) {
+
+ case EBML_ID_EDITIONENTRY:
+ $editionentry_entry = array();
+
+ while ($this->getEBMLelement($sub_subelement, $subelement['end'], array(EBML_ID_CHAPTERATOM))) {
+ switch ($sub_subelement['id']) {
+
+ case EBML_ID_EDITIONUID:
+ $editionentry_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']);
+ break;
+
+ case EBML_ID_EDITIONFLAGHIDDEN:
+ case EBML_ID_EDITIONFLAGDEFAULT:
+ case EBML_ID_EDITIONFLAGORDERED:
+ $editionentry_entry[$sub_subelement['id_name']] = (bool)getid3_lib::BigEndian2Int($sub_subelement['data']);
+ break;
+
+ case EBML_ID_CHAPTERATOM:
+ $chapteratom_entry = array();
+
+ while ($this->getEBMLelement($sub_sub_subelement, $sub_subelement['end'], array(EBML_ID_CHAPTERTRACK, EBML_ID_CHAPTERDISPLAY))) {
+ switch ($sub_sub_subelement['id']) {
+
+ case EBML_ID_CHAPTERSEGMENTUID:
+ case EBML_ID_CHAPTERSEGMENTEDITIONUID:
+ $chapteratom_entry[$sub_sub_subelement['id_name']] = $sub_sub_subelement['data'];
+ break;
+
+ case EBML_ID_CHAPTERFLAGENABLED:
+ case EBML_ID_CHAPTERFLAGHIDDEN:
+ $chapteratom_entry[$sub_sub_subelement['id_name']] = (bool)getid3_lib::BigEndian2Int($sub_sub_subelement['data']);
+ break;
+
+ case EBML_ID_CHAPTERUID:
+ case EBML_ID_CHAPTERTIMESTART:
+ case EBML_ID_CHAPTERTIMEEND:
+ $chapteratom_entry[$sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_subelement['data']);
+ break;
+
+ case EBML_ID_CHAPTERTRACK:
+ $chaptertrack_entry = array();
+
+ while ($this->getEBMLelement($sub_sub_sub_subelement, $sub_sub_subelement['end'], true)) {
+ switch ($sub_sub_sub_subelement['id']) {
+
+ case EBML_ID_CHAPTERTRACKNUMBER:
+ $chaptertrack_entry[$sub_sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_sub_subelement['data']);
+ break;
+
+ default:
+ $this->unhandledElement('chapters.editionentry.chapteratom.chaptertrack', __LINE__, $sub_sub_sub_subelement);
+ }
+ }
+ $chapteratom_entry[$sub_sub_subelement['id_name']][] = $chaptertrack_entry;
+ break;
+
+ case EBML_ID_CHAPTERDISPLAY:
+ $chapterdisplay_entry = array();
+
+ while ($this->getEBMLelement($sub_sub_sub_subelement, $sub_sub_subelement['end'], true)) {
+ switch ($sub_sub_sub_subelement['id']) {
+
+ case EBML_ID_CHAPSTRING:
+ case EBML_ID_CHAPLANGUAGE:
+ case EBML_ID_CHAPCOUNTRY:
+ $chapterdisplay_entry[$sub_sub_sub_subelement['id_name']] = $sub_sub_sub_subelement['data'];
+ break;
+
+ default:
+ $this->unhandledElement('chapters.editionentry.chapteratom.chapterdisplay', __LINE__, $sub_sub_sub_subelement);
+ }
+ }
+ $chapteratom_entry[$sub_sub_subelement['id_name']][] = $chapterdisplay_entry;
+ break;
+
+ default:
+ $this->unhandledElement('chapters.editionentry.chapteratom', __LINE__, $sub_sub_subelement);
+ }
+ }
+ $editionentry_entry[$sub_subelement['id_name']][] = $chapteratom_entry;
+ break;
+
+ default:
+ $this->unhandledElement('chapters.editionentry', __LINE__, $sub_subelement);
+ }
+ }
+ $info['matroska']['chapters'][] = $editionentry_entry;
+ break;
+
+ default:
+ $this->unhandledElement('chapters', __LINE__, $subelement);
+ }
+ }
+ break;
+
+ case EBML_ID_CLUSTER: // The lower level element containing the (monolithic) Block structure.
+ $cluster_entry = array();
+
+ while ($this->getEBMLelement($subelement, $element_data['end'], array(EBML_ID_CLUSTERSILENTTRACKS, EBML_ID_CLUSTERBLOCKGROUP, EBML_ID_CLUSTERSIMPLEBLOCK))) {
+ switch ($subelement['id']) {
+
+ case EBML_ID_CLUSTERTIMECODE:
+ case EBML_ID_CLUSTERPOSITION:
+ case EBML_ID_CLUSTERPREVSIZE:
+ $cluster_entry[$subelement['id_name']] = getid3_lib::BigEndian2Int($subelement['data']);
+ break;
+
+ case EBML_ID_CLUSTERSILENTTRACKS:
+ $cluster_silent_tracks = array();
+
+ while ($this->getEBMLelement($sub_subelement, $subelement['end'], true)) {
+ switch ($sub_subelement['id']) {
+
+ case EBML_ID_CLUSTERSILENTTRACKNUMBER:
+ $cluster_silent_tracks[] = getid3_lib::BigEndian2Int($sub_subelement['data']);
+ break;
+
+ default:
+ $this->unhandledElement('cluster.silenttracks', __LINE__, $sub_subelement);
+ }
+ }
+ $cluster_entry[$subelement['id_name']][] = $cluster_silent_tracks;
+ break;
+
+ case EBML_ID_CLUSTERBLOCKGROUP:
+ $cluster_block_group = array('offset' => $this->current_offset);
+
+ while ($this->getEBMLelement($sub_subelement, $subelement['end'], array(EBML_ID_CLUSTERBLOCK))) {
+ switch ($sub_subelement['id']) {
+
+ case EBML_ID_CLUSTERBLOCK:
+ $cluster_block_group[$sub_subelement['id_name']] = $this->HandleEMBLClusterBlock($sub_subelement, EBML_ID_CLUSTERBLOCK, $info);
+ break;
+
+ case EBML_ID_CLUSTERREFERENCEPRIORITY: // unsigned-int
+ case EBML_ID_CLUSTERBLOCKDURATION: // unsigned-int
+ $cluster_block_group[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']);
+ break;
+
+ case EBML_ID_CLUSTERREFERENCEBLOCK: // signed-int
+ $cluster_block_group[$sub_subelement['id_name']][] = getid3_lib::BigEndian2Int($sub_subelement['data'], false, true);
+ break;
+
+ case EBML_ID_CLUSTERCODECSTATE:
+ $cluster_block_group[$sub_subelement['id_name']] = getid3_lib::trimNullByte($sub_subelement['data']);
+ break;
+
+ default:
+ $this->unhandledElement('clusters.blockgroup', __LINE__, $sub_subelement);
+ }
+ }
+ $cluster_entry[$subelement['id_name']][] = $cluster_block_group;
+ break;
+
+ case EBML_ID_CLUSTERSIMPLEBLOCK:
+ $cluster_entry[$subelement['id_name']][] = $this->HandleEMBLClusterBlock($subelement, EBML_ID_CLUSTERSIMPLEBLOCK, $info);
+ break;
+
+ default:
+ $this->unhandledElement('cluster', __LINE__, $subelement);
+ }
+ $this->current_offset = $subelement['end'];
+ }
+ if (!self::$hide_clusters) {
+ $info['matroska']['cluster'][] = $cluster_entry;
+ }
+
+ // check to see if all the data we need exists already, if so, break out of the loop
+ if (!self::$parse_whole_file) {
+ if (isset($info['matroska']['info']) && is_array($info['matroska']['info'])) {
+ if (isset($info['matroska']['tracks']['tracks']) && is_array($info['matroska']['tracks']['tracks'])) {
+ return;
+ }
+ }
+ }
+ break;
+
+ default:
+ $this->unhandledElement('segment', __LINE__, $element_data);
+ }
+ }
+ break;
+
+ default:
+ $this->unhandledElement('root', __LINE__, $top_element);
+ }
+ }
+ }
+
+ private function EnsureBufferHasEnoughData($min_data = 1024)
+ {
+ if (($this->current_offset - $this->EBMLbuffer_offset) >= ($this->EBMLbuffer_length - $min_data)) {
+
+ if (!getid3_lib::intValueSupported($this->current_offset + $this->getid3->fread_buffer_size())) {
+ $this->getid3->info['error'][] = 'EBML parser: cannot read past '.$this->current_offset;
+ return false;
+ }
+
+ fseek($this->getid3->fp, $this->current_offset, SEEK_SET);
+ $this->EBMLbuffer_offset = $this->current_offset;
+ $this->EBMLbuffer = fread($this->getid3->fp, max($min_data, $this->getid3->fread_buffer_size()));
+ $this->EBMLbuffer_length = strlen($this->EBMLbuffer);
+
+ if ($this->EBMLbuffer_length == 0 && feof($this->getid3->fp)) {
+ $this->getid3->info['error'][] = 'EBML parser: ran out of file at offset '.$this->current_offset;
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ private function readEBMLint()
+ {
+ $actual_offset = $this->current_offset - $this->EBMLbuffer_offset;
+
+ // get length of integer
+ $first_byte_int = ord($this->EBMLbuffer[$actual_offset]);
+ if (0x80 & $first_byte_int) {
+ $length = 1;
+ } elseif (0x40 & $first_byte_int) {
+ $length = 2;
+ } elseif (0x20 & $first_byte_int) {
+ $length = 3;
+ } elseif (0x10 & $first_byte_int) {
+ $length = 4;
+ } elseif (0x08 & $first_byte_int) {
+ $length = 5;
+ } elseif (0x04 & $first_byte_int) {
+ $length = 6;
+ } elseif (0x02 & $first_byte_int) {
+ $length = 7;
+ } elseif (0x01 & $first_byte_int) {
+ $length = 8;
+ } else {
+ throw new Exception('invalid EBML integer (leading 0x00) at '.$this->current_offset);
+ }
+
+ // read
+ $int_value = self::EBML2Int(substr($this->EBMLbuffer, $actual_offset, $length));
+ $this->current_offset += $length;
+
+ return $int_value;
+ }
+
+ private function readEBMLelementData($length)
+ {
+ $data = substr($this->EBMLbuffer, $this->current_offset - $this->EBMLbuffer_offset, $length);
+ $this->current_offset += $length;
+
+ return $data;
+ }
+
+ private function getEBMLelement(&$element, $parent_end, $get_data = false)
+ {
+ if ($this->current_offset >= $parent_end) {
+ return false;
+ }
+
+ if (!$this->EnsureBufferHasEnoughData()) {
+ $this->current_offset = PHP_INT_MAX; // do not exit parser right now, allow to finish current loop to gather maximum information
+ return false;
+ }
+
+ $element = array();
+
+ // set offset
+ $element['offset'] = $this->current_offset;
+
+ // get ID
+ $element['id'] = $this->readEBMLint();
+
+ // get name
+ $element['id_name'] = self::EBMLidName($element['id']);
+
+ // get length
+ $element['length'] = $this->readEBMLint();
+
+ // get end offset
+ $element['end'] = $this->current_offset + $element['length'];
+
+ // get raw data
+ $dont_parse = (in_array($element['id'], $this->unuseful_elements) || $element['id_name'] == dechex($element['id']));
+ if (($get_data === true || (is_array($get_data) && !in_array($element['id'], $get_data))) && !$dont_parse) {
+ $element['data'] = $this->readEBMLelementData($element['length'], $element);
+ }
+
+ return true;
+ }
+
+ private function unhandledElement($type, $line, $element)
+ {
+ // warn only about unknown and missed elements, not about unuseful
+ if (!in_array($element['id'], $this->unuseful_elements)) {
+ $this->getid3->warning('Unhandled '.$type.' element ['.basename(__FILE__).':'.$line.'] ('.$element['id'].'::'.$element['id_name'].' ['.$element['length'].' bytes]) at '.$element['offset']);
+ }
+
+ // increase offset for unparsed elements
+ if (!isset($element['data'])) {
+ $this->current_offset = $element['end'];
+ }
+ }
+
+ private function ExtractCommentsSimpleTag($SimpleTagArray)
+ {
+ if (!empty($SimpleTagArray['SimpleTag'])) {
+ foreach ($SimpleTagArray['SimpleTag'] as $SimpleTagKey => $SimpleTagData) {
+ if (!empty($SimpleTagData['TagName']) && !empty($SimpleTagData['TagString'])) {
+ $this->getid3->info['matroska']['comments'][strtolower($SimpleTagData['TagName'])][] = $SimpleTagData['TagString'];
+ }
+ if (!empty($SimpleTagData['SimpleTag'])) {
+ $this->ExtractCommentsSimpleTag($SimpleTagData);
+ }
+ }
+ }
+
+ return true;
+ }
+
+ private function HandleEMBLSimpleTag($parent_end)
+ {
+ $simpletag_entry = array();
+
+ while ($this->getEBMLelement($element, $parent_end, array(EBML_ID_SIMPLETAG))) {
+ switch ($element['id']) {
+
+ case EBML_ID_TAGNAME:
+ case EBML_ID_TAGLANGUAGE:
+ case EBML_ID_TAGSTRING:
+ case EBML_ID_TAGBINARY:
+ $simpletag_entry[$element['id_name']] = $element['data'];
+ break;
+
+ case EBML_ID_SIMPLETAG:
+ $simpletag_entry[$element['id_name']][] = $this->HandleEMBLSimpleTag($element['end']);
+ break;
+
+ case EBML_ID_TAGDEFAULT:
+ $simpletag_entry[$element['id_name']] = (bool)getid3_lib::BigEndian2Int($element['data']);
+ break;
+
+ default:
+ $this->unhandledElement('tag.simpletag', __LINE__, $element);
+ }
+ }
+
+ return $simpletag_entry;
+ }
+
+ private function HandleEMBLClusterBlock($element, $block_type, &$info)
+ {
+ // http://www.matroska.org/technical/specs/index.html#block_structure
+ // http://www.matroska.org/technical/specs/index.html#simpleblock_structure
+
+ $cluster_block_data = array();
+ $cluster_block_data['tracknumber'] = $this->readEBMLint();
+ $cluster_block_data['timecode'] = getid3_lib::BigEndian2Int($this->readEBMLelementData(2));
+ $cluster_block_data['flags_raw'] = getid3_lib::BigEndian2Int($this->readEBMLelementData(1));
+
+ if ($block_type == EBML_ID_CLUSTERSIMPLEBLOCK) {
+ $cluster_block_data['flags']['keyframe'] = (($cluster_block_data['flags_raw'] & 0x80) >> 7);
+ //$cluster_block_data['flags']['reserved1'] = (($cluster_block_data['flags_raw'] & 0x70) >> 4);
+ }
+ else {
+ //$cluster_block_data['flags']['reserved1'] = (($cluster_block_data['flags_raw'] & 0xF0) >> 4);
+ }
+ $cluster_block_data['flags']['invisible'] = (bool)(($cluster_block_data['flags_raw'] & 0x08) >> 3);
+ $cluster_block_data['flags']['lacing'] = (($cluster_block_data['flags_raw'] & 0x06) >> 1); // 00=no lacing; 01=Xiph lacing; 11=EBML lacing; 10=fixed-size lacing
+ if ($block_type == EBML_ID_CLUSTERSIMPLEBLOCK) {
+ $cluster_block_data['flags']['discardable'] = (($cluster_block_data['flags_raw'] & 0x01));
+ }
+ else {
+ //$cluster_block_data['flags']['reserved2'] = (($cluster_block_data['flags_raw'] & 0x01) >> 0);
+ }
+ $cluster_block_data['flags']['lacing_type'] = self::MatroskaBlockLacingType($cluster_block_data['flags']['lacing']);
+
+ // Lace (when lacing bit is set)
+ if ($cluster_block_data['flags']['lacing'] > 0) {
+ $cluster_block_data['lace_frames'] = getid3_lib::BigEndian2Int($this->readEBMLelementData(1)) + 1; // Number of frames in the lace-1 (uint8)
+ if ($cluster_block_data['flags']['lacing'] != 0x02) { // Lace-coded size of each frame of the lace, except for the last one (multiple uint8). *This is not used with Fixed-size lacing as it is calculated automatically from (total size of lace) / (number of frames in lace).
+ for ($i = 1; $i < $cluster_block_data['lace_frames']; $i ++) {
+ if ($cluster_block_data['flags']['lacing'] == 0x03) { // EBML lacing
+ // TODO: read size correctly, calc size for the last frame. For now offsets are deteminded OK with readEBMLint() and that's the most important thing.
+ $cluster_block_data['lace_frames_size'][$i] = $this->readEBMLint();
+ }
+ else { // Xiph lacing
+ $cluster_block_data['lace_frames_size'][$i] = getid3_lib::BigEndian2Int($this->readEBMLelementData(1));
+ }
+ }
+ }
+ }
+
+ if (!isset($info['matroska']['track_data_offsets'][$cluster_block_data['tracknumber']])) {
+ $info['matroska']['track_data_offsets'][$cluster_block_data['tracknumber']]['offset'] = $this->current_offset;
+ $info['matroska']['track_data_offsets'][$cluster_block_data['tracknumber']]['length'] = $element['end'] - $this->current_offset;
+ }
+
+ // set offset manually
+ $this->current_offset = $element['end'];
+
+ return $cluster_block_data;
+ }
+
+ private static function EBML2Int($EBMLstring) {
+ // http://matroska.org/specs/
+
+ // Element ID coded with an UTF-8 like system:
+ // 1xxx xxxx - Class A IDs (2^7 -2 possible values) (base 0x8X)
+ // 01xx xxxx xxxx xxxx - Class B IDs (2^14-2 possible values) (base 0x4X 0xXX)
+ // 001x xxxx xxxx xxxx xxxx xxxx - Class C IDs (2^21-2 possible values) (base 0x2X 0xXX 0xXX)
+ // 0001 xxxx xxxx xxxx xxxx xxxx xxxx xxxx - Class D IDs (2^28-2 possible values) (base 0x1X 0xXX 0xXX 0xXX)
+ // Values with all x at 0 and 1 are reserved (hence the -2).
+
+ // Data size, in octets, is also coded with an UTF-8 like system :
+ // 1xxx xxxx - value 0 to 2^7-2
+ // 01xx xxxx xxxx xxxx - value 0 to 2^14-2
+ // 001x xxxx xxxx xxxx xxxx xxxx - value 0 to 2^21-2
+ // 0001 xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^28-2
+ // 0000 1xxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^35-2
+ // 0000 01xx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^42-2
+ // 0000 001x xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^49-2
+ // 0000 0001 xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^56-2
+
+ $first_byte_int = ord($EBMLstring[0]);
+ if (0x80 & $first_byte_int) {
+ $EBMLstring[0] = chr($first_byte_int & 0x7F);
+ } elseif (0x40 & $first_byte_int) {
+ $EBMLstring[0] = chr($first_byte_int & 0x3F);
+ } elseif (0x20 & $first_byte_int) {
+ $EBMLstring[0] = chr($first_byte_int & 0x1F);
+ } elseif (0x10 & $first_byte_int) {
+ $EBMLstring[0] = chr($first_byte_int & 0x0F);
+ } elseif (0x08 & $first_byte_int) {
+ $EBMLstring[0] = chr($first_byte_int & 0x07);
+ } elseif (0x04 & $first_byte_int) {
+ $EBMLstring[0] = chr($first_byte_int & 0x03);
+ } elseif (0x02 & $first_byte_int) {
+ $EBMLstring[0] = chr($first_byte_int & 0x01);
+ } elseif (0x01 & $first_byte_int) {
+ $EBMLstring[0] = chr($first_byte_int & 0x00);
+ }
+
+ return getid3_lib::BigEndian2Int($EBMLstring);
+ }
+
+ private static function EBMLdate2unix($EBMLdatestamp) {
+ // Date - signed 8 octets integer in nanoseconds with 0 indicating the precise beginning of the millennium (at 2001-01-01T00:00:00,000000000 UTC)
+ // 978307200 == mktime(0, 0, 0, 1, 1, 2001) == January 1, 2001 12:00:00am UTC
+ return round(($EBMLdatestamp / 1000000000) + 978307200);
+ }
+
+ public static function MatroskaTargetTypeValue($target_type) {
+ // http://www.matroska.org/technical/specs/tagging/index.html
+ static $MatroskaTargetTypeValue = array();
+ if (empty($MatroskaTargetTypeValue)) {
+ $MatroskaTargetTypeValue[10] = 'A: ~ V:shot'; // the lowest hierarchy found in music or movies
+ $MatroskaTargetTypeValue[20] = 'A:subtrack/part/movement ~ V:scene'; // corresponds to parts of a track for audio (like a movement)
+ $MatroskaTargetTypeValue[30] = 'A:track/song ~ V:chapter'; // the common parts of an album or a movie
+ $MatroskaTargetTypeValue[40] = 'A:part/session ~ V:part/session'; // when an album or episode has different logical parts
+ $MatroskaTargetTypeValue[50] = 'A:album/opera/concert ~ V:movie/episode/concert'; // the most common grouping level of music and video (equals to an episode for TV series)
+ $MatroskaTargetTypeValue[60] = 'A:edition/issue/volume/opus ~ V:season/sequel/volume'; // a list of lower levels grouped together
+ $MatroskaTargetTypeValue[70] = 'A:collection ~ V:collection'; // the high hierarchy consisting of many different lower items
+ }
+ return (isset($MatroskaTargetTypeValue[$target_type]) ? $MatroskaTargetTypeValue[$target_type] : $target_type);
+ }
+
+ public static function MatroskaBlockLacingType($lacingtype) {
+ // http://matroska.org/technical/specs/index.html#block_structure
+ static $MatroskaBlockLacingType = array();
+ if (empty($MatroskaBlockLacingType)) {
+ $MatroskaBlockLacingType[0x00] = 'no lacing';
+ $MatroskaBlockLacingType[0x01] = 'Xiph lacing';
+ $MatroskaBlockLacingType[0x02] = 'fixed-size lacing';
+ $MatroskaBlockLacingType[0x03] = 'EBML lacing';
+ }
+ return (isset($MatroskaBlockLacingType[$lacingtype]) ? $MatroskaBlockLacingType[$lacingtype] : $lacingtype);
+ }
+
+ public static function MatroskaCodecIDtoCommonName($codecid) {
+ // http://www.matroska.org/technical/specs/codecid/index.html
+ static $MatroskaCodecIDlist = array();
+ if (empty($MatroskaCodecIDlist)) {
+ $MatroskaCodecIDlist['A_AAC'] = 'aac';
+ $MatroskaCodecIDlist['A_AAC/MPEG2/LC'] = 'aac';
+ $MatroskaCodecIDlist['A_AC3'] = 'ac3';
+ $MatroskaCodecIDlist['A_DTS'] = 'dts';
+ $MatroskaCodecIDlist['A_FLAC'] = 'flac';
+ $MatroskaCodecIDlist['A_MPEG/L1'] = 'mp1';
+ $MatroskaCodecIDlist['A_MPEG/L2'] = 'mp2';
+ $MatroskaCodecIDlist['A_MPEG/L3'] = 'mp3';
+ $MatroskaCodecIDlist['A_PCM/INT/LIT'] = 'pcm'; // PCM Integer Little Endian
+ $MatroskaCodecIDlist['A_PCM/INT/BIG'] = 'pcm'; // PCM Integer Big Endian
+ $MatroskaCodecIDlist['A_QUICKTIME/QDMC'] = 'quicktime'; // Quicktime: QDesign Music
+ $MatroskaCodecIDlist['A_QUICKTIME/QDM2'] = 'quicktime'; // Quicktime: QDesign Music v2
+ $MatroskaCodecIDlist['A_VORBIS'] = 'vorbis';
+ $MatroskaCodecIDlist['V_MPEG1'] = 'mpeg';
+ $MatroskaCodecIDlist['V_THEORA'] = 'theora';
+ $MatroskaCodecIDlist['V_REAL/RV40'] = 'real';
+ $MatroskaCodecIDlist['V_REAL/RV10'] = 'real';
+ $MatroskaCodecIDlist['V_REAL/RV20'] = 'real';
+ $MatroskaCodecIDlist['V_REAL/RV30'] = 'real';
+ $MatroskaCodecIDlist['V_QUICKTIME'] = 'quicktime'; // Quicktime
+ $MatroskaCodecIDlist['V_MPEG4/ISO/AP'] = 'mpeg4';
+ $MatroskaCodecIDlist['V_MPEG4/ISO/ASP'] = 'mpeg4';
+ $MatroskaCodecIDlist['V_MPEG4/ISO/AVC'] = 'h264';
+ $MatroskaCodecIDlist['V_MPEG4/ISO/SP'] = 'mpeg4';
+ $MatroskaCodecIDlist['V_VP8'] = 'vp8';
+ $MatroskaCodecIDlist['V_MS/VFW/FOURCC'] = 'riff';
+ $MatroskaCodecIDlist['A_MS/ACM'] = 'riff';
+ }
+ return (isset($MatroskaCodecIDlist[$codecid]) ? $MatroskaCodecIDlist[$codecid] : $codecid);
+ }
+
+ private static function EBMLidName($value) {
+ static $EBMLidList = array();
+ if (empty($EBMLidList)) {
+ $EBMLidList[EBML_ID_ASPECTRATIOTYPE] = 'AspectRatioType';
+ $EBMLidList[EBML_ID_ATTACHEDFILE] = 'AttachedFile';
+ $EBMLidList[EBML_ID_ATTACHMENTLINK] = 'AttachmentLink';
+ $EBMLidList[EBML_ID_ATTACHMENTS] = 'Attachments';
+ $EBMLidList[EBML_ID_AUDIO] = 'Audio';
+ $EBMLidList[EBML_ID_BITDEPTH] = 'BitDepth';
+ $EBMLidList[EBML_ID_CHANNELPOSITIONS] = 'ChannelPositions';
+ $EBMLidList[EBML_ID_CHANNELS] = 'Channels';
+ $EBMLidList[EBML_ID_CHAPCOUNTRY] = 'ChapCountry';
+ $EBMLidList[EBML_ID_CHAPLANGUAGE] = 'ChapLanguage';
+ $EBMLidList[EBML_ID_CHAPPROCESS] = 'ChapProcess';
+ $EBMLidList[EBML_ID_CHAPPROCESSCODECID] = 'ChapProcessCodecID';
+ $EBMLidList[EBML_ID_CHAPPROCESSCOMMAND] = 'ChapProcessCommand';
+ $EBMLidList[EBML_ID_CHAPPROCESSDATA] = 'ChapProcessData';
+ $EBMLidList[EBML_ID_CHAPPROCESSPRIVATE] = 'ChapProcessPrivate';
+ $EBMLidList[EBML_ID_CHAPPROCESSTIME] = 'ChapProcessTime';
+ $EBMLidList[EBML_ID_CHAPSTRING] = 'ChapString';
+ $EBMLidList[EBML_ID_CHAPTERATOM] = 'ChapterAtom';
+ $EBMLidList[EBML_ID_CHAPTERDISPLAY] = 'ChapterDisplay';
+ $EBMLidList[EBML_ID_CHAPTERFLAGENABLED] = 'ChapterFlagEnabled';
+ $EBMLidList[EBML_ID_CHAPTERFLAGHIDDEN] = 'ChapterFlagHidden';
+ $EBMLidList[EBML_ID_CHAPTERPHYSICALEQUIV] = 'ChapterPhysicalEquiv';
+ $EBMLidList[EBML_ID_CHAPTERS] = 'Chapters';
+ $EBMLidList[EBML_ID_CHAPTERSEGMENTEDITIONUID] = 'ChapterSegmentEditionUID';
+ $EBMLidList[EBML_ID_CHAPTERSEGMENTUID] = 'ChapterSegmentUID';
+ $EBMLidList[EBML_ID_CHAPTERTIMEEND] = 'ChapterTimeEnd';
+ $EBMLidList[EBML_ID_CHAPTERTIMESTART] = 'ChapterTimeStart';
+ $EBMLidList[EBML_ID_CHAPTERTRACK] = 'ChapterTrack';
+ $EBMLidList[EBML_ID_CHAPTERTRACKNUMBER] = 'ChapterTrackNumber';
+ $EBMLidList[EBML_ID_CHAPTERTRANSLATE] = 'ChapterTranslate';
+ $EBMLidList[EBML_ID_CHAPTERTRANSLATECODEC] = 'ChapterTranslateCodec';
+ $EBMLidList[EBML_ID_CHAPTERTRANSLATEEDITIONUID] = 'ChapterTranslateEditionUID';
+ $EBMLidList[EBML_ID_CHAPTERTRANSLATEID] = 'ChapterTranslateID';
+ $EBMLidList[EBML_ID_CHAPTERUID] = 'ChapterUID';
+ $EBMLidList[EBML_ID_CLUSTER] = 'Cluster';
+ $EBMLidList[EBML_ID_CLUSTERBLOCK] = 'ClusterBlock';
+ $EBMLidList[EBML_ID_CLUSTERBLOCKADDID] = 'ClusterBlockAddID';
+ $EBMLidList[EBML_ID_CLUSTERBLOCKADDITIONAL] = 'ClusterBlockAdditional';
+ $EBMLidList[EBML_ID_CLUSTERBLOCKADDITIONID] = 'ClusterBlockAdditionID';
+ $EBMLidList[EBML_ID_CLUSTERBLOCKADDITIONS] = 'ClusterBlockAdditions';
+ $EBMLidList[EBML_ID_CLUSTERBLOCKDURATION] = 'ClusterBlockDuration';
+ $EBMLidList[EBML_ID_CLUSTERBLOCKGROUP] = 'ClusterBlockGroup';
+ $EBMLidList[EBML_ID_CLUSTERBLOCKMORE] = 'ClusterBlockMore';
+ $EBMLidList[EBML_ID_CLUSTERBLOCKVIRTUAL] = 'ClusterBlockVirtual';
+ $EBMLidList[EBML_ID_CLUSTERCODECSTATE] = 'ClusterCodecState';
+ $EBMLidList[EBML_ID_CLUSTERDELAY] = 'ClusterDelay';
+ $EBMLidList[EBML_ID_CLUSTERDURATION] = 'ClusterDuration';
+ $EBMLidList[EBML_ID_CLUSTERENCRYPTEDBLOCK] = 'ClusterEncryptedBlock';
+ $EBMLidList[EBML_ID_CLUSTERFRAMENUMBER] = 'ClusterFrameNumber';
+ $EBMLidList[EBML_ID_CLUSTERLACENUMBER] = 'ClusterLaceNumber';
+ $EBMLidList[EBML_ID_CLUSTERPOSITION] = 'ClusterPosition';
+ $EBMLidList[EBML_ID_CLUSTERPREVSIZE] = 'ClusterPrevSize';
+ $EBMLidList[EBML_ID_CLUSTERREFERENCEBLOCK] = 'ClusterReferenceBlock';
+ $EBMLidList[EBML_ID_CLUSTERREFERENCEPRIORITY] = 'ClusterReferencePriority';
+ $EBMLidList[EBML_ID_CLUSTERREFERENCEVIRTUAL] = 'ClusterReferenceVirtual';
+ $EBMLidList[EBML_ID_CLUSTERSILENTTRACKNUMBER] = 'ClusterSilentTrackNumber';
+ $EBMLidList[EBML_ID_CLUSTERSILENTTRACKS] = 'ClusterSilentTracks';
+ $EBMLidList[EBML_ID_CLUSTERSIMPLEBLOCK] = 'ClusterSimpleBlock';
+ $EBMLidList[EBML_ID_CLUSTERTIMECODE] = 'ClusterTimecode';
+ $EBMLidList[EBML_ID_CLUSTERTIMESLICE] = 'ClusterTimeSlice';
+ $EBMLidList[EBML_ID_CODECDECODEALL] = 'CodecDecodeAll';
+ $EBMLidList[EBML_ID_CODECDOWNLOADURL] = 'CodecDownloadURL';
+ $EBMLidList[EBML_ID_CODECID] = 'CodecID';
+ $EBMLidList[EBML_ID_CODECINFOURL] = 'CodecInfoURL';
+ $EBMLidList[EBML_ID_CODECNAME] = 'CodecName';
+ $EBMLidList[EBML_ID_CODECPRIVATE] = 'CodecPrivate';
+ $EBMLidList[EBML_ID_CODECSETTINGS] = 'CodecSettings';
+ $EBMLidList[EBML_ID_COLOURSPACE] = 'ColourSpace';
+ $EBMLidList[EBML_ID_CONTENTCOMPALGO] = 'ContentCompAlgo';
+ $EBMLidList[EBML_ID_CONTENTCOMPRESSION] = 'ContentCompression';
+ $EBMLidList[EBML_ID_CONTENTCOMPSETTINGS] = 'ContentCompSettings';
+ $EBMLidList[EBML_ID_CONTENTENCALGO] = 'ContentEncAlgo';
+ $EBMLidList[EBML_ID_CONTENTENCKEYID] = 'ContentEncKeyID';
+ $EBMLidList[EBML_ID_CONTENTENCODING] = 'ContentEncoding';
+ $EBMLidList[EBML_ID_CONTENTENCODINGORDER] = 'ContentEncodingOrder';
+ $EBMLidList[EBML_ID_CONTENTENCODINGS] = 'ContentEncodings';
+ $EBMLidList[EBML_ID_CONTENTENCODINGSCOPE] = 'ContentEncodingScope';
+ $EBMLidList[EBML_ID_CONTENTENCODINGTYPE] = 'ContentEncodingType';
+ $EBMLidList[EBML_ID_CONTENTENCRYPTION] = 'ContentEncryption';
+ $EBMLidList[EBML_ID_CONTENTSIGALGO] = 'ContentSigAlgo';
+ $EBMLidList[EBML_ID_CONTENTSIGHASHALGO] = 'ContentSigHashAlgo';
+ $EBMLidList[EBML_ID_CONTENTSIGKEYID] = 'ContentSigKeyID';
+ $EBMLidList[EBML_ID_CONTENTSIGNATURE] = 'ContentSignature';
+ $EBMLidList[EBML_ID_CRC32] = 'CRC32';
+ $EBMLidList[EBML_ID_CUEBLOCKNUMBER] = 'CueBlockNumber';
+ $EBMLidList[EBML_ID_CUECLUSTERPOSITION] = 'CueClusterPosition';
+ $EBMLidList[EBML_ID_CUECODECSTATE] = 'CueCodecState';
+ $EBMLidList[EBML_ID_CUEPOINT] = 'CuePoint';
+ $EBMLidList[EBML_ID_CUEREFCLUSTER] = 'CueRefCluster';
+ $EBMLidList[EBML_ID_CUEREFCODECSTATE] = 'CueRefCodecState';
+ $EBMLidList[EBML_ID_CUEREFERENCE] = 'CueReference';
+ $EBMLidList[EBML_ID_CUEREFNUMBER] = 'CueRefNumber';
+ $EBMLidList[EBML_ID_CUEREFTIME] = 'CueRefTime';
+ $EBMLidList[EBML_ID_CUES] = 'Cues';
+ $EBMLidList[EBML_ID_CUETIME] = 'CueTime';
+ $EBMLidList[EBML_ID_CUETRACK] = 'CueTrack';
+ $EBMLidList[EBML_ID_CUETRACKPOSITIONS] = 'CueTrackPositions';
+ $EBMLidList[EBML_ID_DATEUTC] = 'DateUTC';
+ $EBMLidList[EBML_ID_DEFAULTDURATION] = 'DefaultDuration';
+ $EBMLidList[EBML_ID_DISPLAYHEIGHT] = 'DisplayHeight';
+ $EBMLidList[EBML_ID_DISPLAYUNIT] = 'DisplayUnit';
+ $EBMLidList[EBML_ID_DISPLAYWIDTH] = 'DisplayWidth';
+ $EBMLidList[EBML_ID_DOCTYPE] = 'DocType';
+ $EBMLidList[EBML_ID_DOCTYPEREADVERSION] = 'DocTypeReadVersion';
+ $EBMLidList[EBML_ID_DOCTYPEVERSION] = 'DocTypeVersion';
+ $EBMLidList[EBML_ID_DURATION] = 'Duration';
+ $EBMLidList[EBML_ID_EBML] = 'EBML';
+ $EBMLidList[EBML_ID_EBMLMAXIDLENGTH] = 'EBMLMaxIDLength';
+ $EBMLidList[EBML_ID_EBMLMAXSIZELENGTH] = 'EBMLMaxSizeLength';
+ $EBMLidList[EBML_ID_EBMLREADVERSION] = 'EBMLReadVersion';
+ $EBMLidList[EBML_ID_EBMLVERSION] = 'EBMLVersion';
+ $EBMLidList[EBML_ID_EDITIONENTRY] = 'EditionEntry';
+ $EBMLidList[EBML_ID_EDITIONFLAGDEFAULT] = 'EditionFlagDefault';
+ $EBMLidList[EBML_ID_EDITIONFLAGHIDDEN] = 'EditionFlagHidden';
+ $EBMLidList[EBML_ID_EDITIONFLAGORDERED] = 'EditionFlagOrdered';
+ $EBMLidList[EBML_ID_EDITIONUID] = 'EditionUID';
+ $EBMLidList[EBML_ID_FILEDATA] = 'FileData';
+ $EBMLidList[EBML_ID_FILEDESCRIPTION] = 'FileDescription';
+ $EBMLidList[EBML_ID_FILEMIMETYPE] = 'FileMimeType';
+ $EBMLidList[EBML_ID_FILENAME] = 'FileName';
+ $EBMLidList[EBML_ID_FILEREFERRAL] = 'FileReferral';
+ $EBMLidList[EBML_ID_FILEUID] = 'FileUID';
+ $EBMLidList[EBML_ID_FLAGDEFAULT] = 'FlagDefault';
+ $EBMLidList[EBML_ID_FLAGENABLED] = 'FlagEnabled';
+ $EBMLidList[EBML_ID_FLAGFORCED] = 'FlagForced';
+ $EBMLidList[EBML_ID_FLAGINTERLACED] = 'FlagInterlaced';
+ $EBMLidList[EBML_ID_FLAGLACING] = 'FlagLacing';
+ $EBMLidList[EBML_ID_GAMMAVALUE] = 'GammaValue';
+ $EBMLidList[EBML_ID_INFO] = 'Info';
+ $EBMLidList[EBML_ID_LANGUAGE] = 'Language';
+ $EBMLidList[EBML_ID_MAXBLOCKADDITIONID] = 'MaxBlockAdditionID';
+ $EBMLidList[EBML_ID_MAXCACHE] = 'MaxCache';
+ $EBMLidList[EBML_ID_MINCACHE] = 'MinCache';
+ $EBMLidList[EBML_ID_MUXINGAPP] = 'MuxingApp';
+ $EBMLidList[EBML_ID_NAME] = 'Name';
+ $EBMLidList[EBML_ID_NEXTFILENAME] = 'NextFilename';
+ $EBMLidList[EBML_ID_NEXTUID] = 'NextUID';
+ $EBMLidList[EBML_ID_OUTPUTSAMPLINGFREQUENCY] = 'OutputSamplingFrequency';
+ $EBMLidList[EBML_ID_PIXELCROPBOTTOM] = 'PixelCropBottom';
+ $EBMLidList[EBML_ID_PIXELCROPLEFT] = 'PixelCropLeft';
+ $EBMLidList[EBML_ID_PIXELCROPRIGHT] = 'PixelCropRight';
+ $EBMLidList[EBML_ID_PIXELCROPTOP] = 'PixelCropTop';
+ $EBMLidList[EBML_ID_PIXELHEIGHT] = 'PixelHeight';
+ $EBMLidList[EBML_ID_PIXELWIDTH] = 'PixelWidth';
+ $EBMLidList[EBML_ID_PREVFILENAME] = 'PrevFilename';
+ $EBMLidList[EBML_ID_PREVUID] = 'PrevUID';
+ $EBMLidList[EBML_ID_SAMPLINGFREQUENCY] = 'SamplingFrequency';
+ $EBMLidList[EBML_ID_SEEK] = 'Seek';
+ $EBMLidList[EBML_ID_SEEKHEAD] = 'SeekHead';
+ $EBMLidList[EBML_ID_SEEKID] = 'SeekID';
+ $EBMLidList[EBML_ID_SEEKPOSITION] = 'SeekPosition';
+ $EBMLidList[EBML_ID_SEGMENT] = 'Segment';
+ $EBMLidList[EBML_ID_SEGMENTFAMILY] = 'SegmentFamily';
+ $EBMLidList[EBML_ID_SEGMENTFILENAME] = 'SegmentFilename';
+ $EBMLidList[EBML_ID_SEGMENTUID] = 'SegmentUID';
+ $EBMLidList[EBML_ID_SIMPLETAG] = 'SimpleTag';
+ $EBMLidList[EBML_ID_CLUSTERSLICES] = 'ClusterSlices';
+ $EBMLidList[EBML_ID_STEREOMODE] = 'StereoMode';
+ $EBMLidList[EBML_ID_TAG] = 'Tag';
+ $EBMLidList[EBML_ID_TAGATTACHMENTUID] = 'TagAttachmentUID';
+ $EBMLidList[EBML_ID_TAGBINARY] = 'TagBinary';
+ $EBMLidList[EBML_ID_TAGCHAPTERUID] = 'TagChapterUID';
+ $EBMLidList[EBML_ID_TAGDEFAULT] = 'TagDefault';
+ $EBMLidList[EBML_ID_TAGEDITIONUID] = 'TagEditionUID';
+ $EBMLidList[EBML_ID_TAGLANGUAGE] = 'TagLanguage';
+ $EBMLidList[EBML_ID_TAGNAME] = 'TagName';
+ $EBMLidList[EBML_ID_TAGTRACKUID] = 'TagTrackUID';
+ $EBMLidList[EBML_ID_TAGS] = 'Tags';
+ $EBMLidList[EBML_ID_TAGSTRING] = 'TagString';
+ $EBMLidList[EBML_ID_TARGETS] = 'Targets';
+ $EBMLidList[EBML_ID_TARGETTYPE] = 'TargetType';
+ $EBMLidList[EBML_ID_TARGETTYPEVALUE] = 'TargetTypeValue';
+ $EBMLidList[EBML_ID_TIMECODESCALE] = 'TimecodeScale';
+ $EBMLidList[EBML_ID_TITLE] = 'Title';
+ $EBMLidList[EBML_ID_TRACKENTRY] = 'TrackEntry';
+ $EBMLidList[EBML_ID_TRACKNUMBER] = 'TrackNumber';
+ $EBMLidList[EBML_ID_TRACKOFFSET] = 'TrackOffset';
+ $EBMLidList[EBML_ID_TRACKOVERLAY] = 'TrackOverlay';
+ $EBMLidList[EBML_ID_TRACKS] = 'Tracks';
+ $EBMLidList[EBML_ID_TRACKTIMECODESCALE] = 'TrackTimecodeScale';
+ $EBMLidList[EBML_ID_TRACKTRANSLATE] = 'TrackTranslate';
+ $EBMLidList[EBML_ID_TRACKTRANSLATECODEC] = 'TrackTranslateCodec';
+ $EBMLidList[EBML_ID_TRACKTRANSLATEEDITIONUID] = 'TrackTranslateEditionUID';
+ $EBMLidList[EBML_ID_TRACKTRANSLATETRACKID] = 'TrackTranslateTrackID';
+ $EBMLidList[EBML_ID_TRACKTYPE] = 'TrackType';
+ $EBMLidList[EBML_ID_TRACKUID] = 'TrackUID';
+ $EBMLidList[EBML_ID_VIDEO] = 'Video';
+ $EBMLidList[EBML_ID_VOID] = 'Void';
+ $EBMLidList[EBML_ID_WRITINGAPP] = 'WritingApp';
+ }
+
+ return (isset($EBMLidList[$value]) ? $EBMLidList[$value] : dechex($value));
+ }
+
+ private static function getDefaultStreamInfo($streams)
+ {
+ foreach (array_reverse($streams) as $stream) {
+ if ($stream['default']) {
+ break;
+ }
+ }
+ unset($stream['default']);
+ if (isset($stream['name'])) {
+ unset($stream['name']);
+ }
+
+ $info = $stream;
+ $info['streams'] = $streams;
+
+ return $info;
+ }
+
+}
+
+?>
\ No newline at end of file
diff --git a/lib/getid3/getid3/module.audio-video.mpeg.php b/lib/getid3/getid3/module.audio-video.mpeg.php
new file mode 100644
index 00000000..499b740c
--- /dev/null
+++ b/lib/getid3/getid3/module.audio-video.mpeg.php
@@ -0,0 +1,299 @@
+ //
+// available at http://getid3.sourceforge.net //
+// or http://www.getid3.org //
+/////////////////////////////////////////////////////////////////
+// See readme.txt for more details //
+/////////////////////////////////////////////////////////////////
+// //
+// module.audio-video.mpeg.php //
+// module for analyzing MPEG files //
+// dependencies: module.audio.mp3.php //
+// ///
+/////////////////////////////////////////////////////////////////
+
+getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.mp3.php', __FILE__, true);
+
+define('GETID3_MPEG_VIDEO_PICTURE_START', "\x00\x00\x01\x00");
+define('GETID3_MPEG_VIDEO_USER_DATA_START', "\x00\x00\x01\xB2");
+define('GETID3_MPEG_VIDEO_SEQUENCE_HEADER', "\x00\x00\x01\xB3");
+define('GETID3_MPEG_VIDEO_SEQUENCE_ERROR', "\x00\x00\x01\xB4");
+define('GETID3_MPEG_VIDEO_EXTENSION_START', "\x00\x00\x01\xB5");
+define('GETID3_MPEG_VIDEO_SEQUENCE_END', "\x00\x00\x01\xB7");
+define('GETID3_MPEG_VIDEO_GROUP_START', "\x00\x00\x01\xB8");
+define('GETID3_MPEG_AUDIO_START', "\x00\x00\x01\xC0");
+
+
+class getid3_mpeg extends getid3_handler
+{
+
+ function Analyze() {
+ $info = &$this->getid3->info;
+
+ if ($info['avdataend'] <= $info['avdataoffset']) {
+ $info['error'][] = '"avdataend" ('.$info['avdataend'].') is unexpectedly less-than-or-equal-to "avdataoffset" ('.$info['avdataoffset'].')';
+ return false;
+ }
+ $info['fileformat'] = 'mpeg';
+ fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
+ $MPEGstreamData = fread($this->getid3->fp, min(100000, $info['avdataend'] - $info['avdataoffset']));
+ $MPEGstreamDataLength = strlen($MPEGstreamData);
+
+ $foundVideo = true;
+ $VideoChunkOffset = 0;
+ while (substr($MPEGstreamData, $VideoChunkOffset++, 4) !== GETID3_MPEG_VIDEO_SEQUENCE_HEADER) {
+ if ($VideoChunkOffset >= $MPEGstreamDataLength) {
+ $foundVideo = false;
+ break;
+ }
+ }
+ if ($foundVideo) {
+
+ // Start code 32 bits
+ // horizontal frame size 12 bits
+ // vertical frame size 12 bits
+ // pixel aspect ratio 4 bits
+ // frame rate 4 bits
+ // bitrate 18 bits
+ // marker bit 1 bit
+ // VBV buffer size 10 bits
+ // constrained parameter flag 1 bit
+ // intra quant. matrix flag 1 bit
+ // intra quant. matrix values 512 bits (present if matrix flag == 1)
+ // non-intra quant. matrix flag 1 bit
+ // non-intra quant. matrix values 512 bits (present if matrix flag == 1)
+
+ $info['video']['dataformat'] = 'mpeg';
+
+ $VideoChunkOffset += (strlen(GETID3_MPEG_VIDEO_SEQUENCE_HEADER) - 1);
+
+ $FrameSizeDWORD = getid3_lib::BigEndian2Int(substr($MPEGstreamData, $VideoChunkOffset, 3));
+ $VideoChunkOffset += 3;
+
+ $AspectRatioFrameRateDWORD = getid3_lib::BigEndian2Int(substr($MPEGstreamData, $VideoChunkOffset, 1));
+ $VideoChunkOffset += 1;
+
+ $assortedinformation = getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $VideoChunkOffset, 4));
+ $VideoChunkOffset += 4;
+
+ $info['mpeg']['video']['raw']['framesize_horizontal'] = ($FrameSizeDWORD & 0xFFF000) >> 12; // 12 bits for horizontal frame size
+ $info['mpeg']['video']['raw']['framesize_vertical'] = ($FrameSizeDWORD & 0x000FFF); // 12 bits for vertical frame size
+ $info['mpeg']['video']['raw']['pixel_aspect_ratio'] = ($AspectRatioFrameRateDWORD & 0xF0) >> 4;
+ $info['mpeg']['video']['raw']['frame_rate'] = ($AspectRatioFrameRateDWORD & 0x0F);
+
+ $info['mpeg']['video']['framesize_horizontal'] = $info['mpeg']['video']['raw']['framesize_horizontal'];
+ $info['mpeg']['video']['framesize_vertical'] = $info['mpeg']['video']['raw']['framesize_vertical'];
+
+ $info['mpeg']['video']['pixel_aspect_ratio'] = $this->MPEGvideoAspectRatioLookup($info['mpeg']['video']['raw']['pixel_aspect_ratio']);
+ $info['mpeg']['video']['pixel_aspect_ratio_text'] = $this->MPEGvideoAspectRatioTextLookup($info['mpeg']['video']['raw']['pixel_aspect_ratio']);
+ $info['mpeg']['video']['frame_rate'] = $this->MPEGvideoFramerateLookup($info['mpeg']['video']['raw']['frame_rate']);
+
+ $info['mpeg']['video']['raw']['bitrate'] = getid3_lib::Bin2Dec(substr($assortedinformation, 0, 18));
+ $info['mpeg']['video']['raw']['marker_bit'] = (bool) getid3_lib::Bin2Dec(substr($assortedinformation, 18, 1));
+ $info['mpeg']['video']['raw']['vbv_buffer_size'] = getid3_lib::Bin2Dec(substr($assortedinformation, 19, 10));
+ $info['mpeg']['video']['raw']['constrained_param_flag'] = (bool) getid3_lib::Bin2Dec(substr($assortedinformation, 29, 1));
+ $info['mpeg']['video']['raw']['intra_quant_flag'] = (bool) getid3_lib::Bin2Dec(substr($assortedinformation, 30, 1));
+ if ($info['mpeg']['video']['raw']['intra_quant_flag']) {
+
+ // read 512 bits
+ $info['mpeg']['video']['raw']['intra_quant'] = getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $VideoChunkOffset, 64));
+ $VideoChunkOffset += 64;
+
+ $info['mpeg']['video']['raw']['non_intra_quant_flag'] = (bool) getid3_lib::Bin2Dec(substr($info['mpeg']['video']['raw']['intra_quant'], 511, 1));
+ $info['mpeg']['video']['raw']['intra_quant'] = getid3_lib::Bin2Dec(substr($assortedinformation, 31, 1)).substr(getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $VideoChunkOffset, 64)), 0, 511);
+
+ if ($info['mpeg']['video']['raw']['non_intra_quant_flag']) {
+ $info['mpeg']['video']['raw']['non_intra_quant'] = substr($MPEGstreamData, $VideoChunkOffset, 64);
+ $VideoChunkOffset += 64;
+ }
+
+ } else {
+
+ $info['mpeg']['video']['raw']['non_intra_quant_flag'] = (bool) getid3_lib::Bin2Dec(substr($assortedinformation, 31, 1));
+ if ($info['mpeg']['video']['raw']['non_intra_quant_flag']) {
+ $info['mpeg']['video']['raw']['non_intra_quant'] = substr($MPEGstreamData, $VideoChunkOffset, 64);
+ $VideoChunkOffset += 64;
+ }
+
+ }
+
+ if ($info['mpeg']['video']['raw']['bitrate'] == 0x3FFFF) { // 18 set bits
+
+ $info['warning'][] = 'This version of getID3() ['.$this->getid3->version().'] cannot determine average bitrate of VBR MPEG video files';
+ $info['mpeg']['video']['bitrate_mode'] = 'vbr';
+
+ } else {
+
+ $info['mpeg']['video']['bitrate'] = $info['mpeg']['video']['raw']['bitrate'] * 400;
+ $info['mpeg']['video']['bitrate_mode'] = 'cbr';
+ $info['video']['bitrate'] = $info['mpeg']['video']['bitrate'];
+
+ }
+
+ $info['video']['resolution_x'] = $info['mpeg']['video']['framesize_horizontal'];
+ $info['video']['resolution_y'] = $info['mpeg']['video']['framesize_vertical'];
+ $info['video']['frame_rate'] = $info['mpeg']['video']['frame_rate'];
+ $info['video']['bitrate_mode'] = $info['mpeg']['video']['bitrate_mode'];
+ $info['video']['pixel_aspect_ratio'] = $info['mpeg']['video']['pixel_aspect_ratio'];
+ $info['video']['lossless'] = false;
+ $info['video']['bits_per_sample'] = 24;
+
+ } else {
+
+ $info['error'][] = 'Could not find start of video block in the first 100,000 bytes (or before end of file) - this might not be an MPEG-video file?';
+
+ }
+
+ //0x000001B3 begins the sequence_header of every MPEG video stream.
+ //But in MPEG-2, this header must immediately be followed by an
+ //extension_start_code (0x000001B5) with a sequence_extension ID (1).
+ //(This extension contains all the additional MPEG-2 stuff.)
+ //MPEG-1 doesn't have this extension, so that's a sure way to tell the
+ //difference between MPEG-1 and MPEG-2 video streams.
+
+ if (substr($MPEGstreamData, $VideoChunkOffset, 4) == GETID3_MPEG_VIDEO_EXTENSION_START) {
+ $info['video']['codec'] = 'MPEG-2';
+ } else {
+ $info['video']['codec'] = 'MPEG-1';
+ }
+
+
+ $AudioChunkOffset = 0;
+ while (true) {
+ while (substr($MPEGstreamData, $AudioChunkOffset++, 4) !== GETID3_MPEG_AUDIO_START) {
+ if ($AudioChunkOffset >= $MPEGstreamDataLength) {
+ break 2;
+ }
+ }
+
+ $getid3_temp = new getID3();
+ $getid3_temp->openfile($this->getid3->filename);
+ $getid3_temp->info = $info;
+ $getid3_mp3 = new getid3_mp3($getid3_temp);
+ for ($i = 0; $i <= 7; $i++) {
+ // some files have the MPEG-audio header 8 bytes after the end of the $00 $00 $01 $C0 signature, some have it up to 13 bytes (or more?) after
+ // I have no idea why or what the difference is, so this is a stupid hack.
+ // If anybody has any better idea of what's going on, please let me know - info@getid3.org
+ fseek($getid3_temp->fp, ftell($this->getid3->fp), SEEK_SET);
+ $getid3_temp->info = $info; // only overwrite real data if valid header found
+ if ($getid3_mp3->decodeMPEGaudioHeader(($AudioChunkOffset + 3) + 8 + $i, $getid3_temp->info, false)) {
+ $info = $getid3_temp->info;
+ $info['audio']['bitrate_mode'] = 'cbr';
+ $info['audio']['lossless'] = false;
+ unset($getid3_temp, $getid3_mp3);
+ break 2;
+ }
+ }
+ unset($getid3_temp, $getid3_mp3);
+ }
+
+ // Temporary hack to account for interleaving overhead:
+ if (!empty($info['video']['bitrate']) && !empty($info['audio']['bitrate'])) {
+ $info['playtime_seconds'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / ($info['video']['bitrate'] + $info['audio']['bitrate']);
+
+ // Interleaved MPEG audio/video files have a certain amount of overhead that varies
+ // by both video and audio bitrates, and not in any sensible, linear/logarithmic patter
+ // Use interpolated lookup tables to approximately guess how much is overhead, because
+ // playtime is calculated as filesize / total-bitrate
+ $info['playtime_seconds'] *= $this->MPEGsystemNonOverheadPercentage($info['video']['bitrate'], $info['audio']['bitrate']);
+
+ //switch ($info['video']['bitrate']) {
+ // case('5000000'):
+ // $multiplier = 0.93292642112380355828048824319889;
+ // break;
+ // case('5500000'):
+ // $multiplier = 0.93582895375200989965359777343219;
+ // break;
+ // case('6000000'):
+ // $multiplier = 0.93796247714820932532911373859139;
+ // break;
+ // case('7000000'):
+ // $multiplier = 0.9413264083635103463010117778776;
+ // break;
+ // default:
+ // $multiplier = 1;
+ // break;
+ //}
+ //$info['playtime_seconds'] *= $multiplier;
+ //$info['warning'][] = 'Interleaved MPEG audio/video playtime may be inaccurate. With current hack should be within a few seconds of accurate. Report to info@getid3.org if off by more than 10 seconds.';
+ if ($info['video']['bitrate'] < 50000) {
+ $info['warning'][] = 'Interleaved MPEG audio/video playtime may be slightly inaccurate for video bitrates below 100kbps. Except in extreme low-bitrate situations, error should be less than 1%. Report to info@getid3.org if greater than this.';
+ }
+ }
+
+ return true;
+ }
+
+
+ function MPEGsystemNonOverheadPercentage($VideoBitrate, $AudioBitrate) {
+ $OverheadPercentage = 0;
+
+ $AudioBitrate = max(min($AudioBitrate / 1000, 384), 32); // limit to range of 32kbps - 384kbps (should be only legal bitrates, but maybe VBR?)
+ $VideoBitrate = max(min($VideoBitrate / 1000, 10000), 10); // limit to range of 10kbps - 10Mbps (beyond that curves flatten anyways, no big loss)
+
+
+ //OMBB[audiobitrate] = array(video-10kbps, video-100kbps, video-1000kbps, video-10000kbps)
+ $OverheadMultiplierByBitrate[32] = array(0, 0.9676287944368530, 0.9802276264360310, 0.9844916183244460, 0.9852821845179940);
+ $OverheadMultiplierByBitrate[48] = array(0, 0.9779100089209830, 0.9787770035359320, 0.9846738664076130, 0.9852683013799960);
+ $OverheadMultiplierByBitrate[56] = array(0, 0.9731249855367600, 0.9776624308938040, 0.9832606361852130, 0.9843922606633340);
+ $OverheadMultiplierByBitrate[64] = array(0, 0.9755642683275760, 0.9795256705493390, 0.9836573009193170, 0.9851122539404470);
+ $OverheadMultiplierByBitrate[96] = array(0, 0.9788025247497290, 0.9798553314148700, 0.9822956869792560, 0.9834815119124690);
+ $OverheadMultiplierByBitrate[128] = array(0, 0.9816940050925480, 0.9821675936072120, 0.9829756927470870, 0.9839763420152050);
+ $OverheadMultiplierByBitrate[160] = array(0, 0.9825894094561180, 0.9820913399073960, 0.9823907143253970, 0.9832821783651570);
+ $OverheadMultiplierByBitrate[192] = array(0, 0.9832038474336260, 0.9825731694317960, 0.9821028622712400, 0.9828262076447620);
+ $OverheadMultiplierByBitrate[224] = array(0, 0.9836516298538770, 0.9824718601823890, 0.9818302180625380, 0.9823735101626480);
+ $OverheadMultiplierByBitrate[256] = array(0, 0.9845863022094920, 0.9837229411967540, 0.9824521662210830, 0.9828645172100790);
+ $OverheadMultiplierByBitrate[320] = array(0, 0.9849565280263180, 0.9837683142805110, 0.9822885275960400, 0.9824424382727190);
+ $OverheadMultiplierByBitrate[384] = array(0, 0.9856094774357600, 0.9844573394432720, 0.9825970399837330, 0.9824673808303890);
+
+ $BitrateToUseMin = 32;
+ $BitrateToUseMax = 32;
+ $previousBitrate = 32;
+ foreach ($OverheadMultiplierByBitrate as $key => $value) {
+ if ($AudioBitrate >= $previousBitrate) {
+ $BitrateToUseMin = $previousBitrate;
+ }
+ if ($AudioBitrate < $key) {
+ $BitrateToUseMax = $key;
+ break;
+ }
+ $previousBitrate = $key;
+ }
+ $FactorA = ($BitrateToUseMax - $AudioBitrate) / ($BitrateToUseMax - $BitrateToUseMin);
+
+ $VideoBitrateLog10 = log10($VideoBitrate);
+ $VideoFactorMin1 = $OverheadMultiplierByBitrate[$BitrateToUseMin][floor($VideoBitrateLog10)];
+ $VideoFactorMin2 = $OverheadMultiplierByBitrate[$BitrateToUseMax][floor($VideoBitrateLog10)];
+ $VideoFactorMax1 = $OverheadMultiplierByBitrate[$BitrateToUseMin][ceil($VideoBitrateLog10)];
+ $VideoFactorMax2 = $OverheadMultiplierByBitrate[$BitrateToUseMax][ceil($VideoBitrateLog10)];
+ $FactorV = $VideoBitrateLog10 - floor($VideoBitrateLog10);
+
+ $OverheadPercentage = $VideoFactorMin1 * $FactorA * $FactorV;
+ $OverheadPercentage += $VideoFactorMin2 * (1 - $FactorA) * $FactorV;
+ $OverheadPercentage += $VideoFactorMax1 * $FactorA * (1 - $FactorV);
+ $OverheadPercentage += $VideoFactorMax2 * (1 - $FactorA) * (1 - $FactorV);
+
+ return $OverheadPercentage;
+ }
+
+
+ function MPEGvideoFramerateLookup($rawframerate) {
+ $MPEGvideoFramerateLookup = array(0, 23.976, 24, 25, 29.97, 30, 50, 59.94, 60);
+ return (isset($MPEGvideoFramerateLookup[$rawframerate]) ? (float) $MPEGvideoFramerateLookup[$rawframerate] : (float) 0);
+ }
+
+ function MPEGvideoAspectRatioLookup($rawaspectratio) {
+ $MPEGvideoAspectRatioLookup = array(0, 1, 0.6735, 0.7031, 0.7615, 0.8055, 0.8437, 0.8935, 0.9157, 0.9815, 1.0255, 1.0695, 1.0950, 1.1575, 1.2015, 0);
+ return (isset($MPEGvideoAspectRatioLookup[$rawaspectratio]) ? (float) $MPEGvideoAspectRatioLookup[$rawaspectratio] : (float) 0);
+ }
+
+ function MPEGvideoAspectRatioTextLookup($rawaspectratio) {
+ $MPEGvideoAspectRatioTextLookup = array('forbidden', 'square pixels', '0.6735', '16:9, 625 line, PAL', '0.7615', '0.8055', '16:9, 525 line, NTSC', '0.8935', '4:3, 625 line, PAL, CCIR601', '0.9815', '1.0255', '1.0695', '4:3, 525 line, NTSC, CCIR601', '1.1575', '1.2015', 'reserved');
+ return (isset($MPEGvideoAspectRatioTextLookup[$rawaspectratio]) ? $MPEGvideoAspectRatioTextLookup[$rawaspectratio] : '');
+ }
+
+}
+
+
+?>
\ No newline at end of file
diff --git a/lib/getid3/getid3/module.audio-video.nsv.php b/lib/getid3/getid3/module.audio-video.nsv.php
new file mode 100644
index 00000000..5a587e67
--- /dev/null
+++ b/lib/getid3/getid3/module.audio-video.nsv.php
@@ -0,0 +1,226 @@
+ //
+// available at http://getid3.sourceforge.net //
+// or http://www.getid3.org //
+/////////////////////////////////////////////////////////////////
+// See readme.txt for more details //
+/////////////////////////////////////////////////////////////////
+// //
+// module.audio.nsv.php //
+// module for analyzing Nullsoft NSV files //
+// dependencies: NONE //
+// ///
+/////////////////////////////////////////////////////////////////
+
+
+class getid3_nsv extends getid3_handler
+{
+
+ function Analyze() {
+ $info = &$this->getid3->info;
+
+ fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
+ $NSVheader = fread($this->getid3->fp, 4);
+
+ switch ($NSVheader) {
+ case 'NSVs':
+ if ($this->getNSVsHeaderFilepointer(0)) {
+ $info['fileformat'] = 'nsv';
+ $info['audio']['dataformat'] = 'nsv';
+ $info['video']['dataformat'] = 'nsv';
+ $info['audio']['lossless'] = false;
+ $info['video']['lossless'] = false;
+ }
+ break;
+
+ case 'NSVf':
+ if ($this->getNSVfHeaderFilepointer(0)) {
+ $info['fileformat'] = 'nsv';
+ $info['audio']['dataformat'] = 'nsv';
+ $info['video']['dataformat'] = 'nsv';
+ $info['audio']['lossless'] = false;
+ $info['video']['lossless'] = false;
+ $this->getNSVsHeaderFilepointer($info['nsv']['NSVf']['header_length']);
+ }
+ break;
+
+ default:
+ $info['error'][] = 'Expecting "NSVs" or "NSVf" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($NSVheader).'"';
+ return false;
+ break;
+ }
+
+ if (!isset($info['nsv']['NSVf'])) {
+ $info['warning'][] = 'NSVf header not present - cannot calculate playtime or bitrate';
+ }
+
+ return true;
+ }
+
+ function getNSVsHeaderFilepointer($fileoffset) {
+ $info = &$this->getid3->info;
+ fseek($this->getid3->fp, $fileoffset, SEEK_SET);
+ $NSVsheader = fread($this->getid3->fp, 28);
+ $offset = 0;
+
+ $info['nsv']['NSVs']['identifier'] = substr($NSVsheader, $offset, 4);
+ $offset += 4;
+
+ if ($info['nsv']['NSVs']['identifier'] != 'NSVs') {
+ $info['error'][] = 'expected "NSVs" at offset ('.$fileoffset.'), found "'.$info['nsv']['NSVs']['identifier'].'" instead';
+ unset($info['nsv']['NSVs']);
+ return false;
+ }
+
+ $info['nsv']['NSVs']['offset'] = $fileoffset;
+
+ $info['nsv']['NSVs']['video_codec'] = substr($NSVsheader, $offset, 4);
+ $offset += 4;
+ $info['nsv']['NSVs']['audio_codec'] = substr($NSVsheader, $offset, 4);
+ $offset += 4;
+ $info['nsv']['NSVs']['resolution_x'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 2));
+ $offset += 2;
+ $info['nsv']['NSVs']['resolution_y'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 2));
+ $offset += 2;
+
+ $info['nsv']['NSVs']['framerate_index'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1));
+ $offset += 1;
+ //$info['nsv']['NSVs']['unknown1b'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1));
+ $offset += 1;
+ //$info['nsv']['NSVs']['unknown1c'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1));
+ $offset += 1;
+ //$info['nsv']['NSVs']['unknown1d'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1));
+ $offset += 1;
+ //$info['nsv']['NSVs']['unknown2a'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1));
+ $offset += 1;
+ //$info['nsv']['NSVs']['unknown2b'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1));
+ $offset += 1;
+ //$info['nsv']['NSVs']['unknown2c'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1));
+ $offset += 1;
+ //$info['nsv']['NSVs']['unknown2d'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1));
+ $offset += 1;
+
+ switch ($info['nsv']['NSVs']['audio_codec']) {
+ case 'PCM ':
+ $info['nsv']['NSVs']['bits_channel'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1));
+ $offset += 1;
+ $info['nsv']['NSVs']['channels'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1));
+ $offset += 1;
+ $info['nsv']['NSVs']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 2));
+ $offset += 2;
+
+ $info['audio']['sample_rate'] = $info['nsv']['NSVs']['sample_rate'];
+ break;
+
+ case 'MP3 ':
+ case 'NONE':
+ default:
+ //$info['nsv']['NSVs']['unknown3'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 4));
+ $offset += 4;
+ break;
+ }
+
+ $info['video']['resolution_x'] = $info['nsv']['NSVs']['resolution_x'];
+ $info['video']['resolution_y'] = $info['nsv']['NSVs']['resolution_y'];
+ $info['nsv']['NSVs']['frame_rate'] = $this->NSVframerateLookup($info['nsv']['NSVs']['framerate_index']);
+ $info['video']['frame_rate'] = $info['nsv']['NSVs']['frame_rate'];
+ $info['video']['bits_per_sample'] = 24;
+ $info['video']['pixel_aspect_ratio'] = (float) 1;
+
+ return true;
+ }
+
+ function getNSVfHeaderFilepointer($fileoffset, $getTOCoffsets=false) {
+ $info = &$this->getid3->info;
+ fseek($this->getid3->fp, $fileoffset, SEEK_SET);
+ $NSVfheader = fread($this->getid3->fp, 28);
+ $offset = 0;
+
+ $info['nsv']['NSVf']['identifier'] = substr($NSVfheader, $offset, 4);
+ $offset += 4;
+
+ if ($info['nsv']['NSVf']['identifier'] != 'NSVf') {
+ $info['error'][] = 'expected "NSVf" at offset ('.$fileoffset.'), found "'.$info['nsv']['NSVf']['identifier'].'" instead';
+ unset($info['nsv']['NSVf']);
+ return false;
+ }
+
+ $info['nsv']['NSVs']['offset'] = $fileoffset;
+
+ $info['nsv']['NSVf']['header_length'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4));
+ $offset += 4;
+ $info['nsv']['NSVf']['file_size'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4));
+ $offset += 4;
+
+ if ($info['nsv']['NSVf']['file_size'] > $info['avdataend']) {
+ $info['warning'][] = 'truncated file - NSVf header indicates '.$info['nsv']['NSVf']['file_size'].' bytes, file actually '.$info['avdataend'].' bytes';
+ }
+
+ $info['nsv']['NSVf']['playtime_ms'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4));
+ $offset += 4;
+ $info['nsv']['NSVf']['meta_size'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4));
+ $offset += 4;
+ $info['nsv']['NSVf']['TOC_entries_1'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4));
+ $offset += 4;
+ $info['nsv']['NSVf']['TOC_entries_2'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4));
+ $offset += 4;
+
+ if ($info['nsv']['NSVf']['playtime_ms'] == 0) {
+ $info['error'][] = 'Corrupt NSV file: NSVf.playtime_ms == zero';
+ return false;
+ }
+
+ $NSVfheader .= fread($this->getid3->fp, $info['nsv']['NSVf']['meta_size'] + (4 * $info['nsv']['NSVf']['TOC_entries_1']) + (4 * $info['nsv']['NSVf']['TOC_entries_2']));
+ $NSVfheaderlength = strlen($NSVfheader);
+ $info['nsv']['NSVf']['metadata'] = substr($NSVfheader, $offset, $info['nsv']['NSVf']['meta_size']);
+ $offset += $info['nsv']['NSVf']['meta_size'];
+
+ if ($getTOCoffsets) {
+ $TOCcounter = 0;
+ while ($TOCcounter < $info['nsv']['NSVf']['TOC_entries_1']) {
+ if ($TOCcounter < $info['nsv']['NSVf']['TOC_entries_1']) {
+ $info['nsv']['NSVf']['TOC_1'][$TOCcounter] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4));
+ $offset += 4;
+ $TOCcounter++;
+ }
+ }
+ }
+
+ if (trim($info['nsv']['NSVf']['metadata']) != '') {
+ $info['nsv']['NSVf']['metadata'] = str_replace('`', "\x01", $info['nsv']['NSVf']['metadata']);
+ $CommentPairArray = explode("\x01".' ', $info['nsv']['NSVf']['metadata']);
+ foreach ($CommentPairArray as $CommentPair) {
+ if (strstr($CommentPair, '='."\x01")) {
+ list($key, $value) = explode('='."\x01", $CommentPair, 2);
+ $info['nsv']['comments'][strtolower($key)][] = trim(str_replace("\x01", '', $value));
+ }
+ }
+ }
+
+ $info['playtime_seconds'] = $info['nsv']['NSVf']['playtime_ms'] / 1000;
+ $info['bitrate'] = ($info['nsv']['NSVf']['file_size'] * 8) / $info['playtime_seconds'];
+
+ return true;
+ }
+
+
+ static function NSVframerateLookup($framerateindex) {
+ if ($framerateindex <= 127) {
+ return (float) $framerateindex;
+ }
+ static $NSVframerateLookup = array();
+ if (empty($NSVframerateLookup)) {
+ $NSVframerateLookup[129] = (float) 29.970;
+ $NSVframerateLookup[131] = (float) 23.976;
+ $NSVframerateLookup[133] = (float) 14.985;
+ $NSVframerateLookup[197] = (float) 59.940;
+ $NSVframerateLookup[199] = (float) 47.952;
+ }
+ return (isset($NSVframerateLookup[$framerateindex]) ? $NSVframerateLookup[$framerateindex] : false);
+ }
+
+}
+
+
+?>
\ No newline at end of file
diff --git a/lib/getid3/getid3/module.audio-video.quicktime.php b/lib/getid3/getid3/module.audio-video.quicktime.php
new file mode 100644
index 00000000..3e96ea1a
--- /dev/null
+++ b/lib/getid3/getid3/module.audio-video.quicktime.php
@@ -0,0 +1,2134 @@
+ //
+// available at http://getid3.sourceforge.net //
+// or http://www.getid3.org //
+/////////////////////////////////////////////////////////////////
+// See readme.txt for more details //
+/////////////////////////////////////////////////////////////////
+// //
+// module.audio-video.quicktime.php //
+// module for analyzing Quicktime and MP3-in-MP4 files //
+// dependencies: module.audio.mp3.php //
+// ///
+/////////////////////////////////////////////////////////////////
+
+getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.mp3.php', __FILE__, true);
+
+class getid3_quicktime extends getid3_handler
+{
+
+ var $ReturnAtomData = true;
+ var $ParseAllPossibleAtoms = false;
+
+ function Analyze() {
+ $info = &$this->getid3->info;
+
+ $info['fileformat'] = 'quicktime';
+ $info['quicktime']['hinting'] = false;
+ $info['quicktime']['controller'] = 'standard'; // may be overridden if 'ctyp' atom is present
+
+ fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
+
+ $offset = 0;
+ $atomcounter = 0;
+
+ while ($offset < $info['avdataend']) {
+ if (!getid3_lib::intValueSupported($offset)) {
+ $info['error'][] = 'Unable to parse atom at offset '.$offset.' because beyond '.round(PHP_INT_MAX / 1073741824).'GB limit of PHP filesystem functions';
+ break;
+ }
+ fseek($this->getid3->fp, $offset, SEEK_SET);
+ $AtomHeader = fread($this->getid3->fp, 8);
+
+ $atomsize = getid3_lib::BigEndian2Int(substr($AtomHeader, 0, 4));
+ $atomname = substr($AtomHeader, 4, 4);
+
+ // 64-bit MOV patch by jlegateØktnc*com
+ if ($atomsize == 1) {
+ $atomsize = getid3_lib::BigEndian2Int(fread($this->getid3->fp, 8));
+ }
+
+ $info['quicktime'][$atomname]['name'] = $atomname;
+ $info['quicktime'][$atomname]['size'] = $atomsize;
+ $info['quicktime'][$atomname]['offset'] = $offset;
+
+ if (($offset + $atomsize) > $info['avdataend']) {
+ $info['error'][] = 'Atom at offset '.$offset.' claims to go beyond end-of-file (length: '.$atomsize.' bytes)';
+ return false;
+ }
+
+ if ($atomsize == 0) {
+ // Furthermore, for historical reasons the list of atoms is optionally
+ // terminated by a 32-bit integer set to 0. If you are writing a program
+ // to read user data atoms, you should allow for the terminating 0.
+ break;
+ }
+ switch ($atomname) {
+ case 'mdat': // Media DATa atom
+ // 'mdat' contains the actual data for the audio/video
+ if (($atomsize > 8) && (!isset($info['avdataend_tmp']) || ($info['quicktime'][$atomname]['size'] > ($info['avdataend_tmp'] - $info['avdataoffset'])))) {
+
+ $info['avdataoffset'] = $info['quicktime'][$atomname]['offset'] + 8;
+ $OldAVDataEnd = $info['avdataend'];
+ $info['avdataend'] = $info['quicktime'][$atomname]['offset'] + $info['quicktime'][$atomname]['size'];
+
+ $getid3_temp = new getID3();
+ $getid3_temp->openfile($this->getid3->filename);
+ $getid3_temp->info['avdataoffset'] = $info['avdataoffset'];
+ $getid3_temp->info['avdataend'] = $info['avdataend'];
+ $getid3_mp3 = new getid3_mp3($getid3_temp);
+ if ($getid3_mp3->MPEGaudioHeaderValid($getid3_mp3->MPEGaudioHeaderDecode(fread($this->getid3->fp, 4)))) {
+ $getid3_mp3->getOnlyMPEGaudioInfo($getid3_temp->info['avdataoffset'], false);
+ if (!empty($getid3_temp->info['warning'])) {
+ foreach ($getid3_temp->info['warning'] as $value) {
+ $info['warning'][] = $value;
+ }
+ }
+ if (!empty($getid3_temp->info['mpeg'])) {
+ $info['mpeg'] = $getid3_temp->info['mpeg'];
+ if (isset($info['mpeg']['audio'])) {
+ $info['audio']['dataformat'] = 'mp3';
+ $info['audio']['codec'] = (!empty($info['mpeg']['audio']['encoder']) ? $info['mpeg']['audio']['encoder'] : (!empty($info['mpeg']['audio']['codec']) ? $info['mpeg']['audio']['codec'] : (!empty($info['mpeg']['audio']['LAME']) ? 'LAME' :'mp3')));
+ $info['audio']['sample_rate'] = $info['mpeg']['audio']['sample_rate'];
+ $info['audio']['channels'] = $info['mpeg']['audio']['channels'];
+ $info['audio']['bitrate'] = $info['mpeg']['audio']['bitrate'];
+ $info['audio']['bitrate_mode'] = strtolower($info['mpeg']['audio']['bitrate_mode']);
+ $info['bitrate'] = $info['audio']['bitrate'];
+ }
+ }
+ }
+ unset($getid3_mp3, $getid3_temp);
+ $info['avdataend'] = $OldAVDataEnd;
+ unset($OldAVDataEnd);
+
+ }
+ break;
+
+ case 'free': // FREE space atom
+ case 'skip': // SKIP atom
+ case 'wide': // 64-bit expansion placeholder atom
+ // 'free', 'skip' and 'wide' are just padding, contains no useful data at all
+ break;
+
+ default:
+ $atomHierarchy = array();
+ $info['quicktime'][$atomname] = $this->QuicktimeParseAtom($atomname, $atomsize, fread($this->getid3->fp, $atomsize), $offset, $atomHierarchy, $this->ParseAllPossibleAtoms);
+ break;
+ }
+
+ $offset += $atomsize;
+ $atomcounter++;
+ }
+
+ if (!empty($info['avdataend_tmp'])) {
+ // this value is assigned to a temp value and then erased because
+ // otherwise any atoms beyond the 'mdat' atom would not get parsed
+ $info['avdataend'] = $info['avdataend_tmp'];
+ unset($info['avdataend_tmp']);
+ }
+
+ if (!isset($info['bitrate']) && isset($info['playtime_seconds'])) {
+ $info['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds'];
+ }
+ if (isset($info['bitrate']) && !isset($info['audio']['bitrate']) && !isset($info['quicktime']['video'])) {
+ $info['audio']['bitrate'] = $info['bitrate'];
+ }
+ if (!empty($info['playtime_seconds']) && !isset($info['video']['frame_rate']) && !empty($info['quicktime']['stts_framecount'])) {
+ foreach ($info['quicktime']['stts_framecount'] as $key => $samples_count) {
+ $samples_per_second = $samples_count / $info['playtime_seconds'];
+ if ($samples_per_second > 240) {
+ // has to be audio samples
+ } else {
+ $info['video']['frame_rate'] = $samples_per_second;
+ break;
+ }
+ }
+ }
+ if (($info['audio']['dataformat'] == 'mp4') && empty($info['video']['resolution_x'])) {
+ $info['fileformat'] = 'mp4';
+ $info['mime_type'] = 'audio/mp4';
+ unset($info['video']['dataformat']);
+ }
+
+ if (!$this->ReturnAtomData) {
+ unset($info['quicktime']['moov']);
+ }
+
+ if (empty($info['audio']['dataformat']) && !empty($info['quicktime']['audio'])) {
+ $info['audio']['dataformat'] = 'quicktime';
+ }
+ if (empty($info['video']['dataformat']) && !empty($info['quicktime']['video'])) {
+ $info['video']['dataformat'] = 'quicktime';
+ }
+
+ return true;
+ }
+
+ function QuicktimeParseAtom($atomname, $atomsize, $atom_data, $baseoffset, &$atomHierarchy, $ParseAllPossibleAtoms) {
+ // http://developer.apple.com/techpubs/quicktime/qtdevdocs/APIREF/INDEX/atomalphaindex.htm
+
+ $info = &$this->getid3->info;
+
+ $atom_parent = array_pop($atomHierarchy);
+ array_push($atomHierarchy, $atomname);
+ $atom_structure['hierarchy'] = implode(' ', $atomHierarchy);
+ $atom_structure['name'] = $atomname;
+ $atom_structure['size'] = $atomsize;
+ $atom_structure['offset'] = $baseoffset;
+//echo getid3_lib::PrintHexBytes(substr($atom_data, 0, 8)).' ';
+//echo getid3_lib::PrintHexBytes(substr($atom_data, 0, 8), false).'