Commit 2f270711 authored by Ludovic Fauvet's avatar Ludovic Fauvet
Browse files

Take the density into account when computing the aspect ratio

parent 51324e33
From b185385d73b661404ed99acebc9514ce95a5774b Mon Sep 17 00:00:00 2001
From: Ludovic Fauvet <etix@videolan.org>
Date: Thu, 20 Sep 2012 23:30:09 +0200
Subject: [PATCH] android vout: expose the density to the JNI
---
modules/video_output/androidsurface.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/modules/video_output/androidsurface.c b/modules/video_output/androidsurface.c
index af2cdc1..952baba 100644
--- a/modules/video_output/androidsurface.c
+++ b/modules/video_output/androidsurface.c
@@ -66,7 +66,7 @@ vlc_module_end()
extern void *jni_LockAndGetAndroidSurface();
extern void jni_UnlockAndroidSurface();
-extern void jni_SetAndroidSurfaceSize(int width, int height);
+extern void jni_SetAndroidSurfaceSize(int width, int height, int sar_num, int sar_den);
// _ZN7android7Surface4lockEPNS0_11SurfaceInfoEb
typedef void (*Surface_lock)(void *, void *, int);
@@ -92,6 +92,10 @@ struct vout_display_sys_t {
Surface_unlockAndPost s_unlockAndPost;
picture_resource_t resource;
+
+ /* density */
+ int i_sar_num;
+ int i_sar_den;
};
/* */
@@ -218,6 +222,9 @@ static int Open(vlc_object_t *p_this) {
/* Fix initial state */
vout_display_SendEventFullscreen(vd, false);
+ sys->i_sar_num = vd->source.i_sar_num;
+ sys->i_sar_den = vd->source.i_sar_den;
+
return VLC_SUCCESS;
enomem:
@@ -270,7 +277,7 @@ static int AndroidLockSurface(picture_t *picture) {
// input size doesn't match the surface size,
// request a resize
if (info->w != sw || info->h != sh) {
- jni_SetAndroidSurfaceSize(sw, sh);
+ jni_SetAndroidSurfaceSize(sw, sh, sys->i_sar_num, sys->i_sar_den);
sys->s_unlockAndPost(surf);
jni_UnlockAndroidSurface();
return VLC_EGENERIC;
--
1.7.12
......@@ -225,7 +225,7 @@ void jni_UnlockAndroidSurface() {
pthread_mutex_unlock(&vout_android_lock);
}
void jni_SetAndroidSurfaceSize(int width, int height)
void jni_SetAndroidSurfaceSize(int width, int height, int sar_num, int sar_den)
{
if (vout_android_gui == NULL)
return;
......@@ -234,9 +234,9 @@ void jni_SetAndroidSurfaceSize(int width, int height)
(*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", "(II)V");
jmethodID methodId = (*p_env)->GetMethodID (p_env, cls, "setSurfaceSize", "(IIII)V");
(*p_env)->CallVoidMethod (p_env, vout_android_gui, methodId, width, height);
(*p_env)->CallVoidMethod (p_env, vout_android_gui, methodId, width, height, sar_num, sar_den);
(*p_env)->DeleteLocalRef(p_env, cls);
(*myVm)->DetachCurrentThread (myVm);
......
......@@ -147,6 +147,8 @@ public class VideoPlayerActivity extends Activity {
// size of the video
private int mVideoHeight;
private int mVideoWidth;
private int mSarNum;
private int mSarDen;
//Audio
private AudioManager mAudioManager;
......@@ -176,7 +178,7 @@ public class VideoPlayerActivity extends Activity {
public void onSystemUiVisibilityChange(int visibility) {
if (visibility == mUiVisibility)
return;
setSurfaceSize(mVideoWidth, mVideoHeight);
setSurfaceSize(mVideoWidth, mVideoHeight, mSarNum, mSarDen);
if (visibility == View.SYSTEM_UI_FLAG_VISIBLE && !mShowing) {
showOverlay();
mHandler.sendMessageDelayed(mHandler.obtainMessage(HIDE_NAV), OVERLAY_TIMEOUT);
......@@ -401,14 +403,16 @@ public class VideoPlayerActivity extends Activity {
@Override
public void onConfigurationChanged(Configuration newConfig) {
setSurfaceSize(mVideoWidth, mVideoHeight);
setSurfaceSize(mVideoWidth, mVideoHeight, mSarNum, mSarDen);
super.onConfigurationChanged(newConfig);
}
public void setSurfaceSize(int width, int height) {
public void setSurfaceSize(int width, int height, int sar_num, int sar_den) {
// store video size
mVideoHeight = height;
mVideoWidth = width;
mSarNum = sar_num;
mSarDen = sar_den;
Message msg = mHandler.obtainMessage(SURFACE_SIZE);
mHandler.sendMessage(msg);
}
......@@ -621,9 +625,20 @@ public class VideoPlayerActivity extends Activity {
if (dw * dh == 0)
return;
// calculate aspect ratio
double ar = (double) mVideoWidth / (double) mVideoHeight;
// calculate display aspect ratio
// compute the aspect ratio
double ar, vw;
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;
} else {
/* Use the specified aspect ratio */
vw = (double)mVideoWidth * density;
ar = vw / (double)mVideoHeight;
}
// compute the display aspect ratio
double dar = (double) dw / (double) dh;
switch (mCurrentSize) {
......@@ -657,7 +672,7 @@ public class VideoPlayerActivity extends Activity {
break;
case SURFACE_ORIGINAL:
dh = mVideoHeight;
dw = mVideoWidth;
dw = (int) vw;
break;
}
......
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