/*******************************************************************
              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 {
	int  fd;
	char path[FILENAME_MAX];
	size_t file_position;
	size_t 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 size_t video_stream_tell(VIDEO_STREAM *p);
extern size_t video_stream_seek(VIDEO_STREAM *p, long offset, int origin);
#endif;

#ifdef __cplusplus
}
#endif

#endif
