mirror of
https://github.com/owntone/owntone-server.git
synced 2025-01-27 14:43:21 -05:00
try to better detect successful transcoding in order to update play counts - #191
This commit is contained in:
parent
da77bb850a
commit
a3d3c21b65
26
src/plugin.c
26
src/plugin.c
@ -540,8 +540,11 @@ int _plugin_ssc_copy(WS_CONNINFO *pwsc, PLUGIN_TRANSCODE_FN *pfn,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(bytes_read < 0)
|
/*
|
||||||
|
if(bytes_read < 0) {
|
||||||
return bytes_read;
|
return bytes_read;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
return total_bytes_read;
|
return total_bytes_read;
|
||||||
}
|
}
|
||||||
@ -564,8 +567,6 @@ int _plugin_ssc_transcode(WS_CONNINFO *pwsc, MP3FILE *pmp3, int offset, int head
|
|||||||
int result = -1;
|
int result = -1;
|
||||||
|
|
||||||
/* first, find the plugin that will do the conversion */
|
/* first, find the plugin that will do the conversion */
|
||||||
|
|
||||||
|
|
||||||
ppi = _plugin_list.next;
|
ppi = _plugin_list.next;
|
||||||
while((ppi) && (!pfn)) {
|
while((ppi) && (!pfn)) {
|
||||||
if(ppi->pinfo->type & PLUGIN_TRANSCODE) {
|
if(ppi->pinfo->type & PLUGIN_TRANSCODE) {
|
||||||
@ -591,14 +592,14 @@ int _plugin_ssc_transcode(WS_CONNINFO *pwsc, MP3FILE *pmp3, int offset, int head
|
|||||||
if(!offset) {
|
if(!offset) {
|
||||||
ws_writefd(pwsc,"HTTP/1.1 200 OK\r\n");
|
ws_writefd(pwsc,"HTTP/1.1 200 OK\r\n");
|
||||||
} else {
|
} else {
|
||||||
ws_addresponseheader(pwsc,"Content-Range","bytes %ld-*/*",
|
ws_addresponseheader(pwsc,"Content-Range",
|
||||||
|
"bytes %ld-*/*",
|
||||||
(long)offset);
|
(long)offset);
|
||||||
ws_writefd(pwsc,"HTTP/1.1 206 Partial Content\r\n");
|
ws_writefd(pwsc,"HTTP/1.1 206 Partial Content\r\n");
|
||||||
}
|
}
|
||||||
ws_emitheaders(pwsc);
|
ws_emitheaders(pwsc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* start reading/writing */
|
/* start reading/writing */
|
||||||
result = _plugin_ssc_copy(pwsc,pfn,vp_ssc,offset);
|
result = _plugin_ssc_copy(pwsc,pfn,vp_ssc,offset);
|
||||||
post_error = 0;
|
post_error = 0;
|
||||||
@ -832,8 +833,8 @@ void pi_stream(WS_CONNINFO *pwsc, char *id) {
|
|||||||
int session = 0;
|
int session = 0;
|
||||||
MP3FILE *pmp3;
|
MP3FILE *pmp3;
|
||||||
int file_fd;
|
int file_fd;
|
||||||
int bytes_copied;
|
int bytes_copied=0;
|
||||||
off_t real_len;
|
off_t real_len=0;
|
||||||
off_t file_len;
|
off_t file_len;
|
||||||
off_t offset=0;
|
off_t offset=0;
|
||||||
long img_size;
|
long img_size;
|
||||||
@ -868,7 +869,10 @@ void pi_stream(WS_CONNINFO *pwsc, char *id) {
|
|||||||
"Session %d: Streaming file '%s' to %s (offset %ld)\n",
|
"Session %d: Streaming file '%s' to %s (offset %ld)\n",
|
||||||
session,pmp3->fname, pwsc->hostname,(long)offset);
|
session,pmp3->fname, pwsc->hostname,(long)offset);
|
||||||
|
|
||||||
|
/* estimate the real length of this thing */
|
||||||
bytes_copied = _plugin_ssc_transcode(pwsc,pmp3,offset,1);
|
bytes_copied = _plugin_ssc_transcode(pwsc,pmp3,offset,1);
|
||||||
|
if(bytes_copied != -1)
|
||||||
|
real_len = bytes_copied;
|
||||||
|
|
||||||
config_set_status(pwsc,session,NULL);
|
config_set_status(pwsc,session,NULL);
|
||||||
db_dispose_item(pmp3);
|
db_dispose_item(pmp3);
|
||||||
@ -967,16 +971,16 @@ void pi_stream(WS_CONNINFO *pwsc, char *id) {
|
|||||||
} else {
|
} else {
|
||||||
DPRINTF(E_INF,L_WS,"Finished streaming file to remote: %d bytes\n",
|
DPRINTF(E_INF,L_WS,"Finished streaming file to remote: %d bytes\n",
|
||||||
bytes_copied);
|
bytes_copied);
|
||||||
/* update play counts */
|
|
||||||
if(bytes_copied + 20 >= real_len) {
|
|
||||||
db_playcount_increment(NULL,pmp3->id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
config_set_status(pwsc,session,NULL);
|
config_set_status(pwsc,session,NULL);
|
||||||
r_close(file_fd);
|
r_close(file_fd);
|
||||||
db_dispose_item(pmp3);
|
db_dispose_item(pmp3);
|
||||||
}
|
}
|
||||||
|
/* update play counts */
|
||||||
|
if(bytes_copied >= (real_len * 80 / 100)) {
|
||||||
|
db_playcount_increment(NULL,pmp3->id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// free(pqi);
|
// free(pqi);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user