Skip to content

Commit

Permalink
[PR-174] - Icon caching support to reduce overhead on upstream provid…
Browse files Browse the repository at this point in the history
…ers.
  • Loading branch information
andyb2000 authored and adamsutton committed Jan 1, 2013
1 parent 2b0e495 commit acdc094
Show file tree
Hide file tree
Showing 15 changed files with 545 additions and 21 deletions.
4 changes: 3 additions & 1 deletion Makefile
Expand Up @@ -32,7 +32,7 @@ CFLAGS += -Wmissing-prototypes -fms-extensions
CFLAGS += -g -funsigned-char -O2
CFLAGS += -D_FILE_OFFSET_BITS=64
CFLAGS += -I${BUILDDIR} -I${CURDIR}/src -I${CURDIR}
LDFLAGS += -lrt -ldl -lpthread -lm
LDFLAGS += -lrt -ldl -lpthread -lm -lcurl

#
# Other config
Expand Down Expand Up @@ -140,6 +140,8 @@ SRCS += src/muxer.c \
src/muxer_pass.c \
src/muxer_tvh.c \

SRCS += src/iconserve.c \

#
# Optional code
#
Expand Down
14 changes: 14 additions & 0 deletions docs/html/config_misc.html
Expand Up @@ -20,5 +20,19 @@
dvb-apps stores these in /usr/share/dvb/. Leave blank to use TVH's internal
file set.

<dt>Cache channel icons:
<dd>
Enable the caching of channel icons. This will cause TVH to download channel
icons locally, and then when requested via HTSP clients the URL for the icon
(or logo) will be retrieved from the TVH web server rather than fetched each
time by the HTSP client.
This REQUIRES the TVH server IP address field to also be populated

<dt>TVH Server IP Address:
<dd>
Enter the IP address of the TVH server used for HTSP clients. This permits the
above cache channel icons to work (TVH Clients are directed to the IP address
entered here to retrieve channel icons from)

</dl>
</div>
47 changes: 47 additions & 0 deletions src/config2.c
Expand Up @@ -74,3 +74,50 @@ int config_set_muxconfpath ( const char *path )
}
return 0;
}

const char *config_get_iconserve ( void )
{
return htsmsg_get_str(config, "iconserve");
}

int config_set_iconserve ( const char *setting )
{
const char *c = config_get_iconserve();
if (!c || strcmp(c, setting)) {
if (c) htsmsg_delete_field(config, "iconserve");
htsmsg_add_str(config, "iconserve", setting);
return 1;
}
return 0;
}
const char *config_get_iconserve_periodicdownload ( void )
{
return htsmsg_get_str(config, "iconserve_periodicdownload");
}

int config_set_iconserve_periodicdownload ( const char *setting )
{
const char *c = config_get_iconserve_periodicdownload();
if (!c || strcmp(c, setting)) {
if (c) htsmsg_delete_field(config, "iconserve_periodicdownload");
htsmsg_add_str(config, "iconserve_periodicdownload", setting);
return 1;
}
return 0;
}

const char *config_get_serverip ( void )
{
return htsmsg_get_str(config, "serverip");
};

int config_set_serverip ( const char *setting )
{
const char *c = config_get_serverip();
if (!c || strcmp(c, setting)) {
if (c) htsmsg_delete_field(config, "serverip");
htsmsg_add_str(config, "serverip", setting);
return 1;
}
return 0;
};
12 changes: 12 additions & 0 deletions src/config2.h
Expand Up @@ -32,6 +32,18 @@ const char *config_get_muxconfpath ( void );
int config_set_muxconfpath ( const char *str )
__attribute__((warn_unused_result));

const char *config_get_iconserve ( void );
int config_set_iconserve ( const char *str )
__attribute__((warn_unused_result));

const char *config_get_iconserve_periodicdownload ( void );
int config_set_iconserve_periodicdownload ( const char *str )
__attribute__((warn_unused_result));

const char *config_get_serverip ( void );
int config_set_serverip ( const char *str )
__attribute__((warn_unused_result));

const char *config_get_language ( void );
int config_set_language ( const char *str )
__attribute__((warn_unused_result));
Expand Down
8 changes: 6 additions & 2 deletions src/htsp_server.c
Expand Up @@ -42,6 +42,8 @@
#include "htsmsg_binary.h"
#include "epg.h"
#include "plumbing/tsfix.h"
#include "iconserve.h"
#include "config2.h"

#include <sys/statvfs.h>
#include "settings.h"
Expand Down Expand Up @@ -447,8 +449,10 @@ htsp_build_channel(channel_t *ch, const char *method)
htsmsg_add_u32(out, "channelNumber", ch->ch_number);

htsmsg_add_str(out, "channelName", ch->ch_name);
if(ch->ch_icon != NULL)
htsmsg_add_str(out, "channelIcon", ch->ch_icon);

if(ch->ch_icon != NULL) {
htsmsg_add_str(out, "channelIcon", logo_query(ch->ch_id, ch->ch_icon));
};

now = ch->ch_epg_now;
next = ch->ch_epg_next;
Expand Down
14 changes: 7 additions & 7 deletions src/http.c
Expand Up @@ -173,18 +173,18 @@ http_send_header(http_connection_t *hc, int rc, const char *content,

tm = gmtime_r(&t, &tm0);
htsbuf_qprintf(&hdrs,
"Last-Modified: %s, %02d %s %d %02d:%02d:%02d GMT\r\n",
cachedays[tm->tm_wday], tm->tm_year + 1900,
cachemonths[tm->tm_mon], tm->tm_mday,
tm->tm_hour, tm->tm_min, tm->tm_sec);
"Last-Modified: %s, %d %s %02d %02d:%02d:%02d GMT\r\n",
cachedays[tm->tm_wday], tm->tm_mday,
cachemonths[tm->tm_mon], tm->tm_year + 1900,
tm->tm_hour, tm->tm_min, tm->tm_sec);

t += maxage;

tm = gmtime_r(&t, &tm0);
htsbuf_qprintf(&hdrs,
"Expires: %s, %02d %s %d %02d:%02d:%02d GMT\r\n",
cachedays[tm->tm_wday], tm->tm_year + 1900,
cachemonths[tm->tm_mon], tm->tm_mday,
"Expires: %s, %d %s %02d %02d:%02d:%02d GMT\r\n",
cachedays[tm->tm_wday], tm->tm_mday,
cachemonths[tm->tm_mon], tm->tm_year + 1900,
tm->tm_hour, tm->tm_min, tm->tm_sec);

htsbuf_qprintf(&hdrs, "Cache-Control: max-age=%d\r\n", maxage);
Expand Down

0 comments on commit acdc094

Please sign in to comment.