What is the use of calling SurfaceHolder.setFixedSize ()?

I have similar code for many examples floating over the network:

mSurfaceHolder = mVideoSurface.getHolder(); mSurfaceHolder.addCallback(this); mSurfaceHolder.setFormat(PixelFormat.TRANSPARENT); mSurfaceHolder.setFixedSize(20, 10); 

Then in callbacks I:

 @Override public void surfaceCreated(SurfaceHolder holder) { Log.d(TAG, "SurfaceCreated"); mSurfaceHolder.setFixedSize(20, 10); } @Override public void surfaceChanged( SurfaceHolder holder, int format, int width, int height ) { Log.d(TAG, "SurfaceChanged to " + format + " width " + width + " height " + height); } 

From this code, I would expect the video surface to be set to a tiny size of 20x10 pixels , then scale to any layout size. I use it showing the pixel / blurry version. However, the video being played looks correctly in full native resolution; it does not decrease to 20x10. But I get the following logs:

 SurfaceChanged to -2 width 20 height 10 

So, if the surface of the video is set to this tiny size, but graphically the video still looks in high resolution, then why use the surface size?

Full source code is available at https://github.com/gradha/Stackoverflow38118219 .

+1
source share
1 answer

Size matters for things like OpenGL ES, where you paint on surfaces of any size. When you send data buffers from a camera or video decoder, the buffers arrive at any size that they were set by the camera or video. It scales to the size of the SurfaceView View, but does not scale to the size of the SurfaceView Surface.

In one place, these two concepts intersect with the Camera2 preview API, which is likely to resize its capture to fit the surface in some cases.

You can learn more about the main uses in this blog post (demo here ) and more about the graphic architecture in general in this document .

+7
source

Source: https://habr.com/ru/post/909651/


All Articles