From: volpol Date: Sat, 7 Sep 2013 10:01:59 +0000 (+0000) Subject: Store intermediate playlist in a tempfile no longer! Put it into the new and (the... X-Git-Url: https://git.packet-gain.de/?a=commitdiff_plain;h=975cf97f08ac0722d02df967670fe3db4cb32a9d;p=hls.git Store intermediate playlist in a tempfile no longer! Put it into the new and (the shiniest) shiny memfile! Some cleanup? or maybe not. memfile could use some more love in the future :) --- diff --git a/CMakeLists.txt b/CMakeLists.txt index df3eb27..71683fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,17 @@ cmake_minimum_required(VERSION 2.6) project(HLS) +set( CMAKE_C_FLAGS "-W -Wall -Wextra" ) include_directories(${HLS_SOURCE_DIR}) add_definitions(-DUSE_TCP) -add_executable(hls curly.c itemq.c m3u8.c) +#add_definitions(-DDEBUG) +add_executable(hls curly.c itemq.c m3u8.c memfile.c) include(FindPkgConfig) pkg_check_modules(CURL REQUIRED libcurl) include_directories(${CURL_INCLUDE_DIR}) target_link_libraries(hls ${CURL_LIBRARIES} ) + +# add distclean make target +add_custom_target( distclean + make clean + COMMAND rm -rf CMakeFiles CMakeCache.txt cmake_install.cmake Makefile +) diff --git a/curly.c b/curly.c index 8102010..4f4d067 100644 --- a/curly.c +++ b/curly.c @@ -7,6 +7,7 @@ #include #include "log.h" +#include "memfile.h" #ifdef USE_TCP #include @@ -21,7 +22,6 @@ static int flag_conn; #endif static unsigned bufsize; -static unsigned delay; #define BSIZE 4096 @@ -76,14 +76,7 @@ size_t fetch_send(void *ptr, size_t size, size_t nmemb, void *stream) { } } - if (!flag_conn) - usleep(delay); - //either limit speed further or burst at max speed filling clien't buffer - //send will block when it's full thus slowing download down -/* - else - if (sent==bufsize) usleep(delay/2); //burst to fill client's buffer -*/ + (void)stream; return bytesize; } @@ -207,7 +200,7 @@ int curly_stream(const char *from_url, unsigned long duration) { //but try to take just as long time_t st = time(NULL); - while (conn < 0 && time(NULL)-stdone = 1; } - +#ifdef USE_STREAM int reload_m3u8(const char *from_file, const char *urlbase) { +#else +int reload_m3u8(MFILE *f, const char *urlbase) { +#endif +#ifdef USE_STREAM FILE *f; +#endif char buf[1024]; struct item *n; struct item *p; @@ -193,12 +199,16 @@ int reload_m3u8(const char *from_file, const char *urlbase) { plist = pid = bw = 0; DPRINT("Reloading M3U8\n"); - f = fopen(PLS, "r"); +#ifdef USE_STREAM + f = fopen(from_file, "r"); +#endif if (!f) return -1; - +#ifdef USE_STREAM while (fgets(buf, sizeof buf, f)) { - +#else + while (mgets(buf, sizeof buf, f)) { +#endif if (buf[strlen(buf) - 1] == '\n') buf[strlen(buf) - 1] = 0; if (buf[strlen(buf) - 1] == '\r') @@ -269,7 +279,9 @@ int reload_m3u8(const char *from_file, const char *urlbase) { } } } +#ifdef USE_STREAM fclose(f); +#endif return 0; } @@ -302,7 +314,6 @@ static void reset_base(char *base, char *url){ //TODO risky dice *(strrchr(base, '/')+1) = 0; } - int main(int argc, char *argv[]) { time_t last, now; @@ -312,8 +323,6 @@ int main(int argc, char *argv[]) { char url[1024]; char base[1024]; - //url = QVC_MASTER_M3U8; - if (argc>1) strcpy(url, argv[1]); else @@ -324,7 +333,7 @@ int main(int argc, char *argv[]) { reset_base(base, url); curly_init(); - curly_stream_init("0.0.0.0",1234); + curly_stream_init("0.0.0.0",1234); last = now = 0; @@ -337,11 +346,22 @@ int main(int argc, char *argv[]) { now = time(NULL); if (live && now-last>=refresh_period) { DPRINT("Refreshing M3U8 after %d real seconds\n",(int)(last?now-last:0)); +#ifdef USE_STREAM refreshed = (0 == curly_refresh_m3u8(url, PLS)); +#else + MFILE *f = mopen(NULL, 0, "w+"); + + refreshed = (0 == curly_refresh_m3u8(url, f)); +#endif if (refreshed) { last = now = time(NULL); purge_prepare(); +#ifdef USE_STREAM if (0 == reload_m3u8(PLS, base)) { +#else + if (0 == reload_m3u8(f, base)) { + mclose(f); +#endif refreshed = 0; purge_run(); print_list();