summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/util/avcomp.h
blob: fde94957a009cbb7cf93f79a2422229eb2ae04ae (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
/***************************************************************************

    avcomp.h

    Audio/video compression and decompression helpers.

****************************************************************************

    Copyright Aaron Giles
    All rights reserved.

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are 
    met:

        * Redistributions of source code must retain the above copyright
          notice, this list of conditions and the following disclaimer.
        * Redistributions in binary form must reproduce the above copyright
          notice, this list of conditions and the following disclaimer in 
          the documentation and/or other materials provided with the 
          distribution.
        * Neither the name 'MAME' nor the names of its contributors may be 
          used to endorse or promote products derived from this software 
          without specific prior written permission.

    THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR 
    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT, 
    INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
    STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
    IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
    POSSIBILITY OF SUCH DAMAGE.

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

#ifndef __AVCOMP_H__
#define __AVCOMP_H__

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


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

/* errors */
enum _avcomp_error
{
	AVCERR_NONE = 0,
	AVCERR_INVALID_DATA,
	AVCERR_VIDEO_TOO_LARGE,
	AVCERR_AUDIO_TOO_LARGE,
	AVCERR_METADATA_TOO_LARGE,
	AVCERR_OUT_OF_MEMORY,
	AVCERR_COMPRESSION_ERROR,
	AVCERR_TOO_MANY_CHANNELS,
	AVCERR_INVALID_CONFIGURATION
};
typedef enum _avcomp_error avcomp_error;

/* default decompression parameters */
#define AVCOMP_ENABLE_META					(1 << 0)
#define AVCOMP_ENABLE_VIDEO					(1 << 1)
#define AVCOMP_ENABLE_AUDIO(x)				(1 << (2 + (x)))
#define AVCOMP_ENABLE_DEFAULT				(~0)



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

/* compression configuration */
typedef struct _av_codec_compress_config av_codec_compress_config;
struct _av_codec_compress_config
{
	bitmap_t *	video;						/* pointer to video bitmap */
	UINT32		channels;					/* number of channels */
	UINT32		samples;					/* number of samples per channel */
	INT16 *		audio[16];					/* pointer to individual audio channels */
	UINT32		metalength;					/* length of metadata */
	UINT8 *		metadata;					/* pointer to metadata buffer */
};


/* decompression configuration */
typedef struct _av_codec_decompress_config av_codec_decompress_config;
struct _av_codec_decompress_config
{
	bitmap_t *	video;						/* pointer to video bitmap */
	UINT32		maxsamples;					/* maximum number of samples per channel */
	UINT32 *	actsamples;					/* actual number of samples per channel */
	INT16 *		audio[16];					/* pointer to individual audio channels */
	UINT32		maxmetalength;				/* maximum length of metadata */
	UINT32 *	actmetalength;				/* actual length of metadata */
	UINT8 *		metadata;					/* pointer to metadata buffer */
};


/* opaque state */
typedef struct _avcomp_state avcomp_state;



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

avcomp_state *avcomp_init(UINT32 maxwidth, UINT32 maxheight, UINT32 maxchannels);
void avcomp_free(avcomp_state *state);

void avcomp_config_compress(avcomp_state *state, const av_codec_compress_config *config);
void avcomp_config_decompress(avcomp_state *state, const av_codec_decompress_config *config);

avcomp_error avcomp_encode_data(avcomp_state *state, const UINT8 *source, UINT8 *dest, UINT32 *complength);
avcomp_error avcomp_decode_data(avcomp_state *state, const UINT8 *source, UINT32 complength, UINT8 *dest);

#endif