Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
htsp/http streaming: fix the de_playcount updates
  • Loading branch information
perexg committed Nov 24, 2016
1 parent 790b38c commit fb5ed85
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
11 changes: 8 additions & 3 deletions src/htsp_server.c
Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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"));
Expand Down
18 changes: 11 additions & 7 deletions src/webui/webui.c
Expand Up @@ -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));
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit fb5ed85

Please sign in to comment.