
// 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 MP3READER_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 
// MP3READER_API functions as being imported from a DLL, wheras this DLL sees symbols
// defined with this macro as being exported.
#ifdef MP3READER_EXPORTS
#define MP3READER_API __declspec(dllexport)
#else
#define MP3READER_API __declspec(dllimport)
#endif


// This class is exported from the MP3Reader.dll
class MP3READER_API CMP3Reader {
public:
	CMP3Reader(void);
	// TODO: add your methods here.
};


#define AVI_MAX_LEN 2000000000
#define HEADERBYTES 2048
#define PAD_EVEN(x) ( ((x)+1) & ~1 )
#define AVIIF_KEYFRAME	0x00000010L

/*
 * INDEX TYPES
 */

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

} video_index_entry;

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

} audio_index_entry;

//enum {
//
//	INPUT_TYPE_FILE,INPUT_TYPE_CACHEFILE,
//	INPUT_TYPE_HTTP
//};

/*
 * File mode enum
 */

//enum {
//
//	INPUT_OPEN_ASCII,
//	INPUT_OPEN_BINARY
//};

/*
 * 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];
} videoinfo;
  

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

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

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

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;

}reader;


	int MP3Reader_IsAVI();
	int MP3Reader_FillHeader(int getIndex);
	int MP3Reader_AddIndexEntry(char *tag, 
			          long flags, 
			          long pos, 
			          long len);
	BOOL MP3Reader_isKeyframe(long frame);

	int               MP3Reader_VideoSeek(long frame);
	int               MP3Reader_AudioSeek(long bytes);

	int               MP3Reader_NextKeyFrame();
	int				  MP3Reader_PreviousKeyFrame();


	int               MP3Reader_SampleSize();

	int MP3Reader_Rewind();

	MP3READER_API double MP3Reader_GetProgress();

	MP3READER_API int MP3Reader_Close();
	MP3READER_API int MP3Reader_ReadAudio(char *audbuf, int bytes);


	MP3READER_API int              MP3Reader_Open(LPTSTR lpFilename, int type, int maxsize,videoinfo** info);
	MP3READER_API double            MP3Reader_FrameRate();
	MP3READER_API int               MP3Reader_NextVideoFrame(char *buffer, int drop);


	MP3READER_API int              MP3Reader_Seek(int percent,int isFrame);
	MP3READER_API int               MP3Reader_ReSeekAudio();
