forked from len0rd/rockbox
Clean up create_track_index, fixing FS#9333, and use tagcache-provided length instead of strlen.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20938 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
c1267dc700
commit
ad5d665620
1 changed files with 33 additions and 36 deletions
|
@ -731,7 +731,7 @@ int create_album_index(void)
|
||||||
while (rb->tagcache_get_next(&tcs))
|
while (rb->tagcache_get_next(&tcs))
|
||||||
{
|
{
|
||||||
buf_size -= sizeof(struct album_data);
|
buf_size -= sizeof(struct album_data);
|
||||||
l = rb->strlen(tcs.result) + 1;
|
l = tcs.result_len;
|
||||||
if ( album_count > 0 )
|
if ( album_count > 0 )
|
||||||
album[-album_count].name_idx = album[1-album_count].name_idx + old_l;
|
album[-album_count].name_idx = album[1-album_count].name_idx + old_l;
|
||||||
|
|
||||||
|
@ -777,6 +777,16 @@ char* get_track_name(const int track_index)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Compare two unsigned ints passed via pointers.
|
||||||
|
*/
|
||||||
|
int compare_uints (const void *a_v, const void *b_v)
|
||||||
|
{
|
||||||
|
uint32_t a = *(uint32_t *)a_v;
|
||||||
|
uint32_t b = *(uint32_t *)b_v;
|
||||||
|
return (int)(a - b);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Create the track index of the given slide_index.
|
Create the track index of the given slide_index.
|
||||||
*/
|
*/
|
||||||
|
@ -789,61 +799,48 @@ int create_track_index(const int slide_index)
|
||||||
if (!rb->tagcache_search(&tcs, tag_title))
|
if (!rb->tagcache_search(&tcs, tag_title))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
int ret = 0;
|
struct track_data temp_tracks[MAX_TRACKS];
|
||||||
char temp_titles[MAX_TRACKS][AVG_TRACK_NAME_LENGTH*4];
|
uint32_t temp_tracknums[MAX_TRACKS];
|
||||||
int temp_seeks[MAX_TRACKS];
|
|
||||||
|
|
||||||
rb->tagcache_search_add_filter(&tcs, tag_album, album[slide_index].seek);
|
rb->tagcache_search_add_filter(&tcs, tag_album, album[slide_index].seek);
|
||||||
track_count=0;
|
track_count=0;
|
||||||
int string_index = 0;
|
int string_index = 0, i, track_num;
|
||||||
int l, track_num, heighest_index = 0;
|
|
||||||
|
|
||||||
for(l=0;l<MAX_TRACKS;l++)
|
|
||||||
temp_titles[l][0] = '\0';
|
|
||||||
while (rb->tagcache_get_next(&tcs) && track_count < MAX_TRACKS)
|
while (rb->tagcache_get_next(&tcs) && track_count < MAX_TRACKS)
|
||||||
{
|
{
|
||||||
track_num = rb->tagcache_get_numeric(&tcs, tag_tracknumber) - 1;
|
track_num = rb->tagcache_get_numeric(&tcs, tag_tracknumber);
|
||||||
|
int avail = sizeof(track_names) - string_index;
|
||||||
|
int len;
|
||||||
if (track_num >= 0)
|
if (track_num >= 0)
|
||||||
{
|
{
|
||||||
rb->snprintf(temp_titles[track_num],sizeof(temp_titles[track_num]),
|
len = 1 + rb->snprintf(track_names + string_index , avail,
|
||||||
"%d: %s", track_num+1, tcs.result);
|
"%d: %s", track_num, tcs.result);
|
||||||
temp_seeks[track_num] = tcs.result_seek;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
track_num = 0;
|
track_num = 0;
|
||||||
while (temp_titles[track_num][0] != '\0')
|
len = tcs.result_len;
|
||||||
track_num++;
|
rb->strncpy(track_names + string_index, tcs.result, avail);
|
||||||
rb->strcpy(temp_titles[track_num], tcs.result);
|
|
||||||
temp_seeks[track_num] = tcs.result_seek;
|
|
||||||
}
|
}
|
||||||
if (track_num > heighest_index)
|
if (len > avail)
|
||||||
heighest_index = track_num;
|
return -1;
|
||||||
|
temp_tracknums[track_count] = (track_num << 8) + track_count;
|
||||||
|
temp_tracks[track_count].name_idx = string_index;
|
||||||
|
temp_tracks[track_count].seek = tcs.result_seek;
|
||||||
track_count++;
|
track_count++;
|
||||||
|
string_index += len;
|
||||||
}
|
}
|
||||||
|
|
||||||
rb->tagcache_search_finish(&tcs);
|
rb->tagcache_search_finish(&tcs);
|
||||||
track_index = slide_index;
|
track_index = slide_index;
|
||||||
|
|
||||||
/* now fix the track list order */
|
/* now fix the track list order */
|
||||||
l = 0;
|
rb->qsort(temp_tracknums, track_count, sizeof(int), compare_uints);
|
||||||
track_count = 0;
|
for (i = 0; i < track_count; i++)
|
||||||
while (l <= heighest_index &&
|
|
||||||
string_index < MAX_TRACKS*AVG_TRACK_NAME_LENGTH)
|
|
||||||
{
|
{
|
||||||
if (temp_titles[l][0] != '\0')
|
tracks[i].name_idx = temp_tracks[0xFF & temp_tracknums[i]].name_idx;
|
||||||
{
|
tracks[i].seek = temp_tracks[0xFF & temp_tracknums[i]].seek;
|
||||||
rb->strcpy(track_names + string_index, temp_titles[l]);
|
|
||||||
tracks[track_count].name_idx = string_index;
|
|
||||||
tracks[track_count].seek = temp_seeks[l];
|
|
||||||
string_index += rb->strlen(temp_titles[l]) + 1;
|
|
||||||
track_count++;
|
|
||||||
}
|
}
|
||||||
l++;
|
|
||||||
}
|
|
||||||
if (ret != 0)
|
|
||||||
return ret;
|
|
||||||
else
|
|
||||||
return (track_count > 0) ? 0 : -1;
|
return (track_count > 0) ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue