[Android] Support cropping in the video output

Martin Storsjö git at videolan.org
Mon Aug 5 14:57:05 CEST 2013


vlc-ports/android | branch: master | Martin Storsjö <martin at martin.st> | Mon Jul 29 21:54:04 2013 +0300| [32479e9ab197adec2cd9a1b03cb74a3c08a3c2b6] | committer: Martin Storsjö

Support cropping in the video output

This changes the IVideoPlayer interface to pass two additional
parameters - the width/height parameters are kept as the full
buffer size, with two additional parameters specifying how much of
it is supposed to be visible. This removes the duplicated alignment
calculation, making sure it's done in one place only - in the calling
vout code.

Signed-off-by: Martin Storsjö <martin at martin.st>

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=32479e9ab197adec2cd9a1b03cb74a3c08a3c2b6
---

 compile.sh                                         |    2 +-
 vlc-android/jni/vout.c                             |    6 ++--
 vlc-android/res/layout/player.xml                  |    5 ++--
 .../src/org/videolan/libvlc/IVideoPlayer.java      |    5 ++--
 .../vlc/gui/video/VideoPlayerActivity.java         |   31 ++++++++++----------
 5 files changed, 24 insertions(+), 25 deletions(-)

diff --git a/compile.sh b/compile.sh
index c53cee6..e3f4614 100755
--- a/compile.sh
+++ b/compile.sh
@@ -80,7 +80,7 @@ export PATH=${NDK_TOOLCHAIN_PATH}:${PATH}
 ANDROID_PATH="`pwd`"
 
 # 1/ libvlc, libvlccore and its plugins
-TESTED_HASH=7c52aacbe
+TESTED_HASH=da08af353
 if [ ! -d "vlc" ]; then
     echo "VLC source not found, cloning"
     git clone git://git.videolan.org/vlc.git vlc
diff --git a/vlc-android/jni/vout.c b/vlc-android/jni/vout.c
index 0dd8058..f2765db 100644
--- a/vlc-android/jni/vout.c
+++ b/vlc-android/jni/vout.c
@@ -45,7 +45,7 @@ void jni_UnlockAndroidSurface() {
     pthread_mutex_unlock(&vout_android_lock);
 }
 
-void jni_SetAndroidSurfaceSize(int width, int height, int sar_num, int sar_den)
+void jni_SetAndroidSurfaceSize(int width, int height, int visible_width, int visible_height, int sar_num, int sar_den)
 {
     if (vout_android_gui == NULL)
         return;
@@ -54,9 +54,9 @@ void jni_SetAndroidSurfaceSize(int width, int height, int sar_num, int sar_den)
 
     (*myVm)->AttachCurrentThread (myVm, &p_env, NULL);
     jclass cls = (*p_env)->GetObjectClass (p_env, vout_android_gui);
-    jmethodID methodId = (*p_env)->GetMethodID (p_env, cls, "setSurfaceSize", "(IIII)V");
+    jmethodID methodId = (*p_env)->GetMethodID (p_env, cls, "setSurfaceSize", "(IIIIII)V");
 
-    (*p_env)->CallVoidMethod (p_env, vout_android_gui, methodId, width, height, sar_num, sar_den);
+    (*p_env)->CallVoidMethod (p_env, vout_android_gui, methodId, width, height, visible_width, visible_height, sar_num, sar_den);
 
     (*p_env)->DeleteLocalRef(p_env, cls);
     (*myVm)->DetachCurrentThread (myVm);
diff --git a/vlc-android/res/layout/player.xml b/vlc-android/res/layout/player.xml
index 2daac8a..f76cc41 100644
--- a/vlc-android/res/layout/player.xml
+++ b/vlc-android/res/layout/player.xml
@@ -16,13 +16,12 @@
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_gravity="center"
-            android:foregroundGravity="clip_horizontal" >
+            android:foregroundGravity="clip_horizontal|clip_vertical" >
 
             <SurfaceView
                 android:id="@+id/player_surface"
                 android:layout_width="1dp"
-                android:layout_height="1dp"
-                android:layout_gravity="center_vertical" />
+                android:layout_height="1dp" />
         </FrameLayout>
     </FrameLayout>
 
diff --git a/vlc-android/src/org/videolan/libvlc/IVideoPlayer.java b/vlc-android/src/org/videolan/libvlc/IVideoPlayer.java
index 17844f1..c714b5b 100644
--- a/vlc-android/src/org/videolan/libvlc/IVideoPlayer.java
+++ b/vlc-android/src/org/videolan/libvlc/IVideoPlayer.java
@@ -23,11 +23,12 @@ package org.videolan.libvlc;
 public interface IVideoPlayer {
     /**
      * This method is called by native vout to request a surface resize when frame size doesn't match surface size.
-     * The new surface width must be aligned on 4 pixels for RV32, 8 pixels for RV16, and 16 pixels for YV12.
      * @param width Frame width
      * @param height Frame height
+     * @param visible_width Visible frame width
+     * @param visible_height Visible frame height
      * @param sar_num Surface aspect ratio numerator
      * @param sar_den Surface aspect ratio denominator
      */
-    void setSurfaceSize(int width, int height, int sar_num, int sar_den);
+    void setSurfaceSize(int width, int height, int visible_width, int visible_height, int sar_num, int sar_den);
 }
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
index 2d89f36..41efe7e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -109,7 +109,6 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
     private SurfaceView mSurface;
     private SurfaceHolder mSurfaceHolder;
     private FrameLayout mSurfaceFrame;
-    private int mSurfaceAlign;
     private LibVLC mLibVLC;
     private String mLocation;
 
@@ -169,6 +168,8 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
     // size of the video
     private int mVideoHeight;
     private int mVideoWidth;
+    private int mVideoVisibleHeight;
+    private int mVideoVisibleWidth;
     private int mSarNum;
     private int mSarDen;
 
@@ -208,7 +209,7 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
                         public void onSystemUiVisibilityChange(int visibility) {
                             if (visibility == mUiVisibility)
                                 return;
-                            setSurfaceSize(mVideoWidth, mVideoHeight, mSarNum, mSarDen);
+                            setSurfaceSize(mVideoWidth, mVideoHeight, mVideoVisibleWidth, mVideoVisibleHeight, mSarNum, mSarDen);
                             if (visibility == View.SYSTEM_UI_FLAG_VISIBLE && !mShowing) {
                                 showOverlay();
                             }
@@ -290,7 +291,6 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
             PixelFormat.getPixelFormatInfo(PixelFormat.RGBX_8888, info);
             pitch = info.bytesPerPixel;
         }
-        mSurfaceAlign = 16 / pitch - 1;
         mSurfaceHolder.addCallback(mSurfaceCallback);
 
         mSeekbar = (SeekBar) findViewById(R.id.player_overlay_seekbar);
@@ -560,18 +560,20 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
 
     @Override
     public void onConfigurationChanged(Configuration newConfig) {
-        setSurfaceSize(mVideoWidth, mVideoHeight, mSarNum, mSarDen);
+        setSurfaceSize(mVideoWidth, mVideoHeight, mVideoVisibleWidth, mVideoVisibleHeight, mSarNum, mSarDen);
         super.onConfigurationChanged(newConfig);
     }
 
     @Override
-    public void setSurfaceSize(int width, int height, int sar_num, int sar_den) {
+    public void setSurfaceSize(int width, int height, int visible_width, int visible_height, int sar_num, int sar_den) {
         if (width * height == 0)
             return;
 
         // store video size
         mVideoHeight = height;
         mVideoWidth = width;
+        mVideoVisibleHeight = visible_height;
+        mVideoVisibleWidth  = visible_width;
         mSarNum = sar_num;
         mSarDen = sar_den;
         Message msg = mHandler.obtainMessage(SURFACE_SIZE);
@@ -801,12 +803,12 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
         double density = (double)mSarNum / (double)mSarDen;
         if (density == 1.0) {
             /* No indication about the density, assuming 1:1 */
-            vw = mVideoWidth;
-            ar = (double)mVideoWidth / (double)mVideoHeight;
+            vw = mVideoVisibleWidth;
+            ar = (double)mVideoVisibleWidth / (double)mVideoVisibleHeight;
         } else {
             /* Use the specified aspect ratio */
-            vw = mVideoWidth * density;
-            ar = vw / mVideoHeight;
+            vw = mVideoVisibleWidth * density;
+            ar = vw / mVideoVisibleHeight;
         }
 
         // compute the display aspect ratio
@@ -842,21 +844,18 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
                     dw = (int) (dh * ar);
                 break;
             case SURFACE_ORIGINAL:
-                dh = mVideoHeight;
+                dh = mVideoVisibleHeight;
                 dw = (int) vw;
                 break;
         }
 
-        // align width on 16bytes
-        int alignedWidth = (mVideoWidth + mSurfaceAlign) & ~mSurfaceAlign;
-
         // force surface buffer size
-        mSurfaceHolder.setFixedSize(alignedWidth, mVideoHeight);
+        mSurfaceHolder.setFixedSize(mVideoWidth, mVideoHeight);
 
         // set display size
         LayoutParams lp = mSurface.getLayoutParams();
-        lp.width = dw * alignedWidth / mVideoWidth;
-        lp.height = dh;
+        lp.width  = dw * mVideoWidth / mVideoVisibleWidth;
+        lp.height = dh * mVideoHeight / mVideoVisibleHeight;
         mSurface.setLayoutParams(lp);
 
         // set frame size (crop if necessary)



More information about the Android mailing list