]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
improve play status handling
authorGlenn-1990 <g_christiaensen@msn.com>
Fri, 14 Apr 2017 18:33:54 +0000 (20:33 +0200)
committerJaroslav Kysela <perex@perex.cz>
Mon, 24 Apr 2017 14:56:42 +0000 (16:56 +0200)
src/htsp_server.c
src/htsp_server.h

index e2d15f54a0125cee71a9f1e1773740675e5b805b..98f7ad3b31d3fcc2c6cb91b8c7a04137d291a305 100644 (file)
@@ -236,9 +236,10 @@ typedef struct htsp_subscription {
  */
 typedef struct htsp_file {
   LIST_ENTRY(htsp_file) hf_link;
-  int hf_id;  // ID sent to client
-  int hf_fd;  // Our file descriptor
-  char *hf_path; // For logging
+  int hf_id;          // ID sent to client
+  int hf_fd;          // Our file descriptor
+  char *hf_path;      // For logging
+  uint32_t  hf_de_id; // Associated dvr entry
 } htsp_file_t;
 
 #define HTSP_DEFAULT_QUEUE_DEPTH 500000
@@ -722,15 +723,11 @@ htsp_file_open(htsp_connection_t *htsp, const char *path, int fd, dvr_entry_t *d
       return htsp_error(htsp, N_("Unable to open file"));
   }
 
-  if (de) {
-    de->de_playcount++;
-    dvr_entry_changed_notify(de);
-  }
-
   htsp_file_t *hf = calloc(1, sizeof(htsp_file_t));
   hf->hf_fd = fd;
   hf->hf_id = ++htsp->htsp_file_id;
   hf->hf_path = strdup(path);
+  hf->hf_de_id = de ? idnode_get_short_uuid(&de->de_id) : 0;
   LIST_INSERT_HEAD(&htsp->htsp_files, hf, hf_link);
 
   htsmsg_t *rep = htsmsg_create_map();
@@ -1975,8 +1972,27 @@ htsp_method_updateDvrEntry(htsp_connection_t *htsp, htsmsg_t *in)
   desc        = htsmsg_get_str(in, "description");
   lang        = htsmsg_get_str(in, "language") ?: htsp->htsp_language;
 
-  if(!htsmsg_get_u32(in, "playcount", &u32))
-    playcount = u32 > INT_MAX ? INT_MAX : u32;
+  if(!htsmsg_get_u32(in, "playcount", &u32)) {
+    if (u32 > INT_MAX)
+      u32 = HTSP_DVR_PLAYCOUNT_INCR;
+    switch (u32) {
+      case HTSP_DVR_PLAYCOUNT_INCR:
+        playcount = de->de_playcount + 1;
+        break;
+      case HTSP_DVR_PLAYCOUNT_SET:
+        if (!de->de_playcount)
+          playcount = 1;
+        break;
+      case HTSP_DVR_PLAYCOUNT_RESET:
+        playcount = 0;
+        break;
+      case HTSP_DVR_PLAYCOUNT_KEEP:
+        break;
+      default:
+        playcount = u32;
+        break;
+    }
+  }
   if(!htsmsg_get_u32(in, "playposition", &u32))
     playposition = u32 > INT_MAX ? INT_MAX : u32;
 
@@ -2785,10 +2801,28 @@ static htsmsg_t *
 htsp_method_file_close(htsp_connection_t *htsp, htsmsg_t *in)
 {
   htsp_file_t *hf = htsp_file_find(htsp, in);
+  uint32_t u32;
+  dvr_entry_t *de;
 
   if(hf == NULL)
     return htsp_error(htsp, N_("Invalid file"));
 
+  if (hf->hf_de_id > 0 && (de = dvr_entry_find_by_id(hf->hf_de_id)))
+  {
+    int save = 0;
+    /* Only allow incrementing playcount on file close, the rest can be done with "updateDvrEntry" */
+    if (htsp->htsp_version < 27 || htsmsg_get_u32_or_default(in, "playcount", HTSP_DVR_PLAYCOUNT_INCR) == HTSP_DVR_PLAYCOUNT_INCR) {
+      de->de_playcount++;
+      save = 1;
+    }
+    if(htsp->htsp_version >= 27 && !htsmsg_get_u32(in, "playposition", &u32)) {
+      de->de_playposition = u32;
+      save = 1;
+    }
+    if (save)
+      dvr_entry_changed_notify(de);
+  }
+
   htsp_file_destroy(hf);
   return htsmsg_create_map();
 }
index ba24bd16fe9c871f2b12b3aafdc66866e4453c8d..3b6470d51ab45e1d9bc9bacc710b0e1f6f49b1b0 100644 (file)
 #include "epg.h"
 #include "dvr/dvr.h"
 
+typedef enum {
+  HTSP_DVR_PLAYCOUNT_RESET = 0,
+  HTSP_DVR_PLAYCOUNT_SET   = 1,
+  HTSP_DVR_PLAYCOUNT_KEEP  = INT32_MAX-1,
+  HTSP_DVR_PLAYCOUNT_INCR  = INT32_MAX
+} dvr_playcount_t;
+
 void htsp_init(const char *bindaddr);
 void htsp_register(void);
 void htsp_done(void);