From c4ca6527f0c58d770a069126d53688f704d556f1 Mon Sep 17 00:00:00 2001 From: Justin Maggard Date: Tue, 21 Apr 2009 02:50:45 +0000 Subject: [PATCH] * Invalidate the scanner cache when an inotify deletion takes place. --- inotify.c | 2 ++ metadata.c | 2 +- scanner.c | 19 +++++++++++-------- scanner.h | 2 ++ upnphttp.c | 13 ++++++++++--- upnphttp.h | 1 + 6 files changed, 27 insertions(+), 12 deletions(-) diff --git a/inotify.c b/inotify.c index c546830..17cff50 100644 --- a/inotify.c +++ b/inotify.c @@ -461,6 +461,8 @@ inotify_remove_file(const char * path) sqlite_int64 detailID = 0; int i, rows, children, ret = 1; + /* Invalidate the scanner cache so we don't insert files into non-existent containers */ + valid_cache = 0; sql = sqlite3_mprintf("SELECT ID from DETAILS where PATH = '%q'", path); if( (sql_get_table(db, sql, &result, &rows, NULL) == SQLITE_OK) ) { diff --git a/metadata.c b/metadata.c index 5130dc1..1ea4ecd 100644 --- a/metadata.c +++ b/metadata.c @@ -847,7 +847,7 @@ GetVideoMetadata(const char * path, char * name) if( !m.mime ) { if( strcmp(ctx->iformat->name, "avi") == 0 ) - asprintf(&m.mime, "video/x-msvideo"); + asprintf(&m.mime, "video/avi"); else if( strcmp(ctx->iformat->name, "mpegts") == 0 ) asprintf(&m.mime, "video/mpeg"); else if( strcmp(ctx->iformat->name, "mpeg") == 0 ) diff --git a/scanner.c b/scanner.c index a2752c3..856092c 100644 --- a/scanner.c +++ b/scanner.c @@ -35,6 +35,8 @@ #include "scanner.h" #include "log.h" +int valid_cache = 0; + struct virtual_item { int objectID; @@ -188,7 +190,7 @@ insert_containers(const char * name, const char *path, const char * refID, const { strcpy(date_taken, "Unknown Date"); } - if( strcmp(last_date.name, date_taken) == 0 ) + if( valid_cache && strcmp(last_date.name, date_taken) == 0 ) { last_date.objectID++; //DEBUG DPRINTF(E_DEBUG, L_SCANNER, "Using last date item: %s/%s/%X\n", last_date.name, last_date.parentID, last_date.objectID); @@ -218,14 +220,14 @@ insert_containers(const char * name, const char *path, const char * refID, const { strcpy(camera, "Unknown Camera"); } - if( strcmp(camera, last_cam.name) != 0 ) + if( !valid_cache || strcmp(camera, last_cam.name) != 0 ) { container = insert_container(camera, "3$13", NULL, "storageFolder", NULL, NULL, NULL, NULL); sprintf(last_cam.parentID, "3$13$%llX", container>>32); strncpy(last_cam.name, camera, 255); last_camdate.name[0] = '\0'; } - if( strcmp(last_camdate.name, date_taken) == 0 ) + if( valid_cache && strcmp(last_camdate.name, date_taken) == 0 ) { last_camdate.objectID++; //DEBUG DPRINTF(E_DEBUG, L_SCANNER, "Using last camdate item: %s/%s/%s/%X\n", camera, last_camdate.name, last_camdate.parentID, last_camdate.objectID); @@ -283,7 +285,7 @@ insert_containers(const char * name, const char *path, const char * refID, const if( album ) { - if( strcmp(album, last_album.name) == 0 ) + if( valid_cache && strcmp(album, last_album.name) == 0 ) { last_album.objectID++; //DEBUG DPRINTF(E_DEBUG, L_SCANNER, "Using last album item: %s/%s/%X\n", last_album.name, last_album.parentID, last_album.objectID); @@ -306,7 +308,7 @@ insert_containers(const char * name, const char *path, const char * refID, const } if( artist ) { - if( strcmp(artist, last_artist.name) != 0 ) + if( !valid_cache || strcmp(artist, last_artist.name) != 0 ) { container = insert_container(artist, "1$6", NULL, "person.musicArtist", NULL, genre, NULL, NULL); sprintf(last_artist.parentID, "1$6$%llX", container>>32); @@ -321,7 +323,7 @@ insert_containers(const char * name, const char *path, const char * refID, const { last_artistAlbumAll.objectID++; } - if( strcmp(album?album:"Unknown Album", last_artistAlbum.name) == 0 ) + if( valid_cache && strcmp(album?album:"Unknown Album", last_artistAlbum.name) == 0 ) { last_artistAlbum.objectID++; //DEBUG DPRINTF(E_DEBUG, L_SCANNER, "Using last artist/album item: %s/%s/%X\n", last_artist.name, last_artist.parentID, last_artist.objectID); @@ -351,7 +353,7 @@ insert_containers(const char * name, const char *path, const char * refID, const } if( genre ) { - if( strcmp(genre, last_genre.name) != 0 ) + if( !valid_cache || strcmp(genre, last_genre.name) != 0 ) { container = insert_container(genre, "1$5", NULL, "genre.musicGenre", NULL, NULL, NULL, NULL); sprintf(last_genre.parentID, "1$5$%llX", container>>32); @@ -366,7 +368,7 @@ insert_containers(const char * name, const char *path, const char * refID, const { last_genreArtistAll.objectID++; } - if( strcmp(artist?artist:"Unknown Artist", last_genreArtist.name) == 0 ) + if( valid_cache && strcmp(artist?artist:"Unknown Artist", last_genreArtist.name) == 0 ) { last_genreArtist.objectID++; } @@ -429,6 +431,7 @@ insert_containers(const char * name, const char *path, const char * refID, const return; } sqlite3_free_table(result); + valid_cache = 1; } int diff --git a/scanner.h b/scanner.h index d835dd5..004592b 100644 --- a/scanner.h +++ b/scanner.h @@ -15,6 +15,8 @@ #define VIDEO_DIR_ID "2$15" #define IMAGE_DIR_ID "3$16" +extern int valid_cache; + int is_video(const char * file); diff --git a/upnphttp.c b/upnphttp.c index 7d87a78..36e2443 100644 --- a/upnphttp.c +++ b/upnphttp.c @@ -214,6 +214,10 @@ intervening space) by either an integer or the keyword "infinite". */ { h->reqflags |= FLAG_TIMESEEK; } + else if(strncasecmp(line, "PlaySpeed.dlna.org", 18)==0) + { + h->reqflags |= FLAG_PLAYSPEED; + } else if(strncasecmp(line, "realTimeInfo.dlna.org", 21)==0) { h->reqflags |= FLAG_REALTIMEINFO; @@ -556,9 +560,10 @@ ProcessHttpQuery_upnphttp(struct upnphttp * h) DPRINTF(E_WARN, L_HTTP, "Invalid request, responding ERROR 400. (No Host specified in HTTP headers?)\n"); Send400(h); } - else if( h->reqflags & FLAG_TIMESEEK ) + else if( (h->reqflags & FLAG_TIMESEEK) || (h->reqflags & FLAG_PLAYSPEED) ) { - DPRINTF(E_WARN, L_HTTP, "DLNA TimeSeek requested, responding ERROR 406\n"); + DPRINTF(E_WARN, L_HTTP, "DLNA %s requested, responding ERROR 406\n", + h->reqflags&FLAG_TIMESEEK ? "TimeSeek" : "PlaySpeed"); Send406(h); } else if(strcmp("GET", HttpCommand) == 0) @@ -1353,7 +1358,7 @@ SendResp_dlnafile(struct upnphttp * h, char * object) goto error; } } - if( h->reqflags & FLAG_XFERINTERACTIVE ) + else if( h->reqflags & FLAG_XFERINTERACTIVE ) { if( h->reqflags & FLAG_REALTIMEINFO ) { @@ -1361,12 +1366,14 @@ SendResp_dlnafile(struct upnphttp * h, char * object) Send400(h); goto error; } +#if 1 // Some Samsung TVs do this? if( strncmp(last_file.mime, "image", 5) != 0 ) { DPRINTF(E_WARN, L_HTTP, "Client tried to specify transferMode as Interactive without an image!\n"); Send406(h); goto error; } +#endif } strftime(date, 30,"%a, %d %b %Y %H:%M:%S GMT" , gmtime(&curtime)); diff --git a/upnphttp.h b/upnphttp.h index 27c9858..f2bb35c 100644 --- a/upnphttp.h +++ b/upnphttp.h @@ -79,6 +79,7 @@ struct upnphttp { #define FLAG_CHUNKED 0x0100 #define FLAG_TIMESEEK 0x0200 #define FLAG_REALTIMEINFO 0x0400 +#define FLAG_PLAYSPEED 0x0800 #define FLAG_XFERSTREAMING 0x1000 #define FLAG_XFERINTERACTIVE 0x2000 #define FLAG_XFERBACKGROUND 0x4000