]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
timeshift: add return to live function to HTSP
authorAdam Sutton <dev@adamsutton.me.uk>
Thu, 7 Mar 2013 16:42:59 +0000 (16:42 +0000)
committerAdam Sutton <dev@adamsutton.me.uk>
Tue, 26 Mar 2013 10:04:26 +0000 (10:04 +0000)
(cherry picked from commit 404316f08f0b5c30b94dd4c5983c2359f3a51de2)

src/htsp_server.c
src/timeshift/timeshift_reader.c
src/tvheadend.h

index 1c578a42543a4a55e1f5eb124d7d245de88cfeb6..8f76fe47f2bf41f27ed1d520b6f0586bca596394 100644 (file)
@@ -57,7 +57,7 @@
 
 static void *htsp_server, *htsp_server_2;
 
-#define HTSP_PROTO_VERSION 8
+#define HTSP_PROTO_VERSION 9
 
 #define HTSP_ASYNC_OFF  0x00
 #define HTSP_ASYNC_ON   0x01
@@ -1463,6 +1463,33 @@ htsp_method_speed(htsp_connection_t *htsp, htsmsg_t *in)
   return NULL;
 }
 
+/*
+ * Revert to live
+ */
+static htsmsg_t *
+htsp_method_live(htsp_connection_t *htsp, htsmsg_t *in)
+{
+  htsp_subscription_t *hs;
+  uint32_t sid;
+  streaming_skip_t skip;
+
+  if(htsmsg_get_u32(in, "subscriptionId", &sid))
+    return htsp_error("Missing argument 'subscriptionId'");
+
+  LIST_FOREACH(hs, &htsp->htsp_subscriptions, hs_link)
+    if(hs->hs_sid == sid)
+      break;
+
+  if(hs == NULL)
+    return htsp_error("Requested subscription does not exist");
+
+  skip.type = SMT_SKIP_LIVE;
+  subscription_set_skip(hs->hs_s, &skip);
+
+  htsp_reply(htsp, in, htsmsg_create_map());
+  return NULL;
+}
+
 /**
  * Open file
  */
@@ -1641,6 +1668,7 @@ struct {
   { "subscriptionSeek",         htsp_method_skip,           ACCESS_STREAMING},
   { "subscriptionSkip",         htsp_method_skip,           ACCESS_STREAMING},
   { "subscriptionSpeed",        htsp_method_speed,          ACCESS_STREAMING},
+  { "subscriptionLive",         htsp_method_live,           ACCESS_STREAMING},
   { "fileOpen",                 htsp_method_file_open,      ACCESS_RECORDER},
   { "fileRead",                 htsp_method_file_read,      ACCESS_RECORDER},
   { "fileClose",                htsp_method_file_close,     ACCESS_RECORDER},
index 1f9e739bfc53498317d6f3b8985aa12597cca51a..a89bd810b5e844cb92f087a417675d4752647a9f 100644 (file)
@@ -534,6 +534,27 @@ void *timeshift_reader ( void *p )
         } else if (ctrl->sm_type == SMT_SKIP) {
           skip = ctrl->sm_data;
           switch (skip->type) {
+            case SMT_SKIP_LIVE:
+              if (ts->state != TS_LIVE) {
+
+                /* Reset */
+                if (ts->full) {
+                  pthread_mutex_lock(&ts->rdwr_mutex);
+                  timeshift_filemgr_flush(ts, NULL);
+                  ts->full = 0;
+                  pthread_mutex_unlock(&ts->rdwr_mutex);
+                }
+
+                /* Release */
+                if (sm)
+                  streaming_msg_free(sm);
+
+                /* Find end */
+                skip_time = 0x7fffffffffffffff;
+                // TODO: change this sometime!
+              }
+              break;
+
             case SMT_SKIP_ABS_TIME:
               if (ts->pts_delta == PTS_UNSET) {
                 tvhlog(LOG_ERR, "timeshift", "ts %d abs skip not possible no PTS delta", ts->id);
@@ -745,8 +766,8 @@ void *timeshift_reader ( void *p )
       if (!end)
         end = (cur_speed > 0) ? 1 : -1;
 
-      /* Back to live */
-      if (end == 1) {
+      /* Back to live (unless buffer is full) */
+      if (end == 1 && !ts->full) {
         tvhlog(LOG_DEBUG, "timeshift", "ts %d eob revert to live mode", ts->id);
         ts->state = TS_LIVE;
         cur_speed = 100;
index d2f2b4e557be5ecaade35117e44d3905dbc5a773..b866754e2911f722cda9d07e50c7051bc1eafa03 100644 (file)
@@ -221,7 +221,8 @@ typedef struct streaming_skip
     SMT_SKIP_REL_TIME,
     SMT_SKIP_ABS_TIME,
     SMT_SKIP_REL_SIZE,
-    SMT_SKIP_ABS_SIZE
+    SMT_SKIP_ABS_SIZE,
+    SMT_SKIP_LIVE
   } type;
   union {
     off_t   size;