summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjaromil <jaromil@949728d9-16ea-0310-a75c-cbdf8430a4b8>2005-05-17 13:51:39 (GMT)
committer jaromil <jaromil@949728d9-16ea-0310-a75c-cbdf8430a4b8>2005-05-17 13:51:39 (GMT)
commit2c5676c4efda628dfbd79fc4c2f44f437835c052 (patch)
tree9694daf3313628117c7e2a561e42fa984b305c32
parent90864bd32c3610ad036a3b69d67d10b3301d5c32 (diff)
fine tuning of sleep timings,
commandline help, cleanup on the interface and code git-svn-id: svn://dyne.org/montevideo/ivysync@41 949728d9-16ea-0310-a75c-cbdf8430a4b8
-rw-r--r--Makefile7
-rw-r--r--cmdline.cpp27
-rw-r--r--decoder.cpp20
-rw-r--r--decoder.h3
-rw-r--r--gui.cpp59
-rw-r--r--gui.h2
-rw-r--r--utils.cpp25
-rw-r--r--utils.h2
8 files changed, 120 insertions, 25 deletions
diff --git a/Makefile b/Makefile
index 1a18d33..fbc16e9 100644
--- a/Makefile
+++ b/Makefile
@@ -8,11 +8,14 @@
CC = gcc
CPP = g++
LINKER = ld
+
# debugging flags:
-CPPFLAGS = -I. -Wall -ggdb `pkg-config --cflags gtk+-2.0`
+#CPPFLAGS = -I. -Wall -ggdb -pg `pkg-config --cflags gtk+-2.0`
# optimized flags:
-# CPPFLAGS = -I. -Wall -O2 -fomit-frame-pointer -ffast-math
+CPPFLAGS = -I. -Wall -O2 -fomit-frame-pointer -ffast-math -march=pentium3 \
+ `pkg-config --cflags gtk+-2.0`
+
LIBS = -lpthread `pkg-config --libs gtk+-2.0`
OBJ = decoder.o thread.o utils.o cmdline.o gui.o
diff --git a/cmdline.cpp b/cmdline.cpp
index 5d0efe7..d2bca03 100644
--- a/cmdline.cpp
+++ b/cmdline.cpp
@@ -46,6 +46,16 @@ vector<Decoder*> decoders;
// graphical interface
Gui *gui;
+char *help =
+"Usage: ivysync [-hsDgt] [ -d /dev/video16 [ -p playmode files ] ]\n"
+" -h --help show this help\n"
+" -d --device activate a device (i.e. /dev/video16)\n"
+" -s --scan scan for available devices\n"
+" -D --daemon run in daemon mode\n"
+" -p --playmode playlist mode (play|cont|loop|rand)\n"
+" -g --gui start the graphical user interface\n"
+" -t --test dummy testrun: don't open devices\n";
+
char *short_options = "-hd:sDp:gt";
const struct option long_options[] = {
{ "help", no_argument, NULL, 'h'},
@@ -90,11 +100,18 @@ int cmdline(int argc, char **argv) {
int c;
int res;
+ N("IvySync 0.2 / (c)2004-2005 Denis Rojo <jaromil@dyne.org>");
+
do {
res = getopt_long(argc, argv, short_options, long_options, NULL);
switch(res) {
-
+
+ case 'h':
+ fprintf(stderr,"%s",help);
+ exit(1);
+ break;
+
case 'd':
dec = new Decoder();
dec->dummy = dummytest;
@@ -251,9 +268,13 @@ int main(int argc, char **argv) {
N("Syncing %i players...",decoders.size());
- jsleep(1,0);
+ jsleep(0,500);
A("Start!");
syncstart = 1;
+ // jsleep(0,2);
+ // syncstart = 0;
+ // jsleep(0,500);
+ // syncstart = 1;
int still_running = decoders.size();
@@ -266,7 +287,7 @@ int main(int argc, char **argv) {
dec = *dec_iter;
if(dec->playing) still_running++;
-
+ jsleep(1,0); // 1 second delay check
}
}
diff --git a/decoder.cpp b/decoder.cpp
index 82a29da..8f2004c 100644
--- a/decoder.cpp
+++ b/decoder.cpp
@@ -39,11 +39,16 @@ Decoder::Decoder()
dummy = false;
gui = false;
- memset(buffo,0,sizeof(buffo));
+// memset(buffo,0,CHUNKSIZE+1024);
+ buffo = (uint8_t*) calloc(CHUNKSIZE,1);
+ if(!buffo)
+ E("fatal error: can't allocate %uMb of memory for decoder",
+ CHUNKSIZE/1024/1024);
}
Decoder::~Decoder() {
close();
+ free(buffo);
quit = true;
}
@@ -147,6 +152,10 @@ void Decoder::run() {
D("thread %u launched",pthread_self());
+ // set max realtime priority
+// if( set_rtpriority(true) )
+// A("thread %u running on max realtime priority",pthread_self());
+
while(!quit) {
update();
@@ -177,6 +186,8 @@ void Decoder::run() {
while(!playing && !quit) {
jsleep(0,200);
}
+
+
if(quit) break;
///////////////////////////
@@ -199,6 +210,8 @@ void Decoder::run() {
buf += written;
+ if(quit) break;
+
if(dummy) // emulation mode with no device (for devel)
written = writing;
else
@@ -234,7 +247,10 @@ void Decoder::flush() {
while( poll(&fdled,1,1000) < 1 ) { // wait infinite until ready
if(fdled.revents & POLLOUT) return;
- else W("device %i still not ready for writing",fd);
+ else {
+ W("device %i still not ready for writing",fd);
+ if(quit) return;
+ }
}
}
diff --git a/decoder.h b/decoder.h
index e20b591..30e4ea8 100644
--- a/decoder.h
+++ b/decoder.h
@@ -98,7 +98,8 @@ class Decoder : public Thread {
int fd;
FILE *playlist_fd;
- uint8_t buffo[(1024*64)+1024]; // 64k + 1k bound
+// uint8_t buffo[CHUNKSIZE+1024]; // + 1k bound
+ uint8_t *buffo;
};
diff --git a/gui.cpp b/gui.cpp
index 59c1003..0d903f1 100644
--- a/gui.cpp
+++ b/gui.cpp
@@ -65,27 +65,35 @@ void on_add_button(GtkWidget *widget, gpointer *data) {
pl->refresh();
}
-/*
-void on_playlist_select(GtkTreeSelection *sel, gpointer data) {
- GtkTreeIter treeiter;
- GtkTreeModel *model;
- int *selection;
- Playlist *pl = (Playlist*)data;
-
- if(gtk_tree_selection_get_selected(sel,&model,&treeiter)) {
- gtk_tree_model_get(model,&treeiter,POSITION,&selection,-1);
- D("selected file %u",*selection);
- pl->selected = *selection;
- pl->refresh();
- }
-}
-*/
void on_save_button(GtkWidget *widget, gpointer *data) {
Playlist *pl = (Playlist*)data;
pl->decoder->save();
}
+void on_syncstart_button(GtkWidget *widget, gpointer *data) {
+ vector<Playlist*>::iterator pl_iter;
+ Gui *gui = (Gui*)data;
+ Playlist *pl;
+
+ gui->syncstart = false;
+
+ for( pl_iter = gui->playlist.begin();
+ pl_iter != gui->playlist.end();
+ ++pl_iter) {
+ pl = *pl_iter;
+ pl->decoder->stop();
+ pl->decoder->position = 0;
+ pl->decoder->play();
+ pl->refresh();
+
+ }
+
+ jsleep(1,0);
+ gui->syncstart = true;
+
+}
+
void on_play_button(GtkWidget *widget, gpointer *data) {
Playlist *pl = (Playlist*)data;
if(!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
@@ -118,6 +126,8 @@ void on_delete_button(GtkWidget *widget, gpointer *data) {
select = gtk_tree_view_get_selection(GTK_TREE_VIEW(pl->treeview));
rowlist = gtk_tree_selection_get_selected_rows(select, &model);
+ if(!rowlist) return;
+
rowlist = g_list_reverse(rowlist);
rowlist = g_list_first(rowlist);
@@ -384,12 +394,14 @@ Playlist::Playlist(int num) {
gtk_widget_show (save_button);
gtk_box_pack_start (GTK_BOX (buttonbox), save_button, TRUE, TRUE, 0);
g_signal_connect((gpointer)save_button, "pressed", G_CALLBACK(on_save_button), this);
-
+
+ /*
statusbar = gtk_statusbar_new ();
snprintf(statusbar_name,255,"statusbar_%u",num);
gtk_widget_set_name (statusbar, statusbar_name);
gtk_widget_show (statusbar);
gtk_box_pack_start (GTK_BOX (widget), statusbar, FALSE, FALSE, 0);
+ */
// now setup the model view for the treeview
treestore = gtk_tree_store_new(COLUMNS,
@@ -518,10 +530,23 @@ Gui::Gui() {
gtk_window_set_title (GTK_WINDOW (window), "IvySync Graphical Interface");
main_window = (GtkWindow*)window; // global static pointer
+ vbox = gtk_vbox_new (FALSE, 0);
+ gtk_widget_set_name (vbox, "main_vbox");
+ gtk_widget_show (vbox);
+ gtk_container_add(GTK_CONTAINER(window), vbox);
+
notebook = gtk_notebook_new ();
gtk_widget_set_name (notebook, "notebook");
gtk_widget_show (notebook);
- gtk_container_add (GTK_CONTAINER (window), notebook);
+ gtk_box_pack_start (GTK_BOX (vbox), notebook, TRUE, TRUE, 0);
+ //gtk_container_add (GTK_CONTAINER (vbox), notebook);
+
+ syncbutton = gtk_toggle_button_new_with_mnemonic ("gtk-media-play");
+ gtk_button_set_use_stock (GTK_BUTTON (syncbutton), TRUE);
+ gtk_widget_set_name (syncbutton, "sync_button");
+ gtk_widget_show (syncbutton);
+ gtk_box_pack_start (GTK_BOX (vbox), syncbutton, FALSE, FALSE, 0);
+ g_signal_connect((gpointer)syncbutton, "pressed", G_CALLBACK(on_syncstart_button), this);
// QUAA
syncstart = true;
diff --git a/gui.h b/gui.h
index 3b014a9..a082671 100644
--- a/gui.h
+++ b/gui.h
@@ -79,6 +79,8 @@ class Gui {
private:
void status(char *format, ...);
GtkWidget *window;
+ GtkWidget *vbox;
+ GtkWidget *syncbutton;
GtkWidget *notebook;
};
diff --git a/utils.cpp b/utils.cpp
index d4d9daa..1e945d8 100644
--- a/utils.cpp
+++ b/utils.cpp
@@ -126,3 +126,28 @@ void chomp(char *str) {
strncpy(str, tmp, MAX_CHOMP_SIZE);
}
+
+
+
+#ifdef linux
+#include <sched.h>
+/* sets the process to "policy" policy, if max=1 then set at max priority,
+ else use min priority */
+
+bool set_rtpriority(bool max) {
+ struct sched_param schp;
+ // set the process to realtime privs
+
+ memset(&schp, 0, sizeof(schp));
+
+ if(max)
+ schp.sched_priority = sched_get_priority_max(SCHED_RR);
+ else
+ schp.sched_priority = sched_get_priority_min(SCHED_RR);
+
+ if (sched_setscheduler(0, SCHED_RR, &schp) != 0)
+ return false;
+ else
+ return true;
+}
+#endif
diff --git a/utils.h b/utils.h
index c5981b5..df7ca37 100644
--- a/utils.h
+++ b/utils.h
@@ -34,6 +34,8 @@ void jsleep(int sec, long nsec);
void chomp(char *str);
+bool set_rtpriority(bool max);
+
#endif