another big glob of changes/fixes
[platform/upstream/flac.git] / include / FLAC / stream_decoder.h
1 /* libFLAC - Free Lossless Audio Codec library
2  * Copyright (C) 2000,2001,2002  Josh Coalson
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA  02111-1307, USA.
18  */
19
20 #ifndef FLAC__STREAM_DECODER_H
21 #define FLAC__STREAM_DECODER_H
22
23 #include "format.h"
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29
30 typedef enum {
31         FLAC__STREAM_DECODER_SEARCH_FOR_METADATA = 0,
32         FLAC__STREAM_DECODER_READ_METADATA,
33         FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC,
34         FLAC__STREAM_DECODER_READ_FRAME,
35         FLAC__STREAM_DECODER_END_OF_STREAM,
36         FLAC__STREAM_DECODER_ABORTED,
37         FLAC__STREAM_DECODER_UNPARSEABLE_STREAM,
38         FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR,
39         FLAC__STREAM_DECODER_ALREADY_INITIALIZED,
40         FLAC__STREAM_DECODER_INVALID_CALLBACK,
41         FLAC__STREAM_DECODER_UNINITIALIZED
42 } FLAC__StreamDecoderState;
43 extern const char * const FLAC__StreamDecoderStateString[];
44
45 typedef enum {
46         FLAC__STREAM_DECODER_READ_STATUS_CONTINUE,
47         FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM,
48         FLAC__STREAM_DECODER_READ_STATUS_ABORT
49 } FLAC__StreamDecoderReadStatus;
50 extern const char * const FLAC__StreamDecoderReadStatusString[];
51
52 typedef enum {
53         FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE,
54         FLAC__STREAM_DECODER_WRITE_STATUS_ABORT
55 } FLAC__StreamDecoderWriteStatus;
56 extern const char * const FLAC__StreamDecoderWriteStatusString[];
57
58 typedef enum {
59         FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC,
60         FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER,
61         FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH
62 } FLAC__StreamDecoderErrorStatus;
63 extern const char * const FLAC__StreamDecoderErrorStatusString[];
64
65 /***********************************************************************
66  *
67  * class FLAC__StreamDecoder
68  *
69  ***********************************************************************/
70
71 struct FLAC__StreamDecoderProtected;
72 struct FLAC__StreamDecoderPrivate;
73 typedef struct {
74         struct FLAC__StreamDecoderProtected *protected_; /* avoid the C++ keyword 'protected' */
75         struct FLAC__StreamDecoderPrivate *private_; /* avoid the C++ keyword 'private' */
76 } FLAC__StreamDecoder;
77
78 /***********************************************************************
79  *
80  * Class constructor/destructor
81  *
82  ***********************************************************************/
83
84 /*
85  * Any parameters that are not set before FLAC__stream_decoder_init()
86  * will take on the defaults from the constructor, shown below.
87  * For more on what the parameters mean, see the documentation.
88  *
89  *        (*read_callback)()               (DEFAULT: NULL ) The callbacks are the only values that MUST be set before FLAC__stream_decoder_init()
90  *        (*write_callback)()              (DEFAULT: NULL )
91  *        (*metadata_callback)()           (DEFAULT: NULL )
92  *        (*error_callback)()              (DEFAULT: NULL )
93  * void*    client_data                    (DEFAULT: NULL ) passed back through the callbacks
94  */
95 FLAC__StreamDecoder *FLAC__stream_decoder_new();
96 void FLAC__stream_decoder_delete(FLAC__StreamDecoder *);
97
98 /***********************************************************************
99  *
100  * Public class method prototypes
101  *
102  ***********************************************************************/
103
104 /*
105  * Various "set" methods.  These may only be called when the decoder
106  * is in the state FLAC__STREAM_DECODER_UNINITIALIZED, i.e. after
107  * FLAC__stream_decoder_new() or FLAC__stream_decoder_finish(), but
108  * before FLAC__stream_decoder_init().  If this is the case they will
109  * return true, otherwise false.
110  *
111  * NOTE that these functions do not validate the values as many are
112  * interdependent.  The FLAC__stream_decoder_init() function will do
113  * this, so make sure to pay attention to the state returned by
114  * FLAC__stream_decoder_init().
115  *
116  * Any parameters that are not set before FLAC__stream_decoder_init()
117  * will take on the defaults from the constructor.  NOTE that
118  * FLAC__stream_decoder_flush() or FLAC__stream_decoder_reset() do
119  * NOT reset the values to the constructor defaults.
120 @@@@ update so that only _set_ methods that need to return FLAC__bool, else void; update documentation.html also
121 @@@@ update defaults above and in documentation.html about the metadata_respond/ignore defaults
122  */
123 FLAC__bool FLAC__stream_decoder_set_read_callback(FLAC__StreamDecoder *decoder, FLAC__StreamDecoderReadStatus (*value)(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data));
124 FLAC__bool FLAC__stream_decoder_set_write_callback(FLAC__StreamDecoder *decoder, FLAC__StreamDecoderWriteStatus (*value)(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data));
125 FLAC__bool FLAC__stream_decoder_set_metadata_callback(FLAC__StreamDecoder *decoder, void (*value)(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data));
126 FLAC__bool FLAC__stream_decoder_set_error_callback(FLAC__StreamDecoder *decoder, void (*value)(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data));
127 FLAC__bool FLAC__stream_decoder_set_client_data(FLAC__StreamDecoder *decoder, void *value);
128 /*
129  * These deserve special attention.  By default, the decoder only calls the
130  * metadata_callback for the STREAMINFO block.  These functions allow you to
131  * tell the decoder explicitly which blocks to parse and return via the
132  * metadata_callback and/or which to skip.  Use a _respond_all(), _ignore() ...
133  * or _ignore_all(), _respond() ... sequence to exactly specify which blocks
134  * to return.  Remember that some metadata blocks can be big so filtering out
135  * the ones you don't use can reduce the memory requirements of the decoder.
136  * Also note the special forms _respond/_ignore_application(id) for filtering
137  * APPLICATION blocks based on the application ID.
138  *
139  * STREAMINFO and SEEKTABLE blocks are always parsed and used internally, but
140  * they still can legally be filtered from the metadata_callback here.
141  */
142 FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
143 FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
144 FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder);
145 FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
146 FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
147 FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder);
148
149 /*
150  * Methods to return the current stream decoder state, number
151  * of channels, channel assignment, bits-per-sample, sample
152  * rate in Hz, and blocksize in samples.  All but the decoder
153  * state will only be valid after decoding has started.
154  */
155 FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder);
156 unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder);
157 FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder);
158 unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder);
159 unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder);
160 unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder);
161
162 /*
163  * Initialize the instance; should be called after construction and
164  * 'set' calls but before any of the 'process' calls.  Will set and
165  * return the decoder state, which will be
166  * FLAC__STREAM_DECODER_SEARCH_FOR_METADATA if initialization
167  * succeeded.
168  */
169 FLAC__StreamDecoderState FLAC__stream_decoder_init(FLAC__StreamDecoder *decoder);
170
171 /*
172  * Flush the decoding buffer, release resources, and return the decoder
173  * state to FLAC__STREAM_DECODER_UNINITIALIZED.
174  */
175 void FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder);
176
177 /*
178  * state control methods
179  */
180 FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder);
181 FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder);
182
183 /*
184  * Methods for decoding the data
185  */
186 FLAC__bool FLAC__stream_decoder_process_whole_stream(FLAC__StreamDecoder *decoder);
187 FLAC__bool FLAC__stream_decoder_process_metadata(FLAC__StreamDecoder *decoder);
188 FLAC__bool FLAC__stream_decoder_process_one_frame(FLAC__StreamDecoder *decoder);
189 FLAC__bool FLAC__stream_decoder_process_remaining_frames(FLAC__StreamDecoder *decoder);
190
191 #ifdef __cplusplus
192 }
193 #endif
194
195 #endif