summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/util/aviio.h
blob: 41f9eba826d057ad890cc2eaa7fd67099841227c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/***************************************************************************

    aviio.h

    AVI movie format parsing helpers.

    Copyright (c) 1996-2007, Nicola Salmoria and the MAME Team.
    Visit http://mamedev.org for licensing and usage restrictions.

***************************************************************************/

#ifndef __AVIIO_H__

#include "osdcore.h"
#include "bitmap.h"


/***************************************************************************
    CONSTANTS
***************************************************************************/

enum _avi_error
{
	AVIERR_NONE = 0,
	AVIERR_END,
	AVIERR_INVALID_DATA,
	AVIERR_NO_MEMORY,
	AVIERR_READ_ERROR,
	AVIERR_WRITE_ERROR,
	AVIERR_STACK_TOO_DEEP,
	AVIERR_UNSUPPORTED_FEATURE,
	AVIERR_CANT_OPEN_FILE,
	AVIERR_INCOMPATIBLE_AUDIO_STREAMS,
	AVIERR_INVALID_SAMPLERATE,
	AVIERR_INVALID_STREAM,
	AVIERR_INVALID_FRAME,
	AVIERR_INVALID_BITMAP,
	AVIERR_UNSUPPORTED_VIDEO_FORMAT,
	AVIERR_UNSUPPORTED_AUDIO_FORMAT,
	AVIERR_EXCEEDED_SOUND_BUFFER
};
typedef enum _avi_error avi_error;


enum _avi_datatype
{
	AVIDATA_VIDEO,
	AVIDATA_AUDIO_CHAN0,
	AVIDATA_AUDIO_CHAN1,
	AVIDATA_AUDIO_CHAN2,
	AVIDATA_AUDIO_CHAN3,
	AVIDATA_AUDIO_CHAN4,
	AVIDATA_AUDIO_CHAN5,
	AVIDATA_AUDIO_CHAN6,
	AVIDATA_AUDIO_CHAN7
};
typedef enum _avi_datatype avi_datatype;



/***************************************************************************
    MACROS
***************************************************************************/

#define AVI_FOURCC(a,b,c,d)		((a) | ((b) << 8) | ((c) << 16) | ((d) << 24))

#define FORMAT_UYVY				AVI_FOURCC('U','Y','V','Y')
#define FORMAT_VYUY				AVI_FOURCC('V','Y','U','Y')
#define FORMAT_YUY2				AVI_FOURCC('Y','U','Y','2')
#define FORMAT_HFYU				AVI_FOURCC('H','F','Y','U')



/***************************************************************************
    TYPE DEFINITIONS
***************************************************************************/

typedef struct _avi_file avi_file;


typedef struct _avi_movie_info avi_movie_info;
struct _avi_movie_info
{
	UINT32			video_format;				/* format of video data */
	UINT32			video_timescale;			/* timescale for video data */
	UINT32			video_sampletime;			/* duration of a single video sample (frame) */
	UINT32			video_numsamples;			/* total number of video samples */
	UINT32			video_width;				/* width of the video */
	UINT32			video_height;				/* height of the video */
	UINT32			video_depth;				/* depth of the video */

	UINT32			audio_format;				/* format of audio data */
	UINT32			audio_timescale;			/* timescale for audio data */
	UINT32			audio_sampletime;			/* duration of a single audio sample */
	UINT32			audio_numsamples;			/* total number of audio samples */
	UINT32			audio_channels;				/* number of audio channels */
	UINT32			audio_samplebits;			/* number of bits per channel */
	UINT32			audio_samplerate;			/* sample rate of audio */
};



/***************************************************************************
    PROTOTYPES
***************************************************************************/

avi_error avi_open(const char *filename, avi_file **file);
avi_error avi_create(const char *filename, const avi_movie_info *info, avi_file **file);
avi_error avi_close(avi_file *file);

void avi_printf_chunks(avi_file *file);
const char *avi_error_string(avi_error err);

const avi_movie_info *avi_get_movie_info(avi_file *file);
UINT32 avi_first_sample_in_frame(avi_file *file, UINT32 framenum);

avi_error avi_read_video_frame_yuy16(avi_file *file, UINT32 framenum, bitmap_t *bitmap);
avi_error avi_read_sound_samples(avi_file *file, int channel, UINT32 firstsample, UINT32 numsamples, INT16 *output);

avi_error avi_append_video_frame_yuy16(avi_file *file, const bitmap_t *bitmap);
avi_error avi_append_sound_samples(avi_file *file, int channel, const INT16 *samples, UINT32 numsamples);

#endif