#pragma once


extern "C" {
JNIEXPORT jobject JNICALL Java_ips_media_jnm_impl_directshow_DSMediaCapture_init(JNIEnv *, jobject);
//JNIEXPORT void JNICALL Java_ips_media_jnm_impl_directshow_DSMediaCapture_setAudioRenderer(JNIEnv *, jobject,jobject,jobject);
JNIEXPORT void JNICALL Java_ips_media_jnm_impl_directshow_DSMediaCapture_buildGraph(JNIEnv *, jobject,jobject,jobject);
//JNIEXPORT void JNICALL Java_ips_media_jnm_impl_directshow_DSMediaCapture_setVideoCanvasSize(JNIEnv *, jobject,jobject,jint,jint);
JNIEXPORT void JNICALL Java_ips_media_jnm_impl_directshow_DSMediaCapture_open(JNIEnv *, jobject,jobject,jstring);

JNIEXPORT jboolean JNICALL Java_ips_media_jnm_impl_directshow_DSMediaCapture_start(JNIEnv *, jobject,jobject);
JNIEXPORT jboolean JNICALL Java_ips_media_jnm_impl_directshow_DSMediaCapture_stop(JNIEnv *, jobject,jobject);
JNIEXPORT void JNICALL Java_ips_media_jnm_impl_directshow_DSMediaCapture_close(JNIEnv *, jobject,jobject);

JNIEXPORT void JNICALL Java_ips_media_jnm_impl_directshow_DSMediaCapture_release(JNIEnv *, jobject,jobject);
}
class DSMediaCapture
{
private:
	JavaVM *javaVm;
	jweak objRef;
	jweak imgArrRef;
	jweak renderMethodRef;
	int width;
	int height;
	int pixelStride;
	jbyte *lineBuffer;

	
IGraphBuilder *pGraph;
IMediaControl *pControl;
IMediaEvent   *pEvent;

IVMRWindowlessControl9 *pWc;

HANDLE hEvent;
CCritSec* cCritSec;
HWND hwndAWT;

IBasicVideo *iBv;
LONGLONG byteLength;
LONGLONG available;
DWORD_PTR dwUserTest;
volatile boolean flushing;
volatile int c;
volatile DWORD renderThreadID;
JNIEnv* renderEnv;
char jRenderThreadName[65];
JavaVMAttachArgs thr_args;

public:
DSMediaCapture(JavaVM*,jweak);
//void DSMediaCapture::getAWTSurface(JNIEnv*,jobject);
//void setAudioRenderer(JAudioRenderer *);
//void setVideoCanvasSize(jint,jint);
//HRESULT buildGraph();
HRESULT open(LPCWSTR);
boolean start();
boolean stop();
void close();

void setVideoSize(GUID,int w,int h);
void rendered(BYTE *,long);
void release(JNIEnv *);
	~DSMediaCapture(void);
};
