From: volpol Date: Wed, 9 Sep 2020 09:38:52 +0000 (+0200) Subject: Prevent recurring output unless requested X-Git-Url: https://git.packet-gain.de/?a=commitdiff_plain;h=refs%2Fheads%2Fmaster;p=hls.git Prevent recurring output unless requested --- diff --git a/curly.c b/curly.c index 9d13ab9..ffa3d5e 100644 --- a/curly.c +++ b/curly.c @@ -295,6 +295,8 @@ void curly_stream_cleanup(void) { sch = NULL; } +//TODO: make it a callback instead +extern void report_xfer(double size, double abps, time_t start); int curly_stream(const char *from_url, unsigned long duration) { CURLcode cc = CURLE_COULDNT_CONNECT; @@ -362,7 +364,7 @@ if (0 && bw_hint) FAKED: if (CURLE_OK == cc) - printf("%8.0f bytes @ %4.2f KB/s (%lu real seconds)\n", size, abps / 1000.0, time(NULL)-st); + report_xfer(size, abps, st); err = 0; CS_OUT: diff --git a/itemq.c b/itemq.c index 331173b..bfedf66 100644 --- a/itemq.c +++ b/itemq.c @@ -32,6 +32,7 @@ static struct { int refresh_interval; const char *cap_base; const char *master_url; + int verbose; } config = { // .refresh_interval = 20, .cap_base = "QVC", @@ -194,23 +195,19 @@ void emulate_stream(void) { if (!live) { in_game = 0; } else { - puts("Ran out of steam..."); - //printf("Ran out of steam, sleeping for %lu\n", sleep_dur); - //DPRINT("sleeping\n"); - //force_refresh = 1; - //sleep(sleep_dur); - sleep(1); + if (config.verbose) puts("Ran out of steam..."); + usleep(1000); } return; } } do { - printf("Streaming %s (%lu)\n", curr->url, curr->duration); + if(config.verbose) printf("Streaming %s (%lu)\n", curr->url, curr->duration); #if 1 err = curly_stream(curr->url, curr->duration); #ifdef USE_CAPTURE - printf ("Ringbuffer is %lu%% filled\n", ring_usage() * 100 / ring_capacity()); + if (config.verbose) printf ("Ringbuffer is %lu%% filled\n", ring_usage() * 100 / ring_capacity()); #endif #else err = -1; curly_fake_stream(); @@ -291,7 +288,7 @@ int reload_m3u8(void *src, const char *urlbase) { } if (M_X_TARGETDURATION == m){ m3u8_get_property(P_DURATION, v, &tgt); - printf ("Target duration: %lu\n", tgt); + if (config.verbose) printf ("Target duration: %lu\n", tgt); } if (M_URL != m) continue; @@ -342,12 +339,12 @@ int reload_m3u8(void *src, const char *urlbase) { } } - printf ("Estimated duration: %lu\n", est); + if (config.verbose) printf ("Estimated duration: %lu\n", est); if (!config.refresh_interval) { refresh_interval = tgt > est ? est : tgt; if (refresh_interval > 2 ) refresh_interval--; } - printf ("Using refresh int: %d\n", refresh_interval); + if (config.verbose) printf ("Using refresh int: %d\n", refresh_interval); return 0; } @@ -407,11 +404,12 @@ static void cap_isr(void){ } #endif +#define DEFAULT_OPTS "r:dvi:a:u:" void parse_config (int argc, char *argv[]){ #ifdef USE_CAPTURE - const char *ostr = "r:c:di:a:u:"; + const char *ostr = DEFAULT_OPTS"c:"; #else - const char *ostr = "r:di:a:u:"; + const char *ostr = DEFAULT_OPTS; #endif int opt; @@ -425,6 +423,9 @@ void parse_config (int argc, char *argv[]){ config.cap_base = optarg; break; #endif + case 'v': + config.verbose = 1; + break; case 'd': config.disable_bwhint = 1; break; @@ -452,6 +453,11 @@ void parse_config (int argc, char *argv[]){ printf ("Master URL: %s\n",config.master_url); } +void report_xfer(double size, double abps, time_t start){ + if (config.verbose) + printf("%8.0f bytes @ %4.2f KB/s (%lu real seconds)\n", size, abps / 1000.0, time(NULL)-start); +} + int main(int argc, char *argv[]) { time_t last, now; @@ -489,7 +495,7 @@ int main(int argc, char *argv[]) { while (in_game) { now = time(NULL); if (live && (force_refresh || now-last>=refresh_interval)) { - printf ("Refreshing M3U8 after %d real seconds (forced:%s)\n",(int)(last?now-last:0), force_refresh ? "yes" : "no"); + if (config.verbose) printf ("Refreshing M3U8 after %d real seconds (forced:%s)\n",(int)(last?now-last:0), force_refresh ? "yes" : "no"); force_refresh = 0; #ifdef USE_MEMFILE MFILE *f = mopen(NULL, 0, "w+");