1 /* libFLAC - Free Lossless Audio Codec library
2 * Copyright (C) 2000,2001 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_UNINITIALIZED
36 } FLAC__StreamDecoderState;
37 extern const char *FLAC__StreamDecoderStateString[];
40 FLAC__STREAM_DECODER_READ_CONTINUE,
41 FLAC__STREAM_DECODER_READ_END_OF_STREAM,
42 FLAC__STREAM_DECODER_READ_ABORT
43 } FLAC__StreamDecoderReadStatus;
44 extern const char *FLAC__StreamDecoderReadStatusString[];
47 FLAC__STREAM_DECODER_WRITE_CONTINUE,
48 FLAC__STREAM_DECODER_WRITE_ABORT
49 } FLAC__StreamDecoderWriteStatus;
50 extern const char *FLAC__StreamDecoderWriteStatusString[];
53 FLAC__STREAM_DECODER_ERROR_LOST_SYNC,
54 FLAC__STREAM_DECODER_ERROR_BAD_HEADER,
55 FLAC__STREAM_DECODER_ERROR_FRAME_CRC_MISMATCH
56 } FLAC__StreamDecoderErrorStatus;
57 extern const char *FLAC__StreamDecoderErrorStatusString[];
59 /***********************************************************************
61 * class FLAC__StreamDecoder
63 ***********************************************************************/
65 struct FLAC__StreamDecoderProtected;
66 struct FLAC__StreamDecoderPrivate;
68 struct FLAC__StreamDecoderProtected *protected;
69 struct FLAC__StreamDecoderPrivate *private;
70 } FLAC__StreamDecoder;
72 /***********************************************************************
74 * Class constructor/destructor
76 ***********************************************************************/
78 FLAC__StreamDecoder *FLAC__stream_decoder_new();
79 void FLAC__stream_decoder_delete(FLAC__StreamDecoder *);
81 /***********************************************************************
83 * Public class method prototypes
85 ***********************************************************************/
88 * Initialize the instance; should be called after construction and
89 * before any other calls. Will set and return the decoder state which
90 * will be FLAC__STREAM_DECODER_SEARCH_FOR_METADATA if initialization
93 FLAC__StreamDecoderState FLAC__stream_decoder_init(
94 FLAC__StreamDecoder *decoder,
95 FLAC__StreamDecoderReadStatus (*read_callback)(const FLAC__StreamDecoder *decoder, byte buffer[], unsigned *bytes, void *client_data),
96 FLAC__StreamDecoderWriteStatus (*write_callback)(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const int32 *buffer[], void *client_data),
97 void (*metadata_callback)(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetaData *metadata, void *client_data),
98 void (*error_callback)(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data),
101 void FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder);
104 * methods to return the stream decoder state, number of channels,
105 * channel assignment, bits-per-sample, sample rate in Hz, and
106 * blocksize in samples.
108 FLAC__StreamDecoderState FLAC__stream_decoder_state(const FLAC__StreamDecoder *decoder);
109 unsigned FLAC__stream_decoder_channels(const FLAC__StreamDecoder *decoder);
110 FLAC__ChannelAssignment FLAC__stream_decoder_channel_assignment(const FLAC__StreamDecoder *decoder);
111 unsigned FLAC__stream_decoder_bits_per_sample(const FLAC__StreamDecoder *decoder);
112 unsigned FLAC__stream_decoder_sample_rate(const FLAC__StreamDecoder *decoder);
113 unsigned FLAC__stream_decoder_blocksize(const FLAC__StreamDecoder *decoder);
116 * state control methods
118 bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder);
119 bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder);
122 * methods for decoding the data
124 bool FLAC__stream_decoder_process_whole_stream(FLAC__StreamDecoder *decoder);
125 bool FLAC__stream_decoder_process_metadata(FLAC__StreamDecoder *decoder);
126 bool FLAC__stream_decoder_process_one_frame(FLAC__StreamDecoder *decoder);
127 bool FLAC__stream_decoder_process_remaining_frames(FLAC__StreamDecoder *decoder);