Android: Let VideoSource dispose SurfaceTextureHelper

This CL is a follow-up to
https://webrtc-review.googlesource.com/c/src/+/71666 where a lot of code
was removed. Accidentally, the code that called
SurfaceTextureHelper.dispose() was removed. This code used to reside in
surfacetexturehelper.cc. This CL reintroduces the call to dispose in the
VideoSource.java backwards compatibility path.

Bug: webrtc:9181
Change-Id: I3e439dbf97965d806d238f7697561ac5ee9e79f1
Reviewed-on: https://webrtc-review.googlesource.com/73180
Commit-Queue: Magnus Jedvert <magjed@webrtc.org>
Reviewed-by: Sami Kalliomäki <sakal@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23087}
This commit is contained in:
Magnus Jedvert
2018-05-02 14:41:22 +02:00
committed by Commit Bot
parent 2e28edaa8a
commit 26b9e12289
2 changed files with 21 additions and 6 deletions

View File

@ -29,7 +29,7 @@ public interface VideoCapturer {
throw new UnsupportedOperationException("Deprecated and not implemented.");
}
// Delivers a captured frame in a texture with id |oesTextureId|. Called on a Java thread
// Delivers a captured frame in a texture with id {@code oesTextureId}. Called on a Java thread
// owned by VideoCapturer.
@Deprecated
default void onTextureFrameCaptured(int width, int height, int oesTextureId,
@ -46,15 +46,18 @@ public interface VideoCapturer {
* capture observer. It will be called only once and before any startCapture() request. The
* camera thread is guaranteed to be valid until dispose() is called. If the VideoCapturer wants
* to deliver texture frames, it should do this by rendering on the SurfaceTexture in
* |surfaceTextureHelper|, register itself as a listener, and forward the frames to
* CapturerObserver.onFrameCaptured().
* {@code surfaceTextureHelper}, register itself as a listener, and forward the frames to
* CapturerObserver.onFrameCaptured(). The caller still has ownership of {@code
* surfaceTextureHelper} and is responsible for making sure surfaceTextureHelper.dispose() is
* called. This also means that the caller can reuse the SurfaceTextureHelper to initialize a new
* VideoCapturer once the previous VideoCapturer has been disposed.
*/
void initialize(SurfaceTextureHelper surfaceTextureHelper, Context applicationContext,
CapturerObserver capturerObserver);
/**
* Start capturing frames in a format that is as close as possible to |width| x |height| and
* |framerate|.
* Start capturing frames in a format that is as close as possible to {@code width x height} and
* {@code framerate}.
*/
void startCapture(int width, int height, int framerate);

View File

@ -75,9 +75,15 @@ public class VideoSource extends MediaSource {
frame.getBuffer().getHeight(), frame.getRotation(), frame.getTimestampNs(),
frame.getBuffer());
}
public void dispose() {
if (surfaceTextureHelper != null) {
surfaceTextureHelper.dispose();
}
}
}
private final VideoCapturer.CapturerObserver capturerObserver;
private final NativeCapturerObserver capturerObserver;
public VideoSource(long nativeSource) {
super(nativeSource);
@ -104,6 +110,12 @@ public class VideoSource extends MediaSource {
return capturerObserver;
}
@Override
public void dispose() {
capturerObserver.dispose();
super.dispose();
}
private static native void nativeAdaptOutputFormat(long source, int width, int height, int fps);
private static native void nativeCapturerStarted(long source, boolean success);
private static native void nativeCapturerStopped(long source);