Cambiar el tamaño de la vista de la superficie para cambiar la relación de aspecto en la visualización de video en Android

Estoy trabajando en un proyecto de videoconferencia. Mi pantalla de video está utilizando la vista de superficie. Ahora, durante una llamada de video, existe la posibilidad de un cambio en la relación de aspecto para los cuadros entrantes. Así que he probado el siguiente código para ello

public void surfaceResize() {

   // WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Point size = new Point();
    int screenWidth = 0;
    //Get the SurfaceView layout parameters

    float aspectRatio = (float) recv_frame_width / recv_frame_height;

    if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) 
    {   
        //Get the width of the screen
        getWindowManager().getDefaultDisplay().getSize(size);
        screenWidth = size.x;

        //Set the width of the SurfaceView to the width of the screen
        surflp.width = screenWidth;

        //Set the height of the SurfaceView to match the aspect ratio of the video 
        //be sure to cast these as floats otherwise the calculation will likely be 0
        surflp.height = (int) ((1 / aspectRatio) * (float)screenWidth);

        //Commit the layout parameters

    } else {

        size.x = size.y = 0;
        //Get the width of the screen
        getWindowManager().getDefaultDisplay().getSize(size);

        int screenHeight = size.y;

        //Set the width of the SurfaceView to the width of the screen
        surflp.height = screenHeight;

        //Set the width of the SurfaceView to match the aspect ratio of the video 
        //be sure to cast these as floats otherwise the calculation will likely be 0
        surflp.width = (int) ( aspectRatio * (float)screenHeight);

        //Commit the layout parameters
        // code to do for Portrait Mode        
    }
    surflp.addRule(RelativeLayout.CENTER_HORIZONTAL);
    surflp.addRule(RelativeLayout.CENTER_VERTICAL);

    if(myVideoSurfaceView != null) 
        myVideoSurfaceView.setLayoutParams(surflp);  
    System.out.println("Surface resized*****************************************");
}

Todo está bien si llamo a esta función al comienzo de la llamada. Mi problema es que cuando invoco esta función entre una llamada para cambiar la relación de aspecto, se tarda demasiado tiempo en mostrar el siguiente cuadro. A veces el video se atasca incluso.

Intenté destruir y recrear la superficie con

myVideoSurface.setVisibility(VIEW.GONE);

Pero la superficie no se está creando.

Estoy usando Mediacodec para la decodificación de video. Recibiré una notificación cuando haya un cambio de resolución.

¿Hay algo más que deba hacer para cambiar el tamaño de una vista de superficie cuando ya se está reproduciendo el video?

Gracias por la ayuda.........................

Respuestas a la pregunta(1)

Su respuesta a la pregunta