SurfaceViewRenderer.java

 1package eu.siacs.conversations.ui.widget;
 2
 3import android.content.Context;
 4import android.util.AttributeSet;
 5import android.util.Log;
 6import android.util.Rational;
 7
 8import eu.siacs.conversations.Config;
 9
10public class SurfaceViewRenderer extends org.webrtc.SurfaceViewRenderer {
11
12    private Rational aspectRatio = new Rational(1,1);
13
14    private OnAspectRatioChanged onAspectRatioChanged;
15
16    public SurfaceViewRenderer(Context context) {
17        super(context);
18    }
19
20    public SurfaceViewRenderer(Context context, AttributeSet attrs) {
21        super(context, attrs);
22    }
23
24    public void onFrameResolutionChanged(int videoWidth, int videoHeight, int rotation) {
25        super.onFrameResolutionChanged(videoWidth, videoHeight, rotation);
26        final int rotatedWidth = rotation != 0 && rotation != 180 ? videoHeight : videoWidth;
27        final int rotatedHeight = rotation != 0 && rotation != 180 ? videoWidth : videoHeight;
28        final Rational currentRational = this.aspectRatio;
29        this.aspectRatio = new Rational(rotatedWidth, rotatedHeight);
30        Log.d(Config.LOGTAG,"onFrameResolutionChanged("+rotatedWidth+","+rotatedHeight+","+aspectRatio+")");
31        if (currentRational.equals(this.aspectRatio) || onAspectRatioChanged == null) {
32            return;
33        }
34        onAspectRatioChanged.onAspectRatioChanged(this.aspectRatio);
35    }
36
37    public void setOnAspectRatioChanged(final OnAspectRatioChanged onAspectRatioChanged) {
38        this.onAspectRatioChanged = onAspectRatioChanged;
39    }
40
41    public Rational getAspectRatio() {
42        return this.aspectRatio;
43    }
44
45    public interface OnAspectRatioChanged {
46        void onAspectRatioChanged(final Rational rational);
47    }
48}