1305
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1 /* seek.c - functions related to real-time seeking
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
2 * Copyright (C) 2000-2007 Jason Jordan <shnutils@freeshell.org>
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
3 *
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
6 * the Free Software Foundation; either version 2 of the License, or
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
7 * (at your option) any later version.
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
8 *
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
9 * This program is distributed in the hope that it will be useful,
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
12 * GNU General Public License for more details.
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
13 *
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
14 * You should have received a copy of the GNU General Public License
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
15 * along with this program; if not, write to the Free Software
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
17 */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
18
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
19 /*
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
20 * $Id: seek.c,v 1.18 2007/03/23 05:49:48 jason Exp $
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
21 */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
22
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
23 #include <stdlib.h>
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
24 #include <glib.h>
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
25 #include <audacious/util.h>
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
26 #include "shorten.h"
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
27
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
28 #ifdef HAVE_CONFIG_H
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
29 #include "config.h"
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
30 #endif
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
31
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
32 #define ID3V1_TAG_SIZE 128
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
33
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
34 shn_seek_entry *shn_seek_entry_search(shn_seek_entry *table,ulong goal,ulong min,ulong max,ulong resolution)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
35 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
36 ulong med = (min + max) / 2;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
37 shn_seek_entry *middle = table + med;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
38 ulong sample = shn_uchar_to_ulong_le(middle->data);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
39
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
40 shn_debug("Examining seek table entry %lu with sample %lu (min/max = %lu/%lu, goal sample is %lu, resolution is %lu samples)",med,sample,min,max,goal,resolution);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
41
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
42 if (goal < sample)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
43 return shn_seek_entry_search(table,goal,min,med-1,resolution);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
44 if (goal > sample + resolution)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
45 return shn_seek_entry_search(table,goal,med+1,max,resolution);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
46 return middle;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
47 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
48
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
49 int load_separate_seek_table_generic(char *filename,shn_file *this_shn)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
50 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
51 VFSFile *f;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
52 slong seek_table_len;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
53
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
54 shn_debug("Looking for seek table in separate file: '%s'",filename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
55
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
56 if (!(f=vfs_fopen(filename,"rb")))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
57 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
58 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
59 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
60
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
61 vfs_fseek(f,0,SEEK_END);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
62 seek_table_len = (slong)vfs_ftell(f) - SEEK_HEADER_SIZE;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
63 vfs_fseek(f,0,SEEK_SET);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
64
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
65 if (vfs_fread((void *)this_shn->seek_header.data,1,SEEK_HEADER_SIZE,f) == SEEK_HEADER_SIZE)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
66 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
67 this_shn->seek_header.version = (slong)shn_uchar_to_ulong_le(this_shn->seek_header.data+4);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
68 this_shn->seek_header.shnFileSize = shn_uchar_to_ulong_le(this_shn->seek_header.data+8);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
69 if (memcmp(this_shn->seek_header.data,SEEK_HEADER_SIGNATURE,strlen(SEEK_HEADER_SIGNATURE)) == 0)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
70 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
71 if (this_shn->seek_header.shnFileSize != this_shn->wave_header.actual_size)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
72 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
73 shn_debug("warning: Seek table expected .shn file size %lu differs from actual .shn file size %lu - seek table might not belong to this file",
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
74 this_shn->seek_header.shnFileSize,this_shn->wave_header.actual_size);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
75 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
76
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
77 if ((this_shn->seek_table = malloc(seek_table_len)))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
78 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
79 if (vfs_fread((void *)this_shn->seek_table,1,seek_table_len,f) == seek_table_len)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
80 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
81 shn_debug("Successfully loaded seek table in separate file: '%s'",filename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
82
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
83 this_shn->vars.seek_table_entries = seek_table_len / SEEK_ENTRY_SIZE;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
84
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
85 if (this_shn->vars.seek_table_entries > 1)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
86 this_shn->vars.seek_resolution = shn_uchar_to_ulong_le(this_shn->seek_table->data+SEEK_ENTRY_SIZE);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
87 else
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
88 this_shn->vars.seek_resolution = SEEK_RESOLUTION;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
89
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
90 vfs_fclose(f);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
91
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
92 return 1;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
93 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
94 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
95 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
96 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
97
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
98 vfs_fclose(f);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
99 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
100 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
101
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
102 int load_appended_seek_table(shn_file *this_shn,char *filename,long bytes_from_end)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
103 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
104 switch (bytes_from_end)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
105 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
106 case 0:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
107 shn_debug("Looking for seek table appended to file: '%s'",filename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
108 break;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
109 case ID3V1_TAG_SIZE:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
110 shn_debug("Looking for seek table hidden behind an ID3v1 tag at the end of file: '%s'",filename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
111 break;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
112 default:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
113 shn_debug("Looking for seek table located %ld bytes from the end of file: '%s'",bytes_from_end,filename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
114 break;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
115 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
116
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
117 vfs_fseek(this_shn->vars.fd,-(SEEK_TRAILER_SIZE+bytes_from_end),SEEK_END);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
118 if (vfs_fread((void *)this_shn->seek_trailer.data,1,SEEK_TRAILER_SIZE,this_shn->vars.fd) == SEEK_TRAILER_SIZE)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
119 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
120 this_shn->seek_trailer.seekTableSize = shn_uchar_to_ulong_le(this_shn->seek_trailer.data);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
121 if (memcmp(this_shn->seek_trailer.data+4,SEEK_TRAILER_SIGNATURE,strlen(SEEK_TRAILER_SIGNATURE)) == 0)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
122 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
123 vfs_fseek(this_shn->vars.fd,-(this_shn->seek_trailer.seekTableSize+bytes_from_end),SEEK_END);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
124 this_shn->seek_trailer.seekTableSize -= (SEEK_HEADER_SIZE + SEEK_TRAILER_SIZE);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
125 if (vfs_fread((void *)this_shn->seek_header.data,1,SEEK_HEADER_SIZE,this_shn->vars.fd) == SEEK_HEADER_SIZE)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
126 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
127 this_shn->seek_header.version = (slong)shn_uchar_to_ulong_le(this_shn->seek_header.data+4);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
128 this_shn->seek_header.shnFileSize = shn_uchar_to_ulong_le(this_shn->seek_header.data+8);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
129 if ((this_shn->seek_table = malloc(this_shn->seek_trailer.seekTableSize)))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
130 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
131 if (vfs_fread((void *)this_shn->seek_table,1,this_shn->seek_trailer.seekTableSize,this_shn->vars.fd) == this_shn->seek_trailer.seekTableSize)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
132 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
133 shn_debug("Successfully loaded seek table appended to file: '%s'",filename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
134
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
135 this_shn->vars.seek_table_entries = this_shn->seek_trailer.seekTableSize / SEEK_ENTRY_SIZE;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
136
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
137 if (this_shn->vars.seek_table_entries > 1)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
138 this_shn->vars.seek_resolution = shn_uchar_to_ulong_le(this_shn->seek_table->data+SEEK_ENTRY_SIZE);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
139 else
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
140 this_shn->vars.seek_resolution = SEEK_RESOLUTION;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
141
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
142 return 1;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
143 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
144 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
145 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
146 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
147 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
148
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
149 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
150 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
151
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
152 int load_separate_seek_table_samedir(shn_file *this_shn,char *filename)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
153 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
154 char *altfilename,*basefile,*basedir;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
155
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
156 if (!(basefile = shn_get_base_filename(filename)))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
157 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
158 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
159 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
160
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
161 if (!(basedir = shn_get_base_directory(filename)))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
162 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
163 free(basefile);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
164 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
165 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
166
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
167 if (!(altfilename = malloc(strlen(basedir)+strlen(basefile)+sizeof(SEEK_SUFFIX)+3)))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
168 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
169 shn_debug("Could not allocate memory for same dir filename");
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
170 free(basefile);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
171 free(basedir);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
172 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
173 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
174
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
175 sprintf(altfilename,"%s/%s.%s",basedir,basefile,SEEK_SUFFIX);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
176
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
177 free(basefile);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
178 free(basedir);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
179
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
180 if (load_separate_seek_table_generic(altfilename,this_shn))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
181 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
182 free(altfilename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
183 return 1;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
184 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
185
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
186 free(altfilename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
187 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
188 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
189
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
190 int load_separate_seek_table_relative(shn_file *this_shn,char *filename)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
191 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
192 char *altfilename,*basefile,*basedir;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
193
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
194 if (0 == strcmp(shn_cfg.relative_seek_tables_path,""))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
195 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
196
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
197 if (!(basefile = shn_get_base_filename(filename)))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
198 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
199 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
200 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
201
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
202 if (!(basedir = shn_get_base_directory(filename)))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
203 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
204 free(basefile);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
205 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
206 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
207
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
208 if (!(altfilename = malloc(strlen(basedir)+strlen(shn_cfg.relative_seek_tables_path)+strlen(basefile)+sizeof(SEEK_SUFFIX)+4)))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
209 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
210 shn_debug("Could not allocate memory for absolute filename");
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
211 free(basefile);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
212 free(basedir);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
213 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
214 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
215
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
216 sprintf(altfilename,"%s/%s/%s.%s",basedir,shn_cfg.relative_seek_tables_path,basefile,SEEK_SUFFIX);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
217
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
218 free(basefile);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
219 free(basedir);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
220
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
221 if (load_separate_seek_table_generic(altfilename,this_shn))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
222 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
223 free(altfilename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
224 return 1;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
225 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
226
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
227 free(altfilename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
228 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
229 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
230
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
231 int load_separate_seek_table_absolute(shn_file *this_shn,char *filename)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
232 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
233 char *altfilename,*basefile;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
234
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
235 if (!(basefile = shn_get_base_filename(filename)))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
236 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
237 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
238 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
239
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
240 if (!(altfilename = malloc(strlen(shn_cfg.seek_tables_path)+strlen(basefile)+sizeof(SEEK_SUFFIX)+3)))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
241 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
242 shn_debug("Could not allocate memory for same dir filename");
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
243 free(basefile);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
244 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
245 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
246
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
247 sprintf(altfilename,"%s/%s.%s",shn_cfg.seek_tables_path,basefile,SEEK_SUFFIX);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
248
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
249 free(basefile);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
250
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
251 if (load_separate_seek_table_generic(altfilename,this_shn))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
252 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
253 free(altfilename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
254 return 1;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
255 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
256
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
257 free(altfilename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
258 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
259 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
260
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
261 void shn_load_seek_table(shn_file *this_shn,char *filename)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
262 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
263 if (load_appended_seek_table(this_shn,filename,0))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
264 return;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
265
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
266 if (load_appended_seek_table(this_shn,filename,ID3V1_TAG_SIZE))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
267 return;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
268
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
269 if (load_separate_seek_table_samedir(this_shn,filename))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
270 return;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
271
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
272 if (load_separate_seek_table_relative(this_shn,filename))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
273 return;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
274
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
275 if (load_separate_seek_table_absolute(this_shn,filename))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
276 return;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
277
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
278 shn_debug("Could not find any seek tables");
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
279 }
|