[Android] Improve libvlc aspect ratios

Nicolas Pomepuy git at videolan.org
Thu Feb 24 10:58:19 UTC 2022


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Mon Feb 21 10:18:43 2022 +0100| [34aa12efe9df1a38b4249f9695144b8202af1af9] | committer: Nicolas Pomepuy

Improve libvlc aspect ratios

> https://code.videolan.org/videolan/vlc-android/commit/34aa12efe9df1a38b4249f9695144b8202af1af9
---

 libvlc/src/org/videolan/libvlc/MediaPlayer.java | 32 +++++++++++++++++----
 libvlc/src/org/videolan/libvlc/VideoHelper.java | 37 +++++++++++++++++--------
 2 files changed, 51 insertions(+), 18 deletions(-)

diff --git a/libvlc/src/org/videolan/libvlc/MediaPlayer.java b/libvlc/src/org/videolan/libvlc/MediaPlayer.java
index fada058c0..a11f1d745 100644
--- a/libvlc/src/org/videolan/libvlc/MediaPlayer.java
+++ b/libvlc/src/org/videolan/libvlc/MediaPlayer.java
@@ -393,12 +393,32 @@ public class MediaPlayer extends VLCObject<MediaPlayer.Event> {
 
     //Video size constants
     public enum ScaleType {
-        SURFACE_BEST_FIT,
-        SURFACE_FIT_SCREEN,
-        SURFACE_FILL,
-        SURFACE_16_9,
-        SURFACE_4_3,
-        SURFACE_ORIGINAL
+        SURFACE_BEST_FIT(null),
+        SURFACE_FIT_SCREEN(null),
+        SURFACE_FILL(null),
+        SURFACE_16_9(16F/9F),
+        SURFACE_4_3(4F/3F),
+        SURFACE_16_10(16F/10F),
+        SURFACE_221_1(2.21F),
+        SURFACE_235_1(2.35F),
+        SURFACE_239_1(2.39F),
+        SURFACE_5_4(5F/4F),
+        SURFACE_ORIGINAL(null);
+
+
+        private final Float ratio;
+
+        ScaleType(Float ratio) {
+            this.ratio = ratio;
+        }
+
+        public Float getRatio() {
+            return ratio;
+        }
+
+        static public ScaleType[] getMainScaleTypes() {
+            return new ScaleType[]{SURFACE_BEST_FIT, SURFACE_FIT_SCREEN, SURFACE_FILL, SURFACE_16_9, SURFACE_4_3, SURFACE_ORIGINAL};
+        }
     }
     public static final int SURFACE_SCALES_COUNT = ScaleType.values().length;
 
diff --git a/libvlc/src/org/videolan/libvlc/VideoHelper.java b/libvlc/src/org/videolan/libvlc/VideoHelper.java
index 1647ef332..917220772 100644
--- a/libvlc/src/org/videolan/libvlc/VideoHelper.java
+++ b/libvlc/src/org/videolan/libvlc/VideoHelper.java
@@ -175,6 +175,26 @@ class VideoHelper implements IVLCVout.OnNewVideoLayoutListener {
                 mMediaPlayer.setAspectRatio("16:9");
                 mMediaPlayer.setScale(0);
                 break;
+            case SURFACE_16_10:
+                mMediaPlayer.setAspectRatio("16:10");
+                mMediaPlayer.setScale(0);
+                break;
+            case SURFACE_221_1:
+                mMediaPlayer.setAspectRatio("2.21:1");
+                mMediaPlayer.setScale(0);
+                break;
+            case SURFACE_235_1:
+                mMediaPlayer.setAspectRatio("2.35:1");
+                mMediaPlayer.setScale(0);
+                break;
+            case SURFACE_239_1:
+                mMediaPlayer.setAspectRatio("2.39:1");
+                mMediaPlayer.setScale(0);
+                break;
+            case SURFACE_5_4:
+                mMediaPlayer.setAspectRatio("5:4");
+                mMediaPlayer.setScale(0);
+                break;
             case SURFACE_4_3:
                 mMediaPlayer.setAspectRatio("4:3");
                 mMediaPlayer.setScale(0);
@@ -277,24 +297,17 @@ class VideoHelper implements IVLCVout.OnNewVideoLayoutListener {
                 break;
             case SURFACE_FILL:
                 break;
-            case SURFACE_16_9:
-                ar = 16.0 / 9.0;
-                if (dar < ar)
-                    dh = dw / ar;
-                else
-                    dw = dh * ar;
+            case SURFACE_ORIGINAL:
+                dh = mVideoVisibleHeight;
+                dw = vw;
                 break;
-            case SURFACE_4_3:
-                ar = 4.0 / 3.0;
+            default:
+                ar = mCurrentScaleType.getRatio();
                 if (dar < ar)
                     dh = dw / ar;
                 else
                     dw = dh * ar;
                 break;
-            case SURFACE_ORIGINAL:
-                dh = mVideoVisibleHeight;
-                dw = vw;
-                break;
         }
 
         // set display size



More information about the Android mailing list