Index: trunk/extensions/OggHandler/OggHandler.php |
— | — | @@ -34,6 +34,9 @@ |
35 | 35 | |
36 | 36 | /******************* CONFIGURATION STARTS HERE **********************/ |
37 | 37 | |
| 38 | +//if wgPlayerStats collection is enabled or not |
| 39 | +$wgPlayerStatsCollection=false; |
| 40 | + |
38 | 41 | // Location of the FFmpeg binary |
39 | 42 | $wgFFmpegLocation = 'ffmpeg'; |
40 | 43 | |
Index: trunk/extensions/OggHandler/PEAR/File_Ogg/File/Ogg/Bitstream.php |
— | — | @@ -83,11 +83,14 @@ |
84 | 84 | foreach ( $streamData as $packet ) { |
85 | 85 | $this->_streamSize += $packet['data_length']; |
86 | 86 | # Reject -1 as a granule pos, that means no segment finished in the packet |
87 | | - if ( $packet['abs_granule_pos'] != 'ffffffffffffffff' ) { |
88 | | - $this->_lastGranulePos = max($this->_lastGranulePos, $packet['abs_granule_pos']); |
| 87 | + if ( $packet['abs_granule_pos'] != 'ffffffffffffffff' ) { |
| 88 | + $currentPos = $packet['abs_granule_pos']; |
| 89 | + $this->_lastGranulePos = max($this->_lastGranulePos, $currentPos); |
89 | 90 | //set the _firstGranulePos |
90 | | - if( $this->_firstGranulePos == 0) |
91 | | - $this->_firstGranulePos =$this->_lastGranulePos; |
| 91 | + if( hexdec( $this->_firstGranulePos ) === 0){ |
| 92 | + //print "on stream: $streamSerial set first gran:". $currentPos.": ". hexdec( $currentPos ) ."\n"; |
| 93 | + $this->_firstGranulePos = $currentPos; |
| 94 | + } |
92 | 95 | } |
93 | 96 | } |
94 | 97 | $this->_group = $streamData[0]['group']; |
Index: trunk/extensions/OggHandler/PEAR/File_Ogg/File/Ogg/Theora.php |
— | — | @@ -49,11 +49,20 @@ |
50 | 50 | File_Ogg_Media::File_Ogg_Media($streamSerial, $streamData, $filePointer); |
51 | 51 | $this->_decodeIdentificationHeader(); |
52 | 52 | $this->_decodeCommentsHeader(); |
53 | | - |
| 53 | + $endSec = $this->getSecondsFromGranulePos( $this->_lastGranulePos ); |
| 54 | + |
54 | 55 | $startSec = $this->getSecondsFromGranulePos( $this->_firstGranulePos ); |
55 | | - $endSec = $this->getSecondsFromGranulePos( $this->_lastGranulePos ); |
56 | | - $this->_streamLength = $endSec - $startSec; |
57 | | - |
| 56 | + |
| 57 | + //make sure the offset is worth taking into account oggz_chop related hack |
| 58 | + if( $startSec > 1) |
| 59 | + $this->_streamLength = $endSec - $startSec; |
| 60 | + else |
| 61 | + $this->_streamLength = $endSec; |
| 62 | + |
| 63 | + /*print "last gran: $this->_lastGranulePos = $endSec \n |
| 64 | +first gran: $this->_firstGranulePos = $startSec \n |
| 65 | +stream len: $this->_streamLength;";*/ |
| 66 | + |
58 | 67 | $this->_avgBitrate = $this->_streamLength ? ($this->_streamSize * 8) / $this->_streamLength : 0; |
59 | 68 | } |
60 | 69 | function getSecondsFromGranulePos($granulePos){ |
Index: trunk/extensions/OggHandler/PEAR/File_Ogg/File/Ogg/Speex.php |
— | — | @@ -43,11 +43,22 @@ |
44 | 44 | parent::__construct($streamSerial, $streamData, $filePointer); |
45 | 45 | $this->_decodeHeader(); |
46 | 46 | $this->_decodeCommentsHeader(); |
47 | | - $this->_streamLength = |
| 47 | + $endSec = |
48 | 48 | (( '0x' . substr( $this->_lastGranulePos, 0, 8 ) ) * pow(2, 32) |
49 | 49 | + ( '0x' . substr( $this->_lastGranulePos, 8, 8 ) )) |
50 | 50 | / $this->_header['rate']; |
51 | | - } |
| 51 | + |
| 52 | + $startSec = |
| 53 | + (( '0x' . substr( $this->_firstGranulePos, 0, 8 ) ) * pow(2, 32) |
| 54 | + + ( '0x' . substr( $this->_firstGranulePos, 8, 8 ) )) |
| 55 | + / $this->_header['rate']; |
| 56 | + |
| 57 | + //make sure the offset is worth taking into account oggz_chop related hack |
| 58 | + if( $startSec > 1) |
| 59 | + $this->_streamLength = $endSec - $startSec; |
| 60 | + else |
| 61 | + $this->_streamLength = $endSec; |
| 62 | + } |
52 | 63 | |
53 | 64 | /** |
54 | 65 | * Get a short string describing the type of the stream |
Index: trunk/extensions/OggHandler/PEAR/File_Ogg/File/Ogg/Vorbis.php |
— | — | @@ -168,10 +168,23 @@ |
169 | 169 | File_Ogg_Bitstream::File_Ogg_Bitstream($streamSerial, $streamData, $filePointer); |
170 | 170 | $this->_decodeIdentificationHeader(); |
171 | 171 | $this->_decodeCommentsHeader(OGG_VORBIS_COMMENTS_HEADER, OGG_VORBIS_COMMENTS_PAGE_OFFSET); |
172 | | - $this->_streamLength = |
173 | | - (( '0x' . substr( $this->_lastGranulePos, 0, 8 ) ) * pow(2, 32) |
| 172 | + $endSec = (( '0x' . substr( $this->_lastGranulePos, 0, 8 ) ) * pow(2, 32) |
174 | 173 | + ( '0x' . substr( $this->_lastGranulePos, 8, 8 ) )) |
175 | 174 | / $this->_idHeader['audio_sample_rate']; |
| 175 | + |
| 176 | + |
| 177 | + $startSec = (( '0x' . substr( $this->_firstGranulePos, 0, 8 ) ) * pow(2, 32) |
| 178 | + + ( '0x' . substr( $this->_firstGranulePos, 8, 8 ) )) |
| 179 | + / $this->_idHeader['audio_sample_rate']; |
| 180 | + |
| 181 | + $this->_streamLength = $stream_endLength - $stream_startLength; |
| 182 | + |
| 183 | + //make sure the offset is worth taking into account oggz_chop related hack |
| 184 | + if( $startSec > 1) |
| 185 | + $this->_streamLength = $endSec - $startSec; |
| 186 | + else |
| 187 | + $this->_streamLength = $endSec; |
| 188 | + |
176 | 189 | $this->_avgBitrate = $this->_streamLength ? ($this->_streamSize * 8) / $this->_streamLength : 0; |
177 | 190 | } |
178 | 191 | |
Index: trunk/extensions/OggHandler/OggHandler_body.php |
— | — | @@ -390,7 +390,9 @@ |
391 | 391 | } |
392 | 392 | |
393 | 393 | function setHeaders( $out ) { |
394 | | - global $wgOggScriptVersion, $wgCortadoJarFile, $wgServer; |
| 394 | + global $wgOggScriptVersion, $wgCortadoJarFile, $wgServer, $wgUser, $wgScriptPath, |
| 395 | + $wgPlayerStatsCollection; |
| 396 | + |
395 | 397 | if ( $out->hasHeadItem( 'OggHandler' ) ) { |
396 | 398 | return; |
397 | 399 | } |
— | — | @@ -430,7 +432,24 @@ |
431 | 433 | } |
432 | 434 | </style> |
433 | 435 | EOT |
434 | | - ); |
| 436 | +); |
| 437 | + |
| 438 | + //if collecting stats add relevant code: |
| 439 | + if( $wgPlayerStatsCollection ){ |
| 440 | + //the player stats js file MUST be on the same server as OggHandler |
| 441 | + $playerStats_js = htmlspecialchars ( $wgScriptPath ). '/extensions/PlayerStatsGrabber/playerStats.js'; |
| 442 | + |
| 443 | + $jsUserHash = sha1( $wgUser->getName() . $wgProxyKey ); |
| 444 | + $enUserHash = Xml::encodeJsVar( $jsUserHash ); |
| 445 | + |
| 446 | + $out->addHeadItem('playerStatsCollection', <<<EOT |
| 447 | +<script type="text/javascript"> |
| 448 | +wgOggPlayer.userHash = $enUserHash; |
| 449 | +</script> |
| 450 | +<script type="text/javascript" src="$playerStats_js"></script> |
| 451 | +EOT |
| 452 | +); |
| 453 | + } |
435 | 454 | |
436 | 455 | } |
437 | 456 | |