Adds a configure option, --enable-debug When enabled, a moderate amount of debug output is printed to stderr diff -X dontdiff -urNp tunesbrowser-0.2.0/albumlist.c tunesbrowser-dsd/albumlist.c --- tunesbrowser-0.2.0/albumlist.c 2004-12-18 23:53:48.000000000 +0000 +++ tunesbrowser-dsd/albumlist.c 2005-01-26 23:36:11.237491968 +0000 @@ -29,6 +29,7 @@ #include #include +#include "debug.h" #include "lists.h" #include "tunesbrowser.h" @@ -137,6 +138,7 @@ void albumlist_redraw() artist *cur_artist = NULL; album *cur_album = NULL; + dbgcall(); gtk_list_store_clear(albumlist); if (!host) return; @@ -175,6 +177,8 @@ static void on_album_selection_changed(G album *album; daap_host *host = daap_host_get_visible(); + dbgcall(); + if (!host) return; if (gtk_tree_selection_get_selected(selection, &model, &iter)) diff -X dontdiff -urNp tunesbrowser-0.2.0/artistlist.c tunesbrowser-dsd/artistlist.c --- tunesbrowser-0.2.0/artistlist.c 2004-12-18 23:54:15.000000000 +0000 +++ tunesbrowser-dsd/artistlist.c 2005-01-26 23:37:10.341506792 +0000 @@ -28,6 +28,7 @@ #include #include +#include "debug.h" #include "lists.h" #include "tunesbrowser.h" @@ -136,6 +137,8 @@ void artistlist_redraw() int count = 0; artist *cur = NULL; + dbgcall(); + gtk_list_store_clear(artistlist); if (!host) return; @@ -159,6 +162,8 @@ static void on_artist_selection_changed( artist *artist; daap_host *host = daap_host_get_visible(); + dbgcall(); + if (!host) return; if (gtk_tree_selection_get_selected(selection, &model, &iter)) diff -X dontdiff -urNp tunesbrowser-0.2.0/audioplayer.c tunesbrowser-dsd/audioplayer.c --- tunesbrowser-0.2.0/audioplayer.c 2004-12-20 08:03:55.000000000 +0000 +++ tunesbrowser-dsd/audioplayer.c 2005-01-26 23:43:22.427941056 +0000 @@ -35,6 +35,7 @@ #include +#include "debug.h" #include "lists.h" #include "tunesbrowser.h" @@ -78,12 +79,14 @@ __UNUSED__ static char *get_state_str(Gs static void async_cmd_cb_gst_state(void *cb_data) { GstElementState state = (GstElementState)cb_data; + dbgcall(); gst_element_set_state (GST_ELEMENT (pipeline_thread), state); } static void async_cmd_cb_gst_pipe(void *cb_data) { int pipe_fd = (int)cb_data; + dbgcall(); audioplayer_setup_pipeline(SOURCE_PIPE); g_object_set (G_OBJECT (srcelem), "fd", pipe_fd, NULL); } @@ -92,6 +95,7 @@ static void async_cmd_cb_gst_file(void * { char *file = (char*)cb_data; + dbgcall(); audioplayer_setup_pipeline(SOURCE_FILE); g_object_set (G_OBJECT (srcelem), "location", file, NULL); @@ -100,6 +104,7 @@ static void async_cmd_cb_gst_file(void * static void async_cmd_cb_play_finished(__UNUSED__ void *cb_data) { + dbgcall(); audioplayer_destroy_pipeline(); daap_audiocb_finished(); } @@ -107,6 +112,7 @@ static void async_cmd_cb_play_finished(_ static void async_cmd_cb_gst_setup_clock(__UNUSED__ void *data) { GstClock *clock = gst_bin_get_clock(GST_BIN(pipeline_thread)); + dbgcall(); songstarted = gst_clock_get_time(clock) / GST_SECOND; } @@ -143,6 +149,7 @@ static void async_cmd_queue_add_setup_cl static void cb_eos(__UNUSED__ GstElement *elem, __UNUSED__ gpointer data) { + dbgcall(); audioplayer_stop(); } @@ -170,6 +177,8 @@ static void cb_iterate(GstBin *bin, __UN static void audioplayer_destroy_pipeline() { + dbgcall(); + /* unlink them first */ gst_element_unlink_many (srcelem, decoder, audiosink, NULL); @@ -181,6 +190,7 @@ static void audioplayer_destroy_pipeline static void audioplayer_setup_pipeline(enum source_type stype) { + dbgcall(); pipeline_thread = gst_thread_new ("pipeline"); #if (GST_VERSION_MINOR <= 6) gst_bin_set_post_iterate_function(GST_BIN(pipeline_thread), @@ -196,9 +206,11 @@ static void audioplayer_setup_pipeline(e { case SOURCE_PIPE: srcelem = gst_element_factory_make ("fdsrc", "source"); + dbgi("Using fdsrc\n"); break; case SOURCE_FILE: srcelem = gst_element_factory_make ("gnomevfssrc", "source"); + dbgi("Using gnomevfssrc\n"); break; } if (!srcelem) goto gst_element_err; @@ -215,12 +227,18 @@ static void audioplayer_setup_pipeline(e if (!decoder) goto gst_element_err; audiosink = gst_element_factory_make ("alsasink", "play_audio"); - if (!audiosink) + if (!audiosink) { + dbgw("alsasink failed, trying osssink...\n"); audiosink = gst_element_factory_make ("osssink", "play_audio"); - if (!audiosink) + } + if (!audiosink) { + dbgw("osssink failed, trying artsdsink...\n"); audiosink = gst_element_factory_make ("artsdsink", "play_audio"); - if (!audiosink) + } + if (!audiosink) { + dbgw("artsdsink failed, trying esdsink...\n"); audiosink = gst_element_factory_make ("esdsink", "play_audio"); + } if (!audiosink) { fprintf(stderr, "Failed to load gstreamer sink - tried all 3 of 'osssink', " @@ -259,6 +277,7 @@ void audioplayer_init() void audioplayer_finalize() { + dbgcall(); g_object_unref(G_OBJECT(pipeline_thread)); } @@ -269,6 +288,7 @@ static void audioplayer_loadpipe(int fd) void audioplayer_playpipe(int fd) { + dbgcall(); playing = 1; audioplayer_loadpipe(fd); @@ -278,6 +298,7 @@ void audioplayer_playpipe(int fd) void audioplayer_playfile(const char *file) { + dbgcall(); playing = 1; async_cmd_queue_add_gst_playfile(file); @@ -297,6 +318,7 @@ void audioplayer_resume() void audioplayer_stop() { + dbgcall(); if (!playing) return; /* already stopping (eos?) */ playing = 0; async_cmd_queue_add_play_finished(); diff -X dontdiff -urNp tunesbrowser-0.2.0/configure.ac tunesbrowser-dsd/configure.ac --- tunesbrowser-0.2.0/configure.ac 2005-01-03 10:05:19.000000000 +0000 +++ tunesbrowser-dsd/configure.ac 2005-01-26 22:52:14.984263376 +0000 @@ -53,6 +53,15 @@ if test x"$enable_gnome" = xyes || test fi fi +dnl Debugging +AC_ARG_ENABLE(debug, + AC_HELP_STRING([--enable-debug], + [Enable debug messages on stderr]),,,) + +if test x"$enable_debug" = xyes; then + AC_DEFINE(DEBUG, 1, [Define if debug message support is enabled]) +fi + AC_SUBST(TB_CFLAGS) AC_SUBST(TB_LIBS) diff -X dontdiff -urNp tunesbrowser-0.2.0/daap.c tunesbrowser-dsd/daap.c --- tunesbrowser-0.2.0/daap.c 2005-01-03 09:40:44.000000000 +0000 +++ tunesbrowser-dsd/daap.c 2005-01-27 00:11:56.998286744 +0000 @@ -40,6 +40,7 @@ #include /* libopendaap */ +#include "debug.h" #include "lists.h" #include "tunesbrowser.h" @@ -194,6 +195,7 @@ static void artistalbumview_add(daap_hos static void update_databases(daap_host *host) { int size; + dbgi("Host: %s\n", host->sharename); size = DAAP_ClientHost_GetDatabases(host->libopendaap_host, NULL, NULL, 0); @@ -215,6 +217,7 @@ static void update_songs(daap_host *host int db_id; int i; + dbgi("Host: %s\n", host->sharename); if (!host->nDatabases) return; db_id = host->databases[0].id; @@ -248,6 +251,8 @@ static void initial_connect(daap_host *h { int ret; + dbgi("Connecting to %s\n", host->sharename); + DAAP_ClientHost_AddRef(host->libopendaap_host); ret = DAAP_ClientHost_Connect(host->libopendaap_host); if (ret == -1) @@ -259,6 +264,7 @@ static void initial_connect(daap_host *h return; } + dbgi("Connected\n"); sourcelist_set_source_connect_state(host, 1); update_databases(host); @@ -315,6 +321,7 @@ static void free_artists(daap_host *host static void disconnect_host(daap_host *host) { + dbgi("Disconnecting from %s\n", host->sharename); g_static_rec_mutex_lock(&host->mutex); if (host->databases) free(host->databases); host->databases = NULL; @@ -361,12 +368,12 @@ static void daap_host_remove(daap_host * if (daap_host_is_connected(host)) { /* delaying final deletion until all references are destroyed */ - fprintf(stderr, "delaying free of %s\n", host->sharename); + dbgw("Delaying free of host %s\n", host->sharename); host->dead = 1; g_static_rec_mutex_unlock(&host->mutex); return; } - fprintf(stderr, "freeing %s\n", host->sharename); + dbgw("Freeing host %s\n", host->sharename); if (host->sharename) free(host->sharename); DAAP_ClientHost_Release(host->libopendaap_host); g_static_rec_mutex_unlock(&host->mutex); @@ -382,6 +389,7 @@ static void DAAP_StatusCB(__UNUSED__ DAA { case DAAP_STATUS_hostschanged: { + dbgi("Status: hostschanged\n"); cb_hosts_updated(); break; } @@ -389,6 +397,7 @@ static void DAAP_StatusCB(__UNUSED__ DAA { if (prev_libopendaap_status == DAAP_STATUS_negotiating) { + dbgi("Status: downloading, now starting playback...\n"); /* start playing the song */ audioplayer_playpipe(songpipe[0]); } @@ -396,6 +405,7 @@ static void DAAP_StatusCB(__UNUSED__ DAA } case DAAP_STATUS_error: { + dbgi("Status: error\n"); if (prev_libopendaap_status == DAAP_STATUS_negotiating || prev_libopendaap_status == DAAP_STATUS_downloading) { @@ -406,6 +416,7 @@ static void DAAP_StatusCB(__UNUSED__ DAA } case DAAP_STATUS_idle: { + dbgi("Status: idle\n"); if (prev_libopendaap_status == DAAP_STATUS_downloading) { /* downloading has finished, close the pipe, @@ -417,6 +428,7 @@ static void DAAP_StatusCB(__UNUSED__ DAA } } default: + dbgw("Unknown status\n"); break; } prev_libopendaap_status = status; @@ -465,6 +477,8 @@ static void cb_hosts_updated() { daap_host *cur; + dbgcall(); + for (cur = clientHosts; cur != NULL; cur = cur->next) cur->marked = 0; @@ -669,6 +683,7 @@ enum playsource daap_get_playsource() void daap_host_play_song(enum playsource playsource, daap_host *host, int song_id) { int songindex; + dbgi("Playing song %d on host %s\n", song_id, host->sharename); if (playing_song.host) { @@ -722,6 +737,7 @@ void daap_host_play_song(enum playsource return; fail: + dbge("Fail\n"); close(songpipe[0]); close(songpipe[1]); } @@ -755,6 +771,7 @@ void daap_audiocb_finished() if (stop_type == STOP_NEWSONG) { + dbgi("STOP_NEWSONG"); daap_host_play_song(next_song.playsource, next_song.host, next_song.song_id); daap_host_release(next_song.host); /* play_song will addref */ next_song.host = NULL; @@ -768,6 +785,7 @@ void daap_audiocb_finished() { DAAP_ClientHost_DatabaseItem *song; int songindex = get_songindex_by_id(prevhost, previd); + dbgi("STOP_NONE : PLAYSOURCE_HOST\n"); song = &(prevhost->songs[songindex]); /* if some other artist / album is visible, break */ if (prevhost->selected_artist && @@ -800,9 +818,11 @@ void daap_audiocb_finished() } break; case PLAYSOURCE_PARTY: + dbgi("STOP_NONE : PLAYSOURCE_PARTY\n"); partyshuffle_play_next(); break; case PLAYSOURCE_NONE: + dbgi("STOP_NONE : PLAYSOURCE_NONE\n"); break; } } diff -X dontdiff -urNp tunesbrowser-0.2.0/debug.h tunesbrowser-dsd/debug.h --- tunesbrowser-0.2.0/debug.h 1970-01-01 01:00:00.000000000 +0100 +++ tunesbrowser-dsd/debug.h 2005-01-27 00:18:26.251111320 +0000 @@ -0,0 +1,62 @@ +/* Copyright (c) 2005 Daniel Drake - All rights reserved + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + */ + + +#ifndef __DEBUG_H +#define __DEBUG_H +#include "config.h" + +#define STRINGIZE(x) #x + +#ifdef DEBUG + +#define dbgi(format, args...) \ + DEBUGMSG("INFO:", format, ##args) + +#define dbgw(format, args...) \ + DEBUGMSG("WARNING:", format, ##args) + +#define dbge(format, args...) \ + DEBUGMSG("ERROR:", format, ##args) + +#define DEBUGMSG(prefix, format, args...) \ + fprintf(stderr, prefix "["); \ + fprintf(stderr, __FILE__ ":"); \ + fprintf(stderr, __FUNCTION__); \ + fprintf(stderr, "] " format, ##args) + +#define dbgcall() \ + DEBUGMSG("CALL:", "\n"); + +#else /* DEBUG */ + +#define dbgi(format, args...) +#define dbgw(format, args...) +#define dbge(format, args...) +#define DEBUGMSG(prefix, format, args...) + +#endif /* DEBUG */ + +#endif + diff -X dontdiff -urNp tunesbrowser-0.2.0/main.c tunesbrowser-dsd/main.c --- tunesbrowser-0.2.0/main.c 2005-01-04 02:58:29.000000000 +0000 +++ tunesbrowser-dsd/main.c 2005-01-26 23:33:16.390072816 +0000 @@ -29,6 +29,7 @@ #include #include +#include "debug.h" #include "lists.h" #include "tunesbrowser.h" @@ -65,6 +66,8 @@ static void install_sighandlers() struct sigaction sa; int ret; + dbgcall(); + sa.sa_handler = (void*)sighandler_sigsegv; sa.sa_flags = SA_NOMASK | SA_SIGINFO; ret = sigaction(SIGSEGV, &sa, NULL); @@ -80,7 +83,7 @@ static void install_sighandlers() void on_tunesbrowser_win_destroy(__UNUSED__ GtkObject *object, __UNUSED__ gpointer user_data) { - printf("exiting\n"); + dbgw("Exiting\n"); gtk_main_quit(); } @@ -90,6 +93,8 @@ void on_tunesbrowser_win_destroy(__UNUSE int main(int argc, char *argv[]) { GladeXML *xml; + dbgi("Initializing\n"); + install_sighandlers(); gtk_init(&argc, &argv); @@ -114,6 +119,7 @@ int main(int argc, char *argv[]) { /* seems gstreamer removes my signal handlers */ install_sighandlers(); + dbgi("Entering gtk_main()\n"); gtk_main(); return 0; diff -X dontdiff -urNp tunesbrowser-0.2.0/misc_ui.c tunesbrowser-dsd/misc_ui.c --- tunesbrowser-0.2.0/misc_ui.c 2005-01-02 01:53:52.000000000 +0000 +++ tunesbrowser-dsd/misc_ui.c 2005-01-27 00:03:43.634289472 +0000 @@ -32,6 +32,7 @@ #include #include +#include "debug.h" #include "lists.h" #include "tunesbrowser.h" @@ -57,21 +58,25 @@ typedef struct static void async_cmd_cb_sourcelist_draw(__UNUSED__ void *cb_data) { + dbgcall(); sourcelist_redraw(); } static void async_cmd_cb_artistlist_draw(__UNUSED__ void *cb_data) { + dbgcall(); artistlist_redraw(); } static void async_cmd_cb_albumlist_draw(__UNUSED__ void *cb_data) { + dbgcall(); albumlist_redraw(); } static void async_cmd_cb_songlist_draw(__UNUSED__ void *cb_data) { + dbgcall(); songlist_redraw(); } @@ -84,6 +89,7 @@ static void async_cmd_cb_set_songpos(voi static void async_cmd_cb_set_status(void *cb_data) { guistatus *status = (guistatus*)cb_data; + dbgcall(); cb_update_songstatus(status->s, status->host, status->songid); @@ -119,6 +125,7 @@ void schedule_lists_draw(int source, int static void cb_update_songstatus(enum songstatus status, daap_host *host, int songid) { currentStatus = status; + dbgcall(); switch(status) { @@ -225,13 +232,14 @@ void on_playpause_clicked(__UNUSED__ Gtk if (currentStatus == GUISTATUS_PLAYING) /* current play -> pause */ { + dbgi("Pausing\n"); /* FIXME shouldn't really call audioplayer from here */ set_songstatus(GUISTATUS_PAUSED, host, songlist_get_selected_id()); audioplayer_pause(); } else if (currentStatus == GUISTATUS_STOPPED) /* current stopped -> play */ { - + dbgi("Playing\n"); if (partyshuffle_is_active()) { partyshuffle_play_selected(); @@ -246,6 +254,7 @@ void on_playpause_clicked(__UNUSED__ Gtk } else if (currentStatus == GUISTATUS_PAUSED) /* current paused -> resume */ { + dbgi("Resuming\n"); /* FIXME shouldn't call audioplayer from here */ set_songstatus(GUISTATUS_PLAYING, host, songlist_get_selected_id()); audioplayer_resume(); diff -X dontdiff -urNp tunesbrowser-0.2.0/partyshuffle.c tunesbrowser-dsd/partyshuffle.c --- tunesbrowser-0.2.0/partyshuffle.c 2005-01-03 07:04:08.000000000 +0000 +++ tunesbrowser-dsd/partyshuffle.c 2005-01-27 00:05:07.813492288 +0000 @@ -32,6 +32,7 @@ #include #endif /* HAVE_GNOME */ +#include "debug.h" #include "lists.h" #include "tunesbrowser.h" @@ -290,6 +291,7 @@ static void party_songlist_append(void * char *disc, char *year) { GtkTreeIter iter; + dbgcall(); gtk_list_store_append(partylist, &iter); @@ -388,6 +390,7 @@ void partyshuffle_play_selected() void partyshuffle_play_next() { GtkTreeIter iter; + dbgcall(); /* FIXME file hack */ if (!playing_song_host) return; /* not playing a song */ diff -X dontdiff -urNp tunesbrowser-0.2.0/songlist.c tunesbrowser-dsd/songlist.c --- tunesbrowser-0.2.0/songlist.c 2004-12-18 23:19:57.000000000 +0000 +++ tunesbrowser-dsd/songlist.c 2005-01-27 00:09:16.106745976 +0000 @@ -23,15 +23,15 @@ */ - +#include +#include #include #include #include +#include "debug.h" #include "lists.h" #include "tunesbrowser.h" -#include -#include static GtkListStore *songlist; static GtkTreeView *songtreeview; @@ -251,6 +251,8 @@ void songlist_redraw() int enum_id = -1; DAAP_ClientHost_DatabaseItem song; + dbgcall(); + gtk_list_store_clear(songlist); if (!host) return; @@ -353,6 +355,8 @@ void songlist_set_playing(daap_host *hos daap_host *prev_host = playing_song_host; daap_host *visible_host = daap_host_get_visible(); + dbgi("Playing song %d\n", id); + playing_song_id = id; playing_song_host = host; diff -X dontdiff -urNp tunesbrowser-0.2.0/sourcelist.c tunesbrowser-dsd/sourcelist.c --- tunesbrowser-0.2.0/sourcelist.c 2004-12-13 13:26:00.000000000 +0000 +++ tunesbrowser-dsd/sourcelist.c 2005-01-27 00:07:52.608439648 +0000 @@ -26,6 +26,7 @@ #include #include +#include "debug.h" #include "lists.h" #include "tunesbrowser.h" @@ -100,6 +101,7 @@ static void sourcelist_append(daap_host GtkTreeIter iter; GdkPixbuf *image; + dbgi("Adding %s\n", daap_host_get_sharename(host)); gtk_list_store_append(sourcelist, &iter); image = daap_host_is_connected(host) ? @@ -116,6 +118,7 @@ static void sourcelist_append(daap_host void sourcelist_redraw() { daap_host *cur = NULL; + dbgcall(); gtk_list_store_clear(sourcelist);