From 0725c9ae1375f7d33efaf90ec94c14a2355b8b00 Mon Sep 17 00:00:00 2001 From: Ron Pedde Date: Mon, 28 Aug 2006 03:59:04 +0000 Subject: [PATCH] Fixes for transcoding flacs with leading id3v2 tags --- src/plugins/ssc-ffmpeg.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/plugins/ssc-ffmpeg.c b/src/plugins/ssc-ffmpeg.c index 66837068..27f387ab 100644 --- a/src/plugins/ssc-ffmpeg.c +++ b/src/plugins/ssc-ffmpeg.c @@ -18,6 +18,20 @@ #include #include "ff-plugins.h" + +#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4) +# define _PACKED __attribute((packed)) +#else +# define _PACKED +#endif + +typedef struct tag_scan_id3header { + unsigned char id[3]; + unsigned char version[2]; + unsigned char flags; + unsigned char size[4]; +} _PACKED SCAN_ID3HEADER; +#pragma pack() #ifndef TRUE # define TRUE 1 @@ -158,6 +172,8 @@ int ssc_ffmpeg_open(void *vp, char *file, char *codec, int duration) { WCHAR utf16_path[_MAX_PATH+1]; WCHAR utf16_mode[3]; #endif + SCAN_ID3HEADER id3; + unsigned int size = 0; if(!handle) return FALSE; @@ -203,6 +219,30 @@ int ssc_ffmpeg_open(void *vp, char *file, char *codec, int duration) { return FALSE; } + /* check to see if there is an id3 tag there... if so, skip it. */ + if(fread((unsigned char *)&id3,1,sizeof(id3),handle->fin) != sizeof(id3)) { + if(ferror(handle->fin)) { + _ppi->log(E_LOG,"Error reading file: %s\n",file); + } else { + _ppi->log(E_LOG,"Short file: %s\n",file); + } + handle->errnum = SSC_FFMPEG_E_FILEOPEN; + fclose(handle->fin); + return FALSE; + + } + + if(strncmp(id3.id,"ID3",3)==0) { + /* found an ID3 header... */ + _ppi->log(E_DBG,"Found ID3 header\n"); + size = (id3.size[0] << 21 | id3.size[1] << 14 | + id3.size[2] << 7 | id3.size[3]); + fseek(handle->fin,size + sizeof(SCAN_ID3HEADER),SEEK_SET); + _ppi->log(E_DBG,"Header length: %d\n",size); + } else { + fseek(handle->fin,0,SEEK_SET); + } + return TRUE; }