Link Here
|
41 |
#include "misc.h" |
41 |
#include "misc.h" |
42 |
#include "charset.h" |
42 |
#include "charset.h" |
43 |
|
43 |
|
|
|
44 |
/* FLAC 1.1.3 has FLAC_API_VERSION_CURRENT == 8 */ |
45 |
/* by LEGACY_FLAC we mean pre-FLAC 1.1.3; in FLAC 1.1.3 the FLAC__FileDecoder was merged into the FLAC__StreamDecoder */ |
46 |
#if !defined(FLAC_API_VERSION_CURRENT) || FLAC_API_VERSION_CURRENT < 8 |
47 |
#define LEGACY_FLAC |
48 |
#else |
49 |
#undef LEGACY_FLAC |
50 |
#endif |
44 |
|
51 |
|
45 |
|
52 |
|
46 |
/**************** |
53 |
/**************** |
Link Here
|
75 |
/************** |
82 |
/************** |
76 |
* Prototypes * |
83 |
* Prototypes * |
77 |
**************/ |
84 |
**************/ |
|
|
85 |
#ifdef LEGACY_FLAC |
78 |
static FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__FileDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data); |
86 |
static FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__FileDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data); |
79 |
static void metadata_callback_(const FLAC__FileDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data); |
87 |
static void metadata_callback_(const FLAC__FileDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data); |
80 |
static void error_callback_ (const FLAC__FileDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data); |
88 |
static void error_callback_ (const FLAC__FileDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data); |
|
|
89 |
#else |
90 |
static FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data); |
91 |
static void metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data); |
92 |
static void error_callback_ (const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data); |
93 |
#endif |
81 |
|
94 |
|
82 |
|
95 |
|
83 |
|
96 |
|
Link Here
|
95 |
gdouble duration = 0; |
108 |
gdouble duration = 0; |
96 |
gulong filesize; |
109 |
gulong filesize; |
97 |
|
110 |
|
|
|
111 |
#ifdef LEGACY_FLAC |
98 |
FLAC__FileDecoder *tmp_decoder; |
112 |
FLAC__FileDecoder *tmp_decoder; |
|
|
113 |
#else |
114 |
FLAC__StreamDecoder *tmp_decoder; |
115 |
#endif |
99 |
file_info_struct tmp_file_info; |
116 |
file_info_struct tmp_file_info; |
100 |
|
117 |
|
101 |
if (!filename || !ETFileInfo) |
118 |
if (!filename || !ETFileInfo) |
Link Here
|
111 |
fclose(file); |
128 |
fclose(file); |
112 |
|
129 |
|
113 |
/* Decoding FLAC file */ |
130 |
/* Decoding FLAC file */ |
|
|
131 |
#ifdef LEGACY_FLAC |
114 |
tmp_decoder = FLAC__file_decoder_new(); |
132 |
tmp_decoder = FLAC__file_decoder_new(); |
|
|
133 |
#else |
134 |
tmp_decoder = FLAC__stream_decoder_new(); |
135 |
#endif |
115 |
if (tmp_decoder == 0) |
136 |
if (tmp_decoder == 0) |
116 |
{ |
137 |
{ |
117 |
return FALSE; |
138 |
return FALSE; |
118 |
} |
139 |
} |
119 |
|
140 |
|
120 |
tmp_file_info.abort_flag = false; |
141 |
tmp_file_info.abort_flag = false; |
|
|
142 |
#ifdef LEGACY_FLAC |
121 |
FLAC__file_decoder_set_md5_checking (tmp_decoder, false); |
143 |
FLAC__file_decoder_set_md5_checking (tmp_decoder, false); |
122 |
FLAC__file_decoder_set_filename (tmp_decoder, filename); |
144 |
FLAC__file_decoder_set_filename (tmp_decoder, filename); |
123 |
FLAC__file_decoder_set_write_callback (tmp_decoder, write_callback_); |
145 |
FLAC__file_decoder_set_write_callback (tmp_decoder, write_callback_); |
Link Here
|
129 |
return FALSE; |
151 |
return FALSE; |
130 |
} |
152 |
} |
131 |
|
153 |
|
|
|
154 |
#else |
155 |
FLAC__stream_decoder_set_md5_checking (tmp_decoder, false); |
156 |
if(FLAC__stream_decoder_init_file(tmp_decoder, filename, write_callback_, metadata_callback_, error_callback_, &tmp_file_info) != FLAC__STREAM_DECODER_INIT_STATUS_OK) |
157 |
return FALSE; |
158 |
#endif |
159 |
|
160 |
#ifdef LEGACY_FLAC |
132 |
// In FLAC 1.0.3, is used : FLAC__file_decoder_process_metadata |
161 |
// In FLAC 1.0.3, is used : FLAC__file_decoder_process_metadata |
133 |
// In FLAC 1.0.4, is used : FLAC__file_decoder_process_until_end_of_metadata |
162 |
// In FLAC 1.0.4, is used : FLAC__file_decoder_process_until_end_of_metadata |
134 |
#if ( (LIBFLAC_MAJOR <= 1) && (LIBFLAC_MINOR <= 0) && (LIBFLAC_PATCH <= 3) ) |
163 |
#if ( (LIBFLAC_MAJOR <= 1) && (LIBFLAC_MINOR <= 0) && (LIBFLAC_PATCH <= 3) ) |
Link Here
|
136 |
#else |
165 |
#else |
137 |
if (!FLAC__file_decoder_process_until_end_of_metadata(tmp_decoder)) // FLAC 1.0.4 (Bastian Kleineidam) |
166 |
if (!FLAC__file_decoder_process_until_end_of_metadata(tmp_decoder)) // FLAC 1.0.4 (Bastian Kleineidam) |
138 |
#endif |
167 |
#endif |
|
|
168 |
#else |
169 |
if(!FLAC__stream_decoder_process_until_end_of_metadata(tmp_decoder)) |
170 |
#endif |
139 |
{ |
171 |
{ |
140 |
return FALSE; |
172 |
return FALSE; |
141 |
} |
173 |
} |
142 |
|
174 |
|
|
|
175 |
#ifdef LEGACY_FLAC |
143 |
FLAC__file_decoder_finish(tmp_decoder); |
176 |
FLAC__file_decoder_finish(tmp_decoder); |
144 |
FLAC__file_decoder_delete(tmp_decoder); |
177 |
FLAC__file_decoder_delete(tmp_decoder); |
|
|
178 |
#else |
179 |
FLAC__stream_decoder_finish(tmp_decoder); |
180 |
FLAC__stream_decoder_delete(tmp_decoder); |
181 |
#endif |
145 |
/* End of decoding FLAC file */ |
182 |
/* End of decoding FLAC file */ |
146 |
|
183 |
|
147 |
|
184 |
|
Link Here
|
161 |
|
198 |
|
162 |
|
199 |
|
163 |
|
200 |
|
|
|
201 |
#ifdef LEGACY_FLAC |
164 |
FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__FileDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data) |
202 |
FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__FileDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data) |
|
|
203 |
#else |
204 |
FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data) |
205 |
#endif |
165 |
{ |
206 |
{ |
166 |
file_info_struct *file_info = (file_info_struct *)client_data; |
207 |
file_info_struct *file_info = (file_info_struct *)client_data; |
167 |
const unsigned bps = file_info->bits_per_sample, channels = file_info->channels, wide_samples = frame->header.blocksize; |
208 |
const unsigned bps = file_info->bits_per_sample, channels = file_info->channels, wide_samples = frame->header.blocksize; |
Link Here
|
194 |
return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; |
235 |
return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; |
195 |
} |
236 |
} |
196 |
|
237 |
|
|
|
238 |
#ifdef LEGACY_FLAC |
197 |
void metadata_callback_(const FLAC__FileDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data) |
239 |
void metadata_callback_(const FLAC__FileDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data) |
|
|
240 |
#else |
241 |
void metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data) |
242 |
#endif |
198 |
{ |
243 |
{ |
199 |
file_info_struct *file_info = (file_info_struct *)client_data; |
244 |
file_info_struct *file_info = (file_info_struct *)client_data; |
200 |
(void)decoder; |
245 |
(void)decoder; |
Link Here
|
219 |
} |
264 |
} |
220 |
} |
265 |
} |
221 |
|
266 |
|
|
|
267 |
#ifdef LEGACY_FLAC |
222 |
void error_callback_(const FLAC__FileDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data) |
268 |
void error_callback_(const FLAC__FileDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data) |
|
|
269 |
#else |
270 |
void error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data) |
271 |
#endif |
223 |
{ |
272 |
{ |
224 |
file_info_struct *file_info = (file_info_struct *)client_data; |
273 |
file_info_struct *file_info = (file_info_struct *)client_data; |
225 |
(void)decoder; |
274 |
(void)decoder; |