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 "shorten.h"
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
26
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
27 #ifdef HAVE_CONFIG_H
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
28 #include "config.h"
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
29 #endif
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
30
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
31 #define ID3V1_TAG_SIZE 128
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
32
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
33 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
|
34 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
35 ulong med = (min + max) / 2;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
36 shn_seek_entry *middle = table + med;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
37 ulong sample = shn_uchar_to_ulong_le(middle->data);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
38
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
39 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
|
40
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
41 if (goal < sample)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
42 return shn_seek_entry_search(table,goal,min,med-1,resolution);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
43 if (goal > sample + resolution)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
44 return shn_seek_entry_search(table,goal,med+1,max,resolution);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
45 return middle;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
46 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
47
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
48 int load_separate_seek_table_generic(char *filename,shn_file *this_shn)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
49 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
50 VFSFile *f;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
51 slong seek_table_len;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
52
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
53 shn_debug("Looking for seek table in separate file: '%s'",filename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
54
|
1978
|
55 if (!(f=aud_vfs_fopen(filename,"rb")))
|
1305
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
56 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
57 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
58 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
59
|
1978
|
60 aud_vfs_fseek(f,0,SEEK_END);
|
|
61 seek_table_len = (slong)aud_vfs_ftell(f) - SEEK_HEADER_SIZE;
|
|
62 aud_vfs_fseek(f,0,SEEK_SET);
|
1305
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
63
|
1978
|
64 if (aud_vfs_fread((void *)this_shn->seek_header.data,1,SEEK_HEADER_SIZE,f) == SEEK_HEADER_SIZE)
|
1305
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
65 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
66 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
|
67 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
|
68 if (memcmp(this_shn->seek_header.data,SEEK_HEADER_SIGNATURE,strlen(SEEK_HEADER_SIGNATURE)) == 0)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
69 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
70 if (this_shn->seek_header.shnFileSize != this_shn->wave_header.actual_size)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
71 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
72 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
|
73 this_shn->seek_header.shnFileSize,this_shn->wave_header.actual_size);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
74 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
75
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
76 if ((this_shn->seek_table = malloc(seek_table_len)))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
77 {
|
1978
|
78 if (aud_vfs_fread((void *)this_shn->seek_table,1,seek_table_len,f) == seek_table_len)
|
1305
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
79 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
80 shn_debug("Successfully loaded seek table in separate file: '%s'",filename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
81
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
82 this_shn->vars.seek_table_entries = seek_table_len / SEEK_ENTRY_SIZE;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
83
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
84 if (this_shn->vars.seek_table_entries > 1)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
85 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
|
86 else
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
87 this_shn->vars.seek_resolution = SEEK_RESOLUTION;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
88
|
1978
|
89 aud_vfs_fclose(f);
|
1305
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
90
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
91 return 1;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
92 }
|
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
|
1978
|
97 aud_vfs_fclose(f);
|
1305
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
98 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
99 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
100
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
101 int load_appended_seek_table(shn_file *this_shn,char *filename,long bytes_from_end)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
102 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
103 switch (bytes_from_end)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
104 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
105 case 0:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
106 shn_debug("Looking for seek table appended to file: '%s'",filename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
107 break;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
108 case ID3V1_TAG_SIZE:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
109 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
|
110 break;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
111 default:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
112 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
|
113 break;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
114 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
115
|
1978
|
116 aud_vfs_fseek(this_shn->vars.fd,-(SEEK_TRAILER_SIZE+bytes_from_end),SEEK_END);
|
|
117 if (aud_vfs_fread((void *)this_shn->seek_trailer.data,1,SEEK_TRAILER_SIZE,this_shn->vars.fd) == SEEK_TRAILER_SIZE)
|
1305
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
118 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
119 this_shn->seek_trailer.seekTableSize = shn_uchar_to_ulong_le(this_shn->seek_trailer.data);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
120 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
|
121 {
|
1978
|
122 aud_vfs_fseek(this_shn->vars.fd,-(this_shn->seek_trailer.seekTableSize+bytes_from_end),SEEK_END);
|
1305
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
123 this_shn->seek_trailer.seekTableSize -= (SEEK_HEADER_SIZE + SEEK_TRAILER_SIZE);
|
1978
|
124 if (aud_vfs_fread((void *)this_shn->seek_header.data,1,SEEK_HEADER_SIZE,this_shn->vars.fd) == SEEK_HEADER_SIZE)
|
1305
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
125 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
126 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
|
127 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
|
128 if ((this_shn->seek_table = malloc(this_shn->seek_trailer.seekTableSize)))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
129 {
|
1978
|
130 if (aud_vfs_fread((void *)this_shn->seek_table,1,this_shn->seek_trailer.seekTableSize,this_shn->vars.fd) == this_shn->seek_trailer.seekTableSize)
|
1305
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
131 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
132 shn_debug("Successfully loaded seek table appended to file: '%s'",filename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
133
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
134 this_shn->vars.seek_table_entries = this_shn->seek_trailer.seekTableSize / SEEK_ENTRY_SIZE;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
135
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
136 if (this_shn->vars.seek_table_entries > 1)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
137 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
|
138 else
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
139 this_shn->vars.seek_resolution = SEEK_RESOLUTION;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
140
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
141 return 1;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
142 }
|
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 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
149 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
150
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
151 int load_separate_seek_table_samedir(shn_file *this_shn,char *filename)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
152 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
153 char *altfilename,*basefile,*basedir;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
154
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
155 if (!(basefile = shn_get_base_filename(filename)))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
156 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
157 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
158 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
159
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
160 if (!(basedir = shn_get_base_directory(filename)))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
161 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
162 free(basefile);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
163 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
164 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
165
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
166 if (!(altfilename = malloc(strlen(basedir)+strlen(basefile)+sizeof(SEEK_SUFFIX)+3)))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
167 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
168 shn_debug("Could not allocate memory for same dir filename");
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
169 free(basefile);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
170 free(basedir);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
171 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
172 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
173
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
174 sprintf(altfilename,"%s/%s.%s",basedir,basefile,SEEK_SUFFIX);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
175
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
176 free(basefile);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
177 free(basedir);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
178
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
179 if (load_separate_seek_table_generic(altfilename,this_shn))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
180 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
181 free(altfilename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
182 return 1;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
183 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
184
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
185 free(altfilename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
186 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
187 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
188
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
189 int load_separate_seek_table_relative(shn_file *this_shn,char *filename)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
190 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
191 char *altfilename,*basefile,*basedir;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
192
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
193 if (0 == strcmp(shn_cfg.relative_seek_tables_path,""))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
194 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
195
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
196 if (!(basefile = shn_get_base_filename(filename)))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
197 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
198 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
199 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
200
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
201 if (!(basedir = shn_get_base_directory(filename)))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
202 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
203 free(basefile);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
204 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
205 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
206
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
207 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
|
208 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
209 shn_debug("Could not allocate memory for absolute filename");
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
210 free(basefile);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
211 free(basedir);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
212 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
213 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
214
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
215 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
|
216
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
217 free(basefile);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
218 free(basedir);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
219
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
220 if (load_separate_seek_table_generic(altfilename,this_shn))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
221 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
222 free(altfilename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
223 return 1;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
224 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
225
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
226 free(altfilename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
227 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
228 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
229
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
230 int load_separate_seek_table_absolute(shn_file *this_shn,char *filename)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
231 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
232 char *altfilename,*basefile;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
233
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
234 if (!(basefile = shn_get_base_filename(filename)))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
235 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
236 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
237 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
238
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
239 if (!(altfilename = malloc(strlen(shn_cfg.seek_tables_path)+strlen(basefile)+sizeof(SEEK_SUFFIX)+3)))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
240 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
241 shn_debug("Could not allocate memory for same dir filename");
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
242 free(basefile);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
243 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
244 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
245
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
246 sprintf(altfilename,"%s/%s.%s",shn_cfg.seek_tables_path,basefile,SEEK_SUFFIX);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
247
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
248 free(basefile);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
249
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
250 if (load_separate_seek_table_generic(altfilename,this_shn))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
251 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
252 free(altfilename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
253 return 1;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
254 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
255
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
256 free(altfilename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
257 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
258 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
259
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
260 void shn_load_seek_table(shn_file *this_shn,char *filename)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
261 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
262 if (load_appended_seek_table(this_shn,filename,0))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
263 return;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
264
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
265 if (load_appended_seek_table(this_shn,filename,ID3V1_TAG_SIZE))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
266 return;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
267
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
268 if (load_separate_seek_table_samedir(this_shn,filename))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
269 return;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
270
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
271 if (load_separate_seek_table_relative(this_shn,filename))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
272 return;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
273
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
274 if (load_separate_seek_table_absolute(this_shn,filename))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
275 return;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
276
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
277 shn_debug("Could not find any seek tables");
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
278 }
|