~ubuntu-branches/debian/sid/mame/sid

« back to all changes in this revision

Viewing changes to src/lib/util/avhuff.h

  • Committer: Package Import Robot
  • Author(s): Jordi Mallach, Emmanuel Kasper, Jordi Mallach
  • Date: 2012-06-05 20:02:23 UTC
  • mfrom: (0.3.1) (0.1.4)
  • Revision ID: package-import@ubuntu.com-20120605200223-gnlpogjrg6oqe9md
Tags: 0.146-1
[ Emmanuel Kasper ]
* New upstream release
* Drop patch to fix man pages section and patches to link with flac 
  and jpeg system lib: all this has been pushed upstream by Cesare Falco
* Add DM-Upload-Allowed: yes field.

[ Jordi Mallach ]
* Create a "gnu" TARGETOS stanza that defines NO_AFFINITY_NP.
* Stop setting TARGETOS to "unix" in d/rules. It should be autodetected,
  and set to the appropriate value.
* mame_manpage_section.patch: Change mame's manpage section to 6 (games),
  in the TH declaration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 
 
3
    avhuff.h
 
4
 
 
5
    Audio/video compression and decompression helpers.
 
6
 
 
7
****************************************************************************
 
8
 
 
9
    Copyright Aaron Giles
 
10
    All rights reserved.
 
11
 
 
12
    Redistribution and use in source and binary forms, with or without
 
13
    modification, are permitted provided that the following conditions are
 
14
    met:
 
15
 
 
16
        * Redistributions of source code must retain the above copyright
 
17
          notice, this list of conditions and the following disclaimer.
 
18
        * Redistributions in binary form must reproduce the above copyright
 
19
          notice, this list of conditions and the following disclaimer in
 
20
          the documentation and/or other materials provided with the
 
21
          distribution.
 
22
        * Neither the name 'MAME' nor the names of its contributors may be
 
23
          used to endorse or promote products derived from this software
 
24
          without specific prior written permission.
 
25
 
 
26
    THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR
 
27
    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 
28
    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 
29
    DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT,
 
30
    INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 
31
    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 
32
    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 
33
    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 
34
    STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 
35
    IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 
36
    POSSIBILITY OF SUCH DAMAGE.
 
37
 
 
38
***************************************************************************/
 
39
 
 
40
#pragma once
 
41
 
 
42
#ifndef __AVHUFF_H__
 
43
#define __AVHUFF_H__
 
44
 
 
45
#include "osdcore.h"
 
46
#include "coretmpl.h"
 
47
#include "bitmap.h"
 
48
#include "huffman.h"
 
49
#include "flac.h"
 
50
 
 
51
 
 
52
//**************************************************************************
 
53
//  CONSTANTS
 
54
//**************************************************************************
 
55
 
 
56
#define AVHUFF_USE_FLAC         (1)
 
57
 
 
58
 
 
59
// errors
 
60
enum avhuff_error
 
61
{
 
62
        AVHERR_NONE = 0,
 
63
        AVHERR_INVALID_DATA,
 
64
        AVHERR_VIDEO_TOO_LARGE,
 
65
        AVHERR_AUDIO_TOO_LARGE,
 
66
        AVHERR_METADATA_TOO_LARGE,
 
67
        AVHERR_OUT_OF_MEMORY,
 
68
        AVHERR_COMPRESSION_ERROR,
 
69
        AVHERR_TOO_MANY_CHANNELS,
 
70
        AVHERR_INVALID_CONFIGURATION,
 
71
        AVHERR_INVALID_PARAMETER,
 
72
        AVHERR_BUFFER_TOO_SMALL
 
73
};
 
74
 
 
75
 
 
76
 
 
77
//**************************************************************************
 
78
//  TYPE DEFINITIONS
 
79
//**************************************************************************
 
80
 
 
81
// ======================> av_codec_decompress_config
 
82
 
 
83
// decompression configuration
 
84
class avhuff_decompress_config
 
85
{
 
86
public:
 
87
        avhuff_decompress_config()
 
88
                : maxsamples(0),
 
89
                  actsamples(NULL),
 
90
                  maxmetalength(0),
 
91
                  actmetalength(NULL),
 
92
                  metadata(NULL)
 
93
        {
 
94
                memset(audio, 0, sizeof(audio));
 
95
        }
 
96
 
 
97
        bitmap_yuy16 video;                                             // pointer to video bitmap
 
98
        UINT32          maxsamples;                                     // maximum number of samples per channel
 
99
        UINT32 *        actsamples;                                     // actual number of samples per channel
 
100
        INT16 *         audio[16];                                      // pointer to individual audio channels
 
101
        UINT32          maxmetalength;                          // maximum length of metadata
 
102
        UINT32 *        actmetalength;                          // actual length of metadata
 
103
        UINT8 *         metadata;                                       // pointer to metadata buffer
 
104
};
 
105
 
 
106
 
 
107
// ======================> avhuff_encoder
 
108
 
 
109
// core state for the codec
 
110
class avhuff_encoder
 
111
{
 
112
public:
 
113
        // construction/destruction
 
114
        avhuff_encoder();
 
115
 
 
116
        // encode/decode
 
117
        avhuff_error encode_data(const UINT8 *source, UINT8 *dest, UINT32 &complength);
 
118
 
 
119
        // static helpers
 
120
        static UINT32 raw_data_size(const UINT8 *data);
 
121
        static UINT32 raw_data_size(UINT32 width, UINT32 height, UINT8 channels, UINT32 numsamples, UINT32 metadatasize = 0) { return 12 + channels * numsamples * 2 + width * height * 2; }
 
122
        static avhuff_error assemble_data(dynamic_buffer &buffer, bitmap_yuy16 &bitmap, UINT8 channels, UINT32 numsamples, INT16 **samples, UINT8 *metadata = NULL, UINT32 metadatasize = 0);
 
123
 
 
124
private:
 
125
        // delta-RLE Huffman encoder
 
126
        class deltarle_encoder
 
127
        {
 
128
        public:
 
129
                // construction/destruction
 
130
                deltarle_encoder()
 
131
                        : m_rlecount(0) { }
 
132
 
 
133
                // histogramming
 
134
                UINT16 *rle_and_histo_bitmap(const UINT8 *source, UINT32 items_per_row, UINT32 item_advance, UINT32 row_count);
 
135
 
 
136
                // encoding
 
137
                void flush_rle() { m_rlecount = 0; }
 
138
                void encode_one(bitstream_out &bitbuf, UINT16 *&rleptr);
 
139
                huffman_error export_tree_rle(bitstream_out &bitbuf) { return m_encoder.export_tree_rle(bitbuf); }
 
140
 
 
141
        private:
 
142
                // internal state
 
143
                int                                                     m_rlecount;
 
144
                huffman_encoder<256 + 16>       m_encoder;
 
145
                dynamic_array<UINT16>           m_rlebuffer;
 
146
        };
 
147
 
 
148
        // internal helpers
 
149
        avhuff_error encode_audio(const UINT8 *source, int channels, int samples, UINT8 *dest, UINT8 *sizes);
 
150
        avhuff_error encode_video(const UINT8 *source, int width, int height, UINT8 *dest, UINT32 &complength);
 
151
        avhuff_error encode_video_lossless(const UINT8 *source, int width, int height, UINT8 *dest, UINT32 &complength);
 
152
 
 
153
        // video encoding contexts
 
154
        deltarle_encoder                        m_ycontext;
 
155
        deltarle_encoder                        m_cbcontext;
 
156
        deltarle_encoder                        m_crcontext;
 
157
 
 
158
        // audio encoding contexts
 
159
        dynamic_buffer                          m_audiobuffer;
 
160
#if AVHUFF_USE_FLAC
 
161
        flac_encoder                            m_flac_encoder;
 
162
#else
 
163
        huffman_8bit_encoder            m_audiohi_encoder;
 
164
        huffman_8bit_encoder            m_audiolo_encoder;
 
165
#endif
 
166
};
 
167
 
 
168
 
 
169
// ======================> avhuff_decoder
 
170
 
 
171
// core state for the codec
 
172
class avhuff_decoder
 
173
{
 
174
public:
 
175
        // construction/destruction
 
176
        avhuff_decoder();
 
177
 
 
178
        // configuration
 
179
        void configure(const avhuff_decompress_config &config);
 
180
 
 
181
        // encode/decode
 
182
        avhuff_error decode_data(const UINT8 *source, UINT32 complength, UINT8 *dest);
 
183
 
 
184
private:
 
185
        // delta-RLE Huffman decoder
 
186
        class deltarle_decoder
 
187
        {
 
188
        public:
 
189
                // construction/destruction
 
190
                deltarle_decoder()
 
191
                        : m_rlecount(0), m_prevdata(0) { }
 
192
 
 
193
                // general
 
194
                void reset() { m_rlecount = m_prevdata = 0; }
 
195
 
 
196
                // decoding
 
197
                void flush_rle() { m_rlecount = 0; }
 
198
                UINT32 decode_one(bitstream_in &bitbuf);
 
199
                huffman_error import_tree_rle(bitstream_in &bitbuf) { return m_decoder.import_tree_rle(bitbuf); }
 
200
 
 
201
        private:
 
202
                // internal state
 
203
                int                                                     m_rlecount;
 
204
                UINT8                                           m_prevdata;
 
205
                huffman_decoder<256 + 16>       m_decoder;
 
206
        };
 
207
 
 
208
 
 
209
        // internal helpers
 
210
        avhuff_error decode_audio(int channels, int samples, const UINT8 *source, UINT8 **dest, UINT32 dxor, const UINT8 *sizes);
 
211
        avhuff_error decode_video(int width, int height, const UINT8 *source, UINT32 complength, UINT8 *dest, UINT32 dstride, UINT32 dxor);
 
212
        avhuff_error decode_video_lossless(int width, int height, const UINT8 *source, UINT32 complength, UINT8 *dest, UINT32 dstride, UINT32 dxor);
 
213
 
 
214
        // internal state
 
215
        avhuff_decompress_config        m_config;
 
216
 
 
217
        // video decoding contexts
 
218
        deltarle_decoder                        m_ycontext;
 
219
        deltarle_decoder                        m_cbcontext;
 
220
        deltarle_decoder                        m_crcontext;
 
221
 
 
222
        // audio decoding contexts
 
223
        huffman_8bit_decoder            m_audiohi_decoder;
 
224
        huffman_8bit_decoder            m_audiolo_decoder;
 
225
#if AVHUFF_USE_FLAC
 
226
        flac_decoder                            m_flac_decoder;
 
227
#endif
 
228
};
 
229
 
 
230
 
 
231
#endif