From 2db562a5587d7e5ca8ca0436c9678f8141734e04 Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Tue, 6 Apr 2010 09:40:32 +0200 Subject: replay fix - stop on 'prev' command --- src/tsnif-replay.c | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/src/tsnif-replay.c b/src/tsnif-replay.c index a0ec61e..40db4da 100644 --- a/src/tsnif-replay.c +++ b/src/tsnif-replay.c @@ -97,6 +97,7 @@ static struct timeval get_timeout(struct timespec *ts_new, enum { ACTION_NEXT, ACTION_PREV, + ACTION_PLAY, ACTION_FIRST, ACTION_TIMEOUT, ACTION_STOP, @@ -108,6 +109,7 @@ enum { static int display_slave = 1; static int display_master= 0; +static int play = 1; static int output(struct tsnif_storage_rec *rec) { @@ -150,6 +152,7 @@ static int get_action(struct timeval *tv) } switch(c) { + case 'P' : return ACTION_PLAY; case 'p' : return ACTION_PREV; case 'n' : return ACTION_NEXT; case 'f' : return ACTION_FIRST; @@ -175,30 +178,46 @@ static int process(void) do { struct timespec ts_prev; - struct timeval tv; - - memset(&tv, 0x0, sizeof(tv)); + struct timeval tv_def, *tv = NULL; if (err != TSNIF_STORAGE_READ_EOF) { + output(&rec); - ts_prev = rec.time; + if (play) { + tv = &tv_def; + memset(tv, 0x0, sizeof(*tv)); + ts_prev = rec.time; - err = tsnif_storage_read(&storage_handle, - TSNIF_STORAGE_READ_NEXT, &rec); - if (err < 0) - break; + err = tsnif_storage_read(&storage_handle, + TSNIF_STORAGE_READ_NEXT, &rec); + if (err < 0) + break; - tv = get_timeout(&rec.time, &ts_prev); + *tv = get_timeout(&rec.time, &ts_prev); + } } - action = get_action(&tv); + action = get_action(tv); + switch(action) { + case ACTION_PLAY: + play = !play; + break; + case ACTION_PREV: err = tsnif_storage_read(&storage_handle, TSNIF_STORAGE_READ_PREV, &rec); if (err < 0) return err; + + /* we reached the first item, do not report + * XXX different code for first item ??? */ + if (err == TSNIF_STORAGE_READ_EOF) + err = 0; + + /* stop play mode when going back */ + play = 0; break; case ACTION_SLAVE: -- cgit