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}
This commit is contained in:
parent
d33258098b
commit
55e9a7dc4b
@ -148,6 +148,7 @@ public class VideoRendererGui implements GLSurfaceView.Renderer {
|
||||
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 @@ public class VideoRendererGui implements GLSurfaceView.Renderer {
|
||||
&& 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 @@ public class VideoRendererGui implements GLSurfaceView.Renderer {
|
||||
// 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 @@ public class VideoRendererGui implements GLSurfaceView.Renderer {
|
||||
}
|
||||
}
|
||||
|
||||
/** 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 class VideoRendererGui implements GLSurfaceView.Renderer {
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user