Brian Wolff has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/148603

Change subject: [WIP] Show appropriately sized video sources first.
......................................................................

[WIP] Show appropriately sized video sources first.

When executing the <video> tags, browsers generally go for the
first source element that they can play. Currently we were ordering
them in ascending order by bitrate. This meant 160p was the first
choice. This seems rather wrong.

Instead order them by ( has a height > player height, smallest bitrate )
This should remove too small transcodes from showing up first well
still prioritizing the smaller files.

WIP mostly because this needs unit tests.

See bug 66143 comment 20.

Change-Id: I6f3316477175634a338efc16a866c7cad0dfc9b3
---
M TimedMediaTransformOutput.php
1 file changed, 36 insertions(+), 2 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TimedMediaHandler 
refs/changes/03/148603/1

diff --git a/TimedMediaTransformOutput.php b/TimedMediaTransformOutput.php
index 18415f9..1c94474 100644
--- a/TimedMediaTransformOutput.php
+++ b/TimedMediaTransformOutput.php
@@ -231,7 +231,41 @@
                return $popUpWidth;
        }
 
-       static function sortMediaByBandwidth( $a, $b){
+       /**
+        * Sort media by bandwidth, but with things not wide enough at end
+        *
+        * The list should be in preferred source order, so we want the file
+        * with the lowest bitrate (to save bandwidth) first, but we also want
+        * appropriate resolution files before the 160p transcodes.
+        */
+       private function sortMediaByBandwidth( $a, $b ) {
+               $width = $this->getPlayerWidth();
+               $maxWidth = $this->getPopupPlayerWidth();
+               if ( $this->useImagePopUp() || $width > $maxWidth ) {
+                       // If its a pop-up player than we should use the pop up 
player size
+                       // if its a normal player, but has a bigger width than 
the pop-up
+                       // player, then we use the pop-up players width as the 
target width
+                       // as that is equivalent to the max transcode size. 
Otherwise this
+                       // will suggest the original file as the best source, 
which seems like
+                       // a potentially bad idea, as it could be anything size 
wise.
+                       $width = $maxWidth;
+               }
+
+               if ( $a['width'] < $width && $b['width'] >= $width ) {
+                       // $a is not wide enough but $b is
+                       // so we consider $a > $b as we want $b before $a
+                       return 1;
+               }
+               if ( $a['width'] >= $width && $b['width'] < $width ) {
+                       // $b not wide enough, so $a must be preferred.
+                       return -1;
+               }
+               if ( $a['width'] < $width && $b['width'] < $width && 
$a['width'] != $b['width'] ) {
+                       // both are too small. Go with the one closer to the 
target width
+                       return ( $a['width'] < $b['width'] ) ? -1 : 1;
+               }
+               // Both are big enough, or both equally to small. Go with the 
one
+               // that has a lower bit-rate (as it will be faster to download).
                return ( $a['bandwidth'] < $b['bandwidth'] ) ? -1 : 1;
        }
        /**
@@ -254,7 +288,7 @@
 
                // Sort sources by bandwidth least to greatest ( so default 
selection on resource constrained
                // browsers ( without js? ) go with minimal source.
-               uasort( $mediaSources, 
'TimedMediaTransformOutput::sortMediaByBandwidth' );
+               uasort( $mediaSources, array( $this, 'sortMediaByBandwidth' ) );
 
                // We prefix some source attributes with data- to pass along to 
the javascript player
                $prefixedSourceAttr = Array( 'width', 'height', 'title', 
'shorttitle', 'bandwidth', 'framerate', 'disablecontrols' );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6f3316477175634a338efc16a866c7cad0dfc9b3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/TimedMediaHandler
Gerrit-Branch: master
Gerrit-Owner: Brian Wolff <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to