jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/332799 )

Change subject: [File_Ogg] calculate length for FLAC when header lists unknown
......................................................................


[File_Ogg] calculate length for FLAC when header lists unknown

0 for total length in the FLAC header indicates 'unknown', which
we can calculate the actual value for similarly to Vorbis/Opus/etc.
Add a check and branch.

Fixes https://pear.php.net/bugs/bug.php?id=21164

Also committing this upstream so we'll be closer to in sync.

Bug: T87619
Change-Id: I8a7caff6f1a9e4b81fb66608b9f5cccfde0065ad
---
M handlers/OggHandler/File_Ogg/File/Ogg/Flac.php
1 file changed, 26 insertions(+), 2 deletions(-)

Approvals:
  jenkins-bot: Verified
  TheDJ: Looks good to me, approved



diff --git a/handlers/OggHandler/File_Ogg/File/Ogg/Flac.php 
b/handlers/OggHandler/File_Ogg/File/Ogg/Flac.php
index 6838ba6..bf98d60 100644
--- a/handlers/OggHandler/File_Ogg/File/Ogg/Flac.php
+++ b/handlers/OggHandler/File_Ogg/File/Ogg/Flac.php
@@ -42,8 +42,32 @@
         parent::__construct($streamSerial, $streamData, $filePointer);
         $this->_decodeHeader();
         $this->_decodeCommentsHeader();
-        $this->_streamLength    = $this->_streamInfo['total_samples']
-            / $this->_streamInfo['sample_rate'];
+
+        if ($this->_streamInfo['total_samples'] > 0) {
+            $this->_streamLength    = $this->_streamInfo['total_samples']
+                                    / $this->_streamInfo['sample_rate'];
+        } else {
+            // Header may have 0 for total_samples in which case we have to 
check.
+            // https://xiph.org/flac/format.html#metadata_block_streaminfo
+              $endSec =  $this->getSecondsFromGranulePos( 
$this->_lastGranulePos );
+              $startSec = $this->getSecondsFromGranulePos( 
$this->_firstGranulePos );
+
+            //make sure the offset is worth taking into account oggz_chop 
related hack
+            if( $startSec > 1) {
+                $this->_streamLength = $endSec - $startSec;
+                $this->_startOffset = $startSec;
+            } else {
+                $this->_streamLength = $endSec;
+            }
+        }
+
+        $this->_avgBitrate      = $this->_streamLength ? ($this->_streamSize * 
8) / $this->_streamLength : 0;
+    }
+
+    function getSecondsFromGranulePos( $granulePos ){
+        return (( '0x' . substr( $granulePos, 0, 8 ) ) * pow(2, 32)
+              + ( '0x' . substr( $granulePos, 8, 8 ) ))
+              / $this->_streamInfo['sample_rate'];
     }
 
     /**

-- 
To view, visit https://gerrit.wikimedia.org/r/332799
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I8a7caff6f1a9e4b81fb66608b9f5cccfde0065ad
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/TimedMediaHandler
Gerrit-Branch: master
Gerrit-Owner: Brion VIBBER <br...@wikimedia.org>
Gerrit-Reviewer: TheDJ <hartman.w...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to