Изменение размера вида поверхности для изменения соотношения сторон при отображении видео в Android
Я работаю над проектом видеоконференцсвязи. Мой видео дисплей использует вид поверхности. Теперь во время видеозвонка есть вероятность изменения соотношения сторон для входящих кадров. Поэтому я попробовал следующий код для него
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*****************************************");
}
Все хорошо, если я вызываю эту функцию в начале вызова. Моя проблема в том, что когда я вызываю эту функцию между вызовами для изменения соотношения сторон, для отображения следующего кадра требуется слишком много времени. Иногда видео застревает даже.
Я пытался уничтожить и воссоздать поверхность с
myVideoSurface.setVisibility(VIEW.GONE);
Но поверхность не создается.
Я использую Mediacodec для декодирования видео. Я получу уведомление при изменении разрешения.
Есть ли что-то еще, что я должен сделать для изменения размера SurfaceView, когда уже воспроизводится видео.
Спасибо за помощь.........................