From 3c4c35b49c665d6ba84bb4ffefea267222c45ab8 Mon Sep 17 00:00:00 2001 From: Justin Maggard Date: Thu, 11 Dec 2014 17:03:35 -0800 Subject: [PATCH] upnpsoap: Use scaled thumbnails when rotation is needed Embedded thumbnails may have an undesirable orientation, so we should do our own scaling with inline rotation if the thumbnail image needs to be rotated. --- upnphttp.c | 2 ++ upnpsoap.c | 17 ++++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/upnphttp.c b/upnphttp.c index ce219e8..bf6f3d3 100644 --- a/upnphttp.c +++ b/upnphttp.c @@ -1646,6 +1646,8 @@ SendResp_resizedimg(struct upnphttp * h, char * object) } DPRINTF(E_INFO, L_HTTP, "Serving resized image for ObjectId: %lld [%s]\n", id, file_path); + if( rotate ) + DPRINTF(E_DEBUG, L_HTTP, "Rotating image %d degrees\n", rotate); switch( rotate ) { case 90: diff --git a/upnpsoap.c b/upnpsoap.c index d226272..04e7996 100644 --- a/upnpsoap.c +++ b/upnpsoap.c @@ -715,9 +715,12 @@ object_exists(const char *object) #define COLUMNS "o.DETAIL_ID, o.CLASS," \ " d.SIZE, d.TITLE, d.DURATION, d.BITRATE, d.SAMPLERATE, d.ARTIST," \ " d.ALBUM, d.GENRE, d.COMMENT, d.CHANNELS, d.TRACK, d.DATE, d.RESOLUTION," \ - " d.THUMBNAIL, d.CREATOR, d.DLNA_PN, d.MIME, d.ALBUM_ART, d.DISC " + " d.THUMBNAIL, d.CREATOR, d.DLNA_PN, d.MIME, d.ALBUM_ART, d.ROTATION, d.DISC " #define SELECT_COLUMNS "SELECT o.OBJECT_ID, o.PARENT_ID, o.REF_ID, " COLUMNS +#define NON_ZERO(x) (x && atoi(x)) +#define IS_ZERO(x) (!x || !atoi(x)) + static int callback(void *args, int argc, char **argv, char **azColName) { @@ -725,7 +728,7 @@ callback(void *args, int argc, char **argv, char **azColName) char *id = argv[0], *parent = argv[1], *refID = argv[2], *detailID = argv[3], *class = argv[4], *size = argv[5], *title = argv[6], *duration = argv[7], *bitrate = argv[8], *sampleFrequency = argv[9], *artist = argv[10], *album = argv[11], *genre = argv[12], *comment = argv[13], *nrAudioChannels = argv[14], *track = argv[15], *date = argv[16], *resolution = argv[17], - *tn = argv[18], *creator = argv[19], *dlna_pn = argv[20], *mime = argv[21], *album_art = argv[22]; + *tn = argv[18], *creator = argv[19], *dlna_pn = argv[20], *mime = argv[21], *album_art = argv[22], *rotate = argv[23]; char dlna_buf[128]; const char *ext; struct string_s *str = passed_args->str; @@ -905,7 +908,7 @@ callback(void *args, int argc, char **argv, char **azColName) if( strncmp(id, MUSIC_PLIST_ID, strlen(MUSIC_PLIST_ID)) == 0 ) { track = strrchr(id, '$')+1; } - if( track && atoi(track) && (passed_args->filter & FILTER_UPNP_ORIGINALTRACKNUMBER) ) { + if( NON_ZERO(track) && (passed_args->filter & FILTER_UPNP_ORIGINALTRACKNUMBER) ) { ret = strcatf(str, "<upnp:originalTrackNumber>%s</upnp:originalTrackNumber>", track); } if( passed_args->filter & FILTER_RES ) { @@ -923,7 +926,7 @@ callback(void *args, int argc, char **argv, char **azColName) if( srcw > 640 || srch > 480 ) add_resized_res(srcw, srch, 640, 480, "JPEG_SM", detailID, passed_args); } - if( !(passed_args->flags & FLAG_RESIZE_THUMBS) && tn && atoi(tn) ) { + if( !(passed_args->flags & FLAG_RESIZE_THUMBS) && NON_ZERO(tn) && IS_ZERO(rotate) ) { ret = strcatf(str, "<res protocolInfo=\"http-get:*:%s:%s\">" "http://%s:%d/Thumbnails/%s.jpg" "</res>", @@ -1022,7 +1025,7 @@ callback(void *args, int argc, char **argv, char **azColName) } } } - if( album_art && atoi(album_art) ) + if( NON_ZERO(album_art) ) { /* Video and audio album art is handled differently */ if( *mime == 'v' && (passed_args->filter & FILTER_RES) && !(passed_args->flags & FLAG_MS_PFS) ) { @@ -1044,7 +1047,7 @@ callback(void *args, int argc, char **argv, char **azColName) ret = strcatf(str, "<upnp:album>%s</upnp:album>", "[No Keywords]"); /* EVA2000 doesn't seem to handle embedded thumbnails */ - if( !(passed_args->flags & FLAG_RESIZE_THUMBS) && tn && atoi(tn) ) { + if( !(passed_args->flags & FLAG_RESIZE_THUMBS) && NON_ZERO(tn) && IS_ZERO(rotate) ) { ret = strcatf(str, "<upnp:albumArtURI>" "http://%s:%d/Thumbnails/%s.jpg" "</upnp:albumArtURI>", @@ -1091,7 +1094,7 @@ callback(void *args, int argc, char **argv, char **azColName) if( artist && (passed_args->filter & FILTER_UPNP_ARTIST) ) { ret = strcatf(str, "<upnp:artist>%s</upnp:artist>", artist); } - if( album_art && atoi(album_art) && (passed_args->filter & FILTER_UPNP_ALBUMARTURI) ) { + if( NON_ZERO(album_art) && (passed_args->filter & FILTER_UPNP_ALBUMARTURI) ) { ret = strcatf(str, "<upnp:albumArtURI "); if( passed_args->filter & FILTER_UPNP_ALBUMARTURI_DLNA_PROFILEID ) { ret = strcatf(str, "dlna:profileID=\"JPEG_TN\" xmlns:dlna=\"urn:schemas-dlna-org:metadata-1-0/\"");