Commit 32479e9a authored by Martin Storsjö's avatar 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ö's avatarMartin Storsjö <martin@martin.st>
parent 2561401f
......@@ -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
......
......@@ -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);
......
......@@ -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>
......
......@@ -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);
}
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment