Mercurial > audlegacy-plugins
comparison src/streambrowser/streambrowser.c @ 2815:cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
| author | Calin Crisan ccrisan@gmail.com |
|---|---|
| date | Sun, 13 Jul 2008 04:00:04 +0300 |
| parents | 7977bdc02664 |
| children | 779125caa3ac |
comparison
equal
deleted
inserted
replaced
| 2814:a03d670e8752 | 2815:cc6f02424609 |
|---|---|
| 23 #include <audacious/ui_plugin_menu.h> | 23 #include <audacious/ui_plugin_menu.h> |
| 24 | 24 |
| 25 #include "streambrowser.h" | 25 #include "streambrowser.h" |
| 26 #include "streamdir.h" | 26 #include "streamdir.h" |
| 27 #include "shoutcast.h" | 27 #include "shoutcast.h" |
| 28 #include "xiph.h" | |
| 28 #include "gui/streambrowser_win.h" | 29 #include "gui/streambrowser_win.h" |
| 29 #include "gui/about_win.h" | 30 #include "gui/about_win.h" |
| 30 | 31 |
| 31 | 32 |
| 32 typedef struct { | 33 typedef struct { |
| 135 | 136 |
| 136 aud_vfs_fclose(local_file); | 137 aud_vfs_fclose(local_file); |
| 137 aud_vfs_fclose(remote_file); | 138 aud_vfs_fclose(remote_file); |
| 138 | 139 |
| 139 return TRUE; | 140 return TRUE; |
| 141 } | |
| 142 | |
| 143 gboolean mystrcasestr(const char *haystack, const char *needle) | |
| 144 { | |
| 145 int len_h = strlen(haystack) + 1; | |
| 146 int len_n = strlen(needle) + 1; | |
| 147 int i; | |
| 148 | |
| 149 char *upper_h = malloc(len_h); | |
| 150 char *upper_n = malloc(len_n); | |
| 151 | |
| 152 for (i = 0; i < len_h; i++) | |
| 153 upper_h[i] = toupper(haystack[i]); | |
| 154 for (i = 0; i < len_n; i++) | |
| 155 upper_n[i] = toupper(needle[i]); | |
| 156 | |
| 157 char *p = strstr(upper_h, upper_n); | |
| 158 | |
| 159 free(upper_h); | |
| 160 free(upper_n); | |
| 161 | |
| 162 return (gboolean) p; | |
| 140 } | 163 } |
| 141 | 164 |
| 142 | 165 |
| 143 static void sb_init() | 166 static void sb_init() |
| 144 { | 167 { |
| 259 if (update_thread_count >= MAX_UPDATE_THREADS) { | 282 if (update_thread_count >= MAX_UPDATE_THREADS) { |
| 260 debug("another %d streamdir updates are pending, this request will be dropped\n", update_thread_count); | 283 debug("another %d streamdir updates are pending, this request will be dropped\n", update_thread_count); |
| 261 } | 284 } |
| 262 else { | 285 else { |
| 263 g_mutex_lock(update_thread_mutex); | 286 g_mutex_lock(update_thread_mutex); |
| 264 | 287 |
| 265 /* do we have a running thread? */ | 288 /* do we have a running thread? */ |
| 266 if (update_thread_count > 0) { | 289 if (update_thread_count > 0) { |
| 267 int i; | 290 int i; |
| 268 gboolean exists = FALSE; | 291 gboolean exists = FALSE; |
| 269 update_thread_data_t *update_thread_data; | 292 update_thread_data_t *update_thread_data; |
| 318 | 341 |
| 319 static gpointer update_thread_core(gpointer user_data) | 342 static gpointer update_thread_core(gpointer user_data) |
| 320 { | 343 { |
| 321 debug("entering update thread core\n"); | 344 debug("entering update thread core\n"); |
| 322 | 345 |
| 323 /* try to get the last item in the queue */ | 346 /* try to get the last item in the queue, but don't remove it */ |
| 324 g_mutex_lock(update_thread_mutex); | 347 g_mutex_lock(update_thread_mutex); |
| 325 update_thread_data_t *data = NULL; | 348 update_thread_data_t *data = NULL; |
| 326 if (update_thread_count > 0) { | 349 if (update_thread_count > 0) { |
| 327 data = g_queue_pop_head(update_thread_data_queue); | 350 data = g_queue_peek_head(update_thread_data_queue); |
| 328 } | 351 } |
| 329 g_mutex_unlock(update_thread_mutex); | 352 g_mutex_unlock(update_thread_mutex); |
| 330 | 353 |
| 331 /* repetitively process the queue elements, until queue is empty */ | 354 /* repetitively process the queue elements, until queue is empty */ |
| 332 while (data != NULL && update_thread_count > 0) { | 355 while (data != NULL && update_thread_count > 0) { |
| 355 gdk_threads_enter(); | 378 gdk_threads_enter(); |
| 356 streambrowser_win_set_category(data->streamdir, data->category); | 379 streambrowser_win_set_category(data->streamdir, data->category); |
| 357 streambrowser_win_set_category_state(data->streamdir, data->category, FALSE); | 380 streambrowser_win_set_category_state(data->streamdir, data->category, FALSE); |
| 358 gdk_threads_leave(); | 381 gdk_threads_leave(); |
| 359 } | 382 } |
| 383 /* xiph */ | |
| 384 else if (strncmp(data->streamdir->name, XIPH_NAME, strlen(XIPH_NAME)) == 0) { | |
| 385 gdk_threads_enter(); | |
| 386 streambrowser_win_set_category_state(data->streamdir, data->category, TRUE); | |
| 387 gdk_threads_leave(); | |
| 388 | |
| 389 xiph_category_fetch(data->category); | |
| 390 | |
| 391 gdk_threads_enter(); | |
| 392 streambrowser_win_set_category(data->streamdir, data->category); | |
| 393 streambrowser_win_set_category_state(data->streamdir, data->category, FALSE); | |
| 394 gdk_threads_leave(); | |
| 395 } | |
| 360 } | 396 } |
| 361 /* update a streamdir */ | 397 /* update a streamdir */ |
| 362 else if (data->streamdir != NULL) { | 398 else if (data->streamdir != NULL) { |
| 363 /* shoutcast */ | 399 /* shoutcast */ |
| 364 if (strncmp(data->streamdir->name, SHOUTCAST_NAME, strlen(SHOUTCAST_NAME)) == 0) { | 400 if (strncmp(data->streamdir->name, SHOUTCAST_NAME, strlen(SHOUTCAST_NAME)) == 0) { |
| 367 gdk_threads_enter(); | 403 gdk_threads_enter(); |
| 368 streambrowser_win_set_streamdir(streamdir, SHOUTCAST_ICON); | 404 streambrowser_win_set_streamdir(streamdir, SHOUTCAST_ICON); |
| 369 gdk_threads_leave(); | 405 gdk_threads_leave(); |
| 370 } | 406 } |
| 371 } | 407 } |
| 408 /* xiph */ | |
| 409 else if (strncmp(data->streamdir->name, XIPH_NAME, strlen(XIPH_NAME)) == 0) { | |
| 410 streamdir_t *streamdir = xiph_streamdir_fetch(); | |
| 411 if (streamdir != NULL) { | |
| 412 gdk_threads_enter(); | |
| 413 streambrowser_win_set_streamdir(streamdir, XIPH_ICON); | |
| 414 gdk_threads_leave(); | |
| 415 } | |
| 416 } | |
| 372 } | 417 } |
| 373 /* update all streamdirs */ | 418 /* update all streamdirs */ |
| 374 else { | 419 else { |
| 375 /* shoutcast */ | 420 /* shoutcast */ |
| 376 streamdir_t *shoutcast_streamdir = shoutcast_streamdir_fetch(); | 421 streamdir_t *streamdir = shoutcast_streamdir_fetch(); |
| 377 if (shoutcast_streamdir != NULL) { | 422 if (streamdir != NULL) { |
| 378 gdk_threads_enter(); | 423 gdk_threads_enter(); |
| 379 streambrowser_win_set_streamdir(shoutcast_streamdir, SHOUTCAST_ICON); | 424 streambrowser_win_set_streamdir(streamdir, SHOUTCAST_ICON); |
| 380 gdk_threads_leave(); | 425 gdk_threads_leave(); |
| 381 } | 426 } |
| 427 /* xiph */ | |
| 428 streamdir = xiph_streamdir_fetch(); | |
| 429 if (streamdir != NULL) { | |
| 430 gdk_threads_enter(); | |
| 431 streambrowser_win_set_streamdir(streamdir, XIPH_ICON); | |
| 432 gdk_threads_leave(); | |
| 433 } | |
| 382 } | 434 } |
| 383 | 435 |
| 384 g_free(data); | 436 g_free(data); |
| 385 | 437 |
| 386 g_mutex_lock(update_thread_mutex); | 438 g_mutex_lock(update_thread_mutex); |
| 439 | |
| 440 /* remove the just processed data from the queue */ | |
| 441 g_queue_pop_head(update_thread_data_queue); | |
| 387 update_thread_count--; | 442 update_thread_count--; |
| 388 | 443 |
| 389 /* try to get the last item in the queue */ | 444 /* try to get the last item in the queue */ |
| 390 if (update_thread_count > 0) | 445 if (update_thread_count > 0) |
| 391 data = g_queue_pop_head(update_thread_data_queue); | 446 data = g_queue_pop_head(update_thread_data_queue); |
| 399 return NULL; | 454 return NULL; |
| 400 } | 455 } |
| 401 | 456 |
| 402 static void streaminfo_add_to_playlist(streaminfo_t *streaminfo) | 457 static void streaminfo_add_to_playlist(streaminfo_t *streaminfo) |
| 403 { | 458 { |
| 404 debug("fetching stream playlist for station '%s' from '%s'\n", streaminfo->name, streaminfo->playlist_url); | 459 if (strlen(streaminfo->playlist_url) > 0) { |
| 405 if (!fetch_remote_to_local_file(streaminfo->playlist_url, PLAYLIST_TEMP_FILE)) { | 460 debug("fetching stream playlist for station '%s' from '%s'\n", streaminfo->name, streaminfo->playlist_url); |
| 406 failure("shoutcast: stream playlist '%s' could not be downloaded to '%s'\n", streaminfo->playlist_url, PLAYLIST_TEMP_FILE); | 461 if (!fetch_remote_to_local_file(streaminfo->playlist_url, PLAYLIST_TEMP_FILE)) { |
| 407 return; | 462 failure("shoutcast: stream playlist '%s' could not be downloaded to '%s'\n", streaminfo->playlist_url, PLAYLIST_TEMP_FILE); |
| 408 } | 463 return; |
| 409 debug("stream playlist '%s' successfuly downloaded to '%s'\n", streaminfo->playlist_url, PLAYLIST_TEMP_FILE); | 464 } |
| 410 | 465 debug("stream playlist '%s' successfuly downloaded to '%s'\n", streaminfo->playlist_url, PLAYLIST_TEMP_FILE); |
| 411 aud_playlist_add_url(aud_playlist_get_active(), PLAYLIST_TEMP_FILE); | 466 |
| 467 aud_playlist_add(aud_playlist_get_active(), PLAYLIST_TEMP_FILE); | |
| 468 debug("stream playlist '%s' added\n", streaminfo->playlist_url); | |
| 469 } | |
| 470 | |
| 471 if (strlen(streaminfo->url) > 0) { | |
| 472 aud_playlist_add(aud_playlist_get_active(), streaminfo->url); | |
| 473 debug("stream '%s' added\n", streaminfo->url); | |
| 474 } | |
| 412 } | 475 } |
| 413 | 476 |
| 414 static void on_plugin_services_menu_item_click() | 477 static void on_plugin_services_menu_item_click() |
| 415 { | 478 { |
| 416 debug("on_plugin_services_menu_item_click()\n"); | 479 debug("on_plugin_services_menu_item_click()\n"); |
