SurfaceTexture.java revision aff2f949395725f4bb82802bd12201b65d514e68
16714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis/* 26714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis * Copyright (C) 2010 The Android Open Source Project 36714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis * 46714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis * Licensed under the Apache License, Version 2.0 (the "License"); 56714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis * you may not use this file except in compliance with the License. 66714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis * You may obtain a copy of the License at 76714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis * 86714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis * http://www.apache.org/licenses/LICENSE-2.0 96714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis * 106714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis * Unless required by applicable law or agreed to in writing, software 116714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis * distributed under the License is distributed on an "AS IS" BASIS, 126714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 136714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis * See the License for the specific language governing permissions and 146714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis * limitations under the License. 156714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis */ 166714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis 176714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennispackage android.graphics; 186714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis 19376590d668e22a918439877b55faf075427b13f3Jamie Gennisimport java.lang.ref.WeakReference; 20b89d88f531ee39927f8f554baaae5ecc9101ba9dMathias Agopian 21ba873d21718b0c0bbeabbb3b4796e54073739700Jeff Brownimport android.annotation.Nullable; 22376590d668e22a918439877b55faf075427b13f3Jamie Gennisimport android.os.Handler; 23376590d668e22a918439877b55faf075427b13f3Jamie Gennisimport android.os.Looper; 24376590d668e22a918439877b55faf075427b13f3Jamie Gennisimport android.os.Message; 25a86ab640f7bb0bf3cb4eaed80473ca8c5d131903Igor Murashkinimport android.view.Surface; 26376590d668e22a918439877b55faf075427b13f3Jamie Gennis 276714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis/** 286714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis * Captures frames from an image stream as an OpenGL ES texture. 296714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis * 30b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * <p>The image stream may come from either camera preview or video decode. A 31b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * {@link android.view.Surface} created from a SurfaceTexture can be used as an output 32b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * destination for the {@link android.hardware.camera2}, {@link android.media.MediaCodec}, 33b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * {@link android.media.MediaPlayer}, and {@link android.renderscript.Allocation} APIs. 34b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * When {@link #updateTexImage} is called, the contents of the texture object specified 35b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * when the SurfaceTexture was created are updated to contain the most recent image from the image 36b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * stream. This may cause some frames of the stream to be skipped. 37b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * 38b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * <p>A SurfaceTexture may also be used in place of a SurfaceHolder when specifying the output 39b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * destination of the older {@link android.hardware.Camera} API. Doing so will cause all the 40b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * frames from the image stream to be sent to the SurfaceTexture object rather than to the device's 41b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * display. 426714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis * 435f8b6653e0b5b99097db7d8f41d5251f7b398704Jamie Gennis * <p>When sampling from the texture one should first transform the texture coordinates using the 448f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy * matrix queried via {@link #getTransformMatrix(float[])}. The transform matrix may change each 458f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy * time {@link #updateTexImage} is called, so it should be re-queried each time the texture image 468f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy * is updated. 475f8b6653e0b5b99097db7d8f41d5251f7b398704Jamie Gennis * This matrix transforms traditional 2D OpenGL ES texture coordinate column vectors of the form (s, 485f8b6653e0b5b99097db7d8f41d5251f7b398704Jamie Gennis * t, 0, 1) where s and t are on the inclusive interval [0, 1] to the proper sampling location in 495f8b6653e0b5b99097db7d8f41d5251f7b398704Jamie Gennis * the streamed texture. This transform compensates for any properties of the image stream source 505f8b6653e0b5b99097db7d8f41d5251f7b398704Jamie Gennis * that cause it to appear different from a traditional OpenGL ES texture. For example, sampling 515f8b6653e0b5b99097db7d8f41d5251f7b398704Jamie Gennis * from the bottom left corner of the image can be accomplished by transforming the column vector 525f8b6653e0b5b99097db7d8f41d5251f7b398704Jamie Gennis * (0, 0, 0, 1) using the queried matrix, while sampling from the top right corner of the image can 535f8b6653e0b5b99097db7d8f41d5251f7b398704Jamie Gennis * be done by transforming (1, 1, 0, 1). 545f8b6653e0b5b99097db7d8f41d5251f7b398704Jamie Gennis * 556714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis * <p>The texture object uses the GL_TEXTURE_EXTERNAL_OES texture target, which is defined by the 56858873271250e80a704c29c71ff0578a87bd9d31Jamie Gennis * <a href="http://www.khronos.org/registry/gles/extensions/OES/OES_EGL_image_external.txt"> 57858873271250e80a704c29c71ff0578a87bd9d31Jamie Gennis * GL_OES_EGL_image_external</a> OpenGL ES extension. This limits how the texture may be used. 58858873271250e80a704c29c71ff0578a87bd9d31Jamie Gennis * Each time the texture is bound it must be bound to the GL_TEXTURE_EXTERNAL_OES target rather than 59858873271250e80a704c29c71ff0578a87bd9d31Jamie Gennis * the GL_TEXTURE_2D target. Additionally, any OpenGL ES 2.0 shader that samples from the texture 60858873271250e80a704c29c71ff0578a87bd9d31Jamie Gennis * must declare its use of this extension using, for example, an "#extension 61858873271250e80a704c29c71ff0578a87bd9d31Jamie Gennis * GL_OES_EGL_image_external : require" directive. Such shaders must also access the texture using 62858873271250e80a704c29c71ff0578a87bd9d31Jamie Gennis * the samplerExternalOES GLSL sampler type. 6337cec0fc50760fe89614863eded14011f9412534Jamie Gennis * 6437cec0fc50760fe89614863eded14011f9412534Jamie Gennis * <p>SurfaceTexture objects may be created on any thread. {@link #updateTexImage} may only be 6537cec0fc50760fe89614863eded14011f9412534Jamie Gennis * called on the thread with the OpenGL ES context that contains the texture object. The 6637cec0fc50760fe89614863eded14011f9412534Jamie Gennis * frame-available callback is called on an arbitrary thread, so unless special care is taken {@link 6737cec0fc50760fe89614863eded14011f9412534Jamie Gennis * #updateTexImage} should not be called directly from the callback. 686714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis */ 696714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennispublic class SurfaceTexture { 70c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown private final Looper mCreatorLooper; 71c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown private Handler mOnFrameAvailableHandler; 72376590d668e22a918439877b55faf075427b13f3Jamie Gennis 738f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy /** 74c99db2bc460cc795947d99076da380e22a21e493Igor Murashkin * These fields are used by native code, do not access or modify. 758f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy */ 7672aa313ff4c91e7b2aae3d37067f9201b2b0fdbeAshok Bhat private long mSurfaceTexture; 770dc146be5a6cd0c33910d5b18885df46873a93cbDan Stoza private long mProducer; 7872aa313ff4c91e7b2aae3d37067f9201b2b0fdbeAshok Bhat private long mFrameAvailableListener; 796714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis 80aff2f949395725f4bb82802bd12201b65d514e68Pablo Ceballos private boolean mIsSingleBuffered; 81aff2f949395725f4bb82802bd12201b65d514e68Pablo Ceballos 826714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis /** 836714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis * Callback interface for being notified that a new stream frame is available. 846714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis */ 856714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis public interface OnFrameAvailableListener { 866714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis void onFrameAvailable(SurfaceTexture surfaceTexture); 876714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis } 886714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis 896714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis /** 90a86ab640f7bb0bf3cb4eaed80473ca8c5d131903Igor Murashkin * Exception thrown when a SurfaceTexture couldn't be created or resized. 91a86ab640f7bb0bf3cb4eaed80473ca8c5d131903Igor Murashkin * 92c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown * @deprecated No longer thrown. {@link android.view.Surface.OutOfResourcesException} 93c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown * is used instead. 946714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis */ 95a86ab640f7bb0bf3cb4eaed80473ca8c5d131903Igor Murashkin @SuppressWarnings("serial") 96a86ab640f7bb0bf3cb4eaed80473ca8c5d131903Igor Murashkin @Deprecated 976714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis public static class OutOfResourcesException extends Exception { 986714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis public OutOfResourcesException() { 996714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis } 1006714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis public OutOfResourcesException(String name) { 1016714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis super(name); 1026714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis } 1036714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis } 1046714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis 1056714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis /** 1066714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis * Construct a new SurfaceTexture to stream images to a given OpenGL texture. 1076714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis * 1086714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis * @param texName the OpenGL texture object name (e.g. generated via glGenTextures) 109a86ab640f7bb0bf3cb4eaed80473ca8c5d131903Igor Murashkin * 110c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown * @throws Surface.OutOfResourcesException If the SurfaceTexture cannot be created. 1116714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis */ 1126714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis public SurfaceTexture(int texName) { 113c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown this(texName, false); 114e591b49de038a9942cbcc77540c03e85c96e3dcbMathias Agopian } 115e591b49de038a9942cbcc77540c03e85c96e3dcbMathias Agopian 116e591b49de038a9942cbcc77540c03e85c96e3dcbMathias Agopian /** 117e591b49de038a9942cbcc77540c03e85c96e3dcbMathias Agopian * Construct a new SurfaceTexture to stream images to a given OpenGL texture. 118e591b49de038a9942cbcc77540c03e85c96e3dcbMathias Agopian * 119e591b49de038a9942cbcc77540c03e85c96e3dcbMathias Agopian * In single buffered mode the application is responsible for serializing access to the image 120e591b49de038a9942cbcc77540c03e85c96e3dcbMathias Agopian * content buffer. Each time the image content is to be updated, the 121e591b49de038a9942cbcc77540c03e85c96e3dcbMathias Agopian * {@link #releaseTexImage()} method must be called before the image content producer takes 122e591b49de038a9942cbcc77540c03e85c96e3dcbMathias Agopian * ownership of the buffer. For example, when producing image content with the NDK 123e591b49de038a9942cbcc77540c03e85c96e3dcbMathias Agopian * ANativeWindow_lock and ANativeWindow_unlockAndPost functions, {@link #releaseTexImage()} 124e591b49de038a9942cbcc77540c03e85c96e3dcbMathias Agopian * must be called before each ANativeWindow_lock, or that call will fail. When producing 125e591b49de038a9942cbcc77540c03e85c96e3dcbMathias Agopian * image content with OpenGL ES, {@link #releaseTexImage()} must be called before the first 126e591b49de038a9942cbcc77540c03e85c96e3dcbMathias Agopian * OpenGL ES function call each frame. 127e591b49de038a9942cbcc77540c03e85c96e3dcbMathias Agopian * 128e591b49de038a9942cbcc77540c03e85c96e3dcbMathias Agopian * @param texName the OpenGL texture object name (e.g. generated via glGenTextures) 129e591b49de038a9942cbcc77540c03e85c96e3dcbMathias Agopian * @param singleBufferMode whether the SurfaceTexture will be in single buffered mode. 130a86ab640f7bb0bf3cb4eaed80473ca8c5d131903Igor Murashkin * 131c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown * @throws Surface.OutOfResourcesException If the SurfaceTexture cannot be created. 132e591b49de038a9942cbcc77540c03e85c96e3dcbMathias Agopian */ 133e591b49de038a9942cbcc77540c03e85c96e3dcbMathias Agopian public SurfaceTexture(int texName, boolean singleBufferMode) { 134c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown mCreatorLooper = Looper.myLooper(); 135aff2f949395725f4bb82802bd12201b65d514e68Pablo Ceballos mIsSingleBuffered = singleBufferMode; 136493f2e11909e2d5839ca81ddc66d48d538192478Dan Stoza nativeInit(false, texName, singleBufferMode, new WeakReference<SurfaceTexture>(this)); 137493f2e11909e2d5839ca81ddc66d48d538192478Dan Stoza } 138493f2e11909e2d5839ca81ddc66d48d538192478Dan Stoza 139493f2e11909e2d5839ca81ddc66d48d538192478Dan Stoza /** 140493f2e11909e2d5839ca81ddc66d48d538192478Dan Stoza * Construct a new SurfaceTexture to stream images to a given OpenGL texture. 141493f2e11909e2d5839ca81ddc66d48d538192478Dan Stoza * 142493f2e11909e2d5839ca81ddc66d48d538192478Dan Stoza * In single buffered mode the application is responsible for serializing access to the image 143493f2e11909e2d5839ca81ddc66d48d538192478Dan Stoza * content buffer. Each time the image content is to be updated, the 144493f2e11909e2d5839ca81ddc66d48d538192478Dan Stoza * {@link #releaseTexImage()} method must be called before the image content producer takes 145493f2e11909e2d5839ca81ddc66d48d538192478Dan Stoza * ownership of the buffer. For example, when producing image content with the NDK 146493f2e11909e2d5839ca81ddc66d48d538192478Dan Stoza * ANativeWindow_lock and ANativeWindow_unlockAndPost functions, {@link #releaseTexImage()} 147493f2e11909e2d5839ca81ddc66d48d538192478Dan Stoza * must be called before each ANativeWindow_lock, or that call will fail. When producing 148493f2e11909e2d5839ca81ddc66d48d538192478Dan Stoza * image content with OpenGL ES, {@link #releaseTexImage()} must be called before the first 149493f2e11909e2d5839ca81ddc66d48d538192478Dan Stoza * OpenGL ES function call each frame. 150493f2e11909e2d5839ca81ddc66d48d538192478Dan Stoza * 151493f2e11909e2d5839ca81ddc66d48d538192478Dan Stoza * Unlike {@link #SurfaceTexture(int, boolean)}, which takes an OpenGL texture object name, 152493f2e11909e2d5839ca81ddc66d48d538192478Dan Stoza * this constructor creates the SurfaceTexture in detached mode. A texture name must be passed 153493f2e11909e2d5839ca81ddc66d48d538192478Dan Stoza * in using {@link #attachToGLContext} before calling {@link #releaseTexImage()} and producing 154493f2e11909e2d5839ca81ddc66d48d538192478Dan Stoza * image content using OpenGL ES. 155493f2e11909e2d5839ca81ddc66d48d538192478Dan Stoza * 156493f2e11909e2d5839ca81ddc66d48d538192478Dan Stoza * @param singleBufferMode whether the SurfaceTexture will be in single buffered mode. 157493f2e11909e2d5839ca81ddc66d48d538192478Dan Stoza * 158493f2e11909e2d5839ca81ddc66d48d538192478Dan Stoza * @throws Surface.OutOfResourcesException If the SurfaceTexture cannot be created. 159493f2e11909e2d5839ca81ddc66d48d538192478Dan Stoza * @hide 160493f2e11909e2d5839ca81ddc66d48d538192478Dan Stoza */ 161493f2e11909e2d5839ca81ddc66d48d538192478Dan Stoza public SurfaceTexture(boolean singleBufferMode) { 162493f2e11909e2d5839ca81ddc66d48d538192478Dan Stoza mCreatorLooper = Looper.myLooper(); 163aff2f949395725f4bb82802bd12201b65d514e68Pablo Ceballos mIsSingleBuffered = singleBufferMode; 164493f2e11909e2d5839ca81ddc66d48d538192478Dan Stoza nativeInit(true, 0, singleBufferMode, new WeakReference<SurfaceTexture>(this)); 1656714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis } 1666714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis 1676714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis /** 1686714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis * Register a callback to be invoked when a new image frame becomes available to the 169c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown * SurfaceTexture. 170c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown * <p> 171ba873d21718b0c0bbeabbb3b4796e54073739700Jeff Brown * The callback may be called on an arbitrary thread, so it is not 1726714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis * safe to call {@link #updateTexImage} without first binding the OpenGL ES context to the 1736714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis * thread invoking the callback. 174c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown * </p> 175c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown * 176ba873d21718b0c0bbeabbb3b4796e54073739700Jeff Brown * @param listener The listener to use, or null to remove the listener. 1776714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis */ 178ba873d21718b0c0bbeabbb3b4796e54073739700Jeff Brown public void setOnFrameAvailableListener(@Nullable OnFrameAvailableListener listener) { 179c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown setOnFrameAvailableListener(listener, null); 180c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown } 181c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown 182c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown /** 183c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown * Register a callback to be invoked when a new image frame becomes available to the 184c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown * SurfaceTexture. 185c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown * <p> 186ba873d21718b0c0bbeabbb3b4796e54073739700Jeff Brown * If a handler is specified, the callback will be invoked on that handler's thread. 187ba873d21718b0c0bbeabbb3b4796e54073739700Jeff Brown * If no handler is specified, then the callback may be called on an arbitrary thread, 188c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown * so it is not safe to call {@link #updateTexImage} without first binding the OpenGL ES 189c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown * context to the thread invoking the callback. 190c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown * </p> 191c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown * 192ba873d21718b0c0bbeabbb3b4796e54073739700Jeff Brown * @param listener The listener to use, or null to remove the listener. 193c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown * @param handler The handler on which the listener should be invoked, or null 194c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown * to use an arbitrary thread. 195c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown */ 196ba873d21718b0c0bbeabbb3b4796e54073739700Jeff Brown public void setOnFrameAvailableListener(@Nullable final OnFrameAvailableListener listener, 197ba873d21718b0c0bbeabbb3b4796e54073739700Jeff Brown @Nullable Handler handler) { 198c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown if (listener != null) { 199c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown // Although we claim the thread is arbitrary, earlier implementation would 200c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown // prefer to send the callback on the creating looper or the main looper 201c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown // so we preserve this behavior here. 202c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown Looper looper = handler != null ? handler.getLooper() : 203c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown mCreatorLooper != null ? mCreatorLooper : Looper.getMainLooper(); 204c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown mOnFrameAvailableHandler = new Handler(looper, null, true /*async*/) { 205c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown @Override 206c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown public void handleMessage(Message msg) { 207c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown listener.onFrameAvailable(SurfaceTexture.this); 208c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown } 209c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown }; 210c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown } else { 211c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown mOnFrameAvailableHandler = null; 212c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown } 2136714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis } 2146714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis 2156714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis /** 2162aafe742e5d2d63d77c49df032ec580966661597Jamie Gennis * Set the default size of the image buffers. The image producer may override the buffer size, 2172aafe742e5d2d63d77c49df032ec580966661597Jamie Gennis * in which case the producer-set buffer size will be used, not the default size set by this 2182aafe742e5d2d63d77c49df032ec580966661597Jamie Gennis * method. Both video and camera based image producers do override the size. This method may 2192aafe742e5d2d63d77c49df032ec580966661597Jamie Gennis * be used to set the image size when producing images with {@link android.graphics.Canvas} (via 2202aafe742e5d2d63d77c49df032ec580966661597Jamie Gennis * {@link android.view.Surface#lockCanvas}), or OpenGL ES (via an EGLSurface). 221050316184b01c0d1a01c46afae7429b89a27c31btedbo * 2222aafe742e5d2d63d77c49df032ec580966661597Jamie Gennis * The new default buffer size will take effect the next time the image producer requests a 2232aafe742e5d2d63d77c49df032ec580966661597Jamie Gennis * buffer to fill. For {@link android.graphics.Canvas} this will be the next time {@link 2242aafe742e5d2d63d77c49df032ec580966661597Jamie Gennis * android.view.Surface#lockCanvas} is called. For OpenGL ES, the EGLSurface should be 2252aafe742e5d2d63d77c49df032ec580966661597Jamie Gennis * destroyed (via eglDestroySurface), made not-current (via eglMakeCurrent), and then recreated 2262aafe742e5d2d63d77c49df032ec580966661597Jamie Gennis * (via eglCreateWindowSurface) to ensure that the new default size has taken effect. 227a86ab640f7bb0bf3cb4eaed80473ca8c5d131903Igor Murashkin * 228b89d88f531ee39927f8f554baaae5ecc9101ba9dMathias Agopian * The width and height parameters must be no greater than the minimum of 229a86ab640f7bb0bf3cb4eaed80473ca8c5d131903Igor Murashkin * GL_MAX_VIEWPORT_DIMS and GL_MAX_TEXTURE_SIZE (see 230b89d88f531ee39927f8f554baaae5ecc9101ba9dMathias Agopian * {@link javax.microedition.khronos.opengles.GL10#glGetIntegerv glGetIntegerv}). 231b89d88f531ee39927f8f554baaae5ecc9101ba9dMathias Agopian * An error due to invalid dimensions might not be reported until 232b89d88f531ee39927f8f554baaae5ecc9101ba9dMathias Agopian * updateTexImage() is called. 233050316184b01c0d1a01c46afae7429b89a27c31btedbo */ 234050316184b01c0d1a01c46afae7429b89a27c31btedbo public void setDefaultBufferSize(int width, int height) { 235050316184b01c0d1a01c46afae7429b89a27c31btedbo nativeSetDefaultBufferSize(width, height); 236050316184b01c0d1a01c46afae7429b89a27c31btedbo } 237050316184b01c0d1a01c46afae7429b89a27c31btedbo 238050316184b01c0d1a01c46afae7429b89a27c31btedbo /** 2396714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis * Update the texture image to the most recent frame from the image stream. This may only be 2402b4bfa5efec7df408b4db127961cfc9aca9e57cfJamie Gennis * called while the OpenGL ES context that owns the texture is current on the calling thread. 2412b4bfa5efec7df408b4db127961cfc9aca9e57cfJamie Gennis * It will implicitly bind its texture to the GL_TEXTURE_EXTERNAL_OES texture target. 2426714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis */ 243376590d668e22a918439877b55faf075427b13f3Jamie Gennis public void updateTexImage() { 24433efb231cb92065c40c019319adae36abc413863Jamie Gennis nativeUpdateTexImage(); 245c6d993077761fc737bbb0f4db44b961a4e7b6bbbJamie Gennis } 246c6d993077761fc737bbb0f4db44b961a4e7b6bbbJamie Gennis 247c6d993077761fc737bbb0f4db44b961a4e7b6bbbJamie Gennis /** 248e591b49de038a9942cbcc77540c03e85c96e3dcbMathias Agopian * Releases the the texture content. This is needed in single buffered mode to allow the image 249e591b49de038a9942cbcc77540c03e85c96e3dcbMathias Agopian * content producer to take ownership of the image buffer. 250cb92a8d9428c2e4a9f038cd5f10e9d61bf265cd4Mathias Agopian * For more information see {@link #SurfaceTexture(int, boolean)}. 251e591b49de038a9942cbcc77540c03e85c96e3dcbMathias Agopian */ 252e591b49de038a9942cbcc77540c03e85c96e3dcbMathias Agopian public void releaseTexImage() { 253e591b49de038a9942cbcc77540c03e85c96e3dcbMathias Agopian nativeReleaseTexImage(); 254e591b49de038a9942cbcc77540c03e85c96e3dcbMathias Agopian } 255e591b49de038a9942cbcc77540c03e85c96e3dcbMathias Agopian 256e591b49de038a9942cbcc77540c03e85c96e3dcbMathias Agopian /** 2572b4bfa5efec7df408b4db127961cfc9aca9e57cfJamie Gennis * Detach the SurfaceTexture from the OpenGL ES context that owns the OpenGL ES texture object. 2582b4bfa5efec7df408b4db127961cfc9aca9e57cfJamie Gennis * This call must be made with the OpenGL ES context current on the calling thread. The OpenGL 2592b4bfa5efec7df408b4db127961cfc9aca9e57cfJamie Gennis * ES texture object will be deleted as a result of this call. After calling this method all 2602b4bfa5efec7df408b4db127961cfc9aca9e57cfJamie Gennis * calls to {@link #updateTexImage} will throw an {@link java.lang.IllegalStateException} until 2612b4bfa5efec7df408b4db127961cfc9aca9e57cfJamie Gennis * a successful call to {@link #attachToGLContext} is made. 2622b4bfa5efec7df408b4db127961cfc9aca9e57cfJamie Gennis * 2632b4bfa5efec7df408b4db127961cfc9aca9e57cfJamie Gennis * This can be used to access the SurfaceTexture image contents from multiple OpenGL ES 2642b4bfa5efec7df408b4db127961cfc9aca9e57cfJamie Gennis * contexts. Note, however, that the image contents are only accessible from one OpenGL ES 2652b4bfa5efec7df408b4db127961cfc9aca9e57cfJamie Gennis * context at a time. 266c6d993077761fc737bbb0f4db44b961a4e7b6bbbJamie Gennis */ 267c6d993077761fc737bbb0f4db44b961a4e7b6bbbJamie Gennis public void detachFromGLContext() { 268c6d993077761fc737bbb0f4db44b961a4e7b6bbbJamie Gennis int err = nativeDetachFromGLContext(); 269c6d993077761fc737bbb0f4db44b961a4e7b6bbbJamie Gennis if (err != 0) { 270c6d993077761fc737bbb0f4db44b961a4e7b6bbbJamie Gennis throw new RuntimeException("Error during detachFromGLContext (see logcat for details)"); 271c6d993077761fc737bbb0f4db44b961a4e7b6bbbJamie Gennis } 272c6d993077761fc737bbb0f4db44b961a4e7b6bbbJamie Gennis } 273c6d993077761fc737bbb0f4db44b961a4e7b6bbbJamie Gennis 274c6d993077761fc737bbb0f4db44b961a4e7b6bbbJamie Gennis /** 2752b4bfa5efec7df408b4db127961cfc9aca9e57cfJamie Gennis * Attach the SurfaceTexture to the OpenGL ES context that is current on the calling thread. A 2762b4bfa5efec7df408b4db127961cfc9aca9e57cfJamie Gennis * new OpenGL ES texture object is created and populated with the SurfaceTexture image frame 2772b4bfa5efec7df408b4db127961cfc9aca9e57cfJamie Gennis * that was current at the time of the last call to {@link #detachFromGLContext}. This new 2782b4bfa5efec7df408b4db127961cfc9aca9e57cfJamie Gennis * texture is bound to the GL_TEXTURE_EXTERNAL_OES texture target. 2792b4bfa5efec7df408b4db127961cfc9aca9e57cfJamie Gennis * 2802b4bfa5efec7df408b4db127961cfc9aca9e57cfJamie Gennis * This can be used to access the SurfaceTexture image contents from multiple OpenGL ES 2812b4bfa5efec7df408b4db127961cfc9aca9e57cfJamie Gennis * contexts. Note, however, that the image contents are only accessible from one OpenGL ES 2822b4bfa5efec7df408b4db127961cfc9aca9e57cfJamie Gennis * context at a time. 2832b4bfa5efec7df408b4db127961cfc9aca9e57cfJamie Gennis * 2842b4bfa5efec7df408b4db127961cfc9aca9e57cfJamie Gennis * @param texName The name of the OpenGL ES texture that will be created. This texture name 2852b4bfa5efec7df408b4db127961cfc9aca9e57cfJamie Gennis * must be unusued in the OpenGL ES context that is current on the calling thread. 286c6d993077761fc737bbb0f4db44b961a4e7b6bbbJamie Gennis */ 287c6d993077761fc737bbb0f4db44b961a4e7b6bbbJamie Gennis public void attachToGLContext(int texName) { 288c6d993077761fc737bbb0f4db44b961a4e7b6bbbJamie Gennis int err = nativeAttachToGLContext(texName); 289c6d993077761fc737bbb0f4db44b961a4e7b6bbbJamie Gennis if (err != 0) { 290425c3da61ad39f5dd4aaba9fd0235f46ff079245Jonathan Dixon throw new RuntimeException("Error during attachToGLContext (see logcat for details)"); 291b89d88f531ee39927f8f554baaae5ecc9101ba9dMathias Agopian } 292376590d668e22a918439877b55faf075427b13f3Jamie Gennis } 293b0ba48c95ea8768a051100c5adb4c906caa1e080Jamie Gennis 294b0ba48c95ea8768a051100c5adb4c906caa1e080Jamie Gennis /** 295b0ba48c95ea8768a051100c5adb4c906caa1e080Jamie Gennis * Retrieve the 4x4 texture coordinate transform matrix associated with the texture image set by 296b0ba48c95ea8768a051100c5adb4c906caa1e080Jamie Gennis * the most recent call to updateTexImage. 297b0ba48c95ea8768a051100c5adb4c906caa1e080Jamie Gennis * 298b0ba48c95ea8768a051100c5adb4c906caa1e080Jamie Gennis * This transform matrix maps 2D homogeneous texture coordinates of the form (s, t, 0, 1) with s 299b0ba48c95ea8768a051100c5adb4c906caa1e080Jamie Gennis * and t in the inclusive range [0, 1] to the texture coordinate that should be used to sample 300b0ba48c95ea8768a051100c5adb4c906caa1e080Jamie Gennis * that location from the texture. Sampling the texture outside of the range of this transform 301b0ba48c95ea8768a051100c5adb4c906caa1e080Jamie Gennis * is undefined. 302b0ba48c95ea8768a051100c5adb4c906caa1e080Jamie Gennis * 303b0ba48c95ea8768a051100c5adb4c906caa1e080Jamie Gennis * The matrix is stored in column-major order so that it may be passed directly to OpenGL ES via 304b0ba48c95ea8768a051100c5adb4c906caa1e080Jamie Gennis * the glLoadMatrixf or glUniformMatrix4fv functions. 305b0ba48c95ea8768a051100c5adb4c906caa1e080Jamie Gennis * 306b0ba48c95ea8768a051100c5adb4c906caa1e080Jamie Gennis * @param mtx the array into which the 4x4 matrix will be stored. The array must have exactly 307b0ba48c95ea8768a051100c5adb4c906caa1e080Jamie Gennis * 16 elements. 308b0ba48c95ea8768a051100c5adb4c906caa1e080Jamie Gennis */ 309b0ba48c95ea8768a051100c5adb4c906caa1e080Jamie Gennis public void getTransformMatrix(float[] mtx) { 310cc562a3576a6a8096626387472e05e8bee03352aGlenn Kasten // Note we intentionally don't check mtx for null, so this will result in a 311cc562a3576a6a8096626387472e05e8bee03352aGlenn Kasten // NullPointerException. But it's safe because it happens before the call to native. 312b0ba48c95ea8768a051100c5adb4c906caa1e080Jamie Gennis if (mtx.length != 16) { 313b0ba48c95ea8768a051100c5adb4c906caa1e080Jamie Gennis throw new IllegalArgumentException(); 314b0ba48c95ea8768a051100c5adb4c906caa1e080Jamie Gennis } 315376590d668e22a918439877b55faf075427b13f3Jamie Gennis nativeGetTransformMatrix(mtx); 316b0ba48c95ea8768a051100c5adb4c906caa1e080Jamie Gennis } 317b0ba48c95ea8768a051100c5adb4c906caa1e080Jamie Gennis 318c5f94d8a4779050125145396ca83fbc862c7ed6bEino-Ville Talvala /** 319c5f94d8a4779050125145396ca83fbc862c7ed6bEino-Ville Talvala * Retrieve the timestamp associated with the texture image set by the most recent call to 320c5f94d8a4779050125145396ca83fbc862c7ed6bEino-Ville Talvala * updateTexImage. 321c5f94d8a4779050125145396ca83fbc862c7ed6bEino-Ville Talvala * 3225c2faf3dc310b100707eb9e32e1e5ae8ceffd0c6Glenn Kasten * This timestamp is in nanoseconds, and is normally monotonically increasing. The timestamp 3235c2faf3dc310b100707eb9e32e1e5ae8ceffd0c6Glenn Kasten * should be unaffected by time-of-day adjustments, and for a camera should be strictly 3245c2faf3dc310b100707eb9e32e1e5ae8ceffd0c6Glenn Kasten * monotonic but for a MediaPlayer may be reset when the position is set. The 325c5f94d8a4779050125145396ca83fbc862c7ed6bEino-Ville Talvala * specific meaning and zero point of the timestamp depends on the source providing images to 326c5f94d8a4779050125145396ca83fbc862c7ed6bEino-Ville Talvala * the SurfaceTexture. Unless otherwise specified by the image source, timestamps cannot 327c5f94d8a4779050125145396ca83fbc862c7ed6bEino-Ville Talvala * generally be compared across SurfaceTexture instances, or across multiple program 328c5f94d8a4779050125145396ca83fbc862c7ed6bEino-Ville Talvala * invocations. It is mostly useful for determining time offsets between subsequent frames. 329c5f94d8a4779050125145396ca83fbc862c7ed6bEino-Ville Talvala */ 3305c2faf3dc310b100707eb9e32e1e5ae8ceffd0c6Glenn Kasten 331c5f94d8a4779050125145396ca83fbc862c7ed6bEino-Ville Talvala public long getTimestamp() { 332c5f94d8a4779050125145396ca83fbc862c7ed6bEino-Ville Talvala return nativeGetTimestamp(); 333c5f94d8a4779050125145396ca83fbc862c7ed6bEino-Ville Talvala } 334c5f94d8a4779050125145396ca83fbc862c7ed6bEino-Ville Talvala 335ec46b4e1ca89d7c3a9ad70ded58da08b5e19f08fMathias Agopian /** 336ec46b4e1ca89d7c3a9ad70ded58da08b5e19f08fMathias Agopian * release() frees all the buffers and puts the SurfaceTexture into the 337ec46b4e1ca89d7c3a9ad70ded58da08b5e19f08fMathias Agopian * 'abandoned' state. Once put in this state the SurfaceTexture can never 338ec46b4e1ca89d7c3a9ad70ded58da08b5e19f08fMathias Agopian * leave it. When in the 'abandoned' state, all methods of the 339d47f7d8b5fe3a3861d7cbdc5f912235407823c8eAndy McFadden * IGraphicBufferProducer interface will fail with the NO_INIT error. 340ec46b4e1ca89d7c3a9ad70ded58da08b5e19f08fMathias Agopian * 341ec46b4e1ca89d7c3a9ad70ded58da08b5e19f08fMathias Agopian * Note that while calling this method causes all the buffers to be freed 342ec46b4e1ca89d7c3a9ad70ded58da08b5e19f08fMathias Agopian * from the perspective of the the SurfaceTexture, if there are additional 343ec46b4e1ca89d7c3a9ad70ded58da08b5e19f08fMathias Agopian * references on the buffers (e.g. if a buffer is referenced by a client or 344ec46b4e1ca89d7c3a9ad70ded58da08b5e19f08fMathias Agopian * by OpenGL ES as a texture) then those buffer will remain allocated. 345ec46b4e1ca89d7c3a9ad70ded58da08b5e19f08fMathias Agopian * 346ec46b4e1ca89d7c3a9ad70ded58da08b5e19f08fMathias Agopian * Always call this method when you are done with SurfaceTexture. Failing 347ec46b4e1ca89d7c3a9ad70ded58da08b5e19f08fMathias Agopian * to do so may delay resource deallocation for a significant amount of 348ec46b4e1ca89d7c3a9ad70ded58da08b5e19f08fMathias Agopian * time. 349ec46b4e1ca89d7c3a9ad70ded58da08b5e19f08fMathias Agopian */ 350ec46b4e1ca89d7c3a9ad70ded58da08b5e19f08fMathias Agopian public void release() { 351ec46b4e1ca89d7c3a9ad70ded58da08b5e19f08fMathias Agopian nativeRelease(); 352ec46b4e1ca89d7c3a9ad70ded58da08b5e19f08fMathias Agopian } 353ec46b4e1ca89d7c3a9ad70ded58da08b5e19f08fMathias Agopian 3546d8371e73ff6452be5a23089e7edeb8d6d96f065John Reck /** 3556d8371e73ff6452be5a23089e7edeb8d6d96f065John Reck * Returns true if the SurfaceTexture was released 3566d8371e73ff6452be5a23089e7edeb8d6d96f065John Reck * @hide 3576d8371e73ff6452be5a23089e7edeb8d6d96f065John Reck */ 3586d8371e73ff6452be5a23089e7edeb8d6d96f065John Reck public boolean isReleased() { 3596d8371e73ff6452be5a23089e7edeb8d6d96f065John Reck return nativeIsReleased(); 3606d8371e73ff6452be5a23089e7edeb8d6d96f065John Reck } 3616d8371e73ff6452be5a23089e7edeb8d6d96f065John Reck 362a86ab640f7bb0bf3cb4eaed80473ca8c5d131903Igor Murashkin @Override 363376590d668e22a918439877b55faf075427b13f3Jamie Gennis protected void finalize() throws Throwable { 364376590d668e22a918439877b55faf075427b13f3Jamie Gennis try { 365376590d668e22a918439877b55faf075427b13f3Jamie Gennis nativeFinalize(); 366376590d668e22a918439877b55faf075427b13f3Jamie Gennis } finally { 367376590d668e22a918439877b55faf075427b13f3Jamie Gennis super.finalize(); 368376590d668e22a918439877b55faf075427b13f3Jamie Gennis } 369376590d668e22a918439877b55faf075427b13f3Jamie Gennis } 370376590d668e22a918439877b55faf075427b13f3Jamie Gennis 3718f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy /** 3728f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy * This method is invoked from native code only. 3738f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy */ 3748f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy @SuppressWarnings({"UnusedDeclaration"}) 375c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown private static void postEventFromNative(WeakReference<SurfaceTexture> weakSelf) { 376c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown SurfaceTexture st = weakSelf.get(); 377c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown if (st != null) { 378c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown Handler handler = st.mOnFrameAvailableHandler; 379c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown if (handler != null) { 380c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown handler.sendEmptyMessage(0); 381c7282e57cd01f1576baac04356bf99bee34e4c18Jeff Brown } 382e591b49de038a9942cbcc77540c03e85c96e3dcbMathias Agopian } 383e591b49de038a9942cbcc77540c03e85c96e3dcbMathias Agopian } 384e591b49de038a9942cbcc77540c03e85c96e3dcbMathias Agopian 385aff2f949395725f4bb82802bd12201b65d514e68Pablo Ceballos /** 386aff2f949395725f4bb82802bd12201b65d514e68Pablo Ceballos * Returns true if the SurfaceTexture is single-buffered 387aff2f949395725f4bb82802bd12201b65d514e68Pablo Ceballos * @hide 388aff2f949395725f4bb82802bd12201b65d514e68Pablo Ceballos */ 389aff2f949395725f4bb82802bd12201b65d514e68Pablo Ceballos public boolean isSingleBuffered() { 390aff2f949395725f4bb82802bd12201b65d514e68Pablo Ceballos return mIsSingleBuffered; 391aff2f949395725f4bb82802bd12201b65d514e68Pablo Ceballos } 392aff2f949395725f4bb82802bd12201b65d514e68Pablo Ceballos 393493f2e11909e2d5839ca81ddc66d48d538192478Dan Stoza private native void nativeInit(boolean isDetached, int texName, 394493f2e11909e2d5839ca81ddc66d48d538192478Dan Stoza boolean singleBufferMode, WeakReference<SurfaceTexture> weakSelf) 395a86ab640f7bb0bf3cb4eaed80473ca8c5d131903Igor Murashkin throws Surface.OutOfResourcesException; 396376590d668e22a918439877b55faf075427b13f3Jamie Gennis private native void nativeFinalize(); 397376590d668e22a918439877b55faf075427b13f3Jamie Gennis private native void nativeGetTransformMatrix(float[] mtx); 398c5f94d8a4779050125145396ca83fbc862c7ed6bEino-Ville Talvala private native long nativeGetTimestamp(); 399050316184b01c0d1a01c46afae7429b89a27c31btedbo private native void nativeSetDefaultBufferSize(int width, int height); 4002b4bfa5efec7df408b4db127961cfc9aca9e57cfJamie Gennis private native void nativeUpdateTexImage(); 401e591b49de038a9942cbcc77540c03e85c96e3dcbMathias Agopian private native void nativeReleaseTexImage(); 402c6d993077761fc737bbb0f4db44b961a4e7b6bbbJamie Gennis private native int nativeDetachFromGLContext(); 403c6d993077761fc737bbb0f4db44b961a4e7b6bbbJamie Gennis private native int nativeAttachToGLContext(int texName); 404925bcaabde5a21687b51caa7ab329310a819f068Grace Kloba private native int nativeGetQueuedCount(); 405ec46b4e1ca89d7c3a9ad70ded58da08b5e19f08fMathias Agopian private native void nativeRelease(); 4066d8371e73ff6452be5a23089e7edeb8d6d96f065John Reck private native boolean nativeIsReleased(); 4076714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis 4086714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis /* 4096714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis * We use a class initializer to allow the native code to cache some 4106714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis * field offsets. 4116714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis */ 4126714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis private static native void nativeClassInit(); 4136714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis static { nativeClassInit(); } 4146714efc5e0c52953b65e774de0003e22377e7d39Jamie Gennis} 415