include_directories(${HLS_SOURCE_DIR})
add_definitions(-DUSE_TCP)
#add_definitions(-DDEBUG)
+add_definitions(-DUSE_TC7200_WORKAROUND)
add_executable(hls curly.c itemq.c m3u8.c memfile.c)
include(FindPkgConfig)
pkg_check_modules(CURL REQUIRED libcurl)
goto ERR_SUCC;
- ERR_LSTN:
- ERR_BIND:
+ERR_LSTN:
+ERR_BIND:
close(sock);
- ERR_SOCK:
- ERR_SUCC:
+ERR_SOCK:
+ERR_SUCC:
return err;
}
sch = curl_easy_init();
bufsize = BSIZE;
-//TODO error handling
+ //TODO error handling
err = prepare_tcp_dream(ip, port);
sch = NULL;
}
-
+#ifdef USE_TC7200_WORKAROUND
+#define TC7200_DEATH_COUNT 3
+#warning TC7200 workaround in effect
+#endif
int curly_stream(const char *from_url, unsigned long duration) {
CURLcode cc = CURLE_COULDNT_CONNECT;
int err = -1;
double abps, size;
+#ifdef USE_TC7200_WORKAROUND
+ static int tc7200_deathcounter = 0;
+#endif
WHOAMI;
curl_easy_setopt(sch, CURLOPT_BUFFERSIZE, bufsize);
+#ifdef USE_TC7200_WORKAROUND
+ //this is to work around a fucked up tc7200 router
+ //thanks a lot, technicolor
+ if (TC7200_DEATH_COUNT == ++tc7200_deathcounter ){
+ putchar('*');
+ curl_easy_setopt(sch, CURLOPT_FRESH_CONNECT, 1);
+ //curl_easy_setopt(sch, CURLOPT_FORBID_REUSE, 1);
+ tc7200_deathcounter = 0;
+ }
+#endif
+
#ifdef DEBUG
curl_easy_setopt(sch, CURLOPT_VERBOSE, 1L);
#endif
#include <string.h>
#include <sys/types.h>
#include <time.h>
+#include <signal.h>
#include "curly.h"
#include "m3u8.h"
#include "log.h"
#define QVC_800_M3U8 "http://live1.qvc.jp/iPhone/800.m3u8"
struct item;
-
-static int in_game;
+static volatile sig_atomic_t in_game;
static struct item *head, *tail, *curr;
static int live;
+
+static void handle_signal(int sig){
+ printf("Caught signal %d\n",sig);
+ switch (sig){
+ case SIGTERM:
+ case SIGINT:
+ if (!in_game) { puts("Hurry up!\n"); exit(-1); }
+ in_game = 0;
+ break;
+ }
+}
+
struct item {
char url[1024];
unsigned int hash;
return hash;
}
-static void purge_run(void) {
+static void purge_run(int killemall) {
struct item *n;
WHOAMI;
-//purge here
- while (head && head->purge) {
+ //purge here
+ while (head && (head->purge || killemall)) {
DPRINT("Purging %s:%X:%d:%d\n", head->url, head->hash, head->done,
head->purge);
n = head;
reset_base(base, url);
curly_init();
- curly_stream_init("0.0.0.0",1234);
+ curly_stream_init("0.0.0.0",7120);
last = now = 0;
head = tail = curr = NULL;
live = in_game = 1;
-
+ signal(SIGTERM, handle_signal);
+ signal(SIGINT, handle_signal);
while (in_game) {
now = time(NULL);
mclose(f);
#endif
refreshed = 0;
- purge_run();
+ purge_run(0);
print_list();
if (head->is_streamlist){
strcpy (url, choose_url());
reset_base(base, url);
curr = NULL; //so purge will not spare it
- purge_run();
+ purge_run(0);
last = 0;
continue;
}
}
-
+ purge_run(1);
curly_stream_cleanup();
curly_cleanup();
return 0;
#define M_RD 1
#define M_WR 2
-#define M_FREE 4
+#define M_AD 4
+#define M_FREE 16
int mclose(MFILE *mf){
WHOAMI;
if ('+' == mode[1]) r->flags |= M_RD;
break;
case 'a':
- r->flags |= M_WR;
+ r->flags |= M_WR | M_AD;
+ if ('+' == mode[1]) r->flags |= M_RD;
break;
}
if (NULL == r->pm) r->flags |= M_FREE;
return r;
}
+#define FIX_WPOS(x) do { if (x->flags & M_AD) x->wpos = x->length; } while (0)
+
int mputc(int c, MFILE *mf){
WHOAMI;
if ((mf->flags & M_WR) == 0) return -1;
+ FIX_WPOS(mf);
if (mf->wpos + 1 > mf->length){
mf->pm = realloc(mf->pm, mf->length + 1);
mf->length++;
WHOAMI;
size_t p = mf->rpos;
int c,slen = 0;
- do { c = mgetc(mf); } while ( (c != -1) && (++slen <= size-1) && (c != '\n'));
+ do { c = mgetc(mf); } while ( (c != -1) && (++slen < size-1) && (c != '\n'));
if (0 == slen) return NULL;
memcpy(s, mf->pm+p, slen);
void *npf;
WHOAMI;
if ((mf->flags & M_WR) == 0) return -1;
+ FIX_WPOS(mf);
while (nmemb){
if (mf->wpos + size > mf->length){
npf = realloc(mf->pm, mf->wpos + size );