FV Flowplayer Video Player - Version 1.0.6

Version Description

  • widgets problems with splash image and controlbar fixed
  • cyan background color fixed
Download this release

Release Info

Developer FolioVision
Plugin Icon 128x128 FV Flowplayer Video Player
Version 1.0.6
Comparing to
See all releases

Code changes from version 0.9.17 to 1.0.6

Files changed (61) hide show
  1. controller/backend.php +166 -88
  2. controller/frontend.php +169 -102
  3. controller/shortcodes.php +85 -0
  4. css/flowplayer.css +115 -101
  5. flowplayer.php +28 -25
  6. flowplayer/flowplayer.min.js +23 -23
  7. flowplayer/style.css +41 -41
  8. images/button-bg.png +0 -0
  9. images/icon.png +0 -0
  10. images/icon.png.toobig +0 -0
  11. images/icon.png.tootiny +0 -0
  12. images/replay.png +0 -0
  13. images/share.png +0 -0
  14. js/flowPlayer.js +449 -449
  15. js/jscolor/jscolor.js +830 -830
  16. js/pngfix.js +3 -3
  17. js/suggestions.js +9 -9
  18. models/flowplayer-backend.php +28 -26
  19. models/flowplayer-frontend.php +181 -130
  20. models/flowplayer.php +117 -150
  21. readme.txt +166 -75
  22. screenshot-2.png +0 -0
  23. screenshot-3.png +0 -0
  24. screenshot-4.png +0 -0
  25. view/admin.php +192 -167
  26. view/backend-head.php +12 -11
  27. view/colours.php +46 -46
  28. view/frontend-head.php +27 -26
  29. view/getid3/extension.cache.dbm.php +222 -0
  30. view/getid3/extension.cache.mysql.php +171 -0
  31. view/getid3/getid3.lib.php +1309 -0
  32. view/getid3/getid3.php +1397 -0
  33. view/getid3/module.archive.gzip.php +271 -0
  34. view/getid3/module.archive.rar.php +52 -0
  35. view/getid3/module.archive.szip.php +97 -0
  36. view/getid3/module.archive.tar.php +175 -0
  37. view/getid3/module.archive.zip.php +416 -0
  38. view/getid3/module.audio-video.asf.php +1673 -0
  39. view/getid3/module.audio-video.bink.php +70 -0
  40. view/getid3/module.audio-video.flv.php +505 -0
  41. view/getid3/module.audio-video.matroska.php +1712 -0
  42. view/getid3/module.audio-video.mpeg.php +292 -0
  43. view/getid3/module.audio-video.nsv.php +224 -0
  44. view/getid3/module.audio-video.quicktime.php +1382 -0
  45. view/getid3/module.audio-video.real.php +528 -0
  46. view/getid3/module.audio-video.riff.php +2110 -0
  47. view/getid3/module.audio-video.swf.php +149 -0
  48. view/getid3/module.audio.aac.php +542 -0
  49. view/getid3/module.audio.ac3.php +497 -0
  50. view/getid3/module.audio.au.php +163 -0
  51. view/getid3/module.audio.avr.php +125 -0
  52. view/getid3/module.audio.bonk.php +221 -0
  53. view/getid3/module.audio.dss.php +72 -0
  54. view/getid3/module.audio.dts.php +239 -0
  55. view/getid3/module.audio.flac.php +397 -0
  56. view/getid3/module.audio.la.php +228 -0
  57. view/getid3/module.audio.lpac.php +126 -0
  58. view/getid3/module.audio.midi.php +522 -0
  59. view/getid3/module.audio.mod.php +101 -0
  60. view/getid3/module.audio.monkey.php +202 -0
  61. view/getid3/module.audio.mp3.php +742 -0
controller/backend.php CHANGED
@@ -1,88 +1,166 @@
1
- <?php
2
-
3
- /**
4
- * Needed includes
5
- */
6
- include dirname( __FILE__ ) . '/../models/flowplayer.php';
7
- include dirname( __FILE__ ) . '/../models/flowplayer-backend.php';
8
-
9
- /**
10
- * Create the flowplayer_backend object
11
- */
12
- $fp = new flowplayer_backend();
13
-
14
- /**
15
- * WP Hooks
16
- */
17
- add_action('admin_head', 'flowplayer_head');
18
- add_action('admin_menu', 'flowplayer_admin');
19
- /**
20
- * END WP Hooks
21
- */
22
-
23
-
24
- /**
25
- * Administrator environment function.
26
- */
27
- function flowplayer_admin () {
28
-
29
- // if we are in administrator environment
30
- if (function_exists('add_submenu_page')) {
31
- add_options_page(
32
- 'FV Wordpress Flowplayer',
33
- 'FV Wordpress Flowplayer',
34
- 8,
35
- basename(__FILE__),
36
- 'flowplayer_page'
37
- );
38
- }
39
- }
40
-
41
- /**
42
- * Outputs HTML code for bool options based on arg passed.
43
- * @param string Currently selected value ('true' or 'false').
44
- * @return string HTML code
45
- */
46
- function flowplayer_bool_select($current) {
47
- switch($current) {
48
- case "true":
49
- $html = '<option selected="selected" value="true">true</option><option value="false">false</option>';
50
- break;
51
- case "false":
52
- $html = '<option value="true" >true</option><option selected="selected" value="false">false</option>';
53
- break;
54
- default:
55
- $html = '<option value="true">true</option><option selected="selected" value="false">false</option>';
56
- break;
57
- }
58
- return $html;
59
- }
60
-
61
- /**
62
- * Displays administrator menu with configuration.
63
- */
64
- function flowplayer_page() {
65
- //initialize the class:
66
- $fp = new flowplayer();
67
- include dirname( __FILE__ ) . '/../view/admin.php';
68
- }
69
-
70
- /**
71
- * Checks for errors regarding access to configuration file. Displays errors if any occur.
72
- * @param object $fp Flowplayer class object.
73
- */
74
- function flowplayer_check_errors($fp){
75
- $html = '';
76
- // config file checks, exists, readable, writeable
77
- $conf_file = realpath(dirname(__FILE__)).'/wpfp.conf';
78
- if(!file_exists($conf_file)){
79
- $html .= '<h3 style="font-weight: bold; color: #ff0000">'.$conf_file.' Does not exist please create it</h3>';
80
- } elseif(!is_readable($conf_file)){
81
- $html .= '<h3 style="font-weight: bold; color: #ff0000">'.$conf_file.' is not readable please check file permissions</h3>';
82
- } elseif(!is_writable($conf_file)){
83
- $html .= '<h3 style="font-weight: bold; color: #ff0000">'.$conf_file.' is not writable please check file permissions</h3>';
84
- }
85
- }
86
-
87
-
88
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Needed includes
5
+ */
6
+ include dirname( __FILE__ ) . '/../models/flowplayer.php';
7
+ include dirname( __FILE__ ) . '/../models/flowplayer-backend.php';
8
+
9
+ /**
10
+ * Create the flowplayer_backend object
11
+ */
12
+ $fp = new flowplayer_backend();
13
+
14
+ /**
15
+ * WP Hooks
16
+ */
17
+ add_action('admin_head', 'flowplayer_head');
18
+ add_action('admin_menu', 'flowplayer_admin');
19
+ add_action('media_buttons', 'flowplayer_add_media_button', 30);
20
+ add_action('media_upload_fv-wp-flowplayer', 'flowplayer_wizard');
21
+ add_filter('media_send_to_editor','fp_media_send_to_editor', 10, 3);
22
+ add_action('the_content', 'flowplayer_content_remove_commas');
23
+
24
+ function flowplayer_content_remove_commas($content){
25
+ preg_match('/.*popup=\'(.*?)\'.*/', $content, $matches);
26
+ //var_dump($matches);
27
+ $content_new = preg_replace('/\,/', '',$content);
28
+ if (isset($matches[1]))
29
+ $content_new = preg_replace('/popup=\'(.*?)\'/', 'popup=\''.$matches[1].'\'',$content_new);
30
+ // var_dump($content_new);
31
+ return $content_new;
32
+
33
+ }
34
+ /**
35
+ * END WP Hooks
36
+ */
37
+
38
+ function fp_media_send_to_editor($html, $attachment_id, $attachment){
39
+ if(isset($_POST['_wp_http_referer'])) {
40
+ preg_match('/width=([0-9]+)/',$_POST['_wp_http_referer'],$matchesw);
41
+ preg_match('/height=([0-9]+)/',$_POST['_wp_http_referer'],$matchesh);
42
+ }
43
+
44
+ if ((!empty($matchesw))&&(!empty($matchesh))&&($matchesw[1]==640)&&($matchesh[1]==723)){
45
+
46
+ $video_types = array('flv','mov','avi','mpeg','mpg','asf','qt','wmv');
47
+ $splash_types = array('jpg','jpeg','gif','png', 'bmp','jpe');
48
+ if (isset($attachment_id))
49
+ {
50
+ $attachment_url = wp_get_attachment_url($attachment_id);
51
+ $path_parts = pathinfo($attachment_url);
52
+ if (in_array($path_parts['extension'], $splash_types)){
53
+ setcookie("selected_image",$attachment_url);
54
+ $selected_attachment = array('url'=>$attachment_url,'id'=>$attachment_id);
55
+ }
56
+ else{
57
+ // if (in_array($path_parts['extension'], $video_types)){
58
+ setcookie("selected_video",$attachment_url);
59
+ $selected_attachment = array('url'=>$attachment_url);
60
+ }
61
+ }
62
+ wp_enqueue_style('media');
63
+ wp_iframe('flowplayer_wizard_function',$selected_attachment);
64
+ die;
65
+ }
66
+ }
67
+ function flowplayer_wizard() {
68
+ setcookie("selected_video",'',time()-3600);
69
+ setcookie("selected_image",'',time()-3600);
70
+ wp_enqueue_style('media');
71
+ wp_iframe('flowplayer_wizard_function','');
72
+ }
73
+
74
+ function flowplayer_wizard_function($selected_attachment) {
75
+ include dirname( __FILE__ ) . '/../view/wizard.php';
76
+ }
77
+
78
+ /**
79
+ * Administrator environment function.
80
+ */
81
+ function flowplayer_admin () {
82
+
83
+ // if we are in administrator environment
84
+ if (function_exists('add_submenu_page')) {
85
+ add_options_page(
86
+ 'FV Wordpress Flowplayer',
87
+ 'FV Wordpress Flowplayer',
88
+ 8,
89
+ basename(__FILE__),
90
+ 'flowplayer_page'
91
+ );
92
+ }
93
+ }
94
+
95
+ /**
96
+ * Outputs HTML code for bool options based on arg passed.
97
+ * @param string Currently selected value ('true' or 'false').
98
+ * @return string HTML code
99
+ */
100
+ function flowplayer_bool_select($current) {
101
+ switch($current) {
102
+ case "true":
103
+ $html = '<option selected="selected" value="true">true</option><option value="false">false</option>';
104
+ break;
105
+ case "false":
106
+ $html = '<option value="true" >true</option><option selected="selected" value="false">false</option>';
107
+ break;
108
+ default:
109
+ $html = '<option value="true">true</option><option selected="selected" value="false">false</option>';
110
+ break;
111
+ }
112
+ return $html;
113
+ }
114
+
115
+ /**
116
+ * Displays administrator menu with configuration.
117
+ */
118
+ function flowplayer_page() {
119
+ //initialize the class:
120
+ $fp = new flowplayer();
121
+ include dirname( __FILE__ ) . '/../view/admin.php';
122
+ }
123
+
124
+ /**
125
+ * Checks for errors regarding access to configuration file. Displays errors if any occur.
126
+ * @param object $fp Flowplayer class object.
127
+ */
128
+ function flowplayer_check_errors($fp){
129
+ $html = '';
130
+ // config file checks, exists, readable, writeable
131
+ $conf_file = realpath(dirname(__FILE__)).'/wpfp.conf'; //Zdenka: I think here should be /../
132
+
133
+ if(!file_exists($conf_file)){
134
+ $html .= '<h3 style="font-weight: bold; color: #ff0000">'.$conf_file.' Does not exist please create it</h3>';
135
+ } elseif(!is_readable($conf_file)){
136
+ $html .= '<h3 style="font-weight: bold; color: #ff0000">'.$conf_file.' is not readable please check file permissions</h3>';
137
+ } elseif(!is_writable($conf_file)){
138
+ $html .= '<h3 style="font-weight: bold; color: #ff0000">'.$conf_file.' is not writable please check file permissions</h3>';
139
+ }
140
+ // return $html; //Zdenka : Why is this not here?
141
+ }
142
+
143
+ function flowplayer_add_media_button(){
144
+ global $post;
145
+ $plugins = get_option('active_plugins');
146
+ $found = false;
147
+
148
+ foreach ( $plugins AS $plugin ) {
149
+ if( stripos($plugin,'foliopress-wysiwyg') !== FALSE )
150
+ $found = true;
151
+ }
152
+ if(!$found)
153
+ {
154
+ /*global $fmp_jw_url, $fmp_jw_files_dir;
155
+ $wizard_url = $fmp_jw_url . '/inc/shortcode_wizard.php';
156
+ $config_dir = $fmp_jw_files_dir . '/configs';
157
+ $playlist_dir = $fmp_jw_files_dir .'/playlists';
158
+ $button_src = $fmp_jw_url . '/inc/images/playerbutton.gif';
159
+ $button_tip = 'Insert a Flash MP3 Player';*/
160
+ $wizard_url = 'media-upload.php?post_id='.$post->ID.'&type=fv-wp-flowplayer';
161
+ $button_src = RELATIVE_PATH.'/images/icon.png';
162
+ echo '<a title="Add FV WP Flowplayer" href="'.$wizard_url.'&TB_iframe=true&width=500&height=300" class="thickbox" ><img src="' . $button_src . '" alt="' . $button_tip . '" /></a>';
163
+ }
164
+ }
165
+
166
+ ?>
controller/frontend.php CHANGED
@@ -1,103 +1,170 @@
1
- <?php
2
-
3
- /**
4
- * Needed includes
5
- */
6
- include dirname( __FILE__ ) . '/../models/flowplayer.php';
7
- include dirname( __FILE__ ) . '/../models/flowplayer-frontend.php';
8
-
9
- /**
10
- * WP Hooks
11
- */
12
- add_action('wp_head', 'flowplayer_head');
13
- add_action('the_content', 'flowplayer_content');
14
- add_action('wp_footer','flowplayer_display_scripts');
15
- // Addition for 0.9.15
16
- add_action('widget_text','flowplayer_content');
17
-
18
- /**
19
- * END WP Hooks
20
- */
21
-
22
- $GLOBALS['scripts'] = array();
23
-
24
- /**
25
- * Replaces the flowplayer tags in post content by players and fills the $GLOBALS['scripts'] array.
26
- * @param string Content to be parsed
27
- * @return string Modified content string
28
- */
29
- function flowplayer_content( $content ) {
30
-
31
- $content_matches = array();
32
- preg_match_all('/\[flowplayer\ [^\]]+\]/i', $content, $content_matches);
33
-
34
- // process all found tags
35
- foreach ($content_matches[0] as $tag) {
36
- $ntag = str_replace("\'",'&#039;',$tag);
37
-
38
- // search for URL
39
- preg_match("/src='([^']*?)'/i",$ntag,$tmp);
40
- if( $tmp[1] == NULL ) {
41
- preg_match_all("/src=([^,\s\]]*)/i",$ntag,$tmp);
42
- $media = $tmp[1][0];
43
- }
44
- else
45
- $media = $tmp[1];
46
-
47
- // width and heigth
48
- preg_match("/width=(\d*)/i",$ntag,$width);
49
- preg_match("/height=(\d*)/i",$ntag,$height);
50
-
51
- if( $width[1] != NULL)
52
- $arguments['width'] = $width[1];
53
- if( $height[1] != NULL)
54
- $arguments['height'] = $height[1];
55
-
56
- // search for popup in quotes
57
- preg_match("/popup='([^']*?)'/i",$ntag,$tmp);
58
- $arguments['popup'] = $tmp[1];
59
-
60
- // search for splash image
61
- preg_match("/splash='([^']*?)'/i",$ntag,$tmp);
62
- if( $tmp[1] == NULL ) {
63
- preg_match_all("/splash=([^,\s\]]*)/i",$ntag,$tmp);
64
- $arguments['splash'] = $tmp[1][0];
65
- }
66
- else
67
- $arguments['splash'] = $tmp[1];
68
-
69
- if (trim($media) != '') {
70
- // build new player
71
- $fp = new flowplayer_frontend();
72
- $new_player = $fp->build_min_player($media,$arguments);
73
- $content = str_replace($tag, $new_player['html'],$content);
74
- $GLOBALS['scripts'][] = $new_player['script'];
75
- }
76
- }
77
-
78
- return $content;
79
- }
80
-
81
-
82
- /**
83
- * Prints flowplayer javascript content to the bottom of the page.
84
- */
85
- function flowplayer_display_scripts() {
86
- if (!empty($GLOBALS['scripts'])) {
87
- echo "\n<script defer=\"defer\" type=\"text/javascript\">\n<!--\n\n";
88
- foreach ($GLOBALS['scripts'] as $scr) {
89
- echo $scr;
90
- }
91
- echo "\n\n//-->\n</script>\n";
92
- }
93
- }
94
-
95
- /**
96
- * This is the template tag. Use the standard Flowplayer shortcodes
97
- */
98
-
99
- function flowplayer($shortcode) {
100
- echo apply_filters('the_content',$shortcode);
101
- }
102
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  ?>
1
+ <?php
2
+
3
+ /**
4
+ * Needed includes
5
+ */
6
+ include dirname( __FILE__ ) . '/../models/flowplayer.php';
7
+ include dirname( __FILE__ ) . '/../models/flowplayer-frontend.php';
8
+
9
+ /**
10
+ * WP Hooks
11
+ */
12
+
13
+ //add_action('the_content', 'flowplayer_content_remove_commas');
14
+ add_action('wp_head', 'flowplayer_head');
15
+ add_action('wp_footer','flowplayer_display_scripts');
16
+ // Addition for 0.9.15
17
+ add_action('widget_text','flowplayer_content');
18
+
19
+ /**
20
+ * END WP Hooks
21
+ */
22
+
23
+ $GLOBALS['scripts'] = array();
24
+
25
+ function flowplayer_content_remove_commas($content){
26
+
27
+ preg_match('/.*popup=\'(.*?)\'.*/', $content, $matches);
28
+ //var_dump($matches);
29
+ $content_new = preg_replace('/\,/', '',$content);
30
+ if (isset($matches[1]))
31
+ $content_new = preg_replace('/popup=\'(.*?)\'/', 'popup=\''.$matches[1].'\'',$content_new);
32
+ // var_dump($content_new);
33
+ return $content_new;
34
+ }
35
+
36
+ /**
37
+ * Replaces the flowplayer tags in post content by players and fills the $GLOBALS['scripts'] array.
38
+ * @param string Content to be parsed
39
+ * @return string Modified content string
40
+ */
41
+ function flowplayer_content( $content ) {
42
+
43
+ $content_matches = array();
44
+ preg_match_all('/\[flowplayer\ [^\]]+\]/i', $content, $content_matches);
45
+
46
+ // process all found tags
47
+ foreach ($content_matches[0] as $tag) {
48
+ $ntag = str_replace("\'",'&#039;',$tag);
49
+
50
+ // search for URL
51
+ preg_match("/src='([^']*?)'/i",$ntag,$tmp);
52
+ if( $tmp[1] == NULL ) {
53
+ preg_match_all("/src=([^,\s\]]*)/i",$ntag,$tmp);
54
+ $media = $tmp[1][0];
55
+ }
56
+ else
57
+ $media = $tmp[1];
58
+ //strip the additional /videos/ from the beginning if present
59
+ preg_match('/(.*)\/videos\/(.*)/',$media,$matches);
60
+ /* if ($matches[0] == NULL)
61
+ $media = $matches[2];
62
+ else
63
+ $media = $matches[0];*/
64
+
65
+ if ($matches[0] == NULL)
66
+ $media = $media;
67
+ elseif ($matches[1] == NULL){
68
+ $media = $matches[2];//$tmp[1][0];
69
+ }
70
+ else{
71
+ $media = $matches[2];
72
+ }
73
+ // var_dump($media);
74
+
75
+ // width and heigth
76
+ preg_match("/width=(\d*)/i",$ntag,$width);
77
+ preg_match("/height=(\d*)/i",$ntag,$height);
78
+
79
+ if( $width[1] != NULL)
80
+ $arguments['width'] = $width[1];
81
+ if( $height[1] != NULL)
82
+ $arguments['height'] = $height[1];
83
+
84
+ preg_match("/controlbar=\'?([a-zA-Z]*)\'?/i",$ntag,$controlbar);
85
+ if( $controlbar[1] != NULL)
86
+ $arguments['controlbar'] = $controlbar[1];
87
+
88
+ preg_match("/redirect=\'?([^\s\]]*)\'?/i",$ntag,$redirect);
89
+ if( $redirect[1] != NULL)
90
+ $arguments['redirect'] = $redirect[1];
91
+
92
+ // search for autoplay
93
+ preg_match("/[\s]+autoplay([\s]|])+/i",$ntag,$tmp);
94
+ if (isset($tmp[0])){
95
+ $arguments['autoplay'] = true;
96
+ }
97
+ else
98
+ {
99
+ preg_match("/autoplay='([A-Za-z]*)'/i",$ntag,$tmp);
100
+ if ( $tmp[1] == NULL )
101
+ preg_match("/autoplay=([A-Za-z]*)/i",$ntag,$tmp);
102
+ if (isset($tmp[1])) $arguments['autoplay'] = $tmp[1];
103
+ }
104
+
105
+ // search for popup in quotes
106
+ preg_match("/popup='([^']*?)'/i",$ntag,$tmp);
107
+ $arguments['popup'] = $tmp[1];
108
+
109
+ // search for splash image
110
+ preg_match("/splash='([^']*?)'/i",$ntag,$tmp); //quotes version
111
+ if( $tmp[1] == NULL ) {
112
+ preg_match_all("/splash=([^,\s\]]*)/i",$ntag,$tmp); //non quotes version
113
+ preg_match('/(.*)\/videos\/(.*)/i',$tmp[1][0],$matches);
114
+ if ($matches[0] == NULL)
115
+ $arguments['splash'] = $tmp[1][0];
116
+ elseif ($matches[1] == NULL){
117
+ $arguments['splash'] = $matches[2];//$tmp[1][0];
118
+ }
119
+ else{
120
+ $arguments['splash'] = $matches[2];
121
+ }
122
+ }
123
+ else{
124
+ preg_match('/(.*)\/videos\/(.*)/',$tmp[1],$matches);
125
+ if ($matches[0] == NULL)
126
+ $arguments['splash'] = $tmp[1];
127
+ elseif ($matches[1] == NULL)
128
+ $arguments['splash'] = $matches[2];
129
+ else
130
+ $arguments['splash'] = $matches[2];//$tmp[1];
131
+ }
132
+
133
+
134
+
135
+ if (trim($media) != '') {
136
+ // build new player
137
+ $fp = new flowplayer_frontend();
138
+ $new_player = $fp->build_min_player($media,$arguments);
139
+ $content = str_replace($tag, $new_player['html'],$content);
140
+ $GLOBALS['scripts'][] = $new_player['script'];
141
+ }
142
+ }
143
+
144
+ return $content;
145
+ }
146
+
147
+
148
+
149
+ /**
150
+ * Prints flowplayer javascript content to the bottom of the page.
151
+ */
152
+ function flowplayer_display_scripts() {
153
+ if (!empty($GLOBALS['scripts'])) {
154
+ echo "\n<script defer=\"defer\" type=\"text/javascript\">\n<!--\n\n";
155
+ foreach ($GLOBALS['scripts'] as $scr) {
156
+ echo $scr;
157
+ }
158
+ echo "\n\n//-->\n</script>\n";
159
+ }
160
+ }
161
+
162
+ /**
163
+ * This is the template tag. Use the standard Flowplayer shortcodes
164
+ */
165
+
166
+ function flowplayer($shortcode) {
167
+ echo apply_filters('the_content',$shortcode);
168
+ }
169
+
170
  ?>
controller/shortcodes.php ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once dirname( __FILE__ ) . '/../models/flowplayer.php';
3
+ //require_once dirname( __FILE__ ) . '/../models/flowplayer-frontend.php';
4
+
5
+
6
+ add_shortcode('flowplayer','flowplayer_content_handle');
7
+
8
+ function flowplayer_content_handle( $atts ) {
9
+ /// Addition 2010/07/12 mv
10
+ $fp = new flowplayer_frontend();
11
+ if( $fp->conf['commas'] == 'true' ) {
12
+
13
+ if( !isset( $atts['src'] ) ) {
14
+ foreach( $atts AS $key => $att ) {
15
+ if( stripos( $att, 'src=' ) !== FALSE ) {
16
+ $atts['src'] = preg_replace( '/^\s*?src=[\'"](.*)[\'"],\s*?$/', '$1', $att );
17
+ $i = $key+1;
18
+ unset( $atts[$key] ); // = ''; // let's remove it, so it won't confuse the rest of workaaround
19
+ }
20
+ }
21
+ }
22
+
23
+ if( !isset( $atts['splash'] ) ) {
24
+ foreach( $atts AS $key => $att ) {
25
+ if( stripos( $att, 'splash=' ) !== FALSE ) {
26
+ $atts['splash'] = preg_replace( '/^\s*?splash=[\'"](.*)[\'"],\s*?$/', '$1', $att );
27
+ unset( $atts[$key] ); // = ''; // let's remove it, so it won't confuse the rest of workaround
28
+ }
29
+ }
30
+ }
31
+
32
+ // the popup should really be a content of the shortcode, not an attribute
33
+ // this part will fix the popup if there is any single quote in it.
34
+ if( !isset( $atts['popup'] ) ) {
35
+ $popup = array();
36
+ $is_popup = false;
37
+ foreach( $atts AS $key => $att ) {
38
+ if( !is_numeric( $key ) ) continue;
39
+ if( ( stripos( $att, 'popup=' ) !== FALSE || $is_popup ) && stripos( $att, 'src=' ) === FALSE && stripos( $att, 'splash=' ) === FALSE) {
40
+ $popup[] = $att;
41
+ $is_popup = true;
42
+ unset( $atts[$key] ); // = ''; // let's remove it, so it won't confuse the rest of workaround
43
+ }
44
+ }
45
+ $popup = implode( ' ', $popup );
46
+ $atts['popup'] = preg_replace( '/^\s*?popup=[\'"](.*)[\'"]\s*?$/mi', '$1', $popup );
47
+ }
48
+
49
+ }
50
+ /// End of addition
51
+
52
+ extract( shortcode_atts( array(
53
+ 'src' => '',
54
+ 'width' => '',
55
+ 'height' => '',
56
+ 'autoplay' => '',
57
+ 'splash' => '',
58
+ 'popup' => '',
59
+ 'controlbar' => '',
60
+ 'redirect' => ''
61
+ ), $atts ) );
62
+
63
+ $arguments['width'] = preg_replace('/\,/', '', $width);
64
+ $arguments['height'] = preg_replace('/\,/', '', $height);
65
+ $arguments['autoplay'] = preg_replace('/\,/', '', $autoplay);
66
+ // $arguments['embed'] = $embed;
67
+ $arguments['splash'] = preg_replace('/\,/', '', $splash);
68
+ $arguments['popup'] = $popup;
69
+ $arguments['controlbar'] = preg_replace('/\,/', '', $controlbar);
70
+ $arguments['redirect'] = preg_replace('/\,/', '', $redirect);
71
+
72
+ $src = preg_replace('/\,/', '', $src);
73
+ if (trim($src) != '') {
74
+ // build new player
75
+ //$fp = new flowplayer_frontend();
76
+ $new_player = $fp->build_min_player($src,$arguments);
77
+ // var_dump($new_player['html']);
78
+ $content = str_replace($src, $new_player['html'],$atts);
79
+ $GLOBALS['scripts'][] = $new_player['script'];
80
+ // var_dump($content);
81
+ }
82
+ return $new_player['html'];
83
+ // return $content;
84
+ }
85
+ ?>
css/flowplayer.css CHANGED
@@ -1,101 +1,115 @@
1
- .flowplayer_container
2
- {
3
- background: #0D0D0D url('../images/finished_bg.png') repeat-x;
4
- display: block;
5
- position: relative;
6
- border: solid 1px black;
7
- margin: 0 auto 0 auto !important;
8
- padding: 0 !important;
9
- text-align: center !important;
10
- }
11
-
12
- .flowplayer_container:hover
13
- {
14
- text-decoration: none;
15
- }
16
-
17
- /* SPLASH IMAGE */
18
- img.splash
19
- {
20
- position: absolute;
21
- top: 0 !important;
22
- left: 0 !important;
23
- width: 100%;
24
- height: 100%;
25
- cursor: pointer;
26
- background: none;
27
- border: none;
28
- margin: 0 !important;
29
- padding: 0 !important;
30
- }
31
-
32
- .splash_play_button
33
- {
34
- position: relative;
35
- margin: auto !important;
36
- cursor: pointer;
37
- background: none;
38
- border: none;
39
- padding: 0 !important;
40
- }
41
-
42
- /* POPUP */
43
- .popup_contents
44
- {
45
- visibility: hidden;
46
- position: absolute;
47
- top: -9999em;
48
- left: -9999em;
49
- }
50
-
51
- .flowplayer_popup
52
- {
53
- position: absolute;
54
- top: 10%;
55
- left: 10%;
56
- text-align: left;
57
- width: 70%;
58
- height: 60%;
59
- background: #454545;
60
- border: solid 1px #C0C0C0;
61
- color: #FFFFFF;
62
- padding: 5%;
63
- z-index: 999;
64
- }
65
-
66
- .wpfp_custom_popup
67
- {
68
- margin: 0;
69
- padding: 0;
70
- }
71
-
72
- .wpfp_custom_popup a, .wpfp_custom_popup a:hover, .wpfp_custom_popup a:visited, .wpfp_custom_popup a:active
73
- {
74
- color: white;
75
- text-decoration: none;
76
- }
77
-
78
- .flowplayer_popup a, .flowplayer_popup a img
79
- {
80
- margin: auto !important;
81
- cursor: pointer;
82
- background: none !important;
83
- border: none;
84
- padding: 0 !important;
85
- }
86
-
87
- .wpfp_custom_popup input
88
- {
89
- width: 80%;
90
- margin: 5px;
91
- }
92
-
93
- .popup_controls
94
- {
95
- text-align: center;
96
- font-size: 100%;
97
- }
98
-
99
-
100
-
101
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .flowplayer_container
2
+ {
3
+ background: #0D0D0D url('../images/finished_bg.png') repeat-x;
4
+ display: block;
5
+ position: relative;
6
+ border: solid 1px black;
7
+ margin: 0 auto 0 auto !important;
8
+ padding: 0 !important;
9
+ text-align: center !important;
10
+ }
11
+
12
+ .flowplayer_container:hover
13
+ {
14
+ text-decoration: none;
15
+ }
16
+
17
+ /* SPLASH IMAGE */
18
+ img.splash
19
+ {
20
+ position: absolute;
21
+ top: 0 !important;
22
+ left: 0 !important;
23
+ width: 100%;
24
+ height: 100%;
25
+ cursor: pointer;
26
+ background: none;
27
+ border: none;
28
+ margin: 0 !important;
29
+ padding: 0 !important;
30
+ }
31
+
32
+ .splash_play_button
33
+ {
34
+ position: relative;
35
+ margin: auto !important;
36
+ cursor: pointer;
37
+ background: none;
38
+ border: none;
39
+ padding: 0 !important;
40
+ }
41
+
42
+ /* POPUP */
43
+ .popup_contents
44
+ {
45
+ visibility: hidden;
46
+ position: absolute;
47
+ /*top: -9999em;
48
+ left: -9999em;*/
49
+ }
50
+
51
+ .flowplayer_popup
52
+ {
53
+ position: absolute;
54
+ top: 0%;
55
+ left: 0%;
56
+ text-align: left;
57
+ width: 100%;
58
+ height: 100%;
59
+ background: #000000;
60
+ border: solid 1px #000000;
61
+ color: #FFFFFF;
62
+ padding: 0%;
63
+ z-index: 999;
64
+ }
65
+
66
+ .wpfp_custom_popup
67
+ {
68
+ margin: 0;
69
+ padding: 0;
70
+ font-family: Arial, serif;
71
+
72
+ }
73
+
74
+ .wpfp_custom_popup a, .wpfp_custom_popup a:hover, .wpfp_custom_popup a:visited, .wpfp_custom_popup a:active
75
+ {
76
+ color: white;
77
+ text-decoration: none;
78
+ }
79
+
80
+ .flowplayer_popup a, .flowplayer_popup a img
81
+ {
82
+ margin: auto !important;
83
+ cursor: pointer !important;
84
+ background: none !important;
85
+ border: none;
86
+ padding: 0 !important;
87
+ }
88
+
89
+ .wpfp_custom_popup input
90
+ {
91
+ width: 80%;
92
+ margin: 5px;
93
+ }
94
+
95
+ .popup_controls
96
+ {
97
+ text-align: center;
98
+ font-size: 100%;
99
+ }
100
+
101
+ .link_button{
102
+ background: #0D0D0D url('../images/button-bg.png') repeat-x;
103
+ padding: 5px 20px;
104
+ border: 1px solid #eeeeee;
105
+ font-family: Arial, serif;
106
+ font-size:11pt;
107
+ z-index: 999;
108
+
109
+ }
110
+ .link_button a, .link_button a:visited, .link_button a:active{
111
+ color:#fff;
112
+ text-decoration: none;
113
+ }
114
+
115
+
flowplayer.php CHANGED
@@ -1,25 +1,28 @@
1
- <?PHP
2
- /*
3
- Plugin Name: FV Wordpress Flowplayer
4
- Plugin URI: http://foliovision.com/seo-tools/wordpress/plugins/fv-wordpress-flowplayer
5
- Description: Embed videos (FLV, H.264, and MP4) into posts or pages. Uses modified version of flowplayer (with removed FP logo and copyright notice).
6
- Version: 0.9.17
7
- Author: Foliovision
8
- Author URI: http://foliovision.com/
9
- */
10
-
11
-
12
- if(is_admin()) {
13
- /**
14
- * If administrator is logged, loads the controller for backend.
15
- */
16
- include( dirname( __FILE__ ) . '/controller/backend.php' );
17
- } else {
18
- /**
19
- * If administrator is not logged, loads the controller for frontend.
20
- */
21
- include( dirname( __FILE__ ) . '/controller/frontend.php' );
22
- }
23
-
24
-
25
- ?>
 
 
 
1
+ <?PHP
2
+ /*
3
+ Plugin Name: FV Wordpress Flowplayer
4
+ Plugin URI: http://foliovision.com/seo-tools/wordpress/plugins/fv-wordpress-flowplayer
5
+ Description: Embed videos (FLV, H.264, and MP4) into posts or pages. Uses modified version of flowplayer (with removed FP logo and copyright notice).
6
+ Version: 1.0.6
7
+ Author: Foliovision
8
+ Author URI: http://foliovision.com/
9
+ */
10
+
11
+ if(is_admin()) {
12
+ /**
13
+ * If administrator is logged, loads the controller for backend.
14
+ */
15
+
16
+ include( dirname( __FILE__ ) . '/controller/backend.php' );
17
+ require_once(dirname( __FILE__ ) . '/controller/shortcodes.php');
18
+
19
+ } else {
20
+ /**
21
+ * If administrator is not logged, loads the controller for frontend.
22
+ */
23
+ include( dirname( __FILE__ ) . '/controller/frontend.php' );
24
+ include( dirname( __FILE__ ) . '/controller/shortcodes.php');
25
+ }
26
+
27
+
28
+ ?>
flowplayer/flowplayer.min.js CHANGED
@@ -1,24 +1,24 @@
1
- /**
2
- * flowplayer.js 3.0.3. The Flowplayer API
3
- *
4
- * Copyright 2008 Flowplayer Oy
5
- *
6
- * This file is part of Flowplayer.
7
- *
8
- * Flowplayer is free software: you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License as published by
10
- * the Free Software Foundation, either version 3 of the License, or
11
- * (at your option) any later version.
12
- *
13
- * Flowplayer is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- * GNU General Public License for more details.
17
- *
18
- * You should have received a copy of the GNU General Public License
19
- * along with Flowplayer. If not, see <http://www.gnu.org/licenses/>.
20
- *
21
- * Version: 3.0.3 - Wed Jan 07 2009 13:22:30 GMT-0000 (GMT+00:00)
22
- */
23
- (function(){function log(args){console.log("$f.fireEvent",[].slice.call(args));}function clone(obj){if(!obj||typeof obj!='object'){return obj;}var temp=new obj.constructor();for(var key in obj){if(obj.hasOwnProperty(key)){temp[key]=clone(obj[key]);}}return temp;}function each(obj,fn){if(!obj){return;}var name,i=0,length=obj.length;if(length===undefined){for(name in obj){if(fn.call(obj[name],name,obj[name])===false){break;}}}else{for(var value=obj[0];i<length&&fn.call(value,i,value)!==false;value=obj[++i]){}}return obj;}function el(id){return document.getElementById(id);}function extend(to,from,skipFuncs){if(to&&from){each(from,function(name,value){if(!skipFuncs||typeof value!='function'){to[name]=value;}});}}function select(query){var index=query.indexOf(".");if(index!=-1){var tag=query.substring(0,index)||"*";var klass=query.substring(index+1,query.length);var els=[];each(document.getElementsByTagName(tag),function(){if(this.className&&this.className.indexOf(klass)!=-1){els.push(this);}});return els;}}function stopEvent(e){e=e||window.event;if(e.preventDefault){e.stopPropagation();e.preventDefault();}else{e.returnValue=false;e.cancelBubble=true;}return false;}function bind(to,evt,fn){to[evt]=to[evt]||[];to[evt].push(fn);}function makeId(){return"_"+(""+Math.random()).substring(2,10);}var Clip=function(json,index,player){var self=this;var cuepoints={};var listeners={};self.index=index;if(typeof json=='string'){json={url:json};}extend(this,json,true);each(("Begin*,Start,Pause*,Resume*,Seek*,Stop*,Finish*,LastSecond,Update,BufferFull,BufferEmpty,BufferStop").split(","),function(){var evt="on"+this;if(evt.indexOf("*")!=-1){evt=evt.substring(0,evt.length-1);var before="onBefore"+evt.substring(2);self[before]=function(fn){bind(listeners,before,fn);return self;};}self[evt]=function(fn){bind(listeners,evt,fn);return self;};if(index==-1){if(self[before]){player[before]=self[before];}if(self[evt]){player[evt]=self[evt];}}});extend(this,{onCuepoint:function(points,fn){if(arguments.length==1){cuepoints.embedded=[null,points];return self;}if(typeof points=='number'){points=[points];}var fnId=makeId();cuepoints[fnId]=[points,fn];if(player.isLoaded()){player._api().fp_addCuepoints(points,index,fnId);}return self;},update:function(json){extend(self,json);if(player.isLoaded()){player._api().fp_updateClip(json,index);}var conf=player.getConfig();var clip=(index==-1)?conf.clip:conf.playlist[index];extend(clip,json,true);},_fireEvent:function(evt,arg1,arg2,target){if(evt=='onLoad'){each(cuepoints,function(key,val){if(val[0]){player._api().fp_addCuepoints(val[0],index,key);}});return false;}if(index!=-1){target=self;}if(evt=='onCuepoint'){var fn=cuepoints[arg1];if(fn){return fn[1].call(player,target,arg2);}}if(evt=='onStart'||evt=='onUpdate'){extend(target,arg1);if(!target.duration){target.duration=arg1.metaData.duration;}else{target.fullDuration=arg1.metaData.duration;}}var ret=true;each(listeners[evt],function(){ret=this.call(player,target,arg1,arg2);});return ret;}});if(json.onCuepoint){var arg=json.onCuepoint;self.onCuepoint.apply(self,typeof arg=='function'?[arg]:arg);delete json.onCuepoint;}each(json,function(key,val){if(typeof val=='function'){bind(listeners,key,val);delete json[key];}});if(index==-1){player.onCuepoint=this.onCuepoint;}};var Plugin=function(name,json,player,fn){var listeners={};var self=this;var hasMethods=false;if(fn){extend(listeners,fn);}each(json,function(key,val){if(typeof val=='function'){listeners[key]=val;delete json[key];}});extend(this,{animate:function(props,speed,fn){if(!props){return self;}if(typeof speed=='function'){fn=speed;speed=500;}if(typeof props=='string'){var key=props;props={};props[key]=speed;speed=500;}if(fn){var fnId=makeId();listeners[fnId]=fn;}if(speed===undefined){speed=500;}json=player._api().fp_animate(name,props,speed,fnId);return self;},css:function(props,val){if(val!==undefined){var css={};css[props]=val;props=css;}json=player._api().fp_css(name,props);extend(self,json);return self;},show:function(){this.display='block';player._api().fp_showPlugin(name);return self;},hide:function(){this.display='none';player._api().fp_hidePlugin(name);return self;},toggle:function(){this.display=player._api().fp_togglePlugin(name);return self;},fadeTo:function(o,speed,fn){if(typeof speed=='function'){fn=speed;speed=500;}if(fn){var fnId=makeId();listeners[fnId]=fn;}this.display=player._api().fp_fadeTo(name,o,speed,fnId);this.opacity=o;return self;},fadeIn:function(speed,fn){return self.fadeTo(1,speed,fn);},fadeOut:function(speed,fn){return self.fadeTo(0,speed,fn);},getName:function(){return name;},_fireEvent:function(evt,arg){if(evt=='onUpdate'){var json=player._api().fp_getPlugin(name);if(!json){return;}extend(self,json);delete self.methods;if(!hasMethods){each(json.methods,function(){var method=""+this;self[method]=function(){var a=[].slice.call(arguments);var ret=player._api().fp_invoke(name,method,a);return ret=='undefined'?self:ret;};});hasMethods=true;}}var fn=listeners[evt];if(fn){fn.call(self,arg);if(evt.substring(0,1)=="_"){delete listeners[evt];}}}});};function Player(wrapper,params,conf){var
24
  self=this,api=null,html,commonClip,playlist=[],plugins={},listeners={},playerId,apiId,playerIndex,activeIndex,swfHeight,wrapperHeight;extend(self,{id:function(){return playerId;},isLoaded:function(){return(api!==null);},getParent:function(){return wrapper;},hide:function(all){if(all){wrapper.style.height="0px";}if(api){api.style.height="0px";}return self;},show:function(){wrapper.style.height=wrapperHeight+"px";if(api){api.style.height=swfHeight+"px";}return self;},isHidden:function(){return api&&parseInt(api.style.height,10)===0;},load:function(fn){if(!api&&self._fireEvent("onBeforeLoad")!==false){each(players,function(){this.unload();});html=wrapper.innerHTML;flashembed(wrapper,params,{config:conf});if(fn){fn.cached=true;bind(listeners,"onLoad",fn);}}return self;},unload:function(){try{if(api&&api.fp_isFullscreen()){}}catch(error){return;}if(api&&html.replace(/\s/g,'')!==''&&!api.fp_isFullscreen()&&self._fireEvent("onBeforeUnload")!==false){api.fp_close();wrapper.innerHTML=html;self._fireEvent("onUnload");api=null;}return self;},getClip:function(index){if(index===undefined){index=activeIndex;}return playlist[index];},getCommonClip:function(){return commonClip;},getPlaylist:function(){return playlist;},getPlugin:function(name){var plugin=plugins[name];if(!plugin&&self.isLoaded()){var json=self._api().fp_getPlugin(name);if(json){plugin=new Plugin(name,json,self);plugins[name]=plugin;}}return plugin;},getScreen:function(){return self.getPlugin("screen");},getControls:function(){return self.getPlugin("controls");},getConfig:function(copy){return copy?clone(conf):conf;},getFlashParams:function(){return params;},loadPlugin:function(name,url,props,fn){if(typeof props=='function'){fn=props;props={};}var fnId=fn?makeId():"_";self._api().fp_loadPlugin(name,url,props,fnId);var arg={};arg[fnId]=fn;var p=new Plugin(name,null,self,arg);plugins[name]=p;return p;},getState:function(){return api?api.fp_getState():-1;},play:function(clip){function play(){if(clip!==undefined){self._api().fp_play(clip);}else{self._api().fp_play();}}if(api){play();}else{self.load(function(){play();});}return self;},getVersion:function(){var js="flowplayer.js 3.0.3";if(api){var ver=api.fp_getVersion();ver.push(js);return ver;}return js;},_api:function(){if(!api){throw"Flowplayer "+self.id()+" not loaded. Try moving your call to player's onLoad event";}return api;},_dump:function(){console.log(listeners);},setClip:function(clip){self.setPlaylist([clip]);},getIndex:function(){return playerIndex;}});each(("Click*,Load*,Unload*,Keypress*,Volume*,Mute*,Unmute*,PlaylistReplace,Fullscreen*,FullscreenExit,Error").split(","),function(){var name="on"+this;if(name.indexOf("*")!=-1){name=name.substring(0,name.length-1);var name2="onBefore"+name.substring(2);self[name2]=function(fn){bind(listeners,name2,fn);return self;};}self[name]=function(fn){bind(listeners,name,fn);return self;};});each(("pause,resume,mute,unmute,stop,toggle,seek,getStatus,getVolume,setVolume,getTime,isPaused,isPlaying,startBuffering,stopBuffering,isFullscreen,reset,close,setPlaylist").split(","),function(){var name=this;self[name]=function(arg){if(!api){return self;}var ret=(arg===undefined)?api["fp_"+name]():api["fp_"+name](arg);return ret=='undefined'?self:ret;};});self._fireEvent=function(evt,arg0,arg1,arg2){if(conf.debug){log(arguments);}if(!api&&evt=='onLoad'&&arg0=='player'){api=api||el(apiId);swfHeight=api.clientHeight;each(playlist,function(){this._fireEvent("onLoad");});each(plugins,function(name,p){p._fireEvent("onUpdate");});commonClip._fireEvent("onLoad");}if(evt=='onLoad'&&arg0!='player'){return;}if(evt=='onError'){if(typeof arg0=='string'||(typeof arg0=='number'&&typeof arg1=='number')){arg0=arg1;arg1=arg2;}}if(evt=='onContextMenu'){each(conf.contextMenu[arg0],function(key,fn){fn.call(self);});return;}if(evt=='onPluginEvent'){var name=arg0.name||arg0;var p=plugins[name];if(p){p._fireEvent("onUpdate",arg0);p._fireEvent(arg1);}return;}if(evt=='onPlaylistReplace'){playlist=[];var index=0;each(arg0,function(){playlist.push(new Clip(this,index++,self));});}var ret=true;if(arg0===0||(arg0&&arg0>=0&&arg0<playlist.length)){activeIndex=arg0;var clip=playlist[arg0];if(clip){ret=clip._fireEvent(evt,arg1,arg2);}if(!clip||ret!==false){ret=commonClip._fireEvent(evt,arg1,arg2,clip);}}var i=0;each(listeners[evt],function(){ret=this.call(self,arg0,arg1);if(this.cached){listeners[evt].splice(i,1);}if(ret===false){return false;}i++;});return ret;};function init(){if($f(wrapper)){$f(wrapper).getParent().innerHTML="";playerIndex=$f(wrapper).getIndex();players[playerIndex]=self;}else{players.push(self);playerIndex=players.length-1;}wrapperHeight=parseInt(wrapper.style.height,10)||wrapper.clientHeight;if(typeof params=='string'){params={src:params};}playerId=wrapper.id||"fp"+makeId();apiId=params.id||playerId+"_api";params.id=apiId;conf.playerId=playerId;if(typeof conf=='string'){conf={clip:{url:conf}};}conf.clip=conf.clip||{};if(wrapper.getAttribute("href",2)&&!conf.clip.url){conf.clip.url=wrapper.getAttribute("href",2);}commonClip=new Clip(conf.clip,-1,self);conf.playlist=conf.playlist||[conf.clip];var index=0;each(conf.playlist,function(){var clip=this;if(typeof clip=='object'&&clip.length){clip=""+clip;}if(!clip.url&&typeof clip=='string'){clip={url:clip};}each(conf.clip,function(key,val){if(clip[key]===undefined&&typeof val!='function'){clip[key]=val;}});conf.playlist[index]=clip;clip=new Clip(clip,index,self);playlist.push(clip);index++;});each(conf,function(key,val){if(typeof val=='function'){bind(listeners,key,val);delete conf[key];}});each(conf.plugins,function(name,val){if(val){plugins[name]=new Plugin(name,val,self);}});if(!conf.plugins||conf.plugins.controls===undefined){plugins.controls=new Plugin("controls",null,self);}params.bgcolor=params.bgcolor||"#000000";params.version=params.version||[9,0];params.expressInstall='http://www.flowplayer.org/swf/expressinstall.swf';function doClick(e){if(!self.isLoaded()&&self._fireEvent("onBeforeClick")!==false){self.load();}return stopEvent(e);}html=wrapper.innerHTML;if(html.replace(/\s/g,'')!==''){if(wrapper.addEventListener){wrapper.addEventListener("click",doClick,false);}else if(wrapper.attachEvent){wrapper.attachEvent("onclick",doClick);}}else{if(wrapper.addEventListener){wrapper.addEventListener("click",stopEvent,false);}self.load();}}if(typeof wrapper=='string'){flashembed.domReady(function(){var node=el(wrapper);if(!node){throw"Flowplayer cannot access element: "+wrapper;}else{wrapper=node;init();}});}else{init();}}var players=[];function Iterator(arr){this.length=arr.length;this.each=function(fn){each(arr,fn);};this.size=function(){return arr.length;};}window.flowplayer=window.$f=function(){var instance=null;var arg=arguments[0];if(!arguments.length){each(players,function(){if(this.isLoaded()){instance=this;return false;}});return instance||players[0];}if(arguments.length==1){if(typeof arg=='number'){return players[arg];}else{if(arg=='*'){return new Iterator(players);}each(players,function(){if(this.id()==arg.id||this.id()==arg||this.getParent()==arg){instance=this;return false;}});return instance;}}if(arguments.length>1){var swf=arguments[1];var conf=(arguments.length==3)?arguments[2]:{};if(typeof arg=='string'){if(arg.indexOf(".")!=-1){var instances=[];each(select(arg),function(){instances.push(new Player(this,clone(swf),clone(conf)));});return new Iterator(instances);}else{var node=el(arg);return new Player(node!==null?node:arg,swf,conf);}}else if(arg){return new Player(arg,swf,conf);}}return null;};extend(window.$f,{fireEvent:function(id,evt,a0,a1,a2){var p=$f(id);return p?p._fireEvent(evt,a0,a1,a2):null;},addPlugin:function(name,fn){Player.prototype[name]=fn;return $f;},each:each,extend:extend});if(document.all){window.onbeforeunload=function(){$f("*").each(function(){if(this.isLoaded()){this.close();}});};}if(typeof jQuery=='function'){jQuery.prototype.flowplayer=function(params,conf){if(!arguments.length||typeof arguments[0]=='number'){var arr=[];this.each(function(){var p=$f(this);if(p){arr.push(p);}});return arguments.length?arr[arguments[0]]:new Iterator(arr);}return this.each(function(){$f(this,clone(params),conf?clone(conf):{});});};}})();(function(){var jQ=typeof jQuery=='function';function isDomReady(){if(domReady.done){return false;}var d=document;if(d&&d.getElementsByTagName&&d.getElementById&&d.body){clearInterval(domReady.timer);domReady.timer=null;for(var i=0;i<domReady.ready.length;i++){domReady.ready[i].call();}domReady.ready=null;domReady.done=true;}}var domReady=jQ?jQuery:function(f){if(domReady.done){return f();}if(domReady.timer){domReady.ready.push(f);}else{domReady.ready=[f];domReady.timer=setInterval(isDomReady,13);}};function extend(to,from){if(from){for(key in from){if(from.hasOwnProperty(key)){to[key]=from[key];}}}return to;}function concatVars(vars){var out="";for(var key in vars){if(vars[key]){out+=[key]+'='+asString(vars[key])+'&';}}return out.substring(0,out.length-1);}function asString(obj){switch(typeOf(obj)){case'string':obj=obj.replace(new RegExp('(["\\\\])','g'),'\\$1');obj=obj.replace(/^\s?(\d+)%/,"$1pct");return'"'+obj+'"';case'array':return'['+map(obj,function(el){return asString(el);}).join(',')+']';case'function':return'"function()"';case'object':var str=[];for(var prop in obj){if(obj.hasOwnProperty(prop)){str.push('"'+prop+'":'+asString(obj[prop]));}}return'{'+str.join(',')+'}';}return String(obj).replace(/\s/g," ").replace(/\'/g,"\"");}function typeOf(obj){if(obj===null||obj===undefined){return false;}var type=typeof obj;return(type=='object'&&obj.push)?'array':type;}if(window.attachEvent){window.attachEvent("onbeforeunload",function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};});}function map(arr,func){var newArr=[];for(var i in arr){if(arr.hasOwnProperty(i)){newArr[i]=func(arr[i]);}}return newArr;}function getEmbedCode(p,c){var html='<embed type="application/x-shockwave-flash" ';if(p.id){extend(p,{name:p.id});}for(var key in p){if(p[key]!==null){html+=key+'="'+p[key]+'"\n\t';}}if(c){html+='flashvars=\''+concatVars(c)+'\'';}html+='/>';return html;}function getObjectCode(p,c,embeddable){var html='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';html+='width="'+p.width+'" height="'+p.height+'"';if(!p.id&&document.all){p.id="_"+(""+Math.random()).substring(5);}if(p.id){html+=' id="'+p.id+'"';}html+='>';if(document.all){p.src+=((p.src.indexOf("?")!=-1?"&":"?")+Math.random());}html+='\n\t<param name="movie" value="'+p.src+'" />';var e=extend({},p);e.id=e.width=e.height=e.src=null;for(var k in e){if(e[k]!==null){html+='\n\t<param name="'+k+'" value="'+e[k]+'" />';}}if(c){html+='\n\t<param name="flashvars" value=\''+concatVars(c)+'\' />';}if(embeddable){html+=getEmbedCode(p,c);}html+="</object>";return html;}function getFullHTML(p,c){return getObjectCode(p,c,true);}function getHTML(p,c){var isNav=navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length;return(isNav)?getEmbedCode(p,c):getObjectCode(p,c);}window.flashembed=function(root,userParams,flashvars){var params={src:'#',width:'100%',height:'100%',version:null,onFail:null,expressInstall:null,debug:false,allowfullscreen:true,allowscriptaccess:'always',quality:'high',type:'application/x-shockwave-flash',pluginspage:'http://www.adobe.com/go/getflashplayer'};if(typeof userParams=='string'){userParams={src:userParams};}extend(params,userParams);var version=flashembed.getVersion();var required=params.version;var express=params.expressInstall;var debug=params.debug;if(typeof root=='string'){var el=document.getElementById(root);if(el){root=el;}else{domReady(function(){flashembed(root,userParams,flashvars);});return;}}if(!root){return;}if(!required||flashembed.isSupported(required)){params.onFail=params.version=params.expressInstall=params.debug=null;root.innerHTML=getHTML(params,flashvars);return root.firstChild;}else if(params.onFail){var ret=params.onFail.call(params,flashembed.getVersion(),flashvars);if(ret===true){root.innerHTML=ret;}}else if(required&&express&&flashembed.isSupported([6,65])){extend(params,{src:express});flashvars={MMredirectURL:location.href,MMplayerType:'PlugIn',MMdoctitle:document.title};root.innerHTML=getHTML(params,flashvars);}else{if(root.innerHTML.replace(/\s/g,'')!==''){}else{root.innerHTML="<h2>Flash version "+required+" or greater is required</h2>"+"<h3>"+(version[0]>0?"Your version is "+version:"You have no flash plugin installed")+"</h3>"+"<p>Download latest version from <a href='"+params.pluginspage+"'>here</a></p>";}}return root;};extend(window.flashembed,{getVersion:function(){var version=[0,0];if(navigator.plugins&&typeof navigator.plugins["Shockwave Flash"]=="object"){var _d=navigator.plugins["Shockwave Flash"].description;if(typeof _d!="undefined"){_d=_d.replace(/^.*\s+(\S+\s+\S+$)/,"$1");var _m=parseInt(_d.replace(/^(.*)\..*$/,"$1"),10);var _r=/r/.test(_d)?parseInt(_d.replace(/^.*r(.*)$/,"$1"),10):0;version=[_m,_r];}}else if(window.ActiveXObject){try{var _a=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{_a=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");version=[6,0];_a.AllowScriptAccess="always";}catch(ee){if(version[0]==6){return;}}try{_a=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(eee){}}if(typeof _a=="object"){_d=_a.GetVariable("$version");if(typeof _d!="undefined"){_d=_d.replace(/^\S+\s+(.*)$/,"$1").split(",");version=[parseInt(_d[0],10),parseInt(_d[2],10)];}}}return version;},isSupported:function(version){var now=flashembed.getVersion();var ret=(now[0]>version[0])||(now[0]==version[0]&&now[1]>=version[1]);return ret;},domReady:domReady,asString:asString,getHTML:getHTML,getFullHTML:getFullHTML});if(jQ){jQuery.prototype.flashembed=function(params,flashvars){return this.each(function(){flashembed(this,params,flashvars);});};}})();
1
+ /**
2
+ * flowplayer.js 3.0.3. The Flowplayer API
3
+ *
4
+ * Copyright 2008 Flowplayer Oy
5
+ *
6
+ * This file is part of Flowplayer.
7
+ *
8
+ * Flowplayer is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * Flowplayer is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with Flowplayer. If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ * Version: 3.0.3 - Wed Jan 07 2009 13:22:30 GMT-0000 (GMT+00:00)
22
+ */
23
+ (function(){function log(args){console.log("$f.fireEvent",[].slice.call(args));}function clone(obj){if(!obj||typeof obj!='object'){return obj;}var temp=new obj.constructor();for(var key in obj){if(obj.hasOwnProperty(key)){temp[key]=clone(obj[key]);}}return temp;}function each(obj,fn){if(!obj){return;}var name,i=0,length=obj.length;if(length===undefined){for(name in obj){if(fn.call(obj[name],name,obj[name])===false){break;}}}else{for(var value=obj[0];i<length&&fn.call(value,i,value)!==false;value=obj[++i]){}}return obj;}function el(id){return document.getElementById(id);}function extend(to,from,skipFuncs){if(to&&from){each(from,function(name,value){if(!skipFuncs||typeof value!='function'){to[name]=value;}});}}function select(query){var index=query.indexOf(".");if(index!=-1){var tag=query.substring(0,index)||"*";var klass=query.substring(index+1,query.length);var els=[];each(document.getElementsByTagName(tag),function(){if(this.className&&this.className.indexOf(klass)!=-1){els.push(this);}});return els;}}function stopEvent(e){e=e||window.event;if(e.preventDefault){e.stopPropagation();e.preventDefault();}else{e.returnValue=false;e.cancelBubble=true;}return false;}function bind(to,evt,fn){to[evt]=to[evt]||[];to[evt].push(fn);}function makeId(){return"_"+(""+Math.random()).substring(2,10);}var Clip=function(json,index,player){var self=this;var cuepoints={};var listeners={};self.index=index;if(typeof json=='string'){json={url:json};}extend(this,json,true);each(("Begin*,Start,Pause*,Resume*,Seek*,Stop*,Finish*,LastSecond,Update,BufferFull,BufferEmpty,BufferStop").split(","),function(){var evt="on"+this;if(evt.indexOf("*")!=-1){evt=evt.substring(0,evt.length-1);var before="onBefore"+evt.substring(2);self[before]=function(fn){bind(listeners,before,fn);return self;};}self[evt]=function(fn){bind(listeners,evt,fn);return self;};if(index==-1){if(self[before]){player[before]=self[before];}if(self[evt]){player[evt]=self[evt];}}});extend(this,{onCuepoint:function(points,fn){if(arguments.length==1){cuepoints.embedded=[null,points];return self;}if(typeof points=='number'){points=[points];}var fnId=makeId();cuepoints[fnId]=[points,fn];if(player.isLoaded()){player._api().fp_addCuepoints(points,index,fnId);}return self;},update:function(json){extend(self,json);if(player.isLoaded()){player._api().fp_updateClip(json,index);}var conf=player.getConfig();var clip=(index==-1)?conf.clip:conf.playlist[index];extend(clip,json,true);},_fireEvent:function(evt,arg1,arg2,target){if(evt=='onLoad'){each(cuepoints,function(key,val){if(val[0]){player._api().fp_addCuepoints(val[0],index,key);}});return false;}if(index!=-1){target=self;}if(evt=='onCuepoint'){var fn=cuepoints[arg1];if(fn){return fn[1].call(player,target,arg2);}}if(evt=='onStart'||evt=='onUpdate'){extend(target,arg1);if(!target.duration){target.duration=arg1.metaData.duration;}else{target.fullDuration=arg1.metaData.duration;}}var ret=true;each(listeners[evt],function(){ret=this.call(player,target,arg1,arg2);});return ret;}});if(json.onCuepoint){var arg=json.onCuepoint;self.onCuepoint.apply(self,typeof arg=='function'?[arg]:arg);delete json.onCuepoint;}each(json,function(key,val){if(typeof val=='function'){bind(listeners,key,val);delete json[key];}});if(index==-1){player.onCuepoint=this.onCuepoint;}};var Plugin=function(name,json,player,fn){var listeners={};var self=this;var hasMethods=false;if(fn){extend(listeners,fn);}each(json,function(key,val){if(typeof val=='function'){listeners[key]=val;delete json[key];}});extend(this,{animate:function(props,speed,fn){if(!props){return self;}if(typeof speed=='function'){fn=speed;speed=500;}if(typeof props=='string'){var key=props;props={};props[key]=speed;speed=500;}if(fn){var fnId=makeId();listeners[fnId]=fn;}if(speed===undefined){speed=500;}json=player._api().fp_animate(name,props,speed,fnId);return self;},css:function(props,val){if(val!==undefined){var css={};css[props]=val;props=css;}json=player._api().fp_css(name,props);extend(self,json);return self;},show:function(){this.display='block';player._api().fp_showPlugin(name);return self;},hide:function(){this.display='none';player._api().fp_hidePlugin(name);return self;},toggle:function(){this.display=player._api().fp_togglePlugin(name);return self;},fadeTo:function(o,speed,fn){if(typeof speed=='function'){fn=speed;speed=500;}if(fn){var fnId=makeId();listeners[fnId]=fn;}this.display=player._api().fp_fadeTo(name,o,speed,fnId);this.opacity=o;return self;},fadeIn:function(speed,fn){return self.fadeTo(1,speed,fn);},fadeOut:function(speed,fn){return self.fadeTo(0,speed,fn);},getName:function(){return name;},_fireEvent:function(evt,arg){if(evt=='onUpdate'){var json=player._api().fp_getPlugin(name);if(!json){return;}extend(self,json);delete self.methods;if(!hasMethods){each(json.methods,function(){var method=""+this;self[method]=function(){var a=[].slice.call(arguments);var ret=player._api().fp_invoke(name,method,a);return ret=='undefined'?self:ret;};});hasMethods=true;}}var fn=listeners[evt];if(fn){fn.call(self,arg);if(evt.substring(0,1)=="_"){delete listeners[evt];}}}});};function Player(wrapper,params,conf){var
24
  self=this,api=null,html,commonClip,playlist=[],plugins={},listeners={},playerId,apiId,playerIndex,activeIndex,swfHeight,wrapperHeight;extend(self,{id:function(){return playerId;},isLoaded:function(){return(api!==null);},getParent:function(){return wrapper;},hide:function(all){if(all){wrapper.style.height="0px";}if(api){api.style.height="0px";}return self;},show:function(){wrapper.style.height=wrapperHeight+"px";if(api){api.style.height=swfHeight+"px";}return self;},isHidden:function(){return api&&parseInt(api.style.height,10)===0;},load:function(fn){if(!api&&self._fireEvent("onBeforeLoad")!==false){each(players,function(){this.unload();});html=wrapper.innerHTML;flashembed(wrapper,params,{config:conf});if(fn){fn.cached=true;bind(listeners,"onLoad",fn);}}return self;},unload:function(){try{if(api&&api.fp_isFullscreen()){}}catch(error){return;}if(api&&html.replace(/\s/g,'')!==''&&!api.fp_isFullscreen()&&self._fireEvent("onBeforeUnload")!==false){api.fp_close();wrapper.innerHTML=html;self._fireEvent("onUnload");api=null;}return self;},getClip:function(index){if(index===undefined){index=activeIndex;}return playlist[index];},getCommonClip:function(){return commonClip;},getPlaylist:function(){return playlist;},getPlugin:function(name){var plugin=plugins[name];if(!plugin&&self.isLoaded()){var json=self._api().fp_getPlugin(name);if(json){plugin=new Plugin(name,json,self);plugins[name]=plugin;}}return plugin;},getScreen:function(){return self.getPlugin("screen");},getControls:function(){return self.getPlugin("controls");},getConfig:function(copy){return copy?clone(conf):conf;},getFlashParams:function(){return params;},loadPlugin:function(name,url,props,fn){if(typeof props=='function'){fn=props;props={};}var fnId=fn?makeId():"_";self._api().fp_loadPlugin(name,url,props,fnId);var arg={};arg[fnId]=fn;var p=new Plugin(name,null,self,arg);plugins[name]=p;return p;},getState:function(){return api?api.fp_getState():-1;},play:function(clip){function play(){if(clip!==undefined){self._api().fp_play(clip);}else{self._api().fp_play();}}if(api){play();}else{self.load(function(){play();});}return self;},getVersion:function(){var js="flowplayer.js 3.0.3";if(api){var ver=api.fp_getVersion();ver.push(js);return ver;}return js;},_api:function(){if(!api){throw"Flowplayer "+self.id()+" not loaded. Try moving your call to player's onLoad event";}return api;},_dump:function(){console.log(listeners);},setClip:function(clip){self.setPlaylist([clip]);},getIndex:function(){return playerIndex;}});each(("Click*,Load*,Unload*,Keypress*,Volume*,Mute*,Unmute*,PlaylistReplace,Fullscreen*,FullscreenExit,Error").split(","),function(){var name="on"+this;if(name.indexOf("*")!=-1){name=name.substring(0,name.length-1);var name2="onBefore"+name.substring(2);self[name2]=function(fn){bind(listeners,name2,fn);return self;};}self[name]=function(fn){bind(listeners,name,fn);return self;};});each(("pause,resume,mute,unmute,stop,toggle,seek,getStatus,getVolume,setVolume,getTime,isPaused,isPlaying,startBuffering,stopBuffering,isFullscreen,reset,close,setPlaylist").split(","),function(){var name=this;self[name]=function(arg){if(!api){return self;}var ret=(arg===undefined)?api["fp_"+name]():api["fp_"+name](arg);return ret=='undefined'?self:ret;};});self._fireEvent=function(evt,arg0,arg1,arg2){if(conf.debug){log(arguments);}if(!api&&evt=='onLoad'&&arg0=='player'){api=api||el(apiId);swfHeight=api.clientHeight;each(playlist,function(){this._fireEvent("onLoad");});each(plugins,function(name,p){p._fireEvent("onUpdate");});commonClip._fireEvent("onLoad");}if(evt=='onLoad'&&arg0!='player'){return;}if(evt=='onError'){if(typeof arg0=='string'||(typeof arg0=='number'&&typeof arg1=='number')){arg0=arg1;arg1=arg2;}}if(evt=='onContextMenu'){each(conf.contextMenu[arg0],function(key,fn){fn.call(self);});return;}if(evt=='onPluginEvent'){var name=arg0.name||arg0;var p=plugins[name];if(p){p._fireEvent("onUpdate",arg0);p._fireEvent(arg1);}return;}if(evt=='onPlaylistReplace'){playlist=[];var index=0;each(arg0,function(){playlist.push(new Clip(this,index++,self));});}var ret=true;if(arg0===0||(arg0&&arg0>=0&&arg0<playlist.length)){activeIndex=arg0;var clip=playlist[arg0];if(clip){ret=clip._fireEvent(evt,arg1,arg2);}if(!clip||ret!==false){ret=commonClip._fireEvent(evt,arg1,arg2,clip);}}var i=0;each(listeners[evt],function(){ret=this.call(self,arg0,arg1);if(this.cached){listeners[evt].splice(i,1);}if(ret===false){return false;}i++;});return ret;};function init(){if($f(wrapper)){$f(wrapper).getParent().innerHTML="";playerIndex=$f(wrapper).getIndex();players[playerIndex]=self;}else{players.push(self);playerIndex=players.length-1;}wrapperHeight=parseInt(wrapper.style.height,10)||wrapper.clientHeight;if(typeof params=='string'){params={src:params};}playerId=wrapper.id||"fp"+makeId();apiId=params.id||playerId+"_api";params.id=apiId;conf.playerId=playerId;if(typeof conf=='string'){conf={clip:{url:conf}};}conf.clip=conf.clip||{};if(wrapper.getAttribute("href",2)&&!conf.clip.url){conf.clip.url=wrapper.getAttribute("href",2);}commonClip=new Clip(conf.clip,-1,self);conf.playlist=conf.playlist||[conf.clip];var index=0;each(conf.playlist,function(){var clip=this;if(typeof clip=='object'&&clip.length){clip=""+clip;}if(!clip.url&&typeof clip=='string'){clip={url:clip};}each(conf.clip,function(key,val){if(clip[key]===undefined&&typeof val!='function'){clip[key]=val;}});conf.playlist[index]=clip;clip=new Clip(clip,index,self);playlist.push(clip);index++;});each(conf,function(key,val){if(typeof val=='function'){bind(listeners,key,val);delete conf[key];}});each(conf.plugins,function(name,val){if(val){plugins[name]=new Plugin(name,val,self);}});if(!conf.plugins||conf.plugins.controls===undefined){plugins.controls=new Plugin("controls",null,self);}params.bgcolor=params.bgcolor||"#000000";params.version=params.version||[9,0];params.expressInstall='http://www.flowplayer.org/swf/expressinstall.swf';function doClick(e){if(!self.isLoaded()&&self._fireEvent("onBeforeClick")!==false){self.load();}return stopEvent(e);}html=wrapper.innerHTML;if(html.replace(/\s/g,'')!==''){if(wrapper.addEventListener){wrapper.addEventListener("click",doClick,false);}else if(wrapper.attachEvent){wrapper.attachEvent("onclick",doClick);}}else{if(wrapper.addEventListener){wrapper.addEventListener("click",stopEvent,false);}self.load();}}if(typeof wrapper=='string'){flashembed.domReady(function(){var node=el(wrapper);if(!node){throw"Flowplayer cannot access element: "+wrapper;}else{wrapper=node;init();}});}else{init();}}var players=[];function Iterator(arr){this.length=arr.length;this.each=function(fn){each(arr,fn);};this.size=function(){return arr.length;};}window.flowplayer=window.$f=function(){var instance=null;var arg=arguments[0];if(!arguments.length){each(players,function(){if(this.isLoaded()){instance=this;return false;}});return instance||players[0];}if(arguments.length==1){if(typeof arg=='number'){return players[arg];}else{if(arg=='*'){return new Iterator(players);}each(players,function(){if(this.id()==arg.id||this.id()==arg||this.getParent()==arg){instance=this;return false;}});return instance;}}if(arguments.length>1){var swf=arguments[1];var conf=(arguments.length==3)?arguments[2]:{};if(typeof arg=='string'){if(arg.indexOf(".")!=-1){var instances=[];each(select(arg),function(){instances.push(new Player(this,clone(swf),clone(conf)));});return new Iterator(instances);}else{var node=el(arg);return new Player(node!==null?node:arg,swf,conf);}}else if(arg){return new Player(arg,swf,conf);}}return null;};extend(window.$f,{fireEvent:function(id,evt,a0,a1,a2){var p=$f(id);return p?p._fireEvent(evt,a0,a1,a2):null;},addPlugin:function(name,fn){Player.prototype[name]=fn;return $f;},each:each,extend:extend});if(document.all){window.onbeforeunload=function(){$f("*").each(function(){if(this.isLoaded()){this.close();}});};}if(typeof jQuery=='function'){jQuery.prototype.flowplayer=function(params,conf){if(!arguments.length||typeof arguments[0]=='number'){var arr=[];this.each(function(){var p=$f(this);if(p){arr.push(p);}});return arguments.length?arr[arguments[0]]:new Iterator(arr);}return this.each(function(){$f(this,clone(params),conf?clone(conf):{});});};}})();(function(){var jQ=typeof jQuery=='function';function isDomReady(){if(domReady.done){return false;}var d=document;if(d&&d.getElementsByTagName&&d.getElementById&&d.body){clearInterval(domReady.timer);domReady.timer=null;for(var i=0;i<domReady.ready.length;i++){domReady.ready[i].call();}domReady.ready=null;domReady.done=true;}}var domReady=jQ?jQuery:function(f){if(domReady.done){return f();}if(domReady.timer){domReady.ready.push(f);}else{domReady.ready=[f];domReady.timer=setInterval(isDomReady,13);}};function extend(to,from){if(from){for(key in from){if(from.hasOwnProperty(key)){to[key]=from[key];}}}return to;}function concatVars(vars){var out="";for(var key in vars){if(vars[key]){out+=[key]+'='+asString(vars[key])+'&';}}return out.substring(0,out.length-1);}function asString(obj){switch(typeOf(obj)){case'string':obj=obj.replace(new RegExp('(["\\\\])','g'),'\\$1');obj=obj.replace(/^\s?(\d+)%/,"$1pct");return'"'+obj+'"';case'array':return'['+map(obj,function(el){return asString(el);}).join(',')+']';case'function':return'"function()"';case'object':var str=[];for(var prop in obj){if(obj.hasOwnProperty(prop)){str.push('"'+prop+'":'+asString(obj[prop]));}}return'{'+str.join(',')+'}';}return String(obj).replace(/\s/g," ").replace(/\'/g,"\"");}function typeOf(obj){if(obj===null||obj===undefined){return false;}var type=typeof obj;return(type=='object'&&obj.push)?'array':type;}if(window.attachEvent){window.attachEvent("onbeforeunload",function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};});}function map(arr,func){var newArr=[];for(var i in arr){if(arr.hasOwnProperty(i)){newArr[i]=func(arr[i]);}}return newArr;}function getEmbedCode(p,c){var html='<embed type="application/x-shockwave-flash" ';if(p.id){extend(p,{name:p.id});}for(var key in p){if(p[key]!==null){html+=key+'="'+p[key]+'"\n\t';}}if(c){html+='flashvars=\''+concatVars(c)+'\'';}html+='/>';return html;}function getObjectCode(p,c,embeddable){var html='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';html+='width="'+p.width+'" height="'+p.height+'"';if(!p.id&&document.all){p.id="_"+(""+Math.random()).substring(5);}if(p.id){html+=' id="'+p.id+'"';}html+='>';if(document.all){p.src+=((p.src.indexOf("?")!=-1?"&":"?")+Math.random());}html+='\n\t<param name="movie" value="'+p.src+'" />';var e=extend({},p);e.id=e.width=e.height=e.src=null;for(var k in e){if(e[k]!==null){html+='\n\t<param name="'+k+'" value="'+e[k]+'" />';}}if(c){html+='\n\t<param name="flashvars" value=\''+concatVars(c)+'\' />';}if(embeddable){html+=getEmbedCode(p,c);}html+="</object>";return html;}function getFullHTML(p,c){return getObjectCode(p,c,true);}function getHTML(p,c){var isNav=navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length;return(isNav)?getEmbedCode(p,c):getObjectCode(p,c);}window.flashembed=function(root,userParams,flashvars){var params={src:'#',width:'100%',height:'100%',version:null,onFail:null,expressInstall:null,debug:false,allowfullscreen:true,allowscriptaccess:'always',quality:'high',type:'application/x-shockwave-flash',pluginspage:'http://www.adobe.com/go/getflashplayer'};if(typeof userParams=='string'){userParams={src:userParams};}extend(params,userParams);var version=flashembed.getVersion();var required=params.version;var express=params.expressInstall;var debug=params.debug;if(typeof root=='string'){var el=document.getElementById(root);if(el){root=el;}else{domReady(function(){flashembed(root,userParams,flashvars);});return;}}if(!root){return;}if(!required||flashembed.isSupported(required)){params.onFail=params.version=params.expressInstall=params.debug=null;root.innerHTML=getHTML(params,flashvars);return root.firstChild;}else if(params.onFail){var ret=params.onFail.call(params,flashembed.getVersion(),flashvars);if(ret===true){root.innerHTML=ret;}}else if(required&&express&&flashembed.isSupported([6,65])){extend(params,{src:express});flashvars={MMredirectURL:location.href,MMplayerType:'PlugIn',MMdoctitle:document.title};root.innerHTML=getHTML(params,flashvars);}else{if(root.innerHTML.replace(/\s/g,'')!==''){}else{root.innerHTML="<h2>Flash version "+required+" or greater is required</h2>"+"<h3>"+(version[0]>0?"Your version is "+version:"You have no flash plugin installed")+"</h3>"+"<p>Download latest version from <a href='"+params.pluginspage+"'>here</a></p>";}}return root;};extend(window.flashembed,{getVersion:function(){var version=[0,0];if(navigator.plugins&&typeof navigator.plugins["Shockwave Flash"]=="object"){var _d=navigator.plugins["Shockwave Flash"].description;if(typeof _d!="undefined"){_d=_d.replace(/^.*\s+(\S+\s+\S+$)/,"$1");var _m=parseInt(_d.replace(/^(.*)\..*$/,"$1"),10);var _r=/r/.test(_d)?parseInt(_d.replace(/^.*r(.*)$/,"$1"),10):0;version=[_m,_r];}}else if(window.ActiveXObject){try{var _a=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{_a=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");version=[6,0];_a.AllowScriptAccess="always";}catch(ee){if(version[0]==6){return;}}try{_a=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(eee){}}if(typeof _a=="object"){_d=_a.GetVariable("$version");if(typeof _d!="undefined"){_d=_d.replace(/^\S+\s+(.*)$/,"$1").split(",");version=[parseInt(_d[0],10),parseInt(_d[2],10)];}}}return version;},isSupported:function(version){var now=flashembed.getVersion();var ret=(now[0]>version[0])||(now[0]==version[0]&&now[1]>=version[1]);return ret;},domReady:domReady,asString:asString,getHTML:getHTML,getFullHTML:getFullHTML});if(jQ){jQuery.prototype.flashembed=function(params,flashvars){return this.each(function(){flashembed(this,params,flashvars);});};}})();
flowplayer/style.css CHANGED
@@ -1,41 +1,41 @@
1
-
2
- body {
3
- background-color:#fff;
4
- font-family:"Lucida Grande","bitstream vera sans","trebuchet ms",verdana,arial;
5
- text-align:center;
6
- }
7
-
8
- #page {
9
- background-color:#efefef;
10
- width:600px;
11
- margin:50px auto;
12
- padding:20px 150px 20px 50px;
13
- min-height:600px;
14
- border:2px solid #fff;
15
- outline:1px solid #ccc;
16
- text-align:left;
17
- }
18
-
19
- h1, h2 {
20
- letter-spacing:-1px;
21
- color:#2D5AC3;
22
- font-weight:normal;
23
- margin-bottom:-10px;
24
- }
25
-
26
- h1 {
27
- font-size:22px;
28
- }
29
-
30
- h2 {
31
- font-size:18px;
32
- }
33
-
34
- .less {
35
- color:#999;
36
- font-size:12px;
37
- }
38
-
39
- a {
40
- color:#295c72;
41
- }
1
+
2
+ body {
3
+ background-color:#fff;
4
+ font-family:"Lucida Grande","bitstream vera sans","trebuchet ms",verdana,arial;
5
+ text-align:center;
6
+ }
7
+
8
+ #page {
9
+ background-color:#efefef;
10
+ width:600px;
11
+ margin:50px auto;
12
+ padding:20px 150px 20px 50px;
13
+ min-height:600px;
14
+ border:2px solid #fff;
15
+ outline:1px solid #ccc;
16
+ text-align:left;
17
+ }
18
+
19
+ h1, h2 {
20
+ letter-spacing:-1px;
21
+ color:#2D5AC3;
22
+ font-weight:normal;
23
+ margin-bottom:-10px;
24
+ }
25
+
26
+ h1 {
27
+ font-size:22px;
28
+ }
29
+
30
+ h2 {
31
+ font-size:18px;
32
+ }
33
+
34
+ .less {
35
+ color:#999;
36
+ font-size:12px;
37
+ }
38
+
39
+ a {
40
+ color:#295c72;
41
+ }
images/button-bg.png ADDED
Binary file
images/icon.png ADDED
Binary file
images/icon.png.toobig ADDED
Binary file
images/icon.png.tootiny ADDED
Binary file
images/replay.png CHANGED
Binary file
images/share.png CHANGED
Binary file
js/flowPlayer.js CHANGED
@@ -1,449 +1,449 @@
1
- /*
2
- * FlowPlayer external configuration file.
3
- *
4
- * NOTE! This file is only needed if you don't want to include all configuration
5
- * in the embedding HTML file. Please see the installation instructions at
6
- * http://flowpalyer.org
7
- *
8
- * Copyright 2005-2008 Anssi Piirainen
9
- *
10
- * All settings defined in this file can be alternatively defined in the
11
- * embedding HTML object tag (as flashvars variables). Values defined in the
12
- * object tag override values defined in this file. You could use this
13
- * config file to provide defaults for multiple player instances that
14
- * are used in a Web site. Individual instances can be then customized
15
- * with their embedding HTML.
16
- *
17
- * Note that you should probably remove all the comments from this file
18
- * before using it. That way the file will be smaller and will load faster.
19
- */
20
- {
21
- /*
22
- * Instructs the player to load the configuration from an external config file.
23
- * This can be a abosulte URL or a relative url (relative to the HTML page
24
- * where the player is embedded).
25
- */
26
- // configFileName: 'flowPlayer.js',
27
-
28
- /*
29
- * Instructs the player to load the configuration from a RTMP server.
30
- * The player connects to the server listening in the address specified
31
- * by this URL and calls a method 'getStreamPlayerConfig' that should return a
32
- * valid FP configuration object.
33
- */
34
- // rtmpConfigUrl: 'rtmp://localhost/myapp',
35
-
36
- /*
37
- * A param value to be passed to getStreamPlayerConfig(). A value 'foobar'
38
- * will make the player to call getStreamPlayerConfig('foobsr')
39
- */
40
- // rtmpConfigParam: 'anssi',
41
-
42
- /*
43
- * Name of the video file. Used if only one video is shown.
44
- *
45
- * Note for testing locally: Specify an empty baseURL '', if you want to load
46
- * the video from your local disk from the directory that contains
47
- * FlowPlayer.swf. In this case the videoFile parameter value should start
48
- * with a slash, for example '/video.flv'.
49
- *
50
- * See also: 'baseURL' that affects this variable
51
- */
52
- // videoFile: 'honda_accord.flv',
53
-
54
- /*
55
- * Clip to be used if the file specified with 'videoFile' or any of the clips in the playlist
56
- * was not found. The missing video clips are replaced by this clip. This can be
57
- * an image or a FLV clip. Typically this will contain an image/video saying
58
- * "the video you requested cannot be found.....".
59
- *
60
- * The syntax for the value is the same is with the clips in a playlist
61
- * including the possibility to have start/end and duration properties.
62
- *
63
- * See also: 'baseURL' that affects this variable
64
- */
65
- noVideoClip: { url: 'main_clickToPlay.jpg', duration: 10 },
66
- //noVideoClip: { url: 'MiltonFriedmanonLimi.flv' },
67
-
68
- /*
69
- * Playlist is used to publish several videos using one player instance.
70
- * You can also have images in the playlist. The playback pauses in the
71
- * image unless a 'duration' property is given for the image:
72
-
73
- * * The clips in the playlist may have following properties:
74
- *
75
- * name: Name for the clip to be shown in the playlist view. If this is
76
- * not given, the clip will be hidden from the view.
77
- *
78
- * url: The URL used to load the clip.
79
- *
80
- * type: One of 'video', 'flv', 'swf', 'jpg'. Optional, determined from the URL's filename extension
81
- * if that is present. 'video' means a video file in any format supported by Flash.
82
- * 'flv' is present here for backward compatibility, use 'video' in new FlowPlayer installations
83
- * now. Defaults to 'video' if the extension is not present in the URL.
84
- *
85
- * start: The start time (seconds) from where to start the playback. A nonzero
86
- * value can only be used when using a streaming server!!
87
- * end: The end time (seconds) where to stop the playback.
88
- *
89
- * duration: The duration the image is to be shown. If not given the playback
90
- * pauses when the image is reached in the list.
91
- *
92
- * protected: (true/false) Apply inlinine linking protection for this clip?
93
- * Optional, defaults to false.
94
- *
95
- * linkUrl: Associates a hyperlink pointing to the specified URL. The linked
96
- * document will be opened to the browser when the clip area is clicked.
97
- * Specifying this parameter will replace the normal pause/resume behavior
98
- * that is associated to clicking the display area. If you specify an empty
99
- * linkUrl '' the pause/resume behavior is disabled but no hyperlink
100
- * is created.
101
- * linkWindow: Specifies the name of the browser window or frame into which to load
102
- * the linked document. Can be a custom name or one of presets: '_blank',
103
- * '_parent', '_self', '_top'. (optional, defaults to '_blank')
104
- *
105
- * controlEnabled: (true/false) Enable transport control buttons for this clip?
106
- * Optional, defaults to true.
107
- *
108
- * allowResize: (true/false) Allow resizing this clip according to the menu selection.
109
- * Optional, defaults to true.
110
- *
111
- * overlay: A filename pointing to an image that will be placed on top of this image clip. This
112
- * is only applicable to image clips (jpg or png files). Essentially this layers two images
113
- * on top of each other. Typically the image on top is a big play button that is used on
114
- * top of an image taken from the main movie.
115
- *
116
- * overlayId: ID that specifies a built-in overlay to be used. Currently the player supports
117
- * one built-in overlay with ID 'play'. It renders a large play button with mouse hover color change.
118
- * You can use this on top of image clips (one clip with both the 'url' property and
119
- * 'overlayId' property).
120
- * You can also specify a clip that only has this ID. In that
121
- * case you should place it immediately before or after a FLV clip. This overlay-only
122
- * clip is then rendered on top of the first or the last frame of the FLV video.
123
- *
124
- * live: (true/false) Is this a live stream (played from a media server)?
125
- *
126
- * showOnLoadBegin: (true/false) If true, make this clip visible when the fist bits have been loaded.
127
- * If false, do not show this clip (show the background instead) before the buffer is filled
128
- * and the playback starts. Optional, defaults to true.
129
- *
130
- * maxPlayCount: The maximum play count for this clip. The clip is removed from the playlist when
131
- * the playcount reaches this amount.
132
- *
133
- * suggestedClipsInfoUrl: URL used to fetch suggestions (related videos) information from the server
134
- *
135
- * See also: 'baseURL' is prefixed with each URL
136
- */
137
- playList: [
138
- { url: 'main_clickToPlay.jpg' },
139
- { name: 'Honda Accord', url: '!honda_accord.flv' },
140
- { name: 'River', url: 'river.flv' },
141
- { name: 'Ounasvaara', url: 'ounasvaara.flv' }
142
- ],
143
-
144
- /*
145
- * Specifies wether the playlist control buttons should be shown in the player SWF component or not.
146
- * Optional, defaults to the value of showPlayList.
147
- */
148
- showPlayListButtons: true,
149
-
150
- /*
151
- * Streaming server connection URL.
152
- * You don't need this with lighttpd, just use the streamingServer setting (see below) with it.
153
- */
154
- // streamingServerURL: 'rtmp://localahost:oflaDemo',
155
-
156
- /*
157
- * baseURL specifies the URL that is appended in front of different file names
158
- * given in this file.
159
- *
160
- * You don't need to specify this at all if you place the video next to
161
- * the player SWF file on the Web server (to be available under the same URL path).
162
- */
163
- // baseURL: 'http://flowplayer.sourceforge.net/video',
164
-
165
-
166
- /*
167
- * What kind of streaming server? Available options: 'fms', 'red5', 'lighttpd'
168
- */
169
- // streamingServer: 'fms',
170
-
171
- /*
172
- * Specifies whether thumbnail information is contained in the FLV's cue point
173
- * metadata. Cue points can be injected into the FLV file using
174
- * for example Flvtool2. See the FlowPlayer web site for more info.
175
- * (optional, defaults to false)
176
- *
177
- * See also: cuePoints below for an alternative way of specifying thumb metadata
178
- */
179
- // thumbsOnFLV: true,
180
-
181
- /*
182
- * Thumbnails specific to cue points. Use this if you don't want to
183
- * embed thumbnail metadata into the FLV's cue points.
184
- * If you have thumbNails defined here you should have thumbsOnFLV: false !
185
- * thumb times are given in seconds
186
- */
187
- // thumbs: [
188
- // { thumbNail: 'Thumb1.jpg', time: 10 },
189
- // { thumbNail: 'Thumb2.jpg', time: 24 },
190
- // { thumbNail: 'Thumb3.jpg', time: 54 },
191
- // { thumbNail: 'Thumb4.jpg', time: 74 },
192
- // { thumbNail: 'Thumb5.jpg', time: 94 },
193
- // { thumbNail: 'Thumb6.jpg', time: 110 }
194
- // ],
195
- // Location of the thumbnail files
196
- // thumbLocation: 'http://www.kolumbus.fi/apiirain/video',
197
-
198
- /*
199
- * 'autoPlay' variable defines whether playback begins immediately or not.
200
- *
201
- * Note that currently with red5 you should not have false in autoPlay
202
- * when you specify a nonzero starting position for the video clip. This is because red5
203
- * does not send FLV metadata when the playback starts from a nonzero value.
204
- *
205
- * (optional, defaults to true)
206
- */
207
- autoPlay: true,
208
-
209
- /*
210
- * 'autoBuffering' specifies wheter to start loading the video stream into
211
- * buffer memory immediately. Only meaningful if 'autoPlay' is set to
212
- * false. (optional, defaults to true)
213
- */
214
- autoBuffering: true,
215
-
216
- /*
217
- * 'startingBufferLength' specifies the video buffer length to be used to kick
218
- * off the playback. This is used in the beginning of the playback and every time
219
- * after the player has ran out of buffer memory.
220
- * More info at: http://www.progettosinergia.com/flashvideo/flashvideoblog.htm#031205
221
- * (optional, defaults to the value of 'bufferLength' setting)
222
- *
223
- * see also: bufferLength
224
- */
225
- // startingBufferLength: 5,
226
-
227
- /*
228
- * 'bufferLength' specifies the video buffer length in seconds. This is used
229
- * after the playback has started with the initial buffer length. You should
230
- * use an arbitrary large value here to ensure stable playback.
231
- * (optional, defaults to 10 seconds)
232
- *
233
- * see also: startingBufferLength
234
- */
235
- bufferLength: 20,
236
-
237
- /*
238
- * 'loop' defines whether the playback should loop to the first clip after
239
- * all clips in the playlist have been shown. It is used as the
240
- * default state of the toggle button that controls looping. (optional,
241
- * defaults to true)
242
- */
243
- loop: true,
244
-
245
- /*
246
- * Rewind back to the fist clip in the playlist when end of the list has been reached?
247
- * This option only has effect if loop is false (please see loop variable above).
248
- * (optional, defaults to false)
249
- */
250
- autoRewind: true,
251
-
252
- /*
253
- * Specifies wether the loop toggle button should be shown in the player SWF component or not.
254
- * Optional, defaults to false.
255
- */
256
- // showLoopButton: true,
257
-
258
- /*
259
- * Specifies the height to be allocated for the video display. This is the
260
- * maximum height available for the different resizing options.
261
- */
262
- videoHeight: 320,
263
-
264
- /*
265
- * Specifies the width for the control buttons area. Optiona, defaults to the
266
- * width setting used in the embedding code.
267
- */
268
- // controlsWidth: 480,
269
-
270
- /*
271
- * Specifies how the video is scaled initially. This can be then changed by
272
- * the user through the menu. (optional, defaults to 'fit')
273
- * Possible values:
274
- * 'fit' Fit to window by preserving the aspect ratios encoded in the FLV metadata.
275
- * This is the default behavior.
276
- * 'half' Half size (preserves aspect ratios)
277
- * 'orig' Use the dimensions encoded in FLV. If the video is too big for the
278
- * available space the video is scaled as if using the 'fit' option.
279
- * 'scale' Scale the video to fill all available space for the video. Ignores
280
- * the dimensions in metadata.
281
- *
282
- */
283
- initialScale: 'fit',
284
-
285
- /*
286
- * Specifies if the menu containing the size options should be shown or not.
287
- * (optional, defaults to true)
288
- // showMenu: false,
289
-
290
- /*
291
- * 'hideControls' if set to true, hides all buttons and the progress bar
292
- * leaving only the video showing (optional, defaults to false)
293
- */
294
- hideControls: false,
295
-
296
- /*
297
- * URL that specifies a base URL that points to a folder containing
298
- * images used to skin the player. You must specify this if you intend
299
- * to load external button images (see 'loadButtonImages' below).
300
- */
301
- skinImagesBaseURL: 'http://flowplayer.sourceforge.net/resources'
302
-
303
- /*
304
- * Will button images be loaded from external files, or will images embedded
305
- * in the player SWF component be used? Set this to false if you want to "skin"
306
- * the buttons. Optional, defaults to true.
307
- *
308
- * NOTE: If you set this to false, you need to have the skin images available
309
- * on the server! Otherwise the player will not show up at all or will show
310
- * up corrupted.
311
- *
312
- * See also: 'skinImagesBaseURL' that affects this variable
313
- */
314
- // useEmbeddedButtonImages: false,
315
-
316
- /*
317
- * 'splashImageFile' specifies an image file to be used as a splash image.
318
- * This is useful if 'autoPlay' is set to false and you want to show a
319
- * welcome image before the video is played. Should be in JPG format. The
320
- * value of 'baseURL' is used similarily as with the video file name and
321
- * therefore the video and the image files should be placed in the Web
322
- * server next to each other.
323
- *
324
- * NOTE: If you set a value for this, you need to have the splash image available
325
- * on the server! Otherwise the player will not show up at all or will show
326
- * up corrupted.
327
- *
328
- * NOTE2: You can also specify the splash in a playlist. This is just
329
- * an alternative way of doing it. It was preserved for backward compatibility.
330
- *
331
- * See also: 'baseURL' that affects this variable
332
- */
333
- // splashImageFile: 'main_clickToPlay.jpg',
334
-
335
- /*
336
- * Should the splash image be scaled to fit the entire video area? If false,
337
- * the image will be centered. Optional, defaults to false.
338
- */
339
- // scaleSplash: false,
340
-
341
- /*
342
- * 'progressBarColor1' defines the color of the progress bar at the bottom
343
- * and top edges. Specified in hexadecimal triplet form indicating the RGB
344
- * color component values. (optional)
345
- */
346
- // progressBarColor1: 0xFFFFFF,
347
-
348
-
349
- /*
350
- * 'progressBarColor2' defines the color in the middle of the progress bar.
351
- * The value of this and 'progressBarColor1' variables define the gradient
352
- * color fill of the progress bar. (optional)
353
- */
354
- // progressBarColor2: 0xDDFFDD,
355
-
356
- /*
357
- * 'bufferBarColor1' defines the color of the buffer size indicator bar at the bottom
358
- * and top edges. (optional)
359
- */
360
- // bufferBarColor1: 0xFFFFFF,
361
-
362
-
363
- /*
364
- * 'bufferBarColor2' defines the color of the buffer size indicator bar in the middle
365
- * of the bar. (optional)
366
- */
367
- // bufferBarColor2: 0xDDFFDD,
368
-
369
- /*
370
- * 'progressBarBorderColor1' defines the color of the progress bar's border at the bottom
371
- * and top edges. (optional)
372
- */
373
- // progressBarBorderColor1: 0xDDDDDD,
374
-
375
-
376
- /*
377
- * 'progressBarBorderColor2' defines the color of the progress bar's border in the middle
378
- * of the bar. (optional)
379
- */
380
- // progressBarBorderColor2: 0xEEEEEE,
381
-
382
- /*
383
- * 'bufferingAnimationColor' defines the color of the moving bars used in the buffering
384
- * animation. (optional)
385
- */
386
- // bufferingAnimationColor: 0x0000FF,
387
-
388
- /*
389
- * 'controlsAreaBorderColor' defines the color of the border behind buttons and progress bar
390
- * (optional)
391
- */
392
- // controlsAreaBorderColor: 0x1234,
393
-
394
- /*
395
- * 'timeDisplayFontColor' defines the color of the progress/duration time display
396
- * (optional)
397
- */
398
- // timeDisplayFontColor: 0xAABBCC,
399
-
400
- /*
401
- * Height of the progress bar. (optional)
402
- */
403
- // progressBarHeight: 10,
404
-
405
- /*
406
- * Height of the progress bar area. (optional)
407
- */
408
- // progressBarAreaHeight: 10,
409
-
410
- /*
411
- * Name of the authentication code file name that is used to prevent inline linking
412
- * of video and image files. This can be a complete URL or just a file name relative
413
- * to the location from where the player is loaded. (optional, defaults to flowplayer_auth.txt)
414
- */
415
- // authFileName: 'http://www.mytube.org/authCode.txt',
416
-
417
- /*
418
- * The URL pointing to a sctipt that opens the player full screen.
419
- * If this is not configured explicitly, the default script,
420
- * http://flowplayer.sourceforge.net/fullscreen.js, is used.
421
- */
422
- // fullScreenScriptURL: 'http://mysite.org/fullscreen.js'
423
-
424
- /**
425
- * Specifies which menu items will be show. This is an array that contains a boolean
426
- * value for each of the items. By default shows them all except "full screen".
427
- */
428
- // menuItems[
429
- // true, // show 'Fit to window'
430
- // true, // show 'Half size'
431
- // true, // show 'Original size'
432
- // true, // show 'Fill window'
433
- // true, // show 'Full screen'
434
- // false // hide 'Embed...'
435
- // ],
436
-
437
-
438
- /*
439
- * Specifies wether the full screen button should be shown in the player SWF component or not.
440
- * Optional, defaults to true.
441
- */
442
- // showFullScreenButton: false,
443
-
444
- /*
445
- * Use the Flash 9 native full screen mode.
446
- */
447
- // useNativeFullScreen: true,
448
- }
449
-
1
+ /*
2
+ * FlowPlayer external configuration file.
3
+ *
4
+ * NOTE! This file is only needed if you don't want to include all configuration
5
+ * in the embedding HTML file. Please see the installation instructions at
6
+ * http://flowpalyer.org
7
+ *
8
+ * Copyright 2005-2008 Anssi Piirainen
9
+ *
10
+ * All settings defined in this file can be alternatively defined in the
11
+ * embedding HTML object tag (as flashvars variables). Values defined in the
12
+ * object tag override values defined in this file. You could use this
13
+ * config file to provide defaults for multiple player instances that
14
+ * are used in a Web site. Individual instances can be then customized
15
+ * with their embedding HTML.
16
+ *
17
+ * Note that you should probably remove all the comments from this file
18
+ * before using it. That way the file will be smaller and will load faster.
19
+ */
20
+ {
21
+ /*
22
+ * Instructs the player to load the configuration from an external config file.
23
+ * This can be a abosulte URL or a relative url (relative to the HTML page
24
+ * where the player is embedded).
25
+ */
26
+ // configFileName: 'flowPlayer.js',
27
+
28
+ /*
29
+ * Instructs the player to load the configuration from a RTMP server.
30
+ * The player connects to the server listening in the address specified
31
+ * by this URL and calls a method 'getStreamPlayerConfig' that should return a
32
+ * valid FP configuration object.
33
+ */
34
+ // rtmpConfigUrl: 'rtmp://localhost/myapp',
35
+
36
+ /*
37
+ * A param value to be passed to getStreamPlayerConfig(). A value 'foobar'
38
+ * will make the player to call getStreamPlayerConfig('foobsr')
39
+ */
40
+ // rtmpConfigParam: 'anssi',
41
+
42
+ /*
43
+ * Name of the video file. Used if only one video is shown.
44
+ *
45
+ * Note for testing locally: Specify an empty baseURL '', if you want to load
46
+ * the video from your local disk from the directory that contains
47
+ * FlowPlayer.swf. In this case the videoFile parameter value should start
48
+ * with a slash, for example '/video.flv'.
49
+ *
50
+ * See also: 'baseURL' that affects this variable
51
+ */
52
+ // videoFile: 'honda_accord.flv',
53
+
54
+ /*
55
+ * Clip to be used if the file specified with 'videoFile' or any of the clips in the playlist
56
+ * was not found. The missing video clips are replaced by this clip. This can be
57
+ * an image or a FLV clip. Typically this will contain an image/video saying
58
+ * "the video you requested cannot be found.....".
59
+ *
60
+ * The syntax for the value is the same is with the clips in a playlist
61
+ * including the possibility to have start/end and duration properties.
62
+ *
63
+ * See also: 'baseURL' that affects this variable
64
+ */
65
+ noVideoClip: { url: 'main_clickToPlay.jpg', duration: 10 },
66
+ //noVideoClip: { url: 'MiltonFriedmanonLimi.flv' },
67
+
68
+ /*
69
+ * Playlist is used to publish several videos using one player instance.
70
+ * You can also have images in the playlist. The playback pauses in the
71
+ * image unless a 'duration' property is given for the image:
72
+
73
+ * * The clips in the playlist may have following properties:
74
+ *
75
+ * name: Name for the clip to be shown in the playlist view. If this is
76
+ * not given, the clip will be hidden from the view.
77
+ *
78
+ * url: The URL used to load the clip.
79
+ *
80
+ * type: One of 'video', 'flv', 'swf', 'jpg'. Optional, determined from the URL's filename extension
81
+ * if that is present. 'video' means a video file in any format supported by Flash.
82
+ * 'flv' is present here for backward compatibility, use 'video' in new FlowPlayer installations
83
+ * now. Defaults to 'video' if the extension is not present in the URL.
84
+ *
85
+ * start: The start time (seconds) from where to start the playback. A nonzero
86
+ * value can only be used when using a streaming server!!
87
+ * end: The end time (seconds) where to stop the playback.
88
+ *
89
+ * duration: The duration the image is to be shown. If not given the playback
90
+ * pauses when the image is reached in the list.
91
+ *
92
+ * protected: (true/false) Apply inlinine linking protection for this clip?
93
+ * Optional, defaults to false.
94
+ *
95
+ * linkUrl: Associates a hyperlink pointing to the specified URL. The linked
96
+ * document will be opened to the browser when the clip area is clicked.
97
+ * Specifying this parameter will replace the normal pause/resume behavior
98
+ * that is associated to clicking the display area. If you specify an empty
99
+ * linkUrl '' the pause/resume behavior is disabled but no hyperlink
100
+ * is created.
101
+ * linkWindow: Specifies the name of the browser window or frame into which to load
102
+ * the linked document. Can be a custom name or one of presets: '_blank',
103
+ * '_parent', '_self', '_top'. (optional, defaults to '_blank')
104
+ *
105
+ * controlEnabled: (true/false) Enable transport control buttons for this clip?
106
+ * Optional, defaults to true.
107
+ *
108
+ * allowResize: (true/false) Allow resizing this clip according to the menu selection.
109
+ * Optional, defaults to true.
110
+ *
111
+ * overlay: A filename pointing to an image that will be placed on top of this image clip. This
112
+ * is only applicable to image clips (jpg or png files). Essentially this layers two images
113
+ * on top of each other. Typically the image on top is a big play button that is used on
114
+ * top of an image taken from the main movie.
115
+ *
116
+ * overlayId: ID that specifies a built-in overlay to be used. Currently the player supports
117
+ * one built-in overlay with ID 'play'. It renders a large play button with mouse hover color change.
118
+ * You can use this on top of image clips (one clip with both the 'url' property and
119
+ * 'overlayId' property).
120
+ * You can also specify a clip that only has this ID. In that
121
+ * case you should place it immediately before or after a FLV clip. This overlay-only
122
+ * clip is then rendered on top of the first or the last frame of the FLV video.
123
+ *
124
+ * live: (true/false) Is this a live stream (played from a media server)?
125
+ *
126
+ * showOnLoadBegin: (true/false) If true, make this clip visible when the fist bits have been loaded.
127
+ * If false, do not show this clip (show the background instead) before the buffer is filled
128
+ * and the playback starts. Optional, defaults to true.
129
+ *
130
+ * maxPlayCount: The maximum play count for this clip. The clip is removed from the playlist when
131
+ * the playcount reaches this amount.
132
+ *
133
+ * suggestedClipsInfoUrl: URL used to fetch suggestions (related videos) information from the server
134
+ *
135
+ * See also: 'baseURL' is prefixed with each URL
136
+ */
137
+ playList: [
138
+ { url: 'main_clickToPlay.jpg' },
139
+ { name: 'Honda Accord', url: '!honda_accord.flv' },
140
+ { name: 'River', url: 'river.flv' },
141
+ { name: 'Ounasvaara', url: 'ounasvaara.flv' }
142
+ ],
143
+
144
+ /*
145
+ * Specifies wether the playlist control buttons should be shown in the player SWF component or not.
146
+ * Optional, defaults to the value of showPlayList.
147
+ */
148
+ showPlayListButtons: true,
149
+
150
+ /*
151
+ * Streaming server connection URL.
152
+ * You don't need this with lighttpd, just use the streamingServer setting (see below) with it.
153
+ */
154
+ // streamingServerURL: 'rtmp://localahost:oflaDemo',
155
+
156
+ /*
157
+ * baseURL specifies the URL that is appended in front of different file names
158
+ * given in this file.
159
+ *
160
+ * You don't need to specify this at all if you place the video next to
161
+ * the player SWF file on the Web server (to be available under the same URL path).
162
+ */
163
+ // baseURL: 'http://flowplayer.sourceforge.net/video',
164
+
165
+
166
+ /*
167
+ * What kind of streaming server? Available options: 'fms', 'red5', 'lighttpd'
168
+ */
169
+ // streamingServer: 'fms',
170
+
171
+ /*
172
+ * Specifies whether thumbnail information is contained in the FLV's cue point
173
+ * metadata. Cue points can be injected into the FLV file using
174
+ * for example Flvtool2. See the FlowPlayer web site for more info.
175
+ * (optional, defaults to false)
176
+ *
177
+ * See also: cuePoints below for an alternative way of specifying thumb metadata
178
+ */
179
+ // thumbsOnFLV: true,
180
+
181
+ /*
182
+ * Thumbnails specific to cue points. Use this if you don't want to
183
+ * embed thumbnail metadata into the FLV's cue points.
184
+ * If you have thumbNails defined here you should have thumbsOnFLV: false !
185
+ * thumb times are given in seconds
186
+ */
187
+ // thumbs: [
188
+ // { thumbNail: 'Thumb1.jpg', time: 10 },
189
+ // { thumbNail: 'Thumb2.jpg', time: 24 },
190
+ // { thumbNail: 'Thumb3.jpg', time: 54 },
191
+ // { thumbNail: 'Thumb4.jpg', time: 74 },
192
+ // { thumbNail: 'Thumb5.jpg', time: 94 },
193
+ // { thumbNail: 'Thumb6.jpg', time: 110 }
194
+ // ],
195
+ // Location of the thumbnail files
196
+ // thumbLocation: 'http://www.kolumbus.fi/apiirain/video',
197
+
198
+ /*
199
+ * 'autoPlay' variable defines whether playback begins immediately or not.
200
+ *
201
+ * Note that currently with red5 you should not have false in autoPlay
202
+ * when you specify a nonzero starting position for the video clip. This is because red5
203
+ * does not send FLV metadata when the playback starts from a nonzero value.
204
+ *
205
+ * (optional, defaults to true)
206
+ */
207
+ autoPlay: true,
208
+
209
+ /*
210
+ * 'autoBuffering' specifies wheter to start loading the video stream into
211
+ * buffer memory immediately. Only meaningful if 'autoPlay' is set to
212
+ * false. (optional, defaults to true)
213
+ */
214
+ autoBuffering: true,
215
+
216
+ /*
217
+ * 'startingBufferLength' specifies the video buffer length to be used to kick
218
+ * off the playback. This is used in the beginning of the playback and every time
219
+ * after the player has ran out of buffer memory.
220
+ * More info at: http://www.progettosinergia.com/flashvideo/flashvideoblog.htm#031205
221
+ * (optional, defaults to the value of 'bufferLength' setting)
222
+ *
223
+ * see also: bufferLength
224
+ */
225
+ // startingBufferLength: 5,
226
+
227
+ /*
228
+ * 'bufferLength' specifies the video buffer length in seconds. This is used
229
+ * after the playback has started with the initial buffer length. You should
230
+ * use an arbitrary large value here to ensure stable playback.
231
+ * (optional, defaults to 10 seconds)
232
+ *
233
+ * see also: startingBufferLength
234
+ */
235
+ bufferLength: 20,
236
+
237
+ /*
238
+ * 'loop' defines whether the playback should loop to the first clip after
239
+ * all clips in the playlist have been shown. It is used as the
240
+ * default state of the toggle button that controls looping. (optional,
241
+ * defaults to true)
242
+ */
243
+ loop: true,
244
+
245
+ /*
246
+ * Rewind back to the fist clip in the playlist when end of the list has been reached?
247
+ * This option only has effect if loop is false (please see loop variable above).
248
+ * (optional, defaults to false)
249
+ */
250
+ autoRewind: true,
251
+
252
+ /*
253
+ * Specifies wether the loop toggle button should be shown in the player SWF component or not.
254
+ * Optional, defaults to false.
255
+ */
256
+ // showLoopButton: true,
257
+
258
+ /*
259
+ * Specifies the height to be allocated for the video display. This is the
260
+ * maximum height available for the different resizing options.
261
+ */
262
+ videoHeight: 240,
263
+
264
+ /*
265
+ * Specifies the width for the control buttons area. Optiona, defaults to the
266
+ * width setting used in the embedding code.
267
+ */
268
+ // controlsWidth: 480,
269
+
270
+ /*
271
+ * Specifies how the video is scaled initially. This can be then changed by
272
+ * the user through the menu. (optional, defaults to 'fit')
273
+ * Possible values:
274
+ * 'fit' Fit to window by preserving the aspect ratios encoded in the FLV metadata.
275
+ * This is the default behavior.
276
+ * 'half' Half size (preserves aspect ratios)
277
+ * 'orig' Use the dimensions encoded in FLV. If the video is too big for the
278
+ * available space the video is scaled as if using the 'fit' option.
279
+ * 'scale' Scale the video to fill all available space for the video. Ignores
280
+ * the dimensions in metadata.
281
+ *
282
+ */
283
+ initialScale: 'fit',
284
+
285
+ /*
286
+ * Specifies if the menu containing the size options should be shown or not.
287
+ * (optional, defaults to true)
288
+ // showMenu: false,
289
+
290
+ /*
291
+ * 'hideControls' if set to true, hides all buttons and the progress bar
292
+ * leaving only the video showing (optional, defaults to false)
293
+ */
294
+ hideControls: true,
295
+
296
+ /*
297
+ * URL that specifies a base URL that points to a folder containing
298
+ * images used to skin the player. You must specify this if you intend
299
+ * to load external button images (see 'loadButtonImages' below).
300
+ */
301
+ skinImagesBaseURL: 'http://flowplayer.sourceforge.net/resources'
302
+
303
+ /*
304
+ * Will button images be loaded from external files, or will images embedded
305
+ * in the player SWF component be used? Set this to false if you want to "skin"
306
+ * the buttons. Optional, defaults to true.
307
+ *
308
+ * NOTE: If you set this to false, you need to have the skin images available
309
+ * on the server! Otherwise the player will not show up at all or will show
310
+ * up corrupted.
311
+ *
312
+ * See also: 'skinImagesBaseURL' that affects this variable
313
+ */
314
+ // useEmbeddedButtonImages: false,
315
+
316
+ /*
317
+ * 'splashImageFile' specifies an image file to be used as a splash image.
318
+ * This is useful if 'autoPlay' is set to false and you want to show a
319
+ * welcome image before the video is played. Should be in JPG format. The
320
+ * value of 'baseURL' is used similarily as with the video file name and
321
+ * therefore the video and the image files should be placed in the Web
322
+ * server next to each other.
323
+ *
324
+ * NOTE: If you set a value for this, you need to have the splash image available
325
+ * on the server! Otherwise the player will not show up at all or will show
326
+ * up corrupted.
327
+ *
328
+ * NOTE2: You can also specify the splash in a playlist. This is just
329
+ * an alternative way of doing it. It was preserved for backward compatibility.
330
+ *
331
+ * See also: 'baseURL' that affects this variable
332
+ */
333
+ // splashImageFile: 'main_clickToPlay.jpg',
334
+
335
+ /*
336
+ * Should the splash image be scaled to fit the entire video area? If false,
337
+ * the image will be centered. Optional, defaults to false.
338
+ */
339
+ // scaleSplash: false,
340
+
341
+ /*
342
+ * 'progressBarColor1' defines the color of the progress bar at the bottom
343
+ * and top edges. Specified in hexadecimal triplet form indicating the RGB
344
+ * color component values. (optional)
345
+ */
346
+ // progressBarColor1: 0xFFFFFF,
347
+
348
+
349
+ /*
350
+ * 'progressBarColor2' defines the color in the middle of the progress bar.
351
+ * The value of this and 'progressBarColor1' variables define the gradient
352
+ * color fill of the progress bar. (optional)
353
+ */
354
+ // progressBarColor2: 0xDDFFDD,
355
+
356
+ /*
357
+ * 'bufferBarColor1' defines the color of the buffer size indicator bar at the bottom
358
+ * and top edges. (optional)
359
+ */
360
+ // bufferBarColor1: 0xFFFFFF,
361
+
362
+
363
+ /*
364
+ * 'bufferBarColor2' defines the color of the buffer size indicator bar in the middle
365
+ * of the bar. (optional)
366
+ */
367
+ // bufferBarColor2: 0xDDFFDD,
368
+
369
+ /*
370
+ * 'progressBarBorderColor1' defines the color of the progress bar's border at the bottom
371
+ * and top edges. (optional)
372
+ */
373
+ // progressBarBorderColor1: 0xDDDDDD,
374
+
375
+
376
+ /*
377
+ * 'progressBarBorderColor2' defines the color of the progress bar's border in the middle
378
+ * of the bar. (optional)
379
+ */
380
+ // progressBarBorderColor2: 0xEEEEEE,
381
+
382
+ /*
383
+ * 'bufferingAnimationColor' defines the color of the moving bars used in the buffering
384
+ * animation. (optional)
385
+ */
386
+ // bufferingAnimationColor: 0x0000FF,
387
+
388
+ /*
389
+ * 'controlsAreaBorderColor' defines the color of the border behind buttons and progress bar
390
+ * (optional)
391
+ */
392
+ // controlsAreaBorderColor: 0x1234,
393
+
394
+ /*
395
+ * 'timeDisplayFontColor' defines the color of the progress/duration time display
396
+ * (optional)
397
+ */
398
+ // timeDisplayFontColor: 0xAABBCC,
399
+
400
+ /*
401
+ * Height of the progress bar. (optional)
402
+ */
403
+ // progressBarHeight: 10,
404
+
405
+ /*
406
+ * Height of the progress bar area. (optional)
407
+ */
408
+ // progressBarAreaHeight: 10,
409
+
410
+ /*
411
+ * Name of the authentication code file name that is used to prevent inline linking
412
+ * of video and image files. This can be a complete URL or just a file name relative
413
+ * to the location from where the player is loaded. (optional, defaults to flowplayer_auth.txt)
414
+ */
415
+ // authFileName: 'http://www.mytube.org/authCode.txt',
416
+
417
+ /*
418
+ * The URL pointing to a sctipt that opens the player full screen.
419
+ * If this is not configured explicitly, the default script,
420
+ * http://flowplayer.sourceforge.net/fullscreen.js, is used.
421
+ */
422
+ // fullScreenScriptURL: 'http://mysite.org/fullscreen.js'
423
+
424
+ /**
425
+ * Specifies which menu items will be show. This is an array that contains a boolean
426
+ * value for each of the items. By default shows them all except "full screen".
427
+ */
428
+ // menuItems[
429
+ // true, // show 'Fit to window'
430
+ // true, // show 'Half size'
431
+ // true, // show 'Original size'
432
+ // true, // show 'Fill window'
433
+ // true, // show 'Full screen'
434
+ // false // hide 'Embed...'
435
+ // ],
436
+
437
+
438
+ /*
439
+ * Specifies wether the full screen button should be shown in the player SWF component or not.
440
+ * Optional, defaults to true.
441
+ */
442
+ showFullScreenButton: false,
443
+
444
+ /*
445
+ * Use the Flash 9 native full screen mode.
446
+ */
447
+ // useNativeFullScreen: true,
448
+ }
449
+
js/jscolor/jscolor.js CHANGED
@@ -1,830 +1,830 @@
1
- /**
2
- * jscolor, JavaScript Color Picker
3
- *
4
- * @version 1.2.3
5
- * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
6
- * @author Honza Odvarko <honza@odvarko.cz>
7
- * @created 2008-06-15
8
- * @updated 2009-02-25
9
- * @link http://jscolor.com
10
- */
11
-
12
-
13
- var jscolor = {
14
-
15
-
16
- dir : '', // location of jscolor directory (leave empty to autodetect)
17
- bindClass : 'color', // class name
18
- binding : true, // automatic binding via <input class="...">
19
- preloading : true, // use image preloading?
20
-
21
-
22
- install : function() {
23
- jscolor.addEvent(window, 'load', jscolor.init)
24
- },
25
-
26
-
27
- init : function() {
28
- if(jscolor.binding) {
29
- jscolor.bind()
30
- }
31
- if(jscolor.preloading) {
32
- jscolor.preload()
33
- }
34
- },
35
-
36
-
37
- getDir : function() {
38
- if(!jscolor.dir) {
39
- var detected = jscolor.detectDir()
40
- jscolor.dir = detected!=false ? detected : 'jscolor/'
41
- }
42
- return jscolor.dir
43
- },
44
-
45
-
46
- detectDir : function() {
47
- var base = location.href
48
-
49
- var e = document.getElementsByTagName('base')
50
- for(var i=0; i<e.length; i++) {
51
- if(e[i].href) base = e[i].href
52
- }
53
-
54
- var e = document.getElementsByTagName('script')
55
- for(var i=0; i<e.length; i++) {
56
- if(e[i].src && /(^|\/)jscolor\.js([?#].*)?$/i.test(e[i].src)) {
57
- var src = new jscolor.URI(e[i].src)
58
- var srcAbs = src.toAbsolute(base)
59
- srcAbs.path = srcAbs.path.replace(/[^\/]+$/, '') // remove filename
60
- delete srcAbs.query
61
- delete srcAbs.fragment
62
- return srcAbs.toString()
63
- }
64
- }
65
- return false
66
- },
67
-
68
-
69
- bind : function() {
70
- var matchClass = new RegExp('(^|\\s)('+jscolor.bindClass+')\\s*(\\{[^}]*\\})?', 'i')
71
- var e = document.getElementsByTagName('input')
72
- for(var i=0; i<e.length; i++) {
73
- var m
74
- if(!e[i].color && e[i].className && (m = e[i].className.match(matchClass))) {
75
- var prop = {}
76
- if(m[3]) {
77
- try {
78
- eval('prop='+m[3])
79
- } catch(eInvalidProp) {}
80
- }
81
- e[i].color = new jscolor.color(e[i], prop)
82
- }
83
- }
84
- },
85
-
86
-
87
- preload : function() {
88
- for(var fn in jscolor.imgRequire) {
89
- jscolor.loadImage(fn)
90
- }
91
- },
92
-
93
-
94
- images : {
95
- pad : [ 181, 101 ],
96
- sld : [ 16, 101 ],
97
- cross : [ 15, 15 ],
98
- arrow : [ 7, 11 ]
99
- },
100
-
101
-
102
- imgRequire : {},
103
- imgLoaded : {},
104
-
105
-
106
- requireImage : function(filename) {
107
- jscolor.imgRequire[filename] = true
108
- },
109
-
110
-
111
- loadImage : function(filename) {
112
- if(!jscolor.imgLoaded[filename]) {
113
- jscolor.imgLoaded[filename] = new Image()
114
- jscolor.imgLoaded[filename].src = jscolor.getDir()+filename
115
- }
116
- },
117
-
118
-
119
- fetchElement : function(mixed) {
120
- return typeof(mixed) == 'string' ? document.getElementById(mixed) : mixed
121
- },
122
-
123
-
124
- addEvent : function(el, evnt, func) {
125
- if(el.addEventListener) {
126
- return el.addEventListener(evnt, func, false)
127
- } else if(el.attachEvent) {
128
- return el.attachEvent('on'+evnt, func)
129
- } else {
130
- return false
131
- }
132
- },
133
-
134
-
135
- fireEvent : function(el, evnt) {
136
- if(!el) {
137
- return false
138
- } else if(document.createEventObject) {
139
- var ev = document.createEventObject()
140
- return el.fireEvent('on'+evnt, ev)
141
- } else if(document.createEvent) {
142
- var ev = document.createEvent('HTMLEvents')
143
- ev.initEvent(evnt, true, true)
144
- return el.dispatchEvent(ev)
145
- } else if(el['on'+evnt]) { // alternatively use the traditional event model (IE5)
146
- return el['on'+evnt]()
147
- } else {
148
- return false
149
- }
150
- },
151
-
152
-
153
- getElementPos : function(e) {
154
- var e1=e, e2=e
155
- var x=0, y=0
156
- if(e1.offsetParent) {
157
- do {
158
- x += e1.offsetLeft
159
- y += e1.offsetTop
160
- } while(e1 = e1.offsetParent)
161
- }
162
- while((e2 = e2.parentNode) && e2.nodeName != 'BODY') {
163
- x -= e2.scrollLeft
164
- y -= e2.scrollTop
165
- }
166
- return [x, y]
167
- },
168
-
169
-
170
- getElementSize : function(e) {
171
- return [e.offsetWidth, e.offsetHeight]
172
- },
173
-
174
-
175
- getMousePos : function(e) {
176
- if(!e) e = window.event
177
- if(typeof e.pageX == 'number') {
178
- return [e.pageX, e.pageY]
179
- } else if(typeof e.clientX == 'number') {
180
- return [
181
- e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft,
182
- e.clientY + document.body.scrollTop + document.documentElement.scrollTop
183
- ]
184
- }
185
- },
186
-
187
-
188
- getViewPos : function() {
189
- if(typeof window.pageYOffset == 'number') {
190
- return [window.pageXOffset, window.pageYOffset]
191
- } else if(document.body && (document.body.scrollLeft || document.body.scrollTop)) {
192
- return [document.body.scrollLeft, document.body.scrollTop]
193
- } else if(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
194
- return [document.documentElement.scrollLeft, document.documentElement.scrollTop]
195
- } else {
196
- return [0, 0]
197
- }
198
- },
199
-
200
-
201
- getViewSize : function() {
202
- if(typeof window.innerWidth == 'number') {
203
- return [window.innerWidth, window.innerHeight]
204
- } else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
205
- return [document.body.clientWidth, document.body.clientHeight]
206
- } else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
207
- return [document.documentElement.clientWidth, document.documentElement.clientHeight]
208
- } else {
209
- return [0, 0]
210
- }
211
- },
212
-
213
-
214
- URI : function(uri) { // See RFC3986
215
-
216
- this.scheme = null
217
- this.authority = null
218
- this.path = ''
219
- this.query = null
220
- this.fragment = null
221
-
222
- this.parse = function(uri) {
223
- var m = uri.match(/^(([A-Za-z][0-9A-Za-z+.-]*)(:))?((\/\/)([^\/?#]*))?([^?#]*)((\?)([^#]*))?((#)(.*))?/)
224
- this.scheme = m[3] ? m[2] : null
225
- this.authority = m[5] ? m[6] : null
226
- this.path = m[7]
227
- this.query = m[9] ? m[10] : null
228
- this.fragment = m[12] ? m[13] : null
229
- return this
230
- }
231
-
232
- this.toString = function() {
233
- var result = ''
234
- if(this.scheme != null) result = result + this.scheme + ':'
235
- if(this.authority != null) result = result + '//' + this.authority
236
- if(this.path != null) result = result + this.path
237
- if(this.query != null) result = result + '?' + this.query
238
- if(this.fragment != null) result = result + '#' + this.fragment
239
- return result
240
- }
241
-
242
- this.toAbsolute = function(base) {
243
- var base = new jscolor.URI(base)
244
- var r = this
245
- var t = new jscolor.URI
246
-
247
- if(base.scheme == null) return false
248
-
249
- if(r.scheme != null && r.scheme.toLowerCase() == base.scheme.toLowerCase()) {
250
- r.scheme = null
251
- }
252
-
253
- if(r.scheme != null) {
254
- t.scheme = r.scheme
255
- t.authority = r.authority
256
- t.path = removeDotSegments(r.path)
257
- t.query = r.query
258
- } else {
259
- if(r.authority != null) {
260
- t.authority = r.authority
261
- t.path = removeDotSegments(r.path)
262
- t.query = r.query
263
- } else {
264
- if(r.path == '') {
265
- t.path = base.path
266
- if(r.query != null) {
267
- t.query = r.query
268
- } else {
269
- t.query = base.query
270
- }
271
- } else {
272
- if(r.path.substr(0,1) == '/') {
273
- t.path = removeDotSegments(r.path)
274
- } else {
275
- if(base.authority != null && base.path == '') {
276
- t.path = '/'+r.path
277
- } else {
278
- t.path = base.path.replace(/[^\/]+$/,'')+r.path
279
- }
280
- t.path = removeDotSegments(t.path)
281
- }
282
- t.query = r.query
283
- }
284
- t.authority = base.authority
285
- }
286
- t.scheme = base.scheme
287
- }
288
- t.fragment = r.fragment
289
-
290
- return t
291
- }
292
-
293
- function removeDotSegments(path) {
294
- var out = ''
295
- while(path) {
296
- if(path.substr(0,3)=='../' || path.substr(0,2)=='./') {
297
- path = path.replace(/^\.+/,'').substr(1)
298
- } else if(path.substr(0,3)=='/./' || path=='/.') {
299
- path = '/'+path.substr(3)
300
- } else if(path.substr(0,4)=='/../' || path=='/..') {
301
- path = '/'+path.substr(4)
302
- out = out.replace(/\/?[^\/]*$/, '')
303
- } else if(path=='.' || path=='..') {
304
- path = ''
305
- } else {
306
- var rm = path.match(/^\/?[^\/]*/)[0]
307
- path = path.substr(rm.length)
308
- out = out + rm
309
- }
310
- }
311
- return out
312
- }
313
-
314
- if(uri) {
315
- this.parse(uri)
316
- }
317
-
318
- },
319
-
320
-
321
- /*
322
- * Usage example:
323
- * var myColor = new jscolor.color(myInputElement)
324
- */
325
-
326
- color : function(target, prop) {
327
-
328
-
329
- this.required = true // refuse empty values?
330
- this.adjust = true // adjust value to uniform notation?
331
- this.hash = false // prefix color with # symbol?
332
- this.caps = true // uppercase?
333
- this.valueElement = target // value holder
334
- this.styleElement = target // where to reflect current color
335
- this.hsv = [0, 0, 1] // read-only 0-6, 0-1, 0-1
336
- this.rgb = [1, 1, 1] // read-only 0-1, 0-1, 0-1
337
-
338
- this.pickerOnfocus = true // display picker on focus?
339
- this.pickerMode = 'HSV' // HSV | HVS
340
- this.pickerPosition = 'bottom' // left | right | top | bottom
341
- this.pickerFace = 10 // px
342
- this.pickerFaceColor = 'ThreeDFace' // CSS color
343
- this.pickerBorder = 1 // px
344
- this.pickerBorderColor = 'ThreeDHighlight ThreeDShadow ThreeDShadow ThreeDHighlight' // CSS color
345
- this.pickerInset = 1 // px
346
- this.pickerInsetColor = 'ThreeDShadow ThreeDHighlight ThreeDHighlight ThreeDShadow' // CSS color
347
- this.pickerZIndex = 10000
348
-
349
-
350
- for(var p in prop) this[p] = prop[p]
351
-
352
-
353
- this.hidePicker = function() {
354
- if(isPickerOwner()) {
355
- removePicker()
356
- }
357
- }
358
-
359
-
360
- this.showPicker = function() {
361
- if(!isPickerOwner()) {
362
- var tp = jscolor.getElementPos(target) // target pos
363
- var ts = jscolor.getElementSize(target) // target size
364
- var vp = jscolor.getViewPos() // view pos
365
- var vs = jscolor.getViewSize() // view size
366
- var ps = [ // picker size
367
- 2*this.pickerBorder + 4*this.pickerInset + 2*this.pickerFace + jscolor.images.pad[0] + 2*jscolor.images.arrow[0] + jscolor.images.sld[0],
368
- 2*this.pickerBorder + 2*this.pickerInset + 2*this.pickerFace + jscolor.images.pad[1]
369
- ]
370
- var a, b, c
371
- switch(this.pickerPosition.toLowerCase()) {
372
- case 'left': a=1; b=0; c=-1; break
373
- case 'right':a=1; b=0; c=1; break
374
- case 'top': a=0; b=1; c=-1; break
375
- default: a=0; b=1; c=1; break
376
- }
377
- var l = (ts[b]+ps[b])/2
378
- var pp = [ // picker pos
379
- -vp[a]+tp[a]+ps[a] > vs[a] ?
380
- (-vp[a]+tp[a]+ts[a]/2 > vs[a]/2 && tp[a]+ts[a]-ps[a] >= 0 ? tp[a]+ts[a]-ps[a] : tp[a]) :
381
- tp[a],
382
- -vp[b]+tp[b]+ts[b]+ps[b]-l+l*c > vs[b] ?
383
- (-vp[b]+tp[b]+ts[b]/2 > vs[b]/2 && tp[b]+ts[b]-l-l*c >= 0 ? tp[b]+ts[b]-l-l*c : tp[b]+ts[b]-l+l*c) :
384
- (tp[b]+ts[b]-l+l*c >= 0 ? tp[b]+ts[b]-l+l*c : tp[b]+ts[b]-l-l*c)
385
- ]
386
- drawPicker(pp[a], pp[b])
387
- }
388
- }
389
-
390
-
391
- this.importColor = function() {
392
- if(!valueElement) {
393
- this.exportColor()
394
- } else {
395
- if(!this.adjust) {
396
- if(!this.fromString(valueElement.value, leaveValue)) {
397
- styleElement.style.backgroundColor = styleElement.jscStyle.backgroundColor
398
- styleElement.style.color = styleElement.jscStyle.color
399
- this.exportColor(leaveValue | leaveStyle)
400
- }
401
- } else if(!this.required && /^\s*$/.test(valueElement.value)) {
402
- valueElement.value = ''
403
- styleElement.style.backgroundColor = styleElement.jscStyle.backgroundColor
404
- styleElement.style.color = styleElement.jscStyle.color
405
- this.exportColor(leaveValue | leaveStyle)
406
-
407
- } else if(this.fromString(valueElement.value)) {
408
- // OK
409
- } else {
410
- this.exportColor()
411
- }
412
- }
413
- }
414
-
415
-
416
- this.exportColor = function(flags) {
417
- if(!(flags & leaveValue) && valueElement) {
418
- var value = this.toString()
419
- if(this.caps) value = value.toUpperCase()
420
- if(this.hash) value = '#'+value
421
- valueElement.value = value
422
- }
423
- if(!(flags & leaveStyle) && styleElement) {
424
- styleElement.style.backgroundColor = '#'+this.toString()
425
- styleElement.style.color =
426
- 0.213 * this.rgb[0] +
427
- 0.715 * this.rgb[1] +
428
- 0.072 * this.rgb[2]
429
- < 0.5 ? '#FFF' : '#000'
430
- }
431
- if(!(flags & leavePad) && isPickerOwner()) {
432
- redrawPad()
433
- }
434
- if(!(flags & leaveSld) && isPickerOwner()) {
435
- redrawSld()
436
- }
437
- }
438
-
439
-
440
- this.fromHSV = function(h, s, v, flags) { // null = don't change
441
- h<0 && (h=0) || h>6 && (h=6)
442
- s<0 && (s=0) || s>1 && (s=1)
443
- v<0 && (v=0) || v>1 && (v=1)
444
- this.rgb = HSV_RGB(
445
- h==null ? this.hsv[0] : (this.hsv[0]=h),
446
- s==null ? this.hsv[1] : (this.hsv[1]=s),
447
- v==null ? this.hsv[2] : (this.hsv[2]=v)
448
- )
449
- this.exportColor(flags)
450
- }
451
-
452
-
453
- this.fromRGB = function(r, g, b, flags) { // null = don't change
454
- r<0 && (r=0) || r>1 && (r=1)
455
- g<0 && (g=0) || g>1 && (g=1)
456
- b<0 && (b=0) || b>1 && (b=1)
457
- var hsv = RGB_HSV(
458
- r==null ? this.rgb[0] : (this.rgb[0]=r),
459
- g==null ? this.rgb[1] : (this.rgb[1]=g),
460
- b==null ? this.rgb[2] : (this.rgb[2]=b)
461
- )
462
- if(hsv[0] != null) {
463
- this.hsv[0] = hsv[0]
464
- }
465
- if(hsv[2] != 0) {
466
- this.hsv[1] = hsv[1]
467
- }
468
- this.hsv[2] = hsv[2]
469
- this.exportColor(flags)
470
- }
471
-
472
-
473
- this.fromString = function(hex, flags) {
474
- var m = hex.match(/^\W*([0-9A-F]{3}([0-9A-F]{3})?)\W*$/i)
475
- if(!m) {
476
- return false
477
- } else {
478
- if(m[1].length == 6) { // 6-char notation
479
- this.fromRGB(
480
- parseInt(m[1].substr(0,2),16) / 255,
481
- parseInt(m[1].substr(2,2),16) / 255,
482
- parseInt(m[1].substr(4,2),16) / 255,
483
- flags
484
- )
485
- } else { // 3-char notation
486
- this.fromRGB(
487
- parseInt(m[1].charAt(0)+m[1].charAt(0),16) / 255,
488
- parseInt(m[1].charAt(1)+m[1].charAt(1),16) / 255,
489
- parseInt(m[1].charAt(2)+m[1].charAt(2),16) / 255,
490
- flags
491
- )
492
- }
493
- return true
494
- }
495
- }
496
-
497
-
498
- this.toString = function() {
499
- return (
500
- (0x100 | Math.round(255*this.rgb[0])).toString(16).substr(1) +
501
- (0x100 | Math.round(255*this.rgb[1])).toString(16).substr(1) +
502
- (0x100 | Math.round(255*this.rgb[2])).toString(16).substr(1)
503
- )
504
- }
505
-
506
-
507
- function RGB_HSV(r, g, b) {
508
- var n = Math.min(Math.min(r,g),b)
509
- var v = Math.max(Math.max(r,g),b)
510
- var m = v - n
511
- if(m == 0) return [ null, 0, v ]
512
- var h = r==n ? 3+(b-g)/m : (g==n ? 5+(r-b)/m : 1+(g-r)/m)
513
- return [ h==6?0:h, m/v, v ]
514
- }
515
-
516
-
517
- function HSV_RGB(h, s, v) {
518
- if(h == null) return [ v, v, v ]
519
- var i = Math.floor(h)
520
- var f = i%2 ? h-i : 1-(h-i)
521
- var m = v * (1 - s)
522
- var n = v * (1 - s*f)
523
- switch(i) {
524
- case 6:
525
- case 0: return [v,n,m]
526
- case 1: return [n,v,m]
527
- case 2: return [m,v,n]
528
- case 3: return [m,n,v]
529
- case 4: return [n,m,v]
530
- case 5: return [v,m,n]
531
- }
532
- }
533
-
534
-
535
- function removePicker() {
536
- delete jscolor.picker.owner
537
- document.getElementsByTagName('body')[0].removeChild(jscolor.picker.boxB)
538
- }
539
-
540
-
541
- function drawPicker(x, y) {
542
- if(!jscolor.picker) {
543
- jscolor.picker = {
544
- box : document.createElement('div'),
545
- boxB : document.createElement('div'),
546
- pad : document.createElement('div'),
547
- padB : document.createElement('div'),
548
- padM : document.createElement('div'),
549
- sld : document.createElement('div'),
550
- sldB : document.createElement('div'),
551
- sldM : document.createElement('div')
552
- }
553
- for(var i=0,segSize=4; i<jscolor.images.sld[1]; i+=segSize) {
554
- var seg = document.createElement('div')
555
- seg.style.height = segSize+'px'
556
- seg.style.fontSize = '1px'
557
- seg.style.lineHeight = '0'
558
- jscolor.picker.sld.appendChild(seg)
559
- }
560
- jscolor.picker.sldB.appendChild(jscolor.picker.sld)
561
- jscolor.picker.box.appendChild(jscolor.picker.sldB)
562
- jscolor.picker.box.appendChild(jscolor.picker.sldM)
563
- jscolor.picker.padB.appendChild(jscolor.picker.pad)
564
- jscolor.picker.box.appendChild(jscolor.picker.padB)
565
- jscolor.picker.box.appendChild(jscolor.picker.padM)
566
- jscolor.picker.boxB.appendChild(jscolor.picker.box)
567
- }
568
-
569
- var p = jscolor.picker
570
-
571
- // recompute controls positions
572
- posPad = [
573
- x+THIS.pickerBorder+THIS.pickerFace+THIS.pickerInset,
574
- y+THIS.pickerBorder+THIS.pickerFace+THIS.pickerInset ]
575
- posSld = [
576
- null,
577
- y+THIS.pickerBorder+THIS.pickerFace+THIS.pickerInset ]
578
-
579
- // controls interaction
580
- p.box.onmouseup =
581
- p.box.onmouseout = function() { target.focus() }
582
- p.box.onmousedown = function() { abortBlur=true }
583
- p.box.onmousemove = function(e) { holdPad && setPad(e); holdSld && setSld(e) }
584
- p.padM.onmouseup =
585
- p.padM.onmouseout = function() { if(holdPad) { holdPad=false; jscolor.fireEvent(valueElement,'change') } }
586
- p.padM.onmousedown = function(e) { holdPad=true; setPad(e) }
587
- p.sldM.onmouseup =
588
- p.sldM.onmouseout = function() { if(holdSld) { holdSld=false; jscolor.fireEvent(valueElement,'change') } }
589
- p.sldM.onmousedown = function(e) { holdSld=true; setSld(e) }
590
-
591
- // picker
592
- p.box.style.width = 4*THIS.pickerInset + 2*THIS.pickerFace + jscolor.images.pad[0] + 2*jscolor.images.arrow[0] + jscolor.images.sld[0] + 'px'
593
- p.box.style.height = 2*THIS.pickerInset + 2*THIS.pickerFace + jscolor.images.pad[1] + 'px'
594
-
595
- // picker border
596
- p.boxB.style.position = 'absolute'
597
- p.boxB.style.clear = 'both'
598
- p.boxB.style.left = x+'px'
599
- p.boxB.style.top = y+'px'
600
- p.boxB.style.zIndex = THIS.pickerZIndex
601
- p.boxB.style.border = THIS.pickerBorder+'px solid'
602
- p.boxB.style.borderColor = THIS.pickerBorderColor
603
- p.boxB.style.background = THIS.pickerFaceColor
604
-
605
- // pad image
606
- p.pad.style.width = jscolor.images.pad[0]+'px'
607
- p.pad.style.height = jscolor.images.pad[1]+'px'
608
-
609
- // pad border
610
- p.padB.style.position = 'absolute'
611
- p.padB.style.left = THIS.pickerFace+'px'
612
- p.padB.style.top = THIS.pickerFace+'px'
613
- p.padB.style.border = THIS.pickerInset+'px solid'
614
- p.padB.style.borderColor = THIS.pickerInsetColor
615
-
616
- // pad mouse area
617
- p.padM.style.position = 'absolute'
618
- p.padM.style.left = '0'
619
- p.padM.style.top = '0'
620
- p.padM.style.width = THIS.pickerFace + 2*THIS.pickerInset + jscolor.images.pad[0] + jscolor.images.arrow[0] + 'px'
621
- p.padM.style.height = p.box.style.height
622
- p.padM.style.cursor = 'crosshair'
623
-
624
- // slider image
625
- p.sld.style.overflow = 'hidden'
626
- p.sld.style.width = jscolor.images.sld[0]+'px'
627
- p.sld.style.height = jscolor.images.sld[1]+'px'
628
-
629
- // slider border
630
- p.sldB.style.position = 'absolute'
631
- p.sldB.style.right = THIS.pickerFace+'px'
632
- p.sldB.style.top = THIS.pickerFace+'px'
633
- p.sldB.style.border = THIS.pickerInset+'px solid'
634
- p.sldB.style.borderColor = THIS.pickerInsetColor
635
-
636
- // slider mouse area
637
- p.sldM.style.position = 'absolute'
638
- p.sldM.style.right = '0'
639
- p.sldM.style.top = '0'
640
- p.sldM.style.width = jscolor.images.sld[0] + jscolor.images.arrow[0] + THIS.pickerFace + 2*THIS.pickerInset + 'px'
641
- p.sldM.style.height = p.box.style.height
642
- try {
643
- p.sldM.style.cursor = 'pointer'
644
- } catch(eOldIE) {
645
- p.sldM.style.cursor = 'hand'
646
- }
647
-
648
- // load images in optimal order
649
- switch(modeID) {
650
- case 0: var padImg = 'hs.png'; break
651
- case 1: var padImg = 'hv.png'; break
652
- }
653
- p.padM.style.background = "url('"+jscolor.getDir()+"cross.gif') no-repeat"
654
- p.sldM.style.background = "url('"+jscolor.getDir()+"arrow.gif') no-repeat"
655
- p.pad.style.background = "url('"+jscolor.getDir()+padImg+"') 0 0 no-repeat"
656
-
657
- // place pointers
658
- redrawPad()
659
- redrawSld()
660
-
661
- jscolor.picker.owner = THIS
662
- document.getElementsByTagName('body')[0].appendChild(p.boxB)
663
- }
664
-
665
-
666
- function redrawPad() {
667
- // redraw the pad pointer
668
- switch(modeID) {
669
- case 0: var yComponent = 1; break
670
- case 1: var yComponent = 2; break
671
- }
672
- var x = Math.round((THIS.hsv[0]/6) * (jscolor.images.pad[0]-1))
673
- var y = Math.round((1-THIS.hsv[yComponent]) * (jscolor.images.pad[1]-1))
674
- jscolor.picker.padM.style.backgroundPosition =
675
- (THIS.pickerFace+THIS.pickerInset+x - Math.floor(jscolor.images.cross[0]/2)) + 'px ' +
676
- (THIS.pickerFace+THIS.pickerInset+y - Math.floor(jscolor.images.cross[1]/2)) + 'px'
677
-
678
- // redraw the slider image
679
- var seg = jscolor.picker.sld.childNodes
680
-
681
- switch(modeID) {
682
- case 0:
683
- var rgb = HSV_RGB(THIS.hsv[0], THIS.hsv[1], 1)
684
- for(var i=0; i<seg.length; i++) {
685
- seg[i].style.backgroundColor = 'rgb('+
686
- (rgb[0]*(1-i/seg.length)*100)+'%,'+
687
- (rgb[1]*(1-i/seg.length)*100)+'%,'+
688
- (rgb[2]*(1-i/seg.length)*100)+'%)'
689
- }
690
- break
691
- case 1:
692
- var rgb, s, c = [ THIS.hsv[2], 0, 0 ]
693
- var i = Math.floor(THIS.hsv[0])
694
- var f = i%2 ? THIS.hsv[0]-i : 1-(THIS.hsv[0]-i)
695
- switch(i) {
696
- case 6:
697
- case 0: rgb=[0,1,2]; break
698
- case 1: rgb=[1,0,2]; break
699
- case 2: rgb=[2,0,1]; break
700
- case 3: rgb=[2,1,0]; break
701
- case 4: rgb=[1,2,0]; break
702
- case 5: rgb=[0,2,1]; break
703
- }
704
- for(var i=0; i<seg.length; i++) {
705
- s = 1 - 1/(seg.length-1)*i
706
- c[1] = c[0] * (1 - s*f)
707
- c[2] = c[0] * (1 - s)
708
- seg[i].style.backgroundColor = 'rgb('+
709
- (c[rgb[0]]*100)+'%,'+
710
- (c[rgb[1]]*100)+'%,'+
711
- (c[rgb[2]]*100)+'%)'
712
- }
713
- break
714
- }
715
- }
716
-
717
-
718
- function redrawSld() {
719
- // redraw the slider pointer
720
- switch(modeID) {
721
- case 0: var yComponent = 2; break
722
- case 1: var yComponent = 1; break
723
- }
724
- var y = Math.round((1-THIS.hsv[yComponent]) * (jscolor.images.sld[1]-1))
725
- jscolor.picker.sldM.style.backgroundPosition =
726
- '0 ' + (THIS.pickerFace+THIS.pickerInset+y - Math.floor(jscolor.images.arrow[1]/2)) + 'px'
727
- }
728
-
729
-
730
- function isPickerOwner() {
731
- return jscolor.picker && jscolor.picker.owner == THIS
732
- }
733
-
734
-
735
- function blurTarget() {
736
- if(valueElement == target) THIS.importColor()
737
- if(THIS.pickerOnfocus) THIS.hidePicker()
738
- }
739
-
740
-
741
- function blurValue() {
742
- if(valueElement != target) THIS.importColor()
743
- }
744
-
745
-
746
- function setPad(e) {
747
- var posM = jscolor.getMousePos(e)
748
- var x = posM[0]-posPad[0]
749
- var y = posM[1]-posPad[1]
750
- switch(modeID) {
751
- case 0: THIS.fromHSV(x*(6/(jscolor.images.pad[0]-1)), 1 - y/(jscolor.images.pad[1]-1), null, leaveSld); break
752
- case 1: THIS.fromHSV(x*(6/(jscolor.images.pad[0]-1)), null, 1 - y/(jscolor.images.pad[1]-1), leaveSld); break
753
- }
754
- }
755
-
756
-
757
- function setSld(e) {
758
- var posM = jscolor.getMousePos(e)
759
- var y = posM[1]-posPad[1]
760
- switch(modeID) {
761
- case 0: THIS.fromHSV(null, null, 1 - y/(jscolor.images.sld[1]-1), leavePad); break
762
- case 1: THIS.fromHSV(null, 1 - y/(jscolor.images.sld[1]-1), null, leavePad); break
763
- }
764
- }
765
-
766
-
767
- var THIS = this
768
- var modeID = this.pickerMode.toLowerCase()=='hvs' ? 1 : 0
769
- var abortBlur = false
770
- var
771
- valueElement = jscolor.fetchElement(this.valueElement),
772
- styleElement = jscolor.fetchElement(this.styleElement)
773
- var
774
- holdPad = false,
775
- holdSld = false
776
- var
777
- posPad,
778
- posSld
779
- var
780
- leaveValue = 1<<0,
781
- leaveStyle = 1<<1,
782
- leavePad = 1<<2,
783
- leaveSld = 1<<3
784
-
785
- // target
786
- jscolor.addEvent(target, 'focus', function() {
787
- if(THIS.pickerOnfocus) THIS.showPicker()
788
- })
789
- jscolor.addEvent(target, 'blur', function() {
790
- if(!abortBlur) {
791
- setTimeout(function(){ abortBlur || blurTarget(); abortBlur=false }, 0)
792
- } else {
793
- abortBlur = false
794
- }
795
- })
796
-
797
- // valueElement
798
- if(valueElement) {
799
- var updateField = function() {
800
- THIS.fromString(valueElement.value, leaveValue)
801
- }
802
- jscolor.addEvent(valueElement, 'keyup', updateField)
803
- jscolor.addEvent(valueElement, 'input', updateField)
804
- jscolor.addEvent(valueElement, 'blur', blurValue)
805
- valueElement.setAttribute('autocomplete', 'off')
806
- }
807
-
808
- // styleElement
809
- if(styleElement) {
810
- styleElement.jscStyle = {
811
- backgroundColor : styleElement.style.backgroundColor,
812
- color : styleElement.style.color
813
- }
814
- }
815
-
816
- // require images
817
- switch(modeID) {
818
- case 0: jscolor.requireImage('hs.png'); break
819
- case 1: jscolor.requireImage('hv.png'); break
820
- }
821
- jscolor.requireImage('cross.gif');
822
- jscolor.requireImage('arrow.gif');
823
-
824
- this.importColor()
825
- }
826
-
827
- }
828
-
829
-
830
- jscolor.install()
1
+ /**
2
+ * jscolor, JavaScript Color Picker
3
+ *
4
+ * @version 1.2.3
5
+ * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
6
+ * @author Honza Odvarko <honza@odvarko.cz>
7
+ * @created 2008-06-15
8
+ * @updated 2009-02-25
9
+ * @link http://jscolor.com
10
+ */
11
+
12
+
13
+ var jscolor = {
14
+
15
+
16
+ dir : '', // location of jscolor directory (leave empty to autodetect)
17
+ bindClass : 'color', // class name
18
+ binding : true, // automatic binding via <input class="...">
19
+ preloading : true, // use image preloading?
20
+
21
+
22
+ install : function() {
23
+ jscolor.addEvent(window, 'load', jscolor.init)
24
+ },
25
+
26
+
27
+ init : function() {
28
+ if(jscolor.binding) {
29
+ jscolor.bind()
30
+ }
31
+ if(jscolor.preloading) {
32
+ jscolor.preload()
33
+ }
34
+ },
35
+
36
+
37
+ getDir : function() {
38
+ if(!jscolor.dir) {
39
+ var detected = jscolor.detectDir()
40
+ jscolor.dir = detected!=false ? detected : 'jscolor/'
41
+ }
42
+ return jscolor.dir
43
+ },
44
+
45
+
46
+ detectDir : function() {
47
+ var base = location.href
48
+
49
+ var e = document.getElementsByTagName('base')
50
+ for(var i=0; i<e.length; i++) {
51
+ if(e[i].href) base = e[i].href
52
+ }
53
+
54
+ var e = document.getElementsByTagName('script')
55
+ for(var i=0; i<e.length; i++) {
56
+ if(e[i].src && /(^|\/)jscolor\.js([?#].*)?$/i.test(e[i].src)) {
57
+ var src = new jscolor.URI(e[i].src)
58
+ var srcAbs = src.toAbsolute(base)
59
+ srcAbs.path = srcAbs.path.replace(/[^\/]+$/, '') // remove filename
60
+ delete srcAbs.query
61
+ delete srcAbs.fragment
62
+ return srcAbs.toString()
63
+ }
64
+ }
65
+ return false
66
+ },
67
+
68
+
69
+ bind : function() {
70
+ var matchClass = new RegExp('(^|\\s)('+jscolor.bindClass+')\\s*(\\{[^}]*\\})?', 'i')
71
+ var e = document.getElementsByTagName('input')
72
+ for(var i=0; i<e.length; i++) {
73
+ var m
74
+ if(!e[i].color && e[i].className && (m = e[i].className.match(matchClass))) {
75
+ var prop = {}
76
+ if(m[3]) {
77
+ try {
78
+ eval('prop='+m[3])
79
+ } catch(eInvalidProp) {}
80
+ }
81
+ e[i].color = new jscolor.color(e[i], prop)
82
+ }
83
+ }
84
+ },
85
+
86
+
87
+ preload : function() {
88
+ for(var fn in jscolor.imgRequire) {
89
+ jscolor.loadImage(fn)
90
+ }
91
+ },
92
+
93
+
94
+ images : {
95
+ pad : [ 181, 101 ],
96
+ sld : [ 16, 101 ],
97
+ cross : [ 15, 15 ],
98
+ arrow : [ 7, 11 ]
99
+ },
100
+
101
+
102
+ imgRequire : {},
103
+ imgLoaded : {},
104
+
105
+
106
+ requireImage : function(filename) {
107
+ jscolor.imgRequire[filename] = true
108
+ },
109
+
110
+
111
+ loadImage : function(filename) {
112
+ if(!jscolor.imgLoaded[filename]) {
113
+ jscolor.imgLoaded[filename] = new Image()
114
+ jscolor.imgLoaded[filename].src = jscolor.getDir()+filename
115
+ }
116
+ },
117
+
118
+
119
+ fetchElement : function(mixed) {
120
+ return typeof(mixed) == 'string' ? document.getElementById(mixed) : mixed
121
+ },
122
+
123
+
124
+ addEvent : function(el, evnt, func) {
125
+ if(el.addEventListener) {
126
+ return el.addEventListener(evnt, func, false)
127
+ } else if(el.attachEvent) {
128
+ return el.attachEvent('on'+evnt, func)
129
+ } else {
130
+ return false
131
+ }
132
+ },
133
+
134
+
135
+ fireEvent : function(el, evnt) {
136
+ if(!el) {
137
+ return false
138
+ } else if(document.createEventObject) {
139
+ var ev = document.createEventObject()
140
+ return el.fireEvent('on'+evnt, ev)
141
+ } else if(document.createEvent) {
142
+ var ev = document.createEvent('HTMLEvents')
143
+ ev.initEvent(evnt, true, true)
144
+ return el.dispatchEvent(ev)
145
+ } else if(el['on'+evnt]) { // alternatively use the traditional event model (IE5)
146
+ return el['on'+evnt]()
147
+ } else {
148
+ return false
149
+ }
150
+ },
151
+
152
+
153
+ getElementPos : function(e) {
154
+ var e1=e, e2=e
155
+ var x=0, y=0
156
+ if(e1.offsetParent) {
157
+ do {
158
+ x += e1.offsetLeft
159
+ y += e1.offsetTop
160
+ } while(e1 = e1.offsetParent)
161
+ }
162
+ while((e2 = e2.parentNode) && e2.nodeName != 'BODY') {
163
+ x -= e2.scrollLeft
164
+ y -= e2.scrollTop
165
+ }
166
+ return [x, y]
167
+ },
168
+
169
+
170
+ getElementSize : function(e) {
171
+ return [e.offsetWidth, e.offsetHeight]
172
+ },
173
+
174
+
175
+ getMousePos : function(e) {
176
+ if(!e) e = window.event
177
+ if(typeof e.pageX == 'number') {
178
+ return [e.pageX, e.pageY]
179
+ } else if(typeof e.clientX == 'number') {
180
+ return [
181
+ e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft,
182
+ e.clientY + document.body.scrollTop + document.documentElement.scrollTop
183
+ ]
184
+ }
185
+ },
186
+
187
+
188
+ getViewPos : function() {
189
+ if(typeof window.pageYOffset == 'number') {
190
+ return [window.pageXOffset, window.pageYOffset]
191
+ } else if(document.body && (document.body.scrollLeft || document.body.scrollTop)) {
192
+ return [document.body.scrollLeft, document.body.scrollTop]
193
+ } else if(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
194
+ return [document.documentElement.scrollLeft, document.documentElement.scrollTop]
195
+ } else {
196
+ return [0, 0]
197
+ }
198
+ },
199
+
200
+
201
+ getViewSize : function() {
202
+ if(typeof window.innerWidth == 'number') {
203
+ return [window.innerWidth, window.innerHeight]
204
+ } else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
205
+ return [document.body.clientWidth, document.body.clientHeight]
206
+ } else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
207
+ return [document.documentElement.clientWidth, document.documentElement.clientHeight]
208
+ } else {
209
+ return [0, 0]
210
+ }
211
+ },
212
+
213
+
214
+ URI : function(uri) { // See RFC3986
215
+
216
+ this.scheme = null
217
+ this.authority = null
218
+ this.path = ''
219
+ this.query = null
220
+ this.fragment = null
221
+
222
+ this.parse = function(uri) {
223
+ var m = uri.match(/^(([A-Za-z][0-9A-Za-z+.-]*)(:))?((\/\/)([^\/?#]*))?([^?#]*)((\?)([^#]*))?((#)(.*))?/)
224
+ this.scheme = m[3] ? m[2] : null
225
+ this.authority = m[5] ? m[6] : null
226
+ this.path = m[7]
227
+ this.query = m[9] ? m[10] : null
228
+ this.fragment = m[12] ? m[13] : null
229
+ return this
230
+ }
231
+
232
+ this.toString = function() {
233
+ var result = ''
234
+ if(this.scheme != null) result = result + this.scheme + ':'
235
+ if(this.authority != null) result = result + '//' + this.authority
236
+ if(this.path != null) result = result + this.path
237
+ if(this.query != null) result = result + '?' + this.query
238
+ if(this.fragment != null) result = result + '#' + this.fragment
239
+ return result
240
+ }
241
+
242
+ this.toAbsolute = function(base) {
243
+ var base = new jscolor.URI(base)
244
+ var r = this
245
+ var t = new jscolor.URI
246
+
247
+ if(base.scheme == null) return false
248
+
249
+ if(r.scheme != null && r.scheme.toLowerCase() == base.scheme.toLowerCase()) {
250
+ r.scheme = null
251
+ }
252
+
253
+ if(r.scheme != null) {
254
+ t.scheme = r.scheme
255
+ t.authority = r.authority
256
+ t.path = removeDotSegments(r.path)
257
+ t.query = r.query
258
+ } else {
259
+ if(r.authority != null) {
260
+ t.authority = r.authority
261
+ t.path = removeDotSegments(r.path)
262
+ t.query = r.query
263
+ } else {
264
+ if(r.path == '') {
265
+ t.path = base.path
266
+ if(r.query != null) {
267
+ t.query = r.query
268
+ } else {
269
+ t.query = base.query
270
+ }
271
+ } else {
272
+ if(r.path.substr(0,1) == '/') {
273
+ t.path = removeDotSegments(r.path)
274
+ } else {
275
+ if(base.authority != null && base.path == '') {
276
+ t.path = '/'+r.path
277
+ } else {
278
+ t.path = base.path.replace(/[^\/]+$/,'')+r.path
279
+ }
280
+ t.path = removeDotSegments(t.path)
281
+ }
282
+ t.query = r.query
283
+ }
284
+ t.authority = base.authority
285
+ }
286
+ t.scheme = base.scheme
287
+ }
288
+ t.fragment = r.fragment
289
+
290
+ return t
291
+ }
292
+
293
+ function removeDotSegments(path) {
294
+ var out = ''
295
+ while(path) {
296
+ if(path.substr(0,3)=='../' || path.substr(0,2)=='./') {
297
+ path = path.replace(/^\.+/,'').substr(1)
298
+ } else if(path.substr(0,3)=='/./' || path=='/.') {
299
+ path = '/'+path.substr(3)
300
+ } else if(path.substr(0,4)=='/../' || path=='/..') {
301
+ path = '/'+path.substr(4)
302
+ out = out.replace(/\/?[^\/]*$/, '')
303
+ } else if(path=='.' || path=='..') {
304
+ path = ''
305
+ } else {
306
+ var rm = path.match(/^\/?[^\/]*/)[0]
307
+ path = path.substr(rm.length)
308
+ out = out + rm
309
+ }
310
+ }
311
+ return out
312
+ }
313
+
314
+ if(uri) {
315
+ this.parse(uri)
316
+ }
317
+
318
+ },
319
+
320
+
321
+ /*
322
+ * Usage example:
323
+ * var myColor = new jscolor.color(myInputElement)
324
+ */
325
+
326
+ color : function(target, prop) {
327
+
328
+
329
+ this.required = true // refuse empty values?
330
+ this.adjust = true // adjust value to uniform notation?
331
+ this.hash = false // prefix color with # symbol?
332
+ this.caps = true // uppercase?
333
+ this.valueElement = target // value holder
334
+ this.styleElement = target // where to reflect current color
335
+ this.hsv = [0, 0, 1] // read-only 0-6, 0-1, 0-1
336
+ this.rgb = [1, 1, 1] // read-only 0-1, 0-1, 0-1
337
+
338
+ this.pickerOnfocus = true // display picker on focus?
339
+ this.pickerMode = 'HSV' // HSV | HVS
340
+ this.pickerPosition = 'bottom' // left | right | top | bottom
341
+ this.pickerFace = 10 // px
342
+ this.pickerFaceColor = 'ThreeDFace' // CSS color
343
+ this.pickerBorder = 1 // px
344
+ this.pickerBorderColor = 'ThreeDHighlight ThreeDShadow ThreeDShadow ThreeDHighlight' // CSS color
345
+ this.pickerInset = 1 // px
346
+ this.pickerInsetColor = 'ThreeDShadow ThreeDHighlight ThreeDHighlight ThreeDShadow' // CSS color
347
+ this.pickerZIndex = 10000
348
+
349
+
350
+ for(var p in prop) this[p] = prop[p]
351
+
352
+
353
+ this.hidePicker = function() {
354
+ if(isPickerOwner()) {
355
+ removePicker()
356
+ }
357
+ }
358
+
359
+
360
+ this.showPicker = function() {
361
+ if(!isPickerOwner()) {
362
+ var tp = jscolor.getElementPos(target) // target pos
363
+ var ts = jscolor.getElementSize(target) // target size
364
+ var vp = jscolor.getViewPos() // view pos
365
+ var vs = jscolor.getViewSize() // view size
366
+ var ps = [ // picker size
367
+ 2*this.pickerBorder + 4*this.pickerInset + 2*this.pickerFace + jscolor.images.pad[0] + 2*jscolor.images.arrow[0] + jscolor.images.sld[0],
368
+ 2*this.pickerBorder + 2*this.pickerInset + 2*this.pickerFace + jscolor.images.pad[1]
369
+ ]
370
+ var a, b, c
371
+ switch(this.pickerPosition.toLowerCase()) {
372
+ case 'left': a=1; b=0; c=-1; break
373
+ case 'right':a=1; b=0; c=1; break
374
+ case 'top': a=0; b=1; c=-1; break
375
+ default: a=0; b=1; c=1; break
376
+ }
377
+ var l = (ts[b]+ps[b])/2
378
+ var pp = [ // picker pos
379
+ -vp[a]+tp[a]+ps[a] > vs[a] ?
380
+ (-vp[a]+tp[a]+ts[a]/2 > vs[a]/2 && tp[a]+ts[a]-ps[a] >= 0 ? tp[a]+ts[a]-ps[a] : tp[a]) :
381
+ tp[a],
382
+ -vp[b]+tp[b]+ts[b]+ps[b]-l+l*c > vs[b] ?
383
+ (-vp[b]+tp[b]+ts[b]/2 > vs[b]/2 && tp[b]+ts[b]-l-l*c >= 0 ? tp[b]+ts[b]-l-l*c : tp[b]+ts[b]-l+l*c) :
384
+ (tp[b]+ts[b]-l+l*c >= 0 ? tp[b]+ts[b]-l+l*c : tp[b]+ts[b]-l-l*c)
385
+ ]
386
+ drawPicker(pp[a], pp[b])
387
+ }
388
+ }
389
+
390
+
391
+ this.importColor = function() {
392
+ if(!valueElement) {
393
+ this.exportColor()
394
+ } else {
395
+ if(!this.adjust) {
396
+ if(!this.fromString(valueElement.value, leaveValue)) {
397
+ styleElement.style.backgroundColor = styleElement.jscStyle.backgroundColor
398
+ styleElement.style.color = styleElement.jscStyle.color
399
+ this.exportColor(leaveValue | leaveStyle)
400
+ }
401
+ } else if(!this.required && /^\s*$/.test(valueElement.value)) {
402
+ valueElement.value = ''
403
+ styleElement.style.backgroundColor = styleElement.jscStyle.backgroundColor
404
+ styleElement.style.color = styleElement.jscStyle.color
405
+ this.exportColor(leaveValue | leaveStyle)
406
+
407
+ } else if(this.fromString(valueElement.value)) {
408
+ // OK
409
+ } else {
410
+ this.exportColor()
411
+ }
412
+ }
413
+ }
414
+
415
+
416
+ this.exportColor = function(flags) {
417
+ if(!(flags & leaveValue) && valueElement) {
418
+ var value = this.toString()
419
+ if(this.caps) value = value.toUpperCase()
420
+ if(this.hash) value = '#'+value
421
+ valueElement.value = value
422
+ }
423
+ if(!(flags & leaveStyle) && styleElement) {
424
+ styleElement.style.backgroundColor = '#'+this.toString()
425
+ styleElement.style.color =
426
+ 0.213 * this.rgb[0] +
427
+ 0.715 * this.rgb[1] +
428
+ 0.072 * this.rgb[2]
429
+ < 0.5 ? '#FFF' : '#000'
430
+ }
431
+ if(!(flags & leavePad) && isPickerOwner()) {
432
+ redrawPad()
433
+ }
434
+ if(!(flags & leaveSld) && isPickerOwner()) {
435
+ redrawSld()
436
+ }
437
+ }
438
+
439
+
440
+ this.fromHSV = function(h, s, v, flags) { // null = don't change
441
+ h<0 && (h=0) || h>6 && (h=6)
442
+ s<0 && (s=0) || s>1 && (s=1)
443
+ v<0 && (v=0) || v>1 && (v=1)
444
+ this.rgb = HSV_RGB(
445
+ h==null ? this.hsv[0] : (this.hsv[0]=h),
446
+ s==null ? this.hsv[1] : (this.hsv[1]=s),
447
+ v==null ? this.hsv[2] : (this.hsv[2]=v)
448
+ )
449
+ this.exportColor(flags)
450
+ }
451
+
452
+
453
+ this.fromRGB = function(r, g, b, flags) { // null = don't change
454
+ r<0 && (r=0) || r>1 && (r=1)
455
+ g<0 && (g=0) || g>1 && (g=1)
456
+ b<0 && (b=0) || b>1 && (b=1)
457
+ var hsv = RGB_HSV(
458
+ r==null ? this.rgb[0] : (this.rgb[0]=r),
459
+ g==null ? this.rgb[1] : (this.rgb[1]=g),
460
+ b==null ? this.rgb[2] : (this.rgb[2]=b)
461
+ )
462
+ if(hsv[0] != null) {
463
+ this.hsv[0] = hsv[0]
464
+ }
465
+ if(hsv[2] != 0) {
466
+ this.hsv[1] = hsv[1]
467
+ }
468
+ this.hsv[2] = hsv[2]
469
+ this.exportColor(flags)
470
+ }
471
+
472
+
473
+ this.fromString = function(hex, flags) {
474
+ var m = hex.match(/^\W*([0-9A-F]{3}([0-9A-F]{3})?)\W*$/i)
475
+ if(!m) {
476
+ return false
477
+ } else {
478
+ if(m[1].length == 6) { // 6-char notation
479
+ this.fromRGB(
480
+ parseInt(m[1].substr(0,2),16) / 255,
481
+ parseInt(m[1].substr(2,2),16) / 255,
482
+ parseInt(m[1].substr(4,2),16) / 255,
483
+ flags
484
+ )
485
+ } else { // 3-char notation
486
+ this.fromRGB(
487
+ parseInt(m[1].charAt(0)+m[1].charAt(0),16) / 255,
488
+ parseInt(m[1].charAt(1)+m[1].charAt(1),16) / 255,
489
+ parseInt(m[1].charAt(2)+m[1].charAt(2),16) / 255,
490
+ flags
491
+ )
492
+ }
493
+ return true
494
+ }
495
+ }
496
+
497
+
498
+ this.toString = function() {
499
+ return (
500
+ (0x100 | Math.round(255*this.rgb[0])).toString(16).substr(1) +
501
+ (0x100 | Math.round(255*this.rgb[1])).toString(16).substr(1) +
502
+ (0x100 | Math.round(255*this.rgb[2])).toString(16).substr(1)
503
+ )
504
+ }
505
+
506
+
507
+ function RGB_HSV(r, g, b) {
508
+ var n = Math.min(Math.min(r,g),b)
509
+ var v = Math.max(Math.max(r,g),b)
510
+ var m = v - n
511
+ if(m == 0) return [ null, 0, v ]
512
+ var h = r==n ? 3+(b-g)/m : (g==n ? 5+(r-b)/m : 1+(g-r)/m)
513
+ return [ h==6?0:h, m/v, v ]
514
+ }
515
+
516
+
517
+ function HSV_RGB(h, s, v) {
518
+ if(h == null) return [ v, v, v ]
519
+ var i = Math.floor(h)
520
+ var f = i%2 ? h-i : 1-(h-i)
521
+ var m = v * (1 - s)
522
+ var n = v * (1 - s*f)
523
+ switch(i) {
524
+ case 6:
525
+ case 0: return [v,n,m]
526
+ case 1: return [n,v,m]
527
+ case 2: return [m,v,n]
528
+ case 3: return [m,n,v]
529
+ case 4: return [n,m,v]
530
+ case 5: return [v,m,n]
531
+ }
532
+ }
533
+
534
+
535
+ function removePicker() {
536
+ delete jscolor.picker.owner
537
+ document.getElementsByTagName('body')[0].removeChild(jscolor.picker.boxB)
538
+ }
539
+
540
+
541
+ function drawPicker(x, y) {
542
+ if(!jscolor.picker) {
543
+ jscolor.picker = {
544
+ box : document.createElement('div'),
545
+ boxB : document.createElement('div'),
546
+ pad : document.createElement('div'),
547
+ padB : document.createElement('div'),
548
+ padM : document.createElement('div'),
549
+ sld : document.createElement('div'),
550
+ sldB : document.createElement('div'),
551
+ sldM : document.createElement('div')
552
+ }
553
+ for(var i=0,segSize=4; i<jscolor.images.sld[1]; i+=segSize) {
554
+ var seg = document.createElement('div')
555
+ seg.style.height = segSize+'px'
556
+ seg.style.fontSize = '1px'
557
+ seg.style.lineHeight = '0'
558
+ jscolor.picker.sld.appendChild(seg)
559
+ }
560
+ jscolor.picker.sldB.appendChild(jscolor.picker.sld)
561
+ jscolor.picker.box.appendChild(jscolor.picker.sldB)
562
+ jscolor.picker.box.appendChild(jscolor.picker.sldM)
563
+ jscolor.picker.padB.appendChild(jscolor.picker.pad)
564
+ jscolor.picker.box.appendChild(jscolor.picker.padB)
565
+ jscolor.picker.box.appendChild(jscolor.picker.padM)
566
+ jscolor.picker.boxB.appendChild(jscolor.picker.box)
567
+ }
568
+
569
+ var p = jscolor.picker
570
+
571
+ // recompute controls positions
572
+ posPad = [
573
+ x+THIS.pickerBorder+THIS.pickerFace+THIS.pickerInset,
574
+ y+THIS.pickerBorder+THIS.pickerFace+THIS.pickerInset ]
575
+ posSld = [
576
+ null,
577
+ y+THIS.pickerBorder+THIS.pickerFace+THIS.pickerInset ]
578
+
579
+ // controls interaction
580
+ p.box.onmouseup =
581
+ p.box.onmouseout = function() { target.focus() }
582
+ p.box.onmousedown = function() { abortBlur=true }
583
+ p.box.onmousemove = function(e) { holdPad && setPad(e); holdSld && setSld(e) }
584
+ p.padM.onmouseup =
585
+ p.padM.onmouseout = function() { if(holdPad) { holdPad=false; jscolor.fireEvent(valueElement,'change') } }
586
+ p.padM.onmousedown = function(e) { holdPad=true; setPad(e) }
587
+ p.sldM.onmouseup =
588
+ p.sldM.onmouseout = function() { if(holdSld) { holdSld=false; jscolor.fireEvent(valueElement,'change') } }
589
+ p.sldM.onmousedown = function(e) { holdSld=true; setSld(e) }
590
+
591
+ // picker
592
+ p.box.style.width = 4*THIS.pickerInset + 2*THIS.pickerFace + jscolor.images.pad[0] + 2*jscolor.images.arrow[0] + jscolor.images.sld[0] + 'px'
593
+ p.box.style.height = 2*THIS.pickerInset + 2*THIS.pickerFace + jscolor.images.pad[1] + 'px'
594
+
595
+ // picker border
596
+ p.boxB.style.position = 'absolute'
597
+ p.boxB.style.clear = 'both'
598
+ p.boxB.style.left = x+'px'
599
+ p.boxB.style.top = y+'px'
600
+ p.boxB.style.zIndex = THIS.pickerZIndex
601
+ p.boxB.style.border = THIS.pickerBorder+'px solid'
602
+ p.boxB.style.borderColor = THIS.pickerBorderColor
603
+ p.boxB.style.background = THIS.pickerFaceColor
604
+
605
+ // pad image
606
+ p.pad.style.width = jscolor.images.pad[0]+'px'
607
+ p.pad.style.height = jscolor.images.pad[1]+'px'
608
+
609
+ // pad border
610
+ p.padB.style.position = 'absolute'
611
+ p.padB.style.left = THIS.pickerFace+'px'
612
+ p.padB.style.top = THIS.pickerFace+'px'
613
+ p.padB.style.border = THIS.pickerInset+'px solid'
614
+ p.padB.style.borderColor = THIS.pickerInsetColor
615
+
616
+ // pad mouse area
617
+ p.padM.style.position = 'absolute'
618
+ p.padM.style.left = '0'
619
+ p.padM.style.top = '0'
620
+ p.padM.style.width = THIS.pickerFace + 2*THIS.pickerInset + jscolor.images.pad[0] + jscolor.images.arrow[0] + 'px'
621
+ p.padM.style.height = p.box.style.height
622
+ p.padM.style.cursor = 'crosshair'
623
+
624
+ // slider image
625
+ p.sld.style.overflow = 'hidden'
626
+ p.sld.style.width = jscolor.images.sld[0]+'px'
627
+ p.sld.style.height = jscolor.images.sld[1]+'px'
628
+
629
+ // slider border
630
+ p.sldB.style.position = 'absolute'
631
+ p.sldB.style.right = THIS.pickerFace+'px'
632
+ p.sldB.style.top = THIS.pickerFace+'px'
633
+ p.sldB.style.border = THIS.pickerInset+'px solid'
634
+ p.sldB.style.borderColor = THIS.pickerInsetColor
635
+
636
+ // slider mouse area
637
+ p.sldM.style.position = 'absolute'
638
+ p.sldM.style.right = '0'
639
+ p.sldM.style.top = '0'
640
+ p.sldM.style.width = jscolor.images.sld[0] + jscolor.images.arrow[0] + THIS.pickerFace + 2*THIS.pickerInset + 'px'
641
+ p.sldM.style.height = p.box.style.height
642
+ try {
643
+ p.sldM.style.cursor = 'pointer'
644
+ } catch(eOldIE) {
645
+ p.sldM.style.cursor = 'hand'
646
+ }
647
+
648
+ // load images in optimal order
649
+ switch(modeID) {
650
+ case 0: var padImg = 'hs.png'; break
651
+ case 1: var padImg = 'hv.png'; break
652
+ }
653
+ p.padM.style.background = "url('"+jscolor.getDir()+"cross.gif') no-repeat"
654
+ p.sldM.style.background = "url('"+jscolor.getDir()+"arrow.gif') no-repeat"
655
+ p.pad.style.background = "url('"+jscolor.getDir()+padImg+"') 0 0 no-repeat"
656
+
657
+ // place pointers
658
+ redrawPad()
659
+ redrawSld()
660
+
661
+ jscolor.picker.owner = THIS
662
+ document.getElementsByTagName('body')[0].appendChild(p.boxB)
663
+ }
664
+
665
+
666
+ function redrawPad() {
667
+ // redraw the pad pointer
668
+ switch(modeID) {
669
+ case 0: var yComponent = 1; break
670
+ case 1: var yComponent = 2; break
671
+ }
672
+ var x = Math.round((THIS.hsv[0]/6) * (jscolor.images.pad[0]-1))
673
+ var y = Math.round((1-THIS.hsv[yComponent]) * (jscolor.images.pad[1]-1))
674
+ jscolor.picker.padM.style.backgroundPosition =
675
+ (THIS.pickerFace+THIS.pickerInset+x - Math.floor(jscolor.images.cross[0]/2)) + 'px ' +
676
+ (THIS.pickerFace+THIS.pickerInset+y - Math.floor(jscolor.images.cross[1]/2)) + 'px'
677
+
678
+ // redraw the slider image
679
+ var seg = jscolor.picker.sld.childNodes
680
+
681
+ switch(modeID) {
682
+ case 0:
683
+ var rgb = HSV_RGB(THIS.hsv[0], THIS.hsv[1], 1)
684
+ for(var i=0; i<seg.length; i++) {
685
+ seg[i].style.backgroundColor = 'rgb('+
686
+ (rgb[0]*(1-i/seg.length)*100)+'%,'+
687
+ (rgb[1]*(1-i/seg.length)*100)+'%,'+
688
+ (rgb[2]*(1-i/seg.length)*100)+'%)'
689
+ }
690
+ break
691
+ case 1:
692
+ var rgb, s, c = [ THIS.hsv[2], 0, 0 ]
693
+ var i = Math.floor(THIS.hsv[0])
694
+ var f = i%2 ? THIS.hsv[0]-i : 1-(THIS.hsv[0]-i)
695
+ switch(i) {
696
+ case 6:
697
+ case 0: rgb=[0,1,2]; break
698
+ case 1: rgb=[1,0,2]; break
699
+ case 2: rgb=[2,0,1]; break
700
+ case 3: rgb=[2,1,0]; break
701
+ case 4: rgb=[1,2,0]; break
702
+ case 5: rgb=[0,2,1]; break
703
+ }
704
+ for(var i=0; i<seg.length; i++) {
705
+ s = 1 - 1/(seg.length-1)*i
706
+ c[1] = c[0] * (1 - s*f)
707
+ c[2] = c[0] * (1 - s)
708
+ seg[i].style.backgroundColor = 'rgb('+
709
+ (c[rgb[0]]*100)+'%,'+
710
+ (c[rgb[1]]*100)+'%,'+
711
+ (c[rgb[2]]*100)+'%)'
712
+ }
713
+ break
714
+ }
715
+ }
716
+
717
+
718
+ function redrawSld() {
719
+ // redraw the slider pointer
720
+ switch(modeID) {
721
+ case 0: var yComponent = 2; break
722
+ case 1: var yComponent = 1; break
723
+ }
724
+ var y = Math.round((1-THIS.hsv[yComponent]) * (jscolor.images.sld[1]-1))
725
+ jscolor.picker.sldM.style.backgroundPosition =
726
+ '0 ' + (THIS.pickerFace+THIS.pickerInset+y - Math.floor(jscolor.images.arrow[1]/2)) + 'px'
727
+ }
728
+
729
+
730
+ function isPickerOwner() {
731
+ return jscolor.picker && jscolor.picker.owner == THIS
732
+ }
733
+
734
+
735
+ function blurTarget() {
736
+ if(valueElement == target) THIS.importColor()
737
+ if(THIS.pickerOnfocus) THIS.hidePicker()
738
+ }
739
+
740
+
741
+ function blurValue() {
742
+ if(valueElement != target) THIS.importColor()
743
+ }
744
+
745
+
746
+ function setPad(e) {
747
+ var posM = jscolor.getMousePos(e)
748
+ var x = posM[0]-posPad[0]
749
+ var y = posM[1]-posPad[1]
750
+ switch(modeID) {
751
+ case 0: THIS.fromHSV(x*(6/(jscolor.images.pad[0]-1)), 1 - y/(jscolor.images.pad[1]-1), null, leaveSld); break
752
+ case 1: THIS.fromHSV(x*(6/(jscolor.images.pad[0]-1)), null, 1 - y/(jscolor.images.pad[1]-1), leaveSld); break
753
+ }
754
+ }
755
+
756
+
757
+ function setSld(e) {
758
+ var posM = jscolor.getMousePos(e)
759
+ var y = posM[1]-posPad[1]
760
+ switch(modeID) {
761
+ case 0: THIS.fromHSV(null, null, 1 - y/(jscolor.images.sld[1]-1), leavePad); break
762
+ case 1: THIS.fromHSV(null, 1 - y/(jscolor.images.sld[1]-1), null, leavePad); break
763
+ }
764
+ }
765
+
766
+
767
+ var THIS = this
768
+ var modeID = this.pickerMode.toLowerCase()=='hvs' ? 1 : 0
769
+ var abortBlur = false
770
+ var
771
+ valueElement = jscolor.fetchElement(this.valueElement),
772
+ styleElement = jscolor.fetchElement(this.styleElement)
773
+ var
774
+ holdPad = false,
775
+ holdSld = false
776
+ var
777
+ posPad,
778
+ posSld
779
+ var
780
+ leaveValue = 1<<0,
781
+ leaveStyle = 1<<1,
782
+ leavePad = 1<<2,
783
+ leaveSld = 1<<3
784
+
785
+ // target
786
+ jscolor.addEvent(target, 'focus', function() {
787
+ if(THIS.pickerOnfocus) THIS.showPicker()
788
+ })
789
+ jscolor.addEvent(target, 'blur', function() {
790
+ if(!abortBlur) {
791
+ setTimeout(function(){ abortBlur || blurTarget(); abortBlur=false }, 0)
792
+ } else {
793
+ abortBlur = false
794
+ }
795
+ })
796
+
797
+ // valueElement
798
+ if(valueElement) {
799
+ var updateField = function() {
800
+ THIS.fromString(valueElement.value, leaveValue)
801
+ }
802
+ jscolor.addEvent(valueElement, 'keyup', updateField)
803
+ jscolor.addEvent(valueElement, 'input', updateField)
804
+ jscolor.addEvent(valueElement, 'blur', blurValue)
805
+ valueElement.setAttribute('autocomplete', 'off')
806
+ }
807
+
808
+ // styleElement
809
+ if(styleElement) {
810
+ styleElement.jscStyle = {
811
+ backgroundColor : styleElement.style.backgroundColor,
812
+ color : styleElement.style.color
813
+ }
814
+ }
815
+
816
+ // require images
817
+ switch(modeID) {
818
+ case 0: jscolor.requireImage('hs.png'); break
819
+ case 1: jscolor.requireImage('hv.png'); break
820
+ }
821
+ jscolor.requireImage('cross.gif');
822
+ jscolor.requireImage('arrow.gif');
823
+
824
+ this.importColor()
825
+ }
826
+
827
+ }
828
+
829
+
830
+ jscolor.install()
js/pngfix.js CHANGED
@@ -1,5 +1,5 @@
1
- /*
2
-
3
  SCRIPT IS MODIFIED TO ONLY AFFECT PLAY BUTTON OF FV-WORDPRESS-FLOWPLAYER PLUGIN!
4
 
5
  Correctly handle PNG transparency in Win IE 5.5 & 6.
@@ -40,4 +40,4 @@ if ((version >= 5.5) && (document.body.filters))
40
  }
41
  }
42
  }
43
-
1
+ /*
2
+
3
  SCRIPT IS MODIFIED TO ONLY AFFECT PLAY BUTTON OF FV-WORDPRESS-FLOWPLAYER PLUGIN!
4
 
5
  Correctly handle PNG transparency in Win IE 5.5 & 6.
40
  }
41
  }
42
  }
43
+
js/suggestions.js CHANGED
@@ -1,10 +1,10 @@
1
- {
2
- clips: [
3
- { url: 'honda_accord.flv', name: 'Honda commercial', suggestedClipsInfoUrl: 'suggestions.js',
4
- duration: 180, thumbnailUrl: 'Thumb1.jpg',
5
- info: { viewed: 631, category: 'ads' } },
6
- { url: 'river.flv', name: 'Skiing in Rovaniemi', suggestedClipsInfoUrl: 'suggestions.js',
7
- duration: 180, thumbnailUrl: 'Thumb2.jpg',
8
- info: { viewed: 2, category: 'sports' } }
9
- ]
10
  }
1
+ {
2
+ clips: [
3
+ { url: 'honda_accord.flv', name: 'Honda commercial', suggestedClipsInfoUrl: 'suggestions.js',
4
+ duration: 180, thumbnailUrl: 'Thumb1.jpg',
5
+ info: { viewed: 631, category: 'ads' } },
6
+ { url: 'river.flv', name: 'Skiing in Rovaniemi', suggestedClipsInfoUrl: 'suggestions.js',
7
+ duration: 180, thumbnailUrl: 'Thumb2.jpg',
8
+ info: { viewed: 2, category: 'sports' } }
9
+ ]
10
  }
models/flowplayer-backend.php CHANGED
@@ -1,26 +1,28 @@
1
- <?php
2
-
3
- /**
4
- * Extension of original flowplayer class intended for administrator backend.
5
- */
6
- class flowplayer_backend extends flowplayer
7
- {
8
-
9
- /**
10
- * Displays elements that need to be added into head in administrator backend.
11
- */
12
- function flowplayer_head() {
13
- /**
14
- * Standard JS and CSS same as for frontend
15
- */
16
- include dirname( __FILE__ ) . '/../view/frontend-head.php';
17
- /**
18
- * Admin specific CSS and JS
19
- */
20
- include dirname( __FILE__ ) . '/../view/backend-head.php';
21
- }
22
-
23
-
24
- }
25
-
26
- ?>
 
 
1
+ <?php
2
+ /**
3
+ * Extension of original flowplayer class intended for administrator backend.
4
+ */
5
+
6
+ class flowplayer_backend extends flowplayer
7
+ {
8
+
9
+ /**
10
+ * Displays elements that need to be added into head in administrator backend.
11
+ */
12
+ function flowplayer_head() {
13
+ /**
14
+ * Standard JS and CSS same as for frontend
15
+ */
16
+
17
+ include dirname( __FILE__ ) . '/../view/frontend-head.php';
18
+ /**
19
+ * Admin specific CSS and JS
20
+ */
21
+ include dirname( __FILE__ ) . '/../view/backend-head.php';
22
+
23
+ }
24
+
25
+
26
+ }
27
+
28
+ ?>
models/flowplayer-frontend.php CHANGED
@@ -1,130 +1,181 @@
1
- <?php
2
-
3
- /**
4
- * Extension of original flowplayer class intended for frontend.
5
- */
6
- class flowplayer_frontend extends flowplayer
7
- {
8
-
9
- /**
10
- * Builds the HTML and JS code of single flowplayer instance on a page/post.
11
- * @param string $media URL or filename (in case it is in the /videos/ directory) of video file to be played.
12
- * @param array $args Array of arguments (name => value).
13
- * @return Returns array with 2 elements - 'html' => html code displayed anywhere on page/post, 'script' => javascript code displayed before </body> tag
14
- */
15
- function build_min_player($media,$args = array()) {
16
-
17
- // returned array with new player's html and javascript content
18
- $ret = array('html' => '', 'script' => '');
19
-
20
- if(strpos($media,'http://') === false) {
21
- $media = VIDEO_PATH.$media;
22
- }
23
-
24
- // unique coe for this player
25
- $hash = md5($media.$this->_salt());
26
-
27
- // setting argument values
28
- $width = 320;
29
- $height = 240;
30
- $popup = '';
31
- if (isset($args['width'])) $width = $args['width'];
32
- if (isset($args['height'])) $height = $args['height'];
33
-
34
- // if allowed by configuration file, set the popup box js code and content
35
- if ($this->conf['popupbox'] != 'false') {
36
- if (isset($args['popup'])) {
37
- $popup = $args['popup'];
38
- //$popup = html_entity_decode(str_replace("_"," ",substr($popup,1,strlen($popup)-2)));
39
- $popup = html_entity_decode( str_replace('&#039;',"'",$popup ) );
40
- } else {
41
- $popup = '<div style="margin-top: 10px;">Would you like to replay the video or share the link to it with your friends?</div>';
42
- }
43
- $popup_controls = '<div class="popup_controls"><a title="Replay video" href="javascript:fp_replay(\''.$hash.'\');"><img src="'.RELATIVE_PATH.'/images/replay.png" alt="Replay video" /></a><a title="Share video" href="javascript:fp_share(\''.$hash.'\');"><img src="'.RELATIVE_PATH.'/images/share.png" alt="Share video" /></a></div>';
44
- $popup_contents = "\n".'<div id="popup_contents_'.$hash.'" class="popup_contents">'.$popup_controls.'<div id="wpfp_'.$hash.'_custom_popup" class="wpfp_custom_popup">'.$popup.'</div></div>';
45
- // replace href attribute by javascript function
46
- $popup_contents = str_replace("href=\"","onClick=\"javascript:window.location=this.href\" href=\"",$popup_contents);
47
- $popup_code = "
48
- window.flowplayer('wpfp_$hash').onFinish(function() {
49
- var fp = document.getElementById('wpfp_$hash');
50
- var popup = document.createElement('div');
51
- var popup_contents = document.getElementById('popup_contents_$hash');
52
- popup.className = 'flowplayer_popup';
53
- popup.id = 'wpfp_".$hash."_popup';
54
- popup.innerHTML = popup_contents.innerHTML;
55
- fp.appendChild(popup);
56
- });
57
- window.flowplayer('wpfp_$hash').onStart(function() {
58
- var popup = document.getElementById('wpfp_".$hash."_popup');
59
- var fp = document.getElementById('wpfp_$hash');
60
- fp.removeChild(popup);
61
- });
62
- ";
63
- }
64
-
65
- if (isset($args['splash']) && !empty($args['splash'])) {
66
- if(strpos($args['splash'],'http://') === false) {
67
- $splash_img = VIDEO_PATH.$args['splash'];
68
- } else {
69
- $splash_img = $args['splash'];
70
- }
71
- $splash = '<img src="'.$splash_img.'" alt="" class="splash" /><img width="83" height="83" src="'.RELATIVE_PATH.'/images/play.png" alt="" class="splash_play_button" style="top: '.round($height/2-45).'px;" />';
72
- // overriding the "autoplay" configuration - video should start immediately after click on the splash image
73
- $this->conf['autoplay'] = 'true';
74
- }
75
-
76
-
77
-
78
- // set the output JavaScript (which will be added to document head)
79
- $ret['script'] = '
80
- if (document.getElementById(\'wpfp_'.$hash.'\') != null) {
81
- flowplayer("wpfp_'.$hash.'", {src: "'.PLAYER.'", wmode: \'opaque\'}, {
82
- '.(isset($this->conf['key'])&&strlen($this->conf['key'])>0?'key:\''.$this->conf['key'].'\',':'').'
83
- plugins: {
84
- controls: {
85
- autoHide: \'always\',
86
- buttonOverColor: \''.$this->conf['buttonOverColor'].'\',
87
- sliderColor: \''.$this->conf['sliderColor'].'\',
88
- bufferColor: \''.$this->conf['bufferColor'].'\',
89
- sliderGradient: \'none\',
90
- progressGradient: \'medium\',
91
- durationColor: \''.$this->conf['durationColor'].'\',
92
- progressColor: \''.$this->conf['progressColor'].'\',
93
- backgroundColor: \''.$this->conf['backgroundColor'].'\',
94
- timeColor: \''.$this->conf['timeColor'].'\',
95
- buttonColor: \''.$this->conf['buttonColor'].'\',
96
- backgroundGradient: \'none\',
97
- bufferGradient: \'none\',
98
- opacity:1.0
99
- }
100
- },
101
- clip: {
102
- url: \''.$media.'\',
103
- autoPlay: '.(isset($this->conf['autoplay'])?$this->conf['autoplay']:'false').',
104
- autoBuffering: '.(isset($this->conf['autobuffer'])?$this->conf['autobuffer']:'false').'
105
- },
106
- canvas: {
107
- backgroundColor:\''.$this->conf['canvas'].'\'
108
- }
109
- });
110
- };
111
- '.$popup_code;
112
-
113
- // set the output HTML (which will be printed into document body)
114
- $ret['html'] .= '<a id="wpfp_'.$hash.'" style="width:'.$width.'px; height:'.$height.'px;" class="flowplayer_container">'.$splash.'</a>'.$popup_contents;
115
-
116
- // return new player's html and script
117
- return $ret;
118
- }
119
-
120
- /**
121
- * Displays the elements that need to be added to frontend.
122
- */
123
- function flowplayer_head() {
124
- include dirname( __FILE__ ) . '/../view/frontend-head.php';
125
- }
126
-
127
-
128
- }
129
-
130
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Extension of original flowplayer class intended for frontend.
5
+ */
6
+
7
+ class flowplayer_frontend extends flowplayer
8
+ {
9
+
10
+ /**
11
+ * Builds the HTML and JS code of single flowplayer instance on a page/post.
12
+ * @param string $media URL or filename (in case it is in the /videos/ directory) of video file to be played.
13
+ * @param array $args Array of arguments (name => value).
14
+ * @return Returns array with 2 elements - 'html' => html code displayed anywhere on page/post, 'script' => javascript code displayed before </body> tag
15
+ */
16
+ function build_min_player($media,$args = array()) {
17
+
18
+ // returned array with new player's html and javascript content
19
+ $ret = array('html' => '', 'script' => '');
20
+
21
+ if( strpos($media,'http://') === false && strpos($media,'https://') === false ) {
22
+ $media = VIDEO_PATH.$media;
23
+ }
24
+
25
+ // unique coe for this player
26
+ $hash = md5($media.$this->_salt());
27
+
28
+ // setting argument values
29
+ $width = 320;
30
+ $height = 240;
31
+ $popup = '';
32
+ $autoplay = 'false';
33
+ $controlbar = 'always';
34
+ $redirect = '';
35
+ $args['redirect'];
36
+ if (isset($this->conf['autoplay'])&&!empty($this->conf['autoplay'])) $autoplay = trim($this->conf['autoplay']);
37
+ if (isset($args['autoplay'])&&!empty($args['autoplay'])) $autoplay = trim($args['autoplay']);
38
+ if (isset($args['width'])&&!empty($args['width'])) $width = trim($args['width']);
39
+ if (isset($args['height'])&&!empty($args['height'])) $height = trim($args['height']);
40
+ if (isset($args['controlbar'])&&($args['controlbar']=='show')) $controlbar = 'never';
41
+ if (isset($args['redirect'])&&!empty($args['redirect'])) $redirect = trim($args['redirect']);
42
+
43
+ // if allowed by configuration file, set the popup box js code and content
44
+ if (((isset($this->conf['popupbox']))&&($this->conf['popupbox'] != 'false')&&!empty($args['popup']))||(!empty($redirect))) {
45
+ if (isset($args['popup'])) {
46
+ $popup = trim($args['popup']);
47
+ //$popup = html_entity_decode(str_replace("_"," ",substr($popup,1,strlen($popup)-2)));
48
+ $popup = html_entity_decode( str_replace('&#039;',"'",$popup ) );
49
+ } else {
50
+ $popup = '<div style="margin-top: 10px;">Would you like to replay the video or share the link to it with your friends?</div>';
51
+ }
52
+ preg_match('/(\<a href=.*?\>)(.*?)\<\/a\>/',$popup,$matches);
53
+ // var_dump($matches);
54
+ $link_button = '';
55
+ if(!empty($matches[1]));
56
+ $link_button = $matches[1] . '<span class=link_button>' . $matches[2] . '</span></a>';
57
+ $popup_controls = '<div style="position:absolute;top:70%; width:100%;">
58
+ <div class="popup_controls" style="border:none;text-align:center;">
59
+ <a title="Replay video" href="javascript:fp_replay(\''.$hash.'\');">
60
+ <img src="'.RELATIVE_PATH.'/images/replay.png" alt="Replay video" />
61
+ </a>&nbsp;&nbsp;&nbsp;
62
+ <a title="Share video" href="javascript:fp_share(\''.$hash.'\');">
63
+ <img src="'.RELATIVE_PATH.'/images/share.png" alt="Share video" />
64
+ </a>
65
+ </div>
66
+ </div>';
67
+ $popup_contents = "\n".'<div id="popup_contents_'.$hash.'" class="popup_contents" style="border:none;">'.$popup_controls.'
68
+ <div id="wpfp_'.$hash.'_custom_popup" class="wpfp_custom_popup" style="border:none;margin:5%;text-align:center;">'.$popup.'
69
+ <br /><br />'.$link_button.'</div>
70
+ </div>';
71
+ // replace href attribute by javascript function
72
+ $popup_contents = str_replace("href=\"","onClick=\"javascript:window.location=this.href\" href=\"",$popup_contents);
73
+ $popup_code = "
74
+ window.flowplayer('wpfp_$hash').onFinish(function() {
75
+ if ('$redirect'){
76
+ window.open('$redirect','fv_redirect_to');
77
+ }
78
+ else{
79
+ var fp = document.getElementById('wpfp_$hash');
80
+ var popup = document.createElement('div');
81
+ var popup_contents = document.getElementById('popup_contents_$hash');
82
+ popup.className = 'flowplayer_popup';
83
+ popup.id = 'wpfp_".$hash."_popup';
84
+ popup.innerHTML = popup_contents.innerHTML;
85
+ fp.appendChild(popup);
86
+ }
87
+ });
88
+ window.flowplayer('wpfp_$hash').onLoad(function() {
89
+ var fp = document.getElementById('wpfp_".$hash."');
90
+ var emb = document.getElementById('wpfp_".$hash."').innerHTML;
91
+ var e_start = emb.substr(0,emb.indexOf(\"width\",0)+7);
92
+ var e_mid = emb.substr(emb.indexOf(\"width\",0)+11,10);
93
+ var e_end = emb.substr(emb.indexOf(\"height\",0)+12,emb.length-emb.indexOf(\"height\",0)+12);
94
+ e_start = e_start+fp.style.width + e_mid + fp.style.height+e_end;
95
+ document.getElementById('embeded_$hash').value = e_start;
96
+ });
97
+ window.flowplayer('wpfp_$hash').onStart(function() {
98
+ var popup = document.getElementById('wpfp_".$hash."_popup');
99
+ var fp = document.getElementById('wpfp_$hash');
100
+ var emb = document.getElementById('wpfp_".$hash."').innerHTML;
101
+ var e_start = emb.substr(0,emb.indexOf(\"width\",0)+7);
102
+ var e_mid = emb.substr(emb.indexOf(\"width\",0)+11,10);
103
+ var e_end = emb.substr(emb.indexOf(\"height\",0)+12,emb.length-emb.indexOf(\"height\",0)+12);
104
+ e_start = e_start+fp.style.width + e_mid + fp.style.height+e_end;
105
+ document.getElementById('embeded_$hash').value = e_start;
106
+ fp.removeChild(popup);
107
+ });
108
+ ";
109
+ }
110
+
111
+ if (isset($args['splash']) && !empty($args['splash'])) {
112
+ if( strpos($args['splash'],'http://') === false && strpos($args['splash'],'https://') === false ) {
113
+ $splash_img = VIDEO_PATH.trim($args['splash']);
114
+ } else {
115
+ $splash_img = trim($args['splash']);
116
+ }
117
+ $splash = '<img src="'.$splash_img.'" alt="" class="splash" /><img width="83" height="83" border="0" src="'.RELATIVE_PATH.'/images/play.png" alt="" class="splash_play_button" style="top: '.round($height/2-45).'px; border:0;" />';
118
+ // overriding the "autoplay" configuration - video should start immediately after click on the splash image
119
+ $this->conf['autoplay'] = 'true';
120
+ $autoplay = true;
121
+ }
122
+
123
+
124
+
125
+ // set the output JavaScript (which will be added to document head)
126
+ $ret['script'] = '
127
+ if (document.getElementById(\'wpfp_'.$hash.'\') != null) {
128
+ flowplayer("wpfp_'.$hash.'", {src: "'.PLAYER.'", wmode: \'opaque\'}, {
129
+ '.(isset($this->conf['key'])&&strlen($this->conf['key'])>0?'key:\''.trim($this->conf['key']).'\',':'').'
130
+ plugins: {
131
+ '.(((empty($args['controlbar']))||$args['controlbar']=='show')?'
132
+ controls: {
133
+ hideDelay: 500,
134
+ autoHide: \''.trim($controlbar).'\',
135
+ buttonOverColor: \''.trim($this->conf['buttonOverColor']).'\',
136
+ sliderColor: \''.trim($this->conf['sliderColor']).'\',
137
+ bufferColor: \''.trim($this->conf['bufferColor']).'\',
138
+ sliderGradient: \'none\',
139
+ progressGradient: \'medium\',
140
+ durationColor: \''.trim($this->conf['durationColor']).'\',
141
+ progressColor: \''.trim($this->conf['progressColor']).'\',
142
+ backgroundColor: \''.trim($this->conf['backgroundColor']).'\',
143
+ timeColor: \''.trim($this->conf['timeColor']).'\',
144
+ buttonColor: \''.trim($this->conf['buttonColor']).'\',
145
+ backgroundGradient: \'none\',
146
+ bufferGradient: \'none\',
147
+ opacity:1.0,
148
+ fullscreen: '.(isset($this->conf['allowfullscreen'])?trim($this->conf['allowfullscreen']):'true').'
149
+ }':'controls:null'
150
+ ).'
151
+ },
152
+ clip: {
153
+ url: \''.trim($media).'\',
154
+ autoPlay: '.trim($autoplay).',
155
+ autoBuffering: '.(isset($this->conf['autobuffer'])?trim($this->conf['autobuffer']):'false').'
156
+ },
157
+ canvas: {
158
+ backgroundColor:\''.trim($this->conf['canvas']).'\'
159
+ }
160
+ });
161
+ };
162
+ '.$popup_code;
163
+
164
+ // set the output HTML (which will be printed into document body)
165
+ $ret['html'] .= '<a id="wpfp_'.$hash.'" style="width:'.$width.'px; height:'.$height.'px;" class="flowplayer_container">'.$splash.'</a>'.$popup_contents;
166
+
167
+ // return new player's html and script
168
+ return $ret;
169
+ }
170
+
171
+ /**
172
+ * Displays the elements that need to be added to frontend.
173
+ */
174
+ function flowplayer_head() {
175
+ include dirname( __FILE__ ) . '/../view/frontend-head.php';
176
+ }
177
+
178
+
179
+ }
180
+
181
+ ?>
models/flowplayer.php CHANGED
@@ -1,150 +1,117 @@
1
- <?php
2
-
3
- class flowplayer {
4
- private $count = 0;
5
-
6
- /**
7
- * Relative URL path
8
- */
9
- const RELATIVE_PATH = '';
10
- /**
11
- * Where videos should be stored
12
- */
13
- const VIDEO_PATH = '';
14
- /**
15
- * Where the config file should be
16
- */
17
- private $conf_path = '';
18
-
19
- /**
20
- * Configuration variables array
21
- */
22
- public $conf = array();
23
-
24
- /**
25
- * Class constructor
26
- */
27
- public function __construct() {
28
- //set conf path
29
- $this->conf_path = realpath(dirname(__FILE__)).'/../wpfp.conf';
30
- //load conf data into stack
31
- $this->_get_conf();
32
- }
33
- /**
34
- * Gets configuration from cfg file.
35
- *
36
- * @return bool Returns false on failiure, true on success.
37
- */
38
- private function _get_conf() {
39
- //check file exists
40
- if(file_exists($this->conf_path)) {
41
- //open file for reading
42
- $fp = fopen($this->conf_path,'r');
43
- //check if failed to open
44
- if(!$fp) {
45
- error_log('Could not open '.$this->conf_path);
46
- $return = false;
47
- } else {
48
- //read data
49
- $data = fread($fp,filesize($this->conf_path));
50
- //get each line
51
- $tmp = explode("\n",$data);
52
- //get each var
53
- foreach($tmp as $key => $dat) {
54
- //split from var:val
55
- $data = explode(':', $dat);
56
- //build into conf stack
57
- $this->conf[$data[0]] = $data[1];
58
- $return = true;
59
- }
60
- }
61
- fclose($fp);
62
- } else {
63
- error_log("File does not exist: $this->conf_path, attempting to create");
64
- //attempt to create file
65
- if(touch($this->conf_path)) {
66
- //everything is ok!
67
- error_log($this->conf_path.' Created');
68
- //read the data
69
- $this->_get_conf();
70
- } else {
71
- //failed
72
- error_log($this->conf_path.' Creation failed');
73
- $return = false;
74
- }
75
- }
76
-
77
- return $return;
78
- }
79
- /**
80
- * Writes configuration into file.
81
- */
82
- public function _set_conf() {
83
- //attempt to open file
84
- $fp = fopen($this->conf_path,'w');
85
-
86
- if(!$fp) {
87
- error_log('Could not open '.$this->conf_path.' for writing');
88
- } else {
89
- //file is opened for editing!
90
- $str = ''; //setup holder var
91
- //loop post data
92
- foreach($_POST as $key => $data) {
93
-
94
- //do not want to record the submit value in the config file
95
- if($key != "submit") {
96
- // if we have a colour in value, add a #
97
- if (strlen($data) == 6) $data = '#'.$data;
98
- $str .= $key.':'.strtolower($data)."\n";
99
- }
100
- }
101
- //comit data
102
- $len = strlen($str);
103
- //check lenght
104
- if($len > 0) {
105
- //attempt write
106
- $write = fwrite($fp, $str, $len);
107
- //report if failed to error_log
108
- if(!$write) {
109
- error_log('Could not write to '.$this->conf_path);
110
- }
111
- } else {
112
- //report 0 length write attempt
113
- error_log('Caught attempt to write 0 length to config file, aborted');
114
- }
115
- fclose($fp);
116
- }
117
- }
118
- /**
119
- * Salt function - returns pseudorandom string hash.
120
- * @return Pseudorandom string hash.
121
- */
122
- public function _salt() {
123
- $salt = substr(md5(uniqid(rand(), true)), 0, 10);
124
- return $salt;
125
- }
126
-
127
-
128
- }
129
-
130
- /**
131
- * Defines some needed constants and loads the right flowplayer_head() function.
132
- */
133
- function flowplayer_head() {
134
- // define needed constants
135
- if (!defined('RELATIVE_PATH')) {
136
- define('RELATIVE_PATH', get_option('siteurl').'/wp-content/plugins/fv-wordpress-flowplayer');
137
- define('PLAYER', RELATIVE_PATH.'/flowplayer/flowplayer.swf');
138
- $vid = 'http://'.$_SERVER['SERVER_NAME'];
139
- if (dirname($_SERVER['PHP_SELF']) != '/') $vid .= dirname($_SERVER['PHP_SELF']);
140
- define('VIDEO_PATH', $vid.'/videos/');
141
- }
142
- // call the right function for displaying CSS and JS links
143
- if (class_exists('flowplayer_frontend')) {
144
- flowplayer_frontend::flowplayer_head();
145
- } else {
146
- flowplayer_backend::flowplayer_head();
147
- }
148
- }
149
-
150
- ?>
1
+ <?php
2
+
3
+ class flowplayer {
4
+ private $count = 0;
5
+
6
+ /**
7
+ * Relative URL path
8
+ */
9
+ const RELATIVE_PATH = '';
10
+ /**
11
+ * Where videos should be stored
12
+ */
13
+ const VIDEO_PATH = '';
14
+ /**
15
+ * Where the config file should be
16
+ */
17
+ private $conf_path = '';
18
+
19
+ /**
20
+ * Configuration variables array
21
+ */
22
+ public $conf = array();
23
+
24
+ /**
25
+ * Class constructor
26
+ */
27
+ public function __construct() {
28
+ //set conf path
29
+ ///$this->conf_path = realpath(dirname(__FILE__)).'/../wpfp.conf';
30
+ //load conf data into stack
31
+ $this->_get_conf();
32
+ }
33
+ /**
34
+ * Gets configuration from cfg file.
35
+ *
36
+ * @return bool Returns false on failiure, true on success.
37
+ */
38
+ private function _get_conf() {
39
+ /// Addition 2010/07/12 mv
40
+ $conf = get_option( 'fvwpflowplayer' );
41
+
42
+ if( !isset( $conf['autoplay'] ) ) $conf['autoplay'] = 'false';
43
+ if( !isset( $conf['key'] ) ) $conf['key'] = 'false';
44
+ if( !isset( $conf['autobuffer'] ) ) $conf['autobuffer'] = 'false';
45
+ if( !isset( $conf['popupbox'] ) ) $conf['popupbox'] = 'false';
46
+ if( !isset( $conf['allowfullscreen'] ) ) $conf['allowfullscreen'] = 'true';
47
+ if( !isset( $conf['allowuploads'] ) ) $conf['allowuploads'] = 'true';
48
+ if( !isset( $conf['postthumbnail'] ) ) $conf['postthumbnail'] = 'false';
49
+ if( !isset( $conf['tgt'] ) ) $conf['tgt'] = 'backgroundcolor';
50
+ if( !isset( $conf['backgroundColor'] ) ) $conf['backgroundColor'] = '#1b1b1d';
51
+ if( !isset( $conf['canvas'] ) ) $conf['canvas'] = '#ffffff';
52
+ if( !isset( $conf['sliderColor'] ) ) $conf['sliderColor'] = '#2e2e2e';
53
+ if( !isset( $conf['buttonColor'] ) ) $conf['buttonColor'] = '#454545';
54
+ if( !isset( $conf['buttonOverColor'] ) ) $conf['buttonOverColor'] = '#ffffff';
55
+ if( !isset( $conf['durationColor'] ) ) $conf['durationColor'] = '#ffffff';
56
+ if( !isset( $conf['timeColor'] ) ) $conf['timeColor'] = '#ededed';
57
+ if( !isset( $conf['progressColor'] ) ) $conf['progressColor'] = '#707070';
58
+ if( !isset( $conf['bufferColor'] ) ) $conf['bufferColor'] = '#4d4d4d';
59
+ if( !isset( $conf['commas'] ) ) $conf['commas'] = 'true';
60
+
61
+ update_option( 'fvwpflowplayer', $conf );
62
+ $this->conf = $conf;
63
+ return true;
64
+ /// End of addition
65
+ }
66
+ /**
67
+ * Writes configuration into file.
68
+ */
69
+ public function _set_conf() {
70
+ //var_dump( $_POST );
71
+ foreach( $_POST AS $key => $value ) {
72
+ if( (strpos( $key, 'Color' ) !== FALSE )||(strpos( $key, 'canvas' ) !== FALSE)) {
73
+ $_POST[$key] = '#'.strtolower($value);
74
+ }
75
+ }
76
+ update_option( 'fvwpflowplayer', $_POST );
77
+ return;
78
+
79
+ }
80
+ /**
81
+ * Salt function - returns pseudorandom string hash.
82
+ * @return Pseudorandom string hash.
83
+ */
84
+ public function _salt() {
85
+ $salt = substr(md5(uniqid(rand(), true)), 0, 10);
86
+ return $salt;
87
+ }
88
+
89
+
90
+ }
91
+
92
+ /**
93
+ * Defines some needed constants and loads the right flowplayer_head() function.
94
+ */
95
+ function flowplayer_head() {
96
+ // define needed constants
97
+ preg_match('/.*wp-content\/plugins\/(.*?)\/models.*/',dirname(__FILE__),$matches);
98
+ if (isset($matches[1]))
99
+ $strFPdirname = $matches[1];
100
+ else
101
+ $strFPdirname = 'fv-wordpress-flowplayer';
102
+ if (!defined('RELATIVE_PATH')) {
103
+ define('RELATIVE_PATH', get_option('siteurl').'/wp-content/plugins/'.$strFPdirname);
104
+ define('PLAYER', RELATIVE_PATH.'/flowplayer/flowplayer.swf');
105
+ $vid = 'http://'.$_SERVER['SERVER_NAME'];
106
+ if (dirname($_SERVER['PHP_SELF']) != '/') $vid .= dirname($_SERVER['PHP_SELF']);
107
+ define('VIDEO_PATH', $vid.'/videos/');
108
+ }
109
+ // call the right function for displaying CSS and JS links
110
+ if (class_exists('flowplayer_frontend')) {
111
+ flowplayer_frontend::flowplayer_head();
112
+ } else {
113
+ flowplayer_backend::flowplayer_head();
114
+ }
115
+ }
116
+
117
+ ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
readme.txt CHANGED
@@ -1,75 +1,166 @@
1
- === FV Wordpress Flowplayer ===
2
- Contributors: FolioVision
3
- Tags: video, flash, flowplayer
4
- Requires at least: 2.0
5
- Tested up to: 2.9.1
6
- Stable tag: 0.9.17
7
-
8
- Embed videos (FLV, H.264, and MP4) into posts or pages. Uses modified version of flowplayer (with removed FP logo and copyright notice).
9
-
10
- == Description ==
11
-
12
- FV Wordpress Flowplayer plugin is a free, easy-to-use, and complete solution for embedding FLV or MP4 videos into your posts or pages.
13
-
14
- * Plugin is completely non-commercial. It contains modified opensource version of Flowplayer 3.1.3, with removed FP logo and copyright notice.
15
- * Supported video formats are FLV, H.264, and MP4. Multiple videos can be displayed in ope post or page.
16
- * Default options for all the embedded videos can be set in comprehensive administration menu.
17
- * It is loosely based on Wordpress Flowplayer plugin. However, there are several improvements:
18
-
19
- 1. Doesn't use jQuery, so there will be no future conflicts with other plugins.
20
- 2. Usage is simpler and forgiving, making the plugin easier to use.
21
- 3. It will never display any annoying flowplayer logos or copyrights over your videos.
22
- 4. Allows user to display clickable splash screen at the beginning of video (which not only looks good, but improves the performance significantly).
23
- 5. Allows user to display popup box after the video ends, with any HTML content (clickable links, images, styling, etc.)
24
-
25
- == Installation ==
26
-
27
- There aren't any special requirements for FV Wordpress Flowplayer to work, and you don't need to install any additional plugins.
28
-
29
- 1. Download and unpack zip archive containing the plugin.
30
- 2. Upload the fv-wordpress-flowplayer directory into wp-content/plugins/ directory of your wordpress installation.
31
- 3. Make sure, that configuration file wpfp.conf is writable.
32
- 4. Go into Wordpress plugins setup in Wordpress administration interface and activate FV Wordpress Flowplayer plugin.
33
- 5. Optionally, if you want to embed videos denoted just by their filename, you can create the /videos/ directory located directly in the root of your domain and place your videos there. Otherwise, you would have to type in a complete URL of video files.
34
-
35
- == Screenshots ==
36
-
37
- 1. Post containing modified flowplayer playing a video.
38
- 2. Adding three players with different arguments into a post.
39
- 3. Configuration menu for administrators.
40
-
41
- == Changelog ==
42
-
43
- = 0.9.17 =
44
- * minor bug fixes
45
-
46
- = 0.9.16 =
47
- * minor bug fixes
48
-
49
- = 0.9.15 =
50
- * support for widget use and template use
51
-
52
- = 0.9.14 =
53
- * Added a possibility to forbid the popup boxes.
54
- * Some output validation.
55
- * Minor visual improvements.
56
-
57
- = 0.9.13 =
58
- * Added "Replay" and "Share" buttons to the popup box after video finishes.
59
- * Some performance tweaks concerning popup box.
60
-
61
- = 0.9.12 =
62
- * First stable version ready to be published.
63
- * Removed farbtastic colour picker using jQuery from settings menu. Substituted by jscolor.
64
-
65
- == Configuration ==
66
-
67
- Once the plugin is uploaded and activated, there will be a submenu of settings menu called FV Wordpress Flowplayer. In that submenu, you can modify following settings:
68
-
69
- * AutoPlay - decides whether the video starts playing automatically, when the page/post is displayed.
70
- * AutoBuffering - decides whether te video starts buffering automatically, when the page/post is displayed. If AutoPlay is set to true, you can ignore this setting.
71
- * Popup Box - decides whether a popup box with "replay" and "share" buttons will be displayed when video ends.
72
- * Colors of all the parts of flowplayer instances on page/post (controlbar, canvas, sliders, buttons, mouseover buttons, time and total time, progress and buffer sliders).
73
-
74
- On the right side of this screen, you can see the current visual configuration of flowplayer. If you click Apply Changes button, this player's looks refreshes.
75
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === FV Wordpress Flowplayer ===
2
+ Contributors: FolioVision
3
+ Tags: video, flash, flowplayer
4
+ Requires at least: 2.0
5
+ Tested up to: 3.0
6
+ Stable tag: 1.0.6
7
+
8
+ Embed videos (FLV, H.264, and MP4) into posts or pages. Uses modified version of flowplayer (with removed FP logo and copyright notice).
9
+
10
+ == Description ==
11
+
12
+ FV Wordpress Flowplayer plugin is a free, easy-to-use, and complete solution for embedding FLV or MP4 videos into your posts or pages.
13
+
14
+ * Plugin is completely non-commercial. It contains modified opensource version of Flowplayer 3.1.3, with removed FP logo and copyright notice.
15
+ * Supported video formats are FLV, H.264, and MP4. Multiple videos can be displayed in one post or page.
16
+ * Plugin is compatible with Wordpress 3.0
17
+ * Default options for all the embedded videos can be set in comprehensive administration menu.
18
+ * It is loosely based on Wordpress Flowplayer plugin. However, there are several improvements:
19
+
20
+ 1. Doesn't use jQuery, so there will be no future conflicts with other plugins.
21
+ 2. Usage is simpler and forgiving, making the plugin easier to use.
22
+ 3. It will never display any annoying flowplayer logos or copyrights over your videos.
23
+ 4. Allows user to display clickable splash screen at the beginning of video (which not only looks good, but improves the performance significantly).
24
+ 5. Allows user to display popup box after the video ends, with any HTML content (clickable links, images, styling, etc.)
25
+ 6. Allows to upload videos and images through WP Media Library
26
+ 7. Does not use configuration file, but Wordpress Options
27
+
28
+ == Installation ==
29
+
30
+ There aren't any special requirements for FV Wordpress Flowplayer to work, and you don't need to install any additional plugins.
31
+
32
+ 1. Download and unpack zip archive containing the plugin.
33
+ 2. Upload the fv-wordpress-flowplayer directory into wp-content/plugins/ directory of your wordpress installation.
34
+ 3. Go into Wordpress plugins setup in Wordpress administration interface and activate FV Wordpress Flowplayer plugin.
35
+ 4. Optionally, if you want to embed videos denoted just by their filename, you can create the /videos/ directory located directly in the root of your domain and place your videos there. Otherwise, you would have to type in a complete URL of video files.
36
+
37
+
38
+ == Frequently Asked Questions ==
39
+
40
+ = I get an error message like this when activating the plugin: Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /wp-content/plugins/fv-wordpress-flowplayer/models/flowplayer.php on line 4 =
41
+
42
+ You need to use at least PHP 5, your site is probably still running on old PHP 5.
43
+
44
+ = I installed the plugin, inserted the video, but it's not working, only a gray box appears. =
45
+
46
+ Solution 1: FV Flowplayer calls some javascript from the footer. That means your footer.php file must contain the &lt;?php wp_footer(); ?&gt; Wordpress hook. Almost all themes do this out of the box, but if you've customised your theme there's a chance that you might have deleted this call.
47
+
48
+ Solution 2: Try to download the zip file from and install it manually by copying it into your plugins directory. We experienced some problems when upgrading the plugin through Wordpress, when not all files were downloaded correctly.
49
+
50
+ = I tried to change some setting in the admin section, but without effect. =
51
+
52
+ If you used v1.0.4 or less, please make sure, that configuration file wpfp.conf is writable (666 permissions).
53
+
54
+ = You player works just fine, but there are some weird display issues. =
55
+
56
+ Please check if these issues also appear when using the default Wordpress template. There seems to be some sort of conflict between the Flowplayer CSS and your theme CSS.
57
+
58
+ = How to make this plugin WPMU compatible? =
59
+
60
+ Just copy the plugin into wp-content/plugins and then activate it on each blog where you want to use it.
61
+
62
+ = Is there a way to force pre-buffering to load a chunk of the video before the splash screen appears? =
63
+
64
+ This option is not available. With autobuffer, it means every visitor on every visit to your page will be downloading the video. This means that you use a lot more bandwidth than on demand. I know that I actually watch the video on only about 1/3 of the pages with video that I visit. That saves you money (no bandwidth overages) and means that people who do want to watch the video and other visitors to your site get faster performance.
65
+ If you want to autobuffer, you can turn that on in the options (we turn it off by default and recommend that it stays off).
66
+
67
+ = My videos are hosted with Amazon S3 service. How can I fill the details into shortcode? =
68
+
69
+ Currently there is no support for Amazon S3 service, this feature might be added in the future.
70
+
71
+ = The spinning circle is off centre when the video is loading. =
72
+
73
+ This happens when you set width and height of the video other than are native dimensions. We recommend to use native dimensions of the video when placing on a webpage.
74
+
75
+ = The splash image and controlbar are not working properly in widgets. =
76
+
77
+ Please upgrade to version at least 1.0.6.
78
+
79
+ = I would like to lozalize the play again button. =
80
+
81
+ Currently there is no support for other languages. Some localizations for Flowplayer exists, but there is no official support from flowplayer.org.
82
+
83
+ = Where can I change the default directory for videos? =
84
+
85
+ You can change this manually in the the models/flowplayer.php in the flowplayer_head function. It you use videos in widgets you might need to edit the function flowplayer_content in controller/frontend.php as well. Please be carefull when editing source codes.
86
+
87
+ = How do I insert flowpayer object outside the post, for example to a sidebar? =
88
+
89
+ You need to use following code to include the shortcode into a sidebar:
90
+
91
+ echo apply_filters('the_content', '[flowplayer src=yourvideo.mp4 width=240 height=320]');
92
+
93
+ Fill the Flowplayer shortcode part according to your needs. The apply filter needs to be called because the flowplayer shortcodes are not parsen outside posts automatically. Also, please do not forget to add the echo at the beginning.
94
+
95
+
96
+ == Screenshots ==
97
+
98
+ 1. Post containing modified flowplayer playing a video.
99
+ 2. Adding three players with different arguments into a post.
100
+ 3. Add new video dialog window in editing mode.
101
+ 4. Configuration menu for administrators.
102
+
103
+ == Changelog ==
104
+
105
+ = 1.0.6 =
106
+ * widgets problems with splash image and controlbar fixed
107
+ * cyan background color fixed
108
+
109
+ = 1.0.5 =
110
+ * compatibility fixes
111
+ * HTTPS support added
112
+
113
+ = 1.0.4 =
114
+ * compatibility fixes
115
+ * configuration file replaced by WP options
116
+
117
+ = 1.0.3 =
118
+ * white spaces causing errors on some servers fixed
119
+
120
+ = 1.0.2 =
121
+ * redirect feature added (Thanks for donation from Klaus Eickelpasch)
122
+ * more bug fix for wp shortcodes api to be compatible with commas in shortcodes
123
+ * fixed the absolute paths
124
+
125
+ = 1.0.1 =
126
+ * bug fix for wp shortcodes api to be compatible with commas in shortcodes
127
+
128
+ = 1.0 =
129
+ * autoplay option for single videos
130
+ * show/hide control bar
131
+ * show/hide fullscreen option
132
+ * connected with wp media library, video and image upload is supported now (Thanks for donation from Kermit Woodhall)
133
+
134
+ = 0.9.18 =
135
+ * added button & dialog window for easy video adding and editing
136
+
137
+ = 0.9.16 =
138
+ * minor bug fixes
139
+
140
+ = 0.9.15 =
141
+ * support for widget use and template use
142
+
143
+ = 0.9.14 =
144
+ * Added a possibility to forbid the popup boxes.
145
+ * Some output validation.
146
+ * Minor visual improvements.
147
+
148
+ = 0.9.13 =
149
+ * Added "Replay" and "Share" buttons to the popup box after video finishes.
150
+ * Some performance tweaks concerning popup box.
151
+
152
+ = 0.9.12 =
153
+ * First stable version ready to be published.
154
+ * Removed farbtastic colour picker using jQuery from settings menu. Substituted by jscolor.
155
+
156
+ == Configuration ==
157
+
158
+ Once the plugin is uploaded and activated, there will be a submenu of settings menu called FV Wordpress Flowplayer. In that submenu, you can modify following settings:
159
+
160
+ * AutoPlay - decides whether the video starts playing automatically, when the page/post is displayed.
161
+ * AutoBuffering - decides whether te video starts buffering automatically, when the page/post is displayed. If AutoPlay is set to true, you can ignore this setting.
162
+ * Popup Box - decides whether a popup box with "replay" and "share" buttons will be displayed when video ends.
163
+ * Colors of all the parts of flowplayer instances on page/post (controlbar, canvas, sliders, buttons, mouseover buttons, time and total time, progress and buffer sliders).
164
+
165
+ On the right side of this screen, you can see the current visual configuration of flowplayer. If you click Apply Changes button, this player's looks refreshes.
166
+
screenshot-2.png CHANGED
Binary file
screenshot-3.png CHANGED
Binary file
screenshot-4.png ADDED
Binary file
view/admin.php CHANGED
@@ -1,168 +1,193 @@
1
- <?php
2
- /**
3
- * Displays administrator backend.
4
- */
5
- ?>
6
- <div class="wrap">
7
- <table>
8
- <tr>
9
- <td style="width: 450px;">
10
- <form id="wpfp_options" method="post" action="">
11
- <div id="icon-options-general" class="icon32"></div>
12
- <h2>FV Wordpress Flowplayer</h2>
13
- <?php echo flowplayer_check_errors($fp); ?>
14
- <h3>Default Flowplayer Options:</h3>
15
- <table>
16
- <tr>
17
- <td>AutoPlay: </td>
18
- <td>
19
- <select name="autoplay">
20
- <?php echo flowplayer_bool_select($fp->conf['autoplay']); ?>
21
- </select>
22
- </td>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  </tr>
24
- <tr style="position: absolute; top: -9999em; left: -9999em;">
25
- <td>Commercial License Key: </td>
26
- <td>
27
- <input type="text" size="20" name="key" id="key" value="<?php echo $fp->conf['key']; ?>" />
28
- </td>
29
- </tr>
30
- <tr>
31
- <td>Auto Buffering:</td>
32
- <td><select name="autobuffer">
33
-
34
- <?php echo flowplayer_bool_select($fp->conf['autobuffer']); ?>
35
-
36
- </select></td>
37
- </tr>
38
- <tr>
39
- <td>Popup Box:</td>
40
- <td><select name="popupbox">
41
-
42
- <?php echo flowplayer_bool_select($fp->conf['popupbox']); ?>
43
-
44
- </select></td>
45
- </tr>
46
-
47
- <?php echo include dirname( __FILE__ ) . '/../view/colours.php'; ?>
48
-
49
- <tr>
50
- <td>
51
- </td>
52
- <td>
53
- <input type="submit" name="submit" class="button-primary" value="Apply Changes" style="margin-top: 2ex;"/>
54
- </td>
55
- </tr>
56
-
57
- <tr>
58
- <td colspan="2" style="text-align: justify;">
59
- <h3>Description:</h3>
60
- <ul>
61
- <li>FV Wordpress Flowplayer is a completely non-commercial solution for embedding video on Wordpress websites.</li>
62
- <li>It contains opensource version of Flowplayer, with removed logo and copyright notice. </li>
63
- <li>Supported video formats are <strong>FLV</strong>, <strong>H.264</strong>, and <strong>MP4</strong>. Multiple videos can be displayed in ope post or page.</li>
64
- <li>Default options for all the embedded videos can be set in the menu above.</li>
65
- </ul>
66
- <h3>Usage:</h3>
67
- <p>
68
- To embed video "example.flv", simply include the following code inside any post or page:
69
- <code>[flowplayer src=example.flv]</code>
70
- </p>
71
- <p>
72
- <code>src</code> is the only compulsory parameter, specifying the video file. Its value can be either a full URL of the file,
73
- or just a filename, if it is located in the /videos/ directory in the root of the web.
74
- </p>
75
- <h4>Optional parameters:</h4>
76
- <ul style="text-align: left;">
77
- <li><code>width</code> and <code>height</code> specify the dimensions of played video in pixels. If they are not set, the default size is 320x240.<br/>
78
- <i>Example</i>:<br/><code>[flowplayer src=example.flv, width=640, height=480]</code></li>
79
- <li><code>splash</code> parameter can be used to display a custom splash image before the video is started. Just like in case of <code>src</code>
80
- parameter, its value can be either complete URL, or filename of an image located in /videos/ folder.<br/>
81
- <i>Example</i>:<br/><code>[flowplayer src=example.flv, splash=image.jpg]</code></li>
82
- <li><code>popup</code> parameter can be used to display any HTML code after the video finishes (ideal for advertisment or links to similar videos).
83
- Content you want to display must be between simgle quotes (<code>''</code>).<br/>
84
- <i>Example</i>:<br/><code>[flowplayer src=example.flv, popup='&lt;p&gt;some HTML content&lt;/p&gt;']</code></li>
85
- </ul>
86
- </td>
87
- <td></td>
88
- </tr>
89
- </table>
90
- </form>
91
- </td>
92
- <td style="padding: 3em; vertical-align: top;">
93
- <a id="player" class="flowplayer_div" style="display:block;width:400px;height:300px;"></a>
94
- </td>
95
- </tr>
96
- </table>
97
-
98
- <script defer="defer" language="Javascript" type="text/javascript">
99
-
100
- //load player
101
- $f("player", "<?php echo PLAYER; ?>", {
102
- <?php echo (isset($fp->conf['key'])&&strlen($fp->conf['key'])>0?'key:\''.$fp->conf['key'].'\',':''); ?>
103
- plugins: {
104
- controls: {
105
- buttonOverColor: '<?php echo $fp->conf['buttonOverColor']; ?>',
106
- sliderColor: '<?php echo $fp->conf['sliderColor']; ?>',
107
- bufferColor: '<?php echo $fp->conf['bufferColor']; ?>',
108
- sliderGradient: 'none',
109
- progressGradient: 'medium',
110
- durationColor: '<?php echo $fp->conf['durationColor']; ?>',
111
- progressColor: '<?php echo $fp->conf['progressColor']; ?>',
112
- backgroundColor: '<?php echo $fp->conf['backgroundColor']; ?>',
113
- timeColor: '<?php echo $fp->conf['timeColor']; ?>',
114
- buttonColor: '<?php echo $fp->conf['buttonColor']; ?>',
115
- backgroundGradient: 'none',
116
- bufferGradient: 'none',
117
- opacity:1.0
118
- }
119
- },
120
- clip: {
121
- url:'<?php echo RELATIVE_PATH; ?>/flowplayer/example.flv',
122
- autoPlay: '<?php if (isset($fp->conf["autoplay"])) { echo $fp->conf["autoplay"]; } else { echo "false"; } ?>',
123
- autoBuffering: '<?php if (isset($fp->conf["autobuffer"])) { echo $fp->conf["autobuffer"]; } else { echo "false"; } ?>'
124
- },
125
-
126
-
127
- <?php
128
- if($fp->conf['logoenable'] == 'true'){
129
- echo 'logo: {url: \'http://'.$fp->conf['logo'].'\', fullscreenOnly: '.$fp->conf['fullscreenonly'].', displayTime: 0, linkUrl: \'http://'.$fp->conf['logolink'].'\'},';
130
- }
131
- ?>
132
-
133
- canvas: {
134
- backgroundColor:'<?php echo $fp->conf["canvas"]; ?>'
135
- },
136
- onLoad: function() {
137
- $(":input[name=tgt]").removeAttr("disabled");
138
- },
139
- onUnload: function() {
140
- $(":input[name=tgt]").attr("disabled", true);
141
- }
142
- });
143
-
144
- </script>
145
-
146
- </div>
147
-
148
- <?php
149
- if(isset($_POST['submit'])) {
150
- /**
151
- * Write the configuration into file, if the form was submitted.
152
- */
153
- $fp->_set_conf();
154
- /**
155
- * Refresh the page.
156
- */
157
- ?>
158
- <script type="text/JavaScript">
159
- <!--
160
- window.location = window.location;
161
- // -->
162
- </script>
163
- <?php
164
- }
165
- ?>
166
-
167
-
168
-
1
+ <?php
2
+ /**
3
+ * Displays administrator backend.
4
+ */
5
+ ?>
6
+ <div class="wrap">
7
+ <table>
8
+ <tr>
9
+ <td style="width: 450px;">
10
+ <form id="wpfp_options" method="post" action="">
11
+ <div id="icon-options-general" class="icon32"></div>
12
+ <h2>FV Wordpress Flowplayer</h2>
13
+ <?php //echo flowplayer_check_errors($fp); ?>
14
+ <h3>Default Flowplayer Options:</h3>
15
+ <table>
16
+ <tr>
17
+ <td>AutoPlay: </td>
18
+ <td>
19
+ <select name="autoplay">
20
+ <?php echo flowplayer_bool_select($fp->conf['autoplay']); ?>
21
+ </select>
22
+ </td>
23
+ </tr>
24
+ <tr style="position: absolute; top: -9999em; left: -9999em;">
25
+ <td>Commercial License Key: </td>
26
+ <td>
27
+ <input type="text" size="20" name="key" id="key" value="<?php echo trim($fp->conf['key']); ?>" />
28
+ </td>
29
+ </tr>
30
+ <tr>
31
+ <td>Auto Buffering:</td>
32
+ <td><select name="autobuffer">
33
+
34
+ <?php echo flowplayer_bool_select($fp->conf['autobuffer']); ?>
35
+
36
+ </select></td>
37
+ </tr>
38
+ <tr>
39
+ <td>Popup Box:</td>
40
+ <td><select name="popupbox">
41
+
42
+ <?php echo flowplayer_bool_select($fp->conf['popupbox']); ?>
43
+
44
+ </select></td>
45
+ </tr>
46
+ <tr>
47
+ <td>Enable Full-screen Mode:</td>
48
+ <td><select name="allowfullscreen">
49
+ <?php echo flowplayer_bool_select($fp->conf['allowfullscreen']); ?>
50
+
51
+ </select></td>
52
+ </tr>
53
+ <tr>
54
+ <td>Allow User Uploads: </td>
55
+ <td>
56
+ <select name="allowuploads">
57
+ <?php echo flowplayer_bool_select($fp->conf['allowuploads']); ?>
58
+ </select>
59
+ </td>
60
+ </tr>
61
+ <tr>
62
+ <td>Enable Post Thumbnail: </td>
63
+ <td>
64
+ <select name="postthumbnail">
65
+ <?php echo flowplayer_bool_select($fp->conf['postthumbnail']); ?>
66
+ </select>
67
+ </td>
68
  </tr>
69
+ <tr>
70
+ <td>Convert old shortcodes with commas (<abbr title="Older versions of this plugin used commas to sepparate shortcode parameters. This option will make sure it works with current version. Turn this off if you have some problems with display or other plugins which use shortcodes.">?</abbr>): </td>
71
+ <td>
72
+ <select name="commas">
73
+ <?php echo flowplayer_bool_select($fp->conf['commas']); ?>
74
+ </select>
75
+ </td>
76
+ </tr>
77
+
78
+ <?php echo include dirname( __FILE__ ) . '/../view/colours.php'; ?>
79
+
80
+ <tr>
81
+ <td>
82
+ </td>
83
+ <td>
84
+ <input type="submit" name="submit" class="button-primary" value="Apply Changes" style="margin-top: 2ex;"/>
85
+ </td>
86
+ </tr>
87
+
88
+ <tr>
89
+ <td colspan="2" style="text-align: justify;">
90
+ <h3>Description:</h3>
91
+ <ul>
92
+ <li>FV Wordpress Flowplayer is a completely non-commercial solution for embedding video on Wordpress websites.</li>
93
+ <li>It contains opensource version of Flowplayer, with removed logo and copyright notice. </li>
94
+ <li>Supported video formats are <strong>FLV</strong>, <strong>H.264</strong>, and <strong>MP4</strong>. Multiple videos can be displayed in one post or page.</li>
95
+ <li>Default options for all the embedded videos can be set in the menu above.</li>
96
+ </ul>
97
+ <h3>Usage:</h3>
98
+ <p>
99
+ To embed video "example.flv", simply include the following code inside any post or page:
100
+ <code>[flowplayer src=example.flv]</code>
101
+ </p>
102
+ <p>
103
+ <code>src</code> is the only compulsory parameter, specifying the video file. Its value can be either a full URL of the file,
104
+ or just a filename, if it is located in the /videos/ directory in the root of the web.
105
+ </p>
106
+ <p>When user uploads are allowed, uploading or selecting video from WP Media Library is available. To insert selected video, simply use the 'Insert into Post' button.</p>
107
+ <h4>Optional parameters:</h4>
108
+ <ul style="text-align: left;">
109
+ <li><code>width</code> and <code>height</code> specify the dimensions of played video in pixels. If they are not set, the default size is 320x240.<br />
110
+ <i>Example</i>:<br /><code>[flowplayer src='example.flv' width=640 height=480]</code></li>
111
+ <li><code>splash</code> parameter can be used to display a custom splash image before the video is started. Just like in case of <code>src</code>
112
+ parameter, its value can be either complete URL, or filename of an image located in /videos/ folder.<br />
113
+ <i>Example</i>:<br /><code>[flowplayer src='example.flv' splash=image.jpg]</code></li>
114
+ <li><code>autoplay</code> parameter specify wheter the video should start to play automaticaly after the page is loaded. This parameter overrides the default autoplay setting above. Its value can be either true or false.<br />
115
+ <i>Example</i>:<br /><code>[flowplayer src='example.flv' autoplay=true]</code></li>
116
+ <li><code>popup</code> parameter can be used to display any HTML code after the video finishes (ideal for advertisment or links to similar videos).
117
+ Content you want to display must be between simgle quotes (<code>''</code>).<br />
118
+ <i>Example</i>:<br /><code>[flowplayer src='example.flv' popup='&lt;p&gt;some HTML content&lt;/p&gt;']</code></li>
119
+ <li><code>controlbar</code> parameter can be used to show or hide the control bar. Value <code>show</code> will keep the controlbar visible for the whole duration of the video, and value <code>hide</code> will completely hide the control bar. If this parameter is not set, the default autohide is applied.<br />
120
+ <i>Example</i>:<br /><code>[flowplayer src='example.flv' controlbar='show']</code></li>
121
+ <li><code>redirect</code> parameter can be used to redirect to another page (in a new tab) after the video stops playing.<br />
122
+ <i>Example</i>:<br /><code>[flowplayer src='example.flv' redirect='http://www.site.com']</code></li>
123
+ </ul>
124
+ </td>
125
+ <td></td>
126
+ </tr>
127
+ </table>
128
+ </form>
129
+ </td>
130
+ <td style="padding: 3em; vertical-align: top;">
131
+ <a id="player" class="flowplayer_div" style="display:block;width:400px;height:300px;"></a>
132
+ </td>
133
+ </tr>
134
+ </table>
135
+
136
+ <script defer="defer" language="Javascript" type="text/javascript">
137
+
138
+ //load player
139
+ $f("player", "<?php echo PLAYER; ?>", {
140
+ <?php echo (isset($fp->conf['key'])&&strlen($fp->conf['key'])>0?'key:\''.trim($fp->conf['key']).'\',':''); ?>
141
+ plugins: {
142
+ <?php echo (((empty($fp->conf['showcontrols']))||($fp->conf['showcontrols']=='true'))?
143
+ 'controls: { buttonOverColor: \''.trim($fp->conf['buttonOverColor']).'\', sliderColor: \''. trim($fp->conf['sliderColor']).'\', bufferColor: \''. trim($fp->conf['bufferColor']).'\', sliderGradient: \'none\', progressGradient: \'medium\', durationColor: \''. trim($fp->conf['durationColor']).'\', progressColor: \''. trim($fp->conf['progressColor']).'\', backgroundColor: \''. trim($fp->conf['backgroundColor']).'\', timeColor: \''. trim($fp->conf['timeColor']).'\', buttonColor: \''. trim($fp->conf['buttonColor']).'\', backgroundGradient: \'none\', bufferGradient: \'none\', opacity:0.9, fullscreen: '.trim($fp->conf['allowfullscreen']).',autoHide: \'always\',hideDelay: 500} ':'controls:null'); ?>
144
+ },
145
+ clip: {
146
+ url:'<?php echo RELATIVE_PATH; ?>/flowplayer/example.flv',
147
+ autoPlay: '<?php if (isset($fp->conf["autoplay"])) { echo trim($fp->conf["autoplay"]); } else { echo(false); } ?>',
148
+ autoBuffering: '<?php if (isset($fp->conf["autobuffer"])) { echo trim($fp->conf["autobuffer"]); } else { echo "false"; } ?>'
149
+ },
150
+
151
+
152
+ <?php
153
+ if($fp->conf['logoenable'] == 'true'){
154
+ echo 'logo: {url: \'http://'.$fp->conf['logo'].'\', fullscreenOnly: '.trim($fp->conf['fullscreenonly']).', displayTime: 0, linkUrl: \'http://'.$fp->conf['logolink'].'\'},';
155
+ }
156
+ ?>
157
+
158
+ canvas: {
159
+ backgroundColor:'<?php echo trim($fp->conf["canvas"]); ?>'
160
+ },
161
+ onLoad: function() {
162
+ $(":input[name=tgt]").removeAttr("disabled");
163
+ },
164
+ onUnload: function() {
165
+ $(":input[name=tgt]").attr("disabled", true);
166
+ }
167
+ });
168
+
169
+ </script>
170
+
171
+ </div>
172
+
173
+ <?php
174
+ if(isset($_POST['submit'])) {
175
+ /**
176
+ * Write the configuration into file, if the form was submitted.
177
+ */
178
+ $fp->_set_conf();
179
+ /**
180
+ * Refresh the page.
181
+ */
182
+ ?>
183
+ <script type="text/JavaScript">
184
+ <!--
185
+ window.location = window.location;
186
+ // -->
187
+ </script>
188
+ <?php
189
+ }
190
+ ?>
191
+
192
+
193
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
view/backend-head.php CHANGED
@@ -1,11 +1,12 @@
1
- <?php
2
- /**
3
- * Displays metatags for administrator backend.
4
- */
5
- ?>
6
- <!-- FV Flowplayer For Wordpress ADMIN Javascript Start -->
7
- <script type="text/javascript" src="<?php echo RELATIVE_PATH; ?>/js/jscolor/jscolor.js"></script>
8
- <script type="text/javascript" src="<?php echo RELATIVE_PATH; ?>/flowplayer/flowplayer.min.js"></script>
9
- <link rel="stylesheet" href="<?php echo RELATIVE_PATH; ?>/css/flowplayer.css" type="text/css" media="screen" />
10
- <!-- FV Flowplayer For Wordpress ADMIN Javascript END -->
11
-
 
1
+ <?php
2
+ /**
3
+ * Displays metatags for administrator backend.
4
+ */
5
+ ?>
6
+ <!-- FV Flowplayer For Wordpress ADMIN Javascript Start -->
7
+
8
+ <script type="text/javascript" src="<?php echo RELATIVE_PATH; ?>/js/jscolor/jscolor.js"></script>
9
+ <script type="text/javascript" src="<?php echo RELATIVE_PATH; ?>/flowplayer/flowplayer.min.js"></script>
10
+ <link rel="stylesheet" href="<?php echo RELATIVE_PATH; ?>/css/flowplayer.css" type="text/css" media="screen" />
11
+ <!-- FV Flowplayer For Wordpress ADMIN Javascript END -->
12
+
view/colours.php CHANGED
@@ -1,46 +1,46 @@
1
- <?php
2
- /**
3
- * Displays input elements for color settings form.
4
- */
5
- ?>
6
- <tr>
7
- <td></td>
8
- <td><input type="hidden" name="tgt" id="tgt" value="backgroundColor" /></td>
9
- </tr>
10
- <tr>
11
- <td><label for="backgroundColor">controlbar</label></td>
12
- <td><input class="color" type="text" name="backgroundColor" id="backgroundColor" value="<?php echo $fp->conf['backgroundColor']; ?>" /></td>
13
- </tr>
14
- <tr>
15
- <td><label for="canvas">canvas</label></td>
16
- <td><input class="color" type="text" name="canvas" id="canvas" value="<?php echo $fp->conf['canvas']; ?>" /></td>
17
- </tr>
18
- <tr>
19
- <td><label for="sliderColor">sliders</label></td>
20
- <td><input class="color" type="text" name="sliderColor" id="sliderColor" value="<?php echo $fp->conf['sliderColor']; ?>" /></td>
21
- </tr>
22
- <tr>
23
- <td><label for="buttonColor">buttons</label></td>
24
- <td><input class="color" type="text" name="buttonColor" id="buttonColor" value="<?php echo $fp->conf['buttonColor']; ?>" /></td>
25
- </tr>
26
- <tr>
27
- <td><label for="buttonOverColor">mouseover</label></td>
28
- <td><input class="color" type="text" name="buttonOverColor" id="buttonOverColor" value="<?php echo $fp->conf['buttonOverColor']; ?>" /></td>
29
- </tr>
30
- <tr>
31
- <td><label for="durationColor">total time</label></td>
32
- <td><input class="color" type="text" name="durationColor" id="durationColor" value="<?php echo $fp->conf['durationColor']; ?>" /></td>
33
- </tr>
34
- <tr>
35
- <td><label for="timeColor">time</label></td>
36
- <td><input class="color" type="text" name="timeColor" id="timeColor" value="<?php echo $fp->conf['timeColor']; ?>" /></td>
37
- </tr>
38
- <tr>
39
- <td><label for="progressColor">progress</label></td>
40
- <td><input class="color" type="text" name="progressColor" id="progressColor" value="<?php echo $fp->conf['progressColor']; ?>" /></td>
41
- </tr>
42
- <tr>
43
- <td><label for="bufferColor">buffer</label></td>
44
- <td><input class="color" type="text" name="bufferColor" id="bufferColor" value="<?php echo $fp->conf['bufferColor']; ?>" /></td>
45
- </tr>
46
-
1
+ <?php
2
+ /**
3
+ * Displays input elements for color settings form.
4
+ */
5
+ ?>
6
+ <tr>
7
+ <td></td>
8
+ <td><input type="hidden" name="tgt" id="tgt" value="backgroundColor" /></td>
9
+ </tr>
10
+ <tr>
11
+ <td><label for="backgroundColor">controlbar</label></td>
12
+ <td><input class="color" type="text" name="backgroundColor" id="backgroundColor" value="<?php echo $fp->conf['backgroundColor']; ?>" /></td>
13
+ </tr>
14
+ <tr>
15
+ <td><label for="canvas">canvas</label></td>
16
+ <td><input class="color" type="text" name="canvas" id="canvas" value="<?php echo $fp->conf['canvas']; ?>" /></td>
17
+ </tr>
18
+ <tr>
19
+ <td><label for="sliderColor">sliders</label></td>
20
+ <td><input class="color" type="text" name="sliderColor" id="sliderColor" value="<?php echo $fp->conf['sliderColor']; ?>" /></td>
21
+ </tr>
22
+ <tr>
23
+ <td><label for="buttonColor">buttons</label></td>
24
+ <td><input class="color" type="text" name="buttonColor" id="buttonColor" value="<?php echo $fp->conf['buttonColor']; ?>" /></td>
25
+ </tr>
26
+ <tr>
27
+ <td><label for="buttonOverColor">mouseover</label></td>
28
+ <td><input class="color" type="text" name="buttonOverColor" id="buttonOverColor" value="<?php echo $fp->conf['buttonOverColor']; ?>" /></td>
29
+ </tr>
30
+ <tr>
31
+ <td><label for="durationColor">total time</label></td>
32
+ <td><input class="color" type="text" name="durationColor" id="durationColor" value="<?php echo $fp->conf['durationColor']; ?>" /></td>
33
+ </tr>
34
+ <tr>
35
+ <td><label for="timeColor">time</label></td>
36
+ <td><input class="color" type="text" name="timeColor" id="timeColor" value="<?php echo $fp->conf['timeColor']; ?>" /></td>
37
+ </tr>
38
+ <tr>
39
+ <td><label for="progressColor">progress</label></td>
40
+ <td><input class="color" type="text" name="progressColor" id="progressColor" value="<?php echo $fp->conf['progressColor']; ?>" /></td>
41
+ </tr>
42
+ <tr>
43
+ <td><label for="bufferColor">buffer</label></td>
44
+ <td><input class="color" type="text" name="bufferColor" id="bufferColor" value="<?php echo $fp->conf['bufferColor']; ?>" /></td>
45
+ </tr>
46
+
view/frontend-head.php CHANGED
@@ -1,26 +1,27 @@
1
- <?php
2
- /**
3
- * Displays metatags for frontend.
4
- */
5
- ?>
6
- <script type="text/javascript" src="<?php echo RELATIVE_PATH; ?>/flowplayer/flowplayer.min.js"></script>
7
- <link rel="stylesheet" href="<?php echo RELATIVE_PATH; ?>/css/flowplayer.css" type="text/css" media="screen" />
8
- <!--[if lt IE 7.]>
9
- <script defer type="text/javascript" src="<?php echo RELATIVE_PATH; ?>/js/pngfix.js"></script>
10
- <![endif]-->
11
- <script type="text/javascript">
12
- /*<![CDATA[*/
13
- function fp_replay(hash) {
14
- var fp = document.getElementById('wpfp_'+hash);
15
- var popup = document.getElementById('wpfp_'+hash+'_popup');
16
- fp.removeChild(popup);
17
- flowplayer('wpfp_'+hash).play();
18
- }
19
-
20
- function fp_share(hash) {
21
- var cp = document.getElementById('wpfp_'+hash+'_custom_popup');
22
- cp.innerHTML = '<div style="margin-top: 10px; text-align: center;"><label for="permalink" style="color: white;">Permalink to this page:</label><input onclick="this.select();" id="permalink" name="permalink" type="text" value="<?php echo 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; ?>" /></div>';
23
- }
24
- /*]]>*/
25
- </script>
26
-
 
1
+ <?php
2
+ /**
3
+ * Displays metatags for frontend.
4
+ */
5
+
6
+ ?>
7
+ <script type="text/javascript" src="<?php echo RELATIVE_PATH; ?>/flowplayer/flowplayer.min.js"></script>
8
+ <link rel="stylesheet" href="<?php echo RELATIVE_PATH; ?>/css/flowplayer.css" type="text/css" media="screen" />
9
+ <!--[if lt IE 7.]>
10
+ <script defer type="text/javascript" src="<?php echo RELATIVE_PATH; ?>/js/pngfix.js"></script>
11
+ <![endif]-->
12
+ <script type="text/javascript">
13
+ /*<![CDATA[*/
14
+ function fp_replay(hash) {
15
+ var fp = document.getElementById('wpfp_'+hash);
16
+ var popup = document.getElementById('wpfp_'+hash+'_popup');
17
+ fp.removeChild(popup);
18
+ flowplayer('wpfp_'+hash).play();
19
+ }
20
+
21
+ function fp_share(hash) {
22
+ var cp = document.getElementById('wpfp_'+hash+'_custom_popup');
23
+ cp.innerHTML = '<div style="margin-top: 10px; text-align: center;"><label for="permalink" style="color: white;">Permalink to this page:</label><input onclick="this.select();" id="permalink" name="permalink" type="text" value="<?php echo 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; ?>" /></div>';
24
+ }
25
+ /*]]>*/
26
+ </script>
27
+
view/getid3/extension.cache.dbm.php ADDED
@@ -0,0 +1,222 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /////////////////////////////////////////////////////////////////
3
+ /// getID3() by James Heinrich <info@getid3.org> //
4
+ // available at http://getid3.sourceforge.net //
5
+ // or http://www.getid3.org //
6
+ /////////////////////////////////////////////////////////////////
7
+ // //
8
+ // extension.cache.dbm.php - part of getID3() //
9
+ // Please see readme.txt for more information //
10
+ // ///
11
+ /////////////////////////////////////////////////////////////////
12
+ // //
13
+ // This extension written by Allan Hansen <ah�artemis*dk> //
14
+ // ///
15
+ /////////////////////////////////////////////////////////////////
16
+
17
+
18
+ /**
19
+ * This is a caching extension for getID3(). It works the exact same
20
+ * way as the getID3 class, but return cached information very fast
21
+ *
22
+ * Example:
23
+ *
24
+ * Normal getID3 usage (example):
25
+ *
26
+ * require_once 'getid3/getid3.php';
27
+ * $getID3 = new getID3;
28
+ * $getID3->encoding = 'UTF-8';
29
+ * $info1 = $getID3->analyze('file1.flac');
30
+ * $info2 = $getID3->analyze('file2.wv');
31
+ *
32
+ * getID3_cached usage:
33
+ *
34
+ * require_once 'getid3/getid3.php';
35
+ * require_once 'getid3/getid3/extension.cache.dbm.php';
36
+ * $getID3 = new getID3_cached('db3', '/tmp/getid3_cache.dbm',
37
+ * '/tmp/getid3_cache.lock');
38
+ * $getID3->encoding = 'UTF-8';
39
+ * $info1 = $getID3->analyze('file1.flac');
40
+ * $info2 = $getID3->analyze('file2.wv');
41
+ *
42
+ *
43
+ * Supported Cache Types
44
+ *
45
+ * SQL Databases: (use extension.cache.mysql)
46
+ *
47
+ * cache_type cache_options
48
+ * -------------------------------------------------------------------
49
+ * mysql host, database, username, password
50
+ *
51
+ *
52
+ * DBM-Style Databases: (this extension)
53
+ *
54
+ * cache_type cache_options
55
+ * -------------------------------------------------------------------
56
+ * gdbm dbm_filename, lock_filename
57
+ * ndbm dbm_filename, lock_filename
58
+ * db2 dbm_filename, lock_filename
59
+ * db3 dbm_filename, lock_filename
60
+ * db4 dbm_filename, lock_filename (PHP5 required)
61
+ *
62
+ * PHP must have write access to both dbm_filename and lock_filename.
63
+ *
64
+ *
65
+ * Recommended Cache Types
66
+ *
67
+ * Infrequent updates, many reads any DBM
68
+ * Frequent updates mysql
69
+ */
70
+
71
+
72
+ class getID3_cached_dbm extends getID3
73
+ {
74
+
75
+ // public: constructor - see top of this file for cache type and cache_options
76
+ function getID3_cached_dbm($cache_type, $dbm_filename, $lock_filename) {
77
+
78
+ // Check for dba extension
79
+ if (!extension_loaded('dba')) {
80
+ die('PHP is not compiled with dba support, required to use DBM style cache.');
81
+ }
82
+
83
+ // Check for specific dba driver
84
+ if (function_exists('dba_handlers')) { // PHP 4.3.0+
85
+ if (!in_array('db3', dba_handlers())) {
86
+ die('PHP is not compiled --with '.$cache_type.' support, required to use DBM style cache.');
87
+ }
88
+ }
89
+ else { // PHP <= 4.2.3
90
+ ob_start(); // nasty, buy the only way to check...
91
+ phpinfo();
92
+ $contents = ob_get_contents();
93
+ ob_end_clean();
94
+ if (!strstr($contents, $cache_type)) {
95
+ die('PHP is not compiled --with '.$cache_type.' support, required to use DBM style cache.');
96
+ }
97
+ }
98
+
99
+ // Create lock file if needed
100
+ if (!file_exists($lock_filename)) {
101
+ if (!touch($lock_filename)) {
102
+ die('failed to create lock file: ' . $lock_filename);
103
+ }
104
+ }
105
+
106
+ // Open lock file for writing
107
+ if (!is_writeable($lock_filename)) {
108
+ die('lock file: ' . $lock_filename . ' is not writable');
109
+ }
110
+ $this->lock = fopen($lock_filename, 'w');
111
+
112
+ // Acquire exclusive write lock to lock file
113
+ flock($this->lock, LOCK_EX);
114
+
115
+ // Create dbm-file if needed
116
+ if (!file_exists($dbm_filename)) {
117
+ if (!touch($dbm_filename)) {
118
+ die('failed to create dbm file: ' . $dbm_filename);
119
+ }
120
+ }
121
+
122
+ // Try to open dbm file for writing
123
+ $this->dba = @dba_open($dbm_filename, 'w', $cache_type);
124
+ if (!$this->dba) {
125
+
126
+ // Failed - create new dbm file
127
+ $this->dba = dba_open($dbm_filename, 'n', $cache_type);
128
+
129
+ if (!$this->dba) {
130
+ die('failed to create dbm file: ' . $dbm_filename);
131
+ }
132
+
133
+ // Insert getID3 version number
134
+ dba_insert(GETID3_VERSION, GETID3_VERSION, $this->dba);
135
+ }
136
+
137
+ // Init misc values
138
+ $this->cache_type = $cache_type;
139
+ $this->dbm_filename = $dbm_filename;
140
+
141
+ // Register destructor
142
+ register_shutdown_function(array($this, '__destruct'));
143
+
144
+ // Check version number and clear cache if changed
145
+ if (dba_fetch(GETID3_VERSION, $this->dba) != GETID3_VERSION) {
146
+ $this->clear_cache();
147
+ }
148
+
149
+ parent::getID3();
150
+ }
151
+
152
+
153
+
154
+ // public: destuctor
155
+ function __destruct() {
156
+
157
+ // Close dbm file
158
+ @dba_close($this->dba);
159
+
160
+ // Release exclusive lock
161
+ @flock($this->lock, LOCK_UN);
162
+
163
+ // Close lock file
164
+ @fclose($this->lock);
165
+ }
166
+
167
+
168
+
169
+ // public: clear cache
170
+ function clear_cache() {
171
+
172
+ // Close dbm file
173
+ dba_close($this->dba);
174
+
175
+ // Create new dbm file
176
+ $this->dba = dba_open($this->dbm_filename, 'n', $this->cache_type);
177
+
178
+ if (!$this->dba) {
179
+ die('failed to clear cache/recreate dbm file: ' . $this->dbm_filename);
180
+ }
181
+
182
+ // Insert getID3 version number
183
+ dba_insert(GETID3_VERSION, GETID3_VERSION, $this->dba);
184
+
185
+ // Reregister shutdown function
186
+ register_shutdown_function(array($this, '__destruct'));
187
+ }
188
+
189
+
190
+
191
+ // public: analyze file
192
+ function analyze($filename) {
193
+
194
+ if (file_exists($filename)) {
195
+
196
+ // Calc key filename::mod_time::size - should be unique
197
+ $key = $filename . '::' . filemtime($filename) . '::' . filesize($filename);
198
+
199
+ // Loopup key
200
+ $result = dba_fetch($key, $this->dba);
201
+
202
+ // Hit
203
+ if ($result !== false) {
204
+ return unserialize($result);
205
+ }
206
+ }
207
+
208
+ // Miss
209
+ $result = parent::analyze($filename);
210
+
211
+ // Save result
212
+ if (file_exists($filename)) {
213
+ dba_insert($key, serialize($result), $this->dba);
214
+ }
215
+
216
+ return $result;
217
+ }
218
+
219
+ }
220
+
221
+
222
+ ?>
view/getid3/extension.cache.mysql.php ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /////////////////////////////////////////////////////////////////
3
+ /// getID3() by James Heinrich <info@getid3.org> //
4
+ // available at http://getid3.sourceforge.net //
5
+ // or http://www.getid3.org //
6
+ /////////////////////////////////////////////////////////////////
7
+ // //
8
+ // extension.cache.mysql.php - part of getID3() //
9
+ // Please see readme.txt for more information //
10
+ // ///
11
+ /////////////////////////////////////////////////////////////////
12
+ // //
13
+ // This extension written by Allan Hansen <ah�artemis*dk> //
14
+ // ///
15
+ /////////////////////////////////////////////////////////////////
16
+
17
+
18
+ /**
19
+ * This is a caching extension for getID3(). It works the exact same
20
+ * way as the getID3 class, but return cached information very fast
21
+ *
22
+ * Example: (see also demo.cache.mysql.php in /demo/)
23
+ *
24
+ * Normal getID3 usage (example):
25
+ *
26
+ * require_once 'getid3/getid3.php';
27
+ * $getID3 = new getID3;
28
+ * $getID3->encoding = 'UTF-8';
29
+ * $info1 = $getID3->analyze('file1.flac');
30
+ * $info2 = $getID3->analyze('file2.wv');
31
+ *
32
+ * getID3_cached usage:
33
+ *
34
+ * require_once 'getid3/getid3.php';
35
+ * require_once 'getid3/getid3/extension.cache.mysql.php';
36
+ * $getID3 = new getID3_cached_mysql('localhost', 'database',
37
+ * 'username', 'password');
38
+ * $getID3->encoding = 'UTF-8';
39
+ * $info1 = $getID3->analyze('file1.flac');
40
+ * $info2 = $getID3->analyze('file2.wv');
41
+ *
42
+ *
43
+ * Supported Cache Types (this extension)
44
+ *
45
+ * SQL Databases:
46
+ *
47
+ * cache_type cache_options
48
+ * -------------------------------------------------------------------
49
+ * mysql host, database, username, password
50
+ *
51
+ *
52
+ * DBM-Style Databases: (use extension.cache.dbm)
53
+ *
54
+ * cache_type cache_options
55
+ * -------------------------------------------------------------------
56
+ * gdbm dbm_filename, lock_filename
57
+ * ndbm dbm_filename, lock_filename
58
+ * db2 dbm_filename, lock_filename
59
+ * db3 dbm_filename, lock_filename
60
+ * db4 dbm_filename, lock_filename (PHP5 required)
61
+ *
62
+ * PHP must have write access to both dbm_filename and lock_filename.
63
+ *
64
+ *
65
+ * Recommended Cache Types
66
+ *
67
+ * Infrequent updates, many reads any DBM
68
+ * Frequent updates mysql
69
+ */
70
+
71
+
72
+ class getID3_cached_mysql extends getID3
73
+ {
74
+
75
+ // private vars
76
+ var $cursor;
77
+ var $connection;
78
+
79
+
80
+ // public: constructor - see top of this file for cache type and cache_options
81
+ function getID3_cached_mysql($host, $database, $username, $password) {
82
+
83
+ // Check for mysql support
84
+ if (!function_exists('mysql_pconnect')) {
85
+ die('PHP not compiled with mysql support.');
86
+ }
87
+
88
+ // Connect to database
89
+ $this->connection = mysql_pconnect($host, $username, $password);
90
+ if (!$this->connection) {
91
+ die('mysql_pconnect() failed - check permissions and spelling.');
92
+ }
93
+
94
+ // Select database
95
+ if (!mysql_select_db($database, $this->connection)) {
96
+ die('Cannot use database '.$database);
97
+ }
98
+
99
+ // Create cache table if not exists
100
+ $this->create_table();
101
+
102
+ // Check version number and clear cache if changed
103
+ $this->cursor = mysql_query("SELECT `value` FROM `getid3_cache` WHERE (`filename` = '".GETID3_VERSION."') AND (`filesize` = '-1') AND (`filetime` = '-1') AND (`analyzetime` = '-1')", $this->connection);
104
+ list($version) = @mysql_fetch_array($this->cursor);
105
+ if ($version != GETID3_VERSION) {
106
+ $this->clear_cache();
107
+ }
108
+
109
+ parent::getID3();
110
+ }
111
+
112
+
113
+
114
+ // public: clear cache
115
+ function clear_cache() {
116
+
117
+ $this->cursor = mysql_query("DELETE FROM `getid3_cache`", $this->connection);
118
+ $this->cursor = mysql_query("INSERT INTO `getid3_cache` VALUES ('".GETID3_VERSION."', -1, -1, -1, '".GETID3_VERSION."')", $this->connection);
119
+ }
120
+
121
+
122
+
123
+ // public: analyze file
124
+ function analyze($filename) {
125
+
126
+ if (file_exists($filename)) {
127
+
128
+ // Short-hands
129
+ $filetime = filemtime($filename);
130
+ $filesize = filesize($filename);
131
+ $filenam2 = mysql_escape_string($filename);
132
+
133
+ // Loopup file
134
+ $this->cursor = mysql_query("SELECT `value` FROM `getid3_cache` WHERE (`filename`='".$filenam2."') AND (`filesize`='".$filesize."') AND (`filetime`='".$filetime."')", $this->connection);
135
+ list($result) = @mysql_fetch_array($this->cursor);
136
+
137
+ // Hit
138
+ if ($result) {
139
+ return unserialize($result);
140
+ }
141
+ }
142
+
143
+ // Miss
144
+ $result = parent::analyze($filename);
145
+
146
+ // Save result
147
+ if (file_exists($filename)) {
148
+ $res2 = mysql_escape_string(serialize($result));
149
+ $this->cursor = mysql_query("INSERT INTO `getid3_cache` (`filename`, `filesize`, `filetime`, `analyzetime`, `value`) VALUES ('".$filenam2."', '".$filesize."', '".$filetime."', '".time()."', '".$res2."')", $this->connection);
150
+ }
151
+ return $result;
152
+ }
153
+
154
+
155
+
156
+ // private: (re)create sql table
157
+ function create_table($drop = false) {
158
+
159
+ $this->cursor = mysql_query("CREATE TABLE IF NOT EXISTS `getid3_cache` (
160
+ `filename` VARCHAR(255) NOT NULL DEFAULT '',
161
+ `filesize` INT(11) NOT NULL DEFAULT '0',
162
+ `filetime` INT(11) NOT NULL DEFAULT '0',
163
+ `analyzetime` INT(11) NOT NULL DEFAULT '0',
164
+ `value` TEXT NOT NULL,
165
+ PRIMARY KEY (`filename`,`filesize`,`filetime`)) TYPE=MyISAM", $this->connection);
166
+ echo mysql_error($this->connection);
167
+ }
168
+ }
169
+
170
+
171
+ ?>
view/getid3/getid3.lib.php ADDED
@@ -0,0 +1,1309 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /////////////////////////////////////////////////////////////////
3
+ /// getID3() by James Heinrich <info@getid3.org> //
4
+ // available at http://getid3.sourceforge.net //
5
+ // or http://www.getid3.org //
6
+ /////////////////////////////////////////////////////////////////
7
+ // //
8
+ // getid3.lib.php - part of getID3() //
9
+ // See readme.txt for more details //
10
+ // ///
11
+ /////////////////////////////////////////////////////////////////
12
+
13
+
14
+ class getid3_lib
15
+ {
16
+
17
+ function PrintHexBytes($string, $hex=true, $spaces=true, $htmlsafe=true) {
18
+ $returnstring = '';
19
+ for ($i = 0; $i < strlen($string); $i++) {
20
+ if ($hex) {
21
+ $returnstring .= str_pad(dechex(ord($string{$i})), 2, '0', STR_PAD_LEFT);
22
+ } else {
23
+ $returnstring .= ' '.(ereg("[\x20-\x7E]", $string{$i}) ? $string{$i} : '�');
24
+ }
25
+ if ($spaces) {
26
+ $returnstring .= ' ';
27
+ }
28
+ }
29
+ if ($htmlsafe) {
30
+ $returnstring = htmlentities($returnstring);
31
+ }
32
+ return $returnstring;
33
+ }
34
+
35
+ function SafeStripSlashes($text) {
36
+ if (get_magic_quotes_gpc()) {
37
+ return stripslashes($text);
38
+ }
39
+ return $text;
40
+ }
41
+
42
+
43
+ function trunc($floatnumber) {
44
+ // truncates a floating-point number at the decimal point
45
+ // returns int (if possible, otherwise float)
46
+ if ($floatnumber >= 1) {
47
+ $truncatednumber = floor($floatnumber);
48
+ } elseif ($floatnumber <= -1) {
49
+ $truncatednumber = ceil($floatnumber);
50
+ } else {
51
+ $truncatednumber = 0;
52
+ }
53
+ if ($truncatednumber <= 1073741824) { // 2^30
54
+ $truncatednumber = (int) $truncatednumber;
55
+ }
56
+ return $truncatednumber;
57
+ }
58
+
59
+
60
+ function CastAsInt($floatnum) {
61
+ // convert to float if not already
62
+ $floatnum = (float) $floatnum;
63
+
64
+ // convert a float to type int, only if possible
65
+ if (getid3_lib::trunc($floatnum) == $floatnum) {
66
+ // it's not floating point
67
+ if ($floatnum <= 2147483647) { // 2^31
68
+ // it's within int range
69
+ $floatnum = (int) $floatnum;
70
+ }
71
+ }
72
+ return $floatnum;
73
+ }
74
+
75
+
76
+ function DecimalBinary2Float($binarynumerator) {
77
+ $numerator = getid3_lib::Bin2Dec($binarynumerator);
78
+ $denominator = getid3_lib::Bin2Dec('1'.str_repeat('0', strlen($binarynumerator)));
79
+ return ($numerator / $denominator);
80
+ }
81
+
82
+
83
+ function NormalizeBinaryPoint($binarypointnumber, $maxbits=52) {
84
+ // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/binary.html
85
+ if (strpos($binarypointnumber, '.') === false) {
86
+ $binarypointnumber = '0.'.$binarypointnumber;
87
+ } elseif ($binarypointnumber{0} == '.') {
88
+ $binarypointnumber = '0'.$binarypointnumber;
89
+ }
90
+ $exponent = 0;
91
+ while (($binarypointnumber{0} != '1') || (substr($binarypointnumber, 1, 1) != '.')) {
92
+ if (substr($binarypointnumber, 1, 1) == '.') {
93
+ $exponent--;
94
+ $binarypointnumber = substr($binarypointnumber, 2, 1).'.'.substr($binarypointnumber, 3);
95
+ } else {
96
+ $pointpos = strpos($binarypointnumber, '.');
97
+ $exponent += ($pointpos - 1);
98
+ $binarypointnumber = str_replace('.', '', $binarypointnumber);
99
+ $binarypointnumber = $binarypointnumber{0}.'.'.substr($binarypointnumber, 1);
100
+ }
101
+ }
102
+ $binarypointnumber = str_pad(substr($binarypointnumber, 0, $maxbits + 2), $maxbits + 2, '0', STR_PAD_RIGHT);
103
+ return array('normalized'=>$binarypointnumber, 'exponent'=>(int) $exponent);
104
+ }
105
+
106
+
107
+ function Float2BinaryDecimal($floatvalue) {
108
+ // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/binary.html
109
+ $maxbits = 128; // to how many bits of precision should the calculations be taken?
110
+ $intpart = getid3_lib::trunc($floatvalue);
111
+ $floatpart = abs($floatvalue - $intpart);
112
+ $pointbitstring = '';
113
+ while (($floatpart != 0) && (strlen($pointbitstring) < $maxbits)) {
114
+ $floatpart *= 2;
115
+ $pointbitstring .= (string) getid3_lib::trunc($floatpart);
116
+ $floatpart -= getid3_lib::trunc($floatpart);
117
+ }
118
+ $binarypointnumber = decbin($intpart).'.'.$pointbitstring;
119
+ return $binarypointnumber;
120
+ }
121
+
122
+
123
+ function Float2String($floatvalue, $bits) {
124
+ // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee-expl.html
125
+ switch ($bits) {
126
+ case 32:
127
+ $exponentbits = 8;
128
+ $fractionbits = 23;
129
+ break;
130
+
131
+ case 64:
132
+ $exponentbits = 11;
133
+ $fractionbits = 52;
134
+ break;
135
+
136
+ default:
137
+ return false;
138
+ break;
139
+ }
140
+ if ($floatvalue >= 0) {
141
+ $signbit = '0';
142
+ } else {
143
+ $signbit = '1';
144
+ }
145
+ $normalizedbinary = getid3_lib::NormalizeBinaryPoint(getid3_lib::Float2BinaryDecimal($floatvalue), $fractionbits);
146
+ $biasedexponent = pow(2, $exponentbits - 1) - 1 + $normalizedbinary['exponent']; // (127 or 1023) +/- exponent
147
+ $exponentbitstring = str_pad(decbin($biasedexponent), $exponentbits, '0', STR_PAD_LEFT);
148
+ $fractionbitstring = str_pad(substr($normalizedbinary['normalized'], 2), $fractionbits, '0', STR_PAD_RIGHT);
149
+
150
+ return getid3_lib::BigEndian2String(getid3_lib::Bin2Dec($signbit.$exponentbitstring.$fractionbitstring), $bits % 8, false);
151
+ }
152
+
153
+
154
+ function LittleEndian2Float($byteword) {
155
+ return getid3_lib::BigEndian2Float(strrev($byteword));
156
+ }
157
+
158
+
159
+ function BigEndian2Float($byteword) {
160
+ // ANSI/IEEE Standard 754-1985, Standard for Binary Floating Point Arithmetic
161
+ // http://www.psc.edu/general/software/packages/ieee/ieee.html
162
+ // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee.html
163
+
164
+ $bitword = getid3_lib::BigEndian2Bin($byteword);
165
+ if (!$bitword) {
166
+ return 0;
167
+ }
168
+ $signbit = $bitword{0};
169
+
170
+ switch (strlen($byteword) * 8) {
171
+ case 32:
172
+ $exponentbits = 8;
173
+ $fractionbits = 23;
174
+ break;
175
+
176
+ case 64:
177
+ $exponentbits = 11;
178
+ $fractionbits = 52;
179
+ break;
180
+
181
+ case 80:
182
+ // 80-bit Apple SANE format
183
+ // http://www.mactech.com/articles/mactech/Vol.06/06.01/SANENormalized/
184
+ $exponentstring = substr($bitword, 1, 15);
185
+ $isnormalized = intval($bitword{16});
186
+ $fractionstring = substr($bitword, 17, 63);
187
+ $exponent = pow(2, getid3_lib::Bin2Dec($exponentstring) - 16383);
188
+ $fraction = $isnormalized + getid3_lib::DecimalBinary2Float($fractionstring);
189
+ $floatvalue = $exponent * $fraction;
190
+ if ($signbit == '1') {
191
+ $floatvalue *= -1;
192
+ }
193
+ return $floatvalue;
194
+ break;
195
+
196
+ default:
197
+ return false;
198
+ break;
199
+ }
200
+ $exponentstring = substr($bitword, 1, $exponentbits);
201
+ $fractionstring = substr($bitword, $exponentbits + 1, $fractionbits);
202
+ $exponent = getid3_lib::Bin2Dec($exponentstring);
203
+ $fraction = getid3_lib::Bin2Dec($fractionstring);
204
+
205
+ if (($exponent == (pow(2, $exponentbits) - 1)) && ($fraction != 0)) {
206
+ // Not a Number
207
+ $floatvalue = false;
208
+ } elseif (($exponent == (pow(2, $exponentbits) - 1)) && ($fraction == 0)) {
209
+ if ($signbit == '1') {
210
+ $floatvalue = '-infinity';
211
+ } else {
212
+ $floatvalue = '+infinity';
213
+ }
214
+ } elseif (($exponent == 0) && ($fraction == 0)) {
215
+ if ($signbit == '1') {
216
+ $floatvalue = -0;
217
+ } else {
218
+ $floatvalue = 0;
219
+ }
220
+ $floatvalue = ($signbit ? 0 : -0);
221
+ } elseif (($exponent == 0) && ($fraction != 0)) {
222
+ // These are 'unnormalized' values
223
+ $floatvalue = pow(2, (-1 * (pow(2, $exponentbits - 1) - 2))) * getid3_lib::DecimalBinary2Float($fractionstring);
224
+ if ($signbit == '1') {
225
+ $floatvalue *= -1;
226
+ }
227
+ } elseif ($exponent != 0) {
228
+ $floatvalue = pow(2, ($exponent - (pow(2, $exponentbits - 1) - 1))) * (1 + getid3_lib::DecimalBinary2Float($fractionstring));
229
+ if ($signbit == '1') {
230
+ $floatvalue *= -1;
231
+ }
232
+ }
233
+ return (float) $floatvalue;
234
+ }
235
+
236
+
237
+ function BigEndian2Int($byteword, $synchsafe=false, $signed=false) {
238
+ $intvalue = 0;
239
+ $bytewordlen = strlen($byteword);
240
+ for ($i = 0; $i < $bytewordlen; $i++) {
241
+ if ($synchsafe) { // disregard MSB, effectively 7-bit bytes
242
+ $intvalue = $intvalue | (ord($byteword{$i}) & 0x7F) << (($bytewordlen - 1 - $i) * 7);
243
+ } else {
244
+ $intvalue += ord($byteword{$i}) * pow(256, ($bytewordlen - 1 - $i));
245
+ }
246
+ }
247
+ if ($signed && !$synchsafe) {
248
+ // synchsafe ints are not allowed to be signed
249
+ switch ($bytewordlen) {
250
+ case 1:
251
+ case 2:
252
+ case 3:
253
+ case 4:
254
+ $signmaskbit = 0x80 << (8 * ($bytewordlen - 1));
255
+ if ($intvalue & $signmaskbit) {
256
+ $intvalue = 0 - ($intvalue & ($signmaskbit - 1));
257
+ }
258
+ break;
259
+
260
+ default:
261
+ die('ERROR: Cannot have signed integers larger than 32-bits in getid3_lib::BigEndian2Int()');
262
+ break;
263
+ }
264
+ }
265
+ return getid3_lib::CastAsInt($intvalue);
266
+ }
267
+
268
+
269
+ function LittleEndian2Int($byteword, $signed=false) {
270
+ return getid3_lib::BigEndian2Int(strrev($byteword), false, $signed);
271
+ }
272
+
273
+
274
+ function BigEndian2Bin($byteword) {
275
+ $binvalue = '';
276
+ $bytewordlen = strlen($byteword);
277
+ for ($i = 0; $i < $bytewordlen; $i++) {
278
+ $binvalue .= str_pad(decbin(ord($byteword{$i})), 8, '0', STR_PAD_LEFT);
279
+ }
280
+ return $binvalue;
281
+ }
282
+
283
+
284
+ function BigEndian2String($number, $minbytes=1, $synchsafe=false, $signed=false) {
285
+ if ($number < 0) {
286
+ return false;
287
+ }
288
+ $maskbyte = (($synchsafe || $signed) ? 0x7F : 0xFF);
289
+ $intstring = '';
290
+ if ($signed) {
291
+ if ($minbytes > 4) {
292
+ die('ERROR: Cannot have signed integers larger than 32-bits in getid3_lib::BigEndian2String()');
293
+ }
294
+ $number = $number & (0x80 << (8 * ($minbytes - 1)));
295
+ }
296
+ while ($number != 0) {
297
+ $quotient = ($number / ($maskbyte + 1));
298
+ $intstring = chr(ceil(($quotient - floor($quotient)) * $maskbyte)).$intstring;
299
+ $number = floor($quotient);
300
+ }
301
+ return str_pad($intstring, $minbytes, "\x00", STR_PAD_LEFT);
302
+ }
303
+
304
+
305
+ function Dec2Bin($number) {
306
+ while ($number >= 256) {
307
+ $bytes[] = (($number / 256) - (floor($number / 256))) * 256;
308
+ $number = floor($number / 256);
309
+ }
310
+ $bytes[] = $number;
311
+ $binstring = '';
312
+ for ($i = 0; $i < count($bytes); $i++) {
313
+ $binstring = (($i == count($bytes) - 1) ? decbin($bytes[$i]) : str_pad(decbin($bytes[$i]), 8, '0', STR_PAD_LEFT)).$binstring;
314
+ }
315
+ return $binstring;
316
+ }
317
+
318
+
319
+ function Bin2Dec($binstring, $signed=false) {
320
+ $signmult = 1;
321
+ if ($signed) {
322
+ if ($binstring{0} == '1') {
323
+ $signmult = -1;
324
+ }
325
+ $binstring = substr($binstring, 1);
326
+ }
327
+ $decvalue = 0;
328
+ for ($i = 0; $i < strlen($binstring); $i++) {
329
+ $decvalue += ((int) substr($binstring, strlen($binstring) - $i - 1, 1)) * pow(2, $i);
330
+ }
331
+ return getid3_lib::CastAsInt($decvalue * $signmult);
332
+ }
333
+
334
+
335
+ function Bin2String($binstring) {
336
+ // return 'hi' for input of '0110100001101001'
337
+ $string = '';
338
+ $binstringreversed = strrev($binstring);
339
+ for ($i = 0; $i < strlen($binstringreversed); $i += 8) {
340
+ $string = chr(getid3_lib::Bin2Dec(strrev(substr($binstringreversed, $i, 8)))).$string;
341
+ }
342
+ return $string;
343
+ }
344
+
345
+
346
+ function LittleEndian2String($number, $minbytes=1, $synchsafe=false) {
347
+ $intstring = '';
348
+ while ($number > 0) {
349
+ if ($synchsafe) {
350
+ $intstring = $intstring.chr($number & 127);
351
+ $number >>= 7;
352
+ } else {
353
+ $intstring = $intstring.chr($number & 255);
354
+ $number >>= 8;
355
+ }
356
+ }
357
+ return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
358
+ }
359
+
360
+
361
+ function array_merge_clobber($array1, $array2) {
362
+ // written by kc�hireability*com
363
+ // taken from http://www.php.net/manual/en/function.array-merge-recursive.php
364
+ if (!is_array($array1) || !is_array($array2)) {
365
+ return false;
366
+ }
367
+ $newarray = $array1;
368
+ foreach ($array2 as $key => $val) {
369
+ if (is_array($val) && isset($newarray[$key]) && is_array($newarray[$key])) {
370
+ $newarray[$key] = getid3_lib::array_merge_clobber($newarray[$key], $val);
371
+ } else {
372
+ $newarray[$key] = $val;
373
+ }
374
+ }
375
+ return $newarray;
376
+ }
377
+
378
+
379
+ function array_merge_noclobber($array1, $array2) {
380
+ if (!is_array($array1) || !is_array($array2)) {
381
+ return false;
382
+ }
383
+ $newarray = $array1;
384
+ foreach ($array2 as $key => $val) {
385
+ if (is_array($val) && isset($newarray[$key]) && is_array($newarray[$key])) {
386
+ $newarray[$key] = getid3_lib::array_merge_noclobber($newarray[$key], $val);
387
+ } elseif (!isset($newarray[$key])) {
388
+ $newarray[$key] = $val;
389
+ }
390
+ }
391
+ return $newarray;
392
+ }
393
+
394
+
395
+ function fileextension($filename, $numextensions=1) {
396
+ if (strstr($filename, '.')) {
397
+ $reversedfilename = strrev($filename);
398
+ $offset = 0;
399
+ for ($i = 0; $i < $numextensions; $i++) {
400
+ $offset = strpos($reversedfilename, '.', $offset + 1);
401
+ if ($offset === false) {
402
+ return '';
403
+ }
404
+ }
405
+ return strrev(substr($reversedfilename, 0, $offset));
406
+ }
407
+ return '';
408
+ }
409
+
410
+
411
+ function PlaytimeString($playtimeseconds) {
412
+ $sign = (($playtimeseconds < 0) ? '-' : '');
413
+ $playtimeseconds = abs($playtimeseconds);
414
+ $contentseconds = round((($playtimeseconds / 60) - floor($playtimeseconds / 60)) * 60);
415
+ $contentminutes = floor($playtimeseconds / 60);
416
+ if ($contentseconds >= 60) {
417
+ $contentseconds -= 60;
418
+ $contentminutes++;
419
+ }
420
+ return $sign.intval($contentminutes).':'.str_pad($contentseconds, 2, 0, STR_PAD_LEFT);
421
+ }
422
+
423
+
424
+ function image_type_to_mime_type($imagetypeid) {
425
+ // only available in PHP v4.3.0+
426
+ static $image_type_to_mime_type = array();
427
+ if (empty($image_type_to_mime_type)) {
428
+ $image_type_to_mime_type[1] = 'image/gif'; // GIF
429
+ $image_type_to_mime_type[2] = 'image/jpeg'; // JPEG
430
+ $image_type_to_mime_type[3] = 'image/png'; // PNG
431
+ $image_type_to_mime_type[4] = 'application/x-shockwave-flash'; // Flash
432
+ $image_type_to_mime_type[5] = 'image/psd'; // PSD
433
+ $image_type_to_mime_type[6] = 'image/bmp'; // BMP
434
+ $image_type_to_mime_type[7] = 'image/tiff'; // TIFF: little-endian (Intel)
435
+ $image_type_to_mime_type[8] = 'image/tiff'; // TIFF: big-endian (Motorola)
436
+ //$image_type_to_mime_type[9] = 'image/jpc'; // JPC
437
+ //$image_type_to_mime_type[10] = 'image/jp2'; // JPC
438
+ //$image_type_to_mime_type[11] = 'image/jpx'; // JPC
439
+ //$image_type_to_mime_type[12] = 'image/jb2'; // JPC
440
+ $image_type_to_mime_type[13] = 'application/x-shockwave-flash'; // Shockwave
441
+ $image_type_to_mime_type[14] = 'image/iff'; // IFF
442
+ }
443
+ return (isset($image_type_to_mime_type[$imagetypeid]) ? $image_type_to_mime_type[$imagetypeid] : 'application/octet-stream');
444
+ }
445
+
446
+
447
+ function DateMac2Unix($macdate) {
448
+ // Macintosh timestamp: seconds since 00:00h January 1, 1904
449
+ // UNIX timestamp: seconds since 00:00h January 1, 1970
450
+ return getid3_lib::CastAsInt($macdate - 2082844800);
451
+ }
452
+
453
+
454
+ function FixedPoint8_8($rawdata) {
455
+ return getid3_lib::BigEndian2Int(substr($rawdata, 0, 1)) + (float) (getid3_lib::BigEndian2Int(substr($rawdata, 1, 1)) / pow(2, 8));
456
+ }
457
+
458
+
459
+ function FixedPoint16_16($rawdata) {
460
+ return getid3_lib::BigEndian2Int(substr($rawdata, 0, 2)) + (float) (getid3_lib::BigEndian2Int(substr($rawdata, 2, 2)) / pow(2, 16));
461
+ }
462
+
463
+
464
+ function FixedPoint2_30($rawdata) {
465
+ $binarystring = getid3_lib::BigEndian2Bin($rawdata);
466
+ return getid3_lib::Bin2Dec(substr($binarystring, 0, 2)) + (float) (getid3_lib::Bin2Dec(substr($binarystring, 2, 30)) / 1073741824);
467
+ }
468
+
469
+
470
+ function CreateDeepArray($ArrayPath, $Separator, $Value) {
471
+ // assigns $Value to a nested array path:
472
+ // $foo = getid3_lib::CreateDeepArray('/path/to/my', '/', 'file.txt')
473
+ // is the same as:
474
+ // $foo = array('path'=>array('to'=>'array('my'=>array('file.txt'))));
475
+ // or
476
+ // $foo['path']['to']['my'] = 'file.txt';
477
+ while ($ArrayPath && ($ArrayPath{0} == $Separator)) {
478
+ $ArrayPath = substr($ArrayPath, 1);
479
+ }
480
+ if (($pos = strpos($ArrayPath, $Separator)) !== false) {
481
+ $ReturnedArray[substr($ArrayPath, 0, $pos)] = getid3_lib::CreateDeepArray(substr($ArrayPath, $pos + 1), $Separator, $Value);
482
+ } else {
483
+ $ReturnedArray[$ArrayPath] = $Value;
484
+ }
485
+ return $ReturnedArray;
486
+ }
487
+
488
+ function array_max($arraydata, $returnkey=false) {
489
+ $maxvalue = false;
490
+ $maxkey = false;
491
+ foreach ($arraydata as $key => $value) {
492
+ if (!is_array($value)) {
493
+ if ($value > $maxvalue) {
494
+ $maxvalue = $value;
495
+ $maxkey = $key;
496
+ }
497
+ }
498
+ }
499
+ return ($returnkey ? $maxkey : $maxvalue);
500
+ }
501
+
502
+ function array_min($arraydata, $returnkey=false) {
503
+ $minvalue = false;
504
+ $minkey = false;
505
+ foreach ($arraydata as $key => $value) {
506
+ if (!is_array($value)) {
507
+ if ($value > $minvalue) {
508
+ $minvalue = $value;
509
+ $minkey = $key;
510
+ }
511
+ }
512
+ }
513
+ return ($returnkey ? $minkey : $minvalue);
514
+ }
515
+
516
+
517
+ function md5_file($file) {
518
+
519
+ // md5_file() exists in PHP 4.2.0+.
520
+ if (function_exists('md5_file')) {
521
+ return md5_file($file);
522
+ }
523
+
524
+ if (GETID3_OS_ISWINDOWS) {
525
+
526
+ $RequiredFiles = array('cygwin1.dll', 'md5sum.exe');
527
+ foreach ($RequiredFiles as $required_file) {
528
+ if (!is_readable(GETID3_HELPERAPPSDIR.$required_file)) {
529
+ die(implode(' and ', $RequiredFiles).' are required in '.GETID3_HELPERAPPSDIR.' for getid3_lib::md5_file() to function under Windows in PHP < v4.2.0');
530
+ }
531
+ }
532
+ $commandline = GETID3_HELPERAPPSDIR.'md5sum.exe "'.str_replace('/', DIRECTORY_SEPARATOR, $file).'"';
533
+ if (ereg("^[\\]?([0-9a-f]{32})", strtolower(`$commandline`), $r)) {
534
+ return $r[1];
535
+ }
536
+
537
+ } else {
538
+
539
+ // The following works under UNIX only
540
+ $file = str_replace('`', '\\`', $file);
541
+ if (ereg("^([0-9a-f]{32})[ \t\n\r]", `md5sum "$file"`, $r)) {
542
+ return $r[1];
543
+ }
544
+
545
+ }
546
+ return false;
547
+ }
548
+
549
+
550
+ function sha1_file($file) {
551
+
552
+ // sha1_file() exists in PHP 4.3.0+.
553
+ if (function_exists('sha1_file')) {
554
+ return sha1_file($file);
555
+ }
556
+
557
+ $file = str_replace('`', '\\`', $file);
558
+
559
+ if (GETID3_OS_ISWINDOWS) {
560
+
561
+ $RequiredFiles = array('cygwin1.dll', 'sha1sum.exe');
562
+ foreach ($RequiredFiles as $required_file) {
563
+ if (!is_readable(GETID3_HELPERAPPSDIR.$required_file)) {
564
+ die(implode(' and ', $RequiredFiles).' are required in '.GETID3_HELPERAPPSDIR.' for getid3_lib::sha1_file() to function under Windows in PHP < v4.3.0');
565
+ }
566
+ }
567
+ $commandline = GETID3_HELPERAPPSDIR.'sha1sum.exe "'.str_replace('/', DIRECTORY_SEPARATOR, $file).'"';
568
+ if (ereg("^sha1=([0-9a-f]{40})", strtolower(`$commandline`), $r)) {
569
+ return $r[1];
570
+ }
571
+
572
+ } else {
573
+
574
+ $commandline = 'sha1sum '.escapeshellarg($file).'';
575
+ if (ereg("^([0-9a-f]{40})[ \t\n\r]", strtolower(`$commandline`), $r)) {
576
+ return $r[1];
577
+ }
578
+
579
+ }
580
+
581
+ return false;
582
+ }
583
+
584
+
585
+ // Allan Hansen <ah�artemis*dk>
586
+ // getid3_lib::md5_data() - returns md5sum for a file from startuing position to absolute end position
587
+ function hash_data($file, $offset, $end, $algorithm) {
588
+ if ($end >= pow(2, 31)) {
589
+ return false;
590
+ }
591
+
592
+ switch ($algorithm) {
593
+ case 'md5':
594
+ $hash_function = 'md5_file';
595
+ $unix_call = 'md5sum';
596
+ $windows_call = 'md5sum.exe';
597
+ $hash_length = 32;
598
+ break;
599
+
600
+ case 'sha1':
601
+ $hash_function = 'sha1_file';
602
+ $unix_call = 'sha1sum';
603
+ $windows_call = 'sha1sum.exe';
604
+ $hash_length = 40;
605
+ break;
606
+
607
+ default:
608
+ die('Invalid algorithm ('.$algorithm.') in getid3_lib::hash_data()');
609
+ break;
610
+ }
611
+ $size = $end - $offset;
612
+ while (true) {
613
+ if (GETID3_OS_ISWINDOWS) {
614
+
615
+ // It seems that sha1sum.exe for Windows only works on physical files, does not accept piped data
616
+ // Fall back to create-temp-file method:
617
+ if ($algorithm == 'sha1') {
618
+ break;
619
+ }
620
+
621
+ $RequiredFiles = array('cygwin1.dll', 'head.exe', 'tail.exe', $windows_call);
622
+ foreach ($RequiredFiles as $required_file) {
623
+ if (!is_readable(GETID3_HELPERAPPSDIR.$required_file)) {
624
+ // helper apps not available - fall back to old method
625
+ break;
626
+ }
627
+ }
628
+ $commandline = GETID3_HELPERAPPSDIR.'head.exe -c '.$end.' "'.escapeshellarg(str_replace('/', DIRECTORY_SEPARATOR, $file)).'" | ';
629
+ $commandline .= GETID3_HELPERAPPSDIR.'tail.exe -c '.$size.' | ';
630
+ $commandline .= GETID3_HELPERAPPSDIR.$windows_call;
631
+
632
+ } else {
633
+
634
+ $commandline = 'head -c'.$end.' '.escapeshellarg($file).' | ';
635
+ $commandline .= 'tail -c'.$size.' | ';
636
+ $commandline .= $unix_call;
637
+
638
+ }
639
+ if ((bool) ini_get('safe_mode')) {
640
+ $ThisFileInfo['warning'][] = 'PHP running in Safe Mode - backtick operator not available, using slower non-system-call '.$algorithm.' algorithm';
641
+ break;
642
+ }
643
+ return substr(`$commandline`, 0, $hash_length);
644
+ }
645
+
646
+ // try to create a temporary file in the system temp directory - invalid dirname should force to system temp dir
647
+ if (($data_filename = tempnam('*', 'getID3')) === false) {
648
+ // can't find anywhere to create a temp file, just die
649
+ return false;
650
+ }
651
+
652
+ // Init
653
+ $result = false;
654
+
655
+ // copy parts of file
656
+ if ($fp = @fopen($file, 'rb')) {
657
+
658
+ if ($fp_data = @fopen($data_filename, 'wb')) {
659
+
660
+ fseek($fp, $offset, SEEK_SET);
661
+ $byteslefttowrite = $end - $offset;
662
+ while (($byteslefttowrite > 0) && ($buffer = fread($fp, GETID3_FREAD_BUFFER_SIZE))) {
663
+ $byteswritten = fwrite($fp_data, $buffer, $byteslefttowrite);
664
+ $byteslefttowrite -= $byteswritten;
665
+ }
666
+ fclose($fp_data);
667
+ $result = getid3_lib::$hash_function($data_filename);
668
+
669
+ }
670
+ fclose($fp);
671
+ }
672
+ unlink($data_filename);
673
+ return $result;
674
+ }
675
+
676
+
677
+ function iconv_fallback_int_utf8($charval) {
678
+ if ($charval < 128) {
679
+ // 0bbbbbbb
680
+ $newcharstring = chr($charval);
681
+ } elseif ($charval < 2048) {
682
+ // 110bbbbb 10bbbbbb
683
+ $newcharstring = chr(($charval >> 6) | 0xC0);
684
+ $newcharstring .= chr(($charval & 0x3F) | 0x80);
685
+ } elseif ($charval < 65536) {
686
+ // 1110bbbb 10bbbbbb 10bbbbbb
687
+ $newcharstring = chr(($charval >> 12) | 0xE0);
688
+ $newcharstring .= chr(($charval >> 6) | 0xC0);
689
+ $newcharstring .= chr(($charval & 0x3F) | 0x80);
690
+ } else {
691
+ // 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb
692
+ $newcharstring = chr(($charval >> 18) | 0xF0);
693
+ $newcharstring .= chr(($charval >> 12) | 0xC0);
694
+ $newcharstring .= chr(($charval >> 6) | 0xC0);
695
+ $newcharstring .= chr(($charval & 0x3F) | 0x80);
696
+ }
697
+ return $newcharstring;
698
+ }
699
+
700
+ // ISO-8859-1 => UTF-8
701
+ function iconv_fallback_iso88591_utf8($string, $bom=false) {
702
+ if (function_exists('utf8_encode')) {
703
+ return utf8_encode($string);
704
+ }
705
+ // utf8_encode() unavailable, use getID3()'s iconv_fallback() conversions (possibly PHP is compiled without XML support)
706
+ $newcharstring = '';
707
+ if ($bom) {
708
+ $newcharstring .= "\xEF\xBB\xBF";
709
+ }
710
+ for ($i = 0; $i < strlen($string); $i++) {
711
+ $charval = ord($string{$i});
712
+ $newcharstring .= getid3_lib::iconv_fallback_int_utf8($charval);
713
+ }
714
+ return $newcharstring;
715
+ }
716
+
717
+ // ISO-8859-1 => UTF-16BE
718
+ function iconv_fallback_iso88591_utf16be($string, $bom=false) {
719
+ $newcharstring = '';
720
+ if ($bom) {
721
+ $newcharstring .= "\xFE\xFF";
722
+ }
723
+ for ($i = 0; $i < strlen($string); $i++) {
724
+ $newcharstring .= "\x00".$string{$i};
725
+ }
726
+ return $newcharstring;
727
+ }
728
+
729
+ // ISO-8859-1 => UTF-16LE
730
+ function iconv_fallback_iso88591_utf16le($string, $bom=false) {
731
+ $newcharstring = '';
732
+ if ($bom) {
733
+ $newcharstring .= "\xFF\xFE";
734
+ }
735
+ for ($i = 0; $i < strlen($string); $i++) {
736
+ $newcharstring .= $string{$i}."\x00";
737
+ }
738
+ return $newcharstring;
739
+ }
740
+
741
+ // ISO-8859-1 => UTF-16LE (BOM)
742
+ function iconv_fallback_iso88591_utf16($string) {
743
+ return getid3_lib::iconv_fallback_iso88591_utf16le($string, true);
744
+ }
745
+
746
+ // UTF-8 => ISO-8859-1
747
+ function iconv_fallback_utf8_iso88591($string) {
748
+ if (function_exists('utf8_decode')) {
749
+ return utf8_decode($string);
750
+ }
751
+ // utf8_decode() unavailable, use getID3()'s iconv_fallback() conversions (possibly PHP is compiled without XML support)
752
+ $newcharstring = '';
753
+ $offset = 0;
754
+ $stringlength = strlen($string);
755
+ while ($offset < $stringlength) {
756
+ if ((ord($string{$offset}) | 0x07) == 0xF7) {
757
+ // 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb
758
+ $charval = ((ord($string{($offset + 0)}) & 0x07) << 18) &
759
+ ((ord($string{($offset + 1)}) & 0x3F) << 12) &
760
+ ((ord($string{($offset + 2)}) & 0x3F) << 6) &
761
+ (ord($string{($offset + 3)}) & 0x3F);
762
+ $offset += 4;
763
+ } elseif ((ord($string{$offset}) | 0x0F) == 0xEF) {
764
+ // 1110bbbb 10bbbbbb 10bbbbbb
765
+ $charval = ((ord($string{($offset + 0)}) & 0x0F) << 12) &
766
+ ((ord($string{($offset + 1)}) & 0x3F) << 6) &
767
+ (ord($string{($offset + 2)}) & 0x3F);
768
+ $offset += 3;
769
+ } elseif ((ord($string{$offset}) | 0x1F) == 0xDF) {
770
+ // 110bbbbb 10bbbbbb
771
+ $charval = ((ord($string{($offset + 0)}) & 0x1F) << 6) &
772
+ (ord($string{($offset + 1)}) & 0x3F);
773
+ $offset += 2;
774
+ } elseif ((ord($string{$offset}) | 0x7F) == 0x7F) {
775
+ // 0bbbbbbb
776
+ $charval = ord($string{$offset});
777
+ $offset += 1;
778
+ } else {
779
+ // error? throw some kind of warning here?
780
+ $charval = false;
781
+ $offset += 1;
782
+ }
783
+ if ($charval !== false) {
784
+ $newcharstring .= (($charval < 256) ? chr($charval) : '?');
785
+ }
786
+ }
787
+ return $newcharstring;
788
+ }
789
+
790
+ // UTF-8 => UTF-16BE
791
+ function iconv_fallback_utf8_utf16be($string, $bom=false) {
792
+ $newcharstring = '';
793
+ if ($bom) {
794
+ $newcharstring .= "\xFE\xFF";
795
+ }
796
+ $offset = 0;
797
+ $stringlength = strlen($string);
798
+ while ($offset < $stringlength) {
799
+ if ((ord($string{$offset}) | 0x07) == 0xF7) {
800
+ // 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb
801
+ $charval = ((ord($string{($offset + 0)}) & 0x07) << 18) &
802
+ ((ord($string{($offset + 1)}) & 0x3F) << 12) &
803
+ ((ord($string{($offset + 2)}) & 0x3F) << 6) &
804
+ (ord($string{($offset + 3)}) & 0x3F);
805
+ $offset += 4;
806
+ } elseif ((ord($string{$offset}) | 0x0F) == 0xEF) {
807
+ // 1110bbbb 10bbbbbb 10bbbbbb
808
+ $charval = ((ord($string{($offset + 0)}) & 0x0F) << 12) &
809
+ ((ord($string{($offset + 1)}) & 0x3F) << 6) &
810
+ (ord($string{($offset + 2)}) & 0x3F);
811
+ $offset += 3;
812
+ } elseif ((ord($string{$offset}) | 0x1F) == 0xDF) {
813
+ // 110bbbbb 10bbbbbb
814
+ $charval = ((ord($string{($offset + 0)}) & 0x1F) << 6) &
815
+ (ord($string{($offset + 1)}) & 0x3F);
816
+ $offset += 2;
817
+ } elseif ((ord($string{$offset}) | 0x7F) == 0x7F) {
818
+ // 0bbbbbbb
819
+ $charval = ord($string{$offset});
820
+ $offset += 1;
821
+ } else {
822
+ // error? throw some kind of warning here?
823
+ $charval = false;
824
+ $offset += 1;
825
+ }
826
+ if ($charval !== false) {
827
+ $newcharstring .= (($charval < 65536) ? getid3_lib::BigEndian2String($charval, 2) : "\x00".'?');
828
+ }
829
+ }
830
+ return $newcharstring;
831
+ }
832
+
833
+ // UTF-8 => UTF-16LE
834
+ function iconv_fallback_utf8_utf16le($string, $bom=false) {
835
+ $newcharstring = '';
836
+ if ($bom) {
837
+ $newcharstring .= "\xFF\xFE";
838
+ }
839
+ $offset = 0;
840
+ $stringlength = strlen($string);
841
+ while ($offset < $stringlength) {
842
+ if ((ord($string{$offset}) | 0x07) == 0xF7) {
843
+ // 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb
844
+ $charval = ((ord($string{($offset + 0)}) & 0x07) << 18) &
845
+ ((ord($string{($offset + 1)}) & 0x3F) << 12) &
846
+ ((ord($string{($offset + 2)}) & 0x3F) << 6) &
847
+ (ord($string{($offset + 3)}) & 0x3F);
848
+ $offset += 4;
849
+ } elseif ((ord($string{$offset}) | 0x0F) == 0xEF) {
850
+ // 1110bbbb 10bbbbbb 10bbbbbb
851
+ $charval = ((ord($string{($offset + 0)}) & 0x0F) << 12) &
852
+ ((ord($string{($offset + 1)}) & 0x3F) << 6) &
853
+ (ord($string{($offset + 2)}) & 0x3F);
854
+ $offset += 3;
855
+ } elseif ((ord($string{$offset}) | 0x1F) == 0xDF) {
856
+ // 110bbbbb 10bbbbbb
857
+ $charval = ((ord($string{($offset + 0)}) & 0x1F) << 6) &
858
+ (ord($string{($offset + 1)}) & 0x3F);
859
+ $offset += 2;
860
+ } elseif ((ord($string{$offset}) | 0x7F) == 0x7F) {
861
+ // 0bbbbbbb
862
+ $charval = ord($string{$offset});
863
+ $offset += 1;
864
+ } else {
865
+ // error? maybe throw some warning here?
866
+ $charval = false;
867
+ $offset += 1;
868
+ }
869
+ if ($charval !== false) {
870
+ $newcharstring .= (($charval < 65536) ? getid3_lib::LittleEndian2String($charval, 2) : '?'."\x00");
871
+ }
872
+ }
873
+ return $newcharstring;
874
+ }
875
+
876
+ // UTF-8 => UTF-16LE (BOM)
877
+ function iconv_fallback_utf8_utf16($string) {
878
+ return getid3_lib::iconv_fallback_utf8_utf16le($string, true);
879
+ }
880
+
881
+ // UTF-16BE => UTF-8
882
+ function iconv_fallback_utf16be_utf8($string) {
883
+ if (substr($string, 0, 2) == "\xFE\xFF") {
884
+ // strip BOM
885
+ $string = substr($string, 2);
886
+ }
887
+ $newcharstring = '';
888
+ for ($i = 0; $i < strlen($string); $i += 2) {
889
+ $charval = getid3_lib::BigEndian2Int(substr($string, $i, 2));
890
+ $newcharstring .= getid3_lib::iconv_fallback_int_utf8($charval);
891
+ }
892
+ return $newcharstring;
893
+ }
894
+
895
+ // UTF-16LE => UTF-8
896
+ function iconv_fallback_utf16le_utf8($string) {
897
+ if (substr($string, 0, 2) == "\xFF\xFE") {
898
+ // strip BOM
899
+ $string = substr($string, 2);
900
+ }
901
+ $newcharstring = '';
902
+ for ($i = 0; $i < strlen($string); $i += 2) {
903
+ $charval = getid3_lib::LittleEndian2Int(substr($string, $i, 2));
904
+ $newcharstring .= getid3_lib::iconv_fallback_int_utf8($charval);
905
+ }
906
+ return $newcharstring;
907
+ }
908
+
909
+ // UTF-16BE => ISO-8859-1
910
+ function iconv_fallback_utf16be_iso88591($string) {
911
+ if (substr($string, 0, 2) == "\xFE\xFF") {
912
+ // strip BOM
913
+ $string = substr($string, 2);
914
+ }
915
+ $newcharstring = '';
916
+ for ($i = 0; $i < strlen($string); $i += 2) {
917
+ $charval = getid3_lib::BigEndian2Int(substr($string, $i, 2));
918
+ $newcharstring .= (($charval < 256) ? chr($charval) : '?');
919
+ }
920
+ return $newcharstring;
921
+ }
922
+
923
+ // UTF-16LE => ISO-8859-1
924
+ function iconv_fallback_utf16le_iso88591($string) {
925
+ if (substr($string, 0, 2) == "\xFF\xFE") {
926
+ // strip BOM
927
+ $string = substr($string, 2);
928
+ }
929
+ $newcharstring = '';
930
+ for ($i = 0; $i < strlen($string); $i += 2) {
931
+ $charval = getid3_lib::LittleEndian2Int(substr($string, $i, 2));
932
+ $newcharstring .= (($charval < 256) ? chr($charval) : '?');
933
+ }
934
+ return $newcharstring;
935
+ }
936
+
937
+ // UTF-16 (BOM) => ISO-8859-1
938
+ function iconv_fallback_utf16_iso88591($string) {
939
+ $bom = substr($string, 0, 2);
940
+ if ($bom == "\xFE\xFF") {
941
+ return getid3_lib::iconv_fallback_utf16be_iso88591(substr($string, 2));
942
+ } elseif ($bom == "\xFF\xFE") {
943
+ return getid3_lib::iconv_fallback_utf16le_iso88591(substr($string, 2));
944
+ }
945
+ return $string;
946
+ }
947
+
948
+ // UTF-16 (BOM) => UTF-8
949
+ function iconv_fallback_utf16_utf8($string) {
950
+ $bom = substr($string, 0, 2);
951
+ if ($bom == "\xFE\xFF") {
952
+ return getid3_lib::iconv_fallback_utf16be_utf8(substr($string, 2));
953
+ } elseif ($bom == "\xFF\xFE") {
954
+ return getid3_lib::iconv_fallback_utf16le_utf8(substr($string, 2));
955
+ }
956
+ return $string;
957
+ }
958
+
959
+ function iconv_fallback($in_charset, $out_charset, $string) {
960
+
961
+ if ($in_charset == $out_charset) {
962
+ return $string;
963
+ }
964
+
965
+ // iconv() availble
966
+ if (function_exists('iconv')) {
967
+
968
+ if ($converted_string = @iconv($in_charset, $out_charset.'//TRANSLIT', $string)) {
969
+ switch ($out_charset) {
970
+ case 'ISO-8859-1':
971
+ $converted_string = rtrim($converted_string, "\x00");
972
+ break;
973
+ }
974
+ return $converted_string;
975
+ }
976
+
977
+ // iconv() may sometimes fail with "illegal character in input string" error message
978
+ // and return an empty string, but returning the unconverted string is more useful
979
+ return $string;
980
+ }
981
+
982
+
983
+ // iconv() not available
984
+ static $ConversionFunctionList = array();
985
+ if (empty($ConversionFunctionList)) {
986
+ $ConversionFunctionList['ISO-8859-1']['UTF-8'] = 'iconv_fallback_iso88591_utf8';
987
+ $ConversionFunctionList['ISO-8859-1']['UTF-16'] = 'iconv_fallback_iso88591_utf16';
988
+ $ConversionFunctionList['ISO-8859-1']['UTF-16BE'] = 'iconv_fallback_iso88591_utf16be';
989
+ $ConversionFunctionList['ISO-8859-1']['UTF-16LE'] = 'iconv_fallback_iso88591_utf16le';
990
+ $ConversionFunctionList['UTF-8']['ISO-8859-1'] = 'iconv_fallback_utf8_iso88591';
991
+ $ConversionFunctionList['UTF-8']['UTF-16'] = 'iconv_fallback_utf8_utf16';
992
+ $ConversionFunctionList['UTF-8']['UTF-16BE'] = 'iconv_fallback_utf8_utf16be';
993
+ $ConversionFunctionList['UTF-8']['UTF-16LE'] = 'iconv_fallback_utf8_utf16le';
994
+ $ConversionFunctionList['UTF-16']['ISO-8859-1'] = 'iconv_fallback_utf16_iso88591';
995
+ $ConversionFunctionList['UTF-16']['UTF-8'] = 'iconv_fallback_utf16_utf8';
996
+ $ConversionFunctionList['UTF-16LE']['ISO-8859-1'] = 'iconv_fallback_utf16le_iso88591';
997
+ $ConversionFunctionList['UTF-16LE']['UTF-8'] = 'iconv_fallback_utf16le_utf8';
998
+ $ConversionFunctionList['UTF-16BE']['ISO-8859-1'] = 'iconv_fallback_utf16be_iso88591';
999
+ $ConversionFunctionList['UTF-16BE']['UTF-8'] = 'iconv_fallback_utf16be_utf8';
1000
+ }
1001
+ if (isset($ConversionFunctionList[strtoupper($in_charset)][strtoupper($out_charset)])) {
1002
+ $ConversionFunction = $ConversionFunctionList[strtoupper($in_charset)][strtoupper($out_charset)];
1003
+ return getid3_lib::$ConversionFunction($string);
1004
+ }
1005
+ die('PHP does not have iconv() support - cannot convert from '.$in_charset.' to '.$out_charset);
1006
+ }
1007
+
1008
+
1009
+ function MultiByteCharString2HTML($string, $charset='ISO-8859-1') {
1010
+ $HTMLstring = '';
1011
+
1012
+ switch ($charset) {
1013
+ case 'ISO-8859-1':
1014
+ case 'ISO8859-1':
1015
+ case 'ISO-8859-15':
1016
+ case 'ISO8859-15':
1017
+ case 'cp866':
1018
+ case 'ibm866':
1019
+ case '866':
1020
+ case 'cp1251':
1021
+ case 'Windows-1251':
1022
+ case 'win-1251':
1023
+ case '1251':
1024
+ case 'cp1252':
1025
+ case 'Windows-1252':
1026
+ case '1252':
1027
+ case 'KOI8-R':
1028
+ case 'koi8-ru':
1029
+ case 'koi8r':
1030
+ case 'BIG5':
1031
+ case '950':
1032
+ case 'GB2312':
1033
+ case '936':
1034
+ case 'BIG5-HKSCS':
1035
+ case 'Shift_JIS':
1036
+ case 'SJIS':
1037
+ case '932':
1038
+ case 'EUC-JP':
1039
+ case 'EUCJP':
1040
+ $HTMLstring = htmlentities($string, ENT_COMPAT, $charset);
1041
+ break;
1042
+
1043
+ case 'UTF-8':
1044
+ $strlen = strlen($string);
1045
+ for ($i = 0; $i < $strlen; $i++) {
1046
+ $char_ord_val = ord($string{$i});
1047
+ $charval = 0;
1048
+ if ($char_ord_val < 0x80) {
1049
+ $charval = $char_ord_val;
1050
+ } elseif ((($char_ord_val & 0xF0) >> 4) == 0x0F && $i+3 < $strlen) {
1051
+ $charval = (($char_ord_val & 0x07) << 18);
1052
+ $charval += ((ord($string{++$i}) & 0x3F) << 12);
1053
+ $charval += ((ord($string{++$i}) & 0x3F) << 6);
1054
+ $charval += (ord($string{++$i}) & 0x3F);
1055
+ } elseif ((($char_ord_val & 0xE0) >> 5) == 0x07 && $i+2 < $strlen) {
1056
+ $charval = (($char_ord_val & 0x0F) << 12);
1057
+ $charval += ((ord($string{++$i}) & 0x3F) << 6);
1058
+ $charval += (ord($string{++$i}) & 0x3F);
1059
+ } elseif ((($char_ord_val & 0xC0) >> 6) == 0x03 && $i+1 < $strlen) {
1060
+ $charval = (($char_ord_val & 0x1F) << 6);
1061
+ $charval += (ord($string{++$i}) & 0x3F);
1062
+ }
1063
+ if (($charval >= 32) && ($charval <= 127)) {
1064
+ $HTMLstring .= htmlentities(chr($charval));
1065
+ } else {
1066
+ $HTMLstring .= '&#'.$charval.';';
1067
+ }
1068
+ }
1069
+ break;
1070
+
1071
+ case 'UTF-16LE':
1072
+ for ($i = 0; $i < strlen($string); $i += 2) {
1073
+ $charval = getid3_lib::LittleEndian2Int(substr($string, $i, 2));
1074
+ if (($charval >= 32) && ($charval <= 127)) {
1075
+ $HTMLstring .= chr($charval);
1076
+ } else {
1077
+ $HTMLstring .= '&#'.$charval.';';
1078
+ }
1079
+ }
1080
+ break;
1081
+
1082
+ case 'UTF-16BE':
1083
+ for ($i = 0; $i < strlen($string); $i += 2) {
1084
+ $charval = getid3_lib::BigEndian2Int(substr($string, $i, 2));
1085
+ if (($charval >= 32) && ($charval <= 127)) {
1086
+ $HTMLstring .= chr($charval);
1087
+ } else {
1088
+ $HTMLstring .= '&#'.$charval.';';
1089
+ }
1090
+ }
1091
+ break;
1092
+
1093
+ default:
1094
+ $HTMLstring = 'ERROR: Character set "'.$charset.'" not supported in MultiByteCharString2HTML()';
1095
+ break;
1096
+ }
1097
+ return $HTMLstring;
1098
+ }
1099
+
1100
+
1101
+
1102
+ function RGADnameLookup($namecode) {
1103
+ static $RGADname = array();
1104
+ if (empty($RGADname)) {
1105
+ $RGADname[0] = 'not set';
1106
+ $RGADname[1] = 'Track Gain Adjustment';
1107
+ $RGADname[2] = 'Album Gain Adjustment';
1108
+ }
1109
+
1110
+ return (isset($RGADname[$namecode]) ? $RGADname[$namecode] : '');
1111
+ }
1112
+
1113
+
1114
+ function RGADoriginatorLookup($originatorcode) {
1115
+ static $RGADoriginator = array();
1116
+ if (empty($RGADoriginator)) {
1117
+ $RGADoriginator[0] = 'unspecified';
1118
+ $RGADoriginator[1] = 'pre-set by artist/producer/mastering engineer';
1119
+ $RGADoriginator[2] = 'set by user';
1120
+ $RGADoriginator[3] = 'determined automatically';
1121
+ }
1122
+
1123
+ return (isset($RGADoriginator[$originatorcode]) ? $RGADoriginator[$originatorcode] : '');
1124
+ }
1125
+
1126
+
1127
+ function RGADadjustmentLookup($rawadjustment, $signbit) {
1128
+ $adjustment = $rawadjustment / 10;
1129
+ if ($signbit == 1) {
1130
+ $adjustment *= -1;
1131
+ }
1132
+ return (float) $adjustment;
1133
+ }
1134
+
1135
+
1136
+ function RGADgainString($namecode, $originatorcode, $replaygain) {
1137
+ if ($replaygain < 0) {
1138
+ $signbit = '1';
1139
+ } else {
1140
+ $signbit = '0';
1141
+ }
1142
+ $storedreplaygain = intval(round($replaygain * 10));
1143
+ $gainstring = str_pad(decbin($namecode), 3, '0', STR_PAD_LEFT);
1144
+ $gainstring .= str_pad(decbin($originatorcode), 3, '0', STR_PAD_LEFT);
1145
+ $gainstring .= $signbit;
1146
+ $gainstring .= str_pad(decbin($storedreplaygain), 9, '0', STR_PAD_LEFT);
1147
+
1148
+ return $gainstring;
1149
+ }
1150
+
1151
+ function RGADamplitude2dB($amplitude) {
1152
+ return 20 * log10($amplitude);
1153
+ }
1154
+
1155
+
1156
+ function GetDataImageSize($imgData, &$imageinfo) {
1157
+ $GetDataImageSize = false;
1158
+ if ($tempfilename = tempnam('*', 'getID3')) {
1159
+ if ($tmp = @fopen($tempfilename, 'wb')) {
1160
+ fwrite($tmp, $imgData);
1161
+ fclose($tmp);
1162
+ $GetDataImageSize = @GetImageSize($tempfilename, $imageinfo);
1163
+ }
1164
+ unlink($tempfilename);
1165
+ }
1166
+ return $GetDataImageSize;
1167
+ }
1168
+
1169
+ function ImageTypesLookup($imagetypeid) {
1170
+ static $ImageTypesLookup = array();
1171
+ if (empty($ImageTypesLookup)) {
1172
+ $ImageTypesLookup[1] = 'gif';
1173
+ $ImageTypesLookup[2] = 'jpeg';
1174
+ $ImageTypesLookup[3] = 'png';
1175
+ $ImageTypesLookup[4] = 'swf';
1176
+ $ImageTypesLookup[5] = 'psd';
1177
+ $ImageTypesLookup[6] = 'bmp';
1178
+ $ImageTypesLookup[7] = 'tiff (little-endian)';
1179
+ $ImageTypesLookup[8] = 'tiff (big-endian)';
1180
+ $ImageTypesLookup[9] = 'jpc';
1181
+ $ImageTypesLookup[10] = 'jp2';
1182
+ $ImageTypesLookup[11] = 'jpx';
1183
+ $ImageTypesLookup[12] = 'jb2';
1184
+ $ImageTypesLookup[13] = 'swc';
1185
+ $ImageTypesLookup[14] = 'iff';
1186
+ }
1187
+ return (isset($ImageTypesLookup[$imagetypeid]) ? $ImageTypesLookup[$imagetypeid] : '');
1188
+ }
1189
+
1190
+ function CopyTagsToComments(&$ThisFileInfo) {
1191
+
1192
+ // Copy all entries from ['tags'] into common ['comments']
1193
+ if (!empty($ThisFileInfo['tags'])) {
1194
+ foreach ($ThisFileInfo['tags'] as $tagtype => $tagarray) {
1195
+ foreach ($tagarray as $tagname => $tagdata) {
1196
+ foreach ($tagdata as $key => $value) {
1197
+ if (!empty($value)) {
1198
+ if (empty($ThisFileInfo['comments'][$tagname])) {
1199
+
1200
+ // fall through and append value
1201
+
1202
+ } elseif ($tagtype == 'id3v1') {
1203
+
1204
+ $newvaluelength = strlen(trim($value));
1205
+ foreach ($ThisFileInfo['comments'][$tagname] as $existingkey => $existingvalue) {
1206
+ $oldvaluelength = strlen(trim($existingvalue));
1207
+ if (($newvaluelength <= $oldvaluelength) && (substr($existingvalue, 0, $newvaluelength) == trim($value))) {
1208
+ // new value is identical but shorter-than (or equal-length to) one already in comments - skip
1209
+ break 2;
1210
+ }
1211
+ }
1212
+
1213
+ } else {
1214
+
1215
+ $newvaluelength = strlen(trim($value));
1216
+ foreach ($ThisFileInfo['comments'][$tagname] as $existingkey => $existingvalue) {
1217
+ $oldvaluelength = strlen(trim($existingvalue));
1218
+ if (($newvaluelength > $oldvaluelength) && (substr(trim($value), 0, strlen($existingvalue)) == $existingvalue)) {
1219
+ $ThisFileInfo['comments'][$tagname][$existingkey] = trim($value);
1220
+ break 2;
1221
+ }
1222
+ }
1223
+
1224
+ }
1225
+ if (empty($ThisFileInfo['comments'][$tagname]) || !in_array(trim($value), $ThisFileInfo['comments'][$tagname])) {
1226
+ $ThisFileInfo['comments'][$tagname][] = trim($value);
1227
+ }
1228
+ }
1229
+ }
1230
+ }
1231
+ }
1232
+
1233
+ // Copy to ['comments_html']
1234
+ foreach ($ThisFileInfo['comments'] as $field => $values) {
1235
+ foreach ($values as $index => $value) {
1236
+ $ThisFileInfo['comments_html'][$field][$index] = str_replace('&#0;', '', getid3_lib::MultiByteCharString2HTML($value, $ThisFileInfo['encoding']));
1237
+ }
1238
+ }
1239
+ }
1240
+ }
1241
+
1242
+
1243
+ function EmbeddedLookup($key, $begin, $end, $file, $name) {
1244
+
1245
+ // Cached
1246
+ static $cache;
1247
+ if (isset($cache[$file][$name])) {
1248
+ return @$cache[$file][$name][$key];
1249
+ }
1250
+
1251
+ // Init
1252
+ $keylength = strlen($key);
1253
+ $line_count = $end - $begin - 7;
1254
+
1255
+ // Open php file
1256
+ $fp = fopen($file, 'r');
1257
+
1258
+ // Discard $begin lines
1259
+ for ($i = 0; $i < ($begin + 3); $i++) {
1260
+ fgets($fp, 1024);
1261
+ }
1262
+
1263
+ // Loop thru line
1264
+ while (0 < $line_count--) {
1265
+
1266
+ // Read line
1267
+ $line = ltrim(fgets($fp, 1024), "\t ");
1268
+
1269
+ // METHOD A: only cache the matching key - less memory but slower on next lookup of not-previously-looked-up key
1270
+ //$keycheck = substr($line, 0, $keylength);
1271
+ //if ($key == $keycheck) {
1272
+ // $cache[$file][$name][$keycheck] = substr($line, $keylength + 1);
1273
+ // break;
1274
+ //}
1275
+
1276
+ // METHOD B: cache all keys in this lookup - more memory but faster on next lookup of not-previously-looked-up key
1277
+ //$cache[$file][$name][substr($line, 0, $keylength)] = trim(substr($line, $keylength + 1));
1278
+ @list($ThisKey, $ThisValue) = explode("\t", $line, 2);
1279
+ $cache[$file][$name][$ThisKey] = trim($ThisValue);
1280
+ }
1281
+
1282
+ // Close and return
1283
+ fclose($fp);
1284
+ return @$cache[$file][$name][$key];
1285
+ }
1286
+
1287
+ function IncludeDependency($filename, $sourcefile, $DieOnFailure=false) {
1288
+ global $GETID3_ERRORARRAY;
1289
+
1290
+ if (file_exists($filename)) {
1291
+ if (@include_once($filename)) {
1292
+ return true;
1293
+ } else {
1294
+ $diemessage = basename($sourcefile).' depends on '.$filename.', which has errors';
1295
+ }
1296
+ } else {
1297
+ $diemessage = basename($sourcefile).' depends on '.$filename.', which is missing';
1298
+ }
1299
+ if ($DieOnFailure) {
1300
+ die($diemessage);
1301
+ } else {
1302
+ $GETID3_ERRORARRAY[] = $diemessage;
1303
+ }
1304
+ return false;
1305
+ }
1306
+
1307
+ }
1308
+
1309
+ ?>
view/getid3/getid3.php ADDED
@@ -0,0 +1,1397 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /////////////////////////////////////////////////////////////////
3
+ /// getID3() by James Heinrich <info@getid3.org> //
4
+ // available at http://getid3.sourceforge.net //
5
+ // or http://www.getid3.org //
6
+ /////////////////////////////////////////////////////////////////
7
+ // //
8
+ // Please see readme.txt for more information //
9
+ // ///
10
+ /////////////////////////////////////////////////////////////////
11
+
12
+ // Defines
13
+ define('GETID3_VERSION', '1.7.9-20090308');
14
+ define('GETID3_FREAD_BUFFER_SIZE', 16384); // read buffer size in bytes
15
+
16
+
17
+
18
+ class getID3
19
+ {
20
+ // public: Settings
21
+ var $encoding = 'ISO-8859-1'; // CASE SENSITIVE! - i.e. (must be supported by iconv())
22
+ // Examples: ISO-8859-1 UTF-8 UTF-16 UTF-16BE
23
+
24
+ var $encoding_id3v1 = 'ISO-8859-1'; // Should always be 'ISO-8859-1', but some tags may be written in other encodings such as 'EUC-CN'
25
+
26
+ var $tempdir = '*'; // default '*' should use system temp dir
27
+
28
+ // public: Optional tag checks - disable for speed.
29
+ var $option_tag_id3v1 = true; // Read and process ID3v1 tags
30
+ var $option_tag_id3v2 = true; // Read and process ID3v2 tags
31
+ var $option_tag_lyrics3 = true; // Read and process Lyrics3 tags
32
+ var $option_tag_apetag = true; // Read and process APE tags
33
+ var $option_tags_process = true; // Copy tags to root key 'tags' and encode to $this->encoding
34
+ var $option_tags_html = true; // Copy tags to root key 'tags_html' properly translated from various encodings to HTML entities
35
+
36
+ // public: Optional tag/comment calucations
37
+ var $option_extra_info = true; // Calculate additional info such as bitrate, channelmode etc
38
+
39
+ // public: Optional calculations
40
+ var $option_md5_data = false; // Get MD5 sum of data part - slow
41
+ var $option_md5_data_source = false; // Use MD5 of source file if availble - only FLAC and OptimFROG
42
+ var $option_sha1_data = false; // Get SHA1 sum of data part - slow
43
+ var $option_max_2gb_check = true; // Check whether file is larger than 2 Gb and thus not supported by PHP
44
+
45
+ // private
46
+ var $filename;
47
+
48
+
49
+ // public: constructor
50
+ function getID3()
51
+ {
52
+
53
+ $this->startup_error = '';
54
+ $this->startup_warning = '';
55
+
56
+ // Check for PHP version >= 4.2.0
57
+ if (phpversion() < '4.2.0') {
58
+ $this->startup_error .= 'getID3() requires PHP v4.2.0 or higher - you are running v'.phpversion();
59
+ }
60
+
61
+ // Check memory
62
+ $memory_limit = ini_get('memory_limit');
63
+ if (eregi('([0-9]+)M', $memory_limit, $matches)) {
64
+ // could be stored as "16M" rather than 16777216 for example
65
+ $memory_limit = $matches[1] * 1048576;
66
+ }
67
+ if ($memory_limit <= 0) {
68
+ // memory limits probably disabled
69
+ } elseif ($memory_limit <= 3145728) {
70
+ $this->startup_error .= 'PHP has less than 3MB available memory and will very likely run out. Increase memory_limit in php.ini';
71
+ } elseif ($memory_limit <= 12582912) {
72
+ $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';
73
+ }
74
+
75
+ // Check safe_mode off
76
+ if ((bool) ini_get('safe_mode')) {
77
+ $this->warning('WARNING: Safe mode is on, shorten support disabled, md5data/sha1data for ogg vorbis disabled, ogg vorbos/flac tag writing disabled.');
78
+ }
79
+
80
+
81
+ // define a constant rather than looking up every time it is needed
82
+ if (!defined('GETID3_OS_ISWINDOWS')) {
83
+ if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
84
+ define('GETID3_OS_ISWINDOWS', true);
85
+ } else {
86
+ define('GETID3_OS_ISWINDOWS', false);
87
+ }
88
+ }
89
+
90
+ // Get base path of getID3() - ONCE
91
+ if (!defined('GETID3_INCLUDEPATH')) {
92
+ foreach (get_included_files() as $key => $val) {
93
+ if (basename($val) == 'getid3.php') {
94
+ define('GETID3_INCLUDEPATH', dirname($val).DIRECTORY_SEPARATOR);
95
+ break;
96
+ }
97
+ }
98
+ }
99
+
100
+ // Load support library
101
+ if (!include_once(GETID3_INCLUDEPATH.'getid3.lib.php')) {
102
+ $this->startup_error .= 'getid3.lib.php is missing or corrupt';
103
+ }
104
+
105
+
106
+ // Needed for Windows only:
107
+ // Define locations of helper applications for Shorten, VorbisComment, MetaFLAC
108
+ // as well as other helper functions such as head, tail, md5sum, etc
109
+ // IMPORTANT: This path cannot have spaces in it. If neccesary, use the 8dot3 equivalent
110
+ // ie for "C:/Program Files/Apache/" put "C:/PROGRA~1/APACHE/"
111
+ // IMPORTANT: This path must include the trailing slash
112
+ if (GETID3_OS_ISWINDOWS && !defined('GETID3_HELPERAPPSDIR')) {
113
+
114
+ $helperappsdir = GETID3_INCLUDEPATH.'..'.DIRECTORY_SEPARATOR.'helperapps'; // must not have any space in this path
115
+
116
+ if (!is_dir($helperappsdir)) {
117
+ $this->startup_error .= '"'.$helperappsdir.'" cannot be defined as GETID3_HELPERAPPSDIR because it does not exist';
118
+ } elseif (strpos(realpath($helperappsdir), ' ') !== false) {
119
+ $DirPieces = explode(DIRECTORY_SEPARATOR, realpath($helperappsdir));
120
+ foreach ($DirPieces as $key => $value) {
121
+ if ((strpos($value, '.') !== false) && (strpos($value, ' ') === false)) {
122
+ if (strpos($value, '.') > 8) {
123
+ $value = substr($value, 0, 6).'~1';
124
+ }
125
+ } elseif ((strpos($value, ' ') !== false) || strlen($value) > 8) {
126
+ $value = substr($value, 0, 6).'~1';
127
+ }
128
+ $DirPieces[$key] = strtoupper($value);
129
+ }
130
+ $this->startup_error .= 'GETID3_HELPERAPPSDIR must not have any spaces in it - use 8dot3 naming convention if neccesary (on this server that would be something like "'.implode(DIRECTORY_SEPARATOR, $DirPieces).'" - NOTE: this may or may not be the actual 8.3 equivalent of "'.$helperappsdir.'", please double-check). You can run "dir /x" from the commandline to see the correct 8.3-style names.';
131
+ }
132
+ define('GETID3_HELPERAPPSDIR', realpath($helperappsdir).DIRECTORY_SEPARATOR);
133
+ }
134
+
135
+ }
136
+
137
+
138
+ // public: setOption
139
+ function setOption($optArray) {
140
+ if (!is_array($optArray) || empty($optArray)) {
141
+ return false;
142
+ }
143
+ foreach ($optArray as $opt => $val) {
144
+ //if (isset($this, $opt) === false) {
145
+ if (isset($this->$opt) === false) {
146
+ continue;
147
+ }
148
+ $this->$opt = $val;
149
+ }
150
+ return true;
151
+ }
152
+
153
+
154
+ // public: analyze file - replaces GetAllFileInfo() and GetTagOnly()
155
+ function analyze($filename) {
156
+
157
+ if (!empty($this->startup_error)) {
158
+ return $this->error($this->startup_error);
159
+ }
160
+ if (!empty($this->startup_warning)) {
161
+ $this->warning($this->startup_warning);
162
+ }
163
+
164
+ // init result array and set parameters
165
+ $this->info = array();
166
+ $this->info['GETID3_VERSION'] = GETID3_VERSION;
167
+
168
+ // Check encoding/iconv support
169
+ if (!function_exists('iconv') && !in_array($this->encoding, array('ISO-8859-1', 'UTF-8', 'UTF-16LE', 'UTF-16BE', 'UTF-16'))) {
170
+ $errormessage = 'iconv() support is needed for encodings other than ISO-8859-1, UTF-8, UTF-16LE, UTF16-BE, UTF-16. ';
171
+ if (GETID3_OS_ISWINDOWS) {
172
+ $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';
173
+ } else {
174
+ $errormessage .= 'PHP is not compiled with iconv() support. Please recompile with the --with-iconv switch';
175
+ }
176
+ return $this->error($errormessage);
177
+ }
178
+
179
+ // Disable magic_quotes_runtime, if neccesary
180
+ $old_magic_quotes_runtime = get_magic_quotes_runtime(); // store current setting of magic_quotes_runtime
181
+ if ($old_magic_quotes_runtime) {
182
+ set_magic_quotes_runtime(0); // turn off magic_quotes_runtime
183
+ if (get_magic_quotes_runtime()) {
184
+ return $this->error('Could not disable magic_quotes_runtime - getID3() cannot work properly with this setting enabled');
185
+ }
186
+ }
187
+
188
+ // remote files not supported
189
+ if (preg_match('/^(ht|f)tp:\/\//', $filename)) {
190
+ return $this->error('Remote files are not supported in this version of getID3() - please copy the file locally first');
191
+ }
192
+
193
+ $filename = str_replace('/', DIRECTORY_SEPARATOR, $filename);
194
+ $filename = preg_replace('#'.preg_quote(DIRECTORY_SEPARATOR).'{2,}#', DIRECTORY_SEPARATOR, $filename);
195
+
196
+ // open local file
197
+ if (file_exists($filename) && ($fp = @fopen($filename, 'rb'))) {
198
+ // great
199
+ } else {
200
+ return $this->error('Could not open file "'.$filename.'"');
201
+ }
202
+
203
+ // set parameters
204
+ $this->info['filesize'] = filesize($filename);
205
+
206
+ // option_max_2gb_check
207
+ if ($this->option_max_2gb_check) {
208
+ // PHP doesn't support integers larger than 31-bit (~2GB)
209
+ // filesize() simply returns (filesize % (pow(2, 32)), no matter the actual filesize
210
+ // ftell() returns 0 if seeking to the end is beyond the range of unsigned integer
211
+ fseek($fp, 0, SEEK_END);
212
+ if ((($this->info['filesize'] != 0) && (ftell($fp) == 0)) ||
213
+ ($this->info['filesize'] < 0) ||
214
+ (ftell($fp) < 0)) {
215
+ $real_filesize = false;
216
+ if (GETID3_OS_ISWINDOWS) {
217
+ $commandline = 'dir /-C "'.str_replace('/', DIRECTORY_SEPARATOR, $filename).'"';
218
+ $dir_output = `$commandline`;
219
+ if (eregi('1 File\(s\)[ ]+([0-9]+) bytes', $dir_output, $matches)) {
220
+ $real_filesize = (float) $matches[1];
221
+ }
222
+ } else {
223
+ $commandline = 'ls -o -g -G --time-style=long-iso '.escapeshellarg($filename);
224
+ $dir_output = `$commandline`;
225
+ if (eregi('([0-9]+) ([0-9]{4}-[0-9]{2}\-[0-9]{2} [0-9]{2}:[0-9]{2}) '.preg_quote($filename).'$', $dir_output, $matches)) {
226
+ $real_filesize = (float) $matches[1];
227
+ }
228
+ }
229
+ if ($real_filesize === false) {
230
+ unset($this->info['filesize']);
231
+ fclose($fp);
232
+ return $this->error('File is most likely larger than 2GB and is not supported by PHP');
233
+ } elseif ($real_filesize < pow(2, 31)) {
234
+ unset($this->info['filesize']);
235
+ fclose($fp);
236
+ return $this->error('PHP seems to think the file is larger than 2GB, but filesystem reports it as '.number_format($real_filesize, 3).'GB, please report to info@getid3.org');
237
+ }
238
+ $this->info['filesize'] = $real_filesize;
239
+ $this->error('File is larger than 2GB (filesystem reports it as '.number_format($real_filesize, 3).'GB) and is not properly supported by PHP.');
240
+ }
241
+ }
242
+
243
+ // set more parameters
244
+ $this->info['avdataoffset'] = 0;
245
+ $this->info['avdataend'] = $this->info['filesize'];
246
+ $this->info['fileformat'] = ''; // filled in later
247
+ $this->info['audio']['dataformat'] = ''; // filled in later, unset if not used
248
+ $this->info['video']['dataformat'] = ''; // filled in later, unset if not used
249
+ $this->info['tags'] = array(); // filled in later, unset if not used
250
+ $this->info['error'] = array(); // filled in later, unset if not used
251
+ $this->info['warning'] = array(); // filled in later, unset if not used
252
+ $this->info['comments'] = array(); // filled in later, unset if not used
253
+ $this->info['encoding'] = $this->encoding; // required by id3v2 and iso modules - can be unset at the end if desired
254
+
255
+ // set redundant parameters - might be needed in some include file
256
+ $this->info['filename'] = basename($filename);
257
+ $this->info['filepath'] = str_replace('\\', '/', realpath(dirname($filename)));
258
+ $this->info['filenamepath'] = $this->info['filepath'].'/'.$this->info['filename'];
259
+
260
+
261
+ // handle ID3v2 tag - done first - already at beginning of file
262
+ // ID3v2 detection (even if not parsing) is always done otherwise fileformat is much harder to detect
263
+ if ($this->option_tag_id3v2) {
264
+
265
+ $GETID3_ERRORARRAY = &$this->info['warning'];
266
+ if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, false)) {
267
+ $tag = new getid3_id3v2($fp, $this->info);
268
+ unset($tag);
269
+ }
270
+
271
+ } else {
272
+
273
+ fseek($fp, 0, SEEK_SET);
274
+ $header = fread($fp, 10);
275
+ if (substr($header, 0, 3) == 'ID3' && strlen($header) == 10) {
276
+ $this->info['id3v2']['header'] = true;
277
+ $this->info['id3v2']['majorversion'] = ord($header{3});
278
+ $this->info['id3v2']['minorversion'] = ord($header{4});
279
+ $this->info['id3v2']['headerlength'] = getid3_lib::BigEndian2Int(substr($header, 6, 4), 1) + 10; // length of ID3v2 tag in 10-byte header doesn't include 10-byte header length
280
+
281
+ $this->info['id3v2']['tag_offset_start'] = 0;
282
+ $this->info['id3v2']['tag_offset_end'] = $this->info['id3v2']['tag_offset_start'] + $this->info['id3v2']['headerlength'];
283
+ $this->info['avdataoffset'] = $this->info['id3v2']['tag_offset_end'];
284
+ }
285
+
286
+ }
287
+
288
+
289
+ // handle ID3v1 tag
290
+ if ($this->option_tag_id3v1) {
291
+ if (!@include_once(GETID3_INCLUDEPATH.'module.tag.id3v1.php')) {
292
+ return $this->error('module.tag.id3v1.php is missing - you may disable option_tag_id3v1.');
293
+ }
294
+ $tag = new getid3_id3v1($fp, $this->info);
295
+ unset($tag);
296
+ }
297
+
298
+ // handle APE tag
299
+ if ($this->option_tag_apetag) {
300
+ if (!@include_once(GETID3_INCLUDEPATH.'module.tag.apetag.php')) {
301
+ return $this->error('module.tag.apetag.php is missing - you may disable option_tag_apetag.');
302
+ }
303
+ $tag = new getid3_apetag($fp, $this->info);
304
+ unset($tag);
305
+ }
306
+
307
+ // handle lyrics3 tag
308
+ if ($this->option_tag_lyrics3) {
309
+ if (!@include_once(GETID3_INCLUDEPATH.'module.tag.lyrics3.php')) {
310
+ return $this->error('module.tag.lyrics3.php is missing - you may disable option_tag_lyrics3.');
311
+ }
312
+ $tag = new getid3_lyrics3($fp, $this->info);
313
+ unset($tag);
314
+ }
315
+
316
+ // read 32 kb file data
317
+ fseek($fp, $this->info['avdataoffset'], SEEK_SET);
318
+ $formattest = fread($fp, 32774);
319
+
320
+ // determine format
321
+ $determined_format = $this->GetFileFormat($formattest, $filename);
322
+
323
+ // unable to determine file format
324
+ if (!$determined_format) {
325
+ fclose($fp);
326
+ return $this->error('unable to determine file format');
327
+ }
328
+
329
+ // check for illegal ID3 tags
330
+ if (isset($determined_format['fail_id3']) && (in_array('id3v1', $this->info['tags']) || in_array('id3v2', $this->info['tags']))) {
331
+ if ($determined_format['fail_id3'] === 'ERROR') {
332
+ fclose($fp);
333
+ return $this->error('ID3 tags not allowed on this file type.');
334
+ } elseif ($determined_format['fail_id3'] === 'WARNING') {
335
+ $this->info['warning'][] = 'ID3 tags not allowed on this file type.';
336
+ }
337
+ }
338
+
339
+ // check for illegal APE tags
340
+ if (isset($determined_format['fail_ape']) && in_array('ape', $this->info['tags'])) {
341
+ if ($determined_format['fail_ape'] === 'ERROR') {
342
+ fclose($fp);
343
+ return $this->error('APE tags not allowed on this file type.');
344
+ } elseif ($determined_format['fail_ape'] === 'WARNING') {
345
+ $this->info['warning'][] = 'APE tags not allowed on this file type.';
346
+ }
347
+ }
348
+
349
+ // set mime type
350
+ $this->info['mime_type'] = $determined_format['mime_type'];
351
+
352
+ // supported format signature pattern detected, but module deleted
353
+ if (!file_exists(GETID3_INCLUDEPATH.$determined_format['include'])) {
354
+ fclose($fp);
355
+ return $this->error('Format not supported, module "'.$determined_format['include'].'" was removed.');
356
+ }
357
+
358
+ // module requires iconv support
359
+ if (!function_exists('iconv') && @$determined_format['iconv_req']) {
360
+ return $this->error('iconv support is required for this module ('.$determined_format['include'].').');
361
+ }
362
+
363
+ // include module
364
+ include_once(GETID3_INCLUDEPATH.$determined_format['include']);
365
+
366
+ // instantiate module class
367
+ $class_name = 'getid3_'.$determined_format['module'];
368
+ if (!class_exists($class_name)) {
369
+ return $this->error('Format not supported, module "'.$determined_format['include'].'" is corrupt.');
370
+ }
371
+ if (isset($determined_format['option'])) {
372
+ $class = new $class_name($fp, $this->info, $determined_format['option']);
373
+ } else {
374
+ $class = new $class_name($fp, $this->info);
375
+ }
376
+ unset($class);
377
+
378
+ // close file
379
+ fclose($fp);
380
+
381
+ // process all tags - copy to 'tags' and convert charsets
382
+ if ($this->option_tags_process) {
383
+ $this->HandleAllTags();
384
+ }
385
+
386
+ // perform more calculations
387
+ if ($this->option_extra_info) {
388
+ $this->ChannelsBitratePlaytimeCalculations();
389
+ $this->CalculateCompressionRatioVideo();
390
+ $this->CalculateCompressionRatioAudio();
391
+ $this->CalculateReplayGain();
392
+ $this->ProcessAudioStreams();
393
+ }
394
+
395
+ // get the MD5 sum of the audio/video portion of the file - without ID3/APE/Lyrics3/etc header/footer tags
396
+ if ($this->option_md5_data) {
397
+ // do not cald md5_data if md5_data_source is present - set by flac only - future MPC/SV8 too
398
+ if (!$this->option_md5_data_source || empty($this->info['md5_data_source'])) {
399
+ $this->getHashdata('md5');
400
+ }
401
+ }
402
+
403
+ // get the SHA1 sum of the audio/video portion of the file - without ID3/APE/Lyrics3/etc header/footer tags
404
+ if ($this->option_sha1_data) {
405
+ $this->getHashdata('sha1');
406
+ }
407
+
408
+ // remove undesired keys
409
+ $this->CleanUp();
410
+
411
+ // restore magic_quotes_runtime setting
412
+ set_magic_quotes_runtime($old_magic_quotes_runtime);
413
+
414
+ // return info array
415
+ return $this->info;
416
+ }
417
+
418
+
419
+ // private: error handling
420
+ function error($message) {
421
+
422
+ $this->CleanUp();
423
+
424
+ $this->info['error'][] = $message;
425
+ return $this->info;
426
+ }
427
+
428
+
429
+ // private: warning handling
430
+ function warning($message) {
431
+ $this->info['warning'][] = $message;
432
+ return true;
433
+ }
434
+
435
+
436
+ // private: CleanUp
437
+ function CleanUp() {
438
+
439
+ // remove possible empty keys
440
+ $AVpossibleEmptyKeys = array('dataformat', 'bits_per_sample', 'encoder_options', 'streams', 'bitrate');
441
+ foreach ($AVpossibleEmptyKeys as $dummy => $key) {
442
+ if (empty($this->info['audio'][$key]) && isset($this->info['audio'][$key])) {
443
+ unset($this->info['audio'][$key]);
444
+ }
445
+ if (empty($this->info['video'][$key]) && isset($this->info['video'][$key])) {
446
+ unset($this->info['video'][$key]);
447
+ }
448
+ }
449
+
450
+ // remove empty root keys
451
+ if (!empty($this->info)) {
452
+ foreach ($this->info as $key => $value) {
453
+ if (empty($this->info[$key]) && ($this->info[$key] !== 0) && ($this->info[$key] !== '0')) {
454
+ unset($this->info[$key]);
455
+ }
456
+ }
457
+ }
458
+
459
+ // remove meaningless entries from unknown-format files
460
+ if (empty($this->info['fileformat'])) {
461
+ if (isset($this->info['avdataoffset'])) {
462
+ unset($this->info['avdataoffset']);
463
+ }
464
+ if (isset($this->info['avdataend'])) {
465
+ unset($this->info['avdataend']);
466
+ }
467
+ }
468
+ }
469
+
470
+
471
+ // return array containing information about all supported formats
472
+ function GetFileFormatArray() {
473
+ static $format_info = array();
474
+ if (empty($format_info)) {
475
+ $format_info = array(
476
+
477
+ // Audio formats
478
+
479
+ // AC-3 - audio - Dolby AC-3 / Dolby Digital
480
+ 'ac3' => array(
481
+ 'pattern' => '^\x0B\x77',
482
+ 'group' => 'audio',
483
+ 'module' => 'ac3',
484
+ 'mime_type' => 'audio/ac3',
485
+ ),
486
+
487
+ // AAC - audio - Advanced Audio Coding (AAC) - ADIF format
488
+ 'adif' => array(
489
+ 'pattern' => '^ADIF',
490
+ 'group' => 'audio',
491
+ 'module' => 'aac',
492
+ 'option' => 'adif',
493
+ 'mime_type' => 'application/octet-stream',
494
+ 'fail_ape' => 'WARNING',
495
+ ),
496
+
497
+
498
+ // AAC - audio - Advanced Audio Coding (AAC) - ADTS format (very similar to MP3)
499
+ 'adts' => array(
500
+ 'pattern' => '^\xFF[\xF0-\xF1\xF8-\xF9]',
501
+ 'group' => 'audio',
502
+ 'module' => 'aac',
503
+ 'option' => 'adts',
504
+ 'mime_type' => 'application/octet-stream',
505
+ 'fail_ape' => 'WARNING',
506
+ ),
507
+
508
+
509
+ // AU - audio - NeXT/Sun AUdio (AU)
510
+ 'au' => array(
511
+ 'pattern' => '^\.snd',
512
+ 'group' => 'audio',
513
+ 'module' => 'au',
514
+ 'mime_type' => 'audio/basic',
515
+ ),
516
+
517
+ // AVR - audio - Audio Visual Research
518
+ 'avr' => array(
519
+ 'pattern' => '^2BIT',
520
+ 'group' => 'audio',
521
+ 'module' => 'avr',
522
+ 'mime_type' => 'application/octet-stream',
523
+ ),
524
+
525
+ // BONK - audio - Bonk v0.9+
526
+ 'bonk' => array(
527
+ 'pattern' => '^\x00(BONK|INFO|META| ID3)',
528
+ 'group' => 'audio',
529
+ 'module' => 'bonk',
530
+ 'mime_type' => 'audio/xmms-bonk',
531
+ ),
532
+
533
+ // DSS - audio - Digital Speech Standard
534
+ 'dss' => array(
535
+ 'pattern' => '^[\x02]dss',
536
+ 'group' => 'audio',
537
+ 'module' => 'dss',
538
+ 'mime_type' => 'application/octet-stream',
539
+ ),
540
+
541
+ // DTS - audio - Dolby Theatre System
542
+ 'dts' => array(
543
+ 'pattern' => '^\x7F\xFE\x80\x01',
544
+ 'group' => 'audio',
545
+ 'module' => 'dts',
546
+ 'mime_type' => 'audio/dts',
547
+ ),
548
+
549
+ // FLAC - audio - Free Lossless Audio Codec
550
+ 'flac' => array(
551
+ 'pattern' => '^fLaC',
552
+ 'group' => 'audio',
553
+ 'module' => 'flac',
554
+ 'mime_type' => 'audio/x-flac',
555
+ ),
556
+
557
+ // LA - audio - Lossless Audio (LA)
558
+ 'la' => array(
559
+ 'pattern' => '^LA0[2-4]',
560
+ 'group' => 'audio',
561
+ 'module' => 'la',
562
+ 'mime_type' => 'application/octet-stream',
563
+ ),
564
+
565
+ // LPAC - audio - Lossless Predictive Audio Compression (LPAC)
566
+ 'lpac' => array(
567
+ 'pattern' => '^LPAC',
568
+ 'group' => 'audio',
569
+ 'module' => 'lpac',
570
+ 'mime_type' => 'application/octet-stream',
571
+ ),
572
+
573
+ // MIDI - audio - MIDI (Musical Instrument Digital Interface)
574
+ 'midi' => array(
575
+ 'pattern' => '^MThd',
576
+ 'group' => 'audio',
577
+ 'module' => 'midi',
578
+ 'mime_type' => 'audio/midi',
579
+ ),
580
+
581
+ // MAC - audio - Monkey's Audio Compressor
582
+ 'mac' => array(
583
+ 'pattern' => '^MAC ',
584
+ 'group' => 'audio',
585
+ 'module' => 'monkey',
586
+ 'mime_type' => 'application/octet-stream',
587
+ ),
588
+
589
+ // has been known to produce false matches in random files (e.g. JPEGs), leave out until more precise matching available
590
+ // // MOD - audio - MODule (assorted sub-formats)
591
+ // 'mod' => array(
592
+ // 'pattern' => '^.{1080}(M\\.K\\.|M!K!|FLT4|FLT8|[5-9]CHN|[1-3][0-9]CH)',
593
+ // 'group' => 'audio',
594
+ // 'module' => 'mod',
595
+ // 'option' => 'mod',
596
+ // 'mime_type' => 'audio/mod',
597
+ // ),
598
+
599
+ // MOD - audio - MODule (Impulse Tracker)
600
+ 'it' => array(
601
+ 'pattern' => '^IMPM',
602
+ 'group' => 'audio',
603
+ 'module' => 'mod',
604
+ 'option' => 'it',
605
+ 'mime_type' => 'audio/it',
606
+ ),
607
+
608
+ // MOD - audio - MODule (eXtended Module, various sub-formats)
609
+ 'xm' => array(
610
+ 'pattern' => '^Extended Module',
611
+ 'group' => 'audio',
612
+ 'module' => 'mod',
613
+ 'option' => 'xm',
614
+ 'mime_type' => 'audio/xm',
615
+ ),
616
+
617
+ // MOD - audio - MODule (ScreamTracker)
618
+ 's3m' => array(
619
+ 'pattern' => '^.{44}SCRM',
620
+ 'group' => 'audio',
621
+ 'module' => 'mod',
622
+ 'option' => 's3m',
623
+ 'mime_type' => 'audio/s3m',
624
+ ),
625
+
626
+ // MPC - audio - Musepack / MPEGplus
627
+ 'mpc' => array(
628
+ '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])',
629
+ 'group' => 'audio',
630
+ 'module' => 'mpc',
631
+ 'mime_type' => 'audio/x-musepack',
632
+ ),
633
+
634
+ // MP3 - audio - MPEG-audio Layer 3 (very similar to AAC-ADTS)
635
+ 'mp3' => array(
636
+ 'pattern' => '^\xFF[\xE2-\xE7\xF2-\xF7\xFA-\xFF][\x00-\xEB]',
637
+ 'group' => 'audio',
638
+ 'module' => 'mp3',
639
+ 'mime_type' => 'audio/mpeg',
640
+ ),
641
+
642
+ // OFR - audio - OptimFROG
643
+ 'ofr' => array(
644
+ 'pattern' => '^(\*RIFF|OFR)',
645
+ 'group' => 'audio',
646
+ 'module' => 'optimfrog',
647
+ 'mime_type' => 'application/octet-stream',
648
+ ),
649
+
650
+ // RKAU - audio - RKive AUdio compressor
651
+ 'rkau' => array(
652
+ 'pattern' => '^RKA',
653
+ 'group' => 'audio',
654
+ 'module' => 'rkau',
655
+ 'mime_type' => 'application/octet-stream',
656
+ ),
657
+
658
+ // SHN - audio - Shorten
659
+ 'shn' => array(
660
+ 'pattern' => '^ajkg',
661
+ 'group' => 'audio',
662
+ 'module' => 'shorten',
663
+ 'mime_type' => 'audio/xmms-shn',
664
+ 'fail_id3' => 'ERROR',
665
+ 'fail_ape' => 'ERROR',
666
+ ),
667
+
668
+ // TTA - audio - TTA Lossless Audio Compressor (http://tta.corecodec.org)
669
+ 'tta' => array(
670
+ 'pattern' => '^TTA', // could also be '^TTA(\x01|\x02|\x03|2|1)'
671
+ 'group' => 'audio',
672
+ 'module' => 'tta',
673
+ 'mime_type' => 'application/octet-stream',
674
+ ),
675
+
676
+ // VOC - audio - Creative Voice (VOC)
677
+ 'voc' => array(
678
+ 'pattern' => '^Creative Voice File',
679
+ 'group' => 'audio',
680
+ 'module' => 'voc',
681
+ 'mime_type' => 'audio/voc',
682
+ ),
683
+
684
+ // VQF - audio - transform-domain weighted interleave Vector Quantization Format (VQF)
685
+ 'vqf' => array(
686
+ 'pattern' => '^TWIN',
687
+ 'group' => 'audio',
688
+ 'module' => 'vqf',
689
+ 'mime_type' => 'application/octet-stream',
690
+ ),
691
+
692
+ // WV - audio - WavPack (v4.0+)
693
+ 'wv' => array(
694
+ 'pattern' => '^wvpk',
695
+ 'group' => 'audio',
696
+ 'module' => 'wavpack',
697
+ 'mime_type' => 'application/octet-stream',
698
+ ),
699
+
700
+
701
+ // Audio-Video formats
702
+
703
+ // ASF - audio/video - Advanced Streaming Format, Windows Media Video, Windows Media Audio
704
+ 'asf' => array(
705
+ 'pattern' => '^\x30\x26\xB2\x75\x8E\x66\xCF\x11\xA6\xD9\x00\xAA\x00\x62\xCE\x6C',
706
+ 'group' => 'audio-video',
707
+ 'module' => 'asf',
708
+ 'mime_type' => 'video/x-ms-asf',
709
+ 'iconv_req' => false,
710
+ ),
711
+
712
+ // BINK - audio/video - Bink / Smacker
713
+ 'bink' => array(
714
+ 'pattern' => '^(BIK|SMK)',
715
+ 'group' => 'audio-video',
716
+ 'module' => 'bink',
717
+ 'mime_type' => 'application/octet-stream',
718
+ ),
719
+
720
+ // FLV - audio/video - FLash Video
721
+ 'flv' => array(
722
+ 'pattern' => '^FLV\x01',
723
+ 'group' => 'audio-video',
724
+ 'module' => 'flv',
725
+ 'mime_type' => 'video/x-flv',
726
+ ),
727
+
728
+ // MKAV - audio/video - Mastroka
729
+ 'matroska' => array(
730
+ 'pattern' => '^\x1A\x45\xDF\xA3',
731
+ 'group' => 'audio-video',
732
+ 'module' => 'matroska',
733
+ 'mime_type' => 'video/x-matroska', // may also be audio/x-matroska
734
+ ),
735
+
736
+ // MPEG - audio/video - MPEG (Moving Pictures Experts Group)
737
+ 'mpeg' => array(
738
+ 'pattern' => '^\x00\x00\x01(\xBA|\xB3)',
739
+ 'group' => 'audio-video',
740
+ 'module' => 'mpeg',
741
+ 'mime_type' => 'video/mpeg',
742
+ ),
743
+
744
+ // NSV - audio/video - Nullsoft Streaming Video (NSV)
745
+ 'nsv' => array(
746
+ 'pattern' => '^NSV[sf]',
747
+ 'group' => 'audio-video',
748
+ 'module' => 'nsv',
749
+ 'mime_type' => 'application/octet-stream',
750
+ ),
751
+
752
+ // Ogg - audio/video - Ogg (Ogg-Vorbis, Ogg-FLAC, Speex, Ogg-Theora(*), Ogg-Tarkin(*))
753
+ 'ogg' => array(
754
+ 'pattern' => '^OggS',
755
+ 'group' => 'audio',
756
+ 'module' => 'ogg',
757
+ 'mime_type' => 'application/ogg',
758
+ 'fail_id3' => 'WARNING',
759
+ 'fail_ape' => 'WARNING',
760
+ ),
761
+
762
+ // QT - audio/video - Quicktime
763
+ 'quicktime' => array(
764
+ 'pattern' => '^.{4}(cmov|free|ftyp|mdat|moov|pnot|skip|wide)',
765
+ 'group' => 'audio-video',
766
+ 'module' => 'quicktime',
767
+ 'mime_type' => 'video/quicktime',
768
+ ),
769
+
770
+ // 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)
771
+ 'riff' => array(
772
+ 'pattern' => '^(RIFF|SDSS|FORM)',
773
+ 'group' => 'audio-video',
774
+ 'module' => 'riff',
775
+ 'mime_type' => 'audio/x-wave',
776
+ 'fail_ape' => 'WARNING',
777
+ ),
778
+
779
+ // Real - audio/video - RealAudio, RealVideo
780
+ 'real' => array(
781
+ 'pattern' => '^(\\.RMF|\\.ra)',
782
+ 'group' => 'audio-video',
783
+ 'module' => 'real',
784
+ 'mime_type' => 'audio/x-realaudio',
785
+ ),
786
+
787
+ // SWF - audio/video - ShockWave Flash
788
+ 'swf' => array(
789
+ 'pattern' => '^(F|C)WS',
790
+ 'group' => 'audio-video',
791
+ 'module' => 'swf',
792
+ 'mime_type' => 'application/x-shockwave-flash',
793
+ ),
794
+
795
+
796
+ // Still-Image formats
797
+
798
+ // BMP - still image - Bitmap (Windows, OS/2; uncompressed, RLE8, RLE4)
799
+ 'bmp' => array(
800
+ 'pattern' => '^BM',
801
+ 'group' => 'graphic',
802
+ 'module' => 'bmp',
803
+ 'mime_type' => 'image/bmp',
804
+ 'fail_id3' => 'ERROR',
805
+ 'fail_ape' => 'ERROR',
806
+ ),
807
+
808
+ // GIF - still image - Graphics Interchange Format
809
+ 'gif' => array(
810
+ 'pattern' => '^GIF',
811
+ 'group' => 'graphic',
812
+ 'module' => 'gif',
813
+ 'mime_type' => 'image/gif',
814
+ 'fail_id3' => 'ERROR',
815
+ 'fail_ape' => 'ERROR',
816
+ ),
817
+
818
+ // JPEG - still image - Joint Photographic Experts Group (JPEG)
819
+ 'jpg' => array(
820
+ 'pattern' => '^\xFF\xD8\xFF',
821
+ 'group' => 'graphic',
822
+ 'module' => 'jpg',
823
+ 'mime_type' => 'image/jpeg',
824
+ 'fail_id3' => 'ERROR',
825
+ 'fail_ape' => 'ERROR',
826
+ ),
827
+
828
+ // PCD - still image - Kodak Photo CD
829
+ 'pcd' => array(
830
+ 'pattern' => '^.{2048}PCD_IPI\x00',
831
+ 'group' => 'graphic',
832
+ 'module' => 'pcd',
833
+ 'mime_type' => 'image/x-photo-cd',
834
+ 'fail_id3' => 'ERROR',
835
+ 'fail_ape' => 'ERROR',
836
+ ),
837
+
838
+
839
+ // PNG - still image - Portable Network Graphics (PNG)
840
+ 'png' => array(
841
+ 'pattern' => '^\x89\x50\x4E\x47\x0D\x0A\x1A\x0A',
842
+ 'group' => 'graphic',
843
+ 'module' => 'png',
844
+ 'mime_type' => 'image/png',
845
+ 'fail_id3' => 'ERROR',
846
+ 'fail_ape' => 'ERROR',
847
+ ),
848
+
849
+
850
+ // SVG - still image - Scalable Vector Graphics (SVG)
851
+ 'svg' => array(
852
+ 'pattern' => '<!DOCTYPE svg PUBLIC ',
853
+ 'group' => 'graphic',
854
+ 'module' => 'svg',
855
+ 'mime_type' => 'image/svg+xml',
856
+ 'fail_id3' => 'ERROR',
857
+ 'fail_ape' => 'ERROR',
858
+ ),
859
+
860
+
861
+ // TIFF - still image - Tagged Information File Format (TIFF)
862
+ 'tiff' => array(
863
+ 'pattern' => '^(II\x2A\x00|MM\x00\x2A)',
864
+ 'group' => 'graphic',
865
+ 'module' => 'tiff',
866
+ 'mime_type' => 'image/tiff',
867
+ 'fail_id3' => 'ERROR',
868
+ 'fail_ape' => 'ERROR',
869
+ ),
870
+
871
+
872
+ // Data formats
873
+
874
+ // ISO - data - International Standards Organization (ISO) CD-ROM Image
875
+ 'iso' => array(
876
+ 'pattern' => '^.{32769}CD001',
877
+ 'group' => 'misc',
878
+ 'module' => 'iso',
879
+ 'mime_type' => 'application/octet-stream',
880
+ 'fail_id3' => 'ERROR',
881
+ 'fail_ape' => 'ERROR',
882
+ 'iconv_req' => false,
883
+ ),
884
+
885
+ // RAR - data - RAR compressed data
886
+ 'rar' => array(
887
+ 'pattern' => '^Rar\!',
888
+ 'group' => 'archive',
889
+ 'module' => 'rar',
890
+ 'mime_type' => 'application/octet-stream',
891
+ 'fail_id3' => 'ERROR',
892
+ 'fail_ape' => 'ERROR',
893
+ ),
894
+
895
+ // SZIP - audio/data - SZIP compressed data
896
+ 'szip' => array(
897
+ 'pattern' => '^SZ\x0A\x04',
898
+ 'group' => 'archive',
899
+ 'module' => 'szip',
900
+ 'mime_type' => 'application/octet-stream',
901
+ 'fail_id3' => 'ERROR',
902
+ 'fail_ape' => 'ERROR',
903
+ ),
904
+
905
+ // TAR - data - TAR compressed data
906
+ 'tar' => array(
907
+ '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}',
908
+ 'group' => 'archive',
909
+ 'module' => 'tar',
910
+ 'mime_type' => 'application/x-tar',
911
+ 'fail_id3' => 'ERROR',
912
+ 'fail_ape' => 'ERROR',
913
+ ),
914
+
915
+ // GZIP - data - GZIP compressed data
916
+ 'gz' => array(
917
+ 'pattern' => '^\x1F\x8B\x08',
918
+ 'group' => 'archive',
919
+ 'module' => 'gzip',
920
+ 'mime_type' => 'application/x-gzip',
921
+ 'fail_id3' => 'ERROR',
922
+ 'fail_ape' => 'ERROR',
923
+ ),
924
+
925
+ // ZIP - data - ZIP compressed data
926
+ 'zip' => array(
927
+ 'pattern' => '^PK\x03\x04',
928
+ 'group' => 'archive',
929
+ 'module' => 'zip',
930
+ 'mime_type' => 'application/zip',
931
+ 'fail_id3' => 'ERROR',
932
+ 'fail_ape' => 'ERROR',
933
+ ),
934
+
935
+
936
+ // Misc other formats
937
+
938
+ // PAR2 - data - Parity Volume Set Specification 2.0
939
+ 'par2' => array (
940
+ 'pattern' => '^PAR2\x00PKT',
941
+ 'group' => 'misc',
942
+ 'module' => 'par2',
943
+ 'mime_type' => 'application/octet-stream',
944
+ 'fail_id3' => 'ERROR',
945
+ 'fail_ape' => 'ERROR',
946
+ ),
947
+
948
+ // PDF - data - Portable Document Format
949
+ 'pdf' => array(
950
+ 'pattern' => '^\x25PDF',
951
+ 'group' => 'misc',
952
+ 'module' => 'pdf',
953
+ 'mime_type' => 'application/pdf',
954
+ 'fail_id3' => 'ERROR',
955
+ 'fail_ape' => 'ERROR',
956
+ ),
957
+
958
+ // MSOFFICE - data - ZIP compressed data
959
+ 'msoffice' => array(
960
+ 'pattern' => '^\xD0\xCF\x11\xE0', // D0CF11E == DOCFILE == Microsoft Office Document
961
+ 'group' => 'misc',
962
+ 'module' => 'msoffice',
963
+ 'mime_type' => 'application/octet-stream',
964
+ 'fail_id3' => 'ERROR',
965
+ 'fail_ape' => 'ERROR',
966
+ ),
967
+ );
968
+ }
969
+
970
+ return $format_info;
971
+ }
972
+
973
+
974
+
975
+ function GetFileFormat(&$filedata, $filename='') {
976
+ // this function will determine the format of a file based on usually
977
+ // the first 2-4 bytes of the file (8 bytes for PNG, 16 bytes for JPG,
978
+ // and in the case of ISO CD image, 6 bytes offset 32kb from the start
979
+ // of the file).
980
+
981
+ // Identify file format - loop through $format_info and detect with reg expr
982
+ foreach ($this->GetFileFormatArray() as $format_name => $info) {
983
+ // Using preg_match() instead of ereg() - much faster
984
+ // The /s switch on preg_match() forces preg_match() NOT to treat
985
+ // newline (0x0A) characters as special chars but do a binary match
986
+ if (preg_match('/'.$info['pattern'].'/s', $filedata)) {
987
+ $info['include'] = 'module.'.$info['group'].'.'.$info['module'].'.php';
988
+ return $info;
989
+ }
990
+ }
991
+
992
+
993
+ if (preg_match('/\.mp[123a]$/i', $filename)) {
994
+ // Too many mp3 encoders on the market put gabage in front of mpeg files
995
+ // use assume format on these if format detection failed
996
+ $GetFileFormatArray = $this->GetFileFormatArray();
997
+ $info = $GetFileFormatArray['mp3'];
998
+ $info['include'] = 'module.'.$info['group'].'.'.$info['module'].'.php';
999
+ return $info;
1000
+ }
1001
+
1002
+ return false;
1003
+ }
1004
+
1005
+
1006
+ // converts array to $encoding charset from $this->encoding
1007
+ function CharConvert(&$array, $encoding) {
1008
+
1009
+ // identical encoding - end here
1010
+ if ($encoding == $this->encoding) {
1011
+ return;
1012
+ }
1013
+
1014
+ // loop thru array
1015
+ foreach ($array as $key => $value) {
1016
+
1017
+ // go recursive
1018
+ if (is_array($value)) {
1019
+ $this->CharConvert($array[$key], $encoding);
1020
+ }
1021
+
1022
+ // convert string
1023
+ elseif (is_string($value)) {
1024
+ $array[$key] = trim(getid3_lib::iconv_fallback($encoding, $this->encoding, $value));
1025
+ }
1026
+ }
1027
+ }
1028
+
1029
+
1030
+ function HandleAllTags() {
1031
+
1032
+ // key name => array (tag name, character encoding)
1033
+ static $tags;
1034
+ if (empty($tags)) {
1035
+ $tags = array(
1036
+ 'asf' => array('asf' , 'UTF-16LE'),
1037
+ 'midi' => array('midi' , 'ISO-8859-1'),
1038
+ 'nsv' => array('nsv' , 'ISO-8859-1'),
1039
+ 'ogg' => array('vorbiscomment' , 'UTF-8'),
1040
+ 'png' => array('png' , 'UTF-8'),
1041
+ 'tiff' => array('tiff' , 'ISO-8859-1'),
1042
+ 'quicktime' => array('quicktime' , 'ISO-8859-1'),
1043
+ 'real' => array('real' , 'ISO-8859-1'),
1044
+ 'vqf' => array('vqf' , 'ISO-8859-1'),
1045
+ 'zip' => array('zip' , 'ISO-8859-1'),
1046
+ 'riff' => array('riff' , 'ISO-8859-1'),
1047
+ 'lyrics3' => array('lyrics3' , 'ISO-8859-1'),
1048
+ 'id3v1' => array('id3v1' , $this->encoding_id3v1),
1049
+ '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
1050
+ 'ape' => array('ape' , 'UTF-8')
1051
+ );
1052
+ }
1053
+
1054
+ // loop thru comments array
1055
+ foreach ($tags as $comment_name => $tagname_encoding_array) {
1056
+ list($tag_name, $encoding) = $tagname_encoding_array;
1057
+
1058
+ // fill in default encoding type if not already present
1059
+ if (isset($this->info[$comment_name]) && !isset($this->info[$comment_name]['encoding'])) {
1060
+ $this->info[$comment_name]['encoding'] = $encoding;
1061
+ }
1062
+
1063
+ // copy comments if key name set
1064
+ if (!empty($this->info[$comment_name]['comments'])) {
1065
+
1066
+ foreach ($this->info[$comment_name]['comments'] as $tag_key => $valuearray) {
1067
+ foreach ($valuearray as $key => $value) {
1068
+ if (strlen(trim($value)) > 0) {
1069
+ $this->info['tags'][trim($tag_name)][trim($tag_key)][] = $value; // do not trim!! Unicode characters will get mangled if trailing nulls are removed!
1070
+ }
1071
+ }
1072
+ }
1073
+
1074
+ if (!isset($this->info['tags'][$tag_name])) {
1075
+ // comments are set but contain nothing but empty strings, so skip
1076
+ continue;
1077
+ }
1078
+
1079
+ if ($this->option_tags_html) {
1080
+ foreach ($this->info['tags'][$tag_name] as $tag_key => $valuearray) {
1081
+ foreach ($valuearray as $key => $value) {
1082
+ if (is_string($value)) {
1083
+ //$this->info['tags_html'][$tag_name][$tag_key][$key] = getid3_lib::MultiByteCharString2HTML($value, $encoding);
1084
+ $this->info['tags_html'][$tag_name][$tag_key][$key] = str_replace('&#0;', '', getid3_lib::MultiByteCharString2HTML($value, $encoding));
1085
+ } else {
1086
+ $this->info['tags_html'][$tag_name][$tag_key][$key] = $value;
1087
+ }
1088
+ }
1089
+ }
1090
+ }
1091
+
1092
+ $this->CharConvert($this->info['tags'][$tag_name], $encoding); // only copy gets converted!
1093
+ }
1094
+
1095
+ }
1096
+ return true;
1097
+ }
1098
+
1099
+
1100
+ function getHashdata($algorithm) {
1101
+ switch ($algorithm) {
1102
+ case 'md5':
1103
+ case 'sha1':
1104
+ break;
1105
+
1106
+ default:
1107
+ return $this->error('bad algorithm "'.$algorithm.'" in getHashdata()');
1108
+ break;
1109
+ }
1110
+
1111
+ if ((@$this->info['fileformat'] == 'ogg') && (@$this->info['audio']['dataformat'] == 'vorbis')) {
1112
+
1113
+ // We cannot get an identical md5_data value for Ogg files where the comments
1114
+ // span more than 1 Ogg page (compared to the same audio data with smaller
1115
+ // comments) using the normal getID3() method of MD5'ing the data between the
1116
+ // end of the comments and the end of the file (minus any trailing tags),
1117
+ // because the page sequence numbers of the pages that the audio data is on
1118
+ // do not match. Under normal circumstances, where comments are smaller than
1119
+ // the nominal 4-8kB page size, then this is not a problem, but if there are
1120
+ // very large comments, the only way around it is to strip off the comment
1121
+ // tags with vorbiscomment and MD5 that file.
1122
+ // This procedure must be applied to ALL Ogg files, not just the ones with
1123
+ // comments larger than 1 page, because the below method simply MD5's the
1124
+ // whole file with the comments stripped, not just the portion after the
1125
+ // comments block (which is the standard getID3() method.
1126
+
1127
+ // The above-mentioned problem of comments spanning multiple pages and changing
1128
+ // page sequence numbers likely happens for OggSpeex and OggFLAC as well, but
1129
+ // currently vorbiscomment only works on OggVorbis files.
1130
+
1131
+ if ((bool) ini_get('safe_mode')) {
1132
+
1133
+ $this->info['warning'][] = 'Failed making system call to vorbiscomment.exe - '.$algorithm.'_data is incorrect - error returned: PHP running in Safe Mode (backtick operator not available)';
1134
+ $this->info[$algorithm.'_data'] = false;
1135
+
1136
+ } else {
1137
+
1138
+ // Prevent user from aborting script
1139
+ $old_abort = ignore_user_abort(true);
1140
+
1141
+ // Create empty file
1142
+ $empty = tempnam('*', 'getID3');
1143
+ touch($empty);
1144
+
1145
+
1146
+ // Use vorbiscomment to make temp file without comments
1147
+ $temp = tempnam('*', 'getID3');
1148
+ $file = $this->info['filenamepath'];
1149
+
1150
+ if (GETID3_OS_ISWINDOWS) {
1151
+
1152
+ if (file_exists(GETID3_HELPERAPPSDIR.'vorbiscomment.exe')) {
1153
+
1154
+ $commandline = '"'.GETID3_HELPERAPPSDIR.'vorbiscomment.exe" -w -c "'.$empty.'" "'.$file.'" "'.$temp.'"';
1155
+ $VorbisCommentError = `$commandline`;
1156
+
1157
+ } else {
1158
+
1159
+ $VorbisCommentError = 'vorbiscomment.exe not found in '.GETID3_HELPERAPPSDIR;
1160
+
1161
+ }
1162
+
1163
+ } else {
1164
+
1165
+ $commandline = 'vorbiscomment -w -c "'.$empty.'" "'.$file.'" "'.$temp.'" 2>&1';
1166
+ $commandline = 'vorbiscomment -w -c '.escapeshellarg($empty).' '.escapeshellarg($file).' '.escapeshellarg($temp).' 2>&1';
1167
+ $VorbisCommentError = `$commandline`;
1168
+
1169
+ }
1170
+
1171
+ if (!empty($VorbisCommentError)) {
1172
+
1173
+ $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;
1174
+ $this->info[$algorithm.'_data'] = false;
1175
+
1176
+ } else {
1177
+
1178
+ // Get hash of newly created file
1179
+ switch ($algorithm) {
1180
+ case 'md5':
1181
+ $this->info[$algorithm.'_data'] = getid3_lib::md5_file($temp);
1182
+ break;
1183
+
1184
+ case 'sha1':
1185
+ $this->info[$algorithm.'_data'] = getid3_lib::sha1_file($temp);
1186
+ break;
1187
+ }
1188
+ }
1189
+
1190
+ // Clean up
1191
+ unlink($empty);
1192
+ unlink($temp);
1193
+
1194
+ // Reset abort setting
1195
+ ignore_user_abort($old_abort);
1196
+
1197
+ }
1198
+
1199
+ } else {
1200
+
1201
+ if (!empty($this->info['avdataoffset']) || (isset($this->info['avdataend']) && ($this->info['avdataend'] < $this->info['filesize']))) {
1202
+
1203
+ // get hash from part of file
1204
+ $this->info[$algorithm.'_data'] = getid3_lib::hash_data($this->info['filenamepath'], $this->info['avdataoffset'], $this->info['avdataend'], $algorithm);
1205
+
1206
+ } else {
1207
+
1208
+ // get hash from whole file
1209
+ switch ($algorithm) {
1210
+ case 'md5':
1211
+ $this->info[$algorithm.'_data'] = getid3_lib::md5_file($this->info['filenamepath']);
1212
+ break;
1213
+
1214
+ case 'sha1':
1215
+ $this->info[$algorithm.'_data'] = getid3_lib::sha1_file($this->info['filenamepath']);
1216
+ break;
1217
+ }
1218
+ }
1219
+
1220
+ }
1221
+ return true;
1222
+ }
1223
+
1224
+
1225
+ function ChannelsBitratePlaytimeCalculations() {
1226
+
1227
+ // set channelmode on audio
1228
+ if (@$this->info['audio']['channels'] == '1') {
1229
+ $this->info['audio']['channelmode'] = 'mono';
1230
+ } elseif (@$this->info['audio']['channels'] == '2') {
1231
+ $this->info['audio']['channelmode'] = 'stereo';
1232
+ }
1233
+
1234
+ // Calculate combined bitrate - audio + video
1235
+ $CombinedBitrate = 0;
1236
+ $CombinedBitrate += (isset($this->info['audio']['bitrate']) ? $this->info['audio']['bitrate'] : 0);
1237
+ $CombinedBitrate += (isset($this->info['video']['bitrate']) ? $this->info['video']['bitrate'] : 0);
1238
+ if (($CombinedBitrate > 0) && empty($this->info['bitrate'])) {
1239
+ $this->info['bitrate'] = $CombinedBitrate;
1240
+ }
1241
+ //if ((isset($this->info['video']) && !isset($this->info['video']['bitrate'])) || (isset($this->info['audio']) && !isset($this->info['audio']['bitrate']))) {
1242
+ // // for example, VBR MPEG video files cannot determine video bitrate:
1243
+ // // should not set overall bitrate and playtime from audio bitrate only
1244
+ // unset($this->info['bitrate']);
1245
+ //}
1246
+
1247
+ // video bitrate undetermined, but calculable
1248
+ if (isset($this->info['video']['dataformat']) && $this->info['video']['dataformat'] && (!isset($this->info['video']['bitrate']) || ($this->info['video']['bitrate'] == 0))) {
1249
+ // if video bitrate not set
1250
+ if (isset($this->info['audio']['bitrate']) && ($this->info['audio']['bitrate'] > 0) && ($this->info['audio']['bitrate'] == $this->info['bitrate'])) {
1251
+ // AND if audio bitrate is set to same as overall bitrate
1252
+ if (isset($this->info['playtime_seconds']) && ($this->info['playtime_seconds'] > 0)) {
1253
+ // AND if playtime is set
1254
+ if (isset($this->info['avdataend']) && isset($this->info['avdataoffset'])) {
1255
+ // AND if AV data offset start/end is known
1256
+ // THEN we can calculate the video bitrate
1257
+ $this->info['bitrate'] = round((($this->info['avdataend'] - $this->info['avdataoffset']) * 8) / $this->info['playtime_seconds']);
1258
+ $this->info['video']['bitrate'] = $this->info['bitrate'] - $this->info['audio']['bitrate'];
1259
+ }
1260
+ }
1261
+ }
1262
+ }
1263
+
1264
+ if ((!isset($this->info['playtime_seconds']) || ($this->info['playtime_seconds'] <= 0)) && !empty($this->info['bitrate'])) {
1265
+ $this->info['playtime_seconds'] = (($this->info['avdataend'] - $this->info['avdataoffset']) * 8) / $this->info['bitrate'];
1266
+ }
1267
+
1268
+ if (!isset($this->info['bitrate']) && !empty($this->info['playtime_seconds'])) {
1269
+ $this->info['bitrate'] = (($this->info['avdataend'] - $this->info['avdataoffset']) * 8) / $this->info['playtime_seconds'];
1270
+ }
1271
+ //echo '<pre>';
1272
+ //var_dump($this->info['bitrate']);
1273
+ //var_dump($this->info['audio']['bitrate']);
1274
+ //var_dump($this->info['video']['bitrate']);
1275
+ //echo '</pre>';
1276
+ if (isset($this->info['bitrate']) && empty($this->info['audio']['bitrate']) && empty($this->info['video']['bitrate'])) {
1277
+ if (isset($this->info['audio']['dataformat']) && empty($this->info['video']['resolution_x'])) {
1278
+ // audio only
1279
+ $this->info['audio']['bitrate'] = $this->info['bitrate'];
1280
+ } elseif (isset($this->info['video']['resolution_x']) && empty($this->info['audio']['dataformat'])) {
1281
+ // video only
1282
+ $this->info['video']['bitrate'] = $this->info['bitrate'];
1283
+ }
1284
+ }
1285
+
1286
+ // Set playtime string
1287
+ if (!empty($this->info['playtime_seconds']) && empty($this->info['playtime_string'])) {
1288
+ $this->info['playtime_string'] = getid3_lib::PlaytimeString($this->info['playtime_seconds']);
1289
+ }
1290
+ }
1291
+
1292
+
1293
+ function CalculateCompressionRatioVideo() {
1294
+ if (empty($this->info['video'])) {
1295
+ return false;
1296
+ }
1297
+ if (empty($this->info['video']['resolution_x']) || empty($this->info['video']['resolution_y'])) {
1298
+ return false;
1299
+ }
1300
+ if (empty($this->info['video']['bits_per_sample'])) {
1301
+ return false;
1302
+ }
1303
+
1304
+ switch ($this->info['video']['dataformat']) {
1305
+ case 'bmp':
1306
+ case 'gif':
1307
+ case 'jpeg':
1308
+ case 'jpg':
1309
+ case 'png':
1310
+ case 'tiff':
1311
+ $FrameRate = 1;
1312
+ $PlaytimeSeconds = 1;
1313
+ $BitrateCompressed = $this->info['filesize'] * 8;
1314
+ break;
1315
+
1316
+ default:
1317
+ if (!empty($this->info['video']['frame_rate'])) {
1318
+ $FrameRate = $this->info['video']['frame_rate'];
1319
+ } else {
1320
+ return false;
1321
+ }
1322
+ if (!empty($this->info['playtime_seconds'])) {
1323
+ $PlaytimeSeconds = $this->info['playtime_seconds'];
1324
+ } else {
1325
+ return false;
1326
+ }
1327
+ if (!empty($this->info['video']['bitrate'])) {
1328
+ $BitrateCompressed = $this->info['video']['bitrate'];
1329
+ } else {
1330
+ return false;
1331
+ }
1332
+ break;
1333
+ }
1334
+ $BitrateUncompressed = $this->info['video']['resolution_x'] * $this->info['video']['resolution_y'] * $this->info['video']['bits_per_sample'] * $FrameRate;
1335
+
1336
+ $this->info['video']['compression_ratio'] = $BitrateCompressed / $BitrateUncompressed;
1337
+ return true;
1338
+ }
1339
+
1340
+
1341
+ function CalculateCompressionRatioAudio() {
1342
+ if (empty($this->info['audio']['bitrate']) || empty($this->info['audio']['channels']) || empty($this->info['audio']['sample_rate'])) {
1343
+ return false;
1344
+ }
1345
+ $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));
1346
+
1347
+ if (!empty($this->info['audio']['streams'])) {
1348
+ foreach ($this->info['audio']['streams'] as $streamnumber => $streamdata) {
1349
+ if (!empty($streamdata['bitrate']) && !empty($streamdata['channels']) && !empty($streamdata['sample_rate'])) {
1350
+ $this->info['audio']['streams'][$streamnumber]['compression_ratio'] = $streamdata['bitrate'] / ($streamdata['channels'] * $streamdata['sample_rate'] * (!empty($streamdata['bits_per_sample']) ? $streamdata['bits_per_sample'] : 16));
1351
+ }
1352
+ }
1353
+ }
1354
+ return true;
1355
+ }
1356
+
1357
+
1358
+ function CalculateReplayGain() {
1359
+ if (isset($this->info['replay_gain'])) {
1360
+ $this->info['replay_gain']['reference_volume'] = 89;
1361
+ if (isset($this->info['replay_gain']['track']['adjustment'])) {
1362
+ $this->info['replay_gain']['track']['volume'] = $this->info['replay_gain']['reference_volume'] - $this->info['replay_gain']['track']['adjustment'];
1363
+ }
1364
+ if (isset($this->info['replay_gain']['album']['adjustment'])) {
1365
+ $this->info['replay_gain']['album']['volume'] = $this->info['replay_gain']['reference_volume'] - $this->info['replay_gain']['album']['adjustment'];
1366
+ }
1367
+
1368
+ if (isset($this->info['replay_gain']['track']['peak'])) {
1369
+ $this->info['replay_gain']['track']['max_noclip_gain'] = 0 - getid3_lib::RGADamplitude2dB($this->info['replay_gain']['track']['peak']);
1370
+ }
1371
+ if (isset($this->info['replay_gain']['album']['peak'])) {
1372
+ $this->info['replay_gain']['album']['max_noclip_gain'] = 0 - getid3_lib::RGADamplitude2dB($this->info['replay_gain']['album']['peak']);
1373
+ }
1374
+ }
1375
+ return true;
1376
+ }
1377
+
1378
+ function ProcessAudioStreams() {
1379
+ if (!empty($this->info['audio']['bitrate']) || !empty($this->info['audio']['channels']) || !empty($this->info['audio']['sample_rate'])) {
1380
+ if (!isset($this->info['audio']['streams'])) {
1381
+ foreach ($this->info['audio'] as $key => $value) {
1382
+ if ($key != 'streams') {
1383
+ $this->info['audio']['streams'][0][$key] = $value;
1384
+ }
1385
+ }
1386
+ }
1387
+ }
1388
+ return true;
1389
+ }
1390
+
1391
+ function getid3_tempnam() {
1392
+ return tempnam($this->tempdir, 'gI3');
1393
+ }
1394
+
1395
+ }
1396
+
1397
+ ?>
view/getid3/module.archive.gzip.php ADDED
@@ -0,0 +1,271 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /////////////////////////////////////////////////////////////////
3
+ /// getID3() by James Heinrich <info@getid3.org> //
4
+ // available at http://getid3.sourceforge.net //
5
+ // or http://www.getid3.org //
6
+ /////////////////////////////////////////////////////////////////
7
+ // See readme.txt for more details //
8
+ /////////////////////////////////////////////////////////////////
9
+ // //
10
+ // module.archive.gzip.php //
11
+ // module for analyzing GZIP files //
12
+ // dependencies: NONE //
13
+ // ///
14
+ /////////////////////////////////////////////////////////////////
15
+ // //
16
+ // Module originally written by //
17
+ // Mike Mozolin <teddybear�mail*ru> //
18
+ // //
19
+ /////////////////////////////////////////////////////////////////
20
+
21
+
22
+ class getid3_gzip {
23
+
24
+ // public: Optional file list - disable for speed.
25
+ var $option_gzip_parse_contents = false; // decode gzipped files, if possible, and parse recursively (.tar.gz for example)
26
+
27
+ function getid3_gzip(&$fd, &$ThisFileInfo) {
28
+ $ThisFileInfo['fileformat'] = 'gzip';
29
+
30
+ $start_length = 10;
31
+ $unpack_header = 'a1id1/a1id2/a1cmethod/a1flags/a4mtime/a1xflags/a1os';
32
+ //+---+---+---+---+---+---+---+---+---+---+
33
+ //|ID1|ID2|CM |FLG| MTIME |XFL|OS |
34
+ //+---+---+---+---+---+---+---+---+---+---+
35
+ @fseek($fd, 0);
36
+ $buffer = @fread($fd, $ThisFileInfo['filesize']);
37
+
38
+ $arr_members = explode("\x1F\x8B\x08", $buffer);
39
+ while (true) {
40
+ $is_wrong_members = false;
41
+ $num_members = intval(count($arr_members));
42
+ for ($i = 0; $i < $num_members; $i++) {
43
+ if (strlen($arr_members[$i]) == 0) {
44
+ continue;
45
+ }
46
+ $buf = "\x1F\x8B\x08".$arr_members[$i];
47
+
48
+ $attr = unpack($unpack_header, substr($buf, 0, $start_length));
49
+ if (!$this->get_os_type(ord($attr['os']))) {
50
+ // Merge member with previous if wrong OS type
51
+ $arr_members[$i - 1] .= $buf;
52
+ $arr_members[$i] = '';
53
+ $is_wrong_members = true;
54
+ continue;
55
+ }
56
+ }
57
+ if (!$is_wrong_members) {
58
+ break;
59
+ }
60
+ }
61
+
62
+ $ThisFileInfo['gzip']['files'] = array();
63
+
64
+ $fpointer = 0;
65
+ $idx = 0;
66
+ for ($i = 0; $i < $num_members; $i++) {
67
+ if (strlen($arr_members[$i]) == 0) {
68
+ continue;
69
+ }
70
+ $thisThisFileInfo = &$ThisFileInfo['gzip']['member_header'][++$idx];
71
+
72
+ $buff = "\x1F\x8B\x08".$arr_members[$i];
73
+
74
+ $attr = unpack($unpack_header, substr($buff, 0, $start_length));
75
+ $thisThisFileInfo['filemtime'] = getid3_lib::LittleEndian2Int($attr['mtime']);
76
+ $thisThisFileInfo['raw']['id1'] = ord($attr['cmethod']);
77
+ $thisThisFileInfo['raw']['id2'] = ord($attr['cmethod']);
78
+ $thisThisFileInfo['raw']['cmethod'] = ord($attr['cmethod']);
79
+ $thisThisFileInfo['raw']['os'] = ord($attr['os']);
80
+ $thisThisFileInfo['raw']['xflags'] = ord($attr['xflags']);
81
+ $thisThisFileInfo['raw']['flags'] = ord($attr['flags']);
82
+
83
+ $thisThisFileInfo['flags']['crc16'] = (bool) ($thisThisFileInfo['raw']['flags'] & 0x02);
84
+ $thisThisFileInfo['flags']['extra'] = (bool) ($thisThisFileInfo['raw']['flags'] & 0x04);
85
+ $thisThisFileInfo['flags']['filename'] = (bool) ($thisThisFileInfo['raw']['flags'] & 0x08);
86
+ $thisThisFileInfo['flags']['comment'] = (bool) ($thisThisFileInfo['raw']['flags'] & 0x10);
87
+
88
+ $thisThisFileInfo['compression'] = $this->get_xflag_type($thisThisFileInfo['raw']['xflags']);
89
+
90
+ $thisThisFileInfo['os'] = $this->get_os_type($thisThisFileInfo['raw']['os']);
91
+ if (!$thisThisFileInfo['os']) {
92
+ $ThisFileInfo['error'][] = 'Read error on gzip file';
93
+ return false;
94
+ }
95
+
96
+ $fpointer = 10;
97
+ $arr_xsubfield = array();
98
+ // bit 2 - FLG.FEXTRA
99
+ //+---+---+=================================+
100
+ //| XLEN |...XLEN bytes of "extra field"...|
101
+ //+---+---+=================================+
102
+ if ($thisThisFileInfo['flags']['extra']) {
103
+ $w_xlen = substr($buff, $fpointer, 2);
104
+ $xlen = getid3_lib::LittleEndian2Int($w_xlen);
105
+ $fpointer += 2;
106
+
107
+ $thisThisFileInfo['raw']['xfield'] = substr($buff, $fpointer, $xlen);
108
+ // Extra SubFields
109
+ //+---+---+---+---+==================================+
110
+ //|SI1|SI2| LEN |... LEN bytes of subfield data ...|
111
+ //+---+---+---+---+==================================+
112
+ $idx = 0;
113
+ while (true) {
114
+ if ($idx >= $xlen) {
115
+ break;
116
+ }
117
+ $si1 = ord(substr($buff, $fpointer + $idx++, 1));
118
+ $si2 = ord(substr($buff, $fpointer + $idx++, 1));
119
+ if (($si1 == 0x41) && ($si2 == 0x70)) {
120
+ $w_xsublen = substr($buff, $fpointer + $idx, 2);
121
+ $xsublen = getid3_lib::LittleEndian2Int($w_xsublen);
122
+ $idx += 2;
123
+ $arr_xsubfield[] = substr($buff, $fpointer + $idx, $xsublen);
124
+ $idx += $xsublen;
125
+ } else {
126
+ break;
127
+ }
128
+ }
129
+ $fpointer += $xlen;
130
+ }
131
+ // bit 3 - FLG.FNAME
132
+ //+=========================================+
133
+ //|...original file name, zero-terminated...|
134
+ //+=========================================+
135
+ // GZIP files may have only one file, with no filename, so assume original filename is current filename without .gz
136
+ $thisThisFileInfo['filename'] = eregi_replace('.gz$', '', $ThisFileInfo['filename']);
137
+ if ($thisThisFileInfo['flags']['filename']) {
138
+ while (true) {
139
+ if (ord($buff[$fpointer]) == 0) {
140
+ $fpointer++;
141
+ break;
142
+ }
143
+ $thisThisFileInfo['filename'] .= $buff[$fpointer];
144
+ $fpointer++;
145
+ }
146
+ }
147
+ // bit 4 - FLG.FCOMMENT
148
+ //+===================================+
149
+ //|...file comment, zero-terminated...|
150
+ //+===================================+
151
+ if ($thisThisFileInfo['flags']['comment']) {
152
+ while (true) {
153
+ if (ord($buff[$fpointer]) == 0) {
154
+ $fpointer++;
155
+ break;
156
+ }
157
+ $thisThisFileInfo['comment'] .= $buff[$fpointer];
158
+ $fpointer++;
159
+ }
160
+ }
161
+ // bit 1 - FLG.FHCRC
162
+ //+---+---+
163
+ //| CRC16 |
164
+ //+---+---+
165
+ if ($thisThisFileInfo['flags']['crc16']) {
166
+ $w_crc = substr($buff, $fpointer, 2);
167
+ $thisThisFileInfo['crc16'] = getid3_lib::LittleEndian2Int($w_crc);
168
+ $fpointer += 2;
169
+ }
170
+ // bit 0 - FLG.FTEXT
171
+ //if ($thisThisFileInfo['raw']['flags'] & 0x01) {
172
+ // Ignored...
173
+ //}
174
+ // bits 5, 6, 7 - reserved
175
+
176
+ $thisThisFileInfo['crc32'] = getid3_lib::LittleEndian2Int(substr($buff, strlen($buff) - 8, 4));
177
+ $thisThisFileInfo['filesize'] = getid3_lib::LittleEndian2Int(substr($buff, strlen($buff) - 4));
178
+
179
+ $ThisFileInfo['gzip']['files'] = getid3_lib::array_merge_clobber($ThisFileInfo['gzip']['files'], getid3_lib::CreateDeepArray($thisThisFileInfo['filename'], '/', $thisThisFileInfo['filesize']));
180
+
181
+ if ($this->option_gzip_parse_contents) {
182
+ // Try to inflate GZip
183
+ $csize = 0;
184
+ $inflated = '';
185
+ $chkcrc32 = '';
186
+ if (function_exists('gzinflate')) {
187
+ $cdata = substr($buff, $fpointer);
188
+ $cdata = substr($cdata, 0, strlen($cdata) - 8);
189
+ $csize = strlen($cdata);
190
+ $inflated = gzinflate($cdata);
191
+
192
+ // Calculate CRC32 for inflated content
193
+ $thisThisFileInfo['crc32_valid'] = (bool) (sprintf('%u', crc32($inflated)) == $thisThisFileInfo['crc32']);
194
+
195
+ // determine format
196
+ $formattest = substr($inflated, 0, 32774);
197
+ $newgetID3 = new getID3();
198
+ $determined_format = $newgetID3->GetFileFormat($formattest);
199
+ unset($newgetID3);
200
+
201
+ // file format is determined
202
+ switch (@$determined_format['module']) {
203
+ case 'tar':
204
+ // view TAR-file info
205
+ if (file_exists(GETID3_INCLUDEPATH.$determined_format['include']) && @include_once(GETID3_INCLUDEPATH.$determined_format['include'])) {
206
+ if (($temp_tar_filename = tempnam('*', 'getID3')) === false) {
207
+ // can't find anywhere to create a temp file, abort
208
+ $ThisFileInfo['error'][] = 'Unable to create temp file to parse TAR inside GZIP file';
209
+ break;
210
+ }
211
+ if ($fp_temp_tar = fopen($temp_tar_filename, 'w+b')) {
212
+ fwrite($fp_temp_tar, $inflated);
213
+ rewind($fp_temp_tar);
214
+ $getid3_tar = new getid3_tar($fp_temp_tar, $dummy);
215
+ $ThisFileInfo['gzip']['member_header'][$idx]['tar'] = $dummy['tar'];
216
+ unset($dummy);
217
+ unset($getid3_tar);
218
+ fclose($fp_temp_tar);
219
+ unlink($temp_tar_filename);
220
+ } else {
221
+ $ThisFileInfo['error'][] = 'Unable to fopen() temp file to parse TAR inside GZIP file';
222
+ break;
223
+ }
224
+ }
225
+ break;
226
+
227
+ case '':
228
+ default:
229
+ // unknown or unhandled format
230
+ break;
231
+ }
232
+ }
233
+ }
234
+ }
235
+ return true;
236
+ }
237
+
238
+ // Converts the OS type
239
+ function get_os_type($key) {
240
+ static $os_type = array(
241
+ '0' => 'FAT filesystem (MS-DOS, OS/2, NT/Win32)',
242
+ '1' => 'Amiga',
243
+ '2' => 'VMS (or OpenVMS)',
244
+ '3' => 'Unix',
245
+ '4' => 'VM/CMS',
246
+ '5' => 'Atari TOS',
247
+ '6' => 'HPFS filesystem (OS/2, NT)',
248
+ '7' => 'Macintosh',
249
+ '8' => 'Z-System',
250
+ '9' => 'CP/M',
251
+ '10' => 'TOPS-20',
252
+ '11' => 'NTFS filesystem (NT)',
253
+ '12' => 'QDOS',
254
+ '13' => 'Acorn RISCOS',
255
+ '255' => 'unknown'
256
+ );
257
+ return @$os_type[$key];
258
+ }
259
+
260
+ // Converts the eXtra FLags
261
+ function get_xflag_type($key) {
262
+ static $xflag_type = array(
263
+ '0' => 'unknown',
264
+ '2' => 'maximum compression',
265
+ '4' => 'fastest algorithm'
266
+ );
267
+ return @$xflag_type[$key];
268
+ }
269
+ }
270
+
271
+ ?>
view/getid3/module.archive.rar.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /////////////////////////////////////////////////////////////////
3
+ /// getID3() by James Heinrich <info@getid3.org> //
4
+ // available at http://getid3.sourceforge.net //
5
+ // or http://www.getid3.org //
6
+ /////////////////////////////////////////////////////////////////
7
+ // See readme.txt for more details //
8
+ /////////////////////////////////////////////////////////////////
9
+ // //
10
+ // module.archive.rar.php //
11
+ // module for analyzing RAR files //
12
+ // dependencies: NONE //
13
+ // ///
14
+ /////////////////////////////////////////////////////////////////
15
+
16
+
17
+ class getid3_rar
18
+ {
19
+
20
+ var $option_use_rar_extension = false;
21
+
22
+ function getid3_rar(&$fd, &$ThisFileInfo) {
23
+
24
+ $ThisFileInfo['fileformat'] = 'rar';
25
+
26
+ if ($this->option_use_rar_extension === true) {
27
+ if (function_exists('rar_open')) {
28
+ if ($rp = rar_open($ThisFileInfo['filename'])) {
29
+ $ThisFileInfo['rar']['files'] = array();
30
+ $entries = rar_list($rp);
31
+ foreach ($entries as $entry) {
32
+ $ThisFileInfo['rar']['files'] = getid3_lib::array_merge_clobber($ThisFileInfo['rar']['files'], getid3_lib::CreateDeepArray($entry->getName(), '/', $entry->getUnpackedSize()));
33
+ }
34
+ rar_close($rp);
35
+ return true;
36
+ } else {
37
+ $ThisFileInfo['error'][] = 'failed to rar_open('.$ThisFileInfo['filename'].')';
38
+ }
39
+ } else {
40
+ $ThisFileInfo['error'][] = 'RAR support does not appear to be available in this PHP installation';
41
+ }
42
+ } else {
43
+ $ThisFileInfo['error'][] = 'PHP-RAR processing has been disabled (set $getid3_rar->option_use_rar_extension=true to enable)';
44
+ }
45
+ return false;
46
+
47
+ }
48
+
49
+ }
50
+
51
+
52
+ ?>
view/getid3/module.archive.szip.php ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /////////////////////////////////////////////////////////////////
3
+ /// getID3() by James Heinrich <info@getid3.org> //
4
+ // available at http://getid3.sourceforge.net //
5
+ // or http://www.getid3.org //
6
+ /////////////////////////////////////////////////////////////////
7
+ // See readme.txt for more details //
8
+ /////////////////////////////////////////////////////////////////
9
+ // //
10
+ // module.archive.szip.php //
11
+ // module for analyzing SZIP compressed files //
12
+ // dependencies: NONE //
13
+ // ///
14
+ /////////////////////////////////////////////////////////////////
15
+
16
+
17
+ class getid3_szip
18
+ {
19
+
20
+ function getid3_szip(&$fd, &$ThisFileInfo) {
21
+
22
+ fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
23
+ $SZIPHeader = fread($fd, 6);
24
+ if (substr($SZIPHeader, 0, 4) != 'SZ'."\x0A\x04") {
25
+ $ThisFileInfo['error'][] = 'Expecting "SZ[x0A][x04]" at offset '.$ThisFileInfo['avdataoffset'].', found "'.substr($SZIPHeader, 0, 4).'"';
26
+ return false;
27
+ }
28
+
29
+ $ThisFileInfo['fileformat'] = 'szip';
30
+
31
+ $ThisFileInfo['szip']['major_version'] = getid3_lib::BigEndian2Int(substr($SZIPHeader, 4, 1));
32
+ $ThisFileInfo['szip']['minor_version'] = getid3_lib::BigEndian2Int(substr($SZIPHeader, 5, 1));
33
+
34
+ while (!feof($fd)) {
35
+ $NextBlockID = fread($fd, 2);
36
+ switch ($NextBlockID) {
37
+ case 'SZ':
38
+ // Note that szip files can be concatenated, this has the same effect as
39
+ // concatenating the files. this also means that global header blocks
40
+ // might be present between directory/data blocks.
41
+ fseek($fd, 4, SEEK_CUR);
42
+ break;
43
+
44
+ case 'BH':
45
+ $BHheaderbytes = getid3_lib::BigEndian2Int(fread($fd, 3));
46
+ $BHheaderdata = fread($fd, $BHheaderbytes);
47
+ $BHheaderoffset = 0;
48
+ while (strpos($BHheaderdata, "\x00", $BHheaderoffset) > 0) {
49
+ //filename as \0 terminated string (empty string indicates end)
50
+ //owner as \0 terminated string (empty is same as last file)
51
+ //group as \0 terminated string (empty is same as last file)
52
+ //3 byte filelength in this block
53
+ //2 byte access flags
54
+ //4 byte creation time (like in unix)
55
+ //4 byte modification time (like in unix)
56
+ //4 byte access time (like in unix)
57
+
58
+ $BHdataArray['filename'] = substr($BHheaderdata, $BHheaderoffset, strcspn($BHheaderdata, "\x00"));
59
+ $BHheaderoffset += (strlen($BHdataArray['filename']) + 1);
60
+
61
+ $BHdataArray['owner'] = substr($BHheaderdata, $BHheaderoffset, strcspn($BHheaderdata, "\x00"));
62
+ $BHheaderoffset += (strlen($BHdataArray['owner']) + 1);
63
+
64
+ $BHdataArray['group'] = substr($BHheaderdata, $BHheaderoffset, strcspn($BHheaderdata, "\x00"));
65
+ $BHheaderoffset += (strlen($BHdataArray['group']) + 1);
66
+
67
+ $BHdataArray['filelength'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 3));
68
+ $BHheaderoffset += 3;
69
+
70
+ $BHdataArray['access_flags'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 2));
71
+ $BHheaderoffset += 2;
72
+
73
+ $BHdataArray['creation_time'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 4));
74
+ $BHheaderoffset += 4;
75
+
76
+ $BHdataArray['modification_time'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 4));
77
+ $BHheaderoffset += 4;
78
+
79
+ $BHdataArray['access_time'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 4));
80
+ $BHheaderoffset += 4;
81
+
82
+ $ThisFileInfo['szip']['BH'][] = $BHdataArray;
83
+ }
84
+ break;
85
+
86
+ default:
87
+ break 2;
88
+ }
89
+ }
90
+
91
+ return true;
92
+
93
+ }
94
+
95
+ }
96
+
97
+ ?>
view/getid3/module.archive.tar.php ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /////////////////////////////////////////////////////////////////
3
+ /// getID3() by James Heinrich <info@getid3.org> //
4
+ // available at http://getid3.sourceforge.net //
5
+ // or http://www.getid3.org //
6
+ /////////////////////////////////////////////////////////////////
7
+ // See readme.txt for more details //
8
+ /////////////////////////////////////////////////////////////////
9
+ // //
10
+ // module.archive.tar.php //
11
+ // module for analyzing TAR files //
12
+ // dependencies: NONE //
13
+ // ///
14
+ /////////////////////////////////////////////////////////////////
15
+ // //
16
+ // Module originally written by //
17
+ // Mike Mozolin <teddybear�mail*ru> //
18
+ // //
19
+ /////////////////////////////////////////////////////////////////
20
+
21
+
22
+ class getid3_tar {
23
+
24
+ function getid3_tar(&$fd, &$ThisFileInfo) {
25
+ $ThisFileInfo['fileformat'] = 'tar';
26
+ $ThisFileInfo['tar']['files'] = array();
27
+
28
+ $unpack_header = 'a100fname/a8mode/a8uid/a8gid/a12size/a12mtime/a8chksum/a1typflag/a100lnkname/a6magic/a2ver/a32uname/a32gname/a8devmaj/a8devmin/a155prefix';
29
+ $null_512k = str_repeat("\x00", 512); // end-of-file marker
30
+
31
+ @fseek($fd, 0);
32
+ while (!feof($fd)) {
33
+ $buffer = fread($fd, 512);
34
+ if (strlen($buffer) < 512) {
35
+ break;
36
+ }
37
+
38
+ // check the block
39
+ $checksum = 0;
40
+ for ($i = 0; $i < 148; $i++) {
41
+ $checksum += ord($buffer{$i});
42
+ }
43
+ for ($i = 148; $i < 156; $i++) {
44
+ $checksum += ord(' ');
45
+ }
46
+ for ($i = 156; $i < 512; $i++) {
47
+ $checksum += ord($buffer{$i});
48
+ }
49
+ $attr = unpack($unpack_header, $buffer);
50
+ $name = trim(@$attr['fname']);
51
+ $mode = octdec(trim(@$attr['mode']));
52
+ $uid = octdec(trim(@$attr['uid']));
53
+ $gid = octdec(trim(@$attr['gid']));
54
+ $size = octdec(trim(@$attr['size']));
55
+ $mtime = octdec(trim(@$attr['mtime']));
56
+ $chksum = octdec(trim(@$attr['chksum']));
57
+ $typflag = trim(@$attr['typflag']);
58
+ $lnkname = trim(@$attr['lnkname']);
59
+ $magic = trim(@$attr['magic']);
60
+ $ver = trim(@$attr['ver']);
61
+ $uname = trim(@$attr['uname']);
62
+ $gname = trim(@$attr['gname']);
63
+ $devmaj = octdec(trim(@$attr['devmaj']));
64
+ $devmin = octdec(trim(@$attr['devmin']));
65
+ $prefix = trim(@$attr['prefix']);
66
+ if (($checksum == 256) && ($chksum == 0)) {
67
+ // EOF Found
68
+ break;
69
+ }
70
+ if ($prefix) {
71
+ $name = $prefix.'/'.$name;
72
+ }
73
+ if ((preg_match('#/$#', $name)) && !$name) {
74
+ $typeflag = 5;
75
+ }
76
+ if ($buffer == $null_512k) {
77
+ // it's the end of the tar-file...
78
+ break;
79
+ }
80
+
81
+ // Read to the next chunk
82
+ fseek($fd, $size, SEEK_CUR);
83
+
84
+ $diff = $size % 512;
85
+ if ($diff != 0) {
86
+ // Padding, throw away
87
+ fseek($fd, (512 - $diff), SEEK_CUR);
88
+ }
89
+ // Protect against tar-files with garbage at the end
90
+ if ($name == '') {
91
+ break;
92
+ }
93
+ $ThisFileInfo['tar']['file_details'][$name] = array (
94
+ 'name' => $name,
95
+ 'mode_raw' => $mode,
96
+ 'mode' => getid3_tar::display_perms($mode),
97
+ 'uid' => $uid,
98
+ 'gid' => $gid,
99
+ 'size' => $size,
100
+ 'mtime' => $mtime,
101
+ 'chksum' => $chksum,
102
+ 'typeflag' => getid3_tar::get_flag_type($typflag),
103
+ 'linkname' => $lnkname,
104
+ 'magic' => $magic,
105
+ 'version' => $ver,
106
+ 'uname' => $uname,
107
+ 'gname' => $gname,
108
+ 'devmajor' => $devmaj,
109
+ 'devminor' => $devmin
110
+ );
111
+ $ThisFileInfo['tar']['files'] = getid3_lib::array_merge_clobber($ThisFileInfo['tar']['files'], getid3_lib::CreateDeepArray($ThisFileInfo['tar']['file_details'][$name]['name'], '/', $size));
112
+ }
113
+ return true;
114
+ }
115
+
116
+ // Parses the file mode to file permissions
117
+ function display_perms($mode) {
118
+ // Determine Type
119
+ if ($mode & 0x1000) $type='p'; // FIFO pipe
120
+ elseif ($mode & 0x2000) $type='c'; // Character special
121
+ elseif ($mode & 0x4000) $type='d'; // Directory
122
+ elseif ($mode & 0x6000) $type='b'; // Block special
123
+ elseif ($mode & 0x8000) $type='-'; // Regular
124
+ elseif ($mode & 0xA000) $type='l'; // Symbolic Link
125
+ elseif ($mode & 0xC000) $type='s'; // Socket
126
+ else $type='u'; // UNKNOWN
127
+
128
+ // Determine permissions
129
+ $owner['read'] = (($mode & 00400) ? 'r' : '-');
130
+ $owner['write'] = (($mode & 00200) ? 'w' : '-');
131
+ $owner['execute'] = (($mode & 00100) ? 'x' : '-');
132
+ $group['read'] = (($mode & 00040) ? 'r' : '-');
133
+ $group['write'] = (($mode & 00020) ? 'w' : '-');
134
+ $group['execute'] = (($mode & 00010) ? 'x' : '-');
135
+ $world['read'] = (($mode & 00004) ? 'r' : '-');
136
+ $world['write'] = (($mode & 00002) ? 'w' : '-');
137
+ $world['execute'] = (($mode & 00001) ? 'x' : '-');
138
+
139
+ // Adjust for SUID, SGID and sticky bit
140
+ if ($mode & 0x800) $owner['execute'] = ($owner['execute'] == 'x') ? 's' : 'S';
141
+ if ($mode & 0x400) $group['execute'] = ($group['execute'] == 'x') ? 's' : 'S';
142
+ if ($mode & 0x200) $world['execute'] = ($world['execute'] == 'x') ? 't' : 'T';
143
+
144
+ $s = sprintf('%1s', $type);
145
+ $s .= sprintf('%1s%1s%1s', $owner['read'], $owner['write'], $owner['execute']);
146
+ $s .= sprintf('%1s%1s%1s', $group['read'], $group['write'], $group['execute']);
147
+ $s .= sprintf('%1s%1s%1s'."\n", $world['read'], $world['write'], $world['execute']);
148
+ return $s;
149
+ }
150
+
151
+ // Converts the file type
152
+ function get_flag_type($typflag) {
153
+ static $flag_types = array(
154
+ '0' => 'LF_NORMAL',
155
+ '1' => 'LF_LINK',
156
+ '2' => 'LF_SYNLINK',
157
+ '3' => 'LF_CHR',
158
+ '4' => 'LF_BLK',
159
+ '5' => 'LF_DIR',
160
+ '6' => 'LF_FIFO',
161
+ '7' => 'LF_CONFIG',
162
+ 'D' => 'LF_DUMPDIR',
163
+ 'K' => 'LF_LONGLINK',
164
+ 'L' => 'LF_LONGNAME',
165
+ 'M' => 'LF_MULTIVOL',
166
+ 'N' => 'LF_NAMES',
167
+ 'S' => 'LF_SPARSE',
168
+ 'V' => 'LF_VOLHDR'
169
+ );
170
+ return @$flag_types[$typflag];
171
+ }
172
+
173
+ }
174
+
175
+ ?>
view/getid3/module.archive.zip.php ADDED
@@ -0,0 +1,416 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /////////////////////////////////////////////////////////////////
3
+ /// getID3() by James Heinrich <info@getid3.org> //
4
+ // available at http://getid3.sourceforge.net //
5
+ // or http://www.getid3.org //
6
+ /////////////////////////////////////////////////////////////////
7
+ // See readme.txt for more details //
8
+ /////////////////////////////////////////////////////////////////
9
+ // //
10
+ // module.archive.zip.php //
11
+ // module for analyzing pkZip files //
12
+ // dependencies: NONE //
13
+ // ///
14
+ /////////////////////////////////////////////////////////////////
15
+
16
+
17
+ class getid3_zip
18
+ {
19
+
20
+ function getid3_zip(&$fd, &$ThisFileInfo) {
21
+
22
+ $ThisFileInfo['fileformat'] = 'zip';
23
+ $ThisFileInfo['zip']['encoding'] = 'ISO-8859-1';
24
+ $ThisFileInfo['zip']['files'] = array();
25
+
26
+ $ThisFileInfo['zip']['compressed_size'] = 0;
27
+ $ThisFileInfo['zip']['uncompressed_size'] = 0;
28
+ $ThisFileInfo['zip']['entries_count'] = 0;
29
+
30
+ if ($ThisFileInfo['filesize'] < pow(2, 31)) {
31
+ $EOCDsearchData = '';
32
+ $EOCDsearchCounter = 0;
33
+ while ($EOCDsearchCounter++ < 512) {
34
+
35
+ fseek($fd, -128 * $EOCDsearchCounter, SEEK_END);
36
+ $EOCDsearchData = fread($fd, 128).$EOCDsearchData;
37
+
38
+ if (strstr($EOCDsearchData, 'PK'."\x05\x06")) {
39
+
40
+ $EOCDposition = strpos($EOCDsearchData, 'PK'."\x05\x06");
41
+ fseek($fd, (-128 * $EOCDsearchCounter) + $EOCDposition, SEEK_END);
42
+ $ThisFileInfo['zip']['end_central_directory'] = $this->ZIPparseEndOfCentralDirectory($fd);
43
+
44
+ fseek($fd, $ThisFileInfo['zip']['end_central_directory']['directory_offset'], SEEK_SET);
45
+ $ThisFileInfo['zip']['entries_count'] = 0;
46
+ while ($centraldirectoryentry = $this->ZIPparseCentralDirectory($fd)) {
47
+ $ThisFileInfo['zip']['central_directory'][] = $centraldirectoryentry;
48
+ $ThisFileInfo['zip']['entries_count']++;
49
+ $ThisFileInfo['zip']['compressed_size'] += $centraldirectoryentry['compressed_size'];
50
+ $ThisFileInfo['zip']['uncompressed_size'] += $centraldirectoryentry['uncompressed_size'];
51
+
52
+ if ($centraldirectoryentry['uncompressed_size'] > 0) {
53
+ $ThisFileInfo['zip']['files'] = getid3_lib::array_merge_clobber($ThisFileInfo['zip']['files'], getid3_lib::CreateDeepArray($centraldirectoryentry['filename'], '/', $centraldirectoryentry['uncompressed_size']));
54
+ }
55
+ }
56
+
57
+ if ($ThisFileInfo['zip']['entries_count'] == 0) {
58
+ $ThisFileInfo['error'][] = 'No Central Directory entries found (truncated file?)';
59
+ return false;
60
+ }
61
+
62
+ if (!empty($ThisFileInfo['zip']['end_central_directory']['comment'])) {
63
+ $ThisFileInfo['zip']['comments']['comment'][] = $ThisFileInfo['zip']['end_central_directory']['comment'];
64
+ }
65
+
66
+ if (isset($ThisFileInfo['zip']['central_directory'][0]['compression_method'])) {
67
+ $ThisFileInfo['zip']['compression_method'] = $ThisFileInfo['zip']['central_directory'][0]['compression_method'];
68
+ }
69
+ if (isset($ThisFileInfo['zip']['central_directory'][0]['flags']['compression_speed'])) {
70
+ $ThisFileInfo['zip']['compression_speed'] = $ThisFileInfo['zip']['central_directory'][0]['flags']['compression_speed'];
71
+ }
72
+ if (isset($ThisFileInfo['zip']['compression_method']) && ($ThisFileInfo['zip']['compression_method'] == 'store') && !isset($ThisFileInfo['zip']['compression_speed'])) {
73
+ $ThisFileInfo['zip']['compression_speed'] = 'store';
74
+ }
75
+
76
+ return true;
77
+
78
+ }
79
+ }
80
+ }
81
+
82
+ if ($this->getZIPentriesFilepointer($fd, $ThisFileInfo)) {
83
+
84
+ // central directory couldn't be found and/or parsed
85
+ // scan through actual file data entries, recover as much as possible from probable trucated file
86
+ if ($ThisFileInfo['zip']['compressed_size'] > ($ThisFileInfo['filesize'] - 46 - 22)) {
87
+ $ThisFileInfo['error'][] = 'Warning: Truncated file! - Total compressed file sizes ('.$ThisFileInfo['zip']['compressed_size'].' bytes) is greater than filesize minus Central Directory and End Of Central Directory structures ('.($ThisFileInfo['filesize'] - 46 - 22).' bytes)';
88
+ }
89
+ $ThisFileInfo['error'][] = 'Cannot find End Of Central Directory - returned list of files in [zip][entries] array may not be complete';
90
+ foreach ($ThisFileInfo['zip']['entries'] as $key => $valuearray) {
91
+ $ThisFileInfo['zip']['files'][$valuearray['filename']] = $valuearray['uncompressed_size'];
92
+ }
93
+ return true;
94
+
95
+ } else {
96
+
97
+ unset($ThisFileInfo['zip']);
98
+ $ThisFileInfo['fileformat'] = '';
99
+ $ThisFileInfo['error'][] = 'Cannot find End Of Central Directory (truncated file?)';
100
+ return false;
101
+
102
+ }
103
+ }
104
+
105
+
106
+ function getZIPHeaderFilepointerTopDown(&$fd, &$ThisFileInfo) {
107
+ $ThisFileInfo['fileformat'] = 'zip';
108
+
109
+ $ThisFileInfo['zip']['compressed_size'] = 0;
110
+ $ThisFileInfo['zip']['uncompressed_size'] = 0;
111
+ $ThisFileInfo['zip']['entries_count'] = 0;
112
+
113
+ rewind($fd);
114
+ while ($fileentry = $this->ZIPparseLocalFileHeader($fd)) {
115
+ $ThisFileInfo['zip']['entries'][] = $fileentry;
116
+ $ThisFileInfo['zip']['entries_count']++;
117
+ }
118
+ if ($ThisFileInfo['zip']['entries_count'] == 0) {
119
+ $ThisFileInfo['error'][] = 'No Local File Header entries found';
120
+ return false;
121
+ }
122
+
123
+ $ThisFileInfo['zip']['entries_count'] = 0;
124
+ while ($centraldirectoryentry = $this->ZIPparseCentralDirectory($fd)) {
125
+ $ThisFileInfo['zip']['central_directory'][] = $centraldirectoryentry;
126
+ $ThisFileInfo['zip']['entries_count']++;
127
+ $ThisFileInfo['zip']['compressed_size'] += $centraldirectoryentry['compressed_size'];
128
+ $ThisFileInfo['zip']['uncompressed_size'] += $centraldirectoryentry['uncompressed_size'];
129
+ }
130
+ if ($ThisFileInfo['zip']['entries_count'] == 0) {
131
+ $ThisFileInfo['error'][] = 'No Central Directory entries found (truncated file?)';
132
+ return false;
133
+ }
134
+
135
+ if ($EOCD = $this->ZIPparseEndOfCentralDirectory($fd)) {
136
+ $ThisFileInfo['zip']['end_central_directory'] = $EOCD;
137
+ } else {
138
+ $ThisFileInfo['error'][] = 'No End Of Central Directory entry found (truncated file?)';
139
+ return false;
140
+ }
141
+
142
+ if (!empty($ThisFileInfo['zip']['end_central_directory']['comment'])) {
143
+ $ThisFileInfo['zip']['comments']['comment'][] = $ThisFileInfo['zip']['end_central_directory']['comment'];
144
+ }
145
+
146
+ return true;
147
+ }
148
+
149
+
150
+ function getZIPentriesFilepointer(&$fd, &$ThisFileInfo) {
151
+ $ThisFileInfo['zip']['compressed_size'] = 0;
152
+ $ThisFileInfo['zip']['uncompressed_size'] = 0;
153
+ $ThisFileInfo['zip']['entries_count'] = 0;
154
+
155
+ rewind($fd);
156
+ while ($fileentry = $this->ZIPparseLocalFileHeader($fd)) {
157
+ $ThisFileInfo['zip']['entries'][] = $fileentry;
158
+ $ThisFileInfo['zip']['entries_count']++;
159
+ $ThisFileInfo['zip']['compressed_size'] += $fileentry['compressed_size'];
160
+ $ThisFileInfo['zip']['uncompressed_size'] += $fileentry['uncompressed_size'];
161
+ }
162
+ if ($ThisFileInfo['zip']['entries_count'] == 0) {
163
+ $ThisFileInfo['error'][] = 'No Local File Header entries found';
164
+ return false;
165
+ }
166
+
167
+ return true;
168
+ }
169
+
170
+
171
+ function ZIPparseLocalFileHeader(&$fd) {
172
+ $LocalFileHeader['offset'] = ftell($fd);
173
+
174
+ $ZIPlocalFileHeader = fread($fd, 30);
175
+
176
+ $LocalFileHeader['raw']['signature'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 0, 4));
177
+ if ($LocalFileHeader['raw']['signature'] != 0x04034B50) {
178
+ // invalid Local File Header Signature
179
+ fseek($fd, $LocalFileHeader['offset'], SEEK_SET); // seek back to where filepointer originally was so it can be handled properly
180
+ return false;
181
+ }
182
+ $LocalFileHeader['raw']['extract_version'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 4, 2));
183
+ $LocalFileHeader['raw']['general_flags'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 6, 2));
184
+ $LocalFileHeader['raw']['compression_method'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 8, 2));
185
+ $LocalFileHeader['raw']['last_mod_file_time'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 10, 2));
186
+ $LocalFileHeader['raw']['last_mod_file_date'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 12, 2));
187
+ $LocalFileHeader['raw']['crc_32'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 14, 4));
188
+ $LocalFileHeader['raw']['compressed_size'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 18, 4));
189
+ $LocalFileHeader['raw']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 22, 4));
190
+ $LocalFileHeader['raw']['filename_length'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 26, 2));
191
+ $LocalFileHeader['raw']['extra_field_length'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 28, 2));
192
+
193
+ $LocalFileHeader['extract_version'] = sprintf('%1.1f', $LocalFileHeader['raw']['extract_version'] / 10);
194
+ $LocalFileHeader['host_os'] = $this->ZIPversionOSLookup(($LocalFileHeader['raw']['extract_version'] & 0xFF00) >> 8);
195
+ $LocalFileHeader['compression_method'] = $this->ZIPcompressionMethodLookup($LocalFileHeader['raw']['compression_method']);
196
+ $LocalFileHeader['compressed_size'] = $LocalFileHeader['raw']['compressed_size'];
197
+ $LocalFileHeader['uncompressed_size'] = $LocalFileHeader['raw']['uncompressed_size'];
198
+ $LocalFileHeader['flags'] = $this->ZIPparseGeneralPurposeFlags($LocalFileHeader['raw']['general_flags'], $LocalFileHeader['raw']['compression_method']);
199
+ $LocalFileHeader['last_modified_timestamp'] = $this->DOStime2UNIXtime($LocalFileHeader['raw']['last_mod_file_date'], $LocalFileHeader['raw']['last_mod_file_time']);
200
+
201
+ $FilenameExtrafieldLength = $LocalFileHeader['raw']['filename_length'] + $LocalFileHeader['raw']['extra_field_length'];
202
+ if ($FilenameExtrafieldLength > 0) {
203
+ $ZIPlocalFileHeader .= fread($fd, $FilenameExtrafieldLength);
204
+
205
+ if ($LocalFileHeader['raw']['filename_length'] > 0) {
206
+ $LocalFileHeader['filename'] = substr($ZIPlocalFileHeader, 30, $LocalFileHeader['raw']['filename_length']);
207
+ }
208
+ if ($LocalFileHeader['raw']['extra_field_length'] > 0) {
209
+ $LocalFileHeader['raw']['extra_field_data'] = substr($ZIPlocalFileHeader, 30 + $LocalFileHeader['raw']['filename_length'], $LocalFileHeader['raw']['extra_field_length']);
210
+ }
211
+ }
212
+
213
+ $LocalFileHeader['data_offset'] = ftell($fd);
214
+ //$LocalFileHeader['compressed_data'] = fread($fd, $LocalFileHeader['raw']['compressed_size']);
215
+ fseek($fd, $LocalFileHeader['raw']['compressed_size'], SEEK_CUR);
216
+
217
+ if ($LocalFileHeader['flags']['data_descriptor_used']) {
218
+ $DataDescriptor = fread($fd, 12);
219
+ $LocalFileHeader['data_descriptor']['crc_32'] = getid3_lib::LittleEndian2Int(substr($DataDescriptor, 0, 4));
220
+ $LocalFileHeader['data_descriptor']['compressed_size'] = getid3_lib::LittleEndian2Int(substr($DataDescriptor, 4, 4));
221
+ $LocalFileHeader['data_descriptor']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($DataDescriptor, 8, 4));
222
+ }
223
+
224
+ return $LocalFileHeader;
225
+ }
226
+
227
+
228
+ function ZIPparseCentralDirectory(&$fd) {
229
+ $CentralDirectory['offset'] = ftell($fd);
230
+
231
+ $ZIPcentralDirectory = fread($fd, 46);
232
+
233
+ $CentralDirectory['raw']['signature'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 0, 4));
234
+ if ($CentralDirectory['raw']['signature'] != 0x02014B50) {
235
+ // invalid Central Directory Signature
236
+ fseek($fd, $CentralDirectory['offset'], SEEK_SET); // seek back to where filepointer originally was so it can be handled properly
237
+ return false;
238
+ }
239
+ $CentralDirectory['raw']['create_version'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 4, 2));
240
+ $CentralDirectory['raw']['extract_version'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 6, 2));
241
+ $CentralDirectory['raw']['general_flags'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 8, 2));
242
+ $CentralDirectory['raw']['compression_method'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 10, 2));
243
+ $CentralDirectory['raw']['last_mod_file_time'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 12, 2));
244
+ $CentralDirectory['raw']['last_mod_file_date'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 14, 2));
245
+ $CentralDirectory['raw']['crc_32'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 16, 4));
246
+ $CentralDirectory['raw']['compressed_size'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 20, 4));
247
+ $CentralDirectory['raw']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 24, 4));
248
+ $CentralDirectory['raw']['filename_length'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 28, 2));
249
+ $CentralDirectory['raw']['extra_field_length'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 30, 2));
250
+ $CentralDirectory['raw']['file_comment_length'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 32, 2));
251
+ $CentralDirectory['raw']['disk_number_start'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 34, 2));
252
+ $CentralDirectory['raw']['internal_file_attrib'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 36, 2));
253
+ $CentralDirectory['raw']['external_file_attrib'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 38, 4));
254
+ $CentralDirectory['raw']['local_header_offset'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 42, 4));
255
+
256
+ $CentralDirectory['entry_offset'] = $CentralDirectory['raw']['local_header_offset'];
257
+ $CentralDirectory['create_version'] = sprintf('%1.1f', $CentralDirectory['raw']['create_version'] / 10);
258
+ $CentralDirectory['extract_version'] = sprintf('%1.1f', $CentralDirectory['raw']['extract_version'] / 10);
259
+ $CentralDirectory['host_os'] = $this->ZIPversionOSLookup(($CentralDirectory['raw']['extract_version'] & 0xFF00) >> 8);
260
+ $CentralDirectory['compression_method'] = $this->ZIPcompressionMethodLookup($CentralDirectory['raw']['compression_method']);
261
+ $CentralDirectory['compressed_size'] = $CentralDirectory['raw']['compressed_size'];
262
+ $CentralDirectory['uncompressed_size'] = $CentralDirectory['raw']['uncompressed_size'];
263
+ $CentralDirectory['flags'] = $this->ZIPparseGeneralPurposeFlags($CentralDirectory['raw']['general_flags'], $CentralDirectory['raw']['compression_method']);
264
+ $CentralDirectory['last_modified_timestamp'] = $this->DOStime2UNIXtime($CentralDirectory['raw']['last_mod_file_date'], $CentralDirectory['raw']['last_mod_file_time']);
265
+
266
+ $FilenameExtrafieldCommentLength = $CentralDirectory['raw']['filename_length'] + $CentralDirectory['raw']['extra_field_length'] + $CentralDirectory['raw']['file_comment_length'];
267
+ if ($FilenameExtrafieldCommentLength > 0) {
268
+ $FilenameExtrafieldComment = fread($fd, $FilenameExtrafieldCommentLength);
269
+
270
+ if ($CentralDirectory['raw']['filename_length'] > 0) {
271
+ $CentralDirectory['filename'] = substr($FilenameExtrafieldComment, 0, $CentralDirectory['raw']['filename_length']);
272
+ }
273
+ if ($CentralDirectory['raw']['extra_field_length'] > 0) {
274
+ $CentralDirectory['raw']['extra_field_data'] = substr($FilenameExtrafieldComment, $CentralDirectory['raw']['filename_length'], $CentralDirectory['raw']['extra_field_length']);
275
+ }
276
+ if ($CentralDirectory['raw']['file_comment_length'] > 0) {
277
+ $CentralDirectory['file_comment'] = substr($FilenameExtrafieldComment, $CentralDirectory['raw']['filename_length'] + $CentralDirectory['raw']['extra_field_length'], $CentralDirectory['raw']['file_comment_length']);
278
+ }
279
+ }
280
+
281
+ return $CentralDirectory;
282
+ }
283
+
284
+ function ZIPparseEndOfCentralDirectory(&$fd) {
285
+ $EndOfCentralDirectory['offset'] = ftell($fd);
286
+
287
+ $ZIPendOfCentralDirectory = fread($fd, 22);
288
+
289
+ $EndOfCentralDirectory['signature'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 0, 4));
290
+ if ($EndOfCentralDirectory['signature'] != 0x06054B50) {
291
+ // invalid End Of Central Directory Signature
292
+ fseek($fd, $EndOfCentralDirectory['offset'], SEEK_SET); // seek back to where filepointer originally was so it can be handled properly
293
+ return false;
294
+ }
295
+ $EndOfCentralDirectory['disk_number_current'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 4, 2));
296
+ $EndOfCentralDirectory['disk_number_start_directory'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 6, 2));
297
+ $EndOfCentralDirectory['directory_entries_this_disk'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 8, 2));
298
+ $EndOfCentralDirectory['directory_entries_total'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 10, 2));
299
+ $EndOfCentralDirectory['directory_size'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 12, 4));
300
+ $EndOfCentralDirectory['directory_offset'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 16, 4));
301
+ $EndOfCentralDirectory['comment_length'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 20, 2));
302
+
303
+ if ($EndOfCentralDirectory['comment_length'] > 0) {
304
+ $EndOfCentralDirectory['comment'] = fread($fd, $EndOfCentralDirectory['comment_length']);
305
+ }
306
+
307
+ return $EndOfCentralDirectory;
308
+ }
309
+
310
+
311
+ function ZIPparseGeneralPurposeFlags($flagbytes, $compressionmethod) {
312
+ $ParsedFlags['encrypted'] = (bool) ($flagbytes & 0x0001);
313
+
314
+ switch ($compressionmethod) {
315
+ case 6:
316
+ $ParsedFlags['dictionary_size'] = (($flagbytes & 0x0002) ? 8192 : 4096);
317
+ $ParsedFlags['shannon_fano_trees'] = (($flagbytes & 0x0004) ? 3 : 2);
318
+ break;
319
+
320
+ case 8:
321
+ case 9:
322
+ switch (($flagbytes & 0x0006) >> 1) {
323
+ case 0:
324
+ $ParsedFlags['compression_speed'] = 'normal';
325
+ break;
326
+ case 1:
327
+ $ParsedFlags['compression_speed'] = 'maximum';
328
+ break;
329
+ case 2:
330
+ $ParsedFlags['compression_speed'] = 'fast';
331
+ break;
332
+ case 3:
333
+ $ParsedFlags['compression_speed'] = 'superfast';
334
+ break;
335
+ }
336
+ break;
337
+ }
338
+ $ParsedFlags['data_descriptor_used'] = (bool) ($flagbytes & 0x0008);
339
+
340
+ return $ParsedFlags;
341
+ }
342
+
343
+
344
+ function ZIPversionOSLookup($index) {
345
+ static $ZIPversionOSLookup = array(
346
+ 0 => 'MS-DOS and OS/2 (FAT / VFAT / FAT32 file systems)',
347
+ 1 => 'Amiga',
348
+ 2 => 'OpenVMS',
349
+ 3 => 'Unix',
350
+ 4 => 'VM/CMS',
351
+ 5 => 'Atari ST',
352
+ 6 => 'OS/2 H.P.F.S.',
353
+ 7 => 'Macintosh',
354
+ 8 => 'Z-System',
355
+ 9 => 'CP/M',
356
+ 10 => 'Windows NTFS',
357
+ 11 => 'MVS',
358
+ 12 => 'VSE',
359
+ 13 => 'Acorn Risc',
360
+ 14 => 'VFAT',
361
+ 15 => 'Alternate MVS',
362
+ 16 => 'BeOS',
363
+ 17 => 'Tandem'
364
+ );
365
+
366
+ return (isset($ZIPversionOSLookup[$index]) ? $ZIPversionOSLookup[$index] : '[unknown]');
367
+ }
368
+
369
+ function ZIPcompressionMethodLookup($index) {
370
+ static $ZIPcompressionMethodLookup = array(
371
+ 0 => 'store',
372
+ 1 => 'shrink',
373
+ 2 => 'reduce-1',
374
+ 3 => 'reduce-2',
375
+ 4 => 'reduce-3',
376
+ 5 => 'reduce-4',
377
+ 6 => 'implode',
378
+ 7 => 'tokenize',
379
+ 8 => 'deflate',
380
+ 9 => 'deflate64',
381
+ 10 => 'PKWARE Date Compression Library Imploding'
382
+ );
383
+
384
+ return (isset($ZIPcompressionMethodLookup[$index]) ? $ZIPcompressionMethodLookup[$index] : '[unknown]');
385
+ }
386
+
387
+ function DOStime2UNIXtime($DOSdate, $DOStime) {
388
+ // wFatDate
389
+ // Specifies the MS-DOS date. The date is a packed 16-bit value with the following format:
390
+ // Bits Contents
391
+ // 0-4 Day of the month (1-31)
392
+ // 5-8 Month (1 = January, 2 = February, and so on)
393
+ // 9-15 Year offset from 1980 (add 1980 to get actual year)
394
+
395
+ $UNIXday = ($DOSdate & 0x001F);
396
+ $UNIXmonth = (($DOSdate & 0x01E0) >> 5);
397
+ $UNIXyear = (($DOSdate & 0xFE00) >> 9) + 1980;
398
+
399
+ // wFatTime
400
+ // Specifies the MS-DOS time. The time is a packed 16-bit value with the following format:
401
+ // Bits Contents
402
+ // 0-4 Second divided by 2
403
+ // 5-10 Minute (0-59)
404
+ // 11-15 Hour (0-23 on a 24-hour clock)
405
+
406
+ $UNIXsecond = ($DOStime & 0x001F) * 2;
407
+ $UNIXminute = (($DOStime & 0x07E0) >> 5);
408
+ $UNIXhour = (($DOStime & 0xF800) >> 11);
409
+
410
+ return gmmktime($UNIXhour, $UNIXminute, $UNIXsecond, $UNIXmonth, $UNIXday, $UNIXyear);
411
+ }
412
+
413
+ }
414
+
415
+
416
+ ?>
view/getid3/module.audio-video.asf.php ADDED
@@ -0,0 +1,1673 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /////////////////////////////////////////////////////////////////
3
+ /// getID3() by James Heinrich <info@getid3.org> //
4
+ // available at http://getid3.sourceforge.net //
5
+ // or http://www.getid3.org //
6
+ /////////////////////////////////////////////////////////////////
7
+ // See readme.txt for more details //
8
+ /////////////////////////////////////////////////////////////////
9
+ // //
10
+ // module.audio-video.asf.php //
11
+ // module for analyzing ASF, WMA and WMV files //
12
+ // dependencies: module.audio-video.riff.php //
13
+ // ///
14
+ /////////////////////////////////////////////////////////////////
15
+
16
+ getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true);
17
+
18
+ $GUIDarray = getid3_asf::KnownGUIDs();
19
+ foreach ($GUIDarray as $GUIDname => $hexstringvalue) {
20
+ // initialize all GUID constants
21
+ define($GUIDname, getid3_asf::GUIDtoBytestring($hexstringvalue));
22
+ }
23
+
24
+
25
+
26
+ class getid3_asf
27
+ {
28
+
29
+ function getid3_asf(&$fd, &$ThisFileInfo) {
30
+
31
+ // Shortcuts
32
+ $thisfile_audio = &$ThisFileInfo['audio'];
33
+ $thisfile_video = &$ThisFileInfo['video'];
34
+ $ThisFileInfo['asf'] = array();
35
+ $thisfile_asf = &$ThisFileInfo['asf'];
36
+ $thisfile_asf['comments'] = array();
37
+ $thisfile_asf_comments = &$thisfile_asf['comments'];
38
+ $thisfile_asf['header_object'] = array();
39
+ $thisfile_asf_headerobject = &$thisfile_asf['header_object'];
40
+
41
+
42
+ // ASF structure:
43
+ // * Header Object [required]
44
+ // * File Properties Object [required] (global file attributes)
45
+ // * Stream Properties Object [required] (defines media stream & characteristics)
46
+ // * Header Extension Object [required] (additional functionality)
47
+ // * Content Description Object (bibliographic information)
48
+ // * Script Command Object (commands for during playback)
49
+ // * Marker Object (named jumped points within the file)
50
+ // * Data Object [required]
51
+ // * Data Packets
52
+ // * Index Object
53
+
54
+ // Header Object: (mandatory, one only)
55
+ // Field Name Field Type Size (bits)
56
+ // Object ID GUID 128 // GUID for header object - GETID3_ASF_Header_Object
57
+ // Object Size QWORD 64 // size of header object, including 30 bytes of Header Object header
58
+ // Number of Header Objects DWORD 32 // number of objects in header object
59
+ // Reserved1 BYTE 8 // hardcoded: 0x01
60
+ // Reserved2 BYTE 8 // hardcoded: 0x02
61
+
62
+ $ThisFileInfo['fileformat'] = 'asf';
63
+
64
+ fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
65
+ $HeaderObjectData = fread($fd, 30);
66
+
67
+ $thisfile_asf_headerobject['objectid'] = substr($HeaderObjectData, 0, 16);
68
+ $thisfile_asf_headerobject['objectid_guid'] = $this->BytestringToGUID($thisfile_asf_headerobject['objectid']);
69
+ if ($thisfile_asf_headerobject['objectid'] != GETID3_ASF_Header_Object) {
70
+ $ThisFileInfo['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).'}';
71
+ unset($ThisFileInfo['fileformat']);
72
+ unset($ThisFileInfo['asf']);
73
+ return false;
74
+ break;
75
+ }
76
+ $thisfile_asf_headerobject['objectsize'] = getid3_lib::LittleEndian2Int(substr($HeaderObjectData, 16, 8));
77
+ $thisfile_asf_headerobject['headerobjects'] = getid3_lib::LittleEndian2Int(substr($HeaderObjectData, 24, 4));
78
+ $thisfile_asf_headerobject['reserved1'] = getid3_lib::LittleEndian2Int(substr($HeaderObjectData, 28, 1));
79
+ $thisfile_asf_headerobject['reserved2'] = getid3_lib::LittleEndian2Int(substr($HeaderObjectData, 29, 1));
80
+
81
+ $ASFHeaderData = fread($fd, $thisfile_asf_headerobject['objectsize'] - 30);
82
+ $offset = 0;
83
+
84
+ for ($HeaderObjectsCounter = 0; $HeaderObjectsCounter < $thisfile_asf_headerobject['headerobjects']; $HeaderObjectsCounter++) {
85
+ $NextObjectGUID = substr($ASFHeaderData, $offset, 16);
86
+ $offset += 16;
87
+ $NextObjectGUIDtext = $this->BytestringToGUID($NextObjectGUID);
88
+ $NextObjectSize = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
89
+ $offset += 8;
90
+ switch ($NextObjectGUID) {
91
+
92
+ case GETID3_ASF_File_Properties_Object:
93
+ // File Properties Object: (mandatory, one only)
94
+ // Field Name Field Type Size (bits)
95
+ // Object ID GUID 128 // GUID for file properties object - GETID3_ASF_File_Properties_Object
96
+ // Object Size QWORD 64 // size of file properties object, including 104 bytes of File Properties Object header
97
+ // File ID GUID 128 // unique ID - identical to File ID in Data Object
98
+ // File Size QWORD 64 // entire file in bytes. Invalid if Broadcast Flag == 1
99
+ // Creation Date QWORD 64 // date & time of file creation. Maybe invalid if Broadcast Flag == 1
100
+ // Data Packets Count QWORD 64 // number of data packets in Data Object. Invalid if Broadcast Flag == 1
101
+ // Play Duration QWORD 64 // playtime, in 100-nanosecond units. Invalid if Broadcast Flag == 1
102
+ // Send Duration QWORD 64 // time needed to send file, in 100-nanosecond units. Players can ignore this value. Invalid if Broadcast Flag == 1
103
+ // 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
104
+ // Flags DWORD 32 //
105
+ // * Broadcast Flag bits 1 (0x01) // file is currently being written, some header values are invalid
106
+ // * Seekable Flag bits 1 (0x02) // is file seekable
107
+ // * Reserved bits 30 (0xFFFFFFFC) // reserved - set to zero
108
+ // Minimum Data Packet Size DWORD 32 // in bytes. should be same as Maximum Data Packet Size. Invalid if Broadcast Flag == 1
109
+ // Maximum Data Packet Size DWORD 32 // in bytes. should be same as Minimum Data Packet Size. Invalid if Broadcast Flag == 1
110
+ // Maximum Bitrate DWORD 32 // maximum instantaneous bitrate in bits per second for entire file, including all data streams and ASF overhead
111
+
112
+ // shortcut
113
+ $thisfile_asf['file_properties_object'] = array();
114
+ $thisfile_asf_filepropertiesobject = &$thisfile_asf['file_properties_object'];
115
+
116
+ $thisfile_asf_filepropertiesobject['objectid'] = $NextObjectGUID;
117
+ $thisfile_asf_filepropertiesobject['objectid_guid'] = $NextObjectGUIDtext;
118
+ $thisfile_asf_filepropertiesobject['objectsize'] = $NextObjectSize;
119
+ $thisfile_asf_filepropertiesobject['fileid'] = substr($ASFHeaderData, $offset, 16);
120
+ $offset += 16;
121
+ $thisfile_asf_filepropertiesobject['fileid_guid'] = $this->BytestringToGUID($thisfile_asf_filepropertiesobject['fileid']);
122
+ $thisfile_asf_filepropertiesobject['filesize'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
123
+ $offset += 8;
124
+ $thisfile_asf_filepropertiesobject['creation_date'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
125
+ $thisfile_asf_filepropertiesobject['creation_date_unix'] = $this->FILETIMEtoUNIXtime($thisfile_asf_filepropertiesobject['creation_date']);
126
+ $offset += 8;
127
+ $thisfile_asf_filepropertiesobject['data_packets'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
128
+ $offset += 8;
129
+ $thisfile_asf_filepropertiesobject['play_duration'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
130
+ $offset += 8;
131
+ $thisfile_asf_filepropertiesobject['send_duration'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
132
+ $offset += 8;
133
+ $thisfile_asf_filepropertiesobject['preroll'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
134
+ $offset += 8;
135
+ $thisfile_asf_filepropertiesobject['flags_raw'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
136
+ $offset += 4;
137
+ $thisfile_asf_filepropertiesobject['flags']['broadcast'] = (bool) ($thisfile_asf_filepropertiesobject['flags_raw'] & 0x0001);
138
+ $thisfile_asf_filepropertiesobject['flags']['seekable'] = (bool) ($thisfile_asf_filepropertiesobject['flags_raw'] & 0x0002);
139
+
140
+ $thisfile_asf_filepropertiesobject['min_packet_size'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
141
+ $offset += 4;
142
+ $thisfile_asf_filepropertiesobject['max_packet_size'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
143
+ $offset += 4;
144
+ $thisfile_asf_filepropertiesobject['max_bitrate'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
145
+ $offset += 4;
146
+
147
+ if ($thisfile_asf_filepropertiesobject['flags']['broadcast']) {
148
+
149
+ // broadcast flag is set, some values invalid
150
+ unset($thisfile_asf_filepropertiesobject['filesize']);
151
+ unset($thisfile_asf_filepropertiesobject['data_packets']);
152
+ unset($thisfile_asf_filepropertiesobject['play_duration']);
153
+ unset($thisfile_asf_filepropertiesobject['send_duration']);
154
+ unset($thisfile_asf_filepropertiesobject['min_packet_size']);
155
+ unset($thisfile_asf_filepropertiesobject['max_packet_size']);
156
+
157
+ } else {
158
+
159
+ // broadcast flag NOT set, perform calculations
160
+ $ThisFileInfo['playtime_seconds'] = ($thisfile_asf_filepropertiesobject['play_duration'] / 10000000) - ($thisfile_asf_filepropertiesobject['preroll'] / 1000);
161
+
162
+ //$ThisFileInfo['bitrate'] = $thisfile_asf_filepropertiesobject['max_bitrate'];
163
+ $ThisFileInfo['bitrate'] = ((isset($thisfile_asf_filepropertiesobject['filesize']) ? $thisfile_asf_filepropertiesobject['filesize'] : $ThisFileInfo['filesize']) * 8) / $ThisFileInfo['playtime_seconds'];
164
+ }
165
+ break;
166
+
167
+ case GETID3_ASF_Stream_Properties_Object:
168
+ // Stream Properties Object: (mandatory, one per media stream)
169
+ // Field Name Field Type Size (bits)
170
+ // Object ID GUID 128 // GUID for stream properties object - GETID3_ASF_Stream_Properties_Object
171
+ // Object Size QWORD 64 // size of stream properties object, including 78 bytes of Stream Properties Object header
172
+ // Stream Type GUID 128 // GETID3_ASF_Audio_Media, GETID3_ASF_Video_Media or GETID3_ASF_Command_Media
173
+ // Error Correction Type GUID 128 // GETID3_ASF_Audio_Spread for audio-only streams, GETID3_ASF_No_Error_Correction for other stream types
174
+ // Time Offset QWORD 64 // 100-nanosecond units. typically zero. added to all timestamps of samples in the stream
175
+ // Type-Specific Data Length DWORD 32 // number of bytes for Type-Specific Data field
176
+ // Error Correction Data Length DWORD 32 // number of bytes for Error Correction Data field
177
+ // Flags WORD 16 //
178
+ // * Stream Number bits 7 (0x007F) // number of this stream. 1 <= valid <= 127
179
+ // * Reserved bits 8 (0x7F80) // reserved - set to zero
180
+ // * Encrypted Content Flag bits 1 (0x8000) // stream contents encrypted if set
181
+ // Reserved DWORD 32 // reserved - set to zero
182
+ // Type-Specific Data BYTESTREAM variable // type-specific format data, depending on value of Stream Type
183
+ // Error Correction Data BYTESTREAM variable // error-correction-specific format data, depending on value of Error Correct Type
184
+
185
+ // There is one GETID3_ASF_Stream_Properties_Object for each stream (audio, video) but the
186
+ // stream number isn't known until halfway through decoding the structure, hence it
187
+ // it is decoded to a temporary variable and then stuck in the appropriate index later
188
+
189
+ $StreamPropertiesObjectData['objectid'] = $NextObjectGUID;
190
+ $StreamPropertiesObjectData['objectid_guid'] = $NextObjectGUIDtext;
191
+ $StreamPropertiesObjectData['objectsize'] = $NextObjectSize;
192
+ $StreamPropertiesObjectData['stream_type'] = substr($ASFHeaderData, $offset, 16);
193
+ $offset += 16;
194
+ $StreamPropertiesObjectData['stream_type_guid'] = $this->BytestringToGUID($StreamPropertiesObjectData['stream_type']);
195
+ $StreamPropertiesObjectData['error_correct_type'] = substr($ASFHeaderData, $offset, 16);
196
+ $offset += 16;
197
+ $StreamPropertiesObjectData['error_correct_guid'] = $this->BytestringToGUID($StreamPropertiesObjectData['error_correct_type']);
198
+ $StreamPropertiesObjectData['time_offset'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
199
+ $offset += 8;
200
+ $StreamPropertiesObjectData['type_data_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
201
+ $offset += 4;
202
+ $StreamPropertiesObjectData['error_data_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
203
+ $offset += 4;
204
+ $StreamPropertiesObjectData['flags_raw'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
205
+ $offset += 2;
206
+ $StreamPropertiesObjectStreamNumber = $StreamPropertiesObjectData['flags_raw'] & 0x007F;
207
+ $StreamPropertiesObjectData['flags']['encrypted'] = (bool) ($StreamPropertiesObjectData['flags_raw'] & 0x8000);
208
+
209
+ $offset += 4; // reserved - DWORD
210
+ $StreamPropertiesObjectData['type_specific_data'] = substr($ASFHeaderData, $offset, $StreamPropertiesObjectData['type_data_length']);
211
+ $offset += $StreamPropertiesObjectData['type_data_length'];
212
+ $StreamPropertiesObjectData['error_correct_data'] = substr($ASFHeaderData, $offset, $StreamPropertiesObjectData['error_data_length']);
213
+ $offset += $StreamPropertiesObjectData['error_data_length'];
214
+
215
+ switch ($StreamPropertiesObjectData['stream_type']) {
216
+
217
+ case GETID3_ASF_Audio_Media:
218
+ $thisfile_audio['dataformat'] = (!empty($thisfile_audio['dataformat']) ? $thisfile_audio['dataformat'] : 'asf');
219
+ $thisfile_audio['bitrate_mode'] = (!empty($thisfile_audio['bitrate_mode']) ? $thisfile_audio['bitrate_mode'] : 'cbr');
220
+
221
+ $audiodata = getid3_riff::RIFFparseWAVEFORMATex(substr($StreamPropertiesObjectData['type_specific_data'], 0, 16));
222
+ unset($audiodata['raw']);
223
+ $thisfile_audio = getid3_lib::array_merge_noclobber($audiodata, $thisfile_audio);
224
+ break;
225
+
226
+ case GETID3_ASF_Video_Media:
227
+ $thisfile_video['dataformat'] = (!empty($thisfile_video['dataformat']) ? $thisfile_video['dataformat'] : 'asf');
228
+ $thisfile_video['bitrate_mode'] = (!empty($thisfile_video['bitrate_mode']) ? $thisfile_video['bitrate_mode'] : 'cbr');
229
+ break;
230
+
231
+ case GETID3_ASF_Command_Media:
232
+ default:
233
+ // do nothing
234
+ break;
235
+
236
+ }
237
+
238
+ $thisfile_asf['stream_properties_object'][$StreamPropertiesObjectStreamNumber] = $StreamPropertiesObjectData;
239
+ unset($StreamPropertiesObjectData); // clear for next stream, if any
240
+ break;
241
+
242
+ case GETID3_ASF_Header_Extension_Object:
243
+ // Header Extension Object: (mandatory, one only)
244
+ // Field Name Field Type Size (bits)
245
+ // Object ID GUID 128 // GUID for Header Extension object - GETID3_ASF_Header_Extension_Object
246
+ // Object Size QWORD 64 // size of Header Extension object, including 46 bytes of Header Extension Object header
247
+ // Reserved Field 1 GUID 128 // hardcoded: GETID3_ASF_Reserved_1
248
+ // Reserved Field 2 WORD 16 // hardcoded: 0x00000006
249
+ // Header Extension Data Size DWORD 32 // in bytes. valid: 0, or > 24. equals object size minus 46
250
+ // Header Extension Data BYTESTREAM variable // array of zero or more extended header objects
251
+
252
+ // shortcut
253
+ $thisfile_asf['header_extension_object'] = array();
254
+ $thisfile_asf_headerextensionobject = &$thisfile_asf['header_extension_object'];
255
+
256
+ $thisfile_asf_headerextensionobject['objectid'] = $NextObjectGUID;
257
+ $thisfile_asf_headerextensionobject['objectid_guid'] = $NextObjectGUIDtext;
258
+ $thisfile_asf_headerextensionobject['objectsize'] = $NextObjectSize;
259
+ $thisfile_asf_headerextensionobject['reserved_1'] = substr($ASFHeaderData, $offset, 16);
260
+ $offset += 16;
261
+ $thisfile_asf_headerextensionobject['reserved_1_guid'] = $this->BytestringToGUID($thisfile_asf_headerextensionobject['reserved_1']);
262
+ if ($thisfile_asf_headerextensionobject['reserved_1'] != GETID3_ASF_Reserved_1) {
263
+ $ThisFileInfo['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).')';
264
+ //return false;
265
+ break;
266
+ }
267
+ $thisfile_asf_headerextensionobject['reserved_2'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
268
+ $offset += 2;
269
+ if ($thisfile_asf_headerextensionobject['reserved_2'] != 6) {
270
+ $ThisFileInfo['warning'][] = 'header_extension_object.reserved_2 ('.getid3_lib::PrintHexBytes($thisfile_asf_headerextensionobject['reserved_2']).') does not match expected value of "6"';
271
+ //return false;
272
+ break;
273
+ }
274
+ $thisfile_asf_headerextensionobject['extension_data_size'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
275
+ $offset += 4;
276
+ $thisfile_asf_headerextensionobject['extension_data'] = substr($ASFHeaderData, $offset, $thisfile_asf_headerextensionobject['extension_data_size']);
277
+ $offset += $thisfile_asf_headerextensionobject['extension_data_size'];
278
+ break;
279
+
280
+ case GETID3_ASF_Codec_List_Object:
281
+ // Codec List Object: (optional, one only)
282
+ // Field Name Field Type Size (bits)
283
+ // Object ID GUID 128 // GUID for Codec List object - GETID3_ASF_Codec_List_Object
284
+ // Object Size QWORD 64 // size of Codec List object, including 44 bytes of Codec List Object header
285
+ // Reserved GUID 128 // hardcoded: 86D15241-311D-11D0-A3A4-00A0C90348F6
286
+ // Codec Entries Count DWORD 32 // number of entries in Codec Entries array
287
+ // Codec Entries array of: variable //
288
+ // * Type WORD 16 // 0x0001 = Video Codec, 0x0002 = Audio Codec, 0xFFFF = Unknown Codec
289
+ // * Codec Name Length WORD 16 // number of Unicode characters stored in the Codec Name field
290
+ // * Codec Name WCHAR variable // array of Unicode characters - name of codec used to create the content
291
+ // * Codec Description Length WORD 16 // number of Unicode characters stored in the Codec Description field
292
+ // * Codec Description WCHAR variable // array of Unicode characters - description of format used to create the content
293
+ // * Codec Information Length WORD 16 // number of Unicode characters stored in the Codec Information field
294
+ // * Codec Information BYTESTREAM variable // opaque array of information bytes about the codec used to create the content
295
+
296
+ // shortcut
297
+ $thisfile_asf['codec_list_object'] = array();
298
+ $thisfile_asf_codeclistobject = &$thisfile_asf['codec_list_object'];
299
+
300
+ $thisfile_asf_codeclistobject['objectid'] = $NextObjectGUID;
301
+ $thisfile_asf_codeclistobject['objectid_guid'] = $NextObjectGUIDtext;
302
+ $thisfile_asf_codeclistobject['objectsize'] = $NextObjectSize;
303
+ $thisfile_asf_codeclistobject['reserved'] = substr($ASFHeaderData, $offset, 16);
304
+ $offset += 16;
305
+ $thisfile_asf_codeclistobject['reserved_guid'] = $this->BytestringToGUID($thisfile_asf_codeclistobject['reserved']);
306
+ if ($thisfile_asf_codeclistobject['reserved'] != $this->GUIDtoBytestring('86D15241-311D-11D0-A3A4-00A0C90348F6')) {
307
+ $ThisFileInfo['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}';
308
+ //return false;
309
+ break;
310
+ }
311
+ $thisfile_asf_codeclistobject['codec_entries_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
312
+ $offset += 4;
313
+ for ($CodecEntryCounter = 0; $CodecEntryCounter < $thisfile_asf_codeclistobject['codec_entries_count']; $CodecEntryCounter++) {
314
+ // shortcut
315
+ $thisfile_asf_codeclistobject['codec_entries'][$CodecEntryCounter] = array();
316
+ $thisfile_asf_codeclistobject_codecentries_current = &$thisfile_asf_codeclistobject['codec_entries'][$CodecEntryCounter];
317
+
318
+ $thisfile_asf_codeclistobject_codecentries_current['type_raw'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
319
+ $offset += 2;
320
+ $thisfile_asf_codeclistobject_codecentries_current['type'] = $this->ASFCodecListObjectTypeLookup($thisfile_asf_codeclistobject_codecentries_current['type_raw']);
321
+
322
+ $CodecNameLength = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)) * 2; // 2 bytes per character
323
+ $offset += 2;
324
+ $thisfile_asf_codeclistobject_codecentries_current['name'] = substr($ASFHeaderData, $offset, $CodecNameLength);
325
+ $offset += $CodecNameLength;
326
+
327
+ $CodecDescriptionLength = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)) * 2; // 2 bytes per character
328
+ $offset += 2;
329
+ $thisfile_asf_codeclistobject_codecentries_current['description'] = substr($ASFHeaderData, $offset, $CodecDescriptionLength);
330
+ $offset += $CodecDescriptionLength;
331
+
332
+ $CodecInformationLength = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
333
+ $offset += 2;
334
+ $thisfile_asf_codeclistobject_codecentries_current['information'] = substr($ASFHeaderData, $offset, $CodecInformationLength);
335
+ $offset += $CodecInformationLength;
336
+
337
+ if ($thisfile_asf_codeclistobject_codecentries_current['type_raw'] == 2) {
338
+ // audio codec
339
+ if (strpos($thisfile_asf_codeclistobject_codecentries_current['description'], ',') === false) {
340
+ $ThisFileInfo['error'][] = '[asf][codec_list_object][codec_entries]['.$CodecEntryCounter.'][description] expected to contain comma-seperated list of parameters: "'.$thisfile_asf_codeclistobject_codecentries_current['description'].'"';
341
+ return false;
342
+ }
343
+ list($AudioCodecBitrate, $AudioCodecFrequency, $AudioCodecChannels) = explode(',', $this->TrimConvert($thisfile_asf_codeclistobject_codecentries_current['description']));
344
+ $thisfile_audio['codec'] = $this->TrimConvert($thisfile_asf_codeclistobject_codecentries_current['name']);
345
+
346
+ if (!isset($thisfile_audio['bitrate']) && strstr($AudioCodecBitrate, 'kbps')) {
347
+ $thisfile_audio['bitrate'] = (int) (trim(str_replace('kbps', '', $AudioCodecBitrate)) * 1000);
348
+ }
349
+ //if (!isset($thisfile_video['bitrate']) && isset($thisfile_audio['bitrate']) && isset($thisfile_asf['file_properties_object']['max_bitrate']) && ($thisfile_asf_codeclistobject['codec_entries_count'] > 1)) {
350
+ if (!@$thisfile_video['bitrate'] && @$thisfile_audio['bitrate'] && @$ThisFileInfo['bitrate']) {
351
+ //$thisfile_video['bitrate'] = $thisfile_asf['file_properties_object']['max_bitrate'] - $thisfile_audio['bitrate'];
352
+ $thisfile_video['bitrate'] = $ThisFileInfo['bitrate'] - $thisfile_audio['bitrate'];
353
+ }
354
+
355
+ $AudioCodecFrequency = (int) trim(str_replace('kHz', '', $AudioCodecFrequency));
356
+ switch ($AudioCodecFrequency) {
357
+ case 8:
358
+ case 8000:
359
+ $thisfile_audio['sample_rate'] = 8000;
360
+ break;
361
+
362
+ case 11:
363
+ case 11025:
364
+ $thisfile_audio['sample_rate'] = 11025;
365
+ break;
366
+
367
+ case 12:
368
+ case 12000:
369
+ $thisfile_audio['sample_rate'] = 12000;
370
+ break;
371
+
372
+ case 16:
373
+ case 16000:
374
+ $thisfile_audio['sample_rate'] = 16000;
375
+ break;
376
+
377
+ case 22:
378
+ case 22050:
379
+ $thisfile_audio['sample_rate'] = 22050;
380
+ break;
381
+
382
+ case 24:
383
+ case 24000:
384
+ $thisfile_audio['sample_rate'] = 24000;
385
+ break;
386
+
387
+ case 32:
388
+ case 32000:
389
+ $thisfile_audio['sample_rate'] = 32000;
390
+ break;
391
+
392
+ case 44:
393
+ case 441000:
394
+ $thisfile_audio['sample_rate'] = 44100;
395
+ break;
396
+
397
+ case 48:
398
+ case 48000:
399
+ $thisfile_audio['sample_rate'] = 48000;
400
+ break;
401
+
402
+ default:
403
+ $ThisFileInfo['warning'][] = 'unknown frequency: "'.$AudioCodecFrequency.'" ('.$this->TrimConvert($thisfile_asf_codeclistobject_codecentries_current['description']).')';
404
+ break;
405
+ }
406
+
407
+ if (!isset($thisfile_audio['channels'])) {
408
+ if (strstr($AudioCodecChannels, 'stereo')) {
409
+ $thisfile_audio['channels'] = 2;
410
+ } elseif (strstr($AudioCodecChannels, 'mono')) {
411
+ $thisfile_audio['channels'] = 1;
412
+ }
413
+ }
414
+ }
415
+ }
416
+ break;
417
+
418
+ case GETID3_ASF_Script_Command_Object:
419
+ // Script Command Object: (optional, one only)
420
+ // Field Name Field Type Size (bits)
421
+ // Object ID GUID 128 // GUID for Script Command object - GETID3_ASF_Script_Command_Object
422
+ // Object Size QWORD 64 // size of Script Command object, including 44 bytes of Script Command Object header
423
+ // Reserved GUID 128 // hardcoded: 4B1ACBE3-100B-11D0-A39B-00A0C90348F6
424
+ // Commands Count WORD 16 // number of Commands structures in the Script Commands Objects
425
+ // Command Types Count WORD 16 // number of Command Types structures in the Script Commands Objects
426
+ // Command Types array of: variable //
427
+ // * Command Type Name Length WORD 16 // number of Unicode characters for Command Type Name
428
+ // * Command Type Name WCHAR variable // array of Unicode characters - name of a type of command
429
+ // Commands array of: variable //
430
+ // * Presentation Time DWORD 32 // presentation time of that command, in milliseconds
431
+ // * Type Index WORD 16 // type of this command, as a zero-based index into the array of Command Types of this object
432
+ // * Command Name Length WORD 16 // number of Unicode characters for Command Name
433
+ // * Command Name WCHAR variable // array of Unicode characters - name of this command
434
+
435
+ // shortcut
436
+ $thisfile_asf['script_command_object'] = array();
437
+ $thisfile_asf_scriptcommandobject = &$thisfile_asf['script_command_object'];
438
+
439
+ $thisfile_asf_scriptcommandobject['objectid'] = $NextObjectGUID;
440
+ $thisfile_asf_scriptcommandobject['objectid_guid'] = $NextObjectGUIDtext;
441
+ $thisfile_asf_scriptcommandobject['objectsize'] = $NextObjectSize;
442
+ $thisfile_asf_scriptcommandobject['reserved'] = substr($ASFHeaderData, $offset, 16);
443
+ $offset += 16;
444
+ $thisfile_asf_scriptcommandobject['reserved_guid'] = $this->BytestringToGUID($thisfile_asf_scriptcommandobject['reserved']);
445
+ if ($thisfile_asf_scriptcommandobject['reserved'] != $this->GUIDtoBytestring('4B1ACBE3-100B-11D0-A39B-00A0C90348F6')) {
446
+ $ThisFileInfo['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}';
447
+ //return false;
448
+ break;
449
+ }
450
+ $thisfile_asf_scriptcommandobject['commands_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
451
+ $offset += 2;
452
+ $thisfile_asf_scriptcommandobject['command_types_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
453
+ $offset += 2;
454
+ for ($CommandTypesCounter = 0; $CommandTypesCounter < $thisfile_asf_scriptcommandobject['command_types_count']; $CommandTypesCounter++) {
455
+ $CommandTypeNameLength = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)) * 2; // 2 bytes per character
456
+ $offset += 2;
457
+ $thisfile_asf_scriptcommandobject['command_types'][$CommandTypesCounter]['name'] = substr($ASFHeaderData, $offset, $CommandTypeNameLength);
458
+ $offset += $CommandTypeNameLength;
459
+ }
460
+ for ($CommandsCounter = 0; $CommandsCounter < $thisfile_asf_scriptcommandobject['commands_count']; $CommandsCounter++) {
461
+ $thisfile_asf_scriptcommandobject['commands'][$CommandsCounter]['presentation_time'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
462
+ $offset += 4;
463
+ $thisfile_asf_scriptcommandobject['commands'][$CommandsCounter]['type_index'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
464
+ $offset += 2;
465
+
466
+ $CommandTypeNameLength = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)) * 2; // 2 bytes per character
467
+ $offset += 2;
468
+ $thisfile_asf_scriptcommandobject['commands'][$CommandsCounter]['name'] = substr($ASFHeaderData, $offset, $CommandTypeNameLength);
469
+ $offset += $CommandTypeNameLength;
470
+ }
471
+ break;
472
+
473
+ case GETID3_ASF_Marker_Object:
474
+ // Marker Object: (optional, one only)
475
+ // Field Name Field Type Size (bits)
476
+ // Object ID GUID 128 // GUID for Marker object - GETID3_ASF_Marker_Object
477
+ // Object Size QWORD 64 // size of Marker object, including 48 bytes of Marker Object header
478
+ // Reserved GUID 128 // hardcoded: 4CFEDB20-75F6-11CF-9C0F-00A0C90349CB
479
+ // Markers Count DWORD 32 // number of Marker structures in Marker Object
480
+ // Reserved WORD 16 // hardcoded: 0x0000
481
+ // Name Length WORD 16 // number of bytes in the Name field
482
+ // Name WCHAR variable // name of the Marker Object
483
+ // Markers array of: variable //
484
+ // * Offset QWORD 64 // byte offset into Data Object
485
+ // * Presentation Time QWORD 64 // in 100-nanosecond units
486
+ // * Entry Length WORD 16 // length in bytes of (Send Time + Flags + Marker Description Length + Marker Description + Padding)
487
+ // * Send Time DWORD 32 // in milliseconds
488
+ // * Flags DWORD 32 // hardcoded: 0x00000000
489
+ // * Marker Description Length DWORD 32 // number of bytes in Marker Description field
490
+ // * Marker Description WCHAR variable // array of Unicode characters - description of marker entry
491
+ // * Padding BYTESTREAM variable // optional padding bytes
492
+
493
+ // shortcut
494
+ $thisfile_asf['marker_object'] = array();
495
+ $thisfile_asf_markerobject = &$thisfile_asf['marker_object'];
496
+
497
+ $thisfile_asf_markerobject['objectid'] = $NextObjectGUID;
498
+ $thisfile_asf_markerobject['objectid_guid'] = $NextObjectGUIDtext;
499
+ $thisfile_asf_markerobject['objectsize'] = $NextObjectSize;
500
+ $thisfile_asf_markerobject['reserved'] = substr($ASFHeaderData, $offset, 16);
501
+ $offset += 16;
502
+ $thisfile_asf_markerobject['reserved_guid'] = $this->BytestringToGUID($thisfile_asf_markerobject['reserved']);
503
+ if ($thisfile_asf_markerobject['reserved'] != $this->GUIDtoBytestring('4CFEDB20-75F6-11CF-9C0F-00A0C90349CB')) {
504
+ $ThisFileInfo['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}';
505
+ break;
506
+ }
507
+ $thisfile_asf_markerobject['markers_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
508
+ $offset += 4;
509
+ $thisfile_asf_markerobject['reserved_2'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
510
+ $offset += 2;
511
+ if ($thisfile_asf_markerobject['reserved_2'] != 0) {
512
+ $ThisFileInfo['warning'][] = 'marker_object.reserved_2 ('.getid3_lib::PrintHexBytes($thisfile_asf_markerobject['reserved_2']).') does not match expected value of "0"';
513
+ break;
514
+ }
515
+ $thisfile_asf_markerobject['name_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
516
+ $offset += 2;
517
+ $thisfile_asf_markerobject['name'] = substr($ASFHeaderData, $offset, $thisfile_asf_markerobject['name_length']);
518
+ $offset += $thisfile_asf_markerobject['name_length'];
519
+ for ($MarkersCounter = 0; $MarkersCounter < $thisfile_asf_markerobject['markers_count']; $MarkersCounter++) {
520
+ $thisfile_asf_markerobject['markers'][$MarkersCounter]['offset'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
521
+ $offset += 8;
522
+ $thisfile_asf_markerobject['markers'][$MarkersCounter]['presentation_time'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
523
+ $offset += 8;
524
+ $thisfile_asf_markerobject['markers'][$MarkersCounter]['entry_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
525
+ $offset += 2;
526
+ $thisfile_asf_markerobject['markers'][$MarkersCounter]['send_time'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
527
+ $offset += 4;
528
+ $thisfile_asf_markerobject['markers'][$MarkersCounter]['flags'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
529
+ $offset += 4;
530
+ $thisfile_asf_markerobject['markers'][$MarkersCounter]['marker_description_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
531
+ $offset += 4;
532
+ $thisfile_asf_markerobject['markers'][$MarkersCounter]['marker_description'] = substr($ASFHeaderData, $offset, $thisfile_asf_markerobject['markers'][$MarkersCounter]['marker_description_length']);
533
+ $offset += $thisfile_asf_markerobject['markers'][$MarkersCounter]['marker_description_length'];
534
+ $PaddingLength = $thisfile_asf_markerobject['markers'][$MarkersCounter]['entry_length'] - 4 - 4 - 4 - $thisfile_asf_markerobject['markers'][$MarkersCounter]['marker_description_length'];
535
+ if ($PaddingLength > 0) {
536
+ $thisfile_asf_markerobject['markers'][$MarkersCounter]['padding'] = substr($ASFHeaderData, $offset, $PaddingLength);
537
+ $offset += $PaddingLength;
538
+ }
539
+ }
540
+ break;
541
+
542
+ case GETID3_ASF_Bitrate_Mutual_Exclusion_Object:
543
+ // Bitrate Mutual Exclusion Object: (optional)
544
+ // Field Name Field Type Size (bits)
545
+ // Object ID GUID 128 // GUID for Bitrate Mutual Exclusion object - GETID3_ASF_Bitrate_Mutual_Exclusion_Object
546
+ // Object Size QWORD 64 // size of Bitrate Mutual Exclusion object, including 42 bytes of Bitrate Mutual Exclusion Object header
547
+ // Exlusion Type GUID 128 // nature of mutual exclusion relationship. one of: (GETID3_ASF_Mutex_Bitrate, GETID3_ASF_Mutex_Unknown)
548
+ // Stream Numbers Count WORD 16 // number of video streams
549
+ // Stream Numbers WORD variable // array of mutually exclusive video stream numbers. 1 <= valid <= 127
550
+
551
+ // shortcut
552
+ $thisfile_asf['bitrate_mutual_exclusion_object'] = array();
553
+ $thisfile_asf_bitratemutualexclusionobject = &$thisfile_asf['bitrate_mutual_exclusion_object'];
554
+
555
+ $thisfile_asf_bitratemutualexclusionobject['objectid'] = $NextObjectGUID;
556
+ $thisfile_asf_bitratemutualexclusionobject['objectid_guid'] = $NextObjectGUIDtext;
557
+ $thisfile_asf_bitratemutualexclusionobject['objectsize'] = $NextObjectSize;
558
+ $thisfile_asf_bitratemutualexclusionobject['reserved'] = substr($ASFHeaderData, $offset, 16);
559
+ $thisfile_asf_bitratemutualexclusionobject['reserved_guid'] = $this->BytestringToGUID($thisfile_asf_bitratemutualexclusionobject['reserved']);
560
+ $offset += 16;
561
+ if (($thisfile_asf_bitratemutualexclusionobject['reserved'] != GETID3_ASF_Mutex_Bitrate) && ($thisfile_asf_bitratemutualexclusionobject['reserved'] != GETID3_ASF_Mutex_Unknown)) {
562
+ $ThisFileInfo['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).'}';
563
+ //return false;
564
+ break;
565
+ }
566
+ $thisfile_asf_bitratemutualexclusionobject['stream_numbers_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
567
+ $offset += 2;
568
+ for ($StreamNumberCounter = 0; $StreamNumberCounter < $thisfile_asf_bitratemutualexclusionobject['stream_numbers_count']; $StreamNumberCounter++) {
569
+ $thisfile_asf_bitratemutualexclusionobject['stream_numbers'][$StreamNumberCounter] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
570
+ $offset += 2;
571
+ }
572
+ break;
573
+
574
+ case GETID3_ASF_Error_Correction_Object:
575
+ // Error Correction Object: (optional, one only)
576
+ // Field Name Field Type Size (bits)
577
+ // Object ID GUID 128 // GUID for Error Correction object - GETID3_ASF_Error_Correction_Object
578
+ // Object Size QWORD 64 // size of Error Correction object, including 44 bytes of Error Correction Object header
579
+ // Error Correction Type GUID 128 // type of error correction. one of: (GETID3_ASF_No_Error_Correction, GETID3_ASF_Audio_Spread)
580
+ // Error Correction Data Length DWORD 32 // number of bytes in Error Correction Data field
581
+ // Error Correction Data BYTESTREAM variable // structure depends on value of Error Correction Type field
582
+
583
+ // shortcut
584
+ $thisfile_asf['error_correction_object'] = array();
585
+ $thisfile_asf_errorcorrectionobject = &$thisfile_asf['error_correction_object'];
586
+
587
+ $thisfile_asf_errorcorrectionobject['objectid'] = $NextObjectGUID;
588
+ $thisfile_asf_errorcorrectionobject['objectid_guid'] = $NextObjectGUIDtext;
589
+ $thisfile_asf_errorcorrectionobject['objectsize'] = $NextObjectSize;
590
+ $thisfile_asf_errorcorrectionobject['error_correction_type'] = substr($ASFHeaderData, $offset, 16);
591
+ $offset += 16;
592
+ $thisfile_asf_errorcorrectionobject['error_correction_guid'] = $this->BytestringToGUID($thisfile_asf_errorcorrectionobject['error_correction_type']);
593
+ $thisfile_asf_errorcorrectionobject['error_correction_data_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
594
+ $offset += 4;
595
+ switch ($thisfile_asf_errorcorrectionobject['error_correction_type']) {
596
+ case GETID3_ASF_No_Error_Correction:
597
+ // should be no data, but just in case there is, skip to the end of the field
598
+ $offset += $thisfile_asf_errorcorrectionobject['error_correction_data_length'];
599
+ break;
600
+
601
+ case GETID3_ASF_Audio_Spread:
602
+ // Field Name Field Type Size (bits)
603
+ // Span BYTE 8 // number of packets over which audio will be spread.
604
+ // Virtual Packet Length WORD 16 // size of largest audio payload found in audio stream
605
+ // Virtual Chunk Length WORD 16 // size of largest audio payload found in audio stream
606
+ // Silence Data Length WORD 16 // number of bytes in Silence Data field
607
+ // Silence Data BYTESTREAM variable // hardcoded: 0x00 * (Silence Data Length) bytes
608
+
609
+ $thisfile_asf_errorcorrectionobject['span'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 1));
610
+ $offset += 1;
611
+ $thisfile_asf_errorcorrectionobject['virtual_packet_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
612
+ $offset += 2;
613
+ $thisfile_asf_errorcorrectionobject['virtual_chunk_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
614
+ $offset += 2;
615
+ $thisfile_asf_errorcorrectionobject['silence_data_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
616
+ $offset += 2;
617
+ $thisfile_asf_errorcorrectionobject['silence_data'] = substr($ASFHeaderData, $offset, $thisfile_asf_errorcorrectionobject['silence_data_length']);
618
+ $offset += $thisfile_asf_errorcorrectionobject['silence_data_length'];
619
+ break;
620
+
621
+ default:
622
+ $ThisFileInfo['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).'}';
623
+ //return false;
624
+ break;
625
+ }
626
+
627
+ break;
628
+
629
+ case GETID3_ASF_Content_Description_Object:
630
+ // Content Description Object: (optional, one only)
631
+ // Field Name Field Type Size (bits)
632
+ // Object ID GUID 128 // GUID for Content Description object - GETID3_ASF_Content_Description_Object
633
+ // Object Size QWORD 64 // size of Content Description object, including 34 bytes of Content Description Object header
634
+ // Title Length WORD 16 // number of bytes in Title field
635
+ // Author Length WORD 16 // number of bytes in Author field
636
+ // Copyright Length WORD 16 // number of bytes in Copyright field
637
+ // Description Length WORD 16 // number of bytes in Description field
638
+ // Rating Length WORD 16 // number of bytes in Rating field
639
+ // Title WCHAR 16 // array of Unicode characters - Title
640
+ // Author WCHAR 16 // array of Unicode characters - Author
641
+ // Copyright WCHAR 16 // array of Unicode characters - Copyright
642
+ // Description WCHAR 16 // array of Unicode characters - Description
643
+ // Rating WCHAR 16 // array of Unicode characters - Rating
644
+
645
+ // shortcut
646
+ $thisfile_asf['content_description_object'] = array();
647
+ $thisfile_asf_contentdescriptionobject = &$thisfile_asf['content_description_object'];
648
+
649
+ $thisfile_asf_contentdescriptionobject['objectid'] = $NextObjectGUID;
650
+ $thisfile_asf_contentdescriptionobject['objectid_guid'] = $NextObjectGUIDtext;
651
+ $thisfile_asf_contentdescriptionobject['objectsize'] = $NextObjectSize;
652
+ $thisfile_asf_contentdescriptionobject['title_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
653
+ $offset += 2;
654
+ $thisfile_asf_contentdescriptionobject['author_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
655
+ $offset += 2;
656
+ $thisfile_asf_contentdescriptionobject['copyright_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
657
+ $offset += 2;
658
+ $thisfile_asf_contentdescriptionobject['description_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
659
+ $offset += 2;
660
+ $thisfile_asf_contentdescriptionobject['rating_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
661
+ $offset += 2;
662
+ $thisfile_asf_contentdescriptionobject['title'] = substr($ASFHeaderData, $offset, $thisfile_asf_contentdescriptionobject['title_length']);
663
+ $offset += $thisfile_asf_contentdescriptionobject['title_length'];
664
+ $thisfile_asf_contentdescriptionobject['author'] = substr($ASFHeaderData, $offset, $thisfile_asf_contentdescriptionobject['author_length']);
665
+ $offset += $thisfile_asf_contentdescriptionobject['author_length'];
666
+ $thisfile_asf_contentdescriptionobject['copyright'] = substr($ASFHeaderData, $offset, $thisfile_asf_contentdescriptionobject['copyright_length']);
667
+ $offset += $thisfile_asf_contentdescriptionobject['copyright_length'];
668
+ $thisfile_asf_contentdescriptionobject['description'] = substr($ASFHeaderData, $offset, $thisfile_asf_contentdescriptionobject['description_length']);
669
+ $offset += $thisfile_asf_contentdescriptionobject['description_length'];
670
+ $thisfile_asf_contentdescriptionobject['rating'] = substr($ASFHeaderData, $offset, $thisfile_asf_contentdescriptionobject['rating_length']);
671
+ $offset += $thisfile_asf_contentdescriptionobject['rating_length'];
672
+
673
+ $ASFcommentKeysToCopy = array('title'=>'title', 'author'=>'artist', 'copyright'=>'copyright', 'description'=>'comment', 'rating'=>'rating');
674
+ foreach ($ASFcommentKeysToCopy as $keytocopyfrom => $keytocopyto) {
675
+ if (!empty($thisfile_asf_contentdescriptionobject[$keytocopyfrom])) {
676
+ $thisfile_asf_comments[$keytocopyto][] = $this->TrimTerm($thisfile_asf_contentdescriptionobject[$keytocopyfrom]);
677
+ }
678
+ }
679
+ break;
680
+
681
+ case GETID3_ASF_Extended_Content_Description_Object:
682
+ // Extended Content Description Object: (optional, one only)
683
+ // Field Name Field Type Size (bits)
684
+ // Object ID GUID 128 // GUID for Extended Content Description object - GETID3_ASF_Extended_Content_Description_Object
685
+ // Object Size QWORD 64 // size of ExtendedContent Description object, including 26 bytes of Extended Content Description Object header
686
+ // Content Descriptors Count WORD 16 // number of entries in Content Descriptors list
687
+ // Content Descriptors array of: variable //
688
+ // * Descriptor Name Length WORD 16 // size in bytes of Descriptor Name field
689
+ // * Descriptor Name WCHAR variable // array of Unicode characters - Descriptor Name
690
+ // * Descriptor Value Data Type WORD 16 // Lookup array:
691
+ // 0x0000 = Unicode String (variable length)
692
+ // 0x0001 = BYTE array (variable length)
693
+ // 0x0002 = BOOL (DWORD, 32 bits)
694
+ // 0x0003 = DWORD (DWORD, 32 bits)
695
+ // 0x0004 = QWORD (QWORD, 64 bits)
696
+ // 0x0005 = WORD (WORD, 16 bits)
697
+ // * Descriptor Value Length WORD 16 // number of bytes stored in Descriptor Value field
698
+ // * Descriptor Value variable variable // value for Content Descriptor
699
+
700
+ // shortcut
701
+ $thisfile_asf['extended_content_description_object'] = array();
702
+ $thisfile_asf_extendedcontentdescriptionobject = &$thisfile_asf['extended_content_description_object'];
703
+
704
+ $thisfile_asf_extendedcontentdescriptionobject['objectid'] = $NextObjectGUID;
705
+ $thisfile_asf_extendedcontentdescriptionobject['objectid_guid'] = $NextObjectGUIDtext;
706
+ $thisfile_asf_extendedcontentdescriptionobject['objectsize'] = $NextObjectSize;
707
+ $thisfile_asf_extendedcontentdescriptionobject['content_descriptors_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
708
+ $offset += 2;
709
+ for ($ExtendedContentDescriptorsCounter = 0; $ExtendedContentDescriptorsCounter < $thisfile_asf_extendedcontentdescriptionobject['content_descriptors_count']; $ExtendedContentDescriptorsCounter++) {
710
+ // shortcut
711
+ $thisfile_asf_extendedcontentdescriptionobject['content_descriptors'][$ExtendedContentDescriptorsCounter] = array();
712
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current = &$thisfile_asf_extendedcontentdescriptionobject['content_descriptors'][$ExtendedContentDescriptorsCounter];
713
+
714
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['base_offset'] = $offset + 30;
715
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
716
+ $offset += 2;
717
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name'] = substr($ASFHeaderData, $offset, $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name_length']);
718
+ $offset += $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name_length'];
719
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_type'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
720
+ $offset += 2;
721
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
722
+ $offset += 2;
723
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'] = substr($ASFHeaderData, $offset, $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_length']);
724
+ $offset += $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_length'];
725
+ switch ($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_type']) {
726
+ case 0x0000: // Unicode string
727
+ break;
728
+
729
+ case 0x0001: // BYTE array
730
+ // do nothing
731
+ break;
732
+
733
+ case 0x0002: // BOOL
734
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'] = (bool) getid3_lib::LittleEndian2Int($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']);
735
+ break;
736
+
737
+ case 0x0003: // DWORD
738
+ case 0x0004: // QWORD
739
+ case 0x0005: // WORD
740
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'] = getid3_lib::LittleEndian2Int($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']);
741
+ break;
742
+
743
+ default:
744
+ $ThisFileInfo['warning'][] = 'extended_content_description.content_descriptors.'.$ExtendedContentDescriptorsCounter.'.value_type is invalid ('.$thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_type'].')';
745
+ //return false;
746
+ break;
747
+ }
748
+ switch ($this->TrimConvert(strtolower($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name']))) {
749
+
750
+ case 'wm/albumartist':
751
+ case 'artist':
752
+ $thisfile_asf_comments['artist'] = array($this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']));
753
+ break;
754
+
755
+ case 'wm/albumtitle':
756
+ case 'album':
757
+ $thisfile_asf_comments['album'] = array($this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']));
758
+ break;
759
+
760
+ case 'wm/genre':
761
+ case 'genre':
762
+ $thisfile_asf_comments['genre'] = array($this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']));
763
+ break;
764
+
765
+ case 'wm/tracknumber':
766
+ case 'tracknumber':
767
+ $thisfile_asf_comments['track'] = array(intval($this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'])));
768
+ break;
769
+
770
+ case 'wm/track':
771
+ if (empty($thisfile_asf_comments['track'])) {
772
+ $thisfile_asf_comments['track'] = array(1 + $this->TrimConvert($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']));
773
+ }
774
+ break;
775
+
776
+ case 'wm/year':
777
+ case 'year':
778
+ case 'date':
779
+ $thisfile_asf_comments['year'] = array( $this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']));
780
+ break;
781
+
782
+ case 'wm/lyrics':
783
+ case 'lyrics':
784
+ $thisfile_asf_comments['lyrics'] = array($this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']));
785
+ break;
786
+
787
+ case 'isvbr':
788
+ if ($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']) {
789
+ $thisfile_audio['bitrate_mode'] = 'vbr';
790
+ $thisfile_video['bitrate_mode'] = 'vbr';
791
+ }
792
+ break;
793
+
794
+ case 'id3':
795
+ // id3v2 module might not be loaded
796
+ if (class_exists('getid3_id3v2')) {
797
+ $tempfile = tempnam('*', 'getID3');
798
+ $tempfilehandle = fopen($tempfile, "wb");
799
+ $tempThisfileInfo = array('encoding'=>$ThisFileInfo['encoding']);
800
+ fwrite($tempfilehandle, $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']);
801
+ fclose($tempfilehandle);
802
+
803
+ $tempfilehandle = fopen($tempfile, "rb");
804
+ $id3 = new getid3_id3v2($tempfilehandle, $tempThisfileInfo);
805
+ unset($id3);
806
+ fclose($tempfilehandle);
807
+ unlink($tempfile);
808
+
809
+ $ThisFileInfo['id3v2'] = $tempThisfileInfo['id3v2'];
810
+ unset($tempThisfileInfo);
811
+ }
812
+ break;
813
+
814
+ case 'wm/encodingtime':
815
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['encoding_time_unix'] = $this->FILETIMEtoUNIXtime($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']);
816
+ $thisfile_asf_comments['encoding_time_unix'] = array($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['encoding_time_unix']);
817
+ break;
818
+
819
+ case 'wm/picture':
820
+ //typedef struct _WMPicture{
821
+ // LPWSTR pwszMIMEType;
822
+ // BYTE bPictureType;
823
+ // LPWSTR pwszDescription;
824
+ // DWORD dwDataLen;
825
+ // BYTE* pbData;
826
+ //} WM_PICTURE;
827
+
828
+ $wm_picture_offset = 0;
829
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_type_id'] = getid3_lib::LittleEndian2Int(substr($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'], $wm_picture_offset, 1));
830
+ $wm_picture_offset += 1;
831
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_type'] = $this->WMpictureTypeLookup($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_type_id']);
832
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_size'] = getid3_lib::LittleEndian2Int(substr($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'], $wm_picture_offset, 4));
833
+ $wm_picture_offset += 4;
834
+
835
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_mime'] = '';
836
+ do {
837
+ $next_byte_pair = substr($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'], $wm_picture_offset, 2);
838
+ $wm_picture_offset += 2;
839
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_mime'] .= $next_byte_pair;
840
+ } while ($next_byte_pair !== "\x00\x00");
841
+
842
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_description'] = '';
843
+ do {
844
+ $next_byte_pair = substr($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'], $wm_picture_offset, 2);
845
+ $wm_picture_offset += 2;
846
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_description'] .= $next_byte_pair;
847
+ } while ($next_byte_pair !== "\x00\x00");
848
+
849
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['dataoffset'] = $wm_picture_offset;
850
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['data'] = substr($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'], $wm_picture_offset);
851
+ unset($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']);
852
+
853
+ break;
854
+
855
+ default:
856
+ switch ($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_type']) {
857
+ case 0: // Unicode string
858
+ if (substr($this->TrimConvert($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name']), 0, 3) == 'WM/') {
859
+ $thisfile_asf_comments[str_replace('wm/', '', strtolower($this->TrimConvert($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name'])))] = array($this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']));
860
+ }
861
+ break;
862
+
863
+ case 1:
864
+ break;
865
+ }
866
+ break;
867
+ }
868
+
869
+ }
870
+ break;
871
+
872
+ case GETID3_ASF_Stream_Bitrate_Properties_Object:
873
+ // Stream Bitrate Properties Object: (optional, one only)
874
+ // Field Name Field Type Size (bits)
875
+ // Object ID GUID 128 // GUID for Stream Bitrate Properties object - GETID3_ASF_Stream_Bitrate_Properties_Object
876
+ // Object Size QWORD 64 // size of Extended Content Description object, including 26 bytes of Stream Bitrate Properties Object header
877
+ // Bitrate Records Count WORD 16 // number of records in Bitrate Records
878
+ // Bitrate Records array of: variable //
879
+ // * Flags WORD 16 //
880
+ // * * Stream Number bits 7 (0x007F) // number of this stream
881
+ // * * Reserved bits 9 (0xFF80) // hardcoded: 0
882
+ // * Average Bitrate DWORD 32 // in bits per second
883
+
884
+ // shortcut
885
+ $thisfile_asf['stream_bitrate_properties_object'] = array();
886
+ $thisfile_asf_streambitratepropertiesobject = &$thisfile_asf['stream_bitrate_properties_object'];
887
+
888
+ $thisfile_asf_streambitratepropertiesobject['objectid'] = $NextObjectGUID;
889
+ $thisfile_asf_streambitratepropertiesobject['objectid_guid'] = $NextObjectGUIDtext;
890
+ $thisfile_asf_streambitratepropertiesobject['objectsize'] = $NextObjectSize;
891
+ $thisfile_asf_streambitratepropertiesobject['bitrate_records_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
892
+ $offset += 2;
893
+ for ($BitrateRecordsCounter = 0; $BitrateRecordsCounter < $thisfile_asf_streambitratepropertiesobject['bitrate_records_count']; $BitrateRecordsCounter++) {
894
+ $thisfile_asf_streambitratepropertiesobject['bitrate_records'][$BitrateRecordsCounter]['flags_raw'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
895
+ $offset += 2;
896
+ $thisfile_asf_streambitratepropertiesobject['bitrate_records'][$BitrateRecordsCounter]['flags']['stream_number'] = $thisfile_asf_streambitratepropertiesobject['bitrate_records'][$BitrateRecordsCounter]['flags_raw'] & 0x007F;
897
+ $thisfile_asf_streambitratepropertiesobject['bitrate_records'][$BitrateRecordsCounter]['bitrate'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
898
+ $offset += 4;
899
+ }
900
+ break;
901
+
902
+ case GETID3_ASF_Padding_Object:
903
+ // Padding Object: (optional)
904
+ // Field Name Field Type Size (bits)
905
+ // Object ID GUID 128 // GUID for Padding object - GETID3_ASF_Padding_Object
906
+ // Object Size QWORD 64 // size of Padding object, including 24 bytes of ASF Padding Object header
907
+ // Padding Data BYTESTREAM variable // ignore
908
+
909
+ // shortcut
910
+ $thisfile_asf['padding_object'] = array();
911
+ $thisfile_asf_paddingobject = &$thisfile_asf['padding_object'];
912
+
913
+ $thisfile_asf_paddingobject['objectid'] = $NextObjectGUID;
914
+ $thisfile_asf_paddingobject['objectid_guid'] = $NextObjectGUIDtext;
915
+ $thisfile_asf_paddingobject['objectsize'] = $NextObjectSize;
916
+ $thisfile_asf_paddingobject['padding_length'] = $thisfile_asf_paddingobject['objectsize'] - 16 - 8;
917
+ $thisfile_asf_paddingobject['padding'] = substr($ASFHeaderData, $offset, $thisfile_asf_paddingobject['padding_length']);
918
+ $offset += ($NextObjectSize - 16 - 8);
919
+ break;
920
+
921
+ case GETID3_ASF_Extended_Content_Encryption_Object:
922
+ case GETID3_ASF_Content_Encryption_Object:
923
+ // WMA DRM - just ignore
924
+ $offset += ($NextObjectSize - 16 - 8);
925
+ break;
926
+
927
+ default:
928
+ // Implementations shall ignore any standard or non-standard object that they do not know how to handle.
929
+ if ($this->GUIDname($NextObjectGUIDtext)) {
930
+ $ThisFileInfo['warning'][] = 'unhandled GUID "'.$this->GUIDname($NextObjectGUIDtext).'" {'.$NextObjectGUIDtext.'} in ASF header at offset '.($offset - 16 - 8);
931
+ } else {
932
+ $ThisFileInfo['warning'][] = 'unknown GUID {'.$NextObjectGUIDtext.'} in ASF header at offset '.($offset - 16 - 8);
933
+ }
934
+ $offset += ($NextObjectSize - 16 - 8);
935
+ break;
936
+ }
937
+ }
938
+ if (isset($thisfile_asf_streambitrateproperties['bitrate_records_count'])) {
939
+ $ASFbitrateAudio = 0;
940
+ $ASFbitrateVideo = 0;
941
+ for ($BitrateRecordsCounter = 0; $BitrateRecordsCounter < $thisfile_asf_streambitrateproperties['bitrate_records_count']; $BitrateRecordsCounter++) {
942
+ if (isset($thisfile_asf_codeclistobject['codec_entries'][$BitrateRecordsCounter])) {
943
+ switch ($thisfile_asf_codeclistobject['codec_entries'][$BitrateRecordsCounter]['type_raw']) {
944
+ case 1:
945
+ $ASFbitrateVideo += $thisfile_asf_streambitrateproperties['bitrate_records'][$BitrateRecordsCounter]['bitrate'];
946
+ break;
947
+
948
+ case 2:
949
+ $ASFbitrateAudio += $thisfile_asf_streambitrateproperties['bitrate_records'][$BitrateRecordsCounter]['bitrate'];
950
+ break;
951
+
952
+ default:
953
+ // do nothing
954
+ break;
955
+ }
956
+ }
957
+ }
958
+ if ($ASFbitrateAudio > 0) {
959
+ $thisfile_audio['bitrate'] = $ASFbitrateAudio;
960
+ }
961
+ if ($ASFbitrateVideo > 0) {
962
+ $thisfile_video['bitrate'] = $ASFbitrateVideo;
963
+ }
964
+ }
965
+ if (isset($thisfile_asf['stream_properties_object']) && is_array($thisfile_asf['stream_properties_object'])) {
966
+
967
+ $thisfile_audio['bitrate'] = 0;
968
+ $thisfile_video['bitrate'] = 0;
969
+
970
+ foreach ($thisfile_asf['stream_properties_object'] as $streamnumber => $streamdata) {
971
+
972
+ switch ($streamdata['stream_type']) {
973
+ case GETID3_ASF_Audio_Media:
974
+ // Field Name Field Type Size (bits)
975
+ // Codec ID / Format Tag WORD 16 // unique ID of audio codec - defined as wFormatTag field of WAVEFORMATEX structure
976
+ // Number of Channels WORD 16 // number of channels of audio - defined as nChannels field of WAVEFORMATEX structure
977
+ // Samples Per Second DWORD 32 // in Hertz - defined as nSamplesPerSec field of WAVEFORMATEX structure
978
+ // Average number of Bytes/sec DWORD 32 // bytes/sec of audio stream - defined as nAvgBytesPerSec field of WAVEFORMATEX structure
979
+ // Block Alignment WORD 16 // block size in bytes of audio codec - defined as nBlockAlign field of WAVEFORMATEX structure
980
+ // 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
981
+ // Codec Specific Data Size WORD 16 // size in bytes of Codec Specific Data buffer - defined as cbSize field of WAVEFORMATEX structure
982
+ // Codec Specific Data BYTESTREAM variable // array of codec-specific data bytes
983
+
984
+ // shortcut
985
+ $thisfile_asf['audio_media'][$streamnumber] = array();
986
+ $thisfile_asf_audiomedia_currentstream = &$thisfile_asf['audio_media'][$streamnumber];
987
+
988
+ $audiomediaoffset = 0;
989
+
990
+ $thisfile_asf_audiomedia_currentstream = getid3_riff::RIFFparseWAVEFORMATex(substr($streamdata['type_specific_data'], $audiomediaoffset, 16));
991
+ $audiomediaoffset += 16;
992
+
993
+ $thisfile_audio['lossless'] = false;
994
+ switch ($thisfile_asf_audiomedia_currentstream['raw']['wFormatTag']) {
995
+ case 0x0001: // PCM
996
+ case 0x0163: // WMA9 Lossless
997
+ $thisfile_audio['lossless'] = true;
998
+ break;
999
+ }
1000
+
1001
+ if (!empty($thisfile_asf['stream_bitrate_properties_object']['bitrate_records'])) {
1002
+ foreach ($thisfile_asf['stream_bitrate_properties_object']['bitrate_records'] as $dummy => $dataarray) {
1003
+ if (@$dataarray['flags']['stream_number'] == $streamnumber) {
1004
+ $thisfile_asf_audiomedia_currentstream['bitrate'] = $dataarray['bitrate'];
1005
+ $thisfile_audio['bitrate'] += $dataarray['bitrate'];
1006
+ break;
1007
+ }
1008
+ }
1009
+ } else {
1010
+ if (@$thisfile_asf_audiomedia_currentstream['bytes_sec']) {
1011
+ $thisfile_audio['bitrate'] += $thisfile_asf_audiomedia_currentstream['bytes_sec'] * 8;
1012
+ } elseif (@$thisfile_asf_audiomedia_currentstream['bitrate']) {
1013
+ $thisfile_audio['bitrate'] += $thisfile_asf_audiomedia_currentstream['bitrate'];
1014
+ }
1015
+ }
1016
+ $thisfile_audio['streams'][$streamnumber] = $thisfile_asf_audiomedia_currentstream;
1017
+ $thisfile_audio['streams'][$streamnumber]['wformattag'] = $thisfile_asf_audiomedia_currentstream['raw']['wFormatTag'];
1018
+ $thisfile_audio['streams'][$streamnumber]['lossless'] = $thisfile_audio['lossless'];
1019
+ $thisfile_audio['streams'][$streamnumber]['bitrate'] = $thisfile_audio['bitrate'];
1020
+ $thisfile_audio['streams'][$streamnumber]['dataformat'] = 'wma';
1021
+ unset($thisfile_audio['streams'][$streamnumber]['raw']);
1022
+
1023
+ $thisfile_asf_audiomedia_currentstream['codec_data_size'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $audiomediaoffset, 2));
1024
+ $audiomediaoffset += 2;
1025
+ $thisfile_asf_audiomedia_currentstream['codec_data'] = substr($streamdata['type_specific_data'], $audiomediaoffset, $thisfile_asf_audiomedia_currentstream['codec_data_size']);
1026
+ $audiomediaoffset += $thisfile_asf_audiomedia_currentstream['codec_data_size'];
1027
+
1028
+ break;
1029
+
1030
+ case GETID3_ASF_Video_Media:
1031
+ // Field Name Field Type Size (bits)
1032
+ // Encoded Image Width DWORD 32 // width of image in pixels
1033
+ // Encoded Image Height DWORD 32 // height of image in pixels
1034
+ // Reserved Flags BYTE 8 // hardcoded: 0x02
1035
+ // Format Data Size WORD 16 // size of Format Data field in bytes
1036
+ // Format Data array of: variable //
1037
+ // * Format Data Size DWORD 32 // number of bytes in Format Data field, in bytes - defined as biSize field of BITMAPINFOHEADER structure
1038
+ // * Image Width LONG 32 // width of encoded image in pixels - defined as biWidth field of BITMAPINFOHEADER structure
1039
+ // * Image Height LONG 32 // height of encoded image in pixels - defined as biHeight field of BITMAPINFOHEADER structure
1040
+ // * Reserved WORD 16 // hardcoded: 0x0001 - defined as biPlanes field of BITMAPINFOHEADER structure
1041
+ // * Bits Per Pixel Count WORD 16 // bits per pixel - defined as biBitCount field of BITMAPINFOHEADER structure
1042
+ // * Compression ID FOURCC 32 // fourcc of video codec - defined as biCompression field of BITMAPINFOHEADER structure
1043
+ // * Image Size DWORD 32 // image size in bytes - defined as biSizeImage field of BITMAPINFOHEADER structure
1044
+ // * Horizontal Pixels / Meter DWORD 32 // horizontal resolution of target device in pixels per meter - defined as biXPelsPerMeter field of BITMAPINFOHEADER structure
1045
+ // * Vertical Pixels / Meter DWORD 32 // vertical resolution of target device in pixels per meter - defined as biYPelsPerMeter field of BITMAPINFOHEADER structure
1046
+ // * Colors Used Count DWORD 32 // number of color indexes in the color table that are actually used - defined as biClrUsed field of BITMAPINFOHEADER structure
1047
+ // * 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
1048
+ // * Codec Specific Data BYTESTREAM variable // array of codec-specific data bytes
1049
+
1050
+ // shortcut
1051
+ $thisfile_asf['video_media'][$streamnumber] = array();
1052
+ $thisfile_asf_videomedia_currentstream = &$thisfile_asf['video_media'][$streamnumber];
1053
+
1054
+ $videomediaoffset = 0;
1055
+ $thisfile_asf_videomedia_currentstream['image_width'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
1056
+ $videomediaoffset += 4;
1057
+ $thisfile_asf_videomedia_currentstream['image_height'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
1058
+ $videomediaoffset += 4;
1059
+ $thisfile_asf_videomedia_currentstream['flags'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 1));
1060
+ $videomediaoffset += 1;
1061
+ $thisfile_asf_videomedia_currentstream['format_data_size'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 2));
1062
+ $videomediaoffset += 2;
1063
+ $thisfile_asf_videomedia_currentstream['format_data']['format_data_size'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
1064
+ $videomediaoffset += 4;
1065
+ $thisfile_asf_videomedia_currentstream['format_data']['image_width'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
1066
+ $videomediaoffset += 4;
1067
+ $thisfile_asf_videomedia_currentstream['format_data']['image_height'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
1068
+ $videomediaoffset += 4;
1069
+ $thisfile_asf_videomedia_currentstream['format_data']['reserved'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 2));
1070
+ $videomediaoffset += 2;
1071
+ $thisfile_asf_videomedia_currentstream['format_data']['bits_per_pixel'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 2));
1072
+ $videomediaoffset += 2;
1073
+ $thisfile_asf_videomedia_currentstream['format_data']['codec_fourcc'] = substr($streamdata['type_specific_data'], $videomediaoffset, 4);
1074
+ $videomediaoffset += 4;
1075
+ $thisfile_asf_videomedia_currentstream['format_data']['image_size'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
1076
+ $videomediaoffset += 4;
1077
+ $thisfile_asf_videomedia_currentstream['format_data']['horizontal_pels'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
1078
+ $videomediaoffset += 4;
1079
+ $thisfile_asf_videomedia_currentstream['format_data']['vertical_pels'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
1080
+ $videomediaoffset += 4;
1081
+ $thisfile_asf_videomedia_currentstream['format_data']['colors_used'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
1082
+ $videomediaoffset += 4;
1083
+ $thisfile_asf_videomedia_currentstream['format_data']['colors_important'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
1084
+ $videomediaoffset += 4;
1085
+ $thisfile_asf_videomedia_currentstream['format_data']['codec_data'] = substr($streamdata['type_specific_data'], $videomediaoffset);
1086
+
1087
+ if (!empty($thisfile_asf['stream_bitrate_properties_object']['bitrate_records'])) {
1088
+ foreach ($thisfile_asf['stream_bitrate_properties_object']['bitrate_records'] as $dummy => $dataarray) {
1089
+ if (@$dataarray['flags']['stream_number'] == $streamnumber) {
1090
+ $thisfile_asf_videomedia_currentstream['bitrate'] = $dataarray['bitrate'];
1091
+ $thisfile_video['streams'][$streamnumber]['bitrate'] = $dataarray['bitrate'];
1092
+ $thisfile_video['bitrate'] += $dataarray['bitrate'];
1093
+ break;
1094
+ }
1095
+ }
1096
+ }
1097
+
1098
+ $thisfile_asf_videomedia_currentstream['format_data']['codec'] = getid3_riff::RIFFfourccLookup($thisfile_asf_videomedia_currentstream['format_data']['codec_fourcc']);
1099
+
1100
+ $thisfile_video['streams'][$streamnumber]['fourcc'] = $thisfile_asf_videomedia_currentstream['format_data']['codec_fourcc'];
1101
+ $thisfile_video['streams'][$streamnumber]['codec'] = $thisfile_asf_videomedia_currentstream['format_data']['codec'];
1102
+ $thisfile_video['streams'][$streamnumber]['resolution_x'] = $thisfile_asf_videomedia_currentstream['image_width'];
1103
+ $thisfile_video['streams'][$streamnumber]['resolution_y'] = $thisfile_asf_videomedia_currentstream['image_height'];
1104
+ $thisfile_video['streams'][$streamnumber]['bits_per_sample'] = $thisfile_asf_videomedia_currentstream['format_data']['bits_per_pixel'];
1105
+ break;
1106
+
1107
+ default:
1108
+ break;
1109
+ }
1110
+ }
1111
+ }
1112
+
1113
+ while (ftell($fd) < $ThisFileInfo['avdataend']) {
1114
+ $NextObjectDataHeader = fread($fd, 24);
1115
+ $offset = 0;
1116
+ $NextObjectGUID = substr($NextObjectDataHeader, 0, 16);
1117
+ $offset += 16;
1118
+ $NextObjectGUIDtext = $this->BytestringToGUID($NextObjectGUID);
1119
+ $NextObjectSize = getid3_lib::LittleEndian2Int(substr($NextObjectDataHeader, $offset, 8));
1120
+ $offset += 8;
1121
+
1122
+ switch ($NextObjectGUID) {
1123
+ case GETID3_ASF_Data_Object:
1124
+ // Data Object: (mandatory, one only)
1125
+ // Field Name Field Type Size (bits)
1126
+ // Object ID GUID 128 // GUID for Data object - GETID3_ASF_Data_Object
1127
+ // Object Size QWORD 64 // size of Data object, including 50 bytes of Data Object header. may be 0 if FilePropertiesObject.BroadcastFlag == 1
1128
+ // File ID GUID 128 // unique identifier. identical to File ID field in Header Object
1129
+ // Total Data Packets QWORD 64 // number of Data Packet entries in Data Object. invalid if FilePropertiesObject.BroadcastFlag == 1
1130
+ // Reserved WORD 16 // hardcoded: 0x0101
1131
+
1132
+ // shortcut
1133
+ $thisfile_asf['data_object'] = array();
1134
+ $thisfile_asf_dataobject = &$thisfile_asf['data_object'];
1135
+
1136
+ $DataObjectData = $NextObjectDataHeader.fread($fd, 50 - 24);
1137
+ $offset = 24;
1138
+
1139
+ $thisfile_asf_dataobject['objectid'] = $NextObjectGUID;
1140
+ $thisfile_asf_dataobject['objectid_guid'] = $NextObjectGUIDtext;
1141
+ $thisfile_asf_dataobject['objectsize'] = $NextObjectSize;
1142
+
1143
+ $thisfile_asf_dataobject['fileid'] = substr($DataObjectData, $offset, 16);
1144
+ $offset += 16;
1145
+ $thisfile_asf_dataobject['fileid_guid'] = $this->BytestringToGUID($thisfile_asf_dataobject['fileid']);
1146
+ $thisfile_asf_dataobject['total_data_packets'] = getid3_lib::LittleEndian2Int(substr($DataObjectData, $offset, 8));
1147
+ $offset += 8;
1148
+ $thisfile_asf_dataobject['reserved'] = getid3_lib::LittleEndian2Int(substr($DataObjectData, $offset, 2));
1149
+ $offset += 2;
1150
+ if ($thisfile_asf_dataobject['reserved'] != 0x0101) {
1151
+ $ThisFileInfo['warning'][] = 'data_object.reserved ('.getid3_lib::PrintHexBytes($thisfile_asf_dataobject['reserved']).') does not match expected value of "0x0101"';
1152
+ //return false;
1153
+ break;
1154
+ }
1155
+
1156
+ // Data Packets array of: variable //
1157
+ // * Error Correction Flags BYTE 8 //
1158
+ // * * Error Correction Data Length bits 4 // if Error Correction Length Type == 00, size of Error Correction Data in bytes, else hardcoded: 0000
1159
+ // * * Opaque Data Present bits 1 //
1160
+ // * * Error Correction Length Type bits 2 // number of bits for size of the error correction data. hardcoded: 00
1161
+ // * * Error Correction Present bits 1 // If set, use Opaque Data Packet structure, else use Payload structure
1162
+ // * Error Correction Data
1163
+
1164
+ $ThisFileInfo['avdataoffset'] = ftell($fd);
1165
+ fseek($fd, ($thisfile_asf_dataobject['objectsize'] - 50), SEEK_CUR); // skip actual audio/video data
1166
+ $ThisFileInfo['avdataend'] = ftell($fd);
1167
+ break;
1168
+
1169
+ case GETID3_ASF_Simple_Index_Object:
1170
+ // Simple Index Object: (optional, recommended, one per video stream)
1171
+ // Field Name Field Type Size (bits)
1172
+ // Object ID GUID 128 // GUID for Simple Index object - GETID3_ASF_Data_Object
1173
+ // Object Size QWORD 64 // size of Simple Index object, including 56 bytes of Simple Index Object header
1174
+ // File ID GUID 128 // unique identifier. may be zero or identical to File ID field in Data Object and Header Object
1175
+ // Index Entry Time Interval QWORD 64 // interval between index entries in 100-nanosecond units
1176
+ // Maximum Packet Count DWORD 32 // maximum packet count for all index entries
1177
+ // Index Entries Count DWORD 32 // number of Index Entries structures
1178
+ // Index Entries array of: variable //
1179
+ // * Packet Number DWORD 32 // number of the Data Packet associated with this index entry
1180
+ // * Packet Count WORD 16 // number of Data Packets to sent at this index entry
1181
+
1182
+ // shortcut
1183
+ $thisfile_asf['simple_index_object'] = array();
1184
+ $thisfile_asf_simpleindexobject = &$thisfile_asf['simple_index_object'];
1185
+
1186
+ $SimpleIndexObjectData = $NextObjectDataHeader.fread($fd, 56 - 24);
1187
+ $offset = 24;
1188
+
1189
+ $thisfile_asf_simpleindexobject['objectid'] = $NextObjectGUID;
1190
+ $thisfile_asf_simpleindexobject['objectid_guid'] = $NextObjectGUIDtext;
1191
+ $thisfile_asf_simpleindexobject['objectsize'] = $NextObjectSize;
1192
+
1193
+ $thisfile_asf_simpleindexobject['fileid'] = substr($SimpleIndexObjectData, $offset, 16);
1194
+ $offset += 16;
1195
+ $thisfile_asf_simpleindexobject['fileid_guid'] = $this->BytestringToGUID($thisfile_asf_simpleindexobject['fileid']);
1196
+ $thisfile_asf_simpleindexobject['index_entry_time_interval'] = getid3_lib::LittleEndian2Int(substr($SimpleIndexObjectData, $offset, 8));
1197
+ $offset += 8;
1198
+ $thisfile_asf_simpleindexobject['maximum_packet_count'] = getid3_lib::LittleEndian2Int(substr($SimpleIndexObjectData, $offset, 4));
1199
+ $offset += 4;
1200
+ $thisfile_asf_simpleindexobject['index_entries_count'] = getid3_lib::LittleEndian2Int(substr($SimpleIndexObjectData, $offset, 4));
1201
+ $offset += 4;
1202
+
1203
+ $IndexEntriesData = $SimpleIndexObjectData.fread($fd, 6 * $thisfile_asf_simpleindexobject['index_entries_count']);
1204
+ for ($IndexEntriesCounter = 0; $IndexEntriesCounter < $thisfile_asf_simpleindexobject['index_entries_count']; $IndexEntriesCounter++) {
1205
+ $thisfile_asf_simpleindexobject['index_entries'][$IndexEntriesCounter]['packet_number'] = getid3_lib::LittleEndian2Int(substr($IndexEntriesData, $offset, 4));
1206
+ $offset += 4;
1207
+ $thisfile_asf_simpleindexobject['index_entries'][$IndexEntriesCounter]['packet_count'] = getid3_lib::LittleEndian2Int(substr($IndexEntriesData, $offset, 4));
1208
+ $offset += 2;
1209
+ }
1210
+
1211
+ break;
1212
+
1213
+ case GETID3_ASF_Index_Object:
1214
+ // 6.2 ASF top-level Index Object (optional but recommended when appropriate, 0 or 1)
1215
+ // Field Name Field Type Size (bits)
1216
+ // Object ID GUID 128 // GUID for the Index Object - GETID3_ASF_Index_Object
1217
+ // Object Size QWORD 64 // Specifies the size, in bytes, of the Index Object, including at least 34 bytes of Index Object header
1218
+ // Index Entry Time Interval DWORD 32 // Specifies the time interval between each index entry in ms.
1219
+ // Index Specifiers Count WORD 16 // Specifies the number of Index Specifiers structures in this Index Object.
1220
+ // Index Blocks Count DWORD 32 // Specifies the number of Index Blocks structures in this Index Object.
1221
+
1222
+ // Index Entry Time Interval DWORD 32 // Specifies the time interval between index entries in milliseconds. This value cannot be 0.
1223
+ // Index Specifiers Count WORD 16 // Specifies the number of entries in the Index Specifiers list. Valid values are 1 and greater.
1224
+ // Index Specifiers array of: varies //
1225
+ // * Stream Number WORD 16 // Specifies the stream number that the Index Specifiers refer to. Valid values are between 1 and 127.
1226
+ // * Index Type WORD 16 // Specifies Index Type values as follows:
1227
+ // 1 = Nearest Past Data Packet - indexes point to the data packet whose presentation time is closest to the index entry time.
1228
+ // 2 = Nearest Past Media Object - indexes point to the closest data packet containing an entire object or first fragment of an object.
1229
+ // 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.
1230
+ // Nearest Past Cleanpoint is the most common type of index.
1231
+ // Index Entry Count DWORD 32 // Specifies the number of Index Entries in the block.
1232
+ // * 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.
1233
+ // * Index Entries array of: varies //
1234
+ // * * Offsets DWORD varies // An offset value of 0xffffffff indicates an invalid offset value
1235
+
1236
+ // shortcut
1237
+ $thisfile_asf['asf_index_object'] = array();
1238
+ $thisfile_asf_asfindexobject = &$thisfile_asf['asf_index_object'];
1239
+
1240
+ $ASFIndexObjectData = $NextObjectDataHeader.fread($fd, 34 - 24);
1241
+ $offset = 24;
1242
+
1243
+ $thisfile_asf_asfindexobject['objectid'] = $NextObjectGUID;
1244
+ $thisfile_asf_asfindexobject['objectid_guid'] = $NextObjectGUIDtext;
1245
+ $thisfile_asf_asfindexobject['objectsize'] = $NextObjectSize;
1246
+
1247
+ $thisfile_asf_asfindexobject['entry_time_interval'] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 4));
1248
+ $offset += 4;
1249
+ $thisfile_asf_asfindexobject['index_specifiers_count'] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 2));
1250
+ $offset += 2;
1251
+ $thisfile_asf_asfindexobject['index_blocks_count'] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 4));
1252
+ $offset += 4;
1253
+
1254
+ $ASFIndexObjectData .= fread($fd, 4 * $thisfile_asf_asfindexobject['index_specifiers_count']);
1255
+ for ($IndexSpecifiersCounter = 0; $IndexSpecifiersCounter < $thisfile_asf_asfindexobject['index_specifiers_count']; $IndexSpecifiersCounter++) {
1256
+ $IndexSpecifierStreamNumber = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 2));
1257
+ $offset += 2;
1258
+ $thisfile_asf_asfindexobject['index_specifiers'][$IndexSpecifiersCounter]['stream_number'] = $IndexSpecifierStreamNumber;
1259
+ $thisfile_asf_asfindexobject['index_specifiers'][$IndexSpecifiersCounter]['index_type'] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 2));
1260
+ $offset += 2;
1261
+ $thisfile_asf_asfindexobject['index_specifiers'][$IndexSpecifiersCounter]['index_type_text'] = $this->ASFIndexObjectIndexTypeLookup($thisfile_asf_asfindexobject['index_specifiers'][$IndexSpecifiersCounter]['index_type']);
1262
+ }
1263
+
1264
+ $ASFIndexObjectData .= fread($fd, 4);
1265
+ $thisfile_asf_asfindexobject['index_entry_count'] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 4));
1266
+ $offset += 4;
1267
+
1268
+ $ASFIndexObjectData .= fread($fd, 8 * $thisfile_asf_asfindexobject['index_specifiers_count']);
1269
+ for ($IndexSpecifiersCounter = 0; $IndexSpecifiersCounter < $thisfile_asf_asfindexobject['index_specifiers_count']; $IndexSpecifiersCounter++) {
1270
+ $thisfile_asf_asfindexobject['block_positions'][$IndexSpecifiersCounter] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 8));
1271
+ $offset += 8;
1272
+ }
1273
+
1274
+ $ASFIndexObjectData .= fread($fd, 4 * $thisfile_asf_asfindexobject['index_specifiers_count'] * $thisfile_asf_asfindexobject['index_entry_count']);
1275
+ for ($IndexEntryCounter = 0; $IndexEntryCounter < $thisfile_asf_asfindexobject['index_entry_count']; $IndexEntryCounter++) {
1276
+ for ($IndexSpecifiersCounter = 0; $IndexSpecifiersCounter < $thisfile_asf_asfindexobject['index_specifiers_count']; $IndexSpecifiersCounter++) {
1277
+ $thisfile_asf_asfindexobject['offsets'][$IndexSpecifiersCounter][$IndexEntryCounter] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 4));
1278
+ $offset += 4;
1279
+ }
1280
+ }
1281
+ break;
1282
+
1283
+
1284
+ default:
1285
+ // Implementations shall ignore any standard or non-standard object that they do not know how to handle.
1286
+ if ($this->GUIDname($NextObjectGUIDtext)) {
1287
+ $ThisFileInfo['warning'][] = 'unhandled GUID "'.$this->GUIDname($NextObjectGUIDtext).'" {'.$NextObjectGUIDtext.'} in ASF body at offset '.($offset - 16 - 8);
1288
+ } else {
1289
+ $ThisFileInfo['warning'][] = 'unknown GUID {'.$NextObjectGUIDtext.'} in ASF body at offset '.(ftell($fd) - 16 - 8);
1290
+ }
1291
+ fseek($fd, ($NextObjectSize - 16 - 8), SEEK_CUR);
1292
+ break;
1293
+ }
1294
+ }
1295
+
1296
+ if (isset($thisfile_asf_codeclistobject['codec_entries']) && is_array($thisfile_asf_codeclistobject['codec_entries'])) {
1297
+ foreach ($thisfile_asf_codeclistobject['codec_entries'] as $streamnumber => $streamdata) {
1298
+ switch ($streamdata['information']) {
1299
+ case 'WMV1':
1300
+ case 'WMV2':
1301
+ case 'WMV3':
1302
+ case 'MSS1':
1303
+ case 'MSS2':
1304
+ case 'WMVA':
1305
+ case 'WVC1':
1306
+ case 'WMVP':
1307
+ case 'WVP2':
1308
+ $thisfile_video['dataformat'] = 'wmv';
1309
+ $ThisFileInfo['mime_type'] = 'video/x-ms-wmv';
1310
+ break;
1311
+
1312
+ case 'MP42':
1313
+ case 'MP43':
1314
+ case 'MP4S':
1315
+ case 'mp4s':
1316
+ $thisfile_video['dataformat'] = 'asf';
1317
+ $ThisFileInfo['mime_type'] = 'video/x-ms-asf';
1318
+ break;
1319
+
1320
+ default:
1321
+ switch ($streamdata['type_raw']) {
1322
+ case 1:
1323
+ if (strstr($this->TrimConvert($streamdata['name']), 'Windows Media')) {
1324
+ $thisfile_video['dataformat'] = 'wmv';
1325
+ if ($ThisFileInfo['mime_type'] == 'video/x-ms-asf') {
1326
+ $ThisFileInfo['mime_type'] = 'video/x-ms-wmv';
1327
+ }
1328
+ }
1329
+ break;
1330
+
1331
+ case 2:
1332
+ if (strstr($this->TrimConvert($streamdata['name']), 'Windows Media')) {
1333
+ $thisfile_audio['dataformat'] = 'wma';
1334
+ if ($ThisFileInfo['mime_type'] == 'video/x-ms-asf') {
1335
+ $ThisFileInfo['mime_type'] = 'audio/x-ms-wma';
1336
+ }
1337
+ }
1338
+ break;
1339
+
1340
+ }
1341
+ break;
1342
+ }
1343
+ }
1344
+ }
1345
+
1346
+ switch (@$thisfile_audio['codec']) {
1347
+ case 'MPEG Layer-3':
1348
+ $thisfile_audio['dataformat'] = 'mp3';
1349
+ break;
1350
+
1351
+ default:
1352
+ break;
1353
+ }
1354
+
1355
+ if (isset($thisfile_asf_codeclistobject['codec_entries'])) {
1356
+ foreach ($thisfile_asf_codeclistobject['codec_entries'] as $streamnumber => $streamdata) {
1357
+ switch ($streamdata['type_raw']) {
1358
+
1359
+ case 1: // video
1360
+ $thisfile_video['encoder'] = $this->TrimConvert($thisfile_asf_codeclistobject['codec_entries'][$streamnumber]['name']);
1361
+ break;
1362
+
1363
+ case 2: // audio
1364
+ $thisfile_audio['encoder'] = $this->TrimConvert($thisfile_asf_codeclistobject['codec_entries'][$streamnumber]['name']);
1365
+
1366
+ // AH 2003-10-01
1367
+ $thisfile_audio['encoder_options'] = $this->TrimConvert($thisfile_asf_codeclistobject['codec_entries'][0]['description']);
1368
+
1369
+ $thisfile_audio['codec'] = $thisfile_audio['encoder'];
1370
+ break;
1371
+
1372
+ default:
1373
+ $ThisFileInfo['warning'][] = 'Unknown streamtype: [codec_list_object][codec_entries]['.$streamnumber.'][type_raw] == '.$streamdata['type_raw'];
1374
+ break;
1375
+
1376
+ }
1377
+ }
1378
+ }
1379
+
1380
+ if (isset($ThisFileInfo['audio'])) {
1381
+ $thisfile_audio['lossless'] = (isset($thisfile_audio['lossless']) ? $thisfile_audio['lossless'] : false);
1382
+ $thisfile_audio['dataformat'] = (!empty($thisfile_audio['dataformat']) ? $thisfile_audio['dataformat'] : 'asf');
1383
+ }
1384
+ if (!empty($thisfile_video['dataformat'])) {
1385
+ $thisfile_video['lossless'] = (isset($thisfile_audio['lossless']) ? $thisfile_audio['lossless'] : false);
1386
+ $thisfile_video['pixel_aspect_ratio'] = (isset($thisfile_audio['pixel_aspect_ratio']) ? $thisfile_audio['pixel_aspect_ratio'] : (float) 1);
1387
+ $thisfile_video['dataformat'] = (!empty($thisfile_video['dataformat']) ? $thisfile_video['dataformat'] : 'asf');
1388
+ }
1389
+ if (!empty($thisfile_video['streams'])) {
1390
+ $thisfile_video['streams']['resolution_x'] = 0;
1391
+ $thisfile_video['streams']['resolution_y'] = 0;
1392
+ foreach ($thisfile_video['streams'] as $key => $valuearray) {
1393
+ if (($valuearray['resolution_x'] > $thisfile_video['streams']['resolution_x']) || ($valuearray['resolution_y'] > $thisfile_video['streams']['resolution_y'])) {
1394
+ $thisfile_video['resolution_x'] = $valuearray['resolution_x'];
1395
+ $thisfile_video['resolution_y'] = $valuearray['resolution_y'];
1396
+ }
1397
+ }
1398
+ }
1399
+ $ThisFileInfo['bitrate'] = @$thisfile_audio['bitrate'] + @$thisfile_video['bitrate'];
1400
+
1401
+ if ((!isset($ThisFileInfo['playtime_seconds']) || ($ThisFileInfo['playtime_seconds'] <= 0)) && ($ThisFileInfo['bitrate'] > 0)) {
1402
+ $ThisFileInfo['playtime_seconds'] = ($ThisFileInfo['filesize'] - $ThisFileInfo['avdataoffset']) / ($ThisFileInfo['bitrate'] / 8);
1403
+ }
1404
+
1405
+ return true;
1406
+ }
1407
+
1408
+ function ASFCodecListObjectTypeLookup($CodecListType) {
1409
+ static $ASFCodecListObjectTypeLookup = array();
1410
+ if (empty($ASFCodecListObjectTypeLookup)) {
1411
+ $ASFCodecListObjectTypeLookup[0x0001] = 'Video Codec';
1412
+ $ASFCodecListObjectTypeLookup[0x0002] = 'Audio Codec';
1413
+ $ASFCodecListObjectTypeLookup[0xFFFF] = 'Unknown Codec';
1414
+ }
1415
+
1416
+ return (isset($ASFCodecListObjectTypeLookup[$CodecListType]) ? $ASFCodecListObjectTypeLookup[$CodecListType] : 'Invalid Codec Type');
1417
+ }
1418
+
1419
+ function KnownGUIDs() {
1420
+ static $GUIDarray = array();
1421
+ if (empty($GUIDarray)) {
1422
+ $GUIDarray['GETID3_ASF_Extended_Stream_Properties_Object'] = '14E6A5CB-C672-4332-8399-A96952065B5A';
1423
+ $GUIDarray['GETID3_ASF_Padding_Object'] = '1806D474-CADF-4509-A4BA-9AABCB96AAE8';
1424
+ $GUIDarray['GETID3_ASF_Payload_Ext_Syst_Pixel_Aspect_Ratio'] = '1B1EE554-F9EA-4BC8-821A-376B74E4C4B8';
1425
+ $GUIDarray['GETID3_ASF_Script_Command_Object'] = '1EFB1A30-0B62-11D0-A39B-00A0C90348F6';
1426
+ $GUIDarray['GETID3_ASF_No_Error_Correction'] = '20FB5700-5B55-11CF-A8FD-00805F5C442B';
1427
+ $GUIDarray['GETID3_ASF_Content_Branding_Object'] = '2211B3FA-BD23-11D2-B4B7-00A0C955FC6E';
1428
+ $GUIDarray['GETID3_ASF_Content_Encryption_Object'] = '2211B3FB-BD23-11D2-B4B7-00A0C955FC6E';
1429
+ $GUIDarray['GETID3_ASF_Digital_Signature_Object'] = '2211B3FC-BD23-11D2-B4B7-00A0C955FC6E';
1430
+ $GUIDarray['GETID3_ASF_Extended_Content_Encryption_Object'] = '298AE614-2622-4C17-B935-DAE07EE9289C';
1431
+ $GUIDarray['GETID3_ASF_Simple_Index_Object'] = '33000890-E5B1-11CF-89F4-00A0C90349CB';
1432
+ $GUIDarray['GETID3_ASF_Degradable_JPEG_Media'] = '35907DE0-E415-11CF-A917-00805F5C442B';
1433
+ $GUIDarray['GETID3_ASF_Payload_Extension_System_Timecode'] = '399595EC-8667-4E2D-8FDB-98814CE76C1E';
1434
+ $GUIDarray['GETID3_ASF_Binary_Media'] = '3AFB65E2-47EF-40F2-AC2C-70A90D71D343';
1435
+ $GUIDarray['GETID3_ASF_Timecode_Index_Object'] = '3CB73FD0-0C4A-4803-953D-EDF7B6228F0C';
1436
+ $GUIDarray['GETID3_ASF_Metadata_Library_Object'] = '44231C94-9498-49D1-A141-1D134E457054';
1437
+ $GUIDarray['GETID3_ASF_Reserved_3'] = '4B1ACBE3-100B-11D0-A39B-00A0C90348F6';
1438
+ $GUIDarray['GETID3_ASF_Reserved_4'] = '4CFEDB20-75F6-11CF-9C0F-00A0C90349CB';
1439
+ $GUIDarray['GETID3_ASF_Command_Media'] = '59DACFC0-59E6-11D0-A3AC-00A0C90348F6';
1440
+ $GUIDarray['GETID3_ASF_Header_Extension_Object'] = '5FBF03B5-A92E-11CF-8EE3-00C00C205365';
1441
+ $GUIDarray['GETID3_ASF_Media_Object_Index_Parameters_Obj'] = '6B203BAD-3F11-4E84-ACA8-D7613DE2CFA7';
1442
+ $GUIDarray['GETID3_ASF_Header_Object'] = '75B22630-668E-11CF-A6D9-00AA0062CE6C';
1443
+ $GUIDarray['GETID3_ASF_Content_Description_Object'] = '75B22633-668E-11CF-A6D9-00AA0062CE6C';
1444
+ $GUIDarray['GETID3_ASF_Error_Correction_Object'] = '75B22635-668E-11CF-A6D9-00AA0062CE6C';
1445
+ $GUIDarray['GETID3_ASF_Data_Object'] = '75B22636-668E-11CF-A6D9-00AA0062CE6C';
1446
+ $GUIDarray['GETID3_ASF_Web_Stream_Media_Subtype'] = '776257D4-C627-41CB-8F81-7AC7FF1C40CC';
1447
+ $GUIDarray['GETID3_ASF_Stream_Bitrate_Properties_Object'] = '7BF875CE-468D-11D1-8D82-006097C9A2B2';
1448
+ $GUIDarray['GETID3_ASF_Language_List_Object'] = '7C4346A9-EFE0-4BFC-B229-393EDE415C85';
1449
+ $GUIDarray['GETID3_ASF_Codec_List_Object'] = '86D15240-311D-11D0-A3A4-00A0C90348F6';
1450
+ $GUIDarray['GETID3_ASF_Reserved_2'] = '86D15241-311D-11D0-A3A4-00A0C90348F6';
1451
+ $GUIDarray['GETID3_ASF_File_Properties_Object'] = '8CABDCA1-A947-11CF-8EE4-00C00C205365';
1452
+ $GUIDarray['GETID3_ASF_File_Transfer_Media'] = '91BD222C-F21C-497A-8B6D-5AA86BFC0185';
1453
+ $GUIDarray['GETID3_ASF_Old_RTP_Extension_Data'] = '96800C63-4C94-11D1-837B-0080C7A37F95';
1454
+ $GUIDarray['GETID3_ASF_Advanced_Mutual_Exclusion_Object'] = 'A08649CF-4775-4670-8A16-6E35357566CD';
1455
+ $GUIDarray['GETID3_ASF_Bandwidth_Sharing_Object'] = 'A69609E6-517B-11D2-B6AF-00C04FD908E9';
1456
+ $GUIDarray['GETID3_ASF_Reserved_1'] = 'ABD3D211-A9BA-11cf-8EE6-00C00C205365';
1457
+ $GUIDarray['GETID3_ASF_Bandwidth_Sharing_Exclusive'] = 'AF6060AA-5197-11D2-B6AF-00C04FD908E9';
1458
+ $GUIDarray['GETID3_ASF_Bandwidth_Sharing_Partial'] = 'AF6060AB-5197-11D2-B6AF-00C04FD908E9';
1459
+ $GUIDarray['GETID3_ASF_JFIF_Media'] = 'B61BE100-5B4E-11CF-A8FD-00805F5C442B';
1460
+ $GUIDarray['GETID3_ASF_Stream_Properties_Object'] = 'B7DC0791-A9B7-11CF-8EE6-00C00C205365';
1461
+ $GUIDarray['GETID3_ASF_Video_Media'] = 'BC19EFC0-5B4D-11CF-A8FD-00805F5C442B';
1462
+ $GUIDarray['GETID3_ASF_Audio_Spread'] = 'BFC3CD50-618F-11CF-8BB2-00AA00B4E220';
1463
+ $GUIDarray['GETID3_ASF_Metadata_Object'] = 'C5F8CBEA-5BAF-4877-8467-AA8C44FA4CCA';
1464
+ $GUIDarray['GETID3_ASF_Payload_Ext_Syst_Sample_Duration'] = 'C6BD9450-867F-4907-83A3-C77921B733AD';
1465
+ $GUIDarray['GETID3_ASF_Group_Mutual_Exclusion_Object'] = 'D1465A40-5A79-4338-B71B-E36B8FD6C249';
1466
+ $GUIDarray['GETID3_ASF_Extended_Content_Description_Object'] = 'D2D0A440-E307-11D2-97F0-00A0C95EA850';
1467
+ $GUIDarray['GETID3_ASF_Stream_Prioritization_Object'] = 'D4FED15B-88D3-454F-81F0-ED5C45999E24';
1468
+ $GUIDarray['GETID3_ASF_Payload_Ext_System_Content_Type'] = 'D590DC20-07BC-436C-9CF7-F3BBFBF1A4DC';
1469
+ $GUIDarray['GETID3_ASF_Old_File_Properties_Object'] = 'D6E229D0-35DA-11D1-9034-00A0C90349BE';
1470
+ $GUIDarray['GETID3_ASF_Old_ASF_Header_Object'] = 'D6E229D1-35DA-11D1-9034-00A0C90349BE';
1471
+ $GUIDarray['GETID3_ASF_Old_ASF_Data_Object'] = 'D6E229D2-35DA-11D1-9034-00A0C90349BE';
1472
+ $GUIDarray['GETID3_ASF_Index_Object'] = 'D6E229D3-35DA-11D1-9034-00A0C90349BE';
1473
+ $GUIDarray['GETID3_ASF_Old_Stream_Properties_Object'] = 'D6E229D4-35DA-11D1-9034-00A0C90349BE';
1474
+ $GUIDarray['GETID3_ASF_Old_Content_Description_Object'] = 'D6E229D5-35DA-11D1-9034-00A0C90349BE';
1475
+ $GUIDarray['GETID3_ASF_Old_Script_Command_Object'] = 'D6E229D6-35DA-11D1-9034-00A0C90349BE';
1476
+ $GUIDarray['GETID3_ASF_Old_Marker_Object'] = 'D6E229D7-35DA-11D1-9034-00A0C90349BE';
1477
+ $GUIDarray['GETID3_ASF_Old_Component_Download_Object'] = 'D6E229D8-35DA-11D1-9034-00A0C90349BE';
1478
+ $GUIDarray['GETID3_ASF_Old_Stream_Group_Object'] = 'D6E229D9-35DA-11D1-9034-00A0C90349BE';
1479
+ $GUIDarray['GETID3_ASF_Old_Scalable_Object'] = 'D6E229DA-35DA-11D1-9034-00A0C90349BE';
1480
+ $GUIDarray['GETID3_ASF_Old_Prioritization_Object'] = 'D6E229DB-35DA-11D1-9034-00A0C90349BE';
1481
+ $GUIDarray['GETID3_ASF_Bitrate_Mutual_Exclusion_Object'] = 'D6E229DC-35DA-11D1-9034-00A0C90349BE';
1482
+ $GUIDarray['GETID3_ASF_Old_Inter_Media_Dependency_Object'] = 'D6E229DD-35DA-11D1-9034-00A0C90349BE';
1483
+ $GUIDarray['GETID3_ASF_Old_Rating_Object'] = 'D6E229DE-35DA-11D1-9034-00A0C90349BE';
1484
+ $GUIDarray['GETID3_ASF_Index_Parameters_Object'] = 'D6E229DF-35DA-11D1-9034-00A0C90349BE';
1485
+ $GUIDarray['GETID3_ASF_Old_Color_Table_Object'] = 'D6E229E0-35DA-11D1-9034-00A0C90349BE';
1486
+ $GUIDarray['GETID3_ASF_Old_Language_List_Object'] = 'D6E229E1-35DA-11D1-9034-00A0C90349BE';
1487
+ $GUIDarray['GETID3_ASF_Old_Audio_Media'] = 'D6E229E2-35DA-11D1-9034-00A0C90349BE';
1488
+ $GUIDarray['GETID3_ASF_Old_Video_Media'] = 'D6E229E3-35DA-11D1-9034-00A0C90349BE';
1489
+ $GUIDarray['GETID3_ASF_Old_Image_Media'] = 'D6E229E4-35DA-11D1-9034-00A0C90349BE';
1490
+ $GUIDarray['GETID3_ASF_Old_Timecode_Media'] = 'D6E229E5-35DA-11D1-9034-00A0C90349BE';
1491
+ $GUIDarray['GETID3_ASF_Old_Text_Media'] = 'D6E229E6-35DA-11D1-9034-00A0C90349BE';
1492
+ $GUIDarray['GETID3_ASF_Old_MIDI_Media'] = 'D6E229E7-35DA-11D1-9034-00A0C90349BE';
1493
+ $GUIDarray['GETID3_ASF_Old_Command_Media'] = 'D6E229E8-35DA-11D1-9034-00A0C90349BE';
1494
+ $GUIDarray['GETID3_ASF_Old_No_Error_Concealment'] = 'D6E229EA-35DA-11D1-9034-00A0C90349BE';
1495
+ $GUIDarray['GETID3_ASF_Old_Scrambled_Audio'] = 'D6E229EB-35DA-11D1-9034-00A0C90349BE';
1496
+ $GUIDarray['GETID3_ASF_Old_No_Color_Table'] = 'D6E229EC-35DA-11D1-9034-00A0C90349BE';
1497
+ $GUIDarray['GETID3_ASF_Old_SMPTE_Time'] = 'D6E229ED-35DA-11D1-9034-00A0C90349BE';
1498
+ $GUIDarray['GETID3_ASF_Old_ASCII_Text'] = 'D6E229EE-35DA-11D1-9034-00A0C90349BE';
1499
+ $GUIDarray['GETID3_ASF_Old_Unicode_Text'] = 'D6E229EF-35DA-11D1-9034-00A0C90349BE';
1500
+ $GUIDarray['GETID3_ASF_Old_HTML_Text'] = 'D6E229F0-35DA-11D1-9034-00A0C90349BE';
1501
+ $GUIDarray['GETID3_ASF_Old_URL_Command'] = 'D6E229F1-35DA-11D1-9034-00A0C90349BE';
1502
+ $GUIDarray['GETID3_ASF_Old_Filename_Command'] = 'D6E229F2-35DA-11D1-9034-00A0C90349BE';
1503
+ $GUIDarray['GETID3_ASF_Old_ACM_Codec'] = 'D6E229F3-35DA-11D1-9034-00A0C90349BE';
1504
+ $GUIDarray['GETID3_ASF_Old_VCM_Codec'] = 'D6E229F4-35DA-11D1-9034-00A0C90349BE';
1505
+ $GUIDarray['GETID3_ASF_Old_QuickTime_Codec'] = 'D6E229F5-35DA-11D1-9034-00A0C90349BE';
1506
+ $GUIDarray['GETID3_ASF_Old_DirectShow_Transform_Filter'] = 'D6E229F6-35DA-11D1-9034-00A0C90349BE';
1507
+ $GUIDarray['GETID3_ASF_Old_DirectShow_Rendering_Filter'] = 'D6E229F7-35DA-11D1-9034-00A0C90349BE';
1508
+ $GUIDarray['GETID3_ASF_Old_No_Enhancement'] = 'D6E229F8-35DA-11D1-9034-00A0C90349BE';
1509
+ $GUIDarray['GETID3_ASF_Old_Unknown_Enhancement_Type'] = 'D6E229F9-35DA-11D1-9034-00A0C90349BE';
1510
+ $GUIDarray['GETID3_ASF_Old_Temporal_Enhancement'] = 'D6E229FA-35DA-11D1-9034-00A0C90349BE';
1511
+ $GUIDarray['GETID3_ASF_Old_Spatial_Enhancement'] = 'D6E229FB-35DA-11D1-9034-00A0C90349BE';
1512
+ $GUIDarray['GETID3_ASF_Old_Quality_Enhancement'] = 'D6E229FC-35DA-11D1-9034-00A0C90349BE';
1513
+ $GUIDarray['GETID3_ASF_Old_Number_of_Channels_Enhancement'] = 'D6E229FD-35DA-11D1-9034-00A0C90349BE';
1514
+ $GUIDarray['GETID3_ASF_Old_Frequency_Response_Enhancement'] = 'D6E229FE-35DA-11D1-9034-00A0C90349BE';
1515
+ $GUIDarray['GETID3_ASF_Old_Media_Object'] = 'D6E229FF-35DA-11D1-9034-00A0C90349BE';
1516
+ $GUIDarray['GETID3_ASF_Mutex_Language'] = 'D6E22A00-35DA-11D1-9034-00A0C90349BE';
1517
+ $GUIDarray['GETID3_ASF_Mutex_Bitrate'] = 'D6E22A01-35DA-11D1-9034-00A0C90349BE';
1518
+ $GUIDarray['GETID3_ASF_Mutex_Unknown'] = 'D6E22A02-35DA-11D1-9034-00A0C90349BE';
1519
+ $GUIDarray['GETID3_ASF_Old_ASF_Placeholder_Object'] = 'D6E22A0E-35DA-11D1-9034-00A0C90349BE';
1520
+ $GUIDarray['GETID3_ASF_Old_Data_Unit_Extension_Object'] = 'D6E22A0F-35DA-11D1-9034-00A0C90349BE';
1521
+ $GUIDarray['GETID3_ASF_Web_Stream_Format'] = 'DA1E6B13-8359-4050-B398-388E965BF00C';
1522
+ $GUIDarray['GETID3_ASF_Payload_Ext_System_File_Name'] = 'E165EC0E-19ED-45D7-B4A7-25CBD1E28E9B';
1523
+ $GUIDarray['GETID3_ASF_Marker_Object'] = 'F487CD01-A951-11CF-8EE6-00C00C205365';
1524
+ $GUIDarray['GETID3_ASF_Timecode_Index_Parameters_Object'] = 'F55E496D-9797-4B5D-8C8B-604DFE9BFB24';
1525
+ $GUIDarray['GETID3_ASF_Audio_Media'] = 'F8699E40-5B4D-11CF-A8FD-00805F5C442B';
1526
+ $GUIDarray['GETID3_ASF_Media_Object_Index_Object'] = 'FEB103F8-12AD-4C64-840F-2A1D2F7AD48C';
1527
+ $GUIDarray['GETID3_ASF_Alt_Extended_Content_Encryption_Obj'] = 'FF889EF1-ADEE-40DA-9E71-98704BB928CE';
1528
+ }
1529
+ return $GUIDarray;
1530
+ }
1531
+
1532
+ function GUIDname($GUIDstring) {
1533
+ static $GUIDarray = array();
1534
+ if (empty($GUIDarray)) {
1535
+ $GUIDarray = $this->KnownGUIDs();
1536
+ }
1537
+ return array_search($GUIDstring, $GUIDarray);
1538
+ }
1539
+
1540
+ function ASFIndexObjectIndexTypeLookup($id) {
1541
+ static $ASFIndexObjectIndexTypeLookup = array();
1542
+ if (empty($ASFIndexObjectIndexTypeLookup)) {
1543
+ $ASFIndexObjectIndexTypeLookup[1] = 'Nearest Past Data Packet';
1544
+ $ASFIndexObjectIndexTypeLookup[2] = 'Nearest Past Media Object';
1545
+ $ASFIndexObjectIndexTypeLookup[3] = 'Nearest Past Cleanpoint';
1546
+ }
1547
+ return (isset($ASFIndexObjectIndexTypeLookup[$id]) ? $ASFIndexObjectIndexTypeLookup[$id] : 'invalid');
1548
+ }
1549
+
1550
+ function GUIDtoBytestring($GUIDstring) {
1551
+ // Microsoft defines these 16-byte (128-bit) GUIDs in the strangest way:
1552
+ // first 4 bytes are in little-endian order
1553
+ // next 2 bytes are appended in little-endian order
1554
+ // next 2 bytes are appended in little-endian order
1555
+ // next 2 bytes are appended in big-endian order
1556
+ // next 6 bytes are appended in big-endian order
1557
+
1558
+ // AaBbCcDd-EeFf-GgHh-IiJj-KkLlMmNnOoPp is stored as this 16-byte string:
1559
+ // $Dd $Cc $Bb $Aa $Ff $Ee $Hh $Gg $Ii $Jj $Kk $Ll $Mm $Nn $Oo $Pp
1560
+
1561
+ $hexbytecharstring = chr(hexdec(substr($GUIDstring, 6, 2)));
1562
+ $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 4, 2)));
1563
+ $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 2, 2)));
1564
+ $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 0, 2)));
1565
+
1566
+ $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 11, 2)));
1567
+ $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 9, 2)));
1568
+
1569
+ $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 16, 2)));
1570
+ $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 14, 2)));
1571
+
1572
+ $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 19, 2)));
1573
+ $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 21, 2)));
1574
+
1575
+ $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 24, 2)));
1576
+ $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 26, 2)));
1577
+ $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 28, 2)));
1578
+ $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 30, 2)));
1579
+ $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 32, 2)));
1580
+ $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 34, 2)));
1581
+
1582
+ return $hexbytecharstring;
1583
+ }
1584
+
1585
+ function BytestringToGUID($Bytestring) {
1586
+ $GUIDstring = str_pad(dechex(ord($Bytestring{3})), 2, '0', STR_PAD_LEFT);
1587
+ $GUIDstring .= str_pad(dechex(ord($Bytestring{2})), 2, '0', STR_PAD_LEFT);
1588
+ $GUIDstring .= str_pad(dechex(ord($Bytestring{1})), 2, '0', STR_PAD_LEFT);
1589
+ $GUIDstring .= str_pad(dechex(ord($Bytestring{0})), 2, '0', STR_PAD_LEFT);
1590
+ $GUIDstring .= '-';
1591
+ $GUIDstring .= str_pad(dechex(ord($Bytestring{5})), 2, '0', STR_PAD_LEFT);
1592
+ $GUIDstring .= str_pad(dechex(ord($Bytestring{4})), 2, '0', STR_PAD_LEFT);
1593
+ $GUIDstring .= '-';
1594
+ $GUIDstring .= str_pad(dechex(ord($Bytestring{7})), 2, '0', STR_PAD_LEFT);
1595
+ $GUIDstring .= str_pad(dechex(ord($Bytestring{6})), 2, '0', STR_PAD_LEFT);
1596
+ $GUIDstring .= '-';
1597
+ $GUIDstring .= str_pad(dechex(ord($Bytestring{8})), 2, '0', STR_PAD_LEFT);
1598
+ $GUIDstring .= str_pad(dechex(ord($Bytestring{9})), 2, '0', STR_PAD_LEFT);
1599
+ $GUIDstring .= '-';
1600
+ $GUIDstring .= str_pad(dechex(ord($Bytestring{10})), 2, '0', STR_PAD_LEFT);
1601
+ $GUIDstring .= str_pad(dechex(ord($Bytestring{11})), 2, '0', STR_PAD_LEFT);
1602
+ $GUIDstring .= str_pad(dechex(ord($Bytestring{12})), 2, '0', STR_PAD_LEFT);
1603
+ $GUIDstring .= str_pad(dechex(ord($Bytestring{13})), 2, '0', STR_PAD_LEFT);
1604
+ $GUIDstring .= str_pad(dechex(ord($Bytestring{14})), 2, '0', STR_PAD_LEFT);
1605
+ $GUIDstring .= str_pad(dechex(ord($Bytestring{15})), 2, '0', STR_PAD_LEFT);
1606
+
1607
+ return strtoupper($GUIDstring);
1608
+ }
1609
+
1610
+ function FILETIMEtoUNIXtime($FILETIME, $round=true) {
1611
+ // FILETIME is a 64-bit unsigned integer representing
1612
+ // the number of 100-nanosecond intervals since January 1, 1601
1613
+ // UNIX timestamp is number of seconds since January 1, 1970
1614
+ // 116444736000000000 = 10000000 * 60 * 60 * 24 * 365 * 369 + 89 leap days
1615
+ if ($round) {
1616
+ return intval(round(($FILETIME - 116444736000000000) / 10000000));
1617
+ }
1618
+ return ($FILETIME - 116444736000000000) / 10000000;
1619
+ }
1620
+
1621
+ function WMpictureTypeLookup($WMpictureType) {
1622
+ static $WMpictureTypeLookup = array();
1623
+ if (empty($WMpictureTypeLookup)) {
1624
+ $WMpictureTypeLookup[0x03] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Front Cover');
1625
+ $WMpictureTypeLookup[0x04] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Back Cover');
1626
+ $WMpictureTypeLookup[0x00] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'User Defined');
1627
+ $WMpictureTypeLookup[0x05] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Leaflet Page');
1628
+ $WMpictureTypeLookup[0x06] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Media Label');
1629
+ $WMpictureTypeLookup[0x07] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Lead Artist');
1630
+ $WMpictureTypeLookup[0x08] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Artist');
1631
+ $WMpictureTypeLookup[0x09] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Conductor');
1632
+ $WMpictureTypeLookup[0x0A] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Band');
1633
+ $WMpictureTypeLookup[0x0B] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Composer');
1634
+ $WMpictureTypeLookup[0x0C] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Lyricist');
1635
+ $WMpictureTypeLookup[0x0D] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Recording Location');
1636
+ $WMpictureTypeLookup[0x0E] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'During Recording');
1637
+ $WMpictureTypeLookup[0x0F] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'During Performance');
1638
+ $WMpictureTypeLookup[0x10] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Video Screen Capture');
1639
+ $WMpictureTypeLookup[0x12] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Illustration');
1640
+ $WMpictureTypeLookup[0x13] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Band Logotype');
1641
+ $WMpictureTypeLookup[0x14] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Publisher Logotype');
1642
+ }
1643
+ return @$WMpictureTypeLookup[$WMpictureType];
1644
+ }
1645
+
1646
+
1647
+ // Remove terminator 00 00 and convert UNICODE to Latin-1
1648
+ function TrimConvert($string) {
1649
+
1650
+ // remove terminator, only if present (it should be, but...)
1651
+ if (substr($string, strlen($string) - 2, 2) == "\x00\x00") {
1652
+ $string = substr($string, 0, strlen($string) - 2);
1653
+ }
1654
+
1655
+ // convert
1656
+ return trim(getid3_lib::iconv_fallback('UTF-16LE', 'ISO-8859-1', $string), ' ');
1657
+ }
1658
+
1659
+
1660
+ function TrimTerm($string) {
1661
+
1662
+ // remove terminator, only if present (it should be, but...)
1663
+ if (substr($string, -2) == "\x00\x00") {
1664
+ $string = substr($string, 0, -2);
1665
+ }
1666
+ return $string;
1667
+ }
1668
+
1669
+
1670
+ }
1671
+
1672
+
1673
+ ?>
view/getid3/module.audio-video.bink.php ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /////////////////////////////////////////////////////////////////
3
+ /// getID3() by James Heinrich <info@getid3.org> //
4
+ // available at http://getid3.sourceforge.net //
5
+ // or http://www.getid3.org //
6
+ /////////////////////////////////////////////////////////////////
7
+ // See readme.txt for more details //
8
+ /////////////////////////////////////////////////////////////////
9
+ // //
10
+ // module.audio.bink.php //
11
+ // module for analyzing Bink or Smacker audio-video files //
12
+ // dependencies: NONE //
13
+ // ///
14
+ /////////////////////////////////////////////////////////////////
15
+
16
+
17
+ class getid3_bink
18
+ {
19
+
20
+ function getid3_bink(&$fd, &$ThisFileInfo) {
21
+
22
+ $ThisFileInfo['error'][] = 'Bink / Smacker files not properly processed by this version of getID3()';
23
+
24
+ fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
25
+ $fileTypeID = fread($fd, 3);
26
+ switch ($fileTypeID) {
27
+ case 'BIK':
28
+ return $this->ParseBink($fd, $ThisFileInfo);
29
+ break;
30
+
31
+ case 'SMK':
32
+ return $this->ParseSmacker($fd, $ThisFileInfo);
33
+ break;
34
+
35
+ default:
36
+ $ThisFileInfo['error'][] = 'Expecting "BIK" or "SMK" at offset '.$ThisFileInfo['avdataoffset'].', found "'.$fileTypeID.'"';
37
+ return false;
38
+ break;
39
+ }
40
+
41
+ return true;
42
+
43
+ }
44
+
45
+ function ParseBink(&$fd, &$ThisFileInfo) {
46
+ $ThisFileInfo['fileformat'] = 'bink';
47
+ $ThisFileInfo['video']['dataformat'] = 'bink';
48
+
49
+ $fileData = 'BIK'.fread($fd, 13);
50
+
51
+ $ThisFileInfo['bink']['data_size'] = getid3_lib::LittleEndian2Int(substr($fileData, 4, 4));
52
+ $ThisFileInfo['bink']['frame_count'] = getid3_lib::LittleEndian2Int(substr($fileData, 8, 2));
53
+
54
+ if (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) != ($ThisFileInfo['bink']['data_size'] + 8)) {
55
+ $ThisFileInfo['error'][] = 'Probably truncated file: expecting '.$ThisFileInfo['bink']['data_size'].' bytes, found '.($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']);
56
+ }
57
+
58
+ return true;
59
+ }
60
+
61
+ function ParseSmacker(&$fd, &$ThisFileInfo) {
62
+ $ThisFileInfo['fileformat'] = 'smacker';
63
+ $ThisFileInfo['video']['dataformat'] = 'smacker';
64
+
65
+ return false;
66
+ }
67
+
68
+ }
69
+
70
+ ?>
view/getid3/module.audio-video.flv.php ADDED
@@ -0,0 +1,505 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /////////////////////////////////////////////////////////////////
3
+ /// getID3() by James Heinrich <info@getid3.org> //
4
+ // available at http://getid3.sourceforge.net //
5
+ // or http://www.getid3.org //
6
+ // //
7
+ // FLV module by Seth Kaufman <seth@whirl-i-gig.com> //
8
+ // //
9
+ // * version 0.1 (26 June 2005) //
10
+ // //
11
+ // minor modifications by James Heinrich <info@getid3.org> //
12
+ // * version 0.1.1 (15 July 2005) //
13
+ // //
14
+ // Support for On2 VP6 codec and meta information //
15
+ // by Steve Webster <steve.webster@featurecreep.com> //
16
+ // * version 0.2 (22 February 2006) //
17
+ // //
18
+ // Modified to not read entire file into memory //
19
+ // by James Heinrich <info@getid3.org> //
20
+ // * version 0.3 (15 June 2006) //
21
+ // //
22
+ // Bugfixes for incorrectly parsed FLV dimensions //
23
+ // and incorrect parsing of onMetaTag //
24
+ // by Evgeny Moysevich <moysevich@gmail.com> //
25
+ // * version 0.4 (07 December 2007) //
26
+ // //
27
+ /////////////////////////////////////////////////////////////////
28
+ // //
29
+ // module.audio-video.flv.php //
30
+ // module for analyzing Shockwave Flash Video files //
31
+ // dependencies: NONE //
32
+ // ///
33
+ /////////////////////////////////////////////////////////////////
34
+
35
+ define('GETID3_FLV_TAG_AUDIO', 8);
36
+ define('GETID3_FLV_TAG_VIDEO', 9);
37
+ define('GETID3_FLV_TAG_META', 18);
38
+
39
+ define('GETID3_FLV_VIDEO_H263', 2);
40
+ define('GETID3_FLV_VIDEO_SCREEN', 3);
41
+ define('GETID3_FLV_VIDEO_VP6', 4);
42
+
43
+ class getid3_flv
44
+ {
45
+
46
+ function getid3_flv(&$fd, &$ThisFileInfo, $ReturnAllTagData=false) {
47
+ //$start_time = microtime(true);
48
+ fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
49
+
50
+ $FLVdataLength = $ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset'];
51
+ $FLVheader = fread($fd, 5);
52
+
53
+ $ThisFileInfo['fileformat'] = 'flv';
54
+ $ThisFileInfo['flv']['header']['signature'] = substr($FLVheader, 0, 3);
55
+ $ThisFileInfo['flv']['header']['version'] = getid3_lib::BigEndian2Int(substr($FLVheader, 3, 1));
56
+ $TypeFlags = getid3_lib::BigEndian2Int(substr($FLVheader, 4, 1));
57
+
58
+ if ($ThisFileInfo['flv']['header']['signature'] != 'FLV') {
59
+ $ThisFileInfo['error'][] = 'Expecting "FLV" at offset '.$ThisFileInfo['avdataoffset'].', found "'.$ThisFileInfo['flv']['header']['signature'].'"';
60
+ unset($ThisFileInfo['flv']);
61
+ unset($ThisFileInfo['fileformat']);
62
+ return false;
63
+ }
64
+
65
+ $ThisFileInfo['flv']['header']['hasAudio'] = (bool) ($TypeFlags & 0x04);
66
+ $ThisFileInfo['flv']['header']['hasVideo'] = (bool) ($TypeFlags & 0x01);
67
+
68
+ $FrameSizeDataLength = getid3_lib::BigEndian2Int(fread($fd, 4));
69
+ $FLVheaderFrameLength = 9;
70
+ if ($FrameSizeDataLength > $FLVheaderFrameLength) {
71
+ fseek($fd, $FrameSizeDataLength - $FLVheaderFrameLength, SEEK_CUR);
72
+ }
73
+ //echo __LINE__.'='.number_format(microtime(true) - $start_time, 3).'<br>';
74
+
75
+ $Duration = 0;
76
+ $found_video = false;
77
+ $found_audio = false;
78
+ $found_meta = false;
79
+ while ((ftell($fd) + 16) < $ThisFileInfo['avdataend']) {
80
+ $ThisTagHeader = fread($fd, 16);
81
+
82
+ $PreviousTagLength = getid3_lib::BigEndian2Int(substr($ThisTagHeader, 0, 4));
83
+ $TagType = getid3_lib::BigEndian2Int(substr($ThisTagHeader, 4, 1));
84
+ $DataLength = getid3_lib::BigEndian2Int(substr($ThisTagHeader, 5, 3));
85
+ $Timestamp = getid3_lib::BigEndian2Int(substr($ThisTagHeader, 8, 3));
86
+ $LastHeaderByte = getid3_lib::BigEndian2Int(substr($ThisTagHeader, 15, 1));
87
+ $NextOffset = ftell($fd) - 1 + $DataLength;
88
+ if ($Timestamp > $Duration) {
89
+ $Duration = $Timestamp;
90
+ }
91
+
92
+ //echo __LINE__.'['.ftell($fd).']=('.$TagType.')='.number_format(microtime(true) - $start_time, 3).'<br>';
93
+
94
+ switch ($TagType) {
95
+ case GETID3_FLV_TAG_AUDIO:
96
+ if (!$found_audio) {
97
+ $found_audio = true;
98
+ $ThisFileInfo['flv']['audio']['audioFormat'] = $LastHeaderByte & 0x07;
99
+ $ThisFileInfo['flv']['audio']['audioRate'] = ($LastHeaderByte & 0x30) / 0x10;
100
+ $ThisFileInfo['flv']['audio']['audioSampleSize'] = ($LastHeaderByte & 0x40) / 0x40;
101
+ $ThisFileInfo['flv']['audio']['audioType'] = ($LastHeaderByte & 0x80) / 0x80;
102
+ }
103
+ break;
104
+
105
+ case GETID3_FLV_TAG_VIDEO:
106
+ if (!$found_video) {
107
+ $found_video = true;
108
+ $ThisFileInfo['flv']['video']['videoCodec'] = $LastHeaderByte & 0x07;
109
+
110
+ $FLVvideoHeader = fread($fd, 11);
111
+
112
+ if ($ThisFileInfo['flv']['video']['videoCodec'] != GETID3_FLV_VIDEO_VP6) {
113
+
114
+ $PictureSizeType = (getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 3, 2))) >> 7;
115
+ $PictureSizeType = $PictureSizeType & 0x0007;
116
+ $ThisFileInfo['flv']['header']['videoSizeType'] = $PictureSizeType;
117
+ switch ($PictureSizeType) {
118
+ case 0:
119
+ //$PictureSizeEnc = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 5, 2));
120
+ //$PictureSizeEnc <<= 1;
121
+ //$ThisFileInfo['video']['resolution_x'] = ($PictureSizeEnc & 0xFF00) >> 8;
122
+ //$PictureSizeEnc = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 6, 2));
123
+ //$PictureSizeEnc <<= 1;
124
+ //$ThisFileInfo['video']['resolution_y'] = ($PictureSizeEnc & 0xFF00) >> 8;
125
+
126
+ $PictureSizeEnc['x'] = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 4, 2));
127
+ $PictureSizeEnc['y'] = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 5, 2));
128
+ $PictureSizeEnc['x'] >>= 7;
129
+ $PictureSizeEnc['y'] >>= 7;
130
+ $ThisFileInfo['video']['resolution_x'] = $PictureSizeEnc['x'] & 0xFF;
131
+ $ThisFileInfo['video']['resolution_y'] = $PictureSizeEnc['y'] & 0xFF;
132
+ break;
133
+
134
+ case 1:
135
+ $PictureSizeEnc['x'] = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 4, 3));
136
+ $PictureSizeEnc['y'] = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 6, 3));
137
+ $PictureSizeEnc['x'] >>= 7;
138
+ $PictureSizeEnc['y'] >>= 7;
139
+ $ThisFileInfo['video']['resolution_x'] = $PictureSizeEnc['x'] & 0xFFFF;
140
+ $ThisFileInfo['video']['resolution_y'] = $PictureSizeEnc['y'] & 0xFFFF;
141
+ break;
142
+
143
+ case 2:
144
+ $ThisFileInfo['video']['resolution_x'] = 352;
145
+ $ThisFileInfo['video']['resolution_y'] = 288;
146
+ break;
147
+
148
+ case 3:
149
+ $ThisFileInfo['video']['resolution_x'] = 176;
150
+ $ThisFileInfo['video']['resolution_y'] = 144;
151
+ break;
152
+
153
+ case 4:
154
+ $ThisFileInfo['video']['resolution_x'] = 128;
155
+ $ThisFileInfo['video']['resolution_y'] = 96;
156
+ break;
157
+
158
+ case 5:
159
+ $ThisFileInfo['video']['resolution_x'] = 320;
160
+ $ThisFileInfo['video']['resolution_y'] = 240;
161
+ break;
162
+
163
+ case 6:
164
+ $ThisFileInfo['video']['resolution_x'] = 160;
165
+ $ThisFileInfo['video']['resolution_y'] = 120;
166
+ break;
167
+
168
+ default:
169
+ $ThisFileInfo['video']['resolution_x'] = 0;
170
+ $ThisFileInfo['video']['resolution_y'] = 0;
171
+ break;
172
+
173
+ }
174
+ }
175
+ }
176
+ break;
177
+
178
+ // Meta tag
179
+ case GETID3_FLV_TAG_META:
180
+ if (!$found_meta) {
181
+ $found_meta = true;
182
+ fseek($fd, -1, SEEK_CUR);
183
+ $reader = new AMFReader(new AMFStream(fread($fd, $DataLength)));
184
+ $eventName = $reader->readData();
185
+ $ThisFileInfo['meta'][$eventName] = $reader->readData();
186
+ unset($reader);
187
+
188
+ $ThisFileInfo['video']['frame_rate'] = @$ThisFileInfo['meta']['onMetaData']['framerate'];
189
+ $ThisFileInfo['video']['resolution_x'] = @$ThisFileInfo['meta']['onMetaData']['width'];
190
+ $ThisFileInfo['video']['resolution_y'] = @$ThisFileInfo['meta']['onMetaData']['height'];
191
+ }
192
+ break;
193
+
194
+ default:
195
+ // noop
196
+ break;
197
+ }
198
+
199
+ fseek($fd, $NextOffset, SEEK_SET);
200
+ }
201
+
202
+ if ($ThisFileInfo['playtime_seconds'] = $Duration / 1000) {
203
+ $ThisFileInfo['bitrate'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) / $ThisFileInfo['playtime_seconds'];
204
+ }
205
+
206
+ if ($ThisFileInfo['flv']['header']['hasAudio']) {
207
+ $ThisFileInfo['audio']['codec'] = $this->FLVaudioFormat($ThisFileInfo['flv']['audio']['audioFormat']);
208
+ $ThisFileInfo['audio']['sample_rate'] = $this->FLVaudioRate($ThisFileInfo['flv']['audio']['audioRate']);
209
+ $ThisFileInfo['audio']['bits_per_sample'] = $this->FLVaudioBitDepth($ThisFileInfo['flv']['audio']['audioSampleSize']);
210
+
211
+ $ThisFileInfo['audio']['channels'] = $ThisFileInfo['flv']['audio']['audioType'] + 1; // 0=mono,1=stereo
212
+ $ThisFileInfo['audio']['lossless'] = ($ThisFileInfo['flv']['audio']['audioFormat'] ? false : true); // 0=uncompressed
213
+ $ThisFileInfo['audio']['dataformat'] = 'flv';
214
+ }
215
+ if (@$ThisFileInfo['flv']['header']['hasVideo']) {
216
+ $ThisFileInfo['video']['codec'] = $this->FLVvideoCodec($ThisFileInfo['flv']['video']['videoCodec']);
217
+ $ThisFileInfo['video']['dataformat'] = 'flv';
218
+ $ThisFileInfo['video']['lossless'] = false;
219
+ }
220
+
221
+ return true;
222
+ }
223
+
224
+
225
+ function FLVaudioFormat($id) {
226
+ $FLVaudioFormat = array(
227
+ 0 => 'uncompressed',
228
+ 1 => 'ADPCM',
229
+ 2 => 'mp3',
230
+ 5 => 'Nellymoser 8kHz mono',
231
+ 6 => 'Nellymoser',
232
+ );
233
+ return (@$FLVaudioFormat[$id] ? @$FLVaudioFormat[$id] : false);
234
+ }
235
+
236
+ function FLVaudioRate($id) {
237
+ $FLVaudioRate = array(
238
+ 0 => 5500,
239
+ 1 => 11025,
240
+ 2 => 22050,
241
+ 3 => 44100,
242
+ );
243
+ return (@$FLVaudioRate[$id] ? @$FLVaudioRate[$id] : false);
244
+ }
245
+
246
+ function FLVaudioBitDepth($id) {
247
+ $FLVaudioBitDepth = array(
248
+ 0 => 8,
249
+ 1 => 16,
250
+ );
251
+ return (@$FLVaudioBitDepth[$id] ? @$FLVaudioBitDepth[$id] : false);
252
+ }
253
+
254
+ function FLVvideoCodec($id) {
255
+ $FLVvideoCodec = array(
256
+ GETID3_FLV_VIDEO_H263 => 'Sorenson H.263',
257
+ GETID3_FLV_VIDEO_SCREEN => 'Screen video',
258
+ GETID3_FLV_VIDEO_VP6 => 'On2 VP6',
259
+ );
260
+ return (@$FLVvideoCodec[$id] ? @$FLVvideoCodec[$id] : false);
261
+ }
262
+ }
263
+
264
+ class AMFStream {
265
+ var $bytes;
266
+ var $pos;
267
+
268
+ function AMFStream(&$bytes) {
269
+ $this->bytes =& $bytes;
270
+ $this->pos = 0;
271
+ }
272
+
273
+ function readByte() {
274
+ return getid3_lib::BigEndian2Int(substr($this->bytes, $this->pos++, 1));
275
+ }
276
+
277
+ function readInt() {
278
+ return ($this->readByte() << 8) + $this->readByte();
279
+ }
280
+
281
+ function readLong() {
282
+ return ($this->readByte() << 24) + ($this->readByte() << 16) + ($this->readByte() << 8) + $this->readByte();
283
+ }
284
+
285
+ function readDouble() {
286
+ return getid3_lib::BigEndian2Float($this->read(8));
287
+ }
288
+
289
+ function readUTF() {
290
+ $length = $this->readInt();
291
+ return $this->read($length);
292
+ }
293
+
294
+ function readLongUTF() {
295
+ $length = $this->readLong();
296
+ return $this->read($length);
297
+ }
298
+
299
+ function read($length) {
300
+ $val = substr($this->bytes, $this->pos, $length);
301
+ $this->pos += $length;
302
+ return $val;
303
+ }
304
+
305
+ function peekByte() {
306
+ $pos = $this->pos;
307
+ $val = $this->readByte();
308
+ $this->pos = $pos;
309
+ return $val;
310
+ }
311
+
312
+ function peekInt() {
313
+ $pos = $this->pos;
314
+ $val = $this->readInt();
315
+ $this->pos = $pos;
316
+ return $val;
317
+ }
318
+
319
+ function peekLong() {
320
+ $pos = $this->pos;
321
+ $val = $this->readLong();
322
+ $this->pos = $pos;
323
+ return $val;
324
+ }
325
+
326
+ function peekDouble() {
327
+ $pos = $this->pos;
328
+ $val = $this->readDouble();
329
+ $this->pos = $pos;
330
+ return $val;
331
+ }
332
+
333
+ function peekUTF() {
334
+ $pos = $this->pos;
335
+ $val = $this->readUTF();
336
+ $this->pos = $pos;
337
+ return $val;
338
+ }
339
+
340
+ function peekLongUTF() {
341
+ $pos = $this->pos;
342
+ $val = $this->readLongUTF();
343
+ $this->pos = $pos;
344
+ return $val;
345
+ }
346
+ }
347
+
348
+ class AMFReader {
349
+ var $stream;
350
+
351
+ function AMFReader(&$stream) {
352
+ $this->stream =& $stream;
353
+ }
354
+
355
+ function readData() {
356
+ $value = null;
357
+
358
+ $type = $this->stream->readByte();
359
+ switch ($type) {
360
+
361
+ // Double
362
+ case 0:
363
+ $value = $this->readDouble();
364
+ break;
365
+
366
+ // Boolean
367
+ case 1:
368
+ $value = $this->readBoolean();
369
+ break;
370
+
371
+ // String
372
+ case 2:
373
+ $value = $this->readString();
374
+ break;
375
+
376
+ // Object
377
+ case 3:
378
+ $value = $this->readObject();
379
+ break;
380
+
381
+ // null
382
+ case 6:
383
+ return null;
384
+ break;
385
+
386
+ // Mixed array
387
+ case 8:
388
+ $value = $this->readMixedArray();
389
+ break;
390
+
391
+ // Array
392
+ case 10:
393
+ $value = $this->readArray();
394
+ break;
395
+
396
+ // Date
397
+ case 11:
398
+ $value = $this->readDate();
399
+ break;
400
+
401
+ // Long string
402
+ case 13:
403
+ $value = $this->readLongString();
404
+ break;
405
+
406
+ // XML (handled as string)
407
+ case 15:
408
+ $value = $this->readXML();
409
+ break;
410
+
411
+ // Typed object (handled as object)
412
+ case 16:
413
+ $value = $this->readTypedObject();
414
+ break;
415
+
416
+ // Long string
417
+ default:
418
+ $value = '(unknown or unsupported data type)';
419
+ break;
420
+ }
421
+
422
+ return $value;
423
+ }
424
+
425
+ function readDouble() {
426
+ return $this->stream->readDouble();
427
+ }
428
+
429
+ function readBoolean() {
430
+ return $this->stream->readByte() == 1;
431
+ }
432
+
433
+ function readString() {
434
+ return $this->stream->readUTF();
435
+ }
436
+
437
+ function readObject() {
438
+ // Get highest numerical index - ignored
439
+ // $highestIndex = $this->stream->readLong();
440
+
441
+ $data = array();
442
+
443
+ while ($key = $this->stream->readUTF()) {
444
+ $data[$key] = $this->readData();
445
+ }
446
+ // Mixed array record ends with empty string (0x00 0x00) and 0x09
447
+ if (($key == '') && ($this->stream->peekByte() == 0x09)) {
448
+ // Consume byte
449
+ $this->stream->readByte();
450
+ }
451
+ return $data;
452
+ }
453
+
454
+ function readMixedArray() {
455
+ // Get highest numerical index - ignored
456
+ $highestIndex = $this->stream->readLong();
457
+
458
+ $data = array();
459
+
460
+ while ($key = $this->stream->readUTF()) {
461
+ if (is_numeric($key)) {
462
+ $key = (float) $key;
463
+ }
464
+ $data[$key] = $this->readData();
465
+ }
466
+ // Mixed array record ends with empty string (0x00 0x00) and 0x09
467
+ if (($key == '') && ($this->stream->peekByte() == 0x09)) {
468
+ // Consume byte
469
+ $this->stream->readByte();
470
+ }
471
+
472
+ return $data;
473
+ }
474
+
475
+ function readArray() {
476
+ $length = $this->stream->readLong();
477
+ $data = array();
478
+
479
+ for ($i = 0; $i < $length; $i++) {
480
+ $data[] = $this->readData();
481
+ }
482
+ return $data;
483
+ }
484
+
485
+ function readDate() {
486
+ $timestamp = $this->stream->readDouble();
487
+ $timezone = $this->stream->readInt();
488
+ return $timestamp;
489
+ }
490
+
491
+ function readLongString() {
492
+ return $this->stream->readLongUTF();
493
+ }
494
+
495
+ function readXML() {
496
+ return $this->stream->readLongUTF();
497
+ }
498
+
499
+ function readTypedObject() {
500
+ $className = $this->stream->readUTF();
501
+ return $this->readObject();
502
+ }
503
+ }
504
+
505
+ ?>
view/getid3/module.audio-video.matroska.php ADDED
@@ -0,0 +1,1712 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /////////////////////////////////////////////////////////////////
3
+ /// getID3() by James Heinrich <info@getid3.org> //
4
+ // available at http://getid3.sourceforge.net //
5
+ // or http://www.getid3.org //
6
+ /////////////////////////////////////////////////////////////////
7
+ // See readme.txt for more details //
8
+ /////////////////////////////////////////////////////////////////
9
+ // //
10
+ // module.audio-video.matriska.php //
11
+ // module for analyzing Matroska containers //
12
+ // dependencies: NONE //
13
+ // ///
14
+ /////////////////////////////////////////////////////////////////
15
+
16
+
17
+ 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.
18
+ define('EBML_ID_SEEKHEAD', 0x014D9B74); // [11][4D][9B][74] -- Contains the position of other level 1 elements.
19
+ define('EBML_ID_TAGS', 0x0254C367); // [12][54][C3][67] -- Element containing elements specific to Tracks/Chapters. A list of valid tags can be found here.
20
+ define('EBML_ID_INFO', 0x0549A966); // [15][49][A9][66] -- Contains miscellaneous general information and statistics on the file.
21
+ define('EBML_ID_TRACKS', 0x0654AE6B); // [16][54][AE][6B] -- A top-level block of information with many tracks described.
22
+ 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.
23
+ define('EBML_ID_ATTACHMENTS', 0x0941A469); // [19][41][A4][69] -- Contain attached files.
24
+ 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.
25
+ define('EBML_ID_CUES', 0x0C53BB6B); // [1C][53][BB][6B] -- A top-level element to speed seeking access. All entries are local to the segment.
26
+ define('EBML_ID_CLUSTER', 0x0F43B675); // [1F][43][B6][75] -- The lower level element containing the (monolithic) Block structure.
27
+ define('EBML_ID_LANGUAGE', 0x02B59C); // [22][B5][9C] -- Specifies the language of the track in the Matroska languages form.
28
+ 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).
29
+ define('EBML_ID_DEFAULTDURATION', 0x03E383); // [23][E3][83] -- Number of nanoseconds (i.e. not scaled) per frame.
30
+ define('EBML_ID_CODECNAME', 0x058688); // [25][86][88] -- A human-readable string specifying the codec.
31
+ define('EBML_ID_CODECDOWNLOADURL', 0x06B240); // [26][B2][40] -- A URL to download about the codec used.
32
+ 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).
33
+ define('EBML_ID_COLOURSPACE', 0x0EB524); // [2E][B5][24] -- Same value as in AVI (32 bits).
34
+ define('EBML_ID_GAMMAVALUE', 0x0FB523); // [2F][B5][23] -- Gamma Value.
35
+ define('EBML_ID_CODECSETTINGS', 0x1A9697); // [3A][96][97] -- A string describing the encoding setting used.
36
+ define('EBML_ID_CODECINFOURL', 0x1B4040); // [3B][40][40] -- A URL to find information about the codec used.
37
+ define('EBML_ID_PREVFILENAME', 0x1C83AB); // [3C][83][AB] -- An escaped filename corresponding to the previous segment.
38
+ define('EBML_ID_PREVUID', 0x1CB923); // [3C][B9][23] -- A unique ID to identify the previous chained segment (128 bits).
39
+ define('EBML_ID_NEXTFILENAME', 0x1E83BB); // [3E][83][BB] -- An escaped filename corresponding to the next segment.
40
+ define('EBML_ID_NEXTUID', 0x1EB923); // [3E][B9][23] -- A unique ID to identify the next chained segment (128 bits).
41
+ define('EBML_ID_CONTENTCOMPALGO', 0x0254); // [42][54] -- The compression algorithm used. Algorithms that have been specified so far are:
42
+ 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.
43
+ define('EBML_ID_DOCTYPE', 0x0282); // [42][82] -- A string that describes the type of document that follows this EBML header ('matroska' in our case).
44
+ define('EBML_ID_DOCTYPEREADVERSION', 0x0285); // [42][85] -- The minimum DocType version an interpreter has to support to read this file.
45
+ define('EBML_ID_EBMLVERSION', 0x0286); // [42][86] -- The version of EBML parser used to create the file.
46
+ define('EBML_ID_DOCTYPEVERSION', 0x0287); // [42][87] -- The version of DocType interpreter used to create the file.
47
+ define('EBML_ID_EBMLMAXIDLENGTH', 0x02F2); // [42][F2] -- The maximum length of the IDs you'll find in this file (4 or less in Matroska).
48
+ 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.
49
+ define('EBML_ID_EBMLREADVERSION', 0x02F7); // [42][F7] -- The minimum EBML version a parser has to support to read this file.
50
+ define('EBML_ID_CHAPLANGUAGE', 0x037C); // [43][7C] -- The languages corresponding to the string, in the bibliographic ISO-639-2 form.
51
+ define('EBML_ID_CHAPCOUNTRY', 0x037E); // [43][7E] -- The countries corresponding to the string, same 2 octets as in Internet domains.
52
+ define('EBML_ID_SEGMENTFAMILY', 0x0444); // [44][44] -- A randomly generated unique ID that all segments related to each other must use (128 bits).
53
+ define('EBML_ID_DATEUTC', 0x0461); // [44][61] -- Date of the origin of timecode (value 0), i.e. production date.
54
+ define('EBML_ID_TAGLANGUAGE', 0x047A); // [44][7A] -- Specifies the language of the tag specified, in the Matroska languages form.
55
+ define('EBML_ID_TAGDEFAULT', 0x0484); // [44][84] -- Indication to know if this is the default/original language to use for the given tag.
56
+ 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.
57
+ define('EBML_ID_TAGSTRING', 0x0487); // [44][87] -- The value of the Tag.
58
+ define('EBML_ID_DURATION', 0x0489); // [44][89] -- Duration of the segment (based on TimecodeScale).
59
+ define('EBML_ID_CHAPPROCESSPRIVATE', 0x050D); // [45][0D] -- Some optional data attached to the ChapProcessCodecID information. For ChapProcessCodecID = 1, it is the "DVD level" equivalent.
60
+ 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.
61
+ define('EBML_ID_TAGNAME', 0x05A3); // [45][A3] -- The name of the Tag that is going to be stored.
62
+ define('EBML_ID_EDITIONENTRY', 0x05B9); // [45][B9] -- Contains all information about a segment edition.
63
+ define('EBML_ID_EDITIONUID', 0x05BC); // [45][BC] -- A unique ID to identify the edition. It's useful for tagging an edition.
64
+ 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).
65
+ define('EBML_ID_EDITIONFLAGDEFAULT', 0x05DB); // [45][DB] -- If a flag is set (1) the edition should be used as the default one.
66
+ define('EBML_ID_EDITIONFLAGORDERED', 0x05DD); // [45][DD] -- Specify if the chapters can be defined multiple times and the order to play them is enforced.
67
+ define('EBML_ID_FILEDATA', 0x065C); // [46][5C] -- The data of the file.
68
+ define('EBML_ID_FILEMIMETYPE', 0x0660); // [46][60] -- MIME type of the file.
69
+ define('EBML_ID_FILENAME', 0x066E); // [46][6E] -- Filename of the attached file.
70
+ define('EBML_ID_FILEREFERRAL', 0x0675); // [46][75] -- A binary value that a track/codec can refer to when the attachment is needed.
71
+ define('EBML_ID_FILEDESCRIPTION', 0x067E); // [46][7E] -- A human-friendly name for the attached file.
72
+ define('EBML_ID_FILEUID', 0x06AE); // [46][AE] -- Unique ID representing the file, as random as possible.
73
+ 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:
74
+ 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.
75
+ define('EBML_ID_CONTENTSIGNATURE', 0x07E3); // [47][E3] -- A cryptographic signature of the contents.
76
+ define('EBML_ID_CONTENTSIGKEYID', 0x07E4); // [47][E4] -- This is the ID of the private key the data was signed with.
77
+ 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:
78
+ 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:
79
+ define('EBML_ID_MUXINGAPP', 0x0D80); // [4D][80] -- Muxing application or library ("libmatroska-0.4.3").
80
+ define('EBML_ID_SEEK', 0x0DBB); // [4D][BB] -- Contains a single seek entry to an EBML element.
81
+ 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.
82
+ 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:
83
+ define('EBML_ID_CONTENTENCODINGTYPE', 0x1033); // [50][33] -- A value describing what kind of transformation has been done. Possible values:
84
+ 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.
85
+ 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.
86
+ define('EBML_ID_CUEREFNUMBER', 0x135F); // [53][5F] -- Number of the referenced Block of Track X in the specified Cluster.
87
+ define('EBML_ID_NAME', 0x136E); // [53][6E] -- A human-readable track name.
88
+ define('EBML_ID_CUEBLOCKNUMBER', 0x1378); // [53][78] -- Number of the Block in the specified Cluster.
89
+ 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.
90
+ define('EBML_ID_SEEKID', 0x13AB); // [53][AB] -- The binary ID corresponding to the element name.
91
+ define('EBML_ID_SEEKPOSITION', 0x13AC); // [53][AC] -- The position of the element in the segment in octets (0 = first level 1 element).
92
+ 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).
93
+ define('EBML_ID_PIXELCROPBOTTOM', 0x14AA); // [54][AA] -- The number of video pixels to remove at the bottom of the image (for HDTV content).
94
+ define('EBML_ID_DISPLAYWIDTH', 0x14B0); // [54][B0] -- Width of the video frames to display.
95
+ define('EBML_ID_DISPLAYUNIT', 0x14B2); // [54][B2] -- Type of the unit for DisplayWidth/Height (0: pixels, 1: centimeters, 2: inches).
96
+ define('EBML_ID_ASPECTRATIOTYPE', 0x14B3); // [54][B3] -- Specify the possible modifications to the aspect ratio (0: free resizing, 1: keep aspect ratio, 2: fixed).
97
+ define('EBML_ID_DISPLAYHEIGHT', 0x14BA); // [54][BA] -- Height of the video frames to display.
98
+ define('EBML_ID_PIXELCROPTOP', 0x14BB); // [54][BB] -- The number of video pixels to remove at the top of the image.
99
+ define('EBML_ID_PIXELCROPLEFT', 0x14CC); // [54][CC] -- The number of video pixels to remove on the left of the image.
100
+ define('EBML_ID_PIXELCROPRIGHT', 0x14DD); // [54][DD] -- The number of video pixels to remove on the right of the image.
101
+ 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.
102
+ define('EBML_ID_MAXBLOCKADDITIONID', 0x15EE); // [55][EE] -- The maximum value of BlockAddID. A value 0 means there is no BlockAdditions for this track.
103
+ define('EBML_ID_WRITINGAPP', 0x1741); // [57][41] -- Writing application ("mkvmerge-0.3.3").
104
+ 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.
105
+ 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.
106
+ define('EBML_ID_ATTACHEDFILE', 0x21A7); // [61][A7] -- An attached file.
107
+ define('EBML_ID_CONTENTENCODING', 0x2240); // [62][40] -- Settings for one content encoding like compression or encryption.
108
+ define('EBML_ID_BITDEPTH', 0x2264); // [62][64] -- Bits per sample, mostly used for PCM.
109
+ define('EBML_ID_CODECPRIVATE', 0x23A2); // [63][A2] -- Private data only known to the codec.
110
+ 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.
111
+ 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.
112
+ 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.
113
+ 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.
114
+ define('EBML_ID_ATTACHMENTUID', 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.
115
+ 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.
116
+ 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).
117
+ define('EBML_ID_TRACKTRANSLATE', 0x2624); // [66][24] -- The track identification for the given Chapter Codec.
118
+ 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.
119
+ define('EBML_ID_TRACKTRANSLATECODEC', 0x26BF); // [66][BF] -- The chapter codec using this ID (0: Matroska Script, 1: DVD-menu).
120
+ 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.
121
+ define('EBML_ID_SIMPLETAG', 0x27C8); // [67][C8] -- Contains general information about the target.
122
+ define('EBML_ID_TARGETTYPEVALUE', 0x28CA); // [68][CA] -- A number to indicate the logical level of the target (see TargetType).
123
+ define('EBML_ID_CHAPPROCESSCOMMAND', 0x2911); // [69][11] -- Contains all the commands associated to the Atom.
124
+ 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).
125
+ define('EBML_ID_CHAPTERTRANSLATE', 0x2924); // [69][24] -- A tuple of corresponding ID used by chapter codecs to represent this segment.
126
+ 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.
127
+ define('EBML_ID_CHAPPROCESS', 0x2944); // [69][44] -- Contains all the commands associated to the Atom.
128
+ 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.
129
+ 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.
130
+ define('EBML_ID_CHAPTERTRANSLATECODEC', 0x29BF); // [69][BF] -- The chapter codec using this ID (0: Matroska Script, 1: DVD-menu).
131
+ 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.
132
+ define('EBML_ID_CONTENTENCODINGS', 0x2D80); // [6D][80] -- Settings for several content encoding mechanisms like compression or encryption.
133
+ 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.
134
+ 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.
135
+ 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.
136
+ define('EBML_ID_CHAPTERSEGMENTEDITIONUID', 0x2EBC); // [6E][BC] -- The edition to play from the segment linked in ChapterSegmentUID.
137
+ 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.
138
+ define('EBML_ID_TAG', 0x3373); // [73][73] -- Element containing elements specific to Tracks/Chapters.
139
+ define('EBML_ID_SEGMENTFILENAME', 0x3384); // [73][84] -- A filename corresponding to this segment.
140
+ define('EBML_ID_SEGMENTUID', 0x33A4); // [73][A4] -- A randomly generated unique ID to identify the current segment between many others (128 bits).
141
+ define('EBML_ID_CHAPTERUID', 0x33C4); // [73][C4] -- A unique ID to identify the Chapter.
142
+ 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.
143
+ define('EBML_ID_ATTACHMENTLINK', 0x3446); // [74][46] -- The UID of an attachment that is used by this codec.
144
+ 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.
145
+ define('EBML_ID_CHANNELPOSITIONS', 0x347B); // [7D][7B] -- Table of horizontal angles for each successive channel, see appendix.
146
+ define('EBML_ID_OUTPUTSAMPLINGFREQUENCY', 0x38B5); // [78][B5] -- Real output sampling frequency in Hz (used for SBR techniques).
147
+ define('EBML_ID_TITLE', 0x3BA9); // [7B][A9] -- General name of the segment.
148
+ define('EBML_ID_CHAPTERDISPLAY', 0x00); // [80] -- Contains all possible strings to use for the chapter display.
149
+ 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).
150
+ define('EBML_ID_CHAPSTRING', 0x05); // [85] -- Contains the string to use as the chapter atom.
151
+ define('EBML_ID_CODECID', 0x06); // [86] -- An ID corresponding to the codec, see the codec page for more info.
152
+ 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.
153
+ 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.
154
+ define('EBML_ID_CLUSTERSLICES', 0x0E); // [8E] -- Contains slices description.
155
+ define('EBML_ID_CHAPTERTRACK', 0x0F); // [8F] -- List of tracks on which the chapter applies. If this element is not present, all tracks apply
156
+ define('EBML_ID_CHAPTERTIMESTART', 0x11); // [91] -- Timecode of the start of Chapter (not scaled).
157
+ define('EBML_ID_CHAPTERTIMEEND', 0x12); // [92] -- Timecode of the end of Chapter (timecode excluded, not scaled).
158
+ define('EBML_ID_CUEREFTIME', 0x16); // [96] -- Timecode of the referenced Block.
159
+ define('EBML_ID_CUEREFCLUSTER', 0x17); // [97] -- Position of the Cluster containing the referenced Block.
160
+ 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).
161
+ define('EBML_ID_FLAGINTERLACED', 0x1A); // [9A] -- Set if the video is interlaced.
162
+ 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.
163
+ define('EBML_ID_FLAGLACING', 0x1C); // [9C] -- Set if the track may contain blocks using lacing.
164
+ define('EBML_ID_CHANNELS', 0x1F); // [9F] -- Numbers of channels in the track.
165
+ define('EBML_ID_CLUSTERBLOCKGROUP', 0x20); // [A0] -- Basic container of information containing a single Block or BlockVirtual, and information specific to that Block/VirtualBlock.
166
+ define('EBML_ID_CLUSTERBLOCK', 0x21); // [A1] -- Block containing the actual data to be rendered and a timecode relative to the Cluster Timecode.
167
+ 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.
168
+ 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.
169
+ 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.
170
+ define('EBML_ID_CLUSTERBLOCKADDITIONAL', 0x25); // [A5] -- Interpreted by the codec as it wishes (using the BlockAddID).
171
+ define('EBML_ID_CLUSTERBLOCKMORE', 0x26); // [A6] -- Contain the BlockAdditional and some parameters.
172
+ 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.
173
+ define('EBML_ID_CODECDECODEALL', 0x2A); // [AA] -- The codec can decode potentially damaged data.
174
+ define('EBML_ID_CLUSTERPREVSIZE', 0x2B); // [AB] -- Size of the previous Cluster, in octets. Can be useful for backward playing.
175
+ define('EBML_ID_TRACKENTRY', 0x2E); // [AE] -- Describes a track with all elements.
176
+ define('EBML_ID_CLUSTERENCRYPTEDBLOCK', 0x2F); // [AF] -- Similar to SimpleBlock but the data inside the Block are Transformed (encrypt and/or signed).
177
+ define('EBML_ID_PIXELWIDTH', 0x30); // [B0] -- Width of the encoded video frames in pixels.
178
+ define('EBML_ID_CUETIME', 0x33); // [B3] -- Absolute timecode according to the segment time base.
179
+ define('EBML_ID_SAMPLINGFREQUENCY', 0x35); // [B5] -- Sampling frequency in Hz.
180
+ define('EBML_ID_CHAPTERATOM', 0x36); // [B6] -- Contains the atom information to use as the chapter atom (apply to all tracks).
181
+ define('EBML_ID_CUETRACKPOSITIONS', 0x37); // [B7] -- Contain positions for different tracks corresponding to the timecode.
182
+ define('EBML_ID_FLAGENABLED', 0x39); // [B9] -- Set if the track is used.
183
+ define('EBML_ID_PIXELHEIGHT', 0x3A); // [BA] -- Height of the encoded video frames in pixels.
184
+ define('EBML_ID_CUEPOINT', 0x3B); // [BB] -- Contains all information relative to a seek point in the segment.
185
+ 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.
186
+ define('EBML_ID_CLUSTERBLOCKADDITIONID', 0x4B); // [CB] -- The ID of the BlockAdditional element (0 is the main Block).
187
+ 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.
188
+ 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).
189
+ define('EBML_ID_CLUSTERDELAY', 0x4E); // [CE] -- The (scaled) delay to apply to the element.
190
+ define('EBML_ID_CLUSTERDURATION', 0x4F); // [CF] -- The (scaled) duration to apply to the element.
191
+ 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).
192
+ define('EBML_ID_CUEREFERENCE', 0x5B); // [DB] -- The Clusters containing the required referenced Blocks.
193
+ define('EBML_ID_VIDEO', 0x60); // [E0] -- Video settings.
194
+ define('EBML_ID_AUDIO', 0x61); // [E1] -- Audio settings.
195
+ 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.
196
+ 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.
197
+ 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.
198
+ 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.
199
+ define('EBML_ID_CLUSTERTIMECODE', 0x67); // [E7] -- Absolute timecode of the cluster (based on TimecodeScale).
200
+ define('EBML_ID_CLUSTERBLOCKADDID', 0x6E); // [EE] -- An ID to identify the BlockAdditional level.
201
+ define('EBML_ID_CUECLUSTERPOSITION', 0x71); // [F1] -- The position of the Cluster containing the required Block.
202
+ define('EBML_ID_CUETRACK', 0x77); // [F7] -- The track for which a position is given.
203
+ 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.
204
+ 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.
205
+ define('EBML_ID_CLUSTERREFERENCEVIRTUAL', 0x7D); // [FD] -- Relative position of the data that should be in position of the virtual block.
206
+
207
+
208
+ class getid3_matroska
209
+ {
210
+ var $read_buffer_size = 32768; // size of read buffer, 32kB is default
211
+ var $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
212
+ var $warnings = array();
213
+
214
+ function getid3_matroska(&$fd, &$ThisFileInfo) {
215
+
216
+ // http://www.matroska.org/technical/specs/index.html#EBMLBasics
217
+ $offset = $ThisFileInfo['avdataoffset'];
218
+ $EBMLdata = '';
219
+ $EBMLdata_offset = $offset;
220
+
221
+ if ($ThisFileInfo['avdataend'] > 2147483648) {
222
+ $this->warnings[] = 'This version of getID3() may or may not correctly handle Matroska files larger than 2GB';
223
+ }
224
+
225
+ while ($offset < $ThisFileInfo['avdataend']) {
226
+ $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
227
+
228
+ $top_element_offset = $offset;
229
+ $top_element_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
230
+ $top_element_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
231
+ if ($top_element_length === false) {
232
+ $this->warnings[] = 'invalid chunk length at '.$top_element_offset;
233
+ $offset = pow(2, 63);
234
+ break;
235
+ }
236
+ $top_element_endoffset = $offset + $top_element_length;
237
+ switch ($top_element_id) {
238
+ case EBML_ID_EBML:
239
+ $ThisFileInfo['fileformat'] = 'matroska';
240
+ $ThisFileInfo['matroska']['header']['offset'] = $top_element_offset;
241
+ $ThisFileInfo['matroska']['header']['length'] = $top_element_length;
242
+
243
+ while ($offset < $top_element_endoffset) {
244
+ $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
245
+ $element_data = array();
246
+ $element_data_offset = $offset;
247
+ $element_data['id'] = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
248
+ $element_data['id_name'] = $this->EBMLidName($element_data['id']);
249
+ $element_data['length'] = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
250
+ $end_offset = $offset + $element_data['length'];
251
+
252
+ switch ($element_data['id']) {
253
+ case EBML_ID_EBMLVERSION:
254
+ case EBML_ID_EBMLREADVERSION:
255
+ case EBML_ID_EBMLMAXIDLENGTH:
256
+ case EBML_ID_EBMLMAXSIZELENGTH:
257
+ case EBML_ID_DOCTYPEVERSION:
258
+ case EBML_ID_DOCTYPEREADVERSION:
259
+ $element_data['data'] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $element_data['length']));
260
+ break;
261
+ case EBML_ID_DOCTYPE:
262
+ $element_data['data'] = trim(substr($EBMLdata, $offset - $EBMLdata_offset, $element_data['length']), "\x00");
263
+ break;
264
+ default:
265
+ $this->warnings[] = 'Unhandled track.video element['.__LINE__.'] ('.$element_data['id'].'::'.$element_data['id_name'].') at '.$element_data_offset;
266
+ break;
267
+ }
268
+ $offset = $end_offset;
269
+ $ThisFileInfo['matroska']['header']['elements'][] = $element_data;
270
+ }
271
+ break;
272
+
273
+
274
+ case EBML_ID_SEGMENT:
275
+ $ThisFileInfo['matroska']['segment'][0]['offset'] = $top_element_offset;
276
+ $ThisFileInfo['matroska']['segment'][0]['length'] = $top_element_length;
277
+
278
+ $segment_key = -1;
279
+ while ($offset < $ThisFileInfo['avdataend']) {
280
+ $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
281
+
282
+ $element_data = array();
283
+ $element_data['offset'] = $offset;
284
+ $element_data['id'] = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
285
+ $element_data['id_name'] = $this->EBMLidName($element_data['id']);
286
+ $element_data['length'] = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
287
+ if ($element_data['length'] === false) {
288
+ $this->warnings[] = 'invalid chunk length at '.$element_data['offset'];
289
+ //$offset = pow(2, 63);
290
+ $offset = $ThisFileInfo['avdataend'];
291
+ break;
292
+ }
293
+ $element_end = $offset + $element_data['length'];
294
+ switch ($element_data['id']) {
295
+ //case EBML_ID_CLUSTER:
296
+ // // too many cluster entries, probably not useful
297
+ // break;
298
+ case false:
299
+ $this->warnings[] = 'invalid ID at '.$element_data['offset'];
300
+ $offset = $element_end;
301
+ continue 3;
302
+ default:
303
+ $ThisFileInfo['matroska']['segments'][] = $element_data;
304
+ break;
305
+ }
306
+ $segment_key++;
307
+
308
+ switch ($element_data['id']) {
309
+ case EBML_ID_SEEKHEAD: // Contains the position of other level 1 elements
310
+ while ($offset < $element_end) {
311
+ $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
312
+ $seek_entry = array();
313
+ $seek_entry['offset'] = $offset;
314
+ $seek_entry['id'] = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
315
+ $seek_entry['id_name'] = $this->EBMLidName($seek_entry['id']);
316
+ $seek_entry['length'] = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
317
+ $seek_end_offset = $offset + $seek_entry['length'];
318
+ switch ($seek_entry['id']) {
319
+ case EBML_ID_SEEK: // Contains a single seek entry to an EBML element
320
+ while ($offset < $seek_end_offset) {
321
+ $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
322
+ $id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
323
+ $length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
324
+ $value = substr($EBMLdata, $offset - $EBMLdata_offset, $length);
325
+ $offset += $length;
326
+ switch ($id) {
327
+ case EBML_ID_SEEKID:
328
+ $dummy = 0;
329
+ $seek_entry['target_id'] = $this->readEBMLint($value, $dummy);
330
+ $seek_entry['target_name'] = $this->EBMLidName($seek_entry['target_id']);
331
+ break;
332
+ case EBML_ID_SEEKPOSITION:
333
+ $seek_entry['target_offset'] = $element_data['offset'] + getid3_lib::BigEndian2Int($value);
334
+ break;
335
+ default:
336
+ $ThisFileInfo['error'][] = 'Unhandled segment['.__LINE__.'] ('.$id.') at '.$offset;
337
+ break;
338
+ }
339
+ }
340
+ $ThisFileInfo['matroska']['seek'][] = $seek_entry;
341
+ //switch ($seek_entry['target_id']) {
342
+ // case EBML_ID_CLUSTER:
343
+ // // too many cluster seek points, probably not useful
344
+ // break;
345
+ // default:
346
+ // $ThisFileInfo['matroska']['seek'][] = $seek_entry;
347
+ // break;
348
+ //}
349
+ break;
350
+ default:
351
+ $this->warnings[] = 'Unhandled seekhead element['.__LINE__.'] ('.$seek_entry['id'].') at '.$offset;
352
+ break;
353
+ }
354
+ $offset = $seek_end_offset;
355
+ }
356
+ break;
357
+
358
+ case EBML_ID_TRACKS: // information about all tracks in segment
359
+ $ThisFileInfo['matroska']['tracks'] = $element_data;
360
+ while ($offset < $element_end) {
361
+ $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
362
+ $track_entry = array();
363
+ $track_entry['offset'] = $offset;
364
+ $track_entry['id'] = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
365
+ $track_entry['id_name'] = $this->EBMLidName($track_entry['id']);
366
+ $track_entry['length'] = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
367
+ $track_entry_endoffset = $offset + $track_entry['length'];
368
+ switch ($track_entry['id']) {
369
+ case EBML_ID_TRACKENTRY: //subelements: Describes a track with all elements.
370
+ while ($offset < $track_entry_endoffset) {
371
+ $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
372
+ $subelement_offset = $offset;
373
+ $subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
374
+ $subelement_idname = $this->EBMLidName($subelement_id);
375
+ $subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
376
+ $subelement_end = $offset + $subelement_length;
377
+ switch ($subelement_id) {
378
+ case EBML_ID_TRACKNUMBER:
379
+ case EBML_ID_TRACKUID:
380
+ case EBML_ID_TRACKTYPE:
381
+ case EBML_ID_MINCACHE:
382
+ case EBML_ID_MAXCACHE:
383
+ case EBML_ID_MAXBLOCKADDITIONID:
384
+ case EBML_ID_DEFAULTDURATION: // nanoseconds per frame
385
+ $track_entry[$subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length));
386
+ break;
387
+ case EBML_ID_TRACKTIMECODESCALE:
388
+ $track_entry[$subelement_idname] = getid3_lib::BigEndian2Float(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length));
389
+ break;
390
+ case EBML_ID_CODECID:
391
+ case EBML_ID_LANGUAGE:
392
+ case EBML_ID_NAME:
393
+ case EBML_ID_CODECPRIVATE:
394
+ $track_entry[$subelement_idname] = trim(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length), "\x00");
395
+ break;
396
+ case EBML_ID_FLAGENABLED:
397
+ case EBML_ID_FLAGDEFAULT:
398
+ case EBML_ID_FLAGFORCED:
399
+ case EBML_ID_FLAGLACING:
400
+ case EBML_ID_CODECDECODEALL:
401
+ $track_entry[$subelement_idname] = (bool) getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length));
402
+ break;
403
+ case EBML_ID_VIDEO:
404
+ while ($offset < $subelement_end) {
405
+ $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
406
+ $sub_subelement_offset = $offset;
407
+ $sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
408
+ $sub_subelement_idname = $this->EBMLidName($sub_subelement_id);
409
+ $sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
410
+ $sub_subelement_end = $offset + $sub_subelement_length;
411
+ switch ($sub_subelement_id) {
412
+ case EBML_ID_PIXELWIDTH:
413
+ case EBML_ID_PIXELHEIGHT:
414
+ case EBML_ID_STEREOMODE:
415
+ case EBML_ID_PIXELCROPBOTTOM:
416
+ case EBML_ID_PIXELCROPTOP:
417
+ case EBML_ID_PIXELCROPLEFT:
418
+ case EBML_ID_PIXELCROPRIGHT:
419
+ case EBML_ID_DISPLAYWIDTH:
420
+ case EBML_ID_DISPLAYHEIGHT:
421
+ case EBML_ID_DISPLAYUNIT:
422
+ case EBML_ID_ASPECTRATIOTYPE:
423
+ $track_entry[$sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
424
+ break;
425
+ case EBML_ID_FLAGINTERLACED:
426
+ $track_entry[$sub_subelement_idname] = (bool) getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
427
+ break;
428
+ case EBML_ID_GAMMAVALUE:
429
+ $track_entry[$sub_subelement_idname] = getid3_lib::BigEndian2Float(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
430
+ break;
431
+ case EBML_ID_COLOURSPACE:
432
+ $track_entry[$sub_subelement_idname] = trim(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length), "\x00");
433
+ break;
434
+ default:
435
+ $this->warnings[] = 'Unhandled track.video element['.__LINE__.'] ('.$sub_subelement_id.'::'.$sub_subelement_idname.') at '.$sub_subelement_offset;
436
+ break;
437
+ }
438
+ $offset = $sub_subelement_end;
439
+ }
440
+
441
+ if ((@$track_entry[$this->EBMLidName(EBML_ID_CODECID)] == 'V_MS/VFW/FOURCC') && isset($track_entry[$this->EBMLidName(EBML_ID_CODECPRIVATE)])) {
442
+ if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, false)) {
443
+ $track_entry['codec_private_parsed'] = getid3_riff::ParseBITMAPINFOHEADER($track_entry[$this->EBMLidName(EBML_ID_CODECPRIVATE)]);
444
+ } else {
445
+ $this->warnings[] = 'Unable to parse codec private data['.__LINE__.'] because cannot include "module.audio-video.riff.php"';
446
+ }
447
+ }
448
+ break;
449
+ case EBML_ID_AUDIO:
450
+ while ($offset < $subelement_end) {
451
+ $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
452
+ $sub_subelement_offset = $offset;
453
+ $sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
454
+ $sub_subelement_idname = $this->EBMLidName($sub_subelement_id);
455
+ $sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
456
+ $sub_subelement_end = $offset + $sub_subelement_length;
457
+ switch ($sub_subelement_id) {
458
+ case EBML_ID_CHANNELS:
459
+ case EBML_ID_BITDEPTH:
460
+ $track_entry[$sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
461
+ break;
462
+ case EBML_ID_SAMPLINGFREQUENCY:
463
+ case EBML_ID_OUTPUTSAMPLINGFREQUENCY:
464
+ $track_entry[$sub_subelement_idname] = getid3_lib::BigEndian2Float(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
465
+ break;
466
+ case EBML_ID_CHANNELPOSITIONS:
467
+ $track_entry[$sub_subelement_idname] = trim(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length), "\x00");
468
+ break;
469
+ default:
470
+ $this->warnings[] = 'Unhandled track.video element['.__LINE__.'] ('.$sub_subelement_id.'::'.$sub_subelement_idname.') at '.$sub_subelement_offset;
471
+ break;
472
+ }
473
+ $offset = $sub_subelement_end;
474
+ }
475
+ break;
476
+
477
+ case EBML_ID_CONTENTENCODINGS:
478
+ while ($offset < $subelement_end) {
479
+ $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
480
+ $sub_subelement_offset = $offset;
481
+ $sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
482
+ $sub_subelement_idname = $this->EBMLidName($sub_subelement_id);
483
+ $sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
484
+ $sub_subelement_end = $offset + $sub_subelement_length;
485
+ switch ($sub_subelement_id) {
486
+ case EBML_ID_CONTENTENCODING:
487
+ while ($offset < $sub_subelement_end) {
488
+ $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
489
+ $sub_sub_subelement_offset = $offset;
490
+ $sub_sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
491
+ $sub_sub_subelement_idname = $this->EBMLidName($sub_sub_subelement_id);
492
+ $sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
493
+ $sub_sub_subelement_end = $offset + $sub_sub_subelement_length;
494
+ switch ($sub_sub_subelement_id) {
495
+ case EBML_ID_CONTENTENCODINGORDER:
496
+ case EBML_ID_CONTENTENCODINGSCOPE:
497
+ case EBML_ID_CONTENTENCODINGTYPE:
498
+ $track_entry[$sub_subelement_idname][$sub_sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length));
499
+ break;
500
+ case EBML_ID_CONTENTCOMPRESSION:
501
+ while ($offset < $sub_sub_subelement_end) {
502
+ $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
503
+ $sub_sub_sub_subelement_offset = $offset;
504
+ $sub_sub_sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
505
+ $sub_sub_sub_subelement_idname = $this->EBMLidName($sub_sub_subelement_id);
506
+ $sub_sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
507
+ $sub_sub_sub_subelement_end = $offset + $sub_sub_sub_subelement_length;
508
+ switch ($sub_sub_sub_subelement_id) {
509
+ case EBML_ID_CONTENTCOMPALGO:
510
+ $track_entry[$sub_subelement_idname][$sub_sub_subelement_idname][$sub_sub_sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_sub_subelement_length));
511
+ break;
512
+ case EBML_ID_CONTENTCOMPSETTINGS:
513
+ $track_entry[$sub_subelement_idname][$sub_sub_subelement_idname][$sub_sub_sub_subelement_idname] = substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_sub_subelement_length);
514
+ break;
515
+ default:
516
+ $this->warnings[] = 'Unhandled track.contentencodings.contentencoding.contentcompression element['.__LINE__.'] ('.$subelement_id.'::'.$subelement_idname.' ['.$subelement_length.' bytes]) at '.$subelement_offset;
517
+ break;
518
+ }
519
+ $offset = $sub_sub_sub_subelement_end;
520
+ }
521
+ break;
522
+
523
+ case EBML_ID_CONTENTENCRYPTION:
524
+ while ($offset < $sub_sub_subelement_end) {
525
+ $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
526
+ $sub_sub_sub_subelement_offset = $offset;
527
+ $sub_sub_sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
528
+ $sub_sub_sub_subelement_idname = $this->EBMLidName($sub_sub_subelement_id);
529
+ $sub_sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
530
+ $sub_sub_sub_subelement_end = $offset + $sub_sub_sub_subelement_length;
531
+ switch ($sub_sub_sub_subelement_id) {
532
+ case EBML_ID_CONTENTENCALGO:
533
+ case EBML_ID_CONTENTSIGALGO:
534
+ case EBML_ID_CONTENTSIGHASHALGO:
535
+ $track_entry[$sub_subelement_idname][$sub_sub_subelement_idname][$sub_sub_sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_sub_subelement_length));
536
+ break;
537
+ case EBML_ID_CONTENTENCKEYID:
538
+ case EBML_ID_CONTENTSIGNATURE:
539
+ case EBML_ID_CONTENTSIGKEYID:
540
+ $track_entry[$sub_subelement_idname][$sub_sub_subelement_idname][$sub_sub_sub_subelement_idname] = substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_sub_subelement_length);
541
+ break;
542
+ default:
543
+ $this->warnings[] = 'Unhandled track.contentencodings.contentencoding.contentcompression element['.__LINE__.'] ('.$subelement_id.'::'.$subelement_idname.' ['.$subelement_length.' bytes]) at '.$subelement_offset;
544
+ break;
545
+ }
546
+ $offset = $sub_sub_sub_subelement_end;
547
+ }
548
+ break;
549
+
550
+ default:
551
+ $this->warnings[] = 'Unhandled track.contentencodings.contentencoding element['.__LINE__.'] ('.$subelement_id.'::'.$subelement_idname.' ['.$subelement_length.' bytes]) at '.$subelement_offset;
552
+ break;
553
+ }
554
+ $offset = $sub_sub_subelement_end;
555
+ }
556
+ break;
557
+ default:
558
+ $this->warnings[] = 'Unhandled track.contentencodings element['.__LINE__.'] ('.$subelement_id.'::'.$subelement_idname.' ['.$subelement_length.' bytes]) at '.$subelement_offset;
559
+ break;
560
+ }
561
+ $offset = $sub_subelement_end;
562
+ }
563
+ break;
564
+
565
+ default:
566
+ $this->warnings[] = 'Unhandled track element['.__LINE__.'] ('.$subelement_id.'::'.$subelement_idname.' ['.$subelement_length.' bytes]) at '.$subelement_offset;
567
+ break;
568
+ }
569
+ $offset = $subelement_end;
570
+ }
571
+ break;
572
+ default:
573
+ $this->warnings[] = 'Unhandled track element['.__LINE__.'] ('.$track_entry['id'].'::'.$track_entry['id_name'].') at '.$track_entry['offset'];
574
+ $offset = $track_entry_endoffset;
575
+ break;
576
+ }
577
+ $ThisFileInfo['matroska']['tracks']['tracks'][] = $track_entry;
578
+ }
579
+ break;
580
+
581
+ case EBML_ID_INFO: // Contains the position of other level 1 elements
582
+ $info_entry = array();
583
+ while ($offset < $element_end) {
584
+ $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
585
+ $subelement_offset = $offset;
586
+ $subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
587
+ $subelement_idname = $this->EBMLidName($subelement_id);
588
+ $subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
589
+ $subelement_end = $offset + $subelement_length;
590
+ switch ($subelement_id) {
591
+ case EBML_ID_CHAPTERTRANSLATEEDITIONUID:
592
+ case EBML_ID_CHAPTERTRANSLATECODEC:
593
+ case EBML_ID_TIMECODESCALE:
594
+ $info_entry[$subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length));
595
+ break;
596
+ case EBML_ID_DURATION:
597
+ $info_entry[$subelement_idname] = getid3_lib::BigEndian2Float(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length));
598
+ break;
599
+ case EBML_ID_DATEUTC:
600
+ $info_entry[$subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length));
601
+ $info_entry[$subelement_idname.'_unix'] = $this->EBMLdate2unix($info_entry[$subelement_idname]);
602
+ break;
603
+ case EBML_ID_SEGMENTUID:
604
+ case EBML_ID_PREVUID:
605
+ case EBML_ID_NEXTUID:
606
+ case EBML_ID_SEGMENTFAMILY:
607
+ case EBML_ID_CHAPTERTRANSLATEID:
608
+ $info_entry[$subelement_idname] = trim(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length), "\x00");
609
+ break;
610
+ case EBML_ID_SEGMENTFILENAME:
611
+ case EBML_ID_PREVFILENAME:
612
+ case EBML_ID_NEXTFILENAME:
613
+ case EBML_ID_TITLE:
614
+ case EBML_ID_MUXINGAPP:
615
+ case EBML_ID_WRITINGAPP:
616
+ $info_entry[$subelement_idname] = trim(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length), "\x00");
617
+ break;
618
+ default:
619
+ $this->warnings[] = 'Unhandled info element['.__LINE__.'] ('.$subelement_id.'::'.$subelement_idname.' ['.$subelement_length.' bytes]) at '.$subelement_offset;
620
+ break;
621
+ }
622
+ $offset = $subelement_end;
623
+ }
624
+ $ThisFileInfo['matroska']['info'][] = $info_entry;
625
+ break;
626
+
627
+ case EBML_ID_CUES:
628
+ $cues_entry = array();
629
+ while ($offset < $element_end) {
630
+ $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
631
+ $subelement_offset = $offset;
632
+ $subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
633
+ $subelement_idname = $this->EBMLidName($subelement_id);
634
+ $subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
635
+ $subelement_end = $offset + $subelement_length;
636
+ switch ($subelement_id) {
637
+ case EBML_ID_CUEPOINT:
638
+ $cuepoint_entry = array();
639
+ while ($offset < $subelement_end) {
640
+ $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
641
+ $sub_subelement_offset = $offset;
642
+ $sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
643
+ $sub_subelement_idname = $this->EBMLidName($sub_subelement_id);
644
+ $sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
645
+ $sub_subelement_end = $offset + $sub_subelement_length;
646
+ switch ($sub_subelement_id) {
647
+ case EBML_ID_CUETRACKPOSITIONS:
648
+ while ($offset < $sub_subelement_end) {
649
+ $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
650
+ $sub_sub_subelement_offset = $offset;
651
+ $sub_sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
652
+ $sub_sub_subelement_idname = $this->EBMLidName($sub_sub_subelement_id);
653
+ $sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
654
+ $sub_sub_subelement_end = $offset + $sub_sub_subelement_length;
655
+ switch ($sub_sub_subelement_id) {
656
+ case EBML_ID_CUETRACK:
657
+ $cuepoint_entry[$sub_sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length));
658
+ break;
659
+ default:
660
+ $this->warnings[] = 'Unhandled cues.cuepoint.cuetrackpositions element['.__LINE__.'] ('.$sub_sub_subelement_id.'::'.$sub_sub_subelement_idname.') at '.$sub_sub_subelement_offset;
661
+ break;
662
+ }
663
+ $offset = $sub_subelement_end;
664
+ }
665
+ break;
666
+ case EBML_ID_CUETIME:
667
+ $cuepoint_entry[$subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
668
+ break;
669
+ default:
670
+ $this->warnings[] = 'Unhandled cues.cuepoint element['.__LINE__.'] ('.$sub_subelement_id.'::'.$sub_subelement_idname.') at '.$sub_subelement_offset;
671
+ break;
672
+ }
673
+ $offset = $sub_subelement_end;
674
+ }
675
+ $cues_entry[] = $cuepoint_entry;
676
+ $offset = $sub_subelement_end;
677
+ break;
678
+ default:
679
+ $this->warnings[] = 'Unhandled cues element['.__LINE__.'] ('.$subelement_id.'::'.$subelement_idname.' ['.$subelement_length.' bytes]) at '.$subelement_offset;
680
+ break;
681
+ }
682
+ $offset = $subelement_end;
683
+ }
684
+ $ThisFileInfo['matroska']['cues'] = $cues_entry;
685
+ break;
686
+
687
+ case EBML_ID_TAGS:
688
+ $tags_entry = array();
689
+ while ($offset < $element_end) {
690
+ $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
691
+ $subelement_offset = $offset;
692
+ $subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
693
+ $subelement_idname = $this->EBMLidName($subelement_id);
694
+ $subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
695
+ $subelement_end = $offset + $subelement_length;
696
+ switch ($subelement_id) {
697
+ case EBML_ID_WRITINGAPP:
698
+ $tags_entry[$subelement_idname] = substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length);
699
+ break;
700
+ case EBML_ID_TAG:
701
+ $tag_entry = array();
702
+ while ($offset < $subelement_end) {
703
+ $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
704
+ $sub_subelement_offset = $offset;
705
+ $sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
706
+ $sub_subelement_idname = $this->EBMLidName($sub_subelement_id);
707
+ $sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
708
+ $sub_subelement_end = $offset + $sub_subelement_length;
709
+ switch ($sub_subelement_id) {
710
+ case EBML_ID_TARGETS:
711
+ $targets_entry = array();
712
+ while ($offset < $sub_subelement_end) {
713
+ $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
714
+ $sub_sub_subelement_offset = $offset;
715
+ $sub_sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
716
+ $sub_sub_subelement_idname = $this->EBMLidName($sub_sub_subelement_id);
717
+ $sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
718
+ $sub_sub_subelement_end = $offset + $sub_sub_subelement_length;
719
+ switch ($sub_sub_subelement_id) {
720
+ case EBML_ID_TARGETTYPEVALUE:
721
+ case EBML_ID_EDITIONUID:
722
+ case EBML_ID_CHAPTERUID:
723
+ case EBML_ID_ATTACHMENTUID:
724
+ case EBML_ID_TAGTRACKUID:
725
+ case EBML_ID_TAGCHAPTERUID:
726
+ $targets_entry[$sub_sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length));
727
+ break;
728
+ default:
729
+ $this->warnings[] = 'Unhandled tag.targets element['.__LINE__.'] ('.$sub_sub_subelement_id.'::'.$sub_sub_subelement_idname.') at '.$sub_sub_subelement_offset;
730
+ break;
731
+ }
732
+ $offset = $sub_sub_subelement_end;
733
+ }
734
+ $tag_entry[$sub_subelement_idname][] = $targets_entry;
735
+ break;
736
+ case EBML_ID_SIMPLETAG:
737
+ $simpletag_entry = array();
738
+ while ($offset < $sub_subelement_end) {
739
+ $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
740
+ $sub_sub_subelement_offset = $offset;
741
+ $sub_sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
742
+ $sub_sub_subelement_idname = $this->EBMLidName($sub_sub_subelement_id);
743
+ $sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
744
+ $sub_sub_subelement_end = $offset + $sub_sub_subelement_length;
745
+ switch ($sub_sub_subelement_id) {
746
+ case EBML_ID_TAGNAME:
747
+ case EBML_ID_TAGLANGUAGE:
748
+ case EBML_ID_TAGSTRING:
749
+ case EBML_ID_TAGBINARY:
750
+ $simpletag_entry[$sub_sub_subelement_idname] = substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length);
751
+ break;
752
+ case EBML_ID_TAGDEFAULT:
753
+ $simpletag_entry[$sub_sub_subelement_idname] = (bool) getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length));
754
+ break;
755
+ default:
756
+ $this->warnings[] = 'Unhandled tag.simpletag element['.__LINE__.'] ('.$sub_sub_subelement_id.'::'.$sub_sub_subelement_idname.') at '.$sub_sub_subelement_offset;
757
+ break;
758
+ }
759
+ $offset = $sub_sub_subelement_end;
760
+ }
761
+ $tag_entry[$sub_subelement_idname][] = $simpletag_entry;
762
+ break;
763
+ case EBML_ID_TARGETTYPE:
764
+ $tag_entry[$sub_subelement_idname] = substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length);
765
+ break;
766
+ case EBML_ID_TRACKUID:
767
+ $tag_entry[$sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
768
+ break;
769
+ default:
770
+ $this->warnings[] = 'Unhandled tags.tag element['.__LINE__.'] ('.$sub_subelement_id.'::'.$sub_subelement_idname.') at '.$sub_subelement_offset;
771
+ break;
772
+ }
773
+ $offset = $sub_subelement_end;
774
+ }
775
+ $tags_entry['tags'][] = $tag_entry;
776
+ $offset = $sub_subelement_end;
777
+ break;
778
+ default:
779
+ $this->warnings[] = 'Unhandled tags element['.__LINE__.'] ('.$subelement_id.'::'.$subelement_idname.' ['.$subelement_length.' bytes]) at '.$subelement_offset;
780
+ break;
781
+ }
782
+ $offset = $subelement_end;
783
+ }
784
+ $ThisFileInfo['matroska']['tags'] = $tags_entry;
785
+ break;
786
+
787
+
788
+ case EBML_ID_ATTACHMENTS:
789
+ while ($offset < $element_end) {
790
+ $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
791
+ $subelement_offset = $offset;
792
+ $subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
793
+ $subelement_idname = $this->EBMLidName($subelement_id);
794
+ $subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
795
+ $subelement_end = $offset + $subelement_length;
796
+ switch ($subelement_id) {
797
+ case EBML_ID_ATTACHEDFILE:
798
+ $attachedfile_entry = array();
799
+ while ($offset < $subelement_end) {
800
+ $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
801
+ $sub_subelement_offset = $offset;
802
+ $sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
803
+ $sub_subelement_idname = $this->EBMLidName($sub_subelement_id);
804
+ $sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
805
+ $sub_subelement_end = $offset + $sub_subelement_length;
806
+ switch ($sub_subelement_id) {
807
+ case EBML_ID_FILEDESCRIPTION:
808
+ case EBML_ID_FILENAME:
809
+ case EBML_ID_FILEMIMETYPE:
810
+ $attachedfile_entry[$sub_subelement_idname] = substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length);
811
+ break;
812
+
813
+ case EBML_ID_FILEDATA:
814
+ $attachedfile_entry['data_offset'] = $offset;
815
+ $attachedfile_entry['data_length'] = $sub_subelement_length;
816
+ if ($sub_subelement_length < 1024) {
817
+ $attachedfile_entry[$sub_subelement_idname] = substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length);
818
+ }
819
+ break;
820
+
821
+ case EBML_ID_FILEUID:
822
+ $attachedfile_entry[$sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
823
+ break;
824
+
825
+ default:
826
+ $this->warnings[] = 'Unhandled attachment.attachedfile element['.__LINE__.'] ('.$sub_subelement_id.'::'.$sub_subelement_idname.') at '.$sub_subelement_offset;
827
+ break;
828
+ }
829
+ $offset = $sub_subelement_end;
830
+ }
831
+ $ThisFileInfo['matroska']['attachments'][] = $attachedfile_entry;
832
+ $offset = $sub_subelement_end;
833
+ break;
834
+ default:
835
+ $this->warnings[] = 'Unhandled tags element['.__LINE__.'] ('.$subelement_id.'::'.$subelement_idname.' ['.$subelement_length.' bytes]) at '.$subelement_offset;
836
+ break;
837
+ }
838
+ $offset = $subelement_end;
839
+ }
840
+ break;
841
+
842
+
843
+ case EBML_ID_CHAPTERS: // not important to us, contains mostly actual audio/video data, ignore
844
+ while ($offset < $element_end) {
845
+ $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
846
+ $subelement_offset = $offset;
847
+ $subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
848
+ $subelement_idname = $this->EBMLidName($subelement_id);
849
+ $subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
850
+ $subelement_end = $offset + $subelement_length;
851
+ switch ($subelement_id) {
852
+ case EBML_ID_EDITIONENTRY:
853
+ $editionentry_entry = array();
854
+ while ($offset < $subelement_end) {
855
+ $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
856
+ $sub_subelement_offset = $offset;
857
+ $sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
858
+ $sub_subelement_idname = $this->EBMLidName($sub_subelement_id);
859
+ $sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
860
+ $sub_subelement_end = $offset + $sub_subelement_length;
861
+ switch ($sub_subelement_id) {
862
+ case EBML_ID_EDITIONUID:
863
+ $editionentry_entry[$sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
864
+ break;
865
+ case EBML_ID_EDITIONFLAGHIDDEN:
866
+ case EBML_ID_EDITIONFLAGDEFAULT:
867
+ case EBML_ID_EDITIONFLAGORDERED:
868
+ $editionentry_entry[$sub_subelement_idname] = (bool) getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
869
+ break;
870
+ case EBML_ID_CHAPTERATOM:
871
+ $chapteratom_entry = array();
872
+ while ($offset < $sub_subelement_end) {
873
+ $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
874
+ $sub_sub_subelement_offset = $offset;
875
+ $sub_sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
876
+ $sub_sub_subelement_idname = $this->EBMLidName($sub_sub_subelement_id);
877
+ $sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
878
+ $sub_sub_subelement_end = $offset + $sub_sub_subelement_length;
879
+ switch ($sub_sub_subelement_id) {
880
+ case EBML_ID_CHAPTERSEGMENTUID:
881
+ case EBML_ID_CHAPTERSEGMENTEDITIONUID:
882
+ $chapteratom_entry[$sub_sub_subelement_idname] = substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length);
883
+ break;
884
+ case EBML_ID_CHAPTERFLAGENABLED:
885
+ case EBML_ID_CHAPTERFLAGHIDDEN:
886
+ $chapteratom_entry[$sub_sub_subelement_idname] = (bool) getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length));
887
+ break;
888
+ case EBML_ID_CHAPTERUID:
889
+ case EBML_ID_CHAPTERTIMESTART:
890
+ case EBML_ID_CHAPTERTIMEEND:
891
+ $chapteratom_entry[$sub_sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length));
892
+ break;
893
+ case EBML_ID_CHAPTERTRACK:
894
+ $chaptertrack_entry = array();
895
+ while ($offset < $sub_sub_subelement_end) {
896
+ $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
897
+ $sub_sub_sub_subelement_offset = $offset;
898
+ $sub_sub_sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
899
+ $sub_sub_sub_subelement_idname = $this->EBMLidName($sub_sub_subelement_id);
900
+ $sub_sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
901
+ $sub_sub_sub_subelement_end = $offset + $sub_sub_sub_subelement_length;
902
+ switch ($sub_sub_sub_subelement_id) {
903
+ case EBML_ID_CHAPTERTRACKNUMBER:
904
+ $chaptertrack_entry[$sub_sub_sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_sub_subelement_length));
905
+ break;
906
+ default:
907
+ $this->warnings[] = 'Unhandled chapters.editionentry.chapteratom.chaptertrack element['.__LINE__.'] ('.$sub_sub_sub_subelement_id.'::'.$sub_sub_sub_subelement_idname.') at '.$sub_sub_sub_subelement_offset;
908
+ break;
909
+ }
910
+ $offset = $sub_sub_sub_subelement_end;
911
+ }
912
+ $chapteratom_entry[$sub_sub_subelement_idname][] = $chaptertrack_entry;
913
+ break;
914
+ case EBML_ID_CHAPTERDISPLAY:
915
+ $chapterdisplay_entry = array();
916
+ while ($offset < $sub_sub_subelement_end) {
917
+ $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
918
+ $sub_sub_sub_subelement_offset = $offset;
919
+ $sub_sub_sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
920
+ $sub_sub_sub_subelement_idname = $this->EBMLidName($sub_sub_sub_subelement_id);
921
+ $sub_sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
922
+ $sub_sub_sub_subelement_end = $offset + $sub_sub_sub_subelement_length;
923
+ switch ($sub_sub_sub_subelement_id) {
924
+ case EBML_ID_CHAPSTRING:
925
+ case EBML_ID_CHAPLANGUAGE:
926
+ case EBML_ID_CHAPCOUNTRY:
927
+ $chapterdisplay_entry[$sub_sub_sub_subelement_idname] = substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_sub_subelement_length);
928
+ break;
929
+ default:
930
+ $this->warnings[] = 'Unhandled chapters.editionentry.chapteratom.chapterdisplay element['.__LINE__.'] ('.$sub_sub_sub_subelement_id.'::'.$sub_sub_sub_subelement_idname.') at '.$sub_sub_sub_subelement_offset;
931
+ break;
932
+ }
933
+ $offset = $sub_sub_sub_subelement_end;
934
+ }
935
+ $chapteratom_entry[$sub_sub_subelement_idname][] = $chapterdisplay_entry;
936
+ break;
937
+ default:
938
+ $this->warnings[] = 'Unhandled chapters.editionentry.chapteratom element['.__LINE__.'] ('.$sub_sub_subelement_id.'::'.$sub_sub_subelement_idname.') at '.$sub_sub_subelement_offset;
939
+ break;
940
+ }
941
+ $offset = $sub_sub_subelement_end;
942
+ }
943
+ $editionentry_entry[$sub_subelement_idname][] = $chapteratom_entry;
944
+ break;
945
+ default:
946
+ $this->warnings[] = 'Unhandled chapters.editionentry element['.__LINE__.'] ('.$sub_subelement_id.'::'.$sub_subelement_idname.') at '.$sub_subelement_offset;
947
+ break;
948
+ }
949
+ $offset = $sub_subelement_end;
950
+ }
951
+ $ThisFileInfo['matroska']['chapters'][] = $editionentry_entry;
952
+ $offset = $sub_subelement_end;
953
+ break;
954
+ default:
955
+ $this->warnings[] = 'Unhandled chapters element['.__LINE__.'] ('.$subelement_id.'::'.$subelement_idname.' ['.$subelement_length.' bytes]) at '.$subelement_offset;
956
+ break;
957
+ }
958
+ $offset = $subelement_end;
959
+ }
960
+ break;
961
+
962
+
963
+ case EBML_ID_VOID: // padding, ignore
964
+ $void_entry = array();
965
+ $void_entry['offset'] = $offset;
966
+ $ThisFileInfo['matroska']['void'][] = $void_entry;
967
+ break;
968
+
969
+ case EBML_ID_CLUSTER: // not important to us, contains mostly actual audio/video data, ignore
970
+ $cluster_entry = array();
971
+ while ($offset < $element_end) {
972
+ $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
973
+ $subelement_offset = $offset;
974
+ //var_dump($offset);
975
+ $subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
976
+ //var_dump($subelement_id);
977
+ //echo '<br>';
978
+ $subelement_idname = $this->EBMLidName($subelement_id);
979
+ $subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
980
+ //var_dump($subelement_length);
981
+ $subelement_end = $offset + $subelement_length;
982
+ //exit;
983
+ switch ($subelement_id) {
984
+ case EBML_ID_CLUSTERTIMECODE:
985
+ case EBML_ID_CLUSTERPOSITION:
986
+ case EBML_ID_CLUSTERPREVSIZE:
987
+ $cluster_entry[$subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length));
988
+ break;
989
+
990
+ case EBML_ID_CLUSTERSILENTTRACKS:
991
+ $cluster_silent_tracks = array();
992
+ while ($offset < $subelement_end) {
993
+ $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
994
+ $sub_subelement_offset = $offset;
995
+ $sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
996
+ $sub_subelement_idname = $this->EBMLidName($sub_subelement_id);
997
+ $sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
998
+ $sub_subelement_end = $offset + $sub_subelement_length;
999
+ switch ($sub_subelement_id) {
1000
+ case EBML_ID_CLUSTERSILENTTRACKNUMBER:
1001
+ $cluster_silent_tracks[] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
1002
+ break;
1003
+ default:
1004
+ $this->warnings[] = 'Unhandled clusters.silenttracks element['.__LINE__.'] ('.$sub_subelement_id.'::'.$sub_subelement_idname.') at '.$sub_subelement_offset;
1005
+ break;
1006
+ }
1007
+ $offset = $sub_subelement_end;
1008
+ }
1009
+ $cluster_entry[$subelement_idname][] = $cluster_silent_tracks;
1010
+ $offset = $sub_subelement_end;
1011
+ break;
1012
+
1013
+ case EBML_ID_CLUSTERBLOCKGROUP:
1014
+ $cluster_block_group = array('offset'=>$offset);
1015
+ while ($offset < $subelement_end) {
1016
+ $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
1017
+ $sub_subelement_offset = $offset;
1018
+ $sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
1019
+ $sub_subelement_idname = $this->EBMLidName($sub_subelement_id);
1020
+ $sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
1021
+ $sub_subelement_end = $offset + $sub_subelement_length;
1022
+ switch ($sub_subelement_id) {
1023
+ case EBML_ID_CLUSTERBLOCK:
1024
+ $cluster_block_data = array();
1025
+ $cluster_block_data['tracknumber'] = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
1026
+ $cluster_block_data['timecode'] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset, 2));
1027
+ $offset += 2;
1028
+ // unsure whether this is 1 octect or 2 octets? (http://matroska.org/technical/specs/index.html#block_structure)
1029
+ $cluster_block_data['flags_raw'] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset, 1));
1030
+ $offset += 1;
1031
+ //$cluster_block_data['flags']['reserved1'] = (($cluster_block_data['flags_raw'] & 0xF0) >> 4);
1032
+ $cluster_block_data['flags']['invisible'] = (bool) (($cluster_block_data['flags_raw'] & 0x08) >> 3);
1033
+ $cluster_block_data['flags']['lacing'] = (($cluster_block_data['flags_raw'] & 0x06) >> 1);
1034
+ //$cluster_block_data['flags']['reserved2'] = (($cluster_block_data['flags_raw'] & 0x01) >> 0);
1035
+ $cluster_block_data['flags']['lacing_type'] = $this->MatroskaBlockLacingType($cluster_block_data['flags']['lacing']);
1036
+ if ($cluster_block_data['flags']['lacing'] != 0) {
1037
+ $cluster_block_data['lace_frames'] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset, 1)); // Number of frames in the lace-1 (uint8)
1038
+ $offset += 1;
1039
+ if ($cluster_block_data['flags']['lacing'] != 2) {
1040
+ $cluster_block_data['lace_frames'] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset, 1)); // 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).
1041
+ $offset += 1;
1042
+ }
1043
+ }
1044
+ if (!isset($ThisFileInfo['matroska']['track_data_offsets'][$cluster_block_data['tracknumber']])) {
1045
+ $ThisFileInfo['matroska']['track_data_offsets'][$cluster_block_data['tracknumber']] = $offset;
1046
+ }
1047
+ $cluster_block_group[$sub_subelement_idname] = $cluster_block_data;
1048
+ break;
1049
+
1050
+ case EBML_ID_CLUSTERREFERENCEPRIORITY: // unsigned-int
1051
+ case EBML_ID_CLUSTERBLOCKDURATION: // unsigned-int
1052
+ $cluster_block_group[$sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
1053
+ break;
1054
+
1055
+ case EBML_ID_CLUSTERREFERENCEBLOCK: // signed-int
1056
+ $cluster_block_group[$sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length), false, true);
1057
+ break;
1058
+
1059
+ default:
1060
+ $this->warnings[] = 'Unhandled clusters.blockgroup element['.__LINE__.'] ('.$sub_subelement_id.'::'.$sub_subelement_idname.') at '.$sub_subelement_offset;
1061
+ break;
1062
+ }
1063
+ $offset = $sub_subelement_end;
1064
+ }
1065
+ $cluster_entry[$subelement_idname][] = $cluster_block_group;
1066
+ $offset = $sub_subelement_end;
1067
+ break;
1068
+
1069
+ default:
1070
+ $this->warnings[] = 'Unhandled cluster element['.__LINE__.'] ('.$subelement_id.'::'.$subelement_idname.' ['.$subelement_length.' bytes]) at '.$subelement_offset;
1071
+ break;
1072
+ }
1073
+ $offset = $subelement_end;
1074
+ }
1075
+ $ThisFileInfo['matroska']['cluster'][] = $cluster_entry;
1076
+
1077
+ // check to see if all the data we need exists already, if so, break out of the loop
1078
+ if (isset($ThisFileInfo['matroska']['info']) && is_array($ThisFileInfo['matroska']['info'])) {
1079
+ if (isset($ThisFileInfo['matroska']['tracks']['tracks']) && is_array($ThisFileInfo['matroska']['tracks']['tracks'])) {
1080
+ break 2;
1081
+ }
1082
+ }
1083
+ break;
1084
+
1085
+ default:
1086
+ if ($element_data['id_name'] == dechex($element_data['id'])) {
1087
+ $ThisFileInfo['error'][] = 'Unhandled segment['.__LINE__.'] ('.$element_data['id'].') at '.$element_data_offset;
1088
+ } else {
1089
+ $this->warnings[] = 'Unhandled segment['.__LINE__.'] ('.$element_data['id'].'::'.$element_data['id_name'].') at '.$element_data['offset'];
1090
+ }
1091
+ break;
1092
+ }
1093
+ $offset = $element_end;
1094
+ }
1095
+ break;
1096
+
1097
+
1098
+ default:
1099
+ $ThisFileInfo['error'][] = 'Unhandled chunk['.__LINE__.'] ('.$top_element_id.') at '.$offset;
1100
+ break;
1101
+ }
1102
+ $offset = $top_element_endoffset;
1103
+ }
1104
+
1105
+
1106
+
1107
+ if (isset($ThisFileInfo['matroska']['info']) && is_array($ThisFileInfo['matroska']['info'])) {
1108
+ foreach ($ThisFileInfo['matroska']['info'] as $key => $infoarray) {
1109
+ if (isset($infoarray['Duration'])) {
1110
+ // TimecodeScale is how many nanoseconds each Duration unit is
1111
+ $ThisFileInfo['playtime_seconds'] = $infoarray['Duration'] * ((isset($infoarray['TimecodeScale']) ? $infoarray['TimecodeScale'] : 1000000) / 1000000000);
1112
+ break;
1113
+ }
1114
+ }
1115
+ }
1116
+ if (isset($ThisFileInfo['matroska']['tracks']['tracks']) && is_array($ThisFileInfo['matroska']['tracks']['tracks'])) {
1117
+ foreach ($ThisFileInfo['matroska']['tracks']['tracks'] as $key => $trackarray) {
1118
+ $track_info = array();
1119
+ switch (@$trackarray['TrackType']) {
1120
+ case 1: // Video
1121
+ if (@$trackarray['PixelWidth']) { $track_info['resolution_x'] = $trackarray['PixelWidth']; }
1122
+ if (@$trackarray['PixelHeight']) { $track_info['resolution_y'] = $trackarray['PixelHeight']; }
1123
+ if (@$trackarray['DisplayWidth']) { $track_info['display_x'] = $trackarray['DisplayWidth']; }
1124
+ if (@$trackarray['DisplayHeight']) { $track_info['display_y'] = $trackarray['DisplayHeight']; }
1125
+ if (@$trackarray['DefaultDuration']) { $track_info['frame_rate'] = round(1000000000 / $trackarray['DefaultDuration'], 3); }
1126
+ if (@$trackarray['CodecID']) { $track_info['dataformat'] = $this->MatroskaCodecIDtoCommonName($trackarray['CodecID']); }
1127
+ if (!empty($trackarray['codec_private_parsed']['fourcc'])) {
1128
+ $track_info['fourcc'] = $trackarray['codec_private_parsed']['fourcc'];
1129
+ }
1130
+ $ThisFileInfo['video']['streams'][] = $track_info;
1131
+ if (isset($track_info['resolution_x']) && empty($ThisFileInfo['video']['resolution_x'])) {
1132
+ foreach ($track_info as $key => $value) {
1133
+ $ThisFileInfo['video'][$key] = $value;
1134
+ }
1135
+ }
1136
+ break;
1137
+ case 2: // Audio
1138
+ if (@$trackarray['CodecID']) { $track_info['dataformat'] = $this->MatroskaCodecIDtoCommonName($trackarray['CodecID']); }
1139
+ if (@$trackarray['SamplingFrequency']) { $track_info['sample_rate'] = $trackarray['SamplingFrequency']; }
1140
+ if (@$trackarray['Channels']) { $track_info['channels'] = $trackarray['Channels']; }
1141
+ if (@$trackarray['BitDepth']) { $track_info['bits_per_sample'] = $trackarray['BitDepth']; }
1142
+ switch (@$trackarray[$this->EBMLidName(EBML_ID_CODECID)]) {
1143
+ case 'A_PCM/INT/LIT':
1144
+ case 'A_PCM/INT/BIG':
1145
+ $track_info['bitrate'] = $trackarray['SamplingFrequency'] * $trackarray['Channels'] * $trackarray['BitDepth'];
1146
+ break;
1147
+
1148
+ case 'A_AC3':
1149
+ if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.ac3.php', __FILE__, false)) {
1150
+ $ac3_thisfileinfo = array('avdataoffset'=>$ThisFileInfo['matroska']['track_data_offsets'][$trackarray['TrackNumber']]);
1151
+ $getid3_ac3 = new getid3_ac3($fd, $ac3_thisfileinfo);
1152
+ $ThisFileInfo['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $ac3_thisfileinfo;
1153
+ if (!empty($ac3_thisfileinfo['error'])) {
1154
+ foreach ($ac3_thisfileinfo['error'] as $newerror) {
1155
+ $this->warnings[] = 'getid3_ac3() says: ['.$newerror.']';
1156
+ }
1157
+ }
1158
+ if (!empty($ac3_thisfileinfo['warning'])) {
1159
+ foreach ($ac3_thisfileinfo['warning'] as $newerror) {
1160
+ $this->warnings[] = 'getid3_ac3() says: ['.$newerror.']';
1161
+ }
1162
+ }
1163
+ if (isset($ac3_thisfileinfo['audio']) && is_array($ac3_thisfileinfo['audio'])) {
1164
+ foreach ($ac3_thisfileinfo['audio'] as $key => $value) {
1165
+ $track_info[$key] = $value;
1166
+ }
1167
+ }
1168
+ unset($ac3_thisfileinfo);
1169
+ unset($getid3_ac3);
1170
+ } else {
1171
+ $this->warnings[] = 'Unable to parse audio data['.__LINE__.'] because cannot include "module.audio.ac3.php"';
1172
+ }
1173
+ break;
1174
+
1175
+ case 'A_DTS':
1176
+ $dts_offset = $ThisFileInfo['matroska']['track_data_offsets'][$trackarray['TrackNumber']];
1177
+ // this is a NASTY hack, but sometimes audio data is off by a byte or two and not sure why, email info@getid3.org if you can explain better
1178
+ fseek($fd, $dts_offset, SEEK_SET);
1179
+ $magic_test = fread($fd, 8);
1180
+ for ($i = 0; $i < 4; $i++) {
1181
+ // look to see if DTS "magic" is here, if so adjust offset by that many bytes
1182
+ if (substr($magic_test, $i, 4) == "\x7F\xFE\x80\x01") {
1183
+ $dts_offset += $i;
1184
+ break;
1185
+ }
1186
+ }
1187
+ if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.dts.php', __FILE__, false)) {
1188
+ $dts_thisfileinfo = array('avdataoffset'=>$dts_offset);
1189
+ $getid3_dts = new getid3_dts($fd, $dts_thisfileinfo);
1190
+ $ThisFileInfo['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $dts_thisfileinfo;
1191
+ if (!empty($dts_thisfileinfo['error'])) {
1192
+ foreach ($dts_thisfileinfo['error'] as $newerror) {
1193
+ $this->warnings[] = 'getid3_dts() says: ['.$newerror.']';
1194
+ }
1195
+ }
1196
+ if (!empty($dts_thisfileinfo['warning'])) {
1197
+ foreach ($dts_thisfileinfo['warning'] as $newerror) {
1198
+ $this->warnings[] = 'getid3_dts() says: ['.$newerror.']';
1199
+ }
1200
+ }
1201
+ if (isset($dts_thisfileinfo['audio']) && is_array($dts_thisfileinfo['audio'])) {
1202
+ foreach ($dts_thisfileinfo['audio'] as $key => $value) {
1203
+ $track_info[$key] = $value;
1204
+ }
1205
+ }
1206
+ unset($dts_thisfileinfo);
1207
+ unset($getid3_dts);
1208
+ } else {
1209
+ $this->warnings[] = 'Unable to parse audio data['.__LINE__.'] because cannot include "module.audio.dts.php"';
1210
+ }
1211
+ break;
1212
+
1213
+ //case 'A_AAC':
1214
+ // if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.aac.php', __FILE__, false)) {
1215
+ // $aac_thisfileinfo = array('avdataoffset'=>$ThisFileInfo['matroska']['track_data_offsets'][$trackarray['TrackNumber']]);
1216
+ // $getid3_aac = new getid3_aac($fd, $aac_thisfileinfo);
1217
+ // $ThisFileInfo['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $aac_thisfileinfo;
1218
+ // if (isset($aac_thisfileinfo['audio']) && is_array($aac_thisfileinfo['audio'])) {
1219
+ // foreach ($aac_thisfileinfo['audio'] as $key => $value) {
1220
+ // $track_info[$key] = $value;
1221
+ // }
1222
+ // }
1223
+ // unset($aac_thisfileinfo);
1224
+ // unset($getid3_aac);
1225
+ // } else {
1226
+ // $this->warnings[] = 'Unable to parse audio data['.__LINE__.'] because cannot include "module.audio.aac.php"';
1227
+ // }
1228
+ // break;
1229
+
1230
+ case 'A_MPEG/L3':
1231
+ if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.mp3.php', __FILE__, false)) {
1232
+ $mp3_thisfileinfo = array(
1233
+ 'avdataoffset' => $ThisFileInfo['matroska']['track_data_offsets'][$trackarray['TrackNumber']],
1234
+ 'avdataend' => $ThisFileInfo['matroska']['track_data_offsets'][$trackarray['TrackNumber']] + 1024,
1235
+ );
1236
+ $getid3_mp3 = new getid3_mp3($fd, $mp3_thisfileinfo);
1237
+ $getid3_mp3->allow_bruteforce = true;
1238
+ //getid3_mp3::getOnlyMPEGaudioInfo($fd, $mp3_thisfileinfo, $offset, false);
1239
+ $ThisFileInfo['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $mp3_thisfileinfo;
1240
+ if (!empty($mp3_thisfileinfo['error'])) {
1241
+ foreach ($mp3_thisfileinfo['error'] as $newerror) {
1242
+ $this->warnings[] = 'getid3_mp3() says: ['.$newerror.']';
1243
+ }
1244
+ }
1245
+ if (!empty($mp3_thisfileinfo['warning'])) {
1246
+ foreach ($mp3_thisfileinfo['warning'] as $newerror) {
1247
+ $this->warnings[] = 'getid3_mp3() says: ['.$newerror.']';
1248
+ }
1249
+ }
1250
+ if (isset($mp3_thisfileinfo['audio']) && is_array($mp3_thisfileinfo['audio'])) {
1251
+ foreach ($mp3_thisfileinfo['audio'] as $key => $value) {
1252
+ $track_info[$key] = $value;
1253
+ }
1254
+ }
1255
+ unset($mp3_thisfileinfo);
1256
+ unset($getid3_mp3);
1257
+ } else {
1258
+ $this->warnings[] = 'Unable to parse audio data['.__LINE__.'] because cannot include "module.audio.mp3.php"';
1259
+ }
1260
+ break;
1261
+
1262
+ case 'A_VORBIS':
1263
+ if (isset($trackarray['CodecPrivate'])) {
1264
+ // this is a NASTY hack, email info@getid3.org if you have a better idea how to get this info out
1265
+ $found_vorbis = false;
1266
+ for ($vorbis_offset = 1; $vorbis_offset < 16; $vorbis_offset++) {
1267
+ if (substr($trackarray['CodecPrivate'], $vorbis_offset, 6) == 'vorbis') {
1268
+ $vorbis_offset--;
1269
+ $found_vorbis = true;
1270
+ break;
1271
+ }
1272
+ }
1273
+ if ($found_vorbis) {
1274
+ if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.ogg.php', __FILE__, false)) {
1275
+ $vorbis_fileinfo = array();
1276
+ $oggpageinfo['page_seqno'] = 0;
1277
+ getid3_ogg::ParseVorbisPageHeader($trackarray['CodecPrivate'], $vorbis_offset, $vorbis_fileinfo, $oggpageinfo);
1278
+ $ThisFileInfo['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $vorbis_fileinfo;
1279
+ if (!empty($vorbis_fileinfo['error'])) {
1280
+ foreach ($vorbis_fileinfo['error'] as $newerror) {
1281
+ $this->warnings[] = 'getid3_ogg() says: ['.$newerror.']';
1282
+ }
1283
+ }
1284
+ if (!empty($vorbis_fileinfo['warning'])) {
1285
+ foreach ($vorbis_fileinfo['warning'] as $newerror) {
1286
+ $this->warnings[] = 'getid3_ogg() says: ['.$newerror.']';
1287
+ }
1288
+ }
1289
+ if (isset($vorbis_fileinfo['audio']) && is_array($vorbis_fileinfo['audio'])) {
1290
+ foreach ($vorbis_fileinfo['audio'] as $key => $value) {
1291
+ $track_info[$key] = $value;
1292
+ }
1293
+ }
1294
+ if (@$vorbis_fileinfo['ogg']['bitrate_average']) {
1295
+ $track_info['bitrate'] = $vorbis_fileinfo['ogg']['bitrate_average'];
1296
+ } elseif (@$vorbis_fileinfo['ogg']['bitrate_nominal']) {
1297
+ $track_info['bitrate'] = $vorbis_fileinfo['ogg']['bitrate_nominal'];
1298
+ }
1299
+ unset($vorbis_fileinfo);
1300
+ unset($oggpageinfo);
1301
+ } else {
1302
+ $this->warnings[] = 'Unable to parse audio data['.__LINE__.'] because cannot include "module.audio.ogg.php"';
1303
+ }
1304
+ } else {
1305
+ }
1306
+ } else {
1307
+ }
1308
+ break;
1309
+
1310
+ default:
1311
+ $this->warnings[] = 'Unhandled audio type "'.@$trackarray[$this->EBMLidName(EBML_ID_CODECID)].'"';
1312
+ break;
1313
+ }
1314
+
1315
+
1316
+ $ThisFileInfo['audio']['streams'][] = $track_info;
1317
+ if (isset($track_info['dataformat']) && empty($ThisFileInfo['audio']['dataformat'])) {
1318
+ foreach ($track_info as $key => $value) {
1319
+ $ThisFileInfo['audio'][$key] = $value;
1320
+ }
1321
+ }
1322
+ break;
1323
+ default:
1324
+ // ignore, do nothing
1325
+ break;
1326
+ }
1327
+ }
1328
+ }
1329
+
1330
+ if ($this->hide_clusters) {
1331
+ // too much data returned that is usually not useful
1332
+ if (isset($ThisFileInfo['matroska']['segments']) && is_array($ThisFileInfo['matroska']['segments'])) {
1333
+ foreach ($ThisFileInfo['matroska']['segments'] as $key => $segmentsarray) {
1334
+ if ($segmentsarray['id'] == EBML_ID_CLUSTER) {
1335
+ unset($ThisFileInfo['matroska']['segments'][$key]);
1336
+ }
1337
+ }
1338
+ }
1339
+ if (isset($ThisFileInfo['matroska']['seek']) && is_array($ThisFileInfo['matroska']['seek'])) {
1340
+ foreach ($ThisFileInfo['matroska']['seek'] as $key => $seekarray) {
1341
+ if ($seekarray['target_id'] == EBML_ID_CLUSTER) {
1342
+ unset($ThisFileInfo['matroska']['seek'][$key]);
1343
+ }
1344
+ }
1345
+ }
1346
+ //unset($ThisFileInfo['matroska']['cluster']);
1347
+ //unset($ThisFileInfo['matroska']['track_data_offsets']);
1348
+ }
1349
+
1350
+ if (!empty($ThisFileInfo['video']['streams'])) {
1351
+ $ThisFileInfo['mime_type'] = 'video/x-matroska';
1352
+ } elseif (!empty($ThisFileInfo['video']['streams'])) {
1353
+ $ThisFileInfo['mime_type'] = 'audio/x-matroska';
1354
+ } elseif (isset($ThisFileInfo['mime_type'])) {
1355
+ unset($ThisFileInfo['mime_type']);
1356
+ }
1357
+
1358
+ foreach ($this->warnings as $key => $value) {
1359
+ $ThisFileInfo['warning'][] = $value;
1360
+ }
1361
+
1362
+ return true;
1363
+ }
1364
+
1365
+
1366
+ ///////////////////////////////////////
1367
+
1368
+
1369
+ function EnsureBufferHasEnoughData(&$fd, &$EBMLdata, &$offset, &$EBMLdata_offset) {
1370
+ $min_data = 1024;
1371
+ if ($offset > 2147450880) { // 2^31 - 2^15 (2G-32k)
1372
+ $offset = pow(2,63);
1373
+ return false;
1374
+ } elseif (($offset - $EBMLdata_offset) >= (strlen($EBMLdata) - $min_data)) {
1375
+ fseek($fd, $offset, SEEK_SET);
1376
+ $EBMLdata_offset = ftell($fd);
1377
+ $EBMLdata = fread($fd, $this->read_buffer_size);
1378
+ }
1379
+ return true;
1380
+ }
1381
+
1382
+ function readEBMLint(&$string, &$offset, $dataoffset=0) {
1383
+ $actual_offset = $offset - $dataoffset;
1384
+ if ($offset > 2147450880) { // 2^31 - 2^15 (2G-32k)
1385
+ $this->warnings[] = 'aborting readEBMLint() because $offset larger than 2GB';
1386
+ return false;
1387
+ } elseif ($actual_offset >= strlen($string)) {
1388
+ $this->warnings[] = '$actual_offset > $string in readEBMLint($string['.strlen($string).'], '.$offset.', '.$dataoffset.')';
1389
+ return false;
1390
+ } elseif ($actual_offset < 0) {
1391
+ $this->warnings[] = '$actual_offset < 0 in readEBMLint($string['.strlen($string).'], '.$offset.', '.$dataoffset.')';
1392
+ return false;
1393
+ }
1394
+ $first_byte_int = ord($string{$actual_offset});
1395
+ if (0x80 & $first_byte_int) {
1396
+ $length = 1;
1397
+ } elseif (0x40 & $first_byte_int) {
1398
+ $length = 2;
1399
+ } elseif (0x20 & $first_byte_int) {
1400
+ $length = 3;
1401
+ } elseif (0x10 & $first_byte_int) {
1402
+ $length = 4;
1403
+ } elseif (0x08 & $first_byte_int) {
1404
+ $length = 5;
1405
+ } elseif (0x04 & $first_byte_int) {
1406
+ $length = 6;
1407
+ } elseif (0x02 & $first_byte_int) {
1408
+ $length = 7;
1409
+ } elseif (0x01 & $first_byte_int) {
1410
+ $length = 8;
1411
+ } else {
1412
+ $offset = pow(2,63); // abort processing, skip to end of file
1413
+ $this->warnings[] = 'invalid EBML integer (leading 0x00) at '.$offset;
1414
+ return false;
1415
+ }
1416
+ $int_value = $this->EBML2Int(substr($string, $actual_offset, $length));
1417
+ $offset += $length;
1418
+ return $int_value;
1419
+ }
1420
+
1421
+ function EBML2Int($EBMLstring) {
1422
+ // http://matroska.org/specs/
1423
+
1424
+ // Element ID coded with an UTF-8 like system:
1425
+ // 1xxx xxxx - Class A IDs (2^7 -2 possible values) (base 0x8X)
1426
+ // 01xx xxxx xxxx xxxx - Class B IDs (2^14-2 possible values) (base 0x4X 0xXX)
1427
+ // 001x xxxx xxxx xxxx xxxx xxxx - Class C IDs (2^21-2 possible values) (base 0x2X 0xXX 0xXX)
1428
+ // 0001 xxxx xxxx xxxx xxxx xxxx xxxx xxxx - Class D IDs (2^28-2 possible values) (base 0x1X 0xXX 0xXX 0xXX)
1429
+ // Values with all x at 0 and 1 are reserved (hence the -2).
1430
+
1431
+ // Data size, in octets, is also coded with an UTF-8 like system :
1432
+ // 1xxx xxxx - value 0 to 2^7-2
1433
+ // 01xx xxxx xxxx xxxx - value 0 to 2^14-2
1434
+ // 001x xxxx xxxx xxxx xxxx xxxx - value 0 to 2^21-2
1435
+ // 0001 xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^28-2
1436
+ // 0000 1xxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^35-2
1437
+ // 0000 01xx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^42-2
1438
+ // 0000 001x xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^49-2
1439
+ // 0000 0001 xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^56-2
1440
+
1441
+ $first_byte_int = ord($EBMLstring{0});
1442
+ if (0x80 & $first_byte_int) {
1443
+ $EBMLstring{0} = chr($first_byte_int & 0x7F);
1444
+ } elseif (0x40 & $first_byte_int) {
1445
+ $EBMLstring{0} = chr($first_byte_int & 0x3F);
1446
+ } elseif (0x20 & $first_byte_int) {
1447
+ $EBMLstring{0} = chr($first_byte_int & 0x1F);
1448
+ } elseif (0x10 & $first_byte_int) {
1449
+ $EBMLstring{0} = chr($first_byte_int & 0x0F);
1450
+ } elseif (0x08 & $first_byte_int) {
1451
+ $EBMLstring{0} = chr($first_byte_int & 0x07);
1452
+ } elseif (0x04 & $first_byte_int) {
1453
+ $EBMLstring{0} = chr($first_byte_int & 0x03);
1454
+ } elseif (0x02 & $first_byte_int) {
1455
+ $EBMLstring{0} = chr($first_byte_int & 0x01);
1456
+ } elseif (0x01 & $first_byte_int) {
1457
+ $EBMLstring{0} = chr($first_byte_int & 0x00);
1458
+ } else {
1459
+ return false;
1460
+ }
1461
+ return getid3_lib::BigEndian2Int($EBMLstring);
1462
+ }
1463
+
1464
+
1465
+ function EBMLdate2unix($EBMLdatestamp) {
1466
+ // Date - signed 8 octets integer in nanoseconds with 0 indicating the precise beginning of the millennium (at 2001-01-01T00:00:00,000000000 UTC)
1467
+ // 978307200 == mktime(0, 0, 0, 1, 1, 2001) == January 1, 2001 12:00:00am UTC
1468
+ return round(($EBMLdatestamp / 1000000000) + 978307200);
1469
+ }
1470
+
1471
+
1472
+ function MatroskaBlockLacingType($lacingtype) {
1473
+ // http://matroska.org/technical/specs/index.html#block_structure
1474
+ static $MatroskaBlockLacingType = array();
1475
+ if (empty($MatroskaBlockLacingType)) {
1476
+ $MatroskaBlockLacingType[0x00] = 'no lacing';
1477
+ $MatroskaBlockLacingType[0x01] = 'Xiph lacing';
1478
+ $MatroskaBlockLacingType[0x02] = 'fixed-size lacing';
1479
+ $MatroskaBlockLacingType[0x03] = 'EBML lacing';
1480
+ }
1481
+ return (isset($MatroskaBlockLacingType[$lacingtype]) ? $MatroskaBlockLacingType[$lacingtype] : $lacingtype);
1482
+ }
1483
+
1484
+ function MatroskaCodecIDtoCommonName($codecid) {
1485
+ // http://www.matroska.org/technical/specs/codecid/index.html
1486
+ static $MatroskaCodecIDlist = array();
1487
+ if (empty($MatroskaCodecIDlist)) {
1488
+ $MatroskaCodecIDlist['A_AAC'] = 'aac';
1489
+ $MatroskaCodecIDlist['A_AAC/MPEG2/LC'] = 'aac';
1490
+ $MatroskaCodecIDlist['A_AC3'] = 'ac3';
1491
+ $MatroskaCodecIDlist['A_DTS'] = 'dts';
1492
+ $MatroskaCodecIDlist['A_FLAC'] = 'flac';
1493
+ $MatroskaCodecIDlist['A_MPEG/L1'] = 'mp1';
1494
+ $MatroskaCodecIDlist['A_MPEG/L2'] = 'mp2';
1495
+ $MatroskaCodecIDlist['A_MPEG/L3'] = 'mp3';
1496
+ $MatroskaCodecIDlist['A_PCM/INT/LIT'] = 'pcm'; // PCM Integer Little Endian
1497
+ $MatroskaCodecIDlist['A_PCM/INT/BIG'] = 'pcm'; // PCM Integer Big Endian
1498
+ $MatroskaCodecIDlist['A_QUICKTIME/QDMC'] = 'quicktime'; // Quicktime: QDesign Music
1499
+ $MatroskaCodecIDlist['A_QUICKTIME/QDM2'] = 'quicktime'; // Quicktime: QDesign Music v2
1500
+ $MatroskaCodecIDlist['A_VORBIS'] = 'vorbis';
1501
+ $MatroskaCodecIDlist['V_MPEG1'] = 'mpeg';
1502
+ $MatroskaCodecIDlist['V_THEORA'] = 'theora';
1503
+ $MatroskaCodecIDlist['V_REAL/RV40'] = 'real';
1504
+ $MatroskaCodecIDlist['V_REAL/RV10'] = 'real';
1505
+ $MatroskaCodecIDlist['V_REAL/RV20'] = 'real';
1506
+ $MatroskaCodecIDlist['V_REAL/RV30'] = 'real';
1507
+ $MatroskaCodecIDlist['V_QUICKTIME'] = 'quicktime'; // Quicktime
1508
+ $MatroskaCodecIDlist['V_MPEG4/ISO/AP'] = 'mpeg4';
1509
+ $MatroskaCodecIDlist['V_MPEG4/ISO/ASP'] = 'mpeg4';
1510
+ $MatroskaCodecIDlist['V_MPEG4/ISO/AVC'] = 'h264';
1511
+ $MatroskaCodecIDlist['V_MPEG4/ISO/SP'] = 'mpeg4';
1512
+ }
1513
+ return (isset($MatroskaCodecIDlist[$codecid]) ? $MatroskaCodecIDlist[$codecid] : $codecid);
1514
+ }
1515
+
1516
+ function EBMLidName($value) {
1517
+ static $EBMLidList = array();
1518
+ if (empty($EBMLidList)) {
1519
+ $EBMLidList[EBML_ID_ASPECTRATIOTYPE] = 'AspectRatioType';
1520
+ $EBMLidList[EBML_ID_ATTACHEDFILE] = 'AttachedFile';
1521
+ $EBMLidList[EBML_ID_ATTACHMENTLINK] = 'AttachmentLink';
1522
+ $EBMLidList[EBML_ID_ATTACHMENTS] = 'Attachments';
1523
+ $EBMLidList[EBML_ID_ATTACHMENTUID] = 'AttachmentUID';
1524
+ $EBMLidList[EBML_ID_AUDIO] = 'Audio';
1525
+ $EBMLidList[EBML_ID_BITDEPTH] = 'BitDepth';
1526
+ $EBMLidList[EBML_ID_CHANNELPOSITIONS] = 'ChannelPositions';
1527
+ $EBMLidList[EBML_ID_CHANNELS] = 'Channels';
1528
+ $EBMLidList[EBML_ID_CHAPCOUNTRY] = 'ChapCountry';
1529
+ $EBMLidList[EBML_ID_CHAPLANGUAGE] = 'ChapLanguage';
1530
+ $EBMLidList[EBML_ID_CHAPPROCESS] = 'ChapProcess';
1531
+ $EBMLidList[EBML_ID_CHAPPROCESSCODECID] = 'ChapProcessCodecID';
1532
+ $EBMLidList[EBML_ID_CHAPPROCESSCOMMAND] = 'ChapProcessCommand';
1533
+ $EBMLidList[EBML_ID_CHAPPROCESSDATA] = 'ChapProcessData';
1534
+ $EBMLidList[EBML_ID_CHAPPROCESSPRIVATE] = 'ChapProcessPrivate';
1535
+ $EBMLidList[EBML_ID_CHAPPROCESSTIME] = 'ChapProcessTime';
1536
+ $EBMLidList[EBML_ID_CHAPSTRING] = 'ChapString';
1537
+ $EBMLidList[EBML_ID_CHAPTERATOM] = 'ChapterAtom';
1538
+ $EBMLidList[EBML_ID_CHAPTERDISPLAY] = 'ChapterDisplay';
1539
+ $EBMLidList[EBML_ID_CHAPTERFLAGENABLED] = 'ChapterFlagEnabled';
1540
+ $EBMLidList[EBML_ID_CHAPTERFLAGHIDDEN] = 'ChapterFlagHidden';
1541
+ $EBMLidList[EBML_ID_CHAPTERPHYSICALEQUIV] = 'ChapterPhysicalEquiv';
1542
+ $EBMLidList[EBML_ID_CHAPTERS] = 'Chapters';
1543
+ $EBMLidList[EBML_ID_CHAPTERSEGMENTEDITIONUID] = 'ChapterSegmentEditionUID';
1544
+ $EBMLidList[EBML_ID_CHAPTERSEGMENTUID] = 'ChapterSegmentUID';
1545
+ $EBMLidList[EBML_ID_CHAPTERTIMEEND] = 'ChapterTimeEnd';
1546
+ $EBMLidList[EBML_ID_CHAPTERTIMESTART] = 'ChapterTimeStart';
1547
+ $EBMLidList[EBML_ID_CHAPTERTRACK] = 'ChapterTrack';
1548
+ $EBMLidList[EBML_ID_CHAPTERTRACKNUMBER] = 'ChapterTrackNumber';
1549
+ $EBMLidList[EBML_ID_CHAPTERTRANSLATE] = 'ChapterTranslate';
1550
+ $EBMLidList[EBML_ID_CHAPTERTRANSLATECODEC] = 'ChapterTranslateCodec';
1551
+ $EBMLidList[EBML_ID_CHAPTERTRANSLATEEDITIONUID] = 'ChapterTranslateEditionUID';
1552
+ $EBMLidList[EBML_ID_CHAPTERTRANSLATEID] = 'ChapterTranslateID';
1553
+ $EBMLidList[EBML_ID_CHAPTERUID] = 'ChapterUID';
1554
+ $EBMLidList[EBML_ID_CLUSTER] = 'Cluster';
1555
+ $EBMLidList[EBML_ID_CLUSTERBLOCK] = 'ClusterBlock';
1556
+ $EBMLidList[EBML_ID_CLUSTERBLOCKADDID] = 'ClusterBlockAddID';
1557
+ $EBMLidList[EBML_ID_CLUSTERBLOCKADDITIONAL] = 'ClusterBlockAdditional';
1558
+ $EBMLidList[EBML_ID_CLUSTERBLOCKADDITIONID] = 'ClusterBlockAdditionID';
1559
+ $EBMLidList[EBML_ID_CLUSTERBLOCKADDITIONS] = 'ClusterBlockAdditions';
1560
+ $EBMLidList[EBML_ID_CLUSTERBLOCKDURATION] = 'ClusterBlockDuration';
1561
+ $EBMLidList[EBML_ID_CLUSTERBLOCKGROUP] = 'ClusterBlockGroup';
1562
+ $EBMLidList[EBML_ID_CLUSTERBLOCKMORE] = 'ClusterBlockMore';
1563
+ $EBMLidList[EBML_ID_CLUSTERBLOCKVIRTUAL] = 'ClusterBlockVirtual';
1564
+ $EBMLidList[EBML_ID_CLUSTERCODECSTATE] = 'ClusterCodecState';
1565
+ $EBMLidList[EBML_ID_CLUSTERDELAY] = 'ClusterDelay';
1566
+ $EBMLidList[EBML_ID_CLUSTERDURATION] = 'ClusterDuration';
1567
+ $EBMLidList[EBML_ID_CLUSTERENCRYPTEDBLOCK] = 'ClusterEncryptedBlock';
1568
+ $EBMLidList[EBML_ID_CLUSTERFRAMENUMBER] = 'ClusterFrameNumber';
1569
+ $EBMLidList[EBML_ID_CLUSTERLACENUMBER] = 'ClusterLaceNumber';
1570
+ $EBMLidList[EBML_ID_CLUSTERPOSITION] = 'ClusterPosition';
1571
+ $EBMLidList[EBML_ID_CLUSTERPREVSIZE] = 'ClusterPrevSize';
1572
+ $EBMLidList[EBML_ID_CLUSTERREFERENCEBLOCK] = 'ClusterReferenceBlock';
1573
+ $EBMLidList[EBML_ID_CLUSTERREFERENCEPRIORITY] = 'ClusterReferencePriority';
1574
+ $EBMLidList[EBML_ID_CLUSTERREFERENCEVIRTUAL] = 'ClusterReferenceVirtual';
1575
+ $EBMLidList[EBML_ID_CLUSTERSILENTTRACKNUMBER] = 'ClusterSilentTrackNumber';
1576
+ $EBMLidList[EBML_ID_CLUSTERSILENTTRACKS] = 'ClusterSilentTracks';
1577
+ $EBMLidList[EBML_ID_CLUSTERSIMPLEBLOCK] = 'ClusterSimpleBlock';
1578
+ $EBMLidList[EBML_ID_CLUSTERTIMECODE] = 'ClusterTimecode';
1579
+ $EBMLidList[EBML_ID_CLUSTERTIMESLICE] = 'ClusterTimeSlice';
1580
+ $EBMLidList[EBML_ID_CODECDECODEALL] = 'CodecDecodeAll';
1581
+ $EBMLidList[EBML_ID_CODECDOWNLOADURL] = 'CodecDownloadURL';
1582
+ $EBMLidList[EBML_ID_CODECID] = 'CodecID';
1583
+ $EBMLidList[EBML_ID_CODECINFOURL] = 'CodecInfoURL';
1584
+ $EBMLidList[EBML_ID_CODECNAME] = 'CodecName';
1585
+ $EBMLidList[EBML_ID_CODECPRIVATE] = 'CodecPrivate';
1586
+ $EBMLidList[EBML_ID_CODECSETTINGS] = 'CodecSettings';
1587
+ $EBMLidList[EBML_ID_COLOURSPACE] = 'ColourSpace';
1588
+ $EBMLidList[EBML_ID_CONTENTCOMPALGO] = 'ContentCompAlgo';
1589
+ $EBMLidList[EBML_ID_CONTENTCOMPRESSION] = 'ContentCompression';
1590
+ $EBMLidList[EBML_ID_CONTENTCOMPSETTINGS] = 'ContentCompSettings';
1591
+ $EBMLidList[EBML_ID_CONTENTENCALGO] = 'ContentEncAlgo';
1592
+ $EBMLidList[EBML_ID_CONTENTENCKEYID] = 'ContentEncKeyID';
1593
+ $EBMLidList[EBML_ID_CONTENTENCODING] = 'ContentEncoding';
1594
+ $EBMLidList[EBML_ID_CONTENTENCODINGORDER] = 'ContentEncodingOrder';
1595
+ $EBMLidList[EBML_ID_CONTENTENCODINGS] = 'ContentEncodings';
1596
+ $EBMLidList[EBML_ID_CONTENTENCODINGSCOPE] = 'ContentEncodingScope';
1597
+ $EBMLidList[EBML_ID_CONTENTENCODINGTYPE] = 'ContentEncodingType';
1598
+ $EBMLidList[EBML_ID_CONTENTENCRYPTION] = 'ContentEncryption';
1599
+ $EBMLidList[EBML_ID_CONTENTSIGALGO] = 'ContentSigAlgo';
1600
+ $EBMLidList[EBML_ID_CONTENTSIGHASHALGO] = 'ContentSigHashAlgo';
1601
+ $EBMLidList[EBML_ID_CONTENTSIGKEYID] = 'ContentSigKeyID';
1602
+ $EBMLidList[EBML_ID_CONTENTSIGNATURE] = 'ContentSignature';
1603
+ $EBMLidList[EBML_ID_CRC32] = 'CRC32';
1604
+ $EBMLidList[EBML_ID_CUEBLOCKNUMBER] = 'CueBlockNumber';
1605
+ $EBMLidList[EBML_ID_CUECLUSTERPOSITION] = 'CueClusterPosition';
1606
+ $EBMLidList[EBML_ID_CUECODECSTATE] = 'CueCodecState';
1607
+ $EBMLidList[EBML_ID_CUEPOINT] = 'CuePoint';
1608
+ $EBMLidList[EBML_ID_CUEREFCLUSTER] = 'CueRefCluster';
1609
+ $EBMLidList[EBML_ID_CUEREFCODECSTATE] = 'CueRefCodecState';
1610
+ $EBMLidList[EBML_ID_CUEREFERENCE] = 'CueReference';
1611
+ $EBMLidList[EBML_ID_CUEREFNUMBER] = 'CueRefNumber';
1612
+ $EBMLidList[EBML_ID_CUEREFTIME] = 'CueRefTime';
1613
+ $EBMLidList[EBML_ID_CUES] = 'Cues';
1614
+ $EBMLidList[EBML_ID_CUETIME] = 'CueTime';
1615
+ $EBMLidList[EBML_ID_CUETRACK] = 'CueTrack';
1616
+ $EBMLidList[EBML_ID_CUETRACKPOSITIONS] = 'CueTrackPositions';
1617
+ $EBMLidList[EBML_ID_DATEUTC] = 'DateUTC';
1618
+ $EBMLidList[EBML_ID_DEFAULTDURATION] = 'DefaultDuration';
1619
+ $EBMLidList[EBML_ID_DISPLAYHEIGHT] = 'DisplayHeight';
1620
+ $EBMLidList[EBML_ID_DISPLAYUNIT] = 'DisplayUnit';
1621
+ $EBMLidList[EBML_ID_DISPLAYWIDTH] = 'DisplayWidth';
1622
+ $EBMLidList[EBML_ID_DOCTYPE] = 'DocType';
1623
+ $EBMLidList[EBML_ID_DOCTYPEREADVERSION] = 'DocTypeReadVersion';
1624
+ $EBMLidList[EBML_ID_DOCTYPEVERSION] = 'DocTypeVersion';
1625
+ $EBMLidList[EBML_ID_DURATION] = 'Duration';
1626
+ $EBMLidList[EBML_ID_EBMLMAXIDLENGTH] = 'EBMLMaxIDLength';
1627
+ $EBMLidList[EBML_ID_EBMLMAXSIZELENGTH] = 'EBMLMaxSizeLength';
1628
+ $EBMLidList[EBML_ID_EBMLREADVERSION] = 'EBMLReadVersion';
1629
+ $EBMLidList[EBML_ID_EBMLVERSION] = 'EBMLVersion';
1630
+ $EBMLidList[EBML_ID_EDITIONENTRY] = 'EditionEntry';
1631
+ $EBMLidList[EBML_ID_EDITIONFLAGDEFAULT] = 'EditionFlagDefault';
1632
+ $EBMLidList[EBML_ID_EDITIONFLAGHIDDEN] = 'EditionFlagHidden';
1633
+ $EBMLidList[EBML_ID_EDITIONFLAGORDERED] = 'EditionFlagOrdered';
1634
+ $EBMLidList[EBML_ID_EDITIONUID] = 'EditionUID';
1635
+ $EBMLidList[EBML_ID_FILEDATA] = 'FileData';
1636
+ $EBMLidList[EBML_ID_FILEDESCRIPTION] = 'FileDescription';
1637
+ $EBMLidList[EBML_ID_FILEMIMETYPE] = 'FileMimeType';
1638
+ $EBMLidList[EBML_ID_FILENAME] = 'FileName';
1639
+ $EBMLidList[EBML_ID_FILEREFERRAL] = 'FileReferral';
1640
+ $EBMLidList[EBML_ID_FILEUID] = 'FileUID';
1641
+ $EBMLidList[EBML_ID_FLAGDEFAULT] = 'FlagDefault';
1642
+ $EBMLidList[EBML_ID_FLAGENABLED] = 'FlagEnabled';
1643
+ $EBMLidList[EBML_ID_FLAGFORCED] = 'FlagForced';
1644
+ $EBMLidList[EBML_ID_FLAGINTERLACED] = 'FlagInterlaced';
1645
+ $EBMLidList[EBML_ID_FLAGLACING] = 'FlagLacing';
1646
+ $EBMLidList[EBML_ID_GAMMAVALUE] = 'GammaValue';
1647
+ $EBMLidList[EBML_ID_INFO] = 'Info';
1648
+ $EBMLidList[EBML_ID_LANGUAGE] = 'Language';
1649
+ $EBMLidList[EBML_ID_MAXBLOCKADDITIONID] = 'MaxBlockAdditionID';
1650
+ $EBMLidList[EBML_ID_MAXCACHE] = 'MaxCache';
1651
+ $EBMLidList[EBML_ID_MINCACHE] = 'MinCache';
1652
+ $EBMLidList[EBML_ID_MUXINGAPP] = 'MuxingApp';
1653
+ $EBMLidList[EBML_ID_NAME] = 'Name';
1654
+ $EBMLidList[EBML_ID_NEXTFILENAME] = 'NextFilename';
1655
+ $EBMLidList[EBML_ID_NEXTUID] = 'NextUID';
1656
+ $EBMLidList[EBML_ID_OUTPUTSAMPLINGFREQUENCY] = 'OutputSamplingFrequency';
1657
+ $EBMLidList[EBML_ID_PIXELCROPBOTTOM] = 'PixelCropBottom';
1658
+ $EBMLidList[EBML_ID_PIXELCROPLEFT] = 'PixelCropLeft';
1659
+ $EBMLidList[EBML_ID_PIXELCROPRIGHT] = 'PixelCropRight';
1660
+ $EBMLidList[EBML_ID_PIXELCROPTOP] = 'PixelCropTop';
1661
+ $EBMLidList[EBML_ID_PIXELHEIGHT] = 'PixelHeight';
1662
+ $EBMLidList[EBML_ID_PIXELWIDTH] = 'PixelWidth';
1663
+ $EBMLidList[EBML_ID_PREVFILENAME] = 'PrevFilename';
1664
+ $EBMLidList[EBML_ID_PREVUID] = 'PrevUID';
1665
+ $EBMLidList[EBML_ID_SAMPLINGFREQUENCY] = 'SamplingFrequency';
1666
+ $EBMLidList[EBML_ID_SEEK] = 'Seek';
1667
+ $EBMLidList[EBML_ID_SEEKHEAD] = 'SeekHead';
1668
+ $EBMLidList[EBML_ID_SEEKID] = 'SeekID';
1669
+ $EBMLidList[EBML_ID_SEEKPOSITION] = 'SeekPosition';
1670
+ $EBMLidList[EBML_ID_SEGMENTFAMILY] = 'SegmentFamily';
1671
+ $EBMLidList[EBML_ID_SEGMENTFILENAME] = 'SegmentFilename';
1672
+ $EBMLidList[EBML_ID_SEGMENTUID] = 'SegmentUID';
1673
+ $EBMLidList[EBML_ID_SIMPLETAG] = 'SimpleTag';
1674
+ $EBMLidList[EBML_ID_CLUSTERSLICES] = 'ClusterSlices';
1675
+ $EBMLidList[EBML_ID_STEREOMODE] = 'StereoMode';
1676
+ $EBMLidList[EBML_ID_TAG] = 'Tag';
1677
+ $EBMLidList[EBML_ID_TAGBINARY] = 'TagBinary';
1678
+ $EBMLidList[EBML_ID_TAGCHAPTERUID] = 'TagChapterUID';
1679
+ $EBMLidList[EBML_ID_TAGDEFAULT] = 'TagDefault';
1680
+ $EBMLidList[EBML_ID_TAGEDITIONUID] = 'TagEditionUID';
1681
+ $EBMLidList[EBML_ID_TAGLANGUAGE] = 'TagLanguage';
1682
+ $EBMLidList[EBML_ID_TAGNAME] = 'TagName';
1683
+ $EBMLidList[EBML_ID_TAGTRACKUID] = 'TagTrackUID';
1684
+ $EBMLidList[EBML_ID_TAGS] = 'Tags';
1685
+ $EBMLidList[EBML_ID_TAGSTRING] = 'TagString';
1686
+ $EBMLidList[EBML_ID_TARGETS] = 'Targets';
1687
+ $EBMLidList[EBML_ID_TARGETTYPE] = 'TargetType';
1688
+ $EBMLidList[EBML_ID_TARGETTYPEVALUE] = 'TargetTypeValue';
1689
+ $EBMLidList[EBML_ID_TIMECODESCALE] = 'TimecodeScale';
1690
+ $EBMLidList[EBML_ID_TITLE] = 'Title';
1691
+ $EBMLidList[EBML_ID_TRACKENTRY] = 'TrackEntry';
1692
+ $EBMLidList[EBML_ID_TRACKNUMBER] = 'TrackNumber';
1693
+ $EBMLidList[EBML_ID_TRACKOFFSET] = 'TrackOffset';
1694
+ $EBMLidList[EBML_ID_TRACKOVERLAY] = 'TrackOverlay';
1695
+ $EBMLidList[EBML_ID_TRACKS] = 'Tracks';
1696
+ $EBMLidList[EBML_ID_TRACKTIMECODESCALE] = 'TrackTimecodeScale';
1697
+ $EBMLidList[EBML_ID_TRACKTRANSLATE] = 'TrackTranslate';
1698
+ $EBMLidList[EBML_ID_TRACKTRANSLATECODEC] = 'TrackTranslateCodec';
1699
+ $EBMLidList[EBML_ID_TRACKTRANSLATEEDITIONUID] = 'TrackTranslateEditionUID';
1700
+ $EBMLidList[EBML_ID_TRACKTRANSLATETRACKID] = 'TrackTranslateTrackID';
1701
+ $EBMLidList[EBML_ID_TRACKTYPE] = 'TrackType';
1702
+ $EBMLidList[EBML_ID_TRACKUID] = 'TrackUID';
1703
+ $EBMLidList[EBML_ID_VIDEO] = 'Video';
1704
+ $EBMLidList[EBML_ID_VOID] = 'Void';
1705
+ $EBMLidList[EBML_ID_WRITINGAPP] = 'WritingApp';
1706
+ }
1707
+ return (isset($EBMLidList[$value]) ? $EBMLidList[$value] : dechex($value));
1708
+ }
1709
+
1710
+ }
1711
+
1712
+ ?>
view/getid3/module.audio-video.mpeg.php ADDED
@@ -0,0 +1,292 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /////////////////////////////////////////////////////////////////
3
+ /// getID3() by James Heinrich <info@getid3.org> //
4
+ // available at http://getid3.sourceforge.net //
5
+ // or http://www.getid3.org //
6
+ /////////////////////////////////////////////////////////////////
7
+ // See readme.txt for more details //
8
+ /////////////////////////////////////////////////////////////////
9
+ // //
10
+ // module.audio-video.mpeg.php //
11
+ // module for analyzing MPEG files //
12
+ // dependencies: module.audio.mp3.php //
13
+ // ///
14
+ /////////////////////////////////////////////////////////////////
15
+
16
+ getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.mp3.php', __FILE__, true);
17
+
18
+ define('GETID3_MPEG_VIDEO_PICTURE_START', "\x00\x00\x01\x00");
19
+ define('GETID3_MPEG_VIDEO_USER_DATA_START', "\x00\x00\x01\xB2");
20
+ define('GETID3_MPEG_VIDEO_SEQUENCE_HEADER', "\x00\x00\x01\xB3");
21
+ define('GETID3_MPEG_VIDEO_SEQUENCE_ERROR', "\x00\x00\x01\xB4");
22
+ define('GETID3_MPEG_VIDEO_EXTENSION_START', "\x00\x00\x01\xB5");
23
+ define('GETID3_MPEG_VIDEO_SEQUENCE_END', "\x00\x00\x01\xB7");
24
+ define('GETID3_MPEG_VIDEO_GROUP_START', "\x00\x00\x01\xB8");
25
+ define('GETID3_MPEG_AUDIO_START', "\x00\x00\x01\xC0");
26
+
27
+
28
+ class getid3_mpeg
29
+ {
30
+
31
+ function getid3_mpeg(&$fd, &$ThisFileInfo) {
32
+ if ($ThisFileInfo['avdataend'] <= $ThisFileInfo['avdataoffset']) {
33
+ $ThisFileInfo['error'][] = '"avdataend" ('.$ThisFileInfo['avdataend'].') is unexpectedly less-than-or-equal-to "avdataoffset" ('.$ThisFileInfo['avdataoffset'].')';
34
+ return false;
35
+ }
36
+ $ThisFileInfo['fileformat'] = 'mpeg';
37
+ fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
38
+ $MPEGstreamData = fread($fd, min(100000, $ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']));
39
+ $MPEGstreamDataLength = strlen($MPEGstreamData);
40
+
41
+ $foundVideo = true;
42
+ $VideoChunkOffset = 0;
43
+ while (substr($MPEGstreamData, $VideoChunkOffset++, 4) !== GETID3_MPEG_VIDEO_SEQUENCE_HEADER) {
44
+ if ($VideoChunkOffset >= $MPEGstreamDataLength) {
45
+ $foundVideo = false;
46
+ break;
47
+ }
48
+ }
49
+ if ($foundVideo) {
50
+
51
+ // Start code 32 bits
52
+ // horizontal frame size 12 bits
53
+ // vertical frame size 12 bits
54
+ // pixel aspect ratio 4 bits
55
+ // frame rate 4 bits
56
+ // bitrate 18 bits
57
+ // marker bit 1 bit
58
+ // VBV buffer size 10 bits
59
+ // constrained parameter flag 1 bit
60
+ // intra quant. matrix flag 1 bit
61
+ // intra quant. matrix values 512 bits (present if matrix flag == 1)
62
+ // non-intra quant. matrix flag 1 bit
63
+ // non-intra quant. matrix values 512 bits (present if matrix flag == 1)
64
+
65
+ $ThisFileInfo['video']['dataformat'] = 'mpeg';
66
+
67
+ $VideoChunkOffset += (strlen(GETID3_MPEG_VIDEO_SEQUENCE_HEADER) - 1);
68
+
69
+ $FrameSizeDWORD = getid3_lib::BigEndian2Int(substr($MPEGstreamData, $VideoChunkOffset, 3));
70
+ $VideoChunkOffset += 3;
71
+
72
+ $AspectRatioFrameRateDWORD = getid3_lib::BigEndian2Int(substr($MPEGstreamData, $VideoChunkOffset, 1));
73
+ $VideoChunkOffset += 1;
74
+
75
+ $assortedinformation = getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $VideoChunkOffset, 4));
76
+ $VideoChunkOffset += 4;
77
+
78
+ $ThisFileInfo['mpeg']['video']['raw']['framesize_horizontal'] = ($FrameSizeDWORD & 0xFFF000) >> 12; // 12 bits for horizontal frame size
79
+ $ThisFileInfo['mpeg']['video']['raw']['framesize_vertical'] = ($FrameSizeDWORD & 0x000FFF); // 12 bits for vertical frame size
80
+ $ThisFileInfo['mpeg']['video']['raw']['pixel_aspect_ratio'] = ($AspectRatioFrameRateDWORD & 0xF0) >> 4;
81
+ $ThisFileInfo['mpeg']['video']['raw']['frame_rate'] = ($AspectRatioFrameRateDWORD & 0x0F);
82
+
83
+ $ThisFileInfo['mpeg']['video']['framesize_horizontal'] = $ThisFileInfo['mpeg']['video']['raw']['framesize_horizontal'];
84
+ $ThisFileInfo['mpeg']['video']['framesize_vertical'] = $ThisFileInfo['mpeg']['video']['raw']['framesize_vertical'];
85
+
86
+ $ThisFileInfo['mpeg']['video']['pixel_aspect_ratio'] = $this->MPEGvideoAspectRatioLookup($ThisFileInfo['mpeg']['video']['raw']['pixel_aspect_ratio']);
87
+ $ThisFileInfo['mpeg']['video']['pixel_aspect_ratio_text'] = $this->MPEGvideoAspectRatioTextLookup($ThisFileInfo['mpeg']['video']['raw']['pixel_aspect_ratio']);
88
+ $ThisFileInfo['mpeg']['video']['frame_rate'] = $this->MPEGvideoFramerateLookup($ThisFileInfo['mpeg']['video']['raw']['frame_rate']);
89
+
90
+ $ThisFileInfo['mpeg']['video']['raw']['bitrate'] = getid3_lib::Bin2Dec(substr($assortedinformation, 0, 18));
91
+ $ThisFileInfo['mpeg']['video']['raw']['marker_bit'] = (bool) getid3_lib::Bin2Dec(substr($assortedinformation, 18, 1));
92
+ $ThisFileInfo['mpeg']['video']['raw']['vbv_buffer_size'] = getid3_lib::Bin2Dec(substr($assortedinformation, 19, 10));
93
+ $ThisFileInfo['mpeg']['video']['raw']['constrained_param_flag'] = (bool) getid3_lib::Bin2Dec(substr($assortedinformation, 29, 1));
94
+ $ThisFileInfo['mpeg']['video']['raw']['intra_quant_flag'] = (bool) getid3_lib::Bin2Dec(substr($assortedinformation, 30, 1));
95
+ if ($ThisFileInfo['mpeg']['video']['raw']['intra_quant_flag']) {
96
+
97
+ // read 512 bits
98
+ $ThisFileInfo['mpeg']['video']['raw']['intra_quant'] = getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $VideoChunkOffset, 64));
99
+ $VideoChunkOffset += 64;
100
+
101
+ $ThisFileInfo['mpeg']['video']['raw']['non_intra_quant_flag'] = (bool) getid3_lib::Bin2Dec(substr($ThisFileInfo['mpeg']['video']['raw']['intra_quant'], 511, 1));
102
+ $ThisFileInfo['mpeg']['video']['raw']['intra_quant'] = getid3_lib::Bin2Dec(substr($assortedinformation, 31, 1)).substr(getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $VideoChunkOffset, 64)), 0, 511);
103
+
104
+ if ($ThisFileInfo['mpeg']['video']['raw']['non_intra_quant_flag']) {
105
+ $ThisFileInfo['mpeg']['video']['raw']['non_intra_quant'] = substr($MPEGstreamData, $VideoChunkOffset, 64);
106
+ $VideoChunkOffset += 64;
107
+ }
108
+
109
+ } else {
110
+
111
+ $ThisFileInfo['mpeg']['video']['raw']['non_intra_quant_flag'] = (bool) getid3_lib::Bin2Dec(substr($assortedinformation, 31, 1));
112
+ if ($ThisFileInfo['mpeg']['video']['raw']['non_intra_quant_flag']) {
113
+ $ThisFileInfo['mpeg']['video']['raw']['non_intra_quant'] = substr($MPEGstreamData, $VideoChunkOffset, 64);
114
+ $VideoChunkOffset += 64;
115
+ }
116
+
117
+ }
118
+
119
+ if ($ThisFileInfo['mpeg']['video']['raw']['bitrate'] == 0x3FFFF) { // 18 set bits
120
+
121
+ $ThisFileInfo['warning'][] = 'This version of getID3() ['.GETID3_VERSION.'] cannot determine average bitrate of VBR MPEG video files';
122
+ $ThisFileInfo['mpeg']['video']['bitrate_mode'] = 'vbr';
123
+
124
+ } else {
125
+
126
+ $ThisFileInfo['mpeg']['video']['bitrate'] = $ThisFileInfo['mpeg']['video']['raw']['bitrate'] * 400;
127
+ $ThisFileInfo['mpeg']['video']['bitrate_mode'] = 'cbr';
128
+ $ThisFileInfo['video']['bitrate'] = $ThisFileInfo['mpeg']['video']['bitrate'];
129
+
130
+ }
131
+
132
+ $ThisFileInfo['video']['resolution_x'] = $ThisFileInfo['mpeg']['video']['framesize_horizontal'];
133
+ $ThisFileInfo['video']['resolution_y'] = $ThisFileInfo['mpeg']['video']['framesize_vertical'];
134
+ $ThisFileInfo['video']['frame_rate'] = $ThisFileInfo['mpeg']['video']['frame_rate'];
135
+ $ThisFileInfo['video']['bitrate_mode'] = $ThisFileInfo['mpeg']['video']['bitrate_mode'];
136
+ $ThisFileInfo['video']['pixel_aspect_ratio'] = $ThisFileInfo['mpeg']['video']['pixel_aspect_ratio'];
137
+ $ThisFileInfo['video']['lossless'] = false;
138
+ $ThisFileInfo['video']['bits_per_sample'] = 24;
139
+
140
+ } else {
141
+
142
+ $ThisFileInfo['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?';
143
+
144
+ }
145
+
146
+ //0x000001B3 begins the sequence_header of every MPEG video stream.
147
+ //But in MPEG-2, this header must immediately be followed by an
148
+ //extension_start_code (0x000001B5) with a sequence_extension ID (1).
149
+ //(This extension contains all the additional MPEG-2 stuff.)
150
+ //MPEG-1 doesn't have this extension, so that's a sure way to tell the
151
+ //difference between MPEG-1 and MPEG-2 video streams.
152
+
153
+ if (substr($MPEGstreamData, $VideoChunkOffset, 4) == GETID3_MPEG_VIDEO_EXTENSION_START) {
154
+ $ThisFileInfo['video']['codec'] = 'MPEG-2';
155
+ } else {
156
+ $ThisFileInfo['video']['codec'] = 'MPEG-1';
157
+ }
158
+
159
+
160
+ $AudioChunkOffset = 0;
161
+ while (true) {
162
+ while (substr($MPEGstreamData, $AudioChunkOffset++, 4) !== GETID3_MPEG_AUDIO_START) {
163
+ if ($AudioChunkOffset >= $MPEGstreamDataLength) {
164
+ break 2;
165
+ }
166
+ }
167
+
168
+ for ($i = 0; $i <= 7; $i++) {
169
+ // 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
170
+ // I have no idea why or what the difference is, so this is a stupid hack.
171
+ // If anybody has any better idea of what's going on, please let me know - info@getid3.org
172
+
173
+ $dummy = $ThisFileInfo;
174
+ if (getid3_mp3::decodeMPEGaudioHeader($fd, ($AudioChunkOffset + 3) + 8 + $i, $dummy, false)) {
175
+ $ThisFileInfo = $dummy;
176
+ $ThisFileInfo['audio']['bitrate_mode'] = 'cbr';
177
+ $ThisFileInfo['audio']['lossless'] = false;
178
+ break 2;
179
+
180
+ }
181
+ }
182
+ }
183
+
184
+ // Temporary hack to account for interleaving overhead:
185
+ if (!empty($ThisFileInfo['video']['bitrate']) && !empty($ThisFileInfo['audio']['bitrate'])) {
186
+ $ThisFileInfo['playtime_seconds'] = (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8) / ($ThisFileInfo['video']['bitrate'] + $ThisFileInfo['audio']['bitrate']);
187
+
188
+ // Interleaved MPEG audio/video files have a certain amount of overhead that varies
189
+ // by both video and audio bitrates, and not in any sensible, linear/logarithmic patter
190
+ // Use interpolated lookup tables to approximately guess how much is overhead, because
191
+ // playtime is calculated as filesize / total-bitrate
192
+ $ThisFileInfo['playtime_seconds'] *= $this->MPEGsystemNonOverheadPercentage($ThisFileInfo['video']['bitrate'], $ThisFileInfo['audio']['bitrate']);
193
+
194
+ //switch ($ThisFileInfo['video']['bitrate']) {
195
+ // case('5000000'):
196
+ // $multiplier = 0.93292642112380355828048824319889;
197
+ // break;
198
+ // case('5500000'):
199
+ // $multiplier = 0.93582895375200989965359777343219;
200
+ // break;
201
+ // case('6000000'):
202
+ // $multiplier = 0.93796247714820932532911373859139;
203
+ // break;
204
+ // case('7000000'):
205
+ // $multiplier = 0.9413264083635103463010117778776;
206
+ // break;
207
+ // default:
208
+ // $multiplier = 1;
209
+ // break;
210
+ //}
211
+ //$ThisFileInfo['playtime_seconds'] *= $multiplier;
212
+ //$ThisFileInfo['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.';
213
+ if ($ThisFileInfo['video']['bitrate'] < 50000) {
214
+ $ThisFileInfo['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.';
215
+ }
216
+ }
217
+
218
+ return true;
219
+ }
220
+
221
+
222
+ function MPEGsystemNonOverheadPercentage($VideoBitrate, $AudioBitrate) {
223
+ $OverheadPercentage = 0;
224
+
225
+ $AudioBitrate = max(min($AudioBitrate / 1000, 384), 32); // limit to range of 32kbps - 384kbps (should be only legal bitrates, but maybe VBR?)
226
+ $VideoBitrate = max(min($VideoBitrate / 1000, 10000), 10); // limit to range of 10kbps - 10Mbps (beyond that curves flatten anyways, no big loss)
227
+
228
+
229
+ //OMBB[audiobitrate] = array(video-10kbps, video-100kbps, video-1000kbps, video-10000kbps)
230
+ $OverheadMultiplierByBitrate[32] = array(0, 0.9676287944368530, 0.9802276264360310, 0.9844916183244460, 0.9852821845179940);
231
+ $OverheadMultiplierByBitrate[48] = array(0, 0.9779100089209830, 0.9787770035359320, 0.9846738664076130, 0.9852683013799960);
232
+ $OverheadMultiplierByBitrate[56] = array(0, 0.9731249855367600, 0.9776624308938040, 0.9832606361852130, 0.9843922606633340);
233
+ $OverheadMultiplierByBitrate[64] = array(0, 0.9755642683275760, 0.9795256705493390, 0.9836573009193170, 0.9851122539404470);
234
+ $OverheadMultiplierByBitrate[96] = array(0, 0.9788025247497290, 0.9798553314148700, 0.9822956869792560, 0.9834815119124690);
235
+ $OverheadMultiplierByBitrate[128] = array(0, 0.9816940050925480, 0.9821675936072120, 0.9829756927470870, 0.9839763420152050);
236
+ $OverheadMultiplierByBitrate[160] = array(0, 0.9825894094561180, 0.9820913399073960, 0.9823907143253970, 0.9832821783651570);
237
+ $OverheadMultiplierByBitrate[192] = array(0, 0.9832038474336260, 0.9825731694317960, 0.9821028622712400, 0.9828262076447620);
238
+ $OverheadMultiplierByBitrate[224] = array(0, 0.9836516298538770, 0.9824718601823890, 0.9818302180625380, 0.9823735101626480);
239
+ $OverheadMultiplierByBitrate[256] = array(0, 0.9845863022094920, 0.9837229411967540, 0.9824521662210830, 0.9828645172100790);
240
+ $OverheadMultiplierByBitrate[320] = array(0, 0.9849565280263180, 0.9837683142805110, 0.9822885275960400, 0.9824424382727190);
241
+ $OverheadMultiplierByBitrate[384] = array(0, 0.9856094774357600, 0.9844573394432720, 0.9825970399837330, 0.9824673808303890);
242
+
243
+ $BitrateToUseMin = 32;
244
+ $BitrateToUseMax = 32;
245
+ $previousBitrate = 32;
246
+ foreach ($OverheadMultiplierByBitrate as $key => $value) {
247
+ if ($AudioBitrate >= $previousBitrate) {
248
+ $BitrateToUseMin = $previousBitrate;
249
+ }
250
+ if ($AudioBitrate < $key) {
251
+ $BitrateToUseMax = $key;
252
+ break;
253
+ }
254
+ $previousBitrate = $key;
255
+ }
256
+ $FactorA = ($BitrateToUseMax - $AudioBitrate) / ($BitrateToUseMax - $BitrateToUseMin);
257
+
258
+ $VideoBitrateLog10 = log10($VideoBitrate);
259
+ $VideoFactorMin1 = $OverheadMultiplierByBitrate[$BitrateToUseMin][floor($VideoBitrateLog10)];
260
+ $VideoFactorMin2 = $OverheadMultiplierByBitrate[$BitrateToUseMax][floor($VideoBitrateLog10)];
261
+ $VideoFactorMax1 = $OverheadMultiplierByBitrate[$BitrateToUseMin][ceil($VideoBitrateLog10)];
262
+ $VideoFactorMax2 = $OverheadMultiplierByBitrate[$BitrateToUseMax][ceil($VideoBitrateLog10)];
263
+ $FactorV = $VideoBitrateLog10 - floor($VideoBitrateLog10);
264
+
265
+ $OverheadPercentage = $VideoFactorMin1 * $FactorA * $FactorV;
266
+ $OverheadPercentage += $VideoFactorMin2 * (1 - $FactorA) * $FactorV;
267
+ $OverheadPercentage += $VideoFactorMax1 * $FactorA * (1 - $FactorV);
268
+ $OverheadPercentage += $VideoFactorMax2 * (1 - $FactorA) * (1 - $FactorV);
269
+
270
+ return $OverheadPercentage;
271
+ }
272
+
273
+
274
+ function MPEGvideoFramerateLookup($rawframerate) {
275
+ $MPEGvideoFramerateLookup = array(0, 23.976, 24, 25, 29.97, 30, 50, 59.94, 60);
276
+ return (isset($MPEGvideoFramerateLookup[$rawframerate]) ? (float) $MPEGvideoFramerateLookup[$rawframerate] : (float) 0);
277
+ }
278
+
279
+ function MPEGvideoAspectRatioLookup($rawaspectratio) {
280
+ $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);
281
+ return (isset($MPEGvideoAspectRatioLookup[$rawaspectratio]) ? (float) $MPEGvideoAspectRatioLookup[$rawaspectratio] : (float) 0);
282
+ }
283
+
284
+ function MPEGvideoAspectRatioTextLookup($rawaspectratio) {
285
+ $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');
286
+ return (isset($MPEGvideoAspectRatioTextLookup[$rawaspectratio]) ? $MPEGvideoAspectRatioTextLookup[$rawaspectratio] : '');
287
+ }
288
+
289
+ }
290
+
291
+
292
+ ?>
view/getid3/module.audio-video.nsv.php ADDED
@@ -0,0 +1,224 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /////////////////////////////////////////////////////////////////
3
+ /// getID3() by James Heinrich <info@getid3.org> //
4
+ // available at http://getid3.sourceforge.net //
5
+ // or http://www.getid3.org //
6
+ /////////////////////////////////////////////////////////////////
7
+ // See readme.txt for more details //
8
+ /////////////////////////////////////////////////////////////////
9
+ // //
10
+ // module.audio.nsv.php //
11
+ // module for analyzing Nullsoft NSV files //
12
+ // dependencies: NONE //
13
+ // ///
14
+ /////////////////////////////////////////////////////////////////
15
+
16
+
17
+ class getid3_nsv
18
+ {
19
+
20
+ function getid3_nsv(&$fd, &$ThisFileInfo) {
21
+
22
+ fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
23
+ $NSVheader = fread($fd, 4);
24
+
25
+ switch ($NSVheader) {
26
+ case 'NSVs':
27
+ if ($this->getNSVsHeaderFilepointer($fd, $ThisFileInfo, 0)) {
28
+ $ThisFileInfo['fileformat'] = 'nsv';
29
+ $ThisFileInfo['audio']['dataformat'] = 'nsv';
30
+ $ThisFileInfo['video']['dataformat'] = 'nsv';
31
+ $ThisFileInfo['audio']['lossless'] = false;
32
+ $ThisFileInfo['video']['lossless'] = false;
33
+ }
34
+ break;
35
+
36
+ case 'NSVf':
37
+ if ($this->getNSVfHeaderFilepointer($fd, $ThisFileInfo, 0)) {
38
+ $ThisFileInfo['fileformat'] = 'nsv';
39
+ $ThisFileInfo['audio']['dataformat'] = 'nsv';
40
+ $ThisFileInfo['video']['dataformat'] = 'nsv';
41
+ $ThisFileInfo['audio']['lossless'] = false;
42
+ $ThisFileInfo['video']['lossless'] = false;
43
+ $this->getNSVsHeaderFilepointer($fd, $ThisFileInfo, $ThisFileInfo['nsv']['NSVf']['header_length']);
44
+ }
45
+ break;
46
+
47
+ default:
48
+ $ThisFileInfo['error'][] = 'Expecting "NSVs" or "NSVf" at offset '.$ThisFileInfo['avdataoffset'].', found "'.$NSVheader.'"';
49
+ return false;
50
+ break;
51
+ }
52
+
53
+ if (!isset($ThisFileInfo['nsv']['NSVf'])) {
54
+ $ThisFileInfo['warning'][] = 'NSVf header not present - cannot calculate playtime or bitrate';
55
+ }
56
+
57
+ return true;
58
+ }
59
+
60
+ function getNSVsHeaderFilepointer(&$fd, &$ThisFileInfo, $fileoffset) {
61
+ fseek($fd, $fileoffset, SEEK_SET);
62
+ $NSVsheader = fread($fd, 28);
63
+ $offset = 0;
64
+
65
+ $ThisFileInfo['nsv']['NSVs']['identifier'] = substr($NSVsheader, $offset, 4);
66
+ $offset += 4;
67
+
68
+ if ($ThisFileInfo['nsv']['NSVs']['identifier'] != 'NSVs') {
69
+ $ThisFileInfo['error'][] = 'expected "NSVs" at offset ('.$fileoffset.'), found "'.$ThisFileInfo['nsv']['NSVs']['identifier'].'" instead';
70
+ unset($ThisFileInfo['nsv']['NSVs']);
71
+ return false;
72
+ }
73
+
74
+ $ThisFileInfo['nsv']['NSVs']['offset'] = $fileoffset;
75
+
76
+ $ThisFileInfo['nsv']['NSVs']['video_codec'] = substr($NSVsheader, $offset, 4);
77
+ $offset += 4;
78
+ $ThisFileInfo['nsv']['NSVs']['audio_codec'] = substr($NSVsheader, $offset, 4);
79
+ $offset += 4;
80
+ $ThisFileInfo['nsv']['NSVs']['resolution_x'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 2));
81
+ $offset += 2;
82
+ $ThisFileInfo['nsv']['NSVs']['resolution_y'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 2));
83
+ $offset += 2;
84
+
85
+ $ThisFileInfo['nsv']['NSVs']['framerate_index'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1));
86
+ $offset += 1;
87
+ //$ThisFileInfo['nsv']['NSVs']['unknown1b'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1));
88
+ $offset += 1;
89
+ //$ThisFileInfo['nsv']['NSVs']['unknown1c'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1));
90
+ $offset += 1;
91
+ //$ThisFileInfo['nsv']['NSVs']['unknown1d'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1));
92
+ $offset += 1;
93
+ //$ThisFileInfo['nsv']['NSVs']['unknown2a'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1));
94
+ $offset += 1;
95
+ //$ThisFileInfo['nsv']['NSVs']['unknown2b'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1));
96
+ $offset += 1;
97
+ //$ThisFileInfo['nsv']['NSVs']['unknown2c'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1));
98
+ $offset += 1;
99
+ //$ThisFileInfo['nsv']['NSVs']['unknown2d'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1));
100
+ $offset += 1;
101
+
102
+ switch ($ThisFileInfo['nsv']['NSVs']['audio_codec']) {
103
+ case 'PCM ':
104
+ $ThisFileInfo['nsv']['NSVs']['bits_channel'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1));
105
+ $offset += 1;
106
+ $ThisFileInfo['nsv']['NSVs']['channels'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1));
107
+ $offset += 1;
108
+ $ThisFileInfo['nsv']['NSVs']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 2));
109
+ $offset += 2;
110
+
111
+ $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['nsv']['NSVs']['sample_rate'];
112
+ break;
113
+
114
+ case 'MP3 ':
115
+ case 'NONE':
116
+ default:
117
+ //$ThisFileInfo['nsv']['NSVs']['unknown3'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 4));
118
+ $offset += 4;
119
+ break;
120
+ }
121
+
122
+ $ThisFileInfo['video']['resolution_x'] = $ThisFileInfo['nsv']['NSVs']['resolution_x'];
123
+ $ThisFileInfo['video']['resolution_y'] = $ThisFileInfo['nsv']['NSVs']['resolution_y'];
124
+ $ThisFileInfo['nsv']['NSVs']['frame_rate'] = $this->NSVframerateLookup($ThisFileInfo['nsv']['NSVs']['framerate_index']);
125
+ $ThisFileInfo['video']['frame_rate'] = $ThisFileInfo['nsv']['NSVs']['frame_rate'];
126
+ $ThisFileInfo['video']['bits_per_sample'] = 24;
127
+ $ThisFileInfo['video']['pixel_aspect_ratio'] = (float) 1;
128
+
129
+ return true;
130
+ }
131
+
132
+ function getNSVfHeaderFilepointer(&$fd, &$ThisFileInfo, $fileoffset, $getTOCoffsets=false) {
133
+ fseek($fd, $fileoffset, SEEK_SET);
134
+ $NSVfheader = fread($fd, 28);
135
+ $offset = 0;
136
+
137
+ $ThisFileInfo['nsv']['NSVf']['identifier'] = substr($NSVfheader, $offset, 4);
138
+ $offset += 4;
139
+
140
+ if ($ThisFileInfo['nsv']['NSVf']['identifier'] != 'NSVf') {
141
+ $ThisFileInfo['error'][] = 'expected "NSVf" at offset ('.$fileoffset.'), found "'.$ThisFileInfo['nsv']['NSVf']['identifier'].'" instead';
142
+ unset($ThisFileInfo['nsv']['NSVf']);
143
+ return false;
144
+ }
145
+
146
+ $ThisFileInfo['nsv']['NSVs']['offset'] = $fileoffset;
147
+
148
+ $ThisFileInfo['nsv']['NSVf']['header_length'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4));
149
+ $offset += 4;
150
+ $ThisFileInfo['nsv']['NSVf']['file_size'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4));
151
+ $offset += 4;
152
+
153
+ if ($ThisFileInfo['nsv']['NSVf']['file_size'] > $ThisFileInfo['avdataend']) {
154
+ $ThisFileInfo['warning'][] = 'truncated file - NSVf header indicates '.$ThisFileInfo['nsv']['NSVf']['file_size'].' bytes, file actually '.$ThisFileInfo['avdataend'].' bytes';
155
+ }
156
+
157
+ $ThisFileInfo['nsv']['NSVf']['playtime_ms'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4));
158
+ $offset += 4;
159
+ $ThisFileInfo['nsv']['NSVf']['meta_size'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4));
160
+ $offset += 4;
161
+ $ThisFileInfo['nsv']['NSVf']['TOC_entries_1'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4));
162
+ $offset += 4;
163
+ $ThisFileInfo['nsv']['NSVf']['TOC_entries_2'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4));
164
+ $offset += 4;
165
+
166
+ if ($ThisFileInfo['nsv']['NSVf']['playtime_ms'] == 0) {
167
+ $ThisFileInfo['error'][] = 'Corrupt NSV file: NSVf.playtime_ms == zero';
168
+ return false;
169
+ }
170
+
171
+ $NSVfheader .= fread($fd, $ThisFileInfo['nsv']['NSVf']['meta_size'] + (4 * $ThisFileInfo['nsv']['NSVf']['TOC_entries_1']) + (4 * $ThisFileInfo['nsv']['NSVf']['TOC_entries_2']));
172
+ $NSVfheaderlength = strlen($NSVfheader);
173
+ $ThisFileInfo['nsv']['NSVf']['metadata'] = substr($NSVfheader, $offset, $ThisFileInfo['nsv']['NSVf']['meta_size']);
174
+ $offset += $ThisFileInfo['nsv']['NSVf']['meta_size'];
175
+
176
+ if ($getTOCoffsets) {
177
+ $TOCcounter = 0;
178
+ while ($TOCcounter < $ThisFileInfo['nsv']['NSVf']['TOC_entries_1']) {
179
+ if ($TOCcounter < $ThisFileInfo['nsv']['NSVf']['TOC_entries_1']) {
180
+ $ThisFileInfo['nsv']['NSVf']['TOC_1'][$TOCcounter] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4));
181
+ $offset += 4;
182
+ $TOCcounter++;
183
+ }
184
+ }
185
+ }
186
+
187
+ if (trim($ThisFileInfo['nsv']['NSVf']['metadata']) != '') {
188
+ $ThisFileInfo['nsv']['NSVf']['metadata'] = str_replace('`', "\x01", $ThisFileInfo['nsv']['NSVf']['metadata']);
189
+ $CommentPairArray = explode("\x01".' ', $ThisFileInfo['nsv']['NSVf']['metadata']);
190
+ foreach ($CommentPairArray as $CommentPair) {
191
+ if (strstr($CommentPair, '='."\x01")) {
192
+ list($key, $value) = explode('='."\x01", $CommentPair, 2);
193
+ $ThisFileInfo['nsv']['comments'][strtolower($key)][] = trim(str_replace("\x01", '', $value));
194
+ }
195
+ }
196
+ }
197
+
198
+ $ThisFileInfo['playtime_seconds'] = $ThisFileInfo['nsv']['NSVf']['playtime_ms'] / 1000;
199
+ $ThisFileInfo['bitrate'] = ($ThisFileInfo['nsv']['NSVf']['file_size'] * 8) / $ThisFileInfo['playtime_seconds'];
200
+
201
+ return true;
202
+ }
203
+
204
+
205
+ function NSVframerateLookup($framerateindex) {
206
+ if ($framerateindex <= 127) {
207
+ return (float) $framerateindex;
208
+ }
209
+
210
+ static $NSVframerateLookup = array();
211
+ if (empty($NSVframerateLookup)) {
212
+ $NSVframerateLookup[129] = (float) 29.970;
213
+ $NSVframerateLookup[131] = (float) 23.976;
214
+ $NSVframerateLookup[133] = (float) 14.985;
215
+ $NSVframerateLookup[197] = (float) 59.940;
216
+ $NSVframerateLookup[199] = (float) 47.952;
217
+ }
218
+ return (isset($NSVframerateLookup[$framerateindex]) ? $NSVframerateLookup[$framerateindex] : false);
219
+ }
220
+
221
+ }
222
+
223
+
224
+ ?>
view/getid3/module.audio-video.quicktime.php ADDED
@@ -0,0 +1,1382 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /////////////////////////////////////////////////////////////////
3
+ /// getID3() by James Heinrich <info@getid3.org> //
4
+ // available at http://getid3.sourceforge.net //
5
+ // or http://www.getid3.org //
6
+ /////////////////////////////////////////////////////////////////
7
+ // See readme.txt for more details //
8
+ /////////////////////////////////////////////////////////////////
9
+ // //
10
+ // module.audio-video.quicktime.php //
11
+ // module for analyzing Quicktime and MP3-in-MP4 files //
12
+ // dependencies: module.audio.mp3.php //
13
+ // ///
14
+ /////////////////////////////////////////////////////////////////
15
+
16
+ getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.mp3.php', __FILE__, true);
17
+
18
+ class getid3_quicktime
19
+ {
20
+
21
+ function getid3_quicktime(&$fd, &$ThisFileInfo, $ReturnAtomData=true, $ParseAllPossibleAtoms=false) {
22
+
23
+ $ThisFileInfo['fileformat'] = 'quicktime';
24
+ $ThisFileInfo['quicktime']['hinting'] = false;
25
+
26
+ fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
27
+
28
+ $offset = 0;
29
+ $atomcounter = 0;
30
+
31
+ while ($offset < $ThisFileInfo['avdataend']) {
32
+ if ($offset >= pow(2, 31)) {
33
+ $ThisFileInfo['error'][] = 'Unable to parse atom at offset '.$offset.' because beyond 2GB limit of PHP filesystem functions';
34
+ break;
35
+ }
36
+ fseek($fd, $offset, SEEK_SET);
37
+ $AtomHeader = fread($fd, 8);
38
+
39
+ $atomsize = getid3_lib::BigEndian2Int(substr($AtomHeader, 0, 4));
40
+ $atomname = substr($AtomHeader, 4, 4);
41
+
42
+ // 64-bit MOV patch by jlegate�ktnc*com
43
+ if ($atomsize == 1) {
44
+ $atomsize = getid3_lib::BigEndian2Int(fread($fd, 8));
45
+ }
46
+
47
+ $ThisFileInfo['quicktime'][$atomname]['name'] = $atomname;
48
+ $ThisFileInfo['quicktime'][$atomname]['size'] = $atomsize;
49
+ $ThisFileInfo['quicktime'][$atomname]['offset'] = $offset;
50
+
51
+ if (($offset + $atomsize) > $ThisFileInfo['avdataend']) {
52
+ $ThisFileInfo['error'][] = 'Atom at offset '.$offset.' claims to go beyond end-of-file (length: '.$atomsize.' bytes)';
53
+ return false;
54
+ }
55
+
56
+ if ($atomsize == 0) {
57
+ // Furthermore, for historical reasons the list of atoms is optionally
58
+ // terminated by a 32-bit integer set to 0. If you are writing a program
59
+ // to read user data atoms, you should allow for the terminating 0.
60
+ break;
61
+ }
62
+ switch ($atomname) {
63
+ case 'mdat': // Media DATa atom
64
+ // 'mdat' contains the actual data for the audio/video
65
+ if (($atomsize > 8) && (!isset($ThisFileInfo['avdataend_tmp']) || ($ThisFileInfo['quicktime'][$atomname]['size'] > ($ThisFileInfo['avdataend_tmp'] - $ThisFileInfo['avdataoffset'])))) {
66
+
67
+ $ThisFileInfo['avdataoffset'] = $ThisFileInfo['quicktime'][$atomname]['offset'] + 8;
68
+ $OldAVDataEnd = $ThisFileInfo['avdataend'];
69
+ $ThisFileInfo['avdataend'] = $ThisFileInfo['quicktime'][$atomname]['offset'] + $ThisFileInfo['quicktime'][$atomname]['size'];
70
+
71
+ if (getid3_mp3::MPEGaudioHeaderValid(getid3_mp3::MPEGaudioHeaderDecode(fread($fd, 4)))) {
72
+ getid3_mp3::getOnlyMPEGaudioInfo($fd, $ThisFileInfo, $ThisFileInfo['avdataoffset'], false);
73
+ if (isset($ThisFileInfo['mpeg']['audio'])) {
74
+ $ThisFileInfo['audio']['dataformat'] = 'mp3';
75
+ $ThisFileInfo['audio']['codec'] = (!empty($ThisFileInfo['mpeg']['audio']['encoder']) ? $ThisFileInfo['mpeg']['audio']['encoder'] : (!empty($ThisFileInfo['mpeg']['audio']['codec']) ? $ThisFileInfo['mpeg']['audio']['codec'] : (!empty($ThisFileInfo['mpeg']['audio']['LAME']) ? 'LAME' :'mp3')));
76
+ $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['mpeg']['audio']['sample_rate'];
77
+ $ThisFileInfo['audio']['channels'] = $ThisFileInfo['mpeg']['audio']['channels'];
78
+ $ThisFileInfo['audio']['bitrate'] = $ThisFileInfo['mpeg']['audio']['bitrate'];
79
+ $ThisFileInfo['audio']['bitrate_mode'] = strtolower($ThisFileInfo['mpeg']['audio']['bitrate_mode']);
80
+ $ThisFileInfo['bitrate'] = $ThisFileInfo['audio']['bitrate'];
81
+ }
82
+ }
83
+ $ThisFileInfo['avdataend'] = $OldAVDataEnd;
84
+ unset($OldAVDataEnd);
85
+
86
+ }
87
+ break;
88
+
89
+ case 'free': // FREE space atom
90
+ case 'skip': // SKIP atom
91
+ case 'wide': // 64-bit expansion placeholder atom
92
+ // 'free', 'skip' and 'wide' are just padding, contains no useful data at all
93
+ break;
94
+
95
+ default:
96
+ $atomHierarchy = array();
97
+ $ThisFileInfo['quicktime'][$atomname] = $this->QuicktimeParseAtom($atomname, $atomsize, fread($fd, $atomsize), $ThisFileInfo, $offset, $atomHierarchy, $ParseAllPossibleAtoms);
98
+ break;
99
+ }
100
+
101
+ $offset += $atomsize;
102
+ $atomcounter++;
103
+ }
104
+
105
+ if (!empty($ThisFileInfo['avdataend_tmp'])) {
106
+ // this value is assigned to a temp value and then erased because
107
+ // otherwise any atoms beyond the 'mdat' atom would not get parsed
108
+ $ThisFileInfo['avdataend'] = $ThisFileInfo['avdataend_tmp'];
109
+ unset($ThisFileInfo['avdataend_tmp']);
110
+ }
111
+
112
+ if (!isset($ThisFileInfo['bitrate']) && isset($ThisFileInfo['playtime_seconds'])) {
113
+ $ThisFileInfo['bitrate'] = (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8) / $ThisFileInfo['playtime_seconds'];
114
+ }
115
+ if (isset($ThisFileInfo['bitrate']) && !isset($ThisFileInfo['audio']['bitrate']) && !isset($ThisFileInfo['quicktime']['video'])) {
116
+ $ThisFileInfo['audio']['bitrate'] = $ThisFileInfo['bitrate'];
117
+ }
118
+ if (@$ThisFileInfo['playtime_seconds'] && !isset($ThisFileInfo['video']['frame_rate']) && !empty($ThisFileInfo['quicktime']['stts_framecount'])) {
119
+ foreach ($ThisFileInfo['quicktime']['stts_framecount'] as $key => $samples_count) {
120
+ $samples_per_second = $samples_count / $ThisFileInfo['playtime_seconds'];
121
+ if ($samples_per_second > 240) {
122
+ // has to be audio samples
123
+ } else {
124
+ $ThisFileInfo['video']['frame_rate'] = $samples_per_second;
125
+ break;
126
+ }
127
+ }
128
+ }
129
+ if (($ThisFileInfo['audio']['dataformat'] == 'mp4') && empty($ThisFileInfo['video']['resolution_x'])) {
130
+ $ThisFileInfo['fileformat'] = 'mp4';
131
+ $ThisFileInfo['mime_type'] = 'audio/mp4';
132
+ unset($ThisFileInfo['video']['dataformat']);
133
+ }
134
+
135
+ if (!$ReturnAtomData) {
136
+ unset($ThisFileInfo['quicktime']['moov']);
137
+ }
138
+
139
+ if (empty($ThisFileInfo['audio']['dataformat']) && !empty($ThisFileInfo['quicktime']['audio'])) {
140
+ $ThisFileInfo['audio']['dataformat'] = 'quicktime';
141
+ }
142
+ if (empty($ThisFileInfo['video']['dataformat']) && !empty($ThisFileInfo['quicktime']['video'])) {
143
+ $ThisFileInfo['video']['dataformat'] = 'quicktime';
144
+ }
145
+
146
+ return true;
147
+ }
148
+
149
+ function QuicktimeParseAtom($atomname, $atomsize, $atomdata, &$ThisFileInfo, $baseoffset, &$atomHierarchy, $ParseAllPossibleAtoms) {
150
+ // http://developer.apple.com/techpubs/quicktime/qtdevdocs/APIREF/INDEX/atomalphaindex.htm
151
+
152
+ array_push($atomHierarchy, $atomname);
153
+ $atomstructure['hierarchy'] = implode(' ', $atomHierarchy);
154
+ $atomstructure['name'] = $atomname;
155
+ $atomstructure['size'] = $atomsize;
156
+ $atomstructure['offset'] = $baseoffset;
157
+
158
+ switch ($atomname) {
159
+ case 'moov': // MOVie container atom
160
+ case 'trak': // TRAcK container atom
161
+ case 'clip': // CLIPping container atom
162
+ case 'matt': // track MATTe container atom
163
+ case 'edts': // EDiTS container atom
164
+ case 'tref': // Track REFerence container atom
165
+ case 'mdia': // MeDIA container atom
166
+ case 'minf': // Media INFormation container atom
167
+ case 'dinf': // Data INFormation container atom
168
+ case 'udta': // User DaTA container atom
169
+ case 'cmov': // Compressed MOVie container atom
170
+ case 'rmra': // Reference Movie Record Atom
171
+ case 'rmda': // Reference Movie Descriptor Atom
172
+ case 'gmhd': // Generic Media info HeaDer atom (seen on QTVR)
173
+ $atomstructure['subatoms'] = $this->QuicktimeParseContainerAtom($atomdata, $ThisFileInfo, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms);
174
+ break;
175
+
176
+ case 'stbl': // Sample TaBLe container atom
177
+ $atomstructure['subatoms'] = $this->QuicktimeParseContainerAtom($atomdata, $ThisFileInfo, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms);
178
+ $isVideo = false;
179
+ $framerate = 0;
180
+ $framecount = 0;
181
+ foreach ($atomstructure['subatoms'] as $key => $value_array) {
182
+ if (isset($value_array['sample_description_table'])) {
183
+ foreach ($value_array['sample_description_table'] as $key2 => $value_array2) {
184
+ if (isset($value_array2['data_format'])) {
185
+ switch ($value_array2['data_format']) {
186
+ case 'avc1':
187
+ case 'mp4v':
188
+ // video data
189
+ $isVideo = true;
190
+ break;
191
+ case 'mp4a':
192
+ // audio data
193
+ break;
194
+ }
195
+ }
196
+ }
197
+ } elseif (isset($value_array['time_to_sample_table'])) {
198
+ foreach ($value_array['time_to_sample_table'] as $key2 => $value_array2) {
199
+ if (isset($value_array2['sample_count']) && isset($value_array2['sample_duration'])) {
200
+ $framerate = round($ThisFileInfo['quicktime']['time_scale'] / $value_array2['sample_duration'], 3);
201
+ $framecount = $value_array2['sample_count'];
202
+ }
203
+ }
204
+ }
205
+ }
206
+ if ($isVideo && $framerate) {
207
+ $ThisFileInfo['quicktime']['video']['frame_rate'] = $framerate;
208
+ $ThisFileInfo['video']['frame_rate'] = $ThisFileInfo['quicktime']['video']['frame_rate'];
209
+ }
210
+ if ($isVideo && $framecount) {
211
+ $ThisFileInfo['quicktime']['video']['frame_count'] = $framecount;
212
+ }
213
+ break;
214
+
215
+
216
+ case '�cpy':
217
+ case '�day':
218
+ case '�dir':
219
+ case '�ed1':
220
+ case '�ed2':
221
+ case '�ed3':
222
+ case '�ed4':
223
+ case '�ed5':
224
+ case '�ed6':
225
+ case '�ed7':
226
+ case '�ed8':
227
+ case '�ed9':
228
+ case '�fmt':
229
+ case '�inf':
230
+ case '�prd':
231
+ case '�prf':
232
+ case '�req':
233
+ case '�src':
234
+ case '�wrt':
235
+ case '�nam':
236
+ case '�cmt':
237
+ case '�wrn':
238
+ case '�hst':
239
+ case '�mak':
240
+ case '�mod':
241
+ case '�PRD':
242
+ case '�swr':
243
+ case '�aut':
244
+ case '�ART':
245
+ case '�trk':
246
+ case '�alb':
247
+ case '�com':
248
+ case '�gen':
249
+ case '�ope':
250
+ case '�url':
251
+ case '�enc':
252
+ $atomstructure['data_length'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 2));
253
+ $atomstructure['language_id'] = getid3_lib::BigEndian2Int(substr($atomdata, 2, 2));
254
+ $atomstructure['data'] = substr($atomdata, 4);
255
+
256
+ $atomstructure['language'] = $this->QuicktimeLanguageLookup($atomstructure['language_id']);
257
+ if (empty($ThisFileInfo['comments']['language']) || (!in_array($atomstructure['language'], $ThisFileInfo['comments']['language']))) {
258
+ $ThisFileInfo['comments']['language'][] = $atomstructure['language'];
259
+ }
260
+ $this->CopyToAppropriateCommentsSection($atomname, $atomstructure['data'], $ThisFileInfo);
261
+ break;
262
+
263
+
264
+ case 'play': // auto-PLAY atom
265
+ $atomstructure['autoplay'] = (bool) getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
266
+
267
+ $ThisFileInfo['quicktime']['autoplay'] = $atomstructure['autoplay'];
268
+ break;
269
+
270
+
271
+ case 'WLOC': // Window LOCation atom
272
+ $atomstructure['location_x'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 2));
273
+ $atomstructure['location_y'] = getid3_lib::BigEndian2Int(substr($atomdata, 2, 2));
274
+ break;
275
+
276
+
277
+ case 'LOOP': // LOOPing atom
278
+ case 'SelO': // play SELection Only atom
279
+ case 'AllF': // play ALL Frames atom
280
+ $atomstructure['data'] = getid3_lib::BigEndian2Int($atomdata);
281
+ break;
282
+
283
+
284
+ case 'name': //
285
+ case 'MCPS': // Media Cleaner PRo
286
+ case '@PRM': // adobe PReMiere version
287
+ case '@PRQ': // adobe PRemiere Quicktime version
288
+ $atomstructure['data'] = $atomdata;
289
+ break;
290
+
291
+
292
+ case 'cmvd': // Compressed MooV Data atom
293
+ // Code by ubergeek�ubergeek*tv based on information from
294
+ // http://developer.apple.com/quicktime/icefloe/dispatch012.html
295
+ $atomstructure['unCompressedSize'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 4));
296
+
297
+ $CompressedFileData = substr($atomdata, 4);
298
+ if ($UncompressedHeader = @gzuncompress($CompressedFileData)) {
299
+ $atomstructure['subatoms'] = $this->QuicktimeParseContainerAtom($UncompressedHeader, $ThisFileInfo, 0, $atomHierarchy, $ParseAllPossibleAtoms);
300
+ } else {
301
+ $ThisFileInfo['warning'][] = 'Error decompressing compressed MOV atom at offset '.$atomstructure['offset'];
302
+ }
303
+ break;
304
+
305
+
306
+ case 'dcom': // Data COMpression atom
307
+ $atomstructure['compression_id'] = $atomdata;
308
+ $atomstructure['compression_text'] = $this->QuicktimeDCOMLookup($atomdata);
309
+ break;
310
+
311
+
312
+ case 'rdrf': // Reference movie Data ReFerence atom
313
+ $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
314
+ $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3));
315
+ $atomstructure['flags']['internal_data'] = (bool) ($atomstructure['flags_raw'] & 0x000001);
316
+
317
+ $atomstructure['reference_type_name'] = substr($atomdata, 4, 4);
318
+ $atomstructure['reference_length'] = getid3_lib::BigEndian2Int(substr($atomdata, 8, 4));
319
+ switch ($atomstructure['reference_type_name']) {
320
+ case 'url ':
321
+ $atomstructure['url'] = $this->NoNullString(substr($atomdata, 12));
322
+ break;
323
+
324
+ case 'alis':
325
+ $atomstructure['file_alias'] = substr($atomdata, 12);
326
+ break;
327
+
328
+ case 'rsrc':
329
+ $atomstructure['resource_alias'] = substr($atomdata, 12);
330
+ break;
331
+
332
+ default:
333
+ $atomstructure['data'] = substr($atomdata, 12);
334
+ break;
335
+ }
336
+ break;
337
+
338
+
339
+ case 'rmqu': // Reference Movie QUality atom
340
+ $atomstructure['movie_quality'] = getid3_lib::BigEndian2Int($atomdata);
341
+ break;
342
+
343
+
344
+ case 'rmcs': // Reference Movie Cpu Speed atom
345
+ $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
346
+ $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3)); // hardcoded: 0x0000
347
+ $atomstructure['cpu_speed_rating'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 2));
348
+ break;
349
+
350
+
351
+ case 'rmvc': // Reference Movie Version Check atom
352
+ $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
353
+ $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3)); // hardcoded: 0x0000
354
+ $atomstructure['gestalt_selector'] = substr($atomdata, 4, 4);
355
+ $atomstructure['gestalt_value_mask'] = getid3_lib::BigEndian2Int(substr($atomdata, 8, 4));
356
+ $atomstructure['gestalt_value'] = getid3_lib::BigEndian2Int(substr($atomdata, 12, 4));
357
+ $atomstructure['gestalt_check_type'] = getid3_lib::BigEndian2Int(substr($atomdata, 14, 2));
358
+ break;
359
+
360
+
361
+ case 'rmcd': // Reference Movie Component check atom
362
+ $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
363
+ $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3)); // hardcoded: 0x0000
364
+ $atomstructure['component_type'] = substr($atomdata, 4, 4);
365
+ $atomstructure['component_subtype'] = substr($atomdata, 8, 4);
366
+ $atomstructure['component_manufacturer'] = substr($atomdata, 12, 4);
367
+ $atomstructure['component_flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 16, 4));
368
+ $atomstructure['component_flags_mask'] = getid3_lib::BigEndian2Int(substr($atomdata, 20, 4));
369
+ $atomstructure['component_min_version'] = getid3_lib::BigEndian2Int(substr($atomdata, 24, 4));
370
+ break;
371
+
372
+
373
+ case 'rmdr': // Reference Movie Data Rate atom
374
+ $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
375
+ $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3)); // hardcoded: 0x0000
376
+ $atomstructure['data_rate'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 4));
377
+
378
+ $atomstructure['data_rate_bps'] = $atomstructure['data_rate'] * 10;
379
+ break;
380
+
381
+
382
+ case 'rmla': // Reference Movie Language Atom
383
+ $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
384
+ $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3)); // hardcoded: 0x0000
385
+ $atomstructure['language_id'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 2));
386
+
387
+ $atomstructure['language'] = $this->QuicktimeLanguageLookup($atomstructure['language_id']);
388
+ if (empty($ThisFileInfo['comments']['language']) || (!in_array($atomstructure['language'], $ThisFileInfo['comments']['language']))) {
389
+ $ThisFileInfo['comments']['language'][] = $atomstructure['language'];
390
+ }
391
+ break;
392
+
393
+
394
+ case 'rmla': // Reference Movie Language Atom
395
+ $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
396
+ $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3)); // hardcoded: 0x0000
397
+ $atomstructure['track_id'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 2));
398
+ break;
399
+
400
+
401
+ case 'ptv ': // Print To Video - defines a movie's full screen mode
402
+ // http://developer.apple.com/documentation/QuickTime/APIREF/SOURCESIV/at_ptv-_pg.htm
403
+ $atomstructure['display_size_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 2));
404
+ $atomstructure['reserved_1'] = getid3_lib::BigEndian2Int(substr($atomdata, 2, 2)); // hardcoded: 0x0000
405
+ $atomstructure['reserved_2'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 2)); // hardcoded: 0x0000
406
+ $atomstructure['slide_show_flag'] = getid3_lib::BigEndian2Int(substr($atomdata, 6, 1));
407
+ $atomstructure['play_on_open_flag'] = getid3_lib::BigEndian2Int(substr($atomdata, 7, 1));
408
+
409
+ $atomstructure['flags']['play_on_open'] = (bool) $atomstructure['play_on_open_flag'];
410
+ $atomstructure['flags']['slide_show'] = (bool) $atomstructure['slide_show_flag'];
411
+
412
+ $ptv_lookup[0] = 'normal';
413
+ $ptv_lookup[1] = 'double';
414
+ $ptv_lookup[2] = 'half';
415
+ $ptv_lookup[3] = 'full';
416
+ $ptv_lookup[4] = 'current';
417
+ if (isset($ptv_lookup[$atomstructure['display_size_raw']])) {
418
+ $atomstructure['display_size'] = $ptv_lookup[$atomstructure['display_size_raw']];
419
+ } else {
420
+ $ThisFileInfo['warning'][] = 'unknown "ptv " display constant ('.$atomstructure['display_size_raw'].')';
421
+ }
422
+ break;
423
+
424
+
425
+ case 'stsd': // Sample Table Sample Description atom
426
+ $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
427
+ $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3)); // hardcoded: 0x0000
428
+ $atomstructure['number_entries'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 4));
429
+ $stsdEntriesDataOffset = 8;
430
+ for ($i = 0; $i < $atomstructure['number_entries']; $i++) {
431
+ $atomstructure['sample_description_table'][$i]['size'] = getid3_lib::BigEndian2Int(substr($atomdata, $stsdEntriesDataOffset, 4));
432
+ $stsdEntriesDataOffset += 4;
433
+ $atomstructure['sample_description_table'][$i]['data_format'] = substr($atomdata, $stsdEntriesDataOffset, 4);
434
+ $stsdEntriesDataOffset += 4;
435
+ $atomstructure['sample_description_table'][$i]['reserved'] = getid3_lib::BigEndian2Int(substr($atomdata, $stsdEntriesDataOffset, 6));
436
+ $stsdEntriesDataOffset += 6;
437
+ $atomstructure['sample_description_table'][$i]['reference_index'] = getid3_lib::BigEndian2Int(substr($atomdata, $stsdEntriesDataOffset, 2));
438
+ $stsdEntriesDataOffset += 2;
439
+ $atomstructure['sample_description_table'][$i]['data'] = substr($atomdata, $stsdEntriesDataOffset, ($atomstructure['sample_description_table'][$i]['size'] - 4 - 4 - 6 - 2));
440
+ $stsdEntriesDataOffset += ($atomstructure['sample_description_table'][$i]['size'] - 4 - 4 - 6 - 2);
441
+
442
+ $atomstructure['sample_description_table'][$i]['encoder_version'] = getid3_lib::BigEndian2Int(substr($atomstructure['sample_description_table'][$i]['data'], 0, 2));
443
+ $atomstructure['sample_description_table'][$i]['encoder_revision'] = getid3_lib::BigEndian2Int(substr($atomstructure['sample_description_table'][$i]['data'], 2, 2));
444
+ $atomstructure['sample_description_table'][$i]['encoder_vendor'] = substr($atomstructure['sample_description_table'][$i]['data'], 4, 4);
445
+
446
+ switch ($atomstructure['sample_description_table'][$i]['encoder_vendor']) {
447
+
448
+ case "\x00\x00\x00\x00":
449
+ // audio atom
450
+ $atomstructure['sample_description_table'][$i]['audio_channels'] = getid3_lib::BigEndian2Int(substr($atomstructure['sample_description_table'][$i]['data'], 8, 2));
451
+ $atomstructure['sample_description_table'][$i]['audio_bit_depth'] = getid3_lib::BigEndian2Int(substr($atomstructure['sample_description_table'][$i]['data'], 10, 2));
452
+ $atomstructure['sample_description_table'][$i]['audio_compression_id'] = getid3_lib::BigEndian2Int(substr($atomstructure['sample_description_table'][$i]['data'], 12, 2));
453
+ $atomstructure['sample_description_table'][$i]['audio_packet_size'] = getid3_lib::BigEndian2Int(substr($atomstructure['sample_description_table'][$i]['data'], 14, 2));
454
+ $atomstructure['sample_description_table'][$i]['audio_sample_rate'] = getid3_lib::FixedPoint16_16(substr($atomstructure['sample_description_table'][$i]['data'], 16, 4));
455
+
456
+ switch ($atomstructure['sample_description_table'][$i]['data_format']) {
457
+ case 'avc1':
458
+ case 'mp4v':
459
+ $ThisFileInfo['fileformat'] = 'mp4';
460
+ $ThisFileInfo['video']['fourcc'] = $atomstructure['sample_description_table'][$i]['data_format'];
461
+ $ThisFileInfo['warning'][] = 'This version ('.GETID3_VERSION.') of getID3() does not fully support MPEG-4 audio/video streams';
462
+ break;
463
+
464
+ case 'qtvr':
465
+ $ThisFileInfo['video']['dataformat'] = 'quicktimevr';
466
+ break;
467
+
468
+ case 'mp4a':
469
+ default:
470
+ $ThisFileInfo['quicktime']['audio']['codec'] = $this->QuicktimeAudioCodecLookup($atomstructure['sample_description_table'][$i]['data_format']);
471
+ $ThisFileInfo['quicktime']['audio']['sample_rate'] = $atomstructure['sample_description_table'][$i]['audio_sample_rate'];
472
+ $ThisFileInfo['quicktime']['audio']['channels'] = $atomstructure['sample_description_table'][$i]['audio_channels'];
473
+ $ThisFileInfo['quicktime']['audio']['bit_depth'] = $atomstructure['sample_description_table'][$i]['audio_bit_depth'];
474
+ $ThisFileInfo['audio']['codec'] = $ThisFileInfo['quicktime']['audio']['codec'];
475
+ $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['quicktime']['audio']['sample_rate'];
476
+ $ThisFileInfo['audio']['channels'] = $ThisFileInfo['quicktime']['audio']['channels'];
477
+ $ThisFileInfo['audio']['bits_per_sample'] = $ThisFileInfo['quicktime']['audio']['bit_depth'];
478
+ switch ($atomstructure['sample_description_table'][$i]['data_format']) {
479
+ case 'raw ': // PCM
480
+ case 'alac': // Apple Lossless Audio Codec
481
+ $ThisFileInfo['audio']['lossless'] = true;
482
+ break;
483
+ default:
484
+ $ThisFileInfo['audio']['lossless'] = false;
485
+ break;
486
+ }
487
+ break;
488
+ }
489
+ break;
490
+
491
+ default:
492
+ switch ($atomstructure['sample_description_table'][$i]['data_format']) {
493
+ case 'mp4s':
494
+ $ThisFileInfo['fileformat'] = 'mp4';
495
+ break;
496
+
497
+ default:
498
+ // video atom
499
+ $atomstructure['sample_description_table'][$i]['video_temporal_quality'] = getid3_lib::BigEndian2Int(substr($atomstructure['sample_description_table'][$i]['data'], 8, 4));
500
+ $atomstructure['sample_description_table'][$i]['video_spatial_quality'] = getid3_lib::BigEndian2Int(substr($atomstructure['sample_description_table'][$i]['data'], 12, 4));
501
+ $atomstructure['sample_description_table'][$i]['video_frame_width'] = getid3_lib::BigEndian2Int(substr($atomstructure['sample_description_table'][$i]['data'], 16, 2));
502
+ $atomstructure['sample_description_table'][$i]['video_frame_height'] = getid3_lib::BigEndian2Int(substr($atomstructure['sample_description_table'][$i]['data'], 18, 2));
503
+ $atomstructure['sample_description_table'][$i]['video_resolution_x'] = getid3_lib::FixedPoint16_16(substr($atomstructure['sample_description_table'][$i]['data'], 20, 4));
504
+ $atomstructure['sample_description_table'][$i]['video_resolution_y'] = getid3_lib::FixedPoint16_16(substr($atomstructure['sample_description_table'][$i]['data'], 24, 4));
505
+ $atomstructure['sample_description_table'][$i]['video_data_size'] = getid3_lib::BigEndian2Int(substr($atomstructure['sample_description_table'][$i]['data'], 28, 4));
506
+ $atomstructure['sample_description_table'][$i]['video_frame_count'] = getid3_lib::BigEndian2Int(substr($atomstructure['sample_description_table'][$i]['data'], 32, 2));
507
+ $atomstructure['sample_description_table'][$i]['video_encoder_name_len'] = getid3_lib::BigEndian2Int(substr($atomstructure['sample_description_table'][$i]['data'], 34, 1));
508
+ $atomstructure['sample_description_table'][$i]['video_encoder_name'] = substr($atomstructure['sample_description_table'][$i]['data'], 35, $atomstructure['sample_description_table'][$i]['video_encoder_name_len']);
509
+ $atomstructure['sample_description_table'][$i]['video_pixel_color_depth'] = getid3_lib::BigEndian2Int(substr($atomstructure['sample_description_table'][$i]['data'], 66, 2));
510
+ $atomstructure['sample_description_table'][$i]['video_color_table_id'] = getid3_lib::BigEndian2Int(substr($atomstructure['sample_description_table'][$i]['data'], 68, 2));
511
+
512
+ $atomstructure['sample_description_table'][$i]['video_pixel_color_type'] = (($atomstructure['sample_description_table'][$i]['video_pixel_color_depth'] > 32) ? 'grayscale' : 'color');
513
+ $atomstructure['sample_description_table'][$i]['video_pixel_color_name'] = $this->QuicktimeColorNameLookup($atomstructure['sample_description_table'][$i]['video_pixel_color_depth']);
514
+
515
+ if ($atomstructure['sample_description_table'][$i]['video_pixel_color_name'] != 'invalid') {
516
+ $ThisFileInfo['quicktime']['video']['codec_fourcc'] = $atomstructure['sample_description_table'][$i]['data_format'];
517
+ $ThisFileInfo['quicktime']['video']['codec_fourcc_lookup'] = $this->QuicktimeVideoCodecLookup($atomstructure['sample_description_table'][$i]['data_format']);
518
+ $ThisFileInfo['quicktime']['video']['codec'] = $atomstructure['sample_description_table'][$i]['video_encoder_name'];
519
+ $ThisFileInfo['quicktime']['video']['color_depth'] = $atomstructure['sample_description_table'][$i]['video_pixel_color_depth'];
520
+ $ThisFileInfo['quicktime']['video']['color_depth_name'] = $atomstructure['sample_description_table'][$i]['video_pixel_color_name'];
521
+
522
+ $ThisFileInfo['video']['codec'] = $ThisFileInfo['quicktime']['video']['codec'];
523
+ $ThisFileInfo['video']['bits_per_sample'] = $ThisFileInfo['quicktime']['video']['color_depth'];
524
+ }
525
+ $ThisFileInfo['video']['lossless'] = false;
526
+ $ThisFileInfo['video']['pixel_aspect_ratio'] = (float) 1;
527
+ break;
528
+ }
529
+ break;
530
+ }
531
+ switch (strtolower($atomstructure['sample_description_table'][$i]['data_format'])) {
532
+ case 'mp4a':
533
+ $ThisFileInfo['audio']['dataformat'] = 'mp4';
534
+ $ThisFileInfo['quicktime']['audio']['codec'] = 'mp4';
535
+ break;
536
+
537
+ case '3ivx':
538
+ case '3iv1':
539
+ case '3iv2':
540
+ $ThisFileInfo['video']['dataformat'] = '3ivx';
541
+ break;
542
+
543
+ case 'xvid':
544
+ $ThisFileInfo['video']['dataformat'] = 'xvid';
545
+ break;
546
+
547
+ case 'mp4v':
548
+ $ThisFileInfo['video']['dataformat'] = 'mpeg4';
549
+ break;
550
+
551
+ case 'divx':
552
+ case 'div1':
553
+ case 'div2':
554
+ case 'div3':
555
+ case 'div4':
556
+ case 'div5':
557
+ case 'div6':
558
+ $TDIVXileInfo['video']['dataformat'] = 'divx';
559
+ break;
560
+
561
+ default:
562
+ // do nothing
563
+ break;
564
+ }
565
+ unset($atomstructure['sample_description_table'][$i]['data']);
566
+ }
567
+ break;
568
+
569
+
570
+ case 'stts': // Sample Table Time-to-Sample atom
571
+ $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
572
+ $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3)); // hardcoded: 0x0000
573
+ $atomstructure['number_entries'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 4));
574
+ $sttsEntriesDataOffset = 8;
575
+ //$FrameRateCalculatorArray = array();
576
+ $frames_count = 0;
577
+ for ($i = 0; $i < $atomstructure['number_entries']; $i++) {
578
+ $atomstructure['time_to_sample_table'][$i]['sample_count'] = getid3_lib::BigEndian2Int(substr($atomdata, $sttsEntriesDataOffset, 4));
579
+ $sttsEntriesDataOffset += 4;
580
+ $atomstructure['time_to_sample_table'][$i]['sample_duration'] = getid3_lib::BigEndian2Int(substr($atomdata, $sttsEntriesDataOffset, 4));
581
+ $sttsEntriesDataOffset += 4;
582
+
583
+ $frames_count += $atomstructure['time_to_sample_table'][$i]['sample_count'];
584
+
585
+ // THIS SECTION REPLACED WITH CODE IN "stbl" ATOM
586
+ //if (!empty($ThisFileInfo['quicktime']['time_scale']) && (@$atomstructure['time_to_sample_table'][$i]['sample_duration'] > 0)) {
587
+ // $stts_new_framerate = $ThisFileInfo['quicktime']['time_scale'] / $atomstructure['time_to_sample_table'][$i]['sample_duration'];
588
+ // if ($stts_new_framerate <= 60) {
589
+ // // some atoms have durations of "1" giving a very large framerate, which probably is not right
590
+ // $ThisFileInfo['video']['frame_rate'] = max(@$ThisFileInfo['video']['frame_rate'], $stts_new_framerate);
591
+ // }
592
+ //}
593
+ //
594
+ //@$FrameRateCalculatorArray[($ThisFileInfo['quicktime']['time_scale'] / $atomstructure['time_to_sample_table'][$i]['sample_duration'])] += $atomstructure['time_to_sample_table'][$i]['sample_count'];
595
+ }
596
+ $ThisFileInfo['quicktime']['stts_framecount'][] = $frames_count;
597
+ //$sttsFramesTotal = 0;
598
+ //$sttsSecondsTotal = 0;
599
+ //foreach ($FrameRateCalculatorArray as $frames_per_second => $frame_count) {
600
+ // if (($frames_per_second > 60) || ($frames_per_second < 1)) {
601
+ // // not video FPS information, probably audio information
602
+ // $sttsFramesTotal = 0;
603
+ // $sttsSecondsTotal = 0;
604
+ // break;
605
+ // }
606
+ // $sttsFramesTotal += $frame_count;
607
+ // $sttsSecondsTotal += $frame_count / $frames_per_second;
608
+ //}
609
+ //if (($sttsFramesTotal > 0) && ($sttsSecondsTotal > 0)) {
610
+ // if (($sttsFramesTotal / $sttsSecondsTotal) > @$ThisFileInfo['video']['frame_rate']) {
611
+ // $ThisFileInfo['video']['frame_rate'] = $sttsFramesTotal / $sttsSecondsTotal;
612
+ // }
613
+ //}
614
+ break;
615
+
616
+
617
+ case 'stss': // Sample Table Sync Sample (key frames) atom
618
+ if ($ParseAllPossibleAtoms) {
619
+ $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
620
+ $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3)); // hardcoded: 0x0000
621
+ $atomstructure['number_entries'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 4));
622
+ $stssEntriesDataOffset = 8;
623
+ for ($i = 0; $i < $atomstructure['number_entries']; $i++) {
624
+ $atomstructure['time_to_sample_table'][$i] = getid3_lib::BigEndian2Int(substr($atomdata, $stssEntriesDataOffset, 4));
625
+ $stssEntriesDataOffset += 4;
626
+ }
627
+ }
628
+ break;
629
+
630
+
631
+ case 'stsc': // Sample Table Sample-to-Chunk atom
632
+ if ($ParseAllPossibleAtoms) {
633
+ $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
634
+ $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3)); // hardcoded: 0x0000
635
+ $atomstructure['number_entries'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 4));
636
+ $stscEntriesDataOffset = 8;
637
+ for ($i = 0; $i < $atomstructure['number_entries']; $i++) {
638
+ $atomstructure['sample_to_chunk_table'][$i]['first_chunk'] = getid3_lib::BigEndian2Int(substr($atomdata, $stscEntriesDataOffset, 4));
639
+ $stscEntriesDataOffset += 4;
640
+ $atomstructure['sample_to_chunk_table'][$i]['samples_per_chunk'] = getid3_lib::BigEndian2Int(substr($atomdata, $stscEntriesDataOffset, 4));
641
+ $stscEntriesDataOffset += 4;
642
+ $atomstructure['sample_to_chunk_table'][$i]['sample_description'] = getid3_lib::BigEndian2Int(substr($atomdata, $stscEntriesDataOffset, 4));
643
+ $stscEntriesDataOffset += 4;
644
+ }
645
+ }
646
+ break;
647
+
648
+
649
+ case 'stsz': // Sample Table SiZe atom
650
+ if ($ParseAllPossibleAtoms) {
651
+ $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
652
+ $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3)); // hardcoded: 0x0000
653
+ $atomstructure['sample_size'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 4));
654
+ $atomstructure['number_entries'] = getid3_lib::BigEndian2Int(substr($atomdata, 8, 4));
655
+ $stszEntriesDataOffset = 12;
656
+ if ($atomstructure['sample_size'] == 0) {
657
+ for ($i = 0; $i < $atomstructure['number_entries']; $i++) {
658
+ $atomstructure['sample_size_table'][$i] = getid3_lib::BigEndian2Int(substr($atomdata, $stszEntriesDataOffset, 4));
659
+ $stszEntriesDataOffset += 4;
660
+ }
661
+ }
662
+ }
663
+ break;
664
+
665
+
666
+ case 'stco': // Sample Table Chunk Offset atom
667
+ if ($ParseAllPossibleAtoms) {
668
+ $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
669
+ $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3)); // hardcoded: 0x0000
670
+ $atomstructure['number_entries'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 4));
671
+ $stcoEntriesDataOffset = 8;
672
+ for ($i = 0; $i < $atomstructure['number_entries']; $i++) {
673
+ $atomstructure['chunk_offset_table'][$i] = getid3_lib::BigEndian2Int(substr($atomdata, $stcoEntriesDataOffset, 4));
674
+ $stcoEntriesDataOffset += 4;
675
+ }
676
+ }
677
+ break;
678
+
679
+
680
+ case 'co64': // Chunk Offset 64-bit (version of "stco" that supports > 2GB files)
681
+ if ($ParseAllPossibleAtoms) {
682
+ $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
683
+ $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3)); // hardcoded: 0x0000
684
+ $atomstructure['number_entries'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 4));
685
+ $stcoEntriesDataOffset = 8;
686
+ for ($i = 0; $i < $atomstructure['number_entries']; $i++) {
687
+ $atomstructure['chunk_offset_table'][$i] = getid3_lib::BigEndian2Int(substr($atomdata, $stcoEntriesDataOffset, 8));
688
+ $stcoEntriesDataOffset += 8;
689
+ }
690
+ }
691
+ break;
692
+
693
+
694
+ case 'dref': // Data REFerence atom
695
+ $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
696
+ $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3)); // hardcoded: 0x0000
697
+ $atomstructure['number_entries'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 4));
698
+ $drefDataOffset = 8;
699
+ for ($i = 0; $i < $atomstructure['number_entries']; $i++) {
700
+ $atomstructure['data_references'][$i]['size'] = getid3_lib::BigEndian2Int(substr($atomdata, $drefDataOffset, 4));
701
+ $drefDataOffset += 4;
702
+ $atomstructure['data_references'][$i]['type'] = substr($atomdata, $drefDataOffset, 4);
703
+ $drefDataOffset += 4;
704
+ $atomstructure['data_references'][$i]['version'] = getid3_lib::BigEndian2Int(substr($atomdata, $drefDataOffset, 1));
705
+ $drefDataOffset += 1;
706
+ $atomstructure['data_references'][$i]['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, $drefDataOffset, 3)); // hardcoded: 0x0000
707
+ $drefDataOffset += 3;
708
+ $atomstructure['data_references'][$i]['data'] = substr($atomdata, $drefDataOffset, ($atomstructure['data_references'][$i]['size'] - 4 - 4 - 1 - 3));
709
+ $drefDataOffset += ($atomstructure['data_references'][$i]['size'] - 4 - 4 - 1 - 3);
710
+
711
+ $atomstructure['data_references'][$i]['flags']['self_reference'] = (bool) ($atomstructure['data_references'][$i]['flags_raw'] & 0x001);
712
+ }
713
+ break;
714
+
715
+
716
+ case 'gmin': // base Media INformation atom
717
+ $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
718
+ $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3)); // hardcoded: 0x0000
719
+ $atomstructure['graphics_mode'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 2));
720
+ $atomstructure['opcolor_red'] = getid3_lib::BigEndian2Int(substr($atomdata, 6, 2));
721
+ $atomstructure['opcolor_green'] = getid3_lib::BigEndian2Int(substr($atomdata, 8, 2));
722
+ $atomstructure['opcolor_blue'] = getid3_lib::BigEndian2Int(substr($atomdata, 10, 2));
723
+ $atomstructure['balance'] = getid3_lib::BigEndian2Int(substr($atomdata, 12, 2));
724
+ $atomstructure['reserved'] = getid3_lib::BigEndian2Int(substr($atomdata, 14, 2));
725
+ break;
726
+
727
+
728
+ case 'smhd': // Sound Media information HeaDer atom
729
+ $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
730
+ $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3)); // hardcoded: 0x0000
731
+ $atomstructure['balance'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 2));
732
+ $atomstructure['reserved'] = getid3_lib::BigEndian2Int(substr($atomdata, 6, 2));
733
+ break;
734
+
735
+
736
+ case 'vmhd': // Video Media information HeaDer atom
737
+ $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
738
+ $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3));
739
+ $atomstructure['graphics_mode'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 2));
740
+ $atomstructure['opcolor_red'] = getid3_lib::BigEndian2Int(substr($atomdata, 6, 2));
741
+ $atomstructure['opcolor_green'] = getid3_lib::BigEndian2Int(substr($atomdata, 8, 2));
742
+ $atomstructure['opcolor_blue'] = getid3_lib::BigEndian2Int(substr($atomdata, 10, 2));
743
+
744
+ $atomstructure['flags']['no_lean_ahead'] = (bool) ($atomstructure['flags_raw'] & 0x001);
745
+ break;
746
+
747
+
748
+ case 'hdlr': // HanDLeR reference atom
749
+ $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
750
+ $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3)); // hardcoded: 0x0000
751
+ $atomstructure['component_type'] = substr($atomdata, 4, 4);
752
+ $atomstructure['component_subtype'] = substr($atomdata, 8, 4);
753
+ $atomstructure['component_manufacturer'] = substr($atomdata, 12, 4);
754
+ $atomstructure['component_flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 16, 4));
755
+ $atomstructure['component_flags_mask'] = getid3_lib::BigEndian2Int(substr($atomdata, 20, 4));
756
+ $atomstructure['component_name'] = $this->Pascal2String(substr($atomdata, 24));
757
+
758
+ if (($atomstructure['component_subtype'] == 'STpn') && ($atomstructure['component_manufacturer'] == 'zzzz')) {
759
+ $ThisFileInfo['video']['dataformat'] = 'quicktimevr';
760
+ }
761
+ break;
762
+
763
+
764
+ case 'mdhd': // MeDia HeaDer atom
765
+ $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
766
+ $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3)); // hardcoded: 0x0000
767
+ $atomstructure['creation_time'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 4));
768
+ $atomstructure['modify_time'] = getid3_lib::BigEndian2Int(substr($atomdata, 8, 4));
769
+ $atomstructure['time_scale'] = getid3_lib::BigEndian2Int(substr($atomdata, 12, 4));
770
+ $atomstructure['duration'] = getid3_lib::BigEndian2Int(substr($atomdata, 16, 4));
771
+ $atomstructure['language_id'] = getid3_lib::BigEndian2Int(substr($atomdata, 20, 2));
772
+ $atomstructure['quality'] = getid3_lib::BigEndian2Int(substr($atomdata, 22, 2));
773
+
774
+ if ($atomstructure['time_scale'] == 0) {
775
+ $ThisFileInfo['error'][] = 'Corrupt Quicktime file: mdhd.time_scale == zero';
776
+ return false;
777
+ }
778
+ $ThisFileInfo['quicktime']['time_scale'] = max(@$ThisFileInfo['quicktime']['time_scale'], $atomstructure['time_scale']);
779
+
780
+ $atomstructure['creation_time_unix'] = getid3_lib::DateMac2Unix($atomstructure['creation_time']);
781
+ $atomstructure['modify_time_unix'] = getid3_lib::DateMac2Unix($atomstructure['modify_time']);
782
+ $atomstructure['playtime_seconds'] = $atomstructure['duration'] / $atomstructure['time_scale'];
783
+ $atomstructure['language'] = $this->QuicktimeLanguageLookup($atomstructure['language_id']);
784
+ if (empty($ThisFileInfo['comments']['language']) || (!in_array($atomstructure['language'], $ThisFileInfo['comments']['language']))) {
785
+ $ThisFileInfo['comments']['language'][] = $atomstructure['language'];
786
+ }
787
+ break;
788
+
789
+
790
+ case 'pnot': // Preview atom
791
+ $atomstructure['modification_date'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 4)); // "standard Macintosh format"
792
+ $atomstructure['version_number'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 2)); // hardcoded: 0x00
793
+ $atomstructure['atom_type'] = substr($atomdata, 6, 4); // usually: 'PICT'
794
+ $atomstructure['atom_index'] = getid3_lib::BigEndian2Int(substr($atomdata, 10, 2)); // usually: 0x01
795
+
796
+ $atomstructure['modification_date_unix'] = getid3_lib::DateMac2Unix($atomstructure['modification_date']);
797
+ break;
798
+
799
+
800
+ case 'crgn': // Clipping ReGioN atom
801
+ $atomstructure['region_size'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 2)); // The Region size, Region boundary box,
802
+ $atomstructure['boundary_box'] = getid3_lib::BigEndian2Int(substr($atomdata, 2, 8)); // and Clipping region data fields
803
+ $atomstructure['clipping_data'] = substr($atomdata, 10); // constitute a QuickDraw region.
804
+ break;
805
+
806
+
807
+ case 'load': // track LOAD settings atom
808
+ $atomstructure['preload_start_time'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 4));
809
+ $atomstructure['preload_duration'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 4));
810
+ $atomstructure['preload_flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 8, 4));
811
+ $atomstructure['default_hints_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 12, 4));
812
+
813
+ $atomstructure['default_hints']['double_buffer'] = (bool) ($atomstructure['default_hints_raw'] & 0x0020);
814
+ $atomstructure['default_hints']['high_quality'] = (bool) ($atomstructure['default_hints_raw'] & 0x0100);
815
+ break;
816
+
817
+
818
+ case 'tmcd': // TiMe CoDe atom
819
+ case 'chap': // CHAPter list atom
820
+ case 'sync': // SYNChronization atom
821
+ case 'scpt': // tranSCriPT atom
822
+ case 'ssrc': // non-primary SouRCe atom
823
+ for ($i = 0; $i < (strlen($atomdata) % 4); $i++) {
824
+ $atomstructure['track_id'][$i] = getid3_lib::BigEndian2Int(substr($atomdata, $i * 4, 4));
825
+ }
826
+ break;
827
+
828
+
829
+ case 'elst': // Edit LiST atom
830
+ $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
831
+ $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3)); // hardcoded: 0x0000
832
+ $atomstructure['number_entries'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 4));
833
+ for ($i = 0; $i < $atomstructure['number_entries']; $i++ ) {
834
+ $atomstructure['edit_list'][$i]['track_duration'] = getid3_lib::BigEndian2Int(substr($atomdata, 8 + ($i * 12) + 0, 4));
835
+ $atomstructure['edit_list'][$i]['media_time'] = getid3_lib::BigEndian2Int(substr($atomdata, 8 + ($i * 12) + 4, 4));
836
+ $atomstructure['edit_list'][$i]['media_rate'] = getid3_lib::FixedPoint16_16(substr($atomdata, 8 + ($i * 12) + 8, 4));
837
+ }
838
+ break;
839
+
840
+
841
+ case 'kmat': // compressed MATte atom
842
+ $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
843
+ $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3)); // hardcoded: 0x0000
844
+ $atomstructure['matte_data_raw'] = substr($atomdata, 4);
845
+ break;
846
+
847
+
848
+ case 'ctab': // Color TABle atom
849
+ $atomstructure['color_table_seed'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 4)); // hardcoded: 0x00000000
850
+ $atomstructure['color_table_flags'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 2)); // hardcoded: 0x8000
851
+ $atomstructure['color_table_size'] = getid3_lib::BigEndian2Int(substr($atomdata, 6, 2)) + 1;
852
+ for ($colortableentry = 0; $colortableentry < $atomstructure['color_table_size']; $colortableentry++) {
853
+ $atomstructure['color_table'][$colortableentry]['alpha'] = getid3_lib::BigEndian2Int(substr($atomdata, 8 + ($colortableentry * 8) + 0, 2));
854
+ $atomstructure['color_table'][$colortableentry]['red'] = getid3_lib::BigEndian2Int(substr($atomdata, 8 + ($colortableentry * 8) + 2, 2));
855
+ $atomstructure['color_table'][$colortableentry]['green'] = getid3_lib::BigEndian2Int(substr($atomdata, 8 + ($colortableentry * 8) + 4, 2));
856
+ $atomstructure['color_table'][$colortableentry]['blue'] = getid3_lib::BigEndian2Int(substr($atomdata, 8 + ($colortableentry * 8) + 6, 2));
857
+ }
858
+ break;
859
+
860
+
861
+ case 'mvhd': // MoVie HeaDer atom
862
+ $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
863
+ $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3));
864
+ $atomstructure['creation_time'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 4));
865
+ $atomstructure['modify_time'] = getid3_lib::BigEndian2Int(substr($atomdata, 8, 4));
866
+ $atomstructure['time_scale'] = getid3_lib::BigEndian2Int(substr($atomdata, 12, 4));
867
+ $atomstructure['duration'] = getid3_lib::BigEndian2Int(substr($atomdata, 16, 4));
868
+ $atomstructure['preferred_rate'] = getid3_lib::FixedPoint16_16(substr($atomdata, 20, 4));
869
+ $atomstructure['preferred_volume'] = getid3_lib::FixedPoint8_8(substr($atomdata, 24, 2));
870
+ $atomstructure['reserved'] = substr($atomdata, 26, 10);
871
+ $atomstructure['matrix_a'] = getid3_lib::FixedPoint16_16(substr($atomdata, 36, 4));
872
+ $atomstructure['matrix_b'] = getid3_lib::FixedPoint16_16(substr($atomdata, 40, 4));
873
+ $atomstructure['matrix_u'] = getid3_lib::FixedPoint2_30(substr($atomdata, 44, 4));
874
+ $atomstructure['matrix_c'] = getid3_lib::FixedPoint16_16(substr($atomdata, 48, 4));
875
+ $atomstructure['matrix_d'] = getid3_lib::FixedPoint16_16(substr($atomdata, 52, 4));
876
+ $atomstructure['matrix_v'] = getid3_lib::FixedPoint2_30(substr($atomdata, 56, 4));
877
+ $atomstructure['matrix_x'] = getid3_lib::FixedPoint16_16(substr($atomdata, 60, 4));
878
+ $atomstructure['matrix_y'] = getid3_lib::FixedPoint16_16(substr($atomdata, 64, 4));
879
+ $atomstructure['matrix_w'] = getid3_lib::FixedPoint2_30(substr($atomdata, 68, 4));
880
+ $atomstructure['preview_time'] = getid3_lib::BigEndian2Int(substr($atomdata, 72, 4));
881
+ $atomstructure['preview_duration'] = getid3_lib::BigEndian2Int(substr($atomdata, 76, 4));
882
+ $atomstructure['poster_time'] = getid3_lib::BigEndian2Int(substr($atomdata, 80, 4));
883
+ $atomstructure['selection_time'] = getid3_lib::BigEndian2Int(substr($atomdata, 84, 4));
884
+ $atomstructure['selection_duration'] = getid3_lib::BigEndian2Int(substr($atomdata, 88, 4));
885
+ $atomstructure['current_time'] = getid3_lib::BigEndian2Int(substr($atomdata, 92, 4));
886
+ $atomstructure['next_track_id'] = getid3_lib::BigEndian2Int(substr($atomdata, 96, 4));
887
+
888
+ if ($atomstructure['time_scale'] == 0) {
889
+ $ThisFileInfo['error'][] = 'Corrupt Quicktime file: mvhd.time_scale == zero';
890
+ return false;
891
+ }
892
+ $atomstructure['creation_time_unix'] = getid3_lib::DateMac2Unix($atomstructure['creation_time']);
893
+ $atomstructure['modify_time_unix'] = getid3_lib::DateMac2Unix($atomstructure['modify_time']);
894
+ $ThisFileInfo['quicktime']['time_scale'] = max(@$ThisFileInfo['quicktime']['time_scale'], $atomstructure['time_scale']);
895
+ $ThisFileInfo['quicktime']['display_scale'] = $atomstructure['matrix_a'];
896
+ $ThisFileInfo['playtime_seconds'] = $atomstructure['duration'] / $atomstructure['time_scale'];
897
+ break;
898
+
899
+
900
+ case 'tkhd': // TracK HeaDer atom
901
+ $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
902
+ $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3));
903
+ $atomstructure['creation_time'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 4));
904
+ $atomstructure['modify_time'] = getid3_lib::BigEndian2Int(substr($atomdata, 8, 4));
905
+ $atomstructure['trackid'] = getid3_lib::BigEndian2Int(substr($atomdata, 12, 4));
906
+ $atomstructure['reserved1'] = getid3_lib::BigEndian2Int(substr($atomdata, 16, 4));
907
+ $atomstructure['duration'] = getid3_lib::BigEndian2Int(substr($atomdata, 20, 4));
908
+ $atomstructure['reserved2'] = getid3_lib::BigEndian2Int(substr($atomdata, 24, 8));
909
+ $atomstructure['layer'] = getid3_lib::BigEndian2Int(substr($atomdata, 32, 2));
910
+ $atomstructure['alternate_group'] = getid3_lib::BigEndian2Int(substr($atomdata, 34, 2));
911
+ $atomstructure['volume'] = getid3_lib::FixedPoint8_8(substr($atomdata, 36, 2));
912
+ $atomstructure['reserved3'] = getid3_lib::BigEndian2Int(substr($atomdata, 38, 2));
913
+ $atomstructure['matrix_a'] = getid3_lib::FixedPoint16_16(substr($atomdata, 40, 4));
914
+ $atomstructure['matrix_b'] = getid3_lib::FixedPoint16_16(substr($atomdata, 44, 4));
915
+ $atomstructure['matrix_u'] = getid3_lib::FixedPoint16_16(substr($atomdata, 48, 4));
916
+ $atomstructure['matrix_c'] = getid3_lib::FixedPoint16_16(substr($atomdata, 52, 4));
917
+ $atomstructure['matrix_d'] = getid3_lib::FixedPoint16_16(substr($atomdata, 56, 4));
918
+ $atomstructure['matrix_v'] = getid3_lib::FixedPoint16_16(substr($atomdata, 60, 4));
919
+ $atomstructure['matrix_x'] = getid3_lib::FixedPoint2_30(substr($atomdata, 64, 4));
920
+ $atomstructure['matrix_y'] = getid3_lib::FixedPoint2_30(substr($atomdata, 68, 4));
921
+ $atomstructure['matrix_w'] = getid3_lib::FixedPoint2_30(substr($atomdata, 72, 4));
922
+ $atomstructure['width'] = getid3_lib::FixedPoint16_16(substr($atomdata, 76, 4));
923
+ $atomstructure['height'] = getid3_lib::FixedPoint16_16(substr($atomdata, 80, 4));
924
+
925
+ $atomstructure['flags']['enabled'] = (bool) ($atomstructure['flags_raw'] & 0x0001);
926
+ $atomstructure['flags']['in_movie'] = (bool) ($atomstructure['flags_raw'] & 0x0002);
927
+ $atomstructure['flags']['in_preview'] = (bool) ($atomstructure['flags_raw'] & 0x0004);
928
+ $atomstructure['flags']['in_poster'] = (bool) ($atomstructure['flags_raw'] & 0x0008);
929
+ $atomstructure['creation_time_unix'] = getid3_lib::DateMac2Unix($atomstructure['creation_time']);
930
+ $atomstructure['modify_time_unix'] = getid3_lib::DateMac2Unix($atomstructure['modify_time']);
931
+
932
+ if (!isset($ThisFileInfo['video']['resolution_x']) || !isset($ThisFileInfo['video']['resolution_y'])) {
933
+ $ThisFileInfo['video']['resolution_x'] = $atomstructure['width'];
934
+ $ThisFileInfo['video']['resolution_y'] = $atomstructure['height'];
935
+ }
936
+ if ($atomstructure['flags']['enabled'] == 1) {
937
+ $ThisFileInfo['video']['resolution_x'] = max($ThisFileInfo['video']['resolution_x'], $atomstructure['width']);
938
+ $ThisFileInfo['video']['resolution_y'] = max($ThisFileInfo['video']['resolution_y'], $atomstructure['height']);
939
+ }
940
+ if (!empty($ThisFileInfo['video']['resolution_x']) && !empty($ThisFileInfo['video']['resolution_y'])) {
941
+ $ThisFileInfo['quicktime']['video']['resolution_x'] = $ThisFileInfo['video']['resolution_x'];
942
+ $ThisFileInfo['quicktime']['video']['resolution_y'] = $ThisFileInfo['video']['resolution_y'];
943
+ } else {
944
+ unset($ThisFileInfo['video']['resolution_x']);
945
+ unset($ThisFileInfo['video']['resolution_y']);
946
+ unset($ThisFileInfo['quicktime']['video']);
947
+ }
948
+ break;
949
+
950
+
951
+ case 'meta': // METAdata atom
952
+ // http://www.geocities.com/xhelmboyx/quicktime/formats/qti-layout.txt
953
+ $NextTagPosition = strpos($atomdata, '�');
954
+ while ($NextTagPosition < strlen($atomdata)) {
955
+ $metaItemSize = getid3_lib::BigEndian2Int(substr($atomdata, $NextTagPosition - 4, 4)) - 4;
956
+ if ($metaItemSize == -4) {
957
+ break;
958
+ }
959
+ $metaItemRaw = substr($atomdata, $NextTagPosition, $metaItemSize);
960
+ $metaItemKey = substr($metaItemRaw, 0, 4);
961
+ $metaItemData = substr($metaItemRaw, 20);
962
+ $NextTagPosition += $metaItemSize + 4;
963
+
964
+ $this->CopyToAppropriateCommentsSection($metaItemKey, $metaItemData, $ThisFileInfo);
965
+ }
966
+ break;
967
+
968
+ case 'ftyp': // FileTYPe (?) atom (for MP4 it seems)
969
+ $atomstructure['signature'] = substr($atomdata, 0, 4);
970
+ $atomstructure['unknown_1'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 4));
971
+ $atomstructure['fourcc'] = substr($atomdata, 8, 4);
972
+ break;
973
+
974
+ case 'mdat': // Media DATa atom
975
+ case 'free': // FREE space atom
976
+ case 'skip': // SKIP atom
977
+ case 'wide': // 64-bit expansion placeholder atom
978
+ // 'mdat' data is too big to deal with, contains no useful metadata
979
+ // 'free', 'skip' and 'wide' are just padding, contains no useful data at all
980
+
981
+ // When writing QuickTime files, it is sometimes necessary to update an atom's size.
982
+ // It is impossible to update a 32-bit atom to a 64-bit atom since the 32-bit atom
983
+ // is only 8 bytes in size, and the 64-bit atom requires 16 bytes. Therefore, QuickTime
984
+ // puts an 8-byte placeholder atom before any atoms it may have to update the size of.
985
+ // In this way, if the atom needs to be converted from a 32-bit to a 64-bit atom, the
986
+ // placeholder atom can be overwritten to obtain the necessary 8 extra bytes.
987
+ // The placeholder atom has a type of kWideAtomPlaceholderType ( 'wide' ).
988
+ break;
989
+
990
+
991
+ case 'nsav': // NoSAVe atom
992
+ // http://developer.apple.com/technotes/tn/tn2038.html
993
+ $atomstructure['data'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 4));
994
+ break;
995
+
996
+ case 'ctyp': // Controller TYPe atom (seen on QTVR)
997
+ // http://homepages.slingshot.co.nz/~helmboy/quicktime/formats/qtm-layout.txt
998
+ // some controller names are:
999
+ // 0x00 + 'std' for linear movie
1000
+ // 'none' for no controls
1001
+ $atomstructure['ctyp'] = substr($atomdata, 0, 4);
1002
+ switch ($atomstructure['ctyp']) {
1003
+ case 'qtvr':
1004
+ $ThisFileInfo['video']['dataformat'] = 'quicktimevr';
1005
+ break;
1006
+ }
1007
+ break;
1008
+
1009
+ case 'pano': // PANOrama track (seen on QTVR)
1010
+ $atomstructure['pano'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 4));
1011
+ break;
1012
+
1013
+ case 'hint': // HINT track
1014
+ case 'hinf': //
1015
+ case 'hinv': //
1016
+ case 'hnti': //
1017
+ $ThisFileInfo['quicktime']['hinting'] = true;
1018
+ break;
1019
+
1020
+ case 'imgt': // IMaGe Track reference (kQTVRImageTrackRefType) (seen on QTVR)
1021
+ for ($i = 0; $i < ($atomstructure['size'] - 8); $i += 4) {
1022
+ $atomstructure['imgt'][] = getid3_lib::BigEndian2Int(substr($atomdata, $i, 4));
1023
+ }
1024
+ break;
1025
+
1026
+ case 'FXTC': // Something to do with Adobe After Effects (?)
1027
+ case 'PrmA':
1028
+ case 'code':
1029
+ case 'FIEL': // this is NOT "fiel" (Field Ordering) as describe here: http://developer.apple.com/documentation/QuickTime/QTFF/QTFFChap3/chapter_4_section_2.html
1030
+ // Observed-but-not-handled atom types are just listed here
1031
+ // to prevent warnings being generated
1032
+ $atomstructure['data'] = $atomdata;
1033
+ break;
1034
+
1035
+ default:
1036
+ $ThisFileInfo['warning'][] = 'Unknown QuickTime atom type: "'.$atomname.'" at offset '.$baseoffset;
1037
+ $atomstructure['data'] = $atomdata;
1038
+ break;
1039
+ }
1040
+ array_pop($atomHierarchy);
1041
+ return $atomstructure;
1042
+ }
1043
+
1044
+ function QuicktimeParseContainerAtom($atomdata, &$ThisFileInfo, $baseoffset, &$atomHierarchy, $ParseAllPossibleAtoms) {
1045
+ $atomstructure = false;
1046
+ $subatomoffset = 0;
1047
+ $subatomcounter = 0;
1048
+ if ((strlen($atomdata) == 4) && (getid3_lib::BigEndian2Int($atomdata) == 0x00000000)) {
1049
+ return false;
1050
+ }
1051
+ while ($subatomoffset < strlen($atomdata)) {
1052
+ $subatomsize = getid3_lib::BigEndian2Int(substr($atomdata, $subatomoffset + 0, 4));
1053
+ $subatomname = substr($atomdata, $subatomoffset + 4, 4);
1054
+ $subatomdata = substr($atomdata, $subatomoffset + 8, $subatomsize - 8);
1055
+ if ($subatomsize == 0) {
1056
+ // Furthermore, for historical reasons the list of atoms is optionally
1057
+ // terminated by a 32-bit integer set to 0. If you are writing a program
1058
+ // to read user data atoms, you should allow for the terminating 0.
1059
+ return $atomstructure;
1060
+ }
1061
+
1062
+ $atomstructure[$subatomcounter] = $this->QuicktimeParseAtom($subatomname, $subatomsize, $subatomdata, $ThisFileInfo, $baseoffset + $subatomoffset, $atomHierarchy, $ParseAllPossibleAtoms);
1063
+
1064
+ $subatomoffset += $subatomsize;
1065
+ $subatomcounter++;
1066
+ }
1067
+ return $atomstructure;
1068
+ }
1069
+
1070
+
1071
+ function QuicktimeLanguageLookup($languageid) {
1072
+ static $QuicktimeLanguageLookup = array();
1073
+ if (empty($QuicktimeLanguageLookup)) {
1074
+ $QuicktimeLanguageLookup[0] = 'English';
1075
+ $QuicktimeLanguageLookup[1] = 'French';
1076
+ $QuicktimeLanguageLookup[2] = 'German';
1077
+ $QuicktimeLanguageLookup[3] = 'Italian';
1078
+ $QuicktimeLanguageLookup[4] = 'Dutch';
1079
+ $QuicktimeLanguageLookup[5] = 'Swedish';
1080
+ $QuicktimeLanguageLookup[6] = 'Spanish';
1081
+ $QuicktimeLanguageLookup[7] = 'Danish';
1082
+ $QuicktimeLanguageLookup[8] = 'Portuguese';
1083
+ $QuicktimeLanguageLookup[9] = 'Norwegian';
1084
+ $QuicktimeLanguageLookup[10] = 'Hebrew';
1085
+ $QuicktimeLanguageLookup[11] = 'Japanese';
1086
+ $QuicktimeLanguageLookup[12] = 'Arabic';
1087
+ $QuicktimeLanguageLookup[13] = 'Finnish';
1088
+ $QuicktimeLanguageLookup[14] = 'Greek';
1089
+ $QuicktimeLanguageLookup[15] = 'Icelandic';
1090
+ $QuicktimeLanguageLookup[16] = 'Maltese';
1091
+ $QuicktimeLanguageLookup[17] = 'Turkish';
1092
+ $QuicktimeLanguageLookup[18] = 'Croatian';
1093
+ $QuicktimeLanguageLookup[19] = 'Chinese (Traditional)';
1094
+ $QuicktimeLanguageLookup[20] = 'Urdu';
1095
+ $QuicktimeLanguageLookup[21] = 'Hindi';
1096
+ $QuicktimeLanguageLookup[22] = 'Thai';
1097
+ $QuicktimeLanguageLookup[23] = 'Korean';
1098
+ $QuicktimeLanguageLookup[24] = 'Lithuanian';
1099
+ $QuicktimeLanguageLookup[25] = 'Polish';
1100
+ $QuicktimeLanguageLookup[26] = 'Hungarian';
1101
+ $QuicktimeLanguageLookup[27] = 'Estonian';
1102
+ $QuicktimeLanguageLookup[28] = 'Lettish';
1103
+ $QuicktimeLanguageLookup[28] = 'Latvian';
1104
+ $QuicktimeLanguageLookup[29] = 'Saamisk';
1105
+ $QuicktimeLanguageLookup[29] = 'Lappish';
1106
+ $QuicktimeLanguageLookup[30] = 'Faeroese';
1107
+ $QuicktimeLanguageLookup[31] = 'Farsi';
1108
+ $QuicktimeLanguageLookup[31] = 'Persian';
1109
+ $QuicktimeLanguageLookup[32] = 'Russian';
1110
+ $QuicktimeLanguageLookup[33] = 'Chinese (Simplified)';
1111
+ $QuicktimeLanguageLookup[34] = 'Flemish';
1112
+ $QuicktimeLanguageLookup[35] = 'Irish';
1113
+ $QuicktimeLanguageLookup[36] = 'Albanian';
1114
+ $QuicktimeLanguageLookup[37] = 'Romanian';
1115
+ $QuicktimeLanguageLookup[38] = 'Czech';
1116
+ $QuicktimeLanguageLookup[39] = 'Slovak';
1117
+ $QuicktimeLanguageLookup[40] = 'Slovenian';
1118
+ $QuicktimeLanguageLookup[41] = 'Yiddish';
1119
+ $QuicktimeLanguageLookup[42] = 'Serbian';
1120
+ $QuicktimeLanguageLookup[43] = 'Macedonian';
1121
+ $QuicktimeLanguageLookup[44] = 'Bulgarian';
1122
+ $QuicktimeLanguageLookup[45] = 'Ukrainian';
1123
+ $QuicktimeLanguageLookup[46] = 'Byelorussian';
1124
+ $QuicktimeLanguageLookup[47] = 'Uzbek';
1125
+ $QuicktimeLanguageLookup[48] = 'Kazakh';
1126
+ $QuicktimeLanguageLookup[49] = 'Azerbaijani';
1127
+ $QuicktimeLanguageLookup[50] = 'AzerbaijanAr';
1128
+ $QuicktimeLanguageLookup[51] = 'Armenian';
1129
+ $QuicktimeLanguageLookup[52] = 'Georgian';
1130
+ $QuicktimeLanguageLookup[53] = 'Moldavian';
1131
+ $QuicktimeLanguageLookup[54] = 'Kirghiz';
1132
+ $QuicktimeLanguageLookup[55] = 'Tajiki';
1133
+ $QuicktimeLanguageLookup[56] = 'Turkmen';
1134
+ $QuicktimeLanguageLookup[57] = 'Mongolian';
1135
+ $QuicktimeLanguageLookup[58] = 'MongolianCyr';
1136
+ $QuicktimeLanguageLookup[59] = 'Pashto';
1137
+ $QuicktimeLanguageLookup[60] = 'Kurdish';
1138
+ $QuicktimeLanguageLookup[61] = 'Kashmiri';
1139
+ $QuicktimeLanguageLookup[62] = 'Sindhi';
1140
+ $QuicktimeLanguageLookup[63] = 'Tibetan';
1141
+ $QuicktimeLanguageLookup[64] = 'Nepali';
1142
+ $QuicktimeLanguageLookup[65] = 'Sanskrit';
1143
+ $QuicktimeLanguageLookup[66] = 'Marathi';
1144
+ $QuicktimeLanguageLookup[67] = 'Bengali';
1145
+ $QuicktimeLanguageLookup[68] = 'Assamese';
1146
+ $QuicktimeLanguageLookup[69] = 'Gujarati';
1147
+ $QuicktimeLanguageLookup[70] = 'Punjabi';
1148
+ $QuicktimeLanguageLookup[71] = 'Oriya';
1149
+ $QuicktimeLanguageLookup[72] = 'Malayalam';
1150
+ $QuicktimeLanguageLookup[73] = 'Kannada';
1151
+ $QuicktimeLanguageLookup[74] = 'Tamil';
1152
+ $QuicktimeLanguageLookup[75] = 'Telugu';
1153
+ $QuicktimeLanguageLookup[76] = 'Sinhalese';
1154
+ $QuicktimeLanguageLookup[77] = 'Burmese';
1155
+ $QuicktimeLanguageLookup[78] = 'Khmer';
1156
+ $QuicktimeLanguageLookup[79] = 'Lao';
1157
+ $QuicktimeLanguageLookup[80] = 'Vietnamese';
1158
+ $QuicktimeLanguageLookup[81] = 'Indonesian';
1159
+ $QuicktimeLanguageLookup[82] = 'Tagalog';
1160
+ $QuicktimeLanguageLookup[83] = 'MalayRoman';
1161
+ $QuicktimeLanguageLookup[84] = 'MalayArabic';
1162
+ $QuicktimeLanguageLookup[85] = 'Amharic';
1163
+ $QuicktimeLanguageLookup[86] = 'Tigrinya';
1164
+ $QuicktimeLanguageLookup[87] = 'Galla';
1165
+ $QuicktimeLanguageLookup[87] = 'Oromo';
1166
+ $QuicktimeLanguageLookup[88] = 'Somali';
1167
+ $QuicktimeLanguageLookup[89] = 'Swahili';
1168
+ $QuicktimeLanguageLookup[90] = 'Ruanda';
1169
+ $QuicktimeLanguageLookup[91] = 'Rundi';
1170
+ $QuicktimeLanguageLookup[92] = 'Chewa';
1171
+ $QuicktimeLanguageLookup[93] = 'Malagasy';
1172
+ $QuicktimeLanguageLookup[94] = 'Esperanto';
1173
+ $QuicktimeLanguageLookup[128] = 'Welsh';
1174
+ $QuicktimeLanguageLookup[129] = 'Basque';
1175
+ $QuicktimeLanguageLookup[130] = 'Catalan';
1176
+ $QuicktimeLanguageLookup[131] = 'Latin';
1177
+ $QuicktimeLanguageLookup[132] = 'Quechua';
1178
+ $QuicktimeLanguageLookup[133] = 'Guarani';
1179
+ $QuicktimeLanguageLookup[134] = 'Aymara';
1180
+ $QuicktimeLanguageLookup[135] = 'Tatar';
1181
+ $QuicktimeLanguageLookup[136] = 'Uighur';
1182
+ $QuicktimeLanguageLookup[137] = 'Dzongkha';
1183
+ $QuicktimeLanguageLookup[138] = 'JavaneseRom';
1184
+ }
1185
+ return (isset($QuicktimeLanguageLookup[$languageid]) ? $QuicktimeLanguageLookup[$languageid] : 'invalid');
1186
+ }
1187
+
1188
+ function QuicktimeVideoCodecLookup($codecid) {
1189
+ static $QuicktimeVideoCodecLookup = array();
1190
+ if (empty($QuicktimeVideoCodecLookup)) {
1191
+ $QuicktimeVideoCodecLookup['3IVX'] = '3ivx MPEG-4';
1192
+ $QuicktimeVideoCodecLookup['3IV1'] = '3ivx MPEG-4 v1';
1193
+ $QuicktimeVideoCodecLookup['3IV2'] = '3ivx MPEG-4 v2';
1194
+ $QuicktimeVideoCodecLookup['avr '] = 'AVR-JPEG';
1195
+ $QuicktimeVideoCodecLookup['base'] = 'Base';
1196
+ $QuicktimeVideoCodecLookup['WRLE'] = 'BMP';
1197
+ $QuicktimeVideoCodecLookup['cvid'] = 'Cinepak';
1198
+ $QuicktimeVideoCodecLookup['clou'] = 'Cloud';
1199
+ $QuicktimeVideoCodecLookup['cmyk'] = 'CMYK';
1200
+ $QuicktimeVideoCodecLookup['yuv2'] = 'ComponentVideo';
1201
+ $QuicktimeVideoCodecLookup['yuvu'] = 'ComponentVideoSigned';
1202
+ $QuicktimeVideoCodecLookup['yuvs'] = 'ComponentVideoUnsigned';
1203
+ $QuicktimeVideoCodecLookup['dvc '] = 'DVC-NTSC';
1204
+ $QuicktimeVideoCodecLookup['dvcp'] = 'DVC-PAL';
1205
+ $QuicktimeVideoCodecLookup['dvpn'] = 'DVCPro-NTSC';
1206
+ $QuicktimeVideoCodecLookup['dvpp'] = 'DVCPro-PAL';
1207
+ $QuicktimeVideoCodecLookup['fire'] = 'Fire';
1208
+ $QuicktimeVideoCodecLookup['flic'] = 'FLC';
1209
+ $QuicktimeVideoCodecLookup['b48r'] = '48RGB';
1210
+ $QuicktimeVideoCodecLookup['gif '] = 'GIF';
1211
+ $QuicktimeVideoCodecLookup['smc '] = 'Graphics';
1212
+ $QuicktimeVideoCodecLookup['h261'] = 'H261';
1213
+ $QuicktimeVideoCodecLookup['h263'] = 'H263';
1214
+ $QuicktimeVideoCodecLookup['IV41'] = 'Indeo4';
1215
+ $QuicktimeVideoCodecLookup['jpeg'] = 'JPEG';
1216
+ $QuicktimeVideoCodecLookup['PNTG'] = 'MacPaint';
1217
+ $QuicktimeVideoCodecLookup['msvc'] = 'Microsoft Video1';
1218
+ $QuicktimeVideoCodecLookup['mjpa'] = 'Motion JPEG-A';
1219
+ $QuicktimeVideoCodecLookup['mjpb'] = 'Motion JPEG-B';
1220
+ $QuicktimeVideoCodecLookup['myuv'] = 'MPEG YUV420';
1221
+ $QuicktimeVideoCodecLookup['dmb1'] = 'OpenDML JPEG';
1222
+ $QuicktimeVideoCodecLookup['kpcd'] = 'PhotoCD';
1223
+ $QuicktimeVideoCodecLookup['8BPS'] = 'Planar RGB';
1224
+ $QuicktimeVideoCodecLookup['png '] = 'PNG';
1225
+ $QuicktimeVideoCodecLookup['qdrw'] = 'QuickDraw';
1226
+ $QuicktimeVideoCodecLookup['qdgx'] = 'QuickDrawGX';
1227
+ $QuicktimeVideoCodecLookup['raw '] = 'RAW';
1228
+ $QuicktimeVideoCodecLookup['.SGI'] = 'SGI';
1229
+ $QuicktimeVideoCodecLookup['b16g'] = '16Gray';
1230
+ $QuicktimeVideoCodecLookup['b64a'] = '64ARGB';
1231
+ $QuicktimeVideoCodecLookup['SVQ1'] = 'Sorenson Video 1';
1232
+ $QuicktimeVideoCodecLookup['SVQ1'] = 'Sorenson Video 3';
1233
+ $QuicktimeVideoCodecLookup['syv9'] = 'Sorenson YUV9';
1234
+ $QuicktimeVideoCodecLookup['tga '] = 'Targa';
1235
+ $QuicktimeVideoCodecLookup['b32a'] = '32AlphaGray';
1236
+ $QuicktimeVideoCodecLookup['tiff'] = 'TIFF';
1237
+ $QuicktimeVideoCodecLookup['path'] = 'Vector';
1238
+ $QuicktimeVideoCodecLookup['rpza'] = 'Video';
1239
+ $QuicktimeVideoCodecLookup['ripl'] = 'WaterRipple';
1240
+ $QuicktimeVideoCodecLookup['WRAW'] = 'Windows RAW';
1241
+ $QuicktimeVideoCodecLookup['y420'] = 'YUV420';
1242
+ }
1243
+ return (isset($QuicktimeVideoCodecLookup[$codecid]) ? $QuicktimeVideoCodecLookup[$codecid] : '');
1244
+ }
1245
+
1246
+ function QuicktimeAudioCodecLookup($codecid) {
1247
+ static $QuicktimeAudioCodecLookup = array();
1248
+ if (empty($QuicktimeAudioCodecLookup)) {
1249
+ $QuicktimeAudioCodecLookup['.mp3'] = 'Fraunhofer MPEG Layer-III alias';
1250
+ $QuicktimeAudioCodecLookup['aac '] = 'ISO/IEC 14496-3 AAC';
1251
+ $QuicktimeAudioCodecLookup['agsm'] = 'Apple GSM 10:1';
1252
+ $QuicktimeAudioCodecLookup['alac'] = 'Apple Lossless Audio Codec';
1253
+ $QuicktimeAudioCodecLookup['alaw'] = 'A-law 2:1';
1254
+ $QuicktimeAudioCodecLookup['conv'] = 'Sample Format';
1255
+ $QuicktimeAudioCodecLookup['dvca'] = 'DV';
1256
+ $QuicktimeAudioCodecLookup['dvi '] = 'DV 4:1';
1257
+ $QuicktimeAudioCodecLookup['eqal'] = 'Frequency Equalizer';
1258
+ $QuicktimeAudioCodecLookup['fl32'] = '32-bit Floating Point';
1259
+ $QuicktimeAudioCodecLookup['fl64'] = '64-bit Floating Point';
1260
+ $QuicktimeAudioCodecLookup['ima4'] = 'Interactive Multimedia Association 4:1';
1261
+ $QuicktimeAudioCodecLookup['in24'] = '24-bit Integer';
1262
+ $QuicktimeAudioCodecLookup['in32'] = '32-bit Integer';
1263
+ $QuicktimeAudioCodecLookup['lpc '] = 'LPC 23:1';
1264
+ $QuicktimeAudioCodecLookup['MAC3'] = 'Macintosh Audio Compression/Expansion (MACE) 3:1';
1265
+ $QuicktimeAudioCodecLookup['MAC6'] = 'Macintosh Audio Compression/Expansion (MACE) 6:1';
1266
+ $QuicktimeAudioCodecLookup['mixb'] = '8-bit Mixer';
1267
+ $QuicktimeAudioCodecLookup['mixw'] = '16-bit Mixer';
1268
+ $QuicktimeAudioCodecLookup['mp4a'] = 'ISO/IEC 14496-3 AAC';
1269
+ $QuicktimeAudioCodecLookup['MS'."\x00\x02"] = 'Microsoft ADPCM';
1270
+ $QuicktimeAudioCodecLookup['MS'."\x00\x11"] = 'DV IMA';
1271
+ $QuicktimeAudioCodecLookup['MS'."\x00\x55"] = 'Fraunhofer MPEG Layer III';
1272
+ $QuicktimeAudioCodecLookup['NONE'] = 'No Encoding';
1273
+ $QuicktimeAudioCodecLookup['Qclp'] = 'Qualcomm PureVoice';
1274
+ $QuicktimeAudioCodecLookup['QDM2'] = 'QDesign Music 2';
1275
+ $QuicktimeAudioCodecLookup['QDMC'] = 'QDesign Music 1';
1276
+ $QuicktimeAudioCodecLookup['ratb'] = '8-bit Rate';
1277
+ $QuicktimeAudioCodecLookup['ratw'] = '16-bit Rate';
1278
+ $QuicktimeAudioCodecLookup['raw '] = 'raw PCM';
1279
+ $QuicktimeAudioCodecLookup['sour'] = 'Sound Source';
1280
+ $QuicktimeAudioCodecLookup['sowt'] = 'signed/two\'s complement (Little Endian)';
1281
+ $QuicktimeAudioCodecLookup['str1'] = 'Iomega MPEG layer II';
1282
+ $QuicktimeAudioCodecLookup['str2'] = 'Iomega MPEG *layer II';
1283
+ $QuicktimeAudioCodecLookup['str3'] = 'Iomega MPEG **layer II';
1284
+ $QuicktimeAudioCodecLookup['str4'] = 'Iomega MPEG ***layer II';
1285
+ $QuicktimeAudioCodecLookup['twos'] = 'signed/two\'s complement (Big Endian)';
1286
+ $QuicktimeAudioCodecLookup['ulaw'] = 'mu-law 2:1';
1287
+ }
1288
+ return (isset($QuicktimeAudioCodecLookup[$codecid]) ? $QuicktimeAudioCodecLookup[$codecid] : '');
1289
+ }
1290
+
1291
+ function QuicktimeDCOMLookup($compressionid) {
1292
+ static $QuicktimeDCOMLookup = array();
1293
+ if (empty($QuicktimeDCOMLookup)) {
1294
+ $QuicktimeDCOMLookup['zlib'] = 'ZLib Deflate';
1295
+ $QuicktimeDCOMLookup['adec'] = 'Apple Compression';
1296
+ }
1297
+ return (isset($QuicktimeDCOMLookup[$compressionid]) ? $QuicktimeDCOMLookup[$compressionid] : '');
1298
+ }
1299
+
1300
+ function QuicktimeColorNameLookup($colordepthid) {
1301
+ static $QuicktimeColorNameLookup = array();
1302
+ if (empty($QuicktimeColorNameLookup)) {
1303
+ $QuicktimeColorNameLookup[1] = '2-color (monochrome)';
1304
+ $QuicktimeColorNameLookup[2] = '4-color';
1305
+ $QuicktimeColorNameLookup[4] = '16-color';
1306
+ $QuicktimeColorNameLookup[8] = '256-color';
1307
+ $QuicktimeColorNameLookup[16] = 'thousands (16-bit color)';
1308
+ $QuicktimeColorNameLookup[24] = 'millions (24-bit color)';
1309
+ $QuicktimeColorNameLookup[32] = 'millions+ (32-bit color)';
1310
+ $QuicktimeColorNameLookup[33] = 'black & white';
1311
+ $QuicktimeColorNameLookup[34] = '4-gray';
1312
+ $QuicktimeColorNameLookup[36] = '16-gray';
1313
+ $QuicktimeColorNameLookup[40] = '256-gray';
1314
+ }
1315
+ return (isset($QuicktimeColorNameLookup[$colordepthid]) ? $QuicktimeColorNameLookup[$colordepthid] : 'invalid');
1316
+ }
1317
+
1318
+ function CopyToAppropriateCommentsSection($keyname, $data, &$ThisFileInfo) {
1319
+ static $handyatomtranslatorarray = array();
1320
+ if (empty($handyatomtranslatorarray)) {
1321
+ $handyatomtranslatorarray['�cpy'] = 'copyright';
1322
+ $handyatomtranslatorarray['�day'] = 'creation_date';
1323
+ $handyatomtranslatorarray['�dir'] = 'director';
1324
+ $handyatomtranslatorarray['�ed1'] = 'edit1';
1325
+ $handyatomtranslatorarray['�ed2'] = 'edit2';
1326
+ $handyatomtranslatorarray['�ed3'] = 'edit3';
1327
+ $handyatomtranslatorarray['�ed4'] = 'edit4';
1328
+ $handyatomtranslatorarray['�ed5'] = 'edit5';
1329
+ $handyatomtranslatorarray['�ed6'] = 'edit6';
1330
+ $handyatomtranslatorarray['�ed7'] = 'edit7';
1331
+ $handyatomtranslatorarray['�ed8'] = 'edit8';
1332
+ $handyatomtranslatorarray['�ed9'] = 'edit9';
1333
+ $handyatomtranslatorarray['�fmt'] = 'format';
1334
+ $handyatomtranslatorarray['�inf'] = 'information';
1335
+ $handyatomtranslatorarray['�prd'] = 'producer';
1336
+ $handyatomtranslatorarray['�prf'] = 'performers';
1337
+ $handyatomtranslatorarray['�req'] = 'system_requirements';
1338
+ $handyatomtranslatorarray['�src'] = 'source_credit';
1339
+ $handyatomtranslatorarray['�wrt'] = 'writer';
1340
+
1341
+ // http://www.geocities.com/xhelmboyx/quicktime/formats/qtm-layout.txt
1342
+ $handyatomtranslatorarray['�nam'] = 'title';
1343
+ $handyatomtranslatorarray['�cmt'] = 'comment';
1344
+ $handyatomtranslatorarray['�wrn'] = 'warning';
1345
+ $handyatomtranslatorarray['�hst'] = 'host_computer';
1346
+ $handyatomtranslatorarray['�mak'] = 'make';
1347
+ $handyatomtranslatorarray['�mod'] = 'model';
1348
+ $handyatomtranslatorarray['�PRD'] = 'product';
1349
+ $handyatomtranslatorarray['�swr'] = 'software';
1350
+ $handyatomtranslatorarray['�aut'] = 'author';
1351
+ $handyatomtranslatorarray['�ART'] = 'artist';
1352
+ $handyatomtranslatorarray['�trk'] = 'track';
1353
+ $handyatomtranslatorarray['�alb'] = 'album';
1354
+ $handyatomtranslatorarray['�com'] = 'comment';
1355
+ $handyatomtranslatorarray['�gen'] = 'genre';
1356
+ $handyatomtranslatorarray['�ope'] = 'composer';
1357
+ $handyatomtranslatorarray['�url'] = 'url';
1358
+ $handyatomtranslatorarray['�enc'] = 'encoder';
1359
+ }
1360
+ if (isset($handyatomtranslatorarray[$keyname])) {
1361
+ $ThisFileInfo['quicktime']['comments'][$handyatomtranslatorarray[$keyname]][] = $data;
1362
+ }
1363
+
1364
+ return true;
1365
+ }
1366
+
1367
+ function NoNullString($nullterminatedstring) {
1368
+ // remove the single null terminator on null terminated strings
1369
+ if (substr($nullterminatedstring, strlen($nullterminatedstring) - 1, 1) === "\x00") {
1370
+ return substr($nullterminatedstring, 0, strlen($nullterminatedstring) - 1);
1371
+ }
1372
+ return $nullterminatedstring;
1373
+ }
1374
+
1375
+ function Pascal2String($pascalstring) {
1376
+ // Pascal strings have 1 unsigned byte at the beginning saying how many chars (1-255) are in the string
1377
+ return substr($pascalstring, 1);
1378
+ }
1379
+
1380
+ }
1381
+
1382
+ ?>
view/getid3/module.audio-video.real.php ADDED
@@ -0,0 +1,528 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /////////////////////////////////////////////////////////////////
3
+ /// getID3() by James Heinrich <info@getid3.org> //
4
+ // available at http://getid3.sourceforge.net //
5
+ // or http://www.getid3.org //
6
+ /////////////////////////////////////////////////////////////////
7
+ // See readme.txt for more details //
8
+ /////////////////////////////////////////////////////////////////
9
+ // //
10
+ // module.audio-video.real.php //
11
+ // module for analyzing Real Audio/Video files //
12
+ // dependencies: module.audio-video.riff.php //
13
+ // ///
14
+ /////////////////////////////////////////////////////////////////
15
+
16
+ getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true);
17
+
18
+ class getid3_real
19
+ {
20
+
21
+ function getid3_real(&$fd, &$ThisFileInfo) {
22
+ $ThisFileInfo['fileformat'] = 'real';
23
+ $ThisFileInfo['bitrate'] = 0;
24
+ $ThisFileInfo['playtime_seconds'] = 0;
25
+
26
+ fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
27
+ $ChunkCounter = 0;
28
+ while (ftell($fd) < $ThisFileInfo['avdataend']) {
29
+ $ChunkData = fread($fd, 8);
30
+ $ChunkName = substr($ChunkData, 0, 4);
31
+ $ChunkSize = getid3_lib::BigEndian2Int(substr($ChunkData, 4, 4));
32
+
33
+ if ($ChunkName == '.ra'."\xFD") {
34
+ $ChunkData .= fread($fd, $ChunkSize - 8);
35
+ if ($this->ParseOldRAheader(substr($ChunkData, 0, 128), $ThisFileInfo['real']['old_ra_header'])) {
36
+ $ThisFileInfo['audio']['dataformat'] = 'real';
37
+ $ThisFileInfo['audio']['lossless'] = false;
38
+ $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['real']['old_ra_header']['sample_rate'];
39
+ $ThisFileInfo['audio']['bits_per_sample'] = $ThisFileInfo['real']['old_ra_header']['bits_per_sample'];
40
+ $ThisFileInfo['audio']['channels'] = $ThisFileInfo['real']['old_ra_header']['channels'];
41
+
42
+ $ThisFileInfo['playtime_seconds'] = 60 * ($ThisFileInfo['real']['old_ra_header']['audio_bytes'] / $ThisFileInfo['real']['old_ra_header']['bytes_per_minute']);
43
+ $ThisFileInfo['audio']['bitrate'] = 8 * ($ThisFileInfo['real']['old_ra_header']['audio_bytes'] / $ThisFileInfo['playtime_seconds']);
44
+ $ThisFileInfo['audio']['codec'] = $this->RealAudioCodecFourCClookup($ThisFileInfo['real']['old_ra_header']['fourcc'], $ThisFileInfo['audio']['bitrate']);
45
+
46
+ foreach ($ThisFileInfo['real']['old_ra_header']['comments'] as $key => $valuearray) {
47
+ if (strlen(trim($valuearray[0])) > 0) {
48
+ $ThisFileInfo['real']['comments'][$key][] = trim($valuearray[0]);
49
+ }
50
+ }
51
+ return true;
52
+ }
53
+ $ThisFileInfo['error'][] = 'There was a problem parsing this RealAudio file. Please submit it for analysis to http://www.getid3.org/upload/ or info@getid3.org';
54
+ unset($ThisFileInfo['bitrate']);
55
+ unset($ThisFileInfo['playtime_seconds']);
56
+ return false;
57
+ }
58
+
59
+ // shortcut
60
+ $ThisFileInfo['real']['chunks'][$ChunkCounter] = array();
61
+ $thisfile_real_chunks_currentchunk = &$ThisFileInfo['real']['chunks'][$ChunkCounter];
62
+
63
+ $thisfile_real_chunks_currentchunk['name'] = $ChunkName;
64
+ $thisfile_real_chunks_currentchunk['offset'] = ftell($fd) - 8;
65
+ $thisfile_real_chunks_currentchunk['length'] = $ChunkSize;
66
+ if (($thisfile_real_chunks_currentchunk['offset'] + $thisfile_real_chunks_currentchunk['length']) > $ThisFileInfo['avdataend']) {
67
+ $ThisFileInfo['warning'][] = 'Chunk "'.$thisfile_real_chunks_currentchunk['name'].'" at offset '.$thisfile_real_chunks_currentchunk['offset'].' claims to be '.$thisfile_real_chunks_currentchunk['length'].' bytes long, which is beyond end of file';
68
+ return false;
69
+ }
70
+
71
+ if ($ChunkSize > (GETID3_FREAD_BUFFER_SIZE + 8)) {
72
+
73
+ $ChunkData .= fread($fd, GETID3_FREAD_BUFFER_SIZE - 8);
74
+ fseek($fd, $thisfile_real_chunks_currentchunk['offset'] + $ChunkSize, SEEK_SET);
75
+
76
+ } elseif(($ChunkSize - 8) > 0) {
77
+
78
+ $ChunkData .= fread($fd, $ChunkSize - 8);
79
+
80
+ }
81
+ $offset = 8;
82
+
83
+ switch ($ChunkName) {
84
+
85
+ case '.RMF': // RealMedia File Header
86
+ $thisfile_real_chunks_currentchunk['object_version'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2));
87
+ $offset += 2;
88
+ switch ($thisfile_real_chunks_currentchunk['object_version']) {
89
+
90
+ case 0:
91
+ $thisfile_real_chunks_currentchunk['file_version'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4));
92
+ $offset += 4;
93
+ $thisfile_real_chunks_currentchunk['headers_count'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4));
94
+ $offset += 4;
95
+ break;
96
+
97
+ default:
98
+ //$ThisFileInfo['warning'][] = 'Expected .RMF-object_version to be "0", actual value is "'.$thisfile_real_chunks_currentchunk['object_version'].'" (should not be a problem)';
99
+ break;
100
+
101
+ }
102
+ break;
103
+
104
+
105
+ case 'PROP': // Properties Header
106
+ $thisfile_real_chunks_currentchunk['object_version'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2));
107
+ $offset += 2;
108
+ if ($thisfile_real_chunks_currentchunk['object_version'] == 0) {
109
+ $thisfile_real_chunks_currentchunk['max_bit_rate'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4));
110
+ $offset += 4;
111
+ $thisfile_real_chunks_currentchunk['avg_bit_rate'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4));
112
+ $offset += 4;
113
+ $thisfile_real_chunks_currentchunk['max_packet_size'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4));
114
+ $offset += 4;
115
+ $thisfile_real_chunks_currentchunk['avg_packet_size'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4));
116
+ $offset += 4;
117
+ $thisfile_real_chunks_currentchunk['num_packets'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4));
118
+ $offset += 4;
119
+ $thisfile_real_chunks_currentchunk['duration'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4));
120
+ $offset += 4;
121
+ $thisfile_real_chunks_currentchunk['preroll'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4));
122
+ $offset += 4;
123
+ $thisfile_real_chunks_currentchunk['index_offset'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4));
124
+ $offset += 4;
125
+ $thisfile_real_chunks_currentchunk['data_offset'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4));
126
+ $offset += 4;
127
+ $thisfile_real_chunks_currentchunk['num_streams'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2));
128
+ $offset += 2;
129
+ $thisfile_real_chunks_currentchunk['flags_raw'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2));
130
+ $offset += 2;
131
+ $ThisFileInfo['playtime_seconds'] = $thisfile_real_chunks_currentchunk['duration'] / 1000;
132
+ if ($thisfile_real_chunks_currentchunk['duration'] > 0) {
133
+ $ThisFileInfo['bitrate'] += $thisfile_real_chunks_currentchunk['avg_bit_rate'];
134
+ }
135
+ $thisfile_real_chunks_currentchunk['flags']['save_enabled'] = (bool) ($thisfile_real_chunks_currentchunk['flags_raw'] & 0x0001);
136
+ $thisfile_real_chunks_currentchunk['flags']['perfect_play'] = (bool) ($thisfile_real_chunks_currentchunk['flags_raw'] & 0x0002);
137
+ $thisfile_real_chunks_currentchunk['flags']['live_broadcast'] = (bool) ($thisfile_real_chunks_currentchunk['flags_raw'] & 0x0004);
138
+ }
139
+ break;
140
+
141
+ case 'MDPR': // Media Properties Header
142
+ $thisfile_real_chunks_currentchunk['object_version'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2));
143
+ $offset += 2;
144
+ if ($thisfile_real_chunks_currentchunk['object_version'] == 0) {
145
+ $thisfile_real_chunks_currentchunk['stream_number'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2));
146
+ $offset += 2;
147
+ $thisfile_real_chunks_currentchunk['max_bit_rate'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4));
148
+ $offset += 4;
149
+ $thisfile_real_chunks_currentchunk['avg_bit_rate'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4));
150
+ $offset += 4;
151
+ $thisfile_real_chunks_currentchunk['max_packet_size'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4));
152
+ $offset += 4;
153
+ $thisfile_real_chunks_currentchunk['avg_packet_size'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4));
154
+ $offset += 4;
155
+ $thisfile_real_chunks_currentchunk['start_time'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4));
156
+ $offset += 4;
157
+ $thisfile_real_chunks_currentchunk['preroll'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4));
158
+ $offset += 4;
159
+ $thisfile_real_chunks_currentchunk['duration'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4));
160
+ $offset += 4;
161
+ $thisfile_real_chunks_currentchunk['stream_name_size'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 1));
162
+ $offset += 1;
163
+ $thisfile_real_chunks_currentchunk['stream_name'] = substr($ChunkData, $offset, $thisfile_real_chunks_currentchunk['stream_name_size']);
164
+ $offset += $thisfile_real_chunks_currentchunk['stream_name_size'];
165
+ $thisfile_real_chunks_currentchunk['mime_type_size'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 1));
166
+ $offset += 1;
167
+ $thisfile_real_chunks_currentchunk['mime_type'] = substr($ChunkData, $offset, $thisfile_real_chunks_currentchunk['mime_type_size']);
168
+ $offset += $thisfile_real_chunks_currentchunk['mime_type_size'];
169
+ $thisfile_real_chunks_currentchunk['type_specific_len'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4));
170
+ $offset += 4;
171
+ $thisfile_real_chunks_currentchunk['type_specific_data'] = substr($ChunkData, $offset, $thisfile_real_chunks_currentchunk['type_specific_len']);
172
+ $offset += $thisfile_real_chunks_currentchunk['type_specific_len'];
173
+
174
+ // shortcut
175
+ $thisfile_real_chunks_currentchunk_typespecificdata = &$thisfile_real_chunks_currentchunk['type_specific_data'];
176
+
177
+ switch ($thisfile_real_chunks_currentchunk['mime_type']) {
178
+ case 'video/x-pn-realvideo':
179
+ case 'video/x-pn-multirate-realvideo':
180
+ // http://www.freelists.org/archives/matroska-devel/07-2003/msg00010.html
181
+
182
+ // shortcut
183
+ $thisfile_real_chunks_currentchunk['video_info'] = array();
184
+ $thisfile_real_chunks_currentchunk_videoinfo = &$thisfile_real_chunks_currentchunk['video_info'];
185
+
186
+ $thisfile_real_chunks_currentchunk_videoinfo['dwSize'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 0, 4));
187
+ $thisfile_real_chunks_currentchunk_videoinfo['fourcc1'] = substr($thisfile_real_chunks_currentchunk_typespecificdata, 4, 4);
188
+ $thisfile_real_chunks_currentchunk_videoinfo['fourcc2'] = substr($thisfile_real_chunks_currentchunk_typespecificdata, 8, 4);
189
+ $thisfile_real_chunks_currentchunk_videoinfo['width'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 12, 2));
190
+ $thisfile_real_chunks_currentchunk_videoinfo['height'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 14, 2));
191
+ $thisfile_real_chunks_currentchunk_videoinfo['bits_per_sample'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 16, 2));
192
+ //$thisfile_real_chunks_currentchunk_videoinfo['unknown1'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 18, 2));
193
+ //$thisfile_real_chunks_currentchunk_videoinfo['unknown2'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 20, 2));
194
+ $thisfile_real_chunks_currentchunk_videoinfo['frames_per_second'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 22, 2));
195
+ //$thisfile_real_chunks_currentchunk_videoinfo['unknown3'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 24, 2));
196
+ //$thisfile_real_chunks_currentchunk_videoinfo['unknown4'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 26, 2));
197
+ //$thisfile_real_chunks_currentchunk_videoinfo['unknown5'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 28, 2));
198
+ //$thisfile_real_chunks_currentchunk_videoinfo['unknown6'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 30, 2));
199
+ //$thisfile_real_chunks_currentchunk_videoinfo['unknown7'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 32, 2));
200
+ //$thisfile_real_chunks_currentchunk_videoinfo['unknown8'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 34, 2));
201
+ //$thisfile_real_chunks_currentchunk_videoinfo['unknown9'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 36, 2));
202
+
203
+ $thisfile_real_chunks_currentchunk_videoinfo['codec'] = getid3_riff::RIFFfourccLookup($thisfile_real_chunks_currentchunk_videoinfo['fourcc2']);
204
+
205
+ $ThisFileInfo['video']['resolution_x'] = $thisfile_real_chunks_currentchunk_videoinfo['width'];
206
+ $ThisFileInfo['video']['resolution_y'] = $thisfile_real_chunks_currentchunk_videoinfo['height'];
207
+ $ThisFileInfo['video']['frame_rate'] = (float) $thisfile_real_chunks_currentchunk_videoinfo['frames_per_second'];
208
+ $ThisFileInfo['video']['codec'] = $thisfile_real_chunks_currentchunk_videoinfo['codec'];
209
+ $ThisFileInfo['video']['bits_per_sample'] = $thisfile_real_chunks_currentchunk_videoinfo['bits_per_sample'];
210
+ break;
211
+
212
+ case 'audio/x-pn-realaudio':
213
+ case 'audio/x-pn-multirate-realaudio':
214
+ $this->ParseOldRAheader($thisfile_real_chunks_currentchunk_typespecificdata, $thisfile_real_chunks_currentchunk['parsed_audio_data']);
215
+
216
+ $ThisFileInfo['audio']['sample_rate'] = $thisfile_real_chunks_currentchunk['parsed_audio_data']['sample_rate'];
217
+ $ThisFileInfo['audio']['bits_per_sample'] = $thisfile_real_chunks_currentchunk['parsed_audio_data']['bits_per_sample'];
218
+ $ThisFileInfo['audio']['channels'] = $thisfile_real_chunks_currentchunk['parsed_audio_data']['channels'];
219
+ if (!empty($ThisFileInfo['audio']['dataformat'])) {
220
+ foreach ($ThisFileInfo['audio'] as $key => $value) {
221
+ if ($key != 'streams') {
222
+ $ThisFileInfo['audio']['streams'][$thisfile_real_chunks_currentchunk['stream_number']][$key] = $value;
223
+ }
224
+ }
225
+ }
226
+ break;
227
+
228
+ case 'logical-fileinfo':
229
+ // shortcut
230
+ $thisfile_real_chunks_currentchunk['logical_fileinfo'] = array();
231
+ $thisfile_real_chunks_currentchunk_logicalfileinfo = &$thisfile_real_chunks_currentchunk['logical_fileinfo'];
232
+
233
+ $thisfile_real_chunks_currentchunk_logicalfileinfo_offset = 0;
234
+ $thisfile_real_chunks_currentchunk_logicalfileinfo['logical_fileinfo_length'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, $thisfile_real_chunks_currentchunk_logicalfileinfo_offset, 4));
235
+ $thisfile_real_chunks_currentchunk_logicalfileinfo_offset += 4;
236
+
237
+ //$thisfile_real_chunks_currentchunk_logicalfileinfo['unknown1'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, $thisfile_real_chunks_currentchunk_logicalfileinfo_offset, 4));
238
+ $thisfile_real_chunks_currentchunk_logicalfileinfo_offset += 4;
239
+
240
+ $thisfile_real_chunks_currentchunk_logicalfileinfo['num_tags'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, $thisfile_real_chunks_currentchunk_logicalfileinfo_offset, 4));
241
+ $thisfile_real_chunks_currentchunk_logicalfileinfo_offset += 4;
242
+
243
+ //$thisfile_real_chunks_currentchunk_logicalfileinfo['unknown2'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, $thisfile_real_chunks_currentchunk_logicalfileinfo_offset, 4));
244
+ $thisfile_real_chunks_currentchunk_logicalfileinfo_offset += 4;
245
+
246
+ //$thisfile_real_chunks_currentchunk_logicalfileinfo['d'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, $thisfile_real_chunks_currentchunk_logicalfileinfo_offset, 1));
247
+
248
+ //$thisfile_real_chunks_currentchunk_logicalfileinfo['one_type'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, $thisfile_real_chunks_currentchunk_logicalfileinfo_offset, 4));
249
+ //$thisfile_real_chunks_currentchunk_logicalfileinfo_thislength = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 4 + $thisfile_real_chunks_currentchunk_logicalfileinfo_offset, 2));
250
+ //$thisfile_real_chunks_currentchunk_logicalfileinfo['one'] = substr($thisfile_real_chunks_currentchunk_typespecificdata, 6 + $thisfile_real_chunks_currentchunk_logicalfileinfo_offset, $thisfile_real_chunks_currentchunk_logicalfileinfo_thislength);
251
+ //$thisfile_real_chunks_currentchunk_logicalfileinfo_offset += (6 + $thisfile_real_chunks_currentchunk_logicalfileinfo_thislength);
252
+
253
+ break;
254
+
255
+ }
256
+
257
+
258
+ if (empty($ThisFileInfo['playtime_seconds'])) {
259
+ $ThisFileInfo['playtime_seconds'] = max($ThisFileInfo['playtime_seconds'], ($thisfile_real_chunks_currentchunk['duration'] + $thisfile_real_chunks_currentchunk['start_time']) / 1000);
260
+ }
261
+ if ($thisfile_real_chunks_currentchunk['duration'] > 0) {
262
+ switch ($thisfile_real_chunks_currentchunk['mime_type']) {
263
+ case 'audio/x-pn-realaudio':
264
+ case 'audio/x-pn-multirate-realaudio':
265
+ $ThisFileInfo['audio']['bitrate'] = (isset($ThisFileInfo['audio']['bitrate']) ? $ThisFileInfo['audio']['bitrate'] : 0) + $thisfile_real_chunks_currentchunk['avg_bit_rate'];
266
+ $ThisFileInfo['audio']['codec'] = $this->RealAudioCodecFourCClookup($thisfile_real_chunks_currentchunk['parsed_audio_data']['fourcc'], $ThisFileInfo['audio']['bitrate']);
267
+ $ThisFileInfo['audio']['dataformat'] = 'real';
268
+ $ThisFileInfo['audio']['lossless'] = false;
269
+ break;
270
+
271
+ case 'video/x-pn-realvideo':
272
+ case 'video/x-pn-multirate-realvideo':
273
+ $ThisFileInfo['video']['bitrate'] = (isset($ThisFileInfo['video']['bitrate']) ? $ThisFileInfo['video']['bitrate'] : 0) + $thisfile_real_chunks_currentchunk['avg_bit_rate'];
274
+ $ThisFileInfo['video']['bitrate_mode'] = 'cbr';
275
+ $ThisFileInfo['video']['dataformat'] = 'real';
276
+ $ThisFileInfo['video']['lossless'] = false;
277
+ $ThisFileInfo['video']['pixel_aspect_ratio'] = (float) 1;
278
+ break;
279
+
280
+ case 'audio/x-ralf-mpeg4-generic':
281
+ $ThisFileInfo['audio']['bitrate'] = (isset($ThisFileInfo['audio']['bitrate']) ? $ThisFileInfo['audio']['bitrate'] : 0) + $thisfile_real_chunks_currentchunk['avg_bit_rate'];
282
+ $ThisFileInfo['audio']['codec'] = 'RealAudio Lossless';
283
+ $ThisFileInfo['audio']['dataformat'] = 'real';
284
+ $ThisFileInfo['audio']['lossless'] = true;
285
+ break;
286
+ }
287
+ $ThisFileInfo['bitrate'] = (isset($ThisFileInfo['video']['bitrate']) ? $ThisFileInfo['video']['bitrate'] : 0) + (isset($ThisFileInfo['audio']['bitrate']) ? $ThisFileInfo['audio']['bitrate'] : 0);
288
+ }
289
+ }
290
+ break;
291
+
292
+ case 'CONT': // Content Description Header (text comments)
293
+ $thisfile_real_chunks_currentchunk['object_version'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2));
294
+ $offset += 2;
295
+ if ($thisfile_real_chunks_currentchunk['object_version'] == 0) {
296
+ $thisfile_real_chunks_currentchunk['title_len'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2));
297
+ $offset += 2;
298
+ $thisfile_real_chunks_currentchunk['title'] = (string) substr($ChunkData, $offset, $thisfile_real_chunks_currentchunk['title_len']);
299
+ $offset += $thisfile_real_chunks_currentchunk['title_len'];
300
+
301
+ $thisfile_real_chunks_currentchunk['artist_len'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2));
302
+ $offset += 2;
303
+ $thisfile_real_chunks_currentchunk['artist'] = (string) substr($ChunkData, $offset, $thisfile_real_chunks_currentchunk['artist_len']);
304
+ $offset += $thisfile_real_chunks_currentchunk['artist_len'];
305
+
306
+ $thisfile_real_chunks_currentchunk['copyright_len'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2));
307
+ $offset += 2;
308
+ $thisfile_real_chunks_currentchunk['copyright'] = (string) substr($ChunkData, $offset, $thisfile_real_chunks_currentchunk['copyright_len']);
309
+ $offset += $thisfile_real_chunks_currentchunk['copyright_len'];
310
+
311
+ $thisfile_real_chunks_currentchunk['comment_len'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2));
312
+ $offset += 2;
313
+ $thisfile_real_chunks_currentchunk['comment'] = (string) substr($ChunkData, $offset, $thisfile_real_chunks_currentchunk['comment_len']);
314
+ $offset += $thisfile_real_chunks_currentchunk['comment_len'];
315
+
316
+
317
+ $commentkeystocopy = array('title'=>'title', 'artist'=>'artist', 'copyright'=>'copyright', 'comment'=>'comment');
318
+ foreach ($commentkeystocopy as $key => $val) {
319
+ if ($thisfile_real_chunks_currentchunk[$key]) {
320
+ $ThisFileInfo['real']['comments'][$val][] = trim($thisfile_real_chunks_currentchunk[$key]);
321
+ }
322
+ }
323
+
324
+ }
325
+ break;
326
+
327
+
328
+ case 'DATA': // Data Chunk Header
329
+ // do nothing
330
+ break;
331
+
332
+ case 'INDX': // Index Section Header
333
+ $thisfile_real_chunks_currentchunk['object_version'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2));
334
+ $offset += 2;
335
+ if ($thisfile_real_chunks_currentchunk['object_version'] == 0) {
336
+ $thisfile_real_chunks_currentchunk['num_indices'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4));
337
+ $offset += 4;
338
+ $thisfile_real_chunks_currentchunk['stream_number'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2));
339
+ $offset += 2;
340
+ $thisfile_real_chunks_currentchunk['next_index_header'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4));
341
+ $offset += 4;
342
+
343
+ if ($thisfile_real_chunks_currentchunk['next_index_header'] == 0) {
344
+ // last index chunk found, ignore rest of file
345
+ break 2;
346
+ } else {
347
+ // non-last index chunk, seek to next index chunk (skipping actual index data)
348
+ fseek($fd, $thisfile_real_chunks_currentchunk['next_index_header'], SEEK_SET);
349
+ }
350
+ }
351
+ break;
352
+
353
+ default:
354
+ $ThisFileInfo['warning'][] = 'Unhandled RealMedia chunk "'.$ChunkName.'" at offset '.$thisfile_real_chunks_currentchunk['offset'];
355
+ break;
356
+ }
357
+ $ChunkCounter++;
358
+ }
359
+
360
+ if (!empty($ThisFileInfo['audio']['streams'])) {
361
+ $ThisFileInfo['audio']['bitrate'] = 0;
362
+ foreach ($ThisFileInfo['audio']['streams'] as $key => $valuearray) {
363
+ $ThisFileInfo['audio']['bitrate'] += $valuearray['bitrate'];
364
+ }
365
+ }
366
+
367
+ return true;
368
+ }
369
+
370
+
371
+ function ParseOldRAheader($OldRAheaderData, &$ParsedArray) {
372
+ // http://www.freelists.org/archives/matroska-devel/07-2003/msg00010.html
373
+
374
+ $ParsedArray = array();
375
+ $ParsedArray['magic'] = substr($OldRAheaderData, 0, 4);
376
+ if ($ParsedArray['magic'] != '.ra'."\xFD") {
377
+ return false;
378
+ }
379
+ $ParsedArray['version1'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 4, 2));
380
+
381
+ if ($ParsedArray['version1'] < 3) {
382
+
383
+ return false;
384
+
385
+ } elseif ($ParsedArray['version1'] == 3) {
386
+
387
+ $ParsedArray['fourcc1'] = '.ra3';
388
+ $ParsedArray['bits_per_sample'] = 16; // hard-coded for old versions?
389
+ $ParsedArray['sample_rate'] = 8000; // hard-coded for old versions?
390
+
391
+ $ParsedArray['header_size'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 6, 2));
392
+ $ParsedArray['channels'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 8, 2)); // always 1 (?)
393
+ //$ParsedArray['unknown1'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 10, 2));
394
+ //$ParsedArray['unknown2'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 12, 2));
395
+ //$ParsedArray['unknown3'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 14, 2));
396
+ $ParsedArray['bytes_per_minute'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 16, 2));
397
+ $ParsedArray['audio_bytes'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 18, 4));
398
+ $ParsedArray['comments_raw'] = substr($OldRAheaderData, 22, $ParsedArray['header_size'] - 22 + 1); // not including null terminator
399
+
400
+ $commentoffset = 0;
401
+ $commentlength = getid3_lib::BigEndian2Int(substr($ParsedArray['comments_raw'], $commentoffset++, 1));
402
+ $ParsedArray['comments']['title'][] = substr($ParsedArray['comments_raw'], $commentoffset, $commentlength);
403
+ $commentoffset += $commentlength;
404
+
405
+ $commentlength = getid3_lib::BigEndian2Int(substr($ParsedArray['comments_raw'], $commentoffset++, 1));
406
+ $ParsedArray['comments']['artist'][] = substr($ParsedArray['comments_raw'], $commentoffset, $commentlength);
407
+ $commentoffset += $commentlength;
408
+
409
+ $commentlength = getid3_lib::BigEndian2Int(substr($ParsedArray['comments_raw'], $commentoffset++, 1));
410
+ $ParsedArray['comments']['copyright'][] = substr($ParsedArray['comments_raw'], $commentoffset, $commentlength);
411
+ $commentoffset += $commentlength;
412
+
413
+ $commentoffset++; // final null terminator (?)
414
+ $commentoffset++; // fourcc length (?) should be 4
415
+ $ParsedArray['fourcc'] = substr($OldRAheaderData, 23 + $commentoffset, 4);
416
+
417
+ } elseif ($ParsedArray['version1'] <= 5) {
418
+
419
+ //$ParsedArray['unknown1'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 6, 2));
420
+ $ParsedArray['fourcc1'] = substr($OldRAheaderData, 8, 4);
421
+ $ParsedArray['file_size'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 12, 4));
422
+ $ParsedArray['version2'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 16, 2));
423
+ $ParsedArray['header_size'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 18, 4));
424
+ $ParsedArray['codec_flavor_id'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 22, 2));
425
+ $ParsedArray['coded_frame_size'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 24, 4));
426
+ $ParsedArray['audio_bytes'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 28, 4));
427
+ $ParsedArray['bytes_per_minute'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 32, 4));
428
+ //$ParsedArray['unknown5'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 36, 4));
429
+ $ParsedArray['sub_packet_h'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 40, 2));
430
+ $ParsedArray['frame_size'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 42, 2));
431
+ $ParsedArray['sub_packet_size'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 44, 2));
432
+ //$ParsedArray['unknown6'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 46, 2));
433
+
434
+ switch ($ParsedArray['version1']) {
435
+
436
+ case 4:
437
+ $ParsedArray['sample_rate'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 48, 2));
438
+ //$ParsedArray['unknown8'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 50, 2));
439
+ $ParsedArray['bits_per_sample'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 52, 2));
440
+ $ParsedArray['channels'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 54, 2));
441
+ $ParsedArray['length_fourcc2'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 56, 1));
442
+ $ParsedArray['fourcc2'] = substr($OldRAheaderData, 57, 4);
443
+ $ParsedArray['length_fourcc3'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 61, 1));
444
+ $ParsedArray['fourcc3'] = substr($OldRAheaderData, 62, 4);
445
+ //$ParsedArray['unknown9'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 66, 1));
446
+ //$ParsedArray['unknown10'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 67, 2));
447
+ $ParsedArray['comments_raw'] = substr($OldRAheaderData, 69, $ParsedArray['header_size'] - 69 + 16);
448
+
449
+ $commentoffset = 0;
450
+ $commentlength = getid3_lib::BigEndian2Int(substr($ParsedArray['comments_raw'], $commentoffset++, 1));
451
+ $ParsedArray['comments']['title'][] = substr($ParsedArray['comments_raw'], $commentoffset, $commentlength);
452
+ $commentoffset += $commentlength;
453
+
454
+ $commentlength = getid3_lib::BigEndian2Int(substr($ParsedArray['comments_raw'], $commentoffset++, 1));
455
+ $ParsedArray['comments']['artist'][] = substr($ParsedArray['comments_raw'], $commentoffset, $commentlength);
456
+ $commentoffset += $commentlength;
457
+
458
+ $commentlength = getid3_lib::BigEndian2Int(substr($ParsedArray['comments_raw'], $commentoffset++, 1));
459
+ $ParsedArray['comments']['copyright'][] = substr($ParsedArray['comments_raw'], $commentoffset, $commentlength);
460
+ $commentoffset += $commentlength;
461
+ break;
462
+
463
+ case 5:
464
+ $ParsedArray['sample_rate'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 48, 4));
465
+ $ParsedArray['sample_rate2'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 52, 4));
466
+ $ParsedArray['bits_per_sample'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 56, 4));
467
+ $ParsedArray['channels'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 60, 2));
468
+ $ParsedArray['genr'] = substr($OldRAheaderData, 62, 4);
469
+ $ParsedArray['fourcc3'] = substr($OldRAheaderData, 66, 4);
470
+ $ParsedArray['comments'] = array();
471
+ break;
472
+ }
473
+ $ParsedArray['fourcc'] = $ParsedArray['fourcc3'];
474
+
475
+ }
476
+ foreach ($ParsedArray['comments'] as $key => $value) {
477
+ if ($ParsedArray['comments'][$key][0] === false) {
478
+ $ParsedArray['comments'][$key][0] = '';
479
+ }
480
+ }
481
+
482
+ return true;
483
+ }
484
+
485
+ function RealAudioCodecFourCClookup($fourcc, $bitrate) {
486
+ static $RealAudioCodecFourCClookup = array();
487
+ if (empty($RealAudioCodecFourCClookup)) {
488
+ // http://www.its.msstate.edu/net/real/reports/config/tags.stats
489
+ // http://www.freelists.org/archives/matroska-devel/06-2003/fullthread18.html
490
+
491
+ $RealAudioCodecFourCClookup['14_4'][8000] = 'RealAudio v2 (14.4kbps)';
492
+ $RealAudioCodecFourCClookup['14.4'][8000] = 'RealAudio v2 (14.4kbps)';
493
+ $RealAudioCodecFourCClookup['lpcJ'][8000] = 'RealAudio v2 (14.4kbps)';
494
+ $RealAudioCodecFourCClookup['28_8'][15200] = 'RealAudio v2 (28.8kbps)';
495
+ $RealAudioCodecFourCClookup['28.8'][15200] = 'RealAudio v2 (28.8kbps)';
496
+ $RealAudioCodecFourCClookup['sipr'][4933] = 'RealAudio v4 (5kbps Voice)';
497
+ $RealAudioCodecFourCClookup['sipr'][6444] = 'RealAudio v4 (6.5kbps Voice)';
498
+ $RealAudioCodecFourCClookup['sipr'][8444] = 'RealAudio v4 (8.5kbps Voice)';
499
+ $RealAudioCodecFourCClookup['sipr'][16000] = 'RealAudio v4 (16kbps Wideband)';
500
+ $RealAudioCodecFourCClookup['dnet'][8000] = 'RealAudio v3 (8kbps Music)';
501
+ $RealAudioCodecFourCClookup['dnet'][16000] = 'RealAudio v3 (16kbps Music Low Response)';
502
+ $RealAudioCodecFourCClookup['dnet'][15963] = 'RealAudio v3 (16kbps Music Mid/High Response)';
503
+ $RealAudioCodecFourCClookup['dnet'][20000] = 'RealAudio v3 (20kbps Music Stereo)';
504
+ $RealAudioCodecFourCClookup['dnet'][32000] = 'RealAudio v3 (32kbps Music Mono)';
505
+ $RealAudioCodecFourCClookup['dnet'][31951] = 'RealAudio v3 (32kbps Music Stereo)';
506
+ $RealAudioCodecFourCClookup['dnet'][39965] = 'RealAudio v3 (40kbps Music Mono)';
507
+ $RealAudioCodecFourCClookup['dnet'][40000] = 'RealAudio v3 (40kbps Music Stereo)';
508
+ $RealAudioCodecFourCClookup['dnet'][79947] = 'RealAudio v3 (80kbps Music Mono)';
509
+ $RealAudioCodecFourCClookup['dnet'][80000] = 'RealAudio v3 (80kbps Music Stereo)';
510
+
511
+ $RealAudioCodecFourCClookup['dnet'][0] = 'RealAudio v3';
512
+ $RealAudioCodecFourCClookup['sipr'][0] = 'RealAudio v4';
513
+ $RealAudioCodecFourCClookup['cook'][0] = 'RealAudio G2';
514
+ $RealAudioCodecFourCClookup['atrc'][0] = 'RealAudio 8';
515
+ }
516
+ $roundbitrate = intval(round($bitrate));
517
+ if (isset($RealAudioCodecFourCClookup[$fourcc][$roundbitrate])) {
518
+ return $RealAudioCodecFourCClookup[$fourcc][$roundbitrate];
519
+ } elseif (isset($RealAudioCodecFourCClookup[$fourcc][0])) {
520
+ return $RealAudioCodecFourCClookup[$fourcc][0];
521
+ }
522
+ return $fourcc;
523
+ }
524
+
525
+ }
526
+
527
+
528
+ ?>
view/getid3/module.audio-video.riff.php ADDED
@@ -0,0 +1,2110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /////////////////////////////////////////////////////////////////
3
+ /// getID3() by James Heinrich <info@getid3.org> //
4
+ // available at http://getid3.sourceforge.net //
5
+ // or http://www.getid3.org //
6
+ /////////////////////////////////////////////////////////////////
7
+ // See readme.txt for more details //
8
+ /////////////////////////////////////////////////////////////////
9
+ // //
10
+ // module.audio-video.riff.php //
11
+ // module for analyzing RIFF files //
12
+ // multiple formats supported by this module: //
13
+ // Wave, AVI, AIFF/AIFC, (MP3,AC3)/RIFF, Wavpack v3, 8SVX //
14
+ // dependencies: module.audio.mp3.php //
15
+ // module.audio.ac3.php (optional) //
16
+ // module.audio.dts.php (optional) //
17
+ // ///
18
+ /////////////////////////////////////////////////////////////////
19
+
20
+ getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.mp3.php', __FILE__, true);
21
+
22
+ class getid3_riff
23
+ {
24
+
25
+ function getid3_riff(&$fd, &$ThisFileInfo) {
26
+
27
+ // initialize these values to an empty array, otherwise they default to NULL
28
+ // and you can't append array values to a NULL value
29
+ $ThisFileInfo['riff'] = array('raw'=>array());
30
+
31
+ // Shortcuts
32
+ $thisfile_riff = &$ThisFileInfo['riff'];
33
+ $thisfile_riff_raw = &$thisfile_riff['raw'];
34
+ $thisfile_audio = &$ThisFileInfo['audio'];
35
+ $thisfile_video = &$ThisFileInfo['video'];
36
+ $thisfile_avdataoffset = &$ThisFileInfo['avdataoffset'];
37
+ $thisfile_avdataend = &$ThisFileInfo['avdataend'];
38
+ $thisfile_audio_dataformat = &$thisfile_audio['dataformat'];
39
+ $thisfile_riff_audio = &$thisfile_riff['audio'];
40
+ $thisfile_riff_video = &$thisfile_riff['video'];
41
+
42
+
43
+ $Original['avdataoffset'] = $thisfile_avdataoffset;
44
+ $Original['avdataend'] = $thisfile_avdataend;
45
+
46
+ fseek($fd, $thisfile_avdataoffset, SEEK_SET);
47
+ $RIFFheader = fread($fd, 12);
48
+ $RIFFsubtype = substr($RIFFheader, 8, 4);
49
+ switch (substr($RIFFheader, 0, 4)) {
50
+ case 'FORM':
51
+ $ThisFileInfo['fileformat'] = 'aiff';
52
+ $RIFFheaderSize = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($RIFFheader, 4, 4));
53
+ $thisfile_riff[$RIFFsubtype] = getid3_riff::ParseRIFF($fd, $thisfile_avdataoffset + 12, $thisfile_avdataoffset + $RIFFheaderSize, $ThisFileInfo);
54
+ $thisfile_riff['header_size'] = $RIFFheaderSize;
55
+ break;
56
+
57
+ case 'RIFF':
58
+ case 'SDSS': // SDSS is identical to RIFF, just renamed. Used by SmartSound QuickTracks (www.smartsound.com)
59
+ case 'RMP3': // RMP3 is identical to RIFF, just renamed. Used by [unknown program] when creating RIFF-MP3s
60
+ if ($RIFFsubtype == 'RMP3') {
61
+ // RMP3 is identical to WAVE, just renamed. Used by [unknown program] when creating RIFF-MP3s
62
+ $RIFFsubtype = 'WAVE';
63
+ }
64
+
65
+ $ThisFileInfo['fileformat'] = 'riff';
66
+ $RIFFheaderSize = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($RIFFheader, 4, 4));
67
+ $thisfile_riff['header_size'] = $RIFFheaderSize;
68
+ $thisfile_riff[$RIFFsubtype] = getid3_riff::ParseRIFF($fd, $thisfile_avdataoffset + 12, $thisfile_avdataoffset + $RIFFheaderSize, $ThisFileInfo);
69
+
70
+ fseek($fd, $thisfile_avdataoffset + $RIFFheaderSize);
71
+ $nextRIFFheader = fread($fd, 20);
72
+ if (substr($nextRIFFheader, 8, 4) == 'RIFF') {
73
+ $nextRIFFsize = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($nextRIFFheader, 12, 4));
74
+ $nextRIFFtype = substr($nextRIFFheader, 16, 4).'<br>';
75
+ $thisfile_riff[$nextRIFFtype]['offset'] = ftell($fd) - 4;
76
+ $thisfile_riff[$nextRIFFtype]['size'] = $nextRIFFsize;
77
+ $ThisFileInfo['avdataend'] = $thisfile_riff[$nextRIFFtype]['offset'] + $thisfile_riff[$nextRIFFtype]['size'];
78
+ $ThisFileInfo['error'][] = 'AVI extends beyond 2GB and PHP filesystem functions cannot read that far, playtime is probably wrong';
79
+ $ThisFileInfo['warning'][] = '[avdataend] value may be incorrect, multiple AVIX chunks may be present';
80
+ $thisfile_riff[$nextRIFFtype] = getid3_riff::ParseRIFF($fd, $thisfile_riff[$nextRIFFtype]['offset'] + 4, $thisfile_riff[$nextRIFFtype]['offset'] + $thisfile_riff[$nextRIFFtype]['size'], $ThisFileInfo);
81
+ }
82
+ if ($RIFFsubtype == 'WAVE') {
83
+ $thisfile_riff_WAVE = &$thisfile_riff['WAVE'];
84
+ }
85
+ break;
86
+
87
+ default:
88
+ $ThisFileInfo['error'][] = 'Cannot parse RIFF (this is maybe not a RIFF / WAV / AVI file?) - expecting "FORM|RIFF|SDSS|RMP3" found "'.$RIFFsubtype.'" instead';
89
+ unset($ThisFileInfo['fileformat']);
90
+ return false;
91
+ break;
92
+ }
93
+
94
+ $streamindex = 0;
95
+ switch ($RIFFsubtype) {
96
+ case 'WAVE':
97
+ if (empty($thisfile_audio['bitrate_mode'])) {
98
+ $thisfile_audio['bitrate_mode'] = 'cbr';
99
+ }
100
+ if (empty($thisfile_audio_dataformat)) {
101
+ $thisfile_audio_dataformat = 'wav';
102
+ }
103
+
104
+ if (isset($thisfile_riff_WAVE['data'][0]['offset'])) {
105
+ $thisfile_avdataoffset = $thisfile_riff_WAVE['data'][0]['offset'] + 8;
106
+ $thisfile_avdataend = $thisfile_avdataoffset + $thisfile_riff_WAVE['data'][0]['size'];
107
+ }
108
+ if (isset($thisfile_riff_WAVE['fmt '][0]['data'])) {
109
+
110
+ $thisfile_riff_audio[$streamindex] = getid3_riff::RIFFparseWAVEFORMATex($thisfile_riff_WAVE['fmt '][0]['data']);
111
+ $thisfile_audio['wformattag'] = $thisfile_riff_audio[$streamindex]['raw']['wFormatTag'];
112
+ if (@$thisfile_riff_audio[$streamindex]['bitrate'] == 0) {
113
+ $ThisFileInfo['error'][] = 'Corrupt RIFF file: bitrate_audio == zero';
114
+ return false;
115
+ }
116
+ $thisfile_riff_raw['fmt '] = $thisfile_riff_audio[$streamindex]['raw'];
117
+ unset($thisfile_riff_audio[$streamindex]['raw']);
118
+ $thisfile_audio['streams'][$streamindex] = $thisfile_riff_audio[$streamindex];
119
+
120
+ $thisfile_audio = getid3_lib::array_merge_noclobber($thisfile_audio, $thisfile_riff_audio[$streamindex]);
121
+ if (substr($thisfile_audio['codec'], 0, strlen('unknown: 0x')) == 'unknown: 0x') {
122
+ $ThisFileInfo['warning'][] = 'Audio codec = '.$thisfile_audio['codec'];
123
+ }
124
+ $thisfile_audio['bitrate'] = $thisfile_riff_audio[$streamindex]['bitrate'];
125
+
126
+ $ThisFileInfo['playtime_seconds'] = (float) ((($thisfile_avdataend - $thisfile_avdataoffset) * 8) / $thisfile_audio['bitrate']);
127
+
128
+ $thisfile_audio['lossless'] = false;
129
+ if (isset($thisfile_riff_WAVE['data'][0]['offset']) && isset($thisfile_riff_raw['fmt ']['wFormatTag'])) {
130
+ switch ($thisfile_riff_raw['fmt ']['wFormatTag']) {
131
+
132
+ case 0x0001: // PCM
133
+ $thisfile_audio['lossless'] = true;
134
+ break;
135
+
136
+ case 0x2000: // AC-3
137
+ $thisfile_audio_dataformat = 'ac3';
138
+ break;
139
+
140
+ default:
141
+ // do nothing
142
+ break;
143
+
144
+ }
145
+ }
146
+ $thisfile_audio['streams'][$streamindex]['wformattag'] = $thisfile_audio['wformattag'];
147
+ $thisfile_audio['streams'][$streamindex]['bitrate_mode'] = $thisfile_audio['bitrate_mode'];
148
+ $thisfile_audio['streams'][$streamindex]['lossless'] = $thisfile_audio['lossless'];
149
+ $thisfile_audio['streams'][$streamindex]['dataformat'] = $thisfile_audio_dataformat;
150
+ }
151
+
152
+ if (isset($thisfile_riff_WAVE['rgad'][0]['data'])) {
153
+
154
+ // shortcuts
155
+ $rgadData = &$thisfile_riff_WAVE['rgad'][0]['data'];
156
+ $thisfile_riff_raw['rgad'] = array('track'=>array(), 'album'=>array());
157
+ $thisfile_riff_raw_rgad = &$thisfile_riff_raw['rgad'];
158
+ $thisfile_riff_raw_rgad_track = &$thisfile_riff_raw_rgad['track'];
159
+ $thisfile_riff_raw_rgad_album = &$thisfile_riff_raw_rgad['album'];
160
+
161
+ $thisfile_riff_raw_rgad['fPeakAmplitude'] = getid3_lib::LittleEndian2Float(substr($rgadData, 0, 4));
162
+ $thisfile_riff_raw_rgad['nRadioRgAdjust'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($rgadData, 4, 2));
163
+ $thisfile_riff_raw_rgad['nAudiophileRgAdjust'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($rgadData, 6, 2));
164
+
165
+ $nRadioRgAdjustBitstring = str_pad(getid3_lib::Dec2Bin($thisfile_riff_raw_rgad['nRadioRgAdjust']), 16, '0', STR_PAD_LEFT);
166
+ $nAudiophileRgAdjustBitstring = str_pad(getid3_lib::Dec2Bin($thisfile_riff_raw_rgad['nAudiophileRgAdjust']), 16, '0', STR_PAD_LEFT);
167
+ $thisfile_riff_raw_rgad_track['name'] = getid3_lib::Bin2Dec(substr($nRadioRgAdjustBitstring, 0, 3));
168
+ $thisfile_riff_raw_rgad_track['originator'] = getid3_lib::Bin2Dec(substr($nRadioRgAdjustBitstring, 3, 3));
169
+ $thisfile_riff_raw_rgad_track['signbit'] = getid3_lib::Bin2Dec(substr($nRadioRgAdjustBitstring, 6, 1));
170
+ $thisfile_riff_raw_rgad_track['adjustment'] = getid3_lib::Bin2Dec(substr($nRadioRgAdjustBitstring, 7, 9));
171
+ $thisfile_riff_raw_rgad_album['name'] = getid3_lib::Bin2Dec(substr($nAudiophileRgAdjustBitstring, 0, 3));
172
+ $thisfile_riff_raw_rgad_album['originator'] = getid3_lib::Bin2Dec(substr($nAudiophileRgAdjustBitstring, 3, 3));
173
+ $thisfile_riff_raw_rgad_album['signbit'] = getid3_lib::Bin2Dec(substr($nAudiophileRgAdjustBitstring, 6, 1));
174
+ $thisfile_riff_raw_rgad_album['adjustment'] = getid3_lib::Bin2Dec(substr($nAudiophileRgAdjustBitstring, 7, 9));
175
+
176
+ $thisfile_riff['rgad']['peakamplitude'] = $thisfile_riff_raw_rgad['fPeakAmplitude'];
177
+ if (($thisfile_riff_raw_rgad_track['name'] != 0) && ($thisfile_riff_raw_rgad_track['originator'] != 0)) {
178
+ $thisfile_riff['rgad']['track']['name'] = getid3_lib::RGADnameLookup($thisfile_riff_raw_rgad_track['name']);
179
+ $thisfile_riff['rgad']['track']['originator'] = getid3_lib::RGADoriginatorLookup($thisfile_riff_raw_rgad_track['originator']);
180
+ $thisfile_riff['rgad']['track']['adjustment'] = getid3_lib::RGADadjustmentLookup($thisfile_riff_raw_rgad_track['adjustment'], $thisfile_riff_raw_rgad_track['signbit']);
181
+ }
182
+ if (($thisfile_riff_raw_rgad_album['name'] != 0) && ($thisfile_riff_raw_rgad_album['originator'] != 0)) {
183
+ $thisfile_riff['rgad']['album']['name'] = getid3_lib::RGADnameLookup($thisfile_riff_raw_rgad_album['name']);
184
+ $thisfile_riff['rgad']['album']['originator'] = getid3_lib::RGADoriginatorLookup($thisfile_riff_raw_rgad_album['originator']);
185
+ $thisfile_riff['rgad']['album']['adjustment'] = getid3_lib::RGADadjustmentLookup($thisfile_riff_raw_rgad_album['adjustment'], $thisfile_riff_raw_rgad_album['signbit']);
186
+ }
187
+ }
188
+
189
+ if (isset($thisfile_riff_WAVE['fact'][0]['data'])) {
190
+ $thisfile_riff_raw['fact']['NumberOfSamples'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($thisfile_riff_WAVE['fact'][0]['data'], 0, 4));
191
+
192
+ // This should be a good way of calculating exact playtime,
193
+ // but some sample files have had incorrect number of samples,
194
+ // so cannot use this method
195
+
196
+ // if (!empty($thisfile_riff_raw['fmt ']['nSamplesPerSec'])) {
197
+ // $ThisFileInfo['playtime_seconds'] = (float) $thisfile_riff_raw['fact']['NumberOfSamples'] / $thisfile_riff_raw['fmt ']['nSamplesPerSec'];
198
+ // }
199
+ }
200
+ if (!empty($thisfile_riff_raw['fmt ']['nAvgBytesPerSec'])) {
201
+ $thisfile_audio['bitrate'] = getid3_lib::CastAsInt($thisfile_riff_raw['fmt ']['nAvgBytesPerSec'] * 8);
202
+ }
203
+
204
+ if (isset($thisfile_riff_WAVE['bext'][0]['data'])) {
205
+ // shortcut
206
+ $thisfile_riff_WAVE_bext_0 = &$thisfile_riff_WAVE['bext'][0];
207
+
208
+ $thisfile_riff_WAVE_bext_0['title'] = trim(substr($thisfile_riff_WAVE_bext_0['data'], 0, 256));
209
+ $thisfile_riff_WAVE_bext_0['author'] = trim(substr($thisfile_riff_WAVE_bext_0['data'], 256, 32));
210
+ $thisfile_riff_WAVE_bext_0['reference'] = trim(substr($thisfile_riff_WAVE_bext_0['data'], 288, 32));
211
+ $thisfile_riff_WAVE_bext_0['origin_date'] = substr($thisfile_riff_WAVE_bext_0['data'], 320, 10);
212
+ $thisfile_riff_WAVE_bext_0['origin_time'] = substr($thisfile_riff_WAVE_bext_0['data'], 330, 8);
213
+ $thisfile_riff_WAVE_bext_0['time_reference'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_bext_0['data'], 338, 8));
214
+ $thisfile_riff_WAVE_bext_0['bwf_version'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_bext_0['data'], 346, 1));
215
+ $thisfile_riff_WAVE_bext_0['reserved'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_bext_0['data'], 347, 254));
216
+ $thisfile_riff_WAVE_bext_0['coding_history'] = explode("\r\n", trim(substr($thisfile_riff_WAVE_bext_0['data'], 601)));
217
+
218
+ $thisfile_riff_WAVE_bext_0['origin_date_unix'] = gmmktime(
219
+ substr($thisfile_riff_WAVE_bext_0['origin_time'], 0, 2),
220
+ substr($thisfile_riff_WAVE_bext_0['origin_time'], 3, 2),
221
+ substr($thisfile_riff_WAVE_bext_0['origin_time'], 6, 2),
222
+ substr($thisfile_riff_WAVE_bext_0['origin_date'], 5, 2),
223
+ substr($thisfile_riff_WAVE_bext_0['origin_date'], 8, 2),
224
+ substr($thisfile_riff_WAVE_bext_0['origin_date'], 0, 4));
225
+
226
+ $thisfile_riff['comments']['author'][] = $thisfile_riff_WAVE_bext_0['author'];
227
+ $thisfile_riff['comments']['title'][] = $thisfile_riff_WAVE_bext_0['title'];
228
+ }
229
+
230
+ if (isset($thisfile_riff_WAVE['MEXT'][0]['data'])) {
231
+ // shortcut
232
+ $thisfile_riff_WAVE_MEXT_0 = &$thisfile_riff_WAVE['MEXT'][0];
233
+
234
+ $thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_MEXT_0['data'], 0, 2));
235
+ $thisfile_riff_WAVE_MEXT_0['flags']['homogenous'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] & 0x0001);
236
+ if ($thisfile_riff_WAVE_MEXT_0['flags']['homogenous']) {
237
+ $thisfile_riff_WAVE_MEXT_0['flags']['padding'] = ($thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] & 0x0002) ? false : true;
238
+ $thisfile_riff_WAVE_MEXT_0['flags']['22_or_44'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] & 0x0004);
239
+ $thisfile_riff_WAVE_MEXT_0['flags']['free_format'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] & 0x0008);
240
+
241
+ $thisfile_riff_WAVE_MEXT_0['nominal_frame_size'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_MEXT_0['data'], 2, 2));
242
+ }
243
+ $thisfile_riff_WAVE_MEXT_0['anciliary_data_length'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_MEXT_0['data'], 6, 2));
244
+ $thisfile_riff_WAVE_MEXT_0['raw']['anciliary_data_def'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_MEXT_0['data'], 8, 2));
245
+ $thisfile_riff_WAVE_MEXT_0['flags']['anciliary_data_left'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['anciliary_data_def'] & 0x0001);
246
+ $thisfile_riff_WAVE_MEXT_0['flags']['anciliary_data_free'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['anciliary_data_def'] & 0x0002);
247
+ $thisfile_riff_WAVE_MEXT_0['flags']['anciliary_data_right'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['anciliary_data_def'] & 0x0004);
248
+ }
249
+
250
+ if (isset($thisfile_riff_WAVE['cart'][0]['data'])) {
251
+ // shortcut
252
+ $thisfile_riff_WAVE_cart_0 = &$thisfile_riff_WAVE['cart'][0];
253
+
254
+ $thisfile_riff_WAVE_cart_0['version'] = substr($thisfile_riff_WAVE_cart_0['data'], 0, 4);
255
+ $thisfile_riff_WAVE_cart_0['title'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 4, 64));
256
+ $thisfile_riff_WAVE_cart_0['artist'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 68, 64));
257
+ $thisfile_riff_WAVE_cart_0['cut_id'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 132, 64));
258
+ $thisfile_riff_WAVE_cart_0['client_id'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 196, 64));
259
+ $thisfile_riff_WAVE_cart_0['category'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 260, 64));
260
+ $thisfile_riff_WAVE_cart_0['classification'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 324, 64));
261
+ $thisfile_riff_WAVE_cart_0['out_cue'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 388, 64));
262
+ $thisfile_riff_WAVE_cart_0['start_date'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 452, 10));
263
+ $thisfile_riff_WAVE_cart_0['start_time'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 462, 8));
264
+ $thisfile_riff_WAVE_cart_0['end_date'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 470, 10));
265
+ $thisfile_riff_WAVE_cart_0['end_time'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 480, 8));
266
+ $thisfile_riff_WAVE_cart_0['producer_app_id'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 488, 64));
267
+ $thisfile_riff_WAVE_cart_0['producer_app_version'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 552, 64));
268
+ $thisfile_riff_WAVE_cart_0['user_defined_text'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 616, 64));
269
+ $thisfile_riff_WAVE_cart_0['zero_db_reference'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_cart_0['data'], 680, 4), true);
270
+ for ($i = 0; $i < 8; $i++) {
271
+ $thisfile_riff_WAVE_cart_0['post_time'][$i]['usage_fourcc'] = substr($thisfile_riff_WAVE_cart_0['data'], 684 + ($i * 8), 4);
272
+ $thisfile_riff_WAVE_cart_0['post_time'][$i]['timer_value'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_cart_0['data'], 684 + ($i * 8) + 4, 4));
273
+ }
274
+ $thisfile_riff_WAVE_cart_0['url'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 748, 1024));
275
+ $thisfile_riff_WAVE_cart_0['tag_text'] = explode("\r\n", trim(substr($thisfile_riff_WAVE_cart_0['data'], 1772)));
276
+
277
+ $thisfile_riff['comments']['artist'][] = $thisfile_riff_WAVE_cart_0['artist'];
278
+ $thisfile_riff['comments']['title'][] = $thisfile_riff_WAVE_cart_0['title'];
279
+ }
280
+
281
+ if (!isset($thisfile_audio['bitrate']) && isset($thisfile_riff_audio[$streamindex]['bitrate'])) {
282
+ $thisfile_audio['bitrate'] = $thisfile_riff_audio[$streamindex]['bitrate'];
283
+ $ThisFileInfo['playtime_seconds'] = (float) ((($thisfile_avdataend - $thisfile_avdataoffset) * 8) / $thisfile_audio['bitrate']);
284
+ }
285
+
286
+ if (!empty($ThisFileInfo['wavpack'])) {
287
+ $thisfile_audio_dataformat = 'wavpack';
288
+ $thisfile_audio['bitrate_mode'] = 'vbr';
289
+ $thisfile_audio['encoder'] = 'WavPack v'.$ThisFileInfo['wavpack']['version'];
290
+
291
+ // Reset to the way it was - RIFF parsing will have messed this up
292
+ $thisfile_avdataend = $Original['avdataend'];
293
+ $thisfile_audio['bitrate'] = (($thisfile_avdataend - $thisfile_avdataoffset) * 8) / $ThisFileInfo['playtime_seconds'];
294
+
295
+ fseek($fd, $thisfile_avdataoffset - 44, SEEK_SET);
296
+ $RIFFdata = fread($fd, 44);
297
+ $OrignalRIFFheaderSize = getid3_lib::LittleEndian2Int(substr($RIFFdata, 4, 4)) + 8;
298
+ $OrignalRIFFdataSize = getid3_lib::LittleEndian2Int(substr($RIFFdata, 40, 4)) + 44;
299
+
300
+ if ($OrignalRIFFheaderSize > $OrignalRIFFdataSize) {
301
+ $thisfile_avdataend -= ($OrignalRIFFheaderSize - $OrignalRIFFdataSize);
302
+ fseek($fd, $thisfile_avdataend, SEEK_SET);
303
+ $RIFFdata .= fread($fd, $OrignalRIFFheaderSize - $OrignalRIFFdataSize);
304
+ }
305
+
306
+ // move the data chunk after all other chunks (if any)
307
+ // so that the RIFF parser doesn't see EOF when trying
308
+ // to skip over the data chunk
309
+ $RIFFdata = substr($RIFFdata, 0, 36).substr($RIFFdata, 44).substr($RIFFdata, 36, 8);
310
+ getid3_riff::ParseRIFFdata($RIFFdata, $ThisFileInfo);
311
+ }
312
+
313
+ if (isset($thisfile_riff_raw['fmt ']['wFormatTag'])) {
314
+ switch ($thisfile_riff_raw['fmt ']['wFormatTag']) {
315
+ case 0x08AE: // ClearJump LiteWave
316
+ $thisfile_audio['bitrate_mode'] = 'vbr';
317
+ $thisfile_audio_dataformat = 'litewave';
318
+
319
+ //typedef struct tagSLwFormat {
320
+ // WORD m_wCompFormat; // low byte defines compression method, high byte is compression flags
321
+ // DWORD m_dwScale; // scale factor for lossy compression
322
+ // DWORD m_dwBlockSize; // number of samples in encoded blocks
323
+ // WORD m_wQuality; // alias for the scale factor
324
+ // WORD m_wMarkDistance; // distance between marks in bytes
325
+ // WORD m_wReserved;
326
+ //
327
+ // //following paramters are ignored if CF_FILESRC is not set
328
+ // DWORD m_dwOrgSize; // original file size in bytes
329
+ // WORD m_bFactExists; // indicates if 'fact' chunk exists in the original file
330
+ // DWORD m_dwRiffChunkSize; // riff chunk size in the original file
331
+ //
332
+ // PCMWAVEFORMAT m_OrgWf; // original wave format
333
+ // }SLwFormat, *PSLwFormat;
334
+
335
+ // shortcut
336
+ $thisfile_riff['litewave']['raw'] = array();
337
+ $thisfile_riff_litewave = &$thisfile_riff['litewave'];
338
+ $thisfile_riff_litewave_raw = &$thisfile_riff_litewave['raw'];
339
+
340
+ $thisfile_riff_litewave_raw['compression_method'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE['fmt '][0]['data'], 18, 1));
341
+ $thisfile_riff_litewave_raw['compression_flags'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE['fmt '][0]['data'], 19, 1));
342
+ $thisfile_riff_litewave_raw['m_dwScale'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE['fmt '][0]['data'], 20, 4));
343
+ $thisfile_riff_litewave_raw['m_dwBlockSize'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE['fmt '][0]['data'], 24, 4));
344
+ $thisfile_riff_litewave_raw['m_wQuality'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE['fmt '][0]['data'], 28, 2));
345
+ $thisfile_riff_litewave_raw['m_wMarkDistance'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE['fmt '][0]['data'], 30, 2));
346
+ $thisfile_riff_litewave_raw['m_wReserved'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE['fmt '][0]['data'], 32, 2));
347
+ $thisfile_riff_litewave_raw['m_dwOrgSize'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE['fmt '][0]['data'], 34, 4));
348
+ $thisfile_riff_litewave_raw['m_bFactExists'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE['fmt '][0]['data'], 38, 2));
349
+ $thisfile_riff_litewave_raw['m_dwRiffChunkSize'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE['fmt '][0]['data'], 40, 4));
350
+
351
+ //$thisfile_riff_litewave['quality_factor'] = intval(round((2000 - $thisfile_riff_litewave_raw['m_dwScale']) / 20));
352
+ $thisfile_riff_litewave['quality_factor'] = $thisfile_riff_litewave_raw['m_wQuality'];
353
+
354
+ $thisfile_riff_litewave['flags']['raw_source'] = ($thisfile_riff_litewave_raw['compression_flags'] & 0x01) ? false : true;
355
+ $thisfile_riff_litewave['flags']['vbr_blocksize'] = ($thisfile_riff_litewave_raw['compression_flags'] & 0x02) ? false : true;
356
+ $thisfile_riff_litewave['flags']['seekpoints'] = (bool) ($thisfile_riff_litewave_raw['compression_flags'] & 0x04);
357
+
358
+ $thisfile_audio['lossless'] = (($thisfile_riff_litewave_raw['m_wQuality'] == 100) ? true : false);
359
+ $thisfile_audio['encoder_options'] = '-q'.$thisfile_riff_litewave['quality_factor'];
360
+ break;
361
+
362
+ default:
363
+ break;
364
+ }
365
+ }
366
+ if ($thisfile_avdataend > $ThisFileInfo['filesize']) {
367
+ switch (@$thisfile_audio_dataformat) {
368
+ case 'wavpack': // WavPack
369
+ case 'lpac': // LPAC
370
+ case 'ofr': // OptimFROG
371
+ case 'ofs': // OptimFROG DualStream
372
+ // lossless compressed audio formats that keep original RIFF headers - skip warning
373
+ break;
374
+
375
+ case 'litewave':
376
+ if (($thisfile_avdataend - $ThisFileInfo['filesize']) == 1) {
377
+ // LiteWave appears to incorrectly *not* pad actual output file
378
+ // to nearest WORD boundary so may appear to be short by one
379
+ // byte, in which case - skip warning
380
+ } else {
381
+ // Short by more than one byte, throw warning
382
+ $ThisFileInfo['warning'][] = 'Probably truncated file - expecting '.$thisfile_riff[$RIFFsubtype]['data'][0]['size'].' bytes of data, only found '.($ThisFileInfo['filesize'] - $thisfile_avdataoffset).' (short by '.($thisfile_riff[$RIFFsubtype]['data'][0]['size'] - ($ThisFileInfo['filesize'] - $thisfile_avdataoffset)).' bytes)';
383
+ $thisfile_avdataend = $ThisFileInfo['filesize'];
384
+ }
385
+ break;
386
+
387
+ default:
388
+ if ((($thisfile_avdataend - $ThisFileInfo['filesize']) == 1) && (($thisfile_riff[$RIFFsubtype]['data'][0]['size'] % 2) == 0) && ((($ThisFileInfo['filesize'] - $thisfile_avdataoffset) % 2) == 1)) {
389
+ // output file appears to be incorrectly *not* padded to nearest WORD boundary
390
+ // Output less severe warning
391
+ $ThisFileInfo['warning'][] = 'File should probably be padded to nearest WORD boundary, but it is not (expecting '.$thisfile_riff[$RIFFsubtype]['data'][0]['size'].' bytes of data, only found '.($ThisFileInfo['filesize'] - $thisfile_avdataoffset).' therefore short by '.($thisfile_riff[$RIFFsubtype]['data'][0]['size'] - ($ThisFileInfo['filesize'] - $thisfile_avdataoffset)).' bytes)';
392
+ $thisfile_avdataend = $ThisFileInfo['filesize'];
393
+ break;
394
+ }
395
+ // Short by more than one byte, throw warning
396
+ $ThisFileInfo['warning'][] = 'Probably truncated file - expecting '.$thisfile_riff[$RIFFsubtype]['data'][0]['size'].' bytes of data, only found '.($ThisFileInfo['filesize'] - $thisfile_avdataoffset).' (short by '.($thisfile_riff[$RIFFsubtype]['data'][0]['size'] - ($ThisFileInfo['filesize'] - $thisfile_avdataoffset)).' bytes)';
397
+ $thisfile_avdataend = $ThisFileInfo['filesize'];
398
+ break;
399
+ }
400
+ }
401
+ if (!empty($ThisFileInfo['mpeg']['audio']['LAME']['audio_bytes'])) {
402
+ if ((($thisfile_avdataend - $thisfile_avdataoffset) - $ThisFileInfo['mpeg']['audio']['LAME']['audio_bytes']) == 1) {
403
+ $thisfile_avdataend--;
404
+ $ThisFileInfo['warning'][] = 'Extra null byte at end of MP3 data assumed to be RIFF padding and therefore ignored';
405
+ }
406
+ }
407
+ if (@$thisfile_audio_dataformat == 'ac3') {
408
+ unset($thisfile_audio['bits_per_sample']);
409
+ if (!empty($ThisFileInfo['ac3']['bitrate']) && ($ThisFileInfo['ac3']['bitrate'] != $thisfile_audio['bitrate'])) {
410
+ $thisfile_audio['bitrate'] = $ThisFileInfo['ac3']['bitrate'];
411
+ }
412
+ }
413
+ break;
414
+
415
+ case 'AVI ':
416
+ $thisfile_video['bitrate_mode'] = 'vbr'; // maybe not, but probably
417
+ $thisfile_video['dataformat'] = 'avi';
418
+ $ThisFileInfo['mime_type'] = 'video/avi';
419
+
420
+ if (isset($thisfile_riff[$RIFFsubtype]['movi']['offset'])) {
421
+ $thisfile_avdataoffset = $thisfile_riff[$RIFFsubtype]['movi']['offset'] + 8;
422
+ $thisfile_avdataend = $thisfile_avdataoffset + $thisfile_riff[$RIFFsubtype]['movi']['size'];
423
+ if ($thisfile_avdataend > $ThisFileInfo['filesize']) {
424
+ $ThisFileInfo['warning'][] = 'Probably truncated file - expecting '.$thisfile_riff[$RIFFsubtype]['movi']['size'].' bytes of data, only found '.($ThisFileInfo['filesize'] - $thisfile_avdataoffset).' (short by '.($thisfile_riff[$RIFFsubtype]['movi']['size'] - ($ThisFileInfo['filesize'] - $thisfile_avdataoffset)).' bytes)';
425
+ $thisfile_avdataend = $ThisFileInfo['filesize'];
426
+ }
427
+ }
428
+
429
+ if (isset($thisfile_riff['AVI ']['hdrl']['strl']['indx'])) {
430
+ //$bIndexType = array(
431
+ // 0x00 => 'AVI_INDEX_OF_INDEXES',
432
+ // 0x01 => 'AVI_INDEX_OF_CHUNKS',
433
+ // 0x80 => 'AVI_INDEX_IS_DATA',
434
+ //);
435
+ //$bIndexSubtype = array(
436
+ // 0x01 => array(
437
+ // 0x01 => 'AVI_INDEX_2FIELD',
438
+ // ),
439
+ //);
440
+ foreach ($thisfile_riff['AVI ']['hdrl']['strl']['indx'] as $streamnumber => $steamdataarray) {
441
+ $thisfile_riff_avi_hdrl_strl_indx_stream_data = &$thisfile_riff['AVI ']['hdrl']['strl']['indx'][$streamnumber]['data'];
442
+
443
+ $thisfile_riff_raw['indx'][$streamnumber]['wLongsPerEntry'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($thisfile_riff_avi_hdrl_strl_indx_stream_data, 0, 2));
444
+ $thisfile_riff_raw['indx'][$streamnumber]['bIndexSubType'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($thisfile_riff_avi_hdrl_strl_indx_stream_data, 2, 1));
445
+ $thisfile_riff_raw['indx'][$streamnumber]['bIndexType'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($thisfile_riff_avi_hdrl_strl_indx_stream_data, 3, 1));
446
+ $thisfile_riff_raw['indx'][$streamnumber]['nEntriesInUse'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($thisfile_riff_avi_hdrl_strl_indx_stream_data, 4, 4));
447
+ $thisfile_riff_raw['indx'][$streamnumber]['dwChunkId'] = substr($thisfile_riff_avi_hdrl_strl_indx_stream_data, 8, 4);
448
+ $thisfile_riff_raw['indx'][$streamnumber]['dwReserved'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($thisfile_riff_avi_hdrl_strl_indx_stream_data, 12, 4));
449
+
450
+ //$thisfile_riff_raw['indx'][$streamnumber]['bIndexType_name'] = @$bIndexType[$thisfile_riff_raw['indx'][$streamnumber]['bIndexType']];
451
+ //$thisfile_riff_raw['indx'][$streamnumber]['bIndexSubType_name'] = @$bIndexSubtype[$thisfile_riff_raw['indx'][$streamnumber]['bIndexType']][$thisfile_riff_raw['indx'][$streamnumber]['bIndexSubType']];
452
+
453
+ unset($thisfile_riff_avi_hdrl_strl_indx_stream_data);
454
+ }
455
+ }
456
+ if (isset($thisfile_riff['AVI ']['hdrl']['avih'][$streamindex]['data'])) {
457
+ $avihData = $thisfile_riff['AVI ']['hdrl']['avih'][$streamindex]['data'];
458
+
459
+ // shortcut
460
+ $thisfile_riff_raw['avih'] = array();
461
+ $thisfile_riff_raw_avih = &$thisfile_riff_raw['avih'];
462
+
463
+ $thisfile_riff_raw_avih['dwMicroSecPerFrame'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($avihData, 0, 4)); // frame display rate (or 0L)
464
+ if ($thisfile_riff_raw_avih['dwMicroSecPerFrame'] == 0) {
465
+ $ThisFileInfo['error'][] = 'Corrupt RIFF file: avih.dwMicroSecPerFrame == zero';
466
+ return false;
467
+ }
468
+ $thisfile_riff_raw_avih['dwMaxBytesPerSec'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($avihData, 4, 4)); // max. transfer rate
469
+ $thisfile_riff_raw_avih['dwPaddingGranularity'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($avihData, 8, 4)); // pad to multiples of this size; normally 2K.
470
+ $thisfile_riff_raw_avih['dwFlags'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($avihData, 12, 4)); // the ever-present flags
471
+ $thisfile_riff_raw_avih['dwTotalFrames'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($avihData, 16, 4)); // # frames in file
472
+ $thisfile_riff_raw_avih['dwInitialFrames'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($avihData, 20, 4));
473
+ $thisfile_riff_raw_avih['dwStreams'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($avihData, 24, 4));
474
+ $thisfile_riff_raw_avih['dwSuggestedBufferSize'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($avihData, 28, 4));
475
+ $thisfile_riff_raw_avih['dwWidth'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($avihData, 32, 4));
476
+ $thisfile_riff_raw_avih['dwHeight'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($avihData, 36, 4));
477
+ $thisfile_riff_raw_avih['dwScale'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($avihData, 40, 4));
478
+ $thisfile_riff_raw_avih['dwRate'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($avihData, 44, 4));
479
+ $thisfile_riff_raw_avih['dwStart'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($avihData, 48, 4));
480
+ $thisfile_riff_raw_avih['dwLength'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($avihData, 52, 4));
481
+
482
+ $thisfile_riff_raw_avih['flags']['hasindex'] = (bool) ($thisfile_riff_raw_avih['dwFlags'] & 0x00000010);
483
+ $thisfile_riff_raw_avih['flags']['mustuseindex'] = (bool) ($thisfile_riff_raw_avih['dwFlags'] & 0x00000020);
484
+ $thisfile_riff_raw_avih['flags']['interleaved'] = (bool) ($thisfile_riff_raw_avih['dwFlags'] & 0x00000100);
485
+ $thisfile_riff_raw_avih['flags']['trustcktype'] = (bool) ($thisfile_riff_raw_avih['dwFlags'] & 0x00000800);
486
+ $thisfile_riff_raw_avih['flags']['capturedfile'] = (bool) ($thisfile_riff_raw_avih['dwFlags'] & 0x00010000);
487
+ $thisfile_riff_raw_avih['flags']['copyrighted'] = (bool) ($thisfile_riff_raw_avih['dwFlags'] & 0x00020010);
488
+
489
+ // shortcut
490
+ $thisfile_riff_video[$streamindex] = array();
491
+ $thisfile_riff_video_current = &$thisfile_riff_video[$streamindex];
492
+
493
+ if ($thisfile_riff_raw_avih['dwWidth'] > 0) {
494
+ $thisfile_riff_video_current['frame_width'] = $thisfile_riff_raw_avih['dwWidth'];
495
+ $thisfile_video['resolution_x'] = $thisfile_riff_video_current['frame_width'];
496
+ }
497
+ if ($thisfile_riff_raw_avih['dwHeight'] > 0) {
498
+ $thisfile_riff_video_current['frame_height'] = $thisfile_riff_raw_avih['dwHeight'];
499
+ $thisfile_video['resolution_y'] = $thisfile_riff_video_current['frame_height'];
500
+ }
501
+ if ($thisfile_riff_raw_avih['dwTotalFrames'] > 0) {
502
+ $thisfile_riff_video_current['total_frames'] = $thisfile_riff_raw_avih['dwTotalFrames'];
503
+ $thisfile_video['total_frames'] = $thisfile_riff_video_current['total_frames'];
504
+ }
505
+
506
+ $thisfile_riff_video_current['frame_rate'] = round(1000000 / $thisfile_riff_raw_avih['dwMicroSecPerFrame'], 3);
507
+ $thisfile_video['frame_rate'] = $thisfile_riff_video_current['frame_rate'];
508
+ }
509
+ if (isset($thisfile_riff['AVI ']['hdrl']['strl']['strh'][0]['data'])) {
510
+ if (is_array($thisfile_riff['AVI ']['hdrl']['strl']['strh'])) {
511
+ for ($i = 0; $i < count($thisfile_riff['AVI ']['hdrl']['strl']['strh']); $i++) {
512
+ if (isset($thisfile_riff['AVI ']['hdrl']['strl']['strh'][$i]['data'])) {
513
+ $strhData = $thisfile_riff['AVI ']['hdrl']['strl']['strh'][$i]['data'];
514
+ $strhfccType = substr($strhData, 0, 4);
515
+
516
+ if (isset($thisfile_riff['AVI ']['hdrl']['strl']['strf'][$i]['data'])) {
517
+ $strfData = $thisfile_riff['AVI ']['hdrl']['strl']['strf'][$i]['data'];
518
+
519
+ // shortcut
520
+ $thisfile_riff_raw_strf_strhfccType_streamindex = &$thisfile_riff_raw['strf'][$strhfccType][$streamindex];
521
+
522
+ switch ($strhfccType) {
523
+ case 'auds':
524
+ $thisfile_audio['bitrate_mode'] = 'cbr';
525
+ $thisfile_audio_dataformat = 'wav';
526
+ if (isset($thisfile_riff_audio) && is_array($thisfile_riff_audio)) {
527
+ $streamindex = count($thisfile_riff_audio);
528
+ }
529
+
530
+ $thisfile_riff_audio[$streamindex] = getid3_riff::RIFFparseWAVEFORMATex($strfData);
531
+ $thisfile_audio['wformattag'] = $thisfile_riff_audio[$streamindex]['raw']['wFormatTag'];
532
+
533
+ // shortcut
534
+ $thisfile_audio['streams'][$streamindex] = $thisfile_riff_audio[$streamindex];
535
+ $thisfile_audio_streams_currentstream = &$thisfile_audio['streams'][$streamindex];
536
+
537
+ if ($thisfile_audio_streams_currentstream['bits_per_sample'] == 0) {
538
+ unset($thisfile_audio_streams_currentstream['bits_per_sample']);
539
+ }
540
+ $thisfile_audio_streams_currentstream['wformattag'] = $thisfile_audio_streams_currentstream['raw']['wFormatTag'];
541
+ unset($thisfile_audio_streams_currentstream['raw']);
542
+
543
+ // shortcut
544
+ $thisfile_riff_raw['strf'][$strhfccType][$streamindex] = $thisfile_riff_audio[$streamindex]['raw'];
545
+
546
+ unset($thisfile_riff_audio[$streamindex]['raw']);
547
+ $thisfile_audio = getid3_lib::array_merge_noclobber($thisfile_audio, $thisfile_riff_audio[$streamindex]);
548
+
549
+ $thisfile_audio['lossless'] = false;
550
+ switch ($thisfile_riff_raw_strf_strhfccType_streamindex['wFormatTag']) {
551
+ case 0x0001: // PCM
552
+ $thisfile_audio_dataformat = 'wav';
553
+ $thisfile_audio['lossless'] = true;
554
+ break;
555
+
556
+ case 0x0050: // MPEG Layer 2 or Layer 1
557
+ $thisfile_audio_dataformat = 'mp2'; // Assume Layer-2
558
+ break;
559
+
560
+ case 0x0055: // MPEG Layer 3
561
+ $thisfile_audio_dataformat = 'mp3';
562
+ break;
563
+
564
+ case 0x00FF: // AAC
565
+ $thisfile_audio_dataformat = 'aac';
566
+ break;
567
+
568
+ case 0x0161: // Windows Media v7 / v8 / v9
569
+ case 0x0162: // Windows Media Professional v9
570
+ case 0x0163: // Windows Media Lossess v9
571
+ $thisfile_audio_dataformat = 'wma';
572
+ break;
573
+
574
+ case 0x2000: // AC-3
575
+ $thisfile_audio_dataformat = 'ac3';
576
+ break;
577
+
578
+ case 0x2001: // DTS
579
+ $thisfile_audio_dataformat = 'dts';
580
+ break;
581
+
582
+ default:
583
+ $thisfile_audio_dataformat = 'wav';
584
+ break;
585
+ }
586
+ $thisfile_audio_streams_currentstream['dataformat'] = $thisfile_audio_dataformat;
587
+ $thisfile_audio_streams_currentstream['lossless'] = $thisfile_audio['lossless'];
588
+ $thisfile_audio_streams_currentstream['bitrate_mode'] = $thisfile_audio['bitrate_mode'];
589
+ break;
590
+
591
+
592
+ case 'iavs':
593
+ case 'vids':
594
+ // shortcut
595
+ $thisfile_riff_raw['strh'][$i] = array();
596
+ $thisfile_riff_raw_strh_current = &$thisfile_riff_raw['strh'][$i];
597
+
598
+ $thisfile_riff_raw_strh_current['fccType'] = substr($strhData, 0, 4); // same as $strhfccType;
599
+ $thisfile_riff_raw_strh_current['fccHandler'] = substr($strhData, 4, 4);
600
+ $thisfile_riff_raw_strh_current['dwFlags'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($strhData, 8, 4)); // Contains AVITF_* flags
601
+ $thisfile_riff_raw_strh_current['wPriority'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($strhData, 12, 2));
602
+ $thisfile_riff_raw_strh_current['wLanguage'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($strhData, 14, 2));
603
+ $thisfile_riff_raw_strh_current['dwInitialFrames'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($strhData, 16, 4));
604
+ $thisfile_riff_raw_strh_current['dwScale'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($strhData, 20, 4));
605
+ $thisfile_riff_raw_strh_current['dwRate'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($strhData, 24, 4));
606
+ $thisfile_riff_raw_strh_current['dwStart'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($strhData, 28, 4));
607
+ $thisfile_riff_raw_strh_current['dwLength'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($strhData, 32, 4));
608
+ $thisfile_riff_raw_strh_current['dwSuggestedBufferSize'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($strhData, 36, 4));
609
+ $thisfile_riff_raw_strh_current['dwQuality'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($strhData, 40, 4));
610
+ $thisfile_riff_raw_strh_current['dwSampleSize'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($strhData, 44, 4));
611
+ $thisfile_riff_raw_strh_current['rcFrame'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($strhData, 48, 4));
612
+
613
+ $thisfile_riff_video_current['codec'] = getid3_riff::RIFFfourccLookup($thisfile_riff_raw_strh_current['fccHandler']);
614
+ $thisfile_video['fourcc'] = $thisfile_riff_raw_strh_current['fccHandler'];
615
+ if (!$thisfile_riff_video_current['codec'] && isset($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc']) && getid3_riff::RIFFfourccLookup($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc'])) {
616
+ $thisfile_riff_video_current['codec'] = getid3_riff::RIFFfourccLookup($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc']);
617
+ $thisfile_video['fourcc'] = $thisfile_riff_raw_strf_strhfccType_streamindex['fourcc'];
618
+ }
619
+ $thisfile_video['codec'] = $thisfile_riff_video_current['codec'];
620
+ $thisfile_video['pixel_aspect_ratio'] = (float) 1;
621
+ switch ($thisfile_riff_raw_strh_current['fccHandler']) {
622
+ case 'HFYU': // Huffman Lossless Codec
623
+ case 'IRAW': // Intel YUV Uncompressed
624
+ case 'YUY2': // Uncompressed YUV 4:2:2
625
+ $thisfile_video['lossless'] = true;
626
+ break;
627
+
628
+ default:
629
+ $thisfile_video['lossless'] = false;
630
+ break;
631
+ }
632
+
633
+ switch ($strhfccType) {
634
+ case 'vids':
635
+ $thisfile_riff_raw_strf_strhfccType_streamindex = getid3_riff::ParseBITMAPINFOHEADER(substr($strfData, 0, 40), ($ThisFileInfo['fileformat'] == 'riff'));
636
+ //$thisfile_riff_raw_strf_strhfccType_streamindex['biSize'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($strfData, 0, 4)); // number of bytes required by the BITMAPINFOHEADER structure
637
+ //$thisfile_riff_raw_strf_strhfccType_streamindex['biWidth'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($strfData, 4, 4)); // width of the bitmap in pixels
638
+ //$thisfile_riff_raw_strf_strhfccType_streamindex['biHeight'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($strfData, 8, 4)); // height of the bitmap in pixels. If biHeight is positive, the bitmap is a 'bottom-up' DIB and its origin is the lower left corner. If biHeight is negative, the bitmap is a 'top-down' DIB and its origin is the upper left corner
639
+ //$thisfile_riff_raw_strf_strhfccType_streamindex['biPlanes'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($strfData, 12, 2)); // number of color planes on the target device. In most cases this value must be set to 1
640
+ //$thisfile_riff_raw_strf_strhfccType_streamindex['biBitCount'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($strfData, 14, 2)); // Specifies the number of bits per pixels
641
+ //$thisfile_riff_raw_strf_strhfccType_streamindex['fourcc'] = substr($strfData, 16, 4); //
642
+ //$thisfile_riff_raw_strf_strhfccType_streamindex['biSizeImage'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($strfData, 20, 4)); // size of the bitmap data section of the image (the actual pixel data, excluding BITMAPINFOHEADER and RGBQUAD structures)
643
+ //$thisfile_riff_raw_strf_strhfccType_streamindex['biXPelsPerMeter'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($strfData, 24, 4)); // horizontal resolution, in pixels per metre, of the target device
644
+ //$thisfile_riff_raw_strf_strhfccType_streamindex['biYPelsPerMeter'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($strfData, 28, 4)); // vertical resolution, in pixels per metre, of the target device
645
+ //$thisfile_riff_raw_strf_strhfccType_streamindex['biClrUsed'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($strfData, 32, 4)); // actual number of color indices in the color table used by the bitmap. If this value is zero, the bitmap uses the maximum number of colors corresponding to the value of the biBitCount member for the compression mode specified by biCompression
646
+ //$thisfile_riff_raw_strf_strhfccType_streamindex['biClrImportant'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($strfData, 36, 4)); // number of color indices that are considered important for displaying the bitmap. If this value is zero, all colors are important
647
+
648
+ $thisfile_video['bits_per_sample'] = $thisfile_riff_raw_strf_strhfccType_streamindex['biBitCount'];
649
+
650
+ if ($thisfile_riff_video_current['codec'] == 'DV') {
651
+ $thisfile_riff_video_current['dv_type'] = 2;
652
+ }
653
+ break;
654
+
655
+ case 'iavs':
656
+ $thisfile_riff_video_current['dv_type'] = 1;
657
+ break;
658
+ }
659
+ break;
660
+
661
+ default:
662
+ $ThisFileInfo['warning'][] = 'Unhandled fccType for stream ('.$i.'): "'.$strhfccType.'"';
663
+ break;
664
+
665
+ }
666
+ }
667
+ }
668
+
669
+ if (isset($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc']) && getid3_riff::RIFFfourccLookup($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc'])) {
670
+
671
+ $thisfile_riff_video_current['codec'] = getid3_riff::RIFFfourccLookup($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc']);
672
+ $thisfile_video['codec'] = $thisfile_riff_video_current['codec'];
673
+ $thisfile_video['fourcc'] = $thisfile_riff_raw_strf_strhfccType_streamindex['fourcc'];
674
+
675
+ switch ($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc']) {
676
+ case 'HFYU': // Huffman Lossless Codec
677
+ case 'IRAW': // Intel YUV Uncompressed
678
+ case 'YUY2': // Uncompressed YUV 4:2:2
679
+ $thisfile_video['lossless'] = true;
680
+ $thisfile_video['bits_per_sample'] = 24;
681
+ break;
682
+
683
+ default:
684
+ $thisfile_video['lossless'] = false;
685
+ $thisfile_video['bits_per_sample'] = 24;
686
+ break;
687
+ }
688
+
689
+ }
690
+ }
691
+ }
692
+ }
693
+ break;
694
+
695
+ case 'CDDA':
696
+ $thisfile_audio['bitrate_mode'] = 'cbr';
697
+ $thisfile_audio_dataformat = 'cda';
698
+ $thisfile_audio['lossless'] = true;
699
+ unset($ThisFileInfo['mime_type']);
700
+
701
+ $thisfile_avdataoffset = 44;
702
+
703
+ if (isset($thisfile_riff['CDDA']['fmt '][0]['data'])) {
704
+ // shortcut
705
+ $thisfile_riff_CDDA_fmt_0 = &$thisfile_riff['CDDA']['fmt '][0];
706
+
707
+ $thisfile_riff_CDDA_fmt_0['unknown1'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($thisfile_riff_CDDA_fmt_0['data'], 0, 2));
708
+ $thisfile_riff_CDDA_fmt_0['track_num'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($thisfile_riff_CDDA_fmt_0['data'], 2, 2));
709
+ $thisfile_riff_CDDA_fmt_0['disc_id'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($thisfile_riff_CDDA_fmt_0['data'], 4, 4));
710
+ $thisfile_riff_CDDA_fmt_0['start_offset_frame'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($thisfile_riff_CDDA_fmt_0['data'], 8, 4));
711
+ $thisfile_riff_CDDA_fmt_0['playtime_frames'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($thisfile_riff_CDDA_fmt_0['data'], 12, 4));
712
+ $thisfile_riff_CDDA_fmt_0['unknown6'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($thisfile_riff_CDDA_fmt_0['data'], 16, 4));
713
+ $thisfile_riff_CDDA_fmt_0['unknown7'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($thisfile_riff_CDDA_fmt_0['data'], 20, 4));
714
+
715
+ $thisfile_riff_CDDA_fmt_0['start_offset_seconds'] = (float) $thisfile_riff_CDDA_fmt_0['start_offset_frame'] / 75;
716
+ $thisfile_riff_CDDA_fmt_0['playtime_seconds'] = (float) $thisfile_riff_CDDA_fmt_0['playtime_frames'] / 75;
717
+ $ThisFileInfo['comments']['track'] = $thisfile_riff_CDDA_fmt_0['track_num'];
718
+ $ThisFileInfo['playtime_seconds'] = $thisfile_riff_CDDA_fmt_0['playtime_seconds'];
719
+
720
+ // hardcoded data for CD-audio
721
+ $thisfile_audio['sample_rate'] = 44100;
722
+ $thisfile_audio['channels'] = 2;
723
+ $thisfile_audio['bits_per_sample'] = 16;
724
+ $thisfile_audio['bitrate'] = $thisfile_audio['sample_rate'] * $thisfile_audio['channels'] * $thisfile_audio['bits_per_sample'];
725
+ $thisfile_audio['bitrate_mode'] = 'cbr';
726
+ }
727
+ break;
728
+
729
+
730
+ case 'AIFF':
731
+ case 'AIFC':
732
+ $thisfile_audio['bitrate_mode'] = 'cbr';
733
+ $thisfile_audio_dataformat = 'aiff';
734
+ $thisfile_audio['lossless'] = true;
735
+ $ThisFileInfo['mime_type'] = 'audio/x-aiff';
736
+
737
+ if (isset($thisfile_riff[$RIFFsubtype]['SSND'][0]['offset'])) {
738
+ $thisfile_avdataoffset = $thisfile_riff[$RIFFsubtype]['SSND'][0]['offset'] + 8;
739
+ $thisfile_avdataend = $thisfile_avdataoffset + $thisfile_riff[$RIFFsubtype]['SSND'][0]['size'];
740
+ if ($thisfile_avdataend > $ThisFileInfo['filesize']) {
741
+ if (($thisfile_avdataend == ($ThisFileInfo['filesize'] + 1)) && (($ThisFileInfo['filesize'] % 2) == 1)) {
742
+ // structures rounded to 2-byte boundary, but dumb encoders
743
+ // forget to pad end of file to make this actually work
744
+ } else {
745
+ $ThisFileInfo['warning'][] = 'Probable truncated AIFF file: expecting '.$thisfile_riff[$RIFFsubtype]['SSND'][0]['size'].' bytes of audio data, only '.($ThisFileInfo['filesize'] - $thisfile_avdataoffset).' bytes found';
746
+ }
747
+ $thisfile_avdataend = $ThisFileInfo['filesize'];
748
+ }
749
+ }
750
+
751
+ if (isset($thisfile_riff[$RIFFsubtype]['COMM'][0]['data'])) {
752
+
753
+ // shortcut
754
+ $thisfile_riff_RIFFsubtype_COMM_0_data = &$thisfile_riff[$RIFFsubtype]['COMM'][0]['data'];
755
+
756
+ $thisfile_riff_audio['channels'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_COMM_0_data, 0, 2), true);
757
+ $thisfile_riff_audio['total_samples'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_COMM_0_data, 2, 4), false);
758
+ $thisfile_riff_audio['bits_per_sample'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_COMM_0_data, 6, 2), true);
759
+ $thisfile_riff_audio['sample_rate'] = (int) getid3_lib::BigEndian2Float(substr($thisfile_riff_RIFFsubtype_COMM_0_data, 8, 10));
760
+
761
+ if ($thisfile_riff[$RIFFsubtype]['COMM'][0]['size'] > 18) {
762
+ $thisfile_riff_audio['codec_fourcc'] = substr($thisfile_riff_RIFFsubtype_COMM_0_data, 18, 4);
763
+ $CodecNameSize = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_COMM_0_data, 22, 1), false);
764
+ $thisfile_riff_audio['codec_name'] = substr($thisfile_riff_RIFFsubtype_COMM_0_data, 23, $CodecNameSize);
765
+ switch ($thisfile_riff_audio['codec_name']) {
766
+ case 'NONE':
767
+ $thisfile_audio['codec'] = 'Pulse Code Modulation (PCM)';
768
+ $thisfile_audio['lossless'] = true;
769
+ break;
770
+
771
+ case '':
772
+ switch ($thisfile_riff_audio['codec_fourcc']) {
773
+ // http://developer.apple.com/qa/snd/snd07.html
774
+ case 'sowt':
775
+ $thisfile_riff_audio['codec_name'] = 'Two\'s Compliment Little-Endian PCM';
776
+ $thisfile_audio['lossless'] = true;
777
+ break;
778
+
779
+ case 'twos':
780
+ $thisfile_riff_audio['codec_name'] = 'Two\'s Compliment Big-Endian PCM';
781
+ $thisfile_audio['lossless'] = true;
782
+ break;
783
+
784
+ default:
785
+ break;
786
+ }
787
+ break;
788
+
789
+ default:
790
+ $thisfile_audio['codec'] = $thisfile_riff_audio['codec_name'];
791
+ $thisfile_audio['lossless'] = false;
792
+ break;
793
+ }
794
+ }
795
+
796
+ $thisfile_audio['channels'] = $thisfile_riff_audio['channels'];
797
+ if ($thisfile_riff_audio['bits_per_sample'] > 0) {
798
+ $thisfile_audio['bits_per_sample'] = $thisfile_riff_audio['bits_per_sample'];
799
+ }
800
+ $thisfile_audio['sample_rate'] = $thisfile_riff_audio['sample_rate'];
801
+ if ($thisfile_audio['sample_rate'] == 0) {
802
+ $ThisFileInfo['error'][] = 'Corrupted AIFF file: sample_rate == zero';
803
+ return false;
804
+ }
805
+ $ThisFileInfo['playtime_seconds'] = $thisfile_riff_audio['total_samples'] / $thisfile_audio['sample_rate'];
806
+ }
807
+
808
+ if (isset($thisfile_riff[$RIFFsubtype]['COMT'])) {
809
+ $offset = 0;
810
+ $CommentCount = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, 2), false);
811
+ $offset += 2;
812
+ for ($i = 0; $i < $CommentCount; $i++) {
813
+ $ThisFileInfo['comments_raw'][$i]['timestamp'] = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, 4), false);
814
+ $offset += 4;
815
+ $ThisFileInfo['comments_raw'][$i]['marker_id'] = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, 2), true);
816
+ $offset += 2;
817
+ $CommentLength = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, 2), false);
818
+ $offset += 2;
819
+ $ThisFileInfo['comments_raw'][$i]['comment'] = substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, $CommentLength);
820
+ $offset += $CommentLength;
821
+
822
+ $ThisFileInfo['comments_raw'][$i]['timestamp_unix'] = getid3_lib::DateMac2Unix($ThisFileInfo['comments_raw'][$i]['timestamp']);
823
+ $thisfile_riff['comments']['comment'][] = $ThisFileInfo['comments_raw'][$i]['comment'];
824
+ }
825
+ }
826
+
827
+ $CommentsChunkNames = array('NAME'=>'title', 'author'=>'artist', '(c) '=>'copyright', 'ANNO'=>'comment');
828
+ foreach ($CommentsChunkNames as $key => $value) {
829
+ if (isset($thisfile_riff[$RIFFsubtype][$key][0]['data'])) {
830
+ $thisfile_riff['comments'][$value][] = $thisfile_riff[$RIFFsubtype][$key][0]['data'];
831
+ }
832
+ }
833
+ break;
834
+
835
+ case '8SVX':
836
+ $thisfile_audio['bitrate_mode'] = 'cbr';
837
+ $thisfile_audio_dataformat = '8svx';
838
+ $thisfile_audio['bits_per_sample'] = 8;
839
+ $thisfile_audio['channels'] = 1; // overridden below, if need be
840
+ $ThisFileInfo['mime_type'] = 'audio/x-aiff';
841
+
842
+ if (isset($thisfile_riff[$RIFFsubtype]['BODY'][0]['offset'])) {
843
+ $thisfile_avdataoffset = $thisfile_riff[$RIFFsubtype]['BODY'][0]['offset'] + 8;
844
+ $thisfile_avdataend = $thisfile_avdataoffset + $thisfile_riff[$RIFFsubtype]['BODY'][0]['size'];
845
+ if ($thisfile_avdataend > $ThisFileInfo['filesize']) {
846
+ $ThisFileInfo['warning'][] = 'Probable truncated AIFF file: expecting '.$thisfile_riff[$RIFFsubtype]['BODY'][0]['size'].' bytes of audio data, only '.($ThisFileInfo['filesize'] - $thisfile_avdataoffset).' bytes found';
847
+ }
848
+ }
849
+
850
+ if (isset($thisfile_riff[$RIFFsubtype]['VHDR'][0]['offset'])) {
851
+ // shortcut
852
+ $thisfile_riff_RIFFsubtype_VHDR_0 = &$thisfile_riff[$RIFFsubtype]['VHDR'][0];
853
+
854
+ $thisfile_riff_RIFFsubtype_VHDR_0['oneShotHiSamples'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 0, 4));
855
+ $thisfile_riff_RIFFsubtype_VHDR_0['repeatHiSamples'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 4, 4));
856
+ $thisfile_riff_RIFFsubtype_VHDR_0['samplesPerHiCycle'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 8, 4));
857
+ $thisfile_riff_RIFFsubtype_VHDR_0['samplesPerSec'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 12, 2));
858
+ $thisfile_riff_RIFFsubtype_VHDR_0['ctOctave'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 14, 1));
859
+ $thisfile_riff_RIFFsubtype_VHDR_0['sCompression'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 15, 1));
860
+ $thisfile_riff_RIFFsubtype_VHDR_0['Volume'] = getid3_lib::FixedPoint16_16(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 16, 4));
861
+
862
+ $thisfile_audio['sample_rate'] = $thisfile_riff_RIFFsubtype_VHDR_0['samplesPerSec'];
863
+
864
+ switch ($thisfile_riff_RIFFsubtype_VHDR_0['sCompression']) {
865
+ case 0:
866
+ $thisfile_audio['codec'] = 'Pulse Code Modulation (PCM)';
867
+ $thisfile_audio['lossless'] = true;
868
+ $ActualBitsPerSample = 8;
869
+ break;
870
+
871
+ case 1:
872
+ $thisfile_audio['codec'] = 'Fibonacci-delta encoding';
873
+ $thisfile_audio['lossless'] = false;
874
+ $ActualBitsPerSample = 4;
875
+ break;
876
+
877
+ default:
878
+ $ThisFileInfo['warning'][] = 'Unexpected sCompression value in 8SVX.VHDR chunk - expecting 0 or 1, found "'.sCompression.'"';
879
+ break;
880
+ }
881
+ }
882
+
883
+ if (isset($thisfile_riff[$RIFFsubtype]['CHAN'][0]['data'])) {
884
+ $ChannelsIndex = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['CHAN'][0]['data'], 0, 4));
885
+ switch ($ChannelsIndex) {
886
+ case 6: // Stereo
887
+ $thisfile_audio['channels'] = 2;
888
+ break;
889
+
890
+ case 2: // Left channel only
891
+ case 4: // Right channel only
892
+ $thisfile_audio['channels'] = 1;
893
+ break;
894
+
895
+ default:
896
+ $ThisFileInfo['warning'][] = 'Unexpected value in 8SVX.CHAN chunk - expecting 2 or 4 or 6, found "'.$ChannelsIndex.'"';
897
+ break;
898
+ }
899
+
900
+ }
901
+
902
+ $CommentsChunkNames = array('NAME'=>'title', 'author'=>'artist', '(c) '=>'copyright', 'ANNO'=>'comment');
903
+ foreach ($CommentsChunkNames as $key => $value) {
904
+ if (isset($thisfile_riff[$RIFFsubtype][$key][0]['data'])) {
905
+ $thisfile_riff['comments'][$value][] = $thisfile_riff[$RIFFsubtype][$key][0]['data'];
906
+ }
907
+ }
908
+
909
+ $thisfile_audio['bitrate'] = $thisfile_audio['sample_rate'] * $ActualBitsPerSample * $thisfile_audio['channels'];
910
+ if (!empty($thisfile_audio['bitrate'])) {
911
+ $ThisFileInfo['playtime_seconds'] = ($thisfile_avdataend - $thisfile_avdataoffset) / ($thisfile_audio['bitrate'] / 8);
912
+ }
913
+ break;
914
+
915
+
916
+ case 'CDXA':
917
+ $ThisFileInfo['mime_type'] = 'video/mpeg';
918
+ if (!empty($thisfile_riff['CDXA']['data'][0]['size'])) {
919
+ $GETID3_ERRORARRAY = &$ThisFileInfo['warning'];
920
+ if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.mpeg.php', __FILE__, false)) {
921
+ $dummy = $ThisFileInfo;
922
+ $dummy['error'] = array();
923
+ $mpeg_scanner = new getid3_mpeg($fd, $dummy);
924
+ if (empty($dummy['error'])) {
925
+ $ThisFileInfo['audio'] = $dummy['audio'];
926
+ $ThisFileInfo['video'] = $dummy['video'];
927
+ $ThisFileInfo['mpeg'] = $dummy['mpeg'];
928
+ $ThisFileInfo['warning'] = $dummy['warning'];
929
+ }
930
+ unset($mpeg_scanner);
931
+ }
932
+ }
933
+ break;
934
+
935
+
936
+ default:
937
+ $ThisFileInfo['error'][] = 'Unknown RIFF type: expecting one of (WAVE|RMP3|AVI |CDDA|AIFF|AIFC|8SVX|CDXA), found "'.$RIFFsubtype.'" instead';
938
+ unset($ThisFileInfo['fileformat']);
939
+ break;
940
+ }
941
+
942
+ if (@$thisfile_riff_raw['fmt ']['wFormatTag'] == 1) {
943
+ // http://www.mega-nerd.com/erikd/Blog/Windiots/dts.html
944
+ fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
945
+ $FirstFourBytes = fread($fd, 4);
946
+ if (preg_match('/^\xFF\x1F\x00\xE8/s', $FirstFourBytes)) {
947
+ // DTSWAV
948
+ $thisfile_audio_dataformat = 'dts';
949
+ } elseif (preg_match('/^\x7F\xFF\x80\x01/s', $FirstFourBytes)) {
950
+ // DTS, but this probably shouldn't happen
951
+ $thisfile_audio_dataformat = 'dts';
952
+ }
953
+ }
954
+
955
+
956
+ if (isset($thisfile_riff_WAVE['DISP']) && is_array($thisfile_riff_WAVE['DISP'])) {
957
+ $thisfile_riff['comments']['title'][] = trim(substr($thisfile_riff_WAVE['DISP'][count($thisfile_riff_WAVE['DISP']) - 1]['data'], 4));
958
+ }
959
+ if (isset($thisfile_riff_WAVE['INFO']) && is_array($thisfile_riff_WAVE['INFO'])) {
960
+ $this->RIFFcommentsParse($thisfile_riff_WAVE['INFO'], $thisfile_riff['comments']);
961
+ }
962
+
963
+ if (empty($thisfile_audio['encoder']) && !empty($ThisFileInfo['mpeg']['audio']['LAME']['short_version'])) {
964
+ $thisfile_audio['encoder'] = $ThisFileInfo['mpeg']['audio']['LAME']['short_version'];
965
+ }
966
+
967
+ if (!isset($ThisFileInfo['playtime_seconds'])) {
968
+ $ThisFileInfo['playtime_seconds'] = 0;
969
+ }
970
+ if (isset($thisfile_riff_raw['avih']['dwTotalFrames']) && isset($thisfile_riff_raw['avih']['dwMicroSecPerFrame'])) {
971
+ $ThisFileInfo['playtime_seconds'] = $thisfile_riff_raw['avih']['dwTotalFrames'] * ($thisfile_riff_raw['avih']['dwMicroSecPerFrame'] / 1000000);
972
+ }
973
+
974
+ if ($ThisFileInfo['playtime_seconds'] > 0) {
975
+ if (isset($thisfile_riff_audio) && isset($thisfile_riff_video)) {
976
+
977
+ if (!isset($ThisFileInfo['bitrate'])) {
978
+ $ThisFileInfo['bitrate'] = ((($thisfile_avdataend - $thisfile_avdataoffset) / $ThisFileInfo['playtime_seconds']) * 8);
979
+ }
980
+
981
+ } elseif (isset($thisfile_riff_audio) && !isset($thisfile_riff_video)) {
982
+
983
+ if (!isset($thisfile_audio['bitrate'])) {
984
+ $thisfile_audio['bitrate'] = ((($thisfile_avdataend - $thisfile_avdataoffset) / $ThisFileInfo['playtime_seconds']) * 8);
985
+ }
986
+
987
+ } elseif (!isset($thisfile_riff_audio) && isset($thisfile_riff_video)) {
988
+
989
+ if (!isset($thisfile_video['bitrate'])) {
990
+ $thisfile_video['bitrate'] = ((($thisfile_avdataend - $thisfile_avdataoffset) / $ThisFileInfo['playtime_seconds']) * 8);
991
+ }
992
+
993
+ }
994
+ }
995
+
996
+
997
+ if (isset($thisfile_riff_video) && isset($thisfile_audio['bitrate']) && ($thisfile_audio['bitrate'] > 0) && ($ThisFileInfo['playtime_seconds'] > 0)) {
998
+
999
+ $ThisFileInfo['bitrate'] = ((($thisfile_avdataend - $thisfile_avdataoffset) / $ThisFileInfo['playtime_seconds']) * 8);
1000
+ $thisfile_audio['bitrate'] = 0;
1001
+ $thisfile_video['bitrate'] = $ThisFileInfo['bitrate'];
1002
+ foreach ($thisfile_riff_audio as $channelnumber => $audioinfoarray) {
1003
+ $thisfile_video['bitrate'] -= $audioinfoarray['bitrate'];
1004
+ $thisfile_audio['bitrate'] += $audioinfoarray['bitrate'];
1005
+ }
1006
+ if ($thisfile_video['bitrate'] <= 0) {
1007
+ unset($thisfile_video['bitrate']);
1008
+ }
1009
+ if ($thisfile_audio['bitrate'] <= 0) {
1010
+ unset($thisfile_audio['bitrate']);
1011
+ }
1012
+ }
1013
+
1014
+ if (isset($ThisFileInfo['mpeg']['audio'])) {
1015
+ $thisfile_audio_dataformat = 'mp'.$ThisFileInfo['mpeg']['audio']['layer'];
1016
+ $thisfile_audio['sample_rate'] = $ThisFileInfo['mpeg']['audio']['sample_rate'];
1017
+ $thisfile_audio['channels'] = $ThisFileInfo['mpeg']['audio']['channels'];
1018
+ $thisfile_audio['bitrate'] = $ThisFileInfo['mpeg']['audio']['bitrate'];
1019
+ $thisfile_audio['bitrate_mode'] = strtolower($ThisFileInfo['mpeg']['audio']['bitrate_mode']);
1020
+ if (!empty($ThisFileInfo['mpeg']['audio']['codec'])) {
1021
+ $thisfile_audio['codec'] = $ThisFileInfo['mpeg']['audio']['codec'].' '.$thisfile_audio['codec'];
1022
+ }
1023
+ if (!empty($thisfile_audio['streams'])) {
1024
+ foreach ($thisfile_audio['streams'] as $streamnumber => $streamdata) {
1025
+ if ($streamdata['dataformat'] == $thisfile_audio_dataformat) {
1026
+ $thisfile_audio['streams'][$streamnumber]['sample_rate'] = $thisfile_audio['sample_rate'];
1027
+ $thisfile_audio['streams'][$streamnumber]['channels'] = $thisfile_audio['channels'];
1028
+ $thisfile_audio['streams'][$streamnumber]['bitrate'] = $thisfile_audio['bitrate'];
1029
+ $thisfile_audio['streams'][$streamnumber]['bitrate_mode'] = $thisfile_audio['bitrate_mode'];
1030
+ $thisfile_audio['streams'][$streamnumber]['codec'] = $thisfile_audio['codec'];
1031
+ }
1032
+ }
1033
+ }
1034
+ $thisfile_audio['encoder_options'] = getid3_mp3::GuessEncoderOptions($ThisFileInfo);
1035
+ }
1036
+
1037
+
1038
+ if (!empty($thisfile_riff_raw['fmt ']['wBitsPerSample']) && ($thisfile_riff_raw['fmt ']['wBitsPerSample'] > 0)) {
1039
+ switch ($thisfile_audio_dataformat) {
1040
+ case 'ac3':
1041
+ // ignore bits_per_sample
1042
+ break;
1043
+
1044
+ default:
1045
+ $thisfile_audio['bits_per_sample'] = $thisfile_riff_raw['fmt ']['wBitsPerSample'];
1046
+ break;
1047
+ }
1048
+ }
1049
+
1050
+
1051
+ if (empty($thisfile_riff_raw)) {
1052
+ unset($thisfile_riff['raw']);
1053
+ }
1054
+ if (empty($thisfile_riff_audio)) {
1055
+ unset($thisfile_riff['audio']);
1056
+ }
1057
+ if (empty($thisfile_riff_video)) {
1058
+ unset($thisfile_riff['video']);
1059
+ }
1060
+
1061
+ return true;
1062
+ }
1063
+
1064
+
1065
+ function RIFFcommentsParse(&$RIFFinfoArray, &$CommentsTargetArray) {
1066
+ $RIFFinfoKeyLookup = array(
1067
+ 'IARL'=>'archivallocation',
1068
+ 'IART'=>'artist',
1069
+ 'ICDS'=>'costumedesigner',
1070
+ 'ICMS'=>'commissionedby',
1071
+ 'ICMT'=>'comment',
1072
+ 'ICNT'=>'country',
1073
+ 'ICOP'=>'copyright',
1074
+ 'ICRD'=>'creationdate',
1075
+ 'IDIM'=>'dimensions',
1076
+ 'IDIT'=>'digitizationdate',
1077
+ 'IDPI'=>'resolution',
1078
+ 'IDST'=>'distributor',
1079
+ 'IEDT'=>'editor',
1080
+ 'IENG'=>'engineers',
1081
+ 'IFRM'=>'accountofparts',
1082
+ 'IGNR'=>'genre',
1083
+ 'IKEY'=>'keywords',
1084
+ 'ILGT'=>'lightness',
1085
+ 'ILNG'=>'language',
1086
+ 'IMED'=>'orignalmedium',
1087
+ 'IMUS'=>'composer',
1088
+ 'INAM'=>'title',
1089
+ 'IPDS'=>'productiondesigner',
1090
+ 'IPLT'=>'palette',
1091
+ 'IPRD'=>'product',
1092
+ 'IPRO'=>'producer',
1093
+ 'IPRT'=>'part',
1094
+ 'IRTD'=>'rating',
1095
+ 'ISBJ'=>'subject',
1096
+ 'ISFT'=>'software',
1097
+ 'ISGN'=>'secondarygenre',
1098
+ 'ISHP'=>'sharpness',
1099
+ 'ISRC'=>'sourcesupplier',
1100
+ 'ISRF'=>'digitizationsource',
1101
+ 'ISTD'=>'productionstudio',
1102
+ 'ISTR'=>'starring',
1103
+ 'ITCH'=>'encoded_by',
1104
+ 'IWEB'=>'url',
1105
+ 'IWRI'=>'writer'
1106
+ );
1107
+ foreach ($RIFFinfoKeyLookup as $key => $value) {
1108
+ if (isset($RIFFinfoArray[$key])) {
1109
+ foreach ($RIFFinfoArray[$key] as $commentid => $commentdata) {
1110
+ if (trim($commentdata['data']) != '') {
1111
+ @$CommentsTargetArray[$value][] = trim($commentdata['data']);
1112
+ }
1113
+ }
1114
+ }
1115
+ }
1116
+ return true;
1117
+ }
1118
+
1119
+ function ParseRIFF(&$fd, $startoffset, $maxoffset, &$ThisFileInfo) {
1120
+ $maxoffset = min($maxoffset, $ThisFileInfo['avdataend']);
1121
+
1122
+ $RIFFchunk = false;
1123
+ $FoundAllChunksWeNeed = false;
1124
+
1125
+ if (($startoffset < 0) || ($startoffset >= pow(2, 31))) {
1126
+ $ThisFileInfo['warning'][] = 'Unable to ParseRIFF() at '.$startoffset.' because beyond 2GB limit of PHP filesystem functions';
1127
+ return false;
1128
+ }
1129
+ fseek($fd, $startoffset, SEEK_SET);
1130
+
1131
+ while (ftell($fd) < $maxoffset) {
1132
+ $chunkname = fread($fd, 4);
1133
+ if (strlen($chunkname) < 4) {
1134
+ $ThisFileInfo['error'][] = 'Expecting chunk name at offset '.(ftell($fd) - 4).' but found nothing. Aborting RIFF parsing.';
1135
+ break;
1136
+ }
1137
+
1138
+ $chunksize = getid3_riff::EitherEndian2Int($ThisFileInfo, fread($fd, 4));
1139
+ if ($chunksize == 0) {
1140
+ $ThisFileInfo['warning'][] = 'Chunk size at offset '.(ftell($fd) - 4).' is zero. Aborting RIFF parsing.';
1141
+ continue;
1142
+ }
1143
+ if (($chunksize % 2) != 0) {
1144
+ // all structures are packed on word boundaries
1145
+ $chunksize++;
1146
+ }
1147
+
1148
+ switch ($chunkname) {
1149
+ case 'LIST':
1150
+ $listname = fread($fd, 4);
1151
+ if (eregi('^(movi|rec )$', $listname)) {
1152
+ $RIFFchunk[$listname]['offset'] = ftell($fd) - 4;
1153
+ $RIFFchunk[$listname]['size'] = $chunksize;
1154
+
1155
+ if ($FoundAllChunksWeNeed) {
1156
+
1157
+ // skip over
1158
+
1159
+ } else {
1160
+
1161
+ $WhereWeWere = ftell($fd);
1162
+ $AudioChunkHeader = fread($fd, 12);
1163
+ $AudioChunkStreamNum = substr($AudioChunkHeader, 0, 2);
1164
+ $AudioChunkStreamType = substr($AudioChunkHeader, 2, 2);
1165
+ $AudioChunkSize = getid3_lib::LittleEndian2Int(substr($AudioChunkHeader, 4, 4));
1166
+
1167
+ if ($AudioChunkStreamType == 'wb') {
1168
+ $FirstFourBytes = substr($AudioChunkHeader, 8, 4);
1169
+ if (preg_match('/^\xFF[\xE2-\xE7\xF2-\xF7\xFA-\xFF][\x00-\xEB]/s', $FirstFourBytes)) {
1170
+ // MP3
1171
+ if (getid3_mp3::MPEGaudioHeaderBytesValid($FirstFourBytes)) {
1172
+ $dummy = $ThisFileInfo;
1173
+ $dummy['avdataoffset'] = ftell($fd) - 4;
1174
+ $dummy['avdataend'] = ftell($fd) + $AudioChunkSize;
1175
+ getid3_mp3::getOnlyMPEGaudioInfo($fd, $dummy, $dummy['avdataoffset'], false);
1176
+ if (isset($dummy['mpeg']['audio'])) {
1177
+ $ThisFileInfo = $dummy;
1178
+ $ThisFileInfo['audio']['dataformat'] = 'mp'.$ThisFileInfo['mpeg']['audio']['layer'];
1179
+ $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['mpeg']['audio']['sample_rate'];
1180
+ $ThisFileInfo['audio']['channels'] = $ThisFileInfo['mpeg']['audio']['channels'];
1181
+ $ThisFileInfo['audio']['bitrate'] = $ThisFileInfo['mpeg']['audio']['bitrate'];
1182
+ $ThisFileInfo['bitrate'] = $ThisFileInfo['audio']['bitrate'];
1183
+ $ThisFileInfo['audio']['bitrate_mode'] = strtolower($ThisFileInfo['mpeg']['audio']['bitrate_mode']);
1184
+ }
1185
+ unset($dummy);
1186
+ }
1187
+
1188
+ } elseif (preg_match('/^\x0B\x77/s', $FirstFourBytes)) {
1189
+
1190
+ // AC3
1191
+ $GETID3_ERRORARRAY = &$ThisFileInfo['warning'];
1192
+ if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.ac3.php', __FILE__, false)) {
1193
+
1194
+ $dummy = $ThisFileInfo;
1195
+ $dummy['avdataoffset'] = ftell($fd) - 4;
1196
+ $dummy['avdataend'] = ftell($fd) + $AudioChunkSize;
1197
+ $dummy['error'] = array();
1198
+ $ac3_tag = new getid3_ac3($fd, $dummy);
1199
+ if (empty($dummy['error'])) {
1200
+ $ThisFileInfo['audio'] = $dummy['audio'];
1201
+ $ThisFileInfo['ac3'] = $dummy['ac3'];
1202
+ $ThisFileInfo['warning'] = $dummy['warning'];
1203
+ }
1204
+ unset($ac3_tag);
1205
+
1206
+ }
1207
+
1208
+ }
1209
+
1210
+ }
1211
+
1212
+ $FoundAllChunksWeNeed = true;
1213
+ fseek($fd, $WhereWeWere, SEEK_SET);
1214
+
1215
+ }
1216
+ fseek($fd, $chunksize - 4, SEEK_CUR);
1217
+
1218
+ //} elseif (ereg('^[0-9]{2}(wb|pc|dc|db)$', $listname)) {
1219
+ //
1220
+ // // data chunk, ignore
1221
+ //
1222
+ } else {
1223
+
1224
+ if (!isset($RIFFchunk[$listname])) {
1225
+ $RIFFchunk[$listname] = array();
1226
+ }
1227
+ $LISTchunkParent = $listname;
1228
+ $LISTchunkMaxOffset = ftell($fd) - 4 + $chunksize;
1229
+ if ($parsedChunk = getid3_riff::ParseRIFF($fd, ftell($fd), ftell($fd) + $chunksize - 4, $ThisFileInfo)) {
1230
+ $RIFFchunk[$listname] = array_merge_recursive($RIFFchunk[$listname], $parsedChunk);
1231
+ }
1232
+
1233
+ }
1234
+ break;
1235
+
1236
+ default:
1237
+ if (eregi('^[0-9]{2}(wb|pc|dc|db)$', $chunkname)) {
1238
+ $nextoffset = ftell($fd) + $chunksize;
1239
+ if (($nextoffset < 0) || ($nextoffset >= pow(2, 31))) {
1240
+ $ThisFileInfo['warning'][] = 'Unable to parse chunk at offset '.$nextoffset.' because beyond 2GB limit of PHP filesystem functions';
1241
+ break 2;
1242
+ }
1243
+ fseek($fd, $nextoffset, SEEK_SET);
1244
+ break;
1245
+ }
1246
+ $thisindex = 0;
1247
+ if (isset($RIFFchunk[$chunkname]) && is_array($RIFFchunk[$chunkname])) {
1248
+ $thisindex = count($RIFFchunk[$chunkname]);
1249
+ }
1250
+ $RIFFchunk[$chunkname][$thisindex]['offset'] = ftell($fd) - 8;
1251
+ $RIFFchunk[$chunkname][$thisindex]['size'] = $chunksize;
1252
+ switch ($chunkname) {
1253
+ case 'data':
1254
+ $ThisFileInfo['avdataoffset'] = ftell($fd);
1255
+ $ThisFileInfo['avdataend'] = $ThisFileInfo['avdataoffset'] + $chunksize;
1256
+
1257
+ $RIFFdataChunkContentsTest = fread($fd, 36);
1258
+
1259
+ if ((strlen($RIFFdataChunkContentsTest) > 0) && preg_match('/^\xFF[\xE2-\xE7\xF2-\xF7\xFA-\xFF][\x00-\xEB]/s', substr($RIFFdataChunkContentsTest, 0, 4))) {
1260
+
1261
+ // Probably is MP3 data
1262
+ if (getid3_mp3::MPEGaudioHeaderBytesValid(substr($RIFFdataChunkContentsTest, 0, 4))) {
1263
+
1264
+ // copy info array
1265
+ $dummy = $ThisFileInfo;
1266
+
1267
+ getid3_mp3::getOnlyMPEGaudioInfo($fd, $dummy, $RIFFchunk[$chunkname][$thisindex]['offset'], false);
1268
+
1269
+ // use dummy array unless error
1270
+ if (empty($dummy['error'])) {
1271
+ $ThisFileInfo = $dummy;
1272
+ }
1273
+ }
1274
+
1275
+ } elseif ((strlen($RIFFdataChunkContentsTest) > 0) && (substr($RIFFdataChunkContentsTest, 0, 2) == "\x0B\x77")) {
1276
+
1277
+ // This is probably AC-3 data
1278
+ $GETID3_ERRORARRAY = &$ThisFileInfo['warning'];
1279
+ if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.ac3.php', __FILE__, false)) {
1280
+
1281
+ $dummy = $ThisFileInfo;
1282
+ $dummy['avdataoffset'] = $RIFFchunk[$chunkname][$thisindex]['offset'];
1283
+ $dummy['avdataend'] = $dummy['avdataoffset'] + $RIFFchunk[$chunkname][$thisindex]['size'];
1284
+ $dummy['error'] = array();
1285
+
1286
+ $ac3_tag = new getid3_ac3($fd, $dummy);
1287
+ if (empty($dummy['error'])) {
1288
+ $ThisFileInfo['audio'] = $dummy['audio'];
1289
+ $ThisFileInfo['ac3'] = $dummy['ac3'];
1290
+ $ThisFileInfo['warning'] = $dummy['warning'];
1291
+ }
1292
+ unset($ac3_tag);
1293
+
1294
+ }
1295
+
1296
+ } elseif ((strlen($RIFFdataChunkContentsTest) > 0) && (substr($RIFFdataChunkContentsTest, 8, 2) == "\x77\x0B")) {
1297
+
1298
+ // Dolby Digital WAV
1299
+ // AC-3 content, but not encoded in same format as normal AC-3 file
1300
+ // For one thing, byte order is swapped
1301
+
1302
+ $GETID3_ERRORARRAY = &$ThisFileInfo['warning'];
1303
+ if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.ac3.php', __FILE__, false)) {
1304
+
1305
+ // ok to use tmpfile here - only 56 bytes
1306
+ if ($fd_temp = tmpfile()) {
1307
+
1308
+ for ($i = 0; $i < 28; $i += 2) {
1309
+ // swap byte order
1310
+ fwrite($fd_temp, substr($RIFFdataChunkContentsTest, 8 + $i + 1, 1));
1311
+ fwrite($fd_temp, substr($RIFFdataChunkContentsTest, 8 + $i + 0, 1));
1312
+ }
1313
+
1314
+ $dummy = $ThisFileInfo;
1315
+ $dummy['avdataoffset'] = 0;
1316
+ $dummy['avdataend'] = 20;
1317
+ $dummy['error'] = array();
1318
+ $ac3_tag = new getid3_ac3($fd_temp, $dummy);
1319
+ fclose($fd_temp);
1320
+ if (empty($dummy['error'])) {
1321
+ $ThisFileInfo['audio'] = $dummy['audio'];
1322
+ $ThisFileInfo['ac3'] = $dummy['ac3'];
1323
+ $ThisFileInfo['warning'] = $dummy['warning'];
1324
+ } else {
1325
+ $ThisFileInfo['error'][] = 'Errors parsing DolbyDigital WAV: '.explode(';', $dummy['error']);
1326
+ }
1327
+ unset($ac3_tag);
1328
+
1329
+ } else {
1330
+
1331
+ $ThisFileInfo['error'][] = 'Could not create temporary file to analyze DolbyDigital WAV';
1332
+
1333
+ }
1334
+
1335
+ }
1336
+
1337
+ } elseif ((strlen($RIFFdataChunkContentsTest) > 0) && (substr($RIFFdataChunkContentsTest, 0, 4) == 'wvpk')) {
1338
+
1339
+ // This is WavPack data
1340
+ $ThisFileInfo['wavpack']['offset'] = $RIFFchunk[$chunkname][$thisindex]['offset'];
1341
+ $ThisFileInfo['wavpack']['size'] = getid3_lib::LittleEndian2Int(substr($RIFFdataChunkContentsTest, 4, 4));
1342
+ getid3_riff::RIFFparseWavPackHeader(substr($RIFFdataChunkContentsTest, 8, 28), $ThisFileInfo);
1343
+
1344
+ } else {
1345
+
1346
+ // This is some other kind of data (quite possibly just PCM)
1347
+ // do nothing special, just skip it
1348
+
1349
+ }
1350
+ $nextoffset = $RIFFchunk[$chunkname][$thisindex]['offset'] + 8 + $chunksize;
1351
+ if (($nextoffset < 0) || ($nextoffset >= pow(2, 31))) {
1352
+ $ThisFileInfo['warning'][] = 'Unable to parse chunk at offset '.$nextoffset.' because beyond 2GB limit of PHP filesystem functions';
1353
+ break 3;
1354
+ }
1355
+ fseek($fd, $RIFFchunk[$chunkname][$thisindex]['offset'] + 8 + $chunksize, SEEK_SET);
1356
+ break;
1357
+
1358
+ case 'bext':
1359
+ case 'cart':
1360
+ case 'fmt ':
1361
+ case 'strh':
1362
+ case 'strf':
1363
+ case 'indx':
1364
+ case 'MEXT':
1365
+ case 'DISP':
1366
+ // always read data in
1367
+ $RIFFchunk[$chunkname][$thisindex]['data'] = fread($fd, $chunksize);
1368
+ break;
1369
+
1370
+ default:
1371
+ if (!ereg('^[0-9]{2}(wb|pc|dc|db)$', $chunkname) && !empty($LISTchunkParent) && (($RIFFchunk[$chunkname][$thisindex]['offset'] + $RIFFchunk[$chunkname][$thisindex]['size']) <= $LISTchunkMaxOffset)) {
1372
+ $RIFFchunk[$LISTchunkParent][$chunkname][$thisindex]['offset'] = $RIFFchunk[$chunkname][$thisindex]['offset'];
1373
+ $RIFFchunk[$LISTchunkParent][$chunkname][$thisindex]['size'] = $RIFFchunk[$chunkname][$thisindex]['size'];
1374
+ unset($RIFFchunk[$chunkname][$thisindex]['offset']);
1375
+ unset($RIFFchunk[$chunkname][$thisindex]['size']);
1376
+ if (isset($RIFFchunk[$chunkname][$thisindex]) && empty($RIFFchunk[$chunkname][$thisindex])) {
1377
+ unset($RIFFchunk[$chunkname][$thisindex]);
1378
+ }
1379
+ if (isset($RIFFchunk[$chunkname]) && empty($RIFFchunk[$chunkname])) {
1380
+ unset($RIFFchunk[$chunkname]);
1381
+ }
1382
+ $RIFFchunk[$LISTchunkParent][$chunkname][$thisindex]['data'] = fread($fd, $chunksize);
1383
+ } elseif ($chunksize < 2048) {
1384
+ // only read data in if smaller than 2kB
1385
+ $RIFFchunk[$chunkname][$thisindex]['data'] = fread($fd, $chunksize);
1386
+ } else {
1387
+ $nextoffset = ftell($fd) + $chunksize;
1388
+ if (($nextoffset < 0) || ($nextoffset >= pow(2, 31))) {
1389
+ $ThisFileInfo['warning'][] = 'Unable to parse chunk at offset '.$nextoffset.' because beyond 2GB limit of PHP filesystem functions';
1390
+ break 3;
1391
+ }
1392
+ fseek($fd, $nextoffset, SEEK_SET);
1393
+ }
1394
+ break;
1395
+ }
1396
+ break;
1397
+
1398
+ }
1399
+
1400
+ }
1401
+
1402
+ return $RIFFchunk;
1403
+ }
1404
+
1405
+
1406
+ function ParseRIFFdata(&$RIFFdata, &$ThisFileInfo) {
1407
+ if ($RIFFdata) {
1408
+
1409
+ $tempfile = tempnam('*', 'getID3');
1410
+ $fp_temp = fopen($tempfile, "wb");
1411
+ $RIFFdataLength = strlen($RIFFdata);
1412
+ $NewLengthString = getid3_lib::LittleEndian2String($RIFFdataLength, 4);
1413
+ for ($i = 0; $i < 4; $i++) {
1414
+ $RIFFdata{$i + 4} = $NewLengthString{$i};
1415
+ }
1416
+ fwrite($fp_temp, $RIFFdata);
1417
+ fclose($fp_temp);
1418
+
1419
+ $fp_temp = fopen($tempfile, "rb");
1420
+ $dummy = array('filesize'=>$RIFFdataLength, 'filenamepath'=>$ThisFileInfo['filenamepath'], 'tags'=>$ThisFileInfo['tags'], 'avdataoffset'=>0, 'avdataend'=>$RIFFdataLength, 'warning'=>$ThisFileInfo['warning'], 'error'=>$ThisFileInfo['error'], 'comments'=>$ThisFileInfo['comments'], 'audio'=>(isset($ThisFileInfo['audio']) ? $ThisFileInfo['audio'] : array()), 'video'=>(isset($ThisFileInfo['video']) ? $ThisFileInfo['video'] : array()));
1421
+ $riff = new getid3_riff($fp_temp, $dummy);
1422
+ $ThisFileInfo['riff'] = $dummy['riff'];
1423
+ $ThisFileInfo['warning'] = $dummy['warning'];
1424
+ $ThisFileInfo['error'] = $dummy['error'];
1425
+ $ThisFileInfo['tags'] = $dummy['tags'];
1426
+ $ThisFileInfo['comments'] = $dummy['comments'];
1427
+ unset($riff);
1428
+ fclose($fp_temp);
1429
+ unlink($tempfile);
1430
+ return true;
1431
+ }
1432
+ return false;
1433
+ }
1434
+
1435
+
1436
+ function RIFFparseWAVEFORMATex($WaveFormatExData) {
1437
+ // shortcut
1438
+ $WaveFormatEx['raw'] = array();
1439
+ $WaveFormatEx_raw = &$WaveFormatEx['raw'];
1440
+
1441
+ $WaveFormatEx_raw['wFormatTag'] = getid3_lib::LittleEndian2Int(substr($WaveFormatExData, 0, 2));
1442
+ $WaveFormatEx_raw['nChannels'] = getid3_lib::LittleEndian2Int(substr($WaveFormatExData, 2, 2));
1443
+ $WaveFormatEx_raw['nSamplesPerSec'] = getid3_lib::LittleEndian2Int(substr($WaveFormatExData, 4, 4));
1444
+ $WaveFormatEx_raw['nAvgBytesPerSec'] = getid3_lib::LittleEndian2Int(substr($WaveFormatExData, 8, 4));
1445
+ $WaveFormatEx_raw['nBlockAlign'] = getid3_lib::LittleEndian2Int(substr($WaveFormatExData, 12, 2));
1446
+ $WaveFormatEx_raw['wBitsPerSample'] = getid3_lib::LittleEndian2Int(substr($WaveFormatExData, 14, 2));
1447
+ if (strlen($WaveFormatExData) > 16) {
1448
+ $WaveFormatEx_raw['cbSize'] = getid3_lib::LittleEndian2Int(substr($WaveFormatExData, 16, 2));
1449
+ }
1450
+
1451
+ $WaveFormatEx['codec'] = getid3_riff::RIFFwFormatTagLookup($WaveFormatEx_raw['wFormatTag']);
1452
+ $WaveFormatEx['channels'] = $WaveFormatEx_raw['nChannels'];
1453
+ $WaveFormatEx['sample_rate'] = $WaveFormatEx_raw['nSamplesPerSec'];
1454
+ $WaveFormatEx['bitrate'] = $WaveFormatEx_raw['nAvgBytesPerSec'] * 8;
1455
+ $WaveFormatEx['bits_per_sample'] = $WaveFormatEx_raw['wBitsPerSample'];
1456
+
1457
+ return $WaveFormatEx;
1458
+ }
1459
+
1460
+
1461
+ function RIFFparseWavPackHeader($WavPackChunkData, &$ThisFileInfo) {
1462
+ // typedef struct {
1463
+ // char ckID [4];
1464
+ // long ckSize;
1465
+ // short version;
1466
+ // short bits; // added for version 2.00
1467
+ // short flags, shift; // added for version 3.00
1468
+ // long total_samples, crc, crc2;
1469
+ // char extension [4], extra_bc, extras [3];
1470
+ // } WavpackHeader;
1471
+
1472
+ // shortcut
1473
+ $ThisFileInfo['wavpack'] = array();
1474
+ $thisfile_wavpack = &$ThisFileInfo['wavpack'];
1475
+
1476
+ $thisfile_wavpack['version'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 0, 2));
1477
+ if ($thisfile_wavpack['version'] >= 2) {
1478
+ $thisfile_wavpack['bits'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 2, 2));
1479
+ }
1480
+ if ($thisfile_wavpack['version'] >= 3) {
1481
+ $thisfile_wavpack['flags_raw'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 4, 2));
1482
+ $thisfile_wavpack['shift'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 6, 2));
1483
+ $thisfile_wavpack['total_samples'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 8, 4));
1484
+ $thisfile_wavpack['crc1'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 12, 4));
1485
+ $thisfile_wavpack['crc2'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 16, 4));
1486
+ $thisfile_wavpack['extension'] = substr($WavPackChunkData, 20, 4);
1487
+ $thisfile_wavpack['extra_bc'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 24, 1));
1488
+ for ($i = 0; $i <= 2; $i++) {
1489
+ $thisfile_wavpack['extras'][] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 25 + $i, 1));
1490
+ }
1491
+
1492
+ // shortcut
1493
+ $thisfile_wavpack['flags'] = array();
1494
+ $thisfile_wavpack_flags = &$thisfile_wavpack['flags'];
1495
+
1496
+ $thisfile_wavpack_flags['mono'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000001);
1497
+ $thisfile_wavpack_flags['fast_mode'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000002);
1498
+ $thisfile_wavpack_flags['raw_mode'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000004);
1499
+ $thisfile_wavpack_flags['calc_noise'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000008);
1500
+ $thisfile_wavpack_flags['high_quality'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000010);
1501
+ $thisfile_wavpack_flags['3_byte_samples'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000020);
1502
+ $thisfile_wavpack_flags['over_20_bits'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000040);
1503
+ $thisfile_wavpack_flags['use_wvc'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000080);
1504
+ $thisfile_wavpack_flags['noiseshaping'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000100);
1505
+ $thisfile_wavpack_flags['very_fast_mode'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000200);
1506
+ $thisfile_wavpack_flags['new_high_quality'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000400);
1507
+ $thisfile_wavpack_flags['cancel_extreme'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000800);
1508
+ $thisfile_wavpack_flags['cross_decorrelation'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x001000);
1509
+ $thisfile_wavpack_flags['new_decorrelation'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x002000);
1510
+ $thisfile_wavpack_flags['joint_stereo'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x004000);
1511
+ $thisfile_wavpack_flags['extra_decorrelation'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x008000);
1512
+ $thisfile_wavpack_flags['override_noiseshape'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x010000);
1513
+ $thisfile_wavpack_flags['override_jointstereo'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x020000);
1514
+ $thisfile_wavpack_flags['copy_source_filetime'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x040000);
1515
+ $thisfile_wavpack_flags['create_exe'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x080000);
1516
+ }
1517
+
1518
+ return true;
1519
+ }
1520
+
1521
+ function ParseBITMAPINFOHEADER($BITMAPINFOHEADER, $littleEndian=true) {
1522
+ // yes it's ugly to instantiate a getid3_lib object here, suggested alternative please?
1523
+ $getid3_lib = new getid3_lib();
1524
+ $functionname = ($littleEndian ? 'LittleEndian2Int' : 'BigEndian2Int');
1525
+ $parsed['biSize'] = $getid3_lib->$functionname(substr($BITMAPINFOHEADER, 0, 4)); // number of bytes required by the BITMAPINFOHEADER structure
1526
+ $parsed['biWidth'] = $getid3_lib->$functionname(substr($BITMAPINFOHEADER, 4, 4)); // width of the bitmap in pixels
1527
+ $parsed['biHeight'] = $getid3_lib->$functionname(substr($BITMAPINFOHEADER, 8, 4)); // height of the bitmap in pixels. If biHeight is positive, the bitmap is a 'bottom-up' DIB and its origin is the lower left corner. If biHeight is negative, the bitmap is a 'top-down' DIB and its origin is the upper left corner
1528
+ $parsed['biPlanes'] = $getid3_lib->$functionname(substr($BITMAPINFOHEADER, 12, 2)); // number of color planes on the target device. In most cases this value must be set to 1
1529
+ $parsed['biBitCount'] = $getid3_lib->$functionname(substr($BITMAPINFOHEADER, 14, 2)); // Specifies the number of bits per pixels
1530
+ $parsed['fourcc'] = substr($BITMAPINFOHEADER, 16, 4); // compression identifier
1531
+ $parsed['biSizeImage'] = $getid3_lib->$functionname(substr($BITMAPINFOHEADER, 20, 4)); // size of the bitmap data section of the image (the actual pixel data, excluding BITMAPINFOHEADER and RGBQUAD structures)
1532
+ $parsed['biXPelsPerMeter'] = $getid3_lib->$functionname(substr($BITMAPINFOHEADER, 24, 4)); // horizontal resolution, in pixels per metre, of the target device
1533
+ $parsed['biYPelsPerMeter'] = $getid3_lib->$functionname(substr($BITMAPINFOHEADER, 28, 4)); // vertical resolution, in pixels per metre, of the target device
1534
+ $parsed['biClrUsed'] = $getid3_lib->$functionname(substr($BITMAPINFOHEADER, 32, 4)); // actual number of color indices in the color table used by the bitmap. If this value is zero, the bitmap uses the maximum number of colors corresponding to the value of the biBitCount member for the compression mode specified by biCompression
1535
+ $parsed['biClrImportant'] = $getid3_lib->$functionname(substr($BITMAPINFOHEADER, 36, 4)); // number of color indices that are considered important for displaying the bitmap. If this value is zero, all colors are important
1536
+ return $parsed;
1537
+ }
1538
+
1539
+ function RIFFwFormatTagLookup($wFormatTag) {
1540
+
1541
+ $begin = __LINE__;
1542
+
1543
+ /** This is not a comment!
1544
+
1545
+ 0x0000 Microsoft Unknown Wave Format
1546
+ 0x0001 Pulse Code Modulation (PCM)
1547
+ 0x0002 Microsoft ADPCM
1548
+ 0x0003 IEEE Float
1549
+ 0x0004 Compaq Computer VSELP
1550
+ 0x0005 IBM CVSD
1551
+ 0x0006 Microsoft A-Law
1552
+ 0x0007 Microsoft mu-Law
1553
+ 0x0008 Microsoft DTS
1554
+ 0x0010 OKI ADPCM
1555
+ 0x0011 Intel DVI/IMA ADPCM
1556
+ 0x0012 Videologic MediaSpace ADPCM
1557
+ 0x0013 Sierra Semiconductor ADPCM
1558
+ 0x0014 Antex Electronics G.723 ADPCM
1559
+ 0x0015 DSP Solutions DigiSTD
1560
+ 0x0016 DSP Solutions DigiFIX
1561
+ 0x0017 Dialogic OKI ADPCM
1562
+ 0x0018 MediaVision ADPCM
1563
+ 0x0019 Hewlett-Packard CU
1564
+ 0x0020 Yamaha ADPCM
1565
+ 0x0021 Speech Compression Sonarc
1566
+ 0x0022 DSP Group TrueSpeech
1567
+ 0x0023 Echo Speech EchoSC1
1568
+ 0x0024 Audiofile AF36
1569
+ 0x0025 Audio Processing Technology APTX
1570
+ 0x0026 AudioFile AF10
1571
+ 0x0027 Prosody 1612
1572
+ 0x0028 LRC
1573
+ 0x0030 Dolby AC2
1574
+ 0x0031 Microsoft GSM 6.10
1575
+ 0x0032 MSNAudio
1576
+ 0x0033 Antex Electronics ADPCME
1577
+ 0x0034 Control Resources VQLPC
1578
+ 0x0035 DSP Solutions DigiREAL
1579
+ 0x0036 DSP Solutions DigiADPCM
1580
+ 0x0037 Control Resources CR10
1581
+ 0x0038 Natural MicroSystems VBXADPCM
1582
+ 0x0039 Crystal Semiconductor IMA ADPCM
1583
+ 0x003A EchoSC3
1584
+ 0x003B Rockwell ADPCM
1585
+ 0x003C Rockwell Digit LK
1586
+ 0x003D Xebec
1587
+ 0x0040 Antex Electronics G.721 ADPCM
1588
+ 0x0041 G.728 CELP
1589
+ 0x0042 MSG723
1590
+ 0x0050 MPEG Layer-2 or Layer-1
1591
+ 0x0052 RT24
1592
+ 0x0053 PAC
1593
+ 0x0055 MPEG Layer-3
1594
+ 0x0059 Lucent G.723
1595
+ 0x0060 Cirrus
1596
+ 0x0061 ESPCM
1597
+ 0x0062 Voxware
1598
+ 0x0063 Canopus Atrac
1599
+ 0x0064 G.726 ADPCM
1600
+ 0x0065 G.722 ADPCM
1601
+ 0x0066 DSAT
1602
+ 0x0067 DSAT Display
1603
+ 0x0069 Voxware Byte Aligned
1604
+ 0x0070 Voxware AC8
1605
+ 0x0071 Voxware AC10
1606
+ 0x0072 Voxware AC16
1607
+ 0x0073 Voxware AC20
1608
+ 0x0074 Voxware MetaVoice
1609
+ 0x0075 Voxware MetaSound
1610
+ 0x0076 Voxware RT29HW
1611
+ 0x0077 Voxware VR12
1612
+ 0x0078 Voxware VR18
1613
+ 0x0079 Voxware TQ40
1614
+ 0x0080 Softsound
1615
+ 0x0081 Voxware TQ60
1616
+ 0x0082 MSRT24
1617
+ 0x0083 G.729A
1618
+ 0x0084 MVI MV12
1619
+ 0x0085 DF G.726
1620
+ 0x0086 DF GSM610
1621
+ 0x0088 ISIAudio
1622
+ 0x0089 Onlive
1623
+ 0x0091 SBC24
1624
+ 0x0092 Dolby AC3 SPDIF
1625
+ 0x0093 MediaSonic G.723
1626
+ 0x0094 Aculab PLC Prosody 8kbps
1627
+ 0x0097 ZyXEL ADPCM
1628
+ 0x0098 Philips LPCBB
1629
+ 0x0099 Packed
1630
+ 0x00FF AAC
1631
+ 0x0100 Rhetorex ADPCM
1632
+ 0x0101 IBM mu-law
1633
+ 0x0102 IBM A-law
1634
+ 0x0103 IBM AVC Adaptive Differential Pulse Code Modulation (ADPCM)
1635
+ 0x0111 Vivo G.723
1636
+ 0x0112 Vivo Siren
1637
+ 0x0123 Digital G.723
1638
+ 0x0125 Sanyo LD ADPCM
1639
+ 0x0130 Sipro Lab Telecom ACELP NET
1640
+ 0x0131 Sipro Lab Telecom ACELP 4800
1641
+ 0x0132 Sipro Lab Telecom ACELP 8V3
1642
+ 0x0133 Sipro Lab Telecom G.729
1643
+ 0x0134 Sipro Lab Telecom G.729A
1644
+ 0x0135 Sipro Lab Telecom Kelvin
1645
+ 0x0140 Windows Media Video V8
1646
+ 0x0150 Qualcomm PureVoice
1647
+ 0x0151 Qualcomm HalfRate
1648
+ 0x0155 Ring Zero Systems TUB GSM
1649
+ 0x0160 Microsoft Audio 1
1650
+ 0x0161 Windows Media Audio V7 / V8 / V9
1651
+ 0x0162 Windows Media Audio Professional V9
1652
+ 0x0163 Windows Media Audio Lossless V9
1653
+ 0x0200 Creative Labs ADPCM
1654
+ 0x0202 Creative Labs Fastspeech8
1655
+ 0x0203 Creative Labs Fastspeech10
1656
+ 0x0210 UHER Informatic GmbH ADPCM
1657
+ 0x0220 Quarterdeck
1658
+ 0x0230 I-link Worldwide VC
1659
+ 0x0240 Aureal RAW Sport
1660
+ 0x0250 Interactive Products HSX
1661
+ 0x0251 Interactive Products RPELP
1662
+ 0x0260 Consistent Software CS2
1663
+ 0x0270 Sony SCX
1664
+ 0x0300 Fujitsu FM Towns Snd
1665
+ 0x0400 BTV Digital
1666
+ 0x0401 Intel Music Coder
1667
+ 0x0450 QDesign Music
1668
+ 0x0680 VME VMPCM
1669
+ 0x0681 AT&T Labs TPC
1670
+ 0x08AE ClearJump LiteWave
1671
+ 0x1000 Olivetti GSM
1672
+ 0x1001 Olivetti ADPCM
1673
+ 0x1002 Olivetti CELP
1674
+ 0x1003 Olivetti SBC
1675
+ 0x1004 Olivetti OPR
1676
+ 0x1100 Lernout & Hauspie Codec (0x1100)
1677
+ 0x1101 Lernout & Hauspie CELP Codec (0x1101)
1678
+ 0x1102 Lernout & Hauspie SBC Codec (0x1102)
1679
+ 0x1103 Lernout & Hauspie SBC Codec (0x1103)
1680
+ 0x1104 Lernout & Hauspie SBC Codec (0x1104)
1681
+ 0x1400 Norris
1682
+ 0x1401 AT&T ISIAudio
1683
+ 0x1500 Soundspace Music Compression
1684
+ 0x181C VoxWare RT24 Speech
1685
+ 0x1FC4 NCT Soft ALF2CD (www.nctsoft.com)
1686
+ 0x2000 Dolby AC3
1687
+ 0x2001 Dolby DTS
1688
+ 0x2002 WAVE_FORMAT_14_4
1689
+ 0x2003 WAVE_FORMAT_28_8
1690
+ 0x2004 WAVE_FORMAT_COOK
1691
+ 0x2005 WAVE_FORMAT_DNET
1692
+ 0x674F Ogg Vorbis 1
1693
+ 0x6750 Ogg Vorbis 2
1694
+ 0x6751 Ogg Vorbis 3
1695
+ 0x676F Ogg Vorbis 1+
1696
+ 0x6770 Ogg Vorbis 2+
1697
+ 0x6771 Ogg Vorbis 3+
1698
+ 0x7A21 GSM-AMR (CBR, no SID)
1699
+ 0x7A22 GSM-AMR (VBR, including SID)
1700
+ 0xFFFE WAVE_FORMAT_EXTENSIBLE
1701
+ 0xFFFF WAVE_FORMAT_DEVELOPMENT
1702
+
1703
+ */
1704
+
1705
+ return getid3_lib::EmbeddedLookup('0x'.str_pad(strtoupper(dechex($wFormatTag)), 4, '0', STR_PAD_LEFT), $begin, __LINE__, __FILE__, 'riff-wFormatTag');
1706
+
1707
+ }
1708
+
1709
+
1710
+ function RIFFfourccLookup($fourcc) {
1711
+
1712
+ $begin = __LINE__;
1713
+
1714
+ /** This is not a comment!
1715
+
1716
+ swot http://developer.apple.com/qa/snd/snd07.html
1717
+ ____ No Codec (____)
1718
+ _BIT BI_BITFIELDS (Raw RGB)
1719
+ _JPG JPEG compressed
1720
+ _PNG PNG compressed W3C/ISO/IEC (RFC-2083)
1721
+ _RAW Full Frames (Uncompressed)
1722
+ _RGB Raw RGB Bitmap
1723
+ _RL4 RLE 4bpp RGB
1724
+ _RL8 RLE 8bpp RGB
1725
+ 3IV1 3ivx MPEG-4 v1
1726
+ 3IV2 3ivx MPEG-4 v2
1727
+ 3IVX 3ivx MPEG-4
1728
+ AASC Autodesk Animator
1729
+ ABYR Kensington ?ABYR?
1730
+ AEMI Array Microsystems VideoONE MPEG1-I Capture
1731
+ AFLC Autodesk Animator FLC
1732
+ AFLI Autodesk Animator FLI
1733
+ AMPG Array Microsystems VideoONE MPEG
1734
+ ANIM Intel RDX (ANIM)
1735
+ AP41 AngelPotion Definitive
1736
+ ASV1 Asus Video v1
1737
+ ASV2 Asus Video v2
1738
+ ASVX Asus Video 2.0 (audio)
1739
+ AUR2 AuraVision Aura 2 Codec - YUV 4:2:2
1740
+ AURA AuraVision Aura 1 Codec - YUV 4:1:1
1741
+ AVDJ Independent JPEG Group\'s codec (AVDJ)
1742
+ AVRN Independent JPEG Group\'s codec (AVRN)
1743
+ AYUV 4:4:4 YUV (AYUV)
1744
+ AZPR Quicktime Apple Video (AZPR)
1745
+ BGR Raw RGB32
1746
+ BLZ0 Blizzard DivX MPEG-4
1747
+ BTVC Conexant Composite Video
1748
+ BINK RAD Game Tools Bink Video
1749
+ BT20 Conexant Prosumer Video
1750
+ BTCV Conexant Composite Video Codec
1751
+ BW10 Data Translation Broadway MPEG Capture
1752
+ CC12 Intel YUV12
1753
+ CDVC Canopus DV
1754
+ CFCC Digital Processing Systems DPS Perception
1755
+ CGDI Microsoft Office 97 Camcorder Video
1756
+ CHAM Winnov Caviara Champagne
1757
+ CJPG Creative WebCam JPEG
1758
+ CLJR Cirrus Logic YUV 4:1:1
1759
+ CMYK Common Data Format in Printing (Colorgraph)
1760
+ CPLA Weitek 4:2:0 YUV Planar
1761
+ CRAM Microsoft Video 1 (CRAM)
1762
+ cvid Radius Cinepak
1763
+ CVID Radius Cinepak
1764
+ CWLT Microsoft Color WLT DIB
1765
+ CYUV Creative Labs YUV
1766
+ CYUY ATI YUV
1767
+ D261 H.261
1768
+ D263 H.263
1769
+ DIB Device Independent Bitmap
1770
+ DIV1 FFmpeg OpenDivX
1771
+ DIV2 Microsoft MPEG-4 v1/v2
1772
+ DIV3 DivX ;-) MPEG-4 v3.x Low-Motion
1773
+ DIV4 DivX ;-) MPEG-4 v3.x Fast-Motion
1774
+ DIV5 DivX MPEG-4 v5.x
1775
+ DIV6 DivX ;-) (MS MPEG-4 v3.x)
1776
+ DIVX DivX MPEG-4 v4 (OpenDivX / Project Mayo)
1777
+ divx DivX MPEG-4
1778
+ DMB1 Matrox Rainbow Runner hardware MJPEG
1779
+ DMB2 Paradigm MJPEG
1780
+ DSVD ?DSVD?
1781
+ DUCK Duck TrueMotion 1.0
1782
+ DPS0 DPS/Leitch Reality Motion JPEG
1783
+ DPSC DPS/Leitch PAR Motion JPEG
1784
+ DV25 Matrox DVCPRO codec
1785
+ DV50 Matrox DVCPRO50 codec
1786
+ DVC IEC 61834 and SMPTE 314M (DVC/DV Video)
1787
+ DVCP IEC 61834 and SMPTE 314M (DVC/DV Video)
1788
+ DVHD IEC Standard DV 1125 lines @ 30fps / 1250 lines @ 25fps
1789
+ DVMA Darim Vision DVMPEG (dummy for MPEG compressor) (www.darvision.com)
1790
+ DVSL IEC Standard DV compressed in SD (SDL)
1791
+ DVAN ?DVAN?
1792
+ DVE2 InSoft DVE-2 Videoconferencing
1793
+ dvsd IEC 61834 and SMPTE 314M DVC/DV Video
1794
+ DVSD IEC 61834 and SMPTE 314M DVC/DV Video
1795
+ DVX1 Lucent DVX1000SP Video Decoder
1796
+ DVX2 Lucent DVX2000S Video Decoder
1797
+ DVX3 Lucent DVX3000S Video Decoder
1798
+ DX50 DivX v5
1799
+ DXT1 Microsoft DirectX Compressed Texture (DXT1)
1800
+ DXT2 Microsoft DirectX Compressed Texture (DXT2)
1801
+ DXT3 Microsoft DirectX Compressed Texture (DXT3)
1802
+ DXT4 Microsoft DirectX Compressed Texture (DXT4)
1803
+ DXT5 Microsoft DirectX Compressed Texture (DXT5)
1804
+ DXTC Microsoft DirectX Compressed Texture (DXTC)
1805
+ DXTn Microsoft DirectX Compressed Texture (DXTn)
1806
+ EM2V Etymonix MPEG-2 I-frame (www.etymonix.com)
1807
+ EKQ0 Elsa ?EKQ0?
1808
+ ELK0 Elsa ?ELK0?
1809
+ ESCP Eidos Escape
1810
+ ETV1 eTreppid Video ETV1
1811
+ ETV2 eTreppid Video ETV2
1812
+ ETVC eTreppid Video ETVC
1813
+ FLIC Autodesk FLI/FLC Animation
1814
+ FRWT Darim Vision Forward Motion JPEG (www.darvision.com)
1815
+ FRWU Darim Vision Forward Uncompressed (www.darvision.com)
1816
+ FLJP D-Vision Field Encoded Motion JPEG
1817
+ FRWA SoftLab-Nsk Forward Motion JPEG w/ alpha channel
1818
+ FRWD SoftLab-Nsk Forward Motion JPEG
1819
+ FVF1 Iterated Systems Fractal Video Frame
1820
+ GLZW Motion LZW (gabest@freemail.hu)
1821
+ GPEG Motion JPEG (gabest@freemail.hu)
1822
+ GWLT Microsoft Greyscale WLT DIB
1823
+ H260 Intel ITU H.260 Videoconferencing
1824
+ H261 Intel ITU H.261 Videoconferencing
1825
+ H262 Intel ITU H.262 Videoconferencing
1826
+ H263 Intel ITU H.263 Videoconferencing
1827
+ H264 Intel ITU H.264 Videoconferencing
1828
+ H265 Intel ITU H.265 Videoconferencing
1829
+ H266 Intel ITU H.266 Videoconferencing
1830
+ H267 Intel ITU H.267 Videoconferencing
1831
+ H268 Intel ITU H.268 Videoconferencing
1832
+ H269 Intel ITU H.269 Videoconferencing
1833
+ HFYU Huffman Lossless Codec
1834
+ HMCR Rendition Motion Compensation Format (HMCR)
1835
+ HMRR Rendition Motion Compensation Format (HMRR)
1836
+ I263 FFmpeg I263 decoder
1837
+ IF09 Indeo YVU9 ("YVU9 with additional delta-frame info after the U plane")
1838
+ IUYV Interlaced version of UYVY (www.leadtools.com)
1839
+ IY41 Interlaced version of Y41P (www.leadtools.com)
1840
+ IYU1 12 bit format used in mode 2 of the IEEE 1394 Digital Camera 1.04 spec IEEE standard
1841
+ IYU2 24 bit format used in mode 2 of the IEEE 1394 Digital Camera 1.04 spec IEEE standard
1842
+ IYUV Planar YUV format (8-bpp Y plane, followed by 8-bpp 2�2 U and V planes)
1843
+ i263 Intel ITU H.263 Videoconferencing (i263)
1844
+ I420 Intel Indeo 4
1845
+ IAN Intel Indeo 4 (RDX)
1846
+ ICLB InSoft CellB Videoconferencing
1847
+ IGOR Power DVD
1848
+ IJPG Intergraph JPEG
1849
+ ILVC Intel Layered Video
1850
+ ILVR ITU-T H.263+
1851
+ IPDV I-O Data Device Giga AVI DV Codec
1852
+ IR21 Intel Indeo 2.1
1853
+ IRAW Intel YUV Uncompressed
1854
+ IV30 Intel Indeo 3.0
1855
+ IV31 Intel Indeo 3.1
1856
+ IV32 Ligos Indeo 3.2
1857
+ IV33 Ligos Indeo 3.3
1858
+ IV34 Ligos Indeo 3.4
1859
+ IV35 Ligos Indeo 3.5
1860
+ IV36 Ligos Indeo 3.6
1861
+ IV37 Ligos Indeo 3.7
1862
+ IV38 Ligos Indeo 3.8
1863
+ IV39 Ligos Indeo 3.9
1864
+ IV40 Ligos Indeo Interactive 4.0
1865
+ IV41 Ligos Indeo Interactive 4.1
1866
+ IV42 Ligos Indeo Interactive 4.2
1867
+ IV43 Ligos Indeo Interactive 4.3
1868
+ IV44 Ligos Indeo Interactive 4.4
1869
+ IV45 Ligos Indeo Interactive 4.5
1870
+ IV46 Ligos Indeo Interactive 4.6
1871
+ IV47 Ligos Indeo Interactive 4.7
1872
+ IV48 Ligos Indeo Interactive 4.8
1873
+ IV49 Ligos Indeo Interactive 4.9
1874
+ IV50 Ligos Indeo Interactive 5.0
1875
+ JBYR Kensington ?JBYR?
1876
+ JPEG Still Image JPEG DIB
1877
+ JPGL Pegasus Lossless Motion JPEG
1878
+ KMVC Team17 Software Karl Morton\'s Video Codec
1879
+ LSVM Vianet Lighting Strike Vmail (Streaming) (www.vianet.com)
1880
+ LEAD LEAD Video Codec
1881
+ Ljpg LEAD MJPEG Codec
1882
+ MDVD Alex MicroDVD Video (hacked MS MPEG-4) (www.tiasoft.de)
1883
+ MJPA Morgan Motion JPEG (MJPA) (www.morgan-multimedia.com)
1884
+ MJPB Morgan Motion JPEG (MJPB) (www.morgan-multimedia.com)
1885
+ MMES Matrox MPEG-2 I-frame
1886
+ MP2v Microsoft S-Mpeg 4 version 1 (MP2v)
1887
+ MP42 Microsoft S-Mpeg 4 version 2 (MP42)
1888
+ MP43 Microsoft S-Mpeg 4 version 3 (MP43)
1889
+ MP4S Microsoft S-Mpeg 4 version 3 (MP4S)
1890
+ MP4V FFmpeg MPEG-4
1891
+ MPG1 FFmpeg MPEG 1/2
1892
+ MPG2 FFmpeg MPEG 1/2
1893
+ MPG3 FFmpeg DivX ;-) (MS MPEG-4 v3)
1894
+ MPG4 Microsoft MPEG-4
1895
+ MPGI Sigma Designs MPEG
1896
+ MPNG PNG images decoder
1897
+ MSS1 Microsoft Windows Screen Video
1898
+ MSZH LCL (Lossless Codec Library) (www.geocities.co.jp/Playtown-Denei/2837/LRC.htm)
1899
+ M261 Microsoft H.261
1900
+ M263 Microsoft H.263
1901
+ M4S2 Microsoft Fully Compliant MPEG-4 v2 simple profile (M4S2)
1902
+ m4s2 Microsoft Fully Compliant MPEG-4 v2 simple profile (m4s2)
1903
+ MC12 ATI Motion Compensation Format (MC12)
1904
+ MCAM ATI Motion Compensation Format (MCAM)
1905
+ MJ2C Morgan Multimedia Motion JPEG2000
1906
+ mJPG IBM Motion JPEG w/ Huffman Tables
1907
+ MJPG Microsoft Motion JPEG DIB
1908
+ MP42 Microsoft MPEG-4 (low-motion)
1909
+ MP43 Microsoft MPEG-4 (fast-motion)
1910
+ MP4S Microsoft MPEG-4 (MP4S)
1911
+ mp4s Microsoft MPEG-4 (mp4s)
1912
+ MPEG Chromatic Research MPEG-1 Video I-Frame
1913
+ MPG4 Microsoft MPEG-4 Video High Speed Compressor
1914
+ MPGI Sigma Designs MPEG
1915
+ MRCA FAST Multimedia Martin Regen Codec
1916
+ MRLE Microsoft Run Length Encoding
1917
+ MSVC Microsoft Video 1
1918
+ MTX1 Matrox ?MTX1?
1919
+ MTX2 Matrox ?MTX2?
1920
+ MTX3 Matrox ?MTX3?
1921
+ MTX4 Matrox ?MTX4?
1922
+ MTX5 Matrox ?MTX5?
1923
+ MTX6 Matrox ?MTX6?
1924
+ MTX7 Matrox ?MTX7?
1925
+ MTX8 Matrox ?MTX8?
1926
+ MTX9 Matrox ?MTX9?
1927
+ MV12 Motion Pixels Codec (old)
1928
+ MWV1 Aware Motion Wavelets
1929
+ nAVI SMR Codec (hack of Microsoft MPEG-4) (IRC #shadowrealm)
1930
+ NT00 NewTek LightWave HDTV YUV w/ Alpha (www.newtek.com)
1931
+ NUV1 NuppelVideo
1932
+ NTN1 Nogatech Video Compression 1
1933
+ NVS0 nVidia GeForce Texture (NVS0)
1934
+ NVS1 nVidia GeForce Texture (NVS1)
1935
+ NVS2 nVidia GeForce Texture (NVS2)
1936
+ NVS3 nVidia GeForce Texture (NVS3)
1937
+ NVS4 nVidia GeForce Texture (NVS4)
1938
+ NVS5 nVidia GeForce Texture (NVS5)
1939
+ NVT0 nVidia GeForce Texture (NVT0)
1940
+ NVT1 nVidia GeForce Texture (NVT1)
1941
+ NVT2 nVidia GeForce Texture (NVT2)
1942
+ NVT3 nVidia GeForce Texture (NVT3)
1943
+ NVT4 nVidia GeForce Texture (NVT4)
1944
+ NVT5 nVidia GeForce Texture (NVT5)
1945
+ PIXL MiroXL, Pinnacle PCTV
1946
+ PDVC I-O Data Device Digital Video Capture DV codec
1947
+ PGVV Radius Video Vision
1948
+ PHMO IBM Photomotion
1949
+ PIM1 MPEG Realtime (Pinnacle Cards)
1950
+ PIM2 Pegasus Imaging ?PIM2?
1951
+ PIMJ Pegasus Imaging Lossless JPEG
1952
+ PVEZ Horizons Technology PowerEZ
1953
+ PVMM PacketVideo Corporation MPEG-4
1954
+ PVW2 Pegasus Imaging Wavelet Compression
1955
+ Q1.0 Q-Team\'s QPEG 1.0 (www.q-team.de)
1956
+ Q1.1 Q-Team\'s QPEG 1.1 (www.q-team.de)
1957
+ QPEG Q-Team QPEG 1.0
1958
+ qpeq Q-Team QPEG 1.1
1959
+ RGB Raw BGR32
1960
+ RGBA Raw RGB w/ Alpha
1961
+ RMP4 REALmagic MPEG-4 (unauthorized XVID copy) (www.sigmadesigns.com)
1962
+ ROQV Id RoQ File Video Decoder
1963
+ RPZA Quicktime Apple Video (RPZA)
1964
+ RUD0 Rududu video codec (http://rududu.ifrance.com/rududu/)
1965
+ RV10 RealVideo 1.0 (aka RealVideo 5.0)
1966
+ RV13 RealVideo 1.0 (RV13)
1967
+ RV20 RealVideo G2
1968
+ RV30 RealVideo 8
1969
+ RV40 RealVideo 9
1970
+ RGBT Raw RGB w/ Transparency
1971
+ RLE Microsoft Run Length Encoder
1972
+ RLE4 Run Length Encoded (4bpp, 16-color)
1973
+ RLE8 Run Length Encoded (8bpp, 256-color)
1974
+ RT21 Intel Indeo RealTime Video 2.1
1975
+ rv20 RealVideo G2
1976
+ rv30 RealVideo 8
1977
+ RVX Intel RDX (RVX )
1978
+ SMC Apple Graphics (SMC )
1979
+ SP54 Logitech Sunplus Sp54 Codec for Mustek GSmart Mini 2
1980
+ SPIG Radius Spigot
1981
+ SVQ3 Sorenson Video 3 (Apple Quicktime 5)
1982
+ s422 Tekram VideoCap C210 YUV 4:2:2
1983
+ SDCC Sun Communication Digital Camera Codec
1984
+ SFMC CrystalNet Surface Fitting Method
1985
+ SMSC Radius SMSC
1986
+ SMSD Radius SMSD
1987
+ smsv WorldConnect Wavelet Video
1988
+ SPIG Radius Spigot
1989
+ SPLC Splash Studios ACM Audio Codec (www.splashstudios.net)
1990
+ SQZ2 Microsoft VXTreme Video Codec V2
1991
+ STVA ST Microelectronics CMOS Imager Data (Bayer)
1992
+ STVB ST Microelectronics CMOS Imager Data (Nudged Bayer)
1993
+ STVC ST Microelectronics CMOS Imager Data (Bunched)
1994
+ STVX ST Microelectronics CMOS Imager Data (Extended CODEC Data Format)
1995
+ STVY ST Microelectronics CMOS Imager Data (Extended CODEC Data Format with Correction Data)
1996
+ SV10 Sorenson Video R1
1997
+ SVQ1 Sorenson Video
1998
+ T420 Toshiba YUV 4:2:0
1999
+ TM2A Duck TrueMotion Archiver 2.0 (www.duck.com)
2000
+ TVJP Pinnacle/Truevision Targa 2000 board (TVJP)
2001
+ TVMJ Pinnacle/Truevision Targa 2000 board (TVMJ)
2002
+ TY0N Tecomac Low-Bit Rate Codec (www.tecomac.com)
2003
+ TY2C Trident Decompression Driver
2004
+ TLMS TeraLogic Motion Intraframe Codec (TLMS)
2005
+ TLST TeraLogic Motion Intraframe Codec (TLST)
2006
+ TM20 Duck TrueMotion 2.0
2007
+ TM2X Duck TrueMotion 2X
2008
+ TMIC TeraLogic Motion Intraframe Codec (TMIC)
2009
+ TMOT Horizons Technology TrueMotion S
2010
+ tmot Horizons TrueMotion Video Compression
2011
+ TR20 Duck TrueMotion RealTime 2.0
2012
+ TSCC TechSmith Screen Capture Codec
2013
+ TV10 Tecomac Low-Bit Rate Codec
2014
+ TY2N Trident ?TY2N?
2015
+ U263 UB Video H.263/H.263+/H.263++ Decoder
2016
+ UMP4 UB Video MPEG 4 (www.ubvideo.com)
2017
+ UYNV Nvidia UYVY packed 4:2:2
2018
+ UYVP Evans & Sutherland YCbCr 4:2:2 extended precision
2019
+ UCOD eMajix.com ClearVideo
2020
+ ULTI IBM Ultimotion
2021
+ UYVY UYVY packed 4:2:2
2022
+ V261 Lucent VX2000S
2023
+ VIFP VFAPI Reader Codec (www.yks.ne.jp/~hori/)
2024
+ VIV1 FFmpeg H263+ decoder
2025
+ VIV2 Vivo H.263
2026
+ VQC2 Vector-quantised codec 2 (research) http://eprints.ecs.soton.ac.uk/archive/00001310/01/VTC97-js.pdf)
2027
+ VTLP Alaris VideoGramPiX
2028
+ VYU9 ATI YUV (VYU9)
2029
+ VYUY ATI YUV (VYUY)
2030
+ V261 Lucent VX2000S
2031
+ V422 Vitec Multimedia 24-bit YUV 4:2:2 Format
2032
+ V655 Vitec Multimedia 16-bit YUV 4:2:2 Format
2033
+ VCR1 ATI Video Codec 1
2034
+ VCR2 ATI Video Codec 2
2035
+ VCR3 ATI VCR 3.0
2036
+ VCR4 ATI VCR 4.0
2037
+ VCR5 ATI VCR 5.0
2038
+ VCR6 ATI VCR 6.0
2039
+ VCR7 ATI VCR 7.0
2040
+ VCR8 ATI VCR 8.0
2041
+ VCR9 ATI VCR 9.0
2042
+ VDCT Vitec Multimedia Video Maker Pro DIB
2043
+ VDOM VDOnet VDOWave
2044
+ VDOW VDOnet VDOLive (H.263)
2045
+ VDTZ Darim Vison VideoTizer YUV
2046
+ VGPX Alaris VideoGramPiX
2047
+ VIDS Vitec Multimedia YUV 4:2:2 CCIR 601 for V422
2048
+ VIVO Vivo H.263 v2.00
2049
+ vivo Vivo H.263
2050
+ VIXL Miro/Pinnacle Video XL
2051
+ VLV1 VideoLogic/PURE Digital Videologic Capture
2052
+ VP30 On2 VP3.0
2053
+ VP31 On2 VP3.1
2054
+ VX1K Lucent VX1000S Video Codec
2055
+ VX2K Lucent VX2000S Video Codec
2056
+ VXSP Lucent VX1000SP Video Codec
2057
+ WBVC Winbond W9960
2058
+ WHAM Microsoft Video 1 (WHAM)
2059
+ WINX Winnov Software Compression
2060
+ WJPG AverMedia Winbond JPEG
2061
+ WMV1 Windows Media Video V7
2062
+ WMV2 Windows Media Video V8
2063
+ WMV3 Windows Media Video V9
2064
+ WNV1 Winnov Hardware Compression
2065
+ XYZP Extended PAL format XYZ palette (www.riff.org)
2066
+ x263 Xirlink H.263
2067
+ XLV0 NetXL Video Decoder
2068
+ XMPG Xing MPEG (I-Frame only)
2069
+ XVID XviD MPEG-4 (www.xvid.org)
2070
+ XXAN ?XXAN?
2071
+ YU92 Intel YUV (YU92)
2072
+ YUNV Nvidia Uncompressed YUV 4:2:2
2073
+ YUVP Extended PAL format YUV palette (www.riff.org)
2074
+ Y211 YUV 2:1:1 Packed
2075
+ Y411 YUV 4:1:1 Packed
2076
+ Y41B Weitek YUV 4:1:1 Planar
2077
+ Y41P Brooktree PC1 YUV 4:1:1 Packed
2078
+ Y41T Brooktree PC1 YUV 4:1:1 with transparency
2079
+ Y42B Weitek YUV 4:2:2 Planar
2080
+ Y42T Brooktree UYUV 4:2:2 with transparency
2081
+ Y422 ADS Technologies Copy of UYVY used in Pyro WebCam firewire camera
2082
+ Y800 Simple, single Y plane for monochrome images
2083
+ Y8 Grayscale video
2084
+ YC12 Intel YUV 12 codec
2085
+ YUV8 Winnov Caviar YUV8
2086
+ YUV9 Intel YUV9
2087
+ YUY2 Uncompressed YUV 4:2:2
2088
+ YUYV Canopus YUV
2089
+ YV12 YVU12 Planar
2090
+ YVU9 Intel YVU9 Planar (8-bpp Y plane, followed by 8-bpp 4x4 U and V planes)
2091
+ YVYU YVYU 4:2:2 Packed
2092
+ ZLIB Lossless Codec Library zlib compression (www.geocities.co.jp/Playtown-Denei/2837/LRC.htm)
2093
+ ZPEG Metheus Video Zipper
2094
+
2095
+ */
2096
+
2097
+ return getid3_lib::EmbeddedLookup($fourcc, $begin, __LINE__, __FILE__, 'riff-fourcc');
2098
+ }
2099
+
2100
+
2101
+ function EitherEndian2Int(&$ThisFileInfo, $byteword, $signed=false) {
2102
+ if ($ThisFileInfo['fileformat'] == 'riff') {
2103
+ return getid3_lib::LittleEndian2Int($byteword, $signed);
2104
+ }
2105
+ return getid3_lib::BigEndian2Int($byteword, false, $signed);
2106
+ }
2107
+
2108
+ }
2109
+
2110
+ ?>
view/getid3/module.audio-video.swf.php ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /////////////////////////////////////////////////////////////////
3
+ /// getID3() by James Heinrich <info@getid3.org> //
4
+ // available at http://getid3.sourceforge.net //
5
+ // or http://www.getid3.org //
6
+ /////////////////////////////////////////////////////////////////
7
+ // See readme.txt for more details //
8
+ /////////////////////////////////////////////////////////////////
9
+ // //
10
+ // module.audio-video.swf.php //
11
+ // module for analyzing Shockwave Flash files //
12
+ // dependencies: NONE //
13
+ // ///
14
+ /////////////////////////////////////////////////////////////////
15
+
16
+
17
+ class getid3_swf
18
+ {
19
+
20
+ function getid3_swf(&$fd, &$ThisFileInfo, $ReturnAllTagData=false) {
21
+ //$start_time = microtime(true);
22
+ $ThisFileInfo['fileformat'] = 'swf';
23
+ $ThisFileInfo['video']['dataformat'] = 'swf';
24
+
25
+ // http://www.openswf.org/spec/SWFfileformat.html
26
+
27
+ fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
28
+
29
+ $SWFfileData = fread($fd, $ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']); // 8 + 2 + 2 + max(9) bytes NOT including Frame_Size RECT data
30
+
31
+ $ThisFileInfo['swf']['header']['signature'] = substr($SWFfileData, 0, 3);
32
+ switch ($ThisFileInfo['swf']['header']['signature']) {
33
+ case 'FWS':
34
+ $ThisFileInfo['swf']['header']['compressed'] = false;
35
+ break;
36
+
37
+ case 'CWS':
38
+ $ThisFileInfo['swf']['header']['compressed'] = true;
39
+ break;
40
+
41
+ default:
42
+ $ThisFileInfo['error'][] = 'Expecting "FWS" or "CWS" at offset '.$ThisFileInfo['avdataoffset'].', found "'.$ThisFileInfo['swf']['header']['signature'].'"';
43
+ unset($ThisFileInfo['swf']);
44
+ unset($ThisFileInfo['fileformat']);
45
+ return false;
46
+ break;
47
+ }
48
+ $ThisFileInfo['swf']['header']['version'] = getid3_lib::LittleEndian2Int(substr($SWFfileData, 3, 1));
49
+ $ThisFileInfo['swf']['header']['length'] = getid3_lib::LittleEndian2Int(substr($SWFfileData, 4, 4));
50
+
51
+ //echo __LINE__.'='.number_format(microtime(true) - $start_time, 3).'<br>';
52
+
53
+ if ($ThisFileInfo['swf']['header']['compressed']) {
54
+
55
+ $SWFHead = substr($SWFfileData, 0, 8);
56
+ $SWFfileData = substr($SWFfileData, 8);
57
+ if ($decompressed = @gzuncompress($SWFfileData)) {
58
+
59
+ $SWFfileData = $SWFHead.$decompressed;
60
+
61
+ } else {
62
+
63
+ $ThisFileInfo['error'][] = 'Error decompressing compressed SWF data ('.strlen($SWFfileData).' bytes compressed, should be '.($ThisFileInfo['swf']['header']['length'] - 8).' bytes uncompressed)';
64
+ return false;
65
+
66
+ }
67
+
68
+ }
69
+ //echo __LINE__.'='.number_format(microtime(true) - $start_time, 3).'<br>';
70
+
71
+ $FrameSizeBitsPerValue = (ord(substr($SWFfileData, 8, 1)) & 0xF8) >> 3;
72
+ $FrameSizeDataLength = ceil((5 + (4 * $FrameSizeBitsPerValue)) / 8);
73
+ $FrameSizeDataString = str_pad(decbin(ord(substr($SWFfileData, 8, 1)) & 0x07), 3, '0', STR_PAD_LEFT);
74
+ for ($i = 1; $i < $FrameSizeDataLength; $i++) {
75
+ $FrameSizeDataString .= str_pad(decbin(ord(substr($SWFfileData, 8 + $i, 1))), 8, '0', STR_PAD_LEFT);
76
+ }
77
+ list($X1, $X2, $Y1, $Y2) = explode("\n", wordwrap($FrameSizeDataString, $FrameSizeBitsPerValue, "\n", 1));
78
+ $ThisFileInfo['swf']['header']['frame_width'] = getid3_lib::Bin2Dec($X2);
79
+ $ThisFileInfo['swf']['header']['frame_height'] = getid3_lib::Bin2Dec($Y2);
80
+
81
+ // http://www-lehre.informatik.uni-osnabrueck.de/~fbstark/diplom/docs/swf/Flash_Uncovered.htm
82
+ // Next in the header is the frame rate, which is kind of weird.
83
+ // It is supposed to be stored as a 16bit integer, but the first byte
84
+ // (or last depending on how you look at it) is completely ignored.
85
+ // Example: 0x000C -> 0x0C -> 12 So the frame rate is 12 fps.
86
+
87
+ // Byte at (8 + $FrameSizeDataLength) is always zero and ignored
88
+ $ThisFileInfo['swf']['header']['frame_rate'] = getid3_lib::LittleEndian2Int(substr($SWFfileData, 9 + $FrameSizeDataLength, 1));
89
+ $ThisFileInfo['swf']['header']['frame_count'] = getid3_lib::LittleEndian2Int(substr($SWFfileData, 10 + $FrameSizeDataLength, 2));
90
+
91
+ $ThisFileInfo['video']['frame_rate'] = $ThisFileInfo['swf']['header']['frame_rate'];
92
+ $ThisFileInfo['video']['resolution_x'] = intval(round($ThisFileInfo['swf']['header']['frame_width'] / 20));
93
+ $ThisFileInfo['video']['resolution_y'] = intval(round($ThisFileInfo['swf']['header']['frame_height'] / 20));
94
+ $ThisFileInfo['video']['pixel_aspect_ratio'] = (float) 1;
95
+
96
+ if (($ThisFileInfo['swf']['header']['frame_count'] > 0) && ($ThisFileInfo['swf']['header']['frame_rate'] > 0)) {
97
+ $ThisFileInfo['playtime_seconds'] = $ThisFileInfo['swf']['header']['frame_count'] / $ThisFileInfo['swf']['header']['frame_rate'];
98
+ }
99
+ //echo __LINE__.'='.number_format(microtime(true) - $start_time, 3).'<br>';
100
+
101
+
102
+ // SWF tags
103
+
104
+ $CurrentOffset = 12 + $FrameSizeDataLength;
105
+ $SWFdataLength = strlen($SWFfileData);
106
+
107
+ while ($CurrentOffset < $SWFdataLength) {
108
+ //echo __LINE__.'='.number_format(microtime(true) - $start_time, 3).'<br>';
109
+
110
+ $TagIDTagLength = getid3_lib::LittleEndian2Int(substr($SWFfileData, $CurrentOffset, 2));
111
+ $TagID = ($TagIDTagLength & 0xFFFC) >> 6;
112
+ $TagLength = ($TagIDTagLength & 0x003F);
113
+ $CurrentOffset += 2;
114
+ if ($TagLength == 0x3F) {
115
+ $TagLength = getid3_lib::LittleEndian2Int(substr($SWFfileData, $CurrentOffset, 4));
116
+ $CurrentOffset += 4;
117
+ }
118
+
119
+ unset($TagData);
120
+ $TagData['offset'] = $CurrentOffset;
121
+ $TagData['size'] = $TagLength;
122
+ $TagData['id'] = $TagID;
123
+ $TagData['data'] = substr($SWFfileData, $CurrentOffset, $TagLength);
124
+ switch ($TagID) {
125
+ case 0: // end of movie
126
+ break 2;
127
+
128
+ case 9: // Set background color
129
+ //$ThisFileInfo['swf']['tags'][] = $TagData;
130
+ $ThisFileInfo['swf']['bgcolor'] = strtoupper(str_pad(dechex(getid3_lib::BigEndian2Int($TagData['data'])), 6, '0', STR_PAD_LEFT));
131
+ break;
132
+
133
+ default:
134
+ if ($ReturnAllTagData) {
135
+ $ThisFileInfo['swf']['tags'][] = $TagData;
136
+ }
137
+ break;
138
+ }
139
+
140
+ $CurrentOffset += $TagLength;
141
+ }
142
+
143
+ return true;
144
+ }
145
+
146
+ }
147
+
148
+
149
+ ?>
view/getid3/module.audio.aac.php ADDED
@@ -0,0 +1,542 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /////////////////////////////////////////////////////////////////
3
+ /// getID3() by James Heinrich <info@getid3.org> //
4
+ // available at http://getid3.sourceforge.net //
5
+ // or http://www.getid3.org //
6
+ /////////////////////////////////////////////////////////////////
7
+ // See readme.txt for more details //
8
+ /////////////////////////////////////////////////////////////////
9
+ // //
10
+ // module.audio.aac.php //
11
+ // module for analyzing AAC Audio files //
12
+ // dependencies: NONE //
13
+ // ///
14
+ /////////////////////////////////////////////////////////////////
15
+
16
+
17
+ class getid3_aac
18
+ {
19
+
20
+ // new combined constructor
21
+ function getid3_aac(&$fd, &$ThisFileInfo, $option) {
22
+
23
+ if ($option === 'adif') {
24
+ $this->getAACADIFheaderFilepointer($fd, $ThisFileInfo);
25
+ }
26
+ elseif ($option === 'adts') {
27
+ $this->getAACADTSheaderFilepointer($fd, $ThisFileInfo);
28
+ }
29
+ }
30
+
31
+
32
+
33
+ function getAACADIFheaderFilepointer(&$fd, &$ThisFileInfo) {
34
+ $ThisFileInfo['fileformat'] = 'aac';
35
+ $ThisFileInfo['audio']['dataformat'] = 'aac';
36
+ $ThisFileInfo['audio']['lossless'] = false;
37
+
38
+ fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
39
+ $AACheader = fread($fd, 1024);
40
+ $offset = 0;
41
+
42
+ if (substr($AACheader, 0, 4) == 'ADIF') {
43
+
44
+ // http://faac.sourceforge.net/wiki/index.php?page=ADIF
45
+
46
+ // http://libmpeg.org/mpeg4/doc/w2203tfs.pdf
47
+ // adif_header() {
48
+ // adif_id 32
49
+ // copyright_id_present 1
50
+ // if( copyright_id_present )
51
+ // copyright_id 72
52
+ // original_copy 1
53
+ // home 1
54
+ // bitstream_type 1
55
+ // bitrate 23
56
+ // num_program_config_elements 4
57
+ // for (i = 0; i < num_program_config_elements + 1; i++ ) {
58
+ // if( bitstream_type == '0' )
59
+ // adif_buffer_fullness 20
60
+ // program_config_element()
61
+ // }
62
+ // }
63
+
64
+ $AACheaderBitstream = getid3_lib::BigEndian2Bin($AACheader);
65
+ $bitoffset = 0;
66
+
67
+ $ThisFileInfo['aac']['header_type'] = 'ADIF';
68
+ $bitoffset += 32;
69
+ $ThisFileInfo['aac']['header']['mpeg_version'] = 4;
70
+
71
+ $ThisFileInfo['aac']['header']['copyright'] = (bool) (substr($AACheaderBitstream, $bitoffset, 1) == '1');
72
+ $bitoffset += 1;
73
+ if ($ThisFileInfo['aac']['header']['copyright']) {
74
+ $ThisFileInfo['aac']['header']['copyright_id'] = getid3_lib::Bin2String(substr($AACheaderBitstream, $bitoffset, 72));
75
+ $bitoffset += 72;
76
+ }
77
+ $ThisFileInfo['aac']['header']['original_copy'] = (bool) (substr($AACheaderBitstream, $bitoffset, 1) == '1');
78
+ $bitoffset += 1;
79
+ $ThisFileInfo['aac']['header']['home'] = (bool) (substr($AACheaderBitstream, $bitoffset, 1) == '1');
80
+ $bitoffset += 1;
81
+ $ThisFileInfo['aac']['header']['is_vbr'] = (bool) (substr($AACheaderBitstream, $bitoffset, 1) == '1');
82
+ $bitoffset += 1;
83
+ if ($ThisFileInfo['aac']['header']['is_vbr']) {
84
+ $ThisFileInfo['audio']['bitrate_mode'] = 'vbr';
85
+ $ThisFileInfo['aac']['header']['bitrate_max'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 23));
86
+ $bitoffset += 23;
87
+ } else {
88
+ $ThisFileInfo['audio']['bitrate_mode'] = 'cbr';
89
+ $ThisFileInfo['aac']['header']['bitrate'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 23));
90
+ $bitoffset += 23;
91
+ $ThisFileInfo['audio']['bitrate'] = $ThisFileInfo['aac']['header']['bitrate'];
92
+ }
93
+ if ($ThisFileInfo['audio']['bitrate'] == 0) {
94
+ $ThisFileInfo['error'][] = 'Corrupt AAC file: bitrate_audio == zero';
95
+ return false;
96
+ }
97
+ $ThisFileInfo['aac']['header']['num_program_configs'] = 1 + getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
98
+ $bitoffset += 4;
99
+
100
+ for ($i = 0; $i < $ThisFileInfo['aac']['header']['num_program_configs']; $i++) {
101
+ // http://www.audiocoding.com/wiki/index.php?page=program_config_element
102
+
103
+ // buffer_fullness 20
104
+
105
+ // element_instance_tag 4
106
+ // object_type 2
107
+ // sampling_frequency_index 4
108
+ // num_front_channel_elements 4
109
+ // num_side_channel_elements 4
110
+ // num_back_channel_elements 4
111
+ // num_lfe_channel_elements 2
112
+ // num_assoc_data_elements 3
113
+ // num_valid_cc_elements 4
114
+ // mono_mixdown_present 1
115
+ // mono_mixdown_element_number 4 if mono_mixdown_present == 1
116
+ // stereo_mixdown_present 1
117
+ // stereo_mixdown_element_number 4 if stereo_mixdown_present == 1
118
+ // matrix_mixdown_idx_present 1
119
+ // matrix_mixdown_idx 2 if matrix_mixdown_idx_present == 1
120
+ // pseudo_surround_enable 1 if matrix_mixdown_idx_present == 1
121
+ // for (i = 0; i < num_front_channel_elements; i++) {
122
+ // front_element_is_cpe[i] 1
123
+ // front_element_tag_select[i] 4
124
+ // }
125
+ // for (i = 0; i < num_side_channel_elements; i++) {
126
+ // side_element_is_cpe[i] 1
127
+ // side_element_tag_select[i] 4
128
+ // }
129
+ // for (i = 0; i < num_back_channel_elements; i++) {
130
+ // back_element_is_cpe[i] 1
131
+ // back_element_tag_select[i] 4
132
+ // }
133
+ // for (i = 0; i < num_lfe_channel_elements; i++) {
134
+ // lfe_element_tag_select[i] 4
135
+ // }
136
+ // for (i = 0; i < num_assoc_data_elements; i++) {
137
+ // assoc_data_element_tag_select[i] 4
138
+ // }
139
+ // for (i = 0; i < num_valid_cc_elements; i++) {
140
+ // cc_element_is_ind_sw[i] 1
141
+ // valid_cc_element_tag_select[i] 4
142
+ // }
143
+ // byte_alignment() VAR
144
+ // comment_field_bytes 8
145
+ // for (i = 0; i < comment_field_bytes; i++) {
146
+ // comment_field_data[i] 8
147
+ // }
148
+
149
+ if (!$ThisFileInfo['aac']['header']['is_vbr']) {
150
+ $ThisFileInfo['aac']['program_configs'][$i]['buffer_fullness'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 20));
151
+ $bitoffset += 20;
152
+ }
153
+ $ThisFileInfo['aac']['program_configs'][$i]['element_instance_tag'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
154
+ $bitoffset += 4;
155
+ $ThisFileInfo['aac']['program_configs'][$i]['object_type'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 2));
156
+ $bitoffset += 2;
157
+ $ThisFileInfo['aac']['program_configs'][$i]['sampling_frequency_index'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
158
+ $bitoffset += 4;
159
+ $ThisFileInfo['aac']['program_configs'][$i]['num_front_channel_elements'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
160
+ $bitoffset += 4;
161
+ $ThisFileInfo['aac']['program_configs'][$i]['num_side_channel_elements'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
162
+ $bitoffset += 4;
163
+ $ThisFileInfo['aac']['program_configs'][$i]['num_back_channel_elements'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
164
+ $bitoffset += 4;
165
+ $ThisFileInfo['aac']['program_configs'][$i]['num_lfe_channel_elements'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 2));
166
+ $bitoffset += 2;
167
+ $ThisFileInfo['aac']['program_configs'][$i]['num_assoc_data_elements'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 3));
168
+ $bitoffset += 3;
169
+ $ThisFileInfo['aac']['program_configs'][$i]['num_valid_cc_elements'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
170
+ $bitoffset += 4;
171
+ $ThisFileInfo['aac']['program_configs'][$i]['mono_mixdown_present'] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1));
172
+ $bitoffset += 1;
173
+ if ($ThisFileInfo['aac']['program_configs'][$i]['mono_mixdown_present']) {
174
+ $ThisFileInfo['aac']['program_configs'][$i]['mono_mixdown_element_number'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
175
+ $bitoffset += 4;
176
+ }
177
+ $ThisFileInfo['aac']['program_configs'][$i]['stereo_mixdown_present'] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1));
178
+ $bitoffset += 1;
179
+ if ($ThisFileInfo['aac']['program_configs'][$i]['stereo_mixdown_present']) {
180
+ $ThisFileInfo['aac']['program_configs'][$i]['stereo_mixdown_element_number'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
181
+ $bitoffset += 4;
182
+ }
183
+ $ThisFileInfo['aac']['program_configs'][$i]['matrix_mixdown_idx_present'] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1));
184
+ $bitoffset += 1;
185
+ if ($ThisFileInfo['aac']['program_configs'][$i]['matrix_mixdown_idx_present']) {
186
+ $ThisFileInfo['aac']['program_configs'][$i]['matrix_mixdown_idx'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 2));
187
+ $bitoffset += 2;
188
+ $ThisFileInfo['aac']['program_configs'][$i]['pseudo_surround_enable'] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1));
189
+ $bitoffset += 1;
190
+ }
191
+ for ($j = 0; $j < $ThisFileInfo['aac']['program_configs'][$i]['num_front_channel_elements']; $j++) {
192
+ $ThisFileInfo['aac']['program_configs'][$i]['front_element_is_cpe'][$j] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1));
193
+ $bitoffset += 1;
194
+ $ThisFileInfo['aac']['program_configs'][$i]['front_element_tag_select'][$j] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
195
+ $bitoffset += 4;
196
+ }
197
+ for ($j = 0; $j < $ThisFileInfo['aac']['program_configs'][$i]['num_side_channel_elements']; $j++) {
198
+ $ThisFileInfo['aac']['program_configs'][$i]['side_element_is_cpe'][$j] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1));
199
+ $bitoffset += 1;
200
+ $ThisFileInfo['aac']['program_configs'][$i]['side_element_tag_select'][$j] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
201
+ $bitoffset += 4;
202
+ }
203
+ for ($j = 0; $j < $ThisFileInfo['aac']['program_configs'][$i]['num_back_channel_elements']; $j++) {
204
+ $ThisFileInfo['aac']['program_configs'][$i]['back_element_is_cpe'][$j] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1));
205
+ $bitoffset += 1;
206
+ $ThisFileInfo['aac']['program_configs'][$i]['back_element_tag_select'][$j] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
207
+ $bitoffset += 4;
208
+ }
209
+ for ($j = 0; $j < $ThisFileInfo['aac']['program_configs'][$i]['num_lfe_channel_elements']; $j++) {
210
+ $ThisFileInfo['aac']['program_configs'][$i]['lfe_element_tag_select'][$j] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
211
+ $bitoffset += 4;
212
+ }
213
+ for ($j = 0; $j < $ThisFileInfo['aac']['program_configs'][$i]['num_assoc_data_elements']; $j++) {
214
+ $ThisFileInfo['aac']['program_configs'][$i]['assoc_data_element_tag_select'][$j] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
215
+ $bitoffset += 4;
216
+ }
217
+ for ($j = 0; $j < $ThisFileInfo['aac']['program_configs'][$i]['num_valid_cc_elements']; $j++) {
218
+ $ThisFileInfo['aac']['program_configs'][$i]['cc_element_is_ind_sw'][$j] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1));
219
+ $bitoffset += 1;
220
+ $ThisFileInfo['aac']['program_configs'][$i]['valid_cc_element_tag_select'][$j] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
221
+ $bitoffset += 4;
222
+ }
223
+
224
+ $bitoffset = ceil($bitoffset / 8) * 8;
225
+
226
+ $ThisFileInfo['aac']['program_configs'][$i]['comment_field_bytes'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 8));
227
+ $bitoffset += 8;
228
+ $ThisFileInfo['aac']['program_configs'][$i]['comment_field'] = getid3_lib::Bin2String(substr($AACheaderBitstream, $bitoffset, 8 * $ThisFileInfo['aac']['program_configs'][$i]['comment_field_bytes']));
229
+ $bitoffset += 8 * $ThisFileInfo['aac']['program_configs'][$i]['comment_field_bytes'];
230
+
231
+
232
+ $ThisFileInfo['aac']['header']['profile_text'] = $this->AACprofileLookup($ThisFileInfo['aac']['program_configs'][$i]['object_type'], $ThisFileInfo['aac']['header']['mpeg_version']);
233
+ $ThisFileInfo['aac']['program_configs'][$i]['sampling_frequency'] = $this->AACsampleRateLookup($ThisFileInfo['aac']['program_configs'][$i]['sampling_frequency_index']);
234
+ $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['aac']['program_configs'][$i]['sampling_frequency'];
235
+ $ThisFileInfo['audio']['channels'] = $this->AACchannelCountCalculate($ThisFileInfo['aac']['program_configs'][$i]);
236
+ if ($ThisFileInfo['aac']['program_configs'][$i]['comment_field']) {
237
+ $ThisFileInfo['aac']['comments'][] = $ThisFileInfo['aac']['program_configs'][$i]['comment_field'];
238
+ }
239
+ }
240
+ $ThisFileInfo['playtime_seconds'] = (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8) / $ThisFileInfo['audio']['bitrate'];
241
+
242
+ $ThisFileInfo['audio']['encoder_options'] = $ThisFileInfo['aac']['header_type'].' '.$ThisFileInfo['aac']['header']['profile_text'];
243
+
244
+
245
+
246
+ return true;
247
+
248
+ } else {
249
+
250
+ unset($ThisFileInfo['fileformat']);
251
+ unset($ThisFileInfo['aac']);
252
+ $ThisFileInfo['error'][] = 'AAC-ADIF synch not found at offset '.$ThisFileInfo['avdataoffset'].' (expected "ADIF", found "'.substr($AACheader, 0, 4).'" instead)';
253
+ return false;
254
+
255
+ }
256
+
257
+ }
258
+
259
+
260
+ function getAACADTSheaderFilepointer(&$fd, &$ThisFileInfo, $MaxFramesToScan=1000000, $ReturnExtendedInfo=false) {
261
+ // based loosely on code from AACfile by Jurgen Faul <jfaul�gmx.de>
262
+ // http://jfaul.de/atl or http://j-faul.virtualave.net/atl/atl.html
263
+
264
+
265
+ // http://faac.sourceforge.net/wiki/index.php?page=ADTS
266
+
267
+ // * ADTS Fixed Header: these don't change from frame to frame
268
+ // syncword 12 always: '111111111111'
269
+ // ID 1 0: MPEG-4, 1: MPEG-2
270
+ // layer 2 always: '00'
271
+ // protection_absent 1
272
+ // profile 2
273
+ // sampling_frequency_index 4
274
+ // private_bit 1
275
+ // channel_configuration 3
276
+ // original/copy 1
277
+ // home 1
278
+ // emphasis 2 only if ID == 0 (ie MPEG-4)
279
+
280
+ // * ADTS Variable Header: these can change from frame to frame
281
+ // copyright_identification_bit 1
282
+ // copyright_identification_start 1
283
+ // aac_frame_length 13 length of the frame including header (in bytes)
284
+ // adts_buffer_fullness 11 0x7FF indicates VBR
285
+ // no_raw_data_blocks_in_frame 2
286
+
287
+ // * ADTS Error check
288
+ // crc_check 16 only if protection_absent == 0
289
+
290
+ $byteoffset = 0;
291
+ $framenumber = 0;
292
+
293
+ // Init bit pattern array
294
+ static $decbin = array();
295
+
296
+ // Populate $bindec
297
+ for ($i = 0; $i < 256; $i++) {
298
+ $decbin[chr($i)] = str_pad(decbin($i), 8, '0', STR_PAD_LEFT);
299
+ }
300
+
301
+ // used to calculate bitrate below
302
+ $BitrateCache = array();
303
+
304
+
305
+ while (true) {
306
+ // breaks out when end-of-file encountered, or invalid data found,
307
+ // or MaxFramesToScan frames have been scanned
308
+
309
+ if ($byteoffset >= pow(2, 31)) {
310
+ $ThisFileInfo['warning'][] = 'Unable to parse AAC file beyond '.ftell($fd).' (PHP does not support file operations beyond 2GB)';
311
+ return false;
312
+ }
313
+ fseek($fd, $byteoffset, SEEK_SET);
314
+
315
+ // First get substring
316
+ $substring = fread($fd, 10);
317
+ $substringlength = strlen($substring);
318
+ if ($substringlength != 10) {
319
+ $ThisFileInfo['error'][] = 'Failed to read 10 bytes at offset '.(ftell($fd) - $substringlength).' (only read '.$substringlength.' bytes)';
320
+ return false;
321
+ }
322
+
323
+ // Initialise $AACheaderBitstream
324
+ $AACheaderBitstream = '';
325
+
326
+ // Loop thru substring chars
327
+ for ($i = 0; $i < 10; $i++) {
328
+ $AACheaderBitstream .= $decbin[$substring{$i}];
329
+ }
330
+
331
+ $bitoffset = 0;
332
+
333
+ $synctest = bindec(substr($AACheaderBitstream, $bitoffset, 12));
334
+
335
+ $bitoffset += 12;
336
+ if ($synctest != 0x0FFF) {
337
+ $ThisFileInfo['error'][] = 'Synch pattern (0x0FFF) not found at offset '.(ftell($fd) - 10).' (found 0x0'.strtoupper(dechex($synctest)).' instead)';
338
+ if ($ThisFileInfo['fileformat'] == 'aac') {
339
+ return true;
340
+ }
341
+ return false;
342
+ }
343
+
344
+ // Gather info for first frame only - this takes time to do 1000 times!
345
+ if ($framenumber > 0) {
346
+
347
+ if (!$AACheaderBitstream[$bitoffset]) {
348
+
349
+ // MPEG-4
350
+ $bitoffset += 20;
351
+
352
+ } else {
353
+
354
+ // MPEG-2
355
+ $bitoffset += 18;
356
+
357
+ }
358
+
359
+ } else {
360
+
361
+ $ThisFileInfo['aac']['header_type'] = 'ADTS';
362
+ $ThisFileInfo['aac']['header']['synch'] = $synctest;
363
+ $ThisFileInfo['fileformat'] = 'aac';
364
+ $ThisFileInfo['audio']['dataformat'] = 'aac';
365
+
366
+ $ThisFileInfo['aac']['header']['mpeg_version'] = ((substr($AACheaderBitstream, $bitoffset, 1) == '0') ? 4 : 2);
367
+ $bitoffset += 1;
368
+ $ThisFileInfo['aac']['header']['layer'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 2));
369
+ $bitoffset += 2;
370
+ if ($ThisFileInfo['aac']['header']['layer'] != 0) {
371
+ $ThisFileInfo['error'][] = 'Layer error - expected 0x00, found 0x'.dechex($ThisFileInfo['aac']['header']['layer']).' instead';
372
+ return false;
373
+ }
374
+ $ThisFileInfo['aac']['header']['crc_present'] = ((substr($AACheaderBitstream, $bitoffset, 1) == '0') ? true : false);
375
+ $bitoffset += 1;
376
+ $ThisFileInfo['aac']['header']['profile_id'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 2));
377
+ $bitoffset += 2;
378
+ $ThisFileInfo['aac']['header']['profile_text'] = $this->AACprofileLookup($ThisFileInfo['aac']['header']['profile_id'], $ThisFileInfo['aac']['header']['mpeg_version']);
379
+
380
+ $ThisFileInfo['aac']['header']['sample_frequency_index'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
381
+ $bitoffset += 4;
382
+ $ThisFileInfo['aac']['header']['sample_frequency'] = $this->AACsampleRateLookup($ThisFileInfo['aac']['header']['sample_frequency_index']);
383
+ if ($ThisFileInfo['aac']['header']['sample_frequency'] == 0) {
384
+ $ThisFileInfo['error'][] = 'Corrupt AAC file: sample_frequency == zero';
385
+ return false;
386
+ }
387
+ $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['aac']['header']['sample_frequency'];
388
+
389
+ $ThisFileInfo['aac']['header']['private'] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1));
390
+ $bitoffset += 1;
391
+ $ThisFileInfo['aac']['header']['channel_configuration'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 3));
392
+ $bitoffset += 3;
393
+ $ThisFileInfo['audio']['channels'] = $ThisFileInfo['aac']['header']['channel_configuration'];
394
+ $ThisFileInfo['aac']['header']['original'] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1));
395
+ $bitoffset += 1;
396
+ $ThisFileInfo['aac']['header']['home'] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1));
397
+ $bitoffset += 1;
398
+
399
+ if ($ThisFileInfo['aac']['header']['mpeg_version'] == 4) {
400
+ $ThisFileInfo['aac']['header']['emphasis'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 2));
401
+ $bitoffset += 2;
402
+ }
403
+
404
+ if ($ReturnExtendedInfo) {
405
+
406
+ $ThisFileInfo['aac'][$framenumber]['copyright_id_bit'] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1));
407
+ $bitoffset += 1;
408
+ $ThisFileInfo['aac'][$framenumber]['copyright_id_start'] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1));
409
+ $bitoffset += 1;
410
+
411
+ } else {
412
+
413
+ $bitoffset += 2;
414
+
415
+ }
416
+
417
+ }
418
+
419
+ $FrameLength = bindec(substr($AACheaderBitstream, $bitoffset, 13));
420
+
421
+ if (!isset($BitrateCache[$FrameLength])) {
422
+ $BitrateCache[$FrameLength] = ($ThisFileInfo['aac']['header']['sample_frequency'] / 1024) * $FrameLength * 8;
423
+ }
424
+ @$ThisFileInfo['aac']['bitrate_distribution'][$BitrateCache[$FrameLength]]++;
425
+
426
+ $ThisFileInfo['aac'][$framenumber]['aac_frame_length'] = $FrameLength;
427
+ $bitoffset += 13;
428
+ $ThisFileInfo['aac'][$framenumber]['adts_buffer_fullness'] = bindec(substr($AACheaderBitstream, $bitoffset, 11));
429
+ $bitoffset += 11;
430
+ if ($ThisFileInfo['aac'][$framenumber]['adts_buffer_fullness'] == 0x07FF) {
431
+ $ThisFileInfo['audio']['bitrate_mode'] = 'vbr';
432
+ } else {
433
+ $ThisFileInfo['audio']['bitrate_mode'] = 'cbr';
434
+ }
435
+ $ThisFileInfo['aac'][$framenumber]['num_raw_data_blocks'] = bindec(substr($AACheaderBitstream, $bitoffset, 2));
436
+ $bitoffset += 2;
437
+
438
+ if ($ThisFileInfo['aac']['header']['crc_present']) {
439
+ //$ThisFileInfo['aac'][$framenumber]['crc'] = bindec(substr($AACheaderBitstream, $bitoffset, 16));
440
+ $bitoffset += 16;
441
+ }
442
+
443
+ if (!$ReturnExtendedInfo) {
444
+ unset($ThisFileInfo['aac'][$framenumber]);
445
+ }
446
+
447
+ $byteoffset += $FrameLength;
448
+ if ((++$framenumber < $MaxFramesToScan) && (($byteoffset + 10) < $ThisFileInfo['avdataend'])) {
449
+
450
+ // keep scanning
451
+
452
+ } else {
453
+
454
+ $ThisFileInfo['aac']['frames'] = $framenumber;
455
+ $ThisFileInfo['playtime_seconds'] = ($ThisFileInfo['avdataend'] / $byteoffset) * (($framenumber * 1024) / $ThisFileInfo['aac']['header']['sample_frequency']); // (1 / % of file scanned) * (samples / (samples/sec)) = seconds
456
+ if ($ThisFileInfo['playtime_seconds'] == 0) {
457
+ $ThisFileInfo['error'][] = 'Corrupt AAC file: playtime_seconds == zero';
458
+ return false;
459
+ }
460
+ $ThisFileInfo['audio']['bitrate'] = (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8) / $ThisFileInfo['playtime_seconds'];
461
+ ksort($ThisFileInfo['aac']['bitrate_distribution']);
462
+
463
+ $ThisFileInfo['audio']['encoder_options'] = $ThisFileInfo['aac']['header_type'].' '.$ThisFileInfo['aac']['header']['profile_text'];
464
+
465
+ return true;
466
+
467
+ }
468
+ }
469
+ // should never get here.
470
+ }
471
+
472
+ function AACsampleRateLookup($samplerateid) {
473
+ static $AACsampleRateLookup = array();
474
+ if (empty($AACsampleRateLookup)) {
475
+ $AACsampleRateLookup[0] = 96000;
476
+ $AACsampleRateLookup[1] = 88200;
477
+ $AACsampleRateLookup[2] = 64000;
478
+ $AACsampleRateLookup[3] = 48000;
479
+ $AACsampleRateLookup[4] = 44100;
480
+ $AACsampleRateLookup[5] = 32000;
481
+ $AACsampleRateLookup[6] = 24000;
482
+ $AACsampleRateLookup[7] = 22050;
483
+ $AACsampleRateLookup[8] = 16000;
484
+ $AACsampleRateLookup[9] = 12000;
485
+ $AACsampleRateLookup[10] = 11025;
486
+ $AACsampleRateLookup[11] = 8000;
487
+ $AACsampleRateLookup[12] = 0;
488
+ $AACsampleRateLookup[13] = 0;
489
+ $AACsampleRateLookup[14] = 0;
490
+ $AACsampleRateLookup[15] = 0;
491
+ }
492
+ return (isset($AACsampleRateLookup[$samplerateid]) ? $AACsampleRateLookup[$samplerateid] : 'invalid');
493
+ }
494
+
495
+ function AACprofileLookup($profileid, $mpegversion) {
496
+ static $AACprofileLookup = array();
497
+ if (empty($AACprofileLookup)) {
498
+ $AACprofileLookup[2][0] = 'Main profile';
499
+ $AACprofileLookup[2][1] = 'Low Complexity profile (LC)';
500
+ $AACprofileLookup[2][2] = 'Scalable Sample Rate profile (SSR)';
501
+ $AACprofileLookup[2][3] = '(reserved)';
502
+ $AACprofileLookup[4][0] = 'AAC_MAIN';
503
+ $AACprofileLookup[4][1] = 'AAC_LC';
504
+ $AACprofileLookup[4][2] = 'AAC_SSR';
505
+ $AACprofileLookup[4][3] = 'AAC_LTP';
506
+ }
507
+ return (isset($AACprofileLookup[$mpegversion][$profileid]) ? $AACprofileLookup[$mpegversion][$profileid] : 'invalid');
508
+ }
509
+
510
+ function AACchannelCountCalculate($program_configs) {
511
+ $channels = 0;
512
+ for ($i = 0; $i < $program_configs['num_front_channel_elements']; $i++) {
513
+ $channels++;
514
+ if ($program_configs['front_element_is_cpe'][$i]) {
515
+ // each front element is channel pair (CPE = Channel Pair Element)
516
+ $channels++;
517
+ }
518
+ }
519
+ for ($i = 0; $i < $program_configs['num_side_channel_elements']; $i++) {
520
+ $channels++;
521
+ if ($program_configs['side_element_is_cpe'][$i]) {
522
+ // each side element is channel pair (CPE = Channel Pair Element)
523
+ $channels++;
524
+ }
525
+ }
526
+ for ($i = 0; $i < $program_configs['num_back_channel_elements']; $i++) {
527
+ $channels++;
528
+ if ($program_configs['back_element_is_cpe'][$i]) {
529
+ // each back element is channel pair (CPE = Channel Pair Element)
530
+ $channels++;
531
+ }
532
+ }
533
+ for ($i = 0; $i < $program_configs['num_lfe_channel_elements']; $i++) {
534
+ $channels++;
535
+ }
536
+ return $channels;
537
+ }
538
+
539
+ }
540
+
541
+
542
+ ?>
view/getid3/module.audio.ac3.php ADDED
@@ -0,0 +1,497 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /////////////////////////////////////////////////////////////////
3
+ /// getID3() by James Heinrich <info@getid3.org> //
4
+ // available at http://getid3.sourceforge.net //
5
+ // or http://www.getid3.org //
6
+ /////////////////////////////////////////////////////////////////
7
+ // See readme.txt for more details //
8
+ /////////////////////////////////////////////////////////////////
9
+ // //
10
+ // module.audio.ac3.php //
11
+ // module for analyzing AC-3 (aka Dolby Digital) audio files //
12
+ // dependencies: NONE //
13
+ // ///
14
+ /////////////////////////////////////////////////////////////////
15
+
16
+
17
+ class getid3_ac3
18
+ {
19
+
20
+ function getid3_ac3(&$fd, &$ThisFileInfo) {
21
+
22
+ ///AH
23
+ $ThisFileInfo['ac3']['raw']['bsi'] = array();
24
+ $thisfile_ac3 = &$ThisFileInfo['ac3'];
25
+ $thisfile_ac3_raw = &$thisfile_ac3['raw'];
26
+ $thisfile_ac3_raw_bsi = &$thisfile_ac3_raw['bsi'];
27
+
28
+
29
+ // http://www.atsc.org/standards/a_52a.pdf
30
+
31
+ $ThisFileInfo['fileformat'] = 'ac3';
32
+ $ThisFileInfo['audio']['dataformat'] = 'ac3';
33
+ $ThisFileInfo['audio']['bitrate_mode'] = 'cbr';
34
+ $ThisFileInfo['audio']['lossless'] = false;
35
+
36
+ // An AC-3 serial coded audio bit stream is made up of a sequence of synchronization frames
37
+ // Each synchronization frame contains 6 coded audio blocks (AB), each of which represent 256
38
+ // new audio samples per channel. A synchronization information (SI) header at the beginning
39
+ // of each frame contains information needed to acquire and maintain synchronization. A
40
+ // bit stream information (BSI) header follows SI, and contains parameters describing the coded
41
+ // audio service. The coded audio blocks may be followed by an auxiliary data (Aux) field. At the
42
+ // end of each frame is an error check field that includes a CRC word for error detection. An
43
+ // additional CRC word is located in the SI header, the use of which, by a decoder, is optional.
44
+ //
45
+ // syncinfo() | bsi() | AB0 | AB1 | AB2 | AB3 | AB4 | AB5 | Aux | CRC
46
+
47
+ fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
48
+ $AC3header['syncinfo'] = fread($fd, 5);
49
+ $thisfile_ac3_raw['synchinfo']['synchword'] = substr($AC3header['syncinfo'], 0, 2);
50
+
51
+ if ($thisfile_ac3_raw['synchinfo']['synchword'] != "\x0B\x77") {
52
+
53
+ $ThisFileInfo['error'][] = 'Expecting "\x0B\x77" at offset '.$ThisFileInfo['avdataoffset'].', found \x'.strtoupper(dechex($AC3header['syncinfo']{0})).'\x'.strtoupper(dechex($AC3header['syncinfo']{1})).' instead';
54
+ unset($thisfile_ac3);
55
+ return false;
56
+
57
+ } else {
58
+
59
+ // syncinfo() {
60
+ // syncword 16
61
+ // crc1 16
62
+ // fscod 2
63
+ // frmsizecod 6
64
+ // } /* end of syncinfo */
65
+
66
+ $thisfile_ac3_raw['synchinfo']['crc1'] = getid3_lib::LittleEndian2Int(substr($AC3header['syncinfo'], 2, 2));
67
+ $ac3_synchinfo_fscod_frmsizecod = getid3_lib::LittleEndian2Int(substr($AC3header['syncinfo'], 4, 1));
68
+ $thisfile_ac3_raw['synchinfo']['fscod'] = ($ac3_synchinfo_fscod_frmsizecod & 0xC0) >> 6;
69
+ $thisfile_ac3_raw['synchinfo']['frmsizecod'] = ($ac3_synchinfo_fscod_frmsizecod & 0x3F);
70
+
71
+ $thisfile_ac3['sample_rate'] = $this->AC3sampleRateCodeLookup($thisfile_ac3_raw['synchinfo']['fscod']);
72
+ if ($thisfile_ac3_raw['synchinfo']['fscod'] <= 3) {
73
+ $ThisFileInfo['audio']['sample_rate'] = $thisfile_ac3['sample_rate'];
74
+ }
75
+
76
+ $thisfile_ac3['frame_length'] = $this->AC3frameSizeLookup($thisfile_ac3_raw['synchinfo']['frmsizecod'], $thisfile_ac3_raw['synchinfo']['fscod']);
77
+ $thisfile_ac3['bitrate'] = $this->AC3bitrateLookup($thisfile_ac3_raw['synchinfo']['frmsizecod']);
78
+ $ThisFileInfo['audio']['bitrate'] = $thisfile_ac3['bitrate'];
79
+
80
+ $AC3header['bsi'] = getid3_lib::BigEndian2Bin(fread($fd, 15));
81
+ $ac3_bsi_offset = 0;
82
+
83
+ $thisfile_ac3_raw_bsi['bsid'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 5));
84
+ $ac3_bsi_offset += 5;
85
+ if ($thisfile_ac3_raw_bsi['bsid'] > 8) {
86
+ // Decoders which can decode version 8 will thus be able to decode version numbers less than 8.
87
+ // If this standard is extended by the addition of additional elements or features, a value of bsid greater than 8 will be used.
88
+ // Decoders built to this version of the standard will not be able to decode versions with bsid greater than 8.
89
+ $ThisFileInfo['error'][] = 'Bit stream identification is version '.$thisfile_ac3_raw_bsi['bsid'].', but getID3() only understands up to version 8';
90
+ unset($thisfile_ac3);
91
+ return false;
92
+ }
93
+
94
+ $thisfile_ac3_raw_bsi['bsmod'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 3));
95
+ $ac3_bsi_offset += 3;
96
+ $thisfile_ac3_raw_bsi['acmod'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 3));
97
+ $ac3_bsi_offset += 3;
98
+
99
+ $thisfile_ac3['service_type'] = $this->AC3serviceTypeLookup($thisfile_ac3_raw_bsi['bsmod'], $thisfile_ac3_raw_bsi['acmod']);
100
+ $ac3_coding_mode = $this->AC3audioCodingModeLookup($thisfile_ac3_raw_bsi['acmod']);
101
+ foreach($ac3_coding_mode as $key => $value) {
102
+ $thisfile_ac3[$key] = $value;
103
+ }
104
+ switch ($thisfile_ac3_raw_bsi['acmod']) {
105
+ case 0:
106
+ case 1:
107
+ $ThisFileInfo['audio']['channelmode'] = 'mono';
108
+ break;
109
+ case 3:
110
+ case 4:
111
+ $ThisFileInfo['audio']['channelmode'] = 'stereo';
112
+ break;
113
+ default:
114
+ $ThisFileInfo['audio']['channelmode'] = 'surround';
115
+ break;
116
+ }
117
+ $ThisFileInfo['audio']['channels'] = $thisfile_ac3['num_channels'];
118
+
119
+ if ($thisfile_ac3_raw_bsi['acmod'] & 0x01) {
120
+ // If the lsb of acmod is a 1, center channel is in use and cmixlev follows in the bit stream.
121
+ $thisfile_ac3_raw_bsi['cmixlev'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 2));
122
+ $ac3_bsi_offset += 2;
123
+ $thisfile_ac3['center_mix_level'] = $this->AC3centerMixLevelLookup($thisfile_ac3_raw_bsi['cmixlev']);
124
+ }
125
+
126
+ if ($thisfile_ac3_raw_bsi['acmod'] & 0x04) {
127
+ // If the msb of acmod is a 1, surround channels are in use and surmixlev follows in the bit stream.
128
+ $thisfile_ac3_raw_bsi['surmixlev'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 2));
129
+ $ac3_bsi_offset += 2;
130
+ $thisfile_ac3['surround_mix_level'] = $this->AC3surroundMixLevelLookup($thisfile_ac3_raw_bsi['surmixlev']);
131
+ }
132
+
133
+ if ($thisfile_ac3_raw_bsi['acmod'] == 0x02) {
134
+ // When operating in the two channel mode, this 2-bit code indicates whether or not the program has been encoded in Dolby Surround.
135
+ $thisfile_ac3_raw_bsi['dsurmod'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 2));
136
+ $ac3_bsi_offset += 2;
137
+ $thisfile_ac3['dolby_surround_mode'] = $this->AC3dolbySurroundModeLookup($thisfile_ac3_raw_bsi['dsurmod']);
138
+ }
139
+
140
+ $thisfile_ac3_raw_bsi['lfeon'] = (bool) bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 1));
141
+ $ac3_bsi_offset += 1;
142
+ $thisfile_ac3['lfe_enabled'] = $thisfile_ac3_raw_bsi['lfeon'];
143
+ if ($thisfile_ac3_raw_bsi['lfeon']) {
144
+ //$ThisFileInfo['audio']['channels']++;
145
+ $ThisFileInfo['audio']['channels'] .= '.1';
146
+ }
147
+
148
+ $thisfile_ac3['channels_enabled'] = $this->AC3channelsEnabledLookup($thisfile_ac3_raw_bsi['acmod'], $thisfile_ac3_raw_bsi['lfeon']);
149
+
150
+ // This indicates how far the average dialogue level is below digital 100 percent. Valid values are 1�31.
151
+ // The value of 0 is reserved. The values of 1 to 31 are interpreted as -1 dB to -31 dB with respect to digital 100 percent.
152
+ $thisfile_ac3_raw_bsi['dialnorm'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 5));
153
+ $ac3_bsi_offset += 5;
154
+ $thisfile_ac3['dialogue_normalization'] = '-'.$thisfile_ac3_raw_bsi['dialnorm'].'dB';
155
+
156
+ $thisfile_ac3_raw_bsi['compre_flag'] = (bool) bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 1));
157
+ $ac3_bsi_offset += 1;
158
+ if ($thisfile_ac3_raw_bsi['compre_flag']) {
159
+ $thisfile_ac3_raw_bsi['compr'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 8));
160
+ $ac3_bsi_offset += 8;
161
+ $thisfile_ac3['heavy_compression'] = $this->AC3heavyCompression($thisfile_ac3_raw_bsi['compr']);
162
+ }
163
+
164
+ $thisfile_ac3_raw_bsi['langcode_flag'] = (bool) bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 1));
165
+ $ac3_bsi_offset += 1;
166
+ if ($thisfile_ac3_raw_bsi['langcode_flag']) {
167
+ $thisfile_ac3_raw_bsi['langcod'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 8));
168
+ $ac3_bsi_offset += 8;
169
+ }
170
+
171
+ $thisfile_ac3_raw_bsi['audprodie'] = (bool) bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 1));
172
+ $ac3_bsi_offset += 1;
173
+ if ($thisfile_ac3_raw_bsi['audprodie']) {
174
+ $thisfile_ac3_raw_bsi['mixlevel'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 5));
175
+ $ac3_bsi_offset += 5;
176
+ $thisfile_ac3_raw_bsi['roomtyp'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 2));
177
+ $ac3_bsi_offset += 2;
178
+
179
+ $thisfile_ac3['mixing_level'] = (80 + $thisfile_ac3_raw_bsi['mixlevel']).'dB';
180
+ $thisfile_ac3['room_type'] = $this->AC3roomTypeLookup($thisfile_ac3_raw_bsi['roomtyp']);
181
+ }
182
+
183
+ if ($thisfile_ac3_raw_bsi['acmod'] == 0x00) {
184
+ // If acmod is 0, then two completely independent program channels (dual mono)
185
+ // are encoded into the bit stream, and are referenced as Ch1, Ch2. In this case,
186
+ // a number of additional items are present in BSI or audblk to fully describe Ch2.
187
+
188
+
189
+ // This indicates how far the average dialogue level is below digital 100 percent. Valid values are 1�31.
190
+ // The value of 0 is reserved. The values of 1 to 31 are interpreted as -1 dB to -31 dB with respect to digital 100 percent.
191
+ $thisfile_ac3_raw_bsi['dialnorm2'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 5));
192
+ $ac3_bsi_offset += 5;
193
+ $thisfile_ac3['dialogue_normalization2'] = '-'.$thisfile_ac3_raw_bsi['dialnorm2'].'dB';
194
+
195
+ $thisfile_ac3_raw_bsi['compre_flag2'] = (bool) bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 1));
196
+ $ac3_bsi_offset += 1;
197
+ if ($thisfile_ac3_raw_bsi['compre_flag2']) {
198
+ $thisfile_ac3_raw_bsi['compr2'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 8));
199
+ $ac3_bsi_offset += 8;
200
+ $thisfile_ac3['heavy_compression2'] = $this->AC3heavyCompression($thisfile_ac3_raw_bsi['compr2']);
201
+ }
202
+
203
+ $thisfile_ac3_raw_bsi['langcode_flag2'] = (bool) bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 1));
204
+ $ac3_bsi_offset += 1;
205
+ if ($thisfile_ac3_raw_bsi['langcode_flag2']) {
206
+ $thisfile_ac3_raw_bsi['langcod2'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 8));
207
+ $ac3_bsi_offset += 8;
208
+ }
209
+
210
+ $thisfile_ac3_raw_bsi['audprodie2'] = (bool) bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 1));
211
+ $ac3_bsi_offset += 1;
212
+ if ($thisfile_ac3_raw_bsi['audprodie2']) {
213
+ $thisfile_ac3_raw_bsi['mixlevel2'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 5));
214
+ $ac3_bsi_offset += 5;
215
+ $thisfile_ac3_raw_bsi['roomtyp2'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 2));
216
+ $ac3_bsi_offset += 2;
217
+
218
+ $thisfile_ac3['mixing_level2'] = (80 + $thisfile_ac3_raw_bsi['mixlevel2']).'dB';
219
+ $thisfile_ac3['room_type2'] = $this->AC3roomTypeLookup($thisfile_ac3_raw_bsi['roomtyp2']);
220
+ }
221
+
222
+ }
223
+
224
+ $thisfile_ac3_raw_bsi['copyright'] = (bool) bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 1));
225
+ $ac3_bsi_offset += 1;
226
+
227
+ $thisfile_ac3_raw_bsi['original'] = (bool) bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 1));
228
+ $ac3_bsi_offset += 1;
229
+
230
+ $thisfile_ac3_raw_bsi['timecode1_flag'] = (bool) bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 1));
231
+ $ac3_bsi_offset += 1;
232
+ if ($thisfile_ac3_raw_bsi['timecode1_flag']) {
233
+ $thisfile_ac3_raw_bsi['timecode1'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 14));
234
+ $ac3_bsi_offset += 14;
235
+ }
236
+
237
+ $thisfile_ac3_raw_bsi['timecode2_flag'] = (bool) bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 1));
238
+ $ac3_bsi_offset += 1;
239
+ if ($thisfile_ac3_raw_bsi['timecode2_flag']) {
240
+ $thisfile_ac3_raw_bsi['timecode2'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 14));
241
+ $ac3_bsi_offset += 14;
242
+ }
243
+
244
+ $thisfile_ac3_raw_bsi['addbsi_flag'] = (bool) bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 1));
245
+ $ac3_bsi_offset += 1;
246
+ if ($thisfile_ac3_raw_bsi['addbsi_flag']) {
247
+ $thisfile_ac3_raw_bsi['addbsi_length'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 6));
248
+ $ac3_bsi_offset += 6;
249
+
250
+ $AC3header['bsi'] .= getid3_lib::BigEndian2Bin(fread($fd, $thisfile_ac3_raw_bsi['addbsi_length']));
251
+
252
+ $thisfile_ac3_raw_bsi['addbsi_data'] = substr($AC3header['bsi'], $ac3_bsi_offset, $thisfile_ac3_raw_bsi['addbsi_length'] * 8);
253
+ $ac3_bsi_offset += $thisfile_ac3_raw_bsi['addbsi_length'] * 8;
254
+ }
255
+
256
+ }
257
+
258
+ return true;
259
+ }
260
+
261
+
262
+ function AC3sampleRateCodeLookup($fscod) {
263
+ static $AC3sampleRateCodeLookup = array(
264
+ 0 => 48000,
265
+ 1 => 44100,
266
+ 2 => 32000,
267
+ 3 => 'reserved' // If the reserved code is indicated, the decoder should not attempt to decode audio and should mute.
268
+ );
269
+ return (isset($AC3sampleRateCodeLookup[$fscod]) ? $AC3sampleRateCodeLookup[$fscod] : false);
270
+ }
271
+
272
+ function AC3serviceTypeLookup($bsmod, $acmod) {
273
+ static $AC3serviceTypeLookup = array();
274
+ if (empty($AC3serviceTypeLookup)) {
275
+ for ($i = 0; $i <= 7; $i++) {
276
+ $AC3serviceTypeLookup[0][$i] = 'main audio service: complete main (CM)';
277
+ $AC3serviceTypeLookup[1][$i] = 'main audio service: music and effects (ME)';
278
+ $AC3serviceTypeLookup[2][$i] = 'associated service: visually impaired (VI)';
279
+ $AC3serviceTypeLookup[3][$i] = 'associated service: hearing impaired (HI)';
280
+ $AC3serviceTypeLookup[4][$i] = 'associated service: dialogue (D)';
281
+ $AC3serviceTypeLookup[5][$i] = 'associated service: commentary (C)';
282
+ $AC3serviceTypeLookup[6][$i] = 'associated service: emergency (E)';
283
+ }
284
+
285
+ $AC3serviceTypeLookup[7][1] = 'associated service: voice over (VO)';
286
+ for ($i = 2; $i <= 7; $i++) {
287
+ $AC3serviceTypeLookup[7][$i] = 'main audio service: karaoke';
288
+ }
289
+ }
290
+ return (isset($AC3serviceTypeLookup[$bsmod][$acmod]) ? $AC3serviceTypeLookup[$bsmod][$acmod] : false);
291
+ }
292
+
293
+ function AC3audioCodingModeLookup($acmod) {
294
+ static $AC3audioCodingModeLookup = array();
295
+ if (empty($AC3audioCodingModeLookup)) {
296
+ // array(channel configuration, # channels (not incl LFE), channel order)
297
+ $AC3audioCodingModeLookup = array (
298
+ 0 => array('channel_config'=>'1+1', 'num_channels'=>2, 'channel_order'=>'Ch1,Ch2'),
299
+ 1 => array('channel_config'=>'1/0', 'num_channels'=>1, 'channel_order'=>'C'),
300
+ 2 => array('channel_config'=>'2/0', 'num_channels'=>2, 'channel_order'=>'L,R'),
301
+ 3 => array('channel_config'=>'3/0', 'num_channels'=>3, 'channel_order'=>'L,C,R'),
302
+ 4 => array('channel_config'=>'2/1', 'num_channels'=>3, 'channel_order'=>'L,R,S'),
303
+ 5 => array('channel_config'=>'3/1', 'num_channels'=>4, 'channel_order'=>'L,C,R,S'),
304
+ 6 => array('channel_config'=>'2/2', 'num_channels'=>4, 'channel_order'=>'L,R,SL,SR'),
305
+ 7 => array('channel_config'=>'3/2', 'num_channels'=>5, 'channel_order'=>'L,C,R,SL,SR')
306
+ );
307
+ }
308
+ return (isset($AC3audioCodingModeLookup[$acmod]) ? $AC3audioCodingModeLookup[$acmod] : false);
309
+ }
310
+
311
+ function AC3centerMixLevelLookup($cmixlev) {
312
+ static $AC3centerMixLevelLookup;
313
+ if (empty($AC3centerMixLevelLookup)) {
314
+ $AC3centerMixLevelLookup = array(
315
+ 0 => pow(2, -3.0 / 6), // 0.707 (�3.0 dB)
316
+ 1 => pow(2, -4.5 / 6), // 0.595 (�4.5 dB)
317
+ 2 => pow(2, -6.0 / 6), // 0.500 (�6.0 dB)
318
+ 3 => 'reserved'
319
+ );
320
+ }
321
+ return (isset($AC3centerMixLevelLookup[$cmixlev]) ? $AC3centerMixLevelLookup[$cmixlev] : false);
322
+ }
323
+
324
+ function AC3surroundMixLevelLookup($surmixlev) {
325
+ static $AC3surroundMixLevelLookup;
326
+ if (empty($AC3surroundMixLevelLookup)) {
327
+ $AC3surroundMixLevelLookup = array(
328
+ 0 => pow(2, -3.0 / 6),
329
+ 1 => pow(2, -6.0 / 6),
330
+ 2 => 0,
331
+ 3 => 'reserved'
332
+ );
333
+ }
334
+ return (isset($AC3surroundMixLevelLookup[$surmixlev]) ? $AC3surroundMixLevelLookup[$surmixlev] : false);
335
+ }
336
+
337
+ function AC3dolbySurroundModeLookup($dsurmod) {
338
+ static $AC3dolbySurroundModeLookup = array(
339
+ 0 => 'not indicated',
340
+ 1 => 'Not Dolby Surround encoded',
341
+ 2 => 'Dolby Surround encoded',
342
+ 3 => 'reserved'
343
+ );
344
+ return (isset($AC3dolbySurroundModeLookup[$dsurmod]) ? $AC3dolbySurroundModeLookup[$dsurmod] : false);
345
+ }
346
+
347
+ function AC3channelsEnabledLookup($acmod, $lfeon) {
348
+ $AC3channelsEnabledLookup = array(
349
+ 'ch1'=>(bool) ($acmod == 0),
350
+ 'ch2'=>(bool) ($acmod == 0),
351
+ 'left'=>(bool) ($acmod > 1),
352
+ 'right'=>(bool) ($acmod > 1),
353
+ 'center'=>(bool) ($acmod & 0x01),
354
+ 'surround_mono'=>false,
355
+ 'surround_left'=>false,
356
+ 'surround_right'=>false,
357
+ 'lfe'=>$lfeon);
358
+ switch ($acmod) {
359
+ case 4:
360
+ case 5:
361
+ $AC3channelsEnabledLookup['surround_mono'] = true;
362
+ break;
363
+ case 6:
364
+ case 7:
365
+ $AC3channelsEnabledLookup['surround_left'] = true;
366
+ $AC3channelsEnabledLookup['surround_right'] = true;
367
+ break;
368
+ }
369
+ return $AC3channelsEnabledLookup;
370
+ }
371
+
372
+ function AC3heavyCompression($compre) {
373
+ // The first four bits indicate gain changes in 6.02dB increments which can be
374
+ // implemented with an arithmetic shift operation. The following four bits
375
+ // indicate linear gain changes, and require a 5-bit multiply.
376
+ // We will represent the two 4-bit fields of compr as follows:
377
+ // X0 X1 X2 X3 . Y4 Y5 Y6 Y7
378
+ // The meaning of the X values is most simply described by considering X to represent a 4-bit
379
+ // signed integer with values from �8 to +7. The gain indicated by X is then (X + 1) * 6.02 dB. The
380
+ // following table shows this in detail.
381
+
382
+ // Meaning of 4 msb of compr
383
+ // 7 +48.16 dB
384
+ // 6 +42.14 dB
385
+ // 5 +36.12 dB
386
+ // 4 +30.10 dB
387
+ // 3 +24.08 dB
388
+ // 2 +18.06 dB
389
+ // 1 +12.04 dB
390
+ // 0 +6.02 dB
391
+ // -1 0 dB
392
+ // -2 �6.02 dB
393
+ // -3 �12.04 dB
394
+ // -4 �18.06 dB
395
+ // -5 �24.08 dB
396
+ // -6 �30.10 dB
397
+ // -7 �36.12 dB
398
+ // -8 �42.14 dB
399
+
400
+ $fourbit = str_pad(decbin(($compre & 0xF0) >> 4), 4, '0', STR_PAD_LEFT);
401
+ if ($fourbit{0} == '1') {
402
+ $log_gain = -8 + bindec(substr($fourbit, 1));
403
+ } else {
404
+ $log_gain = bindec(substr($fourbit, 1));
405
+ }
406
+ $log_gain = ($log_gain + 1) * getid3_lib::RGADamplitude2dB(2);
407
+
408
+ // The value of Y is a linear representation of a gain change of up to �6 dB. Y is considered to
409
+ // be an unsigned fractional integer, with a leading value of 1, or: 0.1 Y4 Y5 Y6 Y7 (base 2). Y can
410
+ // represent values between 0.111112 (or 31/32) and 0.100002 (or 1/2). Thus, Y can represent gain
411
+ // changes from �0.28 dB to �6.02 dB.
412
+
413
+ $lin_gain = (16 + ($compre & 0x0F)) / 32;
414
+
415
+ // The combination of X and Y values allows compr to indicate gain changes from
416
+ // 48.16 � 0.28 = +47.89 dB, to
417
+ // �42.14 � 6.02 = �48.16 dB.
418
+
419
+ return $log_gain - $lin_gain;
420
+ }
421
+
422
+ function AC3roomTypeLookup($roomtyp) {
423
+ static $AC3roomTypeLookup = array(
424
+ 0 => 'not indicated',
425
+ 1 => 'large room, X curve monitor',
426
+ 2 => 'small room, flat monitor',
427
+ 3 => 'reserved'
428
+ );
429
+ return (isset($AC3roomTypeLookup[$roomtyp]) ? $AC3roomTypeLookup[$roomtyp] : false);
430
+ }
431
+
432
+ function AC3frameSizeLookup($frmsizecod, $fscod) {
433
+ $padding = (bool) ($frmsizecod % 2);
434
+ $framesizeid = floor($frmsizecod / 2);
435
+
436
+ static $AC3frameSizeLookup = array();
437
+ if (empty($AC3frameSizeLookup)) {
438
+ $AC3frameSizeLookup = array (
439
+ 0 => array(128, 138, 192),
440
+ 1 => array(40, 160, 174, 240),
441
+ 2 => array(48, 192, 208, 288),
442
+ 3 => array(56, 224, 242, 336),
443
+ 4 => array(64, 256, 278, 384),
444
+ 5 => array(80, 320, 348, 480),
445
+ 6 => array(96, 384, 416, 576),
446
+ 7 => array(112, 448, 486, 672),
447
+ 8 => array(128, 512, 556, 768),
448
+ 9 => array(160, 640, 696, 960),
449
+ 10 => array(192, 768, 834, 1152),
450
+ 11 => array(224, 896, 974, 1344),
451
+ 12 => array(256, 1024, 1114, 1536),
452
+ 13 => array(320, 1280, 1392, 1920),
453
+ 14 => array(384, 1536, 1670, 2304),
454
+ 15 => array(448, 1792, 1950, 2688),
455
+ 16 => array(512, 2048, 2228, 3072),
456
+ 17 => array(576, 2304, 2506, 3456),
457
+ 18 => array(640, 2560, 2786, 3840)
458
+ );
459
+ }
460
+ if (($fscod == 1) && $padding) {
461
+ // frame lengths are padded by 1 word (16 bits) at 44100
462
+ $AC3frameSizeLookup[$frmsizecod] += 2;
463
+ }
464
+ return (isset($AC3frameSizeLookup[$framesizeid][$fscod]) ? $AC3frameSizeLookup[$framesizeid][$fscod] : false);
465
+ }
466
+
467
+ function AC3bitrateLookup($frmsizecod) {
468
+ $framesizeid = floor($frmsizecod / 2);
469
+
470
+ static $AC3bitrateLookup = array(
471
+ 0 => 32000,
472
+ 1 => 40000,
473
+ 2 => 48000,
474
+ 3 => 56000,
475
+ 4 => 64000,
476
+ 5 => 80000,
477
+ 6 => 96000,
478
+ 7 => 112000,
479
+ 8 => 128000,
480
+ 9 => 160000,
481
+ 10 => 192000,
482
+ 11 => 224000,
483
+ 12 => 256000,
484
+ 13 => 320000,
485
+ 14 => 384000,
486
+ 15 => 448000,
487
+ 16 => 512000,
488
+ 17 => 576000,
489
+ 18 => 640000
490
+ );
491
+ return (isset($AC3bitrateLookup[$framesizeid]) ? $AC3bitrateLookup[$framesizeid] : false);
492
+ }
493
+
494
+
495
+ }
496
+
497
+ ?>
view/getid3/module.audio.au.php ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /////////////////////////////////////////////////////////////////
3
+ /// getID3() by James Heinrich <info@getid3.org> //
4
+ // available at http://getid3.sourceforge.net //
5
+ // or http://www.getid3.org //
6
+ /////////////////////////////////////////////////////////////////
7
+ // See readme.txt for more details //
8
+ /////////////////////////////////////////////////////////////////
9
+ // //
10
+ // module.audio.au.php //
11
+ // module for analyzing AU files //
12
+ // dependencies: NONE //
13
+ // ///
14
+ /////////////////////////////////////////////////////////////////
15
+
16
+
17
+ class getid3_au
18
+ {
19
+
20
+ function getid3_au(&$fd, &$ThisFileInfo) {
21
+
22
+ fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
23
+ $AUheader = fread($fd, 8);
24
+
25
+ if (substr($AUheader, 0, 4) != '.snd') {
26
+ $ThisFileInfo['error'][] = 'Expecting ".snd" at offset '.$ThisFileInfo['avdataoffset'].', found "'.substr($AUheader, 0, 4).'"';
27
+ return false;
28
+ }
29
+
30
+ // shortcut
31
+ $ThisFileInfo['au'] = array();
32
+ $thisfile_au = &$ThisFileInfo['au'];
33
+
34
+ $ThisFileInfo['fileformat'] = 'au';
35
+ $ThisFileInfo['audio']['dataformat'] = 'au';
36
+ $ThisFileInfo['audio']['bitrate_mode'] = 'cbr';
37
+ $thisfile_au['encoding'] = 'ISO-8859-1';
38
+
39
+ $thisfile_au['header_length'] = getid3_lib::BigEndian2Int(substr($AUheader, 4, 4));
40
+ $AUheader .= fread($fd, $thisfile_au['header_length'] - 8);
41
+ $ThisFileInfo['avdataoffset'] += $thisfile_au['header_length'];
42
+
43
+ $thisfile_au['data_size'] = getid3_lib::BigEndian2Int(substr($AUheader, 8, 4));
44
+ $thisfile_au['data_format_id'] = getid3_lib::BigEndian2Int(substr($AUheader, 12, 4));
45
+ $thisfile_au['sample_rate'] = getid3_lib::BigEndian2Int(substr($AUheader, 16, 4));
46
+ $thisfile_au['channels'] = getid3_lib::BigEndian2Int(substr($AUheader, 20, 4));
47
+ $thisfile_au['comments']['comment'][] = trim(substr($AUheader, 24));
48
+
49
+ $thisfile_au['data_format'] = $this->AUdataFormatNameLookup($thisfile_au['data_format_id']);
50
+ $thisfile_au['used_bits_per_sample'] = $this->AUdataFormatUsedBitsPerSampleLookup($thisfile_au['data_format_id']);
51
+ if ($thisfile_au['bits_per_sample'] = $this->AUdataFormatBitsPerSampleLookup($thisfile_au['data_format_id'])) {
52
+ $ThisFileInfo['audio']['bits_per_sample'] = $thisfile_au['bits_per_sample'];
53
+ } else {
54
+ unset($thisfile_au['bits_per_sample']);
55
+ }
56
+
57
+ $ThisFileInfo['audio']['sample_rate'] = $thisfile_au['sample_rate'];
58
+ $ThisFileInfo['audio']['channels'] = $thisfile_au['channels'];
59
+
60
+ if (($ThisFileInfo['avdataoffset'] + $thisfile_au['data_size']) > $ThisFileInfo['avdataend']) {
61
+ $ThisFileInfo['warning'][] = 'Possible truncated file - expecting "'.$thisfile_au['data_size'].'" bytes of audio data, only found '.($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']).' bytes"';
62
+ }
63
+
64
+ $ThisFileInfo['playtime_seconds'] = $thisfile_au['data_size'] / ($thisfile_au['sample_rate'] * $thisfile_au['channels'] * ($thisfile_au['used_bits_per_sample'] / 8));
65
+ $ThisFileInfo['audio']['bitrate'] = ($thisfile_au['data_size'] * 8) / $ThisFileInfo['playtime_seconds'];
66
+
67
+ return true;
68
+ }
69
+
70
+ function AUdataFormatNameLookup($id) {
71
+ static $AUdataFormatNameLookup = array(
72
+ 0 => 'unspecified format',
73
+ 1 => '8-bit mu-law',
74
+ 2 => '8-bit linear',
75
+ 3 => '16-bit linear',
76
+ 4 => '24-bit linear',
77
+ 5 => '32-bit linear',
78
+ 6 => 'floating-point',
79
+ 7 => 'double-precision float',
80
+ 8 => 'fragmented sampled data',
81
+ 9 => 'SUN_FORMAT_NESTED',
82
+ 10 => 'DSP program',
83
+ 11 => '8-bit fixed-point',
84
+ 12 => '16-bit fixed-point',
85
+ 13 => '24-bit fixed-point',
86
+ 14 => '32-bit fixed-point',
87
+
88
+ 16 => 'non-audio display data',
89
+ 17 => 'SND_FORMAT_MULAW_SQUELCH',
90
+ 18 => '16-bit linear with emphasis',
91
+ 19 => '16-bit linear with compression',
92
+ 20 => '16-bit linear with emphasis + compression',
93
+ 21 => 'Music Kit DSP commands',
94
+ 22 => 'SND_FORMAT_DSP_COMMANDS_SAMPLES',
95
+ 23 => 'CCITT g.721 4-bit ADPCM',
96
+ 24 => 'CCITT g.722 ADPCM',
97
+ 25 => 'CCITT g.723 3-bit ADPCM',
98
+ 26 => 'CCITT g.723 5-bit ADPCM',
99
+ 27 => 'A-Law 8-bit'
100
+ );
101
+ return (isset($AUdataFormatNameLookup[$id]) ? $AUdataFormatNameLookup[$id] : false);
102
+ }
103
+
104
+ function AUdataFormatBitsPerSampleLookup($id) {
105
+ static $AUdataFormatBitsPerSampleLookup = array(
106
+ 1 => 8,
107
+ 2 => 8,
108
+ 3 => 16,
109
+ 4 => 24,
110
+ 5 => 32,
111
+ 6 => 32,
112
+ 7 => 64,
113
+
114
+ 11 => 8,
115
+ 12 => 16,
116
+ 13 => 24,
117
+ 14 => 32,
118
+
119
+ 18 => 16,
120
+ 19 => 16,
121
+ 20 => 16,
122
+
123
+ 23 => 16,
124
+
125
+ 25 => 16,
126
+ 26 => 16,
127
+ 27 => 8
128
+ );
129
+ return (isset($AUdataFormatBitsPerSampleLookup[$id]) ? $AUdataFormatBitsPerSampleLookup[$id] : false);
130
+ }
131
+
132
+ function AUdataFormatUsedBitsPerSampleLookup($id) {
133
+ static $AUdataFormatUsedBitsPerSampleLookup = array(
134
+ 1 => 8,
135
+ 2 => 8,
136
+ 3 => 16,
137
+ 4 => 24,
138
+ 5 => 32,
139
+ 6 => 32,
140
+ 7 => 64,
141
+
142
+ 11 => 8,
143
+ 12 => 16,
144
+ 13 => 24,
145
+ 14 => 32,
146
+
147
+ 18 => 16,
148
+ 19 => 16,
149
+ 20 => 16,
150
+
151
+ 23 => 4,
152
+
153
+ 25 => 3,
154
+ 26 => 5,
155
+ 27 => 8,
156
+ );
157
+ return (isset($AUdataFormatUsedBitsPerSampleLookup[$id]) ? $AUdataFormatUsedBitsPerSampleLookup[$id] : false);
158
+ }
159
+
160
+ }
161
+
162
+
163
+ ?>
view/getid3/module.audio.avr.php ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /////////////////////////////////////////////////////////////////
3
+ /// getID3() by James Heinrich <info@getid3.org> //
4
+ // available at http://getid3.sourceforge.net //
5
+ // or http://www.getid3.org //
6
+ /////////////////////////////////////////////////////////////////
7
+ // See readme.txt for more details //
8
+ /////////////////////////////////////////////////////////////////
9
+ // //
10
+ // module.audio.avr.php //
11
+ // module for analyzing AVR Audio files //
12
+ // dependencies: NONE //
13
+ // ///
14
+ /////////////////////////////////////////////////////////////////
15
+
16
+
17
+ class getid3_avr
18
+ {
19
+
20
+ function getid3_avr(&$fd, &$ThisFileInfo) {
21
+
22
+ // http://cui.unige.ch/OSG/info/AudioFormats/ap11.html
23
+ // http://www.btinternet.com/~AnthonyJ/Atari/programming/avr_format.html
24
+ // offset type length name comments
25
+ // ---------------------------------------------------------------------
26
+ // 0 char 4 ID format ID == "2BIT"
27
+ // 4 char 8 name sample name (unused space filled with 0)
28
+ // 12 short 1 mono/stereo 0=mono, -1 (0xFFFF)=stereo
29
+ // With stereo, samples are alternated,
30
+ // the first voice is the left :
31
+ // (LRLRLRLRLRLRLRLRLR...)
32
+ // 14 short 1 resolution 8, 12 or 16 (bits)
33
+ // 16 short 1 signed or not 0=unsigned, -1 (0xFFFF)=signed
34
+ // 18 short 1 loop or not 0=no loop, -1 (0xFFFF)=loop on
35
+ // 20 short 1 MIDI note 0xFFnn, where 0 <= nn <= 127
36
+ // 0xFFFF means "no MIDI note defined"
37
+ // 22 byte 1 Replay speed Frequence in the Replay software
38
+ // 0=5.485 Khz, 1=8.084 Khz, 2=10.971 Khz,
39
+ // 3=16.168 Khz, 4=21.942 Khz, 5=32.336 Khz
40
+ // 6=43.885 Khz, 7=47.261 Khz
41
+ // -1 (0xFF)=no defined Frequence
42
+ // 23 byte 3 sample rate in Hertz
43
+ // 26 long 1 size in bytes (2 * bytes in stereo)
44
+ // 30 long 1 loop begin 0 for no loop
45
+ // 34 long 1 loop size equal to 'size' for no loop
46
+ // 38 short 2 Reserved, MIDI keyboard split */
47
+ // 40 short 2 Reserved, sample compression */
48
+ // 42 short 2 Reserved */
49
+ // 44 char 20; Additional filename space, used if (name[7] != 0)
50
+ // 64 byte 64 user data
51
+ // 128 bytes ? sample data (12 bits samples are coded on 16 bits:
52
+ // 0000 xxxx xxxx xxxx)
53
+ // ---------------------------------------------------------------------
54
+
55
+ // Note that all values are in motorola (big-endian) format, and that long is
56
+ // assumed to be 4 bytes, and short 2 bytes.
57
+ // When reading the samples, you should handle both signed and unsigned data,
58
+ // and be prepared to convert 16->8 bit, or mono->stereo if needed. To convert
59
+ // 8-bit data between signed/unsigned just add 127 to the sample values.
60
+ // Simularly for 16-bit data you should add 32769
61
+
62
+ $ThisFileInfo['fileformat'] = 'avr';
63
+
64
+ fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
65
+ $AVRheader = fread($fd, 128);
66
+
67
+ $ThisFileInfo['avr']['raw']['magic'] = substr($AVRheader, 0, 4);
68
+ if ($ThisFileInfo['avr']['raw']['magic'] != '2BIT') {
69
+ $ThisFileInfo['error'][] = 'Expecting "2BIT" at offset '.$ThisFileInfo['avdataoffset'].', found "'.$ThisFileInfo['avr']['raw']['magic'].'"';
70
+ unset($ThisFileInfo['fileformat']);
71
+ unset($ThisFileInfo['avr']);
72
+ return false;
73
+ }
74
+ $ThisFileInfo['avdataoffset'] += 128;
75
+
76
+ $ThisFileInfo['avr']['sample_name'] = rtrim(substr($AVRheader, 4, 8));
77
+ $ThisFileInfo['avr']['raw']['mono'] = getid3_lib::BigEndian2Int(substr($AVRheader, 12, 2));
78
+ $ThisFileInfo['avr']['bits_per_sample'] = getid3_lib::BigEndian2Int(substr($AVRheader, 14, 2));
79
+ $ThisFileInfo['avr']['raw']['signed'] = getid3_lib::BigEndian2Int(substr($AVRheader, 16, 2));
80
+ $ThisFileInfo['avr']['raw']['loop'] = getid3_lib::BigEndian2Int(substr($AVRheader, 18, 2));
81
+ $ThisFileInfo['avr']['raw']['midi'] = getid3_lib::BigEndian2Int(substr($AVRheader, 20, 2));
82
+ $ThisFileInfo['avr']['raw']['replay_freq'] = getid3_lib::BigEndian2Int(substr($AVRheader, 22, 1));
83
+ $ThisFileInfo['avr']['sample_rate'] = getid3_lib::BigEndian2Int(substr($AVRheader, 23, 3));
84
+ $ThisFileInfo['avr']['sample_length'] = getid3_lib::BigEndian2Int(substr($AVRheader, 26, 4));
85
+ $ThisFileInfo['avr']['loop_start'] = getid3_lib::BigEndian2Int(substr($AVRheader, 30, 4));
86
+ $ThisFileInfo['avr']['loop_end'] = getid3_lib::BigEndian2Int(substr($AVRheader, 34, 4));
87
+ $ThisFileInfo['avr']['midi_split'] = getid3_lib::BigEndian2Int(substr($AVRheader, 38, 2));
88
+ $ThisFileInfo['avr']['sample_compression'] = getid3_lib::BigEndian2Int(substr($AVRheader, 40, 2));
89
+ $ThisFileInfo['avr']['reserved'] = getid3_lib::BigEndian2Int(substr($AVRheader, 42, 2));
90
+ $ThisFileInfo['avr']['sample_name_extra'] = rtrim(substr($AVRheader, 44, 20));
91
+ $ThisFileInfo['avr']['comment'] = rtrim(substr($AVRheader, 64, 64));
92
+
93
+ $ThisFileInfo['avr']['flags']['stereo'] = (($ThisFileInfo['avr']['raw']['mono'] == 0) ? false : true);
94
+ $ThisFileInfo['avr']['flags']['signed'] = (($ThisFileInfo['avr']['raw']['signed'] == 0) ? false : true);
95
+ $ThisFileInfo['avr']['flags']['loop'] = (($ThisFileInfo['avr']['raw']['loop'] == 0) ? false : true);
96
+
97
+ $ThisFileInfo['avr']['midi_notes'] = array();
98
+ if (($ThisFileInfo['avr']['raw']['midi'] & 0xFF00) != 0xFF00) {
99
+ $ThisFileInfo['avr']['midi_notes'][] = ($ThisFileInfo['avr']['raw']['midi'] & 0xFF00) >> 8;
100
+ }
101
+ if (($ThisFileInfo['avr']['raw']['midi'] & 0x00FF) != 0x00FF) {
102
+ $ThisFileInfo['avr']['midi_notes'][] = ($ThisFileInfo['avr']['raw']['midi'] & 0x00FF);
103
+ }
104
+
105
+ if (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) != ($ThisFileInfo['avr']['sample_length'] * (($ThisFileInfo['avr']['bits_per_sample'] == 8) ? 1 : 2))) {
106
+ $ThisFileInfo['warning'][] = 'Probable truncated file: expecting '.($ThisFileInfo['avr']['sample_length'] * (($ThisFileInfo['avr']['bits_per_sample'] == 8) ? 1 : 2)).' bytes of audio data, found '.($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']);
107
+ }
108
+
109
+ $ThisFileInfo['audio']['dataformat'] = 'avr';
110
+ $ThisFileInfo['audio']['lossless'] = true;
111
+ $ThisFileInfo['audio']['bitrate_mode'] = 'cbr';
112
+ $ThisFileInfo['audio']['bits_per_sample'] = $ThisFileInfo['avr']['bits_per_sample'];
113
+ $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['avr']['sample_rate'];
114
+ $ThisFileInfo['audio']['channels'] = ($ThisFileInfo['avr']['flags']['stereo'] ? 2 : 1);
115
+ $ThisFileInfo['playtime_seconds'] = ($ThisFileInfo['avr']['sample_length'] / $ThisFileInfo['audio']['channels']) / $ThisFileInfo['avr']['sample_rate'];
116
+ $ThisFileInfo['audio']['bitrate'] = ($ThisFileInfo['avr']['sample_length'] * (($ThisFileInfo['avr']['bits_per_sample'] == 8) ? 8 : 16)) / $ThisFileInfo['playtime_seconds'];
117
+
118
+
119
+ return true;
120
+ }
121
+
122
+ }
123
+
124
+
125
+ ?>
view/getid3/module.audio.bonk.php ADDED
@@ -0,0 +1,221 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /////////////////////////////////////////////////////////////////
3
+ /// getID3() by James Heinrich <info@getid3.org> //
4
+ // available at http://getid3.sourceforge.net //
5
+ // or http://www.getid3.org //
6
+ /////////////////////////////////////////////////////////////////
7
+ // See readme.txt for more details //
8
+ /////////////////////////////////////////////////////////////////
9
+ // //
10
+ // module.audio.la.php //
11
+ // module for analyzing BONK audio files //
12
+ // dependencies: module.tag.id3v2.php (optional) //
13
+ // ///
14
+ /////////////////////////////////////////////////////////////////
15
+
16
+
17
+ class getid3_bonk
18
+ {
19
+ function getid3_bonk(&$fd, &$ThisFileInfo) {
20
+
21
+ // shortcut
22
+ $ThisFileInfo['bonk'] = array();
23
+ $thisfile_bonk = &$ThisFileInfo['bonk'];
24
+
25
+ $thisfile_bonk['dataoffset'] = $ThisFileInfo['avdataoffset'];
26
+ $thisfile_bonk['dataend'] = $ThisFileInfo['avdataend'];
27
+
28
+ if ($thisfile_bonk['dataend'] >= pow(2, 31)) {
29
+
30
+ $ThisFileInfo['warning'][] = 'Unable to parse BONK file from end (v0.6+ preferred method) because PHP filesystem functions only support up to 2GB';
31
+
32
+ } else {
33
+
34
+ // scan-from-end method, for v0.6 and higher
35
+ fseek($fd, $thisfile_bonk['dataend'] - 8, SEEK_SET);
36
+ $PossibleBonkTag = fread($fd, 8);
37
+ while ($this->BonkIsValidTagName(substr($PossibleBonkTag, 4, 4), true)) {
38
+ $BonkTagSize = getid3_lib::LittleEndian2Int(substr($PossibleBonkTag, 0, 4));
39
+ fseek($fd, 0 - $BonkTagSize, SEEK_CUR);
40
+ $BonkTagOffset = ftell($fd);
41
+ $TagHeaderTest = fread($fd, 5);
42
+ if (($TagHeaderTest{0} != "\x00") || (substr($PossibleBonkTag, 4, 4) != strtolower(substr($PossibleBonkTag, 4, 4)))) {
43
+ $ThisFileInfo['error'][] = 'Expecting "�'.strtoupper(substr($PossibleBonkTag, 4, 4)).'" at offset '.$BonkTagOffset.', found "'.$TagHeaderTest.'"';
44
+ return false;
45
+ }
46
+ $BonkTagName = substr($TagHeaderTest, 1, 4);
47
+
48
+ $thisfile_bonk[$BonkTagName]['size'] = $BonkTagSize;
49
+ $thisfile_bonk[$BonkTagName]['offset'] = $BonkTagOffset;
50
+ $this->HandleBonkTags($fd, $BonkTagName, $ThisFileInfo);
51
+ $NextTagEndOffset = $BonkTagOffset - 8;
52
+ if ($NextTagEndOffset < $thisfile_bonk['dataoffset']) {
53
+ if (empty($ThisFileInfo['audio']['encoder'])) {
54
+ $ThisFileInfo['audio']['encoder'] = 'Extended BONK v0.9+';
55
+ }
56
+ return true;
57
+ }
58
+ fseek($fd, $NextTagEndOffset, SEEK_SET);
59
+ $PossibleBonkTag = fread($fd, 8);
60
+ }
61
+
62
+ }
63
+
64
+ // seek-from-beginning method for v0.4 and v0.5
65
+ if (empty($thisfile_bonk['BONK'])) {
66
+ fseek($fd, $thisfile_bonk['dataoffset'], SEEK_SET);
67
+ do {
68
+ $TagHeaderTest = fread($fd, 5);
69
+ switch ($TagHeaderTest) {
70
+ case "\x00".'BONK':
71
+ if (empty($ThisFileInfo['audio']['encoder'])) {
72
+ $ThisFileInfo['audio']['encoder'] = 'BONK v0.4';
73
+ }
74
+ break;
75
+
76
+ case "\x00".'INFO':
77
+ $ThisFileInfo['audio']['encoder'] = 'Extended BONK v0.5';
78
+ break;
79
+
80
+ default:
81
+ break 2;
82
+ }
83
+ $BonkTagName = substr($TagHeaderTest, 1, 4);
84
+ $thisfile_bonk[$BonkTagName]['size'] = $thisfile_bonk['dataend'] - $thisfile_bonk['dataoffset'];
85
+ $thisfile_bonk[$BonkTagName]['offset'] = $thisfile_bonk['dataoffset'];
86
+ $this->HandleBonkTags($fd, $BonkTagName, $ThisFileInfo);
87
+
88
+ } while (true);
89
+ }
90
+
91
+ // parse META block for v0.6 - v0.8
92
+ if (empty($thisfile_bonk['INFO']) && isset($thisfile_bonk['META']['tags']['info'])) {
93
+ fseek($fd, $thisfile_bonk['META']['tags']['info'], SEEK_SET);
94
+ $TagHeaderTest = fread($fd, 5);
95
+ if ($TagHeaderTest == "\x00".'INFO') {
96
+ $ThisFileInfo['audio']['encoder'] = 'Extended BONK v0.6 - v0.8';
97
+
98
+ $BonkTagName = substr($TagHeaderTest, 1, 4);
99
+ $thisfile_bonk[$BonkTagName]['size'] = $thisfile_bonk['dataend'] - $thisfile_bonk['dataoffset'];
100
+ $thisfile_bonk[$BonkTagName]['offset'] = $thisfile_bonk['dataoffset'];
101
+ $this->HandleBonkTags($fd, $BonkTagName, $ThisFileInfo);
102
+ }
103
+ }
104
+
105
+ if (empty($ThisFileInfo['audio']['encoder'])) {
106
+ $ThisFileInfo['audio']['encoder'] = 'Extended BONK v0.9+';
107
+ }
108
+ if (empty($thisfile_bonk['BONK'])) {
109
+ unset($ThisFileInfo['bonk']);
110
+ }
111
+ return true;
112
+
113
+ }
114
+
115
+ function HandleBonkTags(&$fd, &$BonkTagName, &$ThisFileInfo) {
116
+
117
+ switch ($BonkTagName) {
118
+ case 'BONK':
119
+ // shortcut
120
+ $thisfile_bonk_BONK = &$ThisFileInfo['bonk']['BONK'];
121
+
122
+ $BonkData = "\x00".'BONK'.fread($fd, 17);
123
+ $thisfile_bonk_BONK['version'] = getid3_lib::LittleEndian2Int(substr($BonkData, 5, 1));
124
+ $thisfile_bonk_BONK['number_samples'] = getid3_lib::LittleEndian2Int(substr($BonkData, 6, 4));
125
+ $thisfile_bonk_BONK['sample_rate'] = getid3_lib::LittleEndian2Int(substr($BonkData, 10, 4));
126
+
127
+ $thisfile_bonk_BONK['channels'] = getid3_lib::LittleEndian2Int(substr($BonkData, 14, 1));
128
+ $thisfile_bonk_BONK['lossless'] = (bool) getid3_lib::LittleEndian2Int(substr($BonkData, 15, 1));
129
+ $thisfile_bonk_BONK['joint_stereo'] = (bool) getid3_lib::LittleEndian2Int(substr($BonkData, 16, 1));
130
+ $thisfile_bonk_BONK['number_taps'] = getid3_lib::LittleEndian2Int(substr($BonkData, 17, 2));
131
+ $thisfile_bonk_BONK['downsampling_ratio'] = getid3_lib::LittleEndian2Int(substr($BonkData, 19, 1));
132
+ $thisfile_bonk_BONK['samples_per_packet'] = getid3_lib::LittleEndian2Int(substr($BonkData, 20, 2));
133
+
134
+ $ThisFileInfo['avdataoffset'] = $thisfile_bonk_BONK['offset'] + 5 + 17;
135
+ $ThisFileInfo['avdataend'] = $thisfile_bonk_BONK['offset'] + $thisfile_bonk_BONK['size'];
136
+
137
+ $ThisFileInfo['fileformat'] = 'bonk';
138
+ $ThisFileInfo['audio']['dataformat'] = 'bonk';
139
+ $ThisFileInfo['audio']['bitrate_mode'] = 'vbr'; // assumed
140
+ $ThisFileInfo['audio']['channels'] = $thisfile_bonk_BONK['channels'];
141
+ $ThisFileInfo['audio']['sample_rate'] = $thisfile_bonk_BONK['sample_rate'];
142
+ $ThisFileInfo['audio']['channelmode'] = ($thisfile_bonk_BONK['joint_stereo'] ? 'joint stereo' : 'stereo');
143
+ $ThisFileInfo['audio']['lossless'] = $thisfile_bonk_BONK['lossless'];
144
+ $ThisFileInfo['audio']['codec'] = 'bonk';
145
+
146
+ $ThisFileInfo['playtime_seconds'] = $thisfile_bonk_BONK['number_samples'] / ($thisfile_bonk_BONK['sample_rate'] * $thisfile_bonk_BONK['channels']);
147
+ if ($ThisFileInfo['playtime_seconds'] > 0) {
148
+ $ThisFileInfo['audio']['bitrate'] = (($ThisFileInfo['bonk']['dataend'] - $ThisFileInfo['bonk']['dataoffset']) * 8) / $ThisFileInfo['playtime_seconds'];
149
+ }
150
+ break;
151
+
152
+ case 'INFO':
153
+ // shortcut
154
+ $thisfile_bonk_INFO = &$ThisFileInfo['bonk']['INFO'];
155
+
156
+ $thisfile_bonk_INFO['version'] = getid3_lib::LittleEndian2Int(fread($fd, 1));
157
+ $thisfile_bonk_INFO['entries_count'] = 0;
158
+ $NextInfoDataPair = fread($fd, 5);
159
+ if (!$this->BonkIsValidTagName(substr($NextInfoDataPair, 1, 4))) {
160
+ while (!feof($fd)) {
161
+ //$CurrentSeekInfo['offset'] = getid3_lib::LittleEndian2Int(substr($NextInfoDataPair, 0, 4));
162
+ //$CurrentSeekInfo['nextbit'] = getid3_lib::LittleEndian2Int(substr($NextInfoDataPair, 4, 1));
163
+ //$thisfile_bonk_INFO[] = $CurrentSeekInfo;
164
+
165
+ $NextInfoDataPair = fread($fd, 5);
166
+ if ($this->BonkIsValidTagName(substr($NextInfoDataPair, 1, 4))) {
167
+ fseek($fd, -5, SEEK_CUR);
168
+ break;
169
+ }
170
+ $thisfile_bonk_INFO['entries_count']++;
171
+ }
172
+ }
173
+ break;
174
+
175
+ case 'META':
176
+ $BonkData = "\x00".'META'.fread($fd, $ThisFileInfo['bonk']['META']['size'] - 5);
177
+ $ThisFileInfo['bonk']['META']['version'] = getid3_lib::LittleEndian2Int(substr($BonkData, 5, 1));
178
+
179
+ $MetaTagEntries = floor(((strlen($BonkData) - 8) - 6) / 8); // BonkData - xxxxmeta - �META
180
+ $offset = 6;
181
+ for ($i = 0; $i < $MetaTagEntries; $i++) {
182
+ $MetaEntryTagName = substr($BonkData, $offset, 4);
183
+ $offset += 4;
184
+ $MetaEntryTagOffset = getid3_lib::LittleEndian2Int(substr($BonkData, $offset, 4));
185
+ $offset += 4;
186
+ $ThisFileInfo['bonk']['META']['tags'][$MetaEntryTagName] = $MetaEntryTagOffset;
187
+ }
188
+ break;
189
+
190
+ case ' ID3':
191
+ $ThisFileInfo['audio']['encoder'] = 'Extended BONK v0.9+';
192
+
193
+ // ID3v2 checking is optional
194
+ if (class_exists('getid3_id3v2')) {
195
+ $ThisFileInfo['bonk'][' ID3']['valid'] = new getid3_id3v2($fd, $ThisFileInfo, $ThisFileInfo['bonk'][' ID3']['offset'] + 2);
196
+ }
197
+ break;
198
+
199
+ default:
200
+ $ThisFileInfo['warning'][] = 'Unexpected Bonk tag "'.$BonkTagName.'" at offset '.$ThisFileInfo['bonk'][$BonkTagName]['offset'];
201
+ break;
202
+
203
+ }
204
+ }
205
+
206
+ function BonkIsValidTagName($PossibleBonkTag, $ignorecase=false) {
207
+ static $BonkIsValidTagName = array('BONK', 'INFO', ' ID3', 'META');
208
+ foreach ($BonkIsValidTagName as $validtagname) {
209
+ if ($validtagname == $PossibleBonkTag) {
210
+ return true;
211
+ } elseif ($ignorecase && (strtolower($validtagname) == strtolower($PossibleBonkTag))) {
212
+ return true;
213
+ }
214
+ }
215
+ return false;
216
+ }
217
+
218
+ }
219
+
220
+
221
+ ?>
view/getid3/module.audio.dss.php ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /////////////////////////////////////////////////////////////////
3
+ /// getID3() by James Heinrich <info@getid3.org> //
4
+ // available at http://getid3.sourceforge.net //
5
+ // or http://www.getid3.org //
6
+ /////////////////////////////////////////////////////////////////
7
+ // See readme.txt for more details //
8
+ /////////////////////////////////////////////////////////////////
9
+ // //
10
+ // module.audio.au.php //
11
+ // module for analyzing Digital Speech Standard (DSS) files //
12
+ // dependencies: NONE //
13
+ // ///
14
+ /////////////////////////////////////////////////////////////////
15
+
16
+
17
+ class getid3_dss
18
+ {
19
+
20
+ function getid3_dss(&$fd, &$ThisFileInfo) {
21
+
22
+ fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
23
+ $DSSheader = fread($fd, 1256);
24
+
25
+ if (substr($DSSheader, 0, 4) != "\x02".'dss') {
26
+ $ThisFileInfo['error'][] = 'Expecting "[x02]dss" at offset '.$ThisFileInfo['avdataoffset'].', found "'.substr($DSSheader, 0, 4).'"';
27
+ return false;
28
+ }
29
+
30
+ // some structure information taken from http://cpansearch.perl.org/src/RGIBSON/Audio-DSS-0.02/lib/Audio/DSS.pm
31
+
32
+ // shortcut
33
+ $ThisFileInfo['dss'] = array();
34
+ $thisfile_dss = &$ThisFileInfo['dss'];
35
+
36
+ $ThisFileInfo['fileformat'] = 'dss';
37
+ $ThisFileInfo['audio']['dataformat'] = 'dss';
38
+ $ThisFileInfo['audio']['bitrate_mode'] = 'cbr';
39
+ //$thisfile_dss['encoding'] = 'ISO-8859-1';
40
+
41
+ $thisfile_dss['date_create'] = $this->DSSdateStringToUnixDate(substr($DSSheader, 38, 12));
42
+ $thisfile_dss['date_complete'] = $this->DSSdateStringToUnixDate(substr($DSSheader, 50, 12));
43
+ $thisfile_dss['length'] = intval(substr($DSSheader, 62, 6));
44
+ $thisfile_dss['priority'] = ord(substr($DSSheader, 793, 1));
45
+ $thisfile_dss['comments'] = trim(substr($DSSheader, 798, 100));
46
+
47
+
48
+ //$ThisFileInfo['audio']['bits_per_sample'] = ?;
49
+ //$ThisFileInfo['audio']['sample_rate'] = ?;
50
+ $ThisFileInfo['audio']['channels'] = 1;
51
+
52
+ $ThisFileInfo['playtime_seconds'] = $thisfile_dss['length'];
53
+ $ThisFileInfo['audio']['bitrate'] = ($ThisFileInfo['filesize'] * 8) / $ThisFileInfo['playtime_seconds'];
54
+
55
+ return true;
56
+ }
57
+
58
+ function DSSdateStringToUnixDate($datestring) {
59
+ $y = substr($datestring, 0, 2);
60
+ $m = substr($datestring, 2, 2);
61
+ $d = substr($datestring, 4, 2);
62
+ $h = substr($datestring, 6, 2);
63
+ $i = substr($datestring, 8, 2);
64
+ $s = substr($datestring, 10, 2);
65
+ $y += (($y < 95) ? 2000 : 1900);
66
+ return mktime($h, $i, $s, $m, $d, $y);
67
+ }
68
+
69
+ }
70
+
71
+
72
+ ?>
view/getid3/module.audio.dts.php ADDED
@@ -0,0 +1,239 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /////////////////////////////////////////////////////////////////
3
+ /// getID3() by James Heinrich <info@getid3.org> //
4
+ // available at http://getid3.sourceforge.net //
5
+ // or http://www.getid3.org //
6
+ /////////////////////////////////////////////////////////////////
7
+ // See readme.txt for more details //
8
+ /////////////////////////////////////////////////////////////////
9
+ // //
10
+ // module.audio.dts.php //
11
+ // module for analyzing DTS Audio files //
12
+ // dependencies: NONE //
13
+ // //
14
+ /////////////////////////////////////////////////////////////////
15
+
16
+
17
+ class getid3_dts
18
+ {
19
+
20
+ function getid3_dts(&$fd, &$ThisFileInfo) {
21
+ // Specs taken from "DTS Coherent Acoustics;Core and Extensions, ETSI TS 102 114 V1.2.1 (2002-12)"
22
+ // (http://pda.etsi.org/pda/queryform.asp)
23
+ // With thanks to Gambit <macteam@users.sourceforge.net> http://mac.sourceforge.net/atl/
24
+
25
+ $ThisFileInfo['fileformat'] = 'dts';
26
+
27
+ fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
28
+ $DTSheader = fread($fd, 16);
29
+
30
+ $ThisFileInfo['dts']['raw']['magic'] = getid3_lib::BigEndian2Int(substr($DTSheader, 0, 4));
31
+ if ($ThisFileInfo['dts']['raw']['magic'] != 0x7FFE8001) {
32
+ $ThisFileInfo['error'][] = 'Expecting "0x7FFE8001" at offset '.$ThisFileInfo['avdataoffset'].', found "0x'.str_pad(strtoupper(dechex($ThisFileInfo['dts']['raw']['magic'])), 8, '0', STR_PAD_LEFT).'"';
33
+ unset($ThisFileInfo['fileformat']);
34
+ unset($ThisFileInfo['dts']);
35
+ return false;
36
+ }
37
+
38
+ $fhBS = getid3_lib::BigEndian2Bin(substr($DTSheader, 4, 12));
39
+ $bsOffset = 0;
40
+ $ThisFileInfo['dts']['raw']['frame_type'] = bindec(substr($fhBS, $bsOffset, 1)); $bsOffset += 1;
41
+ $ThisFileInfo['dts']['raw']['deficit_samples'] = bindec(substr($fhBS, $bsOffset, 5)); $bsOffset += 5;
42
+ $ThisFileInfo['dts']['flags']['crc_present'] = (bool) bindec(substr($fhBS, $bsOffset, 1)); $bsOffset += 1;
43
+ $ThisFileInfo['dts']['raw']['pcm_sample_blocks'] = bindec(substr($fhBS, $bsOffset, 7)); $bsOffset += 7;
44
+ $ThisFileInfo['dts']['raw']['frame_byte_size'] = bindec(substr($fhBS, $bsOffset, 14)); $bsOffset += 14;
45
+ $ThisFileInfo['dts']['raw']['channel_arrangement'] = bindec(substr($fhBS, $bsOffset, 6)); $bsOffset += 6;
46
+ $ThisFileInfo['dts']['raw']['sample_frequency'] = bindec(substr($fhBS, $bsOffset, 4)); $bsOffset += 4;
47
+ $ThisFileInfo['dts']['raw']['bitrate'] = bindec(substr($fhBS, $bsOffset, 5)); $bsOffset += 5;
48
+ $ThisFileInfo['dts']['flags']['embedded_downmix'] = (bool) bindec(substr($fhBS, $bsOffset, 1)); $bsOffset += 1;
49
+ $ThisFileInfo['dts']['flags']['dynamicrange'] = (bool) bindec(substr($fhBS, $bsOffset, 1)); $bsOffset += 1;
50
+ $ThisFileInfo['dts']['flags']['timestamp'] = (bool) bindec(substr($fhBS, $bsOffset, 1)); $bsOffset += 1;
51
+ $ThisFileInfo['dts']['flags']['auxdata'] = (bool) bindec(substr($fhBS, $bsOffset, 1)); $bsOffset += 1;
52
+ $ThisFileInfo['dts']['flags']['hdcd'] = (bool) bindec(substr($fhBS, $bsOffset, 1)); $bsOffset += 1;
53
+ $ThisFileInfo['dts']['raw']['extension_audio'] = bindec(substr($fhBS, $bsOffset, 3)); $bsOffset += 3;
54
+ $ThisFileInfo['dts']['flags']['extended_coding'] = (bool) bindec(substr($fhBS, $bsOffset, 1)); $bsOffset += 1;
55
+ $ThisFileInfo['dts']['flags']['audio_sync_insertion'] = (bool) bindec(substr($fhBS, $bsOffset, 1)); $bsOffset += 1;
56
+ $ThisFileInfo['dts']['raw']['lfe_effects'] = bindec(substr($fhBS, $bsOffset, 2)); $bsOffset += 2;
57
+ $ThisFileInfo['dts']['flags']['predictor_history'] = (bool) bindec(substr($fhBS, $bsOffset, 1)); $bsOffset += 1;
58
+ if ($ThisFileInfo['dts']['flags']['crc_present']) {
59
+ $ThisFileInfo['dts']['raw']['crc16'] = bindec(substr($fhBS, $bsOffset, 16)); $bsOffset += 16;
60
+ }
61
+ $ThisFileInfo['dts']['flags']['mri_perfect_reconst'] = (bool) bindec(substr($fhBS, $bsOffset, 1)); $bsOffset += 1;
62
+ $ThisFileInfo['dts']['raw']['encoder_soft_version'] = bindec(substr($fhBS, $bsOffset, 4)); $bsOffset += 4;
63
+ $ThisFileInfo['dts']['raw']['copy_history'] = bindec(substr($fhBS, $bsOffset, 2)); $bsOffset += 2;
64
+ $ThisFileInfo['dts']['raw']['bits_per_sample'] = bindec(substr($fhBS, $bsOffset, 2)); $bsOffset += 2;
65
+ $ThisFileInfo['dts']['flags']['surround_es'] = (bool) bindec(substr($fhBS, $bsOffset, 1)); $bsOffset += 1;
66
+ $ThisFileInfo['dts']['flags']['front_sum_diff'] = (bool) bindec(substr($fhBS, $bsOffset, 1)); $bsOffset += 1;
67
+ $ThisFileInfo['dts']['flags']['surround_sum_diff'] = (bool) bindec(substr($fhBS, $bsOffset, 1)); $bsOffset += 1;
68
+ $ThisFileInfo['dts']['raw']['dialog_normalization'] = bindec(substr($fhBS, $bsOffset, 4)); $bsOffset += 4;
69
+
70
+
71
+ $ThisFileInfo['dts']['bitrate'] = $this->DTSbitrateLookup($ThisFileInfo['dts']['raw']['bitrate']);
72
+ $ThisFileInfo['dts']['bits_per_sample'] = $this->DTSbitPerSampleLookup($ThisFileInfo['dts']['raw']['bits_per_sample']);
73
+ $ThisFileInfo['dts']['sample_rate'] = $this->DTSsampleRateLookup($ThisFileInfo['dts']['raw']['sample_frequency']);
74
+ $ThisFileInfo['dts']['dialog_normalization'] = $this->DTSdialogNormalization($ThisFileInfo['dts']['raw']['dialog_normalization'], $ThisFileInfo['dts']['raw']['encoder_soft_version']);
75
+ $ThisFileInfo['dts']['flags']['lossless'] = (($ThisFileInfo['dts']['raw']['bitrate'] == 31) ? true : false);
76
+ $ThisFileInfo['dts']['bitrate_mode'] = (($ThisFileInfo['dts']['raw']['bitrate'] == 30) ? 'vbr' : 'cbr');
77
+ $ThisFileInfo['dts']['channels'] = $this->DTSnumChannelsLookup($ThisFileInfo['dts']['raw']['channel_arrangement']);
78
+ $ThisFileInfo['dts']['channel_arrangement'] = $this->DTSchannelArrangementLookup($ThisFileInfo['dts']['raw']['channel_arrangement']);
79
+
80
+ $ThisFileInfo['audio']['dataformat'] = 'dts';
81
+ $ThisFileInfo['audio']['lossless'] = $ThisFileInfo['dts']['flags']['lossless'];
82
+ $ThisFileInfo['audio']['bitrate_mode'] = $ThisFileInfo['dts']['bitrate_mode'];
83
+ $ThisFileInfo['audio']['bits_per_sample'] = $ThisFileInfo['dts']['bits_per_sample'];
84
+ $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['dts']['sample_rate'];
85
+ $ThisFileInfo['audio']['channels'] = $ThisFileInfo['dts']['channels'];
86
+ $ThisFileInfo['audio']['bitrate'] = $ThisFileInfo['dts']['bitrate'];
87
+ if (isset($ThisFileInfo['avdataend'])) {
88
+ $ThisFileInfo['playtime_seconds'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) / ($ThisFileInfo['dts']['bitrate'] / 8);
89
+ }
90
+
91
+ return true;
92
+ }
93
+
94
+ function DTSbitrateLookup($index) {
95
+ $DTSbitrateLookup = array(
96
+ 0 => 32000,
97
+ 1 => 56000,
98
+ 2 => 64000,
99
+ 3 => 96000,
100
+ 4 => 112000,
101
+ 5 => 128000,
102
+ 6 => 192000,
103
+ 7 => 224000,
104
+ 8 => 256000,
105
+ 9 => 320000,
106
+ 10 => 384000,
107
+ 11 => 448000,
108
+ 12 => 512000,
109
+ 13 => 576000,
110
+ 14 => 640000,
111
+ 15 => 768000,
112
+ 16 => 960000,
113
+ 17 => 1024000,
114
+ 18 => 1152000,
115
+ 19 => 1280000,
116
+ 20 => 1344000,
117
+ 21 => 1408000,
118
+ 22 => 1411200,
119
+ 23 => 1472000,
120
+ 24 => 1536000,
121
+ 25 => 1920000,
122
+ 26 => 2048000,
123
+ 27 => 3072000,
124
+ 28 => 3840000,
125
+ 29 => 'open',
126
+ 30 => 'variable',
127
+ 31 => 'lossless'
128
+ );
129
+ return @$DTSbitrateLookup[$index];
130
+ }
131
+
132
+ function DTSsampleRateLookup($index) {
133
+ $DTSsampleRateLookup = array(
134
+ 0 => 'invalid',
135
+ 1 => 8000,
136
+ 2 => 16000,
137
+ 3 => 32000,
138
+ 4 => 'invalid',
139
+ 5 => 'invalid',
140
+ 6 => 11025,
141
+ 7 => 22050,
142
+ 8 => 44100,
143
+ 9 => 'invalid',
144
+ 10 => 'invalid',
145
+ 11 => 12000,
146
+ 12 => 24000,
147
+ 13 => 48000,
148
+ 14 => 'invalid',
149
+ 15 => 'invalid'
150
+ );
151
+ return @$DTSsampleRateLookup[$index];
152
+ }
153
+
154
+ function DTSbitPerSampleLookup($index) {
155
+ $DTSbitPerSampleLookup = array(
156
+ 0 => 16,
157
+ 1 => 20,
158
+ 2 => 24,
159
+ 3 => 24,
160
+ );
161
+ return @$DTSbitPerSampleLookup[$index];
162
+ }
163
+
164
+ function DTSnumChannelsLookup($index) {
165
+ switch ($index) {
166
+ case 0:
167
+ return 1;
168
+ break;
169
+ case 1:
170
+ case 2:
171
+ case 3:
172
+ case 4:
173
+ return 2;
174
+ break;
175
+ case 5:
176
+ case 6:
177
+ return 3;
178
+ break;
179
+ case 7:
180
+ case 8:
181
+ return 4;
182
+ break;
183
+ case 9:
184
+ return 5;
185
+ break;
186
+ case 10:
187
+ case 11:
188
+ case 12:
189
+ return 6;
190
+ break;
191
+ case 13:
192
+ return 7;
193
+ break;
194
+ case 14:
195
+ case 15:
196
+ return 8;
197
+ break;
198
+ }
199
+ return false;
200
+ }
201
+
202
+ function DTSchannelArrangementLookup($index) {
203
+ $DTSchannelArrangementLookup = array(
204
+ 0 => 'A',
205
+ 1 => 'A + B (dual mono)',
206
+ 2 => 'L + R (stereo)',
207
+ 3 => '(L+R) + (L-R) (sum-difference)',
208
+ 4 => 'LT + RT (left and right total)',
209
+ 5 => 'C + L + R',
210
+ 6 => 'L + R + S',
211
+ 7 => 'C + L + R + S',
212
+ 8 => 'L + R + SL + SR',
213
+ 9 => 'C + L + R + SL + SR',
214
+ 10 => 'CL + CR + L + R + SL + SR',
215
+ 11 => 'C + L + R+ LR + RR + OV',
216
+ 12 => 'CF + CR + LF + RF + LR + RR',
217
+ 13 => 'CL + C + CR + L + R + SL + SR',
218
+ 14 => 'CL + CR + L + R + SL1 + SL2 + SR1 + SR2',
219
+ 15 => 'CL + C+ CR + L + R + SL + S + SR',
220
+ );
221
+ return (@$DTSchannelArrangementLookup[$index] ? @$DTSchannelArrangementLookup[$index] : 'user-defined');
222
+ }
223
+
224
+ function DTSdialogNormalization($index, $version) {
225
+ switch ($version) {
226
+ case 7:
227
+ return 0 - $index;
228
+ break;
229
+ case 6:
230
+ return 0 - 16 - $index;
231
+ break;
232
+ }
233
+ return false;
234
+ }
235
+
236
+ }
237
+
238
+
239
+ ?>
view/getid3/module.audio.flac.php ADDED
@@ -0,0 +1,397 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /////////////////////////////////////////////////////////////////
3
+ /// getID3() by James Heinrich <info@getid3.org> //
4
+ // available at http://getid3.sourceforge.net //
5
+ // or http://www.getid3.org //
6
+ /////////////////////////////////////////////////////////////////
7
+ // See readme.txt for more details //
8
+ /////////////////////////////////////////////////////////////////
9
+ // //
10
+ // module.audio.flac.php //
11
+ // module for analyzing FLAC and OggFLAC audio files //
12
+ // dependencies: module.audio.ogg.php //
13
+ // ///
14
+ /////////////////////////////////////////////////////////////////
15
+
16
+
17
+ getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.ogg.php', __FILE__, true);
18
+
19
+ class getid3_flac
20
+ {
21
+
22
+ function getid3_flac(&$fd, &$ThisFileInfo) {
23
+ // http://flac.sourceforge.net/format.html
24
+
25
+ fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
26
+ $StreamMarker = fread($fd, 4);
27
+ if ($StreamMarker != 'fLaC') {
28
+ $ThisFileInfo['error'][] = 'Expecting "fLaC" at offset '.$ThisFileInfo['avdataoffset'].', found "'.$StreamMarker.'"';
29
+ return false;
30
+ }
31
+ $ThisFileInfo['fileformat'] = 'flac';
32
+ $ThisFileInfo['audio']['dataformat'] = 'flac';
33
+ $ThisFileInfo['audio']['bitrate_mode'] = 'vbr';
34
+ $ThisFileInfo['audio']['lossless'] = true;
35
+
36
+ return getid3_flac::FLACparseMETAdata($fd, $ThisFileInfo);
37
+ }
38
+
39
+
40
+ function FLACparseMETAdata(&$fd, &$ThisFileInfo) {
41
+
42
+ do {
43
+ $METAdataBlockOffset = ftell($fd);
44
+ $METAdataBlockHeader = fread($fd, 4);
45
+ $METAdataLastBlockFlag = (bool) (getid3_lib::BigEndian2Int(substr($METAdataBlockHeader, 0, 1)) & 0x80);
46
+ $METAdataBlockType = getid3_lib::BigEndian2Int(substr($METAdataBlockHeader, 0, 1)) & 0x7F;
47
+ $METAdataBlockLength = getid3_lib::BigEndian2Int(substr($METAdataBlockHeader, 1, 3));
48
+ $METAdataBlockTypeText = getid3_flac::FLACmetaBlockTypeLookup($METAdataBlockType);
49
+
50
+ if ($METAdataBlockLength < 0) {
51
+ $ThisFileInfo['error'][] = 'corrupt or invalid METADATA_BLOCK_HEADER.BLOCK_TYPE ('.$METAdataBlockType.') at offset '.$METAdataBlockOffset;
52
+ break;
53
+ }
54
+
55
+ $ThisFileInfo['flac'][$METAdataBlockTypeText]['raw'] = array();
56
+ $ThisFileInfo_flac_METAdataBlockTypeText_raw = &$ThisFileInfo['flac'][$METAdataBlockTypeText]['raw'];
57
+
58
+ $ThisFileInfo_flac_METAdataBlockTypeText_raw['offset'] = $METAdataBlockOffset;
59
+ $ThisFileInfo_flac_METAdataBlockTypeText_raw['last_meta_block'] = $METAdataLastBlockFlag;
60
+ $ThisFileInfo_flac_METAdataBlockTypeText_raw['block_type'] = $METAdataBlockType;
61
+ $ThisFileInfo_flac_METAdataBlockTypeText_raw['block_type_text'] = $METAdataBlockTypeText;
62
+ $ThisFileInfo_flac_METAdataBlockTypeText_raw['block_length'] = $METAdataBlockLength;
63
+ $ThisFileInfo_flac_METAdataBlockTypeText_raw['block_data'] = @fread($fd, $METAdataBlockLength);
64
+ $ThisFileInfo['avdataoffset'] = ftell($fd);
65
+
66
+ switch ($METAdataBlockTypeText) {
67
+
68
+ case 'STREAMINFO':
69
+ if (!getid3_flac::FLACparseSTREAMINFO($ThisFileInfo_flac_METAdataBlockTypeText_raw['block_data'], $ThisFileInfo)) {
70
+ return false;
71
+ }
72
+ break;
73
+
74
+ case 'PADDING':
75
+ // ignore
76
+ break;
77
+
78
+ case 'APPLICATION':
79
+ if (!getid3_flac::FLACparseAPPLICATION($ThisFileInfo_flac_METAdataBlockTypeText_raw['block_data'], $ThisFileInfo)) {
80
+ return false;
81
+ }
82
+ break;
83
+
84
+ case 'SEEKTABLE':
85
+ if (!getid3_flac::FLACparseSEEKTABLE($ThisFileInfo_flac_METAdataBlockTypeText_raw['block_data'], $ThisFileInfo)) {
86
+ return false;
87
+ }
88
+ break;
89
+
90
+ case 'VORBIS_COMMENT':
91
+ $OldOffset = ftell($fd);
92
+ fseek($fd, 0 - $METAdataBlockLength, SEEK_CUR);
93
+ getid3_ogg::ParseVorbisCommentsFilepointer($fd, $ThisFileInfo);
94
+ fseek($fd, $OldOffset, SEEK_SET);
95
+ break;
96
+
97
+ case 'CUESHEET':
98
+ if (!getid3_flac::FLACparseCUESHEET($ThisFileInfo_flac_METAdataBlockTypeText_raw['block_data'], $ThisFileInfo)) {
99
+ return false;
100
+ }
101
+ break;
102
+
103
+ case 'PICTURE':
104
+ if (!$this->FLACparsePICTURE($ThisFileInfo_flac_METAdataBlockTypeText_raw['block_data'], $ThisFileInfo)) {
105
+ return false;
106
+ }
107
+ break;
108
+
109
+ default:
110
+ $ThisFileInfo['warning'][] = 'Unhandled METADATA_BLOCK_HEADER.BLOCK_TYPE ('.$METAdataBlockType.') at offset '.$METAdataBlockOffset;
111
+ break;
112
+ }
113
+
114
+ } while ($METAdataLastBlockFlag === false);
115
+
116
+
117
+ if (isset($ThisFileInfo['flac']['STREAMINFO'])) {
118
+ $ThisFileInfo['flac']['compressed_audio_bytes'] = $ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset'];
119
+ $ThisFileInfo['flac']['uncompressed_audio_bytes'] = $ThisFileInfo['flac']['STREAMINFO']['samples_stream'] * $ThisFileInfo['flac']['STREAMINFO']['channels'] * ($ThisFileInfo['flac']['STREAMINFO']['bits_per_sample'] / 8);
120
+ if ($ThisFileInfo['flac']['uncompressed_audio_bytes'] == 0) {
121
+ $ThisFileInfo['error'][] = 'Corrupt FLAC file: uncompressed_audio_bytes == zero';
122
+ return false;
123
+ }
124
+ $ThisFileInfo['flac']['compression_ratio'] = $ThisFileInfo['flac']['compressed_audio_bytes'] / $ThisFileInfo['flac']['uncompressed_audio_bytes'];
125
+ }
126
+
127
+ // set md5_data_source - built into flac 0.5+
128
+ if (isset($ThisFileInfo['flac']['STREAMINFO']['audio_signature'])) {
129
+
130
+ if ($ThisFileInfo['flac']['STREAMINFO']['audio_signature'] === str_repeat("\x00", 16)) {
131
+
132
+ $ThisFileInfo['warning'][] = 'FLAC STREAMINFO.audio_signature is null (known issue with libOggFLAC)';
133
+
134
+ } else {
135
+
136
+ $ThisFileInfo['md5_data_source'] = '';
137
+ $md5 = $ThisFileInfo['flac']['STREAMINFO']['audio_signature'];
138
+ for ($i = 0; $i < strlen($md5); $i++) {
139
+ $ThisFileInfo['md5_data_source'] .= str_pad(dechex(ord($md5{$i})), 2, '00', STR_PAD_LEFT);
140
+ }
141
+ if (!preg_match('/^[0-9a-f]{32}$/', $ThisFileInfo['md5_data_source'])) {
142
+ unset($ThisFileInfo['md5_data_source']);
143
+ }
144
+
145
+ }
146
+
147
+ }
148
+
149
+ $ThisFileInfo['audio']['bits_per_sample'] = $ThisFileInfo['flac']['STREAMINFO']['bits_per_sample'];
150
+ if ($ThisFileInfo['audio']['bits_per_sample'] == 8) {
151
+ // special case
152
+ // must invert sign bit on all data bytes before MD5'ing to match FLAC's calculated value
153
+ // MD5sum calculates on unsigned bytes, but FLAC calculated MD5 on 8-bit audio data as signed
154
+ $ThisFileInfo['warning'][] = 'FLAC calculates MD5 data strangely on 8-bit audio, so the stored md5_data_source value will not match the decoded WAV file';
155
+ }
156
+ if (!empty($ThisFileInfo['ogg']['vendor'])) {
157
+ $ThisFileInfo['audio']['encoder'] = $ThisFileInfo['ogg']['vendor'];
158
+ }
159
+
160
+ return true;
161
+ }
162
+
163
+ function FLACmetaBlockTypeLookup($blocktype) {
164
+ static $FLACmetaBlockTypeLookup = array();
165
+ if (empty($FLACmetaBlockTypeLookup)) {
166
+ $FLACmetaBlockTypeLookup[0] = 'STREAMINFO';
167
+ $FLACmetaBlockTypeLookup[1] = 'PADDING';
168
+ $FLACmetaBlockTypeLookup[2] = 'APPLICATION';
169
+ $FLACmetaBlockTypeLookup[3] = 'SEEKTABLE';
170
+ $FLACmetaBlockTypeLookup[4] = 'VORBIS_COMMENT';
171
+ $FLACmetaBlockTypeLookup[5] = 'CUESHEET';
172
+ $FLACmetaBlockTypeLookup[6] = 'PICTURE';
173
+ }
174
+ return (isset($FLACmetaBlockTypeLookup[$blocktype]) ? $FLACmetaBlockTypeLookup[$blocktype] : 'reserved');
175
+ }
176
+
177
+ function FLACapplicationIDLookup($applicationid) {
178
+ static $FLACapplicationIDLookup = array();
179
+ if (empty($FLACapplicationIDLookup)) {
180
+ // http://flac.sourceforge.net/id.html
181
+ $FLACapplicationIDLookup[0x46746F6C] = 'flac-tools'; // 'Ftol'
182
+ $FLACapplicationIDLookup[0x46746F6C] = 'Sound Font FLAC'; // 'SFFL'
183
+ }
184
+ return (isset($FLACapplicationIDLookup[$applicationid]) ? $FLACapplicationIDLookup[$applicationid] : 'reserved');
185
+ }
186
+
187
+ function FLACpictureTypeLookup($type_id) {
188
+ static $lookup = array (
189
+ 0 => 'Other',
190
+ 1 => '32x32 pixels \'file icon\' (PNG only)',
191
+ 2 => 'Other file icon',
192
+ 3 => 'Cover (front)',
193
+ 4 => 'Cover (back)',
194
+ 5 => 'Leaflet page',
195
+ 6 => 'Media (e.g. label side of CD)',
196
+ 7 => 'Lead artist/lead performer/soloist',
197
+ 8 => 'Artist/performer',
198
+ 9 => 'Conductor',
199
+ 10 => 'Band/Orchestra',
200
+ 11 => 'Composer',
201
+ 12 => 'Lyricist/text writer',
202
+ 13 => 'Recording Location',
203
+ 14 => 'During recording',
204
+ 15 => 'During performance',
205
+ 16 => 'Movie/video screen capture',
206
+ 17 => 'A bright coloured fish',
207
+ 18 => 'Illustration',
208
+ 19 => 'Band/artist logotype',
209
+ 20 => 'Publisher/Studio logotype',
210
+ );
211
+ return (isset($lookup[$type_id]) ? $lookup[$type_id] : 'reserved');
212
+ }
213
+
214
+ function FLACparseSTREAMINFO($METAdataBlockData, &$ThisFileInfo) {
215
+ $offset = 0;
216
+ $ThisFileInfo['flac']['STREAMINFO']['min_block_size'] = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 2));
217
+ $offset += 2;
218
+ $ThisFileInfo['flac']['STREAMINFO']['max_block_size'] = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 2));
219
+ $offset += 2;
220
+ $ThisFileInfo['flac']['STREAMINFO']['min_frame_size'] = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 3));
221
+ $offset += 3;
222
+ $ThisFileInfo['flac']['STREAMINFO']['max_frame_size'] = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 3));
223
+ $offset += 3;
224
+
225
+ $SampleRateChannelsSampleBitsStreamSamples = getid3_lib::BigEndian2Bin(substr($METAdataBlockData, $offset, 8));
226
+ $ThisFileInfo['flac']['STREAMINFO']['sample_rate'] = getid3_lib::Bin2Dec(substr($SampleRateChannelsSampleBitsStreamSamples, 0, 20));
227
+ $ThisFileInfo['flac']['STREAMINFO']['channels'] = getid3_lib::Bin2Dec(substr($SampleRateChannelsSampleBitsStreamSamples, 20, 3)) + 1;
228
+ $ThisFileInfo['flac']['STREAMINFO']['bits_per_sample'] = getid3_lib::Bin2Dec(substr($SampleRateChannelsSampleBitsStreamSamples, 23, 5)) + 1;
229
+ $ThisFileInfo['flac']['STREAMINFO']['samples_stream'] = getid3_lib::Bin2Dec(substr($SampleRateChannelsSampleBitsStreamSamples, 28, 36));
230
+ $offset += 8;
231
+
232
+ $ThisFileInfo['flac']['STREAMINFO']['audio_signature'] = substr($METAdataBlockData, $offset, 16);
233
+ $offset += 16;
234
+
235
+ if (!empty($ThisFileInfo['flac']['STREAMINFO']['sample_rate'])) {
236
+
237
+ $ThisFileInfo['audio']['bitrate_mode'] = 'vbr';
238
+ $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['flac']['STREAMINFO']['sample_rate'];
239
+ $ThisFileInfo['audio']['channels'] = $ThisFileInfo['flac']['STREAMINFO']['channels'];
240
+ $ThisFileInfo['audio']['bits_per_sample'] = $ThisFileInfo['flac']['STREAMINFO']['bits_per_sample'];
241
+ $ThisFileInfo['playtime_seconds'] = $ThisFileInfo['flac']['STREAMINFO']['samples_stream'] / $ThisFileInfo['flac']['STREAMINFO']['sample_rate'];
242
+ $ThisFileInfo['audio']['bitrate'] = (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8) / $ThisFileInfo['playtime_seconds'];
243
+
244
+ } else {
245
+
246
+ $ThisFileInfo['error'][] = 'Corrupt METAdata block: STREAMINFO';
247
+ return false;
248
+
249
+ }
250
+
251
+ unset($ThisFileInfo['flac']['STREAMINFO']['raw']);
252
+
253
+ return true;
254
+ }
255
+
256
+
257
+ function FLACparseAPPLICATION($METAdataBlockData, &$ThisFileInfo) {
258
+ $offset = 0;
259
+ $ApplicationID = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 4));
260
+ $offset += 4;
261
+ $ThisFileInfo['flac']['APPLICATION'][$ApplicationID]['name'] = getid3_flac::FLACapplicationIDLookup($ApplicationID);
262
+ $ThisFileInfo['flac']['APPLICATION'][$ApplicationID]['data'] = substr($METAdataBlockData, $offset);
263
+ $offset = $METAdataBlockLength;
264
+
265
+ unset($ThisFileInfo['flac']['APPLICATION']['raw']);
266
+
267
+ return true;
268
+ }
269
+
270
+
271
+ function FLACparseSEEKTABLE($METAdataBlockData, &$ThisFileInfo) {
272
+ $offset = 0;
273
+ $METAdataBlockLength = strlen($METAdataBlockData);
274
+ $placeholderpattern = str_repeat("\xFF", 8);
275
+ while ($offset < $METAdataBlockLength) {
276
+ $SampleNumberString = substr($METAdataBlockData, $offset, 8);
277
+ $offset += 8;
278
+ if ($SampleNumberString == $placeholderpattern) {
279
+
280
+ // placeholder point
281
+ @$ThisFileInfo['flac']['SEEKTABLE']['placeholders']++;
282
+ $offset += 10;
283
+
284
+ } else {
285
+
286
+ $SampleNumber = getid3_lib::BigEndian2Int($SampleNumberString);
287
+ $ThisFileInfo['flac']['SEEKTABLE'][$SampleNumber]['offset'] = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 8));
288
+ $offset += 8;
289
+ $ThisFileInfo['flac']['SEEKTABLE'][$SampleNumber]['samples'] = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 2));
290
+ $offset += 2;
291
+
292
+ }
293
+ }
294
+
295
+ unset($ThisFileInfo['flac']['SEEKTABLE']['raw']);
296
+
297
+ return true;
298
+ }
299
+
300
+ function FLACparseCUESHEET($METAdataBlockData, &$ThisFileInfo) {
301
+ $offset = 0;
302
+ $ThisFileInfo['flac']['CUESHEET']['media_catalog_number'] = trim(substr($METAdataBlockData, $offset, 128), "\0");
303
+ $offset += 128;
304
+ $ThisFileInfo['flac']['CUESHEET']['lead_in_samples'] = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 8));
305
+ $offset += 8;
306
+ $ThisFileInfo['flac']['CUESHEET']['flags']['is_cd'] = (bool) (getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 1)) & 0x80);
307
+ $offset += 1;
308
+
309
+ $offset += 258; // reserved
310
+
311
+ $ThisFileInfo['flac']['CUESHEET']['number_tracks'] = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 1));
312
+ $offset += 1;
313
+
314
+ for ($track = 0; $track < $ThisFileInfo['flac']['CUESHEET']['number_tracks']; $track++) {
315
+ $TrackSampleOffset = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 8));
316
+ $offset += 8;
317
+ $TrackNumber = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 1));
318
+ $offset += 1;
319
+
320
+ $ThisFileInfo['flac']['CUESHEET']['tracks'][$TrackNumber]['sample_offset'] = $TrackSampleOffset;
321
+
322
+ $ThisFileInfo['flac']['CUESHEET']['tracks'][$TrackNumber]['isrc'] = substr($METAdataBlockData, $offset, 12);
323
+ $offset += 12;
324
+
325
+ $TrackFlagsRaw = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 1));
326
+ $offset += 1;
327
+ $ThisFileInfo['flac']['CUESHEET']['tracks'][$TrackNumber]['flags']['is_audio'] = (bool) ($TrackFlagsRaw & 0x80);
328
+ $ThisFileInfo['flac']['CUESHEET']['tracks'][$TrackNumber]['flags']['pre_emphasis'] = (bool) ($TrackFlagsRaw & 0x40);
329
+
330
+ $offset += 13; // reserved
331
+
332
+ $ThisFileInfo['flac']['CUESHEET']['tracks'][$TrackNumber]['index_points'] = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 1));
333
+ $offset += 1;
334
+
335
+ for ($index = 0; $index < $ThisFileInfo['flac']['CUESHEET']['tracks'][$TrackNumber]['index_points']; $index++) {
336
+ $IndexSampleOffset = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 8));
337
+ $offset += 8;
338
+ $IndexNumber = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 1));
339
+ $offset += 1;
340
+
341
+ $offset += 3; // reserved
342
+
343
+ $ThisFileInfo['flac']['CUESHEET']['tracks'][$TrackNumber]['indexes'][$IndexNumber] = $IndexSampleOffset;
344
+ }
345
+ }
346
+
347
+ unset($ThisFileInfo['flac']['CUESHEET']['raw']);
348
+
349
+ return true;
350
+ }
351
+
352
+
353
+ function FLACparsePICTURE($meta_data_block_data, &$ThisFileInfo) {
354
+ $picture = &$ThisFileInfo['flac']['PICTURE'][sizeof($ThisFileInfo['flac']['PICTURE']) - 1];
355
+
356
+ $offset = 0;
357
+
358
+ $picture['type'] = $this->FLACpictureTypeLookup(getid3_lib::BigEndian2Int(substr($meta_data_block_data, $offset, 4)));
359
+ $offset += 4;
360
+
361
+ $length = getid3_lib::BigEndian2Int(substr($meta_data_block_data, $offset, 4));
362
+ $offset += 4;
363
+
364
+ $picture['mime_type'] = substr($meta_data_block_data, $offset, $length);
365
+ $offset += $length;
366
+
367
+ $length = getid3_lib::BigEndian2Int(substr($meta_data_block_data, $offset, 4));
368
+ $offset += 4;
369
+
370
+ $picture['description'] = substr($meta_data_block_data, $offset, $length);
371
+ $offset += $length;
372
+
373
+ $picture['width'] = getid3_lib::BigEndian2Int(substr($meta_data_block_data, $offset, 4));
374
+ $offset += 4;
375
+
376
+ $picture['height'] = getid3_lib::BigEndian2Int(substr($meta_data_block_data, $offset, 4));
377
+ $offset += 4;
378
+
379
+ $picture['color_depth'] = getid3_lib::BigEndian2Int(substr($meta_data_block_data, $offset, 4));
380
+ $offset += 4;
381
+
382
+ $picture['colors_indexed'] = getid3_lib::BigEndian2Int(substr($meta_data_block_data, $offset, 4));
383
+ $offset += 4;
384
+
385
+ $length = getid3_lib::BigEndian2Int(substr($meta_data_block_data, $offset, 4));
386
+ $offset += 4;
387
+
388
+ $picture['image_data'] = substr($meta_data_block_data, $offset, $length);
389
+ $offset += $length;
390
+
391
+ unset($ThisFileInfo['flac']['PICTURE']['raw']);
392
+
393
+ return true;
394
+ }
395
+ }
396
+
397
+ ?>
view/getid3/module.audio.la.php ADDED
@@ -0,0 +1,228 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /////////////////////////////////////////////////////////////////
3
+ /// getID3() by James Heinrich <info@getid3.org> //
4
+ // available at http://getid3.sourceforge.net //
5
+ // or http://www.getid3.org //
6
+ /////////////////////////////////////////////////////////////////
7
+ // See readme.txt for more details //
8
+ /////////////////////////////////////////////////////////////////
9
+ // //
10
+ // module.audio.la.php //
11
+ // module for analyzing LA audio files //
12
+ // dependencies: module.audio.riff.php //
13
+ // ///
14
+ /////////////////////////////////////////////////////////////////
15
+
16
+ getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true);
17
+
18
+ class getid3_la
19
+ {
20
+
21
+ function getid3_la(&$fd, &$ThisFileInfo) {
22
+ $offset = 0;
23
+ fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
24
+ $rawdata = fread($fd, GETID3_FREAD_BUFFER_SIZE);
25
+
26
+ switch (substr($rawdata, $offset, 4)) {
27
+ case 'LA02':
28
+ case 'LA03':
29
+ case 'LA04':
30
+ $ThisFileInfo['fileformat'] = 'la';
31
+ $ThisFileInfo['audio']['dataformat'] = 'la';
32
+ $ThisFileInfo['audio']['lossless'] = true;
33
+
34
+ $ThisFileInfo['la']['version_major'] = (int) substr($rawdata, $offset + 2, 1);
35
+ $ThisFileInfo['la']['version_minor'] = (int) substr($rawdata, $offset + 3, 1);
36
+ $ThisFileInfo['la']['version'] = (float) $ThisFileInfo['la']['version_major'] + ($ThisFileInfo['la']['version_minor'] / 10);
37
+ $offset += 4;
38
+
39
+ $ThisFileInfo['la']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4));
40
+ $offset += 4;
41
+ if ($ThisFileInfo['la']['uncompressed_size'] == 0) {
42
+ $ThisFileInfo['error'][] = 'Corrupt LA file: uncompressed_size == zero';
43
+ return false;
44
+ }
45
+
46
+ $WAVEchunk = substr($rawdata, $offset, 4);
47
+ if ($WAVEchunk !== 'WAVE') {
48
+ $ThisFileInfo['error'][] = 'Expected "WAVE" ('.getid3_lib::PrintHexBytes('WAVE').') at offset '.$offset.', found "'.$WAVEchunk.'" ('.getid3_lib::PrintHexBytes($WAVEchunk).') instead.';
49
+ return false;
50
+ }
51
+ $offset += 4;
52
+
53
+ $ThisFileInfo['la']['fmt_size'] = 24;
54
+ if ($ThisFileInfo['la']['version'] >= 0.3) {
55
+
56
+ $ThisFileInfo['la']['fmt_size'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4));
57
+ $ThisFileInfo['la']['header_size'] = 49 + $ThisFileInfo['la']['fmt_size'] - 24;
58
+ $offset += 4;
59
+
60
+ } else {
61
+
62
+ // version 0.2 didn't support additional data blocks
63
+ $ThisFileInfo['la']['header_size'] = 41;
64
+
65
+ }
66
+
67
+ $fmt_chunk = substr($rawdata, $offset, 4);
68
+ if ($fmt_chunk !== 'fmt ') {
69
+ $ThisFileInfo['error'][] = 'Expected "fmt " ('.getid3_lib::PrintHexBytes('fmt ').') at offset '.$offset.', found "'.$fmt_chunk.'" ('.getid3_lib::PrintHexBytes($fmt_chunk).') instead.';
70
+ return false;
71
+ }
72
+ $offset += 4;
73
+ $fmt_size = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4));
74
+ $offset += 4;
75
+
76
+ $ThisFileInfo['la']['raw']['format'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 2));
77
+ $offset += 2;
78
+
79
+ $ThisFileInfo['la']['channels'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 2));
80
+ $offset += 2;
81
+ if ($ThisFileInfo['la']['channels'] == 0) {
82
+ $ThisFileInfo['error'][] = 'Corrupt LA file: channels == zero';
83
+ return false;
84
+ }
85
+
86
+ $ThisFileInfo['la']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4));
87
+ $offset += 4;
88
+ if ($ThisFileInfo['la']['sample_rate'] == 0) {
89
+ $ThisFileInfo['error'][] = 'Corrupt LA file: sample_rate == zero';
90
+ return false;
91
+ }
92
+
93
+ $ThisFileInfo['la']['bytes_per_second'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4));
94
+ $offset += 4;
95
+ $ThisFileInfo['la']['bytes_per_sample'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 2));
96
+ $offset += 2;
97
+ $ThisFileInfo['la']['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 2));
98
+ $offset += 2;
99
+
100
+ $ThisFileInfo['la']['samples'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4));
101
+ $offset += 4;
102
+
103
+ $ThisFileInfo['la']['raw']['flags'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 1));
104
+ $offset += 1;
105
+ $ThisFileInfo['la']['flags']['seekable'] = (bool) ($ThisFileInfo['la']['raw']['flags'] & 0x01);
106
+ if ($ThisFileInfo['la']['version'] >= 0.4) {
107
+ $ThisFileInfo['la']['flags']['high_compression'] = (bool) ($ThisFileInfo['la']['raw']['flags'] & 0x02);
108
+ }
109
+
110
+ $ThisFileInfo['la']['original_crc'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4));
111
+ $offset += 4;
112
+
113
+ // mike�bevin*de
114
+ // Basically, the blocksize/seekevery are 61440/19 in La0.4 and 73728/16
115
+ // in earlier versions. A seekpoint is added every blocksize * seekevery
116
+ // samples, so 4 * int(totalSamples / (blockSize * seekEvery)) should
117
+ // give the number of bytes used for the seekpoints. Of course, if seeking
118
+ // is disabled, there are no seekpoints stored.
119
+ if ($ThisFileInfo['la']['version'] >= 0.4) {
120
+ $ThisFileInfo['la']['blocksize'] = 61440;
121
+ $ThisFileInfo['la']['seekevery'] = 19;
122
+ } else {
123
+ $ThisFileInfo['la']['blocksize'] = 73728;
124
+ $ThisFileInfo['la']['seekevery'] = 16;
125
+ }
126
+
127
+ $ThisFileInfo['la']['seekpoint_count'] = 0;
128
+ if ($ThisFileInfo['la']['flags']['seekable']) {
129
+ $ThisFileInfo['la']['seekpoint_count'] = floor($ThisFileInfo['la']['samples'] / ($ThisFileInfo['la']['blocksize'] * $ThisFileInfo['la']['seekevery']));
130
+
131
+ for ($i = 0; $i < $ThisFileInfo['la']['seekpoint_count']; $i++) {
132
+ $ThisFileInfo['la']['seekpoints'][] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4));
133
+ $offset += 4;
134
+ }
135
+ }
136
+
137
+ if ($ThisFileInfo['la']['version'] >= 0.3) {
138
+
139
+ // Following the main header information, the program outputs all of the
140
+ // seekpoints. Following these is what I called the 'footer start',
141
+ // i.e. the position immediately after the La audio data is finished.
142
+ $ThisFileInfo['la']['footerstart'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4));
143
+ $offset += 4;
144
+
145
+ if ($ThisFileInfo['la']['footerstart'] > $ThisFileInfo['filesize']) {
146
+ $ThisFileInfo['warning'][] = 'FooterStart value points to offset '.$ThisFileInfo['la']['footerstart'].' which is beyond end-of-file ('.$ThisFileInfo['filesize'].')';
147
+ $ThisFileInfo['la']['footerstart'] = $ThisFileInfo['filesize'];
148
+ }
149
+
150
+ } else {
151
+
152
+ // La v0.2 didn't have FooterStart value
153
+ $ThisFileInfo['la']['footerstart'] = $ThisFileInfo['avdataend'];
154
+
155
+ }
156
+
157
+ if ($ThisFileInfo['la']['footerstart'] < $ThisFileInfo['avdataend']) {
158
+ if ($RIFFtempfilename = tempnam('*', 'id3')) {
159
+ if ($RIFF_fp = fopen($RIFFtempfilename, 'w+b')) {
160
+ $RIFFdata = 'WAVE';
161
+ if ($ThisFileInfo['la']['version'] == 0.2) {
162
+ $RIFFdata .= substr($rawdata, 12, 24);
163
+ } else {
164
+ $RIFFdata .= substr($rawdata, 16, 24);
165
+ }
166
+ if ($ThisFileInfo['la']['footerstart'] < $ThisFileInfo['avdataend']) {
167
+ fseek($fd, $ThisFileInfo['la']['footerstart'], SEEK_SET);
168
+ $RIFFdata .= fread($fd, $ThisFileInfo['avdataend'] - $ThisFileInfo['la']['footerstart']);
169
+ }
170
+ $RIFFdata = 'RIFF'.getid3_lib::LittleEndian2String(strlen($RIFFdata), 4, false).$RIFFdata;
171
+ fwrite($RIFF_fp, $RIFFdata, strlen($RIFFdata));
172
+ $dummy = $ThisFileInfo;
173
+ $dummy['filesize'] = strlen($RIFFdata);
174
+ $dummy['avdataoffset'] = 0;
175
+ $dummy['avdataend'] = $dummy['filesize'];
176
+
177
+ $riff = new getid3_riff($RIFF_fp, $dummy);
178
+ if (empty($dummy['error'])) {
179
+ $ThisFileInfo['riff'] = $dummy['riff'];
180
+ } else {
181
+ $ThisFileInfo['warning'][] = 'Error parsing RIFF portion of La file: '.implode($dummy['error']);
182
+ }
183
+ unset($riff);
184
+ unset($dummy);
185
+ fclose($RIFF_fp);
186
+ }
187
+ unlink($RIFFtempfilename);
188
+ }
189
+ }
190
+
191
+ // $ThisFileInfo['avdataoffset'] should be zero to begin with, but just in case it's not, include the addition anyway
192
+ $ThisFileInfo['avdataend'] = $ThisFileInfo['avdataoffset'] + $ThisFileInfo['la']['footerstart'];
193
+ $ThisFileInfo['avdataoffset'] = $ThisFileInfo['avdataoffset'] + $offset;
194
+
195
+ //$ThisFileInfo['la']['codec'] = RIFFwFormatTagLookup($ThisFileInfo['la']['raw']['format']);
196
+ $ThisFileInfo['la']['compression_ratio'] = (float) (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) / $ThisFileInfo['la']['uncompressed_size']);
197
+ $ThisFileInfo['playtime_seconds'] = (float) ($ThisFileInfo['la']['samples'] / $ThisFileInfo['la']['sample_rate']) / $ThisFileInfo['la']['channels'];
198
+ if ($ThisFileInfo['playtime_seconds'] == 0) {
199
+ $ThisFileInfo['error'][] = 'Corrupt LA file: playtime_seconds == zero';
200
+ return false;
201
+ }
202
+
203
+ $ThisFileInfo['audio']['bitrate'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8 / $ThisFileInfo['playtime_seconds'];
204
+ //$ThisFileInfo['audio']['codec'] = $ThisFileInfo['la']['codec'];
205
+ $ThisFileInfo['audio']['bits_per_sample'] = $ThisFileInfo['la']['bits_per_sample'];
206
+ break;
207
+
208
+ default:
209
+ if (substr($rawdata, $offset, 2) == 'LA') {
210
+ $ThisFileInfo['error'][] = 'This version of getID3() (v'.GETID3_VERSION.') doesn\'t support LA version '.substr($rawdata, $offset + 2, 1).'.'.substr($rawdata, $offset + 3, 1).' which this appears to be - check http://getid3.sourceforge.net for updates.';
211
+ } else {
212
+ $ThisFileInfo['error'][] = 'Not a LA (Lossless-Audio) file';
213
+ }
214
+ return false;
215
+ break;
216
+ }
217
+
218
+ $ThisFileInfo['audio']['channels'] = $ThisFileInfo['la']['channels'];
219
+ $ThisFileInfo['audio']['sample_rate'] = (int) $ThisFileInfo['la']['sample_rate'];
220
+ $ThisFileInfo['audio']['encoder'] = 'LA v'.$ThisFileInfo['la']['version'];
221
+
222
+ return true;
223
+ }
224
+
225
+ }
226
+
227
+
228
+ ?>
view/getid3/module.audio.lpac.php ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /////////////////////////////////////////////////////////////////
3
+ /// getID3() by James Heinrich <info@getid3.org> //
4
+ // available at http://getid3.sourceforge.net //
5
+ // or http://www.getid3.org //
6
+ /////////////////////////////////////////////////////////////////
7
+ // See readme.txt for more details //
8
+ /////////////////////////////////////////////////////////////////
9
+ // //
10
+ // module.audio.lpac.php //
11
+ // module for analyzing LPAC Audio files //
12
+ // dependencies: module.audio-video.riff.php //
13
+ // ///
14
+ /////////////////////////////////////////////////////////////////
15
+
16
+ getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true);
17
+
18
+ class getid3_lpac
19
+ {
20
+
21
+ function getid3_lpac(&$fd, &$ThisFileInfo) {
22
+
23
+ fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
24
+ $LPACheader = fread($fd, 14);
25
+ if (substr($LPACheader, 0, 4) != 'LPAC') {
26
+ $ThisFileInfo['error'][] = 'Expected "LPAC" at offset '.$ThisFileInfo['avdataoffset'].', found "'.$StreamMarker.'"';
27
+ return false;
28
+ }
29
+ $ThisFileInfo['avdataoffset'] += 14;
30
+
31
+ $ThisFileInfo['fileformat'] = 'lpac';
32
+ $ThisFileInfo['audio']['dataformat'] = 'lpac';
33
+ $ThisFileInfo['audio']['lossless'] = true;
34
+ $ThisFileInfo['audio']['bitrate_mode'] = 'vbr';
35
+
36
+ $ThisFileInfo['lpac']['file_version'] = getid3_lib::BigEndian2Int(substr($LPACheader, 4, 1));
37
+ $flags['audio_type'] = getid3_lib::BigEndian2Int(substr($LPACheader, 5, 1));
38
+ $ThisFileInfo['lpac']['total_samples']= getid3_lib::BigEndian2Int(substr($LPACheader, 6, 4));
39
+ $flags['parameters'] = getid3_lib::BigEndian2Int(substr($LPACheader, 10, 4));
40
+
41
+ $ThisFileInfo['lpac']['flags']['is_wave'] = (bool) ($flags['audio_type'] & 0x40);
42
+ $ThisFileInfo['lpac']['flags']['stereo'] = (bool) ($flags['audio_type'] & 0x04);
43
+ $ThisFileInfo['lpac']['flags']['24_bit'] = (bool) ($flags['audio_type'] & 0x02);
44
+ $ThisFileInfo['lpac']['flags']['16_bit'] = (bool) ($flags['audio_type'] & 0x01);
45
+
46
+ if ($ThisFileInfo['lpac']['flags']['24_bit'] && $ThisFileInfo['lpac']['flags']['16_bit']) {
47
+ $ThisFileInfo['warning'][] = '24-bit and 16-bit flags cannot both be set';
48
+ }
49
+
50
+ $ThisFileInfo['lpac']['flags']['fast_compress'] = (bool) ($flags['parameters'] & 0x40000000);
51
+ $ThisFileInfo['lpac']['flags']['random_access'] = (bool) ($flags['parameters'] & 0x08000000);
52
+ $ThisFileInfo['lpac']['block_length'] = pow(2, (($flags['parameters'] & 0x07000000) >> 24)) * 256;
53
+ $ThisFileInfo['lpac']['flags']['adaptive_prediction_order'] = (bool) ($flags['parameters'] & 0x00800000);
54
+ $ThisFileInfo['lpac']['flags']['adaptive_quantization'] = (bool) ($flags['parameters'] & 0x00400000);
55
+ $ThisFileInfo['lpac']['flags']['joint_stereo'] = (bool) ($flags['parameters'] & 0x00040000);
56
+ $ThisFileInfo['lpac']['quantization'] = ($flags['parameters'] & 0x00001F00) >> 8;
57
+ $ThisFileInfo['lpac']['max_prediction_order'] = ($flags['parameters'] & 0x0000003F);
58
+
59
+ if ($ThisFileInfo['lpac']['flags']['fast_compress'] && ($ThisFileInfo['lpac']['max_prediction_order'] != 3)) {
60
+ $ThisFileInfo['warning'][] = 'max_prediction_order expected to be "3" if fast_compress is true, actual value is "'.$ThisFileInfo['lpac']['max_prediction_order'].'"';
61
+ }
62
+ switch ($ThisFileInfo['lpac']['file_version']) {
63
+ case 6:
64
+ if ($ThisFileInfo['lpac']['flags']['adaptive_quantization']) {
65
+ $ThisFileInfo['warning'][] = 'adaptive_quantization expected to be false in LPAC file stucture v6, actually true';
66
+ }
67
+ if ($ThisFileInfo['lpac']['quantization'] != 20) {
68
+ $ThisFileInfo['warning'][] = 'Quantization expected to be 20 in LPAC file stucture v6, actually '.$ThisFileInfo['lpac']['flags']['Q'];
69
+ }
70
+ break;
71
+
72
+ default:
73
+ //$ThisFileInfo['warning'][] = 'This version of getID3() only supports LPAC file format version 6, this file is version '.$ThisFileInfo['lpac']['file_version'].' - please report to info@getid3.org';
74
+ break;
75
+ }
76
+
77
+ $dummy = $ThisFileInfo;
78
+ $riff = new getid3_riff($fd, $dummy);
79
+ unset($riff);
80
+ $ThisFileInfo['avdataoffset'] = $dummy['avdataoffset'];
81
+ $ThisFileInfo['riff'] = $dummy['riff'];
82
+ $ThisFileInfo['error'] = $dummy['error'];
83
+ $ThisFileInfo['warning'] = $dummy['warning'];
84
+ $ThisFileInfo['lpac']['comments']['comment'] = $dummy['comments'];
85
+ $ThisFileInfo['audio']['sample_rate'] = $dummy['audio']['sample_rate'];
86
+
87
+ $ThisFileInfo['audio']['channels'] = ($ThisFileInfo['lpac']['flags']['stereo'] ? 2 : 1);
88
+
89
+ if ($ThisFileInfo['lpac']['flags']['24_bit']) {
90
+ $ThisFileInfo['audio']['bits_per_sample'] = $ThisFileInfo['riff']['audio'][0]['bits_per_sample'];
91
+ } elseif ($ThisFileInfo['lpac']['flags']['16_bit']) {
92
+ $ThisFileInfo['audio']['bits_per_sample'] = 16;
93
+ } else {
94
+ $ThisFileInfo['audio']['bits_per_sample'] = 8;
95
+ }
96
+
97
+ if ($ThisFileInfo['lpac']['flags']['fast_compress']) {
98
+ // fast
99
+ $ThisFileInfo['audio']['encoder_options'] = '-1';
100
+ } else {
101
+ switch ($ThisFileInfo['lpac']['max_prediction_order']) {
102
+ case 20: // simple
103
+ $ThisFileInfo['audio']['encoder_options'] = '-2';
104
+ break;
105
+ case 30: // medium
106
+ $ThisFileInfo['audio']['encoder_options'] = '-3';
107
+ break;
108
+ case 40: // high
109
+ $ThisFileInfo['audio']['encoder_options'] = '-4';
110
+ break;
111
+ case 60: // extrahigh
112
+ $ThisFileInfo['audio']['encoder_options'] = '-5';
113
+ break;
114
+ }
115
+ }
116
+
117
+ $ThisFileInfo['playtime_seconds'] = $ThisFileInfo['lpac']['total_samples'] / $ThisFileInfo['audio']['sample_rate'];
118
+ $ThisFileInfo['audio']['bitrate'] = (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8) / $ThisFileInfo['playtime_seconds'];
119
+
120
+ return true;
121
+ }
122
+
123
+ }
124
+
125
+
126
+ ?>
view/getid3/module.audio.midi.php ADDED
@@ -0,0 +1,522 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /////////////////////////////////////////////////////////////////
3
+ /// getID3() by James Heinrich <info@getid3.org> //
4
+ // available at http://getid3.sourceforge.net //
5
+ // or http://www.getid3.org //
6
+ /////////////////////////////////////////////////////////////////
7
+ // See readme.txt for more details //
8
+ /////////////////////////////////////////////////////////////////
9
+ // //
10
+ // module.audio.midi.php //
11
+ // module for Midi Audio files //
12
+ // dependencies: NONE //
13
+ // ///
14
+ /////////////////////////////////////////////////////////////////
15
+
16
+
17
+ class getid3_midi
18
+ {
19
+
20
+ function getid3_midi(&$fd, &$ThisFileInfo, $scanwholefile=true) {
21
+
22
+ // shortcut
23
+ $ThisFileInfo['midi']['raw'] = array();
24
+ $thisfile_midi = &$ThisFileInfo['midi'];
25
+ $thisfile_midi_raw = &$thisfile_midi['raw'];
26
+
27
+ $ThisFileInfo['fileformat'] = 'midi';
28
+ $ThisFileInfo['audio']['dataformat'] = 'midi';
29
+
30
+ fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
31
+ $MIDIdata = fread($fd, GETID3_FREAD_BUFFER_SIZE);
32
+ $offset = 0;
33
+ $MIDIheaderID = substr($MIDIdata, $offset, 4); // 'MThd'
34
+ if ($MIDIheaderID != 'MThd') {
35
+ $ThisFileInfo['error'][] = 'Expecting "MThd" at offset '.$ThisFileInfo['avdataoffset'].', found "'.$MIDIheaderID.'"';
36
+ unset($ThisFileInfo['fileformat']);
37
+ return false;
38
+ }
39
+ $offset += 4;
40
+ $thisfile_midi_raw['headersize'] = getid3_lib::BigEndian2Int(substr($MIDIdata, $offset, 4));
41
+ $offset += 4;
42
+ $thisfile_midi_raw['fileformat'] = getid3_lib::BigEndian2Int(substr($MIDIdata, $offset, 2));
43
+ $offset += 2;
44
+ $thisfile_midi_raw['tracks'] = getid3_lib::BigEndian2Int(substr($MIDIdata, $offset, 2));
45
+ $offset += 2;
46
+ $thisfile_midi_raw['ticksperqnote'] = getid3_lib::BigEndian2Int(substr($MIDIdata, $offset, 2));
47
+ $offset += 2;
48
+
49
+ for ($i = 0; $i < $thisfile_midi_raw['tracks']; $i++) {
50
+ if ((strlen($MIDIdata) - $offset) < 8) {
51
+ $MIDIdata .= fread($fd, GETID3_FREAD_BUFFER_SIZE);
52
+ }
53
+ $trackID = substr($MIDIdata, $offset, 4);
54
+ $offset += 4;
55
+ if ($trackID == 'MTrk') {
56
+ $tracksize = getid3_lib::BigEndian2Int(substr($MIDIdata, $offset, 4));
57
+ $offset += 4;
58
+ // $thisfile_midi['tracks'][$i]['size'] = $tracksize;
59
+ $trackdataarray[$i] = substr($MIDIdata, $offset, $tracksize);
60
+ $offset += $tracksize;
61
+ } else {
62
+ $ThisFileInfo['error'][] = 'Expecting "MTrk" at '.$offset.', found '.$trackID.' instead';
63
+ return false;
64
+ }
65
+ }
66
+
67
+ if (!isset($trackdataarray) || !is_array($trackdataarray)) {
68
+ $ThisFileInfo['error'][] = 'Cannot find MIDI track information';
69
+ unset($thisfile_midi);
70
+ unset($ThisFileInfo['fileformat']);
71
+ return false;
72
+ }
73
+
74
+ if ($scanwholefile) { // this can take quite a long time, so have the option to bypass it if speed is very important
75
+ $thisfile_midi['totalticks'] = 0;
76
+ $ThisFileInfo['playtime_seconds'] = 0;
77
+ $CurrentMicroSecondsPerBeat = 500000; // 120 beats per minute; 60,000,000 microseconds per minute -> 500,000 microseconds per beat
78
+ $CurrentBeatsPerMinute = 120; // 120 beats per minute; 60,000,000 microseconds per minute -> 500,000 microseconds per beat
79
+ $MicroSecondsPerQuarterNoteAfter = array ();
80
+
81
+ foreach ($trackdataarray as $tracknumber => $trackdata) {
82
+
83
+ $eventsoffset = 0;
84
+ $LastIssuedMIDIcommand = 0;
85
+ $LastIssuedMIDIchannel = 0;
86
+ $CumulativeDeltaTime = 0;
87
+ $TicksAtCurrentBPM = 0;
88
+ while ($eventsoffset < strlen($trackdata)) {
89
+ $eventid = 0;
90
+ if (isset($MIDIevents[$tracknumber]) && is_array($MIDIevents[$tracknumber])) {
91
+ $eventid = count($MIDIevents[$tracknumber]);
92
+ }
93
+ $deltatime = 0;
94
+ for ($i = 0; $i < 4; $i++) {
95
+ $deltatimebyte = ord(substr($trackdata, $eventsoffset++, 1));
96
+ $deltatime = ($deltatime << 7) + ($deltatimebyte & 0x7F);
97
+ if ($deltatimebyte & 0x80) {
98
+ // another byte follows
99
+ } else {
100
+ break;
101
+ }
102
+ }
103
+ $CumulativeDeltaTime += $deltatime;
104
+ $TicksAtCurrentBPM += $deltatime;
105
+ $MIDIevents[$tracknumber][$eventid]['deltatime'] = $deltatime;
106
+ $MIDI_event_channel = ord(substr($trackdata, $eventsoffset++, 1));
107
+ if ($MIDI_event_channel & 0x80) {
108
+ // OK, normal event - MIDI command has MSB set
109
+ $LastIssuedMIDIcommand = $MIDI_event_channel >> 4;
110
+ $LastIssuedMIDIchannel = $MIDI_event_channel & 0x0F;
111
+ } else {
112
+ // running event - assume last command
113
+ $eventsoffset--;
114
+ }
115
+ $MIDIevents[$tracknumber][$eventid]['eventid'] = $LastIssuedMIDIcommand;
116
+ $MIDIevents[$tracknumber][$eventid]['channel'] = $LastIssuedMIDIchannel;
117
+ if ($MIDIevents[$tracknumber][$eventid]['eventid'] == 0x08) { // Note off (key is released)
118
+
119
+ $notenumber = ord(substr($trackdata, $eventsoffset++, 1));
120
+ $velocity = ord(substr($trackdata, $eventsoffset++, 1));
121
+
122
+ } elseif ($MIDIevents[$tracknumber][$eventid]['eventid'] == 0x09) { // Note on (key is pressed)
123
+
124
+ $notenumber = ord(substr($trackdata, $eventsoffset++, 1));
125
+ $velocity = ord(substr($trackdata, $eventsoffset++, 1));
126
+
127
+ } elseif ($MIDIevents[$tracknumber][$eventid]['eventid'] == 0x0A) { // Key after-touch
128
+
129
+ $notenumber = ord(substr($trackdata, $eventsoffset++, 1));
130
+ $velocity = ord(substr($trackdata, $eventsoffset++, 1));
131
+
132
+ } elseif ($MIDIevents[$tracknumber][$eventid]['eventid'] == 0x0B) { // Control Change
133
+
134
+ $controllernum = ord(substr($trackdata, $eventsoffset++, 1));
135
+ $newvalue = ord(substr($trackdata, $eventsoffset++, 1));
136
+
137
+ } elseif ($MIDIevents[$tracknumber][$eventid]['eventid'] == 0x0C) { // Program (patch) change
138
+
139
+ $newprogramnum = ord(substr($trackdata, $eventsoffset++, 1));
140
+
141
+ $thisfile_midi_raw['track'][$tracknumber]['instrumentid'] = $newprogramnum;
142
+ if ($tracknumber == 10) {
143
+ $thisfile_midi_raw['track'][$tracknumber]['instrument'] = $this->GeneralMIDIpercussionLookup($newprogramnum);
144
+ } else {
145
+ $thisfile_midi_raw['track'][$tracknumber]['instrument'] = $this->GeneralMIDIinstrumentLookup($newprogramnum);
146
+ }
147
+
148
+ } elseif ($MIDIevents[$tracknumber][$eventid]['eventid'] == 0x0D) { // Channel after-touch
149
+
150
+ $channelnumber = ord(substr($trackdata, $eventsoffset++, 1));
151
+
152
+ } elseif ($MIDIevents[$tracknumber][$eventid]['eventid'] == 0x0E) { // Pitch wheel change (2000H is normal or no change)
153
+
154
+ $changeLSB = ord(substr($trackdata, $eventsoffset++, 1));
155
+ $changeMSB = ord(substr($trackdata, $eventsoffset++, 1));
156
+ $pitchwheelchange = (($changeMSB & 0x7F) << 7) & ($changeLSB & 0x7F);
157
+
158
+ } elseif (($MIDIevents[$tracknumber][$eventid]['eventid'] == 0x0F) && ($MIDIevents[$tracknumber][$eventid]['channel'] == 0x0F)) {
159
+
160
+ $METAeventCommand = ord(substr($trackdata, $eventsoffset++, 1));
161
+ $METAeventLength = ord(substr($trackdata, $eventsoffset++, 1));
162
+ $METAeventData = substr($trackdata, $eventsoffset, $METAeventLength);
163
+ $eventsoffset += $METAeventLength;
164
+ switch ($METAeventCommand) {
165
+ case 0x00: // Set track sequence number
166
+ $track_sequence_number = getid3_lib::BigEndian2Int(substr($METAeventData, 0, $METAeventLength));
167
+ //$thisfile_midi_raw['events'][$tracknumber][$eventid]['seqno'] = $track_sequence_number;
168
+ break;
169
+
170
+ case 0x01: // Text: generic
171
+ $text_generic = substr($METAeventData, 0, $METAeventLength);
172
+ //$thisfile_midi_raw['events'][$tracknumber][$eventid]['text'] = $text_generic;
173
+ $thisfile_midi['comments']['comment'][] = $text_generic;
174
+ break;
175
+
176
+ case 0x02: // Text: copyright
177
+ $text_copyright = substr($METAeventData, 0, $METAeventLength);
178
+ //$thisfile_midi_raw['events'][$tracknumber][$eventid]['copyright'] = $text_copyright;
179
+ $thisfile_midi['comments']['copyright'][] = $text_copyright;
180
+ break;
181
+
182
+ case 0x03: // Text: track name
183
+ $text_trackname = substr($METAeventData, 0, $METAeventLength);
184
+ $thisfile_midi_raw['track'][$tracknumber]['name'] = $text_trackname;
185
+ break;
186
+
187
+ case 0x04: // Text: track instrument name
188
+ $text_instrument = substr($METAeventData, 0, $METAeventLength);
189
+ //$thisfile_midi_raw['events'][$tracknumber][$eventid]['instrument'] = $text_instrument;
190
+ break;
191
+
192
+ case 0x05: // Text: lyrics
193
+ $text_lyrics = substr($METAeventData, 0, $METAeventLength);
194
+ //$thisfile_midi_raw['events'][$tracknumber][$eventid]['lyrics'] = $text_lyrics;
195
+ if (!isset($thisfile_midi['lyrics'])) {
196
+ $thisfile_midi['lyrics'] = '';
197
+ }
198
+ $thisfile_midi['lyrics'] .= $text_lyrics."\n";
199
+ break;
200
+
201
+ case 0x06: // Text: marker
202
+ $text_marker = substr($METAeventData, 0, $METAeventLength);
203
+ //$thisfile_midi_raw['events'][$tracknumber][$eventid]['marker'] = $text_marker;
204
+ break;
205
+
206
+ case 0x07: // Text: cue point
207
+ $text_cuepoint = substr($METAeventData, 0, $METAeventLength);
208
+ //$thisfile_midi_raw['events'][$tracknumber][$eventid]['cuepoint'] = $text_cuepoint;
209
+ break;
210
+
211
+ case 0x2F: // End Of Track
212
+ //$thisfile_midi_raw['events'][$tracknumber][$eventid]['EOT'] = $CumulativeDeltaTime;
213
+ break;
214
+
215
+ case 0x51: // Tempo: microseconds / quarter note
216
+ $CurrentMicroSecondsPerBeat = getid3_lib::BigEndian2Int(substr($METAeventData, 0, $METAeventLength));
217
+ if ($CurrentMicroSecondsPerBeat == 0) {
218
+ $ThisFileInfo['error'][] = 'Corrupt MIDI file: CurrentMicroSecondsPerBeat == zero';
219
+ return false;
220
+ }
221
+ $thisfile_midi_raw['events'][$tracknumber][$CumulativeDeltaTime]['us_qnote'] = $CurrentMicroSecondsPerBeat;
222
+ $CurrentBeatsPerMinute = (1000000 / $CurrentMicroSecondsPerBeat) * 60;
223
+ $MicroSecondsPerQuarterNoteAfter[$CumulativeDeltaTime] = $CurrentMicroSecondsPerBeat;
224
+ $TicksAtCurrentBPM = 0;
225
+ break;
226
+
227
+ case 0x58: // Time signature
228
+ $timesig_numerator = getid3_lib::BigEndian2Int($METAeventData{0});
229
+ $timesig_denominator = pow(2, getid3_lib::BigEndian2Int($METAeventData{1})); // $02 -> x/4, $03 -> x/8, etc
230
+ $timesig_32inqnote = getid3_lib::BigEndian2Int($METAeventData{2}); // number of 32nd notes to the quarter note
231
+ //$thisfile_midi_raw['events'][$tracknumber][$eventid]['timesig_32inqnote'] = $timesig_32inqnote;
232
+ //$thisfile_midi_raw['events'][$tracknumber][$eventid]['timesig_numerator'] = $timesig_numerator;
233
+ //$thisfile_midi_raw['events'][$tracknumber][$eventid]['timesig_denominator'] = $timesig_denominator;
234
+ //$thisfile_midi_raw['events'][$tracknumber][$eventid]['timesig_text'] = $timesig_numerator.'/'.$timesig_denominator;
235
+ $thisfile_midi['timesignature'][] = $timesig_numerator.'/'.$timesig_denominator;
236
+ break;
237
+
238
+ case 0x59: // Keysignature
239
+ $keysig_sharpsflats = getid3_lib::BigEndian2Int($METAeventData{0});
240
+ if ($keysig_sharpsflats & 0x80) {
241
+ // (-7 -> 7 flats, 0 ->key of C, 7 -> 7 sharps)
242
+ $keysig_sharpsflats -= 256;
243
+ }
244
+
245
+ $keysig_majorminor = getid3_lib::BigEndian2Int($METAeventData{1}); // 0 -> major, 1 -> minor
246
+ $keysigs = array(-7=>'Cb', -6=>'Gb', -5=>'Db', -4=>'Ab', -3=>'Eb', -2=>'Bb', -1=>'F', 0=>'C', 1=>'G', 2=>'D', 3=>'A', 4=>'E', 5=>'B', 6=>'F#', 7=>'C#');
247
+ //$thisfile_midi_raw['events'][$tracknumber][$eventid]['keysig_sharps'] = (($keysig_sharpsflats > 0) ? abs($keysig_sharpsflats) : 0);
248
+ //$thisfile_midi_raw['events'][$tracknumber][$eventid]['keysig_flats'] = (($keysig_sharpsflats < 0) ? abs($keysig_sharpsflats) : 0);
249
+ //$thisfile_midi_raw['events'][$tracknumber][$eventid]['keysig_minor'] = (bool) $keysig_majorminor;
250
+ //$thisfile_midi_raw['events'][$tracknumber][$eventid]['keysig_text'] = $keysigs[$keysig_sharpsflats].' '.($thisfile_midi_raw['events'][$tracknumber][$eventid]['keysig_minor'] ? 'minor' : 'major');
251
+
252
+ // $keysigs[$keysig_sharpsflats] gets an int key (correct) - $keysigs["$keysig_sharpsflats"] gets a string key (incorrect)
253
+ $thisfile_midi['keysignature'][] = $keysigs[$keysig_sharpsflats].' '.((bool) $keysig_majorminor ? 'minor' : 'major');
254
+ break;
255
+
256
+ case 0x7F: // Sequencer specific information
257
+ $custom_data = substr($METAeventData, 0, $METAeventLength);
258
+ break;
259
+
260
+ default:
261
+ $ThisFileInfo['warning'][] = 'Unhandled META Event Command: '.$METAeventCommand;
262
+ break;
263
+ }
264
+
265
+ } else {
266
+
267
+ $ThisFileInfo['warning'][] = 'Unhandled MIDI Event ID: '.$MIDIevents[$tracknumber][$eventid]['eventid'].' + Channel ID: '.$MIDIevents[$tracknumber][$eventid]['channel'];
268
+
269
+ }
270
+ }
271
+ if (($tracknumber > 0) || (count($trackdataarray) == 1)) {
272
+ $thisfile_midi['totalticks'] = max($thisfile_midi['totalticks'], $CumulativeDeltaTime);
273
+ }
274
+ }
275
+ $previoustickoffset = null;
276
+
277
+ ksort($MicroSecondsPerQuarterNoteAfter);
278
+ foreach ($MicroSecondsPerQuarterNoteAfter as $tickoffset => $microsecondsperbeat) {
279
+ if (is_null($previoustickoffset)) {
280
+ $prevmicrosecondsperbeat = $microsecondsperbeat;
281
+ $previoustickoffset = $tickoffset;
282
+ continue;
283
+ }
284
+ if ($thisfile_midi['totalticks'] > $tickoffset) {
285
+
286
+ if ($thisfile_midi_raw['ticksperqnote'] == 0) {
287
+ $ThisFileInfo['error'][] = 'Corrupt MIDI file: ticksperqnote == zero';
288
+ return false;
289
+ }
290
+
291
+ $ThisFileInfo['playtime_seconds'] += (($tickoffset - $previoustickoffset) / $thisfile_midi_raw['ticksperqnote']) * ($prevmicrosecondsperbeat / 1000000);
292
+
293
+ $prevmicrosecondsperbeat = $microsecondsperbeat;
294
+ $previoustickoffset = $tickoffset;
295
+ }
296
+ }
297
+ if ($thisfile_midi['totalticks'] > $previoustickoffset) {
298
+
299
+ if ($thisfile_midi_raw['ticksperqnote'] == 0) {
300
+ $ThisFileInfo['error'][] = 'Corrupt MIDI file: ticksperqnote == zero';
301
+ return false;
302
+ }
303
+
304
+ $ThisFileInfo['playtime_seconds'] += (($thisfile_midi['totalticks'] - $previoustickoffset) / $thisfile_midi_raw['ticksperqnote']) * ($microsecondsperbeat / 1000000);
305
+
306
+ }
307
+ }
308
+
309
+
310
+ if (@$ThisFileInfo['playtime_seconds'] > 0) {
311
+ $ThisFileInfo['bitrate'] = (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8) / $ThisFileInfo['playtime_seconds'];
312
+ }
313
+
314
+ if (!empty($thisfile_midi['lyrics'])) {
315
+ $thisfile_midi['comments']['lyrics'][] = $thisfile_midi['lyrics'];
316
+ }
317
+
318
+ return true;
319
+ }
320
+
321
+ function GeneralMIDIinstrumentLookup($instrumentid) {
322
+
323
+ $begin = __LINE__;
324
+
325
+ /** This is not a comment!
326
+
327
+ 0 Acoustic Grand
328
+ 1 Bright Acoustic
329
+ 2 Electric Grand
330
+ 3 Honky-Tonk
331
+ 4 Electric Piano 1
332
+ 5 Electric Piano 2
333
+ 6 Harpsichord
334
+ 7 Clavier
335
+ 8 Celesta
336
+ 9 Glockenspiel
337
+ 10 Music Box
338
+ 11 Vibraphone
339
+ 12 Marimba
340
+ 13 Xylophone
341
+ 14 Tubular Bells
342
+ 15 Dulcimer
343
+ 16 Drawbar Organ
344
+ 17 Percussive Organ
345
+ 18 Rock Organ
346
+ 19 Church Organ
347
+ 20 Reed Organ
348
+ 21 Accordian
349
+ 22 Harmonica
350
+ 23 Tango Accordian
351
+ 24 Acoustic Guitar (nylon)
352
+ 25 Acoustic Guitar (steel)
353
+ 26 Electric Guitar (jazz)
354
+ 27 Electric Guitar (clean)
355
+ 28 Electric Guitar (muted)
356
+ 29 Overdriven Guitar
357
+ 30 Distortion Guitar
358
+ 31 Guitar Harmonics
359
+ 32 Acoustic Bass
360
+ 33 Electric Bass (finger)
361
+ 34 Electric Bass (pick)
362
+ 35 Fretless Bass
363
+ 36 Slap Bass 1
364
+ 37 Slap Bass 2
365
+ 38 Synth Bass 1
366
+ 39 Synth Bass 2
367
+ 40 Violin
368
+ 41 Viola
369
+ 42 Cello
370
+ 43 Contrabass
371
+ 44 Tremolo Strings
372
+ 45 Pizzicato Strings
373
+ 46 Orchestral Strings
374
+ 47 Timpani
375
+ 48 String Ensemble 1
376
+ 49 String Ensemble 2
377
+ 50 SynthStrings 1
378
+ 51 SynthStrings 2
379
+ 52 Choir Aahs
380
+ 53 Voice Oohs
381
+ 54 Synth Voice
382
+ 55 Orchestra Hit
383
+ 56 Trumpet
384
+ 57 Trombone
385
+ 58 Tuba
386
+ 59 Muted Trumpet
387
+ 60 French Horn
388
+ 61 Brass Section
389
+ 62 SynthBrass 1
390
+ 63 SynthBrass 2
391
+ 64 Soprano Sax
392
+ 65 Alto Sax
393
+ 66 Tenor Sax
394
+ 67 Baritone Sax
395
+ 68 Oboe
396
+ 69 English Horn
397
+ 70 Bassoon
398
+ 71 Clarinet
399
+ 72 Piccolo
400
+ 73 Flute
401
+ 74 Recorder
402
+ 75 Pan Flute
403
+ 76 Blown Bottle
404
+ 77 Shakuhachi
405
+ 78 Whistle
406
+ 79 Ocarina
407
+ 80 Lead 1 (square)
408
+ 81 Lead 2 (sawtooth)
409
+ 82 Lead 3 (calliope)
410
+ 83 Lead 4 (chiff)
411
+ 84 Lead 5 (charang)
412
+ 85 Lead 6 (voice)
413
+ 86 Lead 7 (fifths)
414
+ 87 Lead 8 (bass + lead)
415
+ 88 Pad 1 (new age)
416
+ 89 Pad 2 (warm)
417
+ 90 Pad 3 (polysynth)
418
+ 91 Pad 4 (choir)
419
+ 92 Pad 5 (bowed)
420
+ 93 Pad 6 (metallic)
421
+ 94 Pad 7 (halo)
422
+ 95 Pad 8 (sweep)
423
+ 96 FX 1 (rain)
424
+ 97 FX 2 (soundtrack)
425
+ 98 FX 3 (crystal)
426
+ 99 FX 4 (atmosphere)
427
+ 100 FX 5 (brightness)
428
+ 101 FX 6 (goblins)
429
+ 102 FX 7 (echoes)
430
+ 103 FX 8 (sci-fi)
431
+ 104 Sitar
432
+ 105 Banjo
433
+ 106 Shamisen
434
+ 107 Koto
435
+ 108 Kalimba
436
+ 109 Bagpipe
437
+ 110 Fiddle
438
+ 111 Shanai
439
+ 112 Tinkle Bell
440
+ 113 Agogo
441
+ 114 Steel Drums
442
+ 115 Woodblock
443
+ 116 Taiko Drum
444
+ 117 Melodic Tom
445
+ 118 Synth Drum
446
+ 119 Reverse Cymbal
447
+ 120 Guitar Fret Noise
448
+ 121 Breath Noise
449
+ 122 Seashore
450
+ 123 Bird Tweet
451
+ 124 Telephone Ring
452
+ 125 Helicopter
453
+ 126 Applause
454
+ 127 Gunshot
455
+
456
+ */
457
+
458
+ return getid3_lib::EmbeddedLookup($instrumentid, $begin, __LINE__, __FILE__, 'GeneralMIDIinstrument');
459
+ }
460
+
461
+ function GeneralMIDIpercussionLookup($instrumentid) {
462
+
463
+ $begin = __LINE__;
464
+
465
+ /** This is not a comment!
466
+
467
+ 35 Acoustic Bass Drum
468
+ 36 Bass Drum 1
469
+ 37 Side Stick
470
+ 38 Acoustic Snare
471
+ 39 Hand Clap
472
+ 40 Electric Snare
473
+ 41 Low Floor Tom
474
+ 42 Closed Hi-Hat
475
+ 43 High Floor Tom
476
+ 44 Pedal Hi-Hat
477
+ 45 Low Tom
478
+ 46 Open Hi-Hat
479
+ 47 Low-Mid Tom
480
+ 48 Hi-Mid Tom
481
+ 49 Crash Cymbal 1
482
+ 50 High Tom
483
+ 51 Ride Cymbal 1
484
+ 52 Chinese Cymbal
485
+ 53 Ride Bell
486
+ 54 Tambourine
487
+ 55 Splash Cymbal
488
+ 56 Cowbell
489
+ 57 Crash Cymbal 2
490
+ 59 Ride Cymbal 2
491
+ 60 Hi Bongo
492
+ 61 Low Bongo
493
+ 62 Mute Hi Conga
494
+ 63 Open Hi Conga
495
+ 64 Low Conga
496
+ 65 High Timbale
497
+ 66 Low Timbale
498
+ 67 High Agogo
499
+ 68 Low Agogo
500
+ 69 Cabasa
501
+ 70 Maracas
502
+ 71 Short Whistle
503
+ 72 Long Whistle
504
+ 73 Short Guiro
505
+ 74 Long Guiro
506
+ 75 Claves
507
+ 76 Hi Wood Block
508
+ 77 Low Wood Block
509
+ 78 Mute Cuica
510
+ 79 Open Cuica
511
+ 80 Mute Triangle
512
+ 81 Open Triangle
513
+
514
+ */
515
+
516
+ return getid3_lib::EmbeddedLookup($instrumentid, $begin, __LINE__, __FILE__, 'GeneralMIDIpercussion');
517
+ }
518
+
519
+ }
520
+
521
+
522
+ ?>
view/getid3/module.audio.mod.php ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /////////////////////////////////////////////////////////////////
3
+ /// getID3() by James Heinrich <info@getid3.org> //
4
+ // available at http://getid3.sourceforge.net //
5
+ // or http://www.getid3.org //
6
+ /////////////////////////////////////////////////////////////////
7
+ // See readme.txt for more details //
8
+ /////////////////////////////////////////////////////////////////
9
+ // //
10
+ // module.audio.mod.php //
11
+ // module for analyzing MOD Audio files //
12
+ // dependencies: NONE //
13
+ // ///
14
+ /////////////////////////////////////////////////////////////////
15
+
16
+
17
+ class getid3_mod
18
+ {
19
+
20
+ // new combined constructor
21
+ function getid3_mod(&$fd, &$ThisFileInfo, $option) {
22
+
23
+ if ($option === 'mod') {
24
+ $this->getMODheaderFilepointer($fd, $ThisFileInfo);
25
+ }
26
+ elseif ($option === 'xm') {
27
+ $this->getXMheaderFilepointer($fd, $ThisFileInfo);
28
+ }
29
+ elseif ($option === 'it') {
30
+ $this->getITheaderFilepointer($fd, $ThisFileInfo);
31
+ }
32
+ elseif ($option === 's3m') {
33
+ $this->getS3MheaderFilepointer($fd, $ThisFileInfo);
34
+ }
35
+ }
36
+
37
+
38
+ function getMODheaderFilepointer(&$fd, &$ThisFileInfo) {
39
+
40
+ fseek($fd, $ThisFileInfo['avdataoffset'] + 1080);
41
+ $FormatID = fread($fd, 4);
42
+ if (!ereg('^(M.K.|[5-9]CHN|[1-3][0-9]CH)$', $FormatID)) {
43
+ $ThisFileInfo['error'][] = 'This is not a known type of MOD file';
44
+ return false;
45
+ }
46
+
47
+ $ThisFileInfo['fileformat'] = 'mod';
48
+
49
+ $ThisFileInfo['error'][] = 'MOD parsing not enabled in this version of getID3()';
50
+ return false;
51
+ }
52
+
53
+ function getXMheaderFilepointer(&$fd, &$ThisFileInfo) {
54
+
55
+ fseek($fd, $ThisFileInfo['avdataoffset']);
56
+ $FormatID = fread($fd, 15);
57
+ if (!ereg('^Extended Module$', $FormatID)) {
58
+ $ThisFileInfo['error'][] = 'This is not a known type of XM-MOD file';
59
+ return false;
60
+ }
61
+
62
+ $ThisFileInfo['fileformat'] = 'xm';
63
+
64
+ $ThisFileInfo['error'][] = 'XM-MOD parsing not enabled in this version of getID3()';
65
+ return false;
66
+ }
67
+
68
+ function getS3MheaderFilepointer(&$fd, &$ThisFileInfo) {
69
+
70
+ fseek($fd, $ThisFileInfo['avdataoffset'] + 44);
71
+ $FormatID = fread($fd, 4);
72
+ if (!ereg('^SCRM$', $FormatID)) {
73
+ $ThisFileInfo['error'][] = 'This is not a ScreamTracker MOD file';
74
+ return false;
75
+ }
76
+
77
+ $ThisFileInfo['fileformat'] = 's3m';
78
+
79
+ $ThisFileInfo['error'][] = 'ScreamTracker parsing not enabled in this version of getID3()';
80
+ return false;
81
+ }
82
+
83
+ function getITheaderFilepointer(&$fd, &$ThisFileInfo) {
84
+
85
+ fseek($fd, $ThisFileInfo['avdataoffset']);
86
+ $FormatID = fread($fd, 4);
87
+ if (!ereg('^IMPM$', $FormatID)) {
88
+ $ThisFileInfo['error'][] = 'This is not an ImpulseTracker MOD file';
89
+ return false;
90
+ }
91
+
92
+ $ThisFileInfo['fileformat'] = 'it';
93
+
94
+ $ThisFileInfo['error'][] = 'ImpulseTracker parsing not enabled in this version of getID3()';
95
+ return false;
96
+ }
97
+
98
+ }
99
+
100
+
101
+ ?>
view/getid3/module.audio.monkey.php ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /////////////////////////////////////////////////////////////////
3
+ /// getID3() by James Heinrich <info@getid3.org> //
4
+ // available at http://getid3.sourceforge.net //
5
+ // or http://www.getid3.org //
6
+ /////////////////////////////////////////////////////////////////
7
+ // See readme.txt for more details //
8
+ /////////////////////////////////////////////////////////////////
9
+ // //
10
+ // module.audio.monkey.php //
11
+ // module for analyzing Monkey's Audio files //
12
+ // dependencies: NONE //
13
+ // ///
14
+ /////////////////////////////////////////////////////////////////
15
+
16
+
17
+ class getid3_monkey
18
+ {
19
+
20
+ function getid3_monkey(&$fd, &$ThisFileInfo) {
21
+ // based loosely on code from TMonkey by Jurgen Faul <jfaul�gmx*de>
22
+ // http://jfaul.de/atl or http://j-faul.virtualave.net/atl/atl.html
23
+
24
+ $ThisFileInfo['fileformat'] = 'mac';
25
+ $ThisFileInfo['audio']['dataformat'] = 'mac';
26
+ $ThisFileInfo['audio']['bitrate_mode'] = 'vbr';
27
+ $ThisFileInfo['audio']['lossless'] = true;
28
+
29
+ $ThisFileInfo['monkeys_audio']['raw'] = array();
30
+ $thisfile_monkeysaudio = &$ThisFileInfo['monkeys_audio'];
31
+ $thisfile_monkeysaudio_raw = &$thisfile_monkeysaudio['raw'];
32
+
33
+ fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
34
+ $MACheaderData = fread($fd, 74);
35
+
36
+ $thisfile_monkeysaudio_raw['magic'] = substr($MACheaderData, 0, 4);
37
+ if ($thisfile_monkeysaudio_raw['magic'] != 'MAC ') {
38
+ $ThisFileInfo['error'][] = 'Expecting "MAC" at offset '.$ThisFileInfo['avdataoffset'].', found "'.$thisfile_monkeysaudio_raw['magic'].'"';
39
+ unset($ThisFileInfo['fileformat']);
40
+ return false;
41
+ }
42
+ $thisfile_monkeysaudio_raw['nVersion'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 4, 2)); // appears to be uint32 in 3.98+
43
+
44
+ if ($thisfile_monkeysaudio_raw['nVersion'] < 3980) {
45
+ $thisfile_monkeysaudio_raw['nCompressionLevel'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 6, 2));
46
+ $thisfile_monkeysaudio_raw['nFormatFlags'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 8, 2));
47
+ $thisfile_monkeysaudio_raw['nChannels'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 10, 2));
48
+ $thisfile_monkeysaudio_raw['nSampleRate'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 12, 4));
49
+ $thisfile_monkeysaudio_raw['nHeaderDataBytes'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 16, 4));
50
+ $thisfile_monkeysaudio_raw['nWAVTerminatingBytes'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 20, 4));
51
+ $thisfile_monkeysaudio_raw['nTotalFrames'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 24, 4));
52
+ $thisfile_monkeysaudio_raw['nFinalFrameSamples'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 28, 4));
53
+ $thisfile_monkeysaudio_raw['nPeakLevel'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 32, 4));
54
+ $thisfile_monkeysaudio_raw['nSeekElements'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 38, 2));
55
+ $offset = 8;
56
+ } else {
57
+ $offset = 8;
58
+ // APE_DESCRIPTOR
59
+ $thisfile_monkeysaudio_raw['nDescriptorBytes'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4));
60
+ $offset += 4;
61
+ $thisfile_monkeysaudio_raw['nHeaderBytes'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4));
62
+ $offset += 4;
63
+ $thisfile_monkeysaudio_raw['nSeekTableBytes'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4));
64
+ $offset += 4;
65
+ $thisfile_monkeysaudio_raw['nHeaderDataBytes'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4));
66
+ $offset += 4;
67
+ $thisfile_monkeysaudio_raw['nAPEFrameDataBytes'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4));
68
+ $offset += 4;
69
+ $thisfile_monkeysaudio_raw['nAPEFrameDataBytesHigh'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4));
70
+ $offset += 4;
71
+ $thisfile_monkeysaudio_raw['nTerminatingDataBytes'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4));
72
+ $offset += 4;
73
+ $thisfile_monkeysaudio_raw['cFileMD5'] = substr($MACheaderData, $offset, 16);
74
+ $offset += 16;
75
+
76
+ // APE_HEADER
77
+ $thisfile_monkeysaudio_raw['nCompressionLevel'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 2));
78
+ $offset += 2;
79
+ $thisfile_monkeysaudio_raw['nFormatFlags'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 2));
80
+ $offset += 2;
81
+ $thisfile_monkeysaudio_raw['nBlocksPerFrame'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4));
82
+ $offset += 4;
83
+ $thisfile_monkeysaudio_raw['nFinalFrameBlocks'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4));
84
+ $offset += 4;
85
+ $thisfile_monkeysaudio_raw['nTotalFrames'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4));
86
+ $offset += 4;
87
+ $thisfile_monkeysaudio_raw['nBitsPerSample'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 2));
88
+ $offset += 2;
89
+ $thisfile_monkeysaudio_raw['nChannels'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 2));
90
+ $offset += 2;
91
+ $thisfile_monkeysaudio_raw['nSampleRate'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4));
92
+ $offset += 4;
93
+ }
94
+
95
+ $thisfile_monkeysaudio['flags']['8-bit'] = (bool) ($thisfile_monkeysaudio_raw['nFormatFlags'] & 0x0001);
96
+ $thisfile_monkeysaudio['flags']['crc-32'] = (bool) ($thisfile_monkeysaudio_raw['nFormatFlags'] & 0x0002);
97
+ $thisfile_monkeysaudio['flags']['peak_level'] = (bool) ($thisfile_monkeysaudio_raw['nFormatFlags'] & 0x0004);
98
+ $thisfile_monkeysaudio['flags']['24-bit'] = (bool) ($thisfile_monkeysaudio_raw['nFormatFlags'] & 0x0008);
99
+ $thisfile_monkeysaudio['flags']['seek_elements'] = (bool) ($thisfile_monkeysaudio_raw['nFormatFlags'] & 0x0010);
100
+ $thisfile_monkeysaudio['flags']['no_wav_header'] = (bool) ($thisfile_monkeysaudio_raw['nFormatFlags'] & 0x0020);
101
+ $thisfile_monkeysaudio['version'] = $thisfile_monkeysaudio_raw['nVersion'] / 1000;
102
+ $thisfile_monkeysaudio['compression'] = $this->MonkeyCompressionLevelNameLookup($thisfile_monkeysaudio_raw['nCompressionLevel']);
103
+ if ($thisfile_monkeysaudio_raw['nVersion'] < 3980) {
104
+ $thisfile_monkeysaudio['samples_per_frame'] = $this->MonkeySamplesPerFrame($thisfile_monkeysaudio_raw['nVersion'], $thisfile_monkeysaudio_raw['nCompressionLevel']);
105
+ }
106
+ $thisfile_monkeysaudio['bits_per_sample'] = ($thisfile_monkeysaudio['flags']['24-bit'] ? 24 : ($thisfile_monkeysaudio['flags']['8-bit'] ? 8 : 16));
107
+ $thisfile_monkeysaudio['channels'] = $thisfile_monkeysaudio_raw['nChannels'];
108
+ $ThisFileInfo['audio']['channels'] = $thisfile_monkeysaudio['channels'];
109
+ $thisfile_monkeysaudio['sample_rate'] = $thisfile_monkeysaudio_raw['nSampleRate'];
110
+ if ($thisfile_monkeysaudio['sample_rate'] == 0) {
111
+ $ThisFileInfo['error'][] = 'Corrupt MAC file: frequency == zero';
112
+ return false;
113
+ }
114
+ $ThisFileInfo['audio']['sample_rate'] = $thisfile_monkeysaudio['sample_rate'];
115
+ if ($thisfile_monkeysaudio['flags']['peak_level']) {
116
+ $thisfile_monkeysaudio['peak_level'] = $thisfile_monkeysaudio_raw['nPeakLevel'];
117
+ $thisfile_monkeysaudio['peak_ratio'] = $thisfile_monkeysaudio['peak_level'] / pow(2, $thisfile_monkeysaudio['bits_per_sample'] - 1);
118
+ }
119
+ if ($thisfile_monkeysaudio_raw['nVersion'] >= 3980) {
120
+ $thisfile_monkeysaudio['samples'] = (($thisfile_monkeysaudio_raw['nTotalFrames'] - 1) * $thisfile_monkeysaudio_raw['nBlocksPerFrame']) + $thisfile_monkeysaudio_raw['nFinalFrameBlocks'];
121
+ } else {
122
+ $thisfile_monkeysaudio['samples'] = (($thisfile_monkeysaudio_raw['nTotalFrames'] - 1) * $thisfile_monkeysaudio['samples_per_frame']) + $thisfile_monkeysaudio_raw['nFinalFrameSamples'];
123
+ }
124
+ $thisfile_monkeysaudio['playtime'] = $thisfile_monkeysaudio['samples'] / $thisfile_monkeysaudio['sample_rate'];
125
+ if ($thisfile_monkeysaudio['playtime'] == 0) {
126
+ $ThisFileInfo['error'][] = 'Corrupt MAC file: playtime == zero';
127
+ return false;
128
+ }
129
+ $ThisFileInfo['playtime_seconds'] = $thisfile_monkeysaudio['playtime'];
130
+ $thisfile_monkeysaudio['compressed_size'] = $ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset'];
131
+ $thisfile_monkeysaudio['uncompressed_size'] = $thisfile_monkeysaudio['samples'] * $thisfile_monkeysaudio['channels'] * ($thisfile_monkeysaudio['bits_per_sample'] / 8);
132
+ if ($thisfile_monkeysaudio['uncompressed_size'] == 0) {
133
+ $ThisFileInfo['error'][] = 'Corrupt MAC file: uncompressed_size == zero';
134
+ return false;
135
+ }
136
+ $thisfile_monkeysaudio['compression_ratio'] = $thisfile_monkeysaudio['compressed_size'] / ($thisfile_monkeysaudio['uncompressed_size'] + $thisfile_monkeysaudio_raw['nHeaderDataBytes']);
137
+ $thisfile_monkeysaudio['bitrate'] = (($thisfile_monkeysaudio['samples'] * $thisfile_monkeysaudio['channels'] * $thisfile_monkeysaudio['bits_per_sample']) / $thisfile_monkeysaudio['playtime']) * $thisfile_monkeysaudio['compression_ratio'];
138
+ $ThisFileInfo['audio']['bitrate'] = $thisfile_monkeysaudio['bitrate'];
139
+
140
+ // add size of MAC header to avdataoffset
141
+ if ($thisfile_monkeysaudio_raw['nVersion'] >= 3980) {
142
+ $ThisFileInfo['avdataoffset'] += $thisfile_monkeysaudio_raw['nDescriptorBytes'];
143
+ $ThisFileInfo['avdataoffset'] += $thisfile_monkeysaudio_raw['nHeaderBytes'];
144
+ $ThisFileInfo['avdataoffset'] += $thisfile_monkeysaudio_raw['nSeekTableBytes'];
145
+ $ThisFileInfo['avdataoffset'] += $thisfile_monkeysaudio_raw['nHeaderDataBytes'];
146
+
147
+ $ThisFileInfo['avdataend'] -= $thisfile_monkeysaudio_raw['nTerminatingDataBytes'];
148
+ } else {
149
+ $ThisFileInfo['avdataoffset'] += $offset;
150
+ }
151
+
152
+ if ($thisfile_monkeysaudio_raw['nVersion'] >= 3980) {
153
+ if ($thisfile_monkeysaudio_raw['cFileMD5'] === str_repeat("\x00", 16)) {
154
+ //$ThisFileInfo['warning'][] = 'cFileMD5 is null';
155
+ } else {
156
+ $ThisFileInfo['md5_data_source'] = '';
157
+ $md5 = $thisfile_monkeysaudio_raw['cFileMD5'];
158
+ for ($i = 0; $i < strlen($md5); $i++) {
159
+ $ThisFileInfo['md5_data_source'] .= str_pad(dechex(ord($md5{$i})), 2, '00', STR_PAD_LEFT);
160
+ }
161
+ if (!preg_match('/^[0-9a-f]{32}$/', $ThisFileInfo['md5_data_source'])) {
162
+ unset($ThisFileInfo['md5_data_source']);
163
+ }
164
+ }
165
+ }
166
+
167
+
168
+
169
+ $ThisFileInfo['audio']['bits_per_sample'] = $thisfile_monkeysaudio['bits_per_sample'];
170
+ $ThisFileInfo['audio']['encoder'] = 'MAC v'.number_format($thisfile_monkeysaudio['version'], 2);
171
+ $ThisFileInfo['audio']['encoder_options'] = ucfirst($thisfile_monkeysaudio['compression']).' compression';
172
+
173
+ return true;
174
+ }
175
+
176
+ function MonkeyCompressionLevelNameLookup($compressionlevel) {
177
+ static $MonkeyCompressionLevelNameLookup = array(
178
+ 0 => 'unknown',
179
+ 1000 => 'fast',
180
+ 2000 => 'normal',
181
+ 3000 => 'high',
182
+ 4000 => 'extra-high',
183
+ 5000 => 'insane'
184
+ );
185
+ return (isset($MonkeyCompressionLevelNameLookup[$compressionlevel]) ? $MonkeyCompressionLevelNameLookup[$compressionlevel] : 'invalid');
186
+ }
187
+
188
+ function MonkeySamplesPerFrame($versionid, $compressionlevel) {
189
+ if ($versionid >= 3950) {
190
+ return 73728 * 4;
191
+ } elseif ($versionid >= 3900) {
192
+ return 73728;
193
+ } elseif (($versionid >= 3800) && ($compressionlevel == 4000)) {
194
+ return 73728;
195
+ } else {
196
+ return 9216;
197
+ }
198
+ }
199
+
200
+ }
201
+
202
+ ?>
view/getid3/module.audio.mp3.php ADDED
@@ -0,0 +1,2022 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /////////////////////////////////////////////////////////////////
3
+ /// getID3() by James Heinrich <info@getid3.org> //
4
+ // available at http://getid3.sourceforge.net //
5
+ // or http://www.getid3.org //
6
+ /////////////////////////////////////////////////////////////////
7
+ // See readme.txt for more details //
8
+ /////////////////////////////////////////////////////////////////
9
+ // //
10
+ // module.audio.mp3.php //
11
+ // module for analyzing MP3 files //
12
+ // dependencies: NONE //
13
+ // ///
14
+ /////////////////////////////////////////////////////////////////
15
+
16
+
17
+ // number of frames to scan to determine if MPEG-audio sequence is valid
18
+ // Lower this number to 5-20 for faster scanning
19
+ // Increase this number to 50+ for most accurate detection of valid VBR/CBR
20
+ // mpeg-audio streams
21
+ define('GETID3_MP3_VALID_CHECK_FRAMES', 35);
22
+
23
+
24
+ class getid3_mp3
25
+ {
26
+
27
+ var $allow_bruteforce = false; // forces getID3() to scan the file byte-by-byte and log all the valid audio frame headers - extremely slow, unrecommended, but may provide data from otherwise-unusuable files
28
+
29
+ function getid3_mp3(&$fd, &$ThisFileInfo) {
30
+
31
+ if (!$this->getOnlyMPEGaudioInfo($fd, $ThisFileInfo, $ThisFileInfo['avdataoffset'])) {
32
+ if ($this->allow_bruteforce) {
33
+ $ThisFileInfo['error'][] = 'Rescanning file in BruteForce mode';
34
+ $this->getOnlyMPEGaudioInfoBruteForce($fd, $ThisFileInfo);
35
+ }
36
+ }
37
+
38
+
39
+ if (isset($ThisFileInfo['mpeg']['audio']['bitrate_mode'])) {
40
+ $ThisFileInfo['audio']['bitrate_mode'] = strtolower($ThisFileInfo['mpeg']['audio']['bitrate_mode']);
41
+ }
42
+
43
+ if (((isset($ThisFileInfo['id3v2']['headerlength']) && ($ThisFileInfo['avdataoffset'] > $ThisFileInfo['id3v2']['headerlength'])) || (!isset($ThisFileInfo['id3v2']) && ($ThisFileInfo['avdataoffset'] > 0)))) {
44
+
45
+ $synchoffsetwarning = 'Unknown data before synch ';
46
+ if (isset($ThisFileInfo['id3v2']['headerlength'])) {
47
+ $synchoffsetwarning .= '(ID3v2 header ends at '.$ThisFileInfo['id3v2']['headerlength'].', then '.($ThisFileInfo['avdataoffset'] - $ThisFileInfo['id3v2']['headerlength']).' bytes garbage, ';
48
+ } else {
49
+ $synchoffsetwarning .= '(should be at beginning of file, ';
50
+ }
51
+ $synchoffsetwarning .= 'synch detected at '.$ThisFileInfo['avdataoffset'].')';
52
+ if (@$ThisFileInfo['audio']['bitrate_mode'] == 'cbr') {
53
+
54
+ if (!empty($ThisFileInfo['id3v2']['headerlength']) && (($ThisFileInfo['avdataoffset'] - $ThisFileInfo['id3v2']['headerlength']) == $ThisFileInfo['mpeg']['audio']['framelength'])) {
55
+
56
+ $synchoffsetwarning .= '. This is a known problem with some versions of LAME (3.90-3.92) DLL in CBR mode.';
57
+ $ThisFileInfo['audio']['codec'] = 'LAME';
58
+ $CurrentDataLAMEversionString = 'LAME3.';
59
+
60
+ } elseif (empty($ThisFileInfo['id3v2']['headerlength']) && ($ThisFileInfo['avdataoffset'] == $ThisFileInfo['mpeg']['audio']['framelength'])) {
61
+
62
+ $synchoffsetwarning .= '. This is a known problem with some versions of LAME (3.90 - 3.92) DLL in CBR mode.';
63
+ $ThisFileInfo['audio']['codec'] = 'LAME';
64
+ $CurrentDataLAMEversionString = 'LAME3.';
65
+
66
+ }
67
+
68
+ }
69
+ $ThisFileInfo['warning'][] = $synchoffsetwarning;
70
+
71
+ }
72
+
73
+ if (isset($ThisFileInfo['mpeg']['audio']['LAME'])) {
74
+ $ThisFileInfo['audio']['codec'] = 'LAME';
75
+ if (!empty($ThisFileInfo['mpeg']['audio']['LAME']['long_version'])) {
76
+ $ThisFileInfo['audio']['encoder'] = rtrim($ThisFileInfo['mpeg']['audio']['LAME']['long_version'], "\x00");
77
+ } elseif (!empty($ThisFileInfo['mpeg']['audio']['LAME']['short_version'])) {
78
+ $ThisFileInfo['audio']['encoder'] = rtrim($ThisFileInfo['mpeg']['audio']['LAME']['short_version'], "\x00");
79
+ }
80
+ }
81
+
82
+ $CurrentDataLAMEversionString = (!empty($CurrentDataLAMEversionString) ? $CurrentDataLAMEversionString : @$ThisFileInfo['audio']['encoder']);
83
+ if (!empty($CurrentDataLAMEversionString) && (substr($CurrentDataLAMEversionString, 0, 6) == 'LAME3.') && !preg_match('[0-9\)]', substr($CurrentDataLAMEversionString, -1))) {
84
+ // a version number of LAME that does not end with a number like "LAME3.92"
85
+ // or with a closing parenthesis like "LAME3.88 (alpha)"
86
+ // or a version of LAME with the LAMEtag-not-filled-in-DLL-mode bug (3.90-3.92)
87
+
88
+ // not sure what the actual last frame length will be, but will be less than or equal to 1441
89
+ $PossiblyLongerLAMEversion_FrameLength = 1441;
90
+
91
+ // Not sure what version of LAME this is - look in padding of last frame for longer version string
92
+ $PossibleLAMEversionStringOffset = $ThisFileInfo['avdataend'] - $PossiblyLongerLAMEversion_FrameLength;
93
+ fseek($fd, $PossibleLAMEversionStringOffset);
94
+ $PossiblyLongerLAMEversion_Data = fread($fd, $PossiblyLongerLAMEversion_FrameLength);
95
+ switch (substr($CurrentDataLAMEversionString, -1)) {
96
+ case 'a':
97
+ case 'b':
98
+ // "LAME3.94a" will have a longer version string of "LAME3.94 (alpha)" for example
99
+ // need to trim off "a" to match longer string
100
+ $CurrentDataLAMEversionString = substr($CurrentDataLAMEversionString, 0, -1);
101
+ break;
102
+ }
103
+ if (($PossiblyLongerLAMEversion_String = strstr($PossiblyLongerLAMEversion_Data, $CurrentDataLAMEversionString)) !== false) {
104
+ if (substr($PossiblyLongerLAMEversion_String, 0, strlen($CurrentDataLAMEversionString)) == $CurrentDataLAMEversionString) {
105
+ $PossiblyLongerLAMEversion_NewString = substr($PossiblyLongerLAMEversion_String, 0, strspn($PossiblyLongerLAMEversion_String, 'LAME0123456789., (abcdefghijklmnopqrstuvwxyzJFSOND)')); //"LAME3.90.3" "LAME3.87 (beta 1, Sep 27 2000)" "LAME3.88 (beta)"
106
+ if (strlen($PossiblyLongerLAMEversion_NewString) > strlen(@$ThisFileInfo['audio']['encoder'])) {
107
+ $ThisFileInfo['audio']['encoder'] = $PossiblyLongerLAMEversion_NewString;
108
+ }
109
+ }
110
+ }
111
+ }
112
+ if (!empty($ThisFileInfo['audio']['encoder'])) {
113
+ $ThisFileInfo['audio']['encoder'] = rtrim($ThisFileInfo['audio']['encoder'], "\x00 ");
114
+ }
115
+
116
+ switch (@$ThisFileInfo['mpeg']['audio']['layer']) {
117
+ case 1:
118
+ case 2:
119
+ $ThisFileInfo['audio']['dataformat'] = 'mp'.$ThisFileInfo['mpeg']['audio']['layer'];
120
+ break;
121
+ }
122
+ if (@$ThisFileInfo['fileformat'] == 'mp3') {
123
+ switch ($ThisFileInfo['audio']['dataformat']) {
124
+ case 'mp1':
125
+ case 'mp2':
126
+ case 'mp3':
127
+ $ThisFileInfo['fileformat'] = $ThisFileInfo['audio']['dataformat'];
128
+ break;
129
+
130
+ default:
131
+ $ThisFileInfo['warning'][] = 'Expecting [audio][dataformat] to be mp1/mp2/mp3 when fileformat == mp3, [audio][dataformat] actually "'.$ThisFileInfo['audio']['dataformat'].'"';
132
+ break;
133
+ }
134
+ }
135
+
136
+ if (empty($ThisFileInfo['fileformat'])) {
137
+ unset($ThisFileInfo['fileformat']);
138
+ unset($ThisFileInfo['audio']['bitrate_mode']);
139
+ unset($ThisFileInfo['avdataoffset']);
140
+ unset($ThisFileInfo['avdataend']);
141
+ return false;
142
+ }
143
+
144
+ $ThisFileInfo['mime_type'] = 'audio/mpeg';
145
+ $ThisFileInfo['audio']['lossless'] = false;
146
+
147
+ // Calculate playtime
148
+ if (!isset($ThisFileInfo['playtime_seconds']) && isset($ThisFileInfo['audio']['bitrate']) && ($ThisFileInfo['audio']['bitrate'] > 0)) {
149
+ $ThisFileInfo['playtime_seconds'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8 / $ThisFileInfo['audio']['bitrate'];
150
+ }
151
+
152
+ $ThisFileInfo['audio']['encoder_options'] = $this->GuessEncoderOptions($ThisFileInfo);
153
+
154
+ return true;
155
+ }
156
+
157
+
158
+ function GuessEncoderOptions(&$ThisFileInfo) {
159
+ // shortcuts
160
+ if (!empty($ThisFileInfo['mpeg']['audio'])) {
161
+ $thisfile_mpeg_audio = &$ThisFileInfo['mpeg']['audio'];
162
+ if (!empty($thisfile_mpeg_audio['LAME'])) {
163
+ $thisfile_mpeg_audio_lame = &$thisfile_mpeg_audio['LAME'];
164
+ }
165
+ }
166
+
167
+ $encoder_options = '';
168
+ static $NamedPresetBitrates = array(16, 24, 40, 56, 112, 128, 160, 192, 256);
169
+
170
+ if ((@$thisfile_mpeg_audio['VBR_method'] == 'Fraunhofer') && !empty($thisfile_mpeg_audio['VBR_quality'])) {
171
+
172
+ $encoder_options = 'VBR q'.$thisfile_mpeg_audio['VBR_quality'];
173
+
174
+ } elseif (!empty($thisfile_mpeg_audio_lame['preset_used']) && (!in_array($thisfile_mpeg_audio_lame['preset_used_id'], $NamedPresetBitrates))) {
175
+
176
+ $encoder_options = $thisfile_mpeg_audio_lame['preset_used'];
177
+
178
+ } elseif (!empty($thisfile_mpeg_audio_lame['vbr_quality'])) {
179
+
180
+ static $KnownEncoderValues = array();
181
+ if (empty($KnownEncoderValues)) {
182
+
183
+ //$KnownEncoderValues[abrbitrate_minbitrate][vbr_quality][raw_vbr_method][raw_noise_shaping][raw_stereo_mode][ath_type][lowpass_frequency] = 'preset name';
184
+ $KnownEncoderValues[0xFF][58][1][1][3][2][20500] = '--alt-preset insane'; // 3.90, 3.90.1, 3.92
185
+ $KnownEncoderValues[0xFF][58][1][1][3][2][20600] = '--alt-preset insane'; // 3.90.2, 3.90.3, 3.91
186
+ $KnownEncoderValues[0xFF][57][1][1][3][4][20500] = '--alt-preset insane'; // 3.94, 3.95
187
+ $KnownEncoderValues['**'][78][3][2][3][2][19500] = '--alt-preset extreme'; // 3.90, 3.90.1, 3.92
188
+ $KnownEncoderValues['**'][78][3][2][3][2][19600] = '--alt-preset extreme'; // 3.90.2, 3.91
189
+ $KnownEncoderValues['**'][78][3][1][3][2][19600] = '--alt-preset extreme'; // 3.90.3
190
+ $KnownEncoderValues['**'][78][4][2][3][2][19500] = '--alt-preset fast extreme'; // 3.90, 3.90.1, 3.92
191
+ $KnownEncoderValues['**'][78][4][2][3][2][19600] = '--alt-preset fast extreme'; // 3.90.2, 3.90.3, 3.91
192
+ $KnownEncoderValues['**'][78][3][2][3][4][19000] = '--alt-preset standard'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92
193
+ $KnownEncoderValues['**'][78][3][1][3][4][19000] = '--alt-preset standard'; // 3.90.3
194
+ $KnownEncoderValues['**'][78][4][2][3][4][19000] = '--alt-preset fast standard'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92
195
+ $KnownEncoderValues['**'][78][4][1][3][4][19000] = '--alt-preset fast standard'; // 3.90.3
196
+ $KnownEncoderValues['**'][88][4][1][3][3][19500] = '--r3mix'; // 3.90, 3.90.1, 3.92
197
+ $KnownEncoderValues['**'][88][4][1][3][3][19600] = '--r3mix'; // 3.90.2, 3.90.3, 3.91
198
+ $KnownEncoderValues['**'][67][4][1][3][4][18000] = '--r3mix'; // 3.94, 3.95
199
+ $KnownEncoderValues['**'][68][3][2][3][4][18000] = '--alt-preset medium'; // 3.90.3
200
+ $KnownEncoderValues['**'][68][4][2][3][4][18000] = '--alt-preset fast medium'; // 3.90.3
201
+
202
+ $KnownEncoderValues[0xFF][99][1][1][1][2][0] = '--preset studio'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92
203
+ $KnownEncoderValues[0xFF][58][2][1][3][2][20600] = '--preset studio'; // 3.90.3, 3.93.1
204
+ $KnownEncoderValues[0xFF][58][2][1][3][2][20500] = '--preset studio'; // 3.93
205
+ $KnownEncoderValues[0xFF][57][2][1][3][4][20500] = '--preset studio'; // 3.94, 3.95
206
+ $KnownEncoderValues[0xC0][88][1][1][1][2][0] = '--preset cd'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92
207
+ $KnownEncoderValues[0xC0][58][2][2][3][2][19600] = '--preset cd'; // 3.90.3, 3.93.1
208
+ $KnownEncoderValues[0xC0][58][2][2][3][2][19500] = '--preset cd'; // 3.93
209
+ $KnownEncoderValues[0xC0][57][2][1][3][4][19500] = '--preset cd'; // 3.94, 3.95
210
+ $KnownEncoderValues[0xA0][78][1][1][3][2][18000] = '--preset hifi'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92
211
+ $KnownEncoderValues[0xA0][58][2][2][3][2][18000] = '--preset hifi'; // 3.90.3, 3.93, 3.93.1
212
+ $KnownEncoderValues[0xA0][57][2][1][3][4][18000] = '--preset hifi'; // 3.94, 3.95
213
+ $KnownEncoderValues[0x80][67][1][1][3][2][18000] = '--preset tape'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92
214
+ $KnownEncoderValues[0x80][67][1][1][3][2][15000] = '--preset radio'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92
215
+ $KnownEncoderValues[0x70][67][1][1][3][2][15000] = '--preset fm'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92
216
+ $KnownEncoderValues[0x70][58][2][2][3][2][16000] = '--preset tape/radio/fm'; // 3.90.3, 3.93, 3.93.1
217
+ $KnownEncoderValues[0x70][57][2][1][3][4][16000] = '--preset tape/radio/fm'; // 3.94, 3.95
218
+ $KnownEncoderValues[0x38][58][2][2][0][2][10000] = '--preset voice'; // 3.90.3, 3.93, 3.93.1
219
+ $KnownEncoderValues[0x38][57][2][1][0][4][15000] = '--preset voice'; // 3.94, 3.95
220
+ $KnownEncoderValues[0x38][57][2][1][0][4][16000] = '--preset voice'; // 3.94a14
221
+ $KnownEncoderValues[0x28][65][1][1][0][2][7500] = '--preset mw-us'; // 3.90, 3.90.1, 3.92
222
+ $KnownEncoderValues[0x28][65][1][1][0][2][7600] = '--preset mw-us'; // 3.90.2, 3.91
223
+ $KnownEncoderValues[0x28][58][2][2][0][2][7000] = '--preset mw-us'; // 3.90.3, 3.93, 3.93.1
224
+ $KnownEncoderValues[0x28][57][2][1][0][4][10500] = '--preset mw-us'; // 3.94, 3.95
225
+ $KnownEncoderValues[0x28][57][2][1][0][4][11200] = '--preset mw-us'; // 3.94a14
226
+ $KnownEncoderValues[0x28][57][2][1][0][4][8800] = '--preset mw-us'; // 3.94a15
227
+ $KnownEncoderValues[0x18][58][2][2][0][2][4000] = '--preset phon+/lw/mw-eu/sw'; // 3.90.3, 3.93.1
228
+ $KnownEncoderValues[0x18][58][2][2][0][2][3900] = '--preset phon+/lw/mw-eu/sw'; // 3.93
229
+ $KnownEncoderValues[0x18][57][2][1][0][4][5900] = '--preset phon+/lw/mw-eu/sw'; // 3.94, 3.95
230
+ $KnownEncoderValues[0x18][57][2][1][0][4][6200] = '--preset phon+/lw/mw-eu/sw'; // 3.94a14
231
+ $KnownEncoderValues[0x18][57][2][1][0][4][3200] = '--preset phon+/lw/mw-eu/sw'; // 3.94a15
232
+ $KnownEncoderValues[0x10][58][2][2][0][2][3800] = '--preset phone'; // 3.90.3, 3.93.1
233
+ $KnownEncoderValues[0x10][58][2][2][0][2][3700] = '--preset phone'; // 3.93
234
+ $KnownEncoderValues[0x10][57][2][1][0][4][5600] = '--preset phone'; // 3.94, 3.95
235
+ }
236
+
237
+ if (isset($KnownEncoderValues[$thisfile_mpeg_audio_lame['raw']['abrbitrate_minbitrate']][$thisfile_mpeg_audio_lame['vbr_quality']][$thisfile_mpeg_audio_lame['raw']['vbr_method']][$thisfile_mpeg_audio_lame['raw']['noise_shaping']][$thisfile_mpeg_audio_lame['raw']['stereo_mode']][$thisfile_mpeg_audio_lame['ath_type']][$thisfile_mpeg_audio_lame['lowpass_frequency']])) {
238
+
239
+ $encoder_options = $KnownEncoderValues[$thisfile_mpeg_audio_lame['raw']['abrbitrate_minbitrate']][$thisfile_mpeg_audio_lame['vbr_quality']][$thisfile_mpeg_audio_lame['raw']['vbr_method']][$thisfile_mpeg_audio_lame['raw']['noise_shaping']][$thisfile_mpeg_audio_lame['raw']['stereo_mode']][$thisfile_mpeg_audio_lame['ath_type']][$thisfile_mpeg_audio_lame['lowpass_frequency']];
240
+
241
+ } elseif (isset($KnownEncoderValues['**'][$thisfile_mpeg_audio_lame['vbr_quality']][$thisfile_mpeg_audio_lame['raw']['vbr_method']][$thisfile_mpeg_audio_lame['raw']['noise_shaping']][$thisfile_mpeg_audio_lame['raw']['stereo_mode']][$thisfile_mpeg_audio_lame['ath_type']][$thisfile_mpeg_audio_lame['lowpass_frequency']])) {
242
+
243
+ $encoder_options = $KnownEncoderValues['**'][$thisfile_mpeg_audio_lame['vbr_quality']][$thisfile_mpeg_audio_lame['raw']['vbr_method']][$thisfile_mpeg_audio_lame['raw']['noise_shaping']][$thisfile_mpeg_audio_lame['raw']['stereo_mode']][$thisfile_mpeg_audio_lame['ath_type']][$thisfile_mpeg_audio_lame['lowpass_frequency']];
244
+
245
+ } elseif ($ThisFileInfo['audio']['bitrate_mode'] == 'vbr') {
246
+
247
+ // http://gabriel.mp3-tech.org/mp3infotag.html
248
+ // int Quality = (100 - 10 * gfp->VBR_q - gfp->quality)h
249
+
250
+
251
+ $LAME_V_value = 10 - ceil($thisfile_mpeg_audio_lame['vbr_quality'] / 10);
252
+ $LAME_q_value = 100 - $thisfile_mpeg_audio_lame['vbr_quality'] - ($LAME_V_value * 10);
253
+ $encoder_options = '-V'.$LAME_V_value.' -q'.$LAME_q_value;
254
+
255
+ } elseif ($ThisFileInfo['audio']['bitrate_mode'] == 'cbr') {
256
+
257
+ $encoder_options = strtoupper($ThisFileInfo['audio']['bitrate_mode']).ceil($ThisFileInfo['audio']['bitrate'] / 1000);
258
+
259
+ } else {
260
+
261
+ $encoder_options = strtoupper($ThisFileInfo['audio']['bitrate_mode']);
262
+
263
+ }
264
+
265
+ } elseif (!empty($thisfile_mpeg_audio_lame['bitrate_abr'])) {
266
+
267
+ $encoder_options = 'ABR'.$thisfile_mpeg_audio_lame['bitrate_abr'];
268
+
269
+ } elseif (!empty($ThisFileInfo['audio']['bitrate'])) {
270
+
271
+ if ($ThisFileInfo['audio']['bitrate_mode'] == 'cbr') {
272
+ $encoder_options = strtoupper($ThisFileInfo['audio']['bitrate_mode']).ceil($ThisFileInfo['audio']['bitrate'] / 1000);
273
+ } else {
274
+ $encoder_options = strtoupper($ThisFileInfo['audio']['bitrate_mode']);
275
+ }
276
+
277
+ }
278
+ if (!empty($thisfile_mpeg_audio_lame['bitrate_min'])) {
279
+ $encoder_options .= ' -b'.$thisfile_mpeg_audio_lame['bitrate_min'];
280
+ }
281
+
282
+ if (@$thisfile_mpeg_audio_lame['encoding_flags']['nogap_prev'] || @$thisfile_mpeg_audio_lame['encoding_flags']['nogap_next']) {
283
+ $encoder_options .= ' --nogap';
284
+ }
285
+
286
+ if (!empty($thisfile_mpeg_audio_lame['lowpass_frequency'])) {
287
+ $ExplodedOptions = explode(' ', $encoder_options, 4);
288
+ if ($ExplodedOptions[0] == '--r3mix') {
289
+ $ExplodedOptions[1] = 'r3mix';
290
+ }
291
+ switch ($ExplodedOptions[0]) {
292
+ case '--preset':
293
+ case '--alt-preset':
294
+ case '--r3mix':
295
+ if ($ExplodedOptions[1] == 'fast') {
296
+ $ExplodedOptions[1] .= ' '.$ExplodedOptions[2];
297
+ }
298
+ switch ($ExplodedOptions[1]) {
299
+ case 'portable':
300
+ case 'medium':
301
+ case 'standard':
302
+ case 'extreme':
303
+ case 'insane':
304
+ case 'fast portable':
305
+ case 'fast medium':
306
+ case 'fast standard':
307
+ case 'fast extreme':
308
+ case 'fast insane':
309
+ case 'r3mix':
310
+ static $ExpectedLowpass = array(
311
+ 'insane|20500' => 20500,
312
+ 'insane|20600' => 20600, // 3.90.2, 3.90.3, 3.91
313
+ 'medium|18000' => 18000,
314
+ 'fast medium|18000' => 18000,
315
+ 'extreme|19500' => 19500, // 3.90, 3.90.1, 3.92, 3.95
316
+ 'extreme|19600' => 19600, // 3.90.2, 3.90.3, 3.91, 3.93.1
317
+ 'fast extreme|19500' => 19500, // 3.90, 3.90.1, 3.92, 3.95
318
+ 'fast extreme|19600' => 19600, // 3.90.2, 3.90.3, 3.91, 3.93.1
319
+ 'standard|19000' => 19000,
320
+ 'fast standard|19000' => 19000,
321
+ 'r3mix|19500' => 19500, // 3.90, 3.90.1, 3.92
322
+ 'r3mix|19600' => 19600, // 3.90.2, 3.90.3, 3.91
323
+ 'r3mix|18000' => 18000, // 3.94, 3.95
324
+ );
325
+ if (!isset($ExpectedLowpass[$ExplodedOptions[1].'|'.$thisfile_mpeg_audio_lame['lowpass_frequency']]) && ($thisfile_mpeg_audio_lame['lowpass_frequency'] < 22050) && (round($thisfile_mpeg_audio_lame['lowpass_frequency'] / 1000) < round($thisfile_mpeg_audio['sample_rate'] / 2000))) {
326
+ $encoder_options .= ' --lowpass '.$thisfile_mpeg_audio_lame['lowpass_frequency'];
327
+ }
328
+ break;
329
+
330
+ default:
331
+ break;
332
+ }
333
+ break;
334
+ }
335
+ }
336
+
337
+ if (isset($thisfile_mpeg_audio_lame['raw']['source_sample_freq'])) {
338
+ if (($thisfile_mpeg_audio['sample_rate'] == 44100) && ($thisfile_mpeg_audio_lame['raw']['source_sample_freq'] != 1)) {
339
+ $encoder_options .= ' --resample 44100';
340
+ } elseif (($thisfile_mpeg_audio['sample_rate'] == 48000) && ($thisfile_mpeg_audio_lame['raw']['source_sample_freq'] != 2)) {
341
+ $encoder_options .= ' --resample 48000';
342
+ } elseif ($thisfile_mpeg_audio['sample_rate'] < 44100) {
343
+ switch ($thisfile_mpeg_audio_lame['raw']['source_sample_freq']) {
344
+ case 0: // <= 32000
345
+ // may or may not be same as source frequency - ignore
346
+ break;
347
+ case 1: // 44100
348
+ case 2: // 48000
349
+ case 3: // 48000+
350
+ $ExplodedOptions = explode(' ', $encoder_options, 4);
351
+ switch ($ExplodedOptions[0]) {
352
+ case '--preset':
353
+ case '--alt-preset':
354
+ switch ($ExplodedOptions[1]) {
355
+ case 'fast':
356
+ case 'portable':
357
+ case 'medium':
358
+ case 'standard':
359
+ case 'extreme':
360
+ case 'insane':
361
+ $encoder_options .= ' --resample '.$thisfile_mpeg_audio['sample_rate'];
362
+ break;
363
+
364
+ default:
365
+ static $ExpectedResampledRate = array(
366
+ 'phon+/lw/mw-eu/sw|16000' => 16000,
367
+ 'mw-us|24000' => 24000, // 3.95
368
+ 'mw-us|32000' => 32000, // 3.93
369
+ 'mw-us|16000' => 16000, // 3.92
370
+ 'phone|16000' => 16000,
371
+ 'phone|11025' => 11025, // 3.94a15
372
+ 'radio|32000' => 32000, // 3.94a15
373
+ 'fm/radio|32000' => 32000, // 3.92
374
+ 'fm|32000' => 32000, // 3.90
375
+ 'voice|32000' => 32000);
376
+ if (!isset($ExpectedResampledRate[$ExplodedOptions[1].'|'.$thisfile_mpeg_audio['sample_rate']])) {
377
+ $encoder_options .= ' --resample '.$thisfile_mpeg_audio['sample_rate'];
378
+ }
379
+ break;
380
+ }
381
+ break;
382
+
383
+ case '--r3mix':
384
+ default:
385
+ $encoder_options .= ' --resample '.$thisfile_mpeg_audio['sample_rate'];
386
+ break;
387
+ }
388
+ break;
389
+ }
390
+ }
391
+ }
392
+ if (empty($encoder_options) && !empty($ThisFileInfo['audio']['bitrate']) && !empty($ThisFileInfo['audio']['bitrate_mode'])) {
393
+ //$encoder_options = strtoupper($ThisFileInfo['audio']['bitrate_mode']).ceil($ThisFileInfo['audio']['bitrate'] / 1000);
394
+ $encoder_options = strtoupper($ThisFileInfo['audio']['bitrate_mode']);
395
+ }
396
+
397
+ return $encoder_options;
398
+ }
399
+
400
+
401
+ function decodeMPEGaudioHeader($fd, $offset, &$ThisFileInfo, $recursivesearch=true, $ScanAsCBR=false, $FastMPEGheaderScan=false) {
402
+
403
+ static $MPEGaudioVersionLookup;
404
+ static $MPEGaudioLayerLookup;
405
+ static $MPEGaudioBitrateLookup;
406
+ static $MPEGaudioFrequencyLookup;
407
+ static $MPEGaudioChannelModeLookup;
408
+ static $MPEGaudioModeExtensionLookup;
409
+ static $MPEGaudioEmphasisLookup;
410
+ if (empty($MPEGaudioVersionLookup)) {
411
+ $MPEGaudioVersionLookup = getid3_mp3::MPEGaudioVersionArray();
412
+ $MPEGaudioLayerLookup = getid3_mp3::MPEGaudioLayerArray();
413
+ $MPEGaudioBitrateLookup = getid3_mp3::MPEGaudioBitrateArray();
414
+ $MPEGaudioFrequencyLookup = getid3_mp3::MPEGaudioFrequencyArray();
415
+ $MPEGaudioChannelModeLookup = getid3_mp3::MPEGaudioChannelModeArray();
416
+ $MPEGaudioModeExtensionLookup = getid3_mp3::MPEGaudioModeExtensionArray();
417
+ $MPEGaudioEmphasisLookup = getid3_mp3::MPEGaudioEmphasisArray();
418
+ }
419
+
420
+ if ($offset >= $ThisFileInfo['avdataend']) {
421
+ $ThisFileInfo['error'][] = 'end of file encounter looking for MPEG synch';
422
+ return false;
423
+ }
424
+ fseek($fd, $offset, SEEK_SET);
425
+ //$headerstring = fread($fd, 1441); // worst-case max length = 32kHz @ 320kbps layer 3 = 1441 bytes/frame
426
+ $headerstring = fread($fd, 226); // LAME header at offset 36 + 190 bytes of Xing/LAME data
427
+
428
+ // MP3 audio frame structure:
429
+ // $aa $aa $aa $aa [$bb $bb] $cc...
430
+ // where $aa..$aa is the four-byte mpeg-audio header (below)
431
+ // $bb $bb is the optional 2-byte CRC
432
+ // and $cc... is the audio data
433
+
434
+ $head4 = substr($headerstring, 0, 4);
435
+
436
+ static $MPEGaudioHeaderDecodeCache = array();
437
+ if (isset($MPEGaudioHeaderDecodeCache[$head4])) {
438
+ $MPEGheaderRawArray = $MPEGaudioHeaderDecodeCache[$head4];
439
+ } else {
440
+ $MPEGheaderRawArray = getid3_mp3::MPEGaudioHeaderDecode($head4);
441
+ $MPEGaudioHeaderDecodeCache[$head4] = $MPEGheaderRawArray;
442
+ }
443
+
444
+ static $MPEGaudioHeaderValidCache = array();
445
+
446
+ // Not in cache
447
+ if (!isset($MPEGaudioHeaderValidCache[$head4])) {
448
+ //$MPEGaudioHeaderValidCache[$head4] = getid3_mp3::MPEGaudioHeaderValid($MPEGheaderRawArray, false, true); // allow badly-formatted freeformat (from LAME 3.90 - 3.93.1)
449
+ $MPEGaudioHeaderValidCache[$head4] = getid3_mp3::MPEGaudioHeaderValid($MPEGheaderRawArray, false, false);
450
+ }
451
+
452
+ // shortcut
453
+ if (!isset($ThisFileInfo['mpeg']['audio'])) {
454
+ $ThisFileInfo['mpeg']['audio'] = array();
455
+ }
456
+ $thisfile_mpeg_audio = &$ThisFileInfo['mpeg']['audio'];
457
+
458
+
459
+ if ($MPEGaudioHeaderValidCache[$head4]) {
460
+ $thisfile_mpeg_audio['raw'] = $MPEGheaderRawArray;
461
+ } else {
462
+ $ThisFileInfo['error'][] = 'Invalid MPEG audio header at offset '.$offset;
463
+ return false;
464
+ }
465
+
466
+ if (!$FastMPEGheaderScan) {
467
+
468
+ $thisfile_mpeg_audio['version'] = $MPEGaudioVersionLookup[$thisfile_mpeg_audio['raw']['version']];
469
+ $thisfile_mpeg_audio['layer'] = $MPEGaudioLayerLookup[$thisfile_mpeg_audio['raw']['layer']];
470
+
471
+ $thisfile_mpeg_audio['channelmode'] = $MPEGaudioChannelModeLookup[$thisfile_mpeg_audio['raw']['channelmode']];
472
+ $thisfile_mpeg_audio['channels'] = (($thisfile_mpeg_audio['channelmode'] == 'mono') ? 1 : 2);
473
+ $thisfile_mpeg_audio['sample_rate'] = $MPEGaudioFrequencyLookup[$thisfile_mpeg_audio['version']][$thisfile_mpeg_audio['raw']['sample_rate']];
474
+ $thisfile_mpeg_audio['protection'] = !$thisfile_mpeg_audio['raw']['protection'];
475
+ $thisfile_mpeg_audio['private'] = (bool) $thisfile_mpeg_audio['raw']['private'];
476
+ $thisfile_mpeg_audio['modeextension'] = $MPEGaudioModeExtensionLookup[$thisfile_mpeg_audio['layer']][$thisfile_mpeg_audio['raw']['modeextension']];
477
+ $thisfile_mpeg_audio['copyright'] = (bool) $thisfile_mpeg_audio['raw']['copyright'];
478
+ $thisfile_mpeg_audio['original'] = (bool) $thisfile_mpeg_audio['raw']['original'];
479
+ $thisfile_mpeg_audio['emphasis'] = $MPEGaudioEmphasisLookup[$thisfile_mpeg_audio['raw']['emphasis']];
480
+
481
+ $ThisFileInfo['audio']['channels'] = $thisfile_mpeg_audio['channels'];
482
+ $ThisFileInfo['audio']['sample_rate'] = $thisfile_mpeg_audio['sample_rate'];
483
+
484
+ if ($thisfile_mpeg_audio['protection']) {
485
+ $thisfile_mpeg_audio['crc'] = getid3_lib::BigEndian2Int(substr($headerstring, 4, 2));
486
+ }
487
+
488
+ }
489
+
490
+ if ($thisfile_mpeg_audio['raw']['bitrate'] == 15) {
491
+ // http://www.hydrogenaudio.org/?act=ST&f=16&t=9682&st=0
492
+ $ThisFileInfo['warning'][] = 'Invalid bitrate index (15), this is a known bug in free-format MP3s encoded by LAME v3.90 - 3.93.1';
493
+ $thisfile_mpeg_audio['raw']['bitrate'] = 0;
494
+ }
495
+ $thisfile_mpeg_audio['padding'] = (bool) $thisfile_mpeg_audio['raw']['padding'];
496
+ $thisfile_mpeg_audio['bitrate'] = $MPEGaudioBitrateLookup[$thisfile_mpeg_audio['version']][$thisfile_mpeg_audio['layer']][$thisfile_mpeg_audio['raw']['bitrate']];
497
+
498
+ if (($thisfile_mpeg_audio['bitrate'] == 'free') && ($offset == $ThisFileInfo['avdataoffset'])) {
499
+ // only skip multiple frame check if free-format bitstream found at beginning of file
500
+ // otherwise is quite possibly simply corrupted data
501
+ $recursivesearch = false;
502
+ }
503
+
504
+ // For Layer 2 there are some combinations of bitrate and mode which are not allowed.
505
+ if (!$FastMPEGheaderScan && ($thisfile_mpeg_audio['layer'] == '2')) {
506
+
507
+ $ThisFileInfo['audio']['dataformat'] = 'mp2';
508
+ switch ($thisfile_mpeg_audio['channelmode']) {
509
+
510
+ case 'mono':
511
+ if (($thisfile_mpeg_audio['bitrate'] == 'free') || ($thisfile_mpeg_audio['bitrate'] <= 192000)) {
512
+ // these are ok
513
+ } else {
514
+ $ThisFileInfo['error'][] = $thisfile_mpeg_audio['bitrate'].'kbps not allowed in Layer 2, '.$thisfile_mpeg_audio['channelmode'].'.';
515
+ return false;
516
+ }
517
+ break;
518
+
519
+ case 'stereo':
520
+ case 'joint stereo':
521
+ case 'dual channel':
522
+ if (($thisfile_mpeg_audio['bitrate'] == 'free') || ($thisfile_mpeg_audio['bitrate'] == 64000) || ($thisfile_mpeg_audio['bitrate'] >= 96000)) {
523
+ // these are ok
524
+ } else {
525
+ $ThisFileInfo['error'][] = intval(round($thisfile_mpeg_audio['bitrate'] / 1000)).'kbps not allowed in Layer 2, '.$thisfile_mpeg_audio['channelmode'].'.';
526
+ return false;
527
+ }
528
+ break;
529
+
530
+ }
531
+
532
+ }
533
+
534
+
535
+ if ($ThisFileInfo['audio']['sample_rate'] > 0) {
536
+ $thisfile_mpeg_audio['framelength'] = getid3_mp3::MPEGaudioFrameLength($thisfile_mpeg_audio['bitrate'], $thisfile_mpeg_audio['version'], $thisfile_mpeg_audio['layer'], (int) $thisfile_mpeg_audio['padding'], $ThisFileInfo['audio']['sample_rate']);
537
+ }
538
+
539
+ $nextframetestoffset = $offset + 1;
540
+ if ($thisfile_mpeg_audio['bitrate'] != 'free') {
541
+
542
+ $ThisFileInfo['audio']['bitrate'] = $thisfile_mpeg_audio['bitrate'];
543
+
544
+ if (isset($thisfile_mpeg_audio['framelength'])) {
545
+ $nextframetestoffset = $offset + $thisfile_mpeg_audio['framelength'];
546
+ } else {
547
+ $ThisFileInfo['error'][] = 'Frame at offset('.$offset.') is has an invalid frame length.';
548
+ return false;
549
+ }
550
+
551
+ }
552
+
553
+ $ExpectedNumberOfAudioBytes = 0;
554
+
555
+ ////////////////////////////////////////////////////////////////////////////////////
556
+ // Variable-bitrate headers
557
+
558
+ if (substr($headerstring, 4 + 32, 4) == 'VBRI') {
559
+ // Fraunhofer VBR header is hardcoded 'VBRI' at offset 0x24 (36)
560
+ // specs taken from http://minnie.tuhs.org/pipermail/mp3encoder/2001-January/001800.html
561
+
562
+ $thisfile_mpeg_audio['bitrate_mode'] = 'vbr';
563
+ $thisfile_mpeg_audio['VBR_method'] = 'Fraunhofer';
564
+ $ThisFileInfo['audio']['codec'] = 'Fraunhofer';
565
+
566
+ $SideInfoData = substr($headerstring, 4 + 2, 32);
567
+
568
+ $FraunhoferVBROffset = 36;
569
+
570
+ $thisfile_mpeg_audio['VBR_encoder_version'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 4, 2)); // VbriVersion
571
+ $thisfile_mpeg_audio['VBR_encoder_delay'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 6, 2)); // VbriDelay
572
+ $thisfile_mpeg_audio['VBR_quality'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 8, 2)); // VbriQuality
573
+ $thisfile_mpeg_audio['VBR_bytes'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 10, 4)); // VbriStreamBytes
574
+ $thisfile_mpeg_audio['VBR_frames'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 14, 4)); // VbriStreamFrames
575
+ $thisfile_mpeg_audio['VBR_seek_offsets'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 18, 2)); // VbriTableSize
576
+ $thisfile_mpeg_audio['VBR_seek_scale'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 20, 2)); // VbriTableScale
577
+ $thisfile_mpeg_audio['VBR_entry_bytes'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 22, 2)); // VbriEntryBytes
578
+ $thisfile_mpeg_audio['VBR_entry_frames'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 24, 2)); // VbriEntryFrames
579
+
580
+ $ExpectedNumberOfAudioBytes = $thisfile_mpeg_audio['VBR_bytes'];
581
+
582
+ $previousbyteoffset = $offset;
583
+ for ($i = 0; $i < $thisfile_mpeg_audio['VBR_seek_offsets']; $i++) {
584
+ $Fraunhofer_OffsetN = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset, $thisfile_mpeg_audio['VBR_entry_bytes']));
585
+ $FraunhoferVBROffset += $thisfile_mpeg_audio['VBR_entry_bytes'];
586
+ $thisfile_mpeg_audio['VBR_offsets_relative'][$i] = ($Fraunhofer_OffsetN * $thisfile_mpeg_audio['VBR_seek_scale']);
587
+ $thisfile_mpeg_audio['VBR_offsets_absolute'][$i] = ($Fraunhofer_OffsetN * $thisfile_mpeg_audio['VBR_seek_scale']) + $previousbyteoffset;
588
+ $previousbyteoffset += $Fraunhofer_OffsetN;
589
+ }
590
+
591
+
592
+ } else {
593
+
594
+ // Xing VBR header is hardcoded 'Xing' at a offset 0x0D (13), 0x15 (21) or 0x24 (36)
595
+ // depending on MPEG layer and number of channels
596
+
597
+ $VBRidOffset = getid3_mp3::XingVBRidOffset($thisfile_mpeg_audio['version'], $thisfile_mpeg_audio['channelmode']);
598
+ $SideInfoData = substr($headerstring, 4 + 2, $VBRidOffset - 4);
599
+
600
+ if ((substr($headerstring, $VBRidOffset, strlen('Xing')) == 'Xing') || (substr($headerstring, $VBRidOffset, strlen('Info')) == 'Info')) {
601
+ // 'Xing' is traditional Xing VBR frame
602
+ // 'Info' is LAME-encoded CBR (This was done to avoid CBR files to be recognized as traditional Xing VBR files by some decoders.)
603
+ // 'Info' *can* legally be used to specify a VBR file as well, however.
604
+
605
+ // http://www.multiweb.cz/twoinches/MP3inside.htm
606
+ //00..03 = "Xing" or "Info"
607
+ //04..07 = Flags:
608
+ // 0x01 Frames Flag set if value for number of frames in file is stored
609
+ // 0x02 Bytes Flag set if value for filesize in bytes is stored
610
+ // 0x04 TOC Flag set if values for TOC are stored
611
+ // 0x08 VBR Scale Flag set if values for VBR scale is stored
612
+ //08..11 Frames: Number of frames in file (including the first Xing/Info one)
613
+ //12..15 Bytes: File length in Bytes
614
+ //16..115 TOC (Table of Contents):
615
+ // Contains of 100 indexes (one Byte length) for easier lookup in file. Approximately solves problem with moving inside file.
616
+ // Each Byte has a value according this formula:
617
+ // (TOC[i] / 256) * fileLenInBytes
618
+ // So if song lasts eg. 240 sec. and you want to jump to 60. sec. (and file is 5 000 000 Bytes length) you can use:
619
+ // TOC[(60/240)*100] = TOC[25]
620
+ // and corresponding Byte in file is then approximately at:
621
+ // (TOC[25]/256) * 5000000
622
+ //116..119 VBR Scale
623
+
624
+
625
+ // should be safe to leave this at 'vbr' and let it be overriden to 'cbr' if a CBR preset/mode is used by LAME
626
+ // if (substr($headerstring, $VBRidOffset, strlen('Info')) == 'Xing') {
627
+ $thisfile_mpeg_audio['bitrate_mode'] = 'vbr';
628
+ $thisfile_mpeg_audio['VBR_method'] = 'Xing';
629
+ // } else {
630
+ // $ScanAsCBR = true;
631
+ // $thisfile_mpeg_audio['bitrate_mode'] = 'cbr';
632
+ // }
633
+
634
+ $thisfile_mpeg_audio['xing_flags_raw'] = getid3_lib::BigEndian2Int(substr($headerstring, $VBRidOffset + 4, 4));
635
+
636
+ $thisfile_mpeg_audio['xing_flags']['frames'] = (bool) ($thisfile_mpeg_audio['xing_flags_raw'] & 0x00000001);
637
+ $thisfile_mpeg_audio['xing_flags']['bytes'] = (bool) ($thisfile_mpeg_audio['xing_flags_raw'] & 0x00000002);
638
+ $thisfile_mpeg_audio['xing_flags']['toc'] = (bool) ($thisfile_mpeg_audio['xing_flags_raw'] & 0x00000004);
639
+ $thisfile_mpeg_audio['xing_flags']['vbr_scale'] = (bool) ($thisfile_mpeg_audio['xing_flags_raw'] & 0x00000008);
640
+
641
+ if ($thisfile_mpeg_audio['xing_flags']['frames']) {
642
+ $thisfile_mpeg_audio['VBR_frames'] = getid3_lib::BigEndian2Int(substr($headerstring, $VBRidOffset + 8, 4));
643
+ //$thisfile_mpeg_audio['VBR_frames']--; // don't count header Xing/Info frame
644
+ }
645
+ if ($thisfile_mpeg_audio['xing_flags']['bytes']) {
646
+ $thisfile_mpeg_audio['VBR_bytes'] = getid3_lib::BigEndian2Int(substr($headerstring, $VBRidOffset + 12, 4));
647
+ }
648
+
649
+ //if (($thisfile_mpeg_audio['bitrate'] == 'free') && !empty($thisfile_mpeg_audio['VBR_frames']) && !empty($thisfile_mpeg_audio['VBR_bytes'])) {
650
+ if (!empty($thisfile_mpeg_audio['VBR_frames']) && !empty($thisfile_mpeg_audio['VBR_bytes'])) {
651
+
652
+ $framelengthfloat = $thisfile_mpeg_audio['VBR_bytes'] / $thisfile_mpeg_audio['VBR_frames'];
653
+
654
+ if ($thisfile_mpeg_audio['layer'] == '1') {
655
+ // BitRate = (((FrameLengthInBytes / 4) - Padding) * SampleRate) / 12
656
+ //$ThisFileInfo['audio']['bitrate'] = ((($framelengthfloat / 4) - intval($thisfile_mpeg_audio['padding'])) * $thisfile_mpeg_audio['sample_rate']) / 12;
657
+ $ThisFileInfo['audio']['bitrate'] = ($framelengthfloat / 4) * $thisfile_mpeg_audio['sample_rate'] * (2 / $ThisFileInfo['audio']['channels']) / 12;
658
+ } else {
659
+ // Bitrate = ((FrameLengthInBytes - Padding) * SampleRate) / 144
660
+ //$ThisFileInfo['audio']['bitrate'] = (($framelengthfloat - intval($thisfile_mpeg_audio['padding'])) * $thisfile_mpeg_audio['sample_rate']) / 144;
661
+ $ThisFileInfo['audio']['bitrate'] = $framelengthfloat * $thisfile_mpeg_audio['sample_rate'] * (2 / $ThisFileInfo['audio']['channels']) / 144;
662
+ }
663
+ $thisfile_mpeg_audio['framelength'] = floor($framelengthfloat);
664
+ }
665
+
666
+ if ($thisfile_mpeg_audio['xing_flags']['toc']) {
667
+ $LAMEtocData = substr($headerstring, $VBRidOffset + 16, 100);
668
+ for ($i = 0; $i < 100; $i++) {
669
+ $thisfile_mpeg_audio['toc'][$i] = ord($LAMEtocData{$i});
670
+ }
671
+ }
672
+ if ($thisfile_mpeg_audio['xing_flags']['vbr_scale']) {
673
+ $thisfile_mpeg_audio['VBR_scale'] = getid3_lib::BigEndian2Int(substr($headerstring, $VBRidOffset + 116, 4));
674
+ }
675
+
676
+
677
+ // http://gabriel.mp3-tech.org/mp3infotag.html
678
+ if (substr($headerstring, $VBRidOffset + 120, 4) == 'LAME') {
679
+
680
+ // shortcut
681
+ $thisfile_mpeg_audio['LAME'] = array();
682
+ $thisfile_mpeg_audio_lame = &$thisfile_mpeg_audio['LAME'];
683
+
684
+
685
+ $thisfile_mpeg_audio_lame['long_version'] = substr($headerstring, $VBRidOffset + 120, 20);
686
+ $thisfile_mpeg_audio_lame['short_version'] = substr($thisfile_mpeg_audio_lame['long_version'], 0, 9);
687
+
688
+ if ($thisfile_mpeg_audio_lame['short_version'] >= 'LAME3.90') {
689
+
690
+ // extra 11 chars are not part of version string when LAMEtag present
691
+ unset($thisfile_mpeg_audio_lame['long_version']);
692
+
693
+ // It the LAME tag was only introduced in LAME v3.90
694
+ // http://www.hydrogenaudio.org/?act=ST&f=15&t=9933
695
+
696
+ // Offsets of various bytes in http://gabriel.mp3-tech.org/mp3infotag.html
697
+ // are assuming a 'Xing' identifier offset of 0x24, which is the case for
698
+ // MPEG-1 non-mono, but not for other combinations
699
+ $LAMEtagOffsetContant = $VBRidOffset - 0x24;
700
+
701
+ // shortcuts
702
+ $thisfile_mpeg_audio_lame['RGAD'] = array('track'=>array(), 'album'=>array());
703
+ $thisfile_mpeg_audio_lame_RGAD = &$thisfile_mpeg_audio_lame['RGAD'];
704
+ $thisfile_mpeg_audio_lame_RGAD_track = &$thisfile_mpeg_audio_lame_RGAD['track'];
705
+ $thisfile_mpeg_audio_lame_RGAD_album = &$thisfile_mpeg_audio_lame_RGAD['album'];
706
+ $thisfile_mpeg_audio_lame['raw'] = array();
707
+ $thisfile_mpeg_audio_lame_raw = &$thisfile_mpeg_audio_lame['raw'];
708
+
709
+ // byte $9B VBR Quality
710
+ // This field is there to indicate a quality level, although the scale was not precised in the original Xing specifications.
711
+ // Actually overwrites original Xing bytes
712
+ unset($thisfile_mpeg_audio['VBR_scale']);
713
+ $thisfile_mpeg_audio_lame['vbr_quality'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0x9B, 1));
714
+
715
+ // bytes $9C-$A4 Encoder short VersionString
716
+ $thisfile_mpeg_audio_lame['short_version'] = substr($headerstring, $LAMEtagOffsetContant + 0x9C, 9);
717
+
718
+ // byte $A5 Info Tag revision + VBR method
719
+ $LAMEtagRevisionVBRmethod = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xA5, 1));
720
+
721
+ $thisfile_mpeg_audio_lame['tag_revision'] = ($LAMEtagRevisionVBRmethod & 0xF0) >> 4;
722
+ $thisfile_mpeg_audio_lame_raw['vbr_method'] = $LAMEtagRevisionVBRmethod & 0x0F;
723
+ $thisfile_mpeg_audio_lame['vbr_method'] = getid3_mp3::LAMEvbrMethodLookup($thisfile_mpeg_audio_lame_raw['vbr_method']);
724
+ $thisfile_mpeg_audio['bitrate_mode'] = substr($thisfile_mpeg_audio_lame['vbr_method'], 0, 3); // usually either 'cbr' or 'vbr', but truncates 'vbr-old / vbr-rh' to 'vbr'
725
+
726
+ // byte $A6 Lowpass filter value
727
+ $thisfile_mpeg_audio_lame['lowpass_frequency'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xA6, 1)) * 100;
728
+
729
+ // bytes $A7-$AE Replay Gain
730
+ // http://privatewww.essex.ac.uk/~djmrob/replaygain/rg_data_format.html
731
+ // bytes $A7-$AA : 32 bit floating point "Peak signal amplitude"
732
+ if ($thisfile_mpeg_audio_lame['short_version'] >= 'LAME3.94b') {
733
+ // LAME 3.94a16 and later - 9.23 fixed point
734
+ // ie 0x0059E2EE / (2^23) = 5890798 / 8388608 = 0.7022378444671630859375
735
+ $thisfile_mpeg_audio_lame_RGAD['peak_amplitude'] = (float) ((getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xA7, 4))) / 8388608);
736
+ } else {
737
+ // LAME 3.94a15 and earlier - 32-bit floating point
738
+ // Actually 3.94a16 will fall in here too and be WRONG, but is hard to detect 3.94a16 vs 3.94a15
739
+ $thisfile_mpeg_audio_lame_RGAD['peak_amplitude'] = getid3_lib::LittleEndian2Float(substr($headerstring, $LAMEtagOffsetContant + 0xA7, 4));
740
+ }
741
+ if ($thisfile_mpeg_audio_lame_RGAD['peak_amplitude'] == 0) {
742
+ unse