add framework for testing transcoder dlls

This commit is contained in:
Ron Pedde 2006-06-04 09:31:32 +00:00
parent 2ca9a89ccf
commit 0554045c32
5 changed files with 136 additions and 12 deletions

View File

@ -779,7 +779,7 @@ void dispatch_stream_id(WS_CONNINFO *pwsc, int session, char *id) {
session,pmp3->fname, pwsc->hostname,(long)offset);
bytes_copied = plugin_ssc_transcode(pwsc,pmp3->path,pmp3->codectype,
pmp3->song_length,offset);
pmp3->song_length,offset,1);
config_set_status(pwsc,session,NULL);
db_dispose_item(pmp3);

View File

@ -661,7 +661,7 @@ int _plugin_ssc_copy(WS_CONNINFO *pwsc, PLUGIN_TRANSCODE_FN *pfn,
* @param duration time in ms
* @returns bytes transferred, or -1 on error
*/
int plugin_ssc_transcode(WS_CONNINFO *pwsc, char *file, char *codec, int duration, int offset) {
int plugin_ssc_transcode(WS_CONNINFO *pwsc, char *file, char *codec, int duration, int offset, int headers) {
PLUGIN_ENTRY *ppi, *ptc=NULL;
PLUGIN_TRANSCODE_FN *pfn = NULL;
void *vp_ssc;
@ -691,16 +691,19 @@ int plugin_ssc_transcode(WS_CONNINFO *pwsc, char *file, char *codec, int duratio
if(vp_ssc) {
if(pfn->ssc_open(vp_ssc,file,codec,duration)) {
/* start reading and throwing */
ws_addresponseheader(pwsc,"Content-Type","audio/wav");
ws_addresponseheader(pwsc,"Connection","Close");
if(!offset) {
ws_writefd(pwsc,"HTTP/1.1 200 OK\r\n");
} else {
ws_addresponseheader(pwsc,"Content-Range","bytes %ld-*/*",
(long)offset);
ws_writefd(pwsc,"HTTP/1.1 206 Partial Content\r\n");
if(headers) {
ws_addresponseheader(pwsc,"Content-Type","audio/wav");
ws_addresponseheader(pwsc,"Connection","Close");
if(!offset) {
ws_writefd(pwsc,"HTTP/1.1 200 OK\r\n");
} else {
ws_addresponseheader(pwsc,"Content-Range","bytes %ld-*/*",
(long)offset);
ws_writefd(pwsc,"HTTP/1.1 206 Partial Content\r\n");
}
ws_emitheaders(pwsc);
}
ws_emitheaders(pwsc);
/* start reading/writing */
result = _plugin_ssc_copy(pwsc,pfn,vp_ssc,offset);

View File

@ -39,7 +39,7 @@ extern void plugin_event_dispatch(int event_id, int intval, void *vp, int len);
/* these should really get rows */
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, int headers);
#define PLUGIN_E_SUCCESS 0
#define PLUGIN_E_NOLOAD 1

110
src/transcoder-driver.c Normal file
View File

@ -0,0 +1,110 @@
#include <fcntl.h>
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "conf.h"
#include "daapd.h"
#include "err.h"
#include "os.h"
#include "plugin.h"
#include "webserver.h"
char *av0;
CONFIG config;
char *scan_winamp_genre[] = { NULL };
void usage(void) {
fprintf(stderr,"Usage: %s [options]\n\n",av0);
fprintf(stderr,"options:\n\n");
fprintf(stderr," -d level set debuglevel (9 is highest)\n");
fprintf(stderr," -c config read config file\n");
fprintf(stderr," -f file file to transcode\n");
fprintf(stderr," -p plugin plugin to use\n");
fprintf(stderr," -t codectype\n");
fprintf(stderr,"\n\n");
exit(-1);
}
int main(int argc, char *argv[]) {
int option;
int debuglevel;
char *plugin=NULL;
char *file=NULL;
char *codectype=NULL;
char *configfile="mt-daapd.conf";
int bytes_read;
char *pe;
WS_CONNINFO wsc;
if(strchr(argv[0],'/')) {
av0 = strrchr(argv[0],'/')+1;
} else {
av0 = argv[0];
}
while((option = getopt(argc, argv, "d:c:f:p:t:")) != -1) {
switch(option) {
case 'd':
debuglevel = atoi(optarg);
break;
case 'c':
configfile=optarg;
break;
case 'f':
file = optarg;
break;
case 'p':
plugin = optarg;
break;
case 't':
codectype = optarg;
break;
default:
fprintf(stderr,"Error: unknown option (%c)\n\n",option);
usage();
}
}
if((!plugin) || (!file) || (!codectype)) {
usage();
}
printf("Reading config file %s\n",configfile);
if(conf_read(configfile) != CONF_E_SUCCESS) {
fprintf(stderr,"Bummer.\n");
exit(-1);
}
err_setdest(LOGDEST_STDERR);
err_setlevel(debuglevel);
plugin_init();
if(plugin_load(&pe, plugin) != PLUGIN_E_SUCCESS) {
fprintf(stderr,"Could not load %s: %s\n",plugin, pe);
exit(-1);
}
/* fake up a wsconninfo */
memset(&wsc,0,sizeof(wsc));
wsc.fd = open("out.wav",O_WRONLY | O_CREAT, 0666);
if(wsc.fd == -1) {
fprintf(stderr,"Error opening output file\n");
exit(-1);
}
bytes_read=plugin_ssc_transcode(&wsc,file,codectype,60*1000*3, 0,0);
close(wsc.fd);
if(bytes_read < 1) {
fprintf(stderr,"Could not transcode\n");
exit(-1);
}
fprintf(stderr,"Transcoded %d bytes\n",bytes_read);
plugin_deinit();
}

11
src/transcoder.mk Normal file
View File

@ -0,0 +1,11 @@
CC=gcc
CFLAGS := $(CFLAGS) -g -I/sw/include -DHAVE_CONFIG_H -I. -I.. -DHOST='"foo"' -DHAVE_SQL -DHAVE_CONFIG_H
LDFLAGS := $(LDFLAGS) -L/sw/lib -lid3tag -logg -lvorbisfile -lFLAC -lvorbis -lsqlite -lsqlite3 -lm
TARGET = transcoder
OBJECTS=transcoder-driver.o restart.o err.o os-unix.o conf.o ll.o webserver.o uici.o configfile.o plugin.o xml-rpc.o db-generic.o smart-parser.o db-sql.o db-sql-sqlite2.o db-sql-sqlite3.o dispatch.o rend-win32.o dynamic-art.o scan-aac.o
$(TARGET): $(OBJECTS)
$(CC) -o $(TARGET) $(LDFLAGS) $(OBJECTS)
clean:
rm -f $(OBJECTS) $(TARGET)