]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
epg: Keep track of next event for all channels. (Useful if there is no current event...
authorAndreas Öman <andreas@lonelycoder.com>
Mon, 7 Mar 2011 19:58:07 +0000 (20:58 +0100)
committerAndreas Öman <andreas@lonelycoder.com>
Mon, 7 Mar 2011 19:58:07 +0000 (20:58 +0100)
htsp: Add nextEventId to HTSP channel updates

src/channels.h
src/epg.c
src/htsp.c
src/htsp.h
src/main.c

index 9cb02fdca1d3ab0d92d76d97188cf46288bfbf66..6dfbc73e0c307f57a918a251b4123922b03de735 100644 (file)
@@ -45,6 +45,7 @@ typedef struct channel {
 
   struct event_tree ch_epg_events;
   struct event *ch_epg_current;
+  struct event *ch_epg_next;
 
   gtimer_t ch_epg_timer_head;
   gtimer_t ch_epg_timer_current;
index 24bf59d2b1c4f54be126e06d2309277a87ffc372..aac82ea90832e7426c6b7a43c2373ebc41e4616a 100644 (file)
--- a/src/epg.c
+++ b/src/epg.c
@@ -53,16 +53,20 @@ e_ch_cmp(const event_t *a, const event_t *b)
  *
  */
 static void
-epg_set_current(channel_t *ch, event_t *e)
+epg_set_current(channel_t *ch, event_t *e, event_t *next)
 {
-  if(ch->ch_epg_current == e)
+  if(next == NULL && e != NULL)
+    next = RB_NEXT(e, e_channel_link);
+
+  if(ch->ch_epg_current == e && ch->ch_epg_next == next)
     return;
 
   ch->ch_epg_current = e;
+  ch->ch_epg_next = next;
   if(e != NULL)
     gtimer_arm_abs(&ch->ch_epg_timer_current, epg_ch_check_current_event,
                   ch, MAX(e->e_stop, dispatch_clock + 1));
-  htsp_event_update(ch, e);
+  htsp_channgel_update_current(ch);
 }
 
 /**
@@ -73,17 +77,16 @@ epg_ch_check_current_event(void *aux)
 {
   channel_t *ch = aux;
   event_t skel, *e = ch->ch_epg_current;
-
   if(e != NULL) {
     if(e->e_start <= dispatch_clock && e->e_stop > dispatch_clock) {
-      epg_set_current(ch, e);
+      epg_set_current(ch, e, NULL);
       return;
     }
 
     if((e = RB_NEXT(e, e_channel_link)) != NULL) {
 
       if(e->e_start <= dispatch_clock && e->e_stop > dispatch_clock) {
-       epg_set_current(ch, e);
+       epg_set_current(ch, e, NULL);
        return;
       }
     }
@@ -91,22 +94,22 @@ epg_ch_check_current_event(void *aux)
 
   e = epg_event_find_by_time(ch, dispatch_clock);
   if(e != NULL) {
-    epg_set_current(ch, e);
+    epg_set_current(ch, e, NULL);
     return;
   }
 
-  epg_set_current(ch, NULL);
-
   skel.e_start = dispatch_clock;
   e = RB_FIND_GT(&ch->ch_epg_events, &skel, e_channel_link, e_ch_cmp);
   if(e != NULL) {
     gtimer_arm_abs(&ch->ch_epg_timer_current, epg_ch_check_current_event,
                   ch, MAX(e->e_start, dispatch_clock + 1));
+    epg_set_current(ch, NULL, e);
+  } else {
+    epg_set_current(ch, NULL, NULL);
   }
 }
 
 
-
 /**
  *
  */
@@ -303,11 +306,13 @@ epg_remove_event_from_channel(channel_t *ch, event_t *e)
   epg_event_unref(e);
 
   if(ch->ch_epg_current == e) {
-    epg_set_current(ch, NULL);
+    epg_set_current(ch, NULL, n);
 
     if(n != NULL)
       gtimer_arm_abs(&ch->ch_epg_timer_current, epg_ch_check_current_event,
                     ch, n->e_start);
+  } else if(ch->ch_epg_next == e) {
+    epg_set_current(ch, ch->ch_epg_current, NULL);
   }
 
   if(wasfirst && (e = RB_FIRST(&ch->ch_epg_events)) != NULL) {
@@ -645,7 +650,12 @@ epg_load(void)
 void
 epg_init(void)
 {
+  channel_t *ch;
+
   epg_load();
+  
+  RB_FOREACH(ch, &channel_name_tree, ch_name_link)
+    epg_ch_check_current_event(ch);
 }
 
 
index 9a49ad2163c8810c56286ad21253100467229a29..571ceb344e3162ab1d407a150269cb6c536c7b03 100644 (file)
@@ -309,6 +309,8 @@ htsp_build_channel(channel_t *ch, const char *method)
 
   htsmsg_add_u32(out, "eventId",
                 ch->ch_epg_current != NULL ? ch->ch_epg_current->e_id : 0);
+  htsmsg_add_u32(out, "nextEventId",
+                ch->ch_epg_next ? ch->ch_epg_next->e_id : 0);
 
   LIST_FOREACH(ctm, &ch->ch_ctms, ctm_channel_link) {
     ct = ctm->ctm_tag;
@@ -1256,7 +1258,7 @@ htsp_async_send(htsmsg_t *m)
  * global_lock is held
  */
 void
-htsp_event_update(channel_t *ch, event_t *e)
+htsp_channgel_update_current(channel_t *ch)
 {
   htsmsg_t *m;
   time_t now;
@@ -1266,10 +1268,10 @@ htsp_event_update(channel_t *ch, event_t *e)
   htsmsg_add_str(m, "method", "channelUpdate");
   htsmsg_add_u32(m, "channelId", ch->ch_id);
 
-  if(e == NULL)
-    e = epg_event_find_by_time(ch, now);
-  
-  htsmsg_add_u32(m, "eventId", e ? e->e_id : 0);
+  htsmsg_add_u32(m, "eventId",
+                ch->ch_epg_current ? ch->ch_epg_current->e_id : 0);
+  htsmsg_add_u32(m, "nextEventId",
+                ch->ch_epg_next ? ch->ch_epg_next->e_id : 0);
   htsp_async_send(m);
 }
 
index db6ca8d730568d159373e35261845eb624a53bb4..7dcf33e69a664b5eee6472b9e971cfcfd8636b6b 100644 (file)
@@ -24,7 +24,7 @@
 
 void htsp_init(void);
 
-void htsp_event_update(channel_t *ch, event_t *e);
+void htsp_channgel_update_current(channel_t *ch);
 
 void htsp_channel_add(channel_t *ch);
 void htsp_channel_update(channel_t *ch);
index d2ee3a4a35a9ec90a2c607663bf390980e285562..17683a4145046ffc08e03877e1f00b47fa48b1bf 100644 (file)
@@ -357,6 +357,8 @@ main(int argc, char **argv)
 
   pthread_mutex_lock(&global_lock);
 
+  time(&dispatch_clock);
+
   trap_init(argv[0]);
   
   /**