comparison src/flacng/tools.c @ 1255:37598c8f4425

- Add flac_is_our_fd()
author Ralf Ertzinger <ralf@skytale.net>
date Thu, 12 Jul 2007 22:34:44 +0200
parents 626f78ff2439
children 47559538ce3d
comparison
equal deleted inserted replaced
1248:0e0f73fed025 1255:37598c8f4425
170 _LEAVE; 170 _LEAVE;
171 } 171 }
172 172
173 /* --- */ 173 /* --- */
174 174
175 gboolean read_metadata(gchar* filename, FLAC__StreamDecoder* decoder, callback_info* info) { 175 gboolean read_metadata(VFSFile* fd, FLAC__StreamDecoder* decoder, callback_info* info) {
176 176
177 FLAC__StreamDecoderState ret; 177 FLAC__StreamDecoderState ret;
178 178
179 _ENTER; 179 _ENTER;
180 180
181 _DEBUG("Using callback_info %s", info->name); 181 _DEBUG("Using callback_info %s", info->name);
182
183 _DEBUG("Opening file %s", filename);
184 182
185 /* 183 /*
186 * Reset the decoder 184 * Reset the decoder
187 */ 185 */
188 if (false == FLAC__stream_decoder_reset(decoder)) { 186 if (false == FLAC__stream_decoder_reset(decoder)) {
190 _LEAVE FALSE; 188 _LEAVE FALSE;
191 } 189 }
192 190
193 reset_info(info); 191 reset_info(info);
194 192
193 info->input_stream = fd;
194
195 /* 195 /*
196 * Just scan the first 8k for the start of metadata 196 * Just scan the first 8k for the start of metadata
197 */ 197 */
198 198
199 info->read_max = 8192; 199 info->read_max = 8192;
201 /* 201 /*
202 * We are not sure if this is an actual flac file, so do not 202 * We are not sure if this is an actual flac file, so do not
203 * complain too much about errors in the stream 203 * complain too much about errors in the stream
204 */ 204 */
205 info->testing = TRUE; 205 info->testing = TRUE;
206
207 /*
208 * Open the file
209 */
210 if (NULL == (info->input_stream = vfs_fopen(filename, "rb"))) {
211 _ERROR("Could not open file for reading! (%s)", filename);
212 _LEAVE FALSE;
213 }
214 206
215 /* 207 /*
216 * Try to decode the metadata 208 * Try to decode the metadata
217 */ 209 */
218 if (false == FLAC__stream_decoder_process_until_end_of_metadata(decoder)) { 210 if (false == FLAC__stream_decoder_process_until_end_of_metadata(decoder)) {
219 ret = FLAC__stream_decoder_get_state(decoder); 211 ret = FLAC__stream_decoder_get_state(decoder);
220 _DEBUG("Could not read the metadata: %s(%d)!", 212 _DEBUG("Could not read the metadata: %s(%d)!",
221 FLAC__StreamDecoderStateString[ret], ret); 213 FLAC__StreamDecoderStateString[ret], ret);
214 /* Do not close the filehandle, it was passed to us */
215 info->input_stream = NULL;
222 reset_info(info); 216 reset_info(info);
223 _LEAVE FALSE; 217 _LEAVE FALSE;
224 } 218 }
225 219
226 /* 220 /*