diff --git a/src/db-generic.h b/src/db-generic.h index 22aeef21..2bb939fd 100644 --- a/src/db-generic.h +++ b/src/db-generic.h @@ -24,6 +24,7 @@ #include "mp3-scanner.h" /** for MP3FILE */ #include "smart-parser.h" /** for PARSETREE */ +#include "webserver.h" /** for WS_CONNINFO */ typedef enum { // generic meta data @@ -131,6 +132,7 @@ typedef struct tag_dbqueryinfo { char *uri_sections[10]; PARSETREE pt; void *output_info; + WS_CONNINFO *pwsc; } DBQUERYINFO; typedef struct { diff --git a/src/db-sql.c b/src/db-sql.c index f31a8241..e31c6fc3 100644 --- a/src/db-sql.c +++ b/src/db-sql.c @@ -1354,7 +1354,7 @@ int db_sql_get_size(DBQUERYINFO *pinfo, SQL_ROW valarray) { case queryTypeItems: case queryTypePlaylistItems: /* essentially the same query */ /* see if this is going to be transcoded */ - transcode = plugin_ssc_can_transcode(valarray[37]); + transcode = plugin_ssc_should_transcode(pinfo->pwsc,valarray[37]); /* Items that get changed by transcode: * @@ -1530,7 +1530,7 @@ int db_sql_build_dmap(DBQUERYINFO *pinfo, char **valarray, unsigned char *presul case queryTypeItems: case queryTypePlaylistItems: /* essentially the same query */ /* see if this is going to be transcoded */ - transcode = plugin_ssc_can_transcode(valarray[37]); + transcode = plugin_ssc_should_transcode(pinfo->pwsc,valarray[37]); /* Items that get changed by transcode: * diff --git a/src/dispatch.c b/src/dispatch.c index 8a5a242d..f7b462c7 100644 --- a/src/dispatch.c +++ b/src/dispatch.c @@ -171,6 +171,7 @@ void daap_handler(WS_CONNINFO *pwsc) { memset(pqi,0x00,sizeof(DBQUERYINFO)); pqi->zero_length = conf_get_int("daap","empty_strings",0); + pqi->pwsc = pwsc; /* we could really pre-parse this to make sure it works */ query=ws_getvar(pwsc,"query"); @@ -764,7 +765,7 @@ void dispatch_stream_id(WS_CONNINFO *pwsc, int session, char *id) { DPRINTF(E_LOG,L_DAAP|L_WS|L_DB,"Could not find requested item %lu\n",item); config_set_status(pwsc,session,NULL); ws_returnerror(pwsc,404,"File Not Found"); - } else if (plugin_ssc_can_transcode(pmp3->codectype)) { + } else if (plugin_ssc_should_transcode(pwsc,pmp3->codectype)) { /************************ * Server side conversion ************************/ diff --git a/src/ff-plugins.h b/src/ff-plugins.h index e0678d23..0ed504d0 100644 --- a/src/ff-plugins.h +++ b/src/ff-plugins.h @@ -130,7 +130,7 @@ typedef struct tag_plugin_input_fn { char* (*server_ver)(void); int (*server_name)(char *, int *); void (*log)(int, char *, ...); - int (*can_transcode)(char *); + int (*should_transcode)(struct tag_ws_conninfo *, char *); int (*db_count)(void); int (*db_enum_start)(char **, DB_QUERY *); diff --git a/src/plugin.c b/src/plugin.c index 4ec74efc..78cda88e 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -108,7 +108,7 @@ PLUGIN_INPUT_FN pi = { pi_server_ver, pi_server_name, pi_log, - plugin_ssc_can_transcode, + plugin_ssc_should_transcode, pi_db_count, pi_db_enum_start, @@ -578,12 +578,35 @@ void plugin_event_dispatch(int event_id, int intval, void *vp, int len) { * @param codec the codec we are trying to serve * @returns TRUE if we can transcode, FALSE otherwise */ -int plugin_ssc_can_transcode(char *codec) { +int plugin_ssc_should_transcode(WS_CONNINFO *pwsc, char *codec) { int result; + char *native_codecs=NULL; + char *user_agent=NULL; + if(pwsc) { + /* see if the headers give us any guidance */ + native_codecs = ws_getrequestheader(pwsc,"accept-codecs"); + if(!native_codecs) { + user_agent = ws_getrequestheader(pwsc,"user-agent"); + if(strncmp(user_agent,"iTunes",6)==0) { + native_codecs = "mpeg,mp4a,wav,mp4v"; + } else if(strncmp(user_agent,"Roku",4)==0) { + native_codecs = "mpeg,mp4a,wav"; + } + } + } + + if(!native_codecs) { + native_codecs = "mpeg,wav"; + } + + /* can't transcode it if we can't transcode it */ if(!_plugin_ssc_codecs) return FALSE; + if(strstr(native_codecs,codec)) + return FALSE; + _plugin_readlock(); result = FALSE; if(strstr(_plugin_ssc_codecs,codec)) { diff --git a/src/plugin.h b/src/plugin.h index d7f80305..6cfe3c1d 100644 --- a/src/plugin.h +++ b/src/plugin.h @@ -38,7 +38,7 @@ extern int plugin_rend_register(char *name, int port, char *iface, char *txt); extern void plugin_event_dispatch(int event_id, int intval, void *vp, int len); /* these should really get rows */ -extern int plugin_ssc_can_transcode(char *codec); +extern int plugin_ssc_should_transcode(WS_CONNINFO *pwsc, char *codec); extern int plugin_ssc_transcode(WS_CONNINFO *pwsc, char *file, char *codec, int duration, int offset); #define PLUGIN_E_SUCCESS 0 diff --git a/src/plugins/rsp.c b/src/plugins/rsp.c index 0f2b9803..bdb8efbc 100644 --- a/src/plugins/rsp.c +++ b/src/plugins/rsp.c @@ -342,23 +342,6 @@ void rsp_playlist(WS_CONNINFO *pwsc, PRIVINFO *ppi) { int transcode; int samplerate; - char *user_agent; - char *native_codecs; - - native_codecs = _ppi->ws_getrequestheader(pwsc,"accept-codecs"); - if(!native_codecs) { - user_agent = _ppi->ws_getrequestheader(pwsc,"user-agent"); - if(user_agent) { - if(strncmp(user_agent,"iTunes",6)==0) { - native_codecs = "mpeg,mp4a,wav,mp4v"; - } else if(strncmp(user_agent,"Roku",4)==0) { - native_codecs = "mpeg,mp4a,wav,wma"; - } else { - native_codecs = "mpeg,mp4a,wav"; - } - } - } - ppi->dq.filter = _ppi->ws_getvar(pwsc,"query"); ppi->dq.filter_type = FILTER_TYPE_FIREFLY; @@ -414,11 +397,9 @@ void rsp_playlist(WS_CONNINFO *pwsc, PRIVINFO *ppi) { rowindex=0; transcode = 0; - if(!strstr(native_codecs,row[37])) { - if(_ppi->can_transcode(row[37])) { - transcode = 1; - } - } + transcode = _ppi->should_transcode(pwsc,row[37]); + + _ppi->log(E_DBG,"Transcode: %d, %s: %s\n",transcode,row[37],row[2]); while(rsp_fields[rowindex].name) { if((rsp_fields[rowindex].flags & type) &&