X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=play.c;h=4f734a3f729c526b8b319edbf2a477c636e2abe6;hb=d955fb7bc5640767c14560e06e6f9c47d3cb49c5;hp=b60557244f5755b620c10240c60a2b73e28983e1;hpb=563b56a493d6a2bdcdebafadd907954dbe1de8a8;p=paraslash.git diff --git a/play.c b/play.c index b6055724..4f734a3f 100644 --- a/play.c +++ b/play.c @@ -7,6 +7,7 @@ #include #include "recv_cmd.lsg.h" +#include "filter_cmd.lsg.h" #include "play_cmd.lsg.h" #include "write_cmd.lsg.h" #include "play.lsg.h" @@ -23,16 +24,7 @@ #include "recv.h" #include "write.h" #include "fd.h" - -/** - * Besides playback tasks which correspond to the receiver/filter/writer nodes, - * para_play creates two further tasks: The play task and the i9e task. It is - * important whether a function can be called in the context of para_play or - * i9e or both. As a rule, all command handlers are called only in i9e context via - * the line handler (input mode) or the key handler (command mode) below. - * - * Playlist handling is done exclusively in play context. - */ +#include "interactive.h" /** Array of error strings. */ DEFINE_PARA_ERRLIST; @@ -192,6 +184,7 @@ static char get_playback_state(void) assert(false); }; +/* returns number of milliseconds */ static long unsigned get_play_time(void) { char state = get_playback_state(); @@ -201,16 +194,16 @@ static long unsigned get_play_time(void) return 0; if (pt->num_chunks == 0 || pt->seconds == 0) return 0; - /* where the stream started (in seconds) */ - result = pt->start_chunk * pt->seconds / pt->num_chunks; + /* where the stream started (in milliseconds) */ + result = 1000ULL * pt->start_chunk * pt->seconds / pt->num_chunks; if (pt->wn.btrn) { /* Add the uptime of the writer node */ struct timeval diff = {.tv_sec = 0}, wstime; btr_get_node_start(pt->wn.btrn, &wstime); if (wstime.tv_sec > 0) tv_diff(now, &wstime, &diff); - result += diff.tv_sec; + result += tv2ms(&diff); } - result = PARA_MIN(result, pt->seconds); + result = PARA_MIN(result, pt->seconds * 1000); result = PARA_MAX(result, 0UL); return result; } @@ -230,7 +223,7 @@ static int get_playback_error(void) int err; if (!pt->wn.task) - return 0; + return 1; err = task_status(pt->wn.task); if (err >= 0) return 0; @@ -238,8 +231,7 @@ static int get_playback_error(void) return 0; if (task_status(pt->rn.task) >= 0) return 0; - if (err == -E_BTR_EOF || err == -E_RECV_EOF || err == -E_EOF - || err == -E_WRITE_COMMON_EOF) + if (err == -E_EOF) return 1; return err; } @@ -262,9 +254,10 @@ static int eof_cleanup(void) decoder = filter_get(pt->fn.filter_num); task_reap(&pt->fn.task); - if (decoder->close) + if (decoder && decoder->close) decoder->close(&pt->fn); btr_remove_node(&pt->fn.btrn); + lls_free_parse_result(pt->fn.lpr, FILTER_CMD(pt->fn.filter_num)); free(pt->fn.conf); memset(&pt->fn, 0, sizeof(struct filter_node)); @@ -478,8 +471,6 @@ static void kill_stream(void) task_notify(pt->wn.task, E_EOF); } -#ifdef HAVE_READLINE - /* only called from com_prev(), nec. only if we have readline */ static int previous_valid_file(void) { @@ -496,8 +487,6 @@ static int previous_valid_file(void) return -E_NO_VALID_FILES; } -#include "interactive.h" - /* * Define the default (internal) key mappings and helper functions to get the * key sequence or the command from a key id, which is what we obtain from @@ -840,20 +829,20 @@ EXPORT_PLAY_CMD_HANDLER(play); static int com_pause(__a_unused struct lls_parse_result *lpr) { char state; - long unsigned seconds, ss; + uint64_t ms; + unsigned long cn; /* chunk num */ state = get_playback_state(); pt->playing = false; if (state != 'P') return 0; - seconds = get_play_time(); + ms = get_play_time(); pt->playing = false; - ss = 0; + cn = 0; if (pt->seconds > 0) - ss = seconds * pt->num_chunks / pt->seconds + 1; - ss = PARA_MAX(ss, 0UL); - ss = PARA_MIN(ss, pt->num_chunks); - pt->start_chunk = ss; + cn = ms * pt->num_chunks / pt->seconds / 1000 + 1; + cn = PARA_MIN(cn, pt->num_chunks); + pt->start_chunk = cn; pt->rq = CRT_REPOS; kill_stream(); return 0; @@ -953,7 +942,7 @@ static int com_ff(struct lls_parse_result *lpr) return ret; if (pt->playing && !pt->fn.btrn) return 0; - seconds += get_play_time(); + seconds += (get_play_time() + 500) / 1000; seconds = PARA_MIN(seconds, (typeof(seconds))pt->seconds - 4); seconds = PARA_MAX(seconds, 0); pt->start_chunk = pt->num_chunks * seconds / pt->seconds; @@ -1056,9 +1045,9 @@ static void session_open(void) char *dot_para = make_message("%s/.paraslash", home); free(home); - ret = para_mkdir(dot_para, 0777); + ret = para_mkdir(dot_para); /* warn, but otherwise ignore mkdir error */ - if (ret < 0 && ret != -ERRNO_TO_PARA_ERROR(EEXIST)) + if (ret < 0) PARA_WARNING_LOG("Can not create %s: %s\n", dot_para, para_strerror(-ret)); history_file = make_message("%s/play.history", dot_para); @@ -1139,31 +1128,6 @@ static int session_post_monitor(__a_unused struct sched *s) return 0; } -#else /* HAVE_READLINE */ - -static int session_post_monitor(struct sched *s) -{ - char c; - - if (!sched_read_ok(STDIN_FILENO, s)) - return 0; - if (read(STDIN_FILENO, &c, 1)) - do_nothing; - kill_stream(); - return 1; -} - -static void session_open(void) -{ -} - -static void session_update_time_string(char *str, __a_unused unsigned len) -{ - printf("\r%s ", str); - fflush(stdout); -} -#endif /* HAVE_READLINE */ - static void play_pre_monitor(struct sched *s, __a_unused void *context) { char state; @@ -1188,7 +1152,7 @@ static unsigned get_time_string(char **result) length = pt->seconds; if (length == 0) return xasprintf(result, "0:00 [0:00] (0%%/0:00)"); - seconds = get_play_time(); + seconds = (get_play_time() + 500) / 1000; return xasprintf(result, "#%u: %d:%02d [%d:%02d] (%d%%/%d:%02d) %s", pt->current_file, seconds / 60, @@ -1245,10 +1209,25 @@ out: /** * The main function of para_play. * - * \param argc Standard. - * \param argv Standard. + * \param argc See man page. + * \param argv See man page. + * + * para_play distributes its work by submitting various tasks to the paraslash + * scheduler. The receiver, filter and writer tasks, which are used to play an + * audio file, require one task each to maintain their underlying buffer tree + * node. These tasks only exist when an audio file is playing. + * + * The i9 task, which is submitted and maintained by the i9e subsystem, reads + * an input line and calls the corresponding command handler such as com_stop() + * which is implemented in this file. The command handlers typically write a + * request to the global play_task structure, whose contents are read and acted + * upon by another task, the play task. + * + * As a rule, playlist handling is performed exclusively in play context, i.e. + * in the post-monitor step of the play task, while command handlers are only + * called in i9e context. * - * \return \p EXIT_FAILURE or \p EXIT_SUCCESS. + * \return EXIT_FAILURE or EXIT_SUCCESS. */ int main(int argc, char *argv[]) {