I am working on an Android camera application that changes the camera channel and displays it on the screen. I work and do what I want on my DROID RAZR MAXX with 4.3, and it works fine on other phones, but, unfortunately, I had a problem with several phones, and I canโt track the problem.
I have attached a screenshot showing what the problem is.

It is very difficult to say what green "artifacts" are, but it almost seems that they are blocked from the camera from the moment it was first turned on. Colors flicker, but the shapes inside the blocks do not change.
I deleted everything that you donโt need and cleared the code as best as possible, but I honestly donโt know why this happens, especially since it works fine on some phones, while other phones donโt.
If I need to give more information just for comment, and I will add it!
CameraActivity.java
public class CameraActivity extends Activity { private MyGLSurfaceView glSurfaceView; private MyCamera mCamera; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mCamera = new MyCamera(); glSurfaceView = new MyGLSurfaceView(this, mCamera); setContentView(glSurfaceView); } @Override protected void onPause() { super.onPause(); mCamera.stop(); } }
MyCamera.java
public class MyCamera { private final static String LOG_TAG = "MyCamera"; private Camera mCamera; private Parameters mCameraParams; private Boolean running = false; void start(SurfaceTexture surface) { Log.v(LOG_TAG, "Starting Camera"); mCamera = Camera.open(0); mCameraParams = mCamera.getParameters(); Log.v(LOG_TAG, mCameraParams.getPreviewSize().width + " x " + mCameraParams.getPreviewSize().height); try { mCamera.setPreviewTexture(surface); mCamera.startPreview(); running = true; } catch (IOException e) { e.printStackTrace(); } } void stop() { if (running) { Log.v(LOG_TAG, "Stopping Camera"); mCamera.stopPreview(); mCamera.release(); running = false; } } }
MyGLSurfaceView.java
class MyGLSurfaceView extends GLSurfaceView implements Renderer { private final static String LOG_TAG = "MyGLSurfaceView"; private MyCamera mCamera; private SurfaceTexture mSurface; private DirectVideo mDirectVideo; public MyGLSurfaceView(Context context, MyCamera camera) { super(context); mCamera = camera; setEGLContextClientVersion(2); setRenderer(this); } @Override public void onDrawFrame(GL10 gl) { float[] mtx = new float[16]; mSurface.updateTexImage(); mSurface.getTransformMatrix(mtx); mDirectVideo.draw(); } @Override public void onSurfaceChanged(GL10 gl, int width, int height) { Log.v(LOG_TAG, "Surface Changed"); GLES20.glViewport(0, 0, width, height); } @Override public void onSurfaceCreated(GL10 gl, EGLConfig config) { Log.v(LOG_TAG, "Surface Created"); int texture = createTexture(); mDirectVideo = new DirectVideo(texture); mSurface = new SurfaceTexture(texture); mCamera.start(mSurface); } private int createTexture() { int[] textures = new int[1];
DirectVideo.java
public class DirectVideo { private final String vertexShaderCode = "attribute vec4 vPosition;" + "attribute vec2 inputTextureCoordinate;" + "varying vec2 textureCoordinate;" + "void main()" + "{"+ "gl_Position = vPosition;"+ "textureCoordinate = inputTextureCoordinate;" + "}"; private final String fragmentShaderCode = "#extension GL_OES_EGL_image_external : require\n"+ "precision mediump float;" + "varying vec2 textureCoordinate;\n" + "uniform samplerExternalOES s_texture;\n" + "void main() {" + " gl_FragColor = texture2D( s_texture, textureCoordinate );\n" + "}"; private FloatBuffer vertexBuffer, textureVerticesBuffer; private ShortBuffer drawListBuffer; private final int mProgram; private int mPositionHandle; private int mTextureCoordHandle; private short drawOrder[] = { 0, 1, 2, 0, 2, 3 };