comparison Plugins/Input/mpg123/mpg123.c @ 1372:b861909ec6da trunk

[svn] mpgdec: - fix smart detection of MPEG streams/Xiph containers/MP3X containers/Fraunhofer VBRX containers - use smart detection instead of extension checking - avoid grabbing FLAC streams if mpgdec is loaded before libflac is.
author nenolod
date Tue, 04 Jul 2006 17:29:40 -0700
parents 9dc0ce1fd3cd
children 86242883ddc7
comparison
equal deleted inserted replaced
1371:ca4f3115d33c 1372:b861909ec6da
266 { 266 {
267 return (buf[0] << 24) + (buf[1] << 16) + (buf[2] << 8) + buf[3]; 267 return (buf[0] << 24) + (buf[1] << 16) + (buf[2] << 8) + buf[3];
268 } 268 }
269 269
270 270
271 #if 0 271 #define DET_BUF_SIZE 4096
272 #define DET_BUF_SIZE 1024
273 272
274 static gboolean 273 static gboolean
275 mpgdec_detect_by_content(char *filename) 274 mpgdec_detect_by_content(char *filename)
276 { 275 {
277 VFSFile *file; 276 VFSFile *file;
291 while (!mpgdec_head_check(head)) { 290 while (!mpgdec_head_check(head)) {
292 /* 291 /*
293 * The mpeg-stream can start anywhere in the file, 292 * The mpeg-stream can start anywhere in the file,
294 * so we check the entire file 293 * so we check the entire file
295 * 294 *
296 * Incorrect! We give up past ten iterations of this 295 * Incorrect! We give up past twenty iterations of this
297 * code for safety's sake. Buffer overflows suck. --nenolod 296 * code for safety's sake. Buffer overflows suck. --nenolod
298 */ 297 */
299 /* Optimize this */ 298 /* Optimize this */
300 in_buf = vfs_fread(buf, 1, DET_BUF_SIZE, file); 299 in_buf = vfs_fread(buf, 1, DET_BUF_SIZE, file);
301 if (in_buf == 0) 300 if (in_buf == 0)
308 vfs_fseek(file, i + 1 - in_buf, SEEK_CUR); 307 vfs_fseek(file, i + 1 - in_buf, SEEK_CUR);
309 break; 308 break;
310 } 309 }
311 } 310 }
312 311
313 if (++cyc > 20) 312 if (++cyc > 1024)
314 goto done; 313 goto done;
315 } 314 }
316 if (mpgdec_decode_header(&fr, head)) { 315 if (mpgdec_decode_header(&fr, head)) {
317 /* 316 /*
318 * We found something which looks like a MPEG-header. 317 * We found something which looks like a MPEG-header.
330 329
331 done: 330 done:
332 vfs_fclose(file); 331 vfs_fclose(file);
333 return ret; 332 return ret;
334 } 333 }
335 #endif
336 334
337 static int 335 static int
338 is_our_file(char *filename) 336 is_our_file(char *filename)
339 { 337 {
340 gchar *ext = strrchr(filename, '.'); 338 gchar *ext = strrchr(filename, '.');
341 339
342 if (!strncasecmp(filename, "http://", 7) && (ext && strncasecmp(ext, ".ogg", 4))) 340 if (!strncasecmp(filename, "http://", 7) && (ext && strncasecmp(ext, ".ogg", 4)) && (ext && strncasecmp(ext, ".flac", 5)))
343 return TRUE; 341 return TRUE;
342 else if (mpgdec_detect_by_content(filename))
343 return TRUE;
344 #if 0
344 else if (ext && (!strncasecmp(ext, ".mp3", 4) 345 else if (ext && (!strncasecmp(ext, ".mp3", 4)
345 || !strncasecmp(ext, ".mp2", 4) 346 || !strncasecmp(ext, ".mp2", 4)
346 || !strncasecmp(ext, ".mpg", 4))) 347 || !strncasecmp(ext, ".mpg", 4)))
347 return TRUE; 348 return TRUE;
349 #endif
348 350
349 return FALSE; 351 return FALSE;
350 } 352 }
351 353
352 static void 354 static void