diff -Naur tvheadend-master/Makefile tvheadend-master-android/Makefile --- tvheadend-master/Makefile 2014-04-29 09:19:45.000000000 +0900 +++ tvheadend-master-android/Makefile 2014-04-29 12:17:17.000000000 +0900 @@ -32,7 +32,8 @@ CFLAGS += -g -funsigned-char -O2 CFLAGS += -D_FILE_OFFSET_BITS=64 CFLAGS += -I${BUILDDIR} -I${ROOTDIR}/src -I${ROOTDIR} -LDFLAGS += -lrt -ldl -lpthread -lm +LDFLAGS += -ldl -lm -llog +#LDFLAGS += -lrt -ldl -lpthread -lm vpath %.c $(ROOTDIR) vpath %.h $(ROOTDIR) diff -Naur tvheadend-master/README tvheadend-master-android/README --- tvheadend-master/README 2014-03-15 22:33:55.000000000 +0900 +++ tvheadend-master-android/README 2014-04-29 11:02:01.000000000 +0900 @@ -16,6 +16,16 @@ $ ./configure +Sample configure for Android: + +$ ./configure --disable-avahi \ + --disable-libav \ + --enable-bundle \ + --enable-android \ + --arch=armeabi-v7a \ + --cc=arm-linux-androideabi-gcc \ + --android_toolchain=/home/jernej/Android/toolchain/android-9 + If any dependencies are missing the configure script will complain or attempt to disable optional features. diff -Naur tvheadend-master/configure tvheadend-master-android/configure --- tvheadend-master/configure 2014-04-29 09:19:45.000000000 +0900 +++ tvheadend-master-android/configure 2014-04-29 12:40:56.000000000 +0900 @@ -36,6 +36,7 @@ "bundle:no" "dvbcsa:no" "kqueue:no" + "android:no" "mpegts_dvb:auto" ) diff -Naur tvheadend-master/src/descrambler/capmt.c tvheadend-master-android/src/descrambler/capmt.c --- tvheadend-master/src/descrambler/capmt.c 2014-04-29 09:19:45.000000000 +0900 +++ tvheadend-master-android/src/descrambler/capmt.c 2014-04-29 11:04:58.000000000 +0900 @@ -75,10 +75,12 @@ printf(format, __VA_ARGS__); int j; for (j = 0; j < len; ++j) printf("%02X ", buf[j]); printf("\n"); #if defined(__GNUC__) && defined(__GNUC_MINOR__) +#if !ENABLE_ANDROID #if 100*__GNUC__+__GNUC_MINOR >=403 #pragma GCC diagnostic ignored "-Warray-bounds" #endif #endif +#endif #define MAX_CA 4 #define MAX_INDEX 64 diff -Naur tvheadend-master/src/epggrab.c tvheadend-master-android/src/epggrab.c --- tvheadend-master/src/epggrab.c 2014-03-15 22:33:55.000000000 +0900 +++ tvheadend-master-android/src/epggrab.c 2014-04-29 12:48:43.000000000 +0900 @@ -16,17 +16,20 @@ * along with this program. If not, see . */ +#include "tvheadend.h" + #include #include #include #include #include #include +#if !ENABLE_ANDROID #include +#endif #include #include "htsmsg.h" #include "settings.h" -#include "tvheadend.h" #include "queue.h" #include "epg.h" #include "epggrab.h" diff -Naur tvheadend-master/src/htsp_server.c tvheadend-master-android/src/htsp_server.c --- tvheadend-master/src/htsp_server.c 2014-03-18 20:23:28.000000000 +0900 +++ tvheadend-master-android/src/htsp_server.c 2014-04-29 11:24:37.000000000 +0900 @@ -54,7 +54,11 @@ #include #include #include +#if ENABLE_ANDROID +#include +#else #include +#endif #include "settings.h" #include @@ -850,12 +854,21 @@ htsp_method_getDiskSpace(htsp_connection_t *htsp, htsmsg_t *in) { htsmsg_t *out; +#if ENABLE_ANDROID + struct statfs diskdata; +#else struct statvfs diskdata; +#endif dvr_config_t *cfg = dvr_config_find_by_name_default(""); +#if ENABLE_ANDROID + if(statfs(cfg->dvr_storage,&diskdata) == -1) + return htsp_error("Unable to stat path"); +#else if(statvfs(cfg->dvr_storage,&diskdata) == -1) return htsp_error("Unable to stat path"); - +#endif + out = htsmsg_create_map(); htsmsg_add_s64(out, "freediskspace", diskdata.f_bsize * (int64_t)diskdata.f_bavail); diff -Naur tvheadend-master/src/input/mpegts/tsfile/tsfile.c tvheadend-master-android/src/input/mpegts/tsfile/tsfile.c --- tvheadend-master/src/input/mpegts/tsfile/tsfile.c 2014-04-29 09:19:45.000000000 +0900 +++ tvheadend-master-android/src/input/mpegts/tsfile/tsfile.c 2014-04-29 13:04:50.000000000 +0900 @@ -110,7 +110,12 @@ { tsfile_input_t *mi; mpegts_mux_t *mm; + +#ifdef __BIONIC__ + char *uuid = NULL, *tok, *tmp = strdup(path); +#else char *uuid = NULL, *tok, *tmp = strdupa(path); +#endif /* Pull UUID from info */ if ((tok = strstr(tmp, "::"))) { diff -Naur tvheadend-master/src/input/mpegts/tsfile/tsfile_input.c tvheadend-master-android/src/input/mpegts/tsfile/tsfile_input.c --- tvheadend-master/src/input/mpegts/tsfile/tsfile_input.c 2014-04-29 09:19:45.000000000 +0900 +++ tvheadend-master-android/src/input/mpegts/tsfile/tsfile_input.c 2014-04-29 11:35:04.000000000 +0900 @@ -33,6 +33,9 @@ extern const idclass_t mpegts_input_class; +#if ENABLE_ANDROID +extern int clock_nanosleep(clockid_t, int, const struct timespec *, struct timespec *); +#endif static void * tsfile_input_thread ( void *aux ) diff -Naur tvheadend-master/src/main.c tvheadend-master-android/src/main.c --- tvheadend-master/src/main.c 2014-04-29 09:19:45.000000000 +0900 +++ tvheadend-master-android/src/main.c 2014-04-29 11:27:59.000000000 +0900 @@ -180,6 +180,9 @@ get_user_groups (const struct passwd *pw, gid_t* glist, size_t gmax) { int num = 0; +#if ENABLE_ANDROID + return num; +#else struct group *gr; char **mem; glist[num++] = pw->pw_gid; @@ -190,6 +193,7 @@ } } return num; +#endif } /** @@ -800,7 +804,11 @@ signal(SIGTERM, doexit); signal(SIGINT, doexit); +#if ENABLE_ANDROID + sigprocmask(SIG_UNBLOCK, &set, NULL); +#else pthread_sigmask(SIG_UNBLOCK, &set, NULL); +#endif tvhlog(LOG_NOTICE, "START", "HTS Tvheadend version %s started, " "running as PID:%d UID:%d GID:%d, CWD:%s CNF:%s", diff -Naur tvheadend-master/src/muxer.c tvheadend-master-android/src/muxer.c --- tvheadend-master/src/muxer.c 2014-04-29 09:19:45.000000000 +0900 +++ tvheadend-master-android/src/muxer.c 2014-04-29 12:56:48.000000000 +0900 @@ -458,7 +458,9 @@ fsync(fd); /* fall through */ case MC_CACHE_DONTKEEP: +#if !ENABLE_ANDROID posix_fadvise(fd, pos, size, POSIX_FADV_DONTNEED); +#endif break; default: abort(); diff -Naur tvheadend-master/src/spawn.c tvheadend-master-android/src/spawn.c --- tvheadend-master/src/spawn.c 2014-03-15 22:33:55.000000000 +0900 +++ tvheadend-master-android/src/spawn.c 2014-04-29 11:35:51.000000000 +0900 @@ -33,6 +33,10 @@ #include "file.h" #include "spawn.h" +#ifndef WIFCONTINUED +#define WIFCONTINUED(s) ((s) == 0xffff) +#endif + extern char **environ; pthread_mutex_t spawn_mutex = PTHREAD_MUTEX_INITIALIZER; diff -Naur tvheadend-master/src/timeshift/timeshift_reader.c tvheadend-master-android/src/timeshift/timeshift_reader.c --- tvheadend-master/src/timeshift/timeshift_reader.c 2014-03-15 22:33:55.000000000 +0900 +++ tvheadend-master-android/src/timeshift/timeshift_reader.c 2014-04-29 11:47:34.000000000 +0900 @@ -325,7 +325,11 @@ ts->id, (*cur_file)->path); *fd = open((*cur_file)->path, O_RDONLY); } +#if ENABLE_ANDROID + tvhtrace("timeshift", "ts %d seek to %"PRIoff_t, ts->id, (long long int)*cur_off); +#else tvhtrace("timeshift", "ts %d seek to %"PRIoff_t, ts->id, *cur_off); +#endif lseek(*fd, *cur_off, SEEK_SET); /* Read msg */ @@ -336,8 +340,13 @@ tvhlog(LOG_ERR, "timeshift", "ts %d could not read buffer", ts->id); return -1; } +#if ENABLE_ANDROID + tvhtrace("timeshift", "ts %d read msg %p (%"PRIssize_t")", + ts->id, *sm, (int)r); +#else tvhtrace("timeshift", "ts %d read msg %p (%"PRIssize_t")", ts->id, *sm, r); +#endif /* Incomplete */ if (r == 0) { diff -Naur tvheadend-master/src/tvheadend.h tvheadend-master-android/src/tvheadend.h --- tvheadend-master/src/tvheadend.h 2014-04-29 09:19:45.000000000 +0900 +++ tvheadend-master-android/src/tvheadend.h 2014-04-29 11:50:45.000000000 +0900 @@ -44,6 +44,10 @@ #include "redblack.h" +#if ENABLE_ANDROID +#define S_IEXEC S_IXUSR +#endif + typedef struct { const char *name; const uint32_t *enabled; @@ -507,6 +511,28 @@ return tp.tv_sec * 1000000ULL + (tp.tv_nsec / 1000); } +#if ENABLE_ANDROID +static inline time_t timegm(struct tm *tm); + +time_t +timegm(struct tm *tm) +{ + time_t ret; + char *tz; + + tz = getenv("TZ"); + setenv("TZ", "", 1); + tzset(); + ret = mktime(tm); + if (tz) + setenv("TZ", tz, 1); + else + unsetenv("TZ"); + tzset(); + return ret; +} +#endif + int sri_to_rate(int sri); int rate_to_sri(int rate); diff -Naur tvheadend-master/src/tvhlog.c tvheadend-master-android/src/tvhlog.c --- tvheadend-master/src/tvhlog.c 2014-03-15 22:33:55.000000000 +0900 +++ tvheadend-master-android/src/tvhlog.c 2014-04-29 12:47:45.000000000 +0900 @@ -147,7 +147,9 @@ tvhlog_process ( tvhlog_msg_t *msg, int options, FILE **fp, const char *path ) { +#if !ENABLE_ANDROID int s; +#endif size_t l; char buf[2048], t[128]; struct tm tm; @@ -155,8 +157,12 @@ /* Syslog */ if (options & TVHLOG_OPT_SYSLOG) { if (options & TVHLOG_OPT_DBG_SYSLOG || msg->severity < LOG_DEBUG) { +#if ENABLE_ANDROID + __android_log_print(ANDROID_LOG_DEBUG, "tvheadend", "%s", msg->msg); +#else s = msg->severity > LOG_DEBUG ? LOG_DEBUG : msg->severity; syslog(s, "%s", msg->msg); +#endif } } @@ -413,7 +419,9 @@ tvhlog_trace = NULL; tvhlog_debug = NULL; tvhlog_run = 0; +#if !ENABLE_ANDROID openlog("tvheadend", LOG_PID, LOG_DAEMON); +#endif pthread_mutex_init(&tvhlog_mutex, NULL); pthread_cond_init(&tvhlog_cond, NULL); TAILQ_INIT(&tvhlog_queue); diff -Naur tvheadend-master/src/tvhlog.h tvheadend-master-android/src/tvhlog.h --- tvheadend-master/src/tvhlog.h 2014-03-15 22:33:55.000000000 +0900 +++ tvheadend-master-android/src/tvhlog.h 2014-04-29 12:46:17.000000000 +0900 @@ -18,8 +18,27 @@ #ifndef __TVH_LOGGING_H__ #define __TVH_LOGGING_H__ +#include "config.h" +#include "tvheadend.h" + #include + +#if ENABLE_ANDROID +#include + +#define LOG_EMERG 0 /* system is unusable */ +#define LOG_ALERT 1 /* action must be taken immediately */ +#define LOG_CRIT 2 /* critical conditions */ +#define LOG_ERR 3 /* error conditions */ +#define LOG_WARNING 4 /* warning conditions */ +#define LOG_NOTICE 5 /* normal but significant condition */ +#define LOG_INFO 6 /* informational */ +#define LOG_DEBUG 7 /* debug-level messages */ + +#else #include +#endif + #include #include diff -Naur tvheadend-master/src/tvhtime.c tvheadend-master-android/src/tvhtime.c --- tvheadend-master/src/tvhtime.c 2014-03-15 22:33:55.000000000 +0900 +++ tvheadend-master-android/src/tvhtime.c 2014-04-29 12:50:19.000000000 +0900 @@ -1,8 +1,12 @@ #define _ISOC9X_SOURCE +#include "tvheadend.h" + #include #include +#if !ENABLE_ANDROID #include +#endif #include #include #include @@ -11,7 +15,6 @@ #include #include "tvhtime.h" -#include "tvheadend.h" #include "settings.h" uint32_t tvhtime_update_enabled; @@ -46,6 +49,7 @@ int pad[10]; } ntp_shm_t; +#if !ENABLE_ANDROID static ntp_shm_t * ntp_shm_init ( void ) { @@ -72,6 +76,7 @@ return shmptr; } +#endif /* * Update time @@ -79,12 +84,13 @@ void tvhtime_update ( struct tm *tm ) { +#if !ENABLE_ANDROID time_t now; struct timeval tv; ntp_shm_t *ntp_shm; int64_t t1, t2; - tvhtrace("time", "current time is %04d/%02d/%02d %02d:%02d:%02d", + tvhtrace("time", "current time is %04d/%02d/%02d %02d:%02d:%02d", tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); /* Current and reported time */ @@ -122,6 +128,7 @@ ntp_shm->count++; ntp_shm->valid = 1; } +#endif } /* Initialise */ diff -Naur tvheadend-master/src/version.c tvheadend-master-android/src/version.c --- tvheadend-master/src/version.c 1970-01-01 09:00:00.000000000 +0900 +++ tvheadend-master-android/src/version.c 2014-04-29 12:22:43.000000000 +0900 @@ -0,0 +1 @@ +const char *tvheadend_version = "0.0.0~unknown"; diff -Naur tvheadend-master/src/webui/webui.c tvheadend-master-android/src/webui/webui.c --- tvheadend-master/src/webui/webui.c 2014-04-29 09:19:45.000000000 +0900 +++ tvheadend-master-android/src/webui/webui.c 2014-04-29 12:08:50.000000000 +0900 @@ -55,6 +55,9 @@ #include #endif +#if ENABLE_ANDROID +#include +#endif /** * */ @@ -961,8 +964,14 @@ file_end = st.st_size-1; range = http_arg_get(&hc->hc_args, "Range"); + +#if ENABLE_ANDROID + if(range != NULL) + sscanf(range, "bytes=%"PRId64"-%"PRId64"", (long long int *)&file_start, (long long int *)&file_end); +#else if(range != NULL) sscanf(range, "bytes=%"PRId64"-%"PRId64"", &file_start, &file_end); +#endif //Sanity checks if(file_start < 0 || file_start >= st.st_size) { @@ -981,8 +990,13 @@ content_len = file_end - file_start+1; +#if ENABLE_ANDROID + sprintf(range_buf, "bytes %"PRId64"-%"PRId64"/%"PRId64"", + (long long int)file_start, (long long int)file_end, st.st_size); +#else sprintf(range_buf, "bytes %"PRId64"-%"PRId64"/%"PRId64"", file_start, file_end, st.st_size); +#endif if(file_start > 0) lseek(fd, file_start, SEEK_SET); diff -Naur tvheadend-master/support/configure.inc tvheadend-master-android/support/configure.inc --- tvheadend-master/support/configure.inc 2014-04-29 09:19:45.000000000 +0900 +++ tvheadend-master-android/support/configure.inc 2014-04-29 12:15:21.000000000 +0900 @@ -201,7 +201,7 @@ *dir|prefix) eval "$opt=$val" ;; - cc|cflags|arch|cpu|platform|python) + cc|cflags|arch|cpu|platform|python|android_toolchain) eval "`toupper $opt`=$val" ;; enable-*) @@ -497,6 +497,19 @@ #define PLATFORM_$(toupper ${PLATFORM}) 1 EOF +if enabled android; then +cat >>${CONFIG_MK} <>${CONFIG_MK} <>"${CONFIG_MK}" <