summaryrefslogtreecommitdiff
path: root/apps/plugins/pictureflow/pictureflow.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/pictureflow/pictureflow.c')
-rw-r--r--apps/plugins/pictureflow/pictureflow.c223
1 files changed, 20 insertions, 203 deletions
diff --git a/apps/plugins/pictureflow/pictureflow.c b/apps/plugins/pictureflow/pictureflow.c
index b231390420..999ed2563f 100644
--- a/apps/plugins/pictureflow/pictureflow.c
+++ b/apps/plugins/pictureflow/pictureflow.c
@@ -33,6 +33,7 @@
33#include "lib/grey.h" 33#include "lib/grey.h"
34#include "lib/mylcd.h" 34#include "lib/mylcd.h"
35#include "lib/feature_wrappers.h" 35#include "lib/feature_wrappers.h"
36#include "lib/id3.h"
36 37
37/******************************* Globals ***********************************/ 38/******************************* Globals ***********************************/
38static fb_data *lcd_fb; 39static fb_data *lcd_fb;
@@ -44,6 +45,7 @@ static fb_data *lcd_fb;
44 45
45#if PF_PLAYBACK_CAPABLE 46#if PF_PLAYBACK_CAPABLE
46#include "lib/playback_control.h" 47#include "lib/playback_control.h"
48#include "lib/mul_id3.h"
47#endif 49#endif
48 50
49#define PF_PREV ACTION_STD_PREV 51#define PF_PREV ACTION_STD_PREV
@@ -397,26 +399,6 @@ struct track_data {
397#endif 399#endif
398}; 400};
399 401
400#if PF_PLAYBACK_CAPABLE
401struct multiple_tracks_id3 {
402 unsigned long length;
403 unsigned long filesize;
404 unsigned long frequency;
405 unsigned int artist_hash;
406 unsigned int composer_hash;
407 unsigned int albumartist_hash;
408 unsigned int grouping_hash;
409 unsigned int comment_hash;
410 unsigned int album_hash;
411 unsigned int genre_hash;
412 unsigned int codectype;
413 unsigned int bitrate;
414 bool filesize_ovf;
415 bool length_ovf;
416 bool vbr;
417};
418#endif
419
420struct rect { 402struct rect {
421 int left; 403 int left;
422 int right; 404 int right;
@@ -2096,15 +2078,13 @@ static inline void free_borrowed_tracks(void)
2096static bool get_albumart_for_index_from_db(const int slide_index, char *buf, 2078static bool get_albumart_for_index_from_db(const int slide_index, char *buf,
2097 int buflen) 2079 int buflen)
2098{ 2080{
2099 if ( slide_index == -1 ) 2081 bool ret;
2100 { 2082 if (slide_index == -1)
2101 rb->strlcpy( buf, EMPTY_SLIDE, buflen ); 2083 rb->strlcpy(buf, EMPTY_SLIDE, buflen);
2102 }
2103 2084
2104 if (tcs.valid || !rb->tagcache_search(&tcs, tag_filename)) 2085 if (tcs.valid || !rb->tagcache_search(&tcs, tag_filename))
2105 return false; 2086 return false;
2106 2087
2107 bool result;
2108 /* find the first track of the album */ 2088 /* find the first track of the album */
2109 rb->tagcache_search_add_filter(&tcs, tag_album, 2089 rb->tagcache_search_add_filter(&tcs, tag_album,
2110 pf_idx.album_index[slide_index].seek); 2090 pf_idx.album_index[slide_index].seek);
@@ -2112,35 +2092,12 @@ static bool get_albumart_for_index_from_db(const int slide_index, char *buf,
2112 rb->tagcache_search_add_filter(&tcs, tag_albumartist, 2092 rb->tagcache_search_add_filter(&tcs, tag_albumartist,
2113 pf_idx.album_index[slide_index].artist_seek); 2093 pf_idx.album_index[slide_index].artist_seek);
2114 2094
2115 if ( rb->tagcache_get_next(&tcs) ) { 2095 ret = rb->tagcache_get_next(&tcs) &&
2116 int fd; 2096 retrieve_id3(&id3, tcs.result, true) &&
2117 2097 search_albumart_files(&id3, ":", buf, buflen);
2118#if defined(HAVE_TC_RAMCACHE) && defined(HAVE_DIRCACHE)
2119 if (rb->tagcache_fill_tags(&id3, tcs.result))
2120 {
2121 rb->strlcpy(id3.path, tcs.result, sizeof(id3.path));
2122 }
2123 else
2124#endif
2125 {
2126 fd = rb->open(tcs.result, O_RDONLY);
2127 if (fd) {
2128 rb->get_metadata(&id3, fd, tcs.result);
2129 rb->close(fd);
2130 }
2131 }
2132 2098
2133 if ( search_albumart_files(&id3, ":", buf, buflen) )
2134 result = true;
2135 else
2136 result = false;
2137 }
2138 else {
2139 /* did not find a matching track */
2140 result = false;
2141 }
2142 rb->tagcache_search_finish(&tcs); 2099 rb->tagcache_search_finish(&tcs);
2143 return result; 2100 return ret;
2144} 2101}
2145 2102
2146/** 2103/**
@@ -4032,145 +3989,21 @@ static void select_prev_album(void)
4032} 3989}
4033 3990
4034#if PF_PLAYBACK_CAPABLE 3991#if PF_PLAYBACK_CAPABLE
4035static void collect_id3(struct multiple_tracks_id3 *mul_id3, bool is_first_track)
4036{
4037 if (is_first_track)
4038 {
4039 mul_id3->artist_hash = mfnv(id3.artist);
4040 mul_id3->album_hash = mfnv(id3.album);
4041 mul_id3->genre_hash = mfnv(id3.genre_string);
4042 mul_id3->composer_hash = mfnv(id3.composer);
4043 mul_id3->albumartist_hash = mfnv(id3.albumartist);
4044 mul_id3->grouping_hash = mfnv(id3.grouping);
4045 mul_id3->comment_hash = mfnv(id3.comment);
4046 mul_id3->codectype = id3.codectype;
4047 mul_id3->vbr = id3.vbr;
4048 mul_id3->bitrate = id3.bitrate;
4049 mul_id3->frequency = id3.frequency;
4050 }
4051 else
4052 {
4053 if (mul_id3->artist_hash && (mfnv(id3.artist) != mul_id3->artist_hash))
4054 mul_id3->artist_hash = 0;
4055 if (mul_id3->album_hash && (mfnv(id3.album) != mul_id3->album_hash))
4056 mul_id3->album_hash = 0;
4057 if (mul_id3->genre_hash && (mfnv(id3.genre_string) != mul_id3->genre_hash))
4058 mul_id3->genre_hash = 0;
4059 if (mul_id3->composer_hash && (mfnv(id3.composer) != mul_id3->composer_hash))
4060 mul_id3->composer_hash = 0;
4061 if (mul_id3->albumartist_hash && (mfnv(id3.albumartist) !=
4062 mul_id3->albumartist_hash))
4063 mul_id3->albumartist_hash = 0;
4064 if (mul_id3->grouping_hash && (mfnv(id3.grouping) != mul_id3->grouping_hash))
4065 mul_id3->grouping_hash = 0;
4066 if (mul_id3->comment_hash && (mfnv(id3.comment) != mul_id3->comment_hash))
4067 mul_id3->comment_hash = 0;
4068
4069 if (mul_id3->codectype && (id3.codectype != mul_id3->codectype))
4070 mul_id3->codectype = AFMT_UNKNOWN;
4071 if (mul_id3->bitrate && (id3.bitrate != mul_id3->bitrate ||
4072 id3.vbr != mul_id3->vbr))
4073 mul_id3->bitrate = 0;
4074 if (mul_id3->frequency && (id3.frequency != mul_id3->frequency))
4075 mul_id3->frequency = 0;
4076 }
4077
4078 if (ULONG_MAX - mul_id3->length < id3.length)
4079 {
4080 mul_id3->length_ovf = true;
4081 mul_id3->length = 0;
4082 }
4083 else if (!mul_id3->length_ovf)
4084 mul_id3->length += id3.length;
4085
4086 if (INT_MAX - mul_id3->filesize < id3.filesize) /* output_dyn_value expects int */
4087 {
4088 mul_id3->filesize_ovf = true;
4089 mul_id3->filesize = 0;
4090 }
4091 else if (!mul_id3->filesize_ovf)
4092 mul_id3->filesize += id3.filesize;
4093}
4094
4095
4096static void write_id3_mul_tracks(struct multiple_tracks_id3 *mul_id3)
4097{
4098 id3.path[0] = '\0';
4099 id3.title = NULL;
4100 if (!mul_id3->artist_hash)
4101 id3.artist = NULL;
4102 if (!mul_id3->album_hash)
4103 id3.album = NULL;
4104 if (!mul_id3->genre_hash)
4105 id3.genre_string = NULL;
4106 if (!mul_id3->composer_hash)
4107 id3.composer = NULL;
4108 if (!mul_id3->albumartist_hash)
4109 id3.albumartist = NULL;
4110 if (!mul_id3->grouping_hash)
4111 id3.grouping = NULL;
4112 if (!mul_id3->comment_hash)
4113 id3.comment = NULL;
4114 id3.disc_string = NULL;
4115 id3.track_string = NULL;
4116 id3.year_string = NULL;
4117 id3.year = pf_idx.album_index[center_index].year;
4118 id3.length = mul_id3->length;
4119 id3.filesize = mul_id3->filesize;
4120 id3.frequency = mul_id3->frequency;
4121 id3.bitrate = mul_id3->bitrate;
4122 id3.codectype = mul_id3->codectype;
4123 id3.vbr = mul_id3->vbr;
4124 id3.discnum = 0;
4125 id3.tracknum = 0;
4126 id3.track_level = 0;
4127 id3.album_level = 0;
4128}
4129
4130static void init_mul_id3(struct multiple_tracks_id3 *mul_id3)
4131{
4132 mul_id3->artist_hash = 0;
4133 mul_id3->album_hash = 0;
4134 mul_id3->genre_hash = 0;
4135 mul_id3->composer_hash = 0;
4136 mul_id3->albumartist_hash = 0;
4137 mul_id3->grouping_hash = 0;
4138 mul_id3->comment_hash = 0;
4139 mul_id3->codectype = 0;
4140 mul_id3->vbr = false;
4141 mul_id3->bitrate = 0;
4142 mul_id3->frequency = 0;
4143 mul_id3->length = 0;
4144 mul_id3->filesize = 0;
4145 mul_id3->length_ovf = false;
4146 mul_id3->filesize_ovf = false;
4147}
4148
4149static int show_id3_info(const char *selected_file) 3992static int show_id3_info(const char *selected_file)
4150{ 3993{
4151 int fd, i; 3994 int i;
4152 unsigned long last_tick; 3995 unsigned long last_tick;
4153 const char *file_name; 3996 const char *file_name;
4154 bool id3_retrieval_successful;
4155 bool is_multiple_tracks = insert_whole_album && pf_tracks.count > 1; 3997 bool is_multiple_tracks = insert_whole_album && pf_tracks.count > 1;
4156 struct multiple_tracks_id3 mul_id3;
4157 3998
4158 init_mul_id3(&mul_id3); 3999 init_mul_id3();
4159 4000
4160 last_tick = *(rb->current_tick) + HZ/2; 4001 last_tick = *(rb->current_tick) + HZ/2;
4161 rb->splash_progress_set_delay(HZ / 2); /* wait 1/2 sec before progress */ 4002 rb->splash_progress_set_delay(HZ / 2); /* wait 1/2 sec before progress */
4162 i = 0; 4003 i = 0;
4163 do { 4004 do {
4164 id3_retrieval_successful = false;
4165 file_name = i == 0 ? selected_file : get_track_filename(i); 4005 file_name = i == 0 ? selected_file : get_track_filename(i);
4166 fd = rb->open(file_name, O_RDONLY); 4006 if (!retrieve_id3(&id3, file_name, false))
4167 if (fd >= 0)
4168 {
4169 if (rb->get_metadata(&id3, fd, file_name))
4170 id3_retrieval_successful = true;
4171 rb->close(fd);
4172 }
4173 if (!id3_retrieval_successful)
4174 return 0; 4007 return 0;
4175 4008
4176 if (is_multiple_tracks) 4009 if (is_multiple_tracks)
@@ -4184,13 +4017,13 @@ static int show_id3_info(const char *selected_file)
4184 last_tick = *(rb->current_tick); 4017 last_tick = *(rb->current_tick);
4185 } 4018 }
4186 4019
4187 collect_id3(&mul_id3, i == 0); 4020 collect_id3(&id3, i == 0);
4188 rb->yield(); 4021 rb->yield();
4189 } 4022 }
4190 } while (++i < pf_tracks.count && is_multiple_tracks); 4023 } while (++i < pf_tracks.count && is_multiple_tracks);
4191 4024
4192 if (is_multiple_tracks) 4025 if (is_multiple_tracks)
4193 write_id3_mul_tracks(&mul_id3); 4026 write_id3_mul_tracks(&id3);
4194 4027
4195 return rb->browse_id3(&id3, 0, 0, NULL) ? PLUGIN_USB_CONNECTED : 0; 4028 return rb->browse_id3(&id3, 0, 0, NULL) ? PLUGIN_USB_CONNECTED : 0;
4196} 4029}
@@ -4520,31 +4353,15 @@ static void draw_album_text(void)
4520 4353
4521static void set_initial_slide(const char* selected_file) 4354static void set_initial_slide(const char* selected_file)
4522{ 4355{
4523 if (selected_file == NULL) 4356 if (selected_file)
4357 set_current_slide(retrieve_id3(&id3, selected_file, true) ?
4358 id3_get_index(&id3) :
4359 pf_cfg.last_album);
4360 else
4524 set_current_slide(rb->audio_status() ? 4361 set_current_slide(rb->audio_status() ?
4525 id3_get_index(rb->audio_current_track()) : 4362 id3_get_index(rb->audio_current_track()) :
4526 pf_cfg.last_album); 4363 pf_cfg.last_album);
4527 else 4364
4528 {
4529#if defined(HAVE_TC_RAMCACHE) && defined(HAVE_DIRCACHE)
4530 if (rb->tagcache_fill_tags(&id3, selected_file))
4531 set_current_slide(id3_get_index(&id3));
4532 else
4533#endif
4534 {
4535 int fd = rb->open(selected_file, O_RDONLY);
4536 if (fd >= 0)
4537 {
4538 if (rb->get_metadata(&id3, fd, selected_file))
4539 set_current_slide(id3_get_index(&id3));
4540 else
4541 set_current_slide(pf_cfg.last_album);
4542 rb->close(fd);
4543 }
4544 else
4545 set_current_slide(pf_cfg.last_album);
4546 }
4547 }
4548} 4365}
4549 4366
4550/** 4367/**