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
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;
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);
conn = -1;
flag_conn = 0;
}
+ usleep(1500);
}
(void)stream;
#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); }
*(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;
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);
}
}
+ cap_isr();
emulate_stream();