
// The following ifdef block is the standard way of creating macros which make exporting 
// from a DLL simpler. All files within this DLL are compiled with the AVISTREAM_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see 
// AVISTREAM_API functions as being imported from a DLL, wheras this DLL sees symbols
// defined with this macro as being exported.
#ifdef AVISTREAM_EXPORTS
#define AVISTREAM_API __declspec(dllexport)
#else
#define AVISTREAM_API __declspec(dllimport)
#endif

// This class is exported from the AVIStream.dll
class AVISTREAM_API CAVIStream {
public:
	CAVIStream(void);
	// TODO: add your methods here.
};

#ifdef __cplusplus
extern "C" {
#endif 

#ifndef AVI_DECAPS_H
#define AVI_DECAPS_H

/*
 * includes
 */
#include <windows.h>
#include <windowsx.h>
#include <malloc.h>
#include <stdlib.h>

/*
 * SOME USEFUL MACROS
 */

#define PAD_EVEN(x) ( ((x)+1) & ~1 )
#define AVIIF_KEYFRAME	0x00000010L

/*
 * INDEX TYPES
 */

typedef struct
{
  long pos;
  long len;
  long flags;

} video_index_entry;

typedef struct
{
   long pos;
   long len;
   long tot;

} audio_index_entry;

/*
 * Seek Enum
 */

enum {

	INPUT_SEEK_SET,
	INPUT_SEEK_CUR,
	INPUT_SEEK_END
};

/*
 * Main Class
 */

typedef struct _videoinfo
{
    long               width;             
    long               height;            
    double             fps;               
    char               compressor[8];     
    long               video_strn;        
    long               video_frames;      
    char               video_tag[4];      
    long               video_pos;         
    long               a_fmt;             
    long               a_chans;           
    long               a_rate;            
    long               a_bits;            

    long               audio_strn;        
    long               audio_bytes;       
    long               audio_chunks;      
    char               audio_tag[4];      
    long               audio_posc;        
    long               audio_posb;        
    long               pos;               
    long               n_idx;             
    long               max_idx;           
    char               (*idx)[16]; 
    video_index_entry *video_index;
    audio_index_entry *audio_index;
    long               last_pos;          
    long               last_len;          
    long               movi_start;

	HANDLE             hIOMutex;
	TCHAR				m_lpFilename[200];
	int					m_type;
	int					threshhold;
	int					AFAP;
	int					ChapterCount;
	TCHAR				ChapterDisplay[100][50];
	video_index_entry	currentframe;
	audio_index_entry	currentchunk;
} videoinfo;



typedef int (CALLBACK* pREADER_Open)(LPTSTR lpFilename, int type, int size,videoinfo** info);

typedef int (CALLBACK* pREADER_ReadAudio)(char *audbuf, int bytes);

typedef int (CALLBACK* pREADER_NextVideoFrame)(char *buffer,int drop);

typedef BOOL (CALLBACK* pREADER_isKeyFrame)(long frame);

typedef int (CALLBACK* pREADER_Seek)(int percent, int isFrame);

typedef int (CALLBACK* pREADER_ReSeekAudio)();

typedef double (CALLBACK* pREADER_GetProgress)();

typedef int (CALLBACK* pREADER_Close)();



typedef struct _reader
{
	pREADER_Open READER_Open;
	pREADER_ReadAudio READER_ReadAudio;
	pREADER_NextVideoFrame READER_NextVideoFrame;
	pREADER_Seek READER_Seek;
	pREADER_ReSeekAudio READER_ReSeekAudio;
	pREADER_GetProgress READER_GetProgress;
	pREADER_Close READER_Close;
	pREADER_isKeyFrame READER_isKeyFrame;

}reader;


    

	int AVIDecaps_IsAVI();
	int AVIDecaps_FillHeader(int getIndex);
	int AVIDecaps_AddIndexEntry(char *tag, 
			          long flags, 
			          long pos, 
			          long len);
	BOOL AVIDecaps_isKeyframe(long frame);
	AVISTREAM_API int AVIDecaps_ReadAudio(char *audbuf, int bytes);


	AVISTREAM_API int               AVIDecaps_Open(LPTSTR lpFilename, int type, int size,videoinfo** info);
	AVISTREAM_API double            AVIDecaps_FrameRate();
	AVISTREAM_API int               AVIDecaps_NextVideoFrame(char *buffer,int drop);

	int               AVIDecaps_VideoSeek(long frame);
	int               AVIDecaps_AudioSeek(long bytes);

	int               AVIDecaps_NextKeyFrame();
	int				  AVIDecaps_PreviousKeyFrame();

	AVISTREAM_API int               AVIDecaps_Seek(int percent, int isFrame);
	AVISTREAM_API int               AVIDecaps_ReSeekAudio();

	int               AVIDecaps_SampleSize();

	AVISTREAM_API int AVIDecaps_Rewind();

	AVISTREAM_API double AVIDecaps_GetProgress();

	AVISTREAM_API int AVIDecaps_Close();
	AVISTREAM_API void InitializeReader(reader* rd);

#endif
#ifdef __cplusplus
}
#endif 
