Mercurial > audlegacy-plugins
comparison src/madplug/plugin.c @ 612:951b24719ce9 trunk
[svn] - fix for audmad_is_our_fd()
- added my TODO list ;p
| author | yaz |
|---|---|
| date | Tue, 06 Feb 2007 21:01:15 -0800 |
| parents | 3f7a52adfe0e |
| children | 85a70ace8c02 |
comparison
equal
deleted
inserted
replaced
| 611:3f7a52adfe0e | 612:951b24719ce9 |
|---|---|
| 184 return ((unsigned long) hbuf[0] << 24) | | 184 return ((unsigned long) hbuf[0] << 24) | |
| 185 ((unsigned long) hbuf[1] << 16) | | 185 ((unsigned long) hbuf[1] << 16) | |
| 186 ((unsigned long) hbuf[2] << 8) | (unsigned long) hbuf[3]; | 186 ((unsigned long) hbuf[2] << 8) | (unsigned long) hbuf[3]; |
| 187 } | 187 } |
| 188 | 188 |
| 189 #if 0 | 189 |
| 190 // XXX: can't add remote stream from add URL dialog. temporally disabled. | |
| 191 // audacious vfs fast version | 190 // audacious vfs fast version |
| 192 static int audmad_is_our_fd(char *filename, VFSFile *fin) | 191 static int audmad_is_our_fd(char *filename, VFSFile *fin) |
| 193 { | 192 { |
| 194 guint32 check; | 193 guint32 check; |
| 195 gchar *ext = extname(filename); | 194 gchar *ext = extname(filename); |
| 196 gint cyc = 0; | 195 gint cyc = 0; |
| 197 guchar buf[4]; | 196 guchar buf[4]; |
| 198 guchar tmp[4096]; | 197 guchar tmp[4096]; |
| 199 gint ret, i; | 198 gint ret, i; |
| 200 | 199 |
| 200 #if 1 | |
| 201 // XXX: temporary fix | |
| 202 if (!strncasecmp("http://", filename, 7) || !strncasecmp("https://", filename, 8)) { | |
| 203 g_message("audmad_is_our_fe: remote"); | |
| 204 info.remote = TRUE; | |
| 205 } | |
| 206 #endif | |
| 207 | |
| 201 /* I've seen some flac files beginning with id3 frames.. | 208 /* I've seen some flac files beginning with id3 frames.. |
| 202 so let's exclude known non-mp3 filename extensions */ | 209 so let's exclude known non-mp3 filename extensions */ |
| 203 if (!strcasecmp(".flac", ext) || !strcasecmp(".mpc", ext) || | 210 if (!strcasecmp(".flac", ext) || !strcasecmp(".mpc", ext) || |
| 204 !strcasecmp(".tta", ext)) | 211 !strcasecmp(".tta", ext)) |
| 205 return 0; | 212 return 0; |
| 223 } | 230 } |
| 224 | 231 |
| 225 while (!mp3_head_check(check)) | 232 while (!mp3_head_check(check)) |
| 226 { | 233 { |
| 227 ret = vfs_fread(tmp, 1, 4096, fin); | 234 ret = vfs_fread(tmp, 1, 4096, fin); |
| 228 if (ret == 0) | 235 if (ret == 0) |
| 229 return 0; | 236 return 0; |
| 230 | 237 |
| 231 for (i = 0; i < ret; i++) | 238 for (i = 0; i < ret; i++) |
| 232 { | 239 { |
| 233 check <<= 8; | 240 check <<= 8; |
| 241 return 0; | 248 return 0; |
| 242 } | 249 } |
| 243 | 250 |
| 244 return 1; | 251 return 1; |
| 245 } | 252 } |
| 246 #endif | |
| 247 | |
| 248 // this function will be replaced soon. | |
| 249 static int audmad_is_our_fd(char *filename, VFSFile *fin) | |
| 250 { | |
| 251 int rtn = 0; | |
| 252 guchar check[4]; | |
| 253 | |
| 254 info.remote = FALSE; //awkward... | |
| 255 | |
| 256 #ifdef DEBUG | |
| 257 g_message("audmad: filename = %s\n", filename); | |
| 258 #endif | |
| 259 | |
| 260 // 0. if url is beginning with http://, take it blindly. | |
| 261 if (!strncasecmp("http://", filename, strlen("http://")) || | |
| 262 !strncasecmp("https://", filename, strlen("https://"))) { | |
| 263 g_message("audmad: remote\n"); | |
| 264 info.remote = TRUE; | |
| 265 return 1; //ours | |
| 266 } | |
| 267 | |
| 268 // 1. check embeded signature | |
| 269 if (fin && vfs_fread(check, 1, 4, fin) == 4) { | |
| 270 /* | |
| 271 * or three bytes are "ID3" | |
| 272 */ | |
| 273 if (mp3_head_check(check)) { | |
| 274 rtn = 1; | |
| 275 } | |
| 276 else if (memcmp(check, "ID3", 3) == 0) { | |
| 277 rtn = 1; | |
| 278 } | |
| 279 else if (memcmp(check, "RIFF", 4) == 0) { | |
| 280 vfs_fseek(fin, 4, SEEK_CUR); | |
| 281 vfs_fread(check, 1, 4, fin); | |
| 282 | |
| 283 if (memcmp(check, "RMP3", 4) == 0) { | |
| 284 rtn = 1; | |
| 285 } | |
| 286 } | |
| 287 } | |
| 288 // 2. exclude files with folloing extensions | |
| 289 if (strcasecmp("flac", filename + strlen(filename) - 4) == 0 || | |
| 290 strcasecmp("mpc", filename + strlen(filename) - 3) == 0 || | |
| 291 strcasecmp("tta", filename + strlen(filename) - 3) == 0) { | |
| 292 rtn = 0; | |
| 293 goto tail; | |
| 294 } | |
| 295 | |
| 296 // 3. if we haven't found any signature, take the files with .mp3 extension. | |
| 297 if (rtn == 0 && strcasecmp("mp3", filename + strlen(filename) - 3) == 0) { | |
| 298 rtn = 1; | |
| 299 } | |
| 300 | |
| 301 tail: | |
| 302 return rtn; | |
| 303 } | |
| 304 | 253 |
| 305 // audacious vfs version | 254 // audacious vfs version |
| 306 static int audmad_is_our_file(char *filename) | 255 static int audmad_is_our_file(char *filename) |
| 307 { | 256 { |
| 308 VFSFile *fin = NULL; | 257 VFSFile *fin = NULL; |
| 321 | 270 |
| 322 static void audmad_stop(InputPlayback *playback) | 271 static void audmad_stop(InputPlayback *playback) |
| 323 { | 272 { |
| 324 #ifdef DEBUG | 273 #ifdef DEBUG |
| 325 g_message("f: audmad_stop"); | 274 g_message("f: audmad_stop"); |
| 326 #endif /* DEBUG */ | 275 #endif |
| 327 g_mutex_lock(mad_mutex); | 276 g_mutex_lock(mad_mutex); |
| 328 info.playback = playback; | 277 info.playback = playback; |
| 329 g_mutex_unlock(mad_mutex); | 278 g_mutex_unlock(mad_mutex); |
| 330 | 279 |
| 331 if (decode_thread) { | 280 if (decode_thread) { |
| 335 g_mutex_unlock(mad_mutex); | 284 g_mutex_unlock(mad_mutex); |
| 336 g_cond_signal(mad_cond); | 285 g_cond_signal(mad_cond); |
| 337 | 286 |
| 338 #ifdef DEBUG | 287 #ifdef DEBUG |
| 339 g_message("waiting for thread"); | 288 g_message("waiting for thread"); |
| 340 #endif /* DEBUG */ | 289 #endif |
| 341 g_thread_join(decode_thread); | 290 g_thread_join(decode_thread); |
| 342 #ifdef DEBUG | 291 #ifdef DEBUG |
| 343 g_message("thread done"); | 292 g_message("thread done"); |
| 344 #endif /* DEBUG */ | 293 #endif |
| 345 input_term(&info); | 294 input_term(&info); |
| 346 decode_thread = NULL; | 295 decode_thread = NULL; |
| 347 | 296 |
| 348 } | 297 } |
| 349 #ifdef DEBUG | 298 #ifdef DEBUG |
| 350 g_message("e: audmad_stop"); | 299 g_message("e: audmad_stop"); |
| 351 #endif /* DEBUG */ | 300 #endif |
| 352 } | 301 } |
| 353 | 302 |
| 354 static void audmad_play_file(InputPlayback *playback) | 303 static void audmad_play_file(InputPlayback *playback) |
| 355 { | 304 { |
| 356 gboolean rtn; | 305 gboolean rtn; |
