diff e2gallerypro/e2upload/Backend/Assets/getid3/module.audio-video.real.php @ 3:3f6b44aa6b35 judyates

[svn r4] added ability to buy stuff, from a Prints page, but it doesn't work well with the css, and it also has not been fitted into the perl make system.
author rlm
date Mon, 22 Feb 2010 08:02:39 -0500
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/e2gallerypro/e2upload/Backend/Assets/getid3/module.audio-video.real.php	Mon Feb 22 08:02:39 2010 -0500
     1.3 @@ -0,0 +1,591 @@
     1.4 +<?php
     1.5 +// +----------------------------------------------------------------------+
     1.6 +// | PHP version 5                                                        |
     1.7 +// +----------------------------------------------------------------------+
     1.8 +// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen                 |
     1.9 +// +----------------------------------------------------------------------+
    1.10 +// | This source file is subject to version 2 of the GPL license,         |
    1.11 +// | that is bundled with this package in the file license.txt and is     |
    1.12 +// | available through the world-wide-web at the following url:           |
    1.13 +// | http://www.gnu.org/copyleft/gpl.html                                 |
    1.14 +// +----------------------------------------------------------------------+
    1.15 +// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org    |
    1.16 +// +----------------------------------------------------------------------+
    1.17 +// | Authors: James Heinrich <infoØgetid3*org>                            |
    1.18 +// |          Allan Hansen <ahØartemis*dk>                                |
    1.19 +// +----------------------------------------------------------------------+
    1.20 +// | module.audio-video.real.php                                          |
    1.21 +// | Module for analyzing Real Audio/Video files                          |
    1.22 +// | dependencies: module.audio-video.riff.php                            |
    1.23 +// +----------------------------------------------------------------------+
    1.24 +//
    1.25 +// $Id: module.audio-video.real.php,v 1.4 2006/11/02 10:48:00 ah Exp $
    1.26 +
    1.27 +        
    1.28 +        
    1.29 +class getid3_real extends getid3_handler
    1.30 +{
    1.31 +
    1.32 +    public function Analyze() {
    1.33 +        
    1.34 +        $getid3 = $this->getid3;
    1.35 +        
    1.36 +        $getid3->include_module('audio-video.riff');
    1.37 +
    1.38 +        $getid3->info['fileformat']       = 'real';
    1.39 +        $getid3->info['bitrate']          = 0;
    1.40 +        $getid3->info['playtime_seconds'] = 0;
    1.41 +
    1.42 +        fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
    1.43 +        $chunk_counter = 0;
    1.44 +
    1.45 +        while (ftell($getid3->fp) < $getid3->info['avdataend']) {
    1.46 +            
    1.47 +            $chunk_data = fread($getid3->fp, 8);
    1.48 +            $chunk_name =                           substr($chunk_data, 0, 4);
    1.49 +            $chunk_size = getid3_lib::BigEndian2Int(substr($chunk_data, 4, 4));
    1.50 +
    1.51 +            if ($chunk_name == '.ra'."\xFD") {
    1.52 +                $chunk_data .= fread($getid3->fp, $chunk_size - 8);
    1.53 +                
    1.54 +                if ($this->ParseOldRAheader(substr($chunk_data, 0, 128), $getid3->info['real']['old_ra_header'])) {
    1.55 +                
    1.56 +                    $getid3->info['audio']['dataformat']      = 'real';
    1.57 +                    $getid3->info['audio']['lossless']        = false;
    1.58 +                    $getid3->info['audio']['sample_rate']     = $getid3->info['real']['old_ra_header']['sample_rate'];
    1.59 +                    $getid3->info['audio']['bits_per_sample'] = $getid3->info['real']['old_ra_header']['bits_per_sample'];
    1.60 +                    $getid3->info['audio']['channels']        = $getid3->info['real']['old_ra_header']['channels'];
    1.61 +
    1.62 +                    $getid3->info['playtime_seconds']         = 60 * ($getid3->info['real']['old_ra_header']['audio_bytes'] / $getid3->info['real']['old_ra_header']['bytes_per_minute']);
    1.63 +                    $getid3->info['audio']['bitrate']         =  8 * ($getid3->info['real']['old_ra_header']['audio_bytes'] / $getid3->info['playtime_seconds']);
    1.64 +                    $getid3->info['audio']['codec']           = $this->RealAudioCodecFourCClookup($getid3->info['real']['old_ra_header']['fourcc'], $getid3->info['audio']['bitrate']);
    1.65 +
    1.66 +                    foreach ($getid3->info['real']['old_ra_header']['comments'] as $key => $value_array) {
    1.67 +                
    1.68 +                        if (strlen(trim($value_array[0])) > 0) {
    1.69 +                            $getid3->info['real']['comments'][$key][] = trim($value_array[0]);
    1.70 +                        }
    1.71 +                    }
    1.72 +                    return true;
    1.73 +                }
    1.74 +                
    1.75 +                throw new getid3_exception('There was a problem parsing this RealAudio file. Please submit it for analysis to http://www.getid3.org/upload/ or info@getid3.org');
    1.76 +            }
    1.77 +
    1.78 +            $getid3->info['real']['chunks'][$chunk_counter] = array ();
    1.79 +            $info_real_chunks_current_chunk = &$getid3->info['real']['chunks'][$chunk_counter];
    1.80 +
    1.81 +            $info_real_chunks_current_chunk['name']   = $chunk_name;
    1.82 +            $info_real_chunks_current_chunk['offset'] = ftell($getid3->fp) - 8;
    1.83 +            $info_real_chunks_current_chunk['length'] = $chunk_size;
    1.84 +            
    1.85 +            if (($info_real_chunks_current_chunk['offset'] + $info_real_chunks_current_chunk['length']) > $getid3->info['avdataend']) {
    1.86 +                $getid3->warning('Chunk "'.$info_real_chunks_current_chunk['name'].'" at offset '.$info_real_chunks_current_chunk['offset'].' claims to be '.$info_real_chunks_current_chunk['length'].' bytes long, which is beyond end of file');
    1.87 +                return false;
    1.88 +            }
    1.89 +
    1.90 +            if ($chunk_size > (getid3::FREAD_BUFFER_SIZE + 8)) {
    1.91 +                $chunk_data .= fread($getid3->fp, getid3::FREAD_BUFFER_SIZE - 8);
    1.92 +                fseek($getid3->fp, $info_real_chunks_current_chunk['offset'] + $chunk_size, SEEK_SET);
    1.93 +
    1.94 +            } elseif(($chunk_size - 8) > 0) {
    1.95 +                $chunk_data .= fread($getid3->fp, $chunk_size - 8);
    1.96 +            }
    1.97 +            $offset = 8;
    1.98 +
    1.99 +            switch ($chunk_name) {
   1.100 +
   1.101 +                case '.RMF': // RealMedia File Header
   1.102 +
   1.103 +                    $info_real_chunks_current_chunk['object_version'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2));
   1.104 +                    $offset += 2;
   1.105 +
   1.106 +                    switch ($info_real_chunks_current_chunk['object_version']) {
   1.107 +
   1.108 +                        case 0:
   1.109 +                            $info_real_chunks_current_chunk['file_version']  = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 4));
   1.110 +                            $offset += 4;
   1.111 +
   1.112 +                            $info_real_chunks_current_chunk['headers_count'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 4));
   1.113 +                            $offset += 4;
   1.114 +                            break;
   1.115 +
   1.116 +                        default:
   1.117 +                            //$getid3->warning('Expected .RMF-object_version to be "0", actual value is "'.$info_real_chunks_current_chunk['object_version'].'" (should not be a problem)';
   1.118 +                            break;
   1.119 +
   1.120 +                    }
   1.121 +                    break;
   1.122 +
   1.123 +
   1.124 +                case 'PROP': // Properties Header
   1.125 +
   1.126 +                    $info_real_chunks_current_chunk['object_version']      = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2));
   1.127 +                    $offset += 2;
   1.128 +
   1.129 +                    if ($info_real_chunks_current_chunk['object_version'] == 0) {
   1.130 +                        
   1.131 +                        getid3_lib::ReadSequence('BigEndian2Int', $info_real_chunks_current_chunk, $chunk_data, $offset,
   1.132 +                            array (
   1.133 +                                'max_bit_rate'    => 4,
   1.134 +                                'avg_bit_rate'    => 4,
   1.135 +                                'max_packet_size' => 4,
   1.136 +                                'avg_packet_size' => 4,
   1.137 +                                'num_packets'     => 4,
   1.138 +                                'duration'        => 4,
   1.139 +                                'preroll'         => 4,
   1.140 +                                'index_offset'    => 4,
   1.141 +                                'data_offset'     => 4,
   1.142 +                                'num_streams'     => 2,
   1.143 +                                'flags_raw'       => 2
   1.144 +                            )
   1.145 +                        );
   1.146 +                        $offset += 40;
   1.147 +
   1.148 +                        $getid3->info['playtime_seconds'] = $info_real_chunks_current_chunk['duration'] / 1000;
   1.149 +                        if ($info_real_chunks_current_chunk['duration'] > 0) {
   1.150 +                            $getid3->info['bitrate'] += $info_real_chunks_current_chunk['avg_bit_rate'];
   1.151 +                        }
   1.152 +                        
   1.153 +                        $info_real_chunks_current_chunk['flags']['save_enabled']   = (bool)($info_real_chunks_current_chunk['flags_raw'] & 0x0001);
   1.154 +                        $info_real_chunks_current_chunk['flags']['perfect_play']   = (bool)($info_real_chunks_current_chunk['flags_raw'] & 0x0002);
   1.155 +                        $info_real_chunks_current_chunk['flags']['live_broadcast'] = (bool)($info_real_chunks_current_chunk['flags_raw'] & 0x0004);
   1.156 +                    }
   1.157 +                    break;
   1.158 +
   1.159 +
   1.160 +                case 'MDPR': // Media Properties Header
   1.161 +
   1.162 +                    $info_real_chunks_current_chunk['object_version']         = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2));
   1.163 +                    $offset += 2;
   1.164 +
   1.165 +                    if ($info_real_chunks_current_chunk['object_version'] == 0) {
   1.166 +
   1.167 +                        getid3_lib::ReadSequence('BigEndian2Int', $info_real_chunks_current_chunk, $chunk_data, $offset,
   1.168 +                            array (
   1.169 +                                'stream_number'    => 2,
   1.170 +                                'max_bit_rate'     => 4,
   1.171 +                                'avg_bit_rate'     => 4,
   1.172 +                                'max_packet_size'  => 4,
   1.173 +                                'avg_packet_size'  => 4,
   1.174 +                                'start_time'       => 4,
   1.175 +                                'preroll'          => 4,
   1.176 +                                'duration'         => 4,
   1.177 +                                'stream_name_size' => 1
   1.178 +                            )
   1.179 +                        );
   1.180 +                        $offset += 31;
   1.181 +                        
   1.182 +                        $info_real_chunks_current_chunk['stream_name']        = substr($chunk_data, $offset, $info_real_chunks_current_chunk['stream_name_size']);
   1.183 +                        $offset += $info_real_chunks_current_chunk['stream_name_size'];
   1.184 +                        
   1.185 +                        $info_real_chunks_current_chunk['mime_type_size']     = getid3_lib::BigEndian2Int($chunk_data{$offset++});
   1.186 +                        
   1.187 +                        $info_real_chunks_current_chunk['mime_type']          = substr($chunk_data, $offset, $info_real_chunks_current_chunk['mime_type_size']);
   1.188 +                        $offset += $info_real_chunks_current_chunk['mime_type_size'];
   1.189 +                        
   1.190 +                        $info_real_chunks_current_chunk['type_specific_len']  = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 4));
   1.191 +                        $offset += 4;
   1.192 +                        
   1.193 +                        $info_real_chunks_current_chunk['type_specific_data'] = substr($chunk_data, $offset, $info_real_chunks_current_chunk['type_specific_len']);
   1.194 +                        $offset += $info_real_chunks_current_chunk['type_specific_len'];
   1.195 +
   1.196 +                        $info_real_chunks_current_chunk_typespecificdata = &$info_real_chunks_current_chunk['type_specific_data'];
   1.197 +
   1.198 +                        switch ($info_real_chunks_current_chunk['mime_type']) {
   1.199 +                          
   1.200 +                            case 'video/x-pn-realvideo':
   1.201 +                            case 'video/x-pn-multirate-realvideo':
   1.202 +                                // http://www.freelists.org/archives/matroska-devel/07-2003/msg00010.html
   1.203 +
   1.204 +                                $info_real_chunks_current_chunk['video_info'] = array ();
   1.205 +                                $info_real_chunks_current_chunk_video_info    = &$info_real_chunks_current_chunk['video_info'];
   1.206 +
   1.207 +                                getid3_lib::ReadSequence('BigEndian2Int', $info_real_chunks_current_chunk_video_info, $info_real_chunks_current_chunk_typespecificdata, 0,
   1.208 +                                    array (
   1.209 +                                        'dwSize'            => 4,
   1.210 +                                        'fourcc1'           => -4,
   1.211 +                                        'fourcc2'           => -4,
   1.212 +                                        'width'             => 2,
   1.213 +                                        'height'            => 2,
   1.214 +                                        'bits_per_sample'   => 2,
   1.215 +                                        'IGNORE-unknown1'   => 2,
   1.216 +                                        'IGNORE-unknown2'   => 2,
   1.217 +                                        'frames_per_second' => 2,
   1.218 +                                        'IGNORE-unknown3'   => 2,
   1.219 +                                        'IGNORE-unknown4'   => 2,
   1.220 +                                        'IGNORE-unknown5'   => 2,
   1.221 +                                        'IGNORE-unknown6'   => 2,
   1.222 +                                        'IGNORE-unknown7'   => 2,
   1.223 +                                        'IGNORE-unknown8'   => 2,
   1.224 +                                        'IGNORE-unknown9'   => 2
   1.225 +                                    )
   1.226 +                                );
   1.227 +
   1.228 +                                $info_real_chunks_current_chunk_video_info['codec'] = getid3_riff::RIFFfourccLookup($info_real_chunks_current_chunk_video_info['fourcc2']);
   1.229 +
   1.230 +                                $getid3->info['video']['resolution_x']    =        $info_real_chunks_current_chunk_video_info['width'];
   1.231 +                                $getid3->info['video']['resolution_y']    =        $info_real_chunks_current_chunk_video_info['height'];
   1.232 +                                $getid3->info['video']['frame_rate']      = (float)$info_real_chunks_current_chunk_video_info['frames_per_second'];
   1.233 +                                $getid3->info['video']['codec']           =        $info_real_chunks_current_chunk_video_info['codec'];
   1.234 +                                $getid3->info['video']['bits_per_sample'] =        $info_real_chunks_current_chunk_video_info['bits_per_sample'];
   1.235 +                                break;
   1.236 +
   1.237 +
   1.238 +                            case 'audio/x-pn-realaudio':
   1.239 +                            case 'audio/x-pn-multirate-realaudio':
   1.240 +
   1.241 +                                $this->ParseOldRAheader($info_real_chunks_current_chunk_typespecificdata, $info_real_chunks_current_chunk['parsed_audio_data']);
   1.242 +
   1.243 +                                $getid3->info['audio']['sample_rate']     = $info_real_chunks_current_chunk['parsed_audio_data']['sample_rate'];
   1.244 +                                $getid3->info['audio']['bits_per_sample'] = $info_real_chunks_current_chunk['parsed_audio_data']['bits_per_sample'];
   1.245 +                                $getid3->info['audio']['channels']        = $info_real_chunks_current_chunk['parsed_audio_data']['channels'];
   1.246 +
   1.247 +                                if (!empty($getid3->info['audio']['dataformat'])) {
   1.248 +                                    foreach ($getid3->info['audio'] as $key => $value) {
   1.249 +                                        if ($key != 'streams') {
   1.250 +                                            $getid3->info['audio']['streams'][$info_real_chunks_current_chunk['stream_number']][$key] = $value;
   1.251 +                                        }
   1.252 +                                    }
   1.253 +                                }
   1.254 +                                break;
   1.255 +
   1.256 +
   1.257 +                            case 'logical-fileinfo':
   1.258 +
   1.259 +                                $info_real_chunks_current_chunk['logical_fileinfo']['logical_fileinfo_length'] = getid3_lib::BigEndian2Int(substr($info_real_chunks_current_chunk_typespecificdata, 0, 4));
   1.260 +                                // $info_real_chunks_current_chunk['logical_fileinfo']['IGNORE-unknown1']             = getid3_lib::BigEndian2Int(substr($info_real_chunks_current_chunk_typespecificdata, 4, 4));
   1.261 +                                $info_real_chunks_current_chunk['logical_fileinfo']['num_tags']                = getid3_lib::BigEndian2Int(substr($info_real_chunks_current_chunk_typespecificdata, 8, 4));
   1.262 +                                // $info_real_chunks_current_chunk['logical_fileinfo']['IGNORE-unknown2']             = getid3_lib::BigEndian2Int(substr($info_real_chunks_current_chunk_typespecificdata, 12, 4));
   1.263 +                                break;
   1.264 +
   1.265 +                        }
   1.266 +
   1.267 +
   1.268 +                        if (empty($getid3->info['playtime_seconds'])) {
   1.269 +                            $getid3->info['playtime_seconds'] = max($getid3->info['playtime_seconds'], ($info_real_chunks_current_chunk['duration'] + $info_real_chunks_current_chunk['start_time']) / 1000);
   1.270 +                        }
   1.271 +                        
   1.272 +                        if ($info_real_chunks_current_chunk['duration'] > 0) {
   1.273 +                        
   1.274 +                            switch ($info_real_chunks_current_chunk['mime_type']) {
   1.275 +                        
   1.276 +                                case 'audio/x-pn-realaudio':
   1.277 +                                case 'audio/x-pn-multirate-realaudio':
   1.278 +                                    
   1.279 +                                    $getid3->info['audio']['bitrate']    = (isset($getid3->info['audio']['bitrate']) ? $getid3->info['audio']['bitrate'] : 0) + $info_real_chunks_current_chunk['avg_bit_rate'];
   1.280 +                                    $getid3->info['audio']['codec']      = $this->RealAudioCodecFourCClookup($info_real_chunks_current_chunk['parsed_audio_data']['fourcc'], $getid3->info['audio']['bitrate']);
   1.281 +                                    $getid3->info['audio']['dataformat'] = 'real';
   1.282 +                                    $getid3->info['audio']['lossless']   = false;
   1.283 +                                    break;
   1.284 +
   1.285 +
   1.286 +                                case 'video/x-pn-realvideo':
   1.287 +                                case 'video/x-pn-multirate-realvideo':
   1.288 +
   1.289 +                                    $getid3->info['video']['bitrate']            = (isset($getid3->info['video']['bitrate']) ? $getid3->info['video']['bitrate'] : 0) + $info_real_chunks_current_chunk['avg_bit_rate'];
   1.290 +                                    $getid3->info['video']['bitrate_mode']       = 'cbr';
   1.291 +                                    $getid3->info['video']['dataformat']         = 'real';
   1.292 +                                    $getid3->info['video']['lossless']           = false;
   1.293 +                                    $getid3->info['video']['pixel_aspect_ratio'] = (float)1;
   1.294 +                                    break;
   1.295 +
   1.296 +
   1.297 +                                case 'audio/x-ralf-mpeg4-generic':
   1.298 +
   1.299 +                                    $getid3->info['audio']['bitrate']    = (isset($getid3->info['audio']['bitrate']) ? $getid3->info['audio']['bitrate'] : 0) + $info_real_chunks_current_chunk['avg_bit_rate'];
   1.300 +                                    $getid3->info['audio']['codec']      = 'RealAudio Lossless';
   1.301 +                                    $getid3->info['audio']['dataformat'] = 'real';
   1.302 +                                    $getid3->info['audio']['lossless']   = true;
   1.303 +                                    break;
   1.304 +                                    
   1.305 +                            }
   1.306 +                            
   1.307 +                            $getid3->info['bitrate'] = (isset($getid3->info['video']['bitrate']) ? $getid3->info['video']['bitrate'] : 0) + (isset($getid3->info['audio']['bitrate']) ? $getid3->info['audio']['bitrate'] : 0);
   1.308 +                        }
   1.309 +                    }
   1.310 +                    break;
   1.311 +
   1.312 +
   1.313 +                case 'CONT': // Content Description Header (text comments)
   1.314 +
   1.315 +                    $info_real_chunks_current_chunk['object_version'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2));
   1.316 +                    $offset += 2;
   1.317 +
   1.318 +                    if ($info_real_chunks_current_chunk['object_version'] == 0) {
   1.319 +
   1.320 +                        $info_real_chunks_current_chunk['title_len'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2));
   1.321 +                        $offset += 2;
   1.322 +
   1.323 +                        $info_real_chunks_current_chunk['title'] = (string) substr($chunk_data, $offset, $info_real_chunks_current_chunk['title_len']);
   1.324 +                        $offset += $info_real_chunks_current_chunk['title_len'];
   1.325 +
   1.326 +                        $info_real_chunks_current_chunk['artist_len'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2));
   1.327 +                        $offset += 2;
   1.328 +
   1.329 +                        $info_real_chunks_current_chunk['artist'] = (string) substr($chunk_data, $offset, $info_real_chunks_current_chunk['artist_len']);
   1.330 +                        $offset += $info_real_chunks_current_chunk['artist_len'];
   1.331 +
   1.332 +                        $info_real_chunks_current_chunk['copyright_len'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2));
   1.333 +                        $offset += 2;
   1.334 +
   1.335 +                        $info_real_chunks_current_chunk['copyright'] = (string) substr($chunk_data, $offset, $info_real_chunks_current_chunk['copyright_len']);
   1.336 +                        $offset += $info_real_chunks_current_chunk['copyright_len'];
   1.337 +
   1.338 +                        $info_real_chunks_current_chunk['comment_len'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2));
   1.339 +                        $offset += 2;
   1.340 +
   1.341 +                        $info_real_chunks_current_chunk['comment'] = (string) substr($chunk_data, $offset, $info_real_chunks_current_chunk['comment_len']);
   1.342 +                        $offset += $info_real_chunks_current_chunk['comment_len'];
   1.343 +
   1.344 +                        foreach (array ('title'=>'title', 'artist'=>'artist', 'copyright'=>'copyright', 'comment'=>'comment') as $key => $val) {
   1.345 +                            if ($info_real_chunks_current_chunk[$key]) {
   1.346 +                                $getid3->info['real']['comments'][$val][] = trim($info_real_chunks_current_chunk[$key]);
   1.347 +                            }
   1.348 +                        }
   1.349 +                    }
   1.350 +                    break;
   1.351 +
   1.352 +
   1.353 +                case 'DATA': // Data Chunk Header
   1.354 +
   1.355 +                    // do nothing
   1.356 +                    break;
   1.357 +
   1.358 +
   1.359 +                case 'INDX': // Index Section Header
   1.360 +
   1.361 +                    $info_real_chunks_current_chunk['object_version']        = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2));
   1.362 +                    $offset += 2;
   1.363 +
   1.364 +                    if ($info_real_chunks_current_chunk['object_version'] == 0) {
   1.365 +
   1.366 +                        getid3_lib::ReadSequence('BigEndian2Int', $info_real_chunks_current_chunk, $chunk_data, $offset, 
   1.367 +                            array (
   1.368 +                                'num_indices'       => 4,
   1.369 +                                'stream_number'     => 2,
   1.370 +                                'next_index_header' => 4
   1.371 +                            )
   1.372 +                        );
   1.373 +                        $offset += 10;
   1.374 +
   1.375 +                        if ($info_real_chunks_current_chunk['next_index_header'] == 0) {
   1.376 +                            // last index chunk found, ignore rest of file
   1.377 +                            break 2;
   1.378 +                        } else {
   1.379 +                            // non-last index chunk, seek to next index chunk (skipping actual index data)
   1.380 +                            fseek($getid3->fp, $info_real_chunks_current_chunk['next_index_header'], SEEK_SET);
   1.381 +                        }
   1.382 +                    }
   1.383 +                    break;
   1.384 +
   1.385 +
   1.386 +                default:
   1.387 +                    $getid3->warning('Unhandled RealMedia chunk "'.$chunk_name.'" at offset '.$info_real_chunks_current_chunk['offset']);
   1.388 +                    break;
   1.389 +            }
   1.390 +            $chunk_counter++;
   1.391 +        }
   1.392 +
   1.393 +        if (!empty($getid3->info['audio']['streams'])) {
   1.394 +            
   1.395 +            $getid3->info['audio']['bitrate'] = 0;
   1.396 +            
   1.397 +            foreach ($getid3->info['audio']['streams'] as $key => $value_array) {
   1.398 +                $getid3->info['audio']['bitrate'] += $value_array['bitrate'];
   1.399 +            }
   1.400 +        }
   1.401 +
   1.402 +        return true;
   1.403 +    }
   1.404 +
   1.405 +
   1.406 +
   1.407 +    public static function ParseOldRAheader($old_ra_header_data, &$parsed_array) {
   1.408 +
   1.409 +        // http://www.freelists.org/archives/matroska-devel/07-2003/msg00010.html
   1.410 +
   1.411 +        $parsed_array = array ();
   1.412 +        $parsed_array['magic'] = substr($old_ra_header_data, 0, 4);
   1.413 +        
   1.414 +        if ($parsed_array['magic'] != '.ra'."\xFD") {
   1.415 +            return false;
   1.416 +        }
   1.417 +        
   1.418 +        $parsed_array['version1'] = getid3_lib::BigEndian2Int(substr($old_ra_header_data,  4, 2));
   1.419 +
   1.420 +        if ($parsed_array['version1'] < 3) {
   1.421 +
   1.422 +            return false;
   1.423 +        } 
   1.424 +
   1.425 +        if ($parsed_array['version1'] == 3) {
   1.426 +
   1.427 +            $parsed_array['fourcc1']          = '.ra3';
   1.428 +            $parsed_array['bits_per_sample']  = 16;   // hard-coded for old versions?
   1.429 +            $parsed_array['sample_rate']      = 8000; // hard-coded for old versions?
   1.430 +
   1.431 +            getid3_lib::ReadSequence('BigEndian2Int', $parsed_array, $old_ra_header_data, 6,
   1.432 +                array (
   1.433 +                    'header_size'      => 2,
   1.434 +                    'channels'         => 2, // always 1 (?)
   1.435 +                    'IGNORE-unknown1'  => 2,
   1.436 +                    'IGNORE-unknown2'  => 2,
   1.437 +                    'IGNORE-unknown3'  => 2,
   1.438 +                    'bytes_per_minute' => 2,
   1.439 +                    'audio_bytes'      => 4,
   1.440 +                )
   1.441 +            );
   1.442 +            
   1.443 +            $parsed_array['comments_raw'] = substr($old_ra_header_data, 22, $parsed_array['header_size'] - 22 + 1); // not including null terminator
   1.444 +
   1.445 +            $comment_offset = 0;
   1.446 +            
   1.447 +            foreach (array ('title', 'artist', 'copyright') as $name) {
   1.448 +                $comment_length = getid3_lib::BigEndian2Int($parsed_array['comments_raw']{$comment_offset++});
   1.449 +                $parsed_array['comments'][$name][]= substr($parsed_array['comments_raw'], $comment_offset, $comment_length);
   1.450 +                $comment_offset += $comment_length;
   1.451 +            }
   1.452 +    
   1.453 +            $comment_offset++; // final null terminator (?)
   1.454 +            $comment_offset++; // fourcc length (?) should be 4
   1.455 +            
   1.456 +            $parsed_array['fourcc'] = substr($old_ra_header_data, 23 + $comment_offset, 4);
   1.457 +
   1.458 +
   1.459 +        } elseif ($parsed_array['version1'] <= 5) {
   1.460 +
   1.461 +            getid3_lib::ReadSequence('BigEndian2Int', $parsed_array, $old_ra_header_data, 6,
   1.462 +                array (
   1.463 +                    'IGNORE-unknown1'  => 2,
   1.464 +                    'fourcc1'          => -4,
   1.465 +                    'file_size'        => 4,
   1.466 +                    'version2'         => 2,
   1.467 +                    'header_size'      => 4,
   1.468 +                    'codec_flavor_id'  => 2,
   1.469 +                    'coded_frame_size' => 4,
   1.470 +                    'audio_bytes'      => 4,
   1.471 +                    'bytes_per_minute' => 4,
   1.472 +                    'IGNORE-unknown5'  => 4,
   1.473 +                    'sub_packet_h'     => 2,
   1.474 +                    'frame_size'       => 2,
   1.475 +                    'sub_packet_size'  => 2,
   1.476 +                    'IGNORE-unknown6'  => 2
   1.477 +                )
   1.478 +            );
   1.479 +
   1.480 +            switch ($parsed_array['version1']) {
   1.481 +
   1.482 +                case 4:
   1.483 +             
   1.484 +                    getid3_lib::ReadSequence('BigEndian2Int', $parsed_array, $old_ra_header_data, 48,
   1.485 +                        array (
   1.486 +                            'sample_rate'      => 2,
   1.487 +                            'IGNORE-unknown8'  => 2,
   1.488 +                            'bits_per_sample'  => 2,
   1.489 +                            'channels'         => 2,
   1.490 +                            'length_fourcc2'   => 1,
   1.491 +                            'fourcc2'          => -4,
   1.492 +                            'length_fourcc3'   => 1,
   1.493 +                            'fourcc3'          => -4,
   1.494 +                            'IGNORE-unknown9'  => 1,
   1.495 +                            'IGNORE-unknown10' => 2,
   1.496 +                        )
   1.497 +                    );
   1.498 +
   1.499 +                    $parsed_array['comments_raw'] = substr($old_ra_header_data, 69, $parsed_array['header_size'] - 69 + 16);
   1.500 +
   1.501 +                    $comment_offset = 0;
   1.502 +                    
   1.503 +                    foreach (array ('title', 'artist', 'copyright') as $name) {
   1.504 +                        $comment_length = getid3_lib::BigEndian2Int($parsed_array['comments_raw']{$comment_offset++});
   1.505 +                        $parsed_array['comments'][$name][]= substr($parsed_array['comments_raw'], $comment_offset, $comment_length);
   1.506 +                        $comment_offset += $comment_length;
   1.507 +                    }
   1.508 +                    break;
   1.509 +
   1.510 +
   1.511 +                case 5:
   1.512 +                
   1.513 +                getid3_lib::ReadSequence('BigEndian2Int', $parsed_array, $old_ra_header_data, 48,
   1.514 +                        array (
   1.515 +                            'sample_rate'      => 4,
   1.516 +                            'sample_rate2'     => 4,
   1.517 +                            'bits_per_sample'  => 4,
   1.518 +                            'channels'         => 2,
   1.519 +                            'genr'             => -4,
   1.520 +                            'fourcc3'          => -4,
   1.521 +                        )
   1.522 +                    );
   1.523 +                    $parsed_array['comments'] = array ();
   1.524 +                    break;
   1.525 +                    
   1.526 +            }
   1.527 +            
   1.528 +            $parsed_array['fourcc'] = $parsed_array['fourcc3'];
   1.529 +
   1.530 +        }
   1.531 +
   1.532 +        foreach ($parsed_array['comments'] as $key => $value) {
   1.533 +            
   1.534 +            if ($parsed_array['comments'][$key][0] === false) {
   1.535 +                $parsed_array['comments'][$key][0] = '';
   1.536 +            }
   1.537 +        }
   1.538 +
   1.539 +        return true;
   1.540 +    }
   1.541 +
   1.542 +
   1.543 +
   1.544 +    public static function RealAudioCodecFourCClookup($fourcc, $bitrate) {
   1.545 +
   1.546 +        // http://www.its.msstate.edu/net/real/reports/config/tags.stats             
   1.547 +        // http://www.freelists.org/archives/matroska-devel/06-2003/fullthread18.html
   1.548 +        
   1.549 +        static $lookup;
   1.550 +        
   1.551 +        if (empty($lookup)) {
   1.552 +            $lookup['14_4'][8000]  = 'RealAudio v2 (14.4kbps)';
   1.553 +            $lookup['14.4'][8000]  = 'RealAudio v2 (14.4kbps)';
   1.554 +            $lookup['lpcJ'][8000]  = 'RealAudio v2 (14.4kbps)';
   1.555 +            $lookup['28_8'][15200] = 'RealAudio v2 (28.8kbps)';
   1.556 +            $lookup['28.8'][15200] = 'RealAudio v2 (28.8kbps)';
   1.557 +            $lookup['sipr'][4933]  = 'RealAudio v4 (5kbps Voice)';
   1.558 +            $lookup['sipr'][6444]  = 'RealAudio v4 (6.5kbps Voice)';
   1.559 +            $lookup['sipr'][8444]  = 'RealAudio v4 (8.5kbps Voice)';
   1.560 +            $lookup['sipr'][16000] = 'RealAudio v4 (16kbps Wideband)';
   1.561 +            $lookup['dnet'][8000]  = 'RealAudio v3 (8kbps Music)';
   1.562 +            $lookup['dnet'][16000] = 'RealAudio v3 (16kbps Music Low Response)';
   1.563 +            $lookup['dnet'][15963] = 'RealAudio v3 (16kbps Music Mid/High Response)';
   1.564 +            $lookup['dnet'][20000] = 'RealAudio v3 (20kbps Music Stereo)';
   1.565 +            $lookup['dnet'][32000] = 'RealAudio v3 (32kbps Music Mono)';
   1.566 +            $lookup['dnet'][31951] = 'RealAudio v3 (32kbps Music Stereo)';
   1.567 +            $lookup['dnet'][39965] = 'RealAudio v3 (40kbps Music Mono)';
   1.568 +            $lookup['dnet'][40000] = 'RealAudio v3 (40kbps Music Stereo)';
   1.569 +            $lookup['dnet'][79947] = 'RealAudio v3 (80kbps Music Mono)';
   1.570 +            $lookup['dnet'][80000] = 'RealAudio v3 (80kbps Music Stereo)';
   1.571 +
   1.572 +            $lookup['dnet'][0] = 'RealAudio v3';
   1.573 +            $lookup['sipr'][0] = 'RealAudio v4';
   1.574 +            $lookup['cook'][0] = 'RealAudio G2';
   1.575 +            $lookup['atrc'][0] = 'RealAudio 8';
   1.576 +        }
   1.577 +        
   1.578 +        $round_bitrate = intval(round($bitrate));
   1.579 +        
   1.580 +        if (isset($lookup[$fourcc][$round_bitrate])) {
   1.581 +            return $lookup[$fourcc][$round_bitrate];
   1.582 +        }
   1.583 +            
   1.584 +        if (isset($lookup[$fourcc][0])) {
   1.585 +            return $lookup[$fourcc][0];
   1.586 +        }
   1.587 +        
   1.588 +        return $fourcc;
   1.589 +    }
   1.590 +
   1.591 +}
   1.592 +
   1.593 +
   1.594 +?>
   1.595 \ No newline at end of file