diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/plugins/pictureflow/pictureflow.c | 69 |
1 files changed, 33 insertions, 36 deletions
diff --git a/apps/plugins/pictureflow/pictureflow.c b/apps/plugins/pictureflow/pictureflow.c index cf9fa13bd8..73dca5a485 100644 --- a/apps/plugins/pictureflow/pictureflow.c +++ b/apps/plugins/pictureflow/pictureflow.c | |||
@@ -731,7 +731,7 @@ int create_album_index(void) | |||
731 | while (rb->tagcache_get_next(&tcs)) | 731 | while (rb->tagcache_get_next(&tcs)) |
732 | { | 732 | { |
733 | buf_size -= sizeof(struct album_data); | 733 | buf_size -= sizeof(struct album_data); |
734 | l = rb->strlen(tcs.result) + 1; | 734 | l = tcs.result_len; |
735 | if ( album_count > 0 ) | 735 | if ( album_count > 0 ) |
736 | album[-album_count].name_idx = album[1-album_count].name_idx + old_l; | 736 | album[-album_count].name_idx = album[1-album_count].name_idx + old_l; |
737 | 737 | ||
@@ -778,6 +778,16 @@ char* get_track_name(const int track_index) | |||
778 | } | 778 | } |
779 | 779 | ||
780 | /** | 780 | /** |
781 | Compare two unsigned ints passed via pointers. | ||
782 | */ | ||
783 | int compare_uints (const void *a_v, const void *b_v) | ||
784 | { | ||
785 | uint32_t a = *(uint32_t *)a_v; | ||
786 | uint32_t b = *(uint32_t *)b_v; | ||
787 | return (int)(a - b); | ||
788 | } | ||
789 | |||
790 | /** | ||
781 | Create the track index of the given slide_index. | 791 | Create the track index of the given slide_index. |
782 | */ | 792 | */ |
783 | int create_track_index(const int slide_index) | 793 | int create_track_index(const int slide_index) |
@@ -789,62 +799,49 @@ int create_track_index(const int slide_index) | |||
789 | if (!rb->tagcache_search(&tcs, tag_title)) | 799 | if (!rb->tagcache_search(&tcs, tag_title)) |
790 | return -1; | 800 | return -1; |
791 | 801 | ||
792 | int ret = 0; | 802 | struct track_data temp_tracks[MAX_TRACKS]; |
793 | char temp_titles[MAX_TRACKS][AVG_TRACK_NAME_LENGTH*4]; | 803 | uint32_t temp_tracknums[MAX_TRACKS]; |
794 | int temp_seeks[MAX_TRACKS]; | ||
795 | 804 | ||
796 | rb->tagcache_search_add_filter(&tcs, tag_album, album[slide_index].seek); | 805 | rb->tagcache_search_add_filter(&tcs, tag_album, album[slide_index].seek); |
797 | track_count=0; | 806 | track_count=0; |
798 | int string_index = 0; | 807 | int string_index = 0, i, track_num; |
799 | int l, track_num, heighest_index = 0; | ||
800 | 808 | ||
801 | for(l=0;l<MAX_TRACKS;l++) | 809 | while (rb->tagcache_get_next(&tcs) && track_count < MAX_TRACKS) |
802 | temp_titles[l][0] = '\0'; | ||
803 | while (rb->tagcache_get_next(&tcs) && track_count < MAX_TRACKS) | ||
804 | { | 810 | { |
805 | track_num = rb->tagcache_get_numeric(&tcs, tag_tracknumber) - 1; | 811 | track_num = rb->tagcache_get_numeric(&tcs, tag_tracknumber); |
812 | int avail = sizeof(track_names) - string_index; | ||
813 | int len; | ||
806 | if (track_num >= 0) | 814 | if (track_num >= 0) |
807 | { | 815 | { |
808 | rb->snprintf(temp_titles[track_num],sizeof(temp_titles[track_num]), | 816 | len = 1 + rb->snprintf(track_names + string_index , avail, |
809 | "%d: %s", track_num+1, tcs.result); | 817 | "%d: %s", track_num, tcs.result); |
810 | temp_seeks[track_num] = tcs.result_seek; | ||
811 | } | 818 | } |
812 | else | 819 | else |
813 | { | 820 | { |
814 | track_num = 0; | 821 | track_num = 0; |
815 | while (temp_titles[track_num][0] != '\0') | 822 | len = tcs.result_len; |
816 | track_num++; | 823 | rb->strncpy(track_names + string_index, tcs.result, avail); |
817 | rb->strcpy(temp_titles[track_num], tcs.result); | ||
818 | temp_seeks[track_num] = tcs.result_seek; | ||
819 | } | 824 | } |
820 | if (track_num > heighest_index) | 825 | if (len > avail) |
821 | heighest_index = track_num; | 826 | return -1; |
827 | temp_tracknums[track_count] = (track_num << 8) + track_count; | ||
828 | temp_tracks[track_count].name_idx = string_index; | ||
829 | temp_tracks[track_count].seek = tcs.result_seek; | ||
822 | track_count++; | 830 | track_count++; |
831 | string_index += len; | ||
823 | } | 832 | } |
824 | 833 | ||
825 | rb->tagcache_search_finish(&tcs); | 834 | rb->tagcache_search_finish(&tcs); |
826 | track_index = slide_index; | 835 | track_index = slide_index; |
827 | 836 | ||
828 | /* now fix the track list order */ | 837 | /* now fix the track list order */ |
829 | l = 0; | 838 | rb->qsort(temp_tracknums, track_count, sizeof(int), compare_uints); |
830 | track_count = 0; | 839 | for (i = 0; i < track_count; i++) |
831 | while (l <= heighest_index && | ||
832 | string_index < MAX_TRACKS*AVG_TRACK_NAME_LENGTH) | ||
833 | { | 840 | { |
834 | if (temp_titles[l][0] != '\0') | 841 | tracks[i].name_idx = temp_tracks[0xFF & temp_tracknums[i]].name_idx; |
835 | { | 842 | tracks[i].seek = temp_tracks[0xFF & temp_tracknums[i]].seek; |
836 | rb->strcpy(track_names + string_index, temp_titles[l]); | ||
837 | tracks[track_count].name_idx = string_index; | ||
838 | tracks[track_count].seek = temp_seeks[l]; | ||
839 | string_index += rb->strlen(temp_titles[l]) + 1; | ||
840 | track_count++; | ||
841 | } | ||
842 | l++; | ||
843 | } | 843 | } |
844 | if (ret != 0) | 844 | return (track_count > 0) ? 0 : -1; |
845 | return ret; | ||
846 | else | ||
847 | return (track_count > 0) ? 0 : -1; | ||
848 | } | 845 | } |
849 | 846 | ||
850 | /** | 847 | /** |