Add Android VideoRendererGui events.

Add events to Android VideoRendererGui implementation to
optionally report first rendered frame and video frame
dimension changes.

R=wzh@webrtc.org

Review URL: https://codereview.webrtc.org/1292293002 .

Cr-Commit-Position: refs/heads/master@{#9715}
diff --git a/talk/app/webrtc/java/android/org/webrtc/VideoRendererGui.java b/talk/app/webrtc/java/android/org/webrtc/VideoRendererGui.java
index 9dd2f02..8246e8b 100644
--- a/talk/app/webrtc/java/android/org/webrtc/VideoRendererGui.java
+++ b/talk/app/webrtc/java/android/org/webrtc/VideoRendererGui.java
@@ -148,6 +148,7 @@
     private RendererType rendererType;
     private ScalingType scalingType;
     private boolean mirror;
+    private RendererEvents rendererEvents;
     // Flag if renderFrame() was ever called.
     boolean seenFrame;
     // Total number of video frames received in renderFrame() call.
@@ -430,6 +431,11 @@
           && rotation == rotationDegree) {
         return;
       }
+      if (rendererEvents != null) {
+        Log.d(TAG, "ID: " + id +
+            ". Reporting frame resolution changed to " + videoWidth + " x " + videoHeight);
+        rendererEvents.onFrameResolutionChanged(videoWidth, videoHeight, rotation);
+      }
 
       // Frame re-allocation need to be synchronized with copying
       // frame to textures in draw() function to avoid re-allocating
@@ -461,6 +467,10 @@
         // This object has been released.
         return;
       }
+      if (!seenFrame && rendererEvents != null) {
+        Log.d(TAG, "ID: " + id + ". Reporting first rendered frame.");
+        rendererEvents.onFirstFrameRendered();
+      }
       setSize(frame.width, frame.height, frame.rotationDegree);
       long now = System.nanoTime();
       framesReceived++;
@@ -518,6 +528,19 @@
     }
   }
 
+  /** Interface for reporting rendering events. */
+  public static interface RendererEvents {
+    /**
+     * Callback fired once first frame is rendered.
+     */
+    public void onFirstFrameRendered();
+
+    /**
+     * Callback fired when rendered frame resolution or rotation has changed.
+     */
+    public void onFrameResolutionChanged(int videoWidth, int videoHeight, int rotation);
+  }
+
   /** Passes GLSurfaceView to video renderer. */
   public static synchronized void setView(GLSurfaceView surface,
       Runnable eglContextReadyCallback) {
@@ -612,6 +635,22 @@
     }
   }
 
+  public static synchronized void setRendererEvents(
+      VideoRenderer.Callbacks renderer, RendererEvents rendererEvents) {
+    Log.d(TAG, "VideoRendererGui.setRendererEvents");
+    if (instance == null) {
+      throw new RuntimeException(
+          "Attempt to set renderer events before setting GLSurfaceView");
+    }
+    synchronized (instance.yuvImageRenderers) {
+      for (YuvImageRenderer yuvImageRenderer : instance.yuvImageRenderers) {
+        if (yuvImageRenderer == renderer) {
+          yuvImageRenderer.rendererEvents = rendererEvents;
+        }
+      }
+    }
+  }
+
   public static synchronized void remove(VideoRenderer.Callbacks renderer) {
     Log.d(TAG, "VideoRendererGui.remove");
     if (instance == null) {