/*******************************************************************
              MPEG-2 VIDEO stream read interface
 *******************************************************************/

#ifndef VIDEO_STREAM_H
#define VIDEO_STREAM_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define VIDEO_STREAM_BUFFER_SIZE 512*1024
#define VIDEO_STREAM_BUFFER_SPARE 7
	
typedef struct {
	char           path[FILENAME_MAX];
	int            fd;
	__int64        file_position;
	__int64        file_length;

	unsigned char  buffer[VIDEO_STREAM_BUFFER_SPARE+VIDEO_STREAM_BUFFER_SIZE];
	unsigned char *current;
	int            buffer_size;

	unsigned int   bits;
	int            bits_rest;
} VIDEO_STREAM;

#ifdef __cplusplus
extern "C" {
#endif

#ifndef VIDEO_STREAM_C
extern int open_video_stream(char *path, VIDEO_STREAM *out);
extern int close_video_stream(VIDEO_STREAM *p);
extern int get_bits(VIDEO_STREAM *in, int num_of_bits);
extern int read_bits(VIDEO_STREAM *in, int num_of_bits);
extern int erase_bits(VIDEO_STREAM *in, int num_of_bits);
extern int next_start_code(VIDEO_STREAM *in);
extern __int64 video_stream_tell(VIDEO_STREAM *p);
extern __int64 video_stream_seek(VIDEO_STREAM *p, __int64 offset, int origin);
#endif;

#ifdef __cplusplus
}
#endif

#endif
