1 /* libFLAC - Free Lossless Audio Codec library
2 * Copyright (C) 2000,2001,2002 Josh Coalson
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.
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.
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.
20 #ifndef FLAC__STREAM_DECODER_H
21 #define FLAC__STREAM_DECODER_H
26 FLAC__STREAM_DECODER_SEARCH_FOR_METADATA = 0,
27 FLAC__STREAM_DECODER_READ_METADATA,
28 FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC,
29 FLAC__STREAM_DECODER_READ_FRAME,
30 FLAC__STREAM_DECODER_END_OF_STREAM,
31 FLAC__STREAM_DECODER_ABORTED,
32 FLAC__STREAM_DECODER_UNPARSEABLE_STREAM,
33 FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR,
34 FLAC__STREAM_DECODER_ALREADY_INITIALIZED,
35 FLAC__STREAM_DECODER_INVALID_CALLBACK,
36 FLAC__STREAM_DECODER_UNINITIALIZED
37 } FLAC__StreamDecoderState;
38 extern const char *FLAC__StreamDecoderStateString[];
41 FLAC__STREAM_DECODER_READ_CONTINUE,
42 FLAC__STREAM_DECODER_READ_END_OF_STREAM,
43 FLAC__STREAM_DECODER_READ_ABORT
44 } FLAC__StreamDecoderReadStatus;
45 extern const char *FLAC__StreamDecoderReadStatusString[];
48 FLAC__STREAM_DECODER_WRITE_CONTINUE,
49 FLAC__STREAM_DECODER_WRITE_ABORT
50 } FLAC__StreamDecoderWriteStatus;
51 extern const char *FLAC__StreamDecoderWriteStatusString[];
54 FLAC__STREAM_DECODER_ERROR_LOST_SYNC,
55 FLAC__STREAM_DECODER_ERROR_BAD_HEADER,
56 FLAC__STREAM_DECODER_ERROR_FRAME_CRC_MISMATCH
57 } FLAC__StreamDecoderErrorStatus;
58 extern const char *FLAC__StreamDecoderErrorStatusString[];
60 /***********************************************************************
62 * class FLAC__StreamDecoder
64 ***********************************************************************/
66 struct FLAC__StreamDecoderProtected;
67 struct FLAC__StreamDecoderPrivate;
69 struct FLAC__StreamDecoderProtected *protected_; /* avoid the C++ keyword 'protected' */
70 struct FLAC__StreamDecoderPrivate *private_; /* avoid the C++ keyword 'private' */
71 } FLAC__StreamDecoder;
73 /***********************************************************************
75 * Class constructor/destructor
77 ***********************************************************************/
80 * Any parameters that are not set before FLAC__stream_decoder_init()
81 * will take on the defaults from the constructor, shown below.
82 * For more on what the parameters mean, see the documentation.
84 * (*read_callback)() (DEFAULT: NULL ) The callbacks are the only values that MUST be set before FLAC__stream_decoder_init()
85 * (*write_callback)() (DEFAULT: NULL )
86 * (*metadata_callback)() (DEFAULT: NULL )
87 * (*error_callback)() (DEFAULT: NULL )
88 * void* client_data (DEFAULT: NULL ) passed back through the callbacks
90 FLAC__StreamDecoder *FLAC__stream_decoder_new();
91 void FLAC__stream_decoder_delete(FLAC__StreamDecoder *);
93 /***********************************************************************
95 * Public class method prototypes
97 ***********************************************************************/
100 * Various "set" methods. These may only be called when the decoder
101 * is in the state FLAC__STREAM_DECODER_UNINITIALIZED, i.e. after
102 * FLAC__stream_decoder_new() or FLAC__stream_decoder_finish(), but
103 * before FLAC__stream_decoder_init(). If this is the case they will
104 * return true, otherwise false.
106 * NOTE that these functions do not validate the values as many are
107 * interdependent. The FLAC__stream_decoder_init() function will do
108 * this, so make sure to pay attention to the state returned by
109 * FLAC__stream_decoder_init().
111 * Any parameters that are not set before FLAC__stream_decoder_init()
112 * will take on the defaults from the constructor. NOTE that
113 * FLAC__stream_decoder_flush() or FLAC__stream_decoder_reset() do
114 * NOT reset the values to the constructor defaults.
116 FLAC__bool FLAC__stream_decoder_set_read_callback(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderReadStatus (*value)(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data));
117 FLAC__bool FLAC__stream_decoder_set_write_callback(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderWriteStatus (*value)(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 *buffer[], void *client_data));
118 FLAC__bool FLAC__stream_decoder_set_metadata_callback(const FLAC__StreamDecoder *decoder, void (*value)(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetaData *metadata, void *client_data));
119 FLAC__bool FLAC__stream_decoder_set_error_callback(const FLAC__StreamDecoder *decoder, void (*value)(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data));
120 FLAC__bool FLAC__stream_decoder_set_client_data(const FLAC__StreamDecoder *decoder, void *value);
123 * Methods to return the current stream decoder state, number
124 * of channels, channel assignment, bits-per-sample, sample
125 * rate in Hz, and blocksize in samples. All but the decoder
126 * state will only be valid after decoding has started.
128 FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder);
129 unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder);
130 FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder);
131 unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder);
132 unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder);
133 unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder);
136 * Initialize the instance; should be called after construction and
137 * 'set' calls but before any of the 'process' calls. Will set and
138 * return the decoder state, which will be
139 * FLAC__STREAM_DECODER_SEARCH_FOR_METADATA if initialization
142 FLAC__StreamDecoderState FLAC__stream_decoder_init(FLAC__StreamDecoder *decoder);
145 * Flush the decoding buffer, release resources, and return the decoder
146 * state to FLAC__STREAM_DECODER_UNINITIALIZED.
148 void FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder);
151 * state control methods
153 FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder);
154 FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder);
157 * Methods for decoding the data
159 FLAC__bool FLAC__stream_decoder_process_whole_stream(FLAC__StreamDecoder *decoder);
160 FLAC__bool FLAC__stream_decoder_process_metadata(FLAC__StreamDecoder *decoder);
161 FLAC__bool FLAC__stream_decoder_process_one_frame(FLAC__StreamDecoder *decoder);
162 FLAC__bool FLAC__stream_decoder_process_remaining_frames(FLAC__StreamDecoder *decoder);