blob: 3ea22736ea34f61925f66b6e1073b3d0c77ab6d6 [file] [log] [blame]
Magnus Jedvert4ae28a12015-09-15 09:44:07 +02001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2015 The WebRTC project authors. All Rights Reserved.
Magnus Jedvert4ae28a12015-09-15 09:44:07 +02003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
Magnus Jedvert4ae28a12015-09-15 09:44:07 +02009 */
10
11package org.webrtc;
12
Jonathan Yu22384412017-08-16 13:25:45 -070013import android.annotation.TargetApi;
Magnus Jedvert4ae28a12015-09-15 09:44:07 +020014import android.graphics.SurfaceTexture;
Magnus Jedvert4ae28a12015-09-15 09:44:07 +020015import android.opengl.GLES11Ext;
16import android.opengl.GLES20;
17import android.os.Build;
18import android.os.Handler;
19import android.os.HandlerThread;
Byoungchan Lee02334e02021-08-14 11:41:59 +090020import androidx.annotation.Nullable;
Magnus Jedvert747c1bc2015-10-12 09:27:48 +020021import java.util.concurrent.Callable;
Sami Kalliomäki066b42f2019-08-30 11:20:42 +020022import org.webrtc.EglBase.Context;
23import org.webrtc.TextureBufferImpl.RefCountMonitor;
Bjorn Mellem8fb23612017-07-18 11:33:39 -070024import org.webrtc.VideoFrame.TextureBuffer;
Magnus Jedvert4ae28a12015-09-15 09:44:07 +020025
26/**
Magnus Jedvert80e7a7f2018-07-06 11:15:13 +020027 * Helper class for using a SurfaceTexture to create WebRTC VideoFrames. In order to create WebRTC
28 * VideoFrames, render onto the SurfaceTexture. The frames will be delivered to the listener. Only
29 * one texture frame can be in flight at once, so the frame must be released in order to receive a
30 * new frame. Call stopListening() to stop receiveing new frames. Call dispose to release all
31 * resources once the texture frame is released.
Magnus Jedvert4ae28a12015-09-15 09:44:07 +020032 */
skvladed6e0772016-11-30 14:40:18 -080033public class SurfaceTextureHelper {
Sami Kalliomäki066b42f2019-08-30 11:20:42 +020034 /**
35 * Interface for monitoring texture buffers created from this SurfaceTexture. Since only one
36 * texture buffer can exist at a time, this can be used to monitor for stuck frames.
37 */
38 public interface FrameRefMonitor {
39 /** A new frame was created. New frames start with ref count of 1. */
40 void onNewBuffer(TextureBuffer textureBuffer);
41 /** Ref count of the frame was incremented by the calling thread. */
42 void onRetainBuffer(TextureBuffer textureBuffer);
43 /** Ref count of the frame was decremented by the calling thread. */
44 void onReleaseBuffer(TextureBuffer textureBuffer);
45 /** Frame was destroyed (ref count reached 0). */
46 void onDestroyBuffer(TextureBuffer textureBuffer);
47 }
48
Magnus Jedvert4ae28a12015-09-15 09:44:07 +020049 private static final String TAG = "SurfaceTextureHelper";
50 /**
Artem Titovd7ac5812021-07-27 12:23:39 +020051 * Construct a new SurfaceTextureHelper sharing OpenGL resources with `sharedContext`. A dedicated
magjed2aa84262016-05-09 08:28:45 -070052 * thread and handler is created for handling the SurfaceTexture. May return null if EGL fails to
Magnus Jedvert95140712018-11-15 12:07:32 +010053 * initialize a pixel buffer surface and make it current. If alignTimestamps is true, the frame
54 * timestamps will be aligned to rtc::TimeNanos(). If frame timestamps are aligned to
55 * rtc::TimeNanos() there is no need for aligning timestamps again in
56 * PeerConnectionFactory.createVideoSource(). This makes the timestamps more accurate and
57 * closer to actual creation time.
Magnus Jedvert747c1bc2015-10-12 09:27:48 +020058 */
Åsa Perssonf2889bb2019-02-25 16:20:01 +010059 public static SurfaceTextureHelper create(final String threadName,
Sami Kalliomäki066b42f2019-08-30 11:20:42 +020060 final EglBase.Context sharedContext, boolean alignTimestamps, final YuvConverter yuvConverter,
61 FrameRefMonitor frameRefMonitor) {
magjed82b750b2016-03-31 00:54:15 -070062 final HandlerThread thread = new HandlerThread(threadName);
magjed9e69dfd2016-02-26 07:45:44 -080063 thread.start();
64 final Handler handler = new Handler(thread.getLooper());
65
Magnus Jedvert747c1bc2015-10-12 09:27:48 +020066 // The onFrameAvailable() callback will be executed on the SurfaceTexture ctor thread. See:
67 // http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/5.1.1_r1/android/graphics/SurfaceTexture.java#195.
68 // Therefore, in order to control the callback thread on API lvl < 21, the SurfaceTextureHelper
Artem Titovd7ac5812021-07-27 12:23:39 +020069 // is constructed on the `handler` thread.
nissea44e72c2016-05-27 00:27:59 -070070 return ThreadUtils.invokeAtFrontUninterruptibly(handler, new Callable<SurfaceTextureHelper>() {
Sami Kalliomäkie7592d82018-03-22 13:32:44 +010071 @Nullable
magjed9e69dfd2016-02-26 07:45:44 -080072 @Override
73 public SurfaceTextureHelper call() {
magjed2aa84262016-05-09 08:28:45 -070074 try {
Sami Kalliomäki066b42f2019-08-30 11:20:42 +020075 return new SurfaceTextureHelper(
76 sharedContext, handler, alignTimestamps, yuvConverter, frameRefMonitor);
magjed2aa84262016-05-09 08:28:45 -070077 } catch (RuntimeException e) {
78 Logging.e(TAG, threadName + " create failure", e);
79 return null;
80 }
Magnus Jedvert747c1bc2015-10-12 09:27:48 +020081 }
82 });
83 }
84
Magnus Jedvert95140712018-11-15 12:07:32 +010085 /**
Åsa Perssonf2889bb2019-02-25 16:20:01 +010086 * Same as above with alignTimestamps set to false and yuvConverter set to new YuvConverter.
Magnus Jedvert95140712018-11-15 12:07:32 +010087 *
Sami Kalliomäki066b42f2019-08-30 11:20:42 +020088 * @see #create(String, EglBase.Context, boolean, YuvConverter, FrameRefMonitor)
Magnus Jedvert95140712018-11-15 12:07:32 +010089 */
90 public static SurfaceTextureHelper create(
91 final String threadName, final EglBase.Context sharedContext) {
Sami Kalliomäki066b42f2019-08-30 11:20:42 +020092 return create(threadName, sharedContext, /* alignTimestamps= */ false, new YuvConverter(),
93 /*frameRefMonitor=*/null);
Åsa Perssonf2889bb2019-02-25 16:20:01 +010094 }
95
96 /**
97 * Same as above with yuvConverter set to new YuvConverter.
98 *
Sami Kalliomäki066b42f2019-08-30 11:20:42 +020099 * @see #create(String, EglBase.Context, boolean, YuvConverter, FrameRefMonitor)
Åsa Perssonf2889bb2019-02-25 16:20:01 +0100100 */
101 public static SurfaceTextureHelper create(
102 final String threadName, final EglBase.Context sharedContext, boolean alignTimestamps) {
Sami Kalliomäki066b42f2019-08-30 11:20:42 +0200103 return create(
104 threadName, sharedContext, alignTimestamps, new YuvConverter(), /*frameRefMonitor=*/null);
Magnus Jedvert95140712018-11-15 12:07:32 +0100105 }
106
Sami Kalliomäki066b42f2019-08-30 11:20:42 +0200107 /**
108 * Create a SurfaceTextureHelper without frame ref monitor.
109 *
110 * @see #create(String, EglBase.Context, boolean, YuvConverter, FrameRefMonitor)
111 */
112 public static SurfaceTextureHelper create(final String threadName,
113 final EglBase.Context sharedContext, boolean alignTimestamps, YuvConverter yuvConverter) {
114 return create(
115 threadName, sharedContext, alignTimestamps, yuvConverter, /*frameRefMonitor=*/null);
116 }
117
118 private final RefCountMonitor textureRefCountMonitor = new RefCountMonitor() {
119 @Override
120 public void onRetain(TextureBufferImpl textureBuffer) {
121 if (frameRefMonitor != null) {
122 frameRefMonitor.onRetainBuffer(textureBuffer);
123 }
124 }
125
126 @Override
127 public void onRelease(TextureBufferImpl textureBuffer) {
128 if (frameRefMonitor != null) {
129 frameRefMonitor.onReleaseBuffer(textureBuffer);
130 }
131 }
132
133 @Override
134 public void onDestroy(TextureBufferImpl textureBuffer) {
135 returnTextureFrame();
136 if (frameRefMonitor != null) {
137 frameRefMonitor.onDestroyBuffer(textureBuffer);
138 }
139 }
140 };
141
Magnus Jedvert4ae28a12015-09-15 09:44:07 +0200142 private final Handler handler;
143 private final EglBase eglBase;
144 private final SurfaceTexture surfaceTexture;
145 private final int oesTextureId;
Åsa Perssonf2889bb2019-02-25 16:20:01 +0100146 private final YuvConverter yuvConverter;
Magnus Jedvert95140712018-11-15 12:07:32 +0100147 @Nullable private final TimestampAligner timestampAligner;
Sami Kalliomäki066b42f2019-08-30 11:20:42 +0200148 private final FrameRefMonitor frameRefMonitor;
nissec490e012015-12-10 06:23:33 -0800149
Artem Titovd7ac5812021-07-27 12:23:39 +0200150 // These variables are only accessed from the `handler` thread.
Magnus Jedvert814f99c2018-08-03 11:15:14 +0200151 @Nullable private VideoSink listener;
Magnus Jedvert4ae28a12015-09-15 09:44:07 +0200152 // The possible states of this class.
Sami Kalliomäki3d50a312018-09-11 11:11:47 +0200153 private boolean hasPendingTexture;
154 private volatile boolean isTextureInUse;
155 private boolean isQuitting;
Magnus Jedvert80e7a7f2018-07-06 11:15:13 +0200156 private int frameRotation;
157 private int textureWidth;
158 private int textureHeight;
Artem Titovd7ac5812021-07-27 12:23:39 +0200159 // `pendingListener` is set in setListener() and the runnable is posted to the handler thread.
magjedd8ddb792016-03-17 03:13:43 -0700160 // setListener() is not allowed to be called again before stopListening(), so this is thread safe.
Magnus Jedvert814f99c2018-08-03 11:15:14 +0200161 @Nullable private VideoSink pendingListener;
magjedd8ddb792016-03-17 03:13:43 -0700162 final Runnable setListenerRunnable = new Runnable() {
163 @Override
164 public void run() {
165 Logging.d(TAG, "Setting listener to " + pendingListener);
166 listener = pendingListener;
167 pendingListener = null;
Magnus Jedvert181310f2016-05-23 16:26:47 +0200168 // May have a pending frame from the previous capture session - drop it.
169 if (hasPendingTexture) {
170 // Calling updateTexImage() is neccessary in order to receive new frames.
171 updateTexImage();
172 hasPendingTexture = false;
173 }
magjedd8ddb792016-03-17 03:13:43 -0700174 }
175 };
Magnus Jedvert4ae28a12015-09-15 09:44:07 +0200176
Sami Kalliomäki066b42f2019-08-30 11:20:42 +0200177 private SurfaceTextureHelper(Context sharedContext, Handler handler, boolean alignTimestamps,
178 YuvConverter yuvConverter, FrameRefMonitor frameRefMonitor) {
Alex Glazneva5b62d92015-10-12 13:56:20 -0700179 if (handler.getLooper().getThread() != Thread.currentThread()) {
Magnus Jedvert747c1bc2015-10-12 09:27:48 +0200180 throw new IllegalStateException("SurfaceTextureHelper must be created on the handler thread");
perkj1b33da12015-10-05 21:06:41 +0200181 }
Magnus Jedvert747c1bc2015-10-12 09:27:48 +0200182 this.handler = handler;
Magnus Jedvert95140712018-11-15 12:07:32 +0100183 this.timestampAligner = alignTimestamps ? new TimestampAligner() : null;
Åsa Perssonf2889bb2019-02-25 16:20:01 +0100184 this.yuvConverter = yuvConverter;
Sami Kalliomäki066b42f2019-08-30 11:20:42 +0200185 this.frameRefMonitor = frameRefMonitor;
Magnus Jedvert4ae28a12015-09-15 09:44:07 +0200186
nisse03f80eb2015-12-07 01:17:16 -0800187 eglBase = EglBase.create(sharedContext, EglBase.CONFIG_PIXEL_BUFFER);
magjed2aa84262016-05-09 08:28:45 -0700188 try {
189 // Both these statements have been observed to fail on rare occasions, see BUG=webrtc:5682.
190 eglBase.createDummyPbufferSurface();
191 eglBase.makeCurrent();
192 } catch (RuntimeException e) {
193 // Clean up before rethrowing the exception.
194 eglBase.release();
195 handler.getLooper().quit();
196 throw e;
197 }
Magnus Jedvert4ae28a12015-09-15 09:44:07 +0200198
199 oesTextureId = GlUtil.generateTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES);
200 surfaceTexture = new SurfaceTexture(oesTextureId);
Xavier Lepaul0f50cc22022-03-07 10:23:23 +0100201 surfaceTexture.setOnFrameAvailableListener(st -> {
Sami Kalliomäki9d9d10c2020-08-14 13:46:04 +0200202 if (hasPendingTexture) {
203 Logging.d(TAG, "A frame is already pending, dropping frame.");
204 }
205
Jonathan Yu22384412017-08-16 13:25:45 -0700206 hasPendingTexture = true;
207 tryDeliverTextureFrame();
208 }, handler);
209 }
210
Magnus Jedvert4ae28a12015-09-15 09:44:07 +0200211 /**
Artem Titovd7ac5812021-07-27 12:23:39 +0200212 * Start to stream textures to the given `listener`. If you need to change listener, you need to
magjed81e8e372016-03-03 02:11:44 -0800213 * call stopListening() first.
Magnus Jedvert80e7a7f2018-07-06 11:15:13 +0200214 */
215 public void startListening(final VideoSink listener) {
magjedd8ddb792016-03-17 03:13:43 -0700216 if (this.listener != null || this.pendingListener != null) {
Per3e9eb4b2015-09-28 10:52:22 +0200217 throw new IllegalStateException("SurfaceTextureHelper listener has already been set.");
218 }
magjedd8ddb792016-03-17 03:13:43 -0700219 this.pendingListener = listener;
220 handler.post(setListenerRunnable);
Per3e9eb4b2015-09-28 10:52:22 +0200221 }
222
223 /**
magjed81e8e372016-03-03 02:11:44 -0800224 * Stop listening. The listener set in startListening() is guaranteded to not receive any more
Magnus Jedvert814f99c2018-08-03 11:15:14 +0200225 * onFrame() callbacks after this function returns.
magjed81e8e372016-03-03 02:11:44 -0800226 */
227 public void stopListening() {
magjedd8ddb792016-03-17 03:13:43 -0700228 Logging.d(TAG, "stopListening()");
229 handler.removeCallbacks(setListenerRunnable);
Magnus Jedvert80e7a7f2018-07-06 11:15:13 +0200230 ThreadUtils.invokeAtFrontUninterruptibly(handler, () -> {
231 listener = null;
232 pendingListener = null;
nissea44e72c2016-05-27 00:27:59 -0700233 });
magjed81e8e372016-03-03 02:11:44 -0800234 }
235
236 /**
Magnus Jedvert80e7a7f2018-07-06 11:15:13 +0200237 * Use this function to set the texture size. Note, do not call setDefaultBufferSize() yourself
238 * since this class needs to be aware of the texture size.
239 */
240 public void setTextureSize(int textureWidth, int textureHeight) {
241 if (textureWidth <= 0) {
242 throw new IllegalArgumentException("Texture width must be positive, but was " + textureWidth);
243 }
244 if (textureHeight <= 0) {
245 throw new IllegalArgumentException(
246 "Texture height must be positive, but was " + textureHeight);
247 }
248 surfaceTexture.setDefaultBufferSize(textureWidth, textureHeight);
249 handler.post(() -> {
250 this.textureWidth = textureWidth;
251 this.textureHeight = textureHeight;
Magnus Jedvert31f18e12019-06-04 11:11:11 +0200252 tryDeliverTextureFrame();
Magnus Jedvert80e7a7f2018-07-06 11:15:13 +0200253 });
254 }
255
Xavier Lepaulf0ab6a02020-06-11 14:03:56 +0200256 /**
257 * Forces a frame to be produced. If no new frame is available, the last frame is sent to the
258 * listener again.
259 */
260 public void forceFrame() {
261 handler.post(() -> {
262 hasPendingTexture = true;
263 tryDeliverTextureFrame();
264 });
265 }
266
Magnus Jedvert80e7a7f2018-07-06 11:15:13 +0200267 /** Set the rotation of the delivered frames. */
268 public void setFrameRotation(int rotation) {
269 handler.post(() -> this.frameRotation = rotation);
270 }
271
272 /**
Magnus Jedvert4ae28a12015-09-15 09:44:07 +0200273 * Retrieve the underlying SurfaceTexture. The SurfaceTexture should be passed in to a video
274 * producer such as a camera or decoder.
275 */
276 public SurfaceTexture getSurfaceTexture() {
277 return surfaceTexture;
278 }
279
Magnus Jedvert814f99c2018-08-03 11:15:14 +0200280 /** Retrieve the handler that calls onFrame(). This handler is valid until dispose() is called. */
magjed9e69dfd2016-02-26 07:45:44 -0800281 public Handler getHandler() {
282 return handler;
283 }
284
285 /**
Magnus Jedvert814f99c2018-08-03 11:15:14 +0200286 * This function is called when the texture frame is released. Only one texture frame can be in
287 * flight at once, so this function must be called before a new frame is delivered.
Magnus Jedvert4ae28a12015-09-15 09:44:07 +0200288 */
Magnus Jedvert814f99c2018-08-03 11:15:14 +0200289 private void returnTextureFrame() {
Magnus Jedvert80e7a7f2018-07-06 11:15:13 +0200290 handler.post(() -> {
291 isTextureInUse = false;
292 if (isQuitting) {
293 release();
294 } else {
295 tryDeliverTextureFrame();
Magnus Jedvert4ae28a12015-09-15 09:44:07 +0200296 }
297 });
298 }
299
perkj88518a22015-12-18 00:37:06 -0800300 public boolean isTextureInUse() {
301 return isTextureInUse;
302 }
303
Magnus Jedvert4ae28a12015-09-15 09:44:07 +0200304 /**
magjed9e69dfd2016-02-26 07:45:44 -0800305 * Call disconnect() to stop receiving frames. OpenGL resources are released and the handler is
Magnus Jedvert814f99c2018-08-03 11:15:14 +0200306 * stopped when the texture frame has been released. You are guaranteed to not receive any more
307 * onFrame() after this function returns.
Magnus Jedvert4ae28a12015-09-15 09:44:07 +0200308 */
magjed81e8e372016-03-03 02:11:44 -0800309 public void dispose() {
magjedd8ddb792016-03-17 03:13:43 -0700310 Logging.d(TAG, "dispose()");
Magnus Jedvert80e7a7f2018-07-06 11:15:13 +0200311 ThreadUtils.invokeAtFrontUninterruptibly(handler, () -> {
312 isQuitting = true;
313 if (!isTextureInUse) {
314 release();
Magnus Jedvert4ae28a12015-09-15 09:44:07 +0200315 }
316 });
Magnus Jedvert4ae28a12015-09-15 09:44:07 +0200317 }
318
Sami Kalliomäkicb98b112017-10-16 11:20:26 +0200319 /**
Artem Titovd7ac5812021-07-27 12:23:39 +0200320 * Posts to the correct thread to convert `textureBuffer` to I420.
Magnus Jedvert80e7a7f2018-07-06 11:15:13 +0200321 *
322 * @deprecated Use toI420() instead.
Sami Kalliomäkicb98b112017-10-16 11:20:26 +0200323 */
Magnus Jedvert80e7a7f2018-07-06 11:15:13 +0200324 @Deprecated
Sami Kalliomäkicb98b112017-10-16 11:20:26 +0200325 public VideoFrame.I420Buffer textureToYuv(final TextureBuffer textureBuffer) {
Magnus Jedvert80e7a7f2018-07-06 11:15:13 +0200326 return textureBuffer.toI420();
Sami Kalliomäkicb98b112017-10-16 11:20:26 +0200327 }
328
Magnus Jedvert181310f2016-05-23 16:26:47 +0200329 private void updateTexImage() {
330 // SurfaceTexture.updateTexImage apparently can compete and deadlock with eglSwapBuffers,
331 // as observed on Nexus 5. Therefore, synchronize it with the EGL functions.
332 // See https://bugs.chromium.org/p/webrtc/issues/detail?id=5702 for more info.
333 synchronized (EglBase.lock) {
334 surfaceTexture.updateTexImage();
335 }
336 }
337
Magnus Jedvert4ae28a12015-09-15 09:44:07 +0200338 private void tryDeliverTextureFrame() {
Alex Glazneva5b62d92015-10-12 13:56:20 -0700339 if (handler.getLooper().getThread() != Thread.currentThread()) {
Magnus Jedvert4ae28a12015-09-15 09:44:07 +0200340 throw new IllegalStateException("Wrong thread.");
341 }
magjed81e8e372016-03-03 02:11:44 -0800342 if (isQuitting || !hasPendingTexture || isTextureInUse || listener == null) {
Magnus Jedvert4ae28a12015-09-15 09:44:07 +0200343 return;
344 }
Magnus Jedvert31f18e12019-06-04 11:11:11 +0200345 if (textureWidth == 0 || textureHeight == 0) {
346 // Information about the resolution needs to be provided by a call to setTextureSize() before
347 // frames are produced.
348 Logging.w(TAG, "Texture size has not been set.");
349 return;
350 }
Magnus Jedvert4ae28a12015-09-15 09:44:07 +0200351 isTextureInUse = true;
352 hasPendingTexture = false;
353
Magnus Jedvert181310f2016-05-23 16:26:47 +0200354 updateTexImage();
perkj1b33da12015-10-05 21:06:41 +0200355
Magnus Jedvert4ae28a12015-09-15 09:44:07 +0200356 final float[] transformMatrix = new float[16];
357 surfaceTexture.getTransformMatrix(transformMatrix);
Magnus Jedvert95140712018-11-15 12:07:32 +0100358 long timestampNs = surfaceTexture.getTimestamp();
359 if (timestampAligner != null) {
360 timestampNs = timestampAligner.translateTimestamp(timestampNs);
361 }
Sami Kalliomäki066b42f2019-08-30 11:20:42 +0200362 final VideoFrame.TextureBuffer buffer =
Magnus Jedvert814f99c2018-08-03 11:15:14 +0200363 new TextureBufferImpl(textureWidth, textureHeight, TextureBuffer.Type.OES, oesTextureId,
364 RendererCommon.convertMatrixToAndroidGraphicsMatrix(transformMatrix), handler,
Sami Kalliomäki066b42f2019-08-30 11:20:42 +0200365 yuvConverter, textureRefCountMonitor);
366 if (frameRefMonitor != null) {
367 frameRefMonitor.onNewBuffer(buffer);
368 }
Magnus Jedvert814f99c2018-08-03 11:15:14 +0200369 final VideoFrame frame = new VideoFrame(buffer, frameRotation, timestampNs);
Sami Kalliomäki066b42f2019-08-30 11:20:42 +0200370 listener.onFrame(frame);
Magnus Jedvert814f99c2018-08-03 11:15:14 +0200371 frame.release();
Magnus Jedvert4ae28a12015-09-15 09:44:07 +0200372 }
373
374 private void release() {
Alex Glazneva5b62d92015-10-12 13:56:20 -0700375 if (handler.getLooper().getThread() != Thread.currentThread()) {
Magnus Jedvert1ab271c2015-09-28 11:05:44 +0200376 throw new IllegalStateException("Wrong thread.");
377 }
Magnus Jedvert4ae28a12015-09-15 09:44:07 +0200378 if (isTextureInUse || !isQuitting) {
379 throw new IllegalStateException("Unexpected release.");
380 }
Magnus Jedvert1d270f82018-04-16 16:28:29 +0200381 yuvConverter.release();
Magnus Jedvert1ab271c2015-09-28 11:05:44 +0200382 GLES20.glDeleteTextures(1, new int[] {oesTextureId}, 0);
383 surfaceTexture.release();
384 eglBase.release();
perkj92375592015-11-24 03:03:13 -0800385 handler.getLooper().quit();
Magnus Jedvert95140712018-11-15 12:07:32 +0100386 if (timestampAligner != null) {
387 timestampAligner.dispose();
388 }
Magnus Jedvert4ae28a12015-09-15 09:44:07 +0200389 }
Magnus Jedvert4ae28a12015-09-15 09:44:07 +0200390}