[MediaWiki-commits] [Gerrit] mediawiki...TimedMediaHandler[master]: More careful order & size check for video sources

2017-08-13 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/371715 )

Change subject: More careful order & size check for video sources
..


More careful order & size check for video sources

Previously we always used the 'most preferred' codec if
available, even if the size was wildly inappropriate.
This caused slow playback of large VP9-encoded videos
even when a more suitable VP8 or Ogg was available.

Now discarding sources larger than the display size,
unless it's the only thing available.

Bug: T145925
Change-Id: I03ccd572ea386553df037e84ed896237c1f02e49
---
M MwEmbedModules/EmbedPlayer/resources/mw.MediaElement.js
1 file changed, 32 insertions(+), 33 deletions(-)

Approvals:
  Brion VIBBER: Looks good to me, approved
  jenkins-bot: Verified
  Jforrester: Looks good to me, approved



diff --git a/MwEmbedModules/EmbedPlayer/resources/mw.MediaElement.js 
b/MwEmbedModules/EmbedPlayer/resources/mw.MediaElement.js
index 9af4899..f05558a 100644
--- a/MwEmbedModules/EmbedPlayer/resources/mw.MediaElement.js
+++ b/MwEmbedModules/EmbedPlayer/resources/mw.MediaElement.js
@@ -310,46 +310,45 @@
if( !  namedSourceSet[ codec ] ){
continue;
}
-   if( namedSourceSet[ codec ].length == 1 ){
-   mw.log('MediaElement::autoSelectSource: 
Set 1 source via EmbedPlayer.CodecPreference: ' + namedSourceSet[ codec 
][0].getTitle() );
-   return setSelectedSource( 
namedSourceSet[ codec ][0] );
-   } else if( namedSourceSet[ codec ].length > 1 ) 
{
-   // select based on size:
-   // Set via embed resolution closest to 
relative to display size
-   var minSizeDelta = null;
+   // select based on size:
+   // Set via embed resolution closest to relative 
to display size
+   var minSizeDelta = null;
 
-   // unless we're really slow...
-   var isBogoSlow = useBogoSlow && 
OGVCompat.isSlow();
+   // unless we're really slow...
+   var isBogoSlow = useBogoSlow && 
OGVCompat.isSlow();
 
-   if( this.parentEmbedId ){
-   var displayWidth = $('#' + 
this.parentEmbedId).width();
-   $.each( namedSourceSet[ codec 
], function(inx, source ){
-   if ( ( isBogoSlow && 
source.height > 240 )
-   || (useBogoSlow 
&& source.height > 360 ) ) {
-   // On iOS or 
slow Windows devices, large videos decoded in JavaScript are a bad idea!
+   if( this.parentEmbedId ){
+   var displayWidth = $('#' + 
this.parentEmbedId).width();
+   $.each( namedSourceSet[ codec ], 
function(inx, source ){
+   if ( ( isBogoSlow && 
source.height > 240 )
+   || (useBogoSlow && 
source.height > 360 ) ) {
+   // On iOS or slow 
Windows devices, large videos decoded in JavaScript are a bad idea!
+   // continue
+   return true;
+   }
+   if( source.width && 
displayWidth ){
+   if ( source.width > 
displayWidth ) {
+   // Bigger than 
the space to display?
+   // Skip it 
unless it's the only one that fits.
// continue
return true;
}
-   if( source.width && 
displayWidth ){
-   var sizeDelta = 
 Math.abs( source.width - displayWidth );
-   
mw.log('MediaElement::autoSelectSource: size delta : ' + sizeDelta + ' for s:' 
+ source.width );
-   

[MediaWiki-commits] [Gerrit] mediawiki...TimedMediaHandler[master]: More careful order & size check for video sources

2017-08-13 Thread Brion VIBBER (Code Review)
Brion VIBBER has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/371715 )

Change subject: More careful order & size check for video sources
..

More careful order & size check for video sources

Previously we always used the 'most preferred' codec if
available, even if the size was wildly inappropriate.
This caused slow playback of large VP9-encoded videos
even when a more suitable VP8 or Ogg was available.

Now discarding sources larger than the display size,
unless it's the only thing available.

Bug: T145925
Change-Id: I03ccd572ea386553df037e84ed896237c1f02e49
---
M MwEmbedModules/EmbedPlayer/resources/mw.MediaElement.js
1 file changed, 32 insertions(+), 33 deletions(-)


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

diff --git a/MwEmbedModules/EmbedPlayer/resources/mw.MediaElement.js 
b/MwEmbedModules/EmbedPlayer/resources/mw.MediaElement.js
index 9af4899..f05558a 100644
--- a/MwEmbedModules/EmbedPlayer/resources/mw.MediaElement.js
+++ b/MwEmbedModules/EmbedPlayer/resources/mw.MediaElement.js
@@ -310,46 +310,45 @@
if( !  namedSourceSet[ codec ] ){
continue;
}
-   if( namedSourceSet[ codec ].length == 1 ){
-   mw.log('MediaElement::autoSelectSource: 
Set 1 source via EmbedPlayer.CodecPreference: ' + namedSourceSet[ codec 
][0].getTitle() );
-   return setSelectedSource( 
namedSourceSet[ codec ][0] );
-   } else if( namedSourceSet[ codec ].length > 1 ) 
{
-   // select based on size:
-   // Set via embed resolution closest to 
relative to display size
-   var minSizeDelta = null;
+   // select based on size:
+   // Set via embed resolution closest to relative 
to display size
+   var minSizeDelta = null;
 
-   // unless we're really slow...
-   var isBogoSlow = useBogoSlow && 
OGVCompat.isSlow();
+   // unless we're really slow...
+   var isBogoSlow = useBogoSlow && 
OGVCompat.isSlow();
 
-   if( this.parentEmbedId ){
-   var displayWidth = $('#' + 
this.parentEmbedId).width();
-   $.each( namedSourceSet[ codec 
], function(inx, source ){
-   if ( ( isBogoSlow && 
source.height > 240 )
-   || (useBogoSlow 
&& source.height > 360 ) ) {
-   // On iOS or 
slow Windows devices, large videos decoded in JavaScript are a bad idea!
+   if( this.parentEmbedId ){
+   var displayWidth = $('#' + 
this.parentEmbedId).width();
+   $.each( namedSourceSet[ codec ], 
function(inx, source ){
+   if ( ( isBogoSlow && 
source.height > 240 )
+   || (useBogoSlow && 
source.height > 360 ) ) {
+   // On iOS or slow 
Windows devices, large videos decoded in JavaScript are a bad idea!
+   // continue
+   return true;
+   }
+   if( source.width && 
displayWidth ){
+   if ( source.width > 
displayWidth ) {
+   // Bigger than 
the space to display?
+   // Skip it 
unless it's the only one that fits.
// continue
return true;
}
-   if( source.width && 
displayWidth ){
-   var sizeDelta = 
 Math.abs( source.width - displayWidth );
-   
mw.log('MediaElement::autoSelectSource: size delta : ' + sizeDelta + ' for s:' 
+ source.width );
-   if(