Initial HTSP async support

This commit is contained in:
Andreas Öman 2008-01-14 19:07:46 +00:00
parent ab6b9e229e
commit 08c24d441c
4 changed files with 96 additions and 21 deletions

3
epg.c
View file

@ -26,6 +26,7 @@
#include "epg.h"
#include "dispatch.h"
#include "htsclient.h"
#include "htsp.h"
#define EPG_MAX_AGE 86400
@ -378,6 +379,8 @@ epg_set_current_event(th_channel_t *ch, event_t *e)
/* Notify clients that a new programme is on */
clients_send_ref(ch->ch_tag);
htsp_async_channel_update(ch);
}
static void

90
htsp.c
View file

@ -37,9 +37,12 @@
#include "htsp.h"
#include "htsp_muxer.h"
#include "tcp.h"
#include "epg.h"
#include <libhts/htsmsg_binary.h>
static LIST_HEAD(, htsp) htsp_sessions;
/*
*
*/
@ -64,6 +67,79 @@ htsp_send_msg(htsp_t *htsp, htsmsg_t *m, int media)
}
/**
* build a channel message
*/
static htsmsg_t *
htsp_build_channel_msg(th_channel_t *ch, const char *method)
{
htsmsg_t *msg = htsmsg_create();
event_t *e;
htsmsg_add_str(msg, "method", method);
htsmsg_add_str(msg, "channelGroupName", ch->ch_group->tcg_name);
htsmsg_add_str(msg, "channelName", ch->ch_name);
htsmsg_add_u32(msg, "channelTag", ch->ch_tag);
if(ch->ch_icon != NULL)
htsmsg_add_str(msg, "channelIcon", refstr_get(ch->ch_icon));
if((e = epg_event_get_current(ch)) != NULL)
htsmsg_add_u32(msg, "currentEvent", e->e_tag);
return msg;
}
/**
* channels_list
*/
static void
htsp_send_all_channels(htsp_t *htsp)
{
htsmsg_t *msg;
th_channel_group_t *tcg;
th_channel_t *ch;
TAILQ_FOREACH(tcg, &all_channel_groups, tcg_global_link) {
if(tcg->tcg_hidden)
continue;
msg = htsmsg_create();
htsmsg_add_str(msg, "method", "channelGroupAdd");
htsmsg_add_str(msg, "channelGroupName", tcg->tcg_name);
htsp_send_msg(htsp, msg, 0);
TAILQ_FOREACH(ch, &tcg->tcg_channels, ch_group_link) {
if(LIST_FIRST(&ch->ch_transports) == NULL)
continue;
msg = htsp_build_channel_msg(ch, "channelAdd");
htsp_send_msg(htsp, msg, 0);
}
}
}
/**
*
*/
void
htsp_async_channel_update(th_channel_t *ch)
{
htsp_t *htsp;
htsmsg_t *msg;
LIST_FOREACH(htsp, &htsp_sessions, htsp_global_link) {
if(!htsp->htsp_rpc.rs_is_async)
continue;
msg = htsp_build_channel_msg(ch, "channelUpdate");
htsp_send_msg(htsp, msg, 0);
}
}
/*
*
*/
@ -71,7 +147,7 @@ static void
htsp_input(htsp_t *htsp, const void *buf, int len)
{
htsmsg_t *in, *out;
int i;
int i, was_async;
const uint8_t *v = buf;
printf("Got %d bytes\n", len);
@ -83,6 +159,9 @@ htsp_input(htsp_t *htsp, const void *buf, int len)
printf("deserialize failed\n");
return;
}
was_async = htsp->htsp_rpc.rs_is_async;
printf("INPUT:\n");
htsmsg_print(in);
@ -94,6 +173,11 @@ htsp_input(htsp_t *htsp, const void *buf, int len)
htsmsg_print(out);
htsp_send_msg(htsp, out, 0);
if(!was_async && htsp->htsp_rpc.rs_is_async) {
/* Session went into async state */
htsp_send_all_channels(htsp);
}
}
@ -158,6 +242,8 @@ htsp_data_input(htsp_t *htsp)
static void
htsp_disconnect(htsp_t *htsp)
{
LIST_REMOVE(htsp, htsp_global_link);
free(htsp->htsp_buf);
rpc_deinit(&htsp->htsp_rpc);
}
@ -173,6 +259,8 @@ htsp_connect(htsp_t *htsp)
htsp->htsp_bufsize = 1000;
htsp->htsp_buf = malloc(htsp->htsp_bufsize);
LIST_INSERT_HEAD(&htsp_sessions, htsp, htsp_global_link);
}
/*

4
htsp.h
View file

@ -27,6 +27,8 @@
typedef struct htsp {
tcp_session_t htsp_tcp_session; /* Must be first */
LIST_ENTRY(htsp) htsp_global_link;
int htsp_bufsize;
int htsp_bufptr;
int htsp_msglen;
@ -42,4 +44,6 @@ void htsp_start(int port);
int htsp_send_msg(htsp_t *htsp, htsmsg_t *m, int media);
void htsp_async_channel_update(th_channel_t *ch);
#endif /* HTSP_H_ */

20
rpc.c
View file

@ -58,26 +58,6 @@ rpc_build_channel_msg(th_channel_t *ch)
#if 0
/**
* channels_list
*/
static void
htsp_send_all_channels(htsp_connection_t *hc)
{
htsp_msg_t *msg;
th_channel_t *ch;
TAILQ_FOREACH(ch, &channels, ch_global_link) {
msg = htsp_build_channel_msg(ch);
htsp_add_string(msg, "msgtype", "channelAdd");
htsp_send_msg(hc, NULL, msg);
htsp_free_msg(msg);
}
}
#endif