r42275 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r42274‎ | r42275 | r42276 >
Date:20:52, 20 October 2008
Author:dale
Status:old (Comments)
Tags:
Comment:
changed to use a single one time use global variable (hopefully addresses -r42237 revert )
Modified paths:
  • /trunk/extensions/OggHandler/OggHandler.php (modified) (history)
  • /trunk/extensions/OggHandler/OggHandler_body.php (modified) (history)
  • /trunk/extensions/OggHandler/PEAR/File_Ogg/File/Ogg/Bitstream.php (modified) (history)
  • /trunk/extensions/OggHandler/PEAR/File_Ogg/File/Ogg/Speex.php (modified) (history)
  • /trunk/extensions/OggHandler/PEAR/File_Ogg/File/Ogg/Theora.php (modified) (history)
  • /trunk/extensions/OggHandler/PEAR/File_Ogg/File/Ogg/Vorbis.php (modified) (history)

Diff [purge]

Index: trunk/extensions/OggHandler/OggHandler.php
@@ -34,6 +34,9 @@
3535
3636 /******************* CONFIGURATION STARTS HERE **********************/
3737
 38+//if wgPlayerStats collection is enabled or not
 39+$wgPlayerStatsCollection=false;
 40+
3841 // Location of the FFmpeg binary
3942 $wgFFmpegLocation = 'ffmpeg';
4043
Index: trunk/extensions/OggHandler/PEAR/File_Ogg/File/Ogg/Bitstream.php
@@ -83,11 +83,14 @@
8484 foreach ( $streamData as $packet ) {
8585 $this->_streamSize += $packet['data_length'];
8686 # 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);
8990 //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+ }
9295 }
9396 }
9497 $this->_group = $streamData[0]['group'];
Index: trunk/extensions/OggHandler/PEAR/File_Ogg/File/Ogg/Theora.php
@@ -49,11 +49,20 @@
5050 File_Ogg_Media::File_Ogg_Media($streamSerial, $streamData, $filePointer);
5151 $this->_decodeIdentificationHeader();
5252 $this->_decodeCommentsHeader();
53 -
 53+ $endSec = $this->getSecondsFromGranulePos( $this->_lastGranulePos );
 54+
5455 $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+
5867 $this->_avgBitrate = $this->_streamLength ? ($this->_streamSize * 8) / $this->_streamLength : 0;
5968 }
6069 function getSecondsFromGranulePos($granulePos){
Index: trunk/extensions/OggHandler/PEAR/File_Ogg/File/Ogg/Speex.php
@@ -43,11 +43,22 @@
4444 parent::__construct($streamSerial, $streamData, $filePointer);
4545 $this->_decodeHeader();
4646 $this->_decodeCommentsHeader();
47 - $this->_streamLength =
 47+ $endSec =
4848 (( '0x' . substr( $this->_lastGranulePos, 0, 8 ) ) * pow(2, 32)
4949 + ( '0x' . substr( $this->_lastGranulePos, 8, 8 ) ))
5050 / $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+ }
5263
5364 /**
5465 * 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 @@
169169 File_Ogg_Bitstream::File_Ogg_Bitstream($streamSerial, $streamData, $filePointer);
170170 $this->_decodeIdentificationHeader();
171171 $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)
174173 + ( '0x' . substr( $this->_lastGranulePos, 8, 8 ) ))
175174 / $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+
176189 $this->_avgBitrate = $this->_streamLength ? ($this->_streamSize * 8) / $this->_streamLength : 0;
177190 }
178191
Index: trunk/extensions/OggHandler/OggHandler_body.php
@@ -390,7 +390,9 @@
391391 }
392392
393393 function setHeaders( $out ) {
394 - global $wgOggScriptVersion, $wgCortadoJarFile, $wgServer;
 394+ global $wgOggScriptVersion, $wgCortadoJarFile, $wgServer, $wgUser, $wgScriptPath,
 395+ $wgPlayerStatsCollection;
 396+
395397 if ( $out->hasHeadItem( 'OggHandler' ) ) {
396398 return;
397399 }
@@ -430,7 +432,24 @@
431433 }
432434 </style>
433435 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+ }
435454
436455 }
437456

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r42237Reverting r42184 "fixed issues of r41969 revert. Removed XSS, ( less variable...brion00:11, 20 October 2008

Comments

#Comment by Brion VIBBER (talk | contribs)   23:27, 23 October 2008

Shouldn't blow anyting up. :)

Status & tagging log