summaryrefslogtreecommitdiff
path: root/firmware/playlist.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2002-05-05 11:59:14 +0000
committerDaniel Stenberg <daniel@haxx.se>2002-05-05 11:59:14 +0000
commita68445f2b035b8f979bd6e885effc8c7106fb964 (patch)
treee687efecf9c3261e0924382d9e7cedfbc7d56e0c /firmware/playlist.c
parent03b78866f1f6b86873fec2feaf323d46f413415c (diff)
downloadrockbox-a68445f2b035b8f979bd6e885effc8c7106fb964.tar.gz
rockbox-a68445f2b035b8f979bd6e885effc8c7106fb964.zip
Changed how indices are read from a playlist. We just can't read the full
file into memory first, and then scan for newlines. The file might be very big. This version instead scans through the file. This could probably be further improved too, to not use this read-single-bytes approach. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@442 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/playlist.c')
-rw-r--r--firmware/playlist.c56
1 files changed, 24 insertions, 32 deletions
diff --git a/firmware/playlist.c b/firmware/playlist.c
index acea68cad6..16eab01cfe 100644
--- a/firmware/playlist.c
+++ b/firmware/playlist.c
@@ -24,7 +24,7 @@
24#include <string.h> 24#include <string.h>
25#include "playlist.h" 25#include "playlist.h"
26#include "debug.h" 26#include "debug.h"
27#include "disk.h" 27#include <file.h>
28 28
29/* 29/*
30 * load playlist info from disk 30 * load playlist info from disk
@@ -59,18 +59,13 @@ int reload_playlist_info( playlist_info_t *playlist )
59 */ 59 */
60void load_playlist( playlist_info_t *playlist, const char *filename ) { 60void load_playlist( playlist_info_t *playlist, const char *filename ) {
61 61
62 char *m3u_buf = NULL;
63
64 DEBUGF( "load_playlist( %s )\n", filename ); 62 DEBUGF( "load_playlist( %s )\n", filename );
65 63
66 /* read file */
67 read_file_into_buffer( &m3u_buf, filename );
68
69 /* store playlist filename */ 64 /* store playlist filename */
70 strncpy( playlist->filename, filename, sizeof(playlist->filename) ); 65 strncpy( playlist->filename, filename, sizeof(playlist->filename) );
71 66
72 /* add track indices to playlist data structure */ 67 /* add track indices to playlist data structure */
73 add_indices_to_playlist( m3u_buf, playlist ); 68 add_indices_to_playlist( playlist );
74} 69}
75 70
76/* 71/*
@@ -88,46 +83,43 @@ void empty_playlist( playlist_info_t *playlist ) {
88} 83}
89 84
90/* 85/*
91 * calculate track offsets within a playlist buffer 86 * calculate track offsets within a playlist file
92 */ 87 */
93void add_indices_to_playlist( char *buf, playlist_info_t *playlist ) 88void add_indices_to_playlist( playlist_info_t *playlist )
94{ 89{
95 char *p; 90 char *p;
96 int i = 0; 91 int i = 0;
92 unsigned char byte;
93 unsigned char lastbyte='\n';
94 int nread;
95
96 int fd;
97
98 fd = open(playlist->filename, O_RDONLY);
99 if(-1 == fd)
100 return; /* failure */
101
97 102
98 /*DEBUGF( "add_indices_to_playlist()\n" ); */ 103 /*DEBUGF( "add_indices_to_playlist()\n" ); */
99 104
100 p = buf; 105 p = &byte;
101 106
102 /* loop thru buffer, store index whenever we get a new line */ 107 /* loop thru buffer, store index whenever we get a new line */
103 108
104 while( p[i] != '\0' ) 109 while((nread = read(fd, &byte, 1)) == 1)
105 { 110 {
106 /* move thru (any) newlines */ 111 /* move thru (any) newlines */
107 112
108 while( ( p[i] != '\0' ) && ( ( p[i] == '\n' ) || ( p[i] == '\r' ) ) ) 113 if(( byte != '\n' ) && ( byte != '\r' ) &&
109 { 114 ((lastbyte == '\n') || (lastbyte == '\r')))
110 i++; 115 /* we're now at the start of a new track filename. store index */
111 } 116 extend_indices( playlist, i );
112 117
113 /* did we get to the end of the buffer? */ 118 lastbyte = byte;
114 119 i++;
115 if( p[i] == '\0' )
116 {
117 break;
118 }
119
120 /* we're now at the start of a new track filename. store index */
121
122 extend_indices( playlist, i );
123
124 /* we're now inside a track name. move to next newline */
125
126 while( ( p[i] != '\0' ) && ( ( p[i] != '\n' ) && ( p[i] != '\r' ) ) )
127 {
128 i++;
129 }
130 } 120 }
121
122 close(fd);
131} 123}
132 124
133/* 125/*