fix constness on _set_ methods
[platform/upstream/flac.git] / include / FLAC / stream_encoder.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_ENCODER_H
21 #define FLAC__STREAM_ENCODER_H
22
23 #include "format.h"
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29
30 typedef enum {
31         FLAC__STREAM_ENCODER_OK = 0,
32         FLAC__STREAM_ENCODER_INVALID_CALLBACK,
33         FLAC__STREAM_ENCODER_INVALID_NUMBER_OF_CHANNELS,
34         FLAC__STREAM_ENCODER_INVALID_BITS_PER_SAMPLE,
35         FLAC__STREAM_ENCODER_INVALID_SAMPLE_RATE,
36         FLAC__STREAM_ENCODER_INVALID_BLOCK_SIZE,
37         FLAC__STREAM_ENCODER_INVALID_QLP_COEFF_PRECISION,
38         FLAC__STREAM_ENCODER_MID_SIDE_CHANNELS_MISMATCH,
39         FLAC__STREAM_ENCODER_MID_SIDE_SAMPLE_SIZE_MISMATCH,
40         FLAC__STREAM_ENCODER_ILLEGAL_MID_SIDE_FORCE,
41         FLAC__STREAM_ENCODER_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER,
42         FLAC__STREAM_ENCODER_NOT_STREAMABLE,
43         FLAC__STREAM_ENCODER_FRAMING_ERROR,
44         FLAC__STREAM_ENCODER_INVALID_SEEK_TABLE,
45         FLAC__STREAM_ENCODER_FATAL_ERROR_WHILE_ENCODING,
46         FLAC__STREAM_ENCODER_FATAL_ERROR_WHILE_WRITING, /* that is, the write_callback returned an error */
47         FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR,
48         FLAC__STREAM_ENCODER_ALREADY_INITIALIZED,
49         FLAC__STREAM_ENCODER_UNINITIALIZED
50 } FLAC__StreamEncoderState;
51 extern const char *FLAC__StreamEncoderStateString[];
52
53 typedef enum {
54         FLAC__STREAM_ENCODER_WRITE_OK = 0,
55         FLAC__STREAM_ENCODER_WRITE_FATAL_ERROR
56 } FLAC__StreamEncoderWriteStatus;
57 extern const char *FLAC__StreamEncoderWriteStatusString[];
58
59 /***********************************************************************
60  *
61  * class FLAC__StreamEncoder
62  *
63  ***********************************************************************/
64
65 struct FLAC__StreamEncoderProtected;
66 struct FLAC__StreamEncoderPrivate;
67 typedef struct {
68         struct FLAC__StreamEncoderProtected *protected_; /* avoid the C++ keyword 'protected' */
69         struct FLAC__StreamEncoderPrivate *private_; /* avoid the C++ keyword 'private' */
70 } FLAC__StreamEncoder;
71
72 /***********************************************************************
73  *
74  * Class constructor/destructor
75  *
76  ***********************************************************************/
77
78 /*
79  * Any parameters that are not set before FLAC__stream_encoder_init()
80  * will take on the defaults from the constructor, shown below.
81  * For more on what the parameters mean, see the documentation.
82  *
83  * FLAC__bool   streamable_subset              (DEFAULT: true ) true to limit encoder to generating a Subset stream, else false
84  * FLAC__bool   do_mid_side_stereo             (DEFAULT: false) if true then channels must be 2
85  * FLAC__bool   loose_mid_side_stereo          (DEFAULT: false) if true then do_mid_side_stereo must be true
86  * unsigned     channels                       (DEFAULT: 2    ) must be <= FLAC__MAX_CHANNELS
87  * unsigned     bits_per_sample                (DEFAULT: 16   ) do not give the encoder wider data than what you specify here or bad things will happen!
88  * unsigned     sample_rate                    (DEFAULT: 44100)
89  * unsigned     blocksize                      (DEFAULT: 1152 )
90  * unsigned     max_lpc_order                  (DEFAULT: 0    ) 0 => encoder will not try general LPC, only fixed predictors; must be <= FLAC__MAX_LPC_ORDER
91  * unsigned     qlp_coeff_precision            (DEFAULT: 0    ) >= FLAC__MIN_QLP_COEFF_PRECISION, or 0 to let encoder select based on blocksize;
92  *                                                          qlp_coeff_precision+bits_per_sample must be < 32
93  * FLAC__bool   do_qlp_coeff_prec_search       (DEFAULT: false) false => use qlp_coeff_precision, true => search around qlp_coeff_precision, take best
94  * FLAC__bool   do_escape_coding               (DEFAULT: false) true => search for escape codes in the entropy coding stage for slightly better compression
95  * FLAC__bool   do_exhaustive_model_search     (DEFAULT: false) false => use estimated bits per residual for scoring, true => generate all, take shortest
96  * unsigned     min_residual_partition_order   (DEFAULT: 0    ) 0 => estimate Rice parameter based on residual variance; >0 => partition residual, use parameter
97  * unsigned     max_residual_partition_order   (DEFAULT: 0    )      for each based on mean; min_ and max_ specify the min and max Rice partition order
98  * unsigned     rice_parameter_search_dist     (DEFAULT: 0    ) 0 => try only calc'd parameter k; else try all [k-dist..k+dist] parameters, use best
99  * FLAC__uint64 total_samples_estimate         (DEFAULT: 0    ) may be 0 if unknown.  acts as a placeholder in the STREAMINFO until the actual total is calculated
100  * const FLAC__StreamMetaData_SeekTable *seek_table  (DEFAULT: NULL) optional seek_table to prepend, NULL => no seek table
101  * int          padding                        (DEFAULT: -1   ) length of PADDING block to add (goes after seek table); -1 => do not add a PADDING block
102  * FLAC__bool   last_metadata_is_last          (DEFAULT: true ) the value the encoder will use for the 'is_last' flag of the last metadata block it writes; set
103  *                                                          this to false if you will be adding more metadata blocks before the audio frames, else true
104  *            (*write_callback)()              (DEFAULT: NULL ) The callbacks are the only values that MUST be set before FLAC__stream_encoder_init()
105  *            (*metadata_callback)()           (DEFAULT: NULL )
106  * void*        client_data                    (DEFAULT: NULL ) passed back through the callbacks
107  */
108 FLAC__StreamEncoder *FLAC__stream_encoder_new();
109 void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder);
110
111 /***********************************************************************
112  *
113  * Public class method prototypes
114  *
115  ***********************************************************************/
116
117 /*
118  * Various "set" methods.  These may only be called when the encoder
119  * is in the state FLAC__STREAM_ENCODER_UNINITIALIZED, i.e. after
120  * FLAC__stream_encoder_new() or FLAC__stream_encoder_finish(), but
121  * before FLAC__stream_encoder_init().  If this is the case they will
122  * return true, otherwise false.
123  *
124  * NOTE that these functions do not validate the values as many are
125  * interdependent.  The FLAC__stream_encoder_init() function will do
126  * this, so make sure to pay attention to the state returned by
127  * FLAC__stream_encoder_init().
128  *
129  * Any parameters that are not set before FLAC__stream_encoder_init()
130  * will take on the defaults from the constructor.  NOTE that
131  * FLAC__stream_encoder_finish() does NOT reset the values to the
132  * constructor defaults.
133 @@@@ update so that only _set_ methods that need to return FLAC__bool, else void
134  */
135 FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value);
136 FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
137 FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
138 FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value);
139 FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value);
140 FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value);
141 FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value);
142 FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value);
143 FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value);
144 FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
145 FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value);
146 FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
147 FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
148 FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
149 FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value);
150 FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value);
151 FLAC__bool FLAC__stream_encoder_set_seek_table(FLAC__StreamEncoder *encoder, const FLAC__StreamMetaData_SeekTable *value);
152 FLAC__bool FLAC__stream_encoder_set_padding(FLAC__StreamEncoder *encoder, int value);
153 FLAC__bool FLAC__stream_encoder_set_last_metadata_is_last(FLAC__StreamEncoder *encoder, FLAC__bool value);
154 FLAC__bool FLAC__stream_encoder_set_write_callback(FLAC__StreamEncoder *encoder, FLAC__StreamEncoderWriteStatus (*value)(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data));
155 FLAC__bool FLAC__stream_encoder_set_metadata_callback(FLAC__StreamEncoder *encoder, void (*value)(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetaData *metadata, void *client_data));
156 FLAC__bool FLAC__stream_encoder_set_client_data(FLAC__StreamEncoder *encoder, void *value);
157
158 /*
159  * Various "get" methods
160  */
161 FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder);
162 FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder);
163 FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder);
164 FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder);
165 unsigned   FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder);
166 unsigned   FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder);
167 unsigned   FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder);
168 unsigned   FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder);
169 unsigned   FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder);
170 unsigned   FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder);
171 FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder);
172 FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder);
173 FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder);
174 unsigned   FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder);
175 unsigned   FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder);
176 unsigned   FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder);
177
178 /*
179  * Initialize the instance; should be called after construction and
180  * 'set' calls but before any of the 'process' calls.  Will set and
181  * return the encoder state, which will be FLAC__STREAM_ENCODER_OK
182  * if initialization succeeded.
183  */
184 FLAC__StreamEncoderState FLAC__stream_encoder_init(FLAC__StreamEncoder *encoder);
185
186 /*
187  * Flush the encoding buffer, release resources, and return the encoder
188  * state to FLAC__STREAM_ENCODER_UNINITIALIZED.  Note that this can
189  * generate one or more write_callback()s before returning.
190  */
191 void FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder);
192
193 /*
194  * Methods for encoding the data
195  */
196 FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 *buf[], unsigned samples);
197 FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buf[], unsigned samples);
198
199 #ifdef __cplusplus
200 }
201 #endif
202
203 #endif