Package: daapd
Version: 0.2.3d-4
Severity: wishlist
Tags: patch

I've added simple Ogg Vorbis support into daapd. The patch is
attached. It works fine for me using an embedded client (wmamp), but
unfortunately I have no other clients to test with at the moment. I'm
hoping that as the maintainer you might... :-)

-- 
Steve McIntyre, Cambridge, UK.                                [EMAIL PROTECTED]
Into the distance, a ribbon of black
Stretched to the point of no turning back
diff -uNrbB daapd-0.2.3d/daapd.cc daapd-0.2.3d.steve/daapd.cc
--- daapd-0.2.3d/daapd.cc       2004-09-08 02:15:49.000000000 +0100
+++ daapd-0.2.3d.steve/daapd.cc 2005-02-02 22:33:17.000000000 +0000
@@ -351,6 +351,10 @@
 }
 
 int sendDatabaseItem( httpd *server, const Song& song ) {
+    if (song.format == "ogg")
+        httpdSetContentType ( server, "application/ogg" );
+    else if (song.format == "mp3")
+        httpdSetContentType ( server, "audio/mpeg" );
        httpdSendFile( server, (char *) song.path.c_str(), 
httpdRequestContentRange( server ) );
        
        return 0;
diff -uNrbB daapd-0.2.3d/daaplib/src/makefile 
daapd-0.2.3d.steve/daaplib/src/makefile
diff -uNrbB daapd-0.2.3d/db.cc daapd-0.2.3d.steve/db.cc
--- daapd-0.2.3d/db.cc  2004-09-08 02:17:58.000000000 +0100
+++ daapd-0.2.3d.steve/db.cc    2005-02-02 22:30:19.000000000 +0000
@@ -33,6 +33,8 @@
 
 #include <id3tag.h>
 
+pthread_mutex_t vf_mutex = PTHREAD_MUTEX_INITIALIZER;
+
 #ifdef __APPLE__
        #include <malloc/malloc.h>
 #else
@@ -216,6 +218,96 @@
        pthread_mutex_unlock(&dbLock);
 }
 
+int Database::getVorbisTag( vorbis_comment* vc, char *label, std::string& out) 
{
+    char *s;
+
+    if (vc) {
+        s = vorbis_comment_query(vc, label, 0);
+        if (s) {
+            out = s;
+            return 0;
+        }
+    }
+    return -1;
+}
+
+void Database::addOgg( std::string& path, struct stat sb ) {
+
+       Song *song = new Song;
+       std::string s;
+    FILE *fh = NULL;
+    OggVorbis_File vf;
+    vorbis_info *vi;
+    vorbis_comment *comment;
+
+       if ( verbose ) printf("\t addOgg on '%s'\n", path.c_str());
+
+       song->present = true;
+       song->path = path;
+       song->format = "ogg";
+
+       song->size = sb.st_size;
+       song->dateadded = time( NULL );
+
+#ifdef __sgi__
+    song->datemodified = sb.st_mtim.tv_sec;
+#elif defined(__linux__)
+    song->datemodified = sb.st_mtime;
+#elif defined(__sun__)
+    song->datemodified = sb.st_mtime;
+#else
+    song->datemodified = sb.st_mtimespec.tv_sec;
+#endif
+
+    fh = fopen(path.c_str(), "r");
+    if (fh != 0) {
+        pthread_mutex_lock(&vf_mutex);
+        if (ov_open(fh, &vf, NULL, 0) == 0) {
+            song->time = (int)ov_time_total(&vf, -1);
+            if ((vi = ov_info(&vf, 0)) != NULL) {
+                song->bitrate = vi->bitrate_nominal/1000;
+                song->samplerate = vi->rate;
+            }
+            if ((comment = ov_comment(&vf, -1))) {
+                if (getVorbisTag(comment, "title", s) == 0)
+                    song->name = s;
+                if (getVorbisTag(comment, "album", s) == 0)
+                    song->album = s;
+                if (getVorbisTag(comment, "artist", s) == 0)
+                    song->artist = s;
+                // No common "composer" field
+                if (getVorbisTag(comment, "comment", s) == 0)
+                    song->comment = s;
+                if (getVorbisTag(comment, "description", s) == 0)
+                    song->description = s;
+                if (getVorbisTag(comment, "genre", s) == 0)
+                    song->genre = s;
+                // Ignoring "year" for now
+                if (getVorbisTag(comment, "tracknumber", s) == 0)
+                    song->tracknumber = strtol(s.c_str(), NULL, 10);           
    
+            }
+            ov_clear(&vf);
+        }
+        else
+            fclose(fh);
+        pthread_mutex_unlock(&vf_mutex);
+    }
+
+       if( song->name == "" ) {
+               // no song title in id3 tags
+               // get it from file name
+               ComponentVect comp; 
+               comp = *tokenizeString( comp, path.c_str(), '/' );
+               song->name = comp[ comp.size() - 1 ];
+       }
+
+       song->starttime = 0;
+       song->stoptime = song->time;
+
+       pthread_mutex_lock(&dbLock);
+       songs.add( song, path );
+       pthread_mutex_unlock(&dbLock);
+}
 
 void Database::addTagless( std::string& path, struct stat sb, int fileType ) {
         Song *song = new Song;
@@ -443,6 +535,9 @@
                        } else if( strncasecmp( pointPos, ".m4p", 4 ) == 0)  {
                                close( fDesc );
                                return( DAAP_M4A );
+                       } else if( strncasecmp( pointPos, ".ogg", 4 ) == 0)  {
+                               close( fDesc );
+                               return( DAAP_OGG );
                        }
                }
        }
@@ -469,6 +564,8 @@
                } else if( strncmp( (const char *)buffer, "RIFF", 4 ) == 0 ) {
                        if( strncmp( (const char *)buffer+8, "WAVE", 4 ) == 0 ) 
                                type = DAAP_WAV;
+               } else if( strncmp( (const char *)buffer, "OggS", 4 ) == 0 ) {
+            type = DAAP_OGG;
                }
        }
        
@@ -500,6 +597,8 @@
                                addMp3( path, sb );
                        } else if( fileType == DAAP_M4A ) {
                                addM4a( path, sb );
+                       } else if( fileType == DAAP_OGG ) {
+                               addOgg( path, sb );
                        } else {
                                addTagless( path, sb, fileType );
                        }
@@ -512,6 +611,8 @@
                                addMp3( path, sb );
                        } else if( fileType == DAAP_M4A ) {
                                addM4a( path, sb );
+                       } else if( fileType == DAAP_OGG ) {
+                               addOgg( path, sb );
                        } else {
                                addTagless( path, sb, fileType );
                        }
@@ -546,7 +647,12 @@
        
                                if( fileType == DAAP_DIRECTORY ) {
                                        addDirectory( fileName );
-                               } else if( fileType == DAAP_MP3 || fileType == 
DAAP_AIFF || fileType == DAAP_WAV || fileType == DAAP_SD2 || fileType == 
DAAP_M4A ) {
+                               } else if( fileType == DAAP_MP3 || 
+                           fileType == DAAP_AIFF || 
+                           fileType == DAAP_WAV || 
+                           fileType == DAAP_SD2 || 
+                           fileType == DAAP_M4A || 
+                           fileType == DAAP_OGG) {
                                        addRegularFile( fileName, fileType );
                                }
                        }
diff -uNrbB daapd-0.2.3d/makefile daapd-0.2.3d.steve/makefile
--- daapd-0.2.3d/makefile       2004-09-08 02:17:58.000000000 +0100
+++ daapd-0.2.3d.steve/makefile 2005-01-29 23:26:32.000000000 +0000
@@ -13,15 +13,15 @@
 TARGET = daapd
 DEPS = daaplib_ libhttpd_
 OBJS = daapd.o db.o dboutput.o songcache.o parsemp3.o
-LIBS = -ldaaplib -lhttpd-persistent -lid3tag -lz -lpthread 
-LIBPATH = -L. -L./daaplib/src -L./libhttpd/src  -L/usr/local/lib
-INCPATH = -I. -I./daaplib/include -I./libhttpd/src  -I/usr/local/include
-DEPLOY = /usr/local
+LIBS = -ldaaplib -lhttpd-persistent -lid3tag -lz -lpthread -lvorbis 
-lvorbisfile
+LIBPATH = -L. -L./daaplib/src -L./libhttpd/src  
+INCPATH = -I. -I./daaplib/include -I./libhttpd/src  
+DEPLOY = $(DESTDIR)/usr
 CFLAGS = -Wall -Wno-multichar
 
 # HOWL
 ifeq ($(HOWL_ENABLE),1)
-       HOWLDIRS := $(sort $(wildcard /usr/local/include/howl*) )
+       HOWLDIRS := $(sort $(wildcard /usr/include/howl*) )
 ifeq ($(words $(HOWLDIRS) ), 0)
 $(error howl not found in /usr/local/include. Install howl or disable it in 
the makefile)
 endif
diff -uNrbB daapd-0.2.3d/types.h daapd-0.2.3d.steve/types.h
--- daapd-0.2.3d/types.h        2005-02-02 22:32:19.000000000 +0000
+++ daapd-0.2.3d.steve/types.h  2005-02-02 22:30:39.000000000 +0000
@@ -34,6 +34,7 @@
 #include <pthread.h>
 
 #include <id3tag.h>
+#include <vorbis/vorbisfile.h>
 #include <daap/tagoutput.h>
 
 #include "dboutput.h"
@@ -158,6 +159,7 @@
 const int DAAP_WAV             = 5;
 const int DAAP_SD2             = 6;
 const int DAAP_M4A             = 7;
+const int DAAP_OGG     = 8;
 
 // utility stuff
 
@@ -301,7 +302,11 @@
 
                        if( fileType == DAAP_DIRECTORY ) {
                                addDirectory( (*dirs)[i] );
-                       } else if( fileType == DAAP_MP3 || fileType == 
DAAP_AIFF || fileType == DAAP_WAV || fileType == DAAP_AIFF ) {
+                       } else if( fileType == DAAP_MP3 ||
+                       fileType == DAAP_AIFF ||
+                       fileType == DAAP_WAV ||
+                       fileType == DAAP_AIFF ||
+                       fileType == DAAP_OGG ) {
                                addRegularFile( (*dirs)[i], fileType );
                        }
                }
@@ -379,7 +384,9 @@
 
        int getId3TextFrame( id3_tag* tag, const char* frameId, std::string& 
out, bool allStrings );
        int getId3Comment( id3_tag* tag, std::string& out);
+       int getVorbisTag( vorbis_comment* vc, char *label, std::string& out);
        void addMp3( std::string& path, struct stat sb );
+       void addOgg( std::string& path, struct stat sb );
        void addM4a( std::string& path, struct stat sb );
        void addTagless( std::string& path, struct stat sb, int fileType);
        int getFileType( std::string& fileName );

Attachment: signature.asc
Description: Digital signature

Reply via email to