r50467 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r50466‎ | r50467 | r50468 >
Date:05:46, 11 May 2009
Author:dale
Status:ok (Comments)
Tags:
Comment:
patch to keep track of offset time in metadata and send it out to the player.

This allows us to present accurate presentation time for a given clip that is it-self a segment of a longer clip. (for example a segment downloaded from archive.org) This applies to oggz_chop segments being played with the mv_embed javascript player where the controls are based in html. Having the time offset is necessary to build a playhead from the offset timestamps given in callbacks during playback.

(I would have submitted a bug and patch to bugzilla but its giving me trouble)
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.php (modified) (history)
  • /trunk/extensions/OggHandler/PEAR/File_Ogg/File/Ogg/Media.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
@@ -43,7 +43,7 @@
4444 $wgPlayerStatsCollection=false;
4545
4646 // Location of the FFmpeg binary
47 -$wgFFmpegLocation = 'ffmpeg';
 47+$wgFFmpegLocation = '/usr/bin/ffmpeg';
4848
4949 // Filename or URL path to the Cortado Java player applet.
5050 //
Index: trunk/extensions/OggHandler/PEAR/File_Ogg/File/Ogg.php
@@ -164,7 +164,7 @@
165165 * Total length in seconds of the entire file
166166 */
167167 var $_totalLength;
168 -
 168+ var $_startOffset = false;
169169 /**
170170 * Returns an interface to an Ogg physical stream.
171171 *
@@ -456,8 +456,13 @@
457457 if (isset($groupLengths[$group])) {
458458 $groupLengths[$group] = max($groupLengths[$group], $stream->getLength());
459459 } else {
460 - $groupLengths[$group] = $stream->getLength();
 460+ $groupLengths[$group] = $stream->getLength();
461461 }
 462+ //just store the startOffset for the first stream:
 463+ if( $this->_startOffset === false ){
 464+ $this->_startOffset = $stream->getStartOffset();
 465+ }
 466+
462467 }
463468 }
464469 $this->_groupLengths = $groupLengths;
@@ -570,8 +575,17 @@
571576 else
572577 return array();
573578 }
574 -
575579 /**
 580+ * getStartOffset
 581+ *
 582+ * @return unknown
 583+ */
 584+ function getStartOffset(){
 585+ if( $this->_startOffset === false)
 586+ return 0;
 587+ return $this->_startOffset;
 588+ }
 589+ /**
576590 * Get the total length of the group of streams
577591 */
578592 function getLength() {
Index: trunk/extensions/OggHandler/PEAR/File_Ogg/File/Ogg/Media.php
@@ -48,7 +48,9 @@
4949 * Length of the stream in seconds
5050 */
5151 var $_streamLength;
52 -
 52+
 53+ /* Start offset of the stream in seconds */
 54+ var $_startOffset = 0;
5355 /*function File_Ogg_Media($streamSerial, $streamData, $filePointer)
5456 {
5557 File_Ogg_Bitstream::File_Ogg_Bitstream($streamSerial, $streamData, $filePointer);
@@ -224,4 +226,12 @@
225227 {
226228 return $this->_streamLength;
227229 }
 230+ /**
 231+ * Get the start offset of the stream in seconds
 232+ *
 233+ * @return float
 234+ */
 235+ function getStartOffset(){
 236+ return $this->_startOffset;
 237+ }
228238 }
Index: trunk/extensions/OggHandler/PEAR/File_Ogg/File/Ogg/Theora.php
@@ -40,7 +40,7 @@
4141 * @version CVS: $Id: Theora.php,v 1.9 2005/11/16 20:43:27 djg Exp $
4242 */
4343 class File_Ogg_Theora extends File_Ogg_Media
44 -{
 44+{
4545 /**
4646 * @access private
4747 */
@@ -54,10 +54,12 @@
5555 $startSec = $this->getSecondsFromGranulePos( $this->_firstGranulePos );
5656
5757 //make sure the offset is worth taking into account oggz_chop related hack
58 - if( $startSec > 1)
 58+ if( $startSec > 1){
5959 $this->_streamLength = $endSec - $startSec;
60 - else
 60+ $this->_startOffset = $startSec;
 61+ }else{
6162 $this->_streamLength = $endSec;
 63+ }
6264
6365 /*print "last gran: $this->_lastGranulePos = $endSec \n
6466 first gran: $this->_firstGranulePos = $startSec \n
Index: trunk/extensions/OggHandler/PEAR/File_Ogg/File/Ogg/Speex.php
@@ -54,10 +54,12 @@
5555 / $this->_header['rate'];
5656
5757 //make sure the offset is worth taking into account oggz_chop related hack
58 - if( $startSec > 1)
 58+ if( $startSec > 1){
5959 $this->_streamLength = $endSec - $startSec;
60 - else
 60+ $this->_startOffset = $startSec;
 61+ }else{
6162 $this->_streamLength = $endSec;
 63+ }
6264 }
6365
6466 /**
Index: trunk/extensions/OggHandler/PEAR/File_Ogg/File/Ogg/Vorbis.php
@@ -148,10 +148,13 @@
149149 * @access private
150150 * @var int
151151 */
152 - var $_streamLength;
153 -
 152+ var $_streamLength;
154153
155154 /**
 155+ * the start offset of this stream in seconds
 156+ */
 157+ var $_startOffset;
 158+ /**
156159 * Constructor for accessing a Vorbis logical stream.
157160 *
158161 * This method is the constructor for the native-PHP interface to a Vorbis logical
@@ -180,10 +183,12 @@
181184 $this->_streamLength = $stream_endLength - $stream_startLength;
182185
183186 //make sure the offset is worth taking into account oggz_chop related hack
184 - if( $startSec > 1)
 187+ if( $startSec > 1){
185188 $this->_streamLength = $endSec - $startSec;
186 - else
 189+ $this->_startOffset = $startSec;
 190+ }else{
187191 $this->_streamLength = $endSec;
 192+ }
188193
189194 $this->_avgBitrate = $this->_streamLength ? ($this->_streamSize * 8) / $this->_streamLength : 0;
190195 }
@@ -386,7 +391,14 @@
387392 {
388393 return ($this->_streamLength);
389394 }
390 -
 395+ /**
 396+ * Get the start offset of the stream in seconds
 397+ * @access public
 398+ * @return int
 399+ */
 400+ function getStartOffset(){
 401+ return ($this->_startOffset);
 402+ }
391403 /**
392404 * States whether this logical stream was encoded in mono.
393405 *
Index: trunk/extensions/OggHandler/OggHandler_body.php
@@ -130,7 +130,7 @@
131131 'group' => $stream->getGroup(),
132132 'type' => $stream->getType(),
133133 'vendor' => $stream->getVendor(),
134 - 'length' => $stream->getLength(),
 134+ 'length' => $stream->getLength(),
135135 'size' => $stream->getSize(),
136136 'header' => $stream->getHeader(),
137137 'comments' => $stream->getComments()
@@ -138,7 +138,9 @@
139139 }
140140 }
141141 $metadata['streams'] = $streams;
142 - $metadata['length'] = $f->getLength();
 142+ $metadata['length'] = $f->getLength();
 143+ //get the offset of the file (in cases where the file is a segment copy)
 144+ $metadata['offset'] = $f->getStartOffset();
143145 } catch ( PEAR_Exception $e ) {
144146 // File not found, invalid stream, etc.
145147 $metadata['error'] = array(
@@ -178,6 +180,7 @@
179181 $srcHeight = $file->getHeight();
180182 $height = $srcWidth == 0 ? $srcHeight : $width * $srcHeight / $srcWidth;
181183 $length = $this->getLength( $file );
 184+ $offset = $this->getOffset( $file );
182185 $noPlayer = isset( $params['noplayer'] );
183186 $noIcon = isset( $params['noicon'] );
184187
@@ -206,16 +209,16 @@
207210 } else {
208211 $width = $params['width'];
209212 }
210 - return new OggAudioDisplay( $file, $file->getURL(), $width, $height, $length, $dstPath, $noIcon );
 213+ return new OggAudioDisplay( $file, $file->getURL(), $width, $height, $length, $dstPath, $noIcon, $offset );
211214 }
212215
213216 // Video thumbnail only
214217 if ( $noPlayer ) {
215 - return new ThumbnailImage( $file, $dstUrl, $width, $height, $dstPath );
 218+ return new ThumbnailImage( $file, $dstUrl, $width, $height, $dstPath , $noIcon, $offset);
216219 }
217220
218221 if ( $flags & self::TRANSFORM_LATER ) {
219 - return new OggVideoDisplay( $file, $file->getURL(), $dstUrl, $width, $height, $length, $dstPath );
 222+ return new OggVideoDisplay( $file, $file->getURL(), $dstUrl, $width, $height, $length, $dstPath, $noIcon, $offset);
220223 }
221224
222225 $thumbTime = false;
@@ -315,6 +318,14 @@
316319 return $metadata['length'];
317320 }
318321 }
 322+ function getOffset( $file ){
 323+ $metadata = $this->unpackMetadata( $file->getMetadata() );
 324+ if ( !$metadata || isset( $metadata['error'] ) ) {
 325+ return 0;
 326+ } else {
 327+ return $metadata['offset'];
 328+ }
 329+ }
319330
320331 function getStreamTypes( $file ) {
321332 $streamTypes = '';
@@ -486,7 +497,7 @@
487498 static $serial = 0;
488499
489500 function __construct( $file, $videoUrl, $thumbUrl, $width, $height, $length, $isVideo,
490 - $path, $noIcon = false )
 501+ $path, $noIcon = false, $offset )
491502 {
492503 $this->file = $file;
493504 $this->videoUrl = $videoUrl;
@@ -494,6 +505,7 @@
495506 $this->width = round( $width );
496507 $this->height = round( $height );
497508 $this->length = round( $length );
 509+ $this->offset = round( $offset );
498510 $this->isVideo = $isVideo;
499511 $this->path = $path;
500512 $this->noIcon = $noIcon;
@@ -514,6 +526,7 @@
515527 $url = $this->videoUrl;
516528 }
517529 $length = intval( $this->length );
 530+ $offset = intval( $this->offset );
518531 $width = intval( $this->width );
519532 $height = intval( $this->height );
520533 $alt = empty( $options['alt'] ) ? $this->file->getTitle()->getText() : $options['alt'];
@@ -591,6 +604,7 @@
592605 'width' => $width,
593606 'height' => $playerHeight,
594607 'length' => $length,
 608+ 'offset' => $offset,
595609 'linkUrl' => $linkUrl,
596610 'isVideo' => $this->isVideo ) );
597611
@@ -623,14 +637,14 @@
624638 }
625639
626640 class OggVideoDisplay extends OggTransformOutput {
627 - function __construct( $file, $videoUrl, $thumbUrl, $width, $height, $length, $path ) {
628 - parent::__construct( $file, $videoUrl, $thumbUrl, $width, $height, $length, true, $path, false );
 641+ function __construct( $file, $videoUrl, $thumbUrl, $width, $height, $length, $path, $noIcon=false, $offset=0 ) {
 642+ parent::__construct( $file, $videoUrl, $thumbUrl, $width, $height, $length, true, $path, false, $offset );
629643 }
630644 }
631645
632646 class OggAudioDisplay extends OggTransformOutput {
633 - function __construct( $file, $videoUrl, $width, $height, $length, $path, $noIcon = false ) {
634 - parent::__construct( $file, $videoUrl, false, $width, $height, $length, false, $path, $noIcon );
 647+ function __construct( $file, $videoUrl, $width, $height, $length, $path, $noIcon = false, $offset=0 ) {
 648+ parent::__construct( $file, $videoUrl, false, $width, $height, $length, false, $path, $noIcon, $offset );
635649 }
636650 }
637651

Comments

#Comment by Tim Starling (talk | contribs)   10:28, 4 June 2009

I'll see about patching this into PEAR and doing a release there after I'm done with current tasks. There's also a bug reported at PEAR that needs a release. Getting CVS accounts there is a bit of a hassle so it's probably best if I just do it.

Status & tagging log