]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
htsp/http streaming: fix the de_playcount updates
authorJaroslav Kysela <perex@perex.cz>
Thu, 24 Nov 2016 14:02:30 +0000 (15:02 +0100)
committerJaroslav Kysela <perex@perex.cz>
Thu, 24 Nov 2016 14:05:59 +0000 (15:05 +0100)
src/htsp_server.c
src/webui/webui.c

index 530cb87f9f7078ab3a30d19a1f240e548dc81a5a..baa543b271a2e78ebb837aa4d61090a50f096ddf 100644 (file)
@@ -707,7 +707,7 @@ htsp_channel_tag_find_by_identifier(htsp_connection_t *htsp, uint32_t id)
  *
  */
 static htsmsg_t *
-htsp_file_open(htsp_connection_t *htsp, const char *path, int fd)
+htsp_file_open(htsp_connection_t *htsp, const char *path, int fd, dvr_entry_t *de)
 {
   struct stat st;
 
@@ -718,6 +718,11 @@ htsp_file_open(htsp_connection_t *htsp, const char *path, int fd)
       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;
@@ -2689,13 +2694,13 @@ htsp_method_file_open(htsp_connection_t *htsp, htsmsg_t *in)
     if (filename == NULL)
       return htsp_error(htsp, N_("DVR schedule does not have a file yet"));
 
-    return htsp_file_open(htsp, filename, 0);
+    return htsp_file_open(htsp, filename, 0, de);
 
   } else if ((s2 = tvh_strbegins(str, "imagecache/")) != NULL) {
     int fd = imagecache_open(atoi(s2));
     if (fd < 0)
       return htsp_error(htsp, N_("Failed to open image"));
-    return htsp_file_open(htsp, str, fd);
+    return htsp_file_open(htsp, str, fd, NULL);
 
   } else {
     return htsp_error(htsp, N_("Unknown file"));
index ba6e87ceb75eb25409c9faa131438c9fe9d3a1f2..8c22ca14478b455150b708d630ce6f339105ac6a 100644 (file)
@@ -1510,7 +1510,6 @@ page_dvrfile(http_connection_t *hc, const char *remain, void *opaque)
     return HTTP_STATUS_UNAUTHORIZED;
 
   pthread_mutex_lock(&global_lock);
-
   de = dvr_entry_find_by_uuid(remain);
   if (de == NULL)
     de = dvr_entry_find_by_id(atoi(remain));
@@ -1523,12 +1522,6 @@ page_dvrfile(http_connection_t *hc, const char *remain, void *opaque)
     return HTTP_STATUS_UNAUTHORIZED;
   }
 
-  /* Play count + 1 when write access */
-  if (!dvr_entry_verify(de, hc->hc_access, 0)) {
-    de->de_playcount = de->de_playcount + 1;
-    dvr_entry_changed_notify(de);
-  }
-
   fname = tvh_strdupa(filename);
   content = muxer_container_filename2mime(fname, 1);
   charset = de->de_config ? de->de_config->dvr_charset_id : NULL;
@@ -1622,6 +1615,17 @@ page_dvrfile(http_connection_t *hc, const char *remain, void *opaque)
       free(str);
     }
   }
+  /* Play count + 1 when write access */
+  if (!hc->hc_no_output && file_start <= 0 &&
+      !dvr_entry_verify(de, hc->hc_access, 0)) {
+    de = dvr_entry_find_by_uuid(remain);
+    if (de == NULL)
+      de = dvr_entry_find_by_id(atoi(remain));
+    if (de) {
+      de->de_playcount = de->de_playcount + 1;
+      dvr_entry_changed_notify(de);
+    }
+  }
   pthread_mutex_unlock(&global_lock);
   if (tcp_id == NULL) {
     close(fd);