massive glob of checkins: improved tests, more tests, bugfixes
[platform/upstream/flac.git] / include / FLAC / file_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__FILE_DECODER_H
21 #define FLAC__FILE_DECODER_H
22
23 #include "stream_decoder.h"
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 typedef enum {
30     FLAC__FILE_DECODER_OK = 0,
31         FLAC__FILE_DECODER_END_OF_FILE,
32     FLAC__FILE_DECODER_ERROR_OPENING_FILE,
33     FLAC__FILE_DECODER_MEMORY_ALLOCATION_ERROR,
34         FLAC__FILE_DECODER_SEEK_ERROR,
35         FLAC__FILE_DECODER_SEEKABLE_STREAM_DECODER_ERROR,
36     FLAC__FILE_DECODER_ALREADY_INITIALIZED,
37     FLAC__FILE_DECODER_INVALID_CALLBACK,
38     FLAC__FILE_DECODER_UNINITIALIZED
39 } FLAC__FileDecoderState;
40 extern const char * const FLAC__FileDecoderStateString[];
41
42 /***********************************************************************
43  *
44  * class FLAC__FileDecoder : public FLAC__StreamDecoder
45  *
46  ***********************************************************************/
47
48 struct FLAC__FileDecoderProtected;
49 struct FLAC__FileDecoderPrivate;
50 typedef struct {
51         struct FLAC__FileDecoderProtected *protected_; /* avoid the C++ keyword 'protected' */
52         struct FLAC__FileDecoderPrivate *private_; /* avoid the C++ keyword 'private' */
53 } FLAC__FileDecoder;
54
55 /***********************************************************************
56  *
57  * Class constructor/destructor
58  *
59  ***********************************************************************/
60
61 /*
62  * Any parameters that are not set before FLAC__file_decoder_init()
63  * will take on the defaults from the constructor, shown below.
64  * For more on what the parameters mean, see the documentation.
65  *
66  * FLAC__bool  md5_checking                   (DEFAULT: false) MD5 checking will be turned off if a seek is requested
67  *           (*write_callback)()              (DEFAULT: NULL ) The callbacks are the only values that MUST be set before FLAC__file_decoder_init()
68  *           (*metadata_callback)()           (DEFAULT: NULL )
69  *           (*error_callback)()              (DEFAULT: NULL )
70  * void*       client_data                    (DEFAULT: NULL ) passed back through the callbacks
71  */
72 FLAC__FileDecoder *FLAC__file_decoder_new();
73 void FLAC__file_decoder_delete(FLAC__FileDecoder *);
74
75 /***********************************************************************
76  *
77  * Public class method prototypes
78  *
79  ***********************************************************************/
80
81 /*
82  * Various "set" methods.  These may only be called when the decoder
83  * is in the state FLAC__FILE_DECODER_UNINITIALIZED, i.e. after
84  * FLAC__file_decoder_new() or FLAC__file_decoder_finish(), but
85  * before FLAC__file_decoder_init().  If this is the case they will
86  * return true, otherwise false.
87  *
88  * NOTE that these functions do not validate the values as many are
89  * interdependent.  The FLAC__file_decoder_init() function will do
90  * this, so make sure to pay attention to the state returned by
91  * FLAC__file_decoder_init().
92  *
93  * Any parameters that are not set before FLAC__file_decoder_init()
94  * will take on the defaults from the constructor.  NOTE that
95  * FLAC__file_decoder_flush() or FLAC__file_decoder_reset() do
96  * NOT reset the values to the constructor defaults.
97 @@@@ update so that only _set_ methods that need to return FLAC__bool, else void; update documentation.html also
98 @@@@ update defaults above and in documentation.html about the metadata_respond/ignore defaults
99  */
100 FLAC__bool FLAC__file_decoder_set_md5_checking(FLAC__FileDecoder *decoder, FLAC__bool value);
101 FLAC__bool FLAC__file_decoder_set_filename(FLAC__FileDecoder *decoder, const char *value); /* 'value' may not be 0; use "-" for stdin */
102 FLAC__bool FLAC__file_decoder_set_write_callback(FLAC__FileDecoder *decoder, FLAC__StreamDecoderWriteStatus (*value)(const FLAC__FileDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data));
103 FLAC__bool FLAC__file_decoder_set_metadata_callback(FLAC__FileDecoder *decoder, void (*value)(const FLAC__FileDecoder *decoder, const FLAC__StreamMetaData *metadata, void *client_data));
104 FLAC__bool FLAC__file_decoder_set_error_callback(FLAC__FileDecoder *decoder, void (*value)(const FLAC__FileDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data));
105 FLAC__bool FLAC__file_decoder_set_client_data(FLAC__FileDecoder *decoder, void *value);
106 /*
107  * See the comments for the equivalent functions in stream_decoder.h
108  */
109 FLAC__bool FLAC__file_decoder_set_metadata_respond(FLAC__FileDecoder *decoder, FLAC__MetaDataType type);
110 FLAC__bool FLAC__file_decoder_set_metadata_respond_application(FLAC__FileDecoder *decoder, const FLAC__byte id[4]);
111 FLAC__bool FLAC__file_decoder_set_metadata_respond_all(FLAC__FileDecoder *decoder);
112 FLAC__bool FLAC__file_decoder_set_metadata_ignore(FLAC__FileDecoder *decoder, FLAC__MetaDataType type);
113 FLAC__bool FLAC__file_decoder_set_metadata_ignore_application(FLAC__FileDecoder *decoder, const FLAC__byte id[4]);
114 FLAC__bool FLAC__file_decoder_set_metadata_ignore_all(FLAC__FileDecoder *decoder);
115
116 /*
117  * Various "get" methods
118  */
119 FLAC__FileDecoderState FLAC__file_decoder_get_state(const FLAC__FileDecoder *decoder);
120 FLAC__bool FLAC__file_decoder_get_md5_checking(const FLAC__FileDecoder *decoder);
121 /*
122  * Methods to return the current number of channels, channel assignment
123  * bits-per-sample, sample rate in Hz, and blocksize in samples.  These
124  * will only be valid after decoding has started.
125  */
126 unsigned FLAC__file_decoder_get_channels(const FLAC__FileDecoder *decoder);
127 FLAC__ChannelAssignment FLAC__file_decoder_get_channel_assignment(const FLAC__FileDecoder *decoder);
128 unsigned FLAC__file_decoder_get_bits_per_sample(const FLAC__FileDecoder *decoder);
129 unsigned FLAC__file_decoder_get_sample_rate(const FLAC__FileDecoder *decoder);
130 unsigned FLAC__file_decoder_get_blocksize(const FLAC__FileDecoder *decoder);
131
132 /*
133  * Initialize the instance; should be called after construction and
134  * 'set' calls but before any of the 'process' or 'seek' calls.  Will
135  * set and return the decoder state, which will be FLAC__FILE_DECODER_OK
136  * if initialization succeeded.
137  */
138 FLAC__FileDecoderState FLAC__file_decoder_init(FLAC__FileDecoder *decoder);
139
140 /*
141  * Flush the decoding buffer, release resources, and return the decoder
142  * state to FLAC__FILE_DECODER_UNINITIALIZED.  Only returns false if
143  * md5_checking is set AND the stored MD5 sum is non-zero AND the stored
144  * MD5 sum and computed MD5 sum do not match.
145  */
146 FLAC__bool FLAC__file_decoder_finish(FLAC__FileDecoder *decoder);
147
148 /*
149  * Methods for decoding the data
150  */
151 FLAC__bool FLAC__file_decoder_process_whole_file(FLAC__FileDecoder *decoder);
152 FLAC__bool FLAC__file_decoder_process_metadata(FLAC__FileDecoder *decoder);
153 FLAC__bool FLAC__file_decoder_process_one_frame(FLAC__FileDecoder *decoder);
154 FLAC__bool FLAC__file_decoder_process_remaining_frames(FLAC__FileDecoder *decoder);
155
156 FLAC__bool FLAC__file_decoder_seek_absolute(FLAC__FileDecoder *decoder, FLAC__uint64 sample);
157
158 #ifdef __cplusplus
159 }
160 #endif
161
162 #endif