Fix the opportunistic encoding thing -- only transcode to platforms that need it

This commit is contained in:
Ron Pedde 2006-05-31 06:07:42 +00:00
parent 9e5cb8879d
commit 8a6b2ee00a
7 changed files with 36 additions and 29 deletions

View File

@ -24,6 +24,7 @@
#include "mp3-scanner.h" /** for MP3FILE */ #include "mp3-scanner.h" /** for MP3FILE */
#include "smart-parser.h" /** for PARSETREE */ #include "smart-parser.h" /** for PARSETREE */
#include "webserver.h" /** for WS_CONNINFO */
typedef enum { typedef enum {
// generic meta data // generic meta data
@ -131,6 +132,7 @@ typedef struct tag_dbqueryinfo {
char *uri_sections[10]; char *uri_sections[10];
PARSETREE pt; PARSETREE pt;
void *output_info; void *output_info;
WS_CONNINFO *pwsc;
} DBQUERYINFO; } DBQUERYINFO;
typedef struct { typedef struct {

View File

@ -1354,7 +1354,7 @@ int db_sql_get_size(DBQUERYINFO *pinfo, SQL_ROW valarray) {
case queryTypeItems: case queryTypeItems:
case queryTypePlaylistItems: /* essentially the same query */ case queryTypePlaylistItems: /* essentially the same query */
/* see if this is going to be transcoded */ /* 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: /* 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 queryTypeItems:
case queryTypePlaylistItems: /* essentially the same query */ case queryTypePlaylistItems: /* essentially the same query */
/* see if this is going to be transcoded */ /* 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: /* Items that get changed by transcode:
* *

View File

@ -171,6 +171,7 @@ void daap_handler(WS_CONNINFO *pwsc) {
memset(pqi,0x00,sizeof(DBQUERYINFO)); memset(pqi,0x00,sizeof(DBQUERYINFO));
pqi->zero_length = conf_get_int("daap","empty_strings",0); pqi->zero_length = conf_get_int("daap","empty_strings",0);
pqi->pwsc = pwsc;
/* we could really pre-parse this to make sure it works */ /* we could really pre-parse this to make sure it works */
query=ws_getvar(pwsc,"query"); 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); DPRINTF(E_LOG,L_DAAP|L_WS|L_DB,"Could not find requested item %lu\n",item);
config_set_status(pwsc,session,NULL); config_set_status(pwsc,session,NULL);
ws_returnerror(pwsc,404,"File Not Found"); 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 * Server side conversion
************************/ ************************/

View File

@ -130,7 +130,7 @@ typedef struct tag_plugin_input_fn {
char* (*server_ver)(void); char* (*server_ver)(void);
int (*server_name)(char *, int *); int (*server_name)(char *, int *);
void (*log)(int, char *, ...); void (*log)(int, char *, ...);
int (*can_transcode)(char *); int (*should_transcode)(struct tag_ws_conninfo *, char *);
int (*db_count)(void); int (*db_count)(void);
int (*db_enum_start)(char **, DB_QUERY *); int (*db_enum_start)(char **, DB_QUERY *);

View File

@ -108,7 +108,7 @@ PLUGIN_INPUT_FN pi = {
pi_server_ver, pi_server_ver,
pi_server_name, pi_server_name,
pi_log, pi_log,
plugin_ssc_can_transcode, plugin_ssc_should_transcode,
pi_db_count, pi_db_count,
pi_db_enum_start, 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 * @param codec the codec we are trying to serve
* @returns TRUE if we can transcode, FALSE otherwise * @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; 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) if(!_plugin_ssc_codecs)
return FALSE; return FALSE;
if(strstr(native_codecs,codec))
return FALSE;
_plugin_readlock(); _plugin_readlock();
result = FALSE; result = FALSE;
if(strstr(_plugin_ssc_codecs,codec)) { if(strstr(_plugin_ssc_codecs,codec)) {

View File

@ -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); extern void plugin_event_dispatch(int event_id, int intval, void *vp, int len);
/* these should really get rows */ /* 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); extern int plugin_ssc_transcode(WS_CONNINFO *pwsc, char *file, char *codec, int duration, int offset);
#define PLUGIN_E_SUCCESS 0 #define PLUGIN_E_SUCCESS 0

View File

@ -342,23 +342,6 @@ void rsp_playlist(WS_CONNINFO *pwsc, PRIVINFO *ppi) {
int transcode; int transcode;
int samplerate; 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 = _ppi->ws_getvar(pwsc,"query");
ppi->dq.filter_type = FILTER_TYPE_FIREFLY; ppi->dq.filter_type = FILTER_TYPE_FIREFLY;
@ -414,11 +397,9 @@ void rsp_playlist(WS_CONNINFO *pwsc, PRIVINFO *ppi) {
rowindex=0; rowindex=0;
transcode = 0; transcode = 0;
if(!strstr(native_codecs,row[37])) { transcode = _ppi->should_transcode(pwsc,row[37]);
if(_ppi->can_transcode(row[37])) {
transcode = 1; _ppi->log(E_DBG,"Transcode: %d, %s: %s\n",transcode,row[37],row[2]);
}
}
while(rsp_fields[rowindex].name) { while(rsp_fields[rowindex].name) {
if((rsp_fields[rowindex].flags & type) && if((rsp_fields[rowindex].flags & type) &&