aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/audiofile_decode.h3
-rw-r--r--src/directory.c4
-rw-r--r--src/flac_decode.c9
-rw-r--r--src/flac_decode.h2
-rw-r--r--src/libid3tag/config.h.in6
-rw-r--r--src/libmad/config.h.in6
-rw-r--r--src/mp3_decode.c2
-rw-r--r--src/ogg_decode.c19
-rw-r--r--src/ogg_decode.h2
-rw-r--r--src/song.c54
-rw-r--r--src/song.h1
-rw-r--r--src/tag.c33
-rw-r--r--src/tag.h1
13 files changed, 80 insertions, 62 deletions
diff --git a/src/audiofile_decode.h b/src/audiofile_decode.h
index 40296ad96..d0bc8d9be 100644
--- a/src/audiofile_decode.h
+++ b/src/audiofile_decode.h
@@ -25,7 +25,8 @@
#include "playerData.h"
-int audiofile_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc);
+int audiofile_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc);;
+
int getAudiofileTotalTime(char * file);
#endif /* HAVE_AUDIOFILE */
diff --git a/src/directory.c b/src/directory.c
index 64384a1a4..457a5d585 100644
--- a/src/directory.c
+++ b/src/directory.c
@@ -327,10 +327,10 @@ int addToDirectory(Directory * directory, char * shortname, char * name) {
return addSubDirectoryToDirectory(directory,shortname,name);
}
else if(isMusic(name)) {
- LOG("adding %s\n",name);
Song * song;
song = addSongToList(directory->songs,shortname,name);
if(!song) return -1;
+ LOG("added %s\n",name);
addSongToTables(song);
return 0;
}
@@ -807,7 +807,7 @@ int directoryPrintSongInfo(FILE * fp, Song * song, void * data) {
int sumSongTime(FILE * fp, Song * song, void * data) {
unsigned long * time = (unsigned long *)data;
- if(song->tag && song->tag->time>=0) *time+=song->tag->time;
+ if(song->time>=0) *time+=song->time;
return 0;
}
diff --git a/src/flac_decode.c b/src/flac_decode.c
index 559721c21..de59001f1 100644
--- a/src/flac_decode.c
+++ b/src/flac_decode.c
@@ -282,6 +282,15 @@ int flac_getAudioFormatAndTime(char * file, AudioFormat * format, float * time)
return ret;
}
+int getFlacTotalTime(char * file) {
+ float totalTime;
+ AudioFormat af;
+
+ if(flac_getAudioFormatAndTime(file,&af,&totalTime)<0) return -1;
+
+ return (int)(totalTime+0.5);
+}
+
int flac_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc) {
if(flac_getAudioFormatAndTime(dc->file,af,&(cb->totalTime))<0) {
ERROR("\"%s\" doesn't seem to be a flac\n",dc->file);
diff --git a/src/flac_decode.h b/src/flac_decode.h
index 90b28b080..66c90ff4a 100644
--- a/src/flac_decode.h
+++ b/src/flac_decode.h
@@ -25,4 +25,6 @@
int flac_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc);
+int getFlacTotalTime(char * file);
+
#endif
diff --git a/src/libid3tag/config.h.in b/src/libid3tag/config.h.in
index ba35b4be9..b4f0f8997 100644
--- a/src/libid3tag/config.h.in
+++ b/src/libid3tag/config.h.in
@@ -72,8 +72,6 @@
/* Define to empty if `const' does not conform to ANSI C. */
#undef const
-/* Define to `__inline__' or `__inline' if that's what the C compiler
- calls it, or to nothing if 'inline' is not supported under any name. */
-#ifndef __cplusplus
+/* Define as `__inline' if that's what the C compiler calls it, or to nothing
+ if it is not supported. */
#undef inline
-#endif
diff --git a/src/libmad/config.h.in b/src/libmad/config.h.in
index a29b58209..2a9671cd2 100644
--- a/src/libmad/config.h.in
+++ b/src/libmad/config.h.in
@@ -125,11 +125,9 @@
/* Define to empty if `const' does not conform to ANSI C. */
#undef const
-/* Define to `__inline__' or `__inline' if that's what the C compiler
- calls it, or to nothing if 'inline' is not supported under any name. */
-#ifndef __cplusplus
+/* Define as `__inline' if that's what the C compiler calls it, or to nothing
+ if it is not supported. */
#undef inline
-#endif
/* Define to `int' if <sys/types.h> does not define. */
#undef pid_t
diff --git a/src/mp3_decode.c b/src/mp3_decode.c
index 5898d074d..d588165b4 100644
--- a/src/mp3_decode.c
+++ b/src/mp3_decode.c
@@ -375,7 +375,7 @@ int getMp3TotalTime(char * file) {
initMp3DecodeData(&data);
if(decodeFirstFrame(&data)<0) ret = -1;
- else ret = data.totalTime;
+ else ret = data.totalTime+0.5;
mp3DecodeDataFinalize(&data);
return ret;
diff --git a/src/ogg_decode.c b/src/ogg_decode.c
index 0b75ce3b2..bcc0f6ee5 100644
--- a/src/ogg_decode.c
+++ b/src/ogg_decode.c
@@ -37,6 +37,25 @@
#define OGG_DECODE_USE_BIGENDIAN 0
#endif
+int getOggTotalTime(char * file) {
+ OggVorbis_File vf;
+ FILE * oggfp;
+ int totalTime;
+
+ if(!(oggfp = fopen(file,"r"))) return -1;
+
+ if(ov_open(oggfp, &vf, NULL, 0) < 0) {
+ fclose(oggfp);
+ return -1;
+ }
+
+ totalTime = ov_time_total(&vf,-1)+0.5;
+
+ ov_clear(&vf);
+
+ return totalTime;
+}
+
int ogg_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc)
{
OggVorbis_File vf;
diff --git a/src/ogg_decode.h b/src/ogg_decode.h
index cbe13b275..8e4bd0fe3 100644
--- a/src/ogg_decode.h
+++ b/src/ogg_decode.h
@@ -25,4 +25,6 @@
int ogg_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc);
+int getOggTotalTime(char * file);
+
#endif
diff --git a/src/song.c b/src/song.c
index 01335d8f8..56032c79f 100644
--- a/src/song.c
+++ b/src/song.c
@@ -23,6 +23,11 @@
#include "utils.h"
#include "tag.h"
#include "log.h"
+#include "mp3_decode.h"
+#include "audiofile_decode.h"
+#include "ogg_decode.h"
+#include "flac_decode.h"
+#include "path.h"
#define SONG_KEY "key: "
#define SONG_FILE "file: "
@@ -38,32 +43,45 @@
Song * newSong(char * utf8file) {
Song * song = malloc(sizeof(Song));
+ song->time = -1;
song->utf8file = strdup(utf8file);
+
+ if(0);
#ifdef HAVE_OGG
- if((song->mtime = isOgg(utf8file))) {
- song->tag = oggTagDup(utf8file);
- return song;
+ else if((song->mtime = isOgg(utf8file))) {
+ song->time = getOggTotalTime(
+ rmp2amp(utf8ToFsCharset(utf8file)));
+ if(song->time>=0) song->tag = oggTagDup(utf8file);
}
#endif
#ifdef HAVE_FLAC
- if((song->mtime = isFlac(utf8file))) {
- song->tag = flacTagDup(utf8file);
- return song;
+ else if((song->mtime = isFlac(utf8file))) {
+ song->time = getFlacTotalTime(
+ rmp2amp(utf8ToFsCharset(utf8file)));
+ if(song->time>=0) song->tag = flacTagDup(utf8file);
}
#endif
#ifdef HAVE_MAD
- if((song->mtime = isMp3(utf8file))) {
- song->tag = mp3TagDup(utf8file);
- return song;
+ else if((song->mtime = isMp3(utf8file))) {
+ song->time = getMp3TotalTime(
+ rmp2amp(utf8ToFsCharset(utf8file)));
+ if(song->time>=0) song->tag = mp3TagDup(utf8file);
}
#endif
#ifdef HAVE_AUDIOFILE
- if((song->mtime = isWave(utf8file))) {
- song->tag = audiofileTagDup(utf8file);
- return song;
+ else if((song->mtime = isWave(utf8file))) {
+ song->time = getAudiofileTotalTime(
+ rmp2amp(utf8ToFsCharset(utf8file)));
+ if(song->time>=0) song->tag = audiofileTagDup(utf8file);
}
#endif
+
+ if(song->time<0) {
+ freeSong(song);
+ song = NULL;
+ }
+
return song;
}
@@ -78,14 +96,13 @@ SongList * newSongList() {
}
Song * addSongToList(SongList * list, char * key, char * utf8file) {
- Song * song;
+ Song * song = NULL;
if(isMusic(utf8file)) {
song = newSong(utf8file);
}
- else {
- return NULL;
- }
+
+ if(song==NULL) return NULL;
insertInList(list,key,(void *)song);
@@ -99,6 +116,8 @@ void freeSongList(SongList * list) {
int printSongInfo(FILE * fp, Song * song) {
myfprintf(fp,"%s%s\n",SONG_FILE,song->utf8file);
+ if(song->time>=0) myfprintf(fp,"%s%i\n",SONG_TIME,song->time);
+
if(song->tag) printMpdTag(fp,song->tag);
return 0;
@@ -172,8 +191,7 @@ void readSongInfoIntoList(FILE * fp, SongList * list) {
song->tag->title = strdup(&(buffer[strlen(SONG_TITLE)]));
}
else if(0==strncmp(SONG_TIME,buffer,strlen(SONG_TIME))) {
- if(!song->tag) song->tag = newMpdTag();
- song->tag->time = atoi(&(buffer[strlen(SONG_TIME)]));
+ song->time = atoi(&(buffer[strlen(SONG_TIME)]));
}
else if(0==strncmp(SONG_MTIME,buffer,strlen(SONG_MTIME))) {
song->mtime = atoi(&(buffer[strlen(SONG_TITLE)]));
diff --git a/src/song.h b/src/song.h
index 768a6aa04..a4f744428 100644
--- a/src/song.h
+++ b/src/song.h
@@ -32,6 +32,7 @@ typedef struct _Song {
char * utf8file;
MpdTag * tag;
time_t mtime;
+ int time;
} Song;
typedef List SongList;
diff --git a/src/tag.c b/src/tag.c
index f7bd5d39d..d1132b2f8 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -20,8 +20,6 @@
#include "path.h"
#include "myfprintf.h"
#include "sig_handlers.h"
-#include "mp3_decode.h"
-#include "audiofile_decode.h"
#include "utils.h"
#include <sys/stat.h>
@@ -50,7 +48,6 @@ void printMpdTag(FILE * fp, MpdTag * tag) {
if(tag->album) myfprintf(fp,"Album: %s\n",tag->album);
if(tag->track) myfprintf(fp,"Track: %s\n",tag->track);
if(tag->title) myfprintf(fp,"Title: %s\n",tag->title);
- if(tag->time>=0) myfprintf(fp,"Time: %i\n",tag->time);
}
#ifdef HAVE_ID3TAG
@@ -138,13 +135,7 @@ MpdTag * id3Dup(char * utf8filename) {
#ifdef HAVE_AUDIOFILE
MpdTag * audiofileTagDup(char * utf8file) {
MpdTag * ret = NULL;
- int time = getAudiofileTotalTime(rmp2amp(utf8ToFsCharset(utf8file)));
- if (time>=0) {
- if(!ret) ret = newMpdTag();
- ret->time = time;
- }
-
return ret;
}
#endif
@@ -152,17 +143,9 @@ MpdTag * audiofileTagDup(char * utf8file) {
#ifdef HAVE_MAD
MpdTag * mp3TagDup(char * utf8file) {
MpdTag * ret = NULL;
- int time;
ret = id3Dup(utf8file);
- time = getMp3TotalTime(rmp2amp(utf8ToFsCharset(utf8file)));
-
- if(time>=0) {
- if(!ret) ret = newMpdTag();
- ret->time = time;
- }
-
return ret;
}
#endif
@@ -188,7 +171,6 @@ MpdTag * oggTagDup(char * utf8file) {
}
ret = newMpdTag();
- ret->time = (int)(ov_time_total(&vf,-1)+0.5);
comments = ov_comment(&vf,-1)->user_comments;
@@ -315,10 +297,6 @@ MpdTag * flacMetadataDup(char * utf8file, int * vorbisCommentFound) {
}
else if(block->type == FLAC__METADATA_TYPE_STREAMINFO) {
if(!ret) ret = newMpdTag();
- ret->time = ((float)block->data.stream_info.
- total_samples) /
- block->data.stream_info.sample_rate +
- 0.5;
}
FLAC__metadata_object_delete(block);
} while(FLAC__metadata_simple_iterator_next(it));
@@ -333,14 +311,9 @@ MpdTag * flacTagDup(char * utf8file) {
int foundVorbisComment = 0;
ret = flacMetadataDup(utf8file,&foundVorbisComment);
- if(!ret) return NULL;
if(!foundVorbisComment) {
- MpdTag * temp = id3Dup(utf8file);
- if(temp) {
- temp->time = ret->time;
- freeMpdTag(ret);
- ret = temp;
- }
+ if(ret) freeMpdTag(ret);
+ ret = id3Dup(utf8file);
}
return ret;
@@ -353,7 +326,6 @@ MpdTag * newMpdTag() {
ret->artist = NULL;
ret->title = NULL;
ret->track = NULL;
- ret->time = -1;
return ret;
}
@@ -374,7 +346,6 @@ MpdTag * mpdTagDup(MpdTag * tag) {
ret->album = strdup(tag->album);
ret->title = strdup(tag->title);
ret->track = strdup(tag->track);
- ret->time = tag->time;
}
return ret;
diff --git a/src/tag.h b/src/tag.h
index 0f176449f..2e2996f8a 100644
--- a/src/tag.h
+++ b/src/tag.h
@@ -26,7 +26,6 @@ typedef struct _MpdTag {
char * album;
char * track;
char * title;
- int time;
} MpdTag;
MpdTag * newMpdTag();