[Android] align surface buffer width (add padding) and crop surfaceView accordingly

Sébastien Toque git at videolan.org
Thu Jan 3 21:26:40 CET 2013


vlc-ports/android | branch: master | Sébastien Toque <xilasz at gmail.com> | Thu Jan  3 21:26:33 2013 +0100| [afd02007c0318e59b678a65b35b8578749ac7071] | committer: Sébastien Toque

align surface buffer width (add padding) and crop surfaceView accordingly

This avoid an alignement issue during chroma conversion
when video width is not a multiple of 4

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

 vlc-android/res/layout/player.xml                  |   12 ++++++--
 .../vlc/gui/video/VideoPlayerActivity.java         |   29 ++++++++++++++++----
 2 files changed, 33 insertions(+), 8 deletions(-)

diff --git a/vlc-android/res/layout/player.xml b/vlc-android/res/layout/player.xml
index fe084f6..50842dc 100644
--- a/vlc-android/res/layout/player.xml
+++ b/vlc-android/res/layout/player.xml
@@ -4,12 +4,18 @@
     android:layout_height="fill_parent"
     android:background="#000001" >
 
-    <SurfaceView
-        android:id="@+id/player_surface"
+    <FrameLayout
+        android:id="@+id/player_surface_frame"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_centerInParent="true"
-        android:layout_gravity="center" />
+        android:foregroundGravity="clip_horizontal" >
+        <SurfaceView
+            android:id="@+id/player_surface"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center_vertical" />
+    </FrameLayout>
 
     <TextView
         android:id="@+id/player_overlay_info"
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 77f7eb2..eb6fbe2 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -94,6 +94,8 @@ public class VideoPlayerActivity extends Activity {
 
     private SurfaceView mSurface;
     private SurfaceHolder mSurfaceHolder;
+    private FrameLayout mSurfaceFrame;
+    private int mSurfaceAlign;
     private LibVLC mLibVLC;
     private String mLocation;
 
@@ -254,11 +256,18 @@ public class VideoPlayerActivity extends Activity {
 
         mSurface = (SurfaceView) findViewById(R.id.player_surface);
         mSurfaceHolder = mSurface.getHolder();
+        mSurfaceFrame = (FrameLayout) findViewById(R.id.player_surface_frame);
+        int pitch;
         if(Util.isGingerbreadOrLater() && pref.getBoolean("enable_yv12_format", false)) {
             mSurfaceHolder.setFormat(ImageFormat.YV12);
+            pitch = ImageFormat.getBitsPerPixel(ImageFormat.YV12) / 8;
         } else {
             mSurfaceHolder.setFormat(PixelFormat.RGBX_8888);
+            PixelFormat info = new PixelFormat();
+            PixelFormat.getPixelFormatInfo(PixelFormat.RGBX_8888, info);
+            pitch = info.bytesPerPixel;
         }
+        mSurfaceAlign = 16 / pitch - 1;
         mSurfaceHolder.addCallback(mSurfaceCallback);
 
         mSeekbar = (SeekBar) findViewById(R.id.player_overlay_seekbar);
@@ -712,14 +721,24 @@ public class VideoPlayerActivity extends Activity {
                 break;
         }
 
-        // FIXME: align properly for YV12 and RGB16
-        // FIXME: crop rightmost pixels to not display garbage (or black them?)
-        mVideoWidth += 3; mVideoWidth &= ~3;
-        mSurfaceHolder.setFixedSize(mVideoWidth, mVideoHeight);
+        // align width on 16bytes
+        int alignedWidth = (mVideoWidth + mSurfaceAlign) & ~mSurfaceAlign;
+
+        // force surface buffer size
+        mSurfaceHolder.setFixedSize(alignedWidth, mVideoHeight);
+
+        // set display size
         LayoutParams lp = mSurface.getLayoutParams();
-        lp.width = dw;
+        lp.width = dw * alignedWidth / mVideoWidth;
         lp.height = dh;
         mSurface.setLayoutParams(lp);
+
+        // set frame size (crop if necessary)
+        lp = mSurfaceFrame.getLayoutParams();
+        lp.width = dw;
+        lp.height = dh;
+        mSurfaceFrame.setLayoutParams(lp);
+
         mSurface.invalidate();
     }
 



More information about the Android mailing list