From: volpol Date: Thu, 20 Mar 2014 17:53:35 +0000 (+0000) Subject: First attempt at stream capture (only while a client is connected for X-Git-Url: https://git.packet-gain.de/?a=commitdiff_plain;h=8f2a727861f05056d45dfe215321e3975ca662a3;p=hls.git First attempt at stream capture (only while a client is connected for now) --- diff --git a/curly.c b/curly.c index 80789ae..a3539f7 100644 --- a/curly.c +++ b/curly.c @@ -21,13 +21,44 @@ static int sock; static int conn; static int flag_conn; - #endif +static FILE *capf = NULL; + static unsigned bufsize; #define BSIZE 4096 +int curly_stop_capture(void){ + FILE *tmp = capf; + capf = NULL; + puts("Finishing capture"); + if (tmp) fclose(tmp); + return 0; + +} + +int curly_start_capture(void){ + + time_t t; + char fname[256]; + + if (capf) curly_stop_capture(); + + t = time(NULL); + strftime(fname, sizeof fname, "QVC_%Y%m%d_%H%M.ts", localtime(&t)); + + capf = fopen(fname, "w"); + + if (capf) + printf ("Starting capture to %s\n", fname); + else + puts ("Tough luck!"); + + return (NULL != capf) ? 0 : -1; + +} + #ifdef USE_TCP @@ -52,6 +83,8 @@ static void simple_http(int sock) { DPRINT ("simple http response sent\n"); } +//TODO capture even in absence of the client? + size_t fetch_send(void *ptr, size_t size, size_t nmemb, void *stream) { size_t bytesize = size * nmemb; @@ -70,6 +103,7 @@ size_t fetch_send(void *ptr, size_t size, size_t nmemb, void *stream) { if (flag_conn) { sent = send(conn, ptr, bytesize, MSG_NOSIGNAL); + if (capf) fwrite(ptr, size, nmemb, capf); if (sent <= 0) { DPRINT("Pious Teardown!\n"); shutdown(conn, SHUT_RDWR); @@ -77,6 +111,7 @@ size_t fetch_send(void *ptr, size_t size, size_t nmemb, void *stream) { conn = -1; flag_conn = 0; } + usleep(1500); } (void)stream; diff --git a/curly.h b/curly.h index 568a9d6..c000a48 100644 --- a/curly.h +++ b/curly.h @@ -17,4 +17,7 @@ void curly_stream_cleanup(void); int curly_is_connected(void); +int curly_stop_capture(void); +int curly_start_capture(void); + #endif /* CURLY_H_ */ diff --git a/itemq.c b/itemq.c index 4754b39..1f2f0cf 100644 --- a/itemq.c +++ b/itemq.c @@ -19,14 +19,18 @@ #define QVC_800_M3U8 "http://live1.qvc.jp/iPhone/800.m3u8" struct item; -static volatile sig_atomic_t in_game; +static volatile sig_atomic_t in_game, capt_req; static struct item *head, *tail, *curr; static int live; +static int capturing; static void handle_signal(int sig){ printf("Caught signal %d\n",sig); switch (sig){ + case SIGUSR1: + capt_req = 1; + break; case SIGTERM: case SIGINT: if (!in_game) { puts("Hurry up!\n"); exit(-1); } @@ -326,6 +330,19 @@ static void reset_base(char *base, char *url){ *(strrchr(base, '/')+1) = 0; } +static void cap_isr(void){ + if (capt_req){ + if (capturing) { + curly_stop_capture(); + capturing = 0; + } else { + capturing = !curly_start_capture(); + } + capt_req = 0; + //return IRQF_HANDLED ;) + } +} + int main(int argc, char *argv[]) { time_t last, now; @@ -351,9 +368,11 @@ int main(int argc, char *argv[]) { last = now = 0; head = tail = curr = NULL; live = in_game = 1; + capturing = capt_req = 0; signal(SIGTERM, handle_signal); signal(SIGINT, handle_signal); + signal(SIGUSR1, handle_signal); while (in_game) { now = time(NULL); @@ -399,6 +418,7 @@ int main(int argc, char *argv[]) { } } + cap_isr(); emulate_stream();