comparison src/icecast/icecast.c @ 2828:f796297a014c

prevent crash when user changes selects plugin
author Andrew O. Shadoura <bugzilla@tut.by>
date Sun, 13 Jul 2008 23:22:43 +0300
parents ab41a5a743a0
children ae797b0c21fa
comparison
equal deleted inserted replaced
2827:ab41a5a743a0 2828:f796297a014c
60 SHOUT_FORMAT_OGG 60 SHOUT_FORMAT_OGG
61 #endif 61 #endif
62 }; 62 };
63 63
64 static FileWriter plugin; 64 static FileWriter plugin;
65 static FileWriter plugin_new;
65 static uint8_t *outputbuffer = NULL; 66 static uint8_t *outputbuffer = NULL;
66 static guint outputlength=0; 67 static guint outputlength=0;
67 static gint buffersize; 68 static gint buffersize;
68 static gint bufferflush; 69 static gint bufferflush;
69 static gint buffersize_new; 70 static gint buffersize_new;
136 if (streamformat < 0 || streamformat >= streamformat_MAX) 137 if (streamformat < 0 || streamformat >= streamformat_MAX)
137 streamformat = 0; 138 streamformat = 0;
138 139
139 #ifdef FILEWRITER_MP3 140 #ifdef FILEWRITER_MP3
140 if (streamformat == MP3) 141 if (streamformat == MP3)
141 plugin = mp3_plugin; 142 plugin_new = mp3_plugin;
142 #endif 143 #endif
143 #ifdef FILEWRITER_VORBIS 144 #ifdef FILEWRITER_VORBIS
144 if (streamformat == VORBIS) 145 if (streamformat == VORBIS)
145 plugin = vorbis_plugin; 146 plugin_new = vorbis_plugin;
146 #endif 147 #endif
147 } 148 }
148 149
149 static void ice_init(void) 150 static void ice_init(void)
150 { 151 {
173 aud_cfg_db_close(db); 174 aud_cfg_db_close(db);
174 175
175 outputbuffer=g_try_malloc(buffersize); 176 outputbuffer=g_try_malloc(buffersize);
176 177
177 set_plugin(); 178 set_plugin();
179 plugin=plugin_new;
178 if (plugin.init) 180 if (plugin.init)
179 plugin.init(&ice_write_output); 181 plugin.init(&ice_write_output);
180 } 182 }
181 183
182 static void ice_cleanup(void) 184 static void ice_cleanup(void)
250 return 0; 252 return 0;
251 253
252 pos = aud_playlist_get_position(playlist); 254 pos = aud_playlist_get_position(playlist);
253 tuple = aud_playlist_get_tuple(playlist, pos); 255 tuple = aud_playlist_get_tuple(playlist, pos);
254 256
257 plugin = plugin_new;
258
255 if (!shout) 259 if (!shout)
256 { 260 {
257 rv = (plugin.open)(); 261 rv = (plugin.open)();
258 262
259 if (!(shout = shout_new())) 263 if (!(shout = shout_new()))
537 541
538 static void streamformat_cb(GtkWidget *combo, gpointer data) 542 static void streamformat_cb(GtkWidget *combo, gpointer data)
539 { 543 {
540 streamformat = gtk_combo_box_get_active(GTK_COMBO_BOX(streamformat_combo)); 544 streamformat = gtk_combo_box_get_active(GTK_COMBO_BOX(streamformat_combo));
541 set_plugin(); 545 set_plugin();
542 if (plugin.init) 546 if (plugin_new.init)
543 plugin.init(&ice_write_output); 547 plugin_new.init(&ice_write_output);
544 548
545 gtk_widget_set_sensitive(plugin_button, plugin.configure != NULL); 549 gtk_widget_set_sensitive(plugin_button, plugin_new.configure != NULL);
546 } 550 }
547 551
548 static void plugin_configure_cb(GtkWidget *button, gpointer data) 552 static void plugin_configure_cb(GtkWidget *button, gpointer data)
549 { 553 {
550 if (plugin.configure) 554 if (plugin_new.configure)
551 plugin.configure(); 555 plugin_new.configure();
552 } 556 }
553 557
554 static void configure_destroy(void) 558 static void configure_destroy(void)
555 { 559 {
556 } 560 }
559 { 563 {
560 if (!configure_win) 564 if (!configure_win)
561 { 565 {
562 GtkWidget * hbox; 566 GtkWidget * hbox;
563 GtkWidget * label; 567 GtkWidget * label;
568
569 plugin_new = plugin;
564 570
565 configure_win = gtk_window_new(GTK_WINDOW_TOPLEVEL); 571 configure_win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
566 572
567 gtk_signal_connect(GTK_OBJECT(configure_win), "destroy", 573 gtk_signal_connect(GTK_OBJECT(configure_win), "destroy",
568 GTK_SIGNAL_FUNC(configure_destroy), NULL); 574 GTK_SIGNAL_FUNC(configure_destroy), NULL);
595 gtk_box_pack_start(GTK_BOX(hbox), streamformat_combo, FALSE, FALSE, 0); 601 gtk_box_pack_start(GTK_BOX(hbox), streamformat_combo, FALSE, FALSE, 0);
596 gtk_combo_box_set_active(GTK_COMBO_BOX(streamformat_combo), streamformat); 602 gtk_combo_box_set_active(GTK_COMBO_BOX(streamformat_combo), streamformat);
597 g_signal_connect(G_OBJECT(streamformat_combo), "changed", G_CALLBACK(streamformat_cb), NULL); 603 g_signal_connect(G_OBJECT(streamformat_combo), "changed", G_CALLBACK(streamformat_cb), NULL);
598 604
599 plugin_button = gtk_button_new_with_label(_("Configure")); 605 plugin_button = gtk_button_new_with_label(_("Configure"));
600 gtk_widget_set_sensitive(plugin_button, plugin.configure != NULL); 606 gtk_widget_set_sensitive(plugin_button, plugin_new.configure != NULL);
601 g_signal_connect(G_OBJECT(plugin_button), "clicked", G_CALLBACK(plugin_configure_cb), NULL); 607 g_signal_connect(G_OBJECT(plugin_button), "clicked", G_CALLBACK(plugin_configure_cb), NULL);
602 gtk_box_pack_end(GTK_BOX(hbox), plugin_button, FALSE, FALSE, 0); 608 gtk_box_pack_end(GTK_BOX(hbox), plugin_button, FALSE, FALSE, 0);
603
604
605
606 609
607 gtk_box_pack_start(GTK_BOX(configure_vbox), gtk_hseparator_new(), FALSE, FALSE, 0); 610 gtk_box_pack_start(GTK_BOX(configure_vbox), gtk_hseparator_new(), FALSE, FALSE, 0);
608 611
609 hbox = gtk_hbox_new(FALSE, 5); 612 hbox = gtk_hbox_new(FALSE, 5);
610 gtk_box_pack_start(GTK_BOX(configure_vbox), hbox, FALSE, FALSE, 0); 613 gtk_box_pack_start(GTK_BOX(configure_vbox), hbox, FALSE, FALSE, 0);