How the video display size making use of resize and rotation is set under Android

1,810 views
Skip to first unread message

sreedhar b

unread,
Apr 30, 2009, 6:09:07 AM4/30/09
to android...@googlegroups.com
Hi,
 
I am doing the video playback in Media player which is making use of  soft PV video decoder giving YUV 420 planar output.
Currently if the input stream is of QVGA resolution, the display is QVGA on my VGA LCD display panel. 
 
If the input stream is of VGA resolution, the display is VGA.
 
I wanted to play QVGA i/p stream as VGA (definitely including resize).
How this can be done inside Android?
 
Similarly i want to display QVGA(320x240) i/p stream decoded and rendered to display as 240X340(definitely including rotation).
 
If somebody has tried these, please let me know how these can be implemented for video playback inside Android.
This is mainly for resize and rotate.
 
Regards,
Sreedhar

Dave Sparks

unread,
Apr 30, 2009, 8:28:51 PM4/30/09
to android-porting
This capability is already built into the framework. You just scale
the SurfaceView to the desired size. You probably want to adjust the
height and width to maintain the aspect ratio of the original
material. The rescaling is handled in SurfaceFlinger by the blitter
engine. In fact, if you use the VideoView widget, it will do this for
you automatically.

sreedhar b

unread,
May 7, 2009, 8:46:47 AM5/7/09
to android...@googlegroups.com
Hi Dave,
 
I have two setups:
 
1. In this hardware setup, my touch screen driver is working.
And the specific configurations are:
 
@PATH  ../packages\apps\Music\res
drawable-finger
drawable-land-finger
layout-finger
layout-land-finger
values-finger
 
This case, when the video playback is done using video player (or video view widget).
Irrespective of the input stream resolution(QCIF, QVGA,VGA ) the output display
is VGA(may be resized by surface flinger) as you said automatically.
Can you please give me the function and file inside the surface flinger where this rescaling is done?.
 
2.In this hardware setup, my touch screen driver is not working.
And the specific configurations are:
 
@PATH ../packages\apps\Music\res
drawable-notouch
drawable-land-notouch
layout-notouch
layout-land-notouch
values-notouch
 
This case, when the video playback is done using video player (or video view widget).
Irrespective of the input stream resolution(QCIF, QVGA,VGA ) the output display
resolution is same as input..
 
Please let me know how the configurations mentioned above are giving different behaviour in 1 and 2.
 
I wanted to do the rescaling of QVGA to VGA by using configuartions and setup mentioned in 2. How this can be done ? Please suggest some ideas.
 
Regards,
Sreedhar

Dave Sparks

unread,
May 7, 2009, 12:20:13 PM5/7/09
to android-porting
I don't think SurfaceFlinger has anything to do with the problem. You
can check this by looking at the window size requested by VideoView
after the video size is determined. If the requested view size is not
full screen, the problem is probably a layout issue.

peter deng

unread,
May 21, 2009, 4:29:02 PM5/21/09
to android...@googlegroups.com, david...@android.com
Dave,
I still have surfaceflinger crash like this, how do you get it fix? The kernel is fine..

I/SurfaceFlinger(  249): SurfaceFlinger is starting
I/SurfaceFlinger(  249): SurfaceFlinger's main thread ready to run. Initializing graphics H/W...
D/SurfaceFlinger(  249): pid 249 requesting gpu core (owner = -1)
W/SurfaceFlinger(  249): couldn't grant gpu core to pid 249
D/EGL     (  249): requestGPU returned -1
E/GLLogger(  249): h/w accelerated eglGetDisplay() failed (EGL_SUCCESS)
I/SurfaceFlinger(  249): EGL informations:
I/SurfaceFlinger(  249): # of configs : 6
I/SurfaceFlinger(  249): vendor    : Android
I/SurfaceFlinger(  249): version   : 1.31 Android META-EGL
I/SurfaceFlinger(  249): extensions:
I/SurfaceFlinger(  249): Client API: OpenGL ES
I/EGLDisplaySurface(  249): using (fd=22)
I/EGLDisplaySurface(  249): id           = msmfb
I/EGLDisplaySurface(  249): xres         = 500 px
I/EGLDisplaySurface(  249): yres         = 600 px
I/EGLDisplaySurface(  249): xres_virtual = 500 px
I/EGLDisplaySurface(  249): yres_virtual = 1200 px
I/EGLDisplaySurface(  249): bpp          = 16
I/EGLDisplaySurface(  249): r            = 11:5
I/EGLDisplaySurface(  249): g            =  5:6
I/EGLDisplaySurface(  249): b            =  0:5
I/EGLDisplaySurface(  249): width        = 500 mm (25.400000 dpi)
I/EGLDisplaySurface(  249): height       = 600 mm (25.400000 dpi)
I/EGLDisplaySurface(  249): refresh rate = 60.00 Hz
...
I/SurfaceFlinger(  249): OpenGL informations:
I/SurfaceFlinger(  249): vendor    : Android
I/SurfaceFlinger(  249): renderer  : Android PixelFlinger 1.0
I/SurfaceFlinger(  249): version   : OpenGL ES-CM 1.0
I/SurfaceFlinger(  249): extensions: GL_OES_byte_coordinates GL_OES_fixed_point GL_OES_single_precision GL_OES_read_format GL_OES_compressed_paletted_texture GL_OES_draw_texture GL_OES_matrix_get GL_OES_query_matrix GL_ARB_texture_compression GL_ARB_texture_non_power_of_two GL_ANDROID_direct_texture GL_ANDROID_user_clip_plane GL_ANDROID_vertex_buffer_object GL_ANDROID_generate_mipmap
...
I/sysproc (  249): System server: starting Android runtime.
I/sysproc (  249): System server: starting Android services.
I/SystemServer(  249): Entered the Android system server!
I/sysproc (  249): System server: entering thread pool.
I/SystemServer(  249): Starting Power Manager.
I/SystemServer(  249): Starting Activity Manager.
I/DEBUG   (   32): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
I/DEBUG   (   32): Build fingerprint: 'generic/htc_dream/dream/trout:1.5/CUPCAKE/eng.pdeng.20090515.143846:eng/test-keys'
I/DEBUG   (   32): pid: 249, tid: 256  >>> system_server <<<
I/DEBUG   (   32): signal 11 (SIGSEGV), fault addr 45494000
I/DEBUG   (   32):  r0 45494000  r1 00000000  r2 0000008c  r3 00000000
I/DEBUG   (   32):  r4 00000096  r5 0177076a  r6 00008000  r7 000001f4
I/DEBUG   (   32):  r8 0000d555  r9 00185f40  10 00000000  fp 00000000
I/DEBUG   (   32):  ip 00000000  sp 44a93c24  lr 00000000  pc afb0451c  cpsr 20000010
I/DEBUG   (   32):          #00  pc 0000451c  /system/lib/libcutils.so
I/DEBUG   (   32):          #01  pc 0000a96c  /system/lib/libpixelflinger.so
...

sreedhar b

unread,
Jun 4, 2009, 11:08:22 AM6/4/09
to android...@googlegroups.com
Hi Dave,
 
I am currently having my android setup for two display panels of resolution VGA, WVGA
 
My observations for video playback using video player :
 
In case of VGA display panel:
 
S.no.     Input stream resoution    O/P display resolution
 
1.          VGA(640X480)                VGA(640X480)                    
 
2.          QVGA(320X240)              QVGA(320X240)=> (No resize)
 
3.          160x120                         160x120            => (No resize)
 
4.          400X240                          Near to VGA     => (resize and maintaining the aspect ratio same as i/p)
 
5.          176X144                          Near to VGA     => (resize and maintaining the aspect ratio same as i/p)                      
 
If we see above table, i observe for all the input stream resolutions having the same aspect ratio as display panel resolution (in this case VGA), there is no resize happening.
 
But for other cases, where the i/p stream resolution aspect ratio is not same as display panel resolution(in this case VGA). We observe that there is a resize and the aspect ratio is maintained as similar to the i/p stream resolution.
 
Similar observations i am having for the WVGA display panel.
 
Please let me know if this is a known behaviour.  
 
Why the resize is happening in cases 4 and 5 and why the resize is not happening in cases 2 and 3?
 
How the resize to full screen(definitely maintaining aspect ratio as i/p) in case of 2 and 3 can also be acheived ??
 
Regards,
Sreedhar

Harishkumar V

unread,
Jun 4, 2009, 11:35:47 AM6/4/09
to android...@googlegroups.com
Hi,

This is achieved using OnMeasure() in VideoView.java.

Also, can u share me how to get the videoplayer in android, presently i am using apidemos to play the video.

Thanks and Regards,
HarishKumar.V

Harishkumar V

unread,
Jun 5, 2009, 12:20:24 AM6/5/09
to android...@googlegroups.com
Hi,

u can check movieview.xml, where andorid:layout_width and android:layout_height plays the trick.

Thanks and Regards,
HarishKumar.V

Harishkumar V

unread,
Jun 5, 2009, 2:17:14 AM6/5/09
to android...@googlegroups.com
Hi,

in movieview.xml,

<VideoView
     android:id="@+id/surface_view"
        android:layout_width="fill_parent"             -> can be replaced to any desried width
        android:layout_height="fill_parent"            -> can be replaced to any desired height
        android:layout_centerInParent="true"
    />

Thanks and Regards,
HarishKumar.V

sreedhar b

unread,
Jun 5, 2009, 11:30:49 AM6/5/09
to android...@googlegroups.com
Hi Harish,
 
I think the video view widget am using is by default available inside android.
It uses the Camera.apk internally having the movie view.
 
And thanks for the inputs on my query.
 
As said in my previous mail, for a VGA(640X480) display panel the resize is not happening for the cases 2 and 3 mentioned.
 
Specifically,
2.          QVGA(320X240)              QVGA(320X240)=> (No resize)
 
3.          160x120                         160x120            => (No resize)
 
Otherwise for other i/p stream resolutions the resize is happening.
 
 
So, as per your suggestion, if i use the following code. Please correct if the notation for width and height fixed values is like "640px" and "480px"?
 
Will this change does resize to full screen(VGA) of cases 2 and 3 as well?
I suppose this change will affect the camera.apk alone.  
 
<VideoView
     android:id="@+id/surface_view"
        android:layout_width="640px"             -> can be replaced to any desried width
        android:layout_height="480px"            -> can be replaced to any desired height
        android:layout_centerInParent="true"
    />
 
Regards,
Sreedhar

Harishkumar V

unread,
Jun 5, 2009, 12:52:32 PM6/5/09
to android...@googlegroups.com
Hi,

It should,

how it works -> the calculation is like this,

for example, in ur case

display width (dw) - 640
display height (dh) - 480
video width (vw) - 320
video height (vh) - 240

these are done in onmeasure function in videoview widget

case 1:

vw*dh > vh*dw
then,
dh=(vh*dw)/vw;
dw= no change

case 2:

vw*dh < vh*dw
then,
dw=(dh*vw)/vh;
dh= no change

case 3:

if the above both cases not satisfied,
(ie) vw*dh = vh*dw
then dw and dh kept the same.

finally, the video will be played at dw x dh.

It works for me, my display size is 640x430.

for testing, i kept android layoutwidth=352 and android layoutheight= 288 in movieview.xml
   
when i play a 3gp video file (176x144) from browser through streaming, it plays at 352x288.


Thanks and Regards,
HarishKumar.V

Dave Sparks

unread,
Jun 6, 2009, 2:01:24 PM6/6/09
to android-porting
I don't have any idea what's involved in getting VGA working. We've
done some work with density-independent-pixels, but that it assumes
that the screen size is fairly close to the current device. You
probably need some help from someone more familiar with the layout
code.

On Jun 4, 8:08 am, sreedhar b <sreedhar...@gmail.com> wrote:
> Hi Dave,
>

sreedhar b

unread,
Jun 9, 2009, 11:01:02 AM6/9/09
to android...@googlegroups.com
Hi Harish,
 
Similar to your use case:
 
My display size ( i mean display panel size) is 800x480.
 
I tried to play 176x144 mp4 stream.
 
And i kept android layoutwidth=352 and android layoutheight= 288 in movieview.xml
 
In my case the result is that the surface now set to 352X288 at the center, i am still getting 176X144 display on the left corner of this surface and no resize from 176x144 to 352x288.
 
Observations in my environment is that,
 
Originally when, 
android layoutwidth=fill parent and android layoutheight= fill parent
 
the surface is equivalent to display panel width and display panel height.
 
This means in 800X480 case,
 
android layoutwidth=800 and android layoutheight= 480.
 
So, it looks like if we try to play input streams like 400X240 or 200X120 whose aspect ratio is same as 800X480, there is no resize. Otherwise if you try to play input streams like 320X240, 176X144, 560X368 whose aspect ratios are not same as 800X480, these are getting resized to nearest size of 800X480 maintaining the aspect ratio.
 
Similar observations, i am getting if i change the
android layoutwidth=352 and android layoutheight= 288.
 
Now the surface is 352X288, i played 176X144 no resize and when i played 320X240, 560X368, 640X480 input streams  all these are resized and displayed as 352X288.
 
Any idea where exactly this resize video postprocessing algorithm is implemented.
 
Definitely it takes the above parameters video width , video height, display width and display height from application and does resizing,  
 
More specifically, any idea where inside surface flinger this resize processing is being done??
 
Regards,
Sreedhar 
Reply all
Reply to author
Forward
0 new messages