Größenänderung der Oberflächenansicht für die Änderung des Seitenverhältnisses in der Videoanzeige in Android

Ich arbeite an einem Videokonferenzprojekt. Mein Videodisplay verwendet die Oberflächenansicht. Während eines Videoanrufs besteht nun die Möglichkeit, dass sich das Seitenverhältnis für die eingehenden Frames ändert. Also habe ich den folgenden Code dafür ausprobiert

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*****************************************");
}

Alles ist in Ordnung, wenn ich diese Funktion zu Beginn des Anrufs aufrufe. Mein Problem ist, wenn ich diese Funktion zwischen einem Aufruf zum Ändern des Seitenverhältnisses aufrufe, dauert es zu lange, bis das nächste Bild angezeigt wird. Manchmal bleibt das Video sogar hängen.

Ich habe versucht, die Oberfläche mit zu zerstören und neu zu erschaffen

myVideoSurface.setVisibility(VIEW.GONE);

Aber die Oberfläche wird nicht erzeugt.

Ich verwende Mediacodec für die Videodekodierung. Ich werde benachrichtigt, wenn sich die Auflösung ändert.

Gibt es etwas mehr, das ich tun sollte, um die Größe eines SurfaceView zu ändern, wenn bereits ein Video abgespielt wird?

Danke für die Hilfe.........................

Antworten auf die Frage(1)

Ihre Antwort auf die Frage