[Android] Take the density into account when computing the aspect ratio
Ludovic Fauvet
git at videolan.org
Thu Sep 20 23:40:53 CEST 2012
vlc-ports/android | branch: master | Ludovic Fauvet <etix at videolan.org> | Thu Sep 20 23:33:43 2012 +0200| [2f270711bf78a05d3f8f7528b9757b08f6f47753] | committer: Ludovic Fauvet
Take the density into account when computing the aspect ratio
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=2f270711bf78a05d3f8f7528b9757b08f6f47753
---
...ndroid-vout-expose-the-density-to-the-JNI.patch | 55 ++++++++++++++++++++
vlc-android/jni/libvlcjni.c | 6 +--
.../vlc/gui/video/VideoPlayerActivity.java | 29 ++++++++---
3 files changed, 80 insertions(+), 10 deletions(-)
diff --git a/patches/0006-android-vout-expose-the-density-to-the-JNI.patch b/patches/0006-android-vout-expose-the-density-to-the-JNI.patch
new file mode 100644
index 0000000..5e8b51b
--- /dev/null
+++ b/patches/0006-android-vout-expose-the-density-to-the-JNI.patch
@@ -0,0 +1,55 @@
+From b185385d73b661404ed99acebc9514ce95a5774b Mon Sep 17 00:00:00 2001
+From: Ludovic Fauvet <etix at 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
+
diff --git a/vlc-android/jni/libvlcjni.c b/vlc-android/jni/libvlcjni.c
index 2fb23db..bbaccb5 100644
--- a/vlc-android/jni/libvlcjni.c
+++ b/vlc-android/jni/libvlcjni.c
@@ -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);
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 3659ba1..365fd84 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -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;
}
More information about the Android
mailing list