// Path: videffects/src/main/java/com/sherazkhilji/videffects/interfaces/ConvertResultListener.java
// public interface ConvertResultListener {
// 
//     void onSuccess();
// 
//     void onFail();
// }
// 
// Path: videffects/src/main/java/com/sherazkhilji/videffects/interfaces/Filter.java
// public interface Filter {
// 
// 	public String getVertexShader();
// 
// 	public String getFragmentShader();
// 
// 	public void setIntensity(float intensity);
// }


import android.graphics.SurfaceTexture;
import android.media.MediaCodec;
import android.media.MediaCodecInfo;
import android.media.MediaCodecList;
import android.media.MediaExtractor;
import android.media.MediaFormat;
import android.media.MediaMuxer;
import android.opengl.EGL14;
import android.opengl.EGLConfig;
import android.opengl.EGLContext;
import android.opengl.EGLDisplay;
import android.opengl.EGLExt;
import android.opengl.EGLSurface;
import android.opengl.GLUtils;
import android.os.Build;
import android.os.Handler;
import android.os.HandlerThread;
import android.util.Log;
import android.view.Surface;
import androidx.annotation.RequiresApi;
import com.sherazkhilji.videffects.interfaces.ConvertResultListener;
import com.sherazkhilji.videffects.interfaces.Filter;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.concurrent.TimeUnit;
import static android.media.MediaCodec.BUFFER_FLAG_END_OF_STREAM;
import static android.opengl.EGLExt.EGL_RECORDABLE_ANDROID;
    private long mediaCodedTimeoutUs = 1000L;
    private final Object lock = new Object();
    private volatile boolean frameAvailable = false;

    private EGLDisplay eglDisplay = null;
    private EGLContext eglContext = null;
    private EGLSurface eglSurface = null;

    public Converter() {

    }

    public Converter(String path) {
        setMetadata(path);
        try {
            videoExtractor.setDataSource(path);
            audioExtractor.setDataSource(path);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private void setMetadata(String path) {
        Metadata metadata = new MetadataExtractor().extract(path);
        if (metadata != null) {
            width = (int) metadata.getWidth();
            height = (int) metadata.getHeight();
            bitrate = metadata.getBitrate();
        }
    }
// Path: videffects/src/main/java/com/sherazkhilji/videffects/interfaces/ConvertResultListener.java
// public interface ConvertResultListener {
// 
//     void onSuccess();
// 
//     void onFail();
// }
// 
// Path: videffects/src/main/java/com/sherazkhilji/videffects/interfaces/Filter.java
// public interface Filter {
// 
// 	public String getVertexShader();
// 
// 	public String getFragmentShader();
// 
// 	public void setIntensity(float intensity);
// }


// Path: videffects/src/main/java/com/sherazkhilji/videffects/model/Converter.java
import android.graphics.SurfaceTexture;
import android.media.MediaCodec;
import android.media.MediaCodecInfo;
import android.media.MediaCodecList;
import android.media.MediaExtractor;
import android.media.MediaFormat;
import android.media.MediaMuxer;
import android.opengl.EGL14;
import android.opengl.EGLConfig;
import android.opengl.EGLContext;
import android.opengl.EGLDisplay;
import android.opengl.EGLExt;
import android.opengl.EGLSurface;
import android.opengl.GLUtils;
import android.os.Build;
import android.os.Handler;
import android.os.HandlerThread;
import android.util.Log;
import android.view.Surface;
import androidx.annotation.RequiresApi;
import com.sherazkhilji.videffects.interfaces.ConvertResultListener;
import com.sherazkhilji.videffects.interfaces.Filter;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.concurrent.TimeUnit;
import static android.media.MediaCodec.BUFFER_FLAG_END_OF_STREAM;
import static android.opengl.EGLExt.EGL_RECORDABLE_ANDROID;

    private long mediaCodedTimeoutUs = 1000L;
    private final Object lock = new Object();
    private volatile boolean frameAvailable = false;

    private EGLDisplay eglDisplay = null;
    private EGLContext eglContext = null;
    private EGLSurface eglSurface = null;

    public Converter() {

    }

    public Converter(String path) {
        setMetadata(path);
        try {
            videoExtractor.setDataSource(path);
            audioExtractor.setDataSource(path);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private void setMetadata(String path) {
        Metadata metadata = new MetadataExtractor().extract(path);
        if (metadata != null) {
            width = (int) metadata.getWidth();
            height = (int) metadata.getHeight();
            bitrate = metadata.getBitrate();
        }
    }
    public void startConverter(Filter filter, String outPath, ConvertResultListener listener) {